Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 75957
b: refs/heads/master
c: 7c3d703
h: refs/heads/master
i:
  75955: 5f29ce4
v: v3
  • Loading branch information
Herbert Xu committed Jan 10, 2008
1 parent 603eeb1 commit b67f098
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 39 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 12dc5e62b4f93f1d399fd81e35be3f9ea0027712
refs/heads/master: 7c3d703fa81db42f9766325cebd6bfc1c5eac838
66 changes: 28 additions & 38 deletions trunk/crypto/authenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,18 @@ static int crypto_authenc_setkey(struct crypto_aead *authenc, const u8 *key,
goto out;
}

static int crypto_authenc_hash(struct aead_request *req)
static u8 *crypto_authenc_hash(struct aead_request *req, unsigned int flags,
struct scatterlist *cipher,
unsigned int cryptlen)
{
struct crypto_aead *authenc = crypto_aead_reqtfm(req);
struct crypto_authenc_ctx *ctx = crypto_aead_ctx(authenc);
struct crypto_hash *auth = ctx->auth;
struct hash_desc desc = {
.tfm = auth,
.flags = aead_request_flags(req) & flags,
};
u8 *hash = aead_request_ctx(req);
struct scatterlist *dst = req->dst;
unsigned int cryptlen = req->cryptlen;
int err;

hash = (u8 *)ALIGN((unsigned long)hash + crypto_hash_alignmask(auth),
Expand All @@ -112,7 +113,7 @@ static int crypto_authenc_hash(struct aead_request *req)
if (err)
goto auth_unlock;

err = crypto_hash_update(&desc, dst, cryptlen);
err = crypto_hash_update(&desc, cipher, cryptlen);
if (err)
goto auth_unlock;

Expand All @@ -121,7 +122,21 @@ static int crypto_authenc_hash(struct aead_request *req)
spin_unlock_bh(&ctx->auth_lock);

if (err)
return err;
return ERR_PTR(err);

return hash;
}

static int crypto_authenc_genicv(struct aead_request *req, unsigned int flags)
{
struct crypto_aead *authenc = crypto_aead_reqtfm(req);
struct scatterlist *dst = req->dst;
unsigned int cryptlen = req->cryptlen;
u8 *hash;

hash = crypto_authenc_hash(req, flags, dst, cryptlen);
if (IS_ERR(hash))
return PTR_ERR(hash);

scatterwalk_map_and_copy(hash, dst, cryptlen,
crypto_aead_authsize(authenc), 1);
Expand All @@ -132,7 +147,7 @@ static void crypto_authenc_encrypt_done(struct crypto_async_request *req,
int err)
{
if (!err)
err = crypto_authenc_hash(req->data);
err = crypto_authenc_genicv(req->data, 0);

aead_request_complete(req->data, err);
}
Expand All @@ -154,50 +169,25 @@ static int crypto_authenc_encrypt(struct aead_request *req)
if (err)
return err;

return crypto_authenc_hash(req);
return crypto_authenc_genicv(req, CRYPTO_TFM_REQ_MAY_SLEEP);
}

static int crypto_authenc_verify(struct aead_request *req,
unsigned int cryptlen)
{
struct crypto_aead *authenc = crypto_aead_reqtfm(req);
struct crypto_authenc_ctx *ctx = crypto_aead_ctx(authenc);
struct crypto_hash *auth = ctx->auth;
struct hash_desc desc = {
.tfm = auth,
.flags = aead_request_flags(req),
};
u8 *ohash = aead_request_ctx(req);
u8 *ohash;
u8 *ihash;
struct scatterlist *src = req->src;
unsigned int authsize;
int err;

ohash = (u8 *)ALIGN((unsigned long)ohash + crypto_hash_alignmask(auth),
crypto_hash_alignmask(auth) + 1);
ihash = ohash + crypto_hash_digestsize(auth);

spin_lock_bh(&ctx->auth_lock);
err = crypto_hash_init(&desc);
if (err)
goto auth_unlock;

err = crypto_hash_update(&desc, req->assoc, req->assoclen);
if (err)
goto auth_unlock;

err = crypto_hash_update(&desc, src, cryptlen);
if (err)
goto auth_unlock;

err = crypto_hash_final(&desc, ohash);
auth_unlock:
spin_unlock_bh(&ctx->auth_lock);

if (err)
return err;
ohash = crypto_authenc_hash(req, CRYPTO_TFM_REQ_MAY_SLEEP, src,
cryptlen);
if (IS_ERR(ohash))
return PTR_ERR(ohash);

authsize = crypto_aead_authsize(authenc);
ihash = ohash + authsize;
scatterwalk_map_and_copy(ihash, src, cryptlen, authsize, 0);
return memcmp(ihash, ohash, authsize) ? -EBADMSG: 0;
}
Expand Down

0 comments on commit b67f098

Please sign in to comment.