1 /*
2 * Copyright 2014-2022 The GmSSL Project. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the License); you may
5 * not use this file except in compliance with the License.
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 */
9
10
11
12 #include <stdio.h>
13 #include <string.h>
14 #include <stdlib.h>
15 #include <gmssl/digest.h>
16
17 const char *digests[] = {
18 // "md5",
19 "sha1",
20 "sm3",
21 "sha224",
22 "sha256",
23 "sha384",
24 "sha512",
25 "sha512-224",
26 "sha512-256",
27 };
28
main(void)29 int main(void)
30 {
31 uint8_t dgst[64];
32 size_t dgstlen;
33 size_t i, j;
34
35 for (i = 0; i < sizeof(digests)/sizeof(digests[0]); i++) {
36 const DIGEST *algor = digest_from_name(digests[i]);
37 digest(algor, (uint8_t *)"abc", 3, dgst, &dgstlen);
38
39 printf("%s (%zu) ", digests[i], dgstlen);
40 for (j = 0; j < dgstlen; j++) {
41 printf("%02x", dgst[j]);
42 }
43 printf("\n");
44 }
45
46 return 0;
47 }
48