8#include <botan/internal/siphash.h>
10#include <botan/exceptn.h>
11#include <botan/internal/buffer_slicer.h>
12#include <botan/internal/fmt.h>
13#include <botan/internal/loadstor.h>
14#include <botan/internal/rotate.h>
27 for(
size_t i = 0; i != r; ++i) {
55 BOTAN_ARG_CHECK(m_C > 0 && m_C <= 64,
"SipHash C parameter out of range");
56 BOTAN_ARG_CHECK(m_D > 0 && m_D <= 64,
"SipHash D parameter out of range");
59void SipHash::add_data(std::span<const uint8_t> input) {
63 m_words +=
static_cast<uint8_t
>(input.size());
68 while(!in.empty() && m_mbuf_pos != 8) {
69 m_mbuf = (m_mbuf >> 8) | (
static_cast<uint64_t
>(in.take_byte()) << 56);
74 SipRounds(m_mbuf, m_V, m_C);
80 while(in.remaining() >= 8) {
85 m_mbuf = (m_mbuf >> 8) | (
static_cast<uint64_t
>(in.take_byte()) << 56);
90void SipHash::final_result(std::span<uint8_t> mac) {
94 m_mbuf = (
static_cast<uint64_t
>(m_words) << 56);
95 }
else if(m_mbuf_pos < 8) {
96 m_mbuf = (m_mbuf >> (64 - m_mbuf_pos * 8)) | (
static_cast<uint64_t
>(m_words) << 56);
99 SipRounds(m_mbuf, m_V, m_C);
102 SipRounds(0, m_V, m_D);
104 const uint64_t X = m_V[0] ^ m_V[1] ^ m_V[2] ^ m_V[3];
111void SipHash::start_msg(std::span<const uint8_t> nonce) {
113 throw Invalid_IV_Length(
name(), nonce.size());
120void SipHash::reset_msg() {
122 m_V[0] = m_K[0] ^ 0x736F6D6570736575;
123 m_V[1] = m_K[1] ^ 0x646F72616E646F6D;
124 m_V[2] = m_K[0] ^ 0x6C7967656E657261;
125 m_V[3] = m_K[1] ^ 0x7465646279746573;
135void SipHash::key_schedule(std::span<const uint8_t> key) {
156 return fmt(
"SipHash({},{})", m_C, m_D);
160 return std::make_unique<SipHash>(m_C, m_D);
#define BOTAN_ARG_CHECK(expr, msg)
std::string name() const override
SipHash(size_t c, size_t d)
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)
std::string fmt(std::string_view format, const T &... args)
constexpr auto store_le(ParamTs &&... params)
BOTAN_FORCE_INLINE constexpr T rotl(T input)
constexpr auto load_le(ParamTs &&... params)
std::vector< T, secure_allocator< T > > secure_vector