mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-26 01:05:40 +01:00
Add RIPEMD-160 to the generic MD layer
This commit is contained in:
parent
ff40c3ac34
commit
e4d47a655b
@ -58,6 +58,7 @@ typedef enum {
|
||||
POLARSSL_MD_SHA256,
|
||||
POLARSSL_MD_SHA384,
|
||||
POLARSSL_MD_SHA512,
|
||||
POLARSSL_MD_RMD160,
|
||||
} md_type_t;
|
||||
|
||||
#if defined(POLARSSL_SHA512_C)
|
||||
|
@ -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_RMD160_C)
|
||||
extern const md_info_t rmd160_info;
|
||||
#endif
|
||||
#if defined(POLARSSL_SHA1_C)
|
||||
extern const md_info_t sha1_info;
|
||||
#endif
|
||||
|
@ -160,6 +160,9 @@ void rmd160_hmac( const unsigned char *key, size_t keylen,
|
||||
*/
|
||||
int rmd160_self_test( int verbose );
|
||||
|
||||
/* Internal use */
|
||||
void rmd160_process( rmd160_context *ctx, const unsigned char data[64] );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
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];
|
||||
|
1
tests/data_files/hash_file_5
Normal file
1
tests/data_files/hash_file_5
Normal file
File diff suppressed because one or more lines are too long
@ -82,6 +82,38 @@ generic md5 Test vector RFC1321 #7
|
||||
depends_on:POLARSSL_MD5_C
|
||||
md_text:"md5":"12345678901234567890123456789012345678901234567890123456789012345678901234567890":"57edf4a22be3c955ac49da2e2107b67a"
|
||||
|
||||
rmd160 Test vector from paper #1
|
||||
depends_on:POLARSSL_RMD160_C
|
||||
md_text:"rmd160":"":"9c1185a5c5e9fc54612808977ee8f548b2258d31"
|
||||
|
||||
rmd160 Test vector from paper #2
|
||||
depends_on:POLARSSL_RMD160_C
|
||||
md_text:"rmd160":"a":"0bdc9d2d256b3ee9daae347be6f4dc835a467ffe"
|
||||
|
||||
rmd160 Test vector from paper #3
|
||||
depends_on:POLARSSL_RMD160_C
|
||||
md_text:"rmd160":"abc":"8eb208f7e05d987a9b044a8e98c6b087f15a0bfc"
|
||||
|
||||
rmd160 Test vector from paper #4
|
||||
depends_on:POLARSSL_RMD160_C
|
||||
md_text:"rmd160":"message digest":"5d0689ef49d2fae572b881b123a85ffa21595f36"
|
||||
|
||||
rmd160 Test vector from paper #5
|
||||
depends_on:POLARSSL_RMD160_C
|
||||
md_text:"rmd160":"abcdefghijklmnopqrstuvwxyz":"f71c27109c692c1b56bbdceb5b9d2865b3708dbc"
|
||||
|
||||
rmd160 Test vector from paper #6
|
||||
depends_on:POLARSSL_RMD160_C
|
||||
md_text:"rmd160":"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq":"12a053384a9c0c88e405a06c27dcf49ada62eb2b"
|
||||
|
||||
rmd160 Test vector from paper #7
|
||||
depends_on:POLARSSL_RMD160_C
|
||||
md_text:"rmd160":"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789":"b0e20b6e3116640286ed3a87a5713079b21f5189"
|
||||
|
||||
rmd160 Test vector from paper #8
|
||||
depends_on:POLARSSL_RMD160_C
|
||||
md_text:"rmd160":"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-RMD160 Test vector RFC 2286 #1
|
||||
depends_on:POLARSSL_RMD160_C
|
||||
md_hmac:"rmd160":20:"0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b":"4869205468657265":"24cb4bd67d20fc1a5d2ed7732dcc39377f0a5668"
|
||||
|
||||
HMAC-RMD160 Test vector RFC 2286 #2
|
||||
depends_on:POLARSSL_RMD160_C
|
||||
md_hmac:"rmd160":20:"4a656665":"7768617420646f2079612077616e7420666f72206e6f7468696e673f":"dda6c0213a485a9e24f4742064a7f033b43c4069"
|
||||
|
||||
HMAC-RMD160 Test vector RFC 2286 #3
|
||||
depends_on:POLARSSL_RMD160_C
|
||||
md_hmac:"rmd160":20:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":"dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd":"b0b105360de759960ab4f35298e116e295d8e7c1"
|
||||
|
||||
HMAC-RMD160 Test vector RFC 2286 #4
|
||||
depends_on:POLARSSL_RMD160_C
|
||||
md_hmac:"rmd160":20:"0102030405060708090a0b0c0d0e0f10111213141516171819":"cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd":"d5ca862f4d21d5e610e18b4cf1beb97a4365ecf4"
|
||||
|
||||
HMAC-RMD160 Test vector RFC 2286 #5
|
||||
depends_on:POLARSSL_RMD160_C
|
||||
md_hmac:"rmd160":20:"0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c":"546573742057697468205472756e636174696f6e":"7619693978f91d90539ae786500ff3d8e0518e39"
|
||||
|
||||
HMAC-RMD160 Test vector RFC 2286 #6
|
||||
depends_on:POLARSSL_RMD160_C
|
||||
md_hmac:"rmd160":20:"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":"54657374205573696e67204c6172676572205468616e20426c6f636b2d53697a65204b6579202d2048617368204b6579204669727374":"6466ca07ac5eac29e1bd523e5ada7605b791fd8b"
|
||||
|
||||
HMAC-RMD160 Test vector RFC 2286 #7
|
||||
depends_on:POLARSSL_RMD160_C
|
||||
md_hmac:"rmd160":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"
|
||||
|
||||
RMD160 Hash file #0 (from paper)
|
||||
depends_on:POLARSSL_RMD160_C
|
||||
md_file:"rmd160":"data_files/hash_file_5":"52783243c1697bdbe16d37f97f68f08325dc1528"
|
||||
|
||||
RMD160 Hash file #1
|
||||
depends_on:POLARSSL_RMD160_C
|
||||
md_file:"rmd160":"data_files/hash_file_1":"82f1d072f0ec0c2b353703a7b575a04c113af1a6"
|
||||
|
||||
RMD160 Hash file #2
|
||||
depends_on:POLARSSL_RMD160_C
|
||||
md_file:"rmd160":"data_files/hash_file_2":"996fbc8b79206ba7393ebcd246584069b1c08f0f"
|
||||
|
||||
RMD160 Hash file #3
|
||||
depends_on:POLARSSL_RMD160_C
|
||||
md_file:"rmd160":"data_files/hash_file_3":"8653b46d65998fa8c8846efa17937e742533ae48"
|
||||
|
||||
RMD160 Hash file #4
|
||||
depends_on:POLARSSL_RMD160_C
|
||||
md_file:"rmd160":"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"
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user