diff options
Diffstat (limited to 'drivers/crypto/ixp4xx_crypto.c')
-rw-r--r-- | drivers/crypto/ixp4xx_crypto.c | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/drivers/crypto/ixp4xx_crypto.c b/drivers/crypto/ixp4xx_crypto.c index 214357e12dc0..9dd6e01eac33 100644 --- a/drivers/crypto/ixp4xx_crypto.c +++ b/drivers/crypto/ixp4xx_crypto.c | |||
@@ -1149,32 +1149,24 @@ static int aead_setkey(struct crypto_aead *tfm, const u8 *key, | |||
1149 | unsigned int keylen) | 1149 | unsigned int keylen) |
1150 | { | 1150 | { |
1151 | struct ixp_ctx *ctx = crypto_aead_ctx(tfm); | 1151 | struct ixp_ctx *ctx = crypto_aead_ctx(tfm); |
1152 | struct rtattr *rta = (struct rtattr *)key; | 1152 | struct crypto_authenc_keys keys; |
1153 | struct crypto_authenc_key_param *param; | ||
1154 | 1153 | ||
1155 | if (!RTA_OK(rta, keylen)) | 1154 | if (crypto_authenc_extractkeys(&keys, key, keylen) != 0) |
1156 | goto badkey; | ||
1157 | if (rta->rta_type != CRYPTO_AUTHENC_KEYA_PARAM) | ||
1158 | goto badkey; | ||
1159 | if (RTA_PAYLOAD(rta) < sizeof(*param)) | ||
1160 | goto badkey; | 1155 | goto badkey; |
1161 | 1156 | ||
1162 | param = RTA_DATA(rta); | 1157 | if (keys.authkeylen > sizeof(ctx->authkey)) |
1163 | ctx->enckey_len = be32_to_cpu(param->enckeylen); | 1158 | goto badkey; |
1164 | |||
1165 | key += RTA_ALIGN(rta->rta_len); | ||
1166 | keylen -= RTA_ALIGN(rta->rta_len); | ||
1167 | 1159 | ||
1168 | if (keylen < ctx->enckey_len) | 1160 | if (keys.enckeylen > sizeof(ctx->enckey)) |
1169 | goto badkey; | 1161 | goto badkey; |
1170 | 1162 | ||
1171 | ctx->authkey_len = keylen - ctx->enckey_len; | 1163 | memcpy(ctx->authkey, keys.authkey, keys.authkeylen); |
1172 | memcpy(ctx->enckey, key + ctx->authkey_len, ctx->enckey_len); | 1164 | memcpy(ctx->enckey, keys.enckey, keys.enckeylen); |
1173 | memcpy(ctx->authkey, key, ctx->authkey_len); | 1165 | ctx->authkey_len = keys.authkeylen; |
1166 | ctx->enckey_len = keys.enckeylen; | ||
1174 | 1167 | ||
1175 | return aead_setup(tfm, crypto_aead_authsize(tfm)); | 1168 | return aead_setup(tfm, crypto_aead_authsize(tfm)); |
1176 | badkey: | 1169 | badkey: |
1177 | ctx->enckey_len = 0; | ||
1178 | crypto_aead_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN); | 1170 | crypto_aead_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN); |
1179 | return -EINVAL; | 1171 | return -EINVAL; |
1180 | } | 1172 | } |