diff options
author | Adrian-Ken Rueegsegger <ken@codelabs.ch> | 2008-12-07 06:34:37 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2008-12-24 19:02:22 -0500 |
commit | 4946510baac6aaa8658528e3deefc7e9ba2951a9 (patch) | |
tree | abffe4ff5e4d7b0f5b6fa29a73d6f7de53cbd06d | |
parent | f63fbd3d501b4283e1551e195cb74434a838064f (diff) |
crypto: wp512 - Switch to shash
This patch changes wp512, wp384 and wp256 to the new shash interface.
Signed-off-by: Adrian-Ken Rueegsegger <ken@codelabs.ch>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | crypto/Kconfig | 2 | ||||
-rw-r--r-- | crypto/wp512.c | 121 |
2 files changed, 66 insertions, 57 deletions
diff --git a/crypto/Kconfig b/crypto/Kconfig index a863d7e5f9e8..bc29216aaada 100644 --- a/crypto/Kconfig +++ b/crypto/Kconfig | |||
@@ -394,7 +394,7 @@ config CRYPTO_TGR192 | |||
394 | 394 | ||
395 | config CRYPTO_WP512 | 395 | config CRYPTO_WP512 |
396 | tristate "Whirlpool digest algorithms" | 396 | tristate "Whirlpool digest algorithms" |
397 | select CRYPTO_ALGAPI | 397 | select CRYPTO_HASH |
398 | help | 398 | help |
399 | Whirlpool hash algorithm 512, 384 and 256-bit hashes | 399 | Whirlpool hash algorithm 512, 384 and 256-bit hashes |
400 | 400 | ||
diff --git a/crypto/wp512.c b/crypto/wp512.c index bff28560d66d..723427273687 100644 --- a/crypto/wp512.c +++ b/crypto/wp512.c | |||
@@ -19,11 +19,11 @@ | |||
19 | * (at your option) any later version. | 19 | * (at your option) any later version. |
20 | * | 20 | * |
21 | */ | 21 | */ |
22 | #include <crypto/internal/hash.h> | ||
22 | #include <linux/init.h> | 23 | #include <linux/init.h> |
23 | #include <linux/module.h> | 24 | #include <linux/module.h> |
24 | #include <linux/mm.h> | 25 | #include <linux/mm.h> |
25 | #include <asm/byteorder.h> | 26 | #include <asm/byteorder.h> |
26 | #include <linux/crypto.h> | ||
27 | #include <linux/types.h> | 27 | #include <linux/types.h> |
28 | 28 | ||
29 | #define WP512_DIGEST_SIZE 64 | 29 | #define WP512_DIGEST_SIZE 64 |
@@ -980,8 +980,8 @@ static void wp512_process_buffer(struct wp512_ctx *wctx) { | |||
980 | 980 | ||
981 | } | 981 | } |
982 | 982 | ||
983 | static void wp512_init(struct crypto_tfm *tfm) { | 983 | static int wp512_init(struct shash_desc *desc) { |
984 | struct wp512_ctx *wctx = crypto_tfm_ctx(tfm); | 984 | struct wp512_ctx *wctx = shash_desc_ctx(desc); |
985 | int i; | 985 | int i; |
986 | 986 | ||
987 | memset(wctx->bitLength, 0, 32); | 987 | memset(wctx->bitLength, 0, 32); |
@@ -990,12 +990,14 @@ static void wp512_init(struct crypto_tfm *tfm) { | |||
990 | for (i = 0; i < 8; i++) { | 990 | for (i = 0; i < 8; i++) { |
991 | wctx->hash[i] = 0L; | 991 | wctx->hash[i] = 0L; |
992 | } | 992 | } |
993 | |||
994 | return 0; | ||
993 | } | 995 | } |
994 | 996 | ||
995 | static void wp512_update(struct crypto_tfm *tfm, const u8 *source, | 997 | static int wp512_update(struct shash_desc *desc, const u8 *source, |
996 | unsigned int len) | 998 | unsigned int len) |
997 | { | 999 | { |
998 | struct wp512_ctx *wctx = crypto_tfm_ctx(tfm); | 1000 | struct wp512_ctx *wctx = shash_desc_ctx(desc); |
999 | int sourcePos = 0; | 1001 | int sourcePos = 0; |
1000 | unsigned int bits_len = len * 8; // convert to number of bits | 1002 | unsigned int bits_len = len * 8; // convert to number of bits |
1001 | int sourceGap = (8 - ((int)bits_len & 7)) & 7; | 1003 | int sourceGap = (8 - ((int)bits_len & 7)) & 7; |
@@ -1051,11 +1053,12 @@ static void wp512_update(struct crypto_tfm *tfm, const u8 *source, | |||
1051 | wctx->bufferBits = bufferBits; | 1053 | wctx->bufferBits = bufferBits; |
1052 | wctx->bufferPos = bufferPos; | 1054 | wctx->bufferPos = bufferPos; |
1053 | 1055 | ||
1056 | return 0; | ||
1054 | } | 1057 | } |
1055 | 1058 | ||
1056 | static void wp512_final(struct crypto_tfm *tfm, u8 *out) | 1059 | static int wp512_final(struct shash_desc *desc, u8 *out) |
1057 | { | 1060 | { |
1058 | struct wp512_ctx *wctx = crypto_tfm_ctx(tfm); | 1061 | struct wp512_ctx *wctx = shash_desc_ctx(desc); |
1059 | int i; | 1062 | int i; |
1060 | u8 *buffer = wctx->buffer; | 1063 | u8 *buffer = wctx->buffer; |
1061 | u8 *bitLength = wctx->bitLength; | 1064 | u8 *bitLength = wctx->bitLength; |
@@ -1084,89 +1087,95 @@ static void wp512_final(struct crypto_tfm *tfm, u8 *out) | |||
1084 | digest[i] = cpu_to_be64(wctx->hash[i]); | 1087 | digest[i] = cpu_to_be64(wctx->hash[i]); |
1085 | wctx->bufferBits = bufferBits; | 1088 | wctx->bufferBits = bufferBits; |
1086 | wctx->bufferPos = bufferPos; | 1089 | wctx->bufferPos = bufferPos; |
1090 | |||
1091 | return 0; | ||
1087 | } | 1092 | } |
1088 | 1093 | ||
1089 | static void wp384_final(struct crypto_tfm *tfm, u8 *out) | 1094 | static int wp384_final(struct shash_desc *desc, u8 *out) |
1090 | { | 1095 | { |
1091 | u8 D[64]; | 1096 | u8 D[64]; |
1092 | 1097 | ||
1093 | wp512_final(tfm, D); | 1098 | wp512_final(desc, D); |
1094 | memcpy (out, D, WP384_DIGEST_SIZE); | 1099 | memcpy (out, D, WP384_DIGEST_SIZE); |
1095 | memset (D, 0, WP512_DIGEST_SIZE); | 1100 | memset (D, 0, WP512_DIGEST_SIZE); |
1101 | |||
1102 | return 0; | ||
1096 | } | 1103 | } |
1097 | 1104 | ||
1098 | static void wp256_final(struct crypto_tfm *tfm, u8 *out) | 1105 | static int wp256_final(struct shash_desc *desc, u8 *out) |
1099 | { | 1106 | { |
1100 | u8 D[64]; | 1107 | u8 D[64]; |
1101 | 1108 | ||
1102 | wp512_final(tfm, D); | 1109 | wp512_final(desc, D); |
1103 | memcpy (out, D, WP256_DIGEST_SIZE); | 1110 | memcpy (out, D, WP256_DIGEST_SIZE); |
1104 | memset (D, 0, WP512_DIGEST_SIZE); | 1111 | memset (D, 0, WP512_DIGEST_SIZE); |
1112 | |||
1113 | return 0; | ||
1105 | } | 1114 | } |
1106 | 1115 | ||
1107 | static struct crypto_alg wp512 = { | 1116 | static struct shash_alg wp512 = { |
1108 | .cra_name = "wp512", | 1117 | .digestsize = WP512_DIGEST_SIZE, |
1109 | .cra_flags = CRYPTO_ALG_TYPE_DIGEST, | 1118 | .init = wp512_init, |
1110 | .cra_blocksize = WP512_BLOCK_SIZE, | 1119 | .update = wp512_update, |
1111 | .cra_ctxsize = sizeof(struct wp512_ctx), | 1120 | .final = wp512_final, |
1112 | .cra_module = THIS_MODULE, | 1121 | .descsize = sizeof(struct wp512_ctx), |
1113 | .cra_list = LIST_HEAD_INIT(wp512.cra_list), | 1122 | .base = { |
1114 | .cra_u = { .digest = { | 1123 | .cra_name = "wp512", |
1115 | .dia_digestsize = WP512_DIGEST_SIZE, | 1124 | .cra_flags = CRYPTO_ALG_TYPE_SHASH, |
1116 | .dia_init = wp512_init, | 1125 | .cra_blocksize = WP512_BLOCK_SIZE, |
1117 | .dia_update = wp512_update, | 1126 | .cra_module = THIS_MODULE, |
1118 | .dia_final = wp512_final } } | 1127 | } |
1119 | }; | 1128 | }; |
1120 | 1129 | ||
1121 | static struct crypto_alg wp384 = { | 1130 | static struct shash_alg wp384 = { |
1122 | .cra_name = "wp384", | 1131 | .digestsize = WP384_DIGEST_SIZE, |
1123 | .cra_flags = CRYPTO_ALG_TYPE_DIGEST, | 1132 | .init = wp512_init, |
1124 | .cra_blocksize = WP512_BLOCK_SIZE, | 1133 | .update = wp512_update, |
1125 | .cra_ctxsize = sizeof(struct wp512_ctx), | 1134 | .final = wp384_final, |
1126 | .cra_module = THIS_MODULE, | 1135 | .descsize = sizeof(struct wp512_ctx), |
1127 | .cra_list = LIST_HEAD_INIT(wp384.cra_list), | 1136 | .base = { |
1128 | .cra_u = { .digest = { | 1137 | .cra_name = "wp384", |
1129 | .dia_digestsize = WP384_DIGEST_SIZE, | 1138 | .cra_flags = CRYPTO_ALG_TYPE_SHASH, |
1130 | .dia_init = wp512_init, | 1139 | .cra_blocksize = WP512_BLOCK_SIZE, |
1131 | .dia_update = wp512_update, | 1140 | .cra_module = THIS_MODULE, |
1132 | .dia_final = wp384_final } } | 1141 | } |
1133 | }; | 1142 | }; |
1134 | 1143 | ||
1135 | static struct crypto_alg wp256 = { | 1144 | static struct shash_alg wp256 = { |
1136 | .cra_name = "wp256", | 1145 | .digestsize = WP256_DIGEST_SIZE, |
1137 | .cra_flags = CRYPTO_ALG_TYPE_DIGEST, | 1146 | .init = wp512_init, |
1138 | .cra_blocksize = WP512_BLOCK_SIZE, | 1147 | .update = wp512_update, |
1139 | .cra_ctxsize = sizeof(struct wp512_ctx), | 1148 | .final = wp256_final, |
1140 | .cra_module = THIS_MODULE, | 1149 | .descsize = sizeof(struct wp512_ctx), |
1141 | .cra_list = LIST_HEAD_INIT(wp256.cra_list), | 1150 | .base = { |
1142 | .cra_u = { .digest = { | 1151 | .cra_name = "wp256", |
1143 | .dia_digestsize = WP256_DIGEST_SIZE, | 1152 | .cra_flags = CRYPTO_ALG_TYPE_SHASH, |
1144 | .dia_init = wp512_init, | 1153 | .cra_blocksize = WP512_BLOCK_SIZE, |
1145 | .dia_update = wp512_update, | 1154 | .cra_module = THIS_MODULE, |
1146 | .dia_final = wp256_final } } | 1155 | } |
1147 | }; | 1156 | }; |
1148 | 1157 | ||
1149 | static int __init wp512_mod_init(void) | 1158 | static int __init wp512_mod_init(void) |
1150 | { | 1159 | { |
1151 | int ret = 0; | 1160 | int ret = 0; |
1152 | 1161 | ||
1153 | ret = crypto_register_alg(&wp512); | 1162 | ret = crypto_register_shash(&wp512); |
1154 | 1163 | ||
1155 | if (ret < 0) | 1164 | if (ret < 0) |
1156 | goto out; | 1165 | goto out; |
1157 | 1166 | ||
1158 | ret = crypto_register_alg(&wp384); | 1167 | ret = crypto_register_shash(&wp384); |
1159 | if (ret < 0) | 1168 | if (ret < 0) |
1160 | { | 1169 | { |
1161 | crypto_unregister_alg(&wp512); | 1170 | crypto_unregister_shash(&wp512); |
1162 | goto out; | 1171 | goto out; |
1163 | } | 1172 | } |
1164 | 1173 | ||
1165 | ret = crypto_register_alg(&wp256); | 1174 | ret = crypto_register_shash(&wp256); |
1166 | if (ret < 0) | 1175 | if (ret < 0) |
1167 | { | 1176 | { |
1168 | crypto_unregister_alg(&wp512); | 1177 | crypto_unregister_shash(&wp512); |
1169 | crypto_unregister_alg(&wp384); | 1178 | crypto_unregister_shash(&wp384); |
1170 | } | 1179 | } |
1171 | out: | 1180 | out: |
1172 | return ret; | 1181 | return ret; |
@@ -1174,9 +1183,9 @@ out: | |||
1174 | 1183 | ||
1175 | static void __exit wp512_mod_fini(void) | 1184 | static void __exit wp512_mod_fini(void) |
1176 | { | 1185 | { |
1177 | crypto_unregister_alg(&wp512); | 1186 | crypto_unregister_shash(&wp512); |
1178 | crypto_unregister_alg(&wp384); | 1187 | crypto_unregister_shash(&wp384); |
1179 | crypto_unregister_alg(&wp256); | 1188 | crypto_unregister_shash(&wp256); |
1180 | } | 1189 | } |
1181 | 1190 | ||
1182 | MODULE_ALIAS("wp384"); | 1191 | MODULE_ALIAS("wp384"); |