Skip to content

Commit

Permalink
Merge pull request #1490 from evoskuil/master
Browse files Browse the repository at this point in the history
Define TEMPLATE/CLASS in .hpp surrounding .ipp.
  • Loading branch information
evoskuil authored Jul 4, 2024
2 parents 0a5bb97 + deb196d commit c0d0b85
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 64 deletions.
8 changes: 8 additions & 0 deletions include/bitcoin/system/hash/accumulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <string>
#include <bitcoin/system/data/data.hpp>
#include <bitcoin/system/define.hpp>
#include <bitcoin/system/endian/endian.hpp>
#include <bitcoin/system/hash/algorithms.hpp>
#include <bitcoin/system/math/math.hpp>

Expand Down Expand Up @@ -170,6 +171,13 @@ extern template class accumulator<sha512>;
} // namespace system
} // namespace libbitcoin

#define TEMPLATE template <typename Algorithm, bool Checked, \
if_base_of<algorithm_t, Algorithm> If>
#define CLASS accumulator<Algorithm, Checked, If>

#include <bitcoin/system/impl/hash/accumulator.ipp>

#undef CLASS
#undef TEMPLATE

#endif
6 changes: 6 additions & 0 deletions include/bitcoin/system/hash/hmac.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ class hmac
} // namespace system
} // namespace libbitcoin

#define TEMPLATE template <typename Algorithm>
#define CLASS hmac<Algorithm>

#include <bitcoin/system/impl/hash/hmac.ipp>

#undef CLASS
#undef TEMPLATE

#endif
8 changes: 8 additions & 0 deletions include/bitcoin/system/hash/pbkd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include <bitcoin/system/data/data.hpp>
#include <bitcoin/system/define.hpp>
#include <bitcoin/system/endian/endian.hpp>
#include <bitcoin/system/hash/hmac.hpp>
#include <bitcoin/system/math/math.hpp>

namespace libbitcoin {
Expand Down Expand Up @@ -61,6 +63,12 @@ struct pbkd
} // namespace system
} // namespace libbitcoin

#define TEMPLATE template <typename Algorithm>
#define CLASS pbkd<Algorithm>

#include <bitcoin/system/impl/hash/pbkd.ipp>

#undef CLASS
#undef TEMPLATE

#endif
7 changes: 7 additions & 0 deletions include/bitcoin/system/hash/rmd/algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <bitcoin/system/data/data.hpp>
#include <bitcoin/system/define.hpp>
#include <bitcoin/system/endian/endian.hpp>
#include <bitcoin/system/hash/algorithm.hpp>
#include <bitcoin/system/math/math.hpp>

Expand Down Expand Up @@ -152,6 +153,12 @@ class algorithm
} // namespace system
} // namespace libbitcoin

#define TEMPLATE template <typename RMD, if_same<typename RMD::T, rmdh_t> If>
#define CLASS algorithm<RMD, If>

#include <bitcoin/system/impl/hash/rmd/algorithm.ipp>

#undef CLASS
#undef TEMPLATE

#endif
12 changes: 11 additions & 1 deletion include/bitcoin/system/hash/scrypt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
#include <bitcoin/system/data/data.hpp>
#include <bitcoin/system/define.hpp>
#include <bitcoin/system/data/data.hpp>
#include <bitcoin/system/hash/pbkd.hpp>
#include <bitcoin/system/endian/endian.hpp>
#include <bitcoin/system/hash/algorithms.hpp>
#include <bitcoin/system/hash/pbkd.hpp>
#include <bitcoin/system/math/math.hpp>

namespace libbitcoin {
Expand Down Expand Up @@ -112,6 +113,15 @@ static_assert(scrypt<16384, 8, 8>::maximum_memory == 134'231'040_u64);
} // namespace system
} // namespace libbitcoin


#define TEMPLATE \
template<size_t W, size_t R, size_t P, bool Concurrent, \
bool_if<is_scrypt_args<W, R, P>> If>
#define CLASS scrypt<W, R, P, Concurrent, If>

#include <bitcoin/system/impl/hash/scrypt.ipp>

#undef CLASS
#undef TEMPLATE

#endif
1 change: 1 addition & 0 deletions include/bitcoin/system/hash/sha/algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <bitcoin/system/data/data.hpp>
#include <bitcoin/system/define.hpp>
#include <bitcoin/system/endian/endian.hpp>
#include <bitcoin/system/hash/algorithm.hpp>
#include <bitcoin/system/intrinsics/intrinsics.hpp>
#include <bitcoin/system/math/math.hpp>
Expand Down
11 changes: 0 additions & 11 deletions include/bitcoin/system/impl/hash/accumulator.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,10 @@

#include <algorithm>
#include <string>
#include <bitcoin/system/define.hpp>
#include <bitcoin/system/data/data.hpp>
#include <bitcoin/system/endian/endian.hpp>
#include <bitcoin/system/math/math.hpp>

namespace libbitcoin {
namespace system {

#define TEMPLATE template <typename Algorithm, bool Checked, \
if_base_of<algorithm_t, Algorithm> If>
#define CLASS accumulator<Algorithm, Checked, If>

// Copy and array index are guarded.
BC_PUSH_WARNING(NO_UNSAFE_COPY_N)
BC_PUSH_WARNING(NO_ARRAY_INDEXING)
Expand Down Expand Up @@ -660,9 +652,6 @@ BC_POP_WARNING()
BC_POP_WARNING()
BC_POP_WARNING()

#undef CLASS
#undef TEMPLATE

} // namespace system
} // namespace libbitcoin

Expand Down
10 changes: 0 additions & 10 deletions include/bitcoin/system/impl/hash/hmac.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,13 @@
#ifndef LIBBITCOIN_SYSTEM_HASH_HMAC_IPP
#define LIBBITCOIN_SYSTEM_HASH_HMAC_IPP

#include <bitcoin/system/data/data.hpp>
#include <bitcoin/system/define.hpp>
#include <bitcoin/system/hash/accumulator.hpp>

// Based on:
// datatracker.ietf.org/doc/html/rfc2104
// [Krawczyk, Bellare, Canetti]

namespace libbitcoin {
namespace system {

#define TEMPLATE template <typename Algorithm>
#define CLASS hmac<Algorithm>

// hmac accumulator
// ---------------------------------------------------------------------------

Expand Down Expand Up @@ -167,9 +160,6 @@ code(const data_slice& data, const data_slice& key) NOEXCEPT
return buffer.flush();
}

#undef CLASS
#undef TEMPLATE

} // namespace system
} // namespace libbitcoin

Expand Down
11 changes: 0 additions & 11 deletions include/bitcoin/system/impl/hash/pbkd.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,13 @@
#define LIBBITCOIN_SYSTEM_HASH_PBKD_IPP

#include <algorithm>
#include <bitcoin/system/data/data.hpp>
#include <bitcoin/system/define.hpp>
#include <bitcoin/system/hash/hmac.hpp>
#include <bitcoin/system/endian/endian.hpp>
#include <bitcoin/system/math/math.hpp>

// based on:
// datatracker.ietf.org/doc/html/rfc8018
// [Moriarty, Kaliski, Rusch]

namespace libbitcoin {
namespace system {

#define TEMPLATE template <typename Algorithm>
#define CLASS pbkd<Algorithm>

// Bugus use constexpr warning with consteval.
BC_PUSH_WARNING(USE_CONSTEXPR_FOR_FUNCTION)
Expand Down Expand Up @@ -148,9 +140,6 @@ key(const data_slice& password, const data_slice& salt,
return dk;
}

#undef CLASS
#undef TEMPLATE

} // namespace system
} // namespace libbitcoin

Expand Down
9 changes: 0 additions & 9 deletions include/bitcoin/system/impl/hash/rmd/algorithm.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@

#include <bit>
#include <iostream>
#include <bitcoin/system/define.hpp>
#include <bitcoin/system/endian/endian.hpp>
#include <bitcoin/system/math/math.hpp>

// Based on:
// homes.esat.kuleuven.be/~bosselae/ripemd160/pdf/AB-9601/AB-9601.pdf
Expand All @@ -33,9 +30,6 @@ namespace libbitcoin {
namespace system {
namespace rmd {

#define TEMPLATE template <typename RMD, if_same<typename RMD::T, rmdh_t> If>
#define CLASS algorithm<RMD, If>

// Bogus warning suggests constexpr when declared consteval.
BC_PUSH_WARNING(USE_CONSTEXPR_FOR_FUNCTION)
BC_PUSH_WARNING(NO_UNGUARDED_POINTERS)
Expand Down Expand Up @@ -652,9 +646,6 @@ BC_POP_WARNING()
BC_POP_WARNING()
BC_POP_WARNING()

#undef CLASS
#undef TEMPLATE

} // namespace rmd
} // namespace system
} // namespace libbitcoin
Expand Down
13 changes: 0 additions & 13 deletions include/bitcoin/system/impl/hash/scrypt.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@
#include <algorithm>
#include <bit>
#include <memory>
#include <bitcoin/system/data/data.hpp>
#include <bitcoin/system/define.hpp>
#include <bitcoin/system/endian/endian.hpp>
#include <bitcoin/system/hash/pbkd.hpp>
#include <bitcoin/system/math/math.hpp>

// Based on:
// tools.ietf.org/html/rfc7914
Expand All @@ -37,11 +32,6 @@
namespace libbitcoin {
namespace system {

#define TEMPLATE \
template<size_t W, size_t R, size_t P, bool Concurrent, \
bool_if<is_scrypt_args<W, R, P>> If>
#define CLASS scrypt<W, R, P, Concurrent, If>

BC_PUSH_WARNING(NO_DYNAMIC_ARRAY_INDEXING)
BC_PUSH_WARNING(NO_POINTER_ARITHMETIC)
BC_PUSH_WARNING(NO_UNGUARDED_POINTERS)
Expand Down Expand Up @@ -536,9 +526,6 @@ BC_POP_WARNING()
BC_POP_WARNING()
BC_POP_WARNING()

#undef CLASS
#undef TEMPLATE

} // namespace system
} // namespace libbitcoin

Expand Down
3 changes: 0 additions & 3 deletions include/bitcoin/system/impl/hash/sha/algorithm.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
#define LIBBITCOIN_SYSTEM_HASH_SHA_ALGORITHM_IPP

#include <utility>
#include <bitcoin/system/define.hpp>
#include <bitcoin/system/endian/endian.hpp>
#include <bitcoin/system/math/math.hpp>

// Based on:
// FIPS PUB 180-4 [Secure Hash Standard (SHS)].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
#ifndef LIBBITCOIN_SYSTEM_HASH_SHA_ALGORITHM_COMPRESSION_IPP
#define LIBBITCOIN_SYSTEM_HASH_SHA_ALGORITHM_COMPRESSION_IPP

#include <bitcoin/system/define.hpp>
#include <bitcoin/system/intrinsics/intrinsics.hpp>

namespace libbitcoin {
namespace system {
namespace sha {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
#ifndef LIBBITCOIN_SYSTEM_HASH_SHA_ALGORITHM_VECTORIZATION_IPP
#define LIBBITCOIN_SYSTEM_HASH_SHA_ALGORITHM_VECTORIZATION_IPP

#include <bitcoin/system/define.hpp>
#include <bitcoin/system/intrinsics/intrinsics.hpp>

namespace libbitcoin {
namespace system {
namespace sha {
Expand Down

0 comments on commit c0d0b85

Please sign in to comment.