summaryrefslogtreecommitdiff
path: root/nacl/commandline/nacl-sha256.c
diff options
context:
space:
mode:
Diffstat (limited to 'nacl/commandline/nacl-sha256.c')
-rw-r--r--nacl/commandline/nacl-sha256.c64
1 files changed, 0 insertions, 64 deletions
diff --git a/nacl/commandline/nacl-sha256.c b/nacl/commandline/nacl-sha256.c
deleted file mode 100644
index 8e0df453..00000000
--- a/nacl/commandline/nacl-sha256.c
+++ /dev/null
@@ -1,64 +0,0 @@
1/*
2commandline/nacl-sha256.c version 20080713
3D. J. Bernstein
4Public domain.
5*/
6
7#include <sys/types.h>
8#include <sys/stat.h>
9#include <sys/mman.h>
10#include <unistd.h>
11#include <string.h>
12#include <stdlib.h>
13#include <stdio.h>
14#include "crypto_hash_sha256.h"
15
16unsigned char *input;
17unsigned long long inputalloc;
18unsigned long long inputlen;
19
20unsigned char h[crypto_hash_sha256_BYTES];
21
22void h_print(void)
23{
24 int i;
25 for (i = 0;i < crypto_hash_sha256_BYTES;++i) printf("%02x",255 & (int) h[i]);
26 printf("\n");
27}
28
29int main()
30{
31 struct stat st;
32 int ch;
33
34 if (fstat(0,&st) == 0) {
35 input = mmap(0,st.st_size,PROT_READ,MAP_SHARED,0,0);
36 if (input != MAP_FAILED) {
37 crypto_hash_sha256(h,input,st.st_size);
38 h_print();
39 return 0;
40 }
41 }
42
43 input = 0;
44 inputalloc = 0;
45 inputlen = 0;
46
47 while ((ch = getchar()) != EOF) {
48 if (inputlen >= inputalloc) {
49 void *newinput;
50 while (inputlen >= inputalloc)
51 inputalloc = inputalloc * 2 + 1;
52 if (posix_memalign(&newinput,16,inputalloc) != 0) return 111;
53 memcpy(newinput,input,inputlen);
54 free(input);
55 input = newinput;
56 }
57 input[inputlen++] = ch;
58 }
59
60 crypto_hash_sha256(h,input,inputlen);
61 h_print();
62
63 return 0;
64}