Difference between revisions of "MD5-Hash"
From Nutwiki
(New page: The Message-Digest Algorithm 5 (MD5-Hash) is provided by the optional Gorp Library. == Test Suite Source Code == The contents of nutapp/testmd5/testmd5.c is: <source lang="c"> #include ...) |
m (1 revision imported) |
(No difference)
| |
Latest revision as of 16:02, 27 October 2016
The Message-Digest Algorithm 5 (MD5-Hash) is provided by the optional Gorp Library.
Test Suite Source Code
The contents of nutapp/testmd5/testmd5.c is:
<source lang="c">
- include <dev/board.h>
- include <gorp/md5.h>
- include <stdio.h>
- include <string.h>
static MD5CONTEXT context; static uint8_t digest[16];
static char *test[] = {
"", "a", "abc", "message digest", "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", "12345678901234567890123456789012345678901234567890123456789012345678901234567890", NULL
};
int main(void) {
int i; int j;
NutRegisterDevice(&DEV_CONSOLE, 0, 0);
freopen(DEV_CONSOLE.dev_name, "w", stdout);
puts("\nMD5 Test Suite " __DATE__ " " __TIME__);
for (i = 0; test[i]; i++) {
NutMD5Init(&context);
NutMD5Update(&context, (uint8_t *)test[i], strlen(test[i]));
NutMD5Final(&context, digest);
printf("MD5 (\"%s\") = ", test[i]);
for (j = 0; j < 16; j++) {
printf("%02x", digest[j]);
}
putchar('\n');
}
for (;;);
return 0;
} </source>
Test Suite Makefile
Note, that lines must me intended with tabs, not spaces.
PROJ = testmd5
include ../Makedefs
SRCS = $(PROJ).c
OBJS = $(SRCS:.c=.o)
LIBS = $(LIBDIR)/nutinit.o -lnutpro -lnutnet -lnutgorp -lnutfs -lnutcrt -lnutos -lnutdev -lnutarch
all: $(OBJS) $(TARG) $(ITARG) $(DTARG)
include ../Makerules
clean:
-rm -f $(OBJS)
-rm -f $(TARG) $(ITARG) $(DTARG)
-rm -f $(PROJ).map
-rm -f $(SRCS:.c=.lst)
-rm -f $(SRCS:.c=.d)
Test Suite Result
Tested on the Elektor Internet Radio, the output equates to http://tools.ietf.org/html/rfc1321.
MD5 Test Suite Oct 10 2012 18:31:11
MD5 ("") = d41d8cd98f00b204e9800998ecf8427e
MD5 ("a") = 0cc175b9c0f1b6a831c399e269772661
MD5 ("abc") = 900150983cd24fb0d6963f7d28e17f72
MD5 ("message digest") = f96b697d7cb7938d525a2f31aaf161d0
MD5 ("abcdefghijklmnopqrstuvwxyz") = c3fcd3d76192e4007dfb496cca67e13b
MD5 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") =
d174ab98d277d9f5a5611c2c9f419d9f
MD5 ("123456789012345678901234567890123456789012345678901234567890123456
78901234567890") = 57edf4a22be3c955ac49da2e2107b67a