Botan 3.11.0
Crypto and TLS for C&
kyber_90s.h
Go to the documentation of this file.
1/*
2 * Symmetric primitives for Kyber (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_90S_H_
11#define BOTAN_KYBER_90S_H_
12
13#include <botan/hash.h>
14#include <botan/internal/aes_crystals_xof.h>
15
16#include <botan/internal/kyber_symmetric_primitives.h>
17
18#include <array>
19#include <memory>
20
21namespace Botan {
22
24 protected:
25 std::optional<std::array<uint8_t, 1>> seed_expansion_domain_separator(
26 const KyberConstants& /*constants*/) const override {
27 return {};
28 }
29
30 std::unique_ptr<HashFunction> create_G() const override { return HashFunction::create_or_throw("SHA-512"); }
31
32 std::unique_ptr<HashFunction> create_H() const override { return HashFunction::create_or_throw("SHA-256"); }
33
34 std::unique_ptr<HashFunction> create_J() const override {
35 throw Invalid_State("Kyber-R3 in 90s mode does not support J()");
36 }
37
38 std::unique_ptr<HashFunction> create_KDF() const override { return HashFunction::create_or_throw("SHA-256"); }
39
40 std::unique_ptr<Botan::XOF> create_PRF(std::span<const uint8_t> seed, const uint8_t nonce) const override {
41 auto xof = std::make_unique<AES_256_CTR_XOF>();
42 init_PRF(*xof, seed, nonce);
43 return xof;
44 }
45
46 void init_PRF(Botan::XOF& xof, std::span<const uint8_t> seed, const uint8_t nonce) const override {
47 xof.clear();
48 dynamic_cast<AES_256_CTR_XOF&>(xof).start(std::array<uint8_t, 12>{nonce, 0}, seed);
49 }
50
51 std::unique_ptr<Botan::XOF> create_XOF(std::span<const uint8_t> seed,
52 std::tuple<uint8_t, uint8_t> mpos) const override {
53 auto xof = std::make_unique<AES_256_CTR_XOF>();
54 init_XOF(*xof, seed, mpos);
55 return xof;
56 }
57
58 void init_XOF(Botan::XOF& xof, std::span<const uint8_t> seed, std::tuple<uint8_t, uint8_t> mpos) const override {
59 xof.clear();
60 dynamic_cast<AES_256_CTR_XOF&>(xof).start(std::array<uint8_t, 12>{std::get<0>(mpos), std::get<1>(mpos), 0},
61 seed);
62 }
63};
64
65} // namespace Botan
66
67#endif
static std::unique_ptr< HashFunction > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition hash.cpp:308
std::optional< std::array< uint8_t, 1 > > seed_expansion_domain_separator(const KyberConstants &) const override
Definition kyber_90s.h:25
void init_PRF(Botan::XOF &xof, std::span< const uint8_t > seed, const uint8_t nonce) const override
Definition kyber_90s.h:46
void init_XOF(Botan::XOF &xof, std::span< const uint8_t > seed, std::tuple< uint8_t, uint8_t > mpos) const override
Definition kyber_90s.h:58
std::unique_ptr< Botan::XOF > create_XOF(std::span< const uint8_t > seed, std::tuple< uint8_t, uint8_t > mpos) const override
Definition kyber_90s.h:51
std::unique_ptr< HashFunction > create_G() const override
Definition kyber_90s.h:30
std::unique_ptr< Botan::XOF > create_PRF(std::span< const uint8_t > seed, const uint8_t nonce) const override
Definition kyber_90s.h:40
std::unique_ptr< HashFunction > create_H() const override
Definition kyber_90s.h:32
std::unique_ptr< HashFunction > create_KDF() const override
Definition kyber_90s.h:38
std::unique_ptr< HashFunction > create_J() const override
Definition kyber_90s.h:34
void clear()
Definition xof.h:64