2013-08-20 11:48:36 +02:00
|
|
|
/* BEGIN_HEADER */
|
2009-06-28 23:50:27 +02:00
|
|
|
#include <polarssl/sha1.h>
|
2013-06-30 14:49:12 +02:00
|
|
|
#include <polarssl/sha256.h>
|
|
|
|
#include <polarssl/sha512.h>
|
2013-08-20 11:48:36 +02:00
|
|
|
/* END_HEADER */
|
2009-06-28 23:50:27 +02:00
|
|
|
|
2013-08-20 12:42:31 +02:00
|
|
|
/* BEGIN_CASE depends_on:POLARSSL_SHA1_C */
|
2013-08-20 11:48:36 +02:00
|
|
|
void sha1_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
|
|
|
|
char *hex_hash_string)
|
2009-06-28 23:50:27 +02:00
|
|
|
{
|
|
|
|
unsigned char src_str[10000];
|
|
|
|
unsigned char key_str[10000];
|
|
|
|
unsigned char hash_str[10000];
|
|
|
|
unsigned char output[41];
|
2009-07-11 21:15:20 +02:00
|
|
|
int key_len, src_len;
|
2009-06-28 23:50:27 +02:00
|
|
|
|
|
|
|
memset(src_str, 0x00, 10000);
|
|
|
|
memset(key_str, 0x00, 10000);
|
|
|
|
memset(hash_str, 0x00, 10000);
|
|
|
|
memset(output, 0x00, 41);
|
|
|
|
|
2013-08-20 11:48:36 +02:00
|
|
|
key_len = unhexify( key_str, hex_key_string );
|
|
|
|
src_len = unhexify( src_str, hex_src_string );
|
2009-06-28 23:50:27 +02:00
|
|
|
|
|
|
|
sha1_hmac( key_str, key_len, src_str, src_len, output );
|
|
|
|
hexify( hash_str, output, 20 );
|
|
|
|
|
2013-08-20 11:48:36 +02:00
|
|
|
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
|
2009-06-28 23:50:27 +02:00
|
|
|
}
|
2013-08-20 11:48:36 +02:00
|
|
|
/* END_CASE */
|
2009-06-28 23:50:27 +02:00
|
|
|
|
2013-08-20 12:42:31 +02:00
|
|
|
/* BEGIN_CASE depends_on:POLARSSL_SHA256_C */
|
2013-08-20 11:48:36 +02:00
|
|
|
void sha224_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
|
|
|
|
char *hex_hash_string)
|
2009-06-28 23:50:27 +02:00
|
|
|
{
|
|
|
|
unsigned char src_str[10000];
|
|
|
|
unsigned char key_str[10000];
|
|
|
|
unsigned char hash_str[10000];
|
|
|
|
unsigned char output[57];
|
2009-07-11 21:15:20 +02:00
|
|
|
int key_len, src_len;
|
2009-06-28 23:50:27 +02:00
|
|
|
|
|
|
|
memset(src_str, 0x00, 10000);
|
|
|
|
memset(key_str, 0x00, 10000);
|
|
|
|
memset(hash_str, 0x00, 10000);
|
|
|
|
memset(output, 0x00, 57);
|
|
|
|
|
2013-08-20 11:48:36 +02:00
|
|
|
key_len = unhexify( key_str, hex_key_string );
|
|
|
|
src_len = unhexify( src_str, hex_src_string );
|
2009-06-28 23:50:27 +02:00
|
|
|
|
2013-06-30 14:34:05 +02:00
|
|
|
sha256_hmac( key_str, key_len, src_str, src_len, output, 1 );
|
2009-06-28 23:50:27 +02:00
|
|
|
hexify( hash_str, output, 28 );
|
|
|
|
|
2013-08-20 11:48:36 +02:00
|
|
|
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
|
2009-06-28 23:50:27 +02:00
|
|
|
}
|
2013-08-20 11:48:36 +02:00
|
|
|
/* END_CASE */
|
2009-06-28 23:50:27 +02:00
|
|
|
|
2013-08-20 12:42:31 +02:00
|
|
|
/* BEGIN_CASE depends_on:POLARSSL_SHA256_C */
|
2013-08-20 11:48:36 +02:00
|
|
|
void sha256_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
|
|
|
|
char *hex_hash_string)
|
2009-06-28 23:50:27 +02:00
|
|
|
{
|
|
|
|
unsigned char src_str[10000];
|
|
|
|
unsigned char key_str[10000];
|
|
|
|
unsigned char hash_str[10000];
|
|
|
|
unsigned char output[65];
|
2009-07-11 21:15:20 +02:00
|
|
|
int key_len, src_len;
|
2009-06-28 23:50:27 +02:00
|
|
|
|
|
|
|
memset(src_str, 0x00, 10000);
|
|
|
|
memset(key_str, 0x00, 10000);
|
|
|
|
memset(hash_str, 0x00, 10000);
|
|
|
|
memset(output, 0x00, 65);
|
|
|
|
|
2013-08-20 11:48:36 +02:00
|
|
|
key_len = unhexify( key_str, hex_key_string );
|
|
|
|
src_len = unhexify( src_str, hex_src_string );
|
2009-06-28 23:50:27 +02:00
|
|
|
|
2013-06-30 14:34:05 +02:00
|
|
|
sha256_hmac( key_str, key_len, src_str, src_len, output, 0 );
|
2009-06-28 23:50:27 +02:00
|
|
|
hexify( hash_str, output, 32 );
|
|
|
|
|
2013-08-20 11:48:36 +02:00
|
|
|
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
|
2009-06-28 23:50:27 +02:00
|
|
|
}
|
2013-08-20 11:48:36 +02:00
|
|
|
/* END_CASE */
|
2009-06-28 23:50:27 +02:00
|
|
|
|
2013-08-20 12:42:31 +02:00
|
|
|
/* BEGIN_CASE depends_on:POLARSSL_SHA512_C */
|
2013-08-20 11:48:36 +02:00
|
|
|
void sha384_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
|
|
|
|
char *hex_hash_string)
|
2009-06-28 23:50:27 +02:00
|
|
|
{
|
|
|
|
unsigned char src_str[10000];
|
|
|
|
unsigned char key_str[10000];
|
|
|
|
unsigned char hash_str[10000];
|
|
|
|
unsigned char output[97];
|
2009-07-11 21:15:20 +02:00
|
|
|
int key_len, src_len;
|
2009-06-28 23:50:27 +02:00
|
|
|
|
|
|
|
memset(src_str, 0x00, 10000);
|
|
|
|
memset(key_str, 0x00, 10000);
|
|
|
|
memset(hash_str, 0x00, 10000);
|
|
|
|
memset(output, 0x00, 97);
|
|
|
|
|
2013-08-20 11:48:36 +02:00
|
|
|
key_len = unhexify( key_str, hex_key_string );
|
|
|
|
src_len = unhexify( src_str, hex_src_string );
|
2009-06-28 23:50:27 +02:00
|
|
|
|
2013-06-30 14:34:05 +02:00
|
|
|
sha512_hmac( key_str, key_len, src_str, src_len, output, 1 );
|
2009-06-28 23:50:27 +02:00
|
|
|
hexify( hash_str, output, 48 );
|
|
|
|
|
2013-08-20 11:48:36 +02:00
|
|
|
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
|
2009-06-28 23:50:27 +02:00
|
|
|
}
|
2013-08-20 11:48:36 +02:00
|
|
|
/* END_CASE */
|
2009-06-28 23:50:27 +02:00
|
|
|
|
2013-08-20 12:42:31 +02:00
|
|
|
/* BEGIN_CASE depends_on:POLARSSL_SHA512_C */
|
2013-08-20 11:48:36 +02:00
|
|
|
void sha512_hmac( int trunc_size, char *hex_key_string, char *hex_src_string,
|
|
|
|
char *hex_hash_string)
|
2009-06-28 23:50:27 +02:00
|
|
|
{
|
|
|
|
unsigned char src_str[10000];
|
|
|
|
unsigned char key_str[10000];
|
|
|
|
unsigned char hash_str[10000];
|
|
|
|
unsigned char output[129];
|
2009-07-11 21:15:20 +02:00
|
|
|
int key_len, src_len;
|
2009-06-28 23:50:27 +02:00
|
|
|
|
|
|
|
memset(src_str, 0x00, 10000);
|
|
|
|
memset(key_str, 0x00, 10000);
|
|
|
|
memset(hash_str, 0x00, 10000);
|
|
|
|
memset(output, 0x00, 129);
|
|
|
|
|
2013-08-20 11:48:36 +02:00
|
|
|
key_len = unhexify( key_str, hex_key_string );
|
|
|
|
src_len = unhexify( src_str, hex_src_string );
|
2009-06-28 23:50:27 +02:00
|
|
|
|
2013-06-30 14:34:05 +02:00
|
|
|
sha512_hmac( key_str, key_len, src_str, src_len, output, 0 );
|
2009-06-28 23:50:27 +02:00
|
|
|
hexify( hash_str, output, 64 );
|
|
|
|
|
2013-08-20 11:48:36 +02:00
|
|
|
TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
|
2009-06-28 23:50:27 +02:00
|
|
|
}
|
2013-08-20 11:48:36 +02:00
|
|
|
/* END_CASE */
|