Richard Marian Thomaiyar | 14fddef | 2018-07-13 23:55:56 +0530 | [diff] [blame] | 1 | #include <mhash.h> |
| 2 | #include <stdio.h> |
| 3 | |
| 4 | int main() |
| 5 | { |
| 6 | |
| 7 | char password[] = "Jefe"; |
| 8 | int keylen = 4; |
| 9 | char data[] = "what do ya want for nothing?"; |
| 10 | int datalen = 28; |
| 11 | MHASH td; |
| 12 | unsigned char mac[16]; |
| 13 | int j; |
| 14 | |
| 15 | td = mhash_hmac_init(MHASH_MD5, password, keylen, mhash_get_hash_pblock(MHASH_MD5)); |
| 16 | |
| 17 | mhash(td, data, datalen); |
| 18 | mhash_hmac_deinit(td, mac); |
| 19 | |
| 20 | /* |
| 21 | * The output should be 0x750c783e6ab0b503eaa86e310a5db738 |
| 22 | * according to RFC 2104. |
| 23 | */ |
| 24 | |
| 25 | printf("0x"); |
| 26 | for (j = 0; j < mhash_get_block_size(MHASH_MD5); j++) { |
| 27 | printf("%.2x", mac[j]); |
| 28 | } |
| 29 | printf("\n"); |
| 30 | |
| 31 | exit(0); |
| 32 | } |