summaryrefslogtreecommitdiff
path: root/nacl/commandline
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-07-02 09:53:34 -0400
committerirungentoo <irungentoo@gmail.com>2013-07-02 09:53:34 -0400
commite2967396ac73cb7410787886cdaf072a184ffc49 (patch)
tree527a74d25a4a0705fc641994fd35bfab22662034 /nacl/commandline
parent8928c817df345f29aa0b194743595aa11bd6a8ba (diff)
Added NaCl crypto library.
Diffstat (limited to 'nacl/commandline')
-rw-r--r--nacl/commandline/nacl-sha256.c64
-rw-r--r--nacl/commandline/nacl-sha512.c64
2 files changed, 128 insertions, 0 deletions
diff --git a/nacl/commandline/nacl-sha256.c b/nacl/commandline/nacl-sha256.c
new file mode 100644
index 00000000..8e0df453
--- /dev/null
+++ b/nacl/commandline/nacl-sha256.c
@@ -0,0 +1,64 @@
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}
diff --git a/nacl/commandline/nacl-sha512.c b/nacl/commandline/nacl-sha512.c
new file mode 100644
index 00000000..6864c76a
--- /dev/null
+++ b/nacl/commandline/nacl-sha512.c
@@ -0,0 +1,64 @@
1/*
2commandline/nacl-sha512.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_sha512.h"
15
16unsigned char *input;
17unsigned long long inputalloc;
18unsigned long long inputlen;
19
20unsigned char h[crypto_hash_sha512_BYTES];
21
22void h_print(void)
23{
24 int i;
25 for (i = 0;i < crypto_hash_sha512_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_sha512(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_sha512(h,input,inputlen);
61 h_print();
62
63 return 0;
64}