hmac fixed for new API
[rofl0r-kripto.git] / test / mac / hmac.c
blob2ffd17f96fd3a07e3978a845c121d105f07198aa
1 /*
2 * Copyright (C) 2013 Gregor Pintar <grpintar@gmail.com>
4 * Permission is granted to deal in this work without any restriction,
5 * including unlimited rights to use, publicly perform, publish,
6 * reproduce, relicence, modify, merge, and/or distribute in any form,
7 * for any purpose, with or without fee, and by any means.
9 * This work is provided "AS IS" and WITHOUT WARRANTY of any kind,
10 * to the utmost extent permitted by applicable law. In no event
11 * shall a licensor, author or contributor be held liable for any
12 * issues arising in any way out of dealing in the work.
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <stdint.h>
18 #include <string.h>
20 #include <kripto/mac.h>
21 #include <kripto/mac/hmac.h>
22 #include <kripto/hash/sha1.h>
23 #include <kripto/hash/sha2_256.h>
25 int main(void)
27 kripto_mac_desc *desc;
28 uint8_t hash[32];
29 unsigned int i;
31 /* SHA1 */
32 desc = kripto_mac_hmac(kripto_hash_sha1);
33 if(!desc) return -1;
35 puts("de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9");
36 kripto_mac_all(
37 desc, 0,
38 "key", 3,
39 "The quick brown fox jumps over the lazy dog", 43,
40 hash, 20
43 free(desc);
45 for(i = 0; i < 20; i++) printf("%.2x", hash[i]);
46 putchar('\n');
48 /* SHA2_256 */
49 desc = kripto_mac_hmac(kripto_hash_sha2_256);
50 if(!desc) return -1;
52 puts("f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8");
53 kripto_mac_all(
54 desc, 0,
55 "key", 3,
56 "The quick brown fox jumps over the lazy dog", 43,
57 hash, 32
60 free(desc);
62 for(i = 0; i < 32; i++) printf("%.2x", hash[i]);
63 putchar('\n');
65 return 0;