mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-02-20 03:39:58 +00:00
Use MD type not string to in MD test data
For all test that want to use a hash, identify it by its numerical type rather than a string. The motivation is that when we isolate the MD-light subset from the larger MD, it won't have support for string identifiers. Do the change for all tests, not just those that will exercise functions in MD-light, for the sake of uniformity and because numerical identifiers just feel better. Note: mbedtls_md_info_from_string is still tested in md_info(). Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
This commit is contained in:
parent
bae8d2ae13
commit
c90514ee11
File diff suppressed because it is too large
Load Diff
@ -131,21 +131,17 @@ void md_info(int md_type, char *md_name, int md_size)
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void md_text(char *text_md_name, char *text_src_string,
|
||||
data_t *hash)
|
||||
void md_text(int md_type, char *text_src_string, data_t *hash)
|
||||
{
|
||||
char md_name[100];
|
||||
unsigned char src_str[1000];
|
||||
unsigned char output[100];
|
||||
const mbedtls_md_info_t *md_info = NULL;
|
||||
|
||||
memset(md_name, 0x00, 100);
|
||||
memset(src_str, 0x00, 1000);
|
||||
memset(output, 0x00, 100);
|
||||
|
||||
strncpy((char *) src_str, text_src_string, sizeof(src_str) - 1);
|
||||
strncpy((char *) md_name, text_md_name, sizeof(md_name) - 1);
|
||||
md_info = mbedtls_md_info_from_string(md_name);
|
||||
md_info = mbedtls_md_info_from_type(md_type);
|
||||
TEST_ASSERT(md_info != NULL);
|
||||
|
||||
TEST_ASSERT(0 == mbedtls_md(md_info, src_str, strlen((char *) src_str), output));
|
||||
@ -157,17 +153,14 @@ void md_text(char *text_md_name, char *text_src_string,
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void md_hex(char *text_md_name, data_t *src_str, data_t *hash)
|
||||
void md_hex(int md_type, data_t *src_str, data_t *hash)
|
||||
{
|
||||
char md_name[100];
|
||||
unsigned char output[100];
|
||||
const mbedtls_md_info_t *md_info = NULL;
|
||||
|
||||
memset(md_name, 0x00, 100);
|
||||
memset(output, 0x00, 100);
|
||||
|
||||
strncpy((char *) md_name, text_md_name, sizeof(md_name) - 1);
|
||||
md_info = mbedtls_md_info_from_string(md_name);
|
||||
md_info = mbedtls_md_info_from_type(md_type);
|
||||
TEST_ASSERT(md_info != NULL);
|
||||
|
||||
TEST_ASSERT(0 == mbedtls_md(md_info, src_str->x, src_str->len, output));
|
||||
@ -180,10 +173,9 @@ void md_hex(char *text_md_name, data_t *src_str, data_t *hash)
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void md_text_multi(char *text_md_name, char *text_src_string,
|
||||
void md_text_multi(int md_type, char *text_src_string,
|
||||
data_t *hash)
|
||||
{
|
||||
char md_name[100];
|
||||
unsigned char src_str[1000];
|
||||
unsigned char output[100];
|
||||
int halfway, len;
|
||||
@ -194,16 +186,14 @@ void md_text_multi(char *text_md_name, char *text_src_string,
|
||||
mbedtls_md_init(&ctx);
|
||||
mbedtls_md_init(&ctx_copy);
|
||||
|
||||
memset(md_name, 0x00, 100);
|
||||
memset(src_str, 0x00, 1000);
|
||||
memset(output, 0x00, 100);
|
||||
|
||||
strncpy((char *) src_str, text_src_string, sizeof(src_str) - 1);
|
||||
strncpy((char *) md_name, text_md_name, sizeof(md_name) - 1);
|
||||
len = strlen((char *) src_str);
|
||||
halfway = len / 2;
|
||||
|
||||
md_info = mbedtls_md_info_from_string(md_name);
|
||||
md_info = mbedtls_md_info_from_type(md_type);
|
||||
TEST_ASSERT(md_info != NULL);
|
||||
TEST_ASSERT(0 == mbedtls_md_setup(&ctx, md_info, 0));
|
||||
TEST_ASSERT(0 == mbedtls_md_setup(&ctx_copy, md_info, 0));
|
||||
@ -237,9 +227,8 @@ exit:
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void md_hex_multi(char *text_md_name, data_t *src_str, data_t *hash)
|
||||
void md_hex_multi(int md_type, data_t *src_str, data_t *hash)
|
||||
{
|
||||
char md_name[100];
|
||||
unsigned char output[100];
|
||||
const mbedtls_md_info_t *md_info = NULL;
|
||||
mbedtls_md_context_t ctx, ctx_copy;
|
||||
@ -248,11 +237,9 @@ void md_hex_multi(char *text_md_name, data_t *src_str, data_t *hash)
|
||||
mbedtls_md_init(&ctx);
|
||||
mbedtls_md_init(&ctx_copy);
|
||||
|
||||
memset(md_name, 0x00, 100);
|
||||
memset(output, 0x00, 100);
|
||||
|
||||
strncpy((char *) md_name, text_md_name, sizeof(md_name) - 1);
|
||||
md_info = mbedtls_md_info_from_string(md_name);
|
||||
md_info = mbedtls_md_info_from_type(md_type);
|
||||
TEST_ASSERT(md_info != NULL);
|
||||
TEST_ASSERT(0 == mbedtls_md_setup(&ctx, md_info, 0));
|
||||
TEST_ASSERT(0 == mbedtls_md_setup(&ctx_copy, md_info, 0));
|
||||
@ -288,19 +275,16 @@ exit:
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_md_hmac(char *text_md_name, int trunc_size,
|
||||
void mbedtls_md_hmac(int md_type, int trunc_size,
|
||||
data_t *key_str, data_t *src_str,
|
||||
data_t *hash)
|
||||
{
|
||||
char md_name[100];
|
||||
unsigned char output[100];
|
||||
const mbedtls_md_info_t *md_info = NULL;
|
||||
|
||||
memset(md_name, 0x00, 100);
|
||||
memset(output, 0x00, 100);
|
||||
|
||||
strncpy((char *) md_name, text_md_name, sizeof(md_name) - 1);
|
||||
md_info = mbedtls_md_info_from_string(md_name);
|
||||
md_info = mbedtls_md_info_from_type(md_type);
|
||||
TEST_ASSERT(md_info != NULL);
|
||||
|
||||
|
||||
@ -313,10 +297,9 @@ void mbedtls_md_hmac(char *text_md_name, int trunc_size,
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void md_hmac_multi(char *text_md_name, int trunc_size, data_t *key_str,
|
||||
void md_hmac_multi(int md_type, int trunc_size, data_t *key_str,
|
||||
data_t *src_str, data_t *hash)
|
||||
{
|
||||
char md_name[100];
|
||||
unsigned char output[100];
|
||||
const mbedtls_md_info_t *md_info = NULL;
|
||||
mbedtls_md_context_t ctx;
|
||||
@ -324,11 +307,9 @@ void md_hmac_multi(char *text_md_name, int trunc_size, data_t *key_str,
|
||||
|
||||
mbedtls_md_init(&ctx);
|
||||
|
||||
memset(md_name, 0x00, 100);
|
||||
memset(output, 0x00, 100);
|
||||
|
||||
strncpy((char *) md_name, text_md_name, sizeof(md_name) - 1);
|
||||
md_info = mbedtls_md_info_from_string(md_name);
|
||||
md_info = mbedtls_md_info_from_type(md_type);
|
||||
TEST_ASSERT(md_info != NULL);
|
||||
TEST_ASSERT(0 == mbedtls_md_setup(&ctx, md_info, 1));
|
||||
TEST_ASSERT(mbedtls_md_info_from_ctx(&ctx) == md_info);
|
||||
@ -361,18 +342,15 @@ exit:
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_FS_IO */
|
||||
void mbedtls_md_file(char *text_md_name, char *filename,
|
||||
void mbedtls_md_file(int md_type, char *filename,
|
||||
data_t *hash)
|
||||
{
|
||||
char md_name[100];
|
||||
unsigned char output[100];
|
||||
const mbedtls_md_info_t *md_info = NULL;
|
||||
|
||||
memset(md_name, 0x00, 100);
|
||||
memset(output, 0x00, 100);
|
||||
|
||||
strncpy((char *) md_name, text_md_name, sizeof(md_name) - 1);
|
||||
md_info = mbedtls_md_info_from_string(md_name);
|
||||
md_info = mbedtls_md_info_from_type(md_type);
|
||||
TEST_ASSERT(md_info != NULL);
|
||||
|
||||
TEST_ASSERT(mbedtls_md_file(md_info, filename, output) == 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user