1 /* License: public domain -or- http://www.wtfpl.net/txt/copying/ */
11 static const char hextab
[16] = {
12 '0', '1', '2', '3', '4', '5', '6', '7',
13 '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
15 static char buffer
[READSIZE
];
17 int main(int arc
, char *argv
[])
20 unsigned char md
[SHA256_DIGEST_LENGTH
];
21 char mdhex
[(2*SHA256_DIGEST_LENGTH
)+1];
30 e
= read(STDIN_FILENO
, buffer
, READSIZE
);
32 (errno
== EINTR
|| errno
== EAGAIN
|| errno
== EWOULDBLOCK
));
37 if (!SHA256_Update(&c
, buffer
, (size_t)e
))
40 if (!SHA256_Final(md
, &c
))
42 for (i
=0; i
< SHA256_DIGEST_LENGTH
; ++i
) {
43 unsigned char c
= md
[i
];
44 mdhex
[i
<<1] = hextab
[c
>> 4];
45 mdhex
[(i
<<1)+1] = hextab
[c
& 0xf];
47 mdhex
[2*SHA256_DIGEST_LENGTH
] = '\0';