Commit d8a5e2e9f4e70ade136c67ce8242f0db4c2cddc7
1 parent
e5835fba02
Exists in
master
and in
4 other branches
crypto: rmd256 - Switch to shash
This patch changes rmd256 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
... | ... | @@ -327,7 +327,7 @@ |
327 | 327 | |
328 | 328 | config CRYPTO_RMD256 |
329 | 329 | tristate "RIPEMD-256 digest algorithm" |
330 | - select CRYPTO_ALGAPI | |
330 | + select CRYPTO_HASH | |
331 | 331 | help |
332 | 332 | RIPEMD-256 is an optional extension of RIPEMD-128 with a |
333 | 333 | 256 bit hash. It is intended for applications that require |
crypto/rmd256.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 | |
... | ... | @@ -233,9 +232,9 @@ |
233 | 232 | return; |
234 | 233 | } |
235 | 234 | |
236 | -static void rmd256_init(struct crypto_tfm *tfm) | |
235 | +static int rmd256_init(struct shash_desc *desc) | |
237 | 236 | { |
238 | - struct rmd256_ctx *rctx = crypto_tfm_ctx(tfm); | |
237 | + struct rmd256_ctx *rctx = shash_desc_ctx(desc); | |
239 | 238 | |
240 | 239 | rctx->byte_count = 0; |
241 | 240 | |
242 | 241 | |
243 | 242 | |
... | ... | @@ -249,12 +248,14 @@ |
249 | 248 | rctx->state[7] = RMD_H8; |
250 | 249 | |
251 | 250 | memset(rctx->buffer, 0, sizeof(rctx->buffer)); |
251 | + | |
252 | + return 0; | |
252 | 253 | } |
253 | 254 | |
254 | -static void rmd256_update(struct crypto_tfm *tfm, const u8 *data, | |
255 | - unsigned int len) | |
255 | +static int rmd256_update(struct shash_desc *desc, const u8 *data, | |
256 | + unsigned int len) | |
256 | 257 | { |
257 | - struct rmd256_ctx *rctx = crypto_tfm_ctx(tfm); | |
258 | + struct rmd256_ctx *rctx = shash_desc_ctx(desc); | |
258 | 259 | const u32 avail = sizeof(rctx->buffer) - (rctx->byte_count & 0x3f); |
259 | 260 | |
260 | 261 | rctx->byte_count += len; |
... | ... | @@ -263,7 +264,7 @@ |
263 | 264 | if (avail > len) { |
264 | 265 | memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail), |
265 | 266 | data, len); |
266 | - return; | |
267 | + goto out; | |
267 | 268 | } |
268 | 269 | |
269 | 270 | memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail), |
270 | 271 | |
271 | 272 | |
... | ... | @@ -281,12 +282,15 @@ |
281 | 282 | } |
282 | 283 | |
283 | 284 | memcpy(rctx->buffer, data, len); |
285 | + | |
286 | +out: | |
287 | + return 0; | |
284 | 288 | } |
285 | 289 | |
286 | 290 | /* Add padding and return the message digest. */ |
287 | -static void rmd256_final(struct crypto_tfm *tfm, u8 *out) | |
291 | +static int rmd256_final(struct shash_desc *desc, u8 *out) | |
288 | 292 | { |
289 | - struct rmd256_ctx *rctx = crypto_tfm_ctx(tfm); | |
293 | + struct rmd256_ctx *rctx = shash_desc_ctx(desc); | |
290 | 294 | u32 i, index, padlen; |
291 | 295 | __le64 bits; |
292 | 296 | __le32 *dst = (__le32 *)out; |
293 | 297 | |
... | ... | @@ -297,10 +301,10 @@ |
297 | 301 | /* Pad out to 56 mod 64 */ |
298 | 302 | index = rctx->byte_count & 0x3f; |
299 | 303 | padlen = (index < 56) ? (56 - index) : ((64+56) - index); |
300 | - rmd256_update(tfm, padding, padlen); | |
304 | + rmd256_update(desc, padding, padlen); | |
301 | 305 | |
302 | 306 | /* Append length */ |
303 | - rmd256_update(tfm, (const u8 *)&bits, sizeof(bits)); | |
307 | + rmd256_update(desc, (const u8 *)&bits, sizeof(bits)); | |
304 | 308 | |
305 | 309 | /* Store state in digest */ |
306 | 310 | for (i = 0; i < 8; i++) |
307 | 311 | |
308 | 312 | |
309 | 313 | |
... | ... | @@ -308,31 +312,32 @@ |
308 | 312 | |
309 | 313 | /* Wipe context */ |
310 | 314 | memset(rctx, 0, sizeof(*rctx)); |
315 | + | |
316 | + return 0; | |
311 | 317 | } |
312 | 318 | |
313 | -static struct crypto_alg alg = { | |
314 | - .cra_name = "rmd256", | |
315 | - .cra_driver_name = "rmd256", | |
316 | - .cra_flags = CRYPTO_ALG_TYPE_DIGEST, | |
317 | - .cra_blocksize = RMD256_BLOCK_SIZE, | |
318 | - .cra_ctxsize = sizeof(struct rmd256_ctx), | |
319 | - .cra_module = THIS_MODULE, | |
320 | - .cra_list = LIST_HEAD_INIT(alg.cra_list), | |
321 | - .cra_u = { .digest = { | |
322 | - .dia_digestsize = RMD256_DIGEST_SIZE, | |
323 | - .dia_init = rmd256_init, | |
324 | - .dia_update = rmd256_update, | |
325 | - .dia_final = rmd256_final } } | |
319 | +static struct shash_alg alg = { | |
320 | + .digestsize = RMD256_DIGEST_SIZE, | |
321 | + .init = rmd256_init, | |
322 | + .update = rmd256_update, | |
323 | + .final = rmd256_final, | |
324 | + .descsize = sizeof(struct rmd256_ctx), | |
325 | + .base = { | |
326 | + .cra_name = "rmd256", | |
327 | + .cra_flags = CRYPTO_ALG_TYPE_SHASH, | |
328 | + .cra_blocksize = RMD256_BLOCK_SIZE, | |
329 | + .cra_module = THIS_MODULE, | |
330 | + } | |
326 | 331 | }; |
327 | 332 | |
328 | 333 | static int __init rmd256_mod_init(void) |
329 | 334 | { |
330 | - return crypto_register_alg(&alg); | |
335 | + return crypto_register_shash(&alg); | |
331 | 336 | } |
332 | 337 | |
333 | 338 | static void __exit rmd256_mod_fini(void) |
334 | 339 | { |
335 | - crypto_unregister_alg(&alg); | |
340 | + crypto_unregister_shash(&alg); | |
336 | 341 | } |
337 | 342 | |
338 | 343 | module_init(rmd256_mod_init); |
... | ... | @@ -340,6 +345,4 @@ |
340 | 345 | |
341 | 346 | MODULE_LICENSE("GPL"); |
342 | 347 | MODULE_DESCRIPTION("RIPEMD-256 Message Digest"); |
343 | - | |
344 | -MODULE_ALIAS("rmd256"); |