[CRYPTO] gcm: Fix givencrypt/givdecrypt

This patch makes givencrypt and givdecrypt call skcipher_givcrypt_set_tfm
to set the correct tfm for the sub-request.  Without this we may try to
call givencrypt and givdecrypt on an skcipher that does not have these
operations.

Signed-off-by: Herbert Xu <[EMAIL PROTECTED]>
---

 crypto/gcm.c |    6 ++++++
 1 files changed, 6 insertions(+)

diff --git a/crypto/gcm.c b/crypto/gcm.c
index 6f23f02..8f1d08c 100644
--- a/crypto/gcm.c
+++ b/crypto/gcm.c
@@ -305,6 +305,8 @@ static int crypto_gcm_encrypt(struct aead_request *req)
 
 static int crypto_gcm_givencrypt(struct aead_givcrypt_request *req)
 {
+       struct crypto_aead *aead = aead_givcrypt_reqtfm(req);
+       struct crypto_gcm_ctx *ctx = crypto_aead_ctx(aead);
        struct aead_request *areq = &req->areq;
        struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(areq);
        struct skcipher_givcrypt_request *greq = &pctx->greq;
@@ -312,6 +314,7 @@ static int crypto_gcm_givencrypt(struct 
aead_givcrypt_request *req)
        int err;
 
        crypto_gcm_init_encrypt(abreq, areq);
+       skcipher_givcrypt_set_tfm(greq, ctx->ctr);
        skcipher_givcrypt_set_giv(greq, req->giv, req->seq);
 
        err = crypto_skcipher_givencrypt(greq);
@@ -388,6 +391,8 @@ static int crypto_gcm_decrypt(struct aead_request *req)
 
 static int crypto_gcm_givdecrypt(struct aead_givcrypt_request *req)
 {
+       struct crypto_aead *aead = aead_givcrypt_reqtfm(req);
+       struct crypto_gcm_ctx *ctx = crypto_aead_ctx(aead);
        struct aead_request *areq = &req->areq;
        struct crypto_gcm_req_priv_ctx *pctx = crypto_gcm_reqctx(areq);
        struct skcipher_givcrypt_request *greq = &pctx->greq;
@@ -398,6 +403,7 @@ static int crypto_gcm_givdecrypt(struct 
aead_givcrypt_request *req)
        if (err)
                return err;
 
+       skcipher_givcrypt_set_tfm(greq, ctx->ctr);
        skcipher_givcrypt_set_giv(greq, req->giv, req->seq);
 
        err = crypto_skcipher_givdecrypt(greq);
-
To unsubscribe from this list: send the line "unsubscribe linux-crypto" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to