+ /*
+ * hash stdin
+ */
+ if (ac == 1 || (ac == 2 && !strcmp(av[1], "-"))) {
+ struct sha256_state md;
+ unsigned char buf[4096];
+ size_t bytes;
+ unsigned char tmp[32];
+ int j;
+
+ sha256_init(&md);
+ do {
+ bytes = fread(buf, 1, sizeof buf, stdin);
+ sha256_process(&md, buf, bytes);
+ } while (bytes && !feof(stdin));
+ if (ferror(stdin)) {
+ exit(1);
+ }
+ sha256_done(&md, tmp);
+ for (j=0;j<32;j++) {
+ sprintf(hash+j*2, "%02x", (unsigned)tmp[j]);
+ }
+ hash[64] = 0;
+ printf("%s\n", hash);
+ return 0;
+ }
+