Botan 3.7.1
Crypto and TLS for C&
cmce_decaps.h
Go to the documentation of this file.
1/*
2 * Classic McEliece Decapsulation
3 * (C) 2023 Jack Lloyd
4 * 2023,2024 Fabian Albert, Amos Treiber - Rohde & Schwarz Cybersecurity
5 *
6 * Botan is released under the Simplified BSD License (see license.txt)
7 **/
8
9#ifndef BOTAN_CMCE_DECAPS_H_
10#define BOTAN_CMCE_DECAPS_H_
11
12#include <botan/cmce.h>
13#include <botan/pk_ops.h>
14#include <botan/rng.h>
15#include <botan/internal/bitvector.h>
16#include <botan/internal/cmce_field_ordering.h>
17#include <botan/internal/cmce_keys_internal.h>
18#include <botan/internal/cmce_matrix.h>
19#include <botan/internal/cmce_types.h>
20#include <botan/internal/pk_ops_impl.h>
21
22namespace Botan {
23
24/**
25 * Classic McEliece Decapsulation Operation
26 */
28 public:
29 /**
30 * @brief Constructs a Classic_McEliece_Decryptor object with the given private key.
31 * @param key The private key used for decryption.
32 */
33 Classic_McEliece_Decryptor(std::shared_ptr<Classic_McEliece_PrivateKeyInternal> key, std::string_view kdf) :
34 KEM_Decryption_with_KDF(kdf), m_key(std::move(key)) {}
35
36 size_t raw_kem_shared_key_length() const override { return m_key->params().hash_out_bytes(); }
37
38 size_t encapsulated_key_length() const override { return m_key->params().ciphertext_size(); }
39
40 void raw_kem_decrypt(std::span<uint8_t> out_shared_key, std::span<const uint8_t> encapsulated_key) override;
41
42 private:
43 /**
44 * @brief Computes the syndrome of a code word.
45 *
46 * Corresponds to H' * code_word of the spec, where H' is the syndrome computation matrix used for the
47 * Berlekamp's method of decoding. See https://tungchou.github.io/papers/mcbits.pdf for more information.
48 *
49 * @param params The McEliece parameters.
50 * @param goppa_poly The Goppa polynomial.
51 * @param ordering The field ordering.
52 * @param code_word The code word.
53 * @return The syndrome S(x) of the code word.
54 */
55 Classic_McEliece_Polynomial compute_goppa_syndrome(const Classic_McEliece_Parameters& params,
57 const Classic_McEliece_Field_Ordering& ordering,
58 const secure_bitvector& code_word) const;
59
60 /**
61 * @brief Applies the Berlekamp-Massey algorithm to compute the error locator polynomial given a syndrome.
62 *
63 * The error locator polynomial C can be used for decoding, as C(a_i) = 0 <=> error at position i.
64 *
65 * @param params The McEliece parameters.
66 * @param syndrome The syndrome polynomial of the code word.
67 * @return The error locator polynomial.
68 */
69 Classic_McEliece_Polynomial berlekamp_massey(const Classic_McEliece_Parameters& params,
70 const Classic_McEliece_Polynomial& syndrome) const;
71
72 /**
73 * @brief Decodes a code word using Berlekamp's method.
74 *
75 * @param big_c The code word.
76 * @return A pair containing the decoded message and the error pattern.
77 */
78 std::pair<CT::Mask<uint8_t>, CmceErrorVector> decode(CmceCodeWord big_c) const;
79
80 std::shared_ptr<Classic_McEliece_PrivateKeyInternal> m_key;
81};
82
83} // namespace Botan
84
85#endif // BOTAN_CMCE_DECAPS_H_
#define BOTAN_TEST_API
Definition api.h:39
size_t encapsulated_key_length() const override
Definition cmce_decaps.h:38
Classic_McEliece_Decryptor(std::shared_ptr< Classic_McEliece_PrivateKeyInternal > key, std::string_view kdf)
Constructs a Classic_McEliece_Decryptor object with the given private key.
Definition cmce_decaps.h:33
size_t raw_kem_shared_key_length() const override
Definition cmce_decaps.h:36
Represents a field ordering for the Classic McEliece cryptosystem.
Representation of a minimal polynomial in GF(q)[y].
Definition cmce_poly.h:81
Representation of a Classic McEliece polynomial.
Definition cmce_poly.h:32
int(* final)(unsigned char *, CTX *)