Commit 4dc10c0142ce0af8c20ec44dc6928ae63ad4f73a
1 parent
0b535adfb1
Exists in
master
and in
4 other branches
crypto: crypto4xx - Switch to new style ahash
This patch changes crypto4xx to use the new style ahash type. In particular, we now use ahash_alg to define ahash algorithms instead of crypto_alg. This is achieved by introducing a union that encapsulates the new type and the existing crypto_alg structure. They're told apart through a u32 field containing the type value. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Showing 3 changed files with 77 additions and 39 deletions Side-by-side Diff
drivers/crypto/amcc/crypto4xx_core.c
... | ... | @@ -31,8 +31,6 @@ |
31 | 31 | #include <asm/dcr.h> |
32 | 32 | #include <asm/dcr-regs.h> |
33 | 33 | #include <asm/cacheflush.h> |
34 | -#include <crypto/internal/hash.h> | |
35 | -#include <crypto/algapi.h> | |
36 | 34 | #include <crypto/aes.h> |
37 | 35 | #include <crypto/sha.h> |
38 | 36 | #include "crypto4xx_reg_def.h" |
39 | 37 | |
40 | 38 | |
... | ... | @@ -998,11 +996,15 @@ |
998 | 996 | ctx->sa_out_dma_addr = 0; |
999 | 997 | ctx->sa_len = 0; |
1000 | 998 | |
1001 | - if (alg->cra_type == &crypto_ablkcipher_type) | |
999 | + switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) { | |
1000 | + default: | |
1002 | 1001 | tfm->crt_ablkcipher.reqsize = sizeof(struct crypto4xx_ctx); |
1003 | - else if (alg->cra_type == &crypto_ahash_type) | |
1002 | + break; | |
1003 | + case CRYPTO_ALG_TYPE_AHASH: | |
1004 | 1004 | crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm), |
1005 | 1005 | sizeof(struct crypto4xx_ctx)); |
1006 | + break; | |
1007 | + } | |
1006 | 1008 | |
1007 | 1009 | return 0; |
1008 | 1010 | } |
... | ... | @@ -1016,7 +1018,8 @@ |
1016 | 1018 | } |
1017 | 1019 | |
1018 | 1020 | int crypto4xx_register_alg(struct crypto4xx_device *sec_dev, |
1019 | - struct crypto_alg *crypto_alg, int array_size) | |
1021 | + struct crypto4xx_alg_common *crypto_alg, | |
1022 | + int array_size) | |
1020 | 1023 | { |
1021 | 1024 | struct crypto4xx_alg *alg; |
1022 | 1025 | int i; |
1023 | 1026 | |
... | ... | @@ -1028,13 +1031,18 @@ |
1028 | 1031 | return -ENOMEM; |
1029 | 1032 | |
1030 | 1033 | alg->alg = crypto_alg[i]; |
1031 | - INIT_LIST_HEAD(&alg->alg.cra_list); | |
1032 | - if (alg->alg.cra_init == NULL) | |
1033 | - alg->alg.cra_init = crypto4xx_alg_init; | |
1034 | - if (alg->alg.cra_exit == NULL) | |
1035 | - alg->alg.cra_exit = crypto4xx_alg_exit; | |
1036 | 1034 | alg->dev = sec_dev; |
1037 | - rc = crypto_register_alg(&alg->alg); | |
1035 | + | |
1036 | + switch (alg->alg.type) { | |
1037 | + case CRYPTO_ALG_TYPE_AHASH: | |
1038 | + rc = crypto_register_ahash(&alg->alg.u.hash); | |
1039 | + break; | |
1040 | + | |
1041 | + default: | |
1042 | + rc = crypto_register_alg(&alg->alg.u.cipher); | |
1043 | + break; | |
1044 | + } | |
1045 | + | |
1038 | 1046 | if (rc) { |
1039 | 1047 | list_del(&alg->entry); |
1040 | 1048 | kfree(alg); |
... | ... | @@ -1052,7 +1060,14 @@ |
1052 | 1060 | |
1053 | 1061 | list_for_each_entry_safe(alg, tmp, &sec_dev->alg_list, entry) { |
1054 | 1062 | list_del(&alg->entry); |
1055 | - crypto_unregister_alg(&alg->alg); | |
1063 | + switch (alg->alg.type) { | |
1064 | + case CRYPTO_ALG_TYPE_AHASH: | |
1065 | + crypto_unregister_ahash(&alg->alg.u.hash); | |
1066 | + break; | |
1067 | + | |
1068 | + default: | |
1069 | + crypto_unregister_alg(&alg->alg.u.cipher); | |
1070 | + } | |
1056 | 1071 | kfree(alg); |
1057 | 1072 | } |
1058 | 1073 | } |
1059 | 1074 | |
1060 | 1075 | |
1061 | 1076 | |
... | ... | @@ -1105,17 +1120,18 @@ |
1105 | 1120 | /** |
1106 | 1121 | * Supported Crypto Algorithms |
1107 | 1122 | */ |
1108 | -struct crypto_alg crypto4xx_alg[] = { | |
1123 | +struct crypto4xx_alg_common crypto4xx_alg[] = { | |
1109 | 1124 | /* Crypto AES modes */ |
1110 | - { | |
1125 | + { .type = CRYPTO_ALG_TYPE_ABLKCIPHER, .u.cipher = { | |
1111 | 1126 | .cra_name = "cbc(aes)", |
1112 | 1127 | .cra_driver_name = "cbc-aes-ppc4xx", |
1113 | 1128 | .cra_priority = CRYPTO4XX_CRYPTO_PRIORITY, |
1114 | 1129 | .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC, |
1115 | 1130 | .cra_blocksize = AES_BLOCK_SIZE, |
1116 | 1131 | .cra_ctxsize = sizeof(struct crypto4xx_ctx), |
1117 | - .cra_alignmask = 0, | |
1118 | 1132 | .cra_type = &crypto_ablkcipher_type, |
1133 | + .cra_init = crypto4xx_alg_init, | |
1134 | + .cra_exit = crypto4xx_alg_exit, | |
1119 | 1135 | .cra_module = THIS_MODULE, |
1120 | 1136 | .cra_u = { |
1121 | 1137 | .ablkcipher = { |
1122 | 1138 | |
1123 | 1139 | |
... | ... | @@ -1127,29 +1143,26 @@ |
1127 | 1143 | .decrypt = crypto4xx_decrypt, |
1128 | 1144 | } |
1129 | 1145 | } |
1130 | - }, | |
1146 | + }}, | |
1131 | 1147 | /* Hash SHA1 */ |
1132 | - { | |
1133 | - .cra_name = "sha1", | |
1134 | - .cra_driver_name = "sha1-ppc4xx", | |
1135 | - .cra_priority = CRYPTO4XX_CRYPTO_PRIORITY, | |
1136 | - .cra_flags = CRYPTO_ALG_TYPE_AHASH | CRYPTO_ALG_ASYNC, | |
1137 | - .cra_blocksize = SHA1_BLOCK_SIZE, | |
1138 | - .cra_ctxsize = sizeof(struct crypto4xx_ctx), | |
1139 | - .cra_alignmask = 0, | |
1140 | - .cra_type = &crypto_ahash_type, | |
1141 | - .cra_init = crypto4xx_sha1_alg_init, | |
1142 | - .cra_module = THIS_MODULE, | |
1143 | - .cra_u = { | |
1144 | - .ahash = { | |
1145 | - .digestsize = SHA1_DIGEST_SIZE, | |
1146 | - .init = crypto4xx_hash_init, | |
1147 | - .update = crypto4xx_hash_update, | |
1148 | - .final = crypto4xx_hash_final, | |
1149 | - .digest = crypto4xx_hash_digest, | |
1150 | - } | |
1148 | + { .type = CRYPTO_ALG_TYPE_AHASH, .u.hash = { | |
1149 | + .init = crypto4xx_hash_init, | |
1150 | + .update = crypto4xx_hash_update, | |
1151 | + .final = crypto4xx_hash_final, | |
1152 | + .digest = crypto4xx_hash_digest, | |
1153 | + .halg.digestsize = SHA1_DIGEST_SIZE, | |
1154 | + .halg.base = { | |
1155 | + .cra_name = "sha1", | |
1156 | + .cra_driver_name = "sha1-ppc4xx", | |
1157 | + .cra_priority = CRYPTO4XX_CRYPTO_PRIORITY, | |
1158 | + .cra_flags = CRYPTO_ALG_ASYNC, | |
1159 | + .cra_blocksize = SHA1_BLOCK_SIZE, | |
1160 | + .cra_ctxsize = sizeof(struct crypto4xx_ctx), | |
1161 | + .cra_init = crypto4xx_sha1_alg_init, | |
1162 | + .cra_exit = crypto4xx_alg_exit, | |
1163 | + .cra_module = THIS_MODULE, | |
1151 | 1164 | } |
1152 | - }, | |
1165 | + }}, | |
1153 | 1166 | }; |
1154 | 1167 | |
1155 | 1168 | /** |
drivers/crypto/amcc/crypto4xx_core.h
... | ... | @@ -22,6 +22,8 @@ |
22 | 22 | #ifndef __CRYPTO4XX_CORE_H__ |
23 | 23 | #define __CRYPTO4XX_CORE_H__ |
24 | 24 | |
25 | +#include <crypto/internal/hash.h> | |
26 | + | |
25 | 27 | #define PPC460SX_SDR0_SRST 0x201 |
26 | 28 | #define PPC405EX_SDR0_SRST 0x200 |
27 | 29 | #define PPC460EX_SDR0_SRST 0x201 |
28 | 30 | |
29 | 31 | |
... | ... | @@ -138,14 +140,31 @@ |
138 | 140 | u16 sa_len; |
139 | 141 | }; |
140 | 142 | |
143 | +struct crypto4xx_alg_common { | |
144 | + u32 type; | |
145 | + union { | |
146 | + struct crypto_alg cipher; | |
147 | + struct ahash_alg hash; | |
148 | + } u; | |
149 | +}; | |
150 | + | |
141 | 151 | struct crypto4xx_alg { |
142 | 152 | struct list_head entry; |
143 | - struct crypto_alg alg; | |
153 | + struct crypto4xx_alg_common alg; | |
144 | 154 | struct crypto4xx_device *dev; |
145 | 155 | }; |
146 | 156 | |
147 | -#define crypto_alg_to_crypto4xx_alg(x) \ | |
148 | - container_of(x, struct crypto4xx_alg, alg) | |
157 | +static inline struct crypto4xx_alg *crypto_alg_to_crypto4xx_alg( | |
158 | + struct crypto_alg *x) | |
159 | +{ | |
160 | + switch (x->cra_flags & CRYPTO_ALG_TYPE_MASK) { | |
161 | + case CRYPTO_ALG_TYPE_AHASH: | |
162 | + return container_of(__crypto_ahash_alg(x), | |
163 | + struct crypto4xx_alg, alg.u.hash); | |
164 | + } | |
165 | + | |
166 | + return container_of(x, struct crypto4xx_alg, alg.u.cipher); | |
167 | +} | |
149 | 168 | |
150 | 169 | extern int crypto4xx_alloc_sa(struct crypto4xx_ctx *ctx, u32 size); |
151 | 170 | extern void crypto4xx_free_sa(struct crypto4xx_ctx *ctx); |
include/crypto/internal/hash.h
... | ... | @@ -103,6 +103,12 @@ |
103 | 103 | return crypto_tfm_ctx(crypto_ahash_tfm(tfm)); |
104 | 104 | } |
105 | 105 | |
106 | +static inline struct ahash_alg *__crypto_ahash_alg(struct crypto_alg *alg) | |
107 | +{ | |
108 | + return container_of(__crypto_hash_alg_common(alg), struct ahash_alg, | |
109 | + halg); | |
110 | +} | |
111 | + | |
106 | 112 | static inline struct old_ahash_alg *crypto_old_ahash_alg( |
107 | 113 | struct crypto_ahash *tfm) |
108 | 114 | { |