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