build: avoid cast and alignment warnings

This commit is contained in:
Danny Robson 2018-06-01 13:24:05 +10:00
parent 623b65041c
commit 2b8b733bfd
6 changed files with 11 additions and 6 deletions

View File

@ -17,6 +17,7 @@
#include "blake.hpp"
#include <cruft/util/bitwise.hpp>
#include <cruft/util/cast.hpp>
#include <cruft/util/endian.hpp>
#include <cruft/util/view.hpp>
@ -256,7 +257,7 @@ blake<width>::operator() (
// perform the simple case where we're consuming whole blocks
for (auto last = data.cend ();
(unsigned)(last - cursor) >= sizeof (dw);
util::cast::sign<size_t> (last - cursor) >= sizeof (dw);
cursor += sizeof (dw))
{
// use the number of bits as the size

View File

@ -152,6 +152,8 @@ blake2::blake2 (util::view<const uint8_t *> key)
blake2::digest_t
blake2::operator() (util::view<const uint8_t *> data) const noexcept
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-align"
auto h = traits::iv;
h[0] ^= 0x01010000 ^ (m_keylen << 8) ^ sizeof (digest_t);
@ -183,5 +185,6 @@ blake2::operator() (util::view<const uint8_t *> data) const noexcept
digest_t d;
memcpy (&d, h.data (), sizeof (d));
return d;
#pragma GCC diagnostic pop
}

View File

@ -135,8 +135,6 @@ MD5::operator() (
static_assert (sizeof (X.b) == BLOCK_SIZE);
static_assert (X.b.size () == BLOCK_SIZE);
static_assert ((void*)&X.w == (void*)&X.b);
uint64_t m_total = 0;
std::array<uint32_t,4> ABCD = {
INITIAL_A,

View File

@ -346,7 +346,7 @@ RIPEMD::operator() (const util::view<const uint8_t*> data)
cursor += chunk;
}
if (m_length >> sizeof (m_length) * 8 - 3 != 0)
if (m_length >> ((sizeof (m_length) * 8) - 3) != 0)
panic ("exceeded maximum message length");
}
@ -355,7 +355,7 @@ RIPEMD::operator() (const util::view<const uint8_t*> data)
{
// Ensure the length wouldn't overflow if converted to bits. We need to
// grab this before there's a chance it gets overwritten.
CHECK_EQ (m_length >> sizeof(m_length) * 8 - 3, 0u);
CHECK_EQ (m_length >> ((sizeof(m_length) * 8) - 3), 0u);
uint64_t length = m_length * 8;
// Push a padding byte into the buffer

View File

@ -22,6 +22,8 @@
std::array<uint8_t,64>
cruft::crypto::stream::salsa20 (const std::array<uint8_t,64> bytes) noexcept
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-align"
auto x = *reinterpret_cast<const std::array<uint32_t,16>*> (&bytes);
auto y = x;
@ -38,4 +40,5 @@ cruft::crypto::stream::salsa20 (const std::array<uint8_t,64> bytes) noexcept
t = util::htol (t);
return *reinterpret_cast<std::array<uint8_t,64>*> (&x);
#pragma GCC diagnostic pop
}

View File

@ -245,5 +245,5 @@ main (void)
test_doubleround (tap);
test_salsa20 (tap);
return 0;
return tap.status ();
}