meillo@0: #include meillo@0: #include meillo@0: #include meillo@0: #include meillo@0: #include "md5.h" meillo@0: #include "hmac_md5.h" meillo@0: meillo@165: /* meillo@165: instead of pad0_copy(d, s, sz) use: meillo@165: memset(d, 0, sz); meillo@165: memcpy(d, s, strlen(s)); meillo@165: meillo@10: static void meillo@10: pad0_copy(char *d, char *s, int sz) meillo@0: { meillo@10: int i = 0; meillo@10: while (*s && (i < sz)) { meillo@10: *(d++) = *(s++); meillo@10: i++; meillo@10: } meillo@10: while (i <= sz) { meillo@10: *(d++) = 0; meillo@10: i++; meillo@10: } meillo@0: } meillo@165: */ meillo@0: meillo@10: int meillo@10: main() meillo@0: { meillo@10: int i; meillo@10: char digest[16]; meillo@10: char *msgid = "<1896.697170952@postoffice.reston.mci.net>"; meillo@10: char secret[65]; meillo@0: meillo@165: meillo@10: hmac_md5("<48157.953508124@mail.class-c.net>", 34, "no!SpamAtAll", 12, digest); meillo@10: for (i = 0; i < 16; i++) meillo@165: printf("%.2x", 0xFF & (unsigned int) digest[i]); meillo@165: printf("\n\n"); meillo@165: meillo@165: meillo@165: puts("---- The next two should be equal"); meillo@165: meillo@0: meillo@10: hmac_md5(msgid, strlen(msgid), "tanstaaftanstaaf", 16, digest); meillo@10: for (i = 0; i < 16; i++) meillo@165: printf("%.2x", 0xFF & (unsigned int) digest[i]); meillo@165: printf("\n\n"); meillo@0: meillo@165: meillo@165: /* pad0_copy(secret, "tanstaaftanstaaf", 64); */ meillo@165: /* let's do it easier ... */ meillo@165: memset(secret, 0, sizeof(secret)); meillo@165: memcpy(secret, "tanstaaftanstaaf", 16); meillo@10: hmac_md5(msgid, strlen(msgid), secret, 64, digest); meillo@10: for (i = 0; i < 16; i++) meillo@165: printf("%.2x", 0xFF & (unsigned int) digest[i]); meillo@165: printf("\n\n"); meillo@165: meillo@165: meillo@165: puts("---- Following are the test vectors from RFC 2104"); meillo@165: meillo@165: meillo@165: char* d01 = "Hi There"; meillo@165: char k01[16]; meillo@165: for (i=0; i<16; i++) { meillo@165: k01[i] = 0x0b; meillo@165: } meillo@165: printf("9294727a3638bb1c13f48ef8158bfc9d (should be)\n"); meillo@165: hmac_md5(d01, strlen(d01), k01, sizeof(k01), digest); meillo@165: for (i = 0; i < 16; i++) { meillo@165: printf("%.2x", 0xFF & (unsigned int) digest[i]); meillo@165: } meillo@165: printf(" (was computed)\n\n"); meillo@165: meillo@165: meillo@165: char* d02 = "what do ya want for nothing?"; meillo@165: char* k02 = "Jefe"; meillo@165: printf("750c783e6ab0b503eaa86e310a5db738 (should be)\n"); meillo@165: hmac_md5(d02, strlen(d02), k02, strlen(k02), digest); meillo@165: for (i = 0; i < 16; i++) { meillo@165: printf("%.2x", 0xFF & (unsigned int) digest[i]); meillo@165: } meillo@165: printf(" (was computed)\n\n"); meillo@165: meillo@165: meillo@165: char d03[50]; meillo@165: for (i=0; i