summaryrefslogtreecommitdiff
path: root/openbsd-compat
diff options
context:
space:
mode:
Diffstat (limited to 'openbsd-compat')
-rw-r--r--openbsd-compat/sha2.c36
-rw-r--r--openbsd-compat/sha2.h25
2 files changed, 57 insertions, 4 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: */
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 */