Skip to content

Commit

Permalink
crypto: talitos - Simplify key parsing
Browse files Browse the repository at this point in the history
Use the common helper function crypto_authenc_extractkeys() for key
parsing.

Cc: Kim Phillips <[email protected]>
Cc: Herbert Xu <[email protected]>
Cc: "David S. Miller" <[email protected]>
Signed-off-by: Mathias Krause <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
Mathias Krause authored and herbertx committed Oct 16, 2013
1 parent ab827fb commit c306a98
Showing 1 changed file with 8 additions and 27 deletions.
35 changes: 8 additions & 27 deletions drivers/crypto/talitos.c
Original file line number Diff line number Diff line change
Expand Up @@ -671,39 +671,20 @@ static int aead_setkey(struct crypto_aead *authenc,
const u8 *key, unsigned int keylen)
{
struct talitos_ctx *ctx = crypto_aead_ctx(authenc);
struct rtattr *rta = (void *)key;
struct crypto_authenc_key_param *param;
unsigned int authkeylen;
unsigned int enckeylen;

if (!RTA_OK(rta, keylen))
goto badkey;
struct crypto_authenc_keys keys;

if (rta->rta_type != CRYPTO_AUTHENC_KEYA_PARAM)
if (crypto_authenc_extractkeys(&keys, key, keylen) != 0)
goto badkey;

if (RTA_PAYLOAD(rta) < sizeof(*param))
if (keys.authkeylen + keys.enckeylen > TALITOS_MAX_KEY_SIZE)
goto badkey;

param = RTA_DATA(rta);
enckeylen = be32_to_cpu(param->enckeylen);

key += RTA_ALIGN(rta->rta_len);
keylen -= RTA_ALIGN(rta->rta_len);

if (keylen < enckeylen)
goto badkey;
memcpy(ctx->key, keys.authkey, keys.authkeylen);
memcpy(&ctx->key[keys.authkeylen], keys.enckey, keys.enckeylen);

authkeylen = keylen - enckeylen;

if (keylen > TALITOS_MAX_KEY_SIZE)
goto badkey;

memcpy(&ctx->key, key, keylen);

ctx->keylen = keylen;
ctx->enckeylen = enckeylen;
ctx->authkeylen = authkeylen;
ctx->keylen = keys.authkeylen + keys.enckeylen;
ctx->enckeylen = keys.enckeylen;
ctx->authkeylen = keys.authkeylen;

return 0;

Expand Down

0 comments on commit c306a98

Please sign in to comment.