OSDN Git Service

Fix no pic
[uclinux-h8/uClinux-dist.git] / user / netflash / sha256sum.c
1 /*
2  *      sha256sum.c -- simple SHA256 sum code (to get a binary output)
3  */
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <stddef.h>
8 #include <unistd.h>
9 #include <string.h>
10 #include "sha256.h"
11
12 void usage(void)
13 {
14         printf("usage: sha256sum [-hvb]\n");
15 }
16
17 int main(int argc, char *argv[])
18 {
19         struct sha256_ctx ctx;
20         unsigned char buf[64];
21         unsigned char hash[32];
22         int c;
23         int dobinary = 0;
24
25         while ((c = getopt(argc, argv, "?hvb")) > 0) {
26                 switch (c) {
27                 case 'b':
28                         dobinary = 1;
29                         break;
30                 case 'v':
31                         printf("Version: 1.0.0\n");
32                         return 0;
33                 case '?':
34                 case 'h':
35                         usage();
36                         return 0;
37                 default:
38                         usage();
39                         return 1;
40                 }
41         }
42
43         sha256_init_ctx(&ctx);
44         do {
45                 c = fread(buf, 1, 64, stdin);
46                 sha256_process_bytes(buf, c, &ctx);
47         } while (c == 64);
48         sha256_finish_ctx(&ctx, hash);
49
50         if (dobinary) {
51                 fwrite(hash, 1, 32, stdout);
52         } else {
53                 for (c = 0; (c < 32); c++)
54                         printf("%02x", hash[c]);
55                 printf("\n");
56         }
57
58         return 0;
59 }
60