]> git.ozlabs.org Git - ccan/blob - ccan/crypto/sha256/_info
crypto/sha256: new module.
[ccan] / ccan / crypto / sha256 / _info
1 #include "config.h"
2 #include <stdio.h>
3 #include <string.h>
4
5 /**
6  * crypto/sha256 - implementation of SHA-2 with 256 bit digest.
7  *
8  * This code is either a wrapper for openssl (if CCAN_CRYPTO_SHA256_USE_OPENSSL
9  * is defined) or an open-coded implementation based on Bitcoin's.
10  *
11  * License: BSD-MIT
12  * Maintainer: Rusty Russell <rusty@rustcorp.com.au>
13  *
14  * Example:
15  *      #include <ccan/crypto/sha256/sha256.h>
16  *      #include <err.h>
17  *      #include <stdio.h>
18  *      #include <string.h>
19  *
20  *      // Simple demonstration: idential strings will have the same hash, but
21  *      // two different strings will not.
22  *      int main(int argc, char *argv[])
23  *      {
24  *              struct sha256 hash1, hash2;
25  *
26  *              if (argc != 3)
27  *                      errx(1, "Usage: %s <string1> <string2>", argv[0]);
28  *
29  *              sha256(&hash1, argv[1], strlen(argv[1]));
30  *              sha256(&hash2, argv[2], strlen(argv[2]));
31  *              printf("Hash is %s\n", memcmp(&hash1, &hash2, sizeof(hash1))
32  *                      ? "different" : "same");
33  *              return 0;
34  *      }
35  */
36 int main(int argc, char *argv[])
37 {
38         /* Expect exactly one argument */
39         if (argc != 2)
40                 return 1;
41
42         if (strcmp(argv[1], "depends") == 0) {
43                 printf("ccan/endian\n");
44                 return 0;
45         }
46
47         if (strcmp(argv[1], "libs") == 0) {
48 #ifdef CCAN_CRYPTO_SHA256_USE_OPENSSL
49                 printf("crypto\n");
50 #endif
51                 return 0;
52         }
53
54         return 1;
55 }