mirror of
https://github.com/yuzu-emu/mbedtls
synced 2024-11-24 22:38:24 +00:00
9e4f77c606
The _ext suffix suggests "new arguments", but the new functions have the same arguments. Use _ret instead, to convey that the difference is that the new functions return a value.
131 lines
3.4 KiB
Text
131 lines
3.4 KiB
Text
/* BEGIN_HEADER */
|
|
#include "mbedtls/sha1.h"
|
|
#include "mbedtls/sha256.h"
|
|
#include "mbedtls/sha512.h"
|
|
/* END_HEADER */
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA1_C */
|
|
void mbedtls_sha1( char *hex_src_string, char *hex_hash_string )
|
|
{
|
|
unsigned char src_str[10000];
|
|
unsigned char hash_str[10000];
|
|
unsigned char output[41];
|
|
int src_len;
|
|
|
|
memset(src_str, 0x00, 10000);
|
|
memset(hash_str, 0x00, 10000);
|
|
memset(output, 0x00, 41);
|
|
|
|
src_len = unhexify( src_str, hex_src_string );
|
|
|
|
TEST_ASSERT( mbedtls_sha1_ret( src_str, src_len, output ) == 0 );
|
|
hexify( hash_str, output, 20 );
|
|
|
|
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
|
|
}
|
|
/* END_CASE */
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C */
|
|
void sha224(char *hex_src_string, char *hex_hash_string )
|
|
{
|
|
unsigned char src_str[10000];
|
|
unsigned char hash_str[10000];
|
|
unsigned char output[57];
|
|
int src_len;
|
|
|
|
memset(src_str, 0x00, 10000);
|
|
memset(hash_str, 0x00, 10000);
|
|
memset(output, 0x00, 57);
|
|
|
|
src_len = unhexify( src_str, hex_src_string );
|
|
|
|
TEST_ASSERT( mbedtls_sha256_ret( src_str, src_len, output, 1 ) == 0 );
|
|
hexify( hash_str, output, 28 );
|
|
|
|
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
|
|
}
|
|
/* END_CASE */
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C */
|
|
void mbedtls_sha256(char *hex_src_string, char *hex_hash_string )
|
|
{
|
|
unsigned char src_str[10000];
|
|
unsigned char hash_str[10000];
|
|
unsigned char output[65];
|
|
int src_len;
|
|
|
|
memset(src_str, 0x00, 10000);
|
|
memset(hash_str, 0x00, 10000);
|
|
memset(output, 0x00, 65);
|
|
|
|
src_len = unhexify( src_str, hex_src_string );
|
|
|
|
TEST_ASSERT( mbedtls_sha256_ret( src_str, src_len, output, 0 ) == 0 );
|
|
hexify( hash_str, output, 32 );
|
|
|
|
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
|
|
}
|
|
/* END_CASE */
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C */
|
|
void sha384(char *hex_src_string, char *hex_hash_string )
|
|
{
|
|
unsigned char src_str[10000];
|
|
unsigned char hash_str[10000];
|
|
unsigned char output[97];
|
|
int src_len;
|
|
|
|
memset(src_str, 0x00, 10000);
|
|
memset(hash_str, 0x00, 10000);
|
|
memset(output, 0x00, 97);
|
|
|
|
src_len = unhexify( src_str, hex_src_string );
|
|
|
|
TEST_ASSERT( mbedtls_sha512_ret( src_str, src_len, output, 1 ) == 0 );
|
|
hexify( hash_str, output, 48 );
|
|
|
|
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
|
|
}
|
|
/* END_CASE */
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C */
|
|
void mbedtls_sha512(char *hex_src_string, char *hex_hash_string )
|
|
{
|
|
unsigned char src_str[10000];
|
|
unsigned char hash_str[10000];
|
|
unsigned char output[129];
|
|
int src_len;
|
|
|
|
memset(src_str, 0x00, 10000);
|
|
memset(hash_str, 0x00, 10000);
|
|
memset(output, 0x00, 129);
|
|
|
|
src_len = unhexify( src_str, hex_src_string );
|
|
|
|
TEST_ASSERT( mbedtls_sha512_ret( src_str, src_len, output, 0 ) == 0 );
|
|
hexify( hash_str, output, 64 );
|
|
|
|
TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
|
|
}
|
|
/* END_CASE */
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA1_C:MBEDTLS_SELF_TEST */
|
|
void sha1_selftest()
|
|
{
|
|
TEST_ASSERT( mbedtls_sha1_self_test( 1 ) == 0 );
|
|
}
|
|
/* END_CASE */
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA256_C:MBEDTLS_SELF_TEST */
|
|
void sha256_selftest()
|
|
{
|
|
TEST_ASSERT( mbedtls_sha256_self_test( 1 ) == 0 );
|
|
}
|
|
/* END_CASE */
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SHA512_C:MBEDTLS_SELF_TEST */
|
|
void sha512_selftest()
|
|
{
|
|
TEST_ASSERT( mbedtls_sha512_self_test( 1 ) == 0 );
|
|
}
|
|
/* END_CASE */
|