rename util namespace to cruft
This commit is contained in:
parent
38888bcfeb
commit
eecf799753
@ -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)
|
||||
|
||||
|
||||
##-----------------------------------------------------------------------------
|
||||
|
@ -148,16 +148,16 @@ G (int i,
|
||||
const auto k = permute[r][2 * i + 1];
|
||||
|
||||
a = a + b + (m[j] ^ traits<width>::pi[k]);
|
||||
d = util::rotater (d ^ a, traits<width>::rotations[0]);
|
||||
d = cruft::rotater (d ^ a, traits<width>::rotations[0]);
|
||||
|
||||
c = c + d;
|
||||
b = util::rotater (b ^ c, traits<width>::rotations[1]);
|
||||
b = cruft::rotater (b ^ c, traits<width>::rotations[1]);
|
||||
|
||||
a = a + b + (m[k] ^ traits<width>::pi[j]);
|
||||
d = util::rotater (d ^ a, traits<width>::rotations[2]);
|
||||
d = cruft::rotater (d ^ a, traits<width>::rotations[2]);
|
||||
|
||||
c = c + d;
|
||||
b = util::rotater (b ^ c, traits<width>::rotations[3]);
|
||||
b = cruft::rotater (b ^ c, traits<width>::rotations[3]);
|
||||
}
|
||||
|
||||
|
||||
@ -212,8 +212,8 @@ compress (
|
||||
template <int width>
|
||||
typename blake<width>::digest_t
|
||||
blake<width>::operator() (
|
||||
util::view<const uint8_t*> data,
|
||||
util::view<const uint8_t*> salt
|
||||
cruft::view<const uint8_t*> data,
|
||||
cruft::view<const uint8_t*> salt
|
||||
) const {
|
||||
std::array<typename traits<width>::word_t, 4> fwd {};
|
||||
|
||||
@ -228,7 +228,7 @@ blake<width>::operator() (
|
||||
template <int width>
|
||||
typename blake<width>::digest_t
|
||||
blake<width>::operator() (
|
||||
util::view<const uint8_t *> data,
|
||||
cruft::view<const uint8_t *> data,
|
||||
const std::array<typename traits<width>::word_t, 4> salt
|
||||
) const noexcept {
|
||||
auto h = traits<width>::iv;
|
||||
@ -249,7 +249,7 @@ blake<width>::operator() (
|
||||
|
||||
// perform the simple case where we're consuming whole blocks
|
||||
for (auto last = data.cend ();
|
||||
util::cast::sign<size_t> (last - cursor) >= sizeof (dw);
|
||||
cruft::cast::sign<size_t> (last - cursor) >= sizeof (dw);
|
||||
cursor += sizeof (dw))
|
||||
{
|
||||
// use the number of bits as the size
|
||||
@ -260,7 +260,7 @@ blake<width>::operator() (
|
||||
std::cbegin (dw),
|
||||
std::cend (dw),
|
||||
std::begin (dw),
|
||||
util::ntoh<word_t>
|
||||
cruft::ntoh<word_t>
|
||||
);
|
||||
h = compress<width> (h, dw, salt, t);
|
||||
}
|
||||
@ -293,7 +293,7 @@ blake<width>::operator() (
|
||||
std::cbegin (dw),
|
||||
std::cend (dw),
|
||||
std::begin (dw),
|
||||
util::ntoh<word_t>
|
||||
cruft::ntoh<word_t>
|
||||
);
|
||||
h = compress<width> (h, dw, salt, t);
|
||||
|
||||
@ -315,12 +315,12 @@ blake<width>::operator() (
|
||||
std::cbegin (dw),
|
||||
std::cend (dw) - 2,
|
||||
std::begin (dw),
|
||||
util::ntoh<word_t>
|
||||
cruft::ntoh<word_t>
|
||||
);
|
||||
h = compress<width> (h, dw, salt, empty ? 0 : t);
|
||||
}
|
||||
|
||||
std::transform (std::cbegin (h), std::cend (h), std::begin (h), util::hton<word_t>);
|
||||
std::transform (std::cbegin (h), std::cend (h), std::begin (h), cruft::hton<word_t>);
|
||||
digest_t d;
|
||||
memcpy (d.data (), h.data (), sizeof (d));
|
||||
return d;
|
||||
|
@ -87,14 +87,14 @@ namespace cruft::crypto::hash {
|
||||
|
||||
|
||||
digest_t operator() (
|
||||
util::view<const uint8_t*> data,
|
||||
util::view<const uint8_t*> salt
|
||||
cruft::view<const uint8_t*> data,
|
||||
cruft::view<const uint8_t*> salt
|
||||
) const;
|
||||
|
||||
digest_t operator() (util::view<const uint8_t*> data,
|
||||
digest_t operator() (cruft::view<const uint8_t*> data,
|
||||
const std::array<word_t,4> salt) const noexcept;
|
||||
|
||||
digest_t operator() (util::view<const uint8_t*> data) const noexcept
|
||||
digest_t operator() (cruft::view<const uint8_t*> data) const noexcept
|
||||
{
|
||||
return (*this) (data, {0,0,0,0});
|
||||
}
|
||||
|
@ -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<word_bits>::uint;
|
||||
using word_t = typename cruft::bits_type<word_bits>::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<word_t,16> &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<word_t,8> h, const word_t m[16], uint64_t t, bool f)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
blake2::blake2 () noexcept:
|
||||
blake2 (util::view<const uint8_t*>{nullptr})
|
||||
blake2 (cruft::view<const uint8_t*>{nullptr})
|
||||
{ ; }
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
blake2::blake2 (util::view<const uint8_t *> key)
|
||||
blake2::blake2 (cruft::view<const uint8_t *> 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<const uint8_t *> key)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
blake2::digest_t
|
||||
blake2::operator() (util::view<const uint8_t *> data) const noexcept
|
||||
blake2::operator() (cruft::view<const uint8_t *> 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<const word_t*> (m_salt.data ()), traits::block_bytes, data.empty ());
|
||||
h = F (h, reinterpret_cast<const word_t*> (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<const uint8_t *> 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<const word_t*> (cursor), counter, false);
|
||||
cursor += traits::block_bytes;
|
||||
cursor += ::traits::block_bytes;
|
||||
}
|
||||
|
||||
if (cursor != data.cend ()) {
|
||||
|
@ -23,9 +23,9 @@ namespace cruft::crypto::hash {
|
||||
|
||||
blake2 () noexcept;
|
||||
blake2 (const salt_t&) noexcept;
|
||||
blake2 (util::view<const uint8_t*> key);
|
||||
blake2 (cruft::view<const uint8_t*> key);
|
||||
|
||||
digest_t operator() (util::view<const uint8_t*>) const noexcept;
|
||||
digest_t operator() (cruft::view<const uint8_t*>) const noexcept;
|
||||
|
||||
private:
|
||||
using state_t = std::array<uint64_t,8>;
|
||||
|
@ -25,7 +25,7 @@ namespace cruft::crypto::hash {
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
HMAC (util::view<const std::uint8_t*> key)
|
||||
HMAC (cruft::view<const std::uint8_t*> key)
|
||||
{
|
||||
CHECK (!key.empty ());
|
||||
|
||||
|
@ -16,7 +16,7 @@ using cruft::crypto::hash::HOTP;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
HOTP::HOTP (util::view<const char*> _key, uint64_t _counter):
|
||||
HOTP::HOTP (cruft::view<const char*> _key, uint64_t _counter):
|
||||
m_counter (_counter),
|
||||
m_hash (_key.template cast<const uint8_t*> ())
|
||||
{ ; }
|
||||
@ -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;
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ namespace cruft::crypto::hash {
|
||||
/// HMAC one-time password (RFC 4226)
|
||||
class HOTP {
|
||||
public:
|
||||
HOTP (util::view<const char*> key, uint64_t counter);
|
||||
HOTP (cruft::view<const char*> key, uint64_t counter);
|
||||
|
||||
unsigned value (void);
|
||||
uint64_t counter (void) const;
|
||||
|
@ -50,7 +50,7 @@ static const size_t M_LENGTH = 16;
|
||||
static void
|
||||
transform (std::array<uint8_t,16> &C, std::array<uint8_t,48> &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<uint8_t,16> &C, std::array<uint8_t,48> &X) noexcept
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
MD2::digest_t
|
||||
MD2::operator() (const util::view<const uint8_t*> data) const noexcept
|
||||
MD2::operator() (const cruft::view<const uint8_t*> data) const noexcept
|
||||
{
|
||||
// zero initialise the state vectors, and create a simple window `M' into
|
||||
// the middle of the `X' state vector.
|
||||
std::array<uint8_t,16> C {};
|
||||
std::array<uint8_t,48> 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.
|
||||
|
@ -22,7 +22,7 @@ namespace cruft::crypto::hash {
|
||||
typedef std::array<uint8_t,16> digest_t;
|
||||
|
||||
public:
|
||||
digest_t operator() (util::view<const uint8_t*>) const noexcept;
|
||||
digest_t operator() (cruft::view<const uint8_t*>) const noexcept;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ transform (std::array<uint32_t,4> &ABCD, const std::array<uint32_t,16> &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<uint32_t,4> &ABCD, const std::array<uint32_t,16> &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<uint32_t,4> &ABCD, const std::array<uint32_t,16> &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<uint32_t,4> &ABCD, const std::array<uint32_t,16> &X) noexc
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
MD4::digest_t
|
||||
MD4::operator() (util::view<const uint8_t*> data) noexcept
|
||||
MD4::operator() (cruft::view<const uint8_t*> data) noexcept
|
||||
{
|
||||
/* RESET */
|
||||
uint64_t total = 0;
|
||||
|
@ -21,7 +21,7 @@ namespace cruft::crypto::hash {
|
||||
public:
|
||||
using digest_t = std::array<uint8_t,16>;
|
||||
|
||||
digest_t operator() (util::view<const uint8_t*>) noexcept;
|
||||
digest_t operator() (cruft::view<const uint8_t*>) noexcept;
|
||||
};
|
||||
}
|
||||
|
||||
|
16
hash/md5.cpp
16
hash/md5.cpp
@ -95,7 +95,7 @@ static constexpr uint32_t INITIAL_D = 0x10325476;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
typename MD5::digest_t
|
||||
MD5::operator() (util::view<const uint8_t*> a) const noexcept
|
||||
MD5::operator() (cruft::view<const uint8_t*> a) const noexcept
|
||||
{
|
||||
return (*this)(a, nullptr);
|
||||
}
|
||||
@ -103,7 +103,7 @@ MD5::operator() (util::view<const uint8_t*> a) const noexcept
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
typename MD5::digest_t
|
||||
MD5::operator() (util::view<const uint8_t*> a, util::view<const uint8_t*> b) const noexcept
|
||||
MD5::operator() (cruft::view<const uint8_t*> a, cruft::view<const uint8_t*> b) const noexcept
|
||||
{
|
||||
return (*this)(a, b, nullptr);
|
||||
}
|
||||
@ -112,9 +112,9 @@ MD5::operator() (util::view<const uint8_t*> a, util::view<const uint8_t*> b) con
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
typename MD5::digest_t
|
||||
MD5::operator() (
|
||||
const util::view<const uint8_t*> data_a,
|
||||
const util::view<const uint8_t*> data_b,
|
||||
const util::view<const uint8_t*> data_c
|
||||
const cruft::view<const uint8_t*> data_a,
|
||||
const cruft::view<const uint8_t*> data_b,
|
||||
const cruft::view<const uint8_t*> data_c
|
||||
) const noexcept {
|
||||
union {
|
||||
std::array<uint32_t,16> 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)
|
||||
|
||||
|
@ -25,9 +25,9 @@ namespace cruft::crypto::hash {
|
||||
static const size_t DIGEST_SIZE = 16;
|
||||
|
||||
public:
|
||||
digest_t operator() (util::view<const uint8_t*>) const noexcept;
|
||||
digest_t operator() (util::view<const uint8_t*>,util::view<const uint8_t*>) const noexcept;
|
||||
digest_t operator() (util::view<const uint8_t*>,util::view<const uint8_t*>,util::view<const uint8_t*>) const noexcept;
|
||||
digest_t operator() (cruft::view<const uint8_t*>) const noexcept;
|
||||
digest_t operator() (cruft::view<const uint8_t*>,cruft::view<const uint8_t*>) const noexcept;
|
||||
digest_t operator() (cruft::view<const uint8_t*>,cruft::view<const uint8_t*>,cruft::view<const uint8_t*>) const noexcept;
|
||||
|
||||
private:
|
||||
std::array<uint32_t,4>
|
||||
|
@ -14,7 +14,7 @@ using cruft::crypto::hash::MD6;
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
#if 0
|
||||
MD6::digest_t
|
||||
MD6::operator() (util::view<const uint8_t*> data) const noexcept
|
||||
MD6::operator() (cruft::view<const uint8_t*> data) const noexcept
|
||||
{
|
||||
static constexpr int rounds = 40 + digest_size / 4;
|
||||
static constexpr int mode_control = 64;
|
||||
|
@ -20,7 +20,7 @@ namespace cruft::crypto::hash {
|
||||
|
||||
using digest_t = std::array<uint8_t,digest_size/8>;
|
||||
|
||||
digest_t operator() (util::view<const uint8_t*> data) const noexcept;
|
||||
digest_t operator() (cruft::view<const uint8_t*> data) const noexcept;
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -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<const uint8_t*> data)
|
||||
RIPEMD::operator() (const cruft::view<const uint8_t*> data)
|
||||
{
|
||||
struct {
|
||||
union {
|
||||
@ -324,7 +324,7 @@ RIPEMD::operator() (const util::view<const uint8_t*> 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;
|
||||
|
@ -21,7 +21,7 @@ namespace cruft::crypto::hash {
|
||||
public:
|
||||
typedef std::array<uint8_t,20> digest_t;
|
||||
|
||||
digest_t operator() (util::view<const uint8_t*>);
|
||||
digest_t operator() (cruft::view<const uint8_t*>);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -92,12 +92,12 @@ process (std::array<uint32_t,5> &H, std::array<uint32_t,16+64> &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<uint32_t,5> &H, std::array<uint32_t,16+64> &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<uint32_t,5> &H, std::array<uint32_t,16+64> &W)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
SHA1::digest_t
|
||||
SHA1::operator() (util::view<const uint8_t*> data) noexcept
|
||||
SHA1::operator() (cruft::view<const uint8_t*> data) noexcept
|
||||
{
|
||||
return (*this) (data, nullptr);
|
||||
}
|
||||
@ -140,8 +140,8 @@ SHA1::operator() (util::view<const uint8_t*> data) noexcept
|
||||
//-----------------------------------------------------------------------------
|
||||
SHA1::digest_t
|
||||
SHA1::operator() (
|
||||
util::view<const uint8_t*> data_a,
|
||||
util::view<const uint8_t*> data_b
|
||||
cruft::view<const uint8_t*> data_a,
|
||||
cruft::view<const uint8_t*> 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<uint32_t>);
|
||||
std::transform (std::begin (H.w), std::end (H.w), std::begin (H.w), cruft::hton<uint32_t>);
|
||||
return H.b;
|
||||
}
|
||||
|
@ -28,8 +28,8 @@ namespace cruft::crypto::hash {
|
||||
//digest_t
|
||||
//operator() (DataT&&...);
|
||||
|
||||
digest_t operator() (util::view<const uint8_t*>, util::view<const uint8_t*>) noexcept;
|
||||
digest_t operator() (util::view<const uint8_t*>) noexcept;
|
||||
digest_t operator() (cruft::view<const uint8_t*>, cruft::view<const uint8_t*>) noexcept;
|
||||
digest_t operator() (cruft::view<const uint8_t*>) noexcept;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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<const uint8_t*> data) noexcept
|
||||
SHA256::operator() (cruft::view<const uint8_t*> 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<uint32_t>);
|
||||
std::transform (M.begin (), M.end (), std::begin (W), cruft::ntoh<uint32_t>);
|
||||
|
||||
for (size_t i = 16; i < 64; ++i)
|
||||
W[i] = s1(W[i - 2]) + W[i - 7] + s0 (W[i - 15]) + W[i - 16];
|
||||
|
@ -23,7 +23,7 @@ namespace cruft::crypto::hash {
|
||||
typedef std::array<uint8_t,32> digest_t;
|
||||
|
||||
public:
|
||||
digest_t operator() (util::view<const uint8_t*>) noexcept;
|
||||
digest_t operator() (cruft::view<const uint8_t*>) noexcept;
|
||||
|
||||
private:
|
||||
void process (void);
|
||||
|
@ -20,7 +20,7 @@ cruft::crypto::stream::salsa20 (const std::array<uint8_t,64> 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<uint8_t,64> bytes) noexcept
|
||||
x[i] += y[i];
|
||||
|
||||
for (auto &t: x)
|
||||
t = util::htol (t);
|
||||
t = cruft::htol (t);
|
||||
|
||||
return *reinterpret_cast<std::array<uint8_t,64>*> (&x);
|
||||
#pragma GCC diagnostic pop
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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];
|
||||
|
@ -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];
|
||||
|
@ -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];
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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");
|
||||
|
@ -48,13 +48,13 @@ main (int, char **) {
|
||||
|
||||
const MD2 h;
|
||||
for (const auto &i: TESTS) {
|
||||
if (h (util::view{i.input}.cast<const uint8_t*> ()) != i.output) {
|
||||
if (h (cruft::view{i.input}.cast<const uint8_t*> ()) != 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 ();
|
||||
}
|
||||
|
@ -56,13 +56,13 @@ main (int, char**) {
|
||||
|
||||
MD4 h;
|
||||
for (auto i: TESTS) {
|
||||
if (h (util::view{i.input}.cast <const uint8_t*> ()) != i.output) {
|
||||
if (h (cruft::view{i.input}.cast <const uint8_t*> ()) != 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 ();
|
||||
}
|
||||
|
@ -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<uint8_t> 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);
|
||||
};
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -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<const uint8_t*> ()), i.output, "%s", i.msg);
|
||||
tap.expect_eq (obj (cruft::view{i.input}.cast<const uint8_t*> ()), i.output, "%s", i.msg);
|
||||
}
|
||||
|
||||
return tap.status ();
|
||||
|
@ -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[] = {
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
void
|
||||
test_quarter (util::TAP::logger &tap)
|
||||
test_quarter (cruft::TAP::logger &tap)
|
||||
{
|
||||
static const struct {
|
||||
std::array<uint32_t, 4> 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<uint32_t, 16> 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<uint32_t,16> 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<uint32_t,16> 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<uint8_t,64> 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);
|
||||
|
@ -53,7 +53,7 @@ template <size_t S>
|
||||
std::ostream&
|
||||
print_digest (std::ostream &os, std::array<uint8_t,S> 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<uint8_t,S> digest)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
static void
|
||||
compute (const std::string &name, const util::view<const uint8_t*> data)
|
||||
compute (const std::string &name, const cruft::view<const uint8_t*> data)
|
||||
{
|
||||
#define stream(TYPE, ...) do { \
|
||||
if (name != #TYPE) \
|
||||
@ -73,7 +73,7 @@ compute (const std::string &name, const util::view<const uint8_t*> 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 {
|
||||
|
Loading…
Reference in New Issue
Block a user