crypto: xcbc - Fix shash conversion
[safe/jmp/linux-2.6] / crypto / authenc.c
index ed8ac5a..2e16ce0 100644 (file)
@@ -11,6 +11,7 @@
  */
 
 #include <crypto/aead.h>
+#include <crypto/internal/hash.h>
 #include <crypto/internal/skcipher.h>
 #include <crypto/authenc.h>
 #include <crypto/scatterwalk.h>
@@ -157,16 +158,19 @@ static int crypto_authenc_genicv(struct aead_request *req, u8 *iv,
        dstp = sg_page(dst);
        vdst = PageHighMem(dstp) ? NULL : page_address(dstp) + dst->offset;
 
-       sg_init_table(cipher, 2);
-       sg_set_buf(cipher, iv, ivsize);
-       authenc_chain(cipher, dst, vdst == iv + ivsize);
+       if (ivsize) {
+               sg_init_table(cipher, 2);
+               sg_set_buf(cipher, iv, ivsize);
+               authenc_chain(cipher, dst, vdst == iv + ivsize);
+               dst = cipher;
+       }
 
        cryptlen = req->cryptlen + ivsize;
-       hash = crypto_authenc_hash(req, flags, cipher, cryptlen);
+       hash = crypto_authenc_hash(req, flags, dst, cryptlen);
        if (IS_ERR(hash))
                return PTR_ERR(hash);
 
-       scatterwalk_map_and_copy(hash, cipher, cryptlen,
+       scatterwalk_map_and_copy(hash, dst, cryptlen,
                                 crypto_aead_authsize(authenc), 1);
        return 0;
 }
@@ -174,8 +178,9 @@ static int crypto_authenc_genicv(struct aead_request *req, u8 *iv,
 static void crypto_authenc_encrypt_done(struct crypto_async_request *req,
                                        int err)
 {
+       struct aead_request *areq = req->data;
+
        if (!err) {
-               struct aead_request *areq = req->data;
                struct crypto_aead *authenc = crypto_aead_reqtfm(areq);
                struct crypto_authenc_ctx *ctx = crypto_aead_ctx(authenc);
                struct ablkcipher_request *abreq = aead_request_ctx(areq);
@@ -185,7 +190,7 @@ static void crypto_authenc_encrypt_done(struct crypto_async_request *req,
                err = crypto_authenc_genicv(areq, iv, 0);
        }
 
-       aead_request_complete(req->data, err);
+       aead_request_complete(areq, err);
 }
 
 static int crypto_authenc_encrypt(struct aead_request *req)
@@ -216,13 +221,15 @@ static int crypto_authenc_encrypt(struct aead_request *req)
 static void crypto_authenc_givencrypt_done(struct crypto_async_request *req,
                                           int err)
 {
+       struct aead_request *areq = req->data;
+
        if (!err) {
-               struct aead_givcrypt_request *greq = req->data;
+               struct skcipher_givcrypt_request *greq = aead_request_ctx(areq);
 
-               err = crypto_authenc_genicv(&greq->areq, greq->giv, 0);
+               err = crypto_authenc_genicv(areq, greq->giv, 0);
        }
 
-       aead_request_complete(req->data, err);
+       aead_request_complete(areq, err);
 }
 
 static int crypto_authenc_givencrypt(struct aead_givcrypt_request *req)
@@ -281,11 +288,14 @@ static int crypto_authenc_iverify(struct aead_request *req, u8 *iv,
        srcp = sg_page(src);
        vsrc = PageHighMem(srcp) ? NULL : page_address(srcp) + src->offset;
 
-       sg_init_table(cipher, 2);
-       sg_set_buf(cipher, iv, ivsize);
-       authenc_chain(cipher, src, vsrc == iv + ivsize);
+       if (ivsize) {
+               sg_init_table(cipher, 2);
+               sg_set_buf(cipher, iv, ivsize);
+               authenc_chain(cipher, src, vsrc == iv + ivsize);
+               src = cipher;
+       }
 
-       return crypto_authenc_verify(req, cipher, cryptlen + ivsize);
+       return crypto_authenc_verify(req, src, cryptlen + ivsize);
 }
 
 static int crypto_authenc_decrypt(struct aead_request *req)
@@ -426,9 +436,7 @@ static struct crypto_instance *crypto_authenc_alloc(struct rtattr **tb)
        inst->alg.cra_type = &crypto_aead_type;
 
        inst->alg.cra_aead.ivsize = enc->cra_ablkcipher.ivsize;
-       inst->alg.cra_aead.maxauthsize = auth->cra_type == &crypto_hash_type ?
-                                        auth->cra_hash.digestsize :
-                                        auth->cra_digest.dia_digestsize;
+       inst->alg.cra_aead.maxauthsize = __crypto_shash_alg(auth)->digestsize;
 
        inst->alg.cra_ctxsize = sizeof(struct crypto_authenc_ctx);