From 077e968fe7668997dde3f11639a33f7949f832f0 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Wed, 29 Apr 2026 11:03:12 +0200 Subject: [PATCH] Introduce `LTC_NO_STRUCT_PADDING`. Directly use it in `ltc_rsa_op_parameters`. Signed-off-by: Steffen Jaeckel --- .ci/build_options.sh | 1 + doc/crypt.tex | 4 ++++ src/headers/tomcrypt_custom.h | 3 +++ src/headers/tomcrypt_pk.h | 4 +++- 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.ci/build_options.sh b/.ci/build_options.sh index 85048be41..ba1f250b6 100755 --- a/.ci/build_options.sh +++ b/.ci/build_options.sh @@ -18,6 +18,7 @@ options=( -DLTC_MECC_FP -DLTC_NO_TABLES -DLTC_NO_FAST +-DLTC_NO_STRUCT_PADDING -DLTC_NO_ASM -DLTC_NO_DEPRECATED_APIS -DLTC_NO_ECC_TIMING_RESISTANT diff --git a/doc/crypt.tex b/doc/crypt.tex index e29cc2aba..7e6913922 100644 --- a/doc/crypt.tex +++ b/doc/crypt.tex @@ -9195,6 +9195,10 @@ \subsection{LTC\_CLEAN\_STACK} When this functions is defined the functions that store key material on the stack will clean up afterwards. Assumes that you have no memory paging with the stack. +\subsection{LTC\_NO\_STRUCT\_PADDING} +Per default the library adds padding to some structs, which are likely to be extended sometime in the future, in order +to provide ABI compatibility to previous versions. To trim down struct sizes where possible, define this macro. + \subsection{LTC\_TEST} When this has been defined the various self--test functions (for ciphers, hashes, prngs, etc) are included in the build. This is the default configuration. If LTC\_NO\_TEST has been defined, the testing routines will be compacted and only return CRYPT\_NOP. diff --git a/src/headers/tomcrypt_custom.h b/src/headers/tomcrypt_custom.h index 75e738fc9..68ef4379f 100644 --- a/src/headers/tomcrypt_custom.h +++ b/src/headers/tomcrypt_custom.h @@ -153,6 +153,9 @@ /* clean the stack of functions which put private information on stack */ /* #define LTC_CLEAN_STACK */ +/* enable this in case you want to disable padding elements in structs */ +/* #define LTC_NO_STRUCT_PADDING */ + /* disable all file related functions */ /* #define LTC_NO_FILE */ diff --git a/src/headers/tomcrypt_pk.h b/src/headers/tomcrypt_pk.h index b2d1e8bf3..ac48452bc 100644 --- a/src/headers/tomcrypt_pk.h +++ b/src/headers/tomcrypt_pk.h @@ -125,8 +125,10 @@ typedef struct ltc_rsa_op_parameters { const unsigned char *lparam; unsigned long lparamlen; } crypt; +#ifndef LTC_NO_STRUCT_PADDING /* let's make space for potential future extensions */ - ulong64 dummy[8]; + void* padding[8]; +#endif } u; } ltc_rsa_op_parameters;