From eecf799753ae5201f1288144ee75faa8ad196a95 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Sun, 5 Aug 2018 14:51:17 +1000 Subject: [PATCH] rename util namespace to cruft --- CMakeLists.txt | 8 +------- hash/blake.cpp | 24 ++++++++++++------------ hash/blake.hpp | 8 ++++---- hash/blake2.cpp | 30 +++++++++++++++--------------- hash/blake2.hpp | 4 ++-- hash/hmac.hpp | 2 +- hash/hotp.cpp | 6 +++--- hash/hotp.hpp | 2 +- hash/md2.cpp | 6 +++--- hash/md2.hpp | 2 +- hash/md4.cpp | 8 ++++---- hash/md4.hpp | 2 +- hash/md5.cpp | 16 ++++++++-------- hash/md5.hpp | 6 +++--- hash/md6.cpp | 2 +- hash/md6.hpp | 2 +- hash/ripemd.cpp | 8 ++++---- hash/ripemd.hpp | 2 +- hash/sha1.cpp | 18 +++++++++--------- hash/sha1.hpp | 4 ++-- hash/sha2.cpp | 14 +++++++------- hash/sha2.hpp | 2 +- stream/salsa.cpp | 4 ++-- stream/salsa.hpp | 2 +- test/block/tea.cpp | 2 +- test/block/xtea.cpp | 2 +- test/block/xxtea.cpp | 2 +- test/hash/blake.cpp | 2 +- test/hash/blake2.cpp | 2 +- test/hash/hmac.cpp | 2 +- test/hash/hotp.cpp | 2 +- test/hash/md2.cpp | 4 ++-- test/hash/md4.cpp | 4 ++-- test/hash/md5.cpp | 4 ++-- test/hash/ripemd.cpp | 2 +- test/hash/sha1.cpp | 2 +- test/hash/sha2.cpp | 4 ++-- test/stream/rc4.cpp | 2 +- test/stream/salsa.cpp | 12 ++++++------ tools/hash.cpp | 10 +++++----- 40 files changed, 117 insertions(+), 123 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 45a3d5d..95dba33 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,12 +3,6 @@ cmake_minimum_required(VERSION 3.7.0) project(cruft-crypto CXX) -############################################################################### -if (NOT TARGET cruft-util) - message (FATAL_ERROR "cruft-util was not found") -endif () - - ############################################################################### list (APPEND sources fwd.hpp @@ -104,7 +98,7 @@ endif () ############################################################################### add_library (cruft-crypto STATIC ${sources}) -target_link_libraries (cruft-crypto INTERFACE cruft-util) +target_link_libraries (cruft-crypto INTERFACE cruft) ##----------------------------------------------------------------------------- diff --git a/hash/blake.cpp b/hash/blake.cpp index a558479..8e59e36 100644 --- a/hash/blake.cpp +++ b/hash/blake.cpp @@ -148,16 +148,16 @@ G (int i, const auto k = permute[r][2 * i + 1]; a = a + b + (m[j] ^ traits::pi[k]); - d = util::rotater (d ^ a, traits::rotations[0]); + d = cruft::rotater (d ^ a, traits::rotations[0]); c = c + d; - b = util::rotater (b ^ c, traits::rotations[1]); + b = cruft::rotater (b ^ c, traits::rotations[1]); a = a + b + (m[k] ^ traits::pi[j]); - d = util::rotater (d ^ a, traits::rotations[2]); + d = cruft::rotater (d ^ a, traits::rotations[2]); c = c + d; - b = util::rotater (b ^ c, traits::rotations[3]); + b = cruft::rotater (b ^ c, traits::rotations[3]); } @@ -212,8 +212,8 @@ compress ( template typename blake::digest_t blake::operator() ( - util::view data, - util::view salt + cruft::view data, + cruft::view salt ) const { std::array::word_t, 4> fwd {}; @@ -228,7 +228,7 @@ blake::operator() ( template typename blake::digest_t blake::operator() ( - util::view data, + cruft::view data, const std::array::word_t, 4> salt ) const noexcept { auto h = traits::iv; @@ -249,7 +249,7 @@ blake::operator() ( // perform the simple case where we're consuming whole blocks for (auto last = data.cend (); - util::cast::sign (last - cursor) >= sizeof (dw); + cruft::cast::sign (last - cursor) >= sizeof (dw); cursor += sizeof (dw)) { // use the number of bits as the size @@ -260,7 +260,7 @@ blake::operator() ( std::cbegin (dw), std::cend (dw), std::begin (dw), - util::ntoh + cruft::ntoh ); h = compress (h, dw, salt, t); } @@ -293,7 +293,7 @@ blake::operator() ( std::cbegin (dw), std::cend (dw), std::begin (dw), - util::ntoh + cruft::ntoh ); h = compress (h, dw, salt, t); @@ -315,12 +315,12 @@ blake::operator() ( std::cbegin (dw), std::cend (dw) - 2, std::begin (dw), - util::ntoh + cruft::ntoh ); h = compress (h, dw, salt, empty ? 0 : t); } - std::transform (std::cbegin (h), std::cend (h), std::begin (h), util::hton); + std::transform (std::cbegin (h), std::cend (h), std::begin (h), cruft::hton); digest_t d; memcpy (d.data (), h.data (), sizeof (d)); return d; diff --git a/hash/blake.hpp b/hash/blake.hpp index 781786c..ce97eaf 100644 --- a/hash/blake.hpp +++ b/hash/blake.hpp @@ -87,14 +87,14 @@ namespace cruft::crypto::hash { digest_t operator() ( - util::view data, - util::view salt + cruft::view data, + cruft::view salt ) const; - digest_t operator() (util::view data, + digest_t operator() (cruft::view data, const std::array salt) const noexcept; - digest_t operator() (util::view data) const noexcept + digest_t operator() (cruft::view data) const noexcept { return (*this) (data, {0,0,0,0}); } diff --git a/hash/blake2.cpp b/hash/blake2.cpp index f92dfee..94c475f 100644 --- a/hash/blake2.cpp +++ b/hash/blake2.cpp @@ -20,7 +20,7 @@ using cruft::crypto::hash::blake2; // blake2b: uint64_t struct traits { static constexpr int word_bits = 64; - using word_t = typename util::bits_type::uint; + using word_t = typename cruft::bits_type::uint; static constexpr int F_rounds = 12; static constexpr int block_bytes = 128; // bb static constexpr int max_hash_bytes = 64; // nn @@ -66,16 +66,16 @@ void G (std::array &v, int a, int b, int c, int d, word_t x, word_t y) { v[a] = v[a] + v[b] + x; - v[d] = util::rotater (v[d] ^ v[a], traits::rotations[0]); + v[d] = cruft::rotater (v[d] ^ v[a], traits::rotations[0]); v[c] = v[c] + v[d]; - v[b] = util::rotater (v[b] ^ v[c], traits::rotations[1]); + v[b] = cruft::rotater (v[b] ^ v[c], traits::rotations[1]); v[a] = v[a] + v[b] + y; - v[d] = util::rotater (v[d] ^ v[a], traits::rotations[2]); + v[d] = cruft::rotater (v[d] ^ v[a], traits::rotations[2]); v[c] = v[c] + v[d]; - v[b] = util::rotater (v[b] ^ v[c], traits::rotations[3]); + v[b] = cruft::rotater (v[b] ^ v[c], traits::rotations[3]); } @@ -123,15 +123,15 @@ F (std::array h, const word_t m[16], uint64_t t, bool f) /////////////////////////////////////////////////////////////////////////////// blake2::blake2 () noexcept: - blake2 (util::view{nullptr}) + blake2 (cruft::view{nullptr}) { ; } //----------------------------------------------------------------------------- -blake2::blake2 (util::view key) +blake2::blake2 (cruft::view key) { // don't give the user flexibility to provide too much key - if (key.size () > traits::max_key_bytes) + if (key.size () > ::traits::max_key_bytes) throw std::invalid_argument ("key is too large"); std::fill (m_salt.begin (), m_salt.end (), 0); @@ -142,15 +142,15 @@ blake2::blake2 (util::view key) //----------------------------------------------------------------------------- blake2::digest_t -blake2::operator() (util::view data) const noexcept +blake2::operator() (cruft::view data) const noexcept { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wcast-align" - auto h = traits::iv; + auto h = ::traits::iv; h[0] ^= 0x01010000 ^ (m_keylen << 8) ^ sizeof (digest_t); if (m_keylen) - h = F (h, reinterpret_cast (m_salt.data ()), traits::block_bytes, data.empty ()); + h = F (h, reinterpret_cast (m_salt.data ()), ::traits::block_bytes, data.empty ()); // special case for the empty key and empty data if (!m_keylen && data.empty ()) { @@ -158,13 +158,13 @@ blake2::operator() (util::view data) const noexcept h = F (h, zeroes.data (), 0, true); } - uint64_t counter = m_keylen?traits::block_bytes:0; + uint64_t counter = m_keylen?::traits::block_bytes:0; auto cursor = data.begin (); - while (cursor + traits::block_bytes < data.end ()) { - counter += traits::block_bytes; + while (cursor + ::traits::block_bytes < data.end ()) { + counter += ::traits::block_bytes; h = F (h, reinterpret_cast (cursor), counter, false); - cursor += traits::block_bytes; + cursor += ::traits::block_bytes; } if (cursor != data.cend ()) { diff --git a/hash/blake2.hpp b/hash/blake2.hpp index 66e4224..51d145c 100644 --- a/hash/blake2.hpp +++ b/hash/blake2.hpp @@ -23,9 +23,9 @@ namespace cruft::crypto::hash { blake2 () noexcept; blake2 (const salt_t&) noexcept; - blake2 (util::view key); + blake2 (cruft::view key); - digest_t operator() (util::view) const noexcept; + digest_t operator() (cruft::view) const noexcept; private: using state_t = std::array; diff --git a/hash/hmac.hpp b/hash/hmac.hpp index cae7944..bdc41aa 100644 --- a/hash/hmac.hpp +++ b/hash/hmac.hpp @@ -25,7 +25,7 @@ namespace cruft::crypto::hash { //--------------------------------------------------------------------- - HMAC (util::view key) + HMAC (cruft::view key) { CHECK (!key.empty ()); diff --git a/hash/hotp.cpp b/hash/hotp.cpp index 2134405..b058cb2 100644 --- a/hash/hotp.cpp +++ b/hash/hotp.cpp @@ -16,7 +16,7 @@ using cruft::crypto::hash::HOTP; /////////////////////////////////////////////////////////////////////////////// -HOTP::HOTP (util::view _key, uint64_t _counter): +HOTP::HOTP (cruft::view _key, uint64_t _counter): m_counter (_counter), m_hash (_key.template cast ()) { ; } @@ -32,9 +32,9 @@ HOTP::value (void) uint8_t bytes[8]; }; - number = util::htob (m_counter); + number = cruft::htob (m_counter); - auto res = truncate (m_hash (util::make_cview (bytes))); + auto res = truncate (m_hash (cruft::make_cview (bytes))); ++m_counter; return res % 1'000'000; } diff --git a/hash/hotp.hpp b/hash/hotp.hpp index bee2fcb..c1c183b 100644 --- a/hash/hotp.hpp +++ b/hash/hotp.hpp @@ -20,7 +20,7 @@ namespace cruft::crypto::hash { /// HMAC one-time password (RFC 4226) class HOTP { public: - HOTP (util::view key, uint64_t counter); + HOTP (cruft::view key, uint64_t counter); unsigned value (void); uint64_t counter (void) const; diff --git a/hash/md2.cpp b/hash/md2.cpp index 93b8e8b..8778dc2 100644 --- a/hash/md2.cpp +++ b/hash/md2.cpp @@ -50,7 +50,7 @@ static const size_t M_LENGTH = 16; static void transform (std::array &C, std::array &X) noexcept { - util::view M { X.data () + M_OFFSET, M_LENGTH }; + cruft::view M { X.data () + M_OFFSET, M_LENGTH }; // Update the checksum. // XXX: I can't see why we need the xor-assign from the spec, but it's the @@ -77,13 +77,13 @@ transform (std::array &C, std::array &X) noexcept /////////////////////////////////////////////////////////////////////////////// MD2::digest_t -MD2::operator() (const util::view data) const noexcept +MD2::operator() (const cruft::view data) const noexcept { // zero initialise the state vectors, and create a simple window `M' into // the middle of the `X' state vector. std::array C {}; std::array X {}; - const util::view M { std::begin (X) + M_OFFSET, M_LENGTH }; + const cruft::view M { std::begin (X) + M_OFFSET, M_LENGTH }; // process each complete block by copying to the window `M' and // transforming X and C. diff --git a/hash/md2.hpp b/hash/md2.hpp index 43debc5..b3db24e 100644 --- a/hash/md2.hpp +++ b/hash/md2.hpp @@ -22,7 +22,7 @@ namespace cruft::crypto::hash { typedef std::array digest_t; public: - digest_t operator() (util::view) const noexcept; + digest_t operator() (cruft::view) const noexcept; }; } diff --git a/hash/md4.cpp b/hash/md4.cpp index 3baaa63..1d257d7 100644 --- a/hash/md4.cpp +++ b/hash/md4.cpp @@ -63,7 +63,7 @@ transform (std::array &ABCD, const std::array &X) noexc #define ROUND1(a,b,c,d,k,s) do { \ (a) += F((b), (c), (d)) + X[k]; \ - (a) = util::rotatel ((a), (s)); \ + (a) = cruft::rotatel ((a), (s)); \ } while (0) ROUND1(A,B,C,D, 0, 3); @@ -88,7 +88,7 @@ transform (std::array &ABCD, const std::array &X) noexc #define ROUND2(a,b,c,d,k,s) do { \ (a) += G((b),(c),(d)) + X[k] + 0x5A827999u; \ - (a) = util::rotatel ((a), (s)); \ + (a) = cruft::rotatel ((a), (s)); \ } while (0) ROUND2(A,B,C,D, 0, 3); @@ -113,7 +113,7 @@ transform (std::array &ABCD, const std::array &X) noexc #define ROUND3(a,b,c,d,k,s) do { \ (a) += H((b),(c),(d)) + X[k] + 0x6ED9EBA1u; \ - (a) = util::rotatel ((a), (s)); \ + (a) = cruft::rotatel ((a), (s)); \ } while (0) ROUND3(A,B,C,D, 0, 3); @@ -145,7 +145,7 @@ transform (std::array &ABCD, const std::array &X) noexc /////////////////////////////////////////////////////////////////////////////// MD4::digest_t -MD4::operator() (util::view data) noexcept +MD4::operator() (cruft::view data) noexcept { /* RESET */ uint64_t total = 0; diff --git a/hash/md4.hpp b/hash/md4.hpp index e7a962e..ced80ec 100644 --- a/hash/md4.hpp +++ b/hash/md4.hpp @@ -21,7 +21,7 @@ namespace cruft::crypto::hash { public: using digest_t = std::array; - digest_t operator() (util::view) noexcept; + digest_t operator() (cruft::view) noexcept; }; } diff --git a/hash/md5.cpp b/hash/md5.cpp index fd63558..1cff626 100644 --- a/hash/md5.cpp +++ b/hash/md5.cpp @@ -95,7 +95,7 @@ static constexpr uint32_t INITIAL_D = 0x10325476; /////////////////////////////////////////////////////////////////////////////// typename MD5::digest_t -MD5::operator() (util::view a) const noexcept +MD5::operator() (cruft::view a) const noexcept { return (*this)(a, nullptr); } @@ -103,7 +103,7 @@ MD5::operator() (util::view a) const noexcept //----------------------------------------------------------------------------- typename MD5::digest_t -MD5::operator() (util::view a, util::view b) const noexcept +MD5::operator() (cruft::view a, cruft::view b) const noexcept { return (*this)(a, b, nullptr); } @@ -112,9 +112,9 @@ MD5::operator() (util::view a, util::view b) con /////////////////////////////////////////////////////////////////////////////// typename MD5::digest_t MD5::operator() ( - const util::view data_a, - const util::view data_b, - const util::view data_c + const cruft::view data_a, + const cruft::view data_b, + const cruft::view data_c ) const noexcept { union { std::array w; @@ -137,8 +137,8 @@ MD5::operator() ( // note we pass in a windowed view of the state block, not the whole // thing. - util::transform_by_block ( - util::view {X.b}, + cruft::transform_by_block ( + cruft::view {X.b}, [&,this] (auto) { ABCD = transform (ABCD, X.w); }, data_a, data_b, data_c ); @@ -193,7 +193,7 @@ MD5::transform ( #define ROUNDx(a,b,c,d,k,s,i,f) do { \ (a) += (f)((b), (c), (d)) + X[k] + T[i]; \ - (a) = util::rotatel ((a), (s)); \ + (a) = cruft::rotatel ((a), (s)); \ (a) += (b); \ } while (0) diff --git a/hash/md5.hpp b/hash/md5.hpp index 15f6f31..89a0a35 100644 --- a/hash/md5.hpp +++ b/hash/md5.hpp @@ -25,9 +25,9 @@ namespace cruft::crypto::hash { static const size_t DIGEST_SIZE = 16; public: - digest_t operator() (util::view) const noexcept; - digest_t operator() (util::view,util::view) const noexcept; - digest_t operator() (util::view,util::view,util::view) const noexcept; + digest_t operator() (cruft::view) const noexcept; + digest_t operator() (cruft::view,cruft::view) const noexcept; + digest_t operator() (cruft::view,cruft::view,cruft::view) const noexcept; private: std::array diff --git a/hash/md6.cpp b/hash/md6.cpp index 1dbfb34..3529f03 100644 --- a/hash/md6.cpp +++ b/hash/md6.cpp @@ -14,7 +14,7 @@ using cruft::crypto::hash::MD6; /////////////////////////////////////////////////////////////////////////////// #if 0 MD6::digest_t -MD6::operator() (util::view data) const noexcept +MD6::operator() (cruft::view data) const noexcept { static constexpr int rounds = 40 + digest_size / 4; static constexpr int mode_control = 64; diff --git a/hash/md6.hpp b/hash/md6.hpp index e5b7699..bcd2c2f 100644 --- a/hash/md6.hpp +++ b/hash/md6.hpp @@ -20,7 +20,7 @@ namespace cruft::crypto::hash { using digest_t = std::array; - digest_t operator() (util::view data) const noexcept; + digest_t operator() (cruft::view data) const noexcept; }; }; diff --git a/hash/ripemd.cpp b/hash/ripemd.cpp index 03192fb..51f6ecd 100644 --- a/hash/ripemd.cpp +++ b/hash/ripemd.cpp @@ -75,9 +75,9 @@ transform (uint32_t state[5], const uint32_t d32[16]) #define ROUND(f,a,b,c,d,e,o,x,s) { \ a += f(b, c, d); \ a += d32[x] + o; \ - a = util::rotatel (a, s); \ + a = cruft::rotatel (a, s); \ a += e; \ - c = util::rotatel (c, 10); \ + c = cruft::rotatel (c, 10); \ } #define R1a(a,b,c,d,e,x,s) ROUND(f1,a,b,c,d,e,0x00000000u,x,s) @@ -293,7 +293,7 @@ transform (uint32_t state[5], const uint32_t d32[16]) /////////////////////////////////////////////////////////////////////////////// RIPEMD::digest_t -RIPEMD::operator() (const util::view data) +RIPEMD::operator() (const cruft::view data) { struct { union { @@ -324,7 +324,7 @@ RIPEMD::operator() (const util::view data) while (cursor < len) { size_t width = sizeof (m_buffer.d08) - m_buffer.size; - size_t chunk = util::min (width, len - cursor); + size_t chunk = cruft::min (width, len - cursor); memcpy (m_buffer.d08 + m_buffer.size, base + cursor, chunk); m_length += chunk; diff --git a/hash/ripemd.hpp b/hash/ripemd.hpp index f4de513..bc7404d 100644 --- a/hash/ripemd.hpp +++ b/hash/ripemd.hpp @@ -21,7 +21,7 @@ namespace cruft::crypto::hash { public: typedef std::array digest_t; - digest_t operator() (util::view); + digest_t operator() (cruft::view); }; } diff --git a/hash/sha1.cpp b/hash/sha1.cpp index 00da479..7e07284 100644 --- a/hash/sha1.cpp +++ b/hash/sha1.cpp @@ -92,12 +92,12 @@ process (std::array &H, std::array &W) std::end (W), std::begin (W), [] (uint32_t x) { - return util::ntoh (x); + return cruft::ntoh (x); }); // Initialise the work buffer and the state variables for (size_t t = 16; t < 80; ++t) - W[t] = util::rotatel (W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1); + W[t] = cruft::rotatel (W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1); uint32_t A = H[0], B = H[1], @@ -107,10 +107,10 @@ process (std::array &H, std::array &W) // Perform each of the four rounds #define ROTATE_STATE(i) do { \ - uint32_t temp = util::rotatel (A, 5) + f_##i (B, C, D) + E + W[t] + K_##i; \ + uint32_t temp = cruft::rotatel (A, 5) + f_##i (B, C, D) + E + W[t] + K_##i; \ E = D; \ D = C; \ - C = util::rotatel (B, 30); \ + C = cruft::rotatel (B, 30); \ B = A; \ A = temp; \ } while (0) @@ -131,7 +131,7 @@ process (std::array &H, std::array &W) /////////////////////////////////////////////////////////////////////////////// SHA1::digest_t -SHA1::operator() (util::view data) noexcept +SHA1::operator() (cruft::view data) noexcept { return (*this) (data, nullptr); } @@ -140,8 +140,8 @@ SHA1::operator() (util::view data) noexcept //----------------------------------------------------------------------------- SHA1::digest_t SHA1::operator() ( - util::view data_a, - util::view data_b + cruft::view data_a, + cruft::view data_b ) noexcept { /* RESET */ uint64_t total = 0; @@ -160,7 +160,7 @@ SHA1::operator() ( /* UPDATE */ transform_by_block ( - util::view {state.c.data (), BLOCK_BYTES }, + cruft::view {state.c.data (), BLOCK_BYTES }, [&] (auto) { process (H.w, state.W); }, data_a, data_b ); @@ -204,6 +204,6 @@ SHA1::operator() ( } /* DIGEST */ - std::transform (std::begin (H.w), std::end (H.w), std::begin (H.w), util::hton); + std::transform (std::begin (H.w), std::end (H.w), std::begin (H.w), cruft::hton); return H.b; } diff --git a/hash/sha1.hpp b/hash/sha1.hpp index 87695ee..e469a87 100644 --- a/hash/sha1.hpp +++ b/hash/sha1.hpp @@ -28,8 +28,8 @@ namespace cruft::crypto::hash { //digest_t //operator() (DataT&&...); - digest_t operator() (util::view, util::view) noexcept; - digest_t operator() (util::view) noexcept; + digest_t operator() (cruft::view, cruft::view) noexcept; + digest_t operator() (cruft::view) noexcept; }; } diff --git a/hash/sha2.cpp b/hash/sha2.cpp index 811d5f4..50d4e2d 100644 --- a/hash/sha2.cpp +++ b/hash/sha2.cpp @@ -86,9 +86,9 @@ static constexpr \ uint32_t \ NAME (uint32_t x) \ { \ - return util::rotater (x, (r0)) ^ \ - util::rotater (x, (r1)) ^ \ - util::rotater (x, (r2)); \ + return cruft::rotater (x, (r0)) ^ \ + cruft::rotater (x, (r1)) ^ \ + cruft::rotater (x, (r2)); \ } FUNC(S0, 2, 13, 22) @@ -103,8 +103,8 @@ static constexpr \ uint32_t \ NAME (uint32_t x) \ { \ - return util::rotater (x, (r0)) ^ \ - util::rotater (x, (r1)) ^ \ + return cruft::rotater (x, (r0)) ^ \ + cruft::rotater (x, (r1)) ^ \ (x >> (s)); \ } @@ -176,7 +176,7 @@ H_512[] = { /////////////////////////////////////////////////////////////////////////////// SHA256::digest_t -SHA256::operator() (util::view data) noexcept +SHA256::operator() (cruft::view data) noexcept { (void)K_80; (void)H_224; @@ -266,7 +266,7 @@ SHA256::process (void) // Initialise the message schedule, W uint32_t W[64]; - std::transform (M.begin (), M.end (), std::begin (W), util::ntoh); + std::transform (M.begin (), M.end (), std::begin (W), cruft::ntoh); for (size_t i = 16; i < 64; ++i) W[i] = s1(W[i - 2]) + W[i - 7] + s0 (W[i - 15]) + W[i - 16]; diff --git a/hash/sha2.hpp b/hash/sha2.hpp index cfbafa6..ece224b 100644 --- a/hash/sha2.hpp +++ b/hash/sha2.hpp @@ -23,7 +23,7 @@ namespace cruft::crypto::hash { typedef std::array digest_t; public: - digest_t operator() (util::view) noexcept; + digest_t operator() (cruft::view) noexcept; private: void process (void); diff --git a/stream/salsa.cpp b/stream/salsa.cpp index 3ade354..c984eac 100644 --- a/stream/salsa.cpp +++ b/stream/salsa.cpp @@ -20,7 +20,7 @@ cruft::crypto::stream::salsa20 (const std::array bytes) noexcept auto y = x; for (auto &t: x) - t = util::ltoh (t); + t = cruft::ltoh (t); for (int i = 0; i < 10; ++i) x = salsa::doubleround (x); @@ -29,7 +29,7 @@ cruft::crypto::stream::salsa20 (const std::array bytes) noexcept x[i] += y[i]; for (auto &t: x) - t = util::htol (t); + t = cruft::htol (t); return *reinterpret_cast*> (&x); #pragma GCC diagnostic pop diff --git a/stream/salsa.hpp b/stream/salsa.hpp index fd6d7f9..a0c4312 100644 --- a/stream/salsa.hpp +++ b/stream/salsa.hpp @@ -24,7 +24,7 @@ namespace cruft::crypto::stream::salsa { uint32_t R (uint32_t a, uint32_t b, uint32_t c, uint32_t k) { - return b ^ util::rotatel (a + c, k); + return b ^ cruft::rotatel (a + c, k); } diff --git a/test/block/tea.cpp b/test/block/tea.cpp index 95fd1d2..cf14f38 100644 --- a/test/block/tea.cpp +++ b/test/block/tea.cpp @@ -41,7 +41,7 @@ main () }, }; - util::TAP::logger tap; + cruft::TAP::logger tap; for (size_t i = 0; i < std::size (TESTS); ++i) { const auto &t = TESTS[i]; diff --git a/test/block/xtea.cpp b/test/block/xtea.cpp index 4aa686b..4a23ca8 100644 --- a/test/block/xtea.cpp +++ b/test/block/xtea.cpp @@ -39,7 +39,7 @@ main () }, }; - util::TAP::logger tap; + cruft::TAP::logger tap; for (size_t i = 0; i < std::size (TESTS); ++i) { const auto &t = TESTS[i]; diff --git a/test/block/xxtea.cpp b/test/block/xxtea.cpp index e177216..e6acca3 100644 --- a/test/block/xxtea.cpp +++ b/test/block/xxtea.cpp @@ -94,7 +94,7 @@ main () }, }; - util::TAP::logger tap; + cruft::TAP::logger tap; for (size_t i = 0; i < std::size (TESTS); ++i) { const auto &t = TESTS[i]; diff --git a/test/hash/blake.cpp b/test/hash/blake.cpp index 0cf5579..ad25256 100644 --- a/test/hash/blake.cpp +++ b/test/hash/blake.cpp @@ -161,7 +161,7 @@ static const struct { int main () { - util::TAP::logger tap; + cruft::TAP::logger tap; for (const auto &t: TESTS) { blake<256> h256; diff --git a/test/hash/blake2.cpp b/test/hash/blake2.cpp index fcd5509..67fe552 100644 --- a/test/hash/blake2.cpp +++ b/test/hash/blake2.cpp @@ -119,7 +119,7 @@ static const struct { int main () { - util::TAP::logger tap; + cruft::TAP::logger tap; for (const auto &t: TESTS2b) { blake2 h (t.salt); diff --git a/test/hash/hmac.cpp b/test/hash/hmac.cpp index b45d262..f7ba953 100644 --- a/test/hash/hmac.cpp +++ b/test/hash/hmac.cpp @@ -276,7 +276,7 @@ static const struct { int main (int, char**) { - util::TAP::logger tap; + cruft::TAP::logger tap; for (size_t i = 0; i < std::size (TESTS); ++i) tap.expect (TESTS[i].fun (TESTS[i].key, TESTS[i].dat, TESTS[i].res), "standard test vector %zu", i); diff --git a/test/hash/hotp.cpp b/test/hash/hotp.cpp index e240f2b..6998c66 100644 --- a/test/hash/hotp.cpp +++ b/test/hash/hotp.cpp @@ -26,7 +26,7 @@ main (int, char**) }; - util::TAP::logger tap; + cruft::TAP::logger tap; for (auto &i: EXPECTED) tap.expect_eq (i, h.value (), "sequence"); diff --git a/test/hash/md2.cpp b/test/hash/md2.cpp index 4f02995..ed6fc45 100644 --- a/test/hash/md2.cpp +++ b/test/hash/md2.cpp @@ -48,13 +48,13 @@ main (int, char **) { const MD2 h; for (const auto &i: TESTS) { - if (h (util::view{i.input}.cast ()) != i.output) { + if (h (cruft::view{i.input}.cast ()) != i.output) { std::cerr << "Failed on " << i.input << "\n"; success = false; } } - util::TAP::logger tap; + cruft::TAP::logger tap; tap.expect (success, "test vectors"); return tap.status (); } diff --git a/test/hash/md4.cpp b/test/hash/md4.cpp index c300aa5..9896fdc 100644 --- a/test/hash/md4.cpp +++ b/test/hash/md4.cpp @@ -56,13 +56,13 @@ main (int, char**) { MD4 h; for (auto i: TESTS) { - if (h (util::view{i.input}.cast ()) != i.output) { + if (h (cruft::view{i.input}.cast ()) != i.output) { std::cerr << "Failed on '" << i.input << "'\n"; success = false; } } - util::TAP::logger tap; + cruft::TAP::logger tap; tap.expect (success, "test vectors"); return tap.status (); } diff --git a/test/hash/md5.cpp b/test/hash/md5.cpp index 89f810e..de4739d 100644 --- a/test/hash/md5.cpp +++ b/test/hash/md5.cpp @@ -65,7 +65,7 @@ main (int, char**) { } }; - util::TAP::logger tap; + cruft::TAP::logger tap; MD5 h; for (const auto &t: TESTS) @@ -84,7 +84,7 @@ main (int, char**) { for (auto l: { 2, 64, 80}) { std::vector data (l); std::iota (std::begin (data), std::end (data), 0); - util::view root {data}; + cruft::view root {data}; const auto &[a,b] = root.split (root.begin () + l / 2); tap.expect_eq (h (a,b), h(root), "split data hash equality, %! bytes", l); }; diff --git a/test/hash/ripemd.cpp b/test/hash/ripemd.cpp index 1cb3f31..5a37f7f 100644 --- a/test/hash/ripemd.cpp +++ b/test/hash/ripemd.cpp @@ -118,7 +118,7 @@ struct { int main(int, char**) { - util::TAP::logger tap; + cruft::TAP::logger tap; // Check against simple test vectors for (const auto &t: TESTS) { diff --git a/test/hash/sha1.cpp b/test/hash/sha1.cpp index fbe00f7..ee7ae40 100644 --- a/test/hash/sha1.cpp +++ b/test/hash/sha1.cpp @@ -27,7 +27,7 @@ operator"" _u8s (const char *str, size_t len) int main (int, char**) { - util::TAP::logger tap; + cruft::TAP::logger tap; static const struct { const char *msg; diff --git a/test/hash/sha2.cpp b/test/hash/sha2.cpp index b698f56..49cc39c 100644 --- a/test/hash/sha2.cpp +++ b/test/hash/sha2.cpp @@ -52,11 +52,11 @@ static const struct { int main (int, char **) { - util::TAP::logger tap; + cruft::TAP::logger tap; for (const auto &i: TESTS) { SHA256 obj; - tap.expect_eq (obj (util::view{i.input}.cast ()), i.output, "%s", i.msg); + tap.expect_eq (obj (cruft::view{i.input}.cast ()), i.output, "%s", i.msg); } return tap.status (); diff --git a/test/stream/rc4.cpp b/test/stream/rc4.cpp index ad95f7a..d4d1409 100644 --- a/test/stream/rc4.cpp +++ b/test/stream/rc4.cpp @@ -12,7 +12,7 @@ using cruft::crypto::stream::RC4; int main () { - util::TAP::logger tap; + cruft::TAP::logger tap; // Test vectors from RFC 6229. static const size_t OFFSETS[] = { diff --git a/test/stream/salsa.cpp b/test/stream/salsa.cpp index 71f23b6..25993e5 100644 --- a/test/stream/salsa.cpp +++ b/test/stream/salsa.cpp @@ -5,7 +5,7 @@ /////////////////////////////////////////////////////////////////////////////// void -test_quarter (util::TAP::logger &tap) +test_quarter (cruft::TAP::logger &tap) { static const struct { std::array a, b; @@ -37,7 +37,7 @@ test_quarter (util::TAP::logger &tap) /////////////////////////////////////////////////////////////////////////////// void -test_row (util::TAP::logger &tap) +test_row (cruft::TAP::logger &tap) { static const struct { std::array a, b; @@ -73,7 +73,7 @@ test_row (util::TAP::logger &tap) /////////////////////////////////////////////////////////////////////////////// void -test_col (util::TAP::logger &tap) +test_col (cruft::TAP::logger &tap) { static const struct { std::array a, b; @@ -107,7 +107,7 @@ test_col (util::TAP::logger &tap) /////////////////////////////////////////////////////////////////////////////// void -test_doubleround (util::TAP::logger &tap) +test_doubleround (cruft::TAP::logger &tap) { static const struct { std::array a, b; @@ -141,7 +141,7 @@ test_doubleround (util::TAP::logger &tap) /////////////////////////////////////////////////////////////////////////////// void -test_salsa20 (util::TAP::logger &tap) +test_salsa20 (cruft::TAP::logger &tap) { static const struct { std::array a, b; @@ -237,7 +237,7 @@ test_salsa20 (util::TAP::logger &tap) int main (void) { - util::TAP::logger tap; + cruft::TAP::logger tap; test_quarter (tap); test_row (tap); diff --git a/tools/hash.cpp b/tools/hash.cpp index 60bc624..8de2d2c 100644 --- a/tools/hash.cpp +++ b/tools/hash.cpp @@ -53,7 +53,7 @@ template std::ostream& print_digest (std::ostream &os, std::array digest) { - util::stream::scoped::flags f (os); + cruft::stream::scoped::flags f (os); os << std::hex; for (auto c: digest) @@ -65,7 +65,7 @@ print_digest (std::ostream &os, std::array digest) /////////////////////////////////////////////////////////////////////////////// static void -compute (const std::string &name, const util::view data) +compute (const std::string &name, const cruft::view data) { #define stream(TYPE, ...) do { \ if (name != #TYPE) \ @@ -73,7 +73,7 @@ compute (const std::string &name, const util::view data) \ print_digest ( \ std::cout, \ - util::hash::TYPE{} (data) \ + cruft::hash::TYPE{} (data) \ ) << '\n'; \ return; \ } while (0); @@ -126,8 +126,8 @@ main (int argc, char **argv) } if (strcmp (argv[ARG_INPUT], "-")) { - const util::mapped_file src (argv[ARG_INPUT]); - compute (argv[ARG_HASH], util::view{src}); + const cruft::mapped_file src (argv[ARG_INPUT]); + compute (argv[ARG_HASH], cruft::view{src}); return EXIT_SUCCESS; } else {