Commit cc1b156d authored by Harsh Jain's avatar Harsh Jain Committed by Herbert Xu

crypto: chcr - Calculate Reverse round key in setkey callback.

Move reverse round key calculation logic in setkey operation.
Signed-off-by: default avatarHarsh Jain <harsh@chelsio.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 44fce12a
...@@ -455,16 +455,13 @@ static int generate_copy_rrkey(struct ablk_ctx *ablkctx, ...@@ -455,16 +455,13 @@ static int generate_copy_rrkey(struct ablk_ctx *ablkctx,
struct _key_ctx *key_ctx) struct _key_ctx *key_ctx)
{ {
if (ablkctx->ciph_mode == CHCR_SCMD_CIPHER_MODE_AES_CBC) { if (ablkctx->ciph_mode == CHCR_SCMD_CIPHER_MODE_AES_CBC) {
get_aes_decrypt_key(key_ctx->key, ablkctx->key, memcpy(key_ctx->key, ablkctx->rrkey, ablkctx->enckey_len);
ablkctx->enckey_len << 3);
memset(key_ctx->key + ablkctx->enckey_len, 0,
CHCR_AES_MAX_KEY_LEN - ablkctx->enckey_len);
} else { } else {
memcpy(key_ctx->key, memcpy(key_ctx->key,
ablkctx->key + (ablkctx->enckey_len >> 1), ablkctx->key + (ablkctx->enckey_len >> 1),
ablkctx->enckey_len >> 1); ablkctx->enckey_len >> 1);
get_aes_decrypt_key(key_ctx->key + (ablkctx->enckey_len >> 1), memcpy(key_ctx->key + (ablkctx->enckey_len >> 1),
ablkctx->key, ablkctx->enckey_len << 2); ablkctx->rrkey, ablkctx->enckey_len >> 1);
} }
return 0; return 0;
} }
...@@ -620,15 +617,9 @@ static int chcr_aes_cbc_setkey(struct crypto_ablkcipher *tfm, const u8 *key, ...@@ -620,15 +617,9 @@ static int chcr_aes_cbc_setkey(struct crypto_ablkcipher *tfm, const u8 *key,
{ {
struct chcr_context *ctx = crypto_ablkcipher_ctx(tfm); struct chcr_context *ctx = crypto_ablkcipher_ctx(tfm);
struct ablk_ctx *ablkctx = ABLK_CTX(ctx); struct ablk_ctx *ablkctx = ABLK_CTX(ctx);
struct ablkcipher_alg *alg = crypto_ablkcipher_alg(tfm);
unsigned int ck_size, context_size; unsigned int ck_size, context_size;
u16 alignment = 0; u16 alignment = 0;
if ((keylen < alg->min_keysize) || (keylen > alg->max_keysize))
goto badkey_err;
memcpy(ablkctx->key, key, keylen);
ablkctx->enckey_len = keylen;
if (keylen == AES_KEYSIZE_128) { if (keylen == AES_KEYSIZE_128) {
ck_size = CHCR_KEYCTX_CIPHER_KEY_SIZE_128; ck_size = CHCR_KEYCTX_CIPHER_KEY_SIZE_128;
} else if (keylen == AES_KEYSIZE_192) { } else if (keylen == AES_KEYSIZE_192) {
...@@ -639,7 +630,9 @@ static int chcr_aes_cbc_setkey(struct crypto_ablkcipher *tfm, const u8 *key, ...@@ -639,7 +630,9 @@ static int chcr_aes_cbc_setkey(struct crypto_ablkcipher *tfm, const u8 *key,
} else { } else {
goto badkey_err; goto badkey_err;
} }
memcpy(ablkctx->key, key, keylen);
ablkctx->enckey_len = keylen;
get_aes_decrypt_key(ablkctx->rrkey, ablkctx->key, keylen << 3);
context_size = (KEY_CONTEXT_HDR_SALT_AND_PAD + context_size = (KEY_CONTEXT_HDR_SALT_AND_PAD +
keylen + alignment) >> 4; keylen + alignment) >> 4;
...@@ -1172,13 +1165,20 @@ static int chcr_aes_xts_setkey(struct crypto_ablkcipher *tfm, const u8 *key, ...@@ -1172,13 +1165,20 @@ static int chcr_aes_xts_setkey(struct crypto_ablkcipher *tfm, const u8 *key,
{ {
struct chcr_context *ctx = crypto_ablkcipher_ctx(tfm); struct chcr_context *ctx = crypto_ablkcipher_ctx(tfm);
struct ablk_ctx *ablkctx = ABLK_CTX(ctx); struct ablk_ctx *ablkctx = ABLK_CTX(ctx);
int status = 0;
unsigned short context_size = 0; unsigned short context_size = 0;
if ((key_len == (AES_KEYSIZE_128 << 1)) || if ((key_len != (AES_KEYSIZE_128 << 1)) &&
(key_len == (AES_KEYSIZE_256 << 1))) { (key_len != (AES_KEYSIZE_256 << 1))) {
crypto_tfm_set_flags((struct crypto_tfm *)tfm,
CRYPTO_TFM_RES_BAD_KEY_LEN);
ablkctx->enckey_len = 0;
return -EINVAL;
}
memcpy(ablkctx->key, key, key_len); memcpy(ablkctx->key, key, key_len);
ablkctx->enckey_len = key_len; ablkctx->enckey_len = key_len;
get_aes_decrypt_key(ablkctx->rrkey, ablkctx->key, key_len << 2);
context_size = (KEY_CONTEXT_HDR_SALT_AND_PAD + key_len) >> 4; context_size = (KEY_CONTEXT_HDR_SALT_AND_PAD + key_len) >> 4;
ablkctx->key_ctx_hdr = ablkctx->key_ctx_hdr =
FILL_KEY_CTX_HDR((key_len == AES_KEYSIZE_256) ? FILL_KEY_CTX_HDR((key_len == AES_KEYSIZE_256) ?
...@@ -1187,13 +1187,7 @@ static int chcr_aes_xts_setkey(struct crypto_ablkcipher *tfm, const u8 *key, ...@@ -1187,13 +1187,7 @@ static int chcr_aes_xts_setkey(struct crypto_ablkcipher *tfm, const u8 *key,
CHCR_KEYCTX_NO_KEY, 1, CHCR_KEYCTX_NO_KEY, 1,
0, context_size); 0, context_size);
ablkctx->ciph_mode = CHCR_SCMD_CIPHER_MODE_AES_XTS; ablkctx->ciph_mode = CHCR_SCMD_CIPHER_MODE_AES_XTS;
} else { return 0;
crypto_tfm_set_flags((struct crypto_tfm *)tfm,
CRYPTO_TFM_RES_BAD_KEY_LEN);
ablkctx->enckey_len = 0;
status = -EINVAL;
}
return status;
} }
static int chcr_sha_init(struct ahash_request *areq) static int chcr_sha_init(struct ahash_request *areq)
......
...@@ -125,8 +125,8 @@ struct ablk_ctx { ...@@ -125,8 +125,8 @@ struct ablk_ctx {
__be32 key_ctx_hdr; __be32 key_ctx_hdr;
unsigned int enckey_len; unsigned int enckey_len;
unsigned int dst_nents; unsigned int dst_nents;
struct scatterlist iv_sg;
u8 key[CHCR_AES_MAX_KEY_LEN]; u8 key[CHCR_AES_MAX_KEY_LEN];
u8 rrkey[AES_MAX_KEY_SIZE];
u8 iv[CHCR_MAX_CRYPTO_IV_LEN]; u8 iv[CHCR_MAX_CRYPTO_IV_LEN];
unsigned char ciph_mode; unsigned char ciph_mode;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment