From d55bea555347eef290ea41374c6fad791b0f85fa Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Wed, 5 Feb 2025 07:46:14 -0500 Subject: [PATCH] Reorganize code and reduce header dependencies --- src/lib/base/secmem.h | 10 +++- src/lib/base/sym_algo.cpp | 5 ++ src/lib/base/sym_algo.h | 6 ++- src/lib/block/aes/aes.h | 1 + src/lib/block/aria/aria.h | 1 + src/lib/block/blowfish/blowfish.h | 1 + src/lib/block/camellia/camellia.h | 1 + src/lib/block/cast128/cast128.h | 1 + src/lib/block/des/des.h | 1 + src/lib/block/gost_28147/gost_28147.h | 1 + src/lib/block/idea/idea.h | 1 + src/lib/block/kuznyechik/kuznyechik.cpp | 1 + src/lib/block/noekeon/noekeon.h | 1 + src/lib/block/seed/seed.h | 1 + src/lib/block/serpent/serpent.h | 1 + src/lib/block/shacal2/shacal2.h | 1 + src/lib/block/sm4/sm4.h | 1 + src/lib/block/threefish_512/threefish_512.h | 1 + src/lib/block/twofish/twofish.h | 1 + src/lib/compression/compression.h | 1 + src/lib/entropy/entropy_src.h | 4 +- src/lib/entropy/getentropy/getentropy.cpp | 2 + src/lib/entropy/rdseed/rdseed.cpp | 9 +++- src/lib/entropy/win32_stats/es_win32.cpp | 2 + src/lib/hash/trunc_hash/trunc_hash.cpp | 1 + src/lib/kdf/kdf.h | 9 +--- src/lib/math/numbertheory/monty.h | 1 + src/lib/math/pcurves/pcurves.h | 1 + src/lib/math/pcurves/pcurves_id.h | 1 - .../math/pcurves/pcurves_impl/pcurves_wrap.h | 1 + src/lib/misc/fpe_fe1/fpe_fe1.h | 8 ++- src/lib/misc/hotp/otp.h | 1 + src/lib/modes/cipher_mode.h | 1 + src/lib/modes/mode_pad/mode_pad.h | 1 + src/lib/pk_pad/emsa.h | 4 +- src/lib/pubkey/dl_group/dl_group.h | 1 + src/lib/pubkey/ec_group/ec_apoint.h | 1 + src/lib/pubkey/ec_group/ec_scalar.h | 1 + src/lib/pubkey/kyber/kyber_common/kyber.h | 2 - src/lib/pubkey/mce/polyn_gf2m.h | 1 + src/lib/pubkey/x509_key.h | 1 + src/lib/rng/processor_rng/processor_rng.cpp | 2 +- src/lib/rng/rng.h | 1 - src/lib/stream/stream_cipher.h | 1 + src/lib/tls/asio/asio_stream.h | 1 - src/lib/tls/tls_extensions.h | 1 - src/lib/tls/tls_session.h | 1 - src/lib/utils/bitvector/bitvector.h | 1 + src/lib/utils/bswap.h | 1 + src/lib/utils/concepts.h | 3 +- src/lib/utils/data_src.h | 1 + src/lib/utils/strong_type.h | 6 +-- src/lib/utils/types.h | 1 - src/scripts/dev_tools/file_size_check.py | 49 +++++++++++++++++++ src/tests/tests.h | 1 + 55 files changed, 130 insertions(+), 31 deletions(-) create mode 100755 src/scripts/dev_tools/file_size_check.py diff --git a/src/lib/base/secmem.h b/src/lib/base/secmem.h index 46c96beafb8..12cc18fa6a5 100644 --- a/src/lib/base/secmem.h +++ b/src/lib/base/secmem.h @@ -10,11 +10,14 @@ #include #include // IWYU pragma: export -#include -#include #include #include // IWYU pragma: export +#if !defined(BOTAN_IS_BEING_BUILT) && !defined(BOTAN_DISABLE_DEPRECATED_FEATURES) + // TODO(Botan4) remove this + #include +#endif + namespace Botan { template @@ -59,8 +62,11 @@ inline bool operator!=(const secure_allocator&, const secure_allocator&) { template using secure_vector = std::vector>; + +#if !defined(BOTAN_IS_BEING_BUILT) && !defined(BOTAN_DISABLE_DEPRECATED_FEATURES) template using secure_deque = std::deque>; +#endif // For better compatibility with 1.10 API template diff --git a/src/lib/base/sym_algo.cpp b/src/lib/base/sym_algo.cpp index 63ebc8e661e..90a0c5d2081 100644 --- a/src/lib/base/sym_algo.cpp +++ b/src/lib/base/sym_algo.cpp @@ -6,10 +6,15 @@ #include +#include #include namespace Botan { +void SymmetricAlgorithm::set_key(const OctetString& key) { + set_key(std::span{key.begin(), key.length()}); +} + void SymmetricAlgorithm::throw_key_not_set_error() const { throw Key_Not_Set(name()); } diff --git a/src/lib/base/sym_algo.h b/src/lib/base/sym_algo.h index 96546281749..f3ea29b84a4 100644 --- a/src/lib/base/sym_algo.h +++ b/src/lib/base/sym_algo.h @@ -8,13 +8,15 @@ #ifndef BOTAN_SYMMETRIC_ALGORITHM_H_ #define BOTAN_SYMMETRIC_ALGORITHM_H_ -#include #include +#include #include namespace Botan { +class OctetString; + /** * Represents the length requirements on an algorithm key */ @@ -110,7 +112,7 @@ class BOTAN_PUBLIC_API(2, 0) SymmetricAlgorithm { * Set the symmetric key of this object. * @param key the SymmetricKey to be set. */ - void set_key(const SymmetricKey& key) { set_key(std::span{key.begin(), key.length()}); } + void set_key(const OctetString& key); /** * Set the symmetric key of this object. diff --git a/src/lib/block/aes/aes.h b/src/lib/block/aes/aes.h index 6676aedf574..ad2bc62278c 100644 --- a/src/lib/block/aes/aes.h +++ b/src/lib/block/aes/aes.h @@ -9,6 +9,7 @@ #define BOTAN_AES_H_ #include +#include namespace Botan { diff --git a/src/lib/block/aria/aria.h b/src/lib/block/aria/aria.h index 4391219d69e..f18bc105b17 100644 --- a/src/lib/block/aria/aria.h +++ b/src/lib/block/aria/aria.h @@ -17,6 +17,7 @@ #define BOTAN_ARIA_H_ #include +#include namespace Botan { diff --git a/src/lib/block/blowfish/blowfish.h b/src/lib/block/blowfish/blowfish.h index 982927b757d..2befc8b2e8c 100644 --- a/src/lib/block/blowfish/blowfish.h +++ b/src/lib/block/blowfish/blowfish.h @@ -9,6 +9,7 @@ #define BOTAN_BLOWFISH_H_ #include +#include namespace Botan { diff --git a/src/lib/block/camellia/camellia.h b/src/lib/block/camellia/camellia.h index 065caf0a480..a072149b2a6 100644 --- a/src/lib/block/camellia/camellia.h +++ b/src/lib/block/camellia/camellia.h @@ -9,6 +9,7 @@ #define BOTAN_CAMELLIA_H_ #include +#include namespace Botan { diff --git a/src/lib/block/cast128/cast128.h b/src/lib/block/cast128/cast128.h index 33d16f97d5f..0efcc04384f 100644 --- a/src/lib/block/cast128/cast128.h +++ b/src/lib/block/cast128/cast128.h @@ -9,6 +9,7 @@ #define BOTAN_CAST128_H_ #include +#include namespace Botan { diff --git a/src/lib/block/des/des.h b/src/lib/block/des/des.h index fd46b0919ef..cc67cf46bd6 100644 --- a/src/lib/block/des/des.h +++ b/src/lib/block/des/des.h @@ -9,6 +9,7 @@ #define BOTAN_DES_H_ #include +#include namespace Botan { diff --git a/src/lib/block/gost_28147/gost_28147.h b/src/lib/block/gost_28147/gost_28147.h index bb0f1991172..6a57b3162fa 100644 --- a/src/lib/block/gost_28147/gost_28147.h +++ b/src/lib/block/gost_28147/gost_28147.h @@ -9,6 +9,7 @@ #define BOTAN_GOST_28147_89_H_ #include +#include namespace Botan { diff --git a/src/lib/block/idea/idea.h b/src/lib/block/idea/idea.h index 1d484edfb32..c38e473376a 100644 --- a/src/lib/block/idea/idea.h +++ b/src/lib/block/idea/idea.h @@ -9,6 +9,7 @@ #define BOTAN_IDEA_H_ #include +#include namespace Botan { diff --git a/src/lib/block/kuznyechik/kuznyechik.cpp b/src/lib/block/kuznyechik/kuznyechik.cpp index b8a43b21a55..766f7c0705f 100644 --- a/src/lib/block/kuznyechik/kuznyechik.cpp +++ b/src/lib/block/kuznyechik/kuznyechik.cpp @@ -13,6 +13,7 @@ #include #include +#include namespace Botan { diff --git a/src/lib/block/noekeon/noekeon.h b/src/lib/block/noekeon/noekeon.h index fb0bb6490b3..52df9bfde86 100644 --- a/src/lib/block/noekeon/noekeon.h +++ b/src/lib/block/noekeon/noekeon.h @@ -9,6 +9,7 @@ #define BOTAN_NOEKEON_H_ #include +#include namespace Botan { diff --git a/src/lib/block/seed/seed.h b/src/lib/block/seed/seed.h index 708d658ec5e..4add7125efc 100644 --- a/src/lib/block/seed/seed.h +++ b/src/lib/block/seed/seed.h @@ -9,6 +9,7 @@ #define BOTAN_SEED_H_ #include +#include namespace Botan { diff --git a/src/lib/block/serpent/serpent.h b/src/lib/block/serpent/serpent.h index 2c2447064d0..c09ba815ab4 100644 --- a/src/lib/block/serpent/serpent.h +++ b/src/lib/block/serpent/serpent.h @@ -9,6 +9,7 @@ #define BOTAN_SERPENT_H_ #include +#include namespace Botan { diff --git a/src/lib/block/shacal2/shacal2.h b/src/lib/block/shacal2/shacal2.h index 50ad76a01ee..0fc4e7726a8 100644 --- a/src/lib/block/shacal2/shacal2.h +++ b/src/lib/block/shacal2/shacal2.h @@ -9,6 +9,7 @@ #define BOTAN_SHACAL2_H_ #include +#include namespace Botan { diff --git a/src/lib/block/sm4/sm4.h b/src/lib/block/sm4/sm4.h index 0dec1f760ec..cc2ab092134 100644 --- a/src/lib/block/sm4/sm4.h +++ b/src/lib/block/sm4/sm4.h @@ -9,6 +9,7 @@ #define BOTAN_SM4_H_ #include +#include namespace Botan { diff --git a/src/lib/block/threefish_512/threefish_512.h b/src/lib/block/threefish_512/threefish_512.h index 3549c26c13e..4624223abe6 100644 --- a/src/lib/block/threefish_512/threefish_512.h +++ b/src/lib/block/threefish_512/threefish_512.h @@ -9,6 +9,7 @@ #define BOTAN_THREEFISH_512_H_ #include +#include namespace Botan { diff --git a/src/lib/block/twofish/twofish.h b/src/lib/block/twofish/twofish.h index cd78c736ecc..48cb9df10d7 100644 --- a/src/lib/block/twofish/twofish.h +++ b/src/lib/block/twofish/twofish.h @@ -9,6 +9,7 @@ #define BOTAN_TWOFISH_H_ #include +#include namespace Botan { diff --git a/src/lib/compression/compression.h b/src/lib/compression/compression.h index d34cd6f234e..4ebf6cb540e 100644 --- a/src/lib/compression/compression.h +++ b/src/lib/compression/compression.h @@ -10,6 +10,7 @@ #include #include +#include #include namespace Botan { diff --git a/src/lib/entropy/entropy_src.h b/src/lib/entropy/entropy_src.h index 7385ee9057e..4623d61d22e 100644 --- a/src/lib/entropy/entropy_src.h +++ b/src/lib/entropy/entropy_src.h @@ -8,11 +8,11 @@ #ifndef BOTAN_ENTROPY_H_ #define BOTAN_ENTROPY_H_ -#include -#include +#include #include #include #include +#include #include namespace Botan { diff --git a/src/lib/entropy/getentropy/getentropy.cpp b/src/lib/entropy/getentropy/getentropy.cpp index 5cf94b114c4..8cb36d319b7 100644 --- a/src/lib/entropy/getentropy/getentropy.cpp +++ b/src/lib/entropy/getentropy/getentropy.cpp @@ -6,6 +6,8 @@ */ #include + +#include #include // macOS and Android include it in sys/random.h instead diff --git a/src/lib/entropy/rdseed/rdseed.cpp b/src/lib/entropy/rdseed/rdseed.cpp index 18e04ac1903..fc671049058 100644 --- a/src/lib/entropy/rdseed/rdseed.cpp +++ b/src/lib/entropy/rdseed/rdseed.cpp @@ -8,10 +8,13 @@ #include +#include #include #include -#include +#if !defined(BOTAN_USE_GCC_INLINE_ASM) + #include +#endif namespace Botan { @@ -48,7 +51,11 @@ BOTAN_FUNC_ISA("rdseed") bool read_rdseed(secure_vector& seed) { } // Intel suggests pausing if RDSEED fails. +#if defined(BOTAN_USE_GCC_INLINE_ASM) + asm volatile("pause"); +#else _mm_pause(); +#endif } return false; // failed to produce an output after many attempts diff --git a/src/lib/entropy/win32_stats/es_win32.cpp b/src/lib/entropy/win32_stats/es_win32.cpp index 5cc5492ef77..5a589331a13 100644 --- a/src/lib/entropy/win32_stats/es_win32.cpp +++ b/src/lib/entropy/win32_stats/es_win32.cpp @@ -6,6 +6,8 @@ #include +#include + #define NOMINMAX 1 #define _WINSOCKAPI_ // stop windows.h including winsock.h #include diff --git a/src/lib/hash/trunc_hash/trunc_hash.cpp b/src/lib/hash/trunc_hash/trunc_hash.cpp index 869f365ac7d..6d422390db8 100644 --- a/src/lib/hash/trunc_hash/trunc_hash.cpp +++ b/src/lib/hash/trunc_hash/trunc_hash.cpp @@ -10,6 +10,7 @@ #include #include +#include namespace Botan { diff --git a/src/lib/kdf/kdf.h b/src/lib/kdf/kdf.h index 355331f5eb6..12cefc45d30 100644 --- a/src/lib/kdf/kdf.h +++ b/src/lib/kdf/kdf.h @@ -10,9 +10,9 @@ #define BOTAN_KDF_BASE_H_ #include -#include #include #include +#include #include #include #include @@ -277,16 +277,11 @@ class BOTAN_PUBLIC_API(2, 0) KDF { BOTAN_DEPRECATED("Use KDF::create") inline KDF* get_kdf(std::string_view algo_spec) { - auto kdf = KDF::create(algo_spec); - if(kdf) { - return kdf.release(); - } - if(algo_spec == "Raw") { return nullptr; } - throw Algorithm_Not_Found(algo_spec); + return KDF::create_or_throw(algo_spec).release(); } } // namespace Botan diff --git a/src/lib/math/numbertheory/monty.h b/src/lib/math/numbertheory/monty.h index bd3186410bc..c1e53149c44 100644 --- a/src/lib/math/numbertheory/monty.h +++ b/src/lib/math/numbertheory/monty.h @@ -10,6 +10,7 @@ #include #include +#include namespace Botan { diff --git a/src/lib/math/pcurves/pcurves.h b/src/lib/math/pcurves/pcurves.h index 5191cf27f3c..5d49715bddd 100644 --- a/src/lib/math/pcurves/pcurves.h +++ b/src/lib/math/pcurves/pcurves.h @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include diff --git a/src/lib/math/pcurves/pcurves_id.h b/src/lib/math/pcurves/pcurves_id.h index ad42ef62cec..3f1ebccebd3 100644 --- a/src/lib/math/pcurves/pcurves_id.h +++ b/src/lib/math/pcurves/pcurves_id.h @@ -7,7 +7,6 @@ #ifndef BOTAN_PCURVES_ID_H_ #define BOTAN_PCURVES_ID_H_ -#include #include #include #include diff --git a/src/lib/math/pcurves/pcurves_impl/pcurves_wrap.h b/src/lib/math/pcurves/pcurves_impl/pcurves_wrap.h index 3f187fe2a3d..3ef8bb4e528 100644 --- a/src/lib/math/pcurves/pcurves_impl/pcurves_wrap.h +++ b/src/lib/math/pcurves/pcurves_impl/pcurves_wrap.h @@ -9,6 +9,7 @@ #include #include +#include namespace Botan::PCurve { diff --git a/src/lib/misc/fpe_fe1/fpe_fe1.h b/src/lib/misc/fpe_fe1/fpe_fe1.h index d27cdc517ee..7597a91c826 100644 --- a/src/lib/misc/fpe_fe1/fpe_fe1.h +++ b/src/lib/misc/fpe_fe1/fpe_fe1.h @@ -9,7 +9,9 @@ #define BOTAN_FPE_FE1_H_ #include +#include #include +#include namespace Botan { @@ -83,6 +85,8 @@ class BOTAN_PUBLIC_API(2, 5) FPE_FE1 final : public SymmetricAlgorithm { namespace FPE { +class OctetString; + /** * Format Preserving Encryption using the scheme FE1 from the paper * "Format-Preserving Encryption" by Bellare, Rogaway, et al @@ -98,7 +102,7 @@ namespace FPE { * may be insecure for some values of n. Prefer FPE_FE1 class */ BigInt BOTAN_PUBLIC_API(2, 0) - fe1_encrypt(const BigInt& n, const BigInt& X, const SymmetricKey& key, const std::vector& tweak); + fe1_encrypt(const BigInt& n, const BigInt& X, const OctetString& key, const std::vector& tweak); /** * Decrypt X from and onto the group Z_n using key and tweak @@ -111,7 +115,7 @@ BigInt BOTAN_PUBLIC_API(2, 0) * may be insecure for some values of n. Prefer FPE_FE1 class */ BigInt BOTAN_PUBLIC_API(2, 0) - fe1_decrypt(const BigInt& n, const BigInt& X, const SymmetricKey& key, const std::vector& tweak); + fe1_decrypt(const BigInt& n, const BigInt& X, const OctetString& key, const std::vector& tweak); } // namespace FPE diff --git a/src/lib/misc/hotp/otp.h b/src/lib/misc/hotp/otp.h index af859b3f44d..20a5caec020 100644 --- a/src/lib/misc/hotp/otp.h +++ b/src/lib/misc/hotp/otp.h @@ -9,6 +9,7 @@ #define BOTAN_ONE_TIME_PASSWORDS_H_ #include +#include #include namespace Botan { diff --git a/src/lib/modes/cipher_mode.h b/src/lib/modes/cipher_mode.h index 1fe21239c03..a6aad120fb0 100644 --- a/src/lib/modes/cipher_mode.h +++ b/src/lib/modes/cipher_mode.h @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include diff --git a/src/lib/modes/mode_pad/mode_pad.h b/src/lib/modes/mode_pad/mode_pad.h index f73a9031f23..64ee0881d91 100644 --- a/src/lib/modes/mode_pad/mode_pad.h +++ b/src/lib/modes/mode_pad/mode_pad.h @@ -10,6 +10,7 @@ #define BOTAN_MODE_PADDING_H_ #include +#include #include namespace Botan { diff --git a/src/lib/pk_pad/emsa.h b/src/lib/pk_pad/emsa.h index dd253042b02..e0b76b59c69 100644 --- a/src/lib/pk_pad/emsa.h +++ b/src/lib/pk_pad/emsa.h @@ -8,8 +8,10 @@ #ifndef BOTAN_PUBKEY_EMSA_H_ #define BOTAN_PUBKEY_EMSA_H_ -#include +#include +#include #include +#include namespace Botan { diff --git a/src/lib/pubkey/dl_group/dl_group.h b/src/lib/pubkey/dl_group/dl_group.h index 0db4d59a775..6b91d066226 100644 --- a/src/lib/pubkey/dl_group/dl_group.h +++ b/src/lib/pubkey/dl_group/dl_group.h @@ -9,6 +9,7 @@ #define BOTAN_DL_PARAM_H_ #include +#include #include namespace Botan { diff --git a/src/lib/pubkey/ec_group/ec_apoint.h b/src/lib/pubkey/ec_group/ec_apoint.h index af4aeddcf55..f69417d84cb 100644 --- a/src/lib/pubkey/ec_group/ec_apoint.h +++ b/src/lib/pubkey/ec_group/ec_apoint.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include diff --git a/src/lib/pubkey/ec_group/ec_scalar.h b/src/lib/pubkey/ec_group/ec_scalar.h index f3157432525..8afbc37cf3f 100644 --- a/src/lib/pubkey/ec_group/ec_scalar.h +++ b/src/lib/pubkey/ec_group/ec_scalar.h @@ -9,6 +9,7 @@ #include #include +#include #include #include #include diff --git a/src/lib/pubkey/kyber/kyber_common/kyber.h b/src/lib/pubkey/kyber/kyber_common/kyber.h index e14fb4da223..78d1cd61293 100644 --- a/src/lib/pubkey/kyber/kyber_common/kyber.h +++ b/src/lib/pubkey/kyber/kyber_common/kyber.h @@ -14,8 +14,6 @@ #ifndef BOTAN_KYBER_COMMON_H_ #define BOTAN_KYBER_COMMON_H_ -#include -#include #include #include diff --git a/src/lib/pubkey/mce/polyn_gf2m.h b/src/lib/pubkey/mce/polyn_gf2m.h index 12f256ad2aa..964d4ec082e 100644 --- a/src/lib/pubkey/mce/polyn_gf2m.h +++ b/src/lib/pubkey/mce/polyn_gf2m.h @@ -13,6 +13,7 @@ #define BOTAN_POLYN_GF2M_H_ #include +#include #include namespace Botan { diff --git a/src/lib/pubkey/x509_key.h b/src/lib/pubkey/x509_key.h index 07738224bf4..fe7adf965fd 100644 --- a/src/lib/pubkey/x509_key.h +++ b/src/lib/pubkey/x509_key.h @@ -10,6 +10,7 @@ #include #include +#include #include #include diff --git a/src/lib/rng/processor_rng/processor_rng.cpp b/src/lib/rng/processor_rng/processor_rng.cpp index 9c85b4b8898..239ad85f00d 100644 --- a/src/lib/rng/processor_rng/processor_rng.cpp +++ b/src/lib/rng/processor_rng/processor_rng.cpp @@ -9,7 +9,7 @@ #include #include -#if defined(BOTAN_TARGET_CPU_IS_X86_FAMILY) +#if defined(BOTAN_TARGET_CPU_IS_X86_FAMILY) && !defined(BOTAN_USE_GCC_INLINE_ASM) #include #endif diff --git a/src/lib/rng/rng.h b/src/lib/rng/rng.h index 1cf1a912111..e84d84c421d 100644 --- a/src/lib/rng/rng.h +++ b/src/lib/rng/rng.h @@ -11,7 +11,6 @@ #include #include -#include #include #include diff --git a/src/lib/stream/stream_cipher.h b/src/lib/stream/stream_cipher.h index 229f59f340d..f352be6ebf7 100644 --- a/src/lib/stream/stream_cipher.h +++ b/src/lib/stream/stream_cipher.h @@ -9,6 +9,7 @@ #define BOTAN_STREAM_CIPHER_H_ #include +#include #include #include #include diff --git a/src/lib/tls/asio/asio_stream.h b/src/lib/tls/asio/asio_stream.h index 20caaaf0f7d..519894af4ff 100644 --- a/src/lib/tls/asio/asio_stream.h +++ b/src/lib/tls/asio/asio_stream.h @@ -31,7 +31,6 @@ #include #include - #include #include #include diff --git a/src/lib/tls/tls_extensions.h b/src/lib/tls/tls_extensions.h index 7d8f0f5d5b4..bb1c7b22cb2 100644 --- a/src/lib/tls/tls_extensions.h +++ b/src/lib/tls/tls_extensions.h @@ -22,7 +22,6 @@ #include #include -#include #include #include #include diff --git a/src/lib/tls/tls_session.h b/src/lib/tls/tls_session.h index 3fae7507381..82fca319146 100644 --- a/src/lib/tls/tls_session.h +++ b/src/lib/tls/tls_session.h @@ -18,7 +18,6 @@ #include #include -#include #include #include #include diff --git a/src/lib/utils/bitvector/bitvector.h b/src/lib/utils/bitvector/bitvector.h index 9a98e00ab4b..5ada5647268 100644 --- a/src/lib/utils/bitvector/bitvector.h +++ b/src/lib/utils/bitvector/bitvector.h @@ -23,6 +23,7 @@ #include #include +#include #include #include #include diff --git a/src/lib/utils/bswap.h b/src/lib/utils/bswap.h index d4ef8392e07..d7bf65fdbae 100644 --- a/src/lib/utils/bswap.h +++ b/src/lib/utils/bswap.h @@ -15,6 +15,7 @@ #include #include +#include namespace Botan { diff --git a/src/lib/utils/concepts.h b/src/lib/utils/concepts.h index 80c80b1faf7..1af3d1734cd 100644 --- a/src/lib/utils/concepts.h +++ b/src/lib/utils/concepts.h @@ -11,10 +11,9 @@ #include -#include #include #include -#include +#include #include #include #include diff --git a/src/lib/utils/data_src.h b/src/lib/utils/data_src.h index 9fe0fc0b382..893f86d2518 100644 --- a/src/lib/utils/data_src.h +++ b/src/lib/utils/data_src.h @@ -11,6 +11,7 @@ #include #include +#include #include #include #include diff --git a/src/lib/utils/strong_type.h b/src/lib/utils/strong_type.h index 4603b1296ea..5f0aa24847f 100644 --- a/src/lib/utils/strong_type.h +++ b/src/lib/utils/strong_type.h @@ -9,11 +9,11 @@ #ifndef BOTAN_STRONG_TYPE_H_ #define BOTAN_STRONG_TYPE_H_ -#include -#include - #include +#include +#include + namespace Botan { /** diff --git a/src/lib/utils/types.h b/src/lib/utils/types.h index 78d07a602e9..4af25c8e661 100644 --- a/src/lib/utils/types.h +++ b/src/lib/utils/types.h @@ -14,7 +14,6 @@ #include // IWYU pragma: export #include // IWYU pragma: export #include // IWYU pragma: export -#include // IWYU pragma: export /** * MSVC does define __cplusplus but pins it at 199711L, because "legacy". diff --git a/src/scripts/dev_tools/file_size_check.py b/src/scripts/dev_tools/file_size_check.py new file mode 100755 index 00000000000..0a6ee70eaa0 --- /dev/null +++ b/src/scripts/dev_tools/file_size_check.py @@ -0,0 +1,49 @@ +#!/usr/bin/python + +import json +import subprocess +import re +import sys + +def lines_in(f): + lines = 0 + for l in f.decode('utf8').splitlines(): + if l == '': + continue + + if l.startswith('#'): + continue + lines += 1 + return lines + +def run_cc(cmd): + preproc = subprocess.run(cmd.split(' '), stdout=subprocess.PIPE) + + return lines_in(preproc.stdout) + +cc = json.loads(open('build/compile_commands.json').read()) + +src_file = re.compile('-E src/lib/([a-z0-9/_]+.cpp) ') + +search_for = None + +if len(sys.argv) == 2: + search_for = re.compile(sys.argv[1]) + +total_lines = 0 +for c in cc: + cmd = c['command'].replace(' -c ', ' -E ').split(' -o')[0] + " -o -" + file_name = src_file.search(cmd) + if file_name is None: + continue + + file_name = file_name.group(1) + if search_for is not None and search_for.search(file_name) is None: + continue + + lines = run_cc(cmd) + total_lines += lines + print(lines, file_name) + sys.stdout.flush() + +print(total_lines, "total") diff --git a/src/tests/tests.h b/src/tests/tests.h index 284cf287e4f..6a775c031f6 100644 --- a/src/tests/tests.h +++ b/src/tests/tests.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include