diff options
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/Kconfig | 2 | ||||
-rw-r--r-- | crypto/sha512_generic.c | 112 |
2 files changed, 60 insertions, 54 deletions
diff --git a/crypto/Kconfig b/crypto/Kconfig index 3f88a526d2da..8dde4fcf99c9 100644 --- a/crypto/Kconfig +++ b/crypto/Kconfig | |||
@@ -369,7 +369,7 @@ config CRYPTO_SHA256 | |||
369 | 369 | ||
370 | config CRYPTO_SHA512 | 370 | config CRYPTO_SHA512 |
371 | tristate "SHA384 and SHA512 digest algorithms" | 371 | tristate "SHA384 and SHA512 digest algorithms" |
372 | select CRYPTO_ALGAPI | 372 | select CRYPTO_HASH |
373 | help | 373 | help |
374 | SHA512 secure hash standard (DFIPS 180-2). | 374 | SHA512 secure hash standard (DFIPS 180-2). |
375 | 375 | ||
diff --git a/crypto/sha512_generic.c b/crypto/sha512_generic.c index cb85516d3a78..3bea38d12242 100644 --- a/crypto/sha512_generic.c +++ b/crypto/sha512_generic.c | |||
@@ -10,7 +10,7 @@ | |||
10 | * later version. | 10 | * later version. |
11 | * | 11 | * |
12 | */ | 12 | */ |
13 | 13 | #include <crypto/internal/hash.h> | |
14 | #include <linux/kernel.h> | 14 | #include <linux/kernel.h> |
15 | #include <linux/module.h> | 15 | #include <linux/module.h> |
16 | #include <linux/mm.h> | 16 | #include <linux/mm.h> |
@@ -138,10 +138,10 @@ sha512_transform(u64 *state, const u8 *input) | |||
138 | put_cpu_var(msg_schedule); | 138 | put_cpu_var(msg_schedule); |
139 | } | 139 | } |
140 | 140 | ||
141 | static void | 141 | static int |
142 | sha512_init(struct crypto_tfm *tfm) | 142 | sha512_init(struct shash_desc *desc) |
143 | { | 143 | { |
144 | struct sha512_ctx *sctx = crypto_tfm_ctx(tfm); | 144 | struct sha512_ctx *sctx = shash_desc_ctx(desc); |
145 | sctx->state[0] = SHA512_H0; | 145 | sctx->state[0] = SHA512_H0; |
146 | sctx->state[1] = SHA512_H1; | 146 | sctx->state[1] = SHA512_H1; |
147 | sctx->state[2] = SHA512_H2; | 147 | sctx->state[2] = SHA512_H2; |
@@ -151,12 +151,14 @@ sha512_init(struct crypto_tfm *tfm) | |||
151 | sctx->state[6] = SHA512_H6; | 151 | sctx->state[6] = SHA512_H6; |
152 | sctx->state[7] = SHA512_H7; | 152 | sctx->state[7] = SHA512_H7; |
153 | sctx->count[0] = sctx->count[1] = sctx->count[2] = sctx->count[3] = 0; | 153 | sctx->count[0] = sctx->count[1] = sctx->count[2] = sctx->count[3] = 0; |
154 | |||
155 | return 0; | ||
154 | } | 156 | } |
155 | 157 | ||
156 | static void | 158 | static int |
157 | sha384_init(struct crypto_tfm *tfm) | 159 | sha384_init(struct shash_desc *desc) |
158 | { | 160 | { |
159 | struct sha512_ctx *sctx = crypto_tfm_ctx(tfm); | 161 | struct sha512_ctx *sctx = shash_desc_ctx(desc); |
160 | sctx->state[0] = SHA384_H0; | 162 | sctx->state[0] = SHA384_H0; |
161 | sctx->state[1] = SHA384_H1; | 163 | sctx->state[1] = SHA384_H1; |
162 | sctx->state[2] = SHA384_H2; | 164 | sctx->state[2] = SHA384_H2; |
@@ -166,12 +168,14 @@ sha384_init(struct crypto_tfm *tfm) | |||
166 | sctx->state[6] = SHA384_H6; | 168 | sctx->state[6] = SHA384_H6; |
167 | sctx->state[7] = SHA384_H7; | 169 | sctx->state[7] = SHA384_H7; |
168 | sctx->count[0] = sctx->count[1] = sctx->count[2] = sctx->count[3] = 0; | 170 | sctx->count[0] = sctx->count[1] = sctx->count[2] = sctx->count[3] = 0; |
171 | |||
172 | return 0; | ||
169 | } | 173 | } |
170 | 174 | ||
171 | static void | 175 | static int |
172 | sha512_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len) | 176 | sha512_update(struct shash_desc *desc, const u8 *data, unsigned int len) |
173 | { | 177 | { |
174 | struct sha512_ctx *sctx = crypto_tfm_ctx(tfm); | 178 | struct sha512_ctx *sctx = shash_desc_ctx(desc); |
175 | 179 | ||
176 | unsigned int i, index, part_len; | 180 | unsigned int i, index, part_len; |
177 | 181 | ||
@@ -203,12 +207,14 @@ sha512_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len) | |||
203 | 207 | ||
204 | /* Buffer remaining input */ | 208 | /* Buffer remaining input */ |
205 | memcpy(&sctx->buf[index], &data[i], len - i); | 209 | memcpy(&sctx->buf[index], &data[i], len - i); |
210 | |||
211 | return 0; | ||
206 | } | 212 | } |
207 | 213 | ||
208 | static void | 214 | static int |
209 | sha512_final(struct crypto_tfm *tfm, u8 *hash) | 215 | sha512_final(struct shash_desc *desc, u8 *hash) |
210 | { | 216 | { |
211 | struct sha512_ctx *sctx = crypto_tfm_ctx(tfm); | 217 | struct sha512_ctx *sctx = shash_desc_ctx(desc); |
212 | static u8 padding[128] = { 0x80, }; | 218 | static u8 padding[128] = { 0x80, }; |
213 | __be64 *dst = (__be64 *)hash; | 219 | __be64 *dst = (__be64 *)hash; |
214 | __be32 bits[4]; | 220 | __be32 bits[4]; |
@@ -224,10 +230,10 @@ sha512_final(struct crypto_tfm *tfm, u8 *hash) | |||
224 | /* Pad out to 112 mod 128. */ | 230 | /* Pad out to 112 mod 128. */ |
225 | index = (sctx->count[0] >> 3) & 0x7f; | 231 | index = (sctx->count[0] >> 3) & 0x7f; |
226 | pad_len = (index < 112) ? (112 - index) : ((128+112) - index); | 232 | pad_len = (index < 112) ? (112 - index) : ((128+112) - index); |
227 | sha512_update(tfm, padding, pad_len); | 233 | sha512_update(desc, padding, pad_len); |
228 | 234 | ||
229 | /* Append length (before padding) */ | 235 | /* Append length (before padding) */ |
230 | sha512_update(tfm, (const u8 *)bits, sizeof(bits)); | 236 | sha512_update(desc, (const u8 *)bits, sizeof(bits)); |
231 | 237 | ||
232 | /* Store state in digest */ | 238 | /* Store state in digest */ |
233 | for (i = 0; i < 8; i++) | 239 | for (i = 0; i < 8; i++) |
@@ -235,66 +241,66 @@ sha512_final(struct crypto_tfm *tfm, u8 *hash) | |||
235 | 241 | ||
236 | /* Zeroize sensitive information. */ | 242 | /* Zeroize sensitive information. */ |
237 | memset(sctx, 0, sizeof(struct sha512_ctx)); | 243 | memset(sctx, 0, sizeof(struct sha512_ctx)); |
244 | |||
245 | return 0; | ||
238 | } | 246 | } |
239 | 247 | ||
240 | static void sha384_final(struct crypto_tfm *tfm, u8 *hash) | 248 | static int sha384_final(struct shash_desc *desc, u8 *hash) |
241 | { | 249 | { |
242 | u8 D[64]; | 250 | u8 D[64]; |
243 | 251 | ||
244 | sha512_final(tfm, D); | 252 | sha512_final(desc, D); |
245 | 253 | ||
246 | memcpy(hash, D, 48); | 254 | memcpy(hash, D, 48); |
247 | memset(D, 0, 64); | 255 | memset(D, 0, 64); |
256 | |||
257 | return 0; | ||
248 | } | 258 | } |
249 | 259 | ||
250 | static struct crypto_alg sha512 = { | 260 | static struct shash_alg sha512 = { |
251 | .cra_name = "sha512", | 261 | .digestsize = SHA512_DIGEST_SIZE, |
252 | .cra_flags = CRYPTO_ALG_TYPE_DIGEST, | 262 | .init = sha512_init, |
253 | .cra_blocksize = SHA512_BLOCK_SIZE, | 263 | .update = sha512_update, |
254 | .cra_ctxsize = sizeof(struct sha512_ctx), | 264 | .final = sha512_final, |
255 | .cra_module = THIS_MODULE, | 265 | .descsize = sizeof(struct sha512_ctx), |
256 | .cra_alignmask = 3, | 266 | .base = { |
257 | .cra_list = LIST_HEAD_INIT(sha512.cra_list), | 267 | .cra_name = "sha512", |
258 | .cra_u = { .digest = { | 268 | .cra_flags = CRYPTO_ALG_TYPE_SHASH, |
259 | .dia_digestsize = SHA512_DIGEST_SIZE, | 269 | .cra_blocksize = SHA512_BLOCK_SIZE, |
260 | .dia_init = sha512_init, | 270 | .cra_module = THIS_MODULE, |
261 | .dia_update = sha512_update, | 271 | } |
262 | .dia_final = sha512_final } | ||
263 | } | ||
264 | }; | 272 | }; |
265 | 273 | ||
266 | static struct crypto_alg sha384 = { | 274 | static struct shash_alg sha384 = { |
267 | .cra_name = "sha384", | 275 | .digestsize = SHA384_DIGEST_SIZE, |
268 | .cra_flags = CRYPTO_ALG_TYPE_DIGEST, | 276 | .init = sha384_init, |
269 | .cra_blocksize = SHA384_BLOCK_SIZE, | 277 | .update = sha512_update, |
270 | .cra_ctxsize = sizeof(struct sha512_ctx), | 278 | .final = sha384_final, |
271 | .cra_alignmask = 3, | 279 | .descsize = sizeof(struct sha512_ctx), |
272 | .cra_module = THIS_MODULE, | 280 | .base = { |
273 | .cra_list = LIST_HEAD_INIT(sha384.cra_list), | 281 | .cra_name = "sha384", |
274 | .cra_u = { .digest = { | 282 | .cra_flags = CRYPTO_ALG_TYPE_SHASH, |
275 | .dia_digestsize = SHA384_DIGEST_SIZE, | 283 | .cra_blocksize = SHA384_BLOCK_SIZE, |
276 | .dia_init = sha384_init, | 284 | .cra_module = THIS_MODULE, |
277 | .dia_update = sha512_update, | 285 | } |
278 | .dia_final = sha384_final } | ||
279 | } | ||
280 | }; | 286 | }; |
281 | 287 | ||
282 | static int __init sha512_generic_mod_init(void) | 288 | static int __init sha512_generic_mod_init(void) |
283 | { | 289 | { |
284 | int ret = 0; | 290 | int ret = 0; |
285 | 291 | ||
286 | if ((ret = crypto_register_alg(&sha384)) < 0) | 292 | if ((ret = crypto_register_shash(&sha384)) < 0) |
287 | goto out; | 293 | goto out; |
288 | if ((ret = crypto_register_alg(&sha512)) < 0) | 294 | if ((ret = crypto_register_shash(&sha512)) < 0) |
289 | crypto_unregister_alg(&sha384); | 295 | crypto_unregister_shash(&sha384); |
290 | out: | 296 | out: |
291 | return ret; | 297 | return ret; |
292 | } | 298 | } |
293 | 299 | ||
294 | static void __exit sha512_generic_mod_fini(void) | 300 | static void __exit sha512_generic_mod_fini(void) |
295 | { | 301 | { |
296 | crypto_unregister_alg(&sha384); | 302 | crypto_unregister_shash(&sha384); |
297 | crypto_unregister_alg(&sha512); | 303 | crypto_unregister_shash(&sha512); |
298 | } | 304 | } |
299 | 305 | ||
300 | module_init(sha512_generic_mod_init); | 306 | module_init(sha512_generic_mod_init); |