Commit a999136e01 for openssl.org
commit a999136e01215faabf19119ba75ccf89037d36e7
Author: Richard Levitte <levitte@openssl.org>
Date: Fri Dec 12 13:56:30 2025 +0100
Refactor types that are '#define'd into proper typedefs
I looked for them with the following grep pipe, and then read through
the output to discern what are actual type definitions, and converted
what I found manually.
git grep -En -e '#define [a-zA-Z_0-9]+ ' -- '*.h' \
| sed -e 's|//.*||' -e 's|/\*.*\*/||g' \
| grep -Ev ' ([0-9]|.*".*|.*\\$)'
Reviewed-by: Paul Yang <paulyang.inf@gmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/29383)
diff --git a/crypto/bn/bn_local.h b/crypto/bn/bn_local.h
index e73cba1733..32d27cd1d3 100644
--- a/crypto/bn/bn_local.h
+++ b/crypto/bn/bn_local.h
@@ -78,7 +78,7 @@
* 64-bit processor with LP64 ABI
*/
#ifdef SIXTY_FOUR_BIT_LONG
-#define BN_ULLONG unsigned long long
+typedef unsigned long long BN_ULLONG;
#define BN_BITS4 32
#define BN_MASK2 (0xffffffffffffffffL)
#define BN_MASK2l (0xffffffffL)
@@ -110,9 +110,9 @@
#ifdef THIRTY_TWO_BIT
#ifdef BN_LLONG
#if defined(_WIN32) && !defined(__GNUC__)
-#define BN_ULLONG unsigned __int64
+typedef unsigned __int64 BN_ULLONG;
#else
-#define BN_ULLONG unsigned long long
+typedef unsigned long long BN_ULLONG;
#endif
#endif
#define BN_BITS4 16
diff --git a/include/crypto/rsa.h b/include/crypto/rsa.h
index 0c3fa8f895..0b853f9a80 100644
--- a/include/crypto/rsa.h
+++ b/include/crypto/rsa.h
@@ -137,7 +137,7 @@ int ossl_rsa_acvp_test_get_params(RSA *r, OSSL_PARAM params[]);
typedef struct rsa_acvp_test_st RSA_ACVP_TEST;
void ossl_rsa_acvp_test_free(RSA_ACVP_TEST *t);
#else
-#define RSA_ACVP_TEST void
+typedef void RSA_ACVP_TEST;
#endif
int ossl_rsa_check_factors(RSA *r);
diff --git a/include/internal/e_os.h b/include/internal/e_os.h
index d287d91055..9e4e0afaa0 100644
--- a/include/internal/e_os.h
+++ b/include/internal/e_os.h
@@ -243,7 +243,7 @@ FILE *__iob_func(void);
#include <sockLib.h>
#include <taskLib.h>
-#define TTY_STRUCT int
+typedef int TTY_STRUCT;
#define sleep(a) taskDelay((a) * sysClkRateGet())
/*
@@ -339,7 +339,7 @@ inline int nssgetpid(void)
* There is no locale_t on NONSTOP.
*/
#if defined(OPENSSL_SYS_WINDOWS)
-#define locale_t _locale_t
+typedef _locale_t locale_t;
#define freelocale _free_locale
#define strcasecmp_l _stricmp_l
#define strncasecmp_l _strnicmp_l
diff --git a/include/internal/sm3.h b/include/internal/sm3.h
index 32a05ae9ef..ee097d85e6 100644
--- a/include/internal/sm3.h
+++ b/include/internal/sm3.h
@@ -20,7 +20,7 @@
#endif
#define SM3_DIGEST_LENGTH 32
-#define SM3_WORD unsigned int
+typedef unsigned int SM3_WORD;
#define SM3_CBLOCK 64
#define SM3_LBLOCK (SM3_CBLOCK / 4)
diff --git a/include/openssl/blowfish.h b/include/openssl/blowfish.h
index 49c74e946c..a1f678855b 100644
--- a/include/openssl/blowfish.h
+++ b/include/openssl/blowfish.h
@@ -36,7 +36,7 @@ extern "C" {
* ! BF_LONG has to be at least 32 bits wide. !
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*/
-#define BF_LONG unsigned int
+typedef unsigned int BF_LONG;
#define BF_ROUNDS 16
diff --git a/include/openssl/bn.h b/include/openssl/bn.h
index d210b8bddd..430d20dcb9 100644
--- a/include/openssl/bn.h
+++ b/include/openssl/bn.h
@@ -34,7 +34,7 @@ extern "C" {
* 64-bit processor with LP64 ABI
*/
#ifdef SIXTY_FOUR_BIT_LONG
-#define BN_ULONG unsigned long
+typedef unsigned long BN_ULONG;
#define BN_BYTES 8
#endif
@@ -42,12 +42,12 @@ extern "C" {
* 64-bit processor other than LP64 ABI
*/
#ifdef SIXTY_FOUR_BIT
-#define BN_ULONG unsigned long long
+typedef unsigned long long BN_ULONG;
#define BN_BYTES 8
#endif
#ifdef THIRTY_TWO_BIT
-#define BN_ULONG unsigned int
+typedef unsigned int BN_ULONG;
#define BN_BYTES 4
#endif
diff --git a/include/openssl/cast.h b/include/openssl/cast.h
index af94312482..7babdb66fe 100644
--- a/include/openssl/cast.h
+++ b/include/openssl/cast.h
@@ -31,7 +31,7 @@ extern "C" {
#define CAST_ENCRYPT 1
#define CAST_DECRYPT 0
-#define CAST_LONG unsigned int
+typedef unsigned int CAST_LONG;
typedef struct cast_key_st {
CAST_LONG data[32];
diff --git a/include/openssl/e_os2.h b/include/openssl/e_os2.h
index 86a572bb12..c8727b037b 100644
--- a/include/openssl/e_os2.h
+++ b/include/openssl/e_os2.h
@@ -186,22 +186,22 @@ extern "C" {
#ifdef _WIN32
#ifdef _WIN64
-#define ossl_ssize_t __int64
+typedef __int64 ossl_ssize_t;
#define OSSL_SSIZE_MAX _I64_MAX
#else
-#define ossl_ssize_t int
+typedef int ossl_ssize_t;
#define OSSL_SSIZE_MAX INT_MAX
#endif
#endif
#if defined(OPENSSL_SYS_UEFI) && !defined(ossl_ssize_t)
-#define ossl_ssize_t INTN
+typedef INTN ossl_ssize_t;
#define OSSL_SSIZE_MAX MAX_INTN
#endif
-#ifndef ossl_ssize_t
+#ifndef OSSL_SSIZE_MAX
#include <sys/types.h>
-#define ossl_ssize_t ssize_t
+typedef ssize_t ossl_ssize_t;
#if defined(SSIZE_MAX)
#define OSSL_SSIZE_MAX SSIZE_MAX
#elif defined(_POSIX_SSIZE_MAX)
diff --git a/include/openssl/md4.h b/include/openssl/md4.h
index d60fe4a667..06993aaa54 100644
--- a/include/openssl/md4.h
+++ b/include/openssl/md4.h
@@ -34,7 +34,7 @@ extern "C" {
* ! MD4_LONG has to be at least 32 bits wide. !
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*/
-#define MD4_LONG unsigned int
+typedef unsigned int MD4_LONG;
#define MD4_CBLOCK 64
#define MD4_LBLOCK (MD4_CBLOCK / 4)
diff --git a/include/openssl/md5.h b/include/openssl/md5.h
index 0ec3d1ce95..9f65778104 100644
--- a/include/openssl/md5.h
+++ b/include/openssl/md5.h
@@ -33,7 +33,7 @@ extern "C" {
* ! MD5_LONG has to be at least 32 bits wide. !
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*/
-#define MD5_LONG unsigned int
+typedef unsigned int MD5_LONG;
#define MD5_CBLOCK 64
#define MD5_LBLOCK (MD5_CBLOCK / 4)
diff --git a/include/openssl/rc5.h b/include/openssl/rc5.h
index 2e91e98540..e13cf9c8d4 100644
--- a/include/openssl/rc5.h
+++ b/include/openssl/rc5.h
@@ -30,7 +30,7 @@ extern "C" {
#define RC5_ENCRYPT 1
#define RC5_DECRYPT 0
-#define RC5_32_INT unsigned int
+typedef unsigned int RC5_32_INT;
/*
* This are the only values supported. Tweak the code if you want more The
diff --git a/include/openssl/ripemd.h b/include/openssl/ripemd.h
index a72d1dad0a..e0bab4d374 100644
--- a/include/openssl/ripemd.h
+++ b/include/openssl/ripemd.h
@@ -29,7 +29,7 @@ extern "C" {
#endif
#if !defined(OPENSSL_NO_DEPRECATED_3_0)
-#define RIPEMD160_LONG unsigned int
+typedef unsigned int RIPEMD160_LONG;
#define RIPEMD160_CBLOCK 64
#define RIPEMD160_LBLOCK (RIPEMD160_CBLOCK / 4)
diff --git a/include/openssl/sha.h b/include/openssl/sha.h
index 52b02661f6..7140d71043 100644
--- a/include/openssl/sha.h
+++ b/include/openssl/sha.h
@@ -31,7 +31,7 @@ extern "C" {
* ! SHA_LONG has to be at least 32 bits wide. !
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
*/
-#define SHA_LONG unsigned int
+typedef unsigned int SHA_LONG;
#define SHA_LBLOCK 16
#define SHA_CBLOCK (SHA_LBLOCK * 4) /* SHA treats input data as a \
@@ -100,11 +100,11 @@ unsigned char *SHA256(const unsigned char *d, size_t n, unsigned char *md);
*/
#define SHA512_CBLOCK (SHA_LBLOCK * 8)
#if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__)
-#define SHA_LONG64 unsigned __int64
+typedef unsigned __int64 SHA_LONG64;
#elif defined(__arch64__)
-#define SHA_LONG64 unsigned long
+typedef unsigned long SHA_LONG64;
#else
-#define SHA_LONG64 unsigned long long
+typedef unsigned long long SHA_LONG64;
#endif
typedef struct SHA512state_st {
diff --git a/include/openssl/types.h b/include/openssl/types.h
index f8bb853229..9eaeb699d3 100644
--- a/include/openssl/types.h
+++ b/include/openssl/types.h
@@ -36,23 +36,23 @@ extern "C" {
typedef struct ossl_provider_st OSSL_PROVIDER; /* Provider Object */
#ifdef NO_ASN1_TYPEDEFS
-#define ASN1_INTEGER ASN1_STRING
-#define ASN1_ENUMERATED ASN1_STRING
-#define ASN1_BIT_STRING ASN1_STRING
-#define ASN1_OCTET_STRING ASN1_STRING
-#define ASN1_PRINTABLESTRING ASN1_STRING
-#define ASN1_T61STRING ASN1_STRING
-#define ASN1_IA5STRING ASN1_STRING
-#define ASN1_UTCTIME ASN1_STRING
-#define ASN1_GENERALIZEDTIME ASN1_STRING
-#define ASN1_TIME ASN1_STRING
-#define ASN1_GENERALSTRING ASN1_STRING
-#define ASN1_UNIVERSALSTRING ASN1_STRING
-#define ASN1_BMPSTRING ASN1_STRING
-#define ASN1_VISIBLESTRING ASN1_STRING
-#define ASN1_UTF8STRING ASN1_STRING
-#define ASN1_BOOLEAN int
-#define ASN1_NULL int
+typedef ASN1_STRING ASN1_INTEGER;
+typedef ASN1_STRING ASN1_ENUMERATED;
+typedef ASN1_STRING ASN1_BIT_STRING;
+typedef ASN1_STRING ASN1_OCTET_STRING;
+typedef ASN1_STRING ASN1_PRINTABLESTRING;
+typedef ASN1_STRING ASN1_T61STRING;
+typedef ASN1_STRING ASN1_IA5STRING;
+typedef ASN1_STRING ASN1_UTCTIME;
+typedef ASN1_STRING ASN1_GENERALIZEDTIME;
+typedef ASN1_STRING ASN1_TIME;
+typedef ASN1_STRING ASN1_GENERALSTRING;
+typedef ASN1_STRING ASN1_UNIVERSALSTRING;
+typedef ASN1_STRING ASN1_BMPSTRING;
+typedef ASN1_STRING ASN1_VISIBLESTRING;
+typedef ASN1_STRING ASN1_UTF8STRING;
+typedef int ASN1_BOOLEAN;
+typedef int ASN1_NULL;
#else
typedef struct asn1_string_st ASN1_INTEGER;
typedef struct asn1_string_st ASN1_ENUMERATED;