summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@dtucker.net>2019-07-23 21:51:22 +1000
committerDarren Tucker <dtucker@dtucker.net>2019-07-23 22:06:24 +1000
commit11cba2a4523fda447e2554ea457484655bedc831 (patch)
tree93ec07a9e0db784b0a729eb339d74a5a2c40ea9d
parent09159594a3bbd363429ee6fafde57ce77986dd7c (diff)
Re-apply portability changes to current sha2.{c,h}.
Rather than attempt to apply 14 years' worth of changes to OpenBSD's sha2 I imported the current versions directly then re-applied the portability changes. This also allowed re-syncing digest-libc.c against upstream.
-rw-r--r--configure.ac16
-rw-r--r--digest-libc.c28
-rw-r--r--digest-openssl.c8
-rw-r--r--mac.c4
-rw-r--r--openbsd-compat/sha2.c36
-rw-r--r--openbsd-compat/sha2.h25
6 files changed, 85 insertions, 32 deletions
diff --git a/configure.ac b/configure.ac
index 63e017733..1c35b090b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1699,6 +1699,9 @@ AC_CHECK_FUNCS([ \
1699 Blowfish_expandstate \ 1699 Blowfish_expandstate \
1700 Blowfish_expand0state \ 1700 Blowfish_expand0state \
1701 Blowfish_stream2word \ 1701 Blowfish_stream2word \
1702 SHA256Update \
1703 SHA384Update \
1704 SHA512Update \
1702 asprintf \ 1705 asprintf \
1703 b64_ntop \ 1706 b64_ntop \
1704 __b64_ntop \ 1707 __b64_ntop \
@@ -2849,16 +2852,9 @@ if test "x$openssl" = "xyes" ; then
2849 fi 2852 fi
2850 AC_CHECK_FUNCS([crypt DES_crypt]) 2853 AC_CHECK_FUNCS([crypt DES_crypt])
2851 2854
2852 # Search for SHA256 support in libc and/or OpenSSL 2855 # Check for SHA256, SHA384 and SHA512 support in OpenSSL
2853 AC_CHECK_FUNCS([SHA256_Update EVP_sha256], , 2856 AC_CHECK_FUNCS([EVP_sha256 EVP_sha384 EVP_sha512])
2854 [unsupported_algorithms="$unsupported_algorithms \ 2857
2855 hmac-sha2-256 \
2856 hmac-sha2-512 \
2857 diffie-hellman-group-exchange-sha256 \
2858 hmac-sha2-256-etm@openssh.com \
2859 hmac-sha2-512-etm@openssh.com"
2860 ]
2861 )
2862 # Search for RIPE-MD support in OpenSSL 2858 # Search for RIPE-MD support in OpenSSL
2863 AC_CHECK_FUNCS([EVP_ripemd160], , 2859 AC_CHECK_FUNCS([EVP_ripemd160], ,
2864 [unsupported_algorithms="$unsupported_algorithms \ 2860 [unsupported_algorithms="$unsupported_algorithms \
diff --git a/digest-libc.c b/digest-libc.c
index c2b0b2403..12737e5d5 100644
--- a/digest-libc.c
+++ b/digest-libc.c
@@ -28,7 +28,11 @@
28#if 0 28#if 0
29#include <md5.h> 29#include <md5.h>
30#include <rmd160.h> 30#include <rmd160.h>
31#endif
32#ifdef HAVE_SHA1_H
31#include <sha1.h> 33#include <sha1.h>
34#endif
35#ifdef HAVE_SHA2_H
32#include <sha2.h> 36#include <sha2.h>
33#endif 37#endif
34 38
@@ -83,30 +87,30 @@ const struct ssh_digest digests[SSH_DIGEST_MAX] = {
83 "SHA256", 87 "SHA256",
84 SHA256_BLOCK_LENGTH, 88 SHA256_BLOCK_LENGTH,
85 SHA256_DIGEST_LENGTH, 89 SHA256_DIGEST_LENGTH,
86 sizeof(SHA256_CTX), 90 sizeof(SHA2_CTX),
87 (md_init_fn *) SHA256_Init, 91 (md_init_fn *) SHA256Init,
88 (md_update_fn *) SHA256_Update, 92 (md_update_fn *) SHA256Update,
89 (md_final_fn *) SHA256_Final 93 (md_final_fn *) SHA256Final
90 }, 94 },
91 { 95 {
92 SSH_DIGEST_SHA384, 96 SSH_DIGEST_SHA384,
93 "SHA384", 97 "SHA384",
94 SHA384_BLOCK_LENGTH, 98 SHA384_BLOCK_LENGTH,
95 SHA384_DIGEST_LENGTH, 99 SHA384_DIGEST_LENGTH,
96 sizeof(SHA384_CTX), 100 sizeof(SHA2_CTX),
97 (md_init_fn *) SHA384_Init, 101 (md_init_fn *) SHA384Init,
98 (md_update_fn *) SHA384_Update, 102 (md_update_fn *) SHA384Update,
99 (md_final_fn *) SHA384_Final 103 (md_final_fn *) SHA384Final
100 }, 104 },
101 { 105 {
102 SSH_DIGEST_SHA512, 106 SSH_DIGEST_SHA512,
103 "SHA512", 107 "SHA512",
104 SHA512_BLOCK_LENGTH, 108 SHA512_BLOCK_LENGTH,
105 SHA512_DIGEST_LENGTH, 109 SHA512_DIGEST_LENGTH,
106 sizeof(SHA512_CTX), 110 sizeof(SHA2_CTX),
107 (md_init_fn *) SHA512_Init, 111 (md_init_fn *) SHA512Init,
108 (md_update_fn *) SHA512_Update, 112 (md_update_fn *) SHA512Update,
109 (md_final_fn *) SHA512_Final 113 (md_final_fn *) SHA512Final
110 } 114 }
111}; 115};
112 116
diff --git a/digest-openssl.c b/digest-openssl.c
index da7ed72bc..11efbf7c0 100644
--- a/digest-openssl.c
+++ b/digest-openssl.c
@@ -34,12 +34,16 @@
34 34
35#ifndef HAVE_EVP_RIPEMD160 35#ifndef HAVE_EVP_RIPEMD160
36# define EVP_ripemd160 NULL 36# define EVP_ripemd160 NULL
37#endif /* HAVE_EVP_RIPEMD160 */ 37#endif
38#ifndef HAVE_EVP_SHA256 38#ifndef HAVE_EVP_SHA256
39# define EVP_sha256 NULL 39# define EVP_sha256 NULL
40#endif
41#ifndef HAVE_EVP_SHA384
40# define EVP_sha384 NULL 42# define EVP_sha384 NULL
43#endif
44#ifndef HAVE_EVP_SHA512
41# define EVP_sha512 NULL 45# define EVP_sha512 NULL
42#endif /* HAVE_EVP_SHA256 */ 46#endif
43 47
44struct ssh_digest_ctx { 48struct ssh_digest_ctx {
45 int alg; 49 int alg;
diff --git a/mac.c b/mac.c
index 51dc11d76..9a504e892 100644
--- a/mac.c
+++ b/mac.c
@@ -58,10 +58,8 @@ static const struct macalg macs[] = {
58 /* Encrypt-and-MAC (encrypt-and-authenticate) variants */ 58 /* Encrypt-and-MAC (encrypt-and-authenticate) variants */
59 { "hmac-sha1", SSH_DIGEST, SSH_DIGEST_SHA1, 0, 0, 0, 0 }, 59 { "hmac-sha1", SSH_DIGEST, SSH_DIGEST_SHA1, 0, 0, 0, 0 },
60 { "hmac-sha1-96", SSH_DIGEST, SSH_DIGEST_SHA1, 96, 0, 0, 0 }, 60 { "hmac-sha1-96", SSH_DIGEST, SSH_DIGEST_SHA1, 96, 0, 0, 0 },
61#ifdef HAVE_EVP_SHA256
62 { "hmac-sha2-256", SSH_DIGEST, SSH_DIGEST_SHA256, 0, 0, 0, 0 }, 61 { "hmac-sha2-256", SSH_DIGEST, SSH_DIGEST_SHA256, 0, 0, 0, 0 },
63 { "hmac-sha2-512", SSH_DIGEST, SSH_DIGEST_SHA512, 0, 0, 0, 0 }, 62 { "hmac-sha2-512", SSH_DIGEST, SSH_DIGEST_SHA512, 0, 0, 0, 0 },
64#endif
65 { "hmac-md5", SSH_DIGEST, SSH_DIGEST_MD5, 0, 0, 0, 0 }, 63 { "hmac-md5", SSH_DIGEST, SSH_DIGEST_MD5, 0, 0, 0, 0 },
66 { "hmac-md5-96", SSH_DIGEST, SSH_DIGEST_MD5, 96, 0, 0, 0 }, 64 { "hmac-md5-96", SSH_DIGEST, SSH_DIGEST_MD5, 96, 0, 0, 0 },
67 { "umac-64@openssh.com", SSH_UMAC, 0, 0, 128, 64, 0 }, 65 { "umac-64@openssh.com", SSH_UMAC, 0, 0, 128, 64, 0 },
@@ -70,10 +68,8 @@ static const struct macalg macs[] = {
70 /* Encrypt-then-MAC variants */ 68 /* Encrypt-then-MAC variants */
71 { "hmac-sha1-etm@openssh.com", SSH_DIGEST, SSH_DIGEST_SHA1, 0, 0, 0, 1 }, 69 { "hmac-sha1-etm@openssh.com", SSH_DIGEST, SSH_DIGEST_SHA1, 0, 0, 0, 1 },
72 { "hmac-sha1-96-etm@openssh.com", SSH_DIGEST, SSH_DIGEST_SHA1, 96, 0, 0, 1 }, 70 { "hmac-sha1-96-etm@openssh.com", SSH_DIGEST, SSH_DIGEST_SHA1, 96, 0, 0, 1 },
73#ifdef HAVE_EVP_SHA256
74 { "hmac-sha2-256-etm@openssh.com", SSH_DIGEST, SSH_DIGEST_SHA256, 0, 0, 0, 1 }, 71 { "hmac-sha2-256-etm@openssh.com", SSH_DIGEST, SSH_DIGEST_SHA256, 0, 0, 0, 1 },
75 { "hmac-sha2-512-etm@openssh.com", SSH_DIGEST, SSH_DIGEST_SHA512, 0, 0, 0, 1 }, 72 { "hmac-sha2-512-etm@openssh.com", SSH_DIGEST, SSH_DIGEST_SHA512, 0, 0, 0, 1 },
76#endif
77 { "hmac-md5-etm@openssh.com", SSH_DIGEST, SSH_DIGEST_MD5, 0, 0, 0, 1 }, 73 { "hmac-md5-etm@openssh.com", SSH_DIGEST, SSH_DIGEST_MD5, 0, 0, 0, 1 },
78 { "hmac-md5-96-etm@openssh.com", SSH_DIGEST, SSH_DIGEST_MD5, 96, 0, 0, 1 }, 74 { "hmac-md5-96-etm@openssh.com", SSH_DIGEST, SSH_DIGEST_MD5, 96, 0, 0, 1 },
79 { "umac-64-etm@openssh.com", SSH_UMAC, 0, 0, 128, 64, 1 }, 75 { "umac-64-etm@openssh.com", SSH_UMAC, 0, 0, 128, 64, 1 },
diff --git a/openbsd-compat/sha2.c b/openbsd-compat/sha2.c
index f16cf9cd0..eca0644c6 100644
--- a/openbsd-compat/sha2.c
+++ b/openbsd-compat/sha2.c
@@ -34,7 +34,14 @@
34 * $From: sha2.c,v 1.1 2001/11/08 00:01:51 adg Exp adg $ 34 * $From: sha2.c,v 1.1 2001/11/08 00:01:51 adg Exp adg $
35 */ 35 */
36 36
37#include <sys/types.h> 37/* OPENBSD ORIGINAL: lib/libc/hash/sha2.c */
38
39#include "includes.h"
40
41#if !defined(HAVE_SHA256UPDATE) || !defined(HAVE_SHA384UPDATE) || \
42 !defined(HAVE_SHA512UPDATE)
43
44#define MAKE_CLONE(x, y) /* no-op out */
38 45
39#include <string.h> 46#include <string.h>
40#include <sha2.h> 47#include <sha2.h>
@@ -264,6 +271,7 @@ static const u_int64_t sha512_initial_hash_value[8] = {
264}; 271};
265 272
266#if !defined(SHA2_SMALL) 273#if !defined(SHA2_SMALL)
274#if 0
267/* Initial hash value H for SHA-224: */ 275/* Initial hash value H for SHA-224: */
268static const u_int32_t sha224_initial_hash_value[8] = { 276static const u_int32_t sha224_initial_hash_value[8] = {
269 0xc1059ed8UL, 277 0xc1059ed8UL,
@@ -275,6 +283,7 @@ static const u_int32_t sha224_initial_hash_value[8] = {
275 0x64f98fa7UL, 283 0x64f98fa7UL,
276 0xbefa4fa4UL 284 0xbefa4fa4UL
277}; 285};
286#endif /* 0 */
278 287
279/* Initial hash value H for SHA-384 */ 288/* Initial hash value H for SHA-384 */
280static const u_int64_t sha384_initial_hash_value[8] = { 289static const u_int64_t sha384_initial_hash_value[8] = {
@@ -288,6 +297,7 @@ static const u_int64_t sha384_initial_hash_value[8] = {
288 0x47b5481dbefa4fa4ULL 297 0x47b5481dbefa4fa4ULL
289}; 298};
290 299
300#if 0
291/* Initial hash value H for SHA-512-256 */ 301/* Initial hash value H for SHA-512-256 */
292static const u_int64_t sha512_256_initial_hash_value[8] = { 302static const u_int64_t sha512_256_initial_hash_value[8] = {
293 0x22312194fc2bf72cULL, 303 0x22312194fc2bf72cULL,
@@ -336,6 +346,7 @@ SHA224Final(u_int8_t digest[SHA224_DIGEST_LENGTH], SHA2_CTX *context)
336} 346}
337DEF_WEAK(SHA224Final); 347DEF_WEAK(SHA224Final);
338#endif /* !defined(SHA2_SMALL) */ 348#endif /* !defined(SHA2_SMALL) */
349#endif /* 0 */
339 350
340/*** SHA-256: *********************************************************/ 351/*** SHA-256: *********************************************************/
341void 352void
@@ -917,6 +928,25 @@ DEF_WEAK(SHA384Transform);
917DEF_WEAK(SHA384Update); 928DEF_WEAK(SHA384Update);
918DEF_WEAK(SHA384Pad); 929DEF_WEAK(SHA384Pad);
919 930
931/* Equivalent of MAKE_CLONE (which is a no-op) for SHA384 funcs */
932void
933SHA384Transform(u_int64_t state[8], const u_int8_t data[SHA512_BLOCK_LENGTH])
934{
935 return SHA512Transform(state, data);
936}
937
938void
939SHA384Update(SHA2_CTX *context, const u_int8_t *data, size_t len)
940{
941 SHA512Update(context, data, len);
942}
943
944void
945SHA384Pad(SHA2_CTX *context)
946{
947 SHA512Pad(context);
948}
949
920void 950void
921SHA384Final(u_int8_t digest[SHA384_DIGEST_LENGTH], SHA2_CTX *context) 951SHA384Final(u_int8_t digest[SHA384_DIGEST_LENGTH], SHA2_CTX *context)
922{ 952{
@@ -936,6 +966,7 @@ SHA384Final(u_int8_t digest[SHA384_DIGEST_LENGTH], SHA2_CTX *context)
936} 966}
937DEF_WEAK(SHA384Final); 967DEF_WEAK(SHA384Final);
938 968
969#if 0
939/*** SHA-512/256: *********************************************************/ 970/*** SHA-512/256: *********************************************************/
940void 971void
941SHA512_256Init(SHA2_CTX *context) 972SHA512_256Init(SHA2_CTX *context)
@@ -973,3 +1004,6 @@ SHA512_256Final(u_int8_t digest[SHA512_256_DIGEST_LENGTH], SHA2_CTX *context)
973} 1004}
974DEF_WEAK(SHA512_256Final); 1005DEF_WEAK(SHA512_256Final);
975#endif /* !defined(SHA2_SMALL) */ 1006#endif /* !defined(SHA2_SMALL) */
1007#endif /* 0 */
1008
1009#endif /* HAVE_SHA{256,384,512}UPDATE */
diff --git a/openbsd-compat/sha2.h b/openbsd-compat/sha2.h
index 52ddb3f79..bf7dafc52 100644
--- a/openbsd-compat/sha2.h
+++ b/openbsd-compat/sha2.h
@@ -34,9 +34,16 @@
34 * $From: sha2.h,v 1.1 2001/11/08 00:02:01 adg Exp adg $ 34 * $From: sha2.h,v 1.1 2001/11/08 00:02:01 adg Exp adg $
35 */ 35 */
36 36
37#ifndef _SHA2_H 37/* OPENBSD ORIGINAL: include/sha2.h */
38#define _SHA2_H
39 38
39#ifndef _SSHSHA2_H
40#define _SSHSHA2_H
41
42#include "includes.h"
43#include <sys/cdefs.h>
44
45#if !defined(HAVE_SHA256UPDATE) || !defined(HAVE_SHA384UPDATE) || \
46 !defined(HAVE_SHA512UPDATE)
40 47
41/*** SHA-256/384/512 Various Length Definitions ***********************/ 48/*** SHA-256/384/512 Various Length Definitions ***********************/
42#define SHA224_BLOCK_LENGTH 64 49#define SHA224_BLOCK_LENGTH 64
@@ -66,6 +73,7 @@ typedef struct _SHA2_CTX {
66 u_int8_t buffer[SHA512_BLOCK_LENGTH]; 73 u_int8_t buffer[SHA512_BLOCK_LENGTH];
67} SHA2_CTX; 74} SHA2_CTX;
68 75
76#if 0
69__BEGIN_DECLS 77__BEGIN_DECLS
70void SHA224Init(SHA2_CTX *); 78void SHA224Init(SHA2_CTX *);
71void SHA224Transform(u_int32_t state[8], const u_int8_t [SHA224_BLOCK_LENGTH]); 79void SHA224Transform(u_int32_t state[8], const u_int8_t [SHA224_BLOCK_LENGTH]);
@@ -83,7 +91,9 @@ char *SHA224FileChunk(const char *, char *, off_t, off_t)
83char *SHA224Data(const u_int8_t *, size_t, char *) 91char *SHA224Data(const u_int8_t *, size_t, char *)
84 __attribute__((__bounded__(__string__,1,2))) 92 __attribute__((__bounded__(__string__,1,2)))
85 __attribute__((__bounded__(__minbytes__,3,SHA224_DIGEST_STRING_LENGTH))); 93 __attribute__((__bounded__(__minbytes__,3,SHA224_DIGEST_STRING_LENGTH)));
94#endif /* 0 */
86 95
96#ifndef HAVE_SHA256UPDATE
87void SHA256Init(SHA2_CTX *); 97void SHA256Init(SHA2_CTX *);
88void SHA256Transform(u_int32_t state[8], const u_int8_t [SHA256_BLOCK_LENGTH]); 98void SHA256Transform(u_int32_t state[8], const u_int8_t [SHA256_BLOCK_LENGTH]);
89void SHA256Update(SHA2_CTX *, const u_int8_t *, size_t) 99void SHA256Update(SHA2_CTX *, const u_int8_t *, size_t)
@@ -100,7 +110,9 @@ char *SHA256FileChunk(const char *, char *, off_t, off_t)
100char *SHA256Data(const u_int8_t *, size_t, char *) 110char *SHA256Data(const u_int8_t *, size_t, char *)
101 __attribute__((__bounded__(__string__,1,2))) 111 __attribute__((__bounded__(__string__,1,2)))
102 __attribute__((__bounded__(__minbytes__,3,SHA256_DIGEST_STRING_LENGTH))); 112 __attribute__((__bounded__(__minbytes__,3,SHA256_DIGEST_STRING_LENGTH)));
113#endif /* HAVE_SHA256UPDATE */
103 114
115#ifndef HAVE_SHA384UPDATE
104void SHA384Init(SHA2_CTX *); 116void SHA384Init(SHA2_CTX *);
105void SHA384Transform(u_int64_t state[8], const u_int8_t [SHA384_BLOCK_LENGTH]); 117void SHA384Transform(u_int64_t state[8], const u_int8_t [SHA384_BLOCK_LENGTH]);
106void SHA384Update(SHA2_CTX *, const u_int8_t *, size_t) 118void SHA384Update(SHA2_CTX *, const u_int8_t *, size_t)
@@ -117,7 +129,9 @@ char *SHA384FileChunk(const char *, char *, off_t, off_t)
117char *SHA384Data(const u_int8_t *, size_t, char *) 129char *SHA384Data(const u_int8_t *, size_t, char *)
118 __attribute__((__bounded__(__string__,1,2))) 130 __attribute__((__bounded__(__string__,1,2)))
119 __attribute__((__bounded__(__minbytes__,3,SHA384_DIGEST_STRING_LENGTH))); 131 __attribute__((__bounded__(__minbytes__,3,SHA384_DIGEST_STRING_LENGTH)));
132#endif /* HAVE_SHA384UPDATE */
120 133
134#ifndef HAVE_SHA512UPDATE
121void SHA512Init(SHA2_CTX *); 135void SHA512Init(SHA2_CTX *);
122void SHA512Transform(u_int64_t state[8], const u_int8_t [SHA512_BLOCK_LENGTH]); 136void SHA512Transform(u_int64_t state[8], const u_int8_t [SHA512_BLOCK_LENGTH]);
123void SHA512Update(SHA2_CTX *, const u_int8_t *, size_t) 137void SHA512Update(SHA2_CTX *, const u_int8_t *, size_t)
@@ -134,7 +148,9 @@ char *SHA512FileChunk(const char *, char *, off_t, off_t)
134char *SHA512Data(const u_int8_t *, size_t, char *) 148char *SHA512Data(const u_int8_t *, size_t, char *)
135 __attribute__((__bounded__(__string__,1,2))) 149 __attribute__((__bounded__(__string__,1,2)))
136 __attribute__((__bounded__(__minbytes__,3,SHA512_DIGEST_STRING_LENGTH))); 150 __attribute__((__bounded__(__minbytes__,3,SHA512_DIGEST_STRING_LENGTH)));
151#endif /* HAVE_SHA512UPDATE */
137 152
153#if 0
138void SHA512_256Init(SHA2_CTX *); 154void SHA512_256Init(SHA2_CTX *);
139void SHA512_256Transform(u_int64_t state[8], const u_int8_t [SHA512_256_BLOCK_LENGTH]); 155void SHA512_256Transform(u_int64_t state[8], const u_int8_t [SHA512_256_BLOCK_LENGTH]);
140void SHA512_256Update(SHA2_CTX *, const u_int8_t *, size_t) 156void SHA512_256Update(SHA2_CTX *, const u_int8_t *, size_t)
@@ -152,5 +168,8 @@ char *SHA512_256Data(const u_int8_t *, size_t, char *)
152 __attribute__((__bounded__(__string__,1,2))) 168 __attribute__((__bounded__(__string__,1,2)))
153 __attribute__((__bounded__(__minbytes__,3,SHA512_256_DIGEST_STRING_LENGTH))); 169 __attribute__((__bounded__(__minbytes__,3,SHA512_256_DIGEST_STRING_LENGTH)));
154__END_DECLS 170__END_DECLS
171#endif /* 0 */
172
173#endif /* HAVE_SHA{256,384,512}UPDATE */
155 174
156#endif /* _SHA2_H */ 175#endif /* _SSHSHA2_H */