]> git.ozlabs.org Git - ccan/blob - ccan/crypto/hmac_sha256/_info
crypto/hmac_sha256: add partial progress functions.
[ccan] / ccan / crypto / hmac_sha256 / _info
1 #include "config.h"
2 #include <stdio.h>
3 #include <string.h>
4
5 /**
6  * crypto/hmac_sha256 - RFC2104 HMAC using SHA256.
7  *
8  * This code implements RFC2104, which is a fairly standard HMAC.
9  *
10  * License: BSD-MIT
11  * Maintainer: Rusty Russell <rusty@rustcorp.com.au>
12  *
13  * Example:
14  *      #include <ccan/crypto/hmac_sha256/hmac_sha256.h>
15  *      #include <err.h>
16  *      #include <stdio.h>
17  *      #include <string.h>
18  *
19  *      // Simple demonstration: idential strings will have the same hash, but
20  *      // two different strings will not.
21  *      int main(int argc, char *argv[])
22  *      {
23  *              struct hmac_sha256 hash1, hash2;
24  *
25  *              if (argc != 3)
26  *                      errx(1, "Usage: %s <string1> <string2>", argv[0]);
27  *
28  *              hmac_sha256(&hash1, "key", 3, argv[1], strlen(argv[1]));
29  *              hmac_sha256(&hash2, "key", 3, argv[2], strlen(argv[2]));
30  *              printf("Hash is %s\n", memcmp(&hash1, &hash2, sizeof(hash1))
31  *                      ? "different" : "same");
32  *              return 0;
33  *      }
34  */
35 int main(int argc, char *argv[])
36 {
37         /* Expect exactly one argument */
38         if (argc != 2)
39                 return 1;
40
41         if (strcmp(argv[1], "depends") == 0) {
42                 printf("ccan/crypto/sha256\n");
43                 return 0;
44         }
45
46         if (strcmp(argv[1], "testdepends") == 0) {
47                 printf("ccan/str/hex\n");
48                 return 0;
49         }
50
51         return 1;
52 }