hmac_test_vectors test: Replace axTLS with mbedTLS

This commit is contained in:
Angus Gratton 2015-09-28 13:01:13 +10:00
parent 8e5221b894
commit 5088e7e64b
2 changed files with 21 additions and 7 deletions

View file

@ -1,2 +1,3 @@
PROGRAM=hmac_test PROGRAM=hmac_test
EXTRA_COMPONENTS=extras/mbedtls
include ../../../common.mk include ../../../common.mk

View file

@ -10,7 +10,7 @@
#include "espressif/esp_common.h" #include "espressif/esp_common.h"
#include "espressif/sdk_private.h" #include "espressif/sdk_private.h"
#include "FreeRTOS.h" #include "FreeRTOS.h"
#include "ssl.h" #include "mbedtls/md.h"
#include <string.h> #include <string.h>
@ -31,9 +31,7 @@ static const uint8_t aa_80_times[] = {0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0x
0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa, 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa}; 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa};
/* NOTE: Vectors 6 & 7 currently cause a fault as the axTLS const uint8_t NUM_MD5_VECTORS = 7;
routines don't support keys longer than the block size. */
const uint8_t NUM_MD5_VECTORS = 5;
static const struct test_vector md5_vectors[] = { static const struct test_vector md5_vectors[] = {
{ /* vector 1*/ { /* vector 1*/
@ -88,15 +86,30 @@ static const struct test_vector md5_vectors[] = {
}, },
}; };
static void print_blob(const char *label, const uint8_t *data, const uint32_t len)
{
printf("%s:", label);
for(int i = 0; i < len; i++) {
if(i % 16 == 0)
printf("\n%02x:", i);
printf(" %02x", data[i]);
}
}
static void test_md5(void) static void test_md5(void)
{ {
printf("\r\nTesting MD5 vectors...\r\n"); printf("\r\nTesting MD5 vectors...\r\n");
uint8_t test_digest[16];
const mbedtls_md_info_t *md5_hmac = mbedtls_md_info_from_type(MBEDTLS_MD_MD5);
for(int i = 0; i < NUM_MD5_VECTORS; i++) { for(int i = 0; i < NUM_MD5_VECTORS; i++) {
const struct test_vector *vector = &md5_vectors[i]; const struct test_vector *vector = &md5_vectors[i];
printf("Test case %d: ", i+1); printf("Test case %d: ", i+1);
hmac_md5(vector->data, vector->data_len, vector->key, vector->key_len, test_digest);
if(memcmp(test_digest, vector->digest, 16)) { uint8_t test_digest[16];
mbedtls_md_hmac(md5_hmac, vector->key, vector->key_len, vector->data, vector->data_len, test_digest);
if(memcmp(vector->digest, test_digest, 16)) {
uint8_t first = 0; uint8_t first = 0;
for(first = 0; first < 16; first++) { for(first = 0; first < 16; first++) {
if(test_digest[first] != vector->digest[first]) { if(test_digest[first] != vector->digest[first]) {