summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2024-06-01 07:36:17 +0000
committertb <>2024-06-01 07:36:17 +0000
commitf3bc6c83f92ef9b23bfc523ef1b24bfa27e1f6e4 (patch)
treed92a9fa364845580193b9ab3f5f391408342fa26
parentaee2754cfbb89d3dff4c3a521fb027d0c6967bc9 (diff)
downloadopenbsd-f3bc6c83f92ef9b23bfc523ef1b24bfa27e1f6e4.tar.gz
openbsd-f3bc6c83f92ef9b23bfc523ef1b24bfa27e1f6e4.tar.bz2
openbsd-f3bc6c83f92ef9b23bfc523ef1b24bfa27e1f6e4.zip
Remove support for static buffers in HMAC/digests
HMAC() and the one-step digests used to support passing a NULL buffer and would return the digest in a static buffer. This design is firmly from the nineties, not thread safe and it saves callers a single line. The few ports that used to rely this were fixed with patches sent to non-hostile (and non-dead) upstreams. It's early enough in the release cycle that remaining uses hidden from the compiler should be caught, at least the ones that matter. There won't be that many since BoringSSL removed this feature in 2017. https://boringssl-review.googlesource.com/14528 Add non-null attributes to the headers and add a few missing bounded attributes. ok beck jsing
-rw-r--r--src/lib/libcrypto/hmac/hmac.c5
-rw-r--r--src/lib/libcrypto/hmac/hmac.h5
-rw-r--r--src/lib/libcrypto/md4/md4.c5
-rw-r--r--src/lib/libcrypto/md4/md4.h5
-rw-r--r--src/lib/libcrypto/md5/md5.c5
-rw-r--r--src/lib/libcrypto/md5/md5.h3
-rw-r--r--src/lib/libcrypto/ripemd/ripemd.c8
-rw-r--r--src/lib/libcrypto/ripemd/ripemd.h7
-rw-r--r--src/lib/libcrypto/sha/sha.h7
-rw-r--r--src/lib/libcrypto/sha/sha1.c6
-rw-r--r--src/lib/libcrypto/sha/sha256.c10
-rw-r--r--src/lib/libcrypto/sha/sha512.c10
-rw-r--r--src/lib/libcrypto/whrlpool/whirlpool.c5
-rw-r--r--src/lib/libcrypto/whrlpool/whrlpool.h9
14 files changed, 35 insertions, 55 deletions
diff --git a/src/lib/libcrypto/hmac/hmac.c b/src/lib/libcrypto/hmac/hmac.c
index 7c882ba15b..1315b1a0d2 100644
--- a/src/lib/libcrypto/hmac/hmac.c
+++ b/src/lib/libcrypto/hmac/hmac.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: hmac.c,v 1.34 2024/03/30 10:10:58 tb Exp $ */ 1/* $OpenBSD: hmac.c,v 1.35 2024/06/01 07:36:16 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -263,11 +263,8 @@ HMAC(const EVP_MD *evp_md, const void *key, int key_len, const unsigned char *d,
263 size_t n, unsigned char *md, unsigned int *md_len) 263 size_t n, unsigned char *md, unsigned int *md_len)
264{ 264{
265 HMAC_CTX c; 265 HMAC_CTX c;
266 static unsigned char m[EVP_MAX_MD_SIZE];
267 const unsigned char dummy_key[1] = { 0 }; 266 const unsigned char dummy_key[1] = { 0 };
268 267
269 if (md == NULL)
270 md = m;
271 if (key == NULL) { 268 if (key == NULL) {
272 key = dummy_key; 269 key = dummy_key;
273 key_len = 0; 270 key_len = 0;
diff --git a/src/lib/libcrypto/hmac/hmac.h b/src/lib/libcrypto/hmac/hmac.h
index 1ce365294c..abdd19450e 100644
--- a/src/lib/libcrypto/hmac/hmac.h
+++ b/src/lib/libcrypto/hmac/hmac.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: hmac.h,v 1.17 2023/04/25 15:48:48 tb Exp $ */ 1/* $OpenBSD: hmac.h,v 1.18 2024/06/01 07:36:16 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -85,7 +85,8 @@ int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, const EVP_MD *md,
85int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, size_t len); 85int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, size_t len);
86int HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len); 86int HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len);
87unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len, 87unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,
88 const unsigned char *d, size_t n, unsigned char *md, unsigned int *md_len); 88 const unsigned char *d, size_t n, unsigned char *md, unsigned int *md_len)
89 __attribute__((__nonnull__ (6)));
89int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx); 90int HMAC_CTX_copy(HMAC_CTX *dctx, HMAC_CTX *sctx);
90 91
91void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags); 92void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags);
diff --git a/src/lib/libcrypto/md4/md4.c b/src/lib/libcrypto/md4/md4.c
index 42c5b21428..9cf1ff9532 100644
--- a/src/lib/libcrypto/md4/md4.c
+++ b/src/lib/libcrypto/md4/md4.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: md4.c,v 1.17 2024/03/28 08:00:07 jsing Exp $ */ 1/* $OpenBSD: md4.c,v 1.18 2024/06/01 07:36:16 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -336,10 +336,7 @@ unsigned char *
336MD4(const unsigned char *d, size_t n, unsigned char *md) 336MD4(const unsigned char *d, size_t n, unsigned char *md)
337{ 337{
338 MD4_CTX c; 338 MD4_CTX c;
339 static unsigned char m[MD4_DIGEST_LENGTH];
340 339
341 if (md == NULL)
342 md = m;
343 if (!MD4_Init(&c)) 340 if (!MD4_Init(&c))
344 return NULL; 341 return NULL;
345 MD4_Update(&c, d, n); 342 MD4_Update(&c, d, n);
diff --git a/src/lib/libcrypto/md4/md4.h b/src/lib/libcrypto/md4/md4.h
index cb4f3cb6e9..bf4313b345 100644
--- a/src/lib/libcrypto/md4/md4.h
+++ b/src/lib/libcrypto/md4/md4.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: md4.h,v 1.17 2023/07/08 06:47:26 jsing Exp $ */ 1/* $OpenBSD: md4.h,v 1.18 2024/06/01 07:36:16 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -92,8 +92,11 @@ typedef struct MD4state_st {
92 92
93int MD4_Init(MD4_CTX *c); 93int MD4_Init(MD4_CTX *c);
94int MD4_Update(MD4_CTX *c, const void *data, size_t len); 94int MD4_Update(MD4_CTX *c, const void *data, size_t len);
95 __attribute__ ((__bounded__(__buffer__, 2, 3)));
95int MD4_Final(unsigned char *md, MD4_CTX *c); 96int MD4_Final(unsigned char *md, MD4_CTX *c);
96unsigned char *MD4(const unsigned char *d, size_t n, unsigned char *md); 97unsigned char *MD4(const unsigned char *d, size_t n, unsigned char *md);
98 __attribute__ ((__nonnull__(3)))
99 __attribute__ ((__bounded__(__buffer__, 1, 2)));
97void MD4_Transform(MD4_CTX *c, const unsigned char *b); 100void MD4_Transform(MD4_CTX *c, const unsigned char *b);
98#ifdef __cplusplus 101#ifdef __cplusplus
99} 102}
diff --git a/src/lib/libcrypto/md5/md5.c b/src/lib/libcrypto/md5/md5.c
index 35d1ac9144..744c66f005 100644
--- a/src/lib/libcrypto/md5/md5.c
+++ b/src/lib/libcrypto/md5/md5.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: md5.c,v 1.22 2024/03/28 08:00:08 jsing Exp $ */ 1/* $OpenBSD: md5.c,v 1.23 2024/06/01 07:36:16 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -371,10 +371,7 @@ unsigned char *
371MD5(const unsigned char *d, size_t n, unsigned char *md) 371MD5(const unsigned char *d, size_t n, unsigned char *md)
372{ 372{
373 MD5_CTX c; 373 MD5_CTX c;
374 static unsigned char m[MD5_DIGEST_LENGTH];
375 374
376 if (md == NULL)
377 md = m;
378 if (!MD5_Init(&c)) 375 if (!MD5_Init(&c))
379 return NULL; 376 return NULL;
380 MD5_Update(&c, d, n); 377 MD5_Update(&c, d, n);
diff --git a/src/lib/libcrypto/md5/md5.h b/src/lib/libcrypto/md5/md5.h
index d248c93a85..9191ff2131 100644
--- a/src/lib/libcrypto/md5/md5.h
+++ b/src/lib/libcrypto/md5/md5.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: md5.h,v 1.21 2023/07/08 06:50:38 jsing Exp $ */ 1/* $OpenBSD: md5.h,v 1.22 2024/06/01 07:36:16 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -98,6 +98,7 @@ int MD5_Update(MD5_CTX *c, const void *data, size_t len)
98 __attribute__ ((__bounded__(__buffer__, 2, 3))); 98 __attribute__ ((__bounded__(__buffer__, 2, 3)));
99int MD5_Final(unsigned char *md, MD5_CTX *c); 99int MD5_Final(unsigned char *md, MD5_CTX *c);
100unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md) 100unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md)
101 __attribute__ ((__nonnull__(3)))
101 __attribute__ ((__bounded__(__buffer__, 1, 2))); 102 __attribute__ ((__bounded__(__buffer__, 1, 2)));
102void MD5_Transform(MD5_CTX *c, const unsigned char *b); 103void MD5_Transform(MD5_CTX *c, const unsigned char *b);
103#ifdef __cplusplus 104#ifdef __cplusplus
diff --git a/src/lib/libcrypto/ripemd/ripemd.c b/src/lib/libcrypto/ripemd/ripemd.c
index b2d798c495..08fa208dcc 100644
--- a/src/lib/libcrypto/ripemd/ripemd.c
+++ b/src/lib/libcrypto/ripemd/ripemd.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ripemd.c,v 1.18 2024/03/28 23:54:15 joshua Exp $ */ 1/* $OpenBSD: ripemd.c,v 1.19 2024/06/01 07:36:16 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -483,14 +483,10 @@ RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c)
483LCRYPTO_ALIAS(RIPEMD160_Final); 483LCRYPTO_ALIAS(RIPEMD160_Final);
484 484
485unsigned char * 485unsigned char *
486RIPEMD160(const unsigned char *d, size_t n, 486RIPEMD160(const unsigned char *d, size_t n, unsigned char *md)
487 unsigned char *md)
488{ 487{
489 RIPEMD160_CTX c; 488 RIPEMD160_CTX c;
490 static unsigned char m[RIPEMD160_DIGEST_LENGTH];
491 489
492 if (md == NULL)
493 md = m;
494 if (!RIPEMD160_Init(&c)) 490 if (!RIPEMD160_Init(&c))
495 return NULL; 491 return NULL;
496 RIPEMD160_Update(&c, d, n); 492 RIPEMD160_Update(&c, d, n);
diff --git a/src/lib/libcrypto/ripemd/ripemd.h b/src/lib/libcrypto/ripemd/ripemd.h
index 03ba781c4f..5925083c0c 100644
--- a/src/lib/libcrypto/ripemd/ripemd.h
+++ b/src/lib/libcrypto/ripemd/ripemd.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: ripemd.h,v 1.15 2023/07/08 06:52:56 jsing Exp $ */ 1/* $OpenBSD: ripemd.h,v 1.16 2024/06/01 07:36:16 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -93,9 +93,12 @@ typedef struct RIPEMD160state_st {
93 93
94int RIPEMD160_Init(RIPEMD160_CTX *c); 94int RIPEMD160_Init(RIPEMD160_CTX *c);
95int RIPEMD160_Update(RIPEMD160_CTX *c, const void *data, size_t len); 95int RIPEMD160_Update(RIPEMD160_CTX *c, const void *data, size_t len);
96 __attribute__ ((__bounded__(__buffer__, 2, 3)));
96int RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c); 97int RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c);
97unsigned char *RIPEMD160(const unsigned char *d, size_t n, 98unsigned char *RIPEMD160(const unsigned char *d, size_t n,
98 unsigned char *md); 99 unsigned char *md)
100 __attribute__ ((__nonnull__(3)))
101 __attribute__ ((__bounded__(__buffer__, 1, 2)));
99void RIPEMD160_Transform(RIPEMD160_CTX *c, const unsigned char *b); 102void RIPEMD160_Transform(RIPEMD160_CTX *c, const unsigned char *b);
100#ifdef __cplusplus 103#ifdef __cplusplus
101} 104}
diff --git a/src/lib/libcrypto/sha/sha.h b/src/lib/libcrypto/sha/sha.h
index e1de79f4f4..f87203d912 100644
--- a/src/lib/libcrypto/sha/sha.h
+++ b/src/lib/libcrypto/sha/sha.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: sha.h,v 1.22 2023/07/08 07:08:11 jsing Exp $ */ 1/* $OpenBSD: sha.h,v 1.23 2024/06/01 07:36:16 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -102,6 +102,7 @@ int SHA1_Update(SHA_CTX *c, const void *data, size_t len)
102 __attribute__ ((__bounded__(__buffer__, 2, 3))); 102 __attribute__ ((__bounded__(__buffer__, 2, 3)));
103int SHA1_Final(unsigned char *md, SHA_CTX *c); 103int SHA1_Final(unsigned char *md, SHA_CTX *c);
104unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md) 104unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md)
105 __attribute__ ((__nonnull__(3)))
105 __attribute__ ((__bounded__(__buffer__, 1, 2))); 106 __attribute__ ((__bounded__(__buffer__, 1, 2)));
106void SHA1_Transform(SHA_CTX *c, const unsigned char *data); 107void SHA1_Transform(SHA_CTX *c, const unsigned char *data);
107#endif 108#endif
@@ -125,12 +126,14 @@ int SHA224_Update(SHA256_CTX *c, const void *data, size_t len)
125 __attribute__ ((__bounded__(__buffer__, 2, 3))); 126 __attribute__ ((__bounded__(__buffer__, 2, 3)));
126int SHA224_Final(unsigned char *md, SHA256_CTX *c); 127int SHA224_Final(unsigned char *md, SHA256_CTX *c);
127unsigned char *SHA224(const unsigned char *d, size_t n, unsigned char *md) 128unsigned char *SHA224(const unsigned char *d, size_t n, unsigned char *md)
129 __attribute__ ((__nonnull__(3)))
128 __attribute__ ((__bounded__(__buffer__, 1, 2))); 130 __attribute__ ((__bounded__(__buffer__, 1, 2)));
129int SHA256_Init(SHA256_CTX *c); 131int SHA256_Init(SHA256_CTX *c);
130int SHA256_Update(SHA256_CTX *c, const void *data, size_t len) 132int SHA256_Update(SHA256_CTX *c, const void *data, size_t len)
131 __attribute__ ((__bounded__(__buffer__, 2, 3))); 133 __attribute__ ((__bounded__(__buffer__, 2, 3)));
132int SHA256_Final(unsigned char *md, SHA256_CTX *c); 134int SHA256_Final(unsigned char *md, SHA256_CTX *c);
133unsigned char *SHA256(const unsigned char *d, size_t n, unsigned char *md) 135unsigned char *SHA256(const unsigned char *d, size_t n, unsigned char *md)
136 __attribute__ ((__nonnull__(3)))
134 __attribute__ ((__bounded__(__buffer__, 1, 2))); 137 __attribute__ ((__bounded__(__buffer__, 1, 2)));
135void SHA256_Transform(SHA256_CTX *c, const unsigned char *data); 138void SHA256_Transform(SHA256_CTX *c, const unsigned char *data);
136#endif 139#endif
@@ -172,12 +175,14 @@ int SHA384_Update(SHA512_CTX *c, const void *data, size_t len)
172 __attribute__ ((__bounded__(__buffer__, 2, 3))); 175 __attribute__ ((__bounded__(__buffer__, 2, 3)));
173int SHA384_Final(unsigned char *md, SHA512_CTX *c); 176int SHA384_Final(unsigned char *md, SHA512_CTX *c);
174unsigned char *SHA384(const unsigned char *d, size_t n, unsigned char *md) 177unsigned char *SHA384(const unsigned char *d, size_t n, unsigned char *md)
178 __attribute__ ((__nonnull__(3)))
175 __attribute__ ((__bounded__(__buffer__, 1, 2))); 179 __attribute__ ((__bounded__(__buffer__, 1, 2)));
176int SHA512_Init(SHA512_CTX *c); 180int SHA512_Init(SHA512_CTX *c);
177int SHA512_Update(SHA512_CTX *c, const void *data, size_t len) 181int SHA512_Update(SHA512_CTX *c, const void *data, size_t len)
178 __attribute__ ((__bounded__(__buffer__, 2, 3))); 182 __attribute__ ((__bounded__(__buffer__, 2, 3)));
179int SHA512_Final(unsigned char *md, SHA512_CTX *c); 183int SHA512_Final(unsigned char *md, SHA512_CTX *c);
180unsigned char *SHA512(const unsigned char *d, size_t n, unsigned char *md) 184unsigned char *SHA512(const unsigned char *d, size_t n, unsigned char *md)
185 __attribute__ ((__nonnull__(3)))
181 __attribute__ ((__bounded__(__buffer__, 1, 2))); 186 __attribute__ ((__bounded__(__buffer__, 1, 2)));
182void SHA512_Transform(SHA512_CTX *c, const unsigned char *data); 187void SHA512_Transform(SHA512_CTX *c, const unsigned char *data);
183#endif 188#endif
diff --git a/src/lib/libcrypto/sha/sha1.c b/src/lib/libcrypto/sha/sha1.c
index 32007d5d52..52338812db 100644
--- a/src/lib/libcrypto/sha/sha1.c
+++ b/src/lib/libcrypto/sha/sha1.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sha1.c,v 1.14 2024/03/28 07:06:12 jsing Exp $ */ 1/* $OpenBSD: sha1.c,v 1.15 2024/06/01 07:36:16 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -496,10 +496,6 @@ unsigned char *
496SHA1(const unsigned char *d, size_t n, unsigned char *md) 496SHA1(const unsigned char *d, size_t n, unsigned char *md)
497{ 497{
498 SHA_CTX c; 498 SHA_CTX c;
499 static unsigned char m[SHA_DIGEST_LENGTH];
500
501 if (md == NULL)
502 md = m;
503 499
504 if (!SHA1_Init(&c)) 500 if (!SHA1_Init(&c))
505 return NULL; 501 return NULL;
diff --git a/src/lib/libcrypto/sha/sha256.c b/src/lib/libcrypto/sha/sha256.c
index d18e8d219d..ab00c17878 100644
--- a/src/lib/libcrypto/sha/sha256.c
+++ b/src/lib/libcrypto/sha/sha256.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sha256.c,v 1.31 2024/03/28 04:23:02 jsing Exp $ */ 1/* $OpenBSD: sha256.c,v 1.32 2024/06/01 07:36:16 tb Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1998-2011 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1998-2011 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -317,10 +317,6 @@ unsigned char *
317SHA224(const unsigned char *d, size_t n, unsigned char *md) 317SHA224(const unsigned char *d, size_t n, unsigned char *md)
318{ 318{
319 SHA256_CTX c; 319 SHA256_CTX c;
320 static unsigned char m[SHA224_DIGEST_LENGTH];
321
322 if (md == NULL)
323 md = m;
324 320
325 SHA224_Init(&c); 321 SHA224_Init(&c);
326 SHA256_Update(&c, d, n); 322 SHA256_Update(&c, d, n);
@@ -479,10 +475,6 @@ unsigned char *
479SHA256(const unsigned char *d, size_t n, unsigned char *md) 475SHA256(const unsigned char *d, size_t n, unsigned char *md)
480{ 476{
481 SHA256_CTX c; 477 SHA256_CTX c;
482 static unsigned char m[SHA256_DIGEST_LENGTH];
483
484 if (md == NULL)
485 md = m;
486 478
487 SHA256_Init(&c); 479 SHA256_Init(&c);
488 SHA256_Update(&c, d, n); 480 SHA256_Update(&c, d, n);
diff --git a/src/lib/libcrypto/sha/sha512.c b/src/lib/libcrypto/sha/sha512.c
index 360a5c29fb..7a2a40d3df 100644
--- a/src/lib/libcrypto/sha/sha512.c
+++ b/src/lib/libcrypto/sha/sha512.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sha512.c,v 1.41 2023/07/08 12:24:10 beck Exp $ */ 1/* $OpenBSD: sha512.c,v 1.42 2024/06/01 07:36:16 tb Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1998-2011 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1998-2011 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -345,10 +345,6 @@ unsigned char *
345SHA384(const unsigned char *d, size_t n, unsigned char *md) 345SHA384(const unsigned char *d, size_t n, unsigned char *md)
346{ 346{
347 SHA512_CTX c; 347 SHA512_CTX c;
348 static unsigned char m[SHA384_DIGEST_LENGTH];
349
350 if (md == NULL)
351 md = m;
352 348
353 SHA384_Init(&c); 349 SHA384_Init(&c);
354 SHA512_Update(&c, d, n); 350 SHA512_Update(&c, d, n);
@@ -498,10 +494,6 @@ unsigned char *
498SHA512(const unsigned char *d, size_t n, unsigned char *md) 494SHA512(const unsigned char *d, size_t n, unsigned char *md)
499{ 495{
500 SHA512_CTX c; 496 SHA512_CTX c;
501 static unsigned char m[SHA512_DIGEST_LENGTH];
502
503 if (md == NULL)
504 md = m;
505 497
506 SHA512_Init(&c); 498 SHA512_Init(&c);
507 SHA512_Update(&c, d, n); 499 SHA512_Update(&c, d, n);
diff --git a/src/lib/libcrypto/whrlpool/whirlpool.c b/src/lib/libcrypto/whrlpool/whirlpool.c
index e1e0f7a899..80e147c3b5 100644
--- a/src/lib/libcrypto/whrlpool/whirlpool.c
+++ b/src/lib/libcrypto/whrlpool/whirlpool.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: whirlpool.c,v 1.2 2024/03/30 03:45:47 joshua Exp $ */ 1/* $OpenBSD: whirlpool.c,v 1.3 2024/06/01 07:36:17 tb Exp $ */
2/** 2/**
3 * The Whirlpool hashing function. 3 * The Whirlpool hashing function.
4 * 4 *
@@ -846,10 +846,7 @@ unsigned char *
846WHIRLPOOL(const void *inp, size_t bytes, unsigned char *md) 846WHIRLPOOL(const void *inp, size_t bytes, unsigned char *md)
847{ 847{
848 WHIRLPOOL_CTX ctx; 848 WHIRLPOOL_CTX ctx;
849 static unsigned char m[WHIRLPOOL_DIGEST_LENGTH];
850 849
851 if (md == NULL)
852 md = m;
853 WHIRLPOOL_Init(&ctx); 850 WHIRLPOOL_Init(&ctx);
854 WHIRLPOOL_Update(&ctx, inp, bytes); 851 WHIRLPOOL_Update(&ctx, inp, bytes);
855 WHIRLPOOL_Final(md, &ctx); 852 WHIRLPOOL_Final(md, &ctx);
diff --git a/src/lib/libcrypto/whrlpool/whrlpool.h b/src/lib/libcrypto/whrlpool/whrlpool.h
index 875d34f7d3..1b4fac1993 100644
--- a/src/lib/libcrypto/whrlpool/whrlpool.h
+++ b/src/lib/libcrypto/whrlpool/whrlpool.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: whrlpool.h,v 1.5 2014/07/10 22:45:58 jsing Exp $ */ 1/* $OpenBSD: whrlpool.h,v 1.6 2024/06/01 07:36:17 tb Exp $ */
2 2
3#include <stddef.h> 3#include <stddef.h>
4 4
@@ -28,10 +28,13 @@ typedef struct {
28 28
29#ifndef OPENSSL_NO_WHIRLPOOL 29#ifndef OPENSSL_NO_WHIRLPOOL
30int WHIRLPOOL_Init (WHIRLPOOL_CTX *c); 30int WHIRLPOOL_Init (WHIRLPOOL_CTX *c);
31int WHIRLPOOL_Update (WHIRLPOOL_CTX *c,const void *inp,size_t bytes); 31int WHIRLPOOL_Update (WHIRLPOOL_CTX *c,const void *inp,size_t bytes)
32 __attribute__ ((__bounded__(__buffer__, 2, 3)));
32void WHIRLPOOL_BitUpdate(WHIRLPOOL_CTX *c,const void *inp,size_t bits); 33void WHIRLPOOL_BitUpdate(WHIRLPOOL_CTX *c,const void *inp,size_t bits);
33int WHIRLPOOL_Final (unsigned char *md,WHIRLPOOL_CTX *c); 34int WHIRLPOOL_Final (unsigned char *md,WHIRLPOOL_CTX *c);
34unsigned char *WHIRLPOOL(const void *inp,size_t bytes,unsigned char *md); 35unsigned char *WHIRLPOOL(const void *inp,size_t bytes,unsigned char *md)
36 __attribute__ ((__nonnull__(3)))
37 __attribute__ ((__bounded__(__buffer__, 1, 2)));
35#endif 38#endif
36 39
37#ifdef __cplusplus 40#ifdef __cplusplus