aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/crypto
diff options
context:
space:
mode:
authorYuan Kang <Yuan.Kang@freescale.com>2011-07-14 23:21:41 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2011-07-14 23:21:41 -0400
commit885e9e2fd3f009de56dd265f4ecd8740e9ad5aaa (patch)
tree0587f587cd5a74f459474cfe82e3350ef798183b /drivers/crypto
parent0e47930020081b07047842be3e4552edb2395352 (diff)
crypto: caam - structure renaming
caam_ctx.key_phys to key_dma caam_alg_template supports multiple algorithm types listed in union, which requires cases for different types in function caam_alg_alloc Signed-off-by: Yuan Kang <Yuan.Kang@freescale.com> Signed-off-by: Kim Phillips <kim.phillips@freescale.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/crypto')
-rw-r--r--drivers/crypto/caam/caamalg.c64
1 files changed, 43 insertions, 21 deletions
diff --git a/drivers/crypto/caam/caamalg.c b/drivers/crypto/caam/caamalg.c
index 4786a204633b..403b293509ba 100644
--- a/drivers/crypto/caam/caamalg.c
+++ b/drivers/crypto/caam/caamalg.c
@@ -87,7 +87,7 @@ struct caam_ctx {
87 u32 class2_alg_type; 87 u32 class2_alg_type;
88 u32 alg_op; 88 u32 alg_op;
89 u8 *key; 89 u8 *key;
90 dma_addr_t key_phys; 90 dma_addr_t key_dma;
91 unsigned int enckeylen; 91 unsigned int enckeylen;
92 unsigned int split_key_len; 92 unsigned int split_key_len;
93 unsigned int split_key_pad_len; 93 unsigned int split_key_pad_len;
@@ -263,9 +263,9 @@ static int build_sh_desc_ipsec(struct caam_ctx *ctx)
263 ctx->split_key_pad_len, ctx->enckeylen, 263 ctx->split_key_pad_len, ctx->enckeylen,
264 ctx->enckeylen, CLASS_1 | KEY_DEST_CLASS_REG); 264 ctx->enckeylen, CLASS_1 | KEY_DEST_CLASS_REG);
265 } else { 265 } else {
266 append_key(sh_desc, ctx->key_phys, ctx->split_key_len, CLASS_2 | 266 append_key(sh_desc, ctx->key_dma, ctx->split_key_len, CLASS_2 |
267 KEY_DEST_MDHA_SPLIT | KEY_ENC); 267 KEY_DEST_MDHA_SPLIT | KEY_ENC);
268 append_key(sh_desc, ctx->key_phys + ctx->split_key_pad_len, 268 append_key(sh_desc, ctx->key_dma + ctx->split_key_pad_len,
269 ctx->enckeylen, CLASS_1 | KEY_DEST_CLASS_REG); 269 ctx->enckeylen, CLASS_1 | KEY_DEST_CLASS_REG);
270 } 270 }
271 271
@@ -342,9 +342,9 @@ static int aead_setkey(struct crypto_aead *aead,
342 /* postpend encryption key to auth split key */ 342 /* postpend encryption key to auth split key */
343 memcpy(ctx->key + ctx->split_key_pad_len, key + authkeylen, enckeylen); 343 memcpy(ctx->key + ctx->split_key_pad_len, key + authkeylen, enckeylen);
344 344
345 ctx->key_phys = dma_map_single(jrdev, ctx->key, ctx->split_key_pad_len + 345 ctx->key_dma = dma_map_single(jrdev, ctx->key, ctx->split_key_pad_len +
346 enckeylen, DMA_TO_DEVICE); 346 enckeylen, DMA_TO_DEVICE);
347 if (dma_mapping_error(jrdev, ctx->key_phys)) { 347 if (dma_mapping_error(jrdev, ctx->key_dma)) {
348 dev_err(jrdev, "unable to map key i/o memory\n"); 348 dev_err(jrdev, "unable to map key i/o memory\n");
349 kfree(ctx->key); 349 kfree(ctx->key);
350 return -ENOMEM; 350 return -ENOMEM;
@@ -359,7 +359,7 @@ static int aead_setkey(struct crypto_aead *aead,
359 359
360 ret = build_sh_desc_ipsec(ctx); 360 ret = build_sh_desc_ipsec(ctx);
361 if (ret) { 361 if (ret) {
362 dma_unmap_single(jrdev, ctx->key_phys, ctx->split_key_pad_len + 362 dma_unmap_single(jrdev, ctx->key_dma, ctx->split_key_pad_len +
363 enckeylen, DMA_TO_DEVICE); 363 enckeylen, DMA_TO_DEVICE);
364 kfree(ctx->key); 364 kfree(ctx->key);
365 } 365 }
@@ -884,11 +884,20 @@ static int aead_givencrypt(struct aead_givcrypt_request *areq)
884 return init_aead_job(edesc, req, OP_ALG_ENCRYPT, aead_encrypt_done); 884 return init_aead_job(edesc, req, OP_ALG_ENCRYPT, aead_encrypt_done);
885} 885}
886 886
887#define template_aead template_u.aead
887struct caam_alg_template { 888struct caam_alg_template {
888 char name[CRYPTO_MAX_ALG_NAME]; 889 char name[CRYPTO_MAX_ALG_NAME];
889 char driver_name[CRYPTO_MAX_ALG_NAME]; 890 char driver_name[CRYPTO_MAX_ALG_NAME];
890 unsigned int blocksize; 891 unsigned int blocksize;
891 struct aead_alg aead; 892 u32 type;
893 union {
894 struct ablkcipher_alg ablkcipher;
895 struct aead_alg aead;
896 struct blkcipher_alg blkcipher;
897 struct cipher_alg cipher;
898 struct compress_alg compress;
899 struct rng_alg rng;
900 } template_u;
892 u32 class1_alg_type; 901 u32 class1_alg_type;
893 u32 class2_alg_type; 902 u32 class2_alg_type;
894 u32 alg_op; 903 u32 alg_op;
@@ -900,7 +909,8 @@ static struct caam_alg_template driver_algs[] = {
900 .name = "authenc(hmac(sha1),cbc(aes))", 909 .name = "authenc(hmac(sha1),cbc(aes))",
901 .driver_name = "authenc-hmac-sha1-cbc-aes-caam", 910 .driver_name = "authenc-hmac-sha1-cbc-aes-caam",
902 .blocksize = AES_BLOCK_SIZE, 911 .blocksize = AES_BLOCK_SIZE,
903 .aead = { 912 .type = CRYPTO_ALG_TYPE_AEAD,
913 .template_aead = {
904 .setkey = aead_setkey, 914 .setkey = aead_setkey,
905 .setauthsize = aead_setauthsize, 915 .setauthsize = aead_setauthsize,
906 .encrypt = aead_encrypt, 916 .encrypt = aead_encrypt,
@@ -918,7 +928,8 @@ static struct caam_alg_template driver_algs[] = {
918 .name = "authenc(hmac(sha256),cbc(aes))", 928 .name = "authenc(hmac(sha256),cbc(aes))",
919 .driver_name = "authenc-hmac-sha256-cbc-aes-caam", 929 .driver_name = "authenc-hmac-sha256-cbc-aes-caam",
920 .blocksize = AES_BLOCK_SIZE, 930 .blocksize = AES_BLOCK_SIZE,
921 .aead = { 931 .type = CRYPTO_ALG_TYPE_AEAD,
932 .template_aead = {
922 .setkey = aead_setkey, 933 .setkey = aead_setkey,
923 .setauthsize = aead_setauthsize, 934 .setauthsize = aead_setauthsize,
924 .encrypt = aead_encrypt, 935 .encrypt = aead_encrypt,
@@ -937,7 +948,8 @@ static struct caam_alg_template driver_algs[] = {
937 .name = "authenc(hmac(sha512),cbc(aes))", 948 .name = "authenc(hmac(sha512),cbc(aes))",
938 .driver_name = "authenc-hmac-sha512-cbc-aes-caam", 949 .driver_name = "authenc-hmac-sha512-cbc-aes-caam",
939 .blocksize = AES_BLOCK_SIZE, 950 .blocksize = AES_BLOCK_SIZE,
940 .aead = { 951 .type = CRYPTO_ALG_TYPE_AEAD,
952 .template_aead = {
941 .setkey = aead_setkey, 953 .setkey = aead_setkey,
942 .setauthsize = aead_setauthsize, 954 .setauthsize = aead_setauthsize,
943 .encrypt = aead_encrypt, 955 .encrypt = aead_encrypt,
@@ -956,7 +968,8 @@ static struct caam_alg_template driver_algs[] = {
956 .name = "authenc(hmac(sha1),cbc(des3_ede))", 968 .name = "authenc(hmac(sha1),cbc(des3_ede))",
957 .driver_name = "authenc-hmac-sha1-cbc-des3_ede-caam", 969 .driver_name = "authenc-hmac-sha1-cbc-des3_ede-caam",
958 .blocksize = DES3_EDE_BLOCK_SIZE, 970 .blocksize = DES3_EDE_BLOCK_SIZE,
959 .aead = { 971 .type = CRYPTO_ALG_TYPE_AEAD,
972 .template_aead = {
960 .setkey = aead_setkey, 973 .setkey = aead_setkey,
961 .setauthsize = aead_setauthsize, 974 .setauthsize = aead_setauthsize,
962 .encrypt = aead_encrypt, 975 .encrypt = aead_encrypt,
@@ -974,7 +987,8 @@ static struct caam_alg_template driver_algs[] = {
974 .name = "authenc(hmac(sha256),cbc(des3_ede))", 987 .name = "authenc(hmac(sha256),cbc(des3_ede))",
975 .driver_name = "authenc-hmac-sha256-cbc-des3_ede-caam", 988 .driver_name = "authenc-hmac-sha256-cbc-des3_ede-caam",
976 .blocksize = DES3_EDE_BLOCK_SIZE, 989 .blocksize = DES3_EDE_BLOCK_SIZE,
977 .aead = { 990 .type = CRYPTO_ALG_TYPE_AEAD,
991 .template_aead = {
978 .setkey = aead_setkey, 992 .setkey = aead_setkey,
979 .setauthsize = aead_setauthsize, 993 .setauthsize = aead_setauthsize,
980 .encrypt = aead_encrypt, 994 .encrypt = aead_encrypt,
@@ -993,7 +1007,8 @@ static struct caam_alg_template driver_algs[] = {
993 .name = "authenc(hmac(sha512),cbc(des3_ede))", 1007 .name = "authenc(hmac(sha512),cbc(des3_ede))",
994 .driver_name = "authenc-hmac-sha512-cbc-des3_ede-caam", 1008 .driver_name = "authenc-hmac-sha512-cbc-des3_ede-caam",
995 .blocksize = DES3_EDE_BLOCK_SIZE, 1009 .blocksize = DES3_EDE_BLOCK_SIZE,
996 .aead = { 1010 .type = CRYPTO_ALG_TYPE_AEAD,
1011 .template_aead = {
997 .setkey = aead_setkey, 1012 .setkey = aead_setkey,
998 .setauthsize = aead_setauthsize, 1013 .setauthsize = aead_setauthsize,
999 .encrypt = aead_encrypt, 1014 .encrypt = aead_encrypt,
@@ -1012,7 +1027,8 @@ static struct caam_alg_template driver_algs[] = {
1012 .name = "authenc(hmac(sha1),cbc(des))", 1027 .name = "authenc(hmac(sha1),cbc(des))",
1013 .driver_name = "authenc-hmac-sha1-cbc-des-caam", 1028 .driver_name = "authenc-hmac-sha1-cbc-des-caam",
1014 .blocksize = DES_BLOCK_SIZE, 1029 .blocksize = DES_BLOCK_SIZE,
1015 .aead = { 1030 .type = CRYPTO_ALG_TYPE_AEAD,
1031 .template_aead = {
1016 .setkey = aead_setkey, 1032 .setkey = aead_setkey,
1017 .setauthsize = aead_setauthsize, 1033 .setauthsize = aead_setauthsize,
1018 .encrypt = aead_encrypt, 1034 .encrypt = aead_encrypt,
@@ -1030,7 +1046,8 @@ static struct caam_alg_template driver_algs[] = {
1030 .name = "authenc(hmac(sha256),cbc(des))", 1046 .name = "authenc(hmac(sha256),cbc(des))",
1031 .driver_name = "authenc-hmac-sha256-cbc-des-caam", 1047 .driver_name = "authenc-hmac-sha256-cbc-des-caam",
1032 .blocksize = DES_BLOCK_SIZE, 1048 .blocksize = DES_BLOCK_SIZE,
1033 .aead = { 1049 .type = CRYPTO_ALG_TYPE_AEAD,
1050 .template_aead = {
1034 .setkey = aead_setkey, 1051 .setkey = aead_setkey,
1035 .setauthsize = aead_setauthsize, 1052 .setauthsize = aead_setauthsize,
1036 .encrypt = aead_encrypt, 1053 .encrypt = aead_encrypt,
@@ -1049,7 +1066,8 @@ static struct caam_alg_template driver_algs[] = {
1049 .name = "authenc(hmac(sha512),cbc(des))", 1066 .name = "authenc(hmac(sha512),cbc(des))",
1050 .driver_name = "authenc-hmac-sha512-cbc-des-caam", 1067 .driver_name = "authenc-hmac-sha512-cbc-des-caam",
1051 .blocksize = DES_BLOCK_SIZE, 1068 .blocksize = DES_BLOCK_SIZE,
1052 .aead = { 1069 .type = CRYPTO_ALG_TYPE_AEAD,
1070 .template_aead = {
1053 .setkey = aead_setkey, 1071 .setkey = aead_setkey,
1054 .setauthsize = aead_setauthsize, 1072 .setauthsize = aead_setauthsize,
1055 .encrypt = aead_encrypt, 1073 .encrypt = aead_encrypt,
@@ -1107,8 +1125,8 @@ static void caam_cra_exit(struct crypto_tfm *tfm)
1107 desc_bytes(ctx->sh_desc), DMA_TO_DEVICE); 1125 desc_bytes(ctx->sh_desc), DMA_TO_DEVICE);
1108 kfree(ctx->sh_desc); 1126 kfree(ctx->sh_desc);
1109 1127
1110 if (!dma_mapping_error(ctx->jrdev, ctx->key_phys)) 1128 if (!dma_mapping_error(ctx->jrdev, ctx->key_dma))
1111 dma_unmap_single(ctx->jrdev, ctx->key_phys, 1129 dma_unmap_single(ctx->jrdev, ctx->key_dma,
1112 ctx->split_key_pad_len + ctx->enckeylen, 1130 ctx->split_key_pad_len + ctx->enckeylen,
1113 DMA_TO_DEVICE); 1131 DMA_TO_DEVICE);
1114 kfree(ctx->key); 1132 kfree(ctx->key);
@@ -1175,12 +1193,16 @@ static struct caam_crypto_alg *caam_alg_alloc(struct device *ctrldev,
1175 alg->cra_init = caam_cra_init; 1193 alg->cra_init = caam_cra_init;
1176 alg->cra_exit = caam_cra_exit; 1194 alg->cra_exit = caam_cra_exit;
1177 alg->cra_priority = CAAM_CRA_PRIORITY; 1195 alg->cra_priority = CAAM_CRA_PRIORITY;
1178 alg->cra_flags = CRYPTO_ALG_TYPE_AEAD | CRYPTO_ALG_ASYNC;
1179 alg->cra_blocksize = template->blocksize; 1196 alg->cra_blocksize = template->blocksize;
1180 alg->cra_alignmask = 0; 1197 alg->cra_alignmask = 0;
1181 alg->cra_type = &crypto_aead_type;
1182 alg->cra_ctxsize = sizeof(struct caam_ctx); 1198 alg->cra_ctxsize = sizeof(struct caam_ctx);
1183 alg->cra_u.aead = template->aead; 1199 alg->cra_flags = CRYPTO_ALG_ASYNC | template->type;
1200 switch (template->type) {
1201 case CRYPTO_ALG_TYPE_AEAD:
1202 alg->cra_type = &crypto_aead_type;
1203 alg->cra_aead = template->template_aead;
1204 break;
1205 }
1184 1206
1185 t_alg->class1_alg_type = template->class1_alg_type; 1207 t_alg->class1_alg_type = template->class1_alg_type;
1186 t_alg->class2_alg_type = template->class2_alg_type; 1208 t_alg->class2_alg_type = template->class2_alg_type;