mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-25 15:05:45 +01:00
Fix MD selftest to use correct type and expose ret
This commit is contained in:
parent
aa464ef23a
commit
2d0aa8be97
@ -248,7 +248,7 @@ exit:
|
||||
/*
|
||||
* RFC 1319 test vectors
|
||||
*/
|
||||
static const char md2_test_str[7][81] =
|
||||
static const unsigned char md2_test_str[7][81] =
|
||||
{
|
||||
{ "" },
|
||||
{ "a" },
|
||||
@ -256,10 +256,15 @@ static const char md2_test_str[7][81] =
|
||||
{ "message digest" },
|
||||
{ "abcdefghijklmnopqrstuvwxyz" },
|
||||
{ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" },
|
||||
{ "12345678901234567890123456789012345678901234567890123456789012" \
|
||||
{ "12345678901234567890123456789012345678901234567890123456789012"
|
||||
"345678901234567890" }
|
||||
};
|
||||
|
||||
static const size_t md2_test_strlen[7] =
|
||||
{
|
||||
0, 1, 3, 14, 26, 62, 80
|
||||
};
|
||||
|
||||
static const unsigned char md2_test_sum[7][16] =
|
||||
{
|
||||
{ 0x83, 0x50, 0xE5, 0xA3, 0xE2, 0x4C, 0x15, 0x3D,
|
||||
@ -283,7 +288,7 @@ static const unsigned char md2_test_sum[7][16] =
|
||||
*/
|
||||
int mbedtls_md2_self_test( int verbose )
|
||||
{
|
||||
int i;
|
||||
int i, ret = 0;
|
||||
unsigned char md2sum[16];
|
||||
|
||||
for( i = 0; i < 7; i++ )
|
||||
@ -291,12 +296,15 @@ int mbedtls_md2_self_test( int verbose )
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " MD2 test #%d: ", i + 1 );
|
||||
|
||||
if( mbedtls_md2_ext( (unsigned char *)md2_test_str[i],
|
||||
strlen( md2_test_str[i] ), md2sum ) != 0 )
|
||||
ret = mbedtls_md2_ext( md2_test_str[i], md2_test_strlen[i], md2sum );
|
||||
if( ret != 0 )
|
||||
goto fail;
|
||||
|
||||
if( memcmp( md2sum, md2_test_sum[i], 16 ) != 0 )
|
||||
{
|
||||
ret = 1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
@ -311,7 +319,7 @@ fail:
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
return( ret );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
@ -352,7 +352,7 @@ exit:
|
||||
/*
|
||||
* RFC 1320 test vectors
|
||||
*/
|
||||
static const char md4_test_str[7][81] =
|
||||
static const unsigned char md4_test_str[7][81] =
|
||||
{
|
||||
{ "" },
|
||||
{ "a" },
|
||||
@ -360,10 +360,15 @@ static const char md4_test_str[7][81] =
|
||||
{ "message digest" },
|
||||
{ "abcdefghijklmnopqrstuvwxyz" },
|
||||
{ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" },
|
||||
{ "12345678901234567890123456789012345678901234567890123456789012" \
|
||||
{ "12345678901234567890123456789012345678901234567890123456789012"
|
||||
"345678901234567890" }
|
||||
};
|
||||
|
||||
static const size_t md4_test_strlen[7] =
|
||||
{
|
||||
0, 1, 3, 14, 26, 62, 80
|
||||
};
|
||||
|
||||
static const unsigned char md4_test_sum[7][16] =
|
||||
{
|
||||
{ 0x31, 0xD6, 0xCF, 0xE0, 0xD1, 0x6A, 0xE9, 0x31,
|
||||
@ -387,7 +392,7 @@ static const unsigned char md4_test_sum[7][16] =
|
||||
*/
|
||||
int mbedtls_md4_self_test( int verbose )
|
||||
{
|
||||
int i;
|
||||
int i, ret = 0;
|
||||
unsigned char md4sum[16];
|
||||
|
||||
for( i = 0; i < 7; i++ )
|
||||
@ -395,12 +400,15 @@ int mbedtls_md4_self_test( int verbose )
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " MD4 test #%d: ", i + 1 );
|
||||
|
||||
if( mbedtls_md4_ext( (unsigned char *) md4_test_str[i],
|
||||
strlen( md4_test_str[i] ), md4sum ) != 0 )
|
||||
ret = mbedtls_md4_ext( md4_test_str[i], md4_test_strlen[i], md4sum );
|
||||
if( ret != 0 )
|
||||
goto fail;
|
||||
|
||||
if( memcmp( md4sum, md4_test_sum[i], 16 ) != 0 )
|
||||
{
|
||||
ret = 1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
@ -415,7 +423,7 @@ fail:
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
return( ret );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
@ -373,11 +373,11 @@ static const unsigned char md5_test_buf[7][81] =
|
||||
{ "message digest" },
|
||||
{ "abcdefghijklmnopqrstuvwxyz" },
|
||||
{ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" },
|
||||
{ "12345678901234567890123456789012345678901234567890123456789012" \
|
||||
{ "12345678901234567890123456789012345678901234567890123456789012"
|
||||
"345678901234567890" }
|
||||
};
|
||||
|
||||
static const int md5_test_buflen[7] =
|
||||
static const size_t md5_test_buflen[7] =
|
||||
{
|
||||
0, 1, 3, 14, 26, 62, 80
|
||||
};
|
||||
@ -405,7 +405,7 @@ static const unsigned char md5_test_sum[7][16] =
|
||||
*/
|
||||
int mbedtls_md5_self_test( int verbose )
|
||||
{
|
||||
int i;
|
||||
int i, ret = 0;
|
||||
unsigned char md5sum[16];
|
||||
|
||||
for( i = 0; i < 7; i++ )
|
||||
@ -413,12 +413,15 @@ int mbedtls_md5_self_test( int verbose )
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " MD5 test #%d: ", i + 1 );
|
||||
|
||||
if( mbedtls_md5_ext( md5_test_buf[i],
|
||||
md5_test_buflen[i], md5sum ) != 0 )
|
||||
ret = mbedtls_md5_ext( md5_test_buf[i], md5_test_buflen[i], md5sum );
|
||||
if( ret != 0 )
|
||||
goto fail;
|
||||
|
||||
if( memcmp( md5sum, md5_test_sum[i], 16 ) != 0 )
|
||||
{
|
||||
ret = 1;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
@ -433,7 +436,7 @@ fail:
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "failed\n" );
|
||||
|
||||
return( 1 );
|
||||
return( ret );
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
|
@ -426,18 +426,22 @@ exit:
|
||||
* http://homes.esat.kuleuven.be/~bosselae/mbedtls_ripemd160.html#HMAC
|
||||
*/
|
||||
#define TESTS 8
|
||||
#define KEYS 2
|
||||
static const char *ripemd160_test_input[TESTS] =
|
||||
static const unsigned char ripemd160_test_str[TESTS][81] =
|
||||
{
|
||||
"",
|
||||
"a",
|
||||
"abc",
|
||||
"message digest",
|
||||
"abcdefghijklmnopqrstuvwxyz",
|
||||
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
|
||||
"1234567890123456789012345678901234567890"
|
||||
"1234567890123456789012345678901234567890",
|
||||
{ "" },
|
||||
{ "a" },
|
||||
{ "abc" },
|
||||
{ "message digest" },
|
||||
{ "abcdefghijklmnopqrstuvwxyz" },
|
||||
{ "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" },
|
||||
{ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" },
|
||||
{ "12345678901234567890123456789012345678901234567890123456789012"
|
||||
"345678901234567890" },
|
||||
};
|
||||
|
||||
static const size_t ripemd160_test_strlen[TESTS] =
|
||||
{
|
||||
0, 1, 3, 14, 26, 56, 62, 80
|
||||
};
|
||||
|
||||
static const unsigned char ripemd160_test_md[TESTS][20] =
|
||||
@ -475,9 +479,8 @@ int mbedtls_ripemd160_self_test( int verbose )
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " RIPEMD-160 test #%d: ", i + 1 );
|
||||
|
||||
ret = mbedtls_ripemd160_ext(
|
||||
(const unsigned char *)ripemd160_test_input[i],
|
||||
strlen( ripemd160_test_input[i] ), output );
|
||||
ret = mbedtls_ripemd160_ext( ripemd160_test_str[i],
|
||||
ripemd160_test_strlen[i], output );
|
||||
if( ret != 0 )
|
||||
goto fail;
|
||||
|
||||
|
@ -405,7 +405,7 @@ static const unsigned char sha1_test_buf[3][57] =
|
||||
{ "" }
|
||||
};
|
||||
|
||||
static const int sha1_test_buflen[3] =
|
||||
static const size_t sha1_test_buflen[3] =
|
||||
{
|
||||
3, 56, 1000
|
||||
};
|
||||
|
@ -380,7 +380,7 @@ static const unsigned char sha256_test_buf[3][57] =
|
||||
{ "" }
|
||||
};
|
||||
|
||||
static const int sha256_test_buflen[3] =
|
||||
static const size_t sha256_test_buflen[3] =
|
||||
{
|
||||
3, 56, 1000
|
||||
};
|
||||
|
@ -418,7 +418,7 @@ static const unsigned char sha512_test_buf[3][113] =
|
||||
{ "" }
|
||||
};
|
||||
|
||||
static const int sha512_test_buflen[3] =
|
||||
static const size_t sha512_test_buflen[3] =
|
||||
{
|
||||
3, 112, 1000
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user