mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-29 11:41:15 +03:00
Remove specific xxx_hmac functions
This commit is contained in:
@ -416,88 +416,6 @@ int ripemd160_file( const char *path, unsigned char output[20] )
|
||||
}
|
||||
#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 );
|
||||
|
||||
polarssl_zeroize( sum, 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 );
|
||||
|
||||
polarssl_zeroize( tmpbuf, 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_init( &ctx );
|
||||
ripemd160_hmac_starts( &ctx, key, keylen );
|
||||
ripemd160_hmac_update( &ctx, input, ilen );
|
||||
ripemd160_hmac_finish( &ctx, output );
|
||||
ripemd160_free( &ctx );
|
||||
}
|
||||
|
||||
|
||||
#if defined(POLARSSL_SELF_TEST)
|
||||
/*
|
||||
* Test vectors from the RIPEMD-160 paper and
|
||||
@ -538,60 +456,12 @@ static const unsigned char ripemd160_test_md[TESTS][20] =
|
||||
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,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, 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;
|
||||
int i;
|
||||
unsigned char output[20];
|
||||
|
||||
memset( output, 0, sizeof output );
|
||||
@ -615,32 +485,6 @@ int ripemd160_self_test( int verbose )
|
||||
|
||||
if( verbose != 0 )
|
||||
polarssl_printf( "passed\n" );
|
||||
|
||||
for( j = 0; j < KEYS; j++ )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
polarssl_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 )
|
||||
polarssl_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
polarssl_printf( "passed\n" );
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
polarssl_printf( "\n" );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
|
Reference in New Issue
Block a user