1313 * any later version.
1414 *
1515 */
16+ #include <crypto/internal/hash.h>
1617#include <linux/init.h>
1718#include <linux/module.h>
1819#include <linux/mm.h>
19- #include <linux/crypto.h>
20- #include <linux/cryptohash.h>
2120#include <linux/types.h>
2221#include <asm/byteorder.h>
2322
@@ -233,9 +232,9 @@ static void rmd256_transform(u32 *state, const __le32 *in)
233232 return ;
234233}
235234
236- static void rmd256_init (struct crypto_tfm * tfm )
235+ static int rmd256_init (struct shash_desc * desc )
237236{
238- struct rmd256_ctx * rctx = crypto_tfm_ctx ( tfm );
237+ struct rmd256_ctx * rctx = shash_desc_ctx ( desc );
239238
240239 rctx -> byte_count = 0 ;
241240
@@ -249,12 +248,14 @@ static void rmd256_init(struct crypto_tfm *tfm)
249248 rctx -> state [7 ] = RMD_H8 ;
250249
251250 memset (rctx -> buffer , 0 , sizeof (rctx -> buffer ));
251+
252+ return 0 ;
252253}
253254
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 )
256257{
257- struct rmd256_ctx * rctx = crypto_tfm_ctx ( tfm );
258+ struct rmd256_ctx * rctx = shash_desc_ctx ( desc );
258259 const u32 avail = sizeof (rctx -> buffer ) - (rctx -> byte_count & 0x3f );
259260
260261 rctx -> byte_count += len ;
@@ -263,7 +264,7 @@ static void rmd256_update(struct crypto_tfm *tfm, const u8 *data,
263264 if (avail > len ) {
264265 memcpy ((char * )rctx -> buffer + (sizeof (rctx -> buffer ) - avail ),
265266 data , len );
266- return ;
267+ goto out ;
267268 }
268269
269270 memcpy ((char * )rctx -> buffer + (sizeof (rctx -> buffer ) - avail ),
@@ -281,12 +282,15 @@ static void rmd256_update(struct crypto_tfm *tfm, const u8 *data,
281282 }
282283
283284 memcpy (rctx -> buffer , data , len );
285+
286+ out :
287+ return 0 ;
284288}
285289
286290/* 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 )
288292{
289- struct rmd256_ctx * rctx = crypto_tfm_ctx ( tfm );
293+ struct rmd256_ctx * rctx = shash_desc_ctx ( desc );
290294 u32 i , index , padlen ;
291295 __le64 bits ;
292296 __le32 * dst = (__le32 * )out ;
@@ -297,48 +301,47 @@ static void rmd256_final(struct crypto_tfm *tfm, u8 *out)
297301 /* Pad out to 56 mod 64 */
298302 index = rctx -> byte_count & 0x3f ;
299303 padlen = (index < 56 ) ? (56 - index ) : ((64 + 56 ) - index );
300- rmd256_update (tfm , padding , padlen );
304+ rmd256_update (desc , padding , padlen );
301305
302306 /* Append length */
303- rmd256_update (tfm , (const u8 * )& bits , sizeof (bits ));
307+ rmd256_update (desc , (const u8 * )& bits , sizeof (bits ));
304308
305309 /* Store state in digest */
306310 for (i = 0 ; i < 8 ; i ++ )
307311 dst [i ] = cpu_to_le32p (& rctx -> state [i ]);
308312
309313 /* Wipe context */
310314 memset (rctx , 0 , sizeof (* rctx ));
315+
316+ return 0 ;
311317}
312318
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+ }
326331};
327332
328333static int __init rmd256_mod_init (void )
329334{
330- return crypto_register_alg (& alg );
335+ return crypto_register_shash (& alg );
331336}
332337
333338static void __exit rmd256_mod_fini (void )
334339{
335- crypto_unregister_alg (& alg );
340+ crypto_unregister_shash (& alg );
336341}
337342
338343module_init (rmd256_mod_init );
339344module_exit (rmd256_mod_fini );
340345
341346MODULE_LICENSE ("GPL" );
342347MODULE_DESCRIPTION ("RIPEMD-256 Message Digest" );
343-
344- MODULE_ALIAS ("rmd256" );
0 commit comments