]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Do thunking of SHA256_Update
authorNeil Horman <nhorman@openssl.org>
Tue, 20 Jan 2026 17:14:04 +0000 (12:14 -0500)
committerPauli <paul.dale@oracle.com>
Wed, 21 Jan 2026 22:40:35 +0000 (09:40 +1100)
The SHA256_Update function (in fact all functions implemented via the
HASH_UPDATE macro) have mismatched prototypes with the
OSSL_FUNC_digest_update_fn.

This leads to ubsan errors with more recent versions of clang

Create a Thunk that does the proper casting on those function pointer
callbacks

Fixes #29615

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/29650)

crypto/sha/sha256.c
include/crypto/md32_common.h
providers/implementations/digests/sha2_prov.c

index 0268e09dde948cd0ed83181be7bb4746f9d6da2b..5a038dc0504f3cfbd7d64924f954c31fe05d934c 100644 (file)
@@ -119,7 +119,8 @@ int SHA224_Final(unsigned char *md, SHA256_CTX *c)
         }                                                           \
     } while (0)
 
-#define HASH_UPDATE SHA256_Update
+#define HASH_UPDATE_THUNK
+#define HASH_UPDATE SHA256_Update_thunk
 #define HASH_TRANSFORM SHA256_Transform
 #define HASH_FINAL SHA256_Final
 #define HASH_BLOCK_DATA_ORDER sha256_block_data_order
@@ -133,6 +134,12 @@ void sha256_block_data_order_c(SHA256_CTX *ctx, const void *in, size_t num);
     void sha256_block_data_order(SHA256_CTX *ctx, const void *in, size_t num);
 
 #include "crypto/md32_common.h"
+#undef HASH_UPDATE_THUNK
+
+int SHA256_Update(SHA256_CTX *ctx, const void *data, size_t sz)
+{
+    return SHA256_Update_thunk((void *)ctx, (const unsigned char *)data, sz);
+}
 
 #if !defined(SHA256_ASM) || defined(INCLUDE_C_SHA256)
 static const SHA_LONG K256[64] = {
index 9ad2e328bdc724c86af8e1ca5f9cb483099d24f0..9d8f6beb1d4a05cc3185e87ab44ff9b825b5a868 100644 (file)
  * Time for some action :-)
  */
 
+#ifdef HASH_UPDATE_THUNK
+int HASH_UPDATE(void *cp, const unsigned char *data_, size_t len);
+int HASH_UPDATE(void *cp, const unsigned char *data_, size_t len)
+#else
 int HASH_UPDATE(HASH_CTX *c, const void *data_, size_t len)
+#endif
 {
+#ifdef HASH_UPDATE_THUNK
+    HASH_CTX *c = (HASH_CTX *)cp;
+#endif
     const unsigned char *data = data_;
     unsigned char *p;
     HASH_LONG l;
index c75b6d9b3f18d23b5c413f292e823f7ab166a580..0f8cdc929c9b9f4389280d22cc5e9ce90f20a059 100644 (file)
@@ -30,6 +30,8 @@
 
 #define SHA2_FLAGS PROV_DIGEST_FLAG_ALGID_ABSENT
 
+extern int SHA256_Update_thunk(void *ctx, const unsigned char *data, size_t sz);
+
 /* Special set_params method for SSL3 */
 static int sha1_set_ctx_params(void *vctx, const OSSL_PARAM params[])
 {
@@ -293,13 +295,13 @@ IMPLEMENT_digest_functions_with_serialize(sha224, SHA256_CTX,
 IMPLEMENT_digest_functions_with_serialize(sha256, SHA256_CTX,
     SHA256_CBLOCK, SHA256_DIGEST_LENGTH,
     SHA2_FLAGS, SHA256_Init,
-    SHA256_Update, SHA256_Final,
+    SHA256_Update_thunk, SHA256_Final,
     SHA256_Serialize, SHA256_Deserialize)
 /* ossl_sha256_192_internal_functions */
 IMPLEMENT_digest_functions_with_serialize(sha256_192_internal, SHA256_CTX,
     SHA256_CBLOCK, SHA256_192_DIGEST_LENGTH,
     SHA2_FLAGS, ossl_sha256_192_init,
-    SHA256_Update, SHA256_Final,
+    SHA256_Update_thunk, SHA256_Final,
     SHA256_Serialize, SHA256_Deserialize)
 /* ossl_sha384_functions */
 IMPLEMENT_digest_functions_with_serialize(sha384, SHA512_CTX,