Blame view
crypto/authencesn.c
15.1 KB
2874c5fd2
|
1 |
// SPDX-License-Identifier: GPL-2.0-or-later |
a5079d084
|
2 3 4 5 6 7 |
/* * authencesn.c - AEAD wrapper for IPsec with extended sequence numbers, * derived from authenc.c * * Copyright (C) 2010 secunet Security Networks AG * Copyright (C) 2010 Steffen Klassert <steffen.klassert@secunet.com> |
104880a6b
|
8 |
* Copyright (c) 2015 Herbert Xu <herbert@gondor.apana.org.au> |
a5079d084
|
9 |
*/ |
7fb2a4bdc
|
10 |
#include <crypto/internal/aead.h> |
a5079d084
|
11 12 13 |
#include <crypto/internal/hash.h> #include <crypto/internal/skcipher.h> #include <crypto/authenc.h> |
104880a6b
|
14 |
#include <crypto/null.h> |
a5079d084
|
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
#include <crypto/scatterwalk.h> #include <linux/err.h> #include <linux/init.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/rtnetlink.h> #include <linux/slab.h> #include <linux/spinlock.h> struct authenc_esn_instance_ctx { struct crypto_ahash_spawn auth; struct crypto_skcipher_spawn enc; }; struct crypto_authenc_esn_ctx { unsigned int reqoff; struct crypto_ahash *auth; |
e75445a84
|
32 |
struct crypto_skcipher *enc; |
8d6053984
|
33 |
struct crypto_sync_skcipher *null; |
a5079d084
|
34 35 36 |
}; struct authenc_esn_request_ctx { |
104880a6b
|
37 38 |
struct scatterlist src[2]; struct scatterlist dst[2]; |
a5079d084
|
39 40 41 42 43 44 45 46 |
char tail[]; }; static void authenc_esn_request_complete(struct aead_request *req, int err) { if (err != -EINPROGRESS) aead_request_complete(req, err); } |
104880a6b
|
47 48 49 50 51 52 53 54 |
static int crypto_authenc_esn_setauthsize(struct crypto_aead *authenc_esn, unsigned int authsize) { if (authsize > 0 && authsize < 4) return -EINVAL; return 0; } |
a5079d084
|
55 56 57 |
static int crypto_authenc_esn_setkey(struct crypto_aead *authenc_esn, const u8 *key, unsigned int keylen) { |
a5079d084
|
58 59 |
struct crypto_authenc_esn_ctx *ctx = crypto_aead_ctx(authenc_esn); struct crypto_ahash *auth = ctx->auth; |
e75445a84
|
60 |
struct crypto_skcipher *enc = ctx->enc; |
fddc2c43c
|
61 |
struct crypto_authenc_keys keys; |
a5079d084
|
62 |
int err = -EINVAL; |
fddc2c43c
|
63 |
if (crypto_authenc_extractkeys(&keys, key, keylen) != 0) |
a5079d084
|
64 |
goto badkey; |
a5079d084
|
65 66 67 68 |
crypto_ahash_clear_flags(auth, CRYPTO_TFM_REQ_MASK); crypto_ahash_set_flags(auth, crypto_aead_get_flags(authenc_esn) & CRYPTO_TFM_REQ_MASK); |
fddc2c43c
|
69 |
err = crypto_ahash_setkey(auth, keys.authkey, keys.authkeylen); |
a5079d084
|
70 71 72 73 74 |
crypto_aead_set_flags(authenc_esn, crypto_ahash_get_flags(auth) & CRYPTO_TFM_RES_MASK); if (err) goto out; |
e75445a84
|
75 76 |
crypto_skcipher_clear_flags(enc, CRYPTO_TFM_REQ_MASK); crypto_skcipher_set_flags(enc, crypto_aead_get_flags(authenc_esn) & |
a5079d084
|
77 |
CRYPTO_TFM_REQ_MASK); |
e75445a84
|
78 79 |
err = crypto_skcipher_setkey(enc, keys.enckey, keys.enckeylen); crypto_aead_set_flags(authenc_esn, crypto_skcipher_get_flags(enc) & |
a5079d084
|
80 81 82 |
CRYPTO_TFM_RES_MASK); out: |
31545df39
|
83 |
memzero_explicit(&keys, sizeof(keys)); |
a5079d084
|
84 85 86 87 88 89 |
return err; badkey: crypto_aead_set_flags(authenc_esn, CRYPTO_TFM_RES_BAD_KEY_LEN); goto out; } |
104880a6b
|
90 91 |
static int crypto_authenc_esn_genicv_tail(struct aead_request *req, unsigned int flags) |
a5079d084
|
92 |
{ |
a5079d084
|
93 94 95 |
struct crypto_aead *authenc_esn = crypto_aead_reqtfm(req); struct crypto_authenc_esn_ctx *ctx = crypto_aead_ctx(authenc_esn); struct authenc_esn_request_ctx *areq_ctx = aead_request_ctx(req); |
104880a6b
|
96 97 98 99 100 101 102 103 |
struct crypto_ahash *auth = ctx->auth; u8 *hash = PTR_ALIGN((u8 *)areq_ctx->tail, crypto_ahash_alignmask(auth) + 1); unsigned int authsize = crypto_aead_authsize(authenc_esn); unsigned int assoclen = req->assoclen; unsigned int cryptlen = req->cryptlen; struct scatterlist *dst = req->dst; u32 tmp[2]; |
a5079d084
|
104 |
|
104880a6b
|
105 106 107 108 |
/* Move high-order bits of sequence number back. */ scatterwalk_map_and_copy(tmp, dst, 4, 4, 0); scatterwalk_map_and_copy(tmp + 1, dst, assoclen + cryptlen, 4, 0); scatterwalk_map_and_copy(tmp, dst, 0, 8, 1); |
a5079d084
|
109 |
|
104880a6b
|
110 111 |
scatterwalk_map_and_copy(hash, dst, assoclen + cryptlen, authsize, 1); return 0; |
a5079d084
|
112 |
} |
a5079d084
|
113 114 115 116 |
static void authenc_esn_geniv_ahash_done(struct crypto_async_request *areq, int err) { struct aead_request *req = areq->data; |
a5079d084
|
117 |
|
104880a6b
|
118 |
err = err ?: crypto_authenc_esn_genicv_tail(req, 0); |
a5079d084
|
119 120 |
aead_request_complete(req, err); } |
104880a6b
|
121 122 |
static int crypto_authenc_esn_genicv(struct aead_request *req, unsigned int flags) |
a5079d084
|
123 |
{ |
a5079d084
|
124 |
struct crypto_aead *authenc_esn = crypto_aead_reqtfm(req); |
a5079d084
|
125 |
struct authenc_esn_request_ctx *areq_ctx = aead_request_ctx(req); |
a5079d084
|
126 |
struct crypto_authenc_esn_ctx *ctx = crypto_aead_ctx(authenc_esn); |
104880a6b
|
127 128 129 |
struct crypto_ahash *auth = ctx->auth; u8 *hash = PTR_ALIGN((u8 *)areq_ctx->tail, crypto_ahash_alignmask(auth) + 1); |
a5079d084
|
130 |
struct ahash_request *ahreq = (void *)(areq_ctx->tail + ctx->reqoff); |
104880a6b
|
131 132 |
unsigned int authsize = crypto_aead_authsize(authenc_esn); unsigned int assoclen = req->assoclen; |
a5079d084
|
133 |
unsigned int cryptlen = req->cryptlen; |
104880a6b
|
134 135 |
struct scatterlist *dst = req->dst; u32 tmp[2]; |
a5079d084
|
136 |
|
104880a6b
|
137 138 |
if (!authsize) return 0; |
a5079d084
|
139 |
|
104880a6b
|
140 141 142 143 |
/* Move high-order bits of sequence number to the end. */ scatterwalk_map_and_copy(tmp, dst, 0, 8, 0); scatterwalk_map_and_copy(tmp, dst, 4, 4, 1); scatterwalk_map_and_copy(tmp + 1, dst, assoclen + cryptlen, 4, 1); |
a5079d084
|
144 |
|
104880a6b
|
145 146 |
sg_init_table(areq_ctx->dst, 2); dst = scatterwalk_ffwd(areq_ctx->dst, dst, 4); |
a5079d084
|
147 |
|
104880a6b
|
148 149 150 151 |
ahash_request_set_tfm(ahreq, auth); ahash_request_set_crypt(ahreq, dst, hash, assoclen + cryptlen); ahash_request_set_callback(ahreq, flags, authenc_esn_geniv_ahash_done, req); |
a5079d084
|
152 |
|
104880a6b
|
153 154 |
return crypto_ahash_digest(ahreq) ?: crypto_authenc_esn_genicv_tail(req, aead_request_flags(req)); |
a5079d084
|
155 |
} |
104880a6b
|
156 157 |
static void crypto_authenc_esn_encrypt_done(struct crypto_async_request *req, int err) |
a5079d084
|
158 |
{ |
104880a6b
|
159 |
struct aead_request *areq = req->data; |
a5079d084
|
160 |
|
104880a6b
|
161 162 |
if (!err) err = crypto_authenc_esn_genicv(areq, 0); |
a5079d084
|
163 |
|
104880a6b
|
164 |
authenc_esn_request_complete(areq, err); |
a5079d084
|
165 |
} |
104880a6b
|
166 |
static int crypto_authenc_esn_copy(struct aead_request *req, unsigned int len) |
a5079d084
|
167 168 169 |
{ struct crypto_aead *authenc_esn = crypto_aead_reqtfm(req); struct crypto_authenc_esn_ctx *ctx = crypto_aead_ctx(authenc_esn); |
8d6053984
|
170 |
SYNC_SKCIPHER_REQUEST_ON_STACK(skreq, ctx->null); |
a5079d084
|
171 |
|
8d6053984
|
172 |
skcipher_request_set_sync_tfm(skreq, ctx->null); |
e75445a84
|
173 174 175 176 177 |
skcipher_request_set_callback(skreq, aead_request_flags(req), NULL, NULL); skcipher_request_set_crypt(skreq, req->src, req->dst, len, NULL); return crypto_skcipher_encrypt(skreq); |
a5079d084
|
178 |
} |
104880a6b
|
179 |
static int crypto_authenc_esn_encrypt(struct aead_request *req) |
a5079d084
|
180 181 182 |
{ struct crypto_aead *authenc_esn = crypto_aead_reqtfm(req); struct authenc_esn_request_ctx *areq_ctx = aead_request_ctx(req); |
104880a6b
|
183 |
struct crypto_authenc_esn_ctx *ctx = crypto_aead_ctx(authenc_esn); |
e75445a84
|
184 185 186 |
struct skcipher_request *skreq = (void *)(areq_ctx->tail + ctx->reqoff); struct crypto_skcipher *enc = ctx->enc; |
104880a6b
|
187 |
unsigned int assoclen = req->assoclen; |
a5079d084
|
188 |
unsigned int cryptlen = req->cryptlen; |
104880a6b
|
189 190 |
struct scatterlist *src, *dst; int err; |
a5079d084
|
191 |
|
104880a6b
|
192 193 194 |
sg_init_table(areq_ctx->src, 2); src = scatterwalk_ffwd(areq_ctx->src, req->src, assoclen); dst = src; |
a5079d084
|
195 |
|
104880a6b
|
196 197 198 199 |
if (req->src != req->dst) { err = crypto_authenc_esn_copy(req, assoclen); if (err) return err; |
a5079d084
|
200 |
|
104880a6b
|
201 202 |
sg_init_table(areq_ctx->dst, 2); dst = scatterwalk_ffwd(areq_ctx->dst, req->dst, assoclen); |
a5079d084
|
203 |
} |
e75445a84
|
204 205 206 207 |
skcipher_request_set_tfm(skreq, enc); skcipher_request_set_callback(skreq, aead_request_flags(req), crypto_authenc_esn_encrypt_done, req); skcipher_request_set_crypt(skreq, src, dst, cryptlen, req->iv); |
a5079d084
|
208 |
|
e75445a84
|
209 |
err = crypto_skcipher_encrypt(skreq); |
a5079d084
|
210 211 |
if (err) return err; |
104880a6b
|
212 |
return crypto_authenc_esn_genicv(req, aead_request_flags(req)); |
a5079d084
|
213 |
} |
104880a6b
|
214 215 |
static int crypto_authenc_esn_decrypt_tail(struct aead_request *req, unsigned int flags) |
a5079d084
|
216 |
{ |
104880a6b
|
217 218 219 220 |
struct crypto_aead *authenc_esn = crypto_aead_reqtfm(req); unsigned int authsize = crypto_aead_authsize(authenc_esn); struct authenc_esn_request_ctx *areq_ctx = aead_request_ctx(req); struct crypto_authenc_esn_ctx *ctx = crypto_aead_ctx(authenc_esn); |
e75445a84
|
221 222 |
struct skcipher_request *skreq = (void *)(areq_ctx->tail + ctx->reqoff); |
104880a6b
|
223 224 225 226 227 228 229 230 |
struct crypto_ahash *auth = ctx->auth; u8 *ohash = PTR_ALIGN((u8 *)areq_ctx->tail, crypto_ahash_alignmask(auth) + 1); unsigned int cryptlen = req->cryptlen - authsize; unsigned int assoclen = req->assoclen; struct scatterlist *dst = req->dst; u8 *ihash = ohash + crypto_ahash_digestsize(auth); u32 tmp[2]; |
a5079d084
|
231 |
|
41cdf7a45
|
232 233 |
if (!authsize) goto decrypt; |
104880a6b
|
234 235 236 237 |
/* Move high-order bits of sequence number back. */ scatterwalk_map_and_copy(tmp, dst, 4, 4, 0); scatterwalk_map_and_copy(tmp + 1, dst, assoclen + cryptlen, 4, 0); scatterwalk_map_and_copy(tmp, dst, 0, 8, 1); |
a5079d084
|
238 |
|
104880a6b
|
239 240 |
if (crypto_memneq(ihash, ohash, authsize)) return -EBADMSG; |
a5079d084
|
241 |
|
41cdf7a45
|
242 |
decrypt: |
104880a6b
|
243 244 |
sg_init_table(areq_ctx->dst, 2); dst = scatterwalk_ffwd(areq_ctx->dst, dst, assoclen); |
a5079d084
|
245 |
|
e75445a84
|
246 247 248 249 |
skcipher_request_set_tfm(skreq, ctx->enc); skcipher_request_set_callback(skreq, flags, req->base.complete, req->base.data); skcipher_request_set_crypt(skreq, dst, dst, cryptlen, req->iv); |
a5079d084
|
250 |
|
e75445a84
|
251 |
return crypto_skcipher_decrypt(skreq); |
a5079d084
|
252 |
} |
104880a6b
|
253 254 |
static void authenc_esn_verify_ahash_done(struct crypto_async_request *areq, int err) |
a5079d084
|
255 |
{ |
104880a6b
|
256 |
struct aead_request *req = areq->data; |
a5079d084
|
257 |
|
104880a6b
|
258 |
err = err ?: crypto_authenc_esn_decrypt_tail(req, 0); |
a77733636
|
259 |
authenc_esn_request_complete(req, err); |
a5079d084
|
260 |
} |
104880a6b
|
261 |
static int crypto_authenc_esn_decrypt(struct aead_request *req) |
a5079d084
|
262 263 264 |
{ struct crypto_aead *authenc_esn = crypto_aead_reqtfm(req); struct authenc_esn_request_ctx *areq_ctx = aead_request_ctx(req); |
104880a6b
|
265 266 267 268 269 270 271 272 273 274 275 276 |
struct crypto_authenc_esn_ctx *ctx = crypto_aead_ctx(authenc_esn); struct ahash_request *ahreq = (void *)(areq_ctx->tail + ctx->reqoff); unsigned int authsize = crypto_aead_authsize(authenc_esn); struct crypto_ahash *auth = ctx->auth; u8 *ohash = PTR_ALIGN((u8 *)areq_ctx->tail, crypto_ahash_alignmask(auth) + 1); unsigned int assoclen = req->assoclen; unsigned int cryptlen = req->cryptlen; u8 *ihash = ohash + crypto_ahash_digestsize(auth); struct scatterlist *dst = req->dst; u32 tmp[2]; int err; |
a5079d084
|
277 |
|
104880a6b
|
278 |
cryptlen -= authsize; |
a5079d084
|
279 |
|
104880a6b
|
280 281 282 283 284 |
if (req->src != dst) { err = crypto_authenc_esn_copy(req, assoclen + cryptlen); if (err) return err; } |
a5079d084
|
285 |
|
104880a6b
|
286 287 |
scatterwalk_map_and_copy(ihash, req->src, assoclen + cryptlen, authsize, 0); |
a5079d084
|
288 |
|
104880a6b
|
289 290 |
if (!authsize) goto tail; |
a5079d084
|
291 |
|
104880a6b
|
292 293 294 295 |
/* Move high-order bits of sequence number to the end. */ scatterwalk_map_and_copy(tmp, dst, 0, 8, 0); scatterwalk_map_and_copy(tmp, dst, 4, 4, 1); scatterwalk_map_and_copy(tmp + 1, dst, assoclen + cryptlen, 4, 1); |
a5079d084
|
296 |
|
104880a6b
|
297 298 |
sg_init_table(areq_ctx->dst, 2); dst = scatterwalk_ffwd(areq_ctx->dst, dst, 4); |
a5079d084
|
299 |
|
104880a6b
|
300 301 302 303 |
ahash_request_set_tfm(ahreq, auth); ahash_request_set_crypt(ahreq, dst, ohash, assoclen + cryptlen); ahash_request_set_callback(ahreq, aead_request_flags(req), authenc_esn_verify_ahash_done, req); |
a5079d084
|
304 |
|
104880a6b
|
305 |
err = crypto_ahash_digest(ahreq); |
a5079d084
|
306 307 |
if (err) return err; |
104880a6b
|
308 309 |
tail: return crypto_authenc_esn_decrypt_tail(req, aead_request_flags(req)); |
a5079d084
|
310 |
} |
104880a6b
|
311 |
static int crypto_authenc_esn_init_tfm(struct crypto_aead *tfm) |
a5079d084
|
312 |
{ |
104880a6b
|
313 314 315 |
struct aead_instance *inst = aead_alg_instance(tfm); struct authenc_esn_instance_ctx *ictx = aead_instance_ctx(inst); struct crypto_authenc_esn_ctx *ctx = crypto_aead_ctx(tfm); |
a5079d084
|
316 |
struct crypto_ahash *auth; |
e75445a84
|
317 |
struct crypto_skcipher *enc; |
8d6053984
|
318 |
struct crypto_sync_skcipher *null; |
a5079d084
|
319 320 321 322 323 |
int err; auth = crypto_spawn_ahash(&ictx->auth); if (IS_ERR(auth)) return PTR_ERR(auth); |
60425a8ba
|
324 |
enc = crypto_spawn_skcipher(&ictx->enc); |
a5079d084
|
325 326 327 |
err = PTR_ERR(enc); if (IS_ERR(enc)) goto err_free_ahash; |
3a2d4fb51
|
328 |
null = crypto_get_default_null_skcipher(); |
104880a6b
|
329 330 331 |
err = PTR_ERR(null); if (IS_ERR(null)) goto err_free_skcipher; |
a5079d084
|
332 333 |
ctx->auth = auth; ctx->enc = enc; |
104880a6b
|
334 |
ctx->null = null; |
a5079d084
|
335 |
|
104880a6b
|
336 337 |
ctx->reqoff = ALIGN(2 * crypto_ahash_digestsize(auth), crypto_ahash_alignmask(auth) + 1); |
a5079d084
|
338 |
|
104880a6b
|
339 340 |
crypto_aead_set_reqsize( tfm, |
6650d09b3
|
341 342 343 |
sizeof(struct authenc_esn_request_ctx) + ctx->reqoff + max_t(unsigned int, |
e75445a84
|
344 345 346 347 |
crypto_ahash_reqsize(auth) + sizeof(struct ahash_request), sizeof(struct skcipher_request) + crypto_skcipher_reqsize(enc))); |
a5079d084
|
348 349 |
return 0; |
104880a6b
|
350 |
err_free_skcipher: |
e75445a84
|
351 |
crypto_free_skcipher(enc); |
a5079d084
|
352 353 354 355 |
err_free_ahash: crypto_free_ahash(auth); return err; } |
104880a6b
|
356 |
static void crypto_authenc_esn_exit_tfm(struct crypto_aead *tfm) |
a5079d084
|
357 |
{ |
104880a6b
|
358 |
struct crypto_authenc_esn_ctx *ctx = crypto_aead_ctx(tfm); |
a5079d084
|
359 360 |
crypto_free_ahash(ctx->auth); |
e75445a84
|
361 |
crypto_free_skcipher(ctx->enc); |
3a2d4fb51
|
362 |
crypto_put_default_null_skcipher(); |
104880a6b
|
363 364 365 366 367 368 369 370 371 |
} static void crypto_authenc_esn_free(struct aead_instance *inst) { struct authenc_esn_instance_ctx *ctx = aead_instance_ctx(inst); crypto_drop_skcipher(&ctx->enc); crypto_drop_ahash(&ctx->auth); kfree(inst); |
a5079d084
|
372 |
} |
104880a6b
|
373 374 |
static int crypto_authenc_esn_create(struct crypto_template *tmpl, struct rtattr **tb) |
a5079d084
|
375 376 |
{ struct crypto_attr_type *algt; |
104880a6b
|
377 |
struct aead_instance *inst; |
a5079d084
|
378 379 |
struct hash_alg_common *auth; struct crypto_alg *auth_base; |
e75445a84
|
380 |
struct skcipher_alg *enc; |
a5079d084
|
381 382 383 384 385 |
struct authenc_esn_instance_ctx *ctx; const char *enc_name; int err; algt = crypto_get_attr_type(tb); |
a5079d084
|
386 |
if (IS_ERR(algt)) |
104880a6b
|
387 |
return PTR_ERR(algt); |
a5079d084
|
388 |
|
5e4b8c1fc
|
389 |
if ((algt->type ^ CRYPTO_ALG_TYPE_AEAD) & algt->mask) |
104880a6b
|
390 |
return -EINVAL; |
a5079d084
|
391 392 |
auth = ahash_attr_alg(tb[1], CRYPTO_ALG_TYPE_HASH, |
927ef32dc
|
393 394 |
CRYPTO_ALG_TYPE_AHASH_MASK | crypto_requires_sync(algt->type, algt->mask)); |
a5079d084
|
395 |
if (IS_ERR(auth)) |
104880a6b
|
396 |
return PTR_ERR(auth); |
a5079d084
|
397 398 399 400 401 402 403 404 405 406 407 408 |
auth_base = &auth->base; enc_name = crypto_attr_alg_name(tb[2]); err = PTR_ERR(enc_name); if (IS_ERR(enc_name)) goto out_put_auth; inst = kzalloc(sizeof(*inst) + sizeof(*ctx), GFP_KERNEL); err = -ENOMEM; if (!inst) goto out_put_auth; |
104880a6b
|
409 |
ctx = aead_instance_ctx(inst); |
a5079d084
|
410 |
|
104880a6b
|
411 412 |
err = crypto_init_ahash_spawn(&ctx->auth, auth, aead_crypto_instance(inst)); |
a5079d084
|
413 414 |
if (err) goto err_free_inst; |
104880a6b
|
415 |
crypto_set_skcipher_spawn(&ctx->enc, aead_crypto_instance(inst)); |
a35528eca
|
416 417 418 |
err = crypto_grab_skcipher(&ctx->enc, enc_name, 0, crypto_requires_sync(algt->type, algt->mask)); |
a5079d084
|
419 420 |
if (err) goto err_drop_auth; |
e75445a84
|
421 |
enc = crypto_spawn_skcipher_alg(&ctx->enc); |
a5079d084
|
422 423 |
err = -ENAMETOOLONG; |
104880a6b
|
424 425 |
if (snprintf(inst->alg.base.cra_name, CRYPTO_MAX_ALG_NAME, "authencesn(%s,%s)", auth_base->cra_name, |
e75445a84
|
426 |
enc->base.cra_name) >= CRYPTO_MAX_ALG_NAME) |
a5079d084
|
427 |
goto err_drop_enc; |
104880a6b
|
428 |
if (snprintf(inst->alg.base.cra_driver_name, CRYPTO_MAX_ALG_NAME, |
a5079d084
|
429 |
"authencesn(%s,%s)", auth_base->cra_driver_name, |
e75445a84
|
430 |
enc->base.cra_driver_name) >= CRYPTO_MAX_ALG_NAME) |
a5079d084
|
431 |
goto err_drop_enc; |
e75445a84
|
432 433 434 |
inst->alg.base.cra_flags = (auth_base->cra_flags | enc->base.cra_flags) & CRYPTO_ALG_ASYNC; inst->alg.base.cra_priority = enc->base.cra_priority * 10 + |
104880a6b
|
435 |
auth_base->cra_priority; |
e75445a84
|
436 |
inst->alg.base.cra_blocksize = enc->base.cra_blocksize; |
104880a6b
|
437 |
inst->alg.base.cra_alignmask = auth_base->cra_alignmask | |
e75445a84
|
438 |
enc->base.cra_alignmask; |
104880a6b
|
439 |
inst->alg.base.cra_ctxsize = sizeof(struct crypto_authenc_esn_ctx); |
e75445a84
|
440 441 |
inst->alg.ivsize = crypto_skcipher_alg_ivsize(enc); inst->alg.chunksize = crypto_skcipher_alg_chunksize(enc); |
104880a6b
|
442 |
inst->alg.maxauthsize = auth->digestsize; |
a5079d084
|
443 |
|
104880a6b
|
444 445 |
inst->alg.init = crypto_authenc_esn_init_tfm; inst->alg.exit = crypto_authenc_esn_exit_tfm; |
a5079d084
|
446 |
|
104880a6b
|
447 448 449 450 |
inst->alg.setkey = crypto_authenc_esn_setkey; inst->alg.setauthsize = crypto_authenc_esn_setauthsize; inst->alg.encrypt = crypto_authenc_esn_encrypt; inst->alg.decrypt = crypto_authenc_esn_decrypt; |
a5079d084
|
451 |
|
104880a6b
|
452 |
inst->free = crypto_authenc_esn_free, |
a5079d084
|
453 |
|
104880a6b
|
454 455 456 |
err = aead_register_instance(tmpl, inst); if (err) goto err_drop_enc; |
a5079d084
|
457 458 459 |
out: crypto_mod_put(auth_base); |
104880a6b
|
460 |
return err; |
a5079d084
|
461 462 463 464 465 466 467 468 |
err_drop_enc: crypto_drop_skcipher(&ctx->enc); err_drop_auth: crypto_drop_ahash(&ctx->auth); err_free_inst: kfree(inst); out_put_auth: |
a5079d084
|
469 470 |
goto out; } |
a5079d084
|
471 472 |
static struct crypto_template crypto_authenc_esn_tmpl = { .name = "authencesn", |
104880a6b
|
473 |
.create = crypto_authenc_esn_create, |
a5079d084
|
474 475 476 477 478 479 480 481 482 483 484 485 |
.module = THIS_MODULE, }; static int __init crypto_authenc_esn_module_init(void) { return crypto_register_template(&crypto_authenc_esn_tmpl); } static void __exit crypto_authenc_esn_module_exit(void) { crypto_unregister_template(&crypto_authenc_esn_tmpl); } |
c4741b230
|
486 |
subsys_initcall(crypto_authenc_esn_module_init); |
a5079d084
|
487 488 489 490 491 |
module_exit(crypto_authenc_esn_module_exit); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Steffen Klassert <steffen.klassert@secunet.com>"); MODULE_DESCRIPTION("AEAD wrapper for IPsec with extended sequence numbers"); |
4943ba16b
|
492 |
MODULE_ALIAS_CRYPTO("authencesn"); |