aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--crypto/Kconfig2
-rw-r--r--crypto/rmd128.c61
2 files changed, 33 insertions, 30 deletions
diff --git a/crypto/Kconfig b/crypto/Kconfig
index 359a7c24af38..848c886d6675 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -297,7 +297,7 @@ config CRYPTO_MICHAEL_MIC
297 297
298config CRYPTO_RMD128 298config CRYPTO_RMD128
299 tristate "RIPEMD-128 digest algorithm" 299 tristate "RIPEMD-128 digest algorithm"
300 select CRYPTO_ALGAPI 300 select CRYPTO_HASH
301 help 301 help
302 RIPEMD-128 (ISO/IEC 10118-3:2004). 302 RIPEMD-128 (ISO/IEC 10118-3:2004).
303 303
diff --git a/crypto/rmd128.c b/crypto/rmd128.c
index 5de6fa2a76fb..1ceb6735aa53 100644
--- a/crypto/rmd128.c
+++ b/crypto/rmd128.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
@@ -218,9 +217,9 @@ static void rmd128_transform(u32 *state, const __le32 *in)
218 return; 217 return;
219} 218}
220 219
221static void rmd128_init(struct crypto_tfm *tfm) 220static int rmd128_init(struct shash_desc *desc)
222{ 221{
223 struct rmd128_ctx *rctx = crypto_tfm_ctx(tfm); 222 struct rmd128_ctx *rctx = shash_desc_ctx(desc);
224 223
225 rctx->byte_count = 0; 224 rctx->byte_count = 0;
226 225
@@ -230,12 +229,14 @@ static void rmd128_init(struct crypto_tfm *tfm)
230 rctx->state[3] = RMD_H3; 229 rctx->state[3] = RMD_H3;
231 230
232 memset(rctx->buffer, 0, sizeof(rctx->buffer)); 231 memset(rctx->buffer, 0, sizeof(rctx->buffer));
232
233 return 0;
233} 234}
234 235
235static void rmd128_update(struct crypto_tfm *tfm, const u8 *data, 236static int rmd128_update(struct shash_desc *desc, const u8 *data,
236 unsigned int len) 237 unsigned int len)
237{ 238{
238 struct rmd128_ctx *rctx = crypto_tfm_ctx(tfm); 239 struct rmd128_ctx *rctx = shash_desc_ctx(desc);
239 const u32 avail = sizeof(rctx->buffer) - (rctx->byte_count & 0x3f); 240 const u32 avail = sizeof(rctx->buffer) - (rctx->byte_count & 0x3f);
240 241
241 rctx->byte_count += len; 242 rctx->byte_count += len;
@@ -244,7 +245,7 @@ static void rmd128_update(struct crypto_tfm *tfm, const u8 *data,
244 if (avail > len) { 245 if (avail > len) {
245 memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail), 246 memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail),
246 data, len); 247 data, len);
247 return; 248 goto out;
248 } 249 }
249 250
250 memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail), 251 memcpy((char *)rctx->buffer + (sizeof(rctx->buffer) - avail),
@@ -262,12 +263,15 @@ static void rmd128_update(struct crypto_tfm *tfm, const u8 *data,
262 } 263 }
263 264
264 memcpy(rctx->buffer, data, len); 265 memcpy(rctx->buffer, data, len);
266
267out:
268 return 0;
265} 269}
266 270
267/* Add padding and return the message digest. */ 271/* Add padding and return the message digest. */
268static void rmd128_final(struct crypto_tfm *tfm, u8 *out) 272static int rmd128_final(struct shash_desc *desc, u8 *out)
269{ 273{
270 struct rmd128_ctx *rctx = crypto_tfm_ctx(tfm); 274 struct rmd128_ctx *rctx = shash_desc_ctx(desc);
271 u32 i, index, padlen; 275 u32 i, index, padlen;
272 __le64 bits; 276 __le64 bits;
273 __le32 *dst = (__le32 *)out; 277 __le32 *dst = (__le32 *)out;
@@ -278,10 +282,10 @@ static void rmd128_final(struct crypto_tfm *tfm, u8 *out)
278 /* Pad out to 56 mod 64 */ 282 /* Pad out to 56 mod 64 */
279 index = rctx->byte_count & 0x3f; 283 index = rctx->byte_count & 0x3f;
280 padlen = (index < 56) ? (56 - index) : ((64+56) - index); 284 padlen = (index < 56) ? (56 - index) : ((64+56) - index);
281 rmd128_update(tfm, padding, padlen); 285 rmd128_update(desc, padding, padlen);
282 286
283 /* Append length */ 287 /* Append length */
284 rmd128_update(tfm, (const u8 *)&bits, sizeof(bits)); 288 rmd128_update(desc, (const u8 *)&bits, sizeof(bits));
285 289
286 /* Store state in digest */ 290 /* Store state in digest */
287 for (i = 0; i < 4; i++) 291 for (i = 0; i < 4; i++)
@@ -289,31 +293,32 @@ static void rmd128_final(struct crypto_tfm *tfm, u8 *out)
289 293
290 /* Wipe context */ 294 /* Wipe context */
291 memset(rctx, 0, sizeof(*rctx)); 295 memset(rctx, 0, sizeof(*rctx));
296
297 return 0;
292} 298}
293 299
294static struct crypto_alg alg = { 300static struct shash_alg alg = {
295 .cra_name = "rmd128", 301 .digestsize = RMD128_DIGEST_SIZE,
296 .cra_driver_name = "rmd128", 302 .init = rmd128_init,
297 .cra_flags = CRYPTO_ALG_TYPE_DIGEST, 303 .update = rmd128_update,
298 .cra_blocksize = RMD128_BLOCK_SIZE, 304 .final = rmd128_final,
299 .cra_ctxsize = sizeof(struct rmd128_ctx), 305 .descsize = sizeof(struct rmd128_ctx),
300 .cra_module = THIS_MODULE, 306 .base = {
301 .cra_list = LIST_HEAD_INIT(alg.cra_list), 307 .cra_name = "rmd128",
302 .cra_u = { .digest = { 308 .cra_flags = CRYPTO_ALG_TYPE_SHASH,
303 .dia_digestsize = RMD128_DIGEST_SIZE, 309 .cra_blocksize = RMD128_BLOCK_SIZE,
304 .dia_init = rmd128_init, 310 .cra_module = THIS_MODULE,
305 .dia_update = rmd128_update, 311 }
306 .dia_final = rmd128_final } }
307}; 312};
308 313
309static int __init rmd128_mod_init(void) 314static int __init rmd128_mod_init(void)
310{ 315{
311 return crypto_register_alg(&alg); 316 return crypto_register_shash(&alg);
312} 317}
313 318
314static void __exit rmd128_mod_fini(void) 319static void __exit rmd128_mod_fini(void)
315{ 320{
316 crypto_unregister_alg(&alg); 321 crypto_unregister_shash(&alg);
317} 322}
318 323
319module_init(rmd128_mod_init); 324module_init(rmd128_mod_init);
@@ -321,5 +326,3 @@ module_exit(rmd128_mod_fini);
321 326
322MODULE_LICENSE("GPL"); 327MODULE_LICENSE("GPL");
323MODULE_DESCRIPTION("RIPEMD-128 Message Digest"); 328MODULE_DESCRIPTION("RIPEMD-128 Message Digest");
324
325MODULE_ALIAS("rmd128");