From: Nikola Pajkovsky Date: Wed, 6 Aug 2025 09:58:57 +0000 (+0200) Subject: bn: save space in bn_mont_ctx_st by reordering elements X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=3f540b6def5218aca11564e8b6c7169e34b1c68d;p=thirdparty%2Fopenssl.git bn: save space in bn_mont_ctx_st by reordering elements # pahole -C bn_mont_ctx_st ./crypto/bn/libcrypto-shlib-bn_mont.o struct bn_mont_ctx_st { int ri; /* 0 4 */ /* XXX 4 bytes hole, try to pack */ BIGNUM RR; /* 8 24 */ BIGNUM N; /* 32 24 */ BIGNUM Ni; /* 56 24 */ /* --- cacheline 1 boundary (64 bytes) was 16 bytes ago --- */ long unsigned int n0[2]; /* 80 16 */ int flags; /* 96 4 */ /* size: 104, cachelines: 2, members: 6 */ /* sum members: 96, holes: 1, sum holes: 4 */ /* padding: 4 */ /* last cacheline: 40 bytes */ }; # pahole -C bn_mont_ctx_st ./crypto/bn/libcrypto-shlib-bn_mont.o struct bn_mont_ctx_st { BIGNUM RR; /* 0 24 */ BIGNUM N; /* 24 24 */ BIGNUM Ni; /* 48 24 */ /* --- cacheline 1 boundary (64 bytes) was 8 bytes ago --- */ long unsigned int n0[2]; /* 72 16 */ int ri; /* 88 4 */ int flags; /* 92 4 */ /* size: 96, cachelines: 2, members: 6 */ /* last cacheline: 32 bytes */ }; 8 bytes were saved. Signed-off-by: Nikola Pajkovsky Reviewed-by: Paul Dale Reviewed-by: Tom Cosgrove Reviewed-by: Neil Horman (Merged from https://github.com/openssl/openssl/pull/28185) --- diff --git a/crypto/bn/bn_local.h b/crypto/bn/bn_local.h index b5be37ba973..7777a1775fb 100644 --- a/crypto/bn/bn_local.h +++ b/crypto/bn/bn_local.h @@ -257,7 +257,6 @@ struct bignum_st { /* Used for montgomery multiplication */ struct bn_mont_ctx_st { - int ri; /* number of bits in R */ BIGNUM RR; /* used to convert to montgomery form, possibly zero-padded */ BIGNUM N; /* The modulus */ @@ -266,6 +265,7 @@ struct bn_mont_ctx_st { BN_ULONG n0[2]; /* least significant word(s) of Ni; (type * changed with 0.9.9, was "BN_ULONG n0;" * before) */ + int ri; /* number of bits in R */ int flags; };