]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
bn: save space in bn_mont_ctx_st by reordering elements
authorNikola Pajkovsky <nikolap@openssl.org>
Wed, 6 Aug 2025 09:58:57 +0000 (11:58 +0200)
committerNeil Horman <nhorman@openssl.org>
Thu, 7 Aug 2025 11:52:33 +0000 (07:52 -0400)
 # 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 <nikolap@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/28185)

crypto/bn/bn_local.h

index b5be37ba973e392a3ed85ccd8178e56c0b2f836b..7777a1775fb790c8cf939514bb033db954e7442f 100644 (file)
@@ -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;
 };