aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/gcm.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/gcm.c')
-rw-r--r--crypto/gcm.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/crypto/gcm.c b/crypto/gcm.c
index 502da929a5fc..73565d607ee7 100644
--- a/crypto/gcm.c
+++ b/crypto/gcm.c
@@ -40,6 +40,7 @@ struct crypto_gcm_req_priv_ctx {
40 u8 iauth_tag[16]; 40 u8 iauth_tag[16];
41 u8 counter[16]; 41 u8 counter[16];
42 struct crypto_gcm_ghash_ctx ghash; 42 struct crypto_gcm_ghash_ctx ghash;
43 struct ablkcipher_request abreq;
43}; 44};
44 45
45static void crypto_gcm_ghash_init(struct crypto_gcm_ghash_ctx *ctx, u32 flags, 46static void crypto_gcm_ghash_init(struct crypto_gcm_ghash_ctx *ctx, u32 flags,
@@ -280,16 +281,17 @@ static void crypto_gcm_encrypt_done(struct crypto_async_request *areq, int err)
280 281
281static int crypto_gcm_encrypt(struct aead_request *req) 282static int crypto_gcm_encrypt(struct aead_request *req)
282{ 283{
283 struct ablkcipher_request abreq; 284 struct crypto_gcm_req_priv_ctx *pctx = aead_request_ctx(req);
285 struct ablkcipher_request *abreq = &pctx->abreq;
284 int err = 0; 286 int err = 0;
285 287
286 err = crypto_gcm_init_crypt(&abreq, req, req->cryptlen, 288 err = crypto_gcm_init_crypt(abreq, req, req->cryptlen,
287 crypto_gcm_encrypt_done); 289 crypto_gcm_encrypt_done);
288 if (err) 290 if (err)
289 return err; 291 return err;
290 292
291 if (req->cryptlen) { 293 if (req->cryptlen) {
292 err = crypto_ablkcipher_encrypt(&abreq); 294 err = crypto_ablkcipher_encrypt(abreq);
293 if (err) 295 if (err)
294 return err; 296 return err;
295 } 297 }
@@ -304,9 +306,9 @@ static void crypto_gcm_decrypt_done(struct crypto_async_request *areq, int err)
304 306
305static int crypto_gcm_decrypt(struct aead_request *req) 307static int crypto_gcm_decrypt(struct aead_request *req)
306{ 308{
307 struct ablkcipher_request abreq;
308 struct crypto_aead *aead = crypto_aead_reqtfm(req); 309 struct crypto_aead *aead = crypto_aead_reqtfm(req);
309 struct crypto_gcm_req_priv_ctx *pctx = aead_request_ctx(req); 310 struct crypto_gcm_req_priv_ctx *pctx = aead_request_ctx(req);
311 struct ablkcipher_request *abreq = &pctx->abreq;
310 u8 *auth_tag = pctx->auth_tag; 312 u8 *auth_tag = pctx->auth_tag;
311 u8 *iauth_tag = pctx->iauth_tag; 313 u8 *iauth_tag = pctx->iauth_tag;
312 struct crypto_gcm_ghash_ctx *ghash = &pctx->ghash; 314 struct crypto_gcm_ghash_ctx *ghash = &pctx->ghash;
@@ -318,7 +320,7 @@ static int crypto_gcm_decrypt(struct aead_request *req)
318 return -EINVAL; 320 return -EINVAL;
319 cryptlen -= authsize; 321 cryptlen -= authsize;
320 322
321 err = crypto_gcm_init_crypt(&abreq, req, cryptlen, 323 err = crypto_gcm_init_crypt(abreq, req, cryptlen,
322 crypto_gcm_decrypt_done); 324 crypto_gcm_decrypt_done);
323 if (err) 325 if (err)
324 return err; 326 return err;
@@ -330,7 +332,7 @@ static int crypto_gcm_decrypt(struct aead_request *req)
330 if (memcmp(iauth_tag, auth_tag, authsize)) 332 if (memcmp(iauth_tag, auth_tag, authsize))
331 return -EBADMSG; 333 return -EBADMSG;
332 334
333 return crypto_ablkcipher_decrypt(&abreq); 335 return crypto_ablkcipher_decrypt(abreq);
334} 336}
335 337
336static int crypto_gcm_init_tfm(struct crypto_tfm *tfm) 338static int crypto_gcm_init_tfm(struct crypto_tfm *tfm)
@@ -353,7 +355,9 @@ static int crypto_gcm_init_tfm(struct crypto_tfm *tfm)
353 align = max_t(unsigned long, crypto_ablkcipher_alignmask(ctr), 355 align = max_t(unsigned long, crypto_ablkcipher_alignmask(ctr),
354 __alignof__(u32) - 1); 356 __alignof__(u32) - 1);
355 align &= ~(crypto_tfm_ctx_alignment() - 1); 357 align &= ~(crypto_tfm_ctx_alignment() - 1);
356 tfm->crt_aead.reqsize = align + sizeof(struct crypto_gcm_req_priv_ctx); 358 tfm->crt_aead.reqsize = align +
359 sizeof(struct crypto_gcm_req_priv_ctx) +
360 crypto_ablkcipher_reqsize(ctr);
357 361
358 return 0; 362 return 0;
359} 363}