Commit ba4605d63e for openssl.org
commit ba4605d63ee13c8f8c1cd899c74a7075b7c0178e
Author: Frederik Wedel-Heinen <frederik.wedel-heinen@dencrypt.dk>
Date: Sun Feb 15 15:04:36 2026 +0100
Move common macro definitions to internal/common.h and fix comments.
Fixes #2480
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Norbert Pocs <norbertp@openssl.org>
MergeDate: Thu Jun 11 15:51:32 2026
(Merged from https://github.com/openssl/openssl/pull/30019)
diff --git a/crypto/bf/bf_local.h b/crypto/bf/bf_local.h
index 8634a57ceb..c9c6d53f9e 100644
--- a/crypto/bf/bf_local.h
+++ b/crypto/bf/bf_local.h
@@ -9,82 +9,9 @@
#ifndef OSSL_CRYPTO_BF_LOCAL_H
#define OSSL_CRYPTO_BF_LOCAL_H
-#include <openssl/opensslconf.h>
-
-/* NOTE - c is not incremented as per n2l */
-#define n2ln(c, l1, l2, n) \
- { \
- c += n; \
- l1 = l2 = 0; \
- switch (n) { \
- case 8: \
- l2 = ((unsigned long)(*(--(c)))); \
- /* fall through */ \
- case 7: \
- l2 |= ((unsigned long)(*(--(c)))) << 8; \
- /* fall through */ \
- case 6: \
- l2 |= ((unsigned long)(*(--(c)))) << 16; \
- /* fall through */ \
- case 5: \
- l2 |= ((unsigned long)(*(--(c)))) << 24; \
- /* fall through */ \
- case 4: \
- l1 = ((unsigned long)(*(--(c)))); \
- /* fall through */ \
- case 3: \
- l1 |= ((unsigned long)(*(--(c)))) << 8; \
- /* fall through */ \
- case 2: \
- l1 |= ((unsigned long)(*(--(c)))) << 16; \
- /* fall through */ \
- case 1: \
- l1 |= ((unsigned long)(*(--(c)))) << 24; \
- } \
- }
-
-/* NOTE - c is not incremented as per l2n */
-#define l2nn(l1, l2, c, n) \
- { \
- c += n; \
- switch (n) { \
- case 8: \
- *(--(c)) = (unsigned char)(((l2)) & 0xff); \
- /* fall through */ \
- case 7: \
- *(--(c)) = (unsigned char)(((l2) >> 8) & 0xff); \
- /* fall through */ \
- case 6: \
- *(--(c)) = (unsigned char)(((l2) >> 16) & 0xff); \
- /* fall through */ \
- case 5: \
- *(--(c)) = (unsigned char)(((l2) >> 24) & 0xff); \
- /* fall through */ \
- case 4: \
- *(--(c)) = (unsigned char)(((l1)) & 0xff); \
- /* fall through */ \
- case 3: \
- *(--(c)) = (unsigned char)(((l1) >> 8) & 0xff); \
- /* fall through */ \
- case 2: \
- *(--(c)) = (unsigned char)(((l1) >> 16) & 0xff); \
- /* fall through */ \
- case 1: \
- *(--(c)) = (unsigned char)(((l1) >> 24) & 0xff); \
- } \
- }
-#undef n2l
-#define n2l(c, l) (l = ((unsigned long)(*((c)++))) << 24L, \
- l |= ((unsigned long)(*((c)++))) << 16L, \
- l |= ((unsigned long)(*((c)++))) << 8L, \
- l |= ((unsigned long)(*((c)++))))
-
-#undef l2n
-#define l2n(l, c) (*((c)++) = (unsigned char)(((l) >> 24L) & 0xff), \
- *((c)++) = (unsigned char)(((l) >> 16L) & 0xff), \
- *((c)++) = (unsigned char)(((l) >> 8L) & 0xff), \
- *((c)++) = (unsigned char)(((l)) & 0xff))
+#include <openssl/opensslconf.h>
+#include "internal/common.h"
/*
* This is actually a big endian algorithm, the most significant byte is used
diff --git a/crypto/cast/cast_local.h b/crypto/cast/cast_local.h
index 954a5b237c..e18a8eee7c 100644
--- a/crypto/cast/cast_local.h
+++ b/crypto/cast/cast_local.h
@@ -6,91 +6,17 @@
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
-
#if !defined(OSSL_LIBCRYPTO_CAST_CAST_LOCAL_H)
#define OSSL_LIBCRYPTO_CAST_CAST_LOCAL_H
#include <openssl/cast.h>
+#include "internal/common.h"
+
#ifdef OPENSSL_SYS_WIN32
#include <stdlib.h>
#endif
-/* NOTE - c is not incremented as per n2l */
-#define n2ln(c, l1, l2, n) \
- { \
- c += n; \
- l1 = l2 = 0; \
- switch (n) { \
- case 8: \
- l2 = ((unsigned long)(*(--(c)))); \
- /* fall through */ \
- case 7: \
- l2 |= ((unsigned long)(*(--(c)))) << 8; \
- /* fall through */ \
- case 6: \
- l2 |= ((unsigned long)(*(--(c)))) << 16; \
- /* fall through */ \
- case 5: \
- l2 |= ((unsigned long)(*(--(c)))) << 24; \
- /* fall through */ \
- case 4: \
- l1 = ((unsigned long)(*(--(c)))); \
- /* fall through */ \
- case 3: \
- l1 |= ((unsigned long)(*(--(c)))) << 8; \
- /* fall through */ \
- case 2: \
- l1 |= ((unsigned long)(*(--(c)))) << 16; \
- /* fall through */ \
- case 1: \
- l1 |= ((unsigned long)(*(--(c)))) << 24; \
- } \
- }
-
-/* NOTE - c is not incremented as per l2n */
-#define l2nn(l1, l2, c, n) \
- { \
- c += n; \
- switch (n) { \
- case 8: \
- *(--(c)) = (unsigned char)(((l2)) & 0xff); \
- /* fall through */ \
- case 7: \
- *(--(c)) = (unsigned char)(((l2) >> 8) & 0xff); \
- /* fall through */ \
- case 6: \
- *(--(c)) = (unsigned char)(((l2) >> 16) & 0xff); \
- /* fall through */ \
- case 5: \
- *(--(c)) = (unsigned char)(((l2) >> 24) & 0xff); \
- /* fall through */ \
- case 4: \
- *(--(c)) = (unsigned char)(((l1)) & 0xff); \
- /* fall through */ \
- case 3: \
- *(--(c)) = (unsigned char)(((l1) >> 8) & 0xff); \
- /* fall through */ \
- case 2: \
- *(--(c)) = (unsigned char)(((l1) >> 16) & 0xff); \
- /* fall through */ \
- case 1: \
- *(--(c)) = (unsigned char)(((l1) >> 24) & 0xff); \
- } \
- }
-
-#undef n2l
-#define n2l(c, l) (l = ((unsigned long)(*((c)++))) << 24L, \
- l |= ((unsigned long)(*((c)++))) << 16L, \
- l |= ((unsigned long)(*((c)++))) << 8L, \
- l |= ((unsigned long)(*((c)++))))
-
-#undef l2n
-#define l2n(l, c) (*((c)++) = (unsigned char)(((l) >> 24L) & 0xff), \
- *((c)++) = (unsigned char)(((l) >> 16L) & 0xff), \
- *((c)++) = (unsigned char)(((l) >> 8L) & 0xff), \
- *((c)++) = (unsigned char)(((l)) & 0xff))
-
#if defined(OPENSSL_SYS_WIN32) && defined(_MSC_VER)
#define ROTL(a, n) (_lrotl(a, n))
#else
diff --git a/crypto/ct/ct_local.h b/crypto/ct/ct_local.h
index 2fffc1a841..337dc272c3 100644
--- a/crypto/ct/ct_local.h
+++ b/crypto/ct/ct_local.h
@@ -17,6 +17,8 @@
#include <openssl/x509v3.h>
#include <openssl/safestack.h>
+#include "internal/common.h"
+
/*
* From RFC6962: opaque SerializedSCT<1..2^16-1>; struct { SerializedSCT
* sct_list <1..2^16-1>; } SignedCertificateTimestampList;
@@ -24,39 +26,6 @@
#define MAX_SCT_SIZE 65535
#define MAX_SCT_LIST_SIZE MAX_SCT_SIZE
-/*
- * Macros to read and write integers in network-byte order.
- */
-
-#define n2s(c, s) ((s = (((unsigned int)((c)[0])) << 8) | (((unsigned int)((c)[1])))), c += 2)
-
-#define s2n(s, c) ((c[0] = (unsigned char)(((s) >> 8) & 0xff), \
- c[1] = (unsigned char)(((s)) & 0xff)), \
- c += 2)
-
-#define l2n3(l, c) ((c[0] = (unsigned char)(((l) >> 16) & 0xff), \
- c[1] = (unsigned char)(((l) >> 8) & 0xff), \
- c[2] = (unsigned char)(((l)) & 0xff)), \
- c += 3)
-
-#define n2l8(c, l) (l = ((uint64_t)(*((c)++))) << 56, \
- l |= ((uint64_t)(*((c)++))) << 48, \
- l |= ((uint64_t)(*((c)++))) << 40, \
- l |= ((uint64_t)(*((c)++))) << 32, \
- l |= ((uint64_t)(*((c)++))) << 24, \
- l |= ((uint64_t)(*((c)++))) << 16, \
- l |= ((uint64_t)(*((c)++))) << 8, \
- l |= ((uint64_t)(*((c)++))))
-
-#define l2n8(l, c) (*((c)++) = (unsigned char)(((l) >> 56) & 0xff), \
- *((c)++) = (unsigned char)(((l) >> 48) & 0xff), \
- *((c)++) = (unsigned char)(((l) >> 40) & 0xff), \
- *((c)++) = (unsigned char)(((l) >> 32) & 0xff), \
- *((c)++) = (unsigned char)(((l) >> 24) & 0xff), \
- *((c)++) = (unsigned char)(((l) >> 16) & 0xff), \
- *((c)++) = (unsigned char)(((l) >> 8) & 0xff), \
- *((c)++) = (unsigned char)(((l)) & 0xff))
-
/* Signed Certificate Timestamp */
struct sct_st {
sct_version_t version;
diff --git a/crypto/des/des_local.h b/crypto/des/des_local.h
index 8d08aca7e6..0fee059ec4 100644
--- a/crypto/des/des_local.h
+++ b/crypto/des/des_local.h
@@ -18,6 +18,8 @@
#include <openssl/des.h>
+#include "internal/common.h"
+
#ifdef OPENSSL_BUILD_SHLIBCRYPTO
#undef OPENSSL_EXTERN
#define OPENSSL_EXTERN OPENSSL_EXPORT
@@ -26,79 +28,6 @@
#define ITERATIONS 16
#define HALF_ITERATIONS 8
-#define c2l(c, l) (l = ((DES_LONG)(*((c)++))), \
- l |= ((DES_LONG)(*((c)++))) << 8L, \
- l |= ((DES_LONG)(*((c)++))) << 16L, \
- l |= ((DES_LONG)(*((c)++))) << 24L)
-
-/* NOTE - c is not incremented as per c2l */
-#define c2ln(c, l1, l2, n) \
- { \
- c += n; \
- l1 = l2 = 0; \
- switch (n) { \
- case 8: \
- l2 = ((DES_LONG)(*(--(c)))) << 24L; \
- /* fall through */ \
- case 7: \
- l2 |= ((DES_LONG)(*(--(c)))) << 16L; \
- /* fall through */ \
- case 6: \
- l2 |= ((DES_LONG)(*(--(c)))) << 8L; \
- /* fall through */ \
- case 5: \
- l2 |= ((DES_LONG)(*(--(c)))); \
- /* fall through */ \
- case 4: \
- l1 = ((DES_LONG)(*(--(c)))) << 24L; \
- /* fall through */ \
- case 3: \
- l1 |= ((DES_LONG)(*(--(c)))) << 16L; \
- /* fall through */ \
- case 2: \
- l1 |= ((DES_LONG)(*(--(c)))) << 8L; \
- /* fall through */ \
- case 1: \
- l1 |= ((DES_LONG)(*(--(c)))); \
- } \
- }
-
-#define l2c(l, c) (*((c)++) = (unsigned char)(((l)) & 0xff), \
- *((c)++) = (unsigned char)(((l) >> 8L) & 0xff), \
- *((c)++) = (unsigned char)(((l) >> 16L) & 0xff), \
- *((c)++) = (unsigned char)(((l) >> 24L) & 0xff))
-
-/* NOTE - c is not incremented as per l2c */
-#define l2cn(l1, l2, c, n) \
- { \
- c += n; \
- switch (n) { \
- case 8: \
- *(--(c)) = (unsigned char)(((l2) >> 24L) & 0xff); \
- /* fall through */ \
- case 7: \
- *(--(c)) = (unsigned char)(((l2) >> 16L) & 0xff); \
- /* fall through */ \
- case 6: \
- *(--(c)) = (unsigned char)(((l2) >> 8L) & 0xff); \
- /* fall through */ \
- case 5: \
- *(--(c)) = (unsigned char)(((l2)) & 0xff); \
- /* fall through */ \
- case 4: \
- *(--(c)) = (unsigned char)(((l1) >> 24L) & 0xff); \
- /* fall through */ \
- case 3: \
- *(--(c)) = (unsigned char)(((l1) >> 16L) & 0xff); \
- /* fall through */ \
- case 2: \
- *(--(c)) = (unsigned char)(((l1) >> 8L) & 0xff); \
- /* fall through */ \
- case 1: \
- *(--(c)) = (unsigned char)(((l1)) & 0xff); \
- } \
- }
-
#if defined(_MSC_VER)
#define ROTATE(a, n) (_lrotr(a, n))
#elif defined(__ICC)
diff --git a/crypto/idea/idea_local.h b/crypto/idea/idea_local.h
index d90d4293e0..6a3d6829ae 100644
--- a/crypto/idea/idea_local.h
+++ b/crypto/idea/idea_local.h
@@ -10,6 +10,8 @@
#if !defined(OSSL_LIBCRYPTO_IDEA_IDEA_LOCAL_H)
#define OSSL_LIBCRYPTO_IDEA_IDEA_LOCAL_H
+#include "internal/common.h"
+
#define idea_mul(r, a, b, ul) \
ul = (unsigned long)a * b; \
if (ul != 0) { \
@@ -19,89 +21,6 @@
r = (-(int)a - b + 1); /* assuming a or b is 0 and in range */ \
}
-/* NOTE - c is not incremented as per n2l */
-#define n2ln(c, l1, l2, n) \
- { \
- c += n; \
- l1 = l2 = 0; \
- switch (n) { \
- case 8: \
- l2 = ((unsigned long)(*(--(c)))); \
- /* fall through */ \
- case 7: \
- l2 |= ((unsigned long)(*(--(c)))) << 8; \
- /* fall through */ \
- case 6: \
- l2 |= ((unsigned long)(*(--(c)))) << 16; \
- /* fall through */ \
- case 5: \
- l2 |= ((unsigned long)(*(--(c)))) << 24; \
- /* fall through */ \
- case 4: \
- l1 = ((unsigned long)(*(--(c)))); \
- /* fall through */ \
- case 3: \
- l1 |= ((unsigned long)(*(--(c)))) << 8; \
- /* fall through */ \
- case 2: \
- l1 |= ((unsigned long)(*(--(c)))) << 16; \
- /* fall through */ \
- case 1: \
- l1 |= ((unsigned long)(*(--(c)))) << 24; \
- } \
- }
-
-/* NOTE - c is not incremented as per l2n */
-#define l2nn(l1, l2, c, n) \
- { \
- c += n; \
- switch (n) { \
- case 8: \
- *(--(c)) = (unsigned char)(((l2)) & 0xff); \
- /* fall through */ \
- case 7: \
- *(--(c)) = (unsigned char)(((l2) >> 8) & 0xff); \
- /* fall through */ \
- case 6: \
- *(--(c)) = (unsigned char)(((l2) >> 16) & 0xff); \
- /* fall through */ \
- case 5: \
- *(--(c)) = (unsigned char)(((l2) >> 24) & 0xff); \
- /* fall through */ \
- case 4: \
- *(--(c)) = (unsigned char)(((l1)) & 0xff); \
- /* fall through */ \
- case 3: \
- *(--(c)) = (unsigned char)(((l1) >> 8) & 0xff); \
- /* fall through */ \
- case 2: \
- *(--(c)) = (unsigned char)(((l1) >> 16) & 0xff); \
- /* fall through */ \
- case 1: \
- *(--(c)) = (unsigned char)(((l1) >> 24) & 0xff); \
- } \
- }
-
-#undef n2l
-#define n2l(c, l) (l = ((unsigned long)(*((c)++))) << 24L, \
- l |= ((unsigned long)(*((c)++))) << 16L, \
- l |= ((unsigned long)(*((c)++))) << 8L, \
- l |= ((unsigned long)(*((c)++))))
-
-#undef l2n
-#define l2n(l, c) (*((c)++) = (unsigned char)(((l) >> 24L) & 0xff), \
- *((c)++) = (unsigned char)(((l) >> 16L) & 0xff), \
- *((c)++) = (unsigned char)(((l) >> 8L) & 0xff), \
- *((c)++) = (unsigned char)(((l)) & 0xff))
-
-#undef s2n
-#define s2n(l, c) (*((c)++) = (unsigned char)(((l)) & 0xff), \
- *((c)++) = (unsigned char)(((l) >> 8L) & 0xff))
-
-#undef n2s
-#define n2s(c, l) (l = ((IDEA_INT)(*((c)++))) << 8L, \
- l |= ((IDEA_INT)(*((c)++))))
-
#define E_IDEA(num) \
x1 &= 0xffff; \
idea_mul(x1, x1, *p, ul); \
diff --git a/crypto/mdc2/mdc2dgst.c b/crypto/mdc2/mdc2dgst.c
index 6fa9bbd356..0a62569c2b 100644
--- a/crypto/mdc2/mdc2dgst.c
+++ b/crypto/mdc2/mdc2dgst.c
@@ -19,18 +19,7 @@
#include <openssl/crypto.h>
#include <openssl/des.h>
#include <openssl/mdc2.h>
-
-#undef c2l
-#define c2l(c, l) (l = ((DES_LONG)(*((c)++))), \
- l |= ((DES_LONG)(*((c)++))) << 8L, \
- l |= ((DES_LONG)(*((c)++))) << 16L, \
- l |= ((DES_LONG)(*((c)++))) << 24L)
-
-#undef l2c
-#define l2c(l, c) (*((c)++) = (unsigned char)(((l)) & 0xff), \
- *((c)++) = (unsigned char)(((l) >> 8L) & 0xff), \
- *((c)++) = (unsigned char)(((l) >> 16L) & 0xff), \
- *((c)++) = (unsigned char)(((l) >> 24L) & 0xff))
+#include "internal/common.h"
static void mdc2_body(MDC2_CTX *c, const unsigned char *in, size_t len);
int MDC2_Init(MDC2_CTX *c)
diff --git a/crypto/rc2/rc2_cbc.c b/crypto/rc2/rc2_cbc.c
index 46baa9b772..2a487ed507 100644
--- a/crypto/rc2/rc2_cbc.c
+++ b/crypto/rc2/rc2_cbc.c
@@ -14,7 +14,7 @@
#include "internal/deprecated.h"
#include <openssl/rc2.h>
-#include "rc2_local.h"
+#include "internal/common.h"
void RC2_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
RC2_KEY *ks, unsigned char *iv, int encrypt)
diff --git a/crypto/rc2/rc2_local.h b/crypto/rc2/rc2_local.h
index c4b8569514..b2be41d419 100644
--- a/crypto/rc2/rc2_local.h
+++ b/crypto/rc2/rc2_local.h
@@ -10,81 +10,6 @@
#if !defined(OSSL_LIBCRYPTO_RC2_RC2_LOCAL_H)
#define OSSL_LIBCRYPTO_RC2_RC2_LOCAL_H
-#undef c2l
-#define c2l(c, l) (l = ((unsigned long)(*((c)++))), \
- l |= ((unsigned long)(*((c)++))) << 8L, \
- l |= ((unsigned long)(*((c)++))) << 16L, \
- l |= ((unsigned long)(*((c)++))) << 24L)
-
-/* NOTE - c is not incremented as per c2l */
-#undef c2ln
-#define c2ln(c, l1, l2, n) \
- { \
- c += n; \
- l1 = l2 = 0; \
- switch (n) { \
- case 8: \
- l2 = ((unsigned long)(*(--(c)))) << 24L; \
- /* fall through */ \
- case 7: \
- l2 |= ((unsigned long)(*(--(c)))) << 16L; \
- /* fall through */ \
- case 6: \
- l2 |= ((unsigned long)(*(--(c)))) << 8L; \
- /* fall through */ \
- case 5: \
- l2 |= ((unsigned long)(*(--(c)))); \
- /* fall through */ \
- case 4: \
- l1 = ((unsigned long)(*(--(c)))) << 24L; \
- /* fall through */ \
- case 3: \
- l1 |= ((unsigned long)(*(--(c)))) << 16L; \
- /* fall through */ \
- case 2: \
- l1 |= ((unsigned long)(*(--(c)))) << 8L; \
- /* fall through */ \
- case 1: \
- l1 |= ((unsigned long)(*(--(c)))); \
- } \
- }
-
-#undef l2c
-#define l2c(l, c) (*((c)++) = (unsigned char)(((l)) & 0xff), \
- *((c)++) = (unsigned char)(((l) >> 8L) & 0xff), \
- *((c)++) = (unsigned char)(((l) >> 16L) & 0xff), \
- *((c)++) = (unsigned char)(((l) >> 24L) & 0xff))
-
-/* NOTE - c is not incremented as per l2c */
-#undef l2cn
-#define l2cn(l1, l2, c, n) \
- { \
- c += n; \
- switch (n) { \
- case 8: \
- *(--(c)) = (unsigned char)(((l2) >> 24L) & 0xff); \
- /* fall through */ \
- case 7: \
- *(--(c)) = (unsigned char)(((l2) >> 16L) & 0xff); \
- /* fall through */ \
- case 6: \
- *(--(c)) = (unsigned char)(((l2) >> 8L) & 0xff); \
- /* fall through */ \
- case 5: \
- *(--(c)) = (unsigned char)(((l2)) & 0xff); \
- /* fall through */ \
- case 4: \
- *(--(c)) = (unsigned char)(((l1) >> 24L) & 0xff); \
- /* fall through */ \
- case 3: \
- *(--(c)) = (unsigned char)(((l1) >> 16L) & 0xff); \
- /* fall through */ \
- case 2: \
- *(--(c)) = (unsigned char)(((l1) >> 8L) & 0xff); \
- /* fall through */ \
- case 1: \
- *(--(c)) = (unsigned char)(((l1)) & 0xff); \
- } \
- }
+#include "internal/common.h"
#endif /* !defined(OSSL_LIBCRYPTO_RC2_RC2_LOCAL_H) */
diff --git a/crypto/rc2/rc2_skey.c b/crypto/rc2/rc2_skey.c
index 908376dc88..02bfe45f2d 100644
--- a/crypto/rc2/rc2_skey.c
+++ b/crypto/rc2/rc2_skey.c
@@ -14,7 +14,7 @@
#include "internal/deprecated.h"
#include <openssl/rc2.h>
-#include "rc2_local.h"
+#include "internal/common.h"
static const unsigned char key_table[256] = {
0xd9, 0x78, 0xf9, 0xc4, 0x19, 0xdd, 0xb5, 0xed, 0x28, 0xe9,
diff --git a/crypto/rc2/rc2cfb64.c b/crypto/rc2/rc2cfb64.c
index c0e45787f8..88c460b004 100644
--- a/crypto/rc2/rc2cfb64.c
+++ b/crypto/rc2/rc2cfb64.c
@@ -14,7 +14,7 @@
#include "internal/deprecated.h"
#include <openssl/rc2.h>
-#include "rc2_local.h"
+#include "internal/common.h"
/*
* The input and output encrypted as though 64bit cfb mode is being used.
diff --git a/crypto/rc2/rc2ofb64.c b/crypto/rc2/rc2ofb64.c
index e771ffc376..45fe7aecd2 100644
--- a/crypto/rc2/rc2ofb64.c
+++ b/crypto/rc2/rc2ofb64.c
@@ -14,7 +14,7 @@
#include "internal/deprecated.h"
#include <openssl/rc2.h>
-#include "rc2_local.h"
+#include "internal/common.h"
/*
* The input and output encrypted as though 64bit ofb mode is being used.
diff --git a/crypto/rc5/rc5_local.h b/crypto/rc5/rc5_local.h
index 7b29c9b853..a1fbe61fec 100644
--- a/crypto/rc5/rc5_local.h
+++ b/crypto/rc5/rc5_local.h
@@ -11,83 +11,7 @@
#define OSSL_LIBCRYPTO_RC5_RC5_LOCAL_H
#include <stdlib.h>
-
-#undef c2l
-#define c2l(c, l) (l = ((unsigned long)(*((c)++))), \
- l |= ((unsigned long)(*((c)++))) << 8L, \
- l |= ((unsigned long)(*((c)++))) << 16L, \
- l |= ((unsigned long)(*((c)++))) << 24L)
-
-/* NOTE - c is not incremented as per c2l */
-#undef c2ln
-#define c2ln(c, l1, l2, n) \
- { \
- c += n; \
- l1 = l2 = 0; \
- switch (n) { \
- case 8: \
- l2 = ((unsigned long)(*(--(c)))) << 24L; \
- /* fall through */ \
- case 7: \
- l2 |= ((unsigned long)(*(--(c)))) << 16L; \
- /* fall through */ \
- case 6: \
- l2 |= ((unsigned long)(*(--(c)))) << 8L; \
- /* fall through */ \
- case 5: \
- l2 |= ((unsigned long)(*(--(c)))); \
- /* fall through */ \
- case 4: \
- l1 = ((unsigned long)(*(--(c)))) << 24L; \
- /* fall through */ \
- case 3: \
- l1 |= ((unsigned long)(*(--(c)))) << 16L; \
- /* fall through */ \
- case 2: \
- l1 |= ((unsigned long)(*(--(c)))) << 8L; \
- /* fall through */ \
- case 1: \
- l1 |= ((unsigned long)(*(--(c)))); \
- } \
- }
-
-#undef l2c
-#define l2c(l, c) (*((c)++) = (unsigned char)(((l)) & 0xff), \
- *((c)++) = (unsigned char)(((l) >> 8L) & 0xff), \
- *((c)++) = (unsigned char)(((l) >> 16L) & 0xff), \
- *((c)++) = (unsigned char)(((l) >> 24L) & 0xff))
-
-/* NOTE - c is not incremented as per l2c */
-#undef l2cn
-#define l2cn(l1, l2, c, n) \
- { \
- c += n; \
- switch (n) { \
- case 8: \
- *(--(c)) = (unsigned char)(((l2) >> 24L) & 0xff); \
- /* fall through */ \
- case 7: \
- *(--(c)) = (unsigned char)(((l2) >> 16L) & 0xff); \
- /* fall through */ \
- case 6: \
- *(--(c)) = (unsigned char)(((l2) >> 8L) & 0xff); \
- /* fall through */ \
- case 5: \
- *(--(c)) = (unsigned char)(((l2)) & 0xff); \
- /* fall through */ \
- case 4: \
- *(--(c)) = (unsigned char)(((l1) >> 24L) & 0xff); \
- /* fall through */ \
- case 3: \
- *(--(c)) = (unsigned char)(((l1) >> 16L) & 0xff); \
- /* fall through */ \
- case 2: \
- *(--(c)) = (unsigned char)(((l1) >> 8L) & 0xff); \
- /* fall through */ \
- case 1: \
- *(--(c)) = (unsigned char)(((l1)) & 0xff); \
- } \
- }
+#include "internal/common.h"
#if (defined(OPENSSL_SYS_WIN32) && defined(_MSC_VER))
#define ROTATE_l32(a, n) _lrotl(a, n)
diff --git a/include/internal/common.h b/include/internal/common.h
index c29acccb37..6e72a7ecec 100644
--- a/include/internal/common.h
+++ b/include/internal/common.h
@@ -109,7 +109,6 @@ __owur static ossl_inline int ossl_assert_int(int expr, const char *exprstr,
l |= (((unsigned long)(*((c)++))) << 16), \
l |= (((unsigned long)(*((c)++))) << 24))
-/* NOTE - c is not incremented as per c2l */
#define c2ln(c, l1, l2, n) \
{ \
c += n; \
@@ -117,18 +116,25 @@ __owur static ossl_inline int ossl_assert_int(int expr, const char *exprstr,
switch (n) { \
case 8: \
l2 = ((unsigned long)(*(--(c)))) << 24; \
+ /* fall through */ \
case 7: \
l2 |= ((unsigned long)(*(--(c)))) << 16; \
+ /* fall through */ \
case 6: \
l2 |= ((unsigned long)(*(--(c)))) << 8; \
+ /* fall through */ \
case 5: \
l2 |= ((unsigned long)(*(--(c)))); \
+ /* fall through */ \
case 4: \
l1 = ((unsigned long)(*(--(c)))) << 24; \
+ /* fall through */ \
case 3: \
l1 |= ((unsigned long)(*(--(c)))) << 16; \
+ /* fall through */ \
case 2: \
l1 |= ((unsigned long)(*(--(c)))) << 8; \
+ /* fall through */ \
case 1: \
l1 |= ((unsigned long)(*(--(c)))); \
} \
@@ -153,6 +159,37 @@ __owur static ossl_inline int ossl_assert_int(int expr, const char *exprstr,
l |= ((uint64_t)(*((c)++))) << 8, \
l |= ((uint64_t)(*((c)++))))
+#define n2ln(c, l1, l2, n) \
+ { \
+ c += n; \
+ l1 = l2 = 0; \
+ switch (n) { \
+ case 8: \
+ l2 = ((unsigned long)(*(--(c)))); \
+ /* fall through */ \
+ case 7: \
+ l2 |= ((unsigned long)(*(--(c)))) << 8; \
+ /* fall through */ \
+ case 6: \
+ l2 |= ((unsigned long)(*(--(c)))) << 16; \
+ /* fall through */ \
+ case 5: \
+ l2 |= ((unsigned long)(*(--(c)))) << 24; \
+ /* fall through */ \
+ case 4: \
+ l1 = ((unsigned long)(*(--(c)))); \
+ /* fall through */ \
+ case 3: \
+ l1 |= ((unsigned long)(*(--(c)))) << 8; \
+ /* fall through */ \
+ case 2: \
+ l1 |= ((unsigned long)(*(--(c)))) << 16; \
+ /* fall through */ \
+ case 1: \
+ l1 |= ((unsigned long)(*(--(c)))) << 24; \
+ } \
+ }
+
#define l2n(l, c) (*((c)++) = (unsigned char)(((l) >> 24) & 0xff), \
*((c)++) = (unsigned char)(((l) >> 16) & 0xff), \
*((c)++) = (unsigned char)(((l) >> 8) & 0xff), \
@@ -167,25 +204,62 @@ __owur static ossl_inline int ossl_assert_int(int expr, const char *exprstr,
*((c)++) = (unsigned char)(((l) >> 8) & 0xff), \
*((c)++) = (unsigned char)(((l)) & 0xff))
-/* NOTE - c is not incremented as per l2c */
+/* NOTE - c is not incremented as per l2n */
+#define l2nn(l1, l2, c, n) \
+ { \
+ c += n; \
+ switch (n) { \
+ case 8: \
+ *(--(c)) = (unsigned char)(((l2)) & 0xff); \
+ /* fall through */ \
+ case 7: \
+ *(--(c)) = (unsigned char)(((l2) >> 8) & 0xff); \
+ /* fall through */ \
+ case 6: \
+ *(--(c)) = (unsigned char)(((l2) >> 16) & 0xff); \
+ /* fall through */ \
+ case 5: \
+ *(--(c)) = (unsigned char)(((l2) >> 24) & 0xff); \
+ /* fall through */ \
+ case 4: \
+ *(--(c)) = (unsigned char)(((l1)) & 0xff); \
+ /* fall through */ \
+ case 3: \
+ *(--(c)) = (unsigned char)(((l1) >> 8) & 0xff); \
+ /* fall through */ \
+ case 2: \
+ *(--(c)) = (unsigned char)(((l1) >> 16) & 0xff); \
+ /* fall through */ \
+ case 1: \
+ *(--(c)) = (unsigned char)(((l1) >> 24) & 0xff); \
+ } \
+ }
+
#define l2cn(l1, l2, c, n) \
{ \
c += n; \
switch (n) { \
case 8: \
*(--(c)) = (unsigned char)(((l2) >> 24) & 0xff); \
+ /* fall through */ \
case 7: \
*(--(c)) = (unsigned char)(((l2) >> 16) & 0xff); \
+ /* fall through */ \
case 6: \
*(--(c)) = (unsigned char)(((l2) >> 8) & 0xff); \
+ /* fall through */ \
case 5: \
*(--(c)) = (unsigned char)(((l2)) & 0xff); \
+ /* fall through */ \
case 4: \
*(--(c)) = (unsigned char)(((l1) >> 24) & 0xff); \
+ /* fall through */ \
case 3: \
*(--(c)) = (unsigned char)(((l1) >> 16) & 0xff); \
+ /* fall through */ \
case 2: \
*(--(c)) = (unsigned char)(((l1) >> 8) & 0xff); \
+ /* fall through */ \
case 1: \
*(--(c)) = (unsigned char)(((l1)) & 0xff); \
} \