avr-crypto-lib/main-md5-test.c

82 lines
2.2 KiB
C

/*
* md5 test suit
*
*/
#include "config.h"
#include "serial-tools.h"
#include "uart.h"
#include "debug.h"
#include "md5.h"
#include <stdint.h>
#include <string.h>
/*****************************************************************************
* additional validation-functions *
*****************************************************************************/
/*****************************************************************************
* self tests *
*****************************************************************************/
/*
* MD5 test suite:
* MD5 ("") = d41d8cd98f00b204e9800998ecf8427e
* MD5 ("a") = 0cc175b9c0f1b6a831c399e269772661
* MD5 ("abc") = 900150983cd24fb0d6963f7d28e17f72
* MD5 ("message digest") = f96b697d7cb7938d525a2f31aaf161d0
* MD5 ("abcdefghijklmnopqrstuvwxyz") = c3fcd3d76192e4007dfb496cca67e13b
* MD5 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") =
* d174ab98d277d9f5a5611c2c9f419d9f
* MD5 ("123456789012345678901234567890123456789012345678901234567890123456
* 78901234567890") = 57edf4a22be3c955ac49da2e2107b67a
*/
void testrun_md5(void){
md5_ctx_t s;
char* testv[]={"", "a", "abc", "message digest", "abcdefghijklmnopqrstuvwxyz",
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
"12345678901234567890123456789012345678901234567890123456789012345678901234567890"};
uint8_t i;
uart_putstr("\r\n=== MD5 test suit ===");
for(i=0; i<7; ++i){
uart_putstr("\r\n MD5 (\"");
uart_putstr(testv[i]);
uart_putstr("\") = \r\n");
md5_init(&s);
md5_lastBlock(&s, testv[i], strlen(testv[i])*8);
uart_hexdump(&s.a[0], 16);
}
}
/*****************************************************************************
* main *
*****************************************************************************/
int main (void){
char str[20];
DEBUG_INIT();
uart_putstr("\r\n");
uart_putstr("\r\n\r\nCrypto-VS (MD5)\r\nloaded and running\r\n");
restart:
while(1){
if (!getnextwordn(str,20)) {DEBUG_S("DBG: W1\r\n"); goto error;}
if (strcmp(str, "test")) {DEBUG_S("DBG: 1b\r\n"); goto error;}
testrun_md5();
goto restart;
continue;
error:
uart_putstr("ERROR\r\n");
} /* while (1) */
}