diff options
author | Catalin Vasile <catalin.vasile@freescale.com> | 2014-10-31 06:45:35 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2014-11-06 10:15:04 -0500 |
commit | 2b22f6c547f90e1a41e3f39ad8d569e3efc74d42 (patch) | |
tree | 8dd1cf11a1a5069f4e3eb3df38e4af40c6f63835 /drivers/crypto/caam/caamalg.c | |
parent | 5d0429a30f06845af78a696de59e3e8d21252846 (diff) |
crypto: caam - add support for ctr(aes)
Add support for AES working in Counter Mode
Signed-off-by: Catalin Vasile <catalin.vasile@freescale.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/crypto/caam/caamalg.c')
-rw-r--r-- | drivers/crypto/caam/caamalg.c | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c index 48df0520ed46..2dc85f8304bb 100644 --- a/drivers/crypto/caam/caamalg.c +++ b/drivers/crypto/caam/caamalg.c | |||
@@ -1740,11 +1740,21 @@ static int ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher, | |||
1740 | int ret = 0; | 1740 | int ret = 0; |
1741 | u32 *key_jump_cmd; | 1741 | u32 *key_jump_cmd; |
1742 | u32 *desc; | 1742 | u32 *desc; |
1743 | u32 ctx1_iv_off = 0; | ||
1744 | const bool ctr_mode = ((ctx->class1_alg_type & OP_ALG_AAI_MASK) == | ||
1745 | OP_ALG_AAI_CTR_MOD128); | ||
1743 | 1746 | ||
1744 | #ifdef DEBUG | 1747 | #ifdef DEBUG |
1745 | print_hex_dump(KERN_ERR, "key in @"__stringify(__LINE__)": ", | 1748 | print_hex_dump(KERN_ERR, "key in @"__stringify(__LINE__)": ", |
1746 | DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1); | 1749 | DUMP_PREFIX_ADDRESS, 16, 4, key, keylen, 1); |
1747 | #endif | 1750 | #endif |
1751 | /* | ||
1752 | * AES-CTR needs to load IV in CONTEXT1 reg | ||
1753 | * at an offset of 128bits (16bytes) | ||
1754 | * CONTEXT1[255:128] = IV | ||
1755 | */ | ||
1756 | if (ctr_mode) | ||
1757 | ctx1_iv_off = 16; | ||
1748 | 1758 | ||
1749 | memcpy(ctx->key, key, keylen); | 1759 | memcpy(ctx->key, key, keylen); |
1750 | ctx->key_dma = dma_map_single(jrdev, ctx->key, keylen, | 1760 | ctx->key_dma = dma_map_single(jrdev, ctx->key, keylen, |
@@ -1770,8 +1780,8 @@ static int ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher, | |||
1770 | set_jump_tgt_here(desc, key_jump_cmd); | 1780 | set_jump_tgt_here(desc, key_jump_cmd); |
1771 | 1781 | ||
1772 | /* Load iv */ | 1782 | /* Load iv */ |
1773 | append_cmd(desc, CMD_SEQ_LOAD | LDST_SRCDST_BYTE_CONTEXT | | 1783 | append_seq_load(desc, tfm->ivsize, LDST_SRCDST_BYTE_CONTEXT | |
1774 | LDST_CLASS_1_CCB | tfm->ivsize); | 1784 | LDST_CLASS_1_CCB | (ctx1_iv_off << LDST_OFFSET_SHIFT)); |
1775 | 1785 | ||
1776 | /* Load operation */ | 1786 | /* Load operation */ |
1777 | append_operation(desc, ctx->class1_alg_type | | 1787 | append_operation(desc, ctx->class1_alg_type | |
@@ -1809,11 +1819,15 @@ static int ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher, | |||
1809 | set_jump_tgt_here(desc, key_jump_cmd); | 1819 | set_jump_tgt_here(desc, key_jump_cmd); |
1810 | 1820 | ||
1811 | /* load IV */ | 1821 | /* load IV */ |
1812 | append_cmd(desc, CMD_SEQ_LOAD | LDST_SRCDST_BYTE_CONTEXT | | 1822 | append_seq_load(desc, tfm->ivsize, LDST_SRCDST_BYTE_CONTEXT | |
1813 | LDST_CLASS_1_CCB | tfm->ivsize); | 1823 | LDST_CLASS_1_CCB | (ctx1_iv_off << LDST_OFFSET_SHIFT)); |
1814 | 1824 | ||
1815 | /* Choose operation */ | 1825 | /* Choose operation */ |
1816 | append_dec_op1(desc, ctx->class1_alg_type); | 1826 | if (ctr_mode) |
1827 | append_operation(desc, ctx->class1_alg_type | | ||
1828 | OP_ALG_AS_INITFINAL | OP_ALG_DECRYPT); | ||
1829 | else | ||
1830 | append_dec_op1(desc, ctx->class1_alg_type); | ||
1817 | 1831 | ||
1818 | /* Perform operation */ | 1832 | /* Perform operation */ |
1819 | ablkcipher_append_src_dst(desc); | 1833 | ablkcipher_append_src_dst(desc); |
@@ -3533,6 +3547,22 @@ static struct caam_alg_template driver_algs[] = { | |||
3533 | .ivsize = DES_BLOCK_SIZE, | 3547 | .ivsize = DES_BLOCK_SIZE, |
3534 | }, | 3548 | }, |
3535 | .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC, | 3549 | .class1_alg_type = OP_ALG_ALGSEL_DES | OP_ALG_AAI_CBC, |
3550 | }, | ||
3551 | { | ||
3552 | .name = "ctr(aes)", | ||
3553 | .driver_name = "ctr-aes-caam", | ||
3554 | .blocksize = 1, | ||
3555 | .type = CRYPTO_ALG_TYPE_ABLKCIPHER, | ||
3556 | .template_ablkcipher = { | ||
3557 | .setkey = ablkcipher_setkey, | ||
3558 | .encrypt = ablkcipher_encrypt, | ||
3559 | .decrypt = ablkcipher_decrypt, | ||
3560 | .geniv = "chainiv", | ||
3561 | .min_keysize = AES_MIN_KEY_SIZE, | ||
3562 | .max_keysize = AES_MAX_KEY_SIZE, | ||
3563 | .ivsize = AES_BLOCK_SIZE, | ||
3564 | }, | ||
3565 | .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CTR_MOD128, | ||
3536 | } | 3566 | } |
3537 | }; | 3567 | }; |
3538 | 3568 | ||