Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorganize code and reduce header dependencies #4638

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/lib/base/secmem.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@

#include <botan/allocator.h>
#include <botan/types.h> // IWYU pragma: export
#include <algorithm>
#include <deque>
#include <type_traits>
#include <vector> // IWYU pragma: export

#if !defined(BOTAN_IS_BEING_BUILT) && !defined(BOTAN_DISABLE_DEPRECATED_FEATURES)
// TODO(Botan4) remove this
#include <deque>
#endif

namespace Botan {

template <typename T>
Expand Down Expand Up @@ -59,8 +62,11 @@ inline bool operator!=(const secure_allocator<T>&, const secure_allocator<U>&) {

template <typename T>
using secure_vector = std::vector<T, secure_allocator<T>>;

#if !defined(BOTAN_IS_BEING_BUILT) && !defined(BOTAN_DISABLE_DEPRECATED_FEATURES)
template <typename T>
using secure_deque = std::deque<T, secure_allocator<T>>;
#endif

// For better compatibility with 1.10 API
template <typename T>
Expand Down
5 changes: 5 additions & 0 deletions src/lib/base/sym_algo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@

#include <botan/sym_algo.h>

#include <botan/symkey.h>
#include <botan/exceptn.h>

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());
}
Expand Down
6 changes: 4 additions & 2 deletions src/lib/base/sym_algo.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
#ifndef BOTAN_SYMMETRIC_ALGORITHM_H_
#define BOTAN_SYMMETRIC_ALGORITHM_H_

#include <botan/symkey.h>
#include <botan/types.h>

#include <string>
#include <span>

namespace Botan {

class OctetString;

/**
* Represents the length requirements on an algorithm key
*/
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/lib/block/aes/aes.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define BOTAN_AES_H_

#include <botan/block_cipher.h>
#include <botan/secmem.h>

namespace Botan {

Expand Down
1 change: 1 addition & 0 deletions src/lib/block/aria/aria.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define BOTAN_ARIA_H_

#include <botan/block_cipher.h>
#include <botan/secmem.h>

namespace Botan {

Expand Down
1 change: 1 addition & 0 deletions src/lib/block/blowfish/blowfish.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define BOTAN_BLOWFISH_H_

#include <botan/block_cipher.h>
#include <botan/secmem.h>

namespace Botan {

Expand Down
1 change: 1 addition & 0 deletions src/lib/block/camellia/camellia.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define BOTAN_CAMELLIA_H_

#include <botan/block_cipher.h>
#include <botan/secmem.h>

namespace Botan {

Expand Down
1 change: 1 addition & 0 deletions src/lib/block/cast128/cast128.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define BOTAN_CAST128_H_

#include <botan/block_cipher.h>
#include <botan/secmem.h>

namespace Botan {

Expand Down
1 change: 1 addition & 0 deletions src/lib/block/des/des.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define BOTAN_DES_H_

#include <botan/block_cipher.h>
#include <botan/secmem.h>

namespace Botan {

Expand Down
1 change: 1 addition & 0 deletions src/lib/block/gost_28147/gost_28147.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define BOTAN_GOST_28147_89_H_

#include <botan/block_cipher.h>
#include <botan/secmem.h>

namespace Botan {

Expand Down
1 change: 1 addition & 0 deletions src/lib/block/idea/idea.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define BOTAN_IDEA_H_

#include <botan/block_cipher.h>
#include <botan/secmem.h>

namespace Botan {

Expand Down
1 change: 1 addition & 0 deletions src/lib/block/kuznyechik/kuznyechik.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <botan/mem_ops.h>
#include <botan/internal/loadstor.h>
#include <algorithm>

namespace Botan {

Expand Down
1 change: 1 addition & 0 deletions src/lib/block/noekeon/noekeon.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define BOTAN_NOEKEON_H_

#include <botan/block_cipher.h>
#include <botan/secmem.h>

namespace Botan {

Expand Down
1 change: 1 addition & 0 deletions src/lib/block/seed/seed.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define BOTAN_SEED_H_

#include <botan/block_cipher.h>
#include <botan/secmem.h>

namespace Botan {

Expand Down
1 change: 1 addition & 0 deletions src/lib/block/serpent/serpent.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define BOTAN_SERPENT_H_

#include <botan/block_cipher.h>
#include <botan/secmem.h>

namespace Botan {

Expand Down
1 change: 1 addition & 0 deletions src/lib/block/shacal2/shacal2.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define BOTAN_SHACAL2_H_

#include <botan/block_cipher.h>
#include <botan/secmem.h>

namespace Botan {

Expand Down
1 change: 1 addition & 0 deletions src/lib/block/sm4/sm4.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define BOTAN_SM4_H_

#include <botan/block_cipher.h>
#include <botan/secmem.h>

namespace Botan {

Expand Down
1 change: 1 addition & 0 deletions src/lib/block/threefish_512/threefish_512.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define BOTAN_THREEFISH_512_H_

#include <botan/block_cipher.h>
#include <botan/secmem.h>

namespace Botan {

Expand Down
1 change: 1 addition & 0 deletions src/lib/block/twofish/twofish.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define BOTAN_TWOFISH_H_

#include <botan/block_cipher.h>
#include <botan/secmem.h>

namespace Botan {

Expand Down
1 change: 1 addition & 0 deletions src/lib/compression/compression.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <botan/exceptn.h>
#include <botan/secmem.h>
#include <memory>
#include <string>

namespace Botan {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/entropy/entropy_src.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
#ifndef BOTAN_ENTROPY_H_
#define BOTAN_ENTROPY_H_

#include <botan/rng.h>
#include <botan/secmem.h>
#include <botan/api.h>
#include <chrono>
#include <memory>
#include <string>
#include <string_view>
#include <vector>

namespace Botan {
Expand Down
2 changes: 2 additions & 0 deletions src/lib/entropy/getentropy/getentropy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/

#include <botan/internal/getentropy.h>

#include <botan/rng.h>
#include <unistd.h>

// macOS and Android include it in sys/random.h instead
Expand Down
9 changes: 8 additions & 1 deletion src/lib/entropy/rdseed/rdseed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@

#include <botan/internal/rdseed.h>

#include <botan/rng.h>
#include <botan/compiler.h>
#include <botan/internal/cpuid.h>

#include <immintrin.h>
#if !defined(BOTAN_USE_GCC_INLINE_ASM)
#include <immintrin.h>
#endif

namespace Botan {

Expand Down Expand Up @@ -48,7 +51,11 @@ BOTAN_FUNC_ISA("rdseed") bool read_rdseed(secure_vector<uint32_t>& 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
Expand Down
2 changes: 2 additions & 0 deletions src/lib/entropy/win32_stats/es_win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include <botan/internal/es_win32.h>

#include <botan/rng.h>

#define NOMINMAX 1
#define _WINSOCKAPI_ // stop windows.h including winsock.h
#include <windows.h>
Expand Down
1 change: 1 addition & 0 deletions src/lib/hash/trunc_hash/trunc_hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <botan/exceptn.h>
#include <botan/internal/fmt.h>
#include <algorithm>

namespace Botan {

Expand Down
9 changes: 2 additions & 7 deletions src/lib/kdf/kdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#define BOTAN_KDF_BASE_H_

#include <botan/concepts.h>
#include <botan/exceptn.h>
#include <botan/mem_ops.h>
#include <botan/secmem.h>
#include <memory>
#include <span>
#include <string>
#include <string_view>
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/lib/math/numbertheory/monty.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <botan/bigint.h>

#include <botan/internal/ct_utils.h>
#include <memory>

namespace Botan {

Expand Down
1 change: 1 addition & 0 deletions src/lib/math/pcurves/pcurves.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <botan/types.h>
#include <array>
#include <optional>
#include <memory>
#include <span>
#include <string_view>
#include <vector>
Expand Down
1 change: 0 additions & 1 deletion src/lib/math/pcurves/pcurves_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#ifndef BOTAN_PCURVES_ID_H_
#define BOTAN_PCURVES_ID_H_

#include <botan/secmem.h>
#include <botan/types.h>
#include <optional>
#include <string>
Expand Down
1 change: 1 addition & 0 deletions src/lib/math/pcurves/pcurves_impl/pcurves_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <botan/internal/pcurves.h>
#include <botan/internal/pcurves_impl.h>
#include <botan/exceptn.h>

namespace Botan::PCurve {

Expand Down
8 changes: 6 additions & 2 deletions src/lib/misc/fpe_fe1/fpe_fe1.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
#define BOTAN_FPE_FE1_H_

#include <botan/bigint.h>
#include <botan/symkey.h>
#include <botan/sym_algo.h>
#include <memory>

namespace Botan {

Expand Down Expand Up @@ -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
Expand All @@ -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<uint8_t>& tweak);
fe1_encrypt(const BigInt& n, const BigInt& X, const OctetString& key, const std::vector<uint8_t>& tweak);

/**
* Decrypt X from and onto the group Z_n using key and tweak
Expand All @@ -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<uint8_t>& tweak);
fe1_decrypt(const BigInt& n, const BigInt& X, const OctetString& key, const std::vector<uint8_t>& tweak);

} // namespace FPE

Expand Down
1 change: 1 addition & 0 deletions src/lib/misc/hotp/otp.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define BOTAN_ONE_TIME_PASSWORDS_H_

#include <botan/mac.h>
#include <botan/symkey.h>
#include <chrono>

namespace Botan {
Expand Down
1 change: 1 addition & 0 deletions src/lib/modes/cipher_mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <botan/exceptn.h>
#include <botan/secmem.h>
#include <botan/sym_algo.h>
#include <memory>
#include <span>
#include <string>
#include <string_view>
Expand Down
1 change: 1 addition & 0 deletions src/lib/modes/mode_pad/mode_pad.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define BOTAN_MODE_PADDING_H_

#include <botan/secmem.h>
#include <memory>
#include <string>

namespace Botan {
Expand Down
Loading
Loading