Commit 3b8efb4c4147094652570d7791a516d07b7df8c2
1 parent
d8a5e2e9f4
Exists in
master
and in
4 other branches
crypto: rmd320 - Switch to shash
This patch changes rmd320 to the new shash interface. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Showing 2 changed files with 33 additions and 30 deletions Side-by-side Diff
crypto/Kconfig
... | ... | @@ -339,7 +339,7 @@ |
339 | 339 | |
340 | 340 | config CRYPTO_RMD320 |
341 | 341 | tristate "RIPEMD-320 digest algorithm" |
342 | - select CRYPTO_ALGAPI | |
342 | + select CRYPTO_HASH | |
343 | 343 | help |
344 | 344 | RIPEMD-320 is an optional extension of RIPEMD-160 with a |
345 | 345 | 320 bit hash. It is intended for applications that require |
crypto/rmd320.c
... | ... | @@ -13,11 +13,10 @@ |
13 | 13 | * any later version. |
14 | 14 | * |
15 | 15 | */ |
16 | +#include <crypto/internal/hash.h> | |
16 | 17 | #include <linux/init.h> |
17 | 18 | #include <linux/module.h> |
18 | 19 | #include <linux/mm.h> |
19 | -#include <linux/crypto.h> | |
20 | -#include <linux/cryptohash.h> | |
21 | 20 | #include <linux/types.h> |
22 | 21 | #include <asm/byteorder.h> |
23 | 22 | |
24 | 23 | |
... | ... | @@ -280,9 +279,9 @@ |
280 | 279 | return; |
281 | 280 | } |
282 | 281 | |
283 | -static void rmd320_init(struct crypto_tfm *tfm) | |
282 | +static int rmd320_init(struct shash_desc *desc) | |
284 | 283 | { |
285 | - struct rmd320_ctx *rctx = crypto_tfm_ctx(tfm); | |
284 | + struct rmd320_ctx *rctx = shash_desc_ctx(desc); | |
286 | 285 | |
287 | 286 | rctx->byte_count = 0; |
288 | 287 | |
289 | 288 | |
290 | 289 | |
... | ... | @@ -298,12 +297,14 @@ |
298 | 297 | rctx->state[9] = RMD_H9; |
299 | 298 | |
300 | 299 | memset(rctx->buffer, 0, sizeof(rctx->buffer)); |
300 | + | |
301 | + return 0; | |
301 | 302 | } |
302 | 303 | |
303 | -static void rmd320_update(struct crypto_tfm *tfm, const u8 *data, | |
304 | - unsigned int len) | |
304 | +static int rmd320_update(struct shash_desc *desc, const u8 *data, | |
305 | + unsigned int len) | |
305 | 306 | { |
306 | - struct rmd320_ctx *rctx = crypto_tfm_ctx(tfm); | |
307 | + struct rmd320_ctx *rctx = shash_desc_ctx(desc); | |
307 | 308 | const u32 avail = sizeof(rctx->buffer) - (rctx->byte_count & 0x3f); |
308 | 309 | |
309 | 310 | rctx->byte_count += len; |
... | ... | @@ -312,7 +313,7 @@ |
312 | 313 | if (avail > len) { |
313 | 314 | memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail), |
314 | 315 | data, len); |
315 | - return; | |
316 | + goto out; | |
316 | 317 | } |
317 | 318 | |
318 | 319 | memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail), |
319 | 320 | |
320 | 321 | |
... | ... | @@ -330,12 +331,15 @@ |
330 | 331 | } |
331 | 332 | |
332 | 333 | memcpy(rctx->buffer, data, len); |
334 | + | |
335 | +out: | |
336 | + return 0; | |
333 | 337 | } |
334 | 338 | |
335 | 339 | /* Add padding and return the message digest. */ |
336 | -static void rmd320_final(struct crypto_tfm *tfm, u8 *out) | |
340 | +static int rmd320_final(struct shash_desc *desc, u8 *out) | |
337 | 341 | { |
338 | - struct rmd320_ctx *rctx = crypto_tfm_ctx(tfm); | |
342 | + struct rmd320_ctx *rctx = shash_desc_ctx(desc); | |
339 | 343 | u32 i, index, padlen; |
340 | 344 | __le64 bits; |
341 | 345 | __le32 *dst = (__le32 *)out; |
342 | 346 | |
... | ... | @@ -346,10 +350,10 @@ |
346 | 350 | /* Pad out to 56 mod 64 */ |
347 | 351 | index = rctx->byte_count & 0x3f; |
348 | 352 | padlen = (index < 56) ? (56 - index) : ((64+56) - index); |
349 | - rmd320_update(tfm, padding, padlen); | |
353 | + rmd320_update(desc, padding, padlen); | |
350 | 354 | |
351 | 355 | /* Append length */ |
352 | - rmd320_update(tfm, (const u8 *)&bits, sizeof(bits)); | |
356 | + rmd320_update(desc, (const u8 *)&bits, sizeof(bits)); | |
353 | 357 | |
354 | 358 | /* Store state in digest */ |
355 | 359 | for (i = 0; i < 10; i++) |
356 | 360 | |
357 | 361 | |
358 | 362 | |
... | ... | @@ -357,31 +361,32 @@ |
357 | 361 | |
358 | 362 | /* Wipe context */ |
359 | 363 | memset(rctx, 0, sizeof(*rctx)); |
364 | + | |
365 | + return 0; | |
360 | 366 | } |
361 | 367 | |
362 | -static struct crypto_alg alg = { | |
363 | - .cra_name = "rmd320", | |
364 | - .cra_driver_name = "rmd320", | |
365 | - .cra_flags = CRYPTO_ALG_TYPE_DIGEST, | |
366 | - .cra_blocksize = RMD320_BLOCK_SIZE, | |
367 | - .cra_ctxsize = sizeof(struct rmd320_ctx), | |
368 | - .cra_module = THIS_MODULE, | |
369 | - .cra_list = LIST_HEAD_INIT(alg.cra_list), | |
370 | - .cra_u = { .digest = { | |
371 | - .dia_digestsize = RMD320_DIGEST_SIZE, | |
372 | - .dia_init = rmd320_init, | |
373 | - .dia_update = rmd320_update, | |
374 | - .dia_final = rmd320_final } } | |
368 | +static struct shash_alg alg = { | |
369 | + .digestsize = RMD320_DIGEST_SIZE, | |
370 | + .init = rmd320_init, | |
371 | + .update = rmd320_update, | |
372 | + .final = rmd320_final, | |
373 | + .descsize = sizeof(struct rmd320_ctx), | |
374 | + .base = { | |
375 | + .cra_name = "rmd320", | |
376 | + .cra_flags = CRYPTO_ALG_TYPE_SHASH, | |
377 | + .cra_blocksize = RMD320_BLOCK_SIZE, | |
378 | + .cra_module = THIS_MODULE, | |
379 | + } | |
375 | 380 | }; |
376 | 381 | |
377 | 382 | static int __init rmd320_mod_init(void) |
378 | 383 | { |
379 | - return crypto_register_alg(&alg); | |
384 | + return crypto_register_shash(&alg); | |
380 | 385 | } |
381 | 386 | |
382 | 387 | static void __exit rmd320_mod_fini(void) |
383 | 388 | { |
384 | - crypto_unregister_alg(&alg); | |
389 | + crypto_unregister_shash(&alg); | |
385 | 390 | } |
386 | 391 | |
387 | 392 | module_init(rmd320_mod_init); |
... | ... | @@ -389,6 +394,4 @@ |
389 | 394 | |
390 | 395 | MODULE_LICENSE("GPL"); |
391 | 396 | MODULE_DESCRIPTION("RIPEMD-320 Message Digest"); |
392 | - | |
393 | -MODULE_ALIAS("rmd320"); |