diff options
author | Darren Tucker <dtucker@dtucker.net> | 2019-07-23 21:51:22 +1000 |
---|---|---|
committer | Darren Tucker <dtucker@dtucker.net> | 2019-07-23 22:06:24 +1000 |
commit | 11cba2a4523fda447e2554ea457484655bedc831 (patch) | |
tree | 93ec07a9e0db784b0a729eb339d74a5a2c40ea9d /openbsd-compat/sha2.c | |
parent | 09159594a3bbd363429ee6fafde57ce77986dd7c (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.
Diffstat (limited to 'openbsd-compat/sha2.c')
-rw-r--r-- | openbsd-compat/sha2.c | 36 |
1 files changed, 35 insertions, 1 deletions
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: */ |
268 | static const u_int32_t sha224_initial_hash_value[8] = { | 276 | static 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 */ |
280 | static const u_int64_t sha384_initial_hash_value[8] = { | 289 | static 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 */ |
292 | static const u_int64_t sha512_256_initial_hash_value[8] = { | 302 | static 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 | } |
337 | DEF_WEAK(SHA224Final); | 347 | DEF_WEAK(SHA224Final); |
338 | #endif /* !defined(SHA2_SMALL) */ | 348 | #endif /* !defined(SHA2_SMALL) */ |
349 | #endif /* 0 */ | ||
339 | 350 | ||
340 | /*** SHA-256: *********************************************************/ | 351 | /*** SHA-256: *********************************************************/ |
341 | void | 352 | void |
@@ -917,6 +928,25 @@ DEF_WEAK(SHA384Transform); | |||
917 | DEF_WEAK(SHA384Update); | 928 | DEF_WEAK(SHA384Update); |
918 | DEF_WEAK(SHA384Pad); | 929 | DEF_WEAK(SHA384Pad); |
919 | 930 | ||
931 | /* Equivalent of MAKE_CLONE (which is a no-op) for SHA384 funcs */ | ||
932 | void | ||
933 | SHA384Transform(u_int64_t state[8], const u_int8_t data[SHA512_BLOCK_LENGTH]) | ||
934 | { | ||
935 | return SHA512Transform(state, data); | ||
936 | } | ||
937 | |||
938 | void | ||
939 | SHA384Update(SHA2_CTX *context, const u_int8_t *data, size_t len) | ||
940 | { | ||
941 | SHA512Update(context, data, len); | ||
942 | } | ||
943 | |||
944 | void | ||
945 | SHA384Pad(SHA2_CTX *context) | ||
946 | { | ||
947 | SHA512Pad(context); | ||
948 | } | ||
949 | |||
920 | void | 950 | void |
921 | SHA384Final(u_int8_t digest[SHA384_DIGEST_LENGTH], SHA2_CTX *context) | 951 | SHA384Final(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 | } |
937 | DEF_WEAK(SHA384Final); | 967 | DEF_WEAK(SHA384Final); |
938 | 968 | ||
969 | #if 0 | ||
939 | /*** SHA-512/256: *********************************************************/ | 970 | /*** SHA-512/256: *********************************************************/ |
940 | void | 971 | void |
941 | SHA512_256Init(SHA2_CTX *context) | 972 | SHA512_256Init(SHA2_CTX *context) |
@@ -973,3 +1004,6 @@ SHA512_256Final(u_int8_t digest[SHA512_256_DIGEST_LENGTH], SHA2_CTX *context) | |||
973 | } | 1004 | } |
974 | DEF_WEAK(SHA512_256Final); | 1005 | DEF_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 */ | ||