diff options
Diffstat (limited to 'nacl/crypto_hash/sha256')
-rw-r--r-- | nacl/crypto_hash/sha256/checksum | 1 | ||||
-rw-r--r-- | nacl/crypto_hash/sha256/ref/api.h | 1 | ||||
-rw-r--r-- | nacl/crypto_hash/sha256/ref/hash.c | 69 | ||||
-rw-r--r-- | nacl/crypto_hash/sha256/ref/implementors | 1 | ||||
-rw-r--r-- | nacl/crypto_hash/sha256/used | 0 |
5 files changed, 72 insertions, 0 deletions
diff --git a/nacl/crypto_hash/sha256/checksum b/nacl/crypto_hash/sha256/checksum new file mode 100644 index 00000000..ee52aa30 --- /dev/null +++ b/nacl/crypto_hash/sha256/checksum | |||
@@ -0,0 +1 @@ | |||
86df8bd202b2a2b5fdc04a7f50a591e43a345849c12fef08d487109648a08e05 | |||
diff --git a/nacl/crypto_hash/sha256/ref/api.h b/nacl/crypto_hash/sha256/ref/api.h new file mode 100644 index 00000000..ae8c7f6a --- /dev/null +++ b/nacl/crypto_hash/sha256/ref/api.h | |||
@@ -0,0 +1 @@ | |||
#define CRYPTO_BYTES 32 | |||
diff --git a/nacl/crypto_hash/sha256/ref/hash.c b/nacl/crypto_hash/sha256/ref/hash.c new file mode 100644 index 00000000..21ce68a0 --- /dev/null +++ b/nacl/crypto_hash/sha256/ref/hash.c | |||
@@ -0,0 +1,69 @@ | |||
1 | /* | ||
2 | 20080913 | ||
3 | D. J. Bernstein | ||
4 | Public domain. | ||
5 | */ | ||
6 | |||
7 | #include "crypto_hashblocks_sha256.h" | ||
8 | #include "crypto_hash.h" | ||
9 | |||
10 | #define blocks crypto_hashblocks_sha256 | ||
11 | |||
12 | typedef unsigned int uint32; | ||
13 | |||
14 | static const char iv[32] = { | ||
15 | 0x6a,0x09,0xe6,0x67, | ||
16 | 0xbb,0x67,0xae,0x85, | ||
17 | 0x3c,0x6e,0xf3,0x72, | ||
18 | 0xa5,0x4f,0xf5,0x3a, | ||
19 | 0x51,0x0e,0x52,0x7f, | ||
20 | 0x9b,0x05,0x68,0x8c, | ||
21 | 0x1f,0x83,0xd9,0xab, | ||
22 | 0x5b,0xe0,0xcd,0x19, | ||
23 | } ; | ||
24 | |||
25 | int crypto_hash(unsigned char *out,const unsigned char *in,unsigned long long inlen) | ||
26 | { | ||
27 | unsigned char h[32]; | ||
28 | unsigned char padded[128]; | ||
29 | int i; | ||
30 | unsigned long long bits = inlen << 3; | ||
31 | |||
32 | for (i = 0;i < 32;++i) h[i] = iv[i]; | ||
33 | |||
34 | blocks(h,in,inlen); | ||
35 | in += inlen; | ||
36 | inlen &= 63; | ||
37 | in -= inlen; | ||
38 | |||
39 | for (i = 0;i < inlen;++i) padded[i] = in[i]; | ||
40 | padded[inlen] = 0x80; | ||
41 | |||
42 | if (inlen < 56) { | ||
43 | for (i = inlen + 1;i < 56;++i) padded[i] = 0; | ||
44 | padded[56] = bits >> 56; | ||
45 | padded[57] = bits >> 48; | ||
46 | padded[58] = bits >> 40; | ||
47 | padded[59] = bits >> 32; | ||
48 | padded[60] = bits >> 24; | ||
49 | padded[61] = bits >> 16; | ||
50 | padded[62] = bits >> 8; | ||
51 | padded[63] = bits; | ||
52 | blocks(h,padded,64); | ||
53 | } else { | ||
54 | for (i = inlen + 1;i < 120;++i) padded[i] = 0; | ||
55 | padded[120] = bits >> 56; | ||
56 | padded[121] = bits >> 48; | ||
57 | padded[122] = bits >> 40; | ||
58 | padded[123] = bits >> 32; | ||
59 | padded[124] = bits >> 24; | ||
60 | padded[125] = bits >> 16; | ||
61 | padded[126] = bits >> 8; | ||
62 | padded[127] = bits; | ||
63 | blocks(h,padded,128); | ||
64 | } | ||
65 | |||
66 | for (i = 0;i < 32;++i) out[i] = h[i]; | ||
67 | |||
68 | return 0; | ||
69 | } | ||
diff --git a/nacl/crypto_hash/sha256/ref/implementors b/nacl/crypto_hash/sha256/ref/implementors new file mode 100644 index 00000000..962e7d8e --- /dev/null +++ b/nacl/crypto_hash/sha256/ref/implementors | |||
@@ -0,0 +1 @@ | |||
Daniel J. Bernstein (wrapper around crypto_hashblocks/sha256) | |||
diff --git a/nacl/crypto_hash/sha256/used b/nacl/crypto_hash/sha256/used new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/nacl/crypto_hash/sha256/used | |||