Skip to content

Commit

Permalink
Split compiler.h into two headers
Browse files Browse the repository at this point in the history
Parts of compiler.h we want to be internal, but parts are handling API
annotations (BOTAN_PUBLIC_API, etc) which have to be visible.

Split the parts that will always be public into api.h
  • Loading branch information
randombit committed Jan 26, 2025
1 parent 6477d87 commit 69afff9
Show file tree
Hide file tree
Showing 34 changed files with 178 additions and 140 deletions.
1 change: 1 addition & 0 deletions src/lib/block/serpent/serpent_fn.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#ifndef BOTAN_SERPENT_FUNCS_H_
#define BOTAN_SERPENT_FUNCS_H_

#include <botan/compiler.h>
#include <botan/types.h>
#include <botan/internal/rotate.h>

Expand Down
2 changes: 2 additions & 0 deletions src/lib/block/shacal2/shacal2_armv8/shacal2_arvm8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/

#include <botan/internal/shacal2.h>

#include <botan/compiler.h>
#include <arm_neon.h>

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

#include <botan/internal/shacal2.h>

#include <botan/compiler.h>
#include <immintrin.h>

namespace Botan {
Expand Down
1 change: 1 addition & 0 deletions src/lib/entropy/rdseed/rdseed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <botan/internal/rdseed.h>

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

#include <immintrin.h>
Expand Down
1 change: 1 addition & 0 deletions src/lib/filters/out_buf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <botan/internal/out_buf.h>

#include <botan/assert.h>
#include <botan/internal/secqueue.h>

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

#include <botan/argon2.h>

#include <botan/compiler.h>
#include <immintrin.h>

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

#include <botan/argon2.h>

#include <botan/compiler.h>
#include <tmmintrin.h>

namespace Botan {
Expand Down
1 change: 1 addition & 0 deletions src/lib/pbkdf/argon2/argon2pwhash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <botan/argon2.h>

#include <botan/assert.h>
#include <botan/exceptn.h>
#include <botan/internal/fmt.h>
#include <botan/internal/time_utils.h>
Expand Down
6 changes: 2 additions & 4 deletions src/lib/pbkdf/pbkdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <botan/pbkdf.h>

#include <botan/assert.h>
#include <botan/exceptn.h>
#include <botan/internal/scan_name.h>

Expand All @@ -25,8 +26,6 @@ std::unique_ptr<PBKDF> PBKDF::create(std::string_view algo_spec, std::string_vie

#if defined(BOTAN_HAS_PBKDF2)
if(req.algo_name() == "PBKDF2") {
// TODO OpenSSL

if(provider.empty() || provider == "base") {
if(auto mac = MessageAuthenticationCode::create("HMAC(" + req.arg(0) + ")")) {
return std::make_unique<PKCS5_PBKDF2>(std::move(mac));
Expand All @@ -49,8 +48,7 @@ std::unique_ptr<PBKDF> PBKDF::create(std::string_view algo_spec, std::string_vie
}
#endif

BOTAN_UNUSED(req);
BOTAN_UNUSED(provider);
BOTAN_UNUSED(req, provider);

return nullptr;
}
Expand Down
1 change: 1 addition & 0 deletions src/lib/pubkey/classic_mceliece/cmce_parameter_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <botan/cmce_parameter_set.h>

#include <botan/assert.h>
#include <botan/internal/fmt.h>

namespace Botan {
Expand Down
1 change: 1 addition & 0 deletions src/lib/pubkey/mce/gf2m_rootfind_dcmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <botan/internal/polyn_gf2m.h>

#include <botan/assert.h>
#include <botan/exceptn.h>
#include <botan/internal/bit_ops.h>
#include <botan/internal/code_based_util.h>
Expand Down
8 changes: 8 additions & 0 deletions src/lib/pubkey/pubkey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ PK_KEM_Encryptor::PK_KEM_Encryptor(const Public_Key& key, std::string_view param
}
}

PK_KEM_Encryptor::PK_KEM_Encryptor(const Public_Key& key,
RandomNumberGenerator& rng,
std::string_view kem_param,
std::string_view provider) :
PK_KEM_Encryptor(key, kem_param, provider) {
BOTAN_UNUSED(rng);
}

PK_KEM_Encryptor::~PK_KEM_Encryptor() = default;

PK_KEM_Encryptor::PK_KEM_Encryptor(PK_KEM_Encryptor&&) noexcept = default;
Expand Down
5 changes: 1 addition & 4 deletions src/lib/pubkey/pubkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -605,10 +605,7 @@ class BOTAN_PUBLIC_API(2, 0) PK_KEM_Encryptor final {
PK_KEM_Encryptor(const Public_Key& key,
RandomNumberGenerator& rng,
std::string_view kem_param = "",
std::string_view provider = "") :
PK_KEM_Encryptor(key, kem_param, provider) {
BOTAN_UNUSED(rng);
}
std::string_view provider = "");

~PK_KEM_Encryptor();

Expand Down
1 change: 1 addition & 0 deletions src/lib/pubkey/xmss/xmss_address.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#ifndef BOTAN_XMSS_ADDRESS_H_
#define BOTAN_XMSS_ADDRESS_H_

#include <botan/assert.h>
#include <botan/secmem.h>
#include <botan/types.h>

Expand Down
11 changes: 11 additions & 0 deletions src/lib/utils/allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@

namespace Botan {

/*
* Define BOTAN_MALLOC_FN
*/
#if defined(__clang__) || defined(__GNUG__)
#define BOTAN_MALLOC_FN __attribute__((malloc))
#elif defined(_MSC_VER)
#define BOTAN_MALLOC_FN __declspec(restrict)
#else
#define BOTAN_MALLOC_FN
#endif

/**
* Allocate a memory buffer by some method. This should only be used for
* primitive types (uint8_t, uint32_t, etc).
Expand Down
111 changes: 111 additions & 0 deletions src/lib/utils/api.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* (C) 2016,2025 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/

#ifndef BOTAN_API_ANNOTATIONS_H_
#define BOTAN_API_ANNOTATIONS_H_

#include <botan/build.h>

/**
* Used to annotate API exports which are public and supported.
* These APIs will not be broken/removed unless strictly required for
* functionality or security, and only in new major versions.
* @param maj The major version this public API was released in
* @param min The minor version this public API was released in
*/
#define BOTAN_PUBLIC_API(maj, min) BOTAN_DLL

/**
* Used to annotate API exports which are public, but are now deprecated
* and which will be removed in a future major release.
*/
#define BOTAN_DEPRECATED_API(msg) BOTAN_DEPRECATED(msg) BOTAN_DLL

/**
* Used to annotate API exports which are public and can be used by
* applications if needed, but which are intentionally not documented,
* and which may change incompatibly in a future major version.
*/
#define BOTAN_UNSTABLE_API BOTAN_DLL

/**
* Used to annotate API exports which are exported but only for the
* purposes of testing. They should not be used by applications and
* may be removed or changed without notice.
*/
#define BOTAN_TEST_API BOTAN_DLL

/**
* Used to annotate API exports which are exported but only for the
* purposes of fuzzing. They should not be used by applications and
* may be removed or changed without notice.
*
* They are only exported if the fuzzers are being built
*/
#if defined(BOTAN_FUZZERS_ARE_BEING_BUILT)
#define BOTAN_FUZZER_API BOTAN_DLL
#else
#define BOTAN_FUZZER_API
#endif

/*
* Define BOTAN_DEPRECATED
*/
#if !defined(BOTAN_NO_DEPRECATED_WARNINGS) && !defined(BOTAN_AMALGAMATION_H_) && !defined(BOTAN_IS_BEING_BUILT)

#define BOTAN_DEPRECATED(msg) [[deprecated(msg)]]

#if defined(__clang__)
#define BOTAN_DEPRECATED_HEADER(hdr) _Pragma("message \"this header is deprecated\"")
#define BOTAN_FUTURE_INTERNAL_HEADER(hdr) _Pragma("message \"this header will be made internal in the future\"")
#elif defined(_MSC_VER)
#define BOTAN_DEPRECATED_HEADER(hdr) __pragma(message("this header is deprecated"))
#define BOTAN_FUTURE_INTERNAL_HEADER(hdr) __pragma(message("this header will be made internal in the future"))
#elif defined(__GNUC__)
#define BOTAN_DEPRECATED_HEADER(hdr) _Pragma("GCC warning \"this header is deprecated\"")
#define BOTAN_FUTURE_INTERNAL_HEADER(hdr) \
_Pragma("GCC warning \"this header will be made internal in the future\"")
#endif

#endif

#if !defined(BOTAN_DEPRECATED)
#define BOTAN_DEPRECATED(msg)
#endif

#if !defined(BOTAN_DEPRECATED_HEADER)
#define BOTAN_DEPRECATED_HEADER(hdr)
#endif

#if !defined(BOTAN_FUTURE_INTERNAL_HEADER)
#define BOTAN_FUTURE_INTERNAL_HEADER(hdr)
#endif

#if defined(__clang__)
#define BOTAN_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push")
#define BOTAN_DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS \
_Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
#define BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
#define BOTAN_DIAGNOSTIC_POP _Pragma("clang diagnostic pop")
#elif defined(__GNUG__)
#define BOTAN_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push")
#define BOTAN_DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS \
_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
#define BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
#define BOTAN_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop")
#elif defined(_MSC_VER)
#define BOTAN_DIAGNOSTIC_PUSH __pragma(warning(push))
#define BOTAN_DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS __pragma(warning(disable : 4996))
#define BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE __pragma(warning(disable : 4250))
#define BOTAN_DIAGNOSTIC_POP __pragma(warning(pop))
#else
#define BOTAN_DIAGNOSTIC_PUSH
#define BOTAN_DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS
#define BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
#define BOTAN_DIAGNOSTIC_POP
#endif

#endif
2 changes: 1 addition & 1 deletion src/lib/utils/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#ifndef BOTAN_ASSERTION_CHECKING_H_
#define BOTAN_ASSERTION_CHECKING_H_

#include <botan/compiler.h>
#include <botan/api.h>

namespace Botan {

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

#include <botan/types.h>

#include <botan/compiler.h>
#include <botan/internal/bswap.h>

namespace Botan {
Expand Down
2 changes: 2 additions & 0 deletions src/lib/utils/bswap.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include <botan/types.h>

#include <botan/compiler.h>

namespace Botan {

/**
Expand Down
Loading

0 comments on commit 69afff9

Please sign in to comment.