forked from Minki/linux
Crypto/chcr: support for 48 byte key_len in aes-xts
Added support for 48 byte key length for aes-xts. Signed-off-by: Ayush Sawal <ayush.sawal@chelsio.com> Signed-off-by: Devulapally Shiva Krishna <shiva@chelsio.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
10b0c75d7b
commit
ee91ac1b11
@ -1077,6 +1077,13 @@ static int chcr_update_tweak(struct skcipher_request *req, u8 *iv,
|
|||||||
|
|
||||||
keylen = ablkctx->enckey_len / 2;
|
keylen = ablkctx->enckey_len / 2;
|
||||||
key = ablkctx->key + keylen;
|
key = ablkctx->key + keylen;
|
||||||
|
/* For a 192 bit key remove the padded zeroes which was
|
||||||
|
* added in chcr_xts_setkey
|
||||||
|
*/
|
||||||
|
if (KEY_CONTEXT_CK_SIZE_G(ntohl(ablkctx->key_ctx_hdr))
|
||||||
|
== CHCR_KEYCTX_CIPHER_KEY_SIZE_192)
|
||||||
|
ret = aes_expandkey(&aes, key, keylen - 8);
|
||||||
|
else
|
||||||
ret = aes_expandkey(&aes, key, keylen);
|
ret = aes_expandkey(&aes, key, keylen);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
@ -2264,12 +2271,28 @@ static int chcr_aes_xts_setkey(struct crypto_skcipher *cipher, const u8 *key,
|
|||||||
ablkctx->enckey_len = key_len;
|
ablkctx->enckey_len = key_len;
|
||||||
get_aes_decrypt_key(ablkctx->rrkey, ablkctx->key, key_len << 2);
|
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;
|
||||||
|
/* Both keys for xts must be aligned to 16 byte boundary
|
||||||
|
* by padding with zeros. So for 24 byte keys padding 8 zeroes.
|
||||||
|
*/
|
||||||
|
if (key_len == 48) {
|
||||||
|
context_size = (KEY_CONTEXT_HDR_SALT_AND_PAD + key_len
|
||||||
|
+ 16) >> 4;
|
||||||
|
memmove(ablkctx->key + 32, ablkctx->key + 24, 24);
|
||||||
|
memset(ablkctx->key + 24, 0, 8);
|
||||||
|
memset(ablkctx->key + 56, 0, 8);
|
||||||
|
ablkctx->enckey_len = 64;
|
||||||
|
ablkctx->key_ctx_hdr =
|
||||||
|
FILL_KEY_CTX_HDR(CHCR_KEYCTX_CIPHER_KEY_SIZE_192,
|
||||||
|
CHCR_KEYCTX_NO_KEY, 1,
|
||||||
|
0, context_size);
|
||||||
|
} else {
|
||||||
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) ?
|
||||||
CHCR_KEYCTX_CIPHER_KEY_SIZE_128 :
|
CHCR_KEYCTX_CIPHER_KEY_SIZE_128 :
|
||||||
CHCR_KEYCTX_CIPHER_KEY_SIZE_256,
|
CHCR_KEYCTX_CIPHER_KEY_SIZE_256,
|
||||||
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;
|
||||||
return 0;
|
return 0;
|
||||||
badkey_err:
|
badkey_err:
|
||||||
|
Loading…
Reference in New Issue
Block a user