Botan 3.4.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 *
6 * Botan is released under the Simplified BSD License (see license.txt)
7 */
8
9#ifndef BOTAN_KYBER_90S_H_
10#define BOTAN_KYBER_90S_H_
11
12#include <botan/hash.h>
13#include <botan/internal/aes_crystals_xof.h>
14
15#include <botan/internal/kyber_symmetric_primitives.h>
16
17#include <array>
18#include <memory>
19
20namespace Botan {
21
23 public:
25 m_sha512(HashFunction::create_or_throw("SHA-512")),
26 m_sha256(HashFunction::create_or_throw("SHA-256")),
27 m_aes256_ctr_xof(std::make_unique<AES_256_CTR_XOF>()),
28 m_aes256_ctr_prf(std::make_unique<AES_256_CTR_XOF>()) {}
29
30 std::unique_ptr<HashFunction> G() const override { return m_sha512->new_object(); }
31
32 std::unique_ptr<HashFunction> H() const override { return m_sha256->new_object(); }
33
34 std::unique_ptr<HashFunction> KDF() const override { return m_sha256->new_object(); }
35
36 Botan::XOF& XOF(std::span<const uint8_t> seed, std::tuple<uint8_t, uint8_t> mpos) const override {
37 m_aes256_ctr_xof->clear();
38 const std::array<uint8_t, 12> iv{std::get<0>(mpos), std::get<1>(mpos), 0};
39 m_aes256_ctr_xof->start(iv, seed);
40 return *m_aes256_ctr_xof;
41 }
42
43 secure_vector<uint8_t> PRF(std::span<const uint8_t> seed,
44 const uint8_t nonce,
45 const size_t outlen) const override {
46 m_aes256_ctr_prf->clear();
47 const std::array<uint8_t, 12> nonce_buffer{nonce, 0};
48 m_aes256_ctr_prf->start(nonce_buffer, seed);
49 return m_aes256_ctr_prf->output(outlen);
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_ctr_xof;
56 std::unique_ptr<AES_256_CTR_XOF> m_aes256_ctr_prf;
57};
58
59} // namespace Botan
60
61#endif
std::unique_ptr< HashFunction > G() const override
Definition kyber_90s.h:30
secure_vector< uint8_t > PRF(std::span< const uint8_t > seed, const uint8_t nonce, const size_t outlen) const override
Definition kyber_90s.h:43
Botan::XOF & XOF(std::span< const uint8_t > seed, std::tuple< uint8_t, uint8_t > mpos) const override
Definition kyber_90s.h:36
std::unique_ptr< HashFunction > KDF() const override
Definition kyber_90s.h:34
std::unique_ptr< HashFunction > H() const override
Definition kyber_90s.h:32
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61