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