From: Niels Möller Date: Thu, 4 Jun 2026 17:15:40 +0000 (+0200) Subject: Move assert_maybe macro to nettle-internal.h. X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=9be35c01f7890ba4cdb58f7918c382a296442e76;p=thirdparty%2Fnettle.git Move assert_maybe macro to nettle-internal.h. --- diff --git a/ChangeLog b/ChangeLog index 0d0ef017..854d1416 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2026-06-04 Niels Möller + * nettle-internal.h (assert_maybe): Move macro here, replacing old + copies. Update all users. + * ecc-internal.h (assert_maybe): Deleted. + * sntrup-internal.h (assert_maybe): Deleted. + * ecc-secp256r1.c (ecc_secp256r1_modq): Rewrite adjustment step, to work around gcc on riscv64 generating an unwanted branch instruction. Suggested by Felix Yan. diff --git a/ecc-curve25519.c b/ecc-curve25519.c index db301252..0d2dabd8 100644 --- a/ecc-curve25519.c +++ b/ecc-curve25519.c @@ -38,6 +38,7 @@ #include #include "ecc-internal.h" +#include "nettle-internal.h" #define USE_REDC 0 diff --git a/ecc-curve448.c b/ecc-curve448.c index 1bffeeb7..0e0ccc34 100644 --- a/ecc-curve448.c +++ b/ecc-curve448.c @@ -39,6 +39,7 @@ #include #include "ecc-internal.h" +#include "nettle-internal.h" #define USE_REDC 0 diff --git a/ecc-internal.h b/ecc-internal.h index 0e03215c..29f41a45 100644 --- a/ecc-internal.h +++ b/ecc-internal.h @@ -83,14 +83,6 @@ #define curve25519_eh_to_x _nettle_curve25519_eh_to_x #define curve448_eh_to_x _nettle_curve448_eh_to_x -/* For asserts that are incompatible with sc tests. Currently used - only by ECC code. */ -#if WITH_EXTRA_ASSERTS -# define assert_maybe(x) assert(x) -#else -# define assert_maybe(x) ((void)(x)) -#endif - extern const struct ecc_curve _nettle_secp_192r1; extern const struct ecc_curve _nettle_secp_224r1; extern const struct ecc_curve _nettle_secp_256r1; diff --git a/ecc-mod-arith.c b/ecc-mod-arith.c index 1650f0b4..a3d28b02 100644 --- a/ecc-mod-arith.c +++ b/ecc-mod-arith.c @@ -38,6 +38,7 @@ #include #include "ecc-internal.h" +#include "nettle-internal.h" /* Routines for modp arithmetic. All values are ecc->size limbs, but not necessarily < p. */ diff --git a/ecc-mod-inv.c b/ecc-mod-inv.c index 8da08c09..d27ca121 100644 --- a/ecc-mod-inv.c +++ b/ecc-mod-inv.c @@ -38,6 +38,7 @@ #include #include "ecc-internal.h" +#include "nettle-internal.h" static void cnd_neg (int cnd, mp_limb_t *rp, const mp_limb_t *ap, mp_size_t n) diff --git a/ecc-mod.c b/ecc-mod.c index 74314b8d..1e03af11 100644 --- a/ecc-mod.c +++ b/ecc-mod.c @@ -38,6 +38,7 @@ #include #include "ecc-internal.h" +#include "nettle-internal.h" /* Computes r <-- x mod m, input 2*m->size, output m->size. It's * allowed to have rp == xp or rp == xp + m->size, but no other kind diff --git a/ecc-pm1-redc.c b/ecc-pm1-redc.c index 0f728a37..8cc01204 100644 --- a/ecc-pm1-redc.c +++ b/ecc-pm1-redc.c @@ -38,6 +38,7 @@ #include #include "ecc-internal.h" +#include "nettle-internal.h" /* Use that 1 = - (p - 1) (mod p), and that at least one low limb of p - 1 is zero. */ diff --git a/ecc-pp1-redc.c b/ecc-pp1-redc.c index c4722041..eb0cadfb 100644 --- a/ecc-pp1-redc.c +++ b/ecc-pp1-redc.c @@ -38,6 +38,7 @@ #include #include "ecc-internal.h" +#include "nettle-internal.h" /* Use that 1 = p + 1 (mod p), and that at least one low limb of p + 1 is zero. */ diff --git a/ecc-secp192r1.c b/ecc-secp192r1.c index 9cb29cef..a1f08f7a 100644 --- a/ecc-secp192r1.c +++ b/ecc-secp192r1.c @@ -41,6 +41,7 @@ #include #include "ecc-internal.h" +#include "nettle-internal.h" #define USE_REDC 0 diff --git a/ecc-secp384r1.c b/ecc-secp384r1.c index a0960d9b..e46c7bc0 100644 --- a/ecc-secp384r1.c +++ b/ecc-secp384r1.c @@ -40,6 +40,7 @@ #include #include "ecc-internal.h" +#include "nettle-internal.h" #define USE_REDC 0 diff --git a/eddsa-sign.c b/eddsa-sign.c index b471fd5f..8c2dc383 100644 --- a/eddsa-sign.c +++ b/eddsa-sign.c @@ -40,6 +40,7 @@ #include "ecc.h" #include "ecc-internal.h" +#include "nettle-internal.h" #include "nettle-meta.h" mp_size_t diff --git a/nettle-internal.h b/nettle-internal.h index 1aed1007..803fa8d9 100644 --- a/nettle-internal.h +++ b/nettle-internal.h @@ -71,6 +71,13 @@ do { assert((size_t)(size) <= (sizeof(name))); } while (0) #endif +/* For asserts that are incompatible with sc tests. */ +#if WITH_EXTRA_ASSERTS +# define assert_maybe(x) assert(x) +#else +# define assert_maybe(x) ((void)(x)) +#endif + /* Limits that apply to systems that don't have alloca */ #define NETTLE_MAX_HASH_BLOCK_SIZE 144 /* For sha3_224*/ #define NETTLE_MAX_HASH_DIGEST_SIZE 64 diff --git a/sntrup-internal.h b/sntrup-internal.h index f44e0753..968df2ac 100644 --- a/sntrup-internal.h +++ b/sntrup-internal.h @@ -76,12 +76,6 @@ /* Octet size of an encoded rounded polynomial, 1007. */ #define SNTRUP761_ROUNDED_SIZE (SNTRUP761_CIPHER_SIZE - SNTRUP_HASH_SIZE) -#if WITH_EXTRA_ASSERTS -# define assert_maybe(x) assert(x) -#else -# define assert_maybe(x) ((void)(x)) -#endif - /* Return -1 if high bit set, otherwise zero. */ static inline int uint16_highbit_mask (uint16_t x) diff --git a/sntrup761-keygen.c b/sntrup761-keygen.c index 00e09907..48074525 100644 --- a/sntrup761-keygen.c +++ b/sntrup761-keygen.c @@ -48,6 +48,8 @@ #include "sntrup.h" #include "sntrup-internal.h" +#include "nettle-internal.h" + static void R3_random (sntrup761_R3_t out, void *random_ctx, nettle_random_func * random) { diff --git a/sntrup761.c b/sntrup761.c index 389ff479..6fdc70f0 100644 --- a/sntrup761.c +++ b/sntrup761.c @@ -50,6 +50,7 @@ #include "sntrup761-encoding.h" #include "bswap-internal.h" +#include "nettle-internal.h" #include "sha2.h" #define uint32_MINMAX(a,b) \