diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2007-12-12 06:16:38 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2008-01-10 16:16:40 -0500 |
commit | 2589469d7bc69bdfad4e05d88a0d2748f92ef0f3 (patch) | |
tree | 40103b6e4b2e36be3bf9b47df5eeafe885fe15b2 /crypto/gcm.c | |
parent | 68b6c7d6919be7c732fc6229c55e35d0166e9258 (diff) |
[CRYPTO] gcm: Fix request context alignment
This patch fixes the request context alignment so that it is actually
aligned to the value required by the algorithm.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto/gcm.c')
-rw-r--r-- | crypto/gcm.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/crypto/gcm.c b/crypto/gcm.c index 73565d607ee7..08183171913c 100644 --- a/crypto/gcm.c +++ b/crypto/gcm.c | |||
@@ -43,6 +43,14 @@ struct crypto_gcm_req_priv_ctx { | |||
43 | struct ablkcipher_request abreq; | 43 | struct ablkcipher_request abreq; |
44 | }; | 44 | }; |
45 | 45 | ||
46 | static inline struct crypto_gcm_req_priv_ctx *crypto_gcm_reqctx( | ||
47 | struct aead_request *req) | ||
48 | { | ||
49 | unsigned long align = crypto_aead_alignmask(crypto_aead_reqtfm(req)); | ||
50 | |||
51 | return (void *)PTR_ALIGN((u8 *)aead_request_ctx(req), align + 1); | ||
52 | } | ||
53 | |||
46 | static void crypto_gcm_ghash_init(struct crypto_gcm_ghash_ctx *ctx, u32 flags, | 54 | static void crypto_gcm_ghash_init(struct crypto_gcm_ghash_ctx *ctx, u32 flags, |
47 | struct gf128mul_4k *gf128) | 55 | struct gf128mul_4k *gf128) |
48 | { | 56 | { |
@@ -224,7 +232,7 @@ static int crypto_gcm_init_crypt(struct ablkcipher_request *ablk_req, | |||
224 | { | 232 | { |
225 | struct crypto_aead *aead = crypto_aead_reqtfm(req); | 233 | struct crypto_aead *aead = crypto_aead_reqtfm(req); |
226 | struct crypto_gcm_ctx *ctx = crypto_aead_ctx(aead); | 234 | struct crypto_gcm_ctx *ctx = crypto_aead_ctx(aead); |
227 | struct crypto_gcm_req_priv_ctx *pctx = aead_request_ctx(req); | 235 | struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); |
228 | u32 flags = req->base.tfm->crt_flags; | 236 | u32 flags = req->base.tfm->crt_flags; |
229 | u8 *auth_tag = pctx->auth_tag; | 237 | u8 *auth_tag = pctx->auth_tag; |
230 | u8 *counter = pctx->counter; | 238 | u8 *counter = pctx->counter; |
@@ -256,7 +264,7 @@ static int crypto_gcm_init_crypt(struct ablkcipher_request *ablk_req, | |||
256 | static int crypto_gcm_hash(struct aead_request *req) | 264 | static int crypto_gcm_hash(struct aead_request *req) |
257 | { | 265 | { |
258 | struct crypto_aead *aead = crypto_aead_reqtfm(req); | 266 | struct crypto_aead *aead = crypto_aead_reqtfm(req); |
259 | struct crypto_gcm_req_priv_ctx *pctx = aead_request_ctx(req); | 267 | struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); |
260 | u8 *auth_tag = pctx->auth_tag; | 268 | u8 *auth_tag = pctx->auth_tag; |
261 | struct crypto_gcm_ghash_ctx *ghash = &pctx->ghash; | 269 | struct crypto_gcm_ghash_ctx *ghash = &pctx->ghash; |
262 | 270 | ||
@@ -281,7 +289,7 @@ static void crypto_gcm_encrypt_done(struct crypto_async_request *areq, int err) | |||
281 | 289 | ||
282 | static int crypto_gcm_encrypt(struct aead_request *req) | 290 | static int crypto_gcm_encrypt(struct aead_request *req) |
283 | { | 291 | { |
284 | struct crypto_gcm_req_priv_ctx *pctx = aead_request_ctx(req); | 292 | struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); |
285 | struct ablkcipher_request *abreq = &pctx->abreq; | 293 | struct ablkcipher_request *abreq = &pctx->abreq; |
286 | int err = 0; | 294 | int err = 0; |
287 | 295 | ||
@@ -307,7 +315,7 @@ static void crypto_gcm_decrypt_done(struct crypto_async_request *areq, int err) | |||
307 | static int crypto_gcm_decrypt(struct aead_request *req) | 315 | static int crypto_gcm_decrypt(struct aead_request *req) |
308 | { | 316 | { |
309 | struct crypto_aead *aead = crypto_aead_reqtfm(req); | 317 | struct crypto_aead *aead = crypto_aead_reqtfm(req); |
310 | struct crypto_gcm_req_priv_ctx *pctx = aead_request_ctx(req); | 318 | struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(req); |
311 | struct ablkcipher_request *abreq = &pctx->abreq; | 319 | struct ablkcipher_request *abreq = &pctx->abreq; |
312 | u8 *auth_tag = pctx->auth_tag; | 320 | u8 *auth_tag = pctx->auth_tag; |
313 | u8 *iauth_tag = pctx->iauth_tag; | 321 | u8 *iauth_tag = pctx->iauth_tag; |
@@ -352,8 +360,7 @@ static int crypto_gcm_init_tfm(struct crypto_tfm *tfm) | |||
352 | ctx->ctr = ctr; | 360 | ctx->ctr = ctr; |
353 | ctx->gf128 = NULL; | 361 | ctx->gf128 = NULL; |
354 | 362 | ||
355 | align = max_t(unsigned long, crypto_ablkcipher_alignmask(ctr), | 363 | align = crypto_tfm_alg_alignmask(tfm); |
356 | __alignof__(u32) - 1); | ||
357 | align &= ~(crypto_tfm_ctx_alignment() - 1); | 364 | align &= ~(crypto_tfm_ctx_alignment() - 1); |
358 | tfm->crt_aead.reqsize = align + | 365 | tfm->crt_aead.reqsize = align + |
359 | sizeof(struct crypto_gcm_req_priv_ctx) + | 366 | sizeof(struct crypto_gcm_req_priv_ctx) + |
@@ -428,7 +435,7 @@ static struct crypto_instance *crypto_gcm_alloc(struct rtattr **tb) | |||
428 | inst->alg.cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC; | 435 | inst->alg.cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC; |
429 | inst->alg.cra_priority = ctr->cra_priority; | 436 | inst->alg.cra_priority = ctr->cra_priority; |
430 | inst->alg.cra_blocksize = 16; | 437 | inst->alg.cra_blocksize = 16; |
431 | inst->alg.cra_alignmask = __alignof__(u32) - 1; | 438 | inst->alg.cra_alignmask = ctr->cra_alignmask | (__alignof__(u64) - 1); |
432 | inst->alg.cra_type = &crypto_aead_type; | 439 | inst->alg.cra_type = &crypto_aead_type; |
433 | inst->alg.cra_aead.ivsize = 12; | 440 | inst->alg.cra_aead.ivsize = 12; |
434 | inst->alg.cra_aead.maxauthsize = 16; | 441 | inst->alg.cra_aead.maxauthsize = 16; |