Blame view
crypto/gcm.c
30 KB
d2912cb15 treewide: Replace... |
1 |
// SPDX-License-Identifier: GPL-2.0-only |
28db8e3e3 [CRYPTO] gcm: New... |
2 3 4 5 |
/* * GCM: Galois/Counter Mode. * * Copyright (c) 2007 Nokia Siemens Networks - Mikko Herranen <mh1@iki.fi> |
28db8e3e3 [CRYPTO] gcm: New... |
6 |
*/ |
28db8e3e3 [CRYPTO] gcm: New... |
7 |
#include <crypto/gf128mul.h> |
dadbc53d0 [CRYPTO] gcm: Int... |
8 |
#include <crypto/internal/aead.h> |
1472e5eba [CRYPTO] gcm: Use... |
9 |
#include <crypto/internal/skcipher.h> |
9382d97af crypto: gcm - Use... |
10 |
#include <crypto/internal/hash.h> |
17db85469 crypto: gcm - Use... |
11 |
#include <crypto/null.h> |
42c271c6c [CRYPTO] scatterw... |
12 |
#include <crypto/scatterwalk.h> |
e0ab7e9c6 crypto: gcm - Use... |
13 |
#include <crypto/gcm.h> |
9382d97af crypto: gcm - Use... |
14 |
#include <crypto/hash.h> |
28db8e3e3 [CRYPTO] gcm: New... |
15 16 17 18 19 |
#include <linux/err.h> #include <linux/init.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/slab.h> |
28db8e3e3 [CRYPTO] gcm: New... |
20 |
struct gcm_instance_ctx { |
1472e5eba [CRYPTO] gcm: Use... |
21 |
struct crypto_skcipher_spawn ctr; |
9382d97af crypto: gcm - Use... |
22 |
struct crypto_ahash_spawn ghash; |
28db8e3e3 [CRYPTO] gcm: New... |
23 24 25 |
}; struct crypto_gcm_ctx { |
16f37ecdd crypto: gcm - Use... |
26 |
struct crypto_skcipher *ctr; |
9382d97af crypto: gcm - Use... |
27 |
struct crypto_ahash *ghash; |
28db8e3e3 [CRYPTO] gcm: New... |
28 |
}; |
dadbc53d0 [CRYPTO] gcm: Int... |
29 30 31 32 |
struct crypto_rfc4106_ctx { struct crypto_aead *child; u8 nonce[4]; }; |
7b05a373a crypto: gcm - Use... |
33 34 35 36 37 |
struct crypto_rfc4106_req_ctx { struct scatterlist src[3]; struct scatterlist dst[3]; struct aead_request subreq; }; |
9489667d3 crypto: gcm - mak... |
38 39 |
struct crypto_rfc4543_instance_ctx { struct crypto_aead_spawn aead; |
9489667d3 crypto: gcm - mak... |
40 |
}; |
73c89c15b crypto: gcm - Add... |
41 42 |
struct crypto_rfc4543_ctx { struct crypto_aead *child; |
8d6053984 crypto: null - Re... |
43 |
struct crypto_sync_skcipher *null; |
73c89c15b crypto: gcm - Add... |
44 45 46 47 |
u8 nonce[4]; }; struct crypto_rfc4543_req_ctx { |
73c89c15b crypto: gcm - Add... |
48 49 |
struct aead_request subreq; }; |
28db8e3e3 [CRYPTO] gcm: New... |
50 |
struct crypto_gcm_ghash_ctx { |
9382d97af crypto: gcm - Use... |
51 52 |
unsigned int cryptlen; struct scatterlist *src; |
adcbc688f crypto: gcm - Con... |
53 |
int (*complete)(struct aead_request *req, u32 flags); |
28db8e3e3 [CRYPTO] gcm: New... |
54 55 56 |
}; struct crypto_gcm_req_priv_ctx { |
adcbc688f crypto: gcm - Con... |
57 |
u8 iv[16]; |
28db8e3e3 [CRYPTO] gcm: New... |
58 |
u8 auth_tag[16]; |
6160b2899 [CRYPTO] gcm: Fix... |
59 |
u8 iauth_tag[16]; |
adcbc688f crypto: gcm - Con... |
60 61 62 |
struct scatterlist src[3]; struct scatterlist dst[3]; struct scatterlist sg; |
9382d97af crypto: gcm - Use... |
63 64 65 |
struct crypto_gcm_ghash_ctx ghash_ctx; union { struct ahash_request ahreq; |
16f37ecdd crypto: gcm - Use... |
66 |
struct skcipher_request skreq; |
9382d97af crypto: gcm - Use... |
67 |
} u; |
28db8e3e3 [CRYPTO] gcm: New... |
68 |
}; |
adcbc688f crypto: gcm - Con... |
69 70 71 72 73 74 |
static struct { u8 buf[16]; struct scatterlist sg; } *gcm_zeroes; static int crypto_rfc4543_copy_src_to_dst(struct aead_request *req, bool enc); |
9382d97af crypto: gcm - Use... |
75 |
|
2589469d7 [CRYPTO] gcm: Fix... |
76 77 78 79 80 81 82 |
static inline struct crypto_gcm_req_priv_ctx *crypto_gcm_reqctx( struct aead_request *req) { unsigned long align = crypto_aead_alignmask(crypto_aead_reqtfm(req)); return (void *)PTR_ALIGN((u8 *)aead_request_ctx(req), align + 1); } |
28db8e3e3 [CRYPTO] gcm: New... |
83 84 85 86 |
static int crypto_gcm_setkey(struct crypto_aead *aead, const u8 *key, unsigned int keylen) { struct crypto_gcm_ctx *ctx = crypto_aead_ctx(aead); |
9382d97af crypto: gcm - Use... |
87 |
struct crypto_ahash *ghash = ctx->ghash; |
16f37ecdd crypto: gcm - Use... |
88 |
struct crypto_skcipher *ctr = ctx->ctr; |
84c911523 [CRYPTO] gcm: Add... |
89 90 |
struct { be128 hash; |
50d2e6dc1 crypto: gcm - Fix... |
91 |
u8 iv[16]; |
84c911523 [CRYPTO] gcm: Add... |
92 |
|
76c673947 crypto: gcm - mov... |
93 |
struct crypto_wait wait; |
84c911523 [CRYPTO] gcm: Add... |
94 95 |
struct scatterlist sg[1]; |
16f37ecdd crypto: gcm - Use... |
96 |
struct skcipher_request req; |
84c911523 [CRYPTO] gcm: Add... |
97 98 |
} *data; int err; |
28db8e3e3 [CRYPTO] gcm: New... |
99 |
|
16f37ecdd crypto: gcm - Use... |
100 101 102 103 |
crypto_skcipher_clear_flags(ctr, CRYPTO_TFM_REQ_MASK); crypto_skcipher_set_flags(ctr, crypto_aead_get_flags(aead) & CRYPTO_TFM_REQ_MASK); err = crypto_skcipher_setkey(ctr, key, keylen); |
28db8e3e3 [CRYPTO] gcm: New... |
104 |
if (err) |
84c911523 [CRYPTO] gcm: Add... |
105 |
return err; |
28db8e3e3 [CRYPTO] gcm: New... |
106 |
|
16f37ecdd crypto: gcm - Use... |
107 |
data = kzalloc(sizeof(*data) + crypto_skcipher_reqsize(ctr), |
84c911523 [CRYPTO] gcm: Add... |
108 109 110 |
GFP_KERNEL); if (!data) return -ENOMEM; |
76c673947 crypto: gcm - mov... |
111 |
crypto_init_wait(&data->wait); |
84c911523 [CRYPTO] gcm: Add... |
112 |
sg_init_one(data->sg, &data->hash, sizeof(data->hash)); |
16f37ecdd crypto: gcm - Use... |
113 114 115 |
skcipher_request_set_tfm(&data->req, ctr); skcipher_request_set_callback(&data->req, CRYPTO_TFM_REQ_MAY_SLEEP | CRYPTO_TFM_REQ_MAY_BACKLOG, |
76c673947 crypto: gcm - mov... |
116 117 |
crypto_req_done, &data->wait); |
16f37ecdd crypto: gcm - Use... |
118 119 |
skcipher_request_set_crypt(&data->req, data->sg, data->sg, sizeof(data->hash), data->iv); |
76c673947 crypto: gcm - mov... |
120 121 |
err = crypto_wait_req(crypto_skcipher_encrypt(&data->req), &data->wait); |
84c911523 [CRYPTO] gcm: Add... |
122 |
|
28db8e3e3 [CRYPTO] gcm: New... |
123 124 |
if (err) goto out; |
9382d97af crypto: gcm - Use... |
125 126 127 128 |
crypto_ahash_clear_flags(ghash, CRYPTO_TFM_REQ_MASK); crypto_ahash_set_flags(ghash, crypto_aead_get_flags(aead) & CRYPTO_TFM_REQ_MASK); err = crypto_ahash_setkey(ghash, (u8 *)&data->hash, sizeof(be128)); |
84c911523 [CRYPTO] gcm: Add... |
129 |
out: |
453431a54 mm, treewide: ren... |
130 |
kfree_sensitive(data); |
28db8e3e3 [CRYPTO] gcm: New... |
131 132 |
return err; } |
dadbc53d0 [CRYPTO] gcm: Int... |
133 134 135 |
static int crypto_gcm_setauthsize(struct crypto_aead *tfm, unsigned int authsize) { |
65526f638 crypto: gcm - hel... |
136 |
return crypto_gcm_check_authsize(authsize); |
dadbc53d0 [CRYPTO] gcm: Int... |
137 |
} |
adcbc688f crypto: gcm - Con... |
138 |
static void crypto_gcm_init_common(struct aead_request *req) |
28db8e3e3 [CRYPTO] gcm: New... |
139 |
{ |
2589469d7 [CRYPTO] gcm: Fix... |
140 |
struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); |
84c911523 [CRYPTO] gcm: Add... |
141 |
__be32 counter = cpu_to_be32(1); |
adcbc688f crypto: gcm - Con... |
142 |
struct scatterlist *sg; |
84c911523 [CRYPTO] gcm: Add... |
143 144 |
memset(pctx->auth_tag, 0, sizeof(pctx->auth_tag)); |
e0ab7e9c6 crypto: gcm - Use... |
145 146 |
memcpy(pctx->iv, req->iv, GCM_AES_IV_SIZE); memcpy(pctx->iv + GCM_AES_IV_SIZE, &counter, 4); |
84c911523 [CRYPTO] gcm: Add... |
147 |
|
adcbc688f crypto: gcm - Con... |
148 |
sg_init_table(pctx->src, 3); |
84c911523 [CRYPTO] gcm: Add... |
149 |
sg_set_buf(pctx->src, pctx->auth_tag, sizeof(pctx->auth_tag)); |
adcbc688f crypto: gcm - Con... |
150 151 |
sg = scatterwalk_ffwd(pctx->src + 1, req->src, req->assoclen); if (sg != pctx->src + 1) |
c56f6d127 crypto: replace s... |
152 |
sg_chain(pctx->src, 2, sg); |
84c911523 [CRYPTO] gcm: Add... |
153 |
|
84c911523 [CRYPTO] gcm: Add... |
154 |
if (req->src != req->dst) { |
adcbc688f crypto: gcm - Con... |
155 |
sg_init_table(pctx->dst, 3); |
84c911523 [CRYPTO] gcm: Add... |
156 |
sg_set_buf(pctx->dst, pctx->auth_tag, sizeof(pctx->auth_tag)); |
adcbc688f crypto: gcm - Con... |
157 158 |
sg = scatterwalk_ffwd(pctx->dst + 1, req->dst, req->assoclen); if (sg != pctx->dst + 1) |
c56f6d127 crypto: replace s... |
159 |
sg_chain(pctx->dst, 2, sg); |
84c911523 [CRYPTO] gcm: Add... |
160 |
} |
adcbc688f crypto: gcm - Con... |
161 162 163 164 165 166 167 168 |
} static void crypto_gcm_init_crypt(struct aead_request *req, unsigned int cryptlen) { struct crypto_aead *aead = crypto_aead_reqtfm(req); struct crypto_gcm_ctx *ctx = crypto_aead_ctx(aead); struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); |
16f37ecdd crypto: gcm - Use... |
169 |
struct skcipher_request *skreq = &pctx->u.skreq; |
adcbc688f crypto: gcm - Con... |
170 171 172 |
struct scatterlist *dst; dst = req->src == req->dst ? pctx->src : pctx->dst; |
28db8e3e3 [CRYPTO] gcm: New... |
173 |
|
16f37ecdd crypto: gcm - Use... |
174 175 |
skcipher_request_set_tfm(skreq, ctx->ctr); skcipher_request_set_crypt(skreq, pctx->src, dst, |
84c911523 [CRYPTO] gcm: Add... |
176 |
cryptlen + sizeof(pctx->auth_tag), |
adcbc688f crypto: gcm - Con... |
177 |
pctx->iv); |
9382d97af crypto: gcm - Use... |
178 179 180 181 182 183 184 185 186 |
} static inline unsigned int gcm_remain(unsigned int len) { len &= 0xfU; return len ? 16 - len : 0; } static void gcm_hash_len_done(struct crypto_async_request *areq, int err); |
28db8e3e3 [CRYPTO] gcm: New... |
187 |
|
9382d97af crypto: gcm - Use... |
188 |
static int gcm_hash_update(struct aead_request *req, |
3e3dc25fe crypto: Resolve s... |
189 |
crypto_completion_t compl, |
9382d97af crypto: gcm - Use... |
190 |
struct scatterlist *src, |
adcbc688f crypto: gcm - Con... |
191 |
unsigned int len, u32 flags) |
9382d97af crypto: gcm - Use... |
192 |
{ |
adcbc688f crypto: gcm - Con... |
193 |
struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); |
9382d97af crypto: gcm - Use... |
194 |
struct ahash_request *ahreq = &pctx->u.ahreq; |
28db8e3e3 [CRYPTO] gcm: New... |
195 |
|
adcbc688f crypto: gcm - Con... |
196 |
ahash_request_set_callback(ahreq, flags, compl, req); |
9382d97af crypto: gcm - Use... |
197 198 199 |
ahash_request_set_crypt(ahreq, src, NULL, len); return crypto_ahash_update(ahreq); |
28db8e3e3 [CRYPTO] gcm: New... |
200 |
} |
9382d97af crypto: gcm - Use... |
201 |
static int gcm_hash_remain(struct aead_request *req, |
9382d97af crypto: gcm - Use... |
202 |
unsigned int remain, |
adcbc688f crypto: gcm - Con... |
203 |
crypto_completion_t compl, u32 flags) |
28db8e3e3 [CRYPTO] gcm: New... |
204 |
{ |
adcbc688f crypto: gcm - Con... |
205 |
return gcm_hash_update(req, compl, &gcm_zeroes->sg, remain, flags); |
9382d97af crypto: gcm - Use... |
206 |
} |
adcbc688f crypto: gcm - Con... |
207 |
static int gcm_hash_len(struct aead_request *req, u32 flags) |
9382d97af crypto: gcm - Use... |
208 |
{ |
adcbc688f crypto: gcm - Con... |
209 |
struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); |
9382d97af crypto: gcm - Use... |
210 211 |
struct ahash_request *ahreq = &pctx->u.ahreq; struct crypto_gcm_ghash_ctx *gctx = &pctx->ghash_ctx; |
18666550f crypto: gcm - use... |
212 |
be128 lengths; |
9382d97af crypto: gcm - Use... |
213 214 215 216 |
lengths.a = cpu_to_be64(req->assoclen * 8); lengths.b = cpu_to_be64(gctx->cryptlen * 8); memcpy(pctx->iauth_tag, &lengths, 16); |
adcbc688f crypto: gcm - Con... |
217 218 219 220 |
sg_init_one(&pctx->sg, pctx->iauth_tag, 16); ahash_request_set_callback(ahreq, flags, gcm_hash_len_done, req); ahash_request_set_crypt(ahreq, &pctx->sg, pctx->iauth_tag, sizeof(lengths)); |
9382d97af crypto: gcm - Use... |
221 |
|
adcbc688f crypto: gcm - Con... |
222 |
return crypto_ahash_finup(ahreq); |
9382d97af crypto: gcm - Use... |
223 |
} |
adcbc688f crypto: gcm - Con... |
224 |
static int gcm_hash_len_continue(struct aead_request *req, u32 flags) |
9382d97af crypto: gcm - Use... |
225 |
{ |
2589469d7 [CRYPTO] gcm: Fix... |
226 |
struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); |
9382d97af crypto: gcm - Use... |
227 |
struct crypto_gcm_ghash_ctx *gctx = &pctx->ghash_ctx; |
adcbc688f crypto: gcm - Con... |
228 |
return gctx->complete(req, flags); |
9382d97af crypto: gcm - Use... |
229 |
} |
adcbc688f crypto: gcm - Con... |
230 |
static void gcm_hash_len_done(struct crypto_async_request *areq, int err) |
9382d97af crypto: gcm - Use... |
231 232 |
{ struct aead_request *req = areq->data; |
62c5593ae crypto: gcm - fix... |
233 |
|
adcbc688f crypto: gcm - Con... |
234 235 |
if (err) goto out; |
9382d97af crypto: gcm - Use... |
236 |
|
adcbc688f crypto: gcm - Con... |
237 238 239 |
err = gcm_hash_len_continue(req, 0); if (err == -EINPROGRESS) return; |
62c5593ae crypto: gcm - fix... |
240 |
|
adcbc688f crypto: gcm - Con... |
241 242 |
out: aead_request_complete(req, err); |
62c5593ae crypto: gcm - fix... |
243 |
} |
adcbc688f crypto: gcm - Con... |
244 |
static int gcm_hash_crypt_remain_continue(struct aead_request *req, u32 flags) |
62c5593ae crypto: gcm - fix... |
245 |
{ |
adcbc688f crypto: gcm - Con... |
246 247 |
return gcm_hash_len(req, flags) ?: gcm_hash_len_continue(req, flags); |
9382d97af crypto: gcm - Use... |
248 |
} |
62c5593ae crypto: gcm - fix... |
249 250 |
static void gcm_hash_crypt_remain_done(struct crypto_async_request *areq, int err) |
9382d97af crypto: gcm - Use... |
251 252 |
{ struct aead_request *req = areq->data; |
62c5593ae crypto: gcm - fix... |
253 |
|
adcbc688f crypto: gcm - Con... |
254 255 256 257 258 259 260 261 262 |
if (err) goto out; err = gcm_hash_crypt_remain_continue(req, 0); if (err == -EINPROGRESS) return; out: aead_request_complete(req, err); |
62c5593ae crypto: gcm - fix... |
263 |
} |
adcbc688f crypto: gcm - Con... |
264 |
static int gcm_hash_crypt_continue(struct aead_request *req, u32 flags) |
62c5593ae crypto: gcm - fix... |
265 |
{ |
9382d97af crypto: gcm - Use... |
266 267 268 |
struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); struct crypto_gcm_ghash_ctx *gctx = &pctx->ghash_ctx; unsigned int remain; |
adcbc688f crypto: gcm - Con... |
269 270 271 272 273 |
remain = gcm_remain(gctx->cryptlen); if (remain) return gcm_hash_remain(req, remain, gcm_hash_crypt_remain_done, flags) ?: gcm_hash_crypt_remain_continue(req, flags); |
9382d97af crypto: gcm - Use... |
274 |
|
adcbc688f crypto: gcm - Con... |
275 |
return gcm_hash_crypt_remain_continue(req, flags); |
9382d97af crypto: gcm - Use... |
276 |
} |
62c5593ae crypto: gcm - fix... |
277 |
static void gcm_hash_crypt_done(struct crypto_async_request *areq, int err) |
9382d97af crypto: gcm - Use... |
278 279 |
{ struct aead_request *req = areq->data; |
62c5593ae crypto: gcm - fix... |
280 |
|
adcbc688f crypto: gcm - Con... |
281 282 283 284 285 286 287 288 289 |
if (err) goto out; err = gcm_hash_crypt_continue(req, 0); if (err == -EINPROGRESS) return; out: aead_request_complete(req, err); |
62c5593ae crypto: gcm - fix... |
290 |
} |
adcbc688f crypto: gcm - Con... |
291 |
static int gcm_hash_assoc_remain_continue(struct aead_request *req, u32 flags) |
62c5593ae crypto: gcm - fix... |
292 |
{ |
9382d97af crypto: gcm - Use... |
293 294 |
struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); struct crypto_gcm_ghash_ctx *gctx = &pctx->ghash_ctx; |
9382d97af crypto: gcm - Use... |
295 |
|
adcbc688f crypto: gcm - Con... |
296 297 298 299 300 301 |
if (gctx->cryptlen) return gcm_hash_update(req, gcm_hash_crypt_done, gctx->src, gctx->cryptlen, flags) ?: gcm_hash_crypt_continue(req, flags); return gcm_hash_crypt_remain_continue(req, flags); |
9382d97af crypto: gcm - Use... |
302 |
} |
62c5593ae crypto: gcm - fix... |
303 304 |
static void gcm_hash_assoc_remain_done(struct crypto_async_request *areq, int err) |
9382d97af crypto: gcm - Use... |
305 306 |
{ struct aead_request *req = areq->data; |
62c5593ae crypto: gcm - fix... |
307 |
|
adcbc688f crypto: gcm - Con... |
308 309 310 311 312 313 314 315 316 |
if (err) goto out; err = gcm_hash_assoc_remain_continue(req, 0); if (err == -EINPROGRESS) return; out: aead_request_complete(req, err); |
62c5593ae crypto: gcm - fix... |
317 |
} |
adcbc688f crypto: gcm - Con... |
318 |
static int gcm_hash_assoc_continue(struct aead_request *req, u32 flags) |
62c5593ae crypto: gcm - fix... |
319 |
{ |
9382d97af crypto: gcm - Use... |
320 |
unsigned int remain; |
adcbc688f crypto: gcm - Con... |
321 322 323 324 325 |
remain = gcm_remain(req->assoclen); if (remain) return gcm_hash_remain(req, remain, gcm_hash_assoc_remain_done, flags) ?: gcm_hash_assoc_remain_continue(req, flags); |
9382d97af crypto: gcm - Use... |
326 |
|
adcbc688f crypto: gcm - Con... |
327 |
return gcm_hash_assoc_remain_continue(req, flags); |
9382d97af crypto: gcm - Use... |
328 |
} |
62c5593ae crypto: gcm - fix... |
329 |
static void gcm_hash_assoc_done(struct crypto_async_request *areq, int err) |
9382d97af crypto: gcm - Use... |
330 331 |
{ struct aead_request *req = areq->data; |
62c5593ae crypto: gcm - fix... |
332 |
|
adcbc688f crypto: gcm - Con... |
333 334 335 336 337 338 339 340 341 |
if (err) goto out; err = gcm_hash_assoc_continue(req, 0); if (err == -EINPROGRESS) return; out: aead_request_complete(req, err); |
62c5593ae crypto: gcm - fix... |
342 |
} |
adcbc688f crypto: gcm - Con... |
343 |
static int gcm_hash_init_continue(struct aead_request *req, u32 flags) |
62c5593ae crypto: gcm - fix... |
344 |
{ |
adcbc688f crypto: gcm - Con... |
345 346 347 348 |
if (req->assoclen) return gcm_hash_update(req, gcm_hash_assoc_done, req->src, req->assoclen, flags) ?: gcm_hash_assoc_continue(req, flags); |
9382d97af crypto: gcm - Use... |
349 |
|
adcbc688f crypto: gcm - Con... |
350 |
return gcm_hash_assoc_remain_continue(req, flags); |
62c5593ae crypto: gcm - fix... |
351 352 353 354 355 |
} static void gcm_hash_init_done(struct crypto_async_request *areq, int err) { struct aead_request *req = areq->data; |
adcbc688f crypto: gcm - Con... |
356 357 358 359 360 361 362 363 364 |
if (err) goto out; err = gcm_hash_init_continue(req, 0); if (err == -EINPROGRESS) return; out: aead_request_complete(req, err); |
9382d97af crypto: gcm - Use... |
365 |
} |
adcbc688f crypto: gcm - Con... |
366 |
static int gcm_hash(struct aead_request *req, u32 flags) |
9382d97af crypto: gcm - Use... |
367 |
{ |
adcbc688f crypto: gcm - Con... |
368 |
struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); |
9382d97af crypto: gcm - Use... |
369 |
struct ahash_request *ahreq = &pctx->u.ahreq; |
adcbc688f crypto: gcm - Con... |
370 |
struct crypto_gcm_ctx *ctx = crypto_aead_ctx(crypto_aead_reqtfm(req)); |
9382d97af crypto: gcm - Use... |
371 372 |
ahash_request_set_tfm(ahreq, ctx->ghash); |
adcbc688f crypto: gcm - Con... |
373 374 375 |
ahash_request_set_callback(ahreq, flags, gcm_hash_init_done, req); return crypto_ahash_init(ahreq) ?: gcm_hash_init_continue(req, flags); |
9382d97af crypto: gcm - Use... |
376 |
} |
adcbc688f crypto: gcm - Con... |
377 |
static int gcm_enc_copy_hash(struct aead_request *req, u32 flags) |
9382d97af crypto: gcm - Use... |
378 |
{ |
adcbc688f crypto: gcm - Con... |
379 |
struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); |
9382d97af crypto: gcm - Use... |
380 381 |
struct crypto_aead *aead = crypto_aead_reqtfm(req); u8 *auth_tag = pctx->auth_tag; |
28db8e3e3 [CRYPTO] gcm: New... |
382 |
|
adcbc688f crypto: gcm - Con... |
383 384 385 |
crypto_xor(auth_tag, pctx->iauth_tag, 16); scatterwalk_map_and_copy(auth_tag, req->dst, req->assoclen + req->cryptlen, |
6160b2899 [CRYPTO] gcm: Fix... |
386 |
crypto_aead_authsize(aead), 1); |
adcbc688f crypto: gcm - Con... |
387 |
return 0; |
6160b2899 [CRYPTO] gcm: Fix... |
388 |
} |
adcbc688f crypto: gcm - Con... |
389 |
static int gcm_encrypt_continue(struct aead_request *req, u32 flags) |
6160b2899 [CRYPTO] gcm: Fix... |
390 |
{ |
9382d97af crypto: gcm - Use... |
391 |
struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); |
adcbc688f crypto: gcm - Con... |
392 |
struct crypto_gcm_ghash_ctx *gctx = &pctx->ghash_ctx; |
6160b2899 [CRYPTO] gcm: Fix... |
393 |
|
adcbc688f crypto: gcm - Con... |
394 395 396 |
gctx->src = sg_next(req->src == req->dst ? pctx->src : pctx->dst); gctx->cryptlen = req->cryptlen; gctx->complete = gcm_enc_copy_hash; |
6160b2899 [CRYPTO] gcm: Fix... |
397 |
|
adcbc688f crypto: gcm - Con... |
398 |
return gcm_hash(req, flags); |
28db8e3e3 [CRYPTO] gcm: New... |
399 |
} |
62c5593ae crypto: gcm - fix... |
400 |
static void gcm_encrypt_done(struct crypto_async_request *areq, int err) |
9382d97af crypto: gcm - Use... |
401 402 |
{ struct aead_request *req = areq->data; |
9382d97af crypto: gcm - Use... |
403 |
|
adcbc688f crypto: gcm - Con... |
404 405 406 407 408 409 |
if (err) goto out; err = gcm_encrypt_continue(req, 0); if (err == -EINPROGRESS) return; |
9382d97af crypto: gcm - Use... |
410 |
|
adcbc688f crypto: gcm - Con... |
411 |
out: |
62c5593ae crypto: gcm - fix... |
412 |
aead_request_complete(req, err); |
9382d97af crypto: gcm - Use... |
413 |
} |
28db8e3e3 [CRYPTO] gcm: New... |
414 415 |
static int crypto_gcm_encrypt(struct aead_request *req) { |
2589469d7 [CRYPTO] gcm: Fix... |
416 |
struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); |
16f37ecdd crypto: gcm - Use... |
417 |
struct skcipher_request *skreq = &pctx->u.skreq; |
adcbc688f crypto: gcm - Con... |
418 |
u32 flags = aead_request_flags(req); |
9382d97af crypto: gcm - Use... |
419 |
|
adcbc688f crypto: gcm - Con... |
420 421 |
crypto_gcm_init_common(req); crypto_gcm_init_crypt(req, req->cryptlen); |
16f37ecdd crypto: gcm - Use... |
422 |
skcipher_request_set_callback(skreq, flags, gcm_encrypt_done, req); |
9382d97af crypto: gcm - Use... |
423 |
|
16f37ecdd crypto: gcm - Use... |
424 |
return crypto_skcipher_encrypt(skreq) ?: |
adcbc688f crypto: gcm - Con... |
425 |
gcm_encrypt_continue(req, flags); |
28db8e3e3 [CRYPTO] gcm: New... |
426 |
} |
adcbc688f crypto: gcm - Con... |
427 |
static int crypto_gcm_verify(struct aead_request *req) |
84c911523 [CRYPTO] gcm: Add... |
428 |
{ |
adcbc688f crypto: gcm - Con... |
429 |
struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); |
84c911523 [CRYPTO] gcm: Add... |
430 |
struct crypto_aead *aead = crypto_aead_reqtfm(req); |
84c911523 [CRYPTO] gcm: Add... |
431 432 433 434 |
u8 *auth_tag = pctx->auth_tag; u8 *iauth_tag = pctx->iauth_tag; unsigned int authsize = crypto_aead_authsize(aead); unsigned int cryptlen = req->cryptlen - authsize; |
9382d97af crypto: gcm - Use... |
435 |
crypto_xor(auth_tag, iauth_tag, 16); |
adcbc688f crypto: gcm - Con... |
436 437 |
scatterwalk_map_and_copy(iauth_tag, req->src, req->assoclen + cryptlen, authsize, 0); |
6bf37e5aa crypto: crypto_me... |
438 |
return crypto_memneq(iauth_tag, auth_tag, authsize) ? -EBADMSG : 0; |
84c911523 [CRYPTO] gcm: Add... |
439 |
} |
9382d97af crypto: gcm - Use... |
440 |
static void gcm_decrypt_done(struct crypto_async_request *areq, int err) |
28db8e3e3 [CRYPTO] gcm: New... |
441 |
{ |
84c911523 [CRYPTO] gcm: Add... |
442 443 444 |
struct aead_request *req = areq->data; if (!err) |
adcbc688f crypto: gcm - Con... |
445 |
err = crypto_gcm_verify(req); |
84c911523 [CRYPTO] gcm: Add... |
446 447 |
aead_request_complete(req, err); |
28db8e3e3 [CRYPTO] gcm: New... |
448 |
} |
adcbc688f crypto: gcm - Con... |
449 |
static int gcm_dec_hash_continue(struct aead_request *req, u32 flags) |
9382d97af crypto: gcm - Use... |
450 |
{ |
9382d97af crypto: gcm - Use... |
451 |
struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); |
16f37ecdd crypto: gcm - Use... |
452 |
struct skcipher_request *skreq = &pctx->u.skreq; |
9382d97af crypto: gcm - Use... |
453 |
struct crypto_gcm_ghash_ctx *gctx = &pctx->ghash_ctx; |
adcbc688f crypto: gcm - Con... |
454 |
crypto_gcm_init_crypt(req, gctx->cryptlen); |
16f37ecdd crypto: gcm - Use... |
455 456 |
skcipher_request_set_callback(skreq, flags, gcm_decrypt_done, req); return crypto_skcipher_decrypt(skreq) ?: crypto_gcm_verify(req); |
9382d97af crypto: gcm - Use... |
457 |
} |
28db8e3e3 [CRYPTO] gcm: New... |
458 459 |
static int crypto_gcm_decrypt(struct aead_request *req) { |
6160b2899 [CRYPTO] gcm: Fix... |
460 |
struct crypto_aead *aead = crypto_aead_reqtfm(req); |
2589469d7 [CRYPTO] gcm: Fix... |
461 |
struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); |
9382d97af crypto: gcm - Use... |
462 |
struct crypto_gcm_ghash_ctx *gctx = &pctx->ghash_ctx; |
6160b2899 [CRYPTO] gcm: Fix... |
463 |
unsigned int authsize = crypto_aead_authsize(aead); |
9382d97af crypto: gcm - Use... |
464 |
unsigned int cryptlen = req->cryptlen; |
adcbc688f crypto: gcm - Con... |
465 |
u32 flags = aead_request_flags(req); |
28db8e3e3 [CRYPTO] gcm: New... |
466 |
|
6160b2899 [CRYPTO] gcm: Fix... |
467 |
cryptlen -= authsize; |
28db8e3e3 [CRYPTO] gcm: New... |
468 |
|
adcbc688f crypto: gcm - Con... |
469 |
crypto_gcm_init_common(req); |
28db8e3e3 [CRYPTO] gcm: New... |
470 |
|
adcbc688f crypto: gcm - Con... |
471 472 473 |
gctx->src = sg_next(pctx->src); gctx->cryptlen = cryptlen; gctx->complete = gcm_dec_hash_continue; |
28db8e3e3 [CRYPTO] gcm: New... |
474 |
|
adcbc688f crypto: gcm - Con... |
475 |
return gcm_hash(req, flags); |
28db8e3e3 [CRYPTO] gcm: New... |
476 |
} |
adcbc688f crypto: gcm - Con... |
477 |
static int crypto_gcm_init_tfm(struct crypto_aead *tfm) |
28db8e3e3 [CRYPTO] gcm: New... |
478 |
{ |
adcbc688f crypto: gcm - Con... |
479 480 481 |
struct aead_instance *inst = aead_alg_instance(tfm); struct gcm_instance_ctx *ictx = aead_instance_ctx(inst); struct crypto_gcm_ctx *ctx = crypto_aead_ctx(tfm); |
16f37ecdd crypto: gcm - Use... |
482 |
struct crypto_skcipher *ctr; |
9382d97af crypto: gcm - Use... |
483 |
struct crypto_ahash *ghash; |
28db8e3e3 [CRYPTO] gcm: New... |
484 485 |
unsigned long align; int err; |
9382d97af crypto: gcm - Use... |
486 487 488 |
ghash = crypto_spawn_ahash(&ictx->ghash); if (IS_ERR(ghash)) return PTR_ERR(ghash); |
60425a8ba crypto: skcipher ... |
489 |
ctr = crypto_spawn_skcipher(&ictx->ctr); |
28db8e3e3 [CRYPTO] gcm: New... |
490 491 |
err = PTR_ERR(ctr); if (IS_ERR(ctr)) |
9382d97af crypto: gcm - Use... |
492 |
goto err_free_hash; |
28db8e3e3 [CRYPTO] gcm: New... |
493 494 |
ctx->ctr = ctr; |
9382d97af crypto: gcm - Use... |
495 |
ctx->ghash = ghash; |
28db8e3e3 [CRYPTO] gcm: New... |
496 |
|
adcbc688f crypto: gcm - Con... |
497 |
align = crypto_aead_alignmask(tfm); |
28db8e3e3 [CRYPTO] gcm: New... |
498 |
align &= ~(crypto_tfm_ctx_alignment() - 1); |
adcbc688f crypto: gcm - Con... |
499 |
crypto_aead_set_reqsize(tfm, |
5d72336f1 crypto: gcm - Use... |
500 |
align + offsetof(struct crypto_gcm_req_priv_ctx, u) + |
16f37ecdd crypto: gcm - Use... |
501 502 |
max(sizeof(struct skcipher_request) + crypto_skcipher_reqsize(ctr), |
9382d97af crypto: gcm - Use... |
503 |
sizeof(struct ahash_request) + |
5d72336f1 crypto: gcm - Use... |
504 |
crypto_ahash_reqsize(ghash))); |
28db8e3e3 [CRYPTO] gcm: New... |
505 506 |
return 0; |
9382d97af crypto: gcm - Use... |
507 508 509 510 |
err_free_hash: crypto_free_ahash(ghash); return err; |
28db8e3e3 [CRYPTO] gcm: New... |
511 |
} |
adcbc688f crypto: gcm - Con... |
512 |
static void crypto_gcm_exit_tfm(struct crypto_aead *tfm) |
28db8e3e3 [CRYPTO] gcm: New... |
513 |
{ |
adcbc688f crypto: gcm - Con... |
514 |
struct crypto_gcm_ctx *ctx = crypto_aead_ctx(tfm); |
28db8e3e3 [CRYPTO] gcm: New... |
515 |
|
9382d97af crypto: gcm - Use... |
516 |
crypto_free_ahash(ctx->ghash); |
16f37ecdd crypto: gcm - Use... |
517 |
crypto_free_skcipher(ctx->ctr); |
28db8e3e3 [CRYPTO] gcm: New... |
518 |
} |
7b05a373a crypto: gcm - Use... |
519 520 521 522 523 524 525 526 |
static void crypto_gcm_free(struct aead_instance *inst) { struct gcm_instance_ctx *ctx = aead_instance_ctx(inst); crypto_drop_skcipher(&ctx->ctr); crypto_drop_ahash(&ctx->ghash); kfree(inst); } |
adcbc688f crypto: gcm - Con... |
527 528 |
static int crypto_gcm_create_common(struct crypto_template *tmpl, struct rtattr **tb, |
adcbc688f crypto: gcm - Con... |
529 530 |
const char *ctr_name, const char *ghash_name) |
28db8e3e3 [CRYPTO] gcm: New... |
531 |
{ |
b9f76dddb crypto: skcipher ... |
532 |
u32 mask; |
adcbc688f crypto: gcm - Con... |
533 |
struct aead_instance *inst; |
ab6ffd360 crypto: gcm - use... |
534 |
struct gcm_instance_ctx *ctx; |
16f37ecdd crypto: gcm - Use... |
535 |
struct skcipher_alg *ctr; |
adcbc688f crypto: gcm - Con... |
536 |
struct hash_alg_common *ghash; |
28db8e3e3 [CRYPTO] gcm: New... |
537 |
int err; |
28db8e3e3 [CRYPTO] gcm: New... |
538 |
|
7bcb2c99f crypto: algapi - ... |
539 540 541 |
err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_AEAD, &mask); if (err) return err; |
b9f76dddb crypto: skcipher ... |
542 |
|
1472e5eba [CRYPTO] gcm: Use... |
543 544 |
inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL); if (!inst) |
ab6ffd360 crypto: gcm - use... |
545 |
return -ENOMEM; |
adcbc688f crypto: gcm - Con... |
546 |
ctx = aead_instance_ctx(inst); |
ab6ffd360 crypto: gcm - use... |
547 548 549 |
err = crypto_grab_ahash(&ctx->ghash, aead_crypto_instance(inst), ghash_name, 0, mask); |
9382d97af crypto: gcm - Use... |
550 551 |
if (err) goto err_free_inst; |
ab6ffd360 crypto: gcm - use... |
552 |
ghash = crypto_spawn_ahash_alg(&ctx->ghash); |
9382d97af crypto: gcm - Use... |
553 |
|
adcbc688f crypto: gcm - Con... |
554 |
err = -EINVAL; |
f699594d4 crypto: gcm - fix... |
555 556 |
if (strcmp(ghash->base.cra_name, "ghash") != 0 || ghash->digestsize != 16) |
ab6ffd360 crypto: gcm - use... |
557 |
goto err_free_inst; |
adcbc688f crypto: gcm - Con... |
558 |
|
b9f76dddb crypto: skcipher ... |
559 560 |
err = crypto_grab_skcipher(&ctx->ctr, aead_crypto_instance(inst), ctr_name, 0, mask); |
1472e5eba [CRYPTO] gcm: Use... |
561 |
if (err) |
ab6ffd360 crypto: gcm - use... |
562 |
goto err_free_inst; |
16f37ecdd crypto: gcm - Use... |
563 |
ctr = crypto_spawn_skcipher_alg(&ctx->ctr); |
28db8e3e3 [CRYPTO] gcm: New... |
564 |
|
f699594d4 crypto: gcm - fix... |
565 |
/* The skcipher algorithm must be CTR mode, using 16-byte blocks. */ |
9b40f79c0 crypto: gcm - Fix... |
566 |
err = -EINVAL; |
f699594d4 crypto: gcm - fix... |
567 568 569 |
if (strncmp(ctr->base.cra_name, "ctr(", 4) != 0 || crypto_skcipher_alg_ivsize(ctr) != 16 || ctr->base.cra_blocksize != 1) |
ab6ffd360 crypto: gcm - use... |
570 |
goto err_free_inst; |
d00aa19b5 [CRYPTO] gcm: All... |
571 |
|
f699594d4 crypto: gcm - fix... |
572 573 574 |
err = -ENAMETOOLONG; if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME, "gcm(%s", ctr->base.cra_name + 4) >= CRYPTO_MAX_ALG_NAME) |
ab6ffd360 crypto: gcm - use... |
575 |
goto err_free_inst; |
28db8e3e3 [CRYPTO] gcm: New... |
576 |
|
adcbc688f crypto: gcm - Con... |
577 |
if (snprintf(inst->alg.base.cra_driver_name, CRYPTO_MAX_ALG_NAME, |
16f37ecdd crypto: gcm - Use... |
578 |
"gcm_base(%s,%s)", ctr->base.cra_driver_name, |
ab6ffd360 crypto: gcm - use... |
579 |
ghash->base.cra_driver_name) >= |
d00aa19b5 [CRYPTO] gcm: All... |
580 |
CRYPTO_MAX_ALG_NAME) |
ab6ffd360 crypto: gcm - use... |
581 |
goto err_free_inst; |
28db8e3e3 [CRYPTO] gcm: New... |
582 |
|
adcbc688f crypto: gcm - Con... |
583 |
inst->alg.base.cra_priority = (ghash->base.cra_priority + |
16f37ecdd crypto: gcm - Use... |
584 |
ctr->base.cra_priority) / 2; |
adcbc688f crypto: gcm - Con... |
585 586 |
inst->alg.base.cra_blocksize = 1; inst->alg.base.cra_alignmask = ghash->base.cra_alignmask | |
16f37ecdd crypto: gcm - Use... |
587 |
ctr->base.cra_alignmask; |
adcbc688f crypto: gcm - Con... |
588 |
inst->alg.base.cra_ctxsize = sizeof(struct crypto_gcm_ctx); |
e0ab7e9c6 crypto: gcm - Use... |
589 |
inst->alg.ivsize = GCM_AES_IV_SIZE; |
16f37ecdd crypto: gcm - Use... |
590 |
inst->alg.chunksize = crypto_skcipher_alg_chunksize(ctr); |
adcbc688f crypto: gcm - Con... |
591 592 593 594 595 596 597 |
inst->alg.maxauthsize = 16; inst->alg.init = crypto_gcm_init_tfm; inst->alg.exit = crypto_gcm_exit_tfm; inst->alg.setkey = crypto_gcm_setkey; inst->alg.setauthsize = crypto_gcm_setauthsize; inst->alg.encrypt = crypto_gcm_encrypt; inst->alg.decrypt = crypto_gcm_decrypt; |
7b05a373a crypto: gcm - Use... |
598 |
inst->free = crypto_gcm_free; |
adcbc688f crypto: gcm - Con... |
599 |
err = aead_register_instance(tmpl, inst); |
ab6ffd360 crypto: gcm - use... |
600 |
if (err) { |
28db8e3e3 [CRYPTO] gcm: New... |
601 |
err_free_inst: |
ab6ffd360 crypto: gcm - use... |
602 603 604 |
crypto_gcm_free(inst); } return err; |
28db8e3e3 [CRYPTO] gcm: New... |
605 |
} |
adcbc688f crypto: gcm - Con... |
606 |
static int crypto_gcm_create(struct crypto_template *tmpl, struct rtattr **tb) |
d00aa19b5 [CRYPTO] gcm: All... |
607 |
{ |
d00aa19b5 [CRYPTO] gcm: All... |
608 609 |
const char *cipher_name; char ctr_name[CRYPTO_MAX_ALG_NAME]; |
d00aa19b5 [CRYPTO] gcm: All... |
610 611 |
cipher_name = crypto_attr_alg_name(tb[1]); |
d00aa19b5 [CRYPTO] gcm: All... |
612 |
if (IS_ERR(cipher_name)) |
adcbc688f crypto: gcm - Con... |
613 |
return PTR_ERR(cipher_name); |
d00aa19b5 [CRYPTO] gcm: All... |
614 615 616 |
if (snprintf(ctr_name, CRYPTO_MAX_ALG_NAME, "ctr(%s)", cipher_name) >= CRYPTO_MAX_ALG_NAME) |
adcbc688f crypto: gcm - Con... |
617 |
return -ENAMETOOLONG; |
d00aa19b5 [CRYPTO] gcm: All... |
618 |
|
f699594d4 crypto: gcm - fix... |
619 |
return crypto_gcm_create_common(tmpl, tb, ctr_name, "ghash"); |
d00aa19b5 [CRYPTO] gcm: All... |
620 |
} |
adcbc688f crypto: gcm - Con... |
621 622 |
static int crypto_gcm_base_create(struct crypto_template *tmpl, struct rtattr **tb) |
d00aa19b5 [CRYPTO] gcm: All... |
623 |
{ |
d00aa19b5 [CRYPTO] gcm: All... |
624 |
const char *ctr_name; |
9382d97af crypto: gcm - Use... |
625 |
const char *ghash_name; |
d00aa19b5 [CRYPTO] gcm: All... |
626 627 |
ctr_name = crypto_attr_alg_name(tb[1]); |
d00aa19b5 [CRYPTO] gcm: All... |
628 |
if (IS_ERR(ctr_name)) |
adcbc688f crypto: gcm - Con... |
629 |
return PTR_ERR(ctr_name); |
d00aa19b5 [CRYPTO] gcm: All... |
630 |
|
9382d97af crypto: gcm - Use... |
631 |
ghash_name = crypto_attr_alg_name(tb[2]); |
9382d97af crypto: gcm - Use... |
632 |
if (IS_ERR(ghash_name)) |
adcbc688f crypto: gcm - Con... |
633 |
return PTR_ERR(ghash_name); |
9382d97af crypto: gcm - Use... |
634 |
|
f699594d4 crypto: gcm - fix... |
635 |
return crypto_gcm_create_common(tmpl, tb, ctr_name, ghash_name); |
d00aa19b5 [CRYPTO] gcm: All... |
636 |
} |
dadbc53d0 [CRYPTO] gcm: Int... |
637 638 639 640 641 |
static int crypto_rfc4106_setkey(struct crypto_aead *parent, const u8 *key, unsigned int keylen) { struct crypto_rfc4106_ctx *ctx = crypto_aead_ctx(parent); struct crypto_aead *child = ctx->child; |
dadbc53d0 [CRYPTO] gcm: Int... |
642 643 644 645 646 647 648 649 650 651 |
if (keylen < 4) return -EINVAL; keylen -= 4; memcpy(ctx->nonce, key + keylen, 4); crypto_aead_clear_flags(child, CRYPTO_TFM_REQ_MASK); crypto_aead_set_flags(child, crypto_aead_get_flags(parent) & CRYPTO_TFM_REQ_MASK); |
af5034e8e crypto: remove pr... |
652 |
return crypto_aead_setkey(child, key, keylen); |
dadbc53d0 [CRYPTO] gcm: Int... |
653 654 655 656 657 658 |
} static int crypto_rfc4106_setauthsize(struct crypto_aead *parent, unsigned int authsize) { struct crypto_rfc4106_ctx *ctx = crypto_aead_ctx(parent); |
65526f638 crypto: gcm - hel... |
659 |
int err; |
dadbc53d0 [CRYPTO] gcm: Int... |
660 |
|
65526f638 crypto: gcm - hel... |
661 662 663 |
err = crypto_rfc4106_check_authsize(authsize); if (err) return err; |
dadbc53d0 [CRYPTO] gcm: Int... |
664 665 666 667 668 669 |
return crypto_aead_setauthsize(ctx->child, authsize); } static struct aead_request *crypto_rfc4106_crypt(struct aead_request *req) { |
7b05a373a crypto: gcm - Use... |
670 |
struct crypto_rfc4106_req_ctx *rctx = aead_request_ctx(req); |
dadbc53d0 [CRYPTO] gcm: Int... |
671 672 |
struct crypto_aead *aead = crypto_aead_reqtfm(req); struct crypto_rfc4106_ctx *ctx = crypto_aead_ctx(aead); |
7b05a373a crypto: gcm - Use... |
673 |
struct aead_request *subreq = &rctx->subreq; |
dadbc53d0 [CRYPTO] gcm: Int... |
674 |
struct crypto_aead *child = ctx->child; |
7b05a373a crypto: gcm - Use... |
675 |
struct scatterlist *sg; |
dadbc53d0 [CRYPTO] gcm: Int... |
676 677 |
u8 *iv = PTR_ALIGN((u8 *)(subreq + 1) + crypto_aead_reqsize(child), crypto_aead_alignmask(child) + 1); |
e0ab7e9c6 crypto: gcm - Use... |
678 |
scatterwalk_map_and_copy(iv + GCM_AES_IV_SIZE, req->src, 0, req->assoclen - 8, 0); |
7b05a373a crypto: gcm - Use... |
679 |
|
dadbc53d0 [CRYPTO] gcm: Int... |
680 681 |
memcpy(iv, ctx->nonce, 4); memcpy(iv + 4, req->iv, 8); |
7b05a373a crypto: gcm - Use... |
682 |
sg_init_table(rctx->src, 3); |
e0ab7e9c6 crypto: gcm - Use... |
683 |
sg_set_buf(rctx->src, iv + GCM_AES_IV_SIZE, req->assoclen - 8); |
7b05a373a crypto: gcm - Use... |
684 685 686 687 688 689 |
sg = scatterwalk_ffwd(rctx->src + 1, req->src, req->assoclen); if (sg != rctx->src + 1) sg_chain(rctx->src, 2, sg); if (req->src != req->dst) { sg_init_table(rctx->dst, 3); |
e0ab7e9c6 crypto: gcm - Use... |
690 |
sg_set_buf(rctx->dst, iv + GCM_AES_IV_SIZE, req->assoclen - 8); |
7b05a373a crypto: gcm - Use... |
691 692 693 694 |
sg = scatterwalk_ffwd(rctx->dst + 1, req->dst, req->assoclen); if (sg != rctx->dst + 1) sg_chain(rctx->dst, 2, sg); } |
dadbc53d0 [CRYPTO] gcm: Int... |
695 696 697 |
aead_request_set_tfm(subreq, child); aead_request_set_callback(subreq, req->base.flags, req->base.complete, req->base.data); |
7b05a373a crypto: gcm - Use... |
698 699 700 701 |
aead_request_set_crypt(subreq, rctx->src, req->src == req->dst ? rctx->src : rctx->dst, req->cryptlen, iv); aead_request_set_ad(subreq, req->assoclen - 8); |
dadbc53d0 [CRYPTO] gcm: Int... |
702 703 704 705 706 707 |
return subreq; } static int crypto_rfc4106_encrypt(struct aead_request *req) { |
65526f638 crypto: gcm - hel... |
708 709 710 711 712 |
int err; err = crypto_ipsec_check_assoclen(req->assoclen); if (err) return err; |
7b05a373a crypto: gcm - Use... |
713 |
|
dadbc53d0 [CRYPTO] gcm: Int... |
714 715 716 717 718 719 720 |
req = crypto_rfc4106_crypt(req); return crypto_aead_encrypt(req); } static int crypto_rfc4106_decrypt(struct aead_request *req) { |
65526f638 crypto: gcm - hel... |
721 722 723 724 725 |
int err; err = crypto_ipsec_check_assoclen(req->assoclen); if (err) return err; |
7b05a373a crypto: gcm - Use... |
726 |
|
dadbc53d0 [CRYPTO] gcm: Int... |
727 728 729 730 |
req = crypto_rfc4106_crypt(req); return crypto_aead_decrypt(req); } |
adcbc688f crypto: gcm - Con... |
731 |
static int crypto_rfc4106_init_tfm(struct crypto_aead *tfm) |
dadbc53d0 [CRYPTO] gcm: Int... |
732 |
{ |
adcbc688f crypto: gcm - Con... |
733 734 735 |
struct aead_instance *inst = aead_alg_instance(tfm); struct crypto_aead_spawn *spawn = aead_instance_ctx(inst); struct crypto_rfc4106_ctx *ctx = crypto_aead_ctx(tfm); |
dadbc53d0 [CRYPTO] gcm: Int... |
736 737 738 739 740 741 742 743 744 745 746 |
struct crypto_aead *aead; unsigned long align; aead = crypto_spawn_aead(spawn); if (IS_ERR(aead)) return PTR_ERR(aead); ctx->child = aead; align = crypto_aead_alignmask(aead); align &= ~(crypto_tfm_ctx_alignment() - 1); |
adcbc688f crypto: gcm - Con... |
747 748 |
crypto_aead_set_reqsize( tfm, |
7b05a373a crypto: gcm - Use... |
749 |
sizeof(struct crypto_rfc4106_req_ctx) + |
5d72336f1 crypto: gcm - Use... |
750 |
ALIGN(crypto_aead_reqsize(aead), crypto_tfm_ctx_alignment()) + |
7b05a373a crypto: gcm - Use... |
751 |
align + 24); |
dadbc53d0 [CRYPTO] gcm: Int... |
752 753 754 |
return 0; } |
adcbc688f crypto: gcm - Con... |
755 |
static void crypto_rfc4106_exit_tfm(struct crypto_aead *tfm) |
dadbc53d0 [CRYPTO] gcm: Int... |
756 |
{ |
adcbc688f crypto: gcm - Con... |
757 |
struct crypto_rfc4106_ctx *ctx = crypto_aead_ctx(tfm); |
dadbc53d0 [CRYPTO] gcm: Int... |
758 759 760 |
crypto_free_aead(ctx->child); } |
7b05a373a crypto: gcm - Use... |
761 762 763 764 765 |
static void crypto_rfc4106_free(struct aead_instance *inst) { crypto_drop_aead(aead_instance_ctx(inst)); kfree(inst); } |
adcbc688f crypto: gcm - Con... |
766 767 |
static int crypto_rfc4106_create(struct crypto_template *tmpl, struct rtattr **tb) |
dadbc53d0 [CRYPTO] gcm: Int... |
768 |
{ |
cd900f0ca crypto: aead - pa... |
769 |
u32 mask; |
adcbc688f crypto: gcm - Con... |
770 |
struct aead_instance *inst; |
dadbc53d0 [CRYPTO] gcm: Int... |
771 |
struct crypto_aead_spawn *spawn; |
adcbc688f crypto: gcm - Con... |
772 |
struct aead_alg *alg; |
dadbc53d0 [CRYPTO] gcm: Int... |
773 |
int err; |
7bcb2c99f crypto: algapi - ... |
774 775 776 |
err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_AEAD, &mask); if (err) return err; |
cd900f0ca crypto: aead - pa... |
777 |
|
dadbc53d0 [CRYPTO] gcm: Int... |
778 779 |
inst = kzalloc(sizeof(*inst) + sizeof(*spawn), GFP_KERNEL); if (!inst) |
adcbc688f crypto: gcm - Con... |
780 |
return -ENOMEM; |
dadbc53d0 [CRYPTO] gcm: Int... |
781 |
|
adcbc688f crypto: gcm - Con... |
782 |
spawn = aead_instance_ctx(inst); |
cd900f0ca crypto: aead - pa... |
783 |
err = crypto_grab_aead(spawn, aead_crypto_instance(inst), |
959ac1cdd crypto: gcm - sim... |
784 |
crypto_attr_alg_name(tb[1]), 0, mask); |
dadbc53d0 [CRYPTO] gcm: Int... |
785 |
if (err) |
959ac1cdd crypto: gcm - sim... |
786 |
goto err_free_inst; |
dadbc53d0 [CRYPTO] gcm: Int... |
787 |
|
adcbc688f crypto: gcm - Con... |
788 |
alg = crypto_spawn_aead_alg(spawn); |
dadbc53d0 [CRYPTO] gcm: Int... |
789 790 |
err = -EINVAL; |
adcbc688f crypto: gcm - Con... |
791 |
/* Underlying IV size must be 12. */ |
e0ab7e9c6 crypto: gcm - Use... |
792 |
if (crypto_aead_alg_ivsize(alg) != GCM_AES_IV_SIZE) |
959ac1cdd crypto: gcm - sim... |
793 |
goto err_free_inst; |
dadbc53d0 [CRYPTO] gcm: Int... |
794 795 |
/* Not a stream cipher? */ |
adcbc688f crypto: gcm - Con... |
796 |
if (alg->base.cra_blocksize != 1) |
959ac1cdd crypto: gcm - sim... |
797 |
goto err_free_inst; |
dadbc53d0 [CRYPTO] gcm: Int... |
798 799 |
err = -ENAMETOOLONG; |
adcbc688f crypto: gcm - Con... |
800 801 802 803 804 |
if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME, "rfc4106(%s)", alg->base.cra_name) >= CRYPTO_MAX_ALG_NAME || snprintf(inst->alg.base.cra_driver_name, CRYPTO_MAX_ALG_NAME, "rfc4106(%s)", alg->base.cra_driver_name) >= |
dadbc53d0 [CRYPTO] gcm: Int... |
805 |
CRYPTO_MAX_ALG_NAME) |
959ac1cdd crypto: gcm - sim... |
806 |
goto err_free_inst; |
dadbc53d0 [CRYPTO] gcm: Int... |
807 |
|
adcbc688f crypto: gcm - Con... |
808 809 810 |
inst->alg.base.cra_priority = alg->base.cra_priority; inst->alg.base.cra_blocksize = 1; inst->alg.base.cra_alignmask = alg->base.cra_alignmask; |
dadbc53d0 [CRYPTO] gcm: Int... |
811 |
|
adcbc688f crypto: gcm - Con... |
812 |
inst->alg.base.cra_ctxsize = sizeof(struct crypto_rfc4106_ctx); |
dadbc53d0 [CRYPTO] gcm: Int... |
813 |
|
e0ab7e9c6 crypto: gcm - Use... |
814 |
inst->alg.ivsize = GCM_RFC4106_IV_SIZE; |
16f37ecdd crypto: gcm - Use... |
815 |
inst->alg.chunksize = crypto_aead_alg_chunksize(alg); |
adcbc688f crypto: gcm - Con... |
816 |
inst->alg.maxauthsize = crypto_aead_alg_maxauthsize(alg); |
dadbc53d0 [CRYPTO] gcm: Int... |
817 |
|
adcbc688f crypto: gcm - Con... |
818 819 |
inst->alg.init = crypto_rfc4106_init_tfm; inst->alg.exit = crypto_rfc4106_exit_tfm; |
dadbc53d0 [CRYPTO] gcm: Int... |
820 |
|
adcbc688f crypto: gcm - Con... |
821 822 823 824 |
inst->alg.setkey = crypto_rfc4106_setkey; inst->alg.setauthsize = crypto_rfc4106_setauthsize; inst->alg.encrypt = crypto_rfc4106_encrypt; inst->alg.decrypt = crypto_rfc4106_decrypt; |
dadbc53d0 [CRYPTO] gcm: Int... |
825 |
|
7b05a373a crypto: gcm - Use... |
826 |
inst->free = crypto_rfc4106_free; |
adcbc688f crypto: gcm - Con... |
827 |
err = aead_register_instance(tmpl, inst); |
959ac1cdd crypto: gcm - sim... |
828 829 830 831 |
if (err) { err_free_inst: crypto_rfc4106_free(inst); } |
adcbc688f crypto: gcm - Con... |
832 |
return err; |
dadbc53d0 [CRYPTO] gcm: Int... |
833 |
} |
73c89c15b crypto: gcm - Add... |
834 835 836 837 838 |
static int crypto_rfc4543_setkey(struct crypto_aead *parent, const u8 *key, unsigned int keylen) { struct crypto_rfc4543_ctx *ctx = crypto_aead_ctx(parent); struct crypto_aead *child = ctx->child; |
73c89c15b crypto: gcm - Add... |
839 840 841 842 843 844 845 846 847 848 |
if (keylen < 4) return -EINVAL; keylen -= 4; memcpy(ctx->nonce, key + keylen, 4); crypto_aead_clear_flags(child, CRYPTO_TFM_REQ_MASK); crypto_aead_set_flags(child, crypto_aead_get_flags(parent) & CRYPTO_TFM_REQ_MASK); |
af5034e8e crypto: remove pr... |
849 |
return crypto_aead_setkey(child, key, keylen); |
73c89c15b crypto: gcm - Add... |
850 851 852 853 854 855 856 857 858 859 860 861 |
} static int crypto_rfc4543_setauthsize(struct crypto_aead *parent, unsigned int authsize) { struct crypto_rfc4543_ctx *ctx = crypto_aead_ctx(parent); if (authsize != 16) return -EINVAL; return crypto_aead_setauthsize(ctx->child, authsize); } |
adcbc688f crypto: gcm - Con... |
862 |
static int crypto_rfc4543_crypt(struct aead_request *req, bool enc) |
73c89c15b crypto: gcm - Add... |
863 864 865 |
{ struct crypto_aead *aead = crypto_aead_reqtfm(req); struct crypto_rfc4543_ctx *ctx = crypto_aead_ctx(aead); |
adcbc688f crypto: gcm - Con... |
866 |
struct crypto_rfc4543_req_ctx *rctx = aead_request_ctx(req); |
73c89c15b crypto: gcm - Add... |
867 |
struct aead_request *subreq = &rctx->subreq; |
73c89c15b crypto: gcm - Add... |
868 |
unsigned int authsize = crypto_aead_authsize(aead); |
73c89c15b crypto: gcm - Add... |
869 870 |
u8 *iv = PTR_ALIGN((u8 *)(rctx + 1) + crypto_aead_reqsize(ctx->child), crypto_aead_alignmask(ctx->child) + 1); |
adcbc688f crypto: gcm - Con... |
871 872 873 874 875 876 877 |
int err; if (req->src != req->dst) { err = crypto_rfc4543_copy_src_to_dst(req, enc); if (err) return err; } |
73c89c15b crypto: gcm - Add... |
878 879 880 |
memcpy(iv, ctx->nonce, 4); memcpy(iv + 4, req->iv, 8); |
73c89c15b crypto: gcm - Add... |
881 |
aead_request_set_tfm(subreq, ctx->child); |
adcbc688f crypto: gcm - Con... |
882 883 884 885 886 887 888 889 |
aead_request_set_callback(subreq, req->base.flags, req->base.complete, req->base.data); aead_request_set_crypt(subreq, req->src, req->dst, enc ? 0 : authsize, iv); aead_request_set_ad(subreq, req->assoclen + req->cryptlen - subreq->cryptlen); return enc ? crypto_aead_encrypt(subreq) : crypto_aead_decrypt(subreq); |
73c89c15b crypto: gcm - Add... |
890 |
} |
9489667d3 crypto: gcm - mak... |
891 892 893 894 895 |
static int crypto_rfc4543_copy_src_to_dst(struct aead_request *req, bool enc) { struct crypto_aead *aead = crypto_aead_reqtfm(req); struct crypto_rfc4543_ctx *ctx = crypto_aead_ctx(aead); unsigned int authsize = crypto_aead_authsize(aead); |
adcbc688f crypto: gcm - Con... |
896 897 |
unsigned int nbytes = req->assoclen + req->cryptlen - (enc ? 0 : authsize); |
8d6053984 crypto: null - Re... |
898 |
SYNC_SKCIPHER_REQUEST_ON_STACK(nreq, ctx->null); |
16f37ecdd crypto: gcm - Use... |
899 |
|
8d6053984 crypto: null - Re... |
900 |
skcipher_request_set_sync_tfm(nreq, ctx->null); |
16f37ecdd crypto: gcm - Use... |
901 902 |
skcipher_request_set_callback(nreq, req->base.flags, NULL, NULL); skcipher_request_set_crypt(nreq, req->src, req->dst, nbytes, NULL); |
9489667d3 crypto: gcm - mak... |
903 |
|
16f37ecdd crypto: gcm - Use... |
904 |
return crypto_skcipher_encrypt(nreq); |
9489667d3 crypto: gcm - mak... |
905 |
} |
73c89c15b crypto: gcm - Add... |
906 907 |
static int crypto_rfc4543_encrypt(struct aead_request *req) { |
74bf81d09 crypto: gcm - res... |
908 909 |
return crypto_ipsec_check_assoclen(req->assoclen) ?: crypto_rfc4543_crypt(req, true); |
73c89c15b crypto: gcm - Add... |
910 911 912 913 |
} static int crypto_rfc4543_decrypt(struct aead_request *req) { |
74bf81d09 crypto: gcm - res... |
914 915 |
return crypto_ipsec_check_assoclen(req->assoclen) ?: crypto_rfc4543_crypt(req, false); |
73c89c15b crypto: gcm - Add... |
916 |
} |
adcbc688f crypto: gcm - Con... |
917 |
static int crypto_rfc4543_init_tfm(struct crypto_aead *tfm) |
73c89c15b crypto: gcm - Add... |
918 |
{ |
adcbc688f crypto: gcm - Con... |
919 920 |
struct aead_instance *inst = aead_alg_instance(tfm); struct crypto_rfc4543_instance_ctx *ictx = aead_instance_ctx(inst); |
9489667d3 crypto: gcm - mak... |
921 |
struct crypto_aead_spawn *spawn = &ictx->aead; |
adcbc688f crypto: gcm - Con... |
922 |
struct crypto_rfc4543_ctx *ctx = crypto_aead_ctx(tfm); |
73c89c15b crypto: gcm - Add... |
923 |
struct crypto_aead *aead; |
8d6053984 crypto: null - Re... |
924 |
struct crypto_sync_skcipher *null; |
73c89c15b crypto: gcm - Add... |
925 |
unsigned long align; |
9489667d3 crypto: gcm - mak... |
926 |
int err = 0; |
73c89c15b crypto: gcm - Add... |
927 928 929 930 |
aead = crypto_spawn_aead(spawn); if (IS_ERR(aead)) return PTR_ERR(aead); |
3a2d4fb51 crypto: null - Ge... |
931 |
null = crypto_get_default_null_skcipher(); |
9489667d3 crypto: gcm - mak... |
932 933 934 |
err = PTR_ERR(null); if (IS_ERR(null)) goto err_free_aead; |
73c89c15b crypto: gcm - Add... |
935 |
ctx->child = aead; |
9489667d3 crypto: gcm - mak... |
936 |
ctx->null = null; |
73c89c15b crypto: gcm - Add... |
937 938 939 |
align = crypto_aead_alignmask(aead); align &= ~(crypto_tfm_ctx_alignment() - 1); |
adcbc688f crypto: gcm - Con... |
940 941 |
crypto_aead_set_reqsize( tfm, |
5d72336f1 crypto: gcm - Use... |
942 943 |
sizeof(struct crypto_rfc4543_req_ctx) + ALIGN(crypto_aead_reqsize(aead), crypto_tfm_ctx_alignment()) + |
e0ab7e9c6 crypto: gcm - Use... |
944 |
align + GCM_AES_IV_SIZE); |
73c89c15b crypto: gcm - Add... |
945 946 |
return 0; |
9489667d3 crypto: gcm - mak... |
947 948 949 950 |
err_free_aead: crypto_free_aead(aead); return err; |
73c89c15b crypto: gcm - Add... |
951 |
} |
adcbc688f crypto: gcm - Con... |
952 |
static void crypto_rfc4543_exit_tfm(struct crypto_aead *tfm) |
73c89c15b crypto: gcm - Add... |
953 |
{ |
adcbc688f crypto: gcm - Con... |
954 |
struct crypto_rfc4543_ctx *ctx = crypto_aead_ctx(tfm); |
73c89c15b crypto: gcm - Add... |
955 956 |
crypto_free_aead(ctx->child); |
3a2d4fb51 crypto: null - Ge... |
957 |
crypto_put_default_null_skcipher(); |
73c89c15b crypto: gcm - Add... |
958 |
} |
7b05a373a crypto: gcm - Use... |
959 960 961 962 963 964 965 966 |
static void crypto_rfc4543_free(struct aead_instance *inst) { struct crypto_rfc4543_instance_ctx *ctx = aead_instance_ctx(inst); crypto_drop_aead(&ctx->aead); kfree(inst); } |
adcbc688f crypto: gcm - Con... |
967 968 |
static int crypto_rfc4543_create(struct crypto_template *tmpl, struct rtattr **tb) |
73c89c15b crypto: gcm - Add... |
969 |
{ |
cd900f0ca crypto: aead - pa... |
970 |
u32 mask; |
adcbc688f crypto: gcm - Con... |
971 |
struct aead_instance *inst; |
adcbc688f crypto: gcm - Con... |
972 |
struct aead_alg *alg; |
9489667d3 crypto: gcm - mak... |
973 |
struct crypto_rfc4543_instance_ctx *ctx; |
73c89c15b crypto: gcm - Add... |
974 |
int err; |
7bcb2c99f crypto: algapi - ... |
975 976 977 |
err = crypto_check_attr_type(tb, CRYPTO_ALG_TYPE_AEAD, &mask); if (err) return err; |
cd900f0ca crypto: aead - pa... |
978 |
|
9489667d3 crypto: gcm - mak... |
979 |
inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL); |
73c89c15b crypto: gcm - Add... |
980 |
if (!inst) |
adcbc688f crypto: gcm - Con... |
981 |
return -ENOMEM; |
73c89c15b crypto: gcm - Add... |
982 |
|
adcbc688f crypto: gcm - Con... |
983 |
ctx = aead_instance_ctx(inst); |
c4caa56d8 crypto: gcm - sim... |
984 985 |
err = crypto_grab_aead(&ctx->aead, aead_crypto_instance(inst), crypto_attr_alg_name(tb[1]), 0, mask); |
73c89c15b crypto: gcm - Add... |
986 |
if (err) |
c4caa56d8 crypto: gcm - sim... |
987 |
goto err_free_inst; |
73c89c15b crypto: gcm - Add... |
988 |
|
c4caa56d8 crypto: gcm - sim... |
989 |
alg = crypto_spawn_aead_alg(&ctx->aead); |
73c89c15b crypto: gcm - Add... |
990 991 |
err = -EINVAL; |
adcbc688f crypto: gcm - Con... |
992 |
/* Underlying IV size must be 12. */ |
e0ab7e9c6 crypto: gcm - Use... |
993 |
if (crypto_aead_alg_ivsize(alg) != GCM_AES_IV_SIZE) |
c4caa56d8 crypto: gcm - sim... |
994 |
goto err_free_inst; |
73c89c15b crypto: gcm - Add... |
995 996 |
/* Not a stream cipher? */ |
adcbc688f crypto: gcm - Con... |
997 |
if (alg->base.cra_blocksize != 1) |
c4caa56d8 crypto: gcm - sim... |
998 |
goto err_free_inst; |
73c89c15b crypto: gcm - Add... |
999 1000 |
err = -ENAMETOOLONG; |
adcbc688f crypto: gcm - Con... |
1001 1002 1003 1004 1005 |
if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME, "rfc4543(%s)", alg->base.cra_name) >= CRYPTO_MAX_ALG_NAME || snprintf(inst->alg.base.cra_driver_name, CRYPTO_MAX_ALG_NAME, "rfc4543(%s)", alg->base.cra_driver_name) >= |
73c89c15b crypto: gcm - Add... |
1006 |
CRYPTO_MAX_ALG_NAME) |
c4caa56d8 crypto: gcm - sim... |
1007 |
goto err_free_inst; |
73c89c15b crypto: gcm - Add... |
1008 |
|
adcbc688f crypto: gcm - Con... |
1009 1010 1011 |
inst->alg.base.cra_priority = alg->base.cra_priority; inst->alg.base.cra_blocksize = 1; inst->alg.base.cra_alignmask = alg->base.cra_alignmask; |
73c89c15b crypto: gcm - Add... |
1012 |
|
adcbc688f crypto: gcm - Con... |
1013 |
inst->alg.base.cra_ctxsize = sizeof(struct crypto_rfc4543_ctx); |
73c89c15b crypto: gcm - Add... |
1014 |
|
e0ab7e9c6 crypto: gcm - Use... |
1015 |
inst->alg.ivsize = GCM_RFC4543_IV_SIZE; |
16f37ecdd crypto: gcm - Use... |
1016 |
inst->alg.chunksize = crypto_aead_alg_chunksize(alg); |
adcbc688f crypto: gcm - Con... |
1017 |
inst->alg.maxauthsize = crypto_aead_alg_maxauthsize(alg); |
73c89c15b crypto: gcm - Add... |
1018 |
|
adcbc688f crypto: gcm - Con... |
1019 1020 |
inst->alg.init = crypto_rfc4543_init_tfm; inst->alg.exit = crypto_rfc4543_exit_tfm; |
73c89c15b crypto: gcm - Add... |
1021 |
|
adcbc688f crypto: gcm - Con... |
1022 1023 1024 1025 |
inst->alg.setkey = crypto_rfc4543_setkey; inst->alg.setauthsize = crypto_rfc4543_setauthsize; inst->alg.encrypt = crypto_rfc4543_encrypt; inst->alg.decrypt = crypto_rfc4543_decrypt; |
73c89c15b crypto: gcm - Add... |
1026 |
|
c4caa56d8 crypto: gcm - sim... |
1027 |
inst->free = crypto_rfc4543_free; |
7b05a373a crypto: gcm - Use... |
1028 |
|
adcbc688f crypto: gcm - Con... |
1029 |
err = aead_register_instance(tmpl, inst); |
c4caa56d8 crypto: gcm - sim... |
1030 1031 1032 1033 |
if (err) { err_free_inst: crypto_rfc4543_free(inst); } |
adcbc688f crypto: gcm - Con... |
1034 |
return err; |
73c89c15b crypto: gcm - Add... |
1035 |
} |
56a00d9da crypto: gcm - use... |
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 |
static struct crypto_template crypto_gcm_tmpls[] = { { .name = "gcm_base", .create = crypto_gcm_base_create, .module = THIS_MODULE, }, { .name = "gcm", .create = crypto_gcm_create, .module = THIS_MODULE, }, { .name = "rfc4106", .create = crypto_rfc4106_create, .module = THIS_MODULE, }, { .name = "rfc4543", .create = crypto_rfc4543_create, .module = THIS_MODULE, }, |
73c89c15b crypto: gcm - Add... |
1054 |
}; |
28db8e3e3 [CRYPTO] gcm: New... |
1055 1056 |
static int __init crypto_gcm_module_init(void) { |
d00aa19b5 [CRYPTO] gcm: All... |
1057 |
int err; |
adcbc688f crypto: gcm - Con... |
1058 |
gcm_zeroes = kzalloc(sizeof(*gcm_zeroes), GFP_KERNEL); |
9382d97af crypto: gcm - Use... |
1059 1060 |
if (!gcm_zeroes) return -ENOMEM; |
adcbc688f crypto: gcm - Con... |
1061 |
sg_init_one(&gcm_zeroes->sg, gcm_zeroes->buf, sizeof(gcm_zeroes->buf)); |
56a00d9da crypto: gcm - use... |
1062 1063 |
err = crypto_register_templates(crypto_gcm_tmpls, ARRAY_SIZE(crypto_gcm_tmpls)); |
d00aa19b5 [CRYPTO] gcm: All... |
1064 |
if (err) |
56a00d9da crypto: gcm - use... |
1065 |
kfree(gcm_zeroes); |
d00aa19b5 [CRYPTO] gcm: All... |
1066 |
|
9382d97af crypto: gcm - Use... |
1067 |
return err; |
28db8e3e3 [CRYPTO] gcm: New... |
1068 1069 1070 1071 |
} static void __exit crypto_gcm_module_exit(void) { |
9382d97af crypto: gcm - Use... |
1072 |
kfree(gcm_zeroes); |
56a00d9da crypto: gcm - use... |
1073 1074 |
crypto_unregister_templates(crypto_gcm_tmpls, ARRAY_SIZE(crypto_gcm_tmpls)); |
28db8e3e3 [CRYPTO] gcm: New... |
1075 |
} |
c4741b230 crypto: run initc... |
1076 |
subsys_initcall(crypto_gcm_module_init); |
28db8e3e3 [CRYPTO] gcm: New... |
1077 1078 1079 1080 1081 |
module_exit(crypto_gcm_module_exit); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Galois/Counter Mode"); MODULE_AUTHOR("Mikko Herranen <mh1@iki.fi>"); |
5d26a105b crypto: prefix mo... |
1082 1083 1084 |
MODULE_ALIAS_CRYPTO("gcm_base"); MODULE_ALIAS_CRYPTO("rfc4106"); MODULE_ALIAS_CRYPTO("rfc4543"); |
4943ba16b crypto: include c... |
1085 |
MODULE_ALIAS_CRYPTO("gcm"); |