aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2008-11-07 20:58:10 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2008-12-24 19:02:12 -0500
commitd8a5e2e9f4e70ade136c67ce8242f0db4c2cddc7 (patch)
tree410fc989e1fd020146ede9f0b643fe945f9f7eb5 /crypto
parente5835fba0206a331bdefdf5d805d1a384af37c44 (diff)
crypto: rmd256 - Switch to shash
This patch changes rmd256 to the new shash interface. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/Kconfig2
-rw-r--r--crypto/rmd256.c61
2 files changed, 33 insertions, 30 deletions
diff --git a/crypto/Kconfig b/crypto/Kconfig
index 513b9fb6723d..7f3d7954c929 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -327,7 +327,7 @@ config CRYPTO_RMD160
327 327
328config CRYPTO_RMD256 328config CRYPTO_RMD256
329 tristate "RIPEMD-256 digest algorithm" 329 tristate "RIPEMD-256 digest algorithm"
330 select CRYPTO_ALGAPI 330 select CRYPTO_HASH
331 help 331 help
332 RIPEMD-256 is an optional extension of RIPEMD-128 with a 332 RIPEMD-256 is an optional extension of RIPEMD-128 with a
333 256 bit hash. It is intended for applications that require 333 256 bit hash. It is intended for applications that require
diff --git a/crypto/rmd256.c b/crypto/rmd256.c
index e3de5b4cb47f..72eafa8d2e7b 100644
--- a/crypto/rmd256.c
+++ b/crypto/rmd256.c
@@ -13,11 +13,10 @@
13 * any later version. 13 * any later version.
14 * 14 *
15 */ 15 */
16#include <crypto/internal/hash.h>
16#include <linux/init.h> 17#include <linux/init.h>
17#include <linux/module.h> 18#include <linux/module.h>
18#include <linux/mm.h> 19#include <linux/mm.h>
19#include <linux/crypto.h>
20#include <linux/cryptohash.h>
21#include <linux/types.h> 20#include <linux/types.h>
22#include <asm/byteorder.h> 21#include <asm/byteorder.h>
23 22
@@ -233,9 +232,9 @@ static void rmd256_transform(u32 *state, const __le32 *in)
233 return; 232 return;
234} 233}
235 234
236static void rmd256_init(struct crypto_tfm *tfm) 235static 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 rctx->byte_count = 0; 239 rctx->byte_count = 0;
241 240
@@ -249,12 +248,14 @@ static void rmd256_init(struct crypto_tfm *tfm)
249 rctx->state[7] = RMD_H8; 248 rctx->state[7] = RMD_H8;
250 249
251 memset(rctx->buffer, 0, sizeof(rctx->buffer)); 250 memset(rctx->buffer, 0, sizeof(rctx->buffer));
251
252 return 0;
252} 253}
253 254
254static void rmd256_update(struct crypto_tfm *tfm, const u8 *data, 255static int rmd256_update(struct shash_desc *desc, const u8 *data,
255 unsigned int len) 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 const u32 avail = sizeof(rctx->buffer) - (rctx->byte_count & 0x3f); 259 const u32 avail = sizeof(rctx->buffer) - (rctx->byte_count & 0x3f);
259 260
260 rctx->byte_count += len; 261 rctx->byte_count += len;
@@ -263,7 +264,7 @@ static void rmd256_update(struct crypto_tfm *tfm, const u8 *data,
263 if (avail > len) { 264 if (avail > len) {
264 memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail), 265 memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail),
265 data, len); 266 data, len);
266 return; 267 goto out;
267 } 268 }
268 269
269 memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail), 270 memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail),
@@ -281,12 +282,15 @@ static void rmd256_update(struct crypto_tfm *tfm, const u8 *data,
281 } 282 }
282 283
283 memcpy(rctx->buffer, data, len); 284 memcpy(rctx->buffer, data, len);
285
286out:
287 return 0;
284} 288}
285 289
286/* Add padding and return the message digest. */ 290/* Add padding and return the message digest. */
287static void rmd256_final(struct crypto_tfm *tfm, u8 *out) 291static 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 u32 i, index, padlen; 294 u32 i, index, padlen;
291 __le64 bits; 295 __le64 bits;
292 __le32 *dst = (__le32 *)out; 296 __le32 *dst = (__le32 *)out;
@@ -297,10 +301,10 @@ static void rmd256_final(struct crypto_tfm *tfm, u8 *out)
297 /* Pad out to 56 mod 64 */ 301 /* Pad out to 56 mod 64 */
298 index = rctx->byte_count & 0x3f; 302 index = rctx->byte_count & 0x3f;
299 padlen = (index < 56) ? (56 - index) : ((64+56) - index); 303 padlen = (index < 56) ? (56 - index) : ((64+56) - index);
300 rmd256_update(tfm, padding, padlen); 304 rmd256_update(desc, padding, padlen);
301 305
302 /* Append length */ 306 /* Append length */
303 rmd256_update(tfm, (const u8 *)&bits, sizeof(bits)); 307 rmd256_update(desc, (const u8 *)&bits, sizeof(bits));
304 308
305 /* Store state in digest */ 309 /* Store state in digest */
306 for (i = 0; i < 8; i++) 310 for (i = 0; i < 8; i++)
@@ -308,31 +312,32 @@ static void rmd256_final(struct crypto_tfm *tfm, u8 *out)
308 312
309 /* Wipe context */ 313 /* Wipe context */
310 memset(rctx, 0, sizeof(*rctx)); 314 memset(rctx, 0, sizeof(*rctx));
315
316 return 0;
311} 317}
312 318
313static struct crypto_alg alg = { 319static struct shash_alg alg = {
314 .cra_name = "rmd256", 320 .digestsize = RMD256_DIGEST_SIZE,
315 .cra_driver_name = "rmd256", 321 .init = rmd256_init,
316 .cra_flags = CRYPTO_ALG_TYPE_DIGEST, 322 .update = rmd256_update,
317 .cra_blocksize = RMD256_BLOCK_SIZE, 323 .final = rmd256_final,
318 .cra_ctxsize = sizeof(struct rmd256_ctx), 324 .descsize = sizeof(struct rmd256_ctx),
319 .cra_module = THIS_MODULE, 325 .base = {
320 .cra_list = LIST_HEAD_INIT(alg.cra_list), 326 .cra_name = "rmd256",
321 .cra_u = { .digest = { 327 .cra_flags = CRYPTO_ALG_TYPE_SHASH,
322 .dia_digestsize = RMD256_DIGEST_SIZE, 328 .cra_blocksize = RMD256_BLOCK_SIZE,
323 .dia_init = rmd256_init, 329 .cra_module = THIS_MODULE,
324 .dia_update = rmd256_update, 330 }
325 .dia_final = rmd256_final } }
326}; 331};
327 332
328static int __init rmd256_mod_init(void) 333static int __init rmd256_mod_init(void)
329{ 334{
330 return crypto_register_alg(&alg); 335 return crypto_register_shash(&alg);
331} 336}
332 337
333static void __exit rmd256_mod_fini(void) 338static void __exit rmd256_mod_fini(void)
334{ 339{
335 crypto_unregister_alg(&alg); 340 crypto_unregister_shash(&alg);
336} 341}
337 342
338module_init(rmd256_mod_init); 343module_init(rmd256_mod_init);
@@ -340,5 +345,3 @@ module_exit(rmd256_mod_fini);
340 345
341MODULE_LICENSE("GPL"); 346MODULE_LICENSE("GPL");
342MODULE_DESCRIPTION("RIPEMD-256 Message Digest"); 347MODULE_DESCRIPTION("RIPEMD-256 Message Digest");
343
344MODULE_ALIAS("rmd256");