Botan 3.11.0
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/internal/bitvector.h>
15#include <botan/internal/cmce_field_ordering.h>
16#include <botan/internal/cmce_keys_internal.h>
17#include <botan/internal/cmce_matrix.h>
18#include <botan/internal/cmce_types.h>
19#include <botan/internal/pk_ops_impl.h>
20
21namespace Botan {
22
23/**
24 * Classic McEliece Decapsulation Operation
25 */
27 public:
28 /**
29 * @brief Constructs a Classic_McEliece_Decryptor object with the given private key.
30 * @param key The private key used for decryption.
31 */
32 Classic_McEliece_Decryptor(std::shared_ptr<Classic_McEliece_PrivateKeyInternal> key, std::string_view kdf) :
33 KEM_Decryption_with_KDF(kdf), m_key(std::move(key)) {}
34
35 size_t raw_kem_shared_key_length() const override { return m_key->params().hash_out_bytes(); }
36
37 size_t encapsulated_key_length() const override { return m_key->params().ciphertext_size(); }
38
39 void raw_kem_decrypt(std::span<uint8_t> out_shared_key, std::span<const uint8_t> encapsulated_key) override;
40
41 private:
42 /**
43 * @brief Computes the syndrome of a code word.
44 *
45 * Corresponds to H' * code_word of the spec, where H' is the syndrome computation matrix used for the
46 * Berlekamp's method of decoding. See https://tungchou.github.io/papers/mcbits.pdf for more information.
47 *
48 * @param params The McEliece parameters.
49 * @param goppa_poly The Goppa polynomial.
50 * @param ordering The field ordering.
51 * @param code_word The code word.
52 * @return The syndrome S(x) of the code word.
53 */
54 Classic_McEliece_Polynomial compute_goppa_syndrome(const Classic_McEliece_Parameters& params,
56 const Classic_McEliece_Field_Ordering& ordering,
57 const secure_bitvector& code_word) const;
58
59 /**
60 * @brief Applies the Berlekamp-Massey algorithm to compute the error locator polynomial given a syndrome.
61 *
62 * The error locator polynomial C can be used for decoding, as C(a_i) = 0 <=> error at position i.
63 *
64 * @param params The McEliece parameters.
65 * @param syndrome The syndrome polynomial of the code word.
66 * @return The error locator polynomial.
67 */
68 Classic_McEliece_Polynomial berlekamp_massey(const Classic_McEliece_Parameters& params,
69 const Classic_McEliece_Polynomial& syndrome) const;
70
71 /**
72 * @brief Decodes a code word using Berlekamp's method.
73 *
74 * @param big_c The code word.
75 * @return A pair containing the decoded message and the error pattern.
76 */
77 std::pair<CT::Mask<uint8_t>, CmceErrorVector> decode(CmceCodeWord big_c) const;
78
79 std::shared_ptr<Classic_McEliece_PrivateKeyInternal> m_key;
80};
81
82} // namespace Botan
83
84#endif // BOTAN_CMCE_DECAPS_H_
#define BOTAN_TEST_API
Definition api.h:41
size_t encapsulated_key_length() const override
Definition cmce_decaps.h:37
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:32
size_t raw_kem_shared_key_length() const override
Definition cmce_decaps.h:35
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
KEM_Decryption_with_KDF(std::string_view kdf)
Definition pk_ops.cpp:266
Strong< secure_bitvector, struct CmceCodeWord_ > CmceCodeWord
Represents C of decapsulation.
Definition cmce_types.h:52
bitvector_base< secure_allocator > secure_bitvector
Definition bitvector.h:1304
Strong< secure_bitvector, struct CmceErrorVector_ > CmceErrorVector
Represents e of encapsulation.
Definition cmce_types.h:49