Botan 3.5.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 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 public:
26 m_sha512(HashFunction::create_or_throw("SHA-512")),
27 m_sha256(HashFunction::create_or_throw("SHA-256")),
28 m_aes256_xof(std::make_unique<AES_256_CTR_XOF>()) {}
29
30 protected:
31 HashFunction& get_G() const override { return *m_sha512; }
32
33 HashFunction& get_H() const override { return *m_sha256; }
34
35 HashFunction& get_KDF() const override { return *m_sha256; }
36
37 Botan::XOF& get_PRF(std::span<const uint8_t> seed, const uint8_t nonce) const override {
38 m_aes256_xof->clear();
39 const std::array<uint8_t, 12> nonce_buffer{nonce, 0};
40 m_aes256_xof->start(nonce_buffer, seed);
41 return *m_aes256_xof;
42 }
43
44 std::unique_ptr<Botan::XOF> get_XOF(std::span<const uint8_t> seed,
45 std::tuple<uint8_t, uint8_t> mpos) const override {
46 auto xof = m_aes256_xof->new_object();
47 const std::array<uint8_t, 12> iv{std::get<0>(mpos), std::get<1>(mpos), 0};
48 xof->start(iv, seed);
49 return xof;
50 }
51
52 private:
53 std::unique_ptr<HashFunction> m_sha512;
54 std::unique_ptr<HashFunction> m_sha256;
55 std::unique_ptr<AES_256_CTR_XOF> m_aes256_xof;
56};
57
58} // namespace Botan
59
60#endif
HashFunction & get_G() const override
Definition kyber_90s.h:31
HashFunction & get_KDF() const override
Definition kyber_90s.h:35
HashFunction & get_H() const override
Definition kyber_90s.h:33
std::unique_ptr< Botan::XOF > get_XOF(std::span< const uint8_t > seed, std::tuple< uint8_t, uint8_t > mpos) const override
Definition kyber_90s.h:44
Botan::XOF & get_PRF(std::span< const uint8_t > seed, const uint8_t nonce) const override
Definition kyber_90s.h:37