mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-30 02:54:20 +01:00
131 lines
3.9 KiB
Plaintext
131 lines
3.9 KiB
Plaintext
/* BEGIN_HEADER */
|
|
#include <polarssl/sha1.h>
|
|
#include <polarssl/sha256.h>
|
|
#include <polarssl/sha512.h>
|
|
/* END_HEADER */
|
|
|
|
/* BEGIN_CASE depends_on:POLARSSL_SHA1_C */
|
|
void sha1_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[41];
|
|
int key_len, src_len;
|
|
|
|
memset(src_str, 0x00, 10000);
|
|
memset(key_str, 0x00, 10000);
|
|
memset(hash_str, 0x00, 10000);
|
|
memset(output, 0x00, 41);
|
|
|
|
key_len = unhexify( key_str, hex_key_string );
|
|
src_len = unhexify( src_str, hex_src_string );
|
|
|
|
sha1_hmac( key_str, key_len, src_str, src_len, output );
|
|
hexify( hash_str, output, 20 );
|
|
|
|
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
|
|
}
|
|
/* END_CASE */
|
|
|
|
/* BEGIN_CASE depends_on:POLARSSL_SHA256_C */
|
|
void sha224_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[57];
|
|
int key_len, src_len;
|
|
|
|
memset(src_str, 0x00, 10000);
|
|
memset(key_str, 0x00, 10000);
|
|
memset(hash_str, 0x00, 10000);
|
|
memset(output, 0x00, 57);
|
|
|
|
key_len = unhexify( key_str, hex_key_string );
|
|
src_len = unhexify( src_str, hex_src_string );
|
|
|
|
sha256_hmac( key_str, key_len, src_str, src_len, output, 1 );
|
|
hexify( hash_str, output, 28 );
|
|
|
|
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
|
|
}
|
|
/* END_CASE */
|
|
|
|
/* BEGIN_CASE depends_on:POLARSSL_SHA256_C */
|
|
void sha256_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[65];
|
|
int key_len, src_len;
|
|
|
|
memset(src_str, 0x00, 10000);
|
|
memset(key_str, 0x00, 10000);
|
|
memset(hash_str, 0x00, 10000);
|
|
memset(output, 0x00, 65);
|
|
|
|
key_len = unhexify( key_str, hex_key_string );
|
|
src_len = unhexify( src_str, hex_src_string );
|
|
|
|
sha256_hmac( key_str, key_len, src_str, src_len, output, 0 );
|
|
hexify( hash_str, output, 32 );
|
|
|
|
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
|
|
}
|
|
/* END_CASE */
|
|
|
|
/* BEGIN_CASE depends_on:POLARSSL_SHA512_C */
|
|
void sha384_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[97];
|
|
int key_len, src_len;
|
|
|
|
memset(src_str, 0x00, 10000);
|
|
memset(key_str, 0x00, 10000);
|
|
memset(hash_str, 0x00, 10000);
|
|
memset(output, 0x00, 97);
|
|
|
|
key_len = unhexify( key_str, hex_key_string );
|
|
src_len = unhexify( src_str, hex_src_string );
|
|
|
|
sha512_hmac( key_str, key_len, src_str, src_len, output, 1 );
|
|
hexify( hash_str, output, 48 );
|
|
|
|
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
|
|
}
|
|
/* END_CASE */
|
|
|
|
/* BEGIN_CASE depends_on:POLARSSL_SHA512_C */
|
|
void sha512_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[129];
|
|
int key_len, src_len;
|
|
|
|
memset(src_str, 0x00, 10000);
|
|
memset(key_str, 0x00, 10000);
|
|
memset(hash_str, 0x00, 10000);
|
|
memset(output, 0x00, 129);
|
|
|
|
key_len = unhexify( key_str, hex_key_string );
|
|
src_len = unhexify( src_str, hex_src_string );
|
|
|
|
sha512_hmac( key_str, key_len, src_str, src_len, output, 0 );
|
|
hexify( hash_str, output, 64 );
|
|
|
|
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
|
|
}
|
|
/* END_CASE */
|