summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2013-12-07 11:24:01 +1100
committerDamien Miller <djm@mindrot.org>2013-12-07 11:24:01 +1100
commit5be9d9e3cbd9c66f24745d25bf2e809c1d158ee0 (patch)
treed2086d37436014ea44f0f024396a1a8638640b00 /hash.c
parentbcd00abd8451f36142ae2ee10cc657202149201e (diff)
- markus@cvs.openbsd.org 2013/12/06 13:39:49
[authfd.c authfile.c key.c key.h myproposal.h pathnames.h readconf.c] [servconf.c ssh-agent.c ssh-keygen.c ssh-keyscan.1 ssh-keyscan.c] [ssh-keysign.c ssh.c ssh_config.5 sshd.8 sshd.c verify.c ssh-ed25519.c] [sc25519.h sc25519.c hash.c ge25519_base.data ge25519.h ge25519.c] [fe25519.h fe25519.c ed25519.c crypto_api.h blocks.c] support ed25519 keys (hostkeys and user identities) using the public domain ed25519 reference code from SUPERCOP, see http://ed25519.cr.yp.to/software.html feedback, help & ok djm@
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/hash.c b/hash.c
new file mode 100644
index 000000000..3298a0bbc
--- /dev/null
+++ b/hash.c
@@ -0,0 +1,74 @@
1/* $OpenBSD: */
2
3/* Public Domain, from supercop-20130419/crypto_hash/sha512/ref/hash.c */
4
5/*
620080913
7D. J. Bernstein
8Public domain.
9*/
10
11#include "crypto_api.h"
12
13#define blocks crypto_hashblocks_sha512
14
15static const unsigned char iv[64] = {
16 0x6a,0x09,0xe6,0x67,0xf3,0xbc,0xc9,0x08,
17 0xbb,0x67,0xae,0x85,0x84,0xca,0xa7,0x3b,
18 0x3c,0x6e,0xf3,0x72,0xfe,0x94,0xf8,0x2b,
19 0xa5,0x4f,0xf5,0x3a,0x5f,0x1d,0x36,0xf1,
20 0x51,0x0e,0x52,0x7f,0xad,0xe6,0x82,0xd1,
21 0x9b,0x05,0x68,0x8c,0x2b,0x3e,0x6c,0x1f,
22 0x1f,0x83,0xd9,0xab,0xfb,0x41,0xbd,0x6b,
23 0x5b,0xe0,0xcd,0x19,0x13,0x7e,0x21,0x79
24} ;
25
26typedef unsigned long long uint64;
27
28int crypto_hash_sha512(unsigned char *out,const unsigned char *in,unsigned long long inlen)
29{
30 unsigned char h[64];
31 unsigned char padded[256];
32 unsigned int i;
33 unsigned long long bytes = inlen;
34
35 for (i = 0;i < 64;++i) h[i] = iv[i];
36
37 blocks(h,in,inlen);
38 in += inlen;
39 inlen &= 127;
40 in -= inlen;
41
42 for (i = 0;i < inlen;++i) padded[i] = in[i];
43 padded[inlen] = 0x80;
44
45 if (inlen < 112) {
46 for (i = inlen + 1;i < 119;++i) padded[i] = 0;
47 padded[119] = bytes >> 61;
48 padded[120] = bytes >> 53;
49 padded[121] = bytes >> 45;
50 padded[122] = bytes >> 37;
51 padded[123] = bytes >> 29;
52 padded[124] = bytes >> 21;
53 padded[125] = bytes >> 13;
54 padded[126] = bytes >> 5;
55 padded[127] = bytes << 3;
56 blocks(h,padded,128);
57 } else {
58 for (i = inlen + 1;i < 247;++i) padded[i] = 0;
59 padded[247] = bytes >> 61;
60 padded[248] = bytes >> 53;
61 padded[249] = bytes >> 45;
62 padded[250] = bytes >> 37;
63 padded[251] = bytes >> 29;
64 padded[252] = bytes >> 21;
65 padded[253] = bytes >> 13;
66 padded[254] = bytes >> 5;
67 padded[255] = bytes << 3;
68 blocks(h,padded,256);
69 }
70
71 for (i = 0;i < 64;++i) out[i] = h[i];
72
73 return 0;
74}