Commit 61b699ed authored by Paul Bakker's avatar Paul Bakker
Browse files

Renamed RMD160 to RIPEMD160

parent e4d47a65
......@@ -1559,15 +1559,15 @@
#define POLARSSL_PKCS12_C
/**
* \def POLARSSL_RMD160_C
* \def POLARSSL_RIPEMD160_C
*
* Enable the RIPEMD-160 hash algorithm.
*
* Module: library/rmd160.c
* Module: library/ripemd160.c
* Caller: library/md.c
*
*/
#define POLARSSL_RMD160_C
#define POLARSSL_RIPEMD160_C
/**
* \def POLARSSL_RSA_C
......
......@@ -58,7 +58,7 @@ typedef enum {
POLARSSL_MD_SHA256,
POLARSSL_MD_SHA384,
POLARSSL_MD_SHA512,
POLARSSL_MD_RMD160,
POLARSSL_MD_RIPEMD160,
} md_type_t;
#if defined(POLARSSL_SHA512_C)
......
......@@ -45,8 +45,8 @@ extern const md_info_t md4_info;
#if defined(POLARSSL_MD5_C)
extern const md_info_t md5_info;
#endif
#if defined(POLARSSL_RMD160_C)
extern const md_info_t rmd160_info;
#if defined(POLARSSL_RIPEMD160_C)
extern const md_info_t ripemd160_info;
#endif
#if defined(POLARSSL_SHA1_C)
extern const md_info_t sha1_info;
......
......@@ -24,8 +24,8 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef POLARSSL_RMD160_H
#define POLARSSL_RMD160_H
#ifndef POLARSSL_RIPEMD160_H
#define POLARSSL_RIPEMD160_H
#include "config.h"
......@@ -38,14 +38,14 @@ typedef UINT32 uint32_t;
#include <inttypes.h>
#endif
#define POLARSSL_ERR_RMD160_FILE_IO_ERROR -0x0074 /**< Read/write error in file. */
#define POLARSSL_ERR_RIPEMD160_FILE_IO_ERROR -0x0074 /**< Read/write error in file. */
#ifdef __cplusplus
extern "C" {
#endif
/**
* \brief RMD160 context structure
* \brief RIPEMD-160 context structure
*/
typedef struct
{
......@@ -56,115 +56,115 @@ typedef struct
unsigned char ipad[64]; /*!< HMAC: inner padding */
unsigned char opad[64]; /*!< HMAC: outer padding */
}
rmd160_context;
ripemd160_context;
/**
* \brief RMD160 context setup
* \brief RIPEMD-160 context setup
*
* \param ctx context to be initialized
*/
void rmd160_starts( rmd160_context *ctx );
void ripemd160_starts( ripemd160_context *ctx );
/**
* \brief RMD160 process buffer
* \brief RIPEMD-160 process buffer
*
* \param ctx RMD160 context
* \param ctx RIPEMD-160 context
* \param input buffer holding the data
* \param ilen length of the input data
*/
void rmd160_update( rmd160_context *ctx,
const unsigned char *input, size_t ilen );
void ripemd160_update( ripemd160_context *ctx,
const unsigned char *input, size_t ilen );
/**
* \brief RMD160 final digest
* \brief RIPEMD-160 final digest
*
* \param ctx RMD160 context
* \param output RMD160 checksum result
* \param ctx RIPEMD-160 context
* \param output RIPEMD-160 checksum result
*/
void rmd160_finish( rmd160_context *ctx, unsigned char output[20] );
void ripemd160_finish( ripemd160_context *ctx, unsigned char output[20] );
/**
* \brief Output = RMD160( input buffer )
* \brief Output = RIPEMD-160( input buffer )
*
* \param input buffer holding the data
* \param ilen length of the input data
* \param output RMD160 checksum result
* \param output RIPEMD-160 checksum result
*/
void rmd160( const unsigned char *input, size_t ilen,
unsigned char output[20] );
void ripemd160( const unsigned char *input, size_t ilen,
unsigned char output[20] );
#if defined(POLARSSL_FS_IO)
/**
* \brief Output = RMD160( file contents )
* \brief Output = RIPEMD-160( file contents )
*
* \param path input file name
* \param output RMD160 checksum result
* \param output RIPEMD-160 checksum result
*
* \return 0 if successful, or POLARSSL_ERR_RMD160_FILE_IO_ERROR
* \return 0 if successful, or POLARSSL_ERR_RIPEMD160_FILE_IO_ERROR
*/
int rmd160_file( const char *path, unsigned char output[20] );
int ripemd160_file( const char *path, unsigned char output[20] );
#endif /* POLARSSL_FS_IO */
/**
* \brief RMD160 HMAC context setup
* \brief RIPEMD-160 HMAC context setup
*
* \param ctx HMAC context to be initialized
* \param key HMAC secret key
* \param keylen length of the HMAC key
*/
void rmd160_hmac_starts( rmd160_context *ctx,
const unsigned char *key, size_t keylen );
void ripemd160_hmac_starts( ripemd160_context *ctx,
const unsigned char *key, size_t keylen );
/**
* \brief RMD160 HMAC process buffer
* \brief RIPEMD-160 HMAC process buffer
*
* \param ctx HMAC context
* \param input buffer holding the data
* \param ilen length of the input data
*/
void rmd160_hmac_update( rmd160_context *ctx,
const unsigned char *input, size_t ilen );
void ripemd160_hmac_update( ripemd160_context *ctx,
const unsigned char *input, size_t ilen );
/**
* \brief RMD160 HMAC final digest
* \brief RIPEMD-160 HMAC final digest
*
* \param ctx HMAC context
* \param output RMD160 HMAC checksum result
* \param output RIPEMD-160 HMAC checksum result
*/
void rmd160_hmac_finish( rmd160_context *ctx, unsigned char output[20] );
void ripemd160_hmac_finish( ripemd160_context *ctx, unsigned char output[20] );
/**
* \brief RMD160 HMAC context reset
* \brief RIPEMD-160 HMAC context reset
*
* \param ctx HMAC context to be reset
*/
void rmd160_hmac_reset( rmd160_context *ctx );
void ripemd160_hmac_reset( ripemd160_context *ctx );
/**
* \brief Output = HMAC-RMD160( hmac key, input buffer )
* \brief Output = HMAC-RIPEMD-160( hmac key, input buffer )
*
* \param key HMAC secret key
* \param keylen length of the HMAC key
* \param input buffer holding the data
* \param ilen length of the input data
* \param output HMAC-RMD160 result
* \param output HMAC-RIPEMD-160 result
*/
void rmd160_hmac( const unsigned char *key, size_t keylen,
const unsigned char *input, size_t ilen,
unsigned char output[20] );
void ripemd160_hmac( const unsigned char *key, size_t keylen,
const unsigned char *input, size_t ilen,
unsigned char output[20] );
/**
* \brief Checkup routine
*
* \return 0 if successful, or 1 if the test failed
*/
int rmd160_self_test( int verbose );
int ripemd160_self_test( int verbose );
/* Internal use */
void rmd160_process( rmd160_context *ctx, const unsigned char data[64] );
void ripemd160_process( ripemd160_context *ctx, const unsigned char data[64] );
#ifdef __cplusplus
}
#endif
#endif /* rmd160.h */
#endif /* ripemd160.h */
......@@ -45,7 +45,7 @@ set(src
pk_wrap.c
pkparse.c
pkwrite.c
rmd160.c
ripemd160.c
rsa.c
sha1.c
sha256.c
......
......@@ -51,7 +51,7 @@ OBJS= aes.o aesni.o arc4.o \
padlock.o pbkdf2.o pem.o \
pkcs5.o pkcs11.o pkcs12.o \
pk.o pk_wrap.o pkparse.o \
pkwrite.o rmd160.o \
pkwrite.o ripemd160.o \
rsa.o sha1.o sha256.o \
sha512.o ssl_cache.o ssl_cli.o \
ssl_srv.o ssl_ciphersuites.o \
......
......@@ -55,8 +55,8 @@ static const int supported_digests[] = {
POLARSSL_MD_MD5,
#endif
#if defined(POLARSSL_RMD160_C)
POLARSSL_MD_RMD160,
#if defined(POLARSSL_RIPEMD160_C)
POLARSSL_MD_RIPEMD160,
#endif
#if defined(POLARSSL_SHA1_C)
......@@ -99,9 +99,9 @@ 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 );
#if defined(POLARSSL_RIPEMD160_C)
if( !strcasecmp( "RIPEMD160", md_name ) )
return md_info_from_type( POLARSSL_MD_RIPEMD160 );
#endif
#if defined(POLARSSL_SHA1_C)
if( !strcasecmp( "SHA1", md_name ) || !strcasecmp( "SHA", md_name ) )
......@@ -138,9 +138,9 @@ 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;
#if defined(POLARSSL_RIPEMD160_C)
case POLARSSL_MD_RIPEMD160:
return &ripemd160_info;
#endif
#if defined(POLARSSL_SHA1_C)
case POLARSSL_MD_SHA1:
......
......@@ -45,8 +45,8 @@
#include "polarssl/md5.h"
#endif
#if defined(POLARSSL_RMD160_C)
#include "polarssl/rmd160.h"
#if defined(POLARSSL_RIPEMD160_C)
#include "polarssl/ripemd160.h"
#endif
#if defined(POLARSSL_SHA1_C)
......@@ -324,27 +324,27 @@ const md_info_t md5_info = {
#endif
#if defined(POLARSSL_RMD160_C)
#if defined(POLARSSL_RIPEMD160_C)
static void rmd160_starts_wrap( void *ctx )
static void ripemd160_starts_wrap( void *ctx )
{
rmd160_starts( (rmd160_context *) ctx );
ripemd160_starts( (ripemd160_context *) ctx );
}
static void rmd160_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
static void ripemd160_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
{
rmd160_update( (rmd160_context *) ctx, input, ilen );
ripemd160_update( (ripemd160_context *) ctx, input, ilen );
}
static void rmd160_finish_wrap( void *ctx, unsigned char *output )
static void ripemd160_finish_wrap( void *ctx, unsigned char *output )
{
rmd160_finish( (rmd160_context *) ctx, output );
ripemd160_finish( (ripemd160_context *) ctx, output );
}
static int rmd160_file_wrap( const char *path, unsigned char *output )
static int ripemd160_file_wrap( const char *path, unsigned char *output )
{
#if defined(POLARSSL_FS_IO)
return rmd160_file( path, output );
return ripemd160_file( path, output );
#else
((void) path);
((void) output);
......@@ -352,58 +352,58 @@ static int rmd160_file_wrap( const char *path, unsigned char *output )
#endif
}
static void rmd160_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
static void ripemd160_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
{
rmd160_hmac_starts( (rmd160_context *) ctx, key, keylen );
ripemd160_hmac_starts( (ripemd160_context *) ctx, key, keylen );
}
static void rmd160_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
static void ripemd160_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
{
rmd160_hmac_update( (rmd160_context *) ctx, input, ilen );
ripemd160_hmac_update( (ripemd160_context *) ctx, input, ilen );
}
static void rmd160_hmac_finish_wrap( void *ctx, unsigned char *output )
static void ripemd160_hmac_finish_wrap( void *ctx, unsigned char *output )
{
rmd160_hmac_finish( (rmd160_context *) ctx, output );
ripemd160_hmac_finish( (ripemd160_context *) ctx, output );
}
static void rmd160_hmac_reset_wrap( void *ctx )
static void ripemd160_hmac_reset_wrap( void *ctx )
{
rmd160_hmac_reset( (rmd160_context *) ctx );
ripemd160_hmac_reset( (ripemd160_context *) ctx );
}
static void * rmd160_ctx_alloc( void )
static void * ripemd160_ctx_alloc( void )
{
return polarssl_malloc( sizeof( rmd160_context ) );
return polarssl_malloc( sizeof( ripemd160_context ) );
}
static void rmd160_ctx_free( void *ctx )
static void ripemd160_ctx_free( void *ctx )
{
polarssl_free( ctx );
}
static void rmd160_process_wrap( void *ctx, const unsigned char *data )
static void ripemd160_process_wrap( void *ctx, const unsigned char *data )
{
rmd160_process( (rmd160_context *) ctx, data );
ripemd160_process( (ripemd160_context *) ctx, data );
}
const md_info_t rmd160_info = {
POLARSSL_MD_RMD160,
"RMD160",
const md_info_t ripemd160_info = {
POLARSSL_MD_RIPEMD160,
"RIPEMD160",
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,
ripemd160_starts_wrap,
ripemd160_update_wrap,
ripemd160_finish_wrap,
ripemd160,
ripemd160_file_wrap,
ripemd160_hmac_starts_wrap,
ripemd160_hmac_update_wrap,
ripemd160_hmac_finish_wrap,
ripemd160_hmac_reset_wrap,
ripemd160_hmac,
ripemd160_ctx_alloc,
ripemd160_ctx_free,
ripemd160_process_wrap,
};
#endif
......
......@@ -31,9 +31,9 @@
#include "polarssl/config.h"
#if defined(POLARSSL_RMD160_C)
#if defined(POLARSSL_RIPEMD160_C)
#include "polarssl/rmd160.h"
#include "polarssl/ripemd160.h"
#if defined(POLARSSL_FS_IO) || defined(POLARSSL_SELF_TEST)
#include <stdio.h>
......@@ -67,9 +67,9 @@
#endif
/*
* RMD160 context setup
* RIPEMD-160 context setup
*/
void rmd160_starts( rmd160_context *ctx )
void ripemd160_starts( ripemd160_context *ctx )
{
ctx->total[0] = 0;
ctx->total[1] = 0;
......@@ -84,7 +84,7 @@ void rmd160_starts( rmd160_context *ctx )
/*
* Process one block
*/
void rmd160_process( rmd160_context *ctx, const unsigned char data[64] )
void ripemd160_process( ripemd160_context *ctx, const unsigned char data[64] )
{
uint32_t A, B, C, D, E, Ap, Bp, Cp, Dp, Ep, X[16];
......@@ -262,10 +262,10 @@ void rmd160_process( rmd160_context *ctx, const unsigned char data[64] )
}
/*
* RMD160 process buffer
* RIPEMD-160 process buffer
*/
void rmd160_update( rmd160_context *ctx,
const unsigned char *input, size_t ilen )
void ripemd160_update( ripemd160_context *ctx,
const unsigned char *input, size_t ilen )
{
size_t fill;
uint32_t left;
......@@ -285,7 +285,7 @@ void rmd160_update( rmd160_context *ctx,
if( left && ilen >= fill )
{
memcpy( (void *) (ctx->buffer + left), input, fill );
rmd160_process( ctx, ctx->buffer );
ripemd160_process( ctx, ctx->buffer );
input += fill;
ilen -= fill;
left = 0;
......@@ -293,7 +293,7 @@ void rmd160_update( rmd160_context *ctx,
while( ilen >= 64 )
{
rmd160_process( ctx, input );
ripemd160_process( ctx, input );
input += 64;
ilen -= 64;
}
......@@ -304,7 +304,7 @@ void rmd160_update( rmd160_context *ctx,
}
}
static const unsigned char rmd160_padding[64] =
static const unsigned char ripemd160_padding[64] =
{
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
......@@ -313,9 +313,9 @@ static const unsigned char rmd160_padding[64] =
};
/*
* RMD160 final digest
* RIPEMD-160 final digest
*/
void rmd160_finish( rmd160_context *ctx, unsigned char output[20] )
void ripemd160_finish( ripemd160_context *ctx, unsigned char output[20] )
{
uint32_t last, padn;
uint32_t high, low;
......@@ -331,8 +331,8 @@ void rmd160_finish( rmd160_context *ctx, unsigned char output[20] )
last = ctx->total[0] & 0x3F;
padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
rmd160_update( ctx, rmd160_padding, padn );
rmd160_update( ctx, msglen, 8 );
ripemd160_update( ctx, ripemd160_padding, padn );
ripemd160_update( ctx, msglen, 8 );
PUT_UINT32_LE( ctx->state[0], output, 0 );
PUT_UINT32_LE( ctx->state[1], output, 4 );
......@@ -342,46 +342,47 @@ void rmd160_finish( rmd160_context *ctx, unsigned char output[20] )
}
/*
* output = RMD160( input buffer )
* output = RIPEMD-160( input buffer )
*/
void rmd160( const unsigned char *input, size_t ilen, unsigned char output[20] )
void ripemd160( const unsigned char *input, size_t ilen,
unsigned char output[20] )
{
rmd160_context ctx;
ripemd160_context ctx;
rmd160_starts( &ctx );
rmd160_update( &ctx, input, ilen );
rmd160_finish( &ctx, output );
ripemd160_starts( &ctx );
ripemd160_update( &ctx, input, ilen );
ripemd160_finish( &ctx, output );
memset( &ctx, 0, sizeof( rmd160_context ) );
memset( &ctx, 0, sizeof( ripemd160_context ) );
}
#if defined(POLARSSL_FS_IO)
/*
* output = RMD160( file contents )
* output = RIPEMD-160( file contents )
*/
int rmd160_file( const char *path, unsigned char output[20] )
int ripemd160_file( const char *path, unsigned char output[20] )
{
FILE *f;
size_t n;
rmd160_context ctx;
ripemd160_context ctx;
unsigned char buf[1024];
if( ( f = fopen( path, "rb" ) ) == NULL )
return( POLARSSL_ERR_RMD160_FILE_IO_ERROR );
return( POLARSSL_ERR_RIPEMD160_FILE_IO_ERROR );
rmd160_starts( &ctx );
ripemd160_starts( &ctx );
while( ( n = fread( buf, 1, sizeof( buf ), f ) ) > 0 )
rmd160_update( &ctx, buf, n );
ripemd160_update( &ctx, buf, n );
rmd160_finish( &ctx, output );
ripemd160_finish( &ctx, output );
memset( &ctx, 0, sizeof( rmd160_context ) );
memset( &ctx, 0, sizeof( ripemd160_context ) );
if( ferror( f ) != 0 )
{
fclose( f );
return( POLARSSL_ERR_RMD160_FILE_IO_ERROR );
return( POLARSSL_ERR_RIPEMD160_FILE_IO_ERROR );
}
fclose( f );
......@@ -389,19 +390,18 @@ int rmd160_file( const char *path, unsigned char output[20] )
}
#endif /* POLARSSL_FS_IO */
/*
* RMD160 HMAC context setup
* RIPEMD-160 HMAC context setup
*/
void rmd160_hmac_starts( rmd160_context *ctx,
const unsigned char *key, size_t keylen )
void ripemd160_hmac_starts( ripemd160_context *ctx,
const unsigned char *key, size_t keylen )
{
size_t i;
unsigned char sum[20];
if( keylen > 64 )
{
rmd160( key, keylen, sum );
ripemd160( key, keylen, sum );
keylen = 20;
key = sum;
}
......@@ -415,60 +415,60 @@ void rmd160_hmac_starts( rmd160_context *ctx,
ctx->opad[i] = (unsigned char)( ctx->opad[i] ^ key[i] );
}
rmd160_starts( ctx );
rmd160_update( ctx, ctx->ipad, 64 );
ripemd160_starts( ctx );
ripemd160_update( ctx, ctx->ipad, 64 );
memset( sum, 0, sizeof( sum ) );
}
/*
* RMD160 HMAC process buffer
* RIPEMD-160 HMAC process buffer
*/
void rmd160_hmac_update( rmd160_context *ctx,
const unsigned char *input, size_t ilen )
void ripemd160_hmac_update( ripemd160_context *ctx,
const unsigned char *input, size_t ilen )
{
rmd160_update( ctx, input, ilen );
ripemd160_update( ctx, input, ilen );
}
/*
* RMD160 HMAC final digest
* RIPEMD-160 HMAC final digest
*/
void rmd160_hmac_finish( rmd160_context *ctx, unsigned char output[20] )
void ripemd160_hmac_finish( ripemd160_context *ctx, unsigned char output[20] )