8#include <botan/internal/siphash.h>
10#include <botan/internal/fmt.h>
11#include <botan/internal/loadstor.h>
12#include <botan/internal/rotate.h>
13#include <botan/internal/stl_util.h>
20 uint64_t V0 = V[0], V1 = V[1], V2 = V[2], V3 = V[3];
23 for(
size_t i = 0; i != r; ++i) {
50void SipHash::add_data(std::span<const uint8_t> input) {
54 m_words +=
static_cast<uint8_t
>(input.size());
56 BufferSlicer in(input);
59 while(!in.empty() && m_mbuf_pos != 8) {
60 m_mbuf = (m_mbuf >> 8) | (
static_cast<uint64_t
>(in.take_byte()) << 56);
65 SipRounds(m_mbuf, m_V, m_C);
71 while(in.remaining() >= 8) {
76 m_mbuf = (m_mbuf >> 8) | (
static_cast<uint64_t
>(in.take_byte()) << 56);
81void SipHash::final_result(std::span<uint8_t> mac) {
85 m_mbuf = (
static_cast<uint64_t
>(m_words) << 56);
86 }
else if(m_mbuf_pos < 8) {
87 m_mbuf = (m_mbuf >> (64 - m_mbuf_pos * 8)) | (
static_cast<uint64_t
>(m_words) << 56);
90 SipRounds(m_mbuf, m_V, m_C);
93 SipRounds(0, m_V, m_D);
95 const uint64_t
X = m_V[0] ^ m_V[1] ^ m_V[2] ^ m_V[3];
99 m_V[0] = m_K[0] ^ 0x736F6D6570736575;
100 m_V[1] = m_K[1] ^ 0x646F72616E646F6D;
101 m_V[2] = m_K[0] ^ 0x6C7967656E657261;
102 m_V[3] = m_K[1] ^ 0x7465646279746573;
112void SipHash::key_schedule(std::span<const uint8_t> key) {
121 m_V[0] = m_K[0] ^ 0x736F6D6570736575;
122 m_V[1] = m_K[1] ^ 0x646F72616E646F6D;
123 m_V[2] = m_K[0] ^ 0x6C7967656E657261;
124 m_V[3] = m_K[1] ^ 0x7465646279746573;
136 return fmt(
"SipHash({},{})", m_C, m_D);
140 return std::make_unique<SipHash>(m_C, m_D);
std::string name() const override
bool has_keying_material() const override
std::unique_ptr< MessageAuthenticationCode > new_object() const override
void assert_key_material_set() const
void zap(std::vector< T, Alloc > &vec)
constexpr T rotl(T input)
std::string fmt(std::string_view format, const T &... args)
constexpr auto store_le(ParamTs &&... params)
constexpr auto load_le(ParamTs &&... params)
std::vector< T, secure_allocator< T > > secure_vector