Merged RIPEMD-160 support

This commit is contained in:
Paul Bakker 2014-01-22 14:18:03 +01:00
commit 5862eee4ca
19 changed files with 1232 additions and 128 deletions

View File

@ -3,6 +3,7 @@ PolarSSL ChangeLog (Sorted per branch, date)
= PolarSSL 1.3 branch
Features
* Support for the Koblitz curves: secp192k1, secp224k1, secp256k1
* Support for RIPEMD-160
* Allow for use of PKCS#1 v2.1 via the PK layer (pk_rsa_set_padding() and
rsa_set_padding())

View File

@ -148,6 +148,7 @@
//#define POLARSSL_MD2_ALT
//#define POLARSSL_MD4_ALT
//#define POLARSSL_MD5_ALT
//#define POLARSSL_RIPEMD160_ALT
//#define POLARSSL_SHA1_ALT
//#define POLARSSL_SHA256_ALT
//#define POLARSSL_SHA512_ALT
@ -1561,6 +1562,17 @@
*/
#define POLARSSL_PKCS12_C
/**
* \def POLARSSL_RIPEMD160_C
*
* Enable the RIPEMD-160 hash algorithm.
*
* Module: library/ripemd160.c
* Caller: library/md.c
*
*/
#define POLARSSL_RIPEMD160_C
/**
* \def POLARSSL_RSA_C
*

View File

@ -58,6 +58,7 @@ typedef enum {
POLARSSL_MD_SHA256,
POLARSSL_MD_SHA384,
POLARSSL_MD_SHA512,
POLARSSL_MD_RIPEMD160,
} md_type_t;
#if defined(POLARSSL_SHA512_C)

View File

@ -45,6 +45,9 @@ extern const md_info_t md4_info;
#if defined(POLARSSL_MD5_C)
extern const md_info_t md5_info;
#endif
#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;
#endif

View File

@ -0,0 +1,186 @@
/**
* \file rdm160.h
*
* \brief RIPE MD-160 message digest
*
* Copyright (C) 2014-2014, Brainspark B.V.
*
* This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
*
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef POLARSSL_RIPEMD160_H
#define POLARSSL_RIPEMD160_H
#include "config.h"
#include <string.h>
#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
#include <basetsd.h>
typedef UINT32 uint32_t;
#else
#include <inttypes.h>
#endif
#define POLARSSL_ERR_RIPEMD160_FILE_IO_ERROR -0x0074 /**< Read/write error in file. */
#if !defined(POLARSSL_RIPEMD160_ALT)
// Regular implementation
//
#ifdef __cplusplus
extern "C" {
#endif
/**
* \brief RIPEMD-160 context structure
*/
typedef struct
{
uint32_t total[2]; /*!< number of bytes processed */
uint32_t state[5]; /*!< intermediate digest state */
unsigned char buffer[64]; /*!< data block being processed */
unsigned char ipad[64]; /*!< HMAC: inner padding */
unsigned char opad[64]; /*!< HMAC: outer padding */
}
ripemd160_context;
/**
* \brief RIPEMD-160 context setup
*
* \param ctx context to be initialized
*/
void ripemd160_starts( ripemd160_context *ctx );
/**
* \brief RIPEMD-160 process buffer
*
* \param ctx RIPEMD-160 context
* \param input buffer holding the data
* \param ilen length of the input data
*/
void ripemd160_update( ripemd160_context *ctx,
const unsigned char *input, size_t ilen );
/**
* \brief RIPEMD-160 final digest
*
* \param ctx RIPEMD-160 context
* \param output RIPEMD-160 checksum result
*/
void ripemd160_finish( ripemd160_context *ctx, unsigned char output[20] );
/* Internal use */
void ripemd160_process( ripemd160_context *ctx, const unsigned char data[64] );
#ifdef __cplusplus
}
#endif
#else /* POLARSSL_RIPEMD160_ALT */
#include "ripemd160.h"
#endif /* POLARSSL_RIPEMD160_ALT */
#ifdef __cplusplus
extern "C" {
#endif
/**
* \brief Output = RIPEMD-160( input buffer )
*
* \param input buffer holding the data
* \param ilen length of the input data
* \param output RIPEMD-160 checksum result
*/
void ripemd160( const unsigned char *input, size_t ilen,
unsigned char output[20] );
#if defined(POLARSSL_FS_IO)
/**
* \brief Output = RIPEMD-160( file contents )
*
* \param path input file name
* \param output RIPEMD-160 checksum result
*
* \return 0 if successful, or POLARSSL_ERR_RIPEMD160_FILE_IO_ERROR
*/
int ripemd160_file( const char *path, unsigned char output[20] );
#endif /* POLARSSL_FS_IO */
/**
* \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 ripemd160_hmac_starts( ripemd160_context *ctx,
const unsigned char *key, size_t keylen );
/**
* \brief RIPEMD-160 HMAC process buffer
*
* \param ctx HMAC context
* \param input buffer holding the data
* \param ilen length of the input data
*/
void ripemd160_hmac_update( ripemd160_context *ctx,
const unsigned char *input, size_t ilen );
/**
* \brief RIPEMD-160 HMAC final digest
*
* \param ctx HMAC context
* \param output RIPEMD-160 HMAC checksum result
*/
void ripemd160_hmac_finish( ripemd160_context *ctx, unsigned char output[20] );
/**
* \brief RIPEMD-160 HMAC context reset
*
* \param ctx HMAC context to be reset
*/
void ripemd160_hmac_reset( ripemd160_context *ctx );
/**
* \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-RIPEMD-160 result
*/
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 ripemd160_self_test( int verbose );
#ifdef __cplusplus
}
#endif
#endif /* ripemd160.h */

View File

@ -45,6 +45,7 @@ set(src
pk_wrap.c
pkparse.c
pkwrite.c
ripemd160.c
rsa.c
sha1.c
sha256.c

View File

@ -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 \
pkwrite.o ripemd160.o \
rsa.o sha1.o sha256.o \
sha512.o ssl_cache.o ssl_cli.o \
ssl_srv.o ssl_ciphersuites.o \

View File

@ -55,6 +55,10 @@ static const int supported_digests[] = {
POLARSSL_MD_MD5,
#endif
#if defined(POLARSSL_RIPEMD160_C)
POLARSSL_MD_RIPEMD160,
#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_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 ) )
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_RIPEMD160_C)
case POLARSSL_MD_RIPEMD160:
return &ripemd160_info;
#endif
#if defined(POLARSSL_SHA1_C)
case POLARSSL_MD_SHA1:
return &sha1_info;

View File

@ -45,6 +45,10 @@
#include "polarssl/md5.h"
#endif
#if defined(POLARSSL_RIPEMD160_C)
#include "polarssl/ripemd160.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_RIPEMD160_C)
static void ripemd160_starts_wrap( void *ctx )
{
ripemd160_starts( (ripemd160_context *) ctx );
}
static void ripemd160_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
{
ripemd160_update( (ripemd160_context *) ctx, input, ilen );
}
static void ripemd160_finish_wrap( void *ctx, unsigned char *output )
{
ripemd160_finish( (ripemd160_context *) ctx, output );
}
static int ripemd160_file_wrap( const char *path, unsigned char *output )
{
#if defined(POLARSSL_FS_IO)
return ripemd160_file( path, output );
#else
((void) path);
((void) output);
return POLARSSL_ERR_MD_FEATURE_UNAVAILABLE;
#endif
}
static void ripemd160_hmac_starts_wrap( void *ctx, const unsigned char *key, size_t keylen )
{
ripemd160_hmac_starts( (ripemd160_context *) ctx, key, keylen );
}
static void ripemd160_hmac_update_wrap( void *ctx, const unsigned char *input, size_t ilen )
{
ripemd160_hmac_update( (ripemd160_context *) ctx, input, ilen );
}
static void ripemd160_hmac_finish_wrap( void *ctx, unsigned char *output )
{
ripemd160_hmac_finish( (ripemd160_context *) ctx, output );
}
static void ripemd160_hmac_reset_wrap( void *ctx )
{
ripemd160_hmac_reset( (ripemd160_context *) ctx );
}
static void * ripemd160_ctx_alloc( void )
{
return polarssl_malloc( sizeof( ripemd160_context ) );
}
static void ripemd160_ctx_free( void *ctx )
{
polarssl_free( ctx );
}
static void ripemd160_process_wrap( void *ctx, const unsigned char *data )
{
ripemd160_process( (ripemd160_context *) ctx, data );
}
const md_info_t ripemd160_info = {
POLARSSL_MD_RIPEMD160,
"RIPEMD160",
20,
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
#if defined(POLARSSL_SHA1_C)
static void sha1_starts_wrap( void *ctx )

624
library/ripemd160.c Normal file
View File

@ -0,0 +1,624 @@
/*
* RIPE MD-160 implementation
*
* Copyright (C) 2014-2014, Brainspark B.V.
*
* This file is part of PolarSSL (http://www.polarssl.org)
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
*
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/*
* The RIPEMD-160 algorithm was designed by RIPE in 1996
* http://homes.esat.kuleuven.be/~bosselae/ripemd160.html
* http://ehash.iaik.tugraz.at/wiki/RIPEMD-160
*/
#include "polarssl/config.h"
#if defined(POLARSSL_RIPEMD160_C)
#include "polarssl/ripemd160.h"
#if defined(POLARSSL_FS_IO) || defined(POLARSSL_SELF_TEST)
#include <stdio.h>
#endif
#if defined(POLARSSL_SELF_TEST)
#include <string.h>
#endif
/*
* 32-bit integer manipulation macros (little endian)
*/
#ifndef GET_UINT32_LE
#define GET_UINT32_LE(n,b,i) \
{ \
(n) = ( (uint32_t) (b)[(i) ] ) \
| ( (uint32_t) (b)[(i) + 1] << 8 ) \
| ( (uint32_t) (b)[(i) + 2] << 16 ) \
| ( (uint32_t) (b)[(i) + 3] << 24 ); \
}
#endif
#ifndef PUT_UINT32_LE
#define PUT_UINT32_LE(n,b,i) \
{ \
(b)[(i) ] = (unsigned char) ( (n) ); \
(b)[(i) + 1] = (unsigned char) ( (n) >> 8 ); \
(b)[(i) + 2] = (unsigned char) ( (n) >> 16 ); \
(b)[(i) + 3] = (unsigned char) ( (n) >> 24 ); \
}
#endif
/*
* RIPEMD-160 context setup
*/
void ripemd160_starts( ripemd160_context *ctx )
{
ctx->total[0] = 0;
ctx->total[1] = 0;
ctx->state[0] = 0x67452301;
ctx->state[1] = 0xEFCDAB89;
ctx->state[2] = 0x98BADCFE;
ctx->state[3] = 0x10325476;
ctx->state[4] = 0xC3D2E1F0;
}
/*
* Process one block
*/
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];
GET_UINT32_LE( X[ 0], data, 0 );
GET_UINT32_LE( X[ 1], data, 4 );
GET_UINT32_LE( X[ 2], data, 8 );
GET_UINT32_LE( X[ 3], data, 12 );
GET_UINT32_LE( X[ 4], data, 16 );
GET_UINT32_LE( X[ 5], data, 20 );
GET_UINT32_LE( X[ 6], data, 24 );
GET_UINT32_LE( X[ 7], data, 28 );
GET_UINT32_LE( X[ 8], data, 32 );
GET_UINT32_LE( X[ 9], data, 36 );
GET_UINT32_LE( X[10], data, 40 );
GET_UINT32_LE( X[11], data, 44 );
GET_UINT32_LE( X[12], data, 48 );
GET_UINT32_LE( X[13], data, 52 );
GET_UINT32_LE( X[14], data, 56 );
GET_UINT32_LE( X[15], data, 60 );
A = Ap = ctx->state[0];
B = Bp = ctx->state[1];
C = Cp = ctx->state[2];
D = Dp = ctx->state[3];
E = Ep = ctx->state[4];
#define F1( x, y, z ) ( x ^ y ^ z )
#define F2( x, y, z ) ( ( x & y ) | ( ~x & z ) )
#define F3( x, y, z ) ( ( x | ~y ) ^ z )
#define F4( x, y, z ) ( ( x & z ) | ( y & ~z ) )
#define F5( x, y, z ) ( x ^ ( y | ~z ) )
#define S( x, n ) ( ( x << n ) | ( x >> (32 - n) ) )
#define P( a, b, c, d, e, r, s, f, k ) \
a += f( b, c, d ) + X[r] + k; \
a = S( a, s ) + e; \
c = S( c, 10 );
#define P2( a, b, c, d, e, r, s, rp, sp ) \
P( a, b, c, d, e, r, s, F, K ); \
P( a ## p, b ## p, c ## p, d ## p, e ## p, rp, sp, Fp, Kp );
#define F F1
#define K 0x00000000
#define Fp F5
#define Kp 0x50A28BE6
P2( A, B, C, D, E, 0, 11, 5, 8 );
P2( E, A, B, C, D, 1, 14, 14, 9 );
P2( D, E, A, B, C, 2, 15, 7, 9 );
P2( C, D, E, A, B, 3, 12, 0, 11 );
P2( B, C, D, E, A, 4, 5, 9, 13 );
P2( A, B, C, D, E, 5, 8, 2, 15 );
P2( E, A, B, C, D, 6, 7, 11, 15 );
P2( D, E, A, B, C, 7, 9, 4, 5 );
P2( C, D, E, A, B, 8, 11, 13, 7 );
P2( B, C, D, E, A, 9, 13, 6, 7 );
P2( A, B, C, D, E, 10, 14, 15, 8 );
P2( E, A, B, C, D, 11, 15, 8, 11 );
P2( D, E, A, B, C, 12, 6, 1, 14 );
P2( C, D, E, A, B, 13, 7, 10, 14 );
P2( B, C, D, E, A, 14, 9, 3, 12 );
P2( A, B, C, D, E, 15, 8, 12, 6 );
#undef F
#undef K
#undef Fp
#undef Kp
#define F F2
#define K 0x5A827999
#define Fp F4
#define Kp 0x5C4DD124
P2( E, A, B, C, D, 7, 7, 6, 9 );
P2( D, E, A, B, C, 4, 6, 11, 13 );
P2( C, D, E, A, B, 13, 8, 3, 15 );
P2( B, C, D, E, A, 1, 13, 7, 7 );
P2( A, B, C, D, E, 10, 11, 0, 12 );
P2( E, A, B, C, D, 6, 9, 13, 8 );
P2( D, E, A, B, C, 15, 7, 5, 9 );
P2( C, D, E, A, B, 3, 15, 10, 11 );
P2( B, C, D, E, A, 12, 7, 14, 7 );
P2( A, B, C, D, E, 0, 12, 15, 7 );
P2( E, A, B, C, D, 9, 15, 8, 12 );
P2( D, E, A, B, C, 5, 9, 12, 7 );
P2( C, D, E, A, B, 2, 11, 4, 6 );
P2( B, C, D, E, A, 14, 7, 9, 15 );
P2( A, B, C, D, E, 11, 13, 1, 13 );
P2( E, A, B, C, D, 8, 12, 2, 11 );
#undef F
#undef K
#undef Fp
#undef Kp
#define F F3
#define K 0x6ED9EBA1
#define Fp F3
#define Kp 0x6D703EF3
P2( D, E, A, B, C, 3, 11, 15, 9 );
P2( C, D, E, A, B, 10, 13, 5, 7 );
P2( B, C, D, E, A, 14, 6, 1, 15 );
P2( A, B, C, D, E, 4, 7, 3, 11 );
P2( E, A, B, C, D, 9, 14, 7, 8 );
P2( D, E, A, B, C, 15, 9, 14, 6 );
P2( C, D, E, A, B, 8, 13, 6, 6 );
P2( B, C, D, E, A, 1, 15, 9, 14 );
P2( A, B, C, D, E, 2, 14, 11, 12 );
P2( E, A, B, C, D, 7, 8, 8, 13 );
P2( D, E, A, B, C, 0, 13, 12, 5 );
P2( C, D, E, A, B, 6, 6, 2, 14 );
P2( B, C, D, E, A, 13, 5, 10, 13 );
P2( A, B, C, D, E, 11, 12, 0, 13 );
P2( E, A, B, C, D, 5, 7, 4, 7 );
P2( D, E, A, B, C, 12, 5, 13, 5 );
#undef F
#undef K
#undef Fp
#undef Kp
#define F F4
#define K 0x8F1BBCDC
#define Fp F2
#define Kp 0x7A6D76E9
P2( C, D, E, A, B, 1, 11, 8, 15 );
P2( B, C, D, E, A, 9, 12, 6, 5 );
P2( A, B, C, D, E, 11, 14, 4, 8 );
P2( E, A, B, C, D, 10, 15, 1, 11 );
P2( D, E, A, B, C, 0, 14, 3, 14 );
P2( C, D, E, A, B, 8, 15, 11, 14 );
P2( B, C, D, E, A, 12, 9, 15, 6 );
P2( A, B, C, D, E, 4, 8, 0, 14 );
P2( E, A, B, C, D, 13, 9, 5, 6 );
P2( D, E, A, B, C, 3, 14, 12, 9 );
P2( C, D, E, A, B, 7, 5, 2, 12 );
P2( B, C, D, E, A, 15, 6, 13, 9 );
P2( A, B, C, D, E, 14, 8, 9, 12 );
P2( E, A, B, C, D, 5, 6, 7, 5 );
P2( D, E, A, B, C, 6, 5, 10, 15 );
P2( C, D, E, A, B, 2, 12, 14, 8 );
#undef F
#undef K
#undef Fp
#undef Kp
#define F F5
#define K 0xA953FD4E
#define Fp F1
#define Kp 0x00000000
P2( B, C, D, E, A, 4, 9, 12, 8 );
P2( A, B, C, D, E, 0, 15, 15, 5 );
P2( E, A, B, C, D, 5, 5, 10, 12 );
P2( D, E, A, B, C, 9, 11, 4, 9 );
P2( C, D, E, A, B, 7, 6, 1, 12 );
P2( B, C, D, E, A, 12, 8, 5, 5 );
P2( A, B, C, D, E, 2, 13, 8, 14 );
P2( E, A, B, C, D, 10, 12, 7, 6 );
P2( D, E, A, B, C, 14, 5, 6, 8 );
P2( C, D, E, A, B, 1, 12, 2, 13 );
P2( B, C, D, E, A, 3, 13, 13, 6 );
P2( A, B, C, D, E, 8, 14, 14, 5 );
P2( E, A, B, C, D, 11, 11, 0, 15 );
P2( D, E, A, B, C, 6, 8, 3, 13 );
P2( C, D, E, A, B, 15, 5, 9, 11 );
P2( B, C, D, E, A, 13, 6, 11, 11 );
#undef F
#undef K
#undef Fp
#undef Kp
C = ctx->state[1] + C + Dp;
ctx->state[1] = ctx->state[2] + D + Ep;
ctx->state[2] = ctx->state[3] + E + Ap;
ctx->state[3] = ctx->state[4] + A + Bp;
ctx->state[4] = ctx->state[0] + B + Cp;
ctx->state[0] = C;
}
/*
* RIPEMD-160 process buffer
*/
void ripemd160_update( ripemd160_context *ctx,
const unsigned char *input, size_t ilen )
{
size_t fill;
uint32_t left;
if( ilen <= 0 )
return;
left = ctx->total[0] & 0x3F;
fill = 64 - left;
ctx->total[0] += (uint32_t) ilen;
ctx->total[0] &= 0xFFFFFFFF;
if( ctx->total[0] < (uint32_t) ilen )
ctx->total[1]++;
if( left && ilen >= fill )
{
memcpy( (void *) (ctx->buffer + left), input, fill );
ripemd160_process( ctx, ctx->buffer );
input += fill;
ilen -= fill;
left = 0;
}
while( ilen >= 64 )
{
ripemd160_process( ctx, input );
input += 64;
ilen -= 64;
}
if( ilen > 0 )
{
memcpy( (void *) (ctx->buffer + left), input, ilen );
}
}
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,
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, 0
};
/*
* RIPEMD-160 final digest
*/
void ripemd160_finish( ripemd160_context *ctx, unsigned char output[20] )
{
uint32_t last, padn;
uint32_t high, low;
unsigned char msglen[8];
high = ( ctx->total[0] >> 29 )
| ( ctx->total[1] << 3 );
low = ( ctx->total[0] << 3 );
PUT_UINT32_LE( low, msglen, 0 );
PUT_UINT32_LE( high, msglen, 4 );
last = ctx->total[0] & 0x3F;
padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
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 );
PUT_UINT32_LE( ctx->state[2], output, 8 );
PUT_UINT32_LE( ctx->state[3], output, 12 );
PUT_UINT32_LE( ctx->state[4], output, 16 );
}
/*
* output = RIPEMD-160( input buffer )
*/
void ripemd160( const unsigned char *input, size_t ilen,
unsigned char output[20] )
{
ripemd160_context ctx;
ripemd160_starts( &ctx );
ripemd160_update( &ctx, input, ilen );
ripemd160_finish( &ctx, output );
memset( &ctx, 0, sizeof( ripemd160_context ) );
}
#if defined(POLARSSL_FS_IO)
/*
* output = RIPEMD-160( file contents )
*/
int ripemd160_file( const char *path, unsigned char output[20] )
{
FILE *f;
size_t n;
ripemd160_context ctx;
unsigned char buf[1024];
if( ( f = fopen( path, "rb" ) ) == NULL )
return( POLARSSL_ERR_RIPEMD160_FILE_IO_ERROR );
ripemd160_starts( &ctx );
while( ( n = fread( buf, 1, sizeof( buf ), f ) ) > 0 )
ripemd160_update( &ctx, buf, n );
ripemd160_finish( &ctx, output );
memset( &ctx, 0, sizeof( ripemd160_context ) );
if( ferror( f ) != 0 )
{
fclose( f );
return( POLARSSL_ERR_RIPEMD160_FILE_IO_ERROR );
}
fclose( f );
return( 0 );
}
#endif /* POLARSSL_FS_IO */
/*
* RIPEMD-160 HMAC context setup
*/
void ripemd160_hmac_starts( ripemd160_context *ctx,
const unsigned char *key, size_t keylen )
{
size_t i;
unsigned char sum[20];
if( keylen > 64 )
{
ripemd160( key, keylen, sum );
keylen = 20;
key = sum;
}
memset( ctx->ipad, 0x36, 64 );
memset( ctx->opad, 0x5C, 64 );
for( i = 0; i < keylen; i++ )
{
ctx->ipad[i] = (unsigned char)( ctx->ipad[i] ^ key[i] );
ctx->opad[i] = (unsigned char)( ctx->opad[i] ^ key[i] );
}
ripemd160_starts( ctx );
ripemd160_update( ctx, ctx->ipad, 64 );
memset( sum, 0, sizeof( sum ) );
}
/*
* RIPEMD-160 HMAC process buffer
*/
void ripemd160_hmac_update( ripemd160_context *ctx,
const unsigned char *input, size_t ilen )
{
ripemd160_update( ctx, input, ilen );
}
/*
* RIPEMD-160 HMAC final digest
*/
void ripemd160_hmac_finish( ripemd160_context *ctx, unsigned char output[20] )
{
unsigned char tmpbuf[20];
ripemd160_finish( ctx, tmpbuf );
ripemd160_starts( ctx );
ripemd160_update( ctx, ctx->opad, 64 );
ripemd160_update( ctx, tmpbuf, 20 );
ripemd160_finish( ctx, output );
memset( tmpbuf, 0, sizeof( tmpbuf ) );
}
/*
* RIPEMD-160 HMAC context reset
*/
void ripemd160_hmac_reset( ripemd160_context *ctx )
{
ripemd160_starts( ctx );
ripemd160_update( ctx, ctx->ipad, 64 );
}
/*
* output = HMAC-RIPEMD-160( hmac key, input buffer )
*/
void ripemd160_hmac( const unsigned char *key, size_t keylen,
const unsigned char *input, size_t ilen,
unsigned char output[20] )
{
ripemd160_context ctx;
ripemd160_hmac_starts( &ctx, key, keylen );
ripemd160_hmac_update( &ctx, input, ilen );
ripemd160_hmac_finish( &ctx, output );
memset( &ctx, 0, sizeof( ripemd160_context ) );
}
#if defined(POLARSSL_SELF_TEST)
/*
* Test vectors from the RIPEMD-160 paper and
* http://homes.esat.kuleuven.be/~bosselae/ripemd160.html#HMAC
*/
#define TESTS 8
#define KEYS 2
static const char *ripemd160_test_input[TESTS] =
{
"",
"a",
"abc",
"message digest",
"abcdefghijklmnopqrstuvwxyz",
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
"1234567890123456789012345678901234567890"
"1234567890123456789012345678901234567890",
};
static const unsigned char ripemd160_test_md[TESTS][20] =
{
{ 0x9c, 0x11, 0x85, 0xa5, 0xc5, 0xe9, 0xfc, 0x54, 0x61, 0x28,
0x08, 0x97, 0x7e, 0xe8, 0xf5, 0x48, 0xb2, 0x25, 0x8d, 0x31 },
{ 0x0b, 0xdc, 0x9d, 0x2d, 0x25, 0x6b, 0x3e, 0xe9, 0xda, 0xae,
0x34, 0x7b, 0xe6, 0xf4, 0xdc, 0x83, 0x5a, 0x46, 0x7f, 0xfe },
{ 0x8e, 0xb2, 0x08, 0xf7, 0xe0, 0x5d, 0x98, 0x7a, 0x9b, 0x04,
0x4a, 0x8e, 0x98, 0xc6, 0xb0, 0x87, 0xf1, 0x5a, 0x0b, 0xfc },
{ 0x5d, 0x06, 0x89, 0xef, 0x49, 0xd2, 0xfa, 0xe5, 0x72, 0xb8,
0x81, 0xb1, 0x23, 0xa8, 0x5f, 0xfa, 0x21, 0x59, 0x5f, 0x36 },
{ 0xf7, 0x1c, 0x27, 0x10, 0x9c, 0x69, 0x2c, 0x1b, 0x56, 0xbb,
0xdc, 0xeb, 0x5b, 0x9d, 0x28, 0x65, 0xb3, 0x70, 0x8d, 0xbc },
{ 0x12, 0xa0, 0x53, 0x38, 0x4a, 0x9c, 0x0c, 0x88, 0xe4, 0x05,
0xa0, 0x6c, 0x27, 0xdc, 0xf4, 0x9a, 0xda, 0x62, 0xeb, 0x2b },
{ 0xb0, 0xe2, 0x0b, 0x6e, 0x31, 0x16, 0x64, 0x02, 0x86, 0xed,
0x3a, 0x87, 0xa5, 0x71, 0x30, 0x79, 0xb2, 0x1f, 0x51, 0x89 },
{ 0x9b, 0x75, 0x2e, 0x45, 0x57, 0x3d, 0x4b, 0x39, 0xf4, 0xdb,
0xd3, 0x32, 0x3c, 0xab, 0x82, 0xbf, 0x63, 0x32, 0x6b, 0xfb },
};
static const unsigned char ripemd160_test_hmac[KEYS][TESTS][20] =
{
{
{ 0xcf, 0x38, 0x76, 0x77, 0xbf, 0xda, 0x84, 0x83, 0xe6, 0x3b,
0x57, 0xe0, 0x6c, 0x3b, 0x5e, 0xcd, 0x8b, 0x7f, 0xc0, 0x55 },
{ 0x0d, 0x35, 0x1d, 0x71, 0xb7, 0x8e, 0x36, 0xdb, 0xb7, 0x39,
0x1c, 0x81, 0x0a, 0x0d, 0x2b, 0x62, 0x40, 0xdd, 0xba, 0xfc },
{ 0xf7, 0xef, 0x28, 0x8c, 0xb1, 0xbb, 0xcc, 0x61, 0x60, 0xd7,
0x65, 0x07, 0xe0, 0xa3, 0xbb, 0xf7, 0x12, 0xfb, 0x67, 0xd6 },
{ 0xf8, 0x36, 0x62, 0xcc, 0x8d, 0x33, 0x9c, 0x22, 0x7e, 0x60,
0x0f, 0xcd, 0x63, 0x6c, 0x57, 0xd2, 0x57, 0x1b, 0x1c, 0x34 },
{ 0x84, 0x3d, 0x1c, 0x4e, 0xb8, 0x80, 0xac, 0x8a, 0xc0, 0xc9,
0xc9, 0x56, 0x96, 0x50, 0x79, 0x57, 0xd0, 0x15, 0x5d, 0xdb },
{ 0x60, 0xf5, 0xef, 0x19, 0x8a, 0x2d, 0xd5, 0x74, 0x55, 0x45,
0xc1, 0xf0, 0xc4, 0x7a, 0xa3, 0xfb, 0x57, 0x76, 0xf8, 0x81 },
{ 0xe4, 0x9c, 0x13, 0x6a, 0x9e, 0x56, 0x27, 0xe0, 0x68, 0x1b,
0x80, 0x8a, 0x3b, 0x97, 0xe6, 0xa6, 0xe6, 0x61, 0xae, 0x79 },
{ 0x31, 0xbe, 0x3c, 0xc9, 0x8c, 0xee, 0x37, 0xb7, 0x9b, 0x06,
0x19, 0xe3, 0xe1, 0xc2, 0xbe, 0x4f, 0x1a, 0xa5, 0x6e, 0x6c },
},
{
{ 0xfe, 0x69, 0xa6, 0x6c, 0x74, 0x23, 0xee, 0xa9, 0xc8, 0xfa,
0x2e, 0xff, 0x8d, 0x9d, 0xaf, 0xb4, 0xf1, 0x7a, 0x62, 0xf5 },
{ 0x85, 0x74, 0x3e, 0x89, 0x9b, 0xc8, 0x2d, 0xbf, 0xa3, 0x6f,
0xaa, 0xa7, 0xa2, 0x5b, 0x7c, 0xfd, 0x37, 0x24, 0x32, 0xcd },
{ 0x6e, 0x4a, 0xfd, 0x50, 0x1f, 0xa6, 0xb4, 0xa1, 0x82, 0x3c,
0xa3, 0xb1, 0x0b, 0xd9, 0xaa, 0x0b, 0xa9, 0x7b, 0xa1, 0x82 },
{ 0x2e, 0x06, 0x6e, 0x62, 0x4b, 0xad, 0xb7, 0x6a, 0x18, 0x4c,
0x8f, 0x90, 0xfb, 0xa0, 0x53, 0x33, 0x0e, 0x65, 0x0e, 0x92 },
{ 0x07, 0xe9, 0x42, 0xaa, 0x4e, 0x3c, 0xd7, 0xc0, 0x4d, 0xed,
0xc1, 0xd4, 0x6e, 0x2e, 0x8c, 0xc4, 0xc7, 0x41, 0xb3, 0xd9 },
{ 0xb6, 0x58, 0x23, 0x18, 0xdd, 0xcf, 0xb6, 0x7a, 0x53, 0xa6,
0x7d, 0x67, 0x6b, 0x8a, 0xd8, 0x69, 0xad, 0xed, 0x62, 0x9a },
{ 0xf1, 0xbe, 0x3e, 0xe8, 0x77, 0x70, 0x31, 0x40, 0xd3, 0x4f,
0x97, 0xea, 0x1a, 0xb3, 0xa0, 0x7c, 0x14, 0x13, 0x33, 0xe2 },
{ 0x85, 0xf1, 0x64, 0x70, 0x3e, 0x61, 0xa6, 0x31, 0x31, 0xbe,
0x7e, 0x45, 0x95, 0x8e, 0x07, 0x94, 0x12, 0x39, 0x04, 0xf9 },
},
};
static const unsigned char ripemd160_test_key[KEYS][20] =
{
{ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99,
0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x01, 0x23, 0x45, 0x67 },
{ 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc,
0xba, 0x98, 0x76, 0x54, 0x32, 0x10, 0x00, 0x11, 0x22, 0x33 },
};
/*
* Checkup routine
*/
int ripemd160_self_test( int verbose )
{
int i, j;
unsigned char output[20];
memset( output, 0, sizeof output );
for( i = 0; i < TESTS; i++ )
{
if( verbose != 0 )
printf( " RIPEMD-160 test #%d: ", i + 1 );
ripemd160( (const unsigned char *) ripemd160_test_input[i],
strlen( ripemd160_test_input[i] ),
output );
if( memcmp( output, ripemd160_test_md[i], 20 ) != 0 )
{
if( verbose != 0 )
printf( "failed\n" );
return( 1 );
}
if( verbose != 0 )
printf( "passed\n" );
for( j = 0; j < KEYS; j++ )
{
if( verbose != 0 )
printf( " HMAC-RIPEMD-160 test #%d, key #%d: ", i + 1, j + 1 );
ripemd160_hmac( ripemd160_test_key[j], 20,
(const unsigned char *) ripemd160_test_input[i],
strlen( ripemd160_test_input[i] ),
output );
if( memcmp( output, ripemd160_test_hmac[j][i], 20 ) != 0 )
{
if( verbose != 0 )
printf( "failed\n" );
return( 1 );
}
if( verbose != 0 )
printf( "passed\n" );
}
if( verbose != 0 )
printf( "\n" );
}
return( 0 );
}
#endif
#endif

View File

@ -33,6 +33,7 @@
#include "polarssl/md4.h"
#include "polarssl/md5.h"
#include "polarssl/ripemd160.h"
#include "polarssl/sha1.h"
#include "polarssl/sha256.h"
#include "polarssl/sha512.h"
@ -132,20 +133,20 @@ do { \
if( ret != 0 ) \
printf( "FAILED\n" ); \
else \
printf( "%9lu " TYPE "/s\n", i / 3 ); \
printf( "%9lu " TYPE "/s\n", i / 3 ); \
} while( 0 )
unsigned char buf[BUFSIZE];
typedef struct {
char md4, md5, sha1, sha256, sha512,
char md4, md5, ripemd160, sha1, sha256, sha512,
arc4, des3, des, aes_cbc, aes_gcm, camellia, blowfish,
havege, ctr_drbg,
rsa, dhm, ecdsa, ecdh;
} todo_list;
#define OPTIONS \
"md4, md5, sha1, sha256, sha512,\n" \
"md4, md5, ripemd160, sha1, sha256, sha512,\n" \
"arc4, des3, des, aes_cbc, aes_gcm, camellia, blowfish,\n" \
"havege, ctr_drbg,\n" \
"rsa, dhm, ecdsa, ecdh.\n"
@ -169,6 +170,8 @@ int main( int argc, char *argv[] )
todo.md4 = 1;
else if( strcmp( argv[i], "md5" ) == 0 )
todo.md5 = 1;
else if( strcmp( argv[i], "ripemd160" ) == 0 )
todo.ripemd160 = 1;
else if( strcmp( argv[i], "sha1" ) == 0 )
todo.sha1 = 1;
else if( strcmp( argv[i], "sha256" ) == 0 )
@ -223,6 +226,11 @@ int main( int argc, char *argv[] )
TIME_AND_TSC( "MD5", md5( buf, BUFSIZE, tmp ) );
#endif
#if defined(POLARSSL_RIPEMD160_C)
if( todo.ripemd160 )
TIME_AND_TSC( "RIPEMD160", ripemd160( buf, BUFSIZE, tmp ) );
#endif
#if defined(POLARSSL_SHA1_C)
if( todo.sha1 )
TIME_AND_TSC( "SHA-1", sha1( buf, BUFSIZE, tmp ) );

View File

@ -34,6 +34,7 @@
#include "polarssl/md2.h"
#include "polarssl/md4.h"
#include "polarssl/md5.h"
#include "polarssl/ripemd160.h"
#include "polarssl/sha1.h"
#include "polarssl/sha256.h"
#include "polarssl/sha512.h"
@ -89,6 +90,11 @@ int main( int argc, char *argv[] )
return( ret );
#endif
#if defined(POLARSSL_RIPEMD160_C)
if( ( ret = ripemd160_self_test( v ) ) != 0 )
return( ret );
#endif
#if defined(POLARSSL_SHA1_C)
if( ( ret = sha1_self_test( v ) ) != 0 )
return( ret );

File diff suppressed because one or more lines are too long

View File

@ -82,6 +82,38 @@ generic md5 Test vector RFC1321 #7
depends_on:POLARSSL_MD5_C
md_text:"md5":"12345678901234567890123456789012345678901234567890123456789012345678901234567890":"57edf4a22be3c955ac49da2e2107b67a"
ripemd160 Test vector from paper #1
depends_on:POLARSSL_RIPEMD160_C
md_text:"ripemd160":"":"9c1185a5c5e9fc54612808977ee8f548b2258d31"
ripemd160 Test vector from paper #2
depends_on:POLARSSL_RIPEMD160_C
md_text:"ripemd160":"a":"0bdc9d2d256b3ee9daae347be6f4dc835a467ffe"
ripemd160 Test vector from paper #3
depends_on:POLARSSL_RIPEMD160_C
md_text:"ripemd160":"abc":"8eb208f7e05d987a9b044a8e98c6b087f15a0bfc"
ripemd160 Test vector from paper #4
depends_on:POLARSSL_RIPEMD160_C
md_text:"ripemd160":"message digest":"5d0689ef49d2fae572b881b123a85ffa21595f36"
ripemd160 Test vector from paper #5
depends_on:POLARSSL_RIPEMD160_C
md_text:"ripemd160":"abcdefghijklmnopqrstuvwxyz":"f71c27109c692c1b56bbdceb5b9d2865b3708dbc"
ripemd160 Test vector from paper #6
depends_on:POLARSSL_RIPEMD160_C
md_text:"ripemd160":"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq":"12a053384a9c0c88e405a06c27dcf49ada62eb2b"
ripemd160 Test vector from paper #7
depends_on:POLARSSL_RIPEMD160_C
md_text:"ripemd160":"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789":"b0e20b6e3116640286ed3a87a5713079b21f5189"
ripemd160 Test vector from paper #8
depends_on:POLARSSL_RIPEMD160_C
md_text:"ripemd160":"12345678901234567890123456789012345678901234567890123456789012345678901234567890":"9b752e45573d4b39f4dbd3323cab82bf63326bfb"
generic HMAC-MD2 Hash File OpenSSL test #1
depends_on:POLARSSL_MD2_C
md_hmac:"md2":16:"61616161616161616161616161616161":"b91ce5ac77d33c234e61002ed6":"d5732582f494f5ddf35efd166c85af9c"
@ -146,6 +178,34 @@ generic HMAC-MD5 Test Vector RFC2202 #7
depends_on:POLARSSL_MD5_C
md_hmac:"md5":16:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":"54657374205573696e67204c6172676572205468616e20426c6f636b2d53697a65204b657920616e64204c6172676572205468616e204f6e6520426c6f636b2d53697a652044617461":"6f630fad67cda0ee1fb1f562db3aa53e"
HMAC-RIPEMD160 Test vector RFC 2286 #1
depends_on:POLARSSL_RIPEMD160_C
md_hmac:"ripemd160":20:"0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b":"4869205468657265":"24cb4bd67d20fc1a5d2ed7732dcc39377f0a5668"
HMAC-RIPEMD160 Test vector RFC 2286 #2
depends_on:POLARSSL_RIPEMD160_C
md_hmac:"ripemd160":20:"4a656665":"7768617420646f2079612077616e7420666f72206e6f7468696e673f":"dda6c0213a485a9e24f4742064a7f033b43c4069"
HMAC-RIPEMD160 Test vector RFC 2286 #3
depends_on:POLARSSL_RIPEMD160_C
md_hmac:"ripemd160":20:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":"dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd":"b0b105360de759960ab4f35298e116e295d8e7c1"
HMAC-RIPEMD160 Test vector RFC 2286 #4
depends_on:POLARSSL_RIPEMD160_C
md_hmac:"ripemd160":20:"0102030405060708090a0b0c0d0e0f10111213141516171819":"cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd":"d5ca862f4d21d5e610e18b4cf1beb97a4365ecf4"
HMAC-RIPEMD160 Test vector RFC 2286 #5
depends_on:POLARSSL_RIPEMD160_C
md_hmac:"ripemd160":20:"0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c":"546573742057697468205472756e636174696f6e":"7619693978f91d90539ae786500ff3d8e0518e39"
HMAC-RIPEMD160 Test vector RFC 2286 #6
depends_on:POLARSSL_RIPEMD160_C
md_hmac:"ripemd160":20:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":"54657374205573696e67204c6172676572205468616e20426c6f636b2d53697a65204b6579202d2048617368204b6579204669727374":"6466ca07ac5eac29e1bd523e5ada7605b791fd8b"
HMAC-RIPEMD160 Test vector RFC 2286 #7
depends_on:POLARSSL_RIPEMD160_C
md_hmac:"ripemd160":20:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":"54657374205573696e67204c6172676572205468616e20426c6f636b2d53697a65204b657920616e64204c6172676572205468616e204f6e6520426c6f636b2d53697a652044617461":"69ea60798d71616cce5fd0871e23754cd75d5a0a"
generic multi step md2 Test vector RFC1319 #1
depends_on:POLARSSL_MD_C:POLARSSL_MD2_C
md_text_multi:"md2":"":"8350e5a3e24c153df2275c9f80692773"
@ -950,6 +1010,26 @@ generic multi step SHA-512 Test Vector NIST CAVS #8
depends_on:POLARSSL_SHA512_C
md_hex_multi:"sha512":"990d1ae71a62d7bda9bfdaa1762a68d296eee72a4cd946f287a898fbabc002ea941fd8d4d991030b4d27a637cce501a834bb95eab1b7889a3e784c7968e67cbf552006b206b68f76d9191327524fcc251aeb56af483d10b4e0c6c5e599ee8c0fe4faeca8293844a8547c6a9a90d093f2526873a19ad4a5e776794c68c742fb834793d2dfcb7fea46c63af4b70fd11cb6e41834e72ee40edb067b292a794990c288d5007e73f349fb383af6a756b8301ad6e5e0aa8cd614399bb3a452376b1575afa6bdaeaafc286cb064bb91edef97c632b6c1113d107fa93a0905098a105043c2f05397f702514439a08a9e5ddc196100721d45c8fc17d2ed659376f8a00bd5cb9a0860e26d8a29d8d6aaf52de97e9346033d6db501a35dbbaf97c20b830cd2d18c2532f3a59cc497ee64c0e57d8d060e5069b28d86edf1adcf59144b221ce3ddaef134b3124fbc7dd000240eff0f5f5f41e83cd7f5bb37c9ae21953fe302b0f6e8b68fa91c6ab99265c64b2fd9cd4942be04321bb5d6d71932376c6f2f88e02422ba6a5e2cb765df93fd5dd0728c6abdaf03bce22e0678a544e2c3636f741b6f4447ee58a8fc656b43ef817932176adbfc2e04b2c812c273cd6cbfa4098f0be036a34221fa02643f5ee2e0b38135f2a18ecd2f16ebc45f8eb31b8ab967a1567ee016904188910861ca1fa205c7adaa194b286893ffe2f4fbe0384c2aef72a4522aeafd3ebc71f9db71eeeef86c48394a1c86d5b36c352cc33a0a2c800bc99e62fd65b3a2fd69e0b53996ec13d8ce483ce9319efd9a85acefabdb5342226febb83fd1daf4b24265f50c61c6de74077ef89b6fecf9f29a1f871af1e9f89b2d345cda7499bd45c42fa5d195a1e1a6ba84851889e730da3b2b916e96152ae0c92154b49719841db7e7cc707ba8a5d7b101eb4ac7b629bb327817910fff61580b59aab78182d1a2e33473d05b00b170b29e331870826cfe45af206aa7d0246bbd8566ca7cfb2d3c10bfa1db7dd48dd786036469ce7282093d78b5e1a5b0fc81a54c8ed4ceac1e5305305e78284ac276f5d7862727aff246e17addde50c670028d572cbfc0be2e4f8b2eb28fa68ad7b4c6c2a239c460441bfb5ea049f23b08563b4e47729a59e5986a61a6093dbd54f8c36ebe87edae01f251cb060ad1364ce677d7e8d5a4a4ca966a7241cc360bc2acb280e5f9e9c1b032ad6a180a35e0c5180b9d16d026c865b252098cc1d99ba7375ca31c7702c0d943d5e3dd2f6861fa55bd46d94b67ed3e52eccd8dd06d968e01897d6de97ed3058d91dd":"8e4bc6f8b8c60fe4d68c61d9b159c8693c3151c46749af58da228442d927f23359bd6ccd6c2ec8fa3f00a86cecbfa728e1ad60b821ed22fcd309ba91a4138bc9"
RIPEMD160 Hash file #0 (from paper)
depends_on:POLARSSL_RIPEMD160_C
md_file:"ripemd160":"data_files/hash_file_5":"52783243c1697bdbe16d37f97f68f08325dc1528"
RIPEMD160 Hash file #1
depends_on:POLARSSL_RIPEMD160_C
md_file:"ripemd160":"data_files/hash_file_1":"82f1d072f0ec0c2b353703a7b575a04c113af1a6"
RIPEMD160 Hash file #2
depends_on:POLARSSL_RIPEMD160_C
md_file:"ripemd160":"data_files/hash_file_2":"996fbc8b79206ba7393ebcd246584069b1c08f0f"
RIPEMD160 Hash file #3
depends_on:POLARSSL_RIPEMD160_C
md_file:"ripemd160":"data_files/hash_file_3":"8653b46d65998fa8c8846efa17937e742533ae48"
RIPEMD160 Hash file #4
depends_on:POLARSSL_RIPEMD160_C
md_file:"ripemd160":"data_files/hash_file_4":"9c1185a5c5e9fc54612808977ee8f548b2258d31"
generic SHA1 Hash file #1
depends_on:POLARSSL_SHA1_C
md_file:"sha1":"data_files/hash_file_1":"d21c965b1e768bd7a6aa6869f5f821901d255f9f"

View File

@ -1,11 +1,5 @@
/* BEGIN_HEADER */
#include <polarssl/md.h>
#include <polarssl/md2.h>
#include <polarssl/md4.h>
#include <polarssl/md5.h>
#include <polarssl/sha1.h>
#include <polarssl/sha256.h>
#include <polarssl/sha512.h>
/* END_HEADER */
/* BEGIN_DEPENDENCIES

View File

@ -1,219 +1,227 @@
md2 Test vector RFC1319 #1
depends_on:POLARSSL_MD2_C
md2_text:"":"8350e5a3e24c153df2275c9f80692773"
md2 Test vector RFC1319 #2
depends_on:POLARSSL_MD2_C
md2_text:"a":"32ec01ec4a6dac72c0ab96fb34c0b5d1"
md2 Test vector RFC1319 #3
depends_on:POLARSSL_MD2_C
md2_text:"abc":"da853b0d3f88d99b30283a69e6ded6bb"
md2 Test vector RFC1319 #4
depends_on:POLARSSL_MD2_C
md2_text:"message digest":"ab4f496bfb2a530b219ff33031fe06b0"
md2 Test vector RFC1319 #5
depends_on:POLARSSL_MD2_C
md2_text:"abcdefghijklmnopqrstuvwxyz":"4e8ddff3650292ab5a4108c3aa47940b"
md2 Test vector RFC1319 #6
depends_on:POLARSSL_MD2_C
md2_text:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789":"da33def2a42df13975352846c30338cd"
md2 Test vector RFC1319 #7
depends_on:POLARSSL_MD2_C
md2_text:"12345678901234567890123456789012345678901234567890123456789012345678901234567890":"d5976f79d83d3a0dc9806c3c66f3efd8"
md4 Test vector RFC1320 #1
depends_on:POLARSSL_MD4_C
md4_text:"":"31d6cfe0d16ae931b73c59d7e0c089c0"
md4 Test vector RFC1320 #2
depends_on:POLARSSL_MD4_C
md4_text:"a":"bde52cb31de33e46245e05fbdbd6fb24"
md4 Test vector RFC1320 #3
depends_on:POLARSSL_MD4_C
md4_text:"abc":"a448017aaf21d8525fc10ae87aa6729d"
md4 Test vector RFC1320 #4
depends_on:POLARSSL_MD4_C
md4_text:"message digest":"d9130a8164549fe818874806e1c7014b"
md4 Test vector RFC1320 #5
depends_on:POLARSSL_MD4_C
md4_text:"abcdefghijklmnopqrstuvwxyz":"d79e1c308aa5bbcdeea8ed63df412da9"
md4 Test vector RFC1320 #6
depends_on:POLARSSL_MD4_C
md4_text:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789":"043f8582f241db351ce627e153e7f0e4"
md4 Test vector RFC1320 #7
depends_on:POLARSSL_MD4_C
md4_text:"12345678901234567890123456789012345678901234567890123456789012345678901234567890":"e33b4ddc9c38f2199c3e7b164fcc0536"
md5 Test vector RFC1321 #1
depends_on:POLARSSL_MD5_C
md5_text:"":"d41d8cd98f00b204e9800998ecf8427e"
md5 Test vector RFC1321 #2
depends_on:POLARSSL_MD5_C
md5_text:"a":"0cc175b9c0f1b6a831c399e269772661"
md5 Test vector RFC1321 #3
depends_on:POLARSSL_MD5_C
md5_text:"abc":"900150983cd24fb0d6963f7d28e17f72"
md5 Test vector RFC1321 #4
depends_on:POLARSSL_MD5_C
md5_text:"message digest":"f96b697d7cb7938d525a2f31aaf161d0"
md5 Test vector RFC1321 #5
depends_on:POLARSSL_MD5_C
md5_text:"abcdefghijklmnopqrstuvwxyz":"c3fcd3d76192e4007dfb496cca67e13b"
md5 Test vector RFC1321 #6
depends_on:POLARSSL_MD5_C
md5_text:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789":"d174ab98d277d9f5a5611c2c9f419d9f"
md5 Test vector RFC1321 #7
depends_on:POLARSSL_MD5_C
md5_text:"12345678901234567890123456789012345678901234567890123456789012345678901234567890":"57edf4a22be3c955ac49da2e2107b67a"
ripemd160 Test vector from paper #1
ripemd160_text:"":"9c1185a5c5e9fc54612808977ee8f548b2258d31"
ripemd160 Test vector from paper #2
ripemd160_text:"a":"0bdc9d2d256b3ee9daae347be6f4dc835a467ffe"
ripemd160 Test vector from paper #3
ripemd160_text:"abc":"8eb208f7e05d987a9b044a8e98c6b087f15a0bfc"
ripemd160 Test vector from paper #4
ripemd160_text:"message digest":"5d0689ef49d2fae572b881b123a85ffa21595f36"
ripemd160 Test vector from paper #5
ripemd160_text:"abcdefghijklmnopqrstuvwxyz":"f71c27109c692c1b56bbdceb5b9d2865b3708dbc"
ripemd160 Test vector from paper #6
ripemd160_text:"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq":"12a053384a9c0c88e405a06c27dcf49ada62eb2b"
ripemd160 Test vector from paper #7
ripemd160_text:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789":"b0e20b6e3116640286ed3a87a5713079b21f5189"
ripemd160 Test vector from paper #8
ripemd160_text:"12345678901234567890123456789012345678901234567890123456789012345678901234567890":"9b752e45573d4b39f4dbd3323cab82bf63326bfb"
HMAC-MD2 Hash File OpenSSL test #1
depends_on:POLARSSL_MD2_C
md2_hmac:16:"61616161616161616161616161616161":"b91ce5ac77d33c234e61002ed6":"d5732582f494f5ddf35efd166c85af9c"
HMAC-MD2 Hash File OpenSSL test #2
depends_on:POLARSSL_MD2_C
md2_hmac:16:"61616161616161616161616161616161":"270fcf11f27c27448457d7049a7edb084a3e554e0b2acf5806982213f0ad516402e4c869c4ff2171e18e3489baa3125d2c3056ebb616296f9b6aa97ef68eeabcdc0b6dde47775004096a241efcf0a90d19b34e898cc7340cdc940f8bdd46e23e352f34bca131d4d67a7c2ddb8d0d68b67f06152a128168e1c341c37e0a66c5018999b7059bcc300beed2c19dd1152d2fe062853293b8f3c8b5":"54ab68503f7d1b5c7741340dff2722a9"
HMAC-MD2 Hash File OpenSSL test #3
depends_on:POLARSSL_MD2_C
md2_hmac:16:"61616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161":"b91ce5ac77d33c234e61002ed6":"d850e5f554558cf0fe79a0612e1d0365"
HMAC-MD4 Hash File OpenSSL test #1
depends_on:POLARSSL_MD4_C
md4_hmac:16:"61616161616161616161616161616161":"b91ce5ac77d33c234e61002ed6":"eabd0fbefb82fb0063a25a6d7b8bdc0f"
HMAC-MD4 Hash File OpenSSL test #2
depends_on:POLARSSL_MD4_C
md4_hmac:16:"61616161616161616161616161616161":"270fcf11f27c27448457d7049a7edb084a3e554e0b2acf5806982213f0ad516402e4c869c4ff2171e18e3489baa3125d2c3056ebb616296f9b6aa97ef68eeabcdc0b6dde47775004096a241efcf0a90d19b34e898cc7340cdc940f8bdd46e23e352f34bca131d4d67a7c2ddb8d0d68b67f06152a128168e1c341c37e0a66c5018999b7059bcc300beed2c19dd1152d2fe062853293b8f3c8b5":"cec3c5e421a7b783aa89cacf78daf6dc"
HMAC-MD4 Hash File OpenSSL test #3
depends_on:POLARSSL_MD4_C
md4_hmac:16:"61616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161":"b91ce5ac77d33c234e61002ed6":"ad5f0a04116109b397b57f9cc9b6df4b"
HMAC-MD5 Hash File OpenSSL test #1
depends_on:POLARSSL_MD5_C
md5_hmac:16:"61616161616161616161616161616161":"b91ce5ac77d33c234e61002ed6":"42552882f00bd4633ea81135a184b284"
HMAC-MD5 Hash File OpenSSL test #2
depends_on:POLARSSL_MD5_C
md5_hmac:16:"61616161616161616161616161616161":"270fcf11f27c27448457d7049a7edb084a3e554e0b2acf5806982213f0ad516402e4c869c4ff2171e18e3489baa3125d2c3056ebb616296f9b6aa97ef68eeabcdc0b6dde47775004096a241efcf0a90d19b34e898cc7340cdc940f8bdd46e23e352f34bca131d4d67a7c2ddb8d0d68b67f06152a128168e1c341c37e0a66c5018999b7059bcc300beed2c19dd1152d2fe062853293b8f3c8b5":"a16a842891786d01fe50ba7731db7464"
HMAC-MD5 Hash File OpenSSL test #3
depends_on:POLARSSL_MD5_C
md5_hmac:16:"61616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161":"b91ce5ac77d33c234e61002ed6":"e97f623936f98a7f741c4bd0612fecc2"
HMAC-MD5 Test Vector RFC2202 #1
depends_on:POLARSSL_MD5_C
md5_hmac:16:"0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b":"4869205468657265":"9294727a3638bb1c13f48ef8158bfc9d"
HMAC-MD5 Test Vector RFC2202 #2
depends_on:POLARSSL_MD5_C
md5_hmac:16:"4a656665":"7768617420646f2079612077616e7420666f72206e6f7468696e673f":"750c783e6ab0b503eaa86e310a5db738"
HMAC-MD5 Test Vector RFC2202 #3
depends_on:POLARSSL_MD5_C
md5_hmac:16:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":"dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd":"56be34521d144c88dbb8c733f0e8b3f6"
HMAC-MD5 Test Vector RFC2202 #4
depends_on:POLARSSL_MD5_C
md5_hmac:16:"0102030405060708090a0b0c0d0e0f10111213141516171819":"cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd":"697eaf0aca3a3aea3a75164746ffaa79"
HMAC-MD5 Test Vector RFC2202 #5
depends_on:POLARSSL_MD5_C
md5_hmac:12:"0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c":"546573742057697468205472756e636174696f6e":"56461ef2342edc00f9bab995"
HMAC-MD5 Test Vector RFC2202 #6
depends_on:POLARSSL_MD5_C
md5_hmac:16:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":"54657374205573696e67204c6172676572205468616e20426c6f636b2d53697a65204b6579202d2048617368204b6579204669727374":"6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd"
HMAC-MD5 Test Vector RFC2202 #7
depends_on:POLARSSL_MD5_C
md5_hmac:16:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":"54657374205573696e67204c6172676572205468616e20426c6f636b2d53697a65204b657920616e64204c6172676572205468616e204f6e6520426c6f636b2d53697a652044617461":"6f630fad67cda0ee1fb1f562db3aa53e"
HMAC-MD2 Bouncy Castle test #1
depends_on:POLARSSL_MD2_C
md2_hmac:16:"0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b":"4869205468657265":"dc1923ef5f161d35bef839ca8c807808"
HMAC-MD4 Bouncy Castle test #1
depends_on:POLARSSL_MD4_C
md4_hmac:16:"0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b":"4869205468657265":"5570ce964ba8c11756cdc3970278ff5a"
HMAC-MD5 Bouncy Castle test #1
depends_on:POLARSSL_MD5_C
md5_hmac:16:"0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b":"4869205468657265":"5ccec34ea9656392457fa1ac27f08fbc"
HMAC-RIPEMD160 Test vector RFC 2286 #1
ripemd160_hmac:20:"0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b":"4869205468657265":"24cb4bd67d20fc1a5d2ed7732dcc39377f0a5668"
HMAC-RIPEMD160 Test vector RFC 2286 #2
ripemd160_hmac:20:"4a656665":"7768617420646f2079612077616e7420666f72206e6f7468696e673f":"dda6c0213a485a9e24f4742064a7f033b43c4069"
HMAC-RIPEMD160 Test vector RFC 2286 #3
ripemd160_hmac:20:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":"dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd":"b0b105360de759960ab4f35298e116e295d8e7c1"
HMAC-RIPEMD160 Test vector RFC 2286 #4
ripemd160_hmac:20:"0102030405060708090a0b0c0d0e0f10111213141516171819":"cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd":"d5ca862f4d21d5e610e18b4cf1beb97a4365ecf4"
HMAC-RIPEMD160 Test vector RFC 2286 #5
ripemd160_hmac:20:"0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c":"546573742057697468205472756e636174696f6e":"7619693978f91d90539ae786500ff3d8e0518e39"
HMAC-RIPEMD160 Test vector RFC 2286 #6
ripemd160_hmac:20:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":"54657374205573696e67204c6172676572205468616e20426c6f636b2d53697a65204b6579202d2048617368204b6579204669727374":"6466ca07ac5eac29e1bd523e5ada7605b791fd8b"
HMAC-RIPEMD160 Test vector RFC 2286 #7
ripemd160_hmac:20:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":"54657374205573696e67204c6172676572205468616e20426c6f636b2d53697a65204b657920616e64204c6172676572205468616e204f6e6520426c6f636b2d53697a652044617461":"69ea60798d71616cce5fd0871e23754cd75d5a0a"
MD2 Hash file #1
depends_on:POLARSSL_MD2_C
md2_file:"data_files/hash_file_1":"b593c098712d2e21628c8986695451a8"
MD2 Hash file #2
depends_on:POLARSSL_MD2_C
md2_file:"data_files/hash_file_2":"3c027b7409909a4c4b26bbab69ad9f4f"
MD2 Hash file #3
depends_on:POLARSSL_MD2_C
md2_file:"data_files/hash_file_3":"6bb43eb285e81f414083a94cdbe2989d"
MD2 Hash file #4
depends_on:POLARSSL_MD2_C
md2_file:"data_files/hash_file_4":"8350e5a3e24c153df2275c9f80692773"
MD4 Hash file #1
depends_on:POLARSSL_MD4_C
md4_file:"data_files/hash_file_1":"8d19772c176bd27153b9486715e2c0b9"
MD4 Hash file #2
depends_on:POLARSSL_MD4_C
md4_file:"data_files/hash_file_2":"f2ac53b8542882a5a0007c6f84b4d9fd"
MD4 Hash file #3
depends_on:POLARSSL_MD4_C
md4_file:"data_files/hash_file_3":"195c15158e2d07881d9a654095ce4a42"
MD4 Hash file #4
depends_on:POLARSSL_MD4_C
md4_file:"data_files/hash_file_4":"31d6cfe0d16ae931b73c59d7e0c089c0"
MD5 Hash file #1
depends_on:POLARSSL_MD5_C
md5_file:"data_files/hash_file_1":"52bcdc983c9ed64fc148a759b3c7a415"
MD5 Hash file #2
depends_on:POLARSSL_MD5_C
md5_file:"data_files/hash_file_2":"d17d466f15891df10542207ae78277f0"
MD5 Hash file #3
depends_on:POLARSSL_MD5_C
md5_file:"data_files/hash_file_3":"d945bcc6200ea95d061a2a818167d920"
MD5 Hash file #4
depends_on:POLARSSL_MD5_C
md5_file:"data_files/hash_file_4":"d41d8cd98f00b204e9800998ecf8427e"
RIPEMD160 Hash file #0 (from paper)
ripemd160_file:"data_files/hash_file_5":"52783243c1697bdbe16d37f97f68f08325dc1528"
RIPEMD160 Hash file #1
ripemd160_file:"data_files/hash_file_1":"82f1d072f0ec0c2b353703a7b575a04c113af1a6"
RIPEMD160 Hash file #2
ripemd160_file:"data_files/hash_file_2":"996fbc8b79206ba7393ebcd246584069b1c08f0f"
RIPEMD160 Hash file #3
ripemd160_file:"data_files/hash_file_3":"8653b46d65998fa8c8846efa17937e742533ae48"
RIPEMD160 Hash file #4
ripemd160_file:"data_files/hash_file_4":"9c1185a5c5e9fc54612808977ee8f548b2258d31"
MD2 Selftest
depends_on:POLARSSL_MD2_C:POLARSSL_SELF_TEST
md2_selftest:
MD4 Selftest
depends_on:POLARSSL_MD4_C:POLARSSL_SELF_TEST
md4_selftest:
MD5 Selftest
depends_on:POLARSSL_MD5_C:POLARSSL_SELF_TEST
md5_selftest:
RIPEMD160 Selftest
ripemd160_selftest:

View File

@ -2,23 +2,24 @@
#include <polarssl/md2.h>
#include <polarssl/md4.h>
#include <polarssl/md5.h>
#include <polarssl/ripemd160.h>
/* END_HEADER */
/* BEGIN_CASE depends_on:POLARSSL_MD2_C */
void md2_text( char *text_src_string, char *hex_hash_string )
{
unsigned char src_str[1000];
unsigned char hash_str[1000];
unsigned char output[33];
unsigned char src_str[100];
unsigned char hash_str[33];
unsigned char output[16];
memset(src_str, 0x00, 1000);
memset(hash_str, 0x00, 1000);
memset(output, 0x00, 33);
memset( src_str, 0x00, sizeof src_str );
memset( hash_str, 0x00, sizeof hash_str );
memset( output, 0x00, sizeof output );
strcpy( (char *) src_str, text_src_string );
md2( src_str, strlen( (char *) src_str ), output );
hexify( hash_str, output, 16 );
hexify( hash_str, output, sizeof output );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
@ -27,18 +28,18 @@ void md2_text( char *text_src_string, char *hex_hash_string )
/* BEGIN_CASE depends_on:POLARSSL_MD4_C */
void md4_text( char *text_src_string, char *hex_hash_string )
{
unsigned char src_str[1000];
unsigned char hash_str[1000];
unsigned char output[33];
unsigned char src_str[100];
unsigned char hash_str[33];
unsigned char output[16];
memset(src_str, 0x00, 1000);
memset(hash_str, 0x00, 1000);
memset(output, 0x00, 33);
memset( src_str, 0x00, sizeof src_str );
memset( hash_str, 0x00, sizeof hash_str );
memset( output, 0x00, sizeof output );
strcpy( (char *) src_str, text_src_string );
md4( src_str, strlen( (char *) src_str ), output );
hexify( hash_str, output, 16 );
hexify( hash_str, output, sizeof output );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
@ -47,18 +48,38 @@ void md4_text( char *text_src_string, char *hex_hash_string )
/* BEGIN_CASE depends_on:POLARSSL_MD5_C */
void md5_text( char *text_src_string, char *hex_hash_string )
{
unsigned char src_str[1000];
unsigned char hash_str[1000];
unsigned char output[33];
unsigned char src_str[100];
unsigned char hash_str[33];
unsigned char output[16];
memset(src_str, 0x00, 1000);
memset(hash_str, 0x00, 1000);
memset(output, 0x00, 33);
memset( src_str, 0x00, sizeof src_str );
memset( hash_str, 0x00, sizeof hash_str );
memset( output, 0x00, sizeof output );
strcpy( (char *) src_str, text_src_string );
md5( src_str, strlen( (char *) src_str ), output );
hexify( hash_str, output, 16 );
hexify( hash_str, output, sizeof output );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
/* END_CASE */
/* BEGIN_CASE depends_on:POLARSSL_RIPEMD160_C */
void ripemd160_text( char *text_src_string, char *hex_hash_string )
{
unsigned char src_str[100];
unsigned char hash_str[41];
unsigned char output[20];
memset(src_str, 0x00, sizeof src_str);
memset(hash_str, 0x00, sizeof hash_str);
memset(output, 0x00, sizeof output);
strcpy( (char *) src_str, text_src_string );
ripemd160( src_str, strlen( (char *) src_str ), output );
hexify( hash_str, output, sizeof output );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
@ -68,22 +89,22 @@ void md5_text( char *text_src_string, char *hex_hash_string )
void md2_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
char *hex_hash_string )
{
unsigned char src_str[10000];
unsigned char key_str[10000];
unsigned char hash_str[10000];
unsigned char output[33];
unsigned char src_str[200];
unsigned char key_str[200];
unsigned char hash_str[33];
unsigned char output[16];
int key_len, src_len;
memset(src_str, 0x00, 10000);
memset(key_str, 0x00, 10000);
memset(hash_str, 0x00, 10000);
memset(output, 0x00, 33);
memset( src_str, 0x00, sizeof src_str );
memset( key_str, 0x00, sizeof key_str );
memset( hash_str, 0x00, sizeof hash_str );
memset( output, 0x00, sizeof output );
key_len = unhexify( key_str, hex_key_string );
src_len = unhexify( src_str, hex_src_string );
md2_hmac( key_str, key_len, src_str, src_len, output );
hexify( hash_str, output, 16 );
hexify( hash_str, output, sizeof output );
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
}
@ -93,22 +114,22 @@ void md2_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
void md4_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
char *hex_hash_string )
{
unsigned char src_str[10000];
unsigned char key_str[10000];
unsigned char hash_str[10000];
unsigned char output[33];
unsigned char src_str[200];
unsigned char key_str[200];
unsigned char hash_str[33];
unsigned char output[16];
int key_len, src_len;
memset(src_str, 0x00, 10000);
memset(key_str, 0x00, 10000);
memset(hash_str, 0x00, 10000);
memset(output, 0x00, 33);
memset( src_str, 0x00, sizeof src_str );
memset( key_str, 0x00, sizeof key_str );
memset( hash_str, 0x00, sizeof hash_str );
memset( output, 0x00, sizeof output );
key_len = unhexify( key_str, hex_key_string );
src_len = unhexify( src_str, hex_src_string );
md4_hmac( key_str, key_len, src_str, src_len, output );
hexify( hash_str, output, 16 );
hexify( hash_str, output, sizeof output );
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
}
@ -118,22 +139,47 @@ void md4_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
void md5_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
char *hex_hash_string )
{
unsigned char src_str[10000];
unsigned char key_str[10000];
unsigned char hash_str[10000];
unsigned char output[33];
unsigned char src_str[200];
unsigned char key_str[200];
unsigned char hash_str[33];
unsigned char output[16];
int key_len, src_len;
memset(src_str, 0x00, 10000);
memset(key_str, 0x00, 10000);
memset(hash_str, 0x00, 10000);
memset(output, 0x00, 33);
memset( src_str, 0x00, sizeof src_str );
memset( key_str, 0x00, sizeof key_str );
memset( hash_str, 0x00, sizeof hash_str );
memset( output, 0x00, sizeof output );
key_len = unhexify( key_str, hex_key_string );
src_len = unhexify( src_str, hex_src_string );
md5_hmac( key_str, key_len, src_str, src_len, output );
hexify( hash_str, output, 16 );
hexify( hash_str, output, sizeof output );
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
}
/* END_CASE */
/* BEGIN_CASE depends_on:POLARSSL_RIPEMD160_C */
void ripemd160_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
char *hex_hash_string )
{
unsigned char src_str[200];
unsigned char key_str[200];
unsigned char hash_str[41];
unsigned char output[20];
int key_len, src_len;
memset( src_str, 0x00, sizeof src_str );
memset( key_str, 0x00, sizeof key_str );
memset( hash_str, 0x00, sizeof hash_str );
memset( output, 0x00, sizeof output );
key_len = unhexify( key_str, hex_key_string );
src_len = unhexify( src_str, hex_src_string );
ripemd160_hmac( key_str, key_len, src_str, src_len, output );
hexify( hash_str, output, sizeof output );
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
}
@ -142,14 +188,14 @@ void md5_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
/* BEGIN_CASE depends_on:POLARSSL_MD2_C:POLARSSL_FS_IO */
void md2_file( char *filename, char *hex_hash_string )
{
unsigned char hash_str[65];
unsigned char output[33];
unsigned char hash_str[33];
unsigned char output[16];
memset(hash_str, 0x00, 65);
memset(output, 0x00, 33);
memset( hash_str, 0x00, sizeof hash_str );
memset( output, 0x00, sizeof output );
md2_file( filename, output);
hexify( hash_str, output, 16 );
hexify( hash_str, output, sizeof output );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
@ -158,14 +204,14 @@ void md2_file( char *filename, char *hex_hash_string )
/* BEGIN_CASE depends_on:POLARSSL_MD4_C:POLARSSL_FS_IO */
void md4_file( char *filename, char *hex_hash_string )
{
unsigned char hash_str[65];
unsigned char output[33];
unsigned char hash_str[33];
unsigned char output[16];
memset(hash_str, 0x00, 65);
memset(output, 0x00, 33);
memset( hash_str, 0x00, sizeof hash_str );
memset( output, 0x00, sizeof output );
md4_file( filename, output);
hexify( hash_str, output, 16 );
hexify( hash_str, output, sizeof output );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
@ -174,14 +220,30 @@ void md4_file( char *filename, char *hex_hash_string )
/* BEGIN_CASE depends_on:POLARSSL_MD5_C:POLARSSL_FS_IO */
void md5_file( char *filename, char *hex_hash_string )
{
unsigned char hash_str[65];
unsigned char output[33];
unsigned char hash_str[33];
unsigned char output[16];
memset(hash_str, 0x00, 65);
memset(output, 0x00, 33);
memset( hash_str, 0x00, sizeof hash_str );
memset( output, 0x00, sizeof output );
md5_file( filename, output);
hexify( hash_str, output, 16 );
hexify( hash_str, output, sizeof output );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
/* END_CASE */
/* BEGIN_CASE depends_on:POLARSSL_RIPEMD160_C:POLARSSL_FS_IO */
void ripemd160_file( char *filename, char *hex_hash_string )
{
unsigned char hash_str[41];
unsigned char output[20];
memset(hash_str, 0x00, sizeof hash_str );
memset(output, 0x00, sizeof output );
ripemd160_file( filename, output);
hexify( hash_str, output, sizeof output );
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
}
@ -207,3 +269,10 @@ void md5_selftest()
TEST_ASSERT( md5_self_test( 0 ) == 0 );
}
/* END_CASE */
/* BEGIN_CASE depends_on:POLARSSL_RIPEMD160_C:POLARSSL_SELF_TEST */
void ripemd160_selftest()
{
TEST_ASSERT( ripemd160_self_test( 0 ) == 0 );
}
/* END_CASE */

View File

@ -184,6 +184,7 @@
<ClInclude Include="..\..\include\polarssl\pkcs12.h" />
<ClInclude Include="..\..\include\polarssl\pkcs5.h" />
<ClInclude Include="..\..\include\polarssl\pk.h" />
<ClInclude Include="..\..\include\polarssl\ripemd160.h" />
<ClInclude Include="..\..\include\polarssl\rsa.h" />
<ClInclude Include="..\..\include\polarssl\sha1.h" />
<ClInclude Include="..\..\include\polarssl\sha256.h" />
@ -245,6 +246,7 @@
<ClCompile Include="..\..\library\pkparse.c" />
<ClCompile Include="..\..\library\pk_wrap.c" />
<ClCompile Include="..\..\library\pkwrite.c" />
<ClCompile Include="..\..\library\ripemd160.c" />
<ClCompile Include="..\..\library\rsa.c" />
<ClCompile Include="..\..\library\sha1.c" />
<ClCompile Include="..\..\library\sha256.c" />

View File

@ -261,6 +261,10 @@ SOURCE=..\..\library\pkwrite.c
# End Source File
# Begin Source File
SOURCE=..\..\library\ripemd160.c
# End Source File
# Begin Source File
SOURCE=..\..\library\rsa.c
# End Source File
# Begin Source File
@ -517,6 +521,10 @@ SOURCE=..\..\include\polarssl\pk.h
# End Source File
# Begin Source File
SOURCE=..\..\include\polarssl\ripemd160.h
# End Source File
# Begin Source File
SOURCE=..\..\include\polarssl\rsa.h
# End Source File
# Begin Source File