mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-08-01 10:06:53 +03:00
Add RIPEMD-160 to the generic MD layer
This commit is contained in:
12
library/md.c
12
library/md.c
@ -55,6 +55,10 @@ static const int supported_digests[] = {
|
||||
POLARSSL_MD_MD5,
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_RMD160_C)
|
||||
POLARSSL_MD_RMD160,
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_SHA1_C)
|
||||
POLARSSL_MD_SHA1,
|
||||
#endif
|
||||
@ -95,6 +99,10 @@ const md_info_t *md_info_from_string( const char *md_name )
|
||||
if( !strcasecmp( "MD5", md_name ) )
|
||||
return md_info_from_type( POLARSSL_MD_MD5 );
|
||||
#endif
|
||||
#if defined(POLARSSL_RMD160_C)
|
||||
if( !strcasecmp( "RMD160", md_name ) )
|
||||
return md_info_from_type( POLARSSL_MD_RMD160 );
|
||||
#endif
|
||||
#if defined(POLARSSL_SHA1_C)
|
||||
if( !strcasecmp( "SHA1", md_name ) || !strcasecmp( "SHA", md_name ) )
|
||||
return md_info_from_type( POLARSSL_MD_SHA1 );
|
||||
@ -130,6 +138,10 @@ const md_info_t *md_info_from_type( md_type_t md_type )
|
||||
case POLARSSL_MD_MD5:
|
||||
return &md5_info;
|
||||
#endif
|
||||
#if defined(POLARSSL_RMD160_C)
|
||||
case POLARSSL_MD_RMD160:
|
||||
return &rmd160_info;
|
||||
#endif
|
||||
#if defined(POLARSSL_SHA1_C)
|
||||
case POLARSSL_MD_SHA1:
|
||||
return &sha1_info;
|
||||
|
@ -45,6 +45,10 @@
|
||||
#include "polarssl/md5.h"
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_RMD160_C)
|
||||
#include "polarssl/rmd160.h"
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_SHA1_C)
|
||||
#include "polarssl/sha1.h"
|
||||
#endif
|
||||
@ -320,6 +324,90 @@ const md_info_t md5_info = {
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_RMD160_C)
|
||||
|
||||
static void rmd160_starts_wrap( void *ctx )
|
||||
{
|
||||
rmd160_starts( (rmd160_context *) ctx );
|
||||
}
|
||||
|
||||
static void rmd160_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
|
||||
{
|
||||
rmd160_update( (rmd160_context *) ctx, input, ilen );
|
||||
}
|
||||
|
||||
static void rmd160_finish_wrap( void *ctx, unsigned char *output )
|
||||
{
|
||||
rmd160_finish( (rmd160_context *) ctx, output );
|
||||
}
|
||||
|
||||
static int rmd160_file_wrap( const char *path, unsigned char *output )
|
||||
{
|
||||
#if defined(POLARSSL_FS_IO)
|
||||
return rmd160_file( path, output );
|
||||
#else
|
||||
((void) path);
|
||||
((void) output);
|
||||
return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void rmd160_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
|
||||
{
|
||||
rmd160_hmac_starts( (rmd160_context *) ctx, key, keylen );
|
||||
}
|
||||
|
||||
static void rmd160_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
|
||||
{
|
||||
rmd160_hmac_update( (rmd160_context *) ctx, input, ilen );
|
||||
}
|
||||
|
||||
static void rmd160_hmac_finish_wrap( void *ctx, unsigned char *output )
|
||||
{
|
||||
rmd160_hmac_finish( (rmd160_context *) ctx, output );
|
||||
}
|
||||
|
||||
static void rmd160_hmac_reset_wrap( void *ctx )
|
||||
{
|
||||
rmd160_hmac_reset( (rmd160_context *) ctx );
|
||||
}
|
||||
|
||||
static void * rmd160_ctx_alloc( void )
|
||||
{
|
||||
return polarssl_malloc( sizeof( rmd160_context ) );
|
||||
}
|
||||
|
||||
static void rmd160_ctx_free( void *ctx )
|
||||
{
|
||||
polarssl_free( ctx );
|
||||
}
|
||||
|
||||
static void rmd160_process_wrap( void *ctx, const unsigned char *data )
|
||||
{
|
||||
rmd160_process( (rmd160_context *) ctx, data );
|
||||
}
|
||||
|
||||
const md_info_t rmd160_info = {
|
||||
POLARSSL_MD_RMD160,
|
||||
"RMD160",
|
||||
20,
|
||||
rmd160_starts_wrap,
|
||||
rmd160_update_wrap,
|
||||
rmd160_finish_wrap,
|
||||
rmd160,
|
||||
rmd160_file_wrap,
|
||||
rmd160_hmac_starts_wrap,
|
||||
rmd160_hmac_update_wrap,
|
||||
rmd160_hmac_finish_wrap,
|
||||
rmd160_hmac_reset_wrap,
|
||||
rmd160_hmac,
|
||||
rmd160_ctx_alloc,
|
||||
rmd160_ctx_free,
|
||||
rmd160_process_wrap,
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_SHA1_C)
|
||||
|
||||
static void sha1_starts_wrap( void *ctx )
|
||||
|
@ -81,6 +81,9 @@ void rmd160_starts( rmd160_context *ctx )
|
||||
ctx->state[4] = 0xC3D2E1F0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Process one block
|
||||
*/
|
||||
void rmd160_process( rmd160_context *ctx, const unsigned char data[64] )
|
||||
{
|
||||
uint32_t A, B, C, D, E, Ap, Bp, Cp, Dp, Ep, X[16];
|
||||
|
Reference in New Issue
Block a user