8#include <botan/siphash.h>
9#include <botan/loadstor.h>
10#include <botan/rotate.h>
16void SipRounds(uint64_t M, secure_vector<uint64_t>& V,
size_t r)
18 uint64_t V0 = V[0], V1 = V[1], V2 = V[2], V3 = V[3];
21 for(
size_t i = 0; i != r; ++i)
37 V[0] = V0; V[1] = V1; V[2] = V2; V[3] = V3;
42void SipHash::add_data(
const uint8_t input[],
size_t length)
47 m_words +=
static_cast<uint8_t
>(length);
51 while(length && m_mbuf_pos != 8)
53 m_mbuf = (m_mbuf >> 8) | (
static_cast<uint64_t
>(input[0]) << 56);
61 SipRounds(m_mbuf, m_V, m_C);
74 for(
size_t i = 0; i != length; ++i)
76 m_mbuf = (m_mbuf >> 8) | (
static_cast<uint64_t
>(input[i]) << 56);
81void SipHash::final_result(uint8_t mac[])
87 m_mbuf = (
static_cast<uint64_t
>(m_words) << 56);
89 else if(m_mbuf_pos < 8)
91 m_mbuf = (m_mbuf >> (64-m_mbuf_pos*8)) | (
static_cast<uint64_t
>(m_words) << 56);
94 SipRounds(m_mbuf, m_V, m_C);
97 SipRounds(0, m_V, m_D);
99 const uint64_t
X = m_V[0] ^ m_V[1] ^ m_V[2] ^ m_V[3];
106void SipHash::key_schedule(
const uint8_t key[],
size_t)
112 m_V[0] = K0 ^ 0x736F6D6570736575;
113 m_V[1] = K1 ^ 0x646F72616E646F6D;
114 m_V[2] = K0 ^ 0x6C7967656E657261;
115 m_V[3] = K1 ^ 0x7465646279746573;
std::string name() const override
MessageAuthenticationCode * clone() const override
SipHash(size_t c=2, size_t d=4)
void verify_key_set(bool cond) const
std::string to_string(const BER_Object &obj)
void zap(std::vector< T, Alloc > &vec)
void store_le(uint16_t in, uint8_t out[2])
uint64_t load_le< uint64_t >(const uint8_t in[], size_t off)