diff options
author | Colin Watson <cjwatson@debian.org> | 2018-04-03 08:20:28 +0100 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2018-04-03 08:57:25 +0100 |
commit | a0b2dce9bf518f561bbb5070c0fb0c38f49035dd (patch) | |
tree | 24298b823e93d4e6efe13f48f1512707ebd625f8 /hash.c | |
parent | 9d4942dc192b6f1888c9ab73a512dd9b197b956c (diff) | |
parent | 76aa43d2298f322f0371b74462418d0461537131 (diff) |
New upstream release (7.7p1)
Diffstat (limited to 'hash.c')
-rw-r--r-- | hash.c | 83 |
1 files changed, 17 insertions, 66 deletions
@@ -1,76 +1,27 @@ | |||
1 | /* $OpenBSD: hash.c,v 1.3 2013/12/09 11:03:45 markus Exp $ */ | 1 | /* $OpenBSD: hash.c,v 1.4 2017/12/14 21:07:39 naddy Exp $ */ |
2 | |||
3 | /* Copied from nacl-20110221/crypto_hash/sha512/ref/hash.c */ | ||
4 | 2 | ||
3 | /* $OpenBSD: hash.c,v 1.5 2018/01/13 00:24:09 naddy Exp $ */ | ||
5 | /* | 4 | /* |
6 | 20080913 | 5 | * Public domain. Author: Christian Weisgerber <naddy@openbsd.org> |
7 | D. J. Bernstein | 6 | * API compatible reimplementation of function from nacl |
8 | Public domain. | 7 | */ |
9 | */ | ||
10 | |||
11 | #include "includes.h" | ||
12 | 8 | ||
13 | #include "crypto_api.h" | 9 | #include "crypto_api.h" |
14 | 10 | ||
15 | #define blocks crypto_hashblocks_sha512 | 11 | #include <stdarg.h> |
16 | 12 | ||
17 | static const unsigned char iv[64] = { | 13 | #include "digest.h" |
18 | 0x6a,0x09,0xe6,0x67,0xf3,0xbc,0xc9,0x08, | 14 | #include "log.h" |
19 | 0xbb,0x67,0xae,0x85,0x84,0xca,0xa7,0x3b, | 15 | #include "ssherr.h" |
20 | 0x3c,0x6e,0xf3,0x72,0xfe,0x94,0xf8,0x2b, | ||
21 | 0xa5,0x4f,0xf5,0x3a,0x5f,0x1d,0x36,0xf1, | ||
22 | 0x51,0x0e,0x52,0x7f,0xad,0xe6,0x82,0xd1, | ||
23 | 0x9b,0x05,0x68,0x8c,0x2b,0x3e,0x6c,0x1f, | ||
24 | 0x1f,0x83,0xd9,0xab,0xfb,0x41,0xbd,0x6b, | ||
25 | 0x5b,0xe0,0xcd,0x19,0x13,0x7e,0x21,0x79 | ||
26 | } ; | ||
27 | 16 | ||
28 | typedef unsigned long long uint64; | 17 | int |
29 | 18 | crypto_hash_sha512(unsigned char *out, const unsigned char *in, | |
30 | int crypto_hash_sha512(unsigned char *out,const unsigned char *in,unsigned long long inlen) | 19 | unsigned long long inlen) |
31 | { | 20 | { |
32 | unsigned char h[64]; | 21 | int r; |
33 | unsigned char padded[256]; | ||
34 | unsigned int i; | ||
35 | unsigned long long bytes = inlen; | ||
36 | |||
37 | for (i = 0;i < 64;++i) h[i] = iv[i]; | ||
38 | |||
39 | blocks(h,in,inlen); | ||
40 | in += inlen; | ||
41 | inlen &= 127; | ||
42 | in -= inlen; | ||
43 | |||
44 | for (i = 0;i < inlen;++i) padded[i] = in[i]; | ||
45 | padded[inlen] = 0x80; | ||
46 | |||
47 | if (inlen < 112) { | ||
48 | for (i = inlen + 1;i < 119;++i) padded[i] = 0; | ||
49 | padded[119] = bytes >> 61; | ||
50 | padded[120] = bytes >> 53; | ||
51 | padded[121] = bytes >> 45; | ||
52 | padded[122] = bytes >> 37; | ||
53 | padded[123] = bytes >> 29; | ||
54 | padded[124] = bytes >> 21; | ||
55 | padded[125] = bytes >> 13; | ||
56 | padded[126] = bytes >> 5; | ||
57 | padded[127] = bytes << 3; | ||
58 | blocks(h,padded,128); | ||
59 | } else { | ||
60 | for (i = inlen + 1;i < 247;++i) padded[i] = 0; | ||
61 | padded[247] = bytes >> 61; | ||
62 | padded[248] = bytes >> 53; | ||
63 | padded[249] = bytes >> 45; | ||
64 | padded[250] = bytes >> 37; | ||
65 | padded[251] = bytes >> 29; | ||
66 | padded[252] = bytes >> 21; | ||
67 | padded[253] = bytes >> 13; | ||
68 | padded[254] = bytes >> 5; | ||
69 | padded[255] = bytes << 3; | ||
70 | blocks(h,padded,256); | ||
71 | } | ||
72 | |||
73 | for (i = 0;i < 64;++i) out[i] = h[i]; | ||
74 | 22 | ||
75 | return 0; | 23 | if ((r = ssh_digest_memory(SSH_DIGEST_SHA512, in, inlen, out, |
24 | crypto_hash_sha512_BYTES)) != 0) | ||
25 | fatal("%s: %s", __func__, ssh_err(r)); | ||
26 | return 0; | ||
76 | } | 27 | } |