Botan 3.11.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-2024 Jack Lloyd
4 * (C) 2022 Hannes Rantzsch, René Meusel, neXenio GmbH
5 * (C) 2024 René Meusel, Rohde & Schwarz Cybersecurity
6 *
7 * Botan is released under the Simplified BSD License (see license.txt)
8 */
9
10#ifndef BOTAN_KYBER_MODERN_H_
11#define BOTAN_KYBER_MODERN_H_
12
13#include <botan/internal/kyber_symmetric_primitives.h>
14
15#include <botan/hash.h>
16#include <botan/xof.h>
17#include <array>
18#include <memory>
19
20namespace Botan {
21
23 protected:
24 std::optional<std::array<uint8_t, 1>> seed_expansion_domain_separator(
25 const KyberConstants& /*constants*/) const override {
26 return {};
27 }
28
29 std::unique_ptr<HashFunction> create_G() const override { return HashFunction::create_or_throw("SHA-3(512)"); }
30
31 std::unique_ptr<HashFunction> create_H() const override { return HashFunction::create_or_throw("SHA-3(256)"); }
32
33 std::unique_ptr<HashFunction> create_J() const override { throw Invalid_State("Kyber-R3 does not support J()"); }
34
35 std::unique_ptr<HashFunction> create_KDF() const override {
36 return HashFunction::create_or_throw("SHAKE-256(256)");
37 }
38
39 std::unique_ptr<Botan::XOF> create_PRF(std::span<const uint8_t> seed, const uint8_t nonce) const override {
40 auto xof = Botan::XOF::create_or_throw("SHAKE-256");
41 init_PRF(*xof, seed, nonce);
42 return xof;
43 }
44
45 void init_PRF(Botan::XOF& xof, std::span<const uint8_t> seed, const uint8_t nonce) const override {
46 xof.clear();
47 xof.update(seed);
48 xof.update({&nonce, 1});
49 }
50
51 std::unique_ptr<Botan::XOF> create_XOF(std::span<const uint8_t> seed,
52 std::tuple<uint8_t, uint8_t> matrix_position) const override {
53 auto xof = Botan::XOF::create_or_throw("SHAKE-128");
54 init_XOF(*xof, seed, matrix_position);
55 return xof;
56 }
57
59 std::span<const uint8_t> seed,
60 std::tuple<uint8_t, uint8_t> matrix_position) const override {
61 xof.clear();
62 xof.update(seed);
63
64 const std::array<uint8_t, 2> pos = {std::get<0>(matrix_position), std::get<1>(matrix_position)};
65 xof.update(pos);
66 }
67};
68
69} // namespace Botan
70
71#endif
static std::unique_ptr< HashFunction > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition hash.cpp:308
void init_PRF(Botan::XOF &xof, std::span< const uint8_t > seed, const uint8_t nonce) const override
void init_XOF(Botan::XOF &xof, std::span< const uint8_t > seed, std::tuple< uint8_t, uint8_t > matrix_position) const override
std::unique_ptr< HashFunction > create_KDF() const override
std::unique_ptr< HashFunction > create_G() const override
std::unique_ptr< HashFunction > create_J() const override
std::optional< std::array< uint8_t, 1 > > seed_expansion_domain_separator(const KyberConstants &) const override
std::unique_ptr< Botan::XOF > create_XOF(std::span< const uint8_t > seed, std::tuple< uint8_t, uint8_t > matrix_position) const override
std::unique_ptr< HashFunction > create_H() const override
std::unique_ptr< Botan::XOF > create_PRF(std::span< const uint8_t > seed, const uint8_t nonce) const override
void clear()
Definition xof.h:64
static std::unique_ptr< XOF > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition xof.cpp:54
void update(std::span< const uint8_t > input)
Definition xof.h:140