summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWinston Hudson (b45308) <winston.h.hudson@freescale.com>2013-06-26 20:37:17 -0700
committerNitin Garg <nitin.garg@freescale.com>2015-01-15 21:19:56 -0600
commite4d16698b46a8d0217290ac7a81d85f83c18432f (patch)
tree0a90f830ca1f877832f405caaf4b0d8b28ae8f92
parent4aa8258ead96b9f2fbcab67e8b1673f24ad27955 (diff)
MLK-9769-13 Add AES-CTR support for CAAM in i.MX6 family
Adds AES-CTR (Counter Mode) support to the CAAM crypto accelerator core in the i.MX6 family of SoC devices. Note that CAAM also goes by sec-4.0 or sec-5.0 in other product families (such as QorIQ). Thus the property names are often tied to the sec-4.0+ nomenclature. [<vicki.milhoan@freescale.com>: Edited to apply to 3.14] Signed-off-by: Winston Hudson (b45308) <winston.h.hudson@freescale.com> Signed-off-by: Victoria Milhoan <vicki.milhoan@freescale.com>
-rw-r--r--drivers/crypto/caam/caamalg.c47
1 files changed, 39 insertions, 8 deletions
diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c
index 905f95c64951..9cc2c706a5e9 100644
--- a/drivers/crypto/caam/caamalg.c
+++ b/drivers/crypto/caam/caamalg.c
@@ -53,6 +53,7 @@
#include "error.h"
#include "sg_sw_sec4.h"
#include "key_gen.h"
+#include <linux/string.h>
/*
* crypto alg
@@ -577,10 +578,15 @@ static int ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher,
/* Propagate errors from shared to job descriptor */
append_cmd(desc, SET_OK_NO_PROP_ERRORS | CMD_LOAD);
- /* Load iv */
- append_cmd(desc, CMD_SEQ_LOAD | LDST_SRCDST_BYTE_CONTEXT |
- LDST_CLASS_1_CCB | tfm->ivsize);
-
+ /* load IV */
+ if (strncmp(ablkcipher->base.__crt_alg->cra_name, "ctr(aes)", 8) == 0) {
+ append_cmd(desc, CMD_SEQ_LOAD | LDST_SRCDST_BYTE_CONTEXT |
+ LDST_CLASS_1_CCB | tfm->ivsize |
+ (16 << LDST_OFFSET_SHIFT));
+ } else {
+ append_cmd(desc, CMD_SEQ_LOAD | LDST_SRCDST_BYTE_CONTEXT |
+ LDST_CLASS_1_CCB | tfm->ivsize);
+ }
/* Load operation */
append_operation(desc, ctx->class1_alg_type |
OP_ALG_AS_INITFINAL | OP_ALG_ENCRYPT);
@@ -624,11 +630,20 @@ static int ablkcipher_setkey(struct crypto_ablkcipher *ablkcipher,
set_jump_tgt_here(desc, jump_cmd);
/* load IV */
- append_cmd(desc, CMD_SEQ_LOAD | LDST_SRCDST_BYTE_CONTEXT |
- LDST_CLASS_1_CCB | tfm->ivsize);
+ if (strncmp(ablkcipher->base.__crt_alg->cra_name, "ctr(aes)", 8) == 0) {
+ append_cmd(desc, CMD_SEQ_LOAD | LDST_SRCDST_BYTE_CONTEXT |
+ LDST_CLASS_1_CCB | tfm->ivsize |
+ (16 << LDST_OFFSET_SHIFT));
- /* Choose operation */
- append_dec_op1(desc, ctx->class1_alg_type);
+ append_operation(desc, ctx->class1_alg_type |
+ OP_ALG_AS_INITFINAL | OP_ALG_DECRYPT);
+ } else {
+ append_cmd(desc, CMD_SEQ_LOAD | LDST_SRCDST_BYTE_CONTEXT |
+ LDST_CLASS_1_CCB | tfm->ivsize);
+
+ /* Choose operation */
+ append_dec_op1(desc, ctx->class1_alg_type);
+ }
/* Perform operation */
ablkcipher_append_src_dst(desc);
@@ -2032,6 +2047,22 @@ static struct caam_alg_template driver_algs[] = {
},
/* ablkcipher descriptor */
{
+ .name = "ctr(aes)",
+ .driver_name = "ctr-aes-caam",
+ .blocksize = AES_BLOCK_SIZE,
+ .type = CRYPTO_ALG_TYPE_ABLKCIPHER,
+ .template_ablkcipher = {
+ .setkey = ablkcipher_setkey,
+ .encrypt = ablkcipher_encrypt,
+ .decrypt = ablkcipher_decrypt,
+ .geniv = "eseqiv",
+ .min_keysize = AES_MIN_KEY_SIZE,
+ .max_keysize = AES_MAX_KEY_SIZE,
+ .ivsize = AES_BLOCK_SIZE,
+ },
+ .class1_alg_type = OP_ALG_ALGSEL_AES | OP_ALG_AAI_CTR_MOD128,
+ },
+ {
.name = "cbc(aes)",
.driver_name = "cbc-aes-caam",
.blocksize = AES_BLOCK_SIZE,