Botan 3.4.0
Crypto and TLS for C&
kyber_modern.h
Go to the documentation of this file.
1/*
2 * Symmetric primitives for Kyber (modern (non-90s) mode)
3 * (C) 2022 Jack Lloyd
4 * (C) 2022 Hannes Rantzsch, René Meusel, neXenio GmbH
5 *
6 * Botan is released under the Simplified BSD License (see license.txt)
7 */
8
9#ifndef BOTAN_KYBER_MODERN_H_
10#define BOTAN_KYBER_MODERN_H_
11
12#include <botan/hash.h>
13#include <botan/xof.h>
14
15#include <botan/internal/kyber_symmetric_primitives.h>
16#include <botan/internal/shake.h>
17
18#include <array>
19#include <memory>
20#include <vector>
21
22namespace Botan {
23
25 public:
27 m_sha3_512(HashFunction::create_or_throw("SHA-3(512)")),
28 m_sha3_256(HashFunction::create_or_throw("SHA-3(256)")),
29 m_shake256_256(HashFunction::create_or_throw("SHAKE-256(256)")),
30 m_shake128(Botan::XOF::create_or_throw("SHAKE-128")) {}
31
32 std::unique_ptr<HashFunction> G() const override { return m_sha3_512->new_object(); }
33
34 std::unique_ptr<HashFunction> H() const override { return m_sha3_256->new_object(); }
35
36 std::unique_ptr<HashFunction> KDF() const override { return m_shake256_256->new_object(); }
37
38 Botan::XOF& XOF(std::span<const uint8_t> seed, std::tuple<uint8_t, uint8_t> matrix_position) const override {
39 m_shake128->clear();
40 m_shake128->update(seed);
41
42 const std::array<uint8_t, 2> matrix_position_buffer{std::get<0>(matrix_position),
43 std::get<1>(matrix_position)};
44 m_shake128->update(matrix_position_buffer);
45 return *m_shake128;
46 }
47
48 secure_vector<uint8_t> PRF(std::span<const uint8_t> seed,
49 const uint8_t nonce,
50 const size_t outlen) const override {
51 SHAKE_256 kdf(outlen * 8);
52 kdf.update(seed.data(), seed.size());
53 kdf.update(nonce);
54 return kdf.final();
55 }
56
57 private:
58 std::unique_ptr<HashFunction> m_sha3_512;
59 std::unique_ptr<HashFunction> m_sha3_256;
60 std::unique_ptr<HashFunction> m_shake256_256;
61 std::unique_ptr<Botan::XOF> m_shake128;
62};
63
64} // namespace Botan
65
66#endif
void update(const uint8_t in[], size_t length)
Definition buf_comp.h:35
void final(uint8_t out[])
Definition buf_comp.h:70
std::unique_ptr< HashFunction > H() const override
std::unique_ptr< HashFunction > KDF() const override
Botan::XOF & XOF(std::span< const uint8_t > seed, std::tuple< uint8_t, uint8_t > matrix_position) const override
std::unique_ptr< HashFunction > G() const override
secure_vector< uint8_t > PRF(std::span< const uint8_t > seed, const uint8_t nonce, const size_t outlen) const override
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61