/src/Botan-3.4.0/build/include/public/botan/sphincsplus.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * SPHINCS+ Hash based signature scheme |
3 | | * Based on the creative commons (CC0 1.0) reference implementation by the |
4 | | * designers (https://github.com/sphincs/sphincsplus/) |
5 | | * |
6 | | * (C) 2023 Jack Lloyd |
7 | | * 2023 Fabian Albert, René Meusel, Rohde & Schwarz Cybersecurity |
8 | | * |
9 | | * Botan is released under the Simplified BSD License (see license.txt) |
10 | | **/ |
11 | | |
12 | | #ifndef BOTAN_SPHINCS_PLUS_H_ |
13 | | #define BOTAN_SPHINCS_PLUS_H_ |
14 | | |
15 | | #include <botan/pk_keys.h> |
16 | | #include <botan/sp_parameters.h> |
17 | | |
18 | | #include <memory> |
19 | | #include <vector> |
20 | | |
21 | | namespace Botan { |
22 | | |
23 | | class SphincsPlus_PublicKeyInternal; |
24 | | class SphincsPlus_PrivateKeyInternal; |
25 | | |
26 | | /** |
27 | | * This implementation is based on |
28 | | * https://github.com/sphincs/sphincsplus/commit/06f42f47491085ac879a72b486ca8edb10891963 |
29 | | * |
30 | | * which implements SPHINCS+ Specification Round 3.1 (https://sphincs.org/data/sphincs+-r3.1-specification.pdf). |
31 | | * The used tweaked hashes are implemented according to the variant 'simple' ('robust' is not supported). |
32 | | */ |
33 | | class BOTAN_PUBLIC_API(3, 1) SphincsPlus_PublicKey : public virtual Public_Key { |
34 | | public: |
35 | | SphincsPlus_PublicKey(std::span<const uint8_t> pub_key, Sphincs_Parameter_Set type, Sphincs_Hash_Type hash); |
36 | | SphincsPlus_PublicKey(std::span<const uint8_t> pub_key, Sphincs_Parameters params); |
37 | | SphincsPlus_PublicKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits); |
38 | | |
39 | | ~SphincsPlus_PublicKey() override; |
40 | | |
41 | | size_t key_length() const override; |
42 | | |
43 | 0 | std::string algo_name() const override { return "SPHINCS+"; } |
44 | | |
45 | | size_t estimated_strength() const override; |
46 | | AlgorithmIdentifier algorithm_identifier() const override; |
47 | | OID object_identifier() const override; |
48 | | bool check_key(RandomNumberGenerator& rng, bool strong) const override; |
49 | | std::vector<uint8_t> public_key_bits() const override; |
50 | | |
51 | | std::unique_ptr<Private_Key> generate_another(RandomNumberGenerator& rng) const final; |
52 | | |
53 | | std::unique_ptr<PK_Ops::Verification> create_verification_op(std::string_view params, |
54 | | std::string_view provider) const override; |
55 | | |
56 | | std::unique_ptr<PK_Ops::Verification> create_x509_verification_op(const AlgorithmIdentifier& signature_algorithm, |
57 | | std::string_view provider) const override; |
58 | | |
59 | | bool supports_operation(PublicKeyOperation op) const override; |
60 | | |
61 | | protected: |
62 | 0 | SphincsPlus_PublicKey() = default; |
63 | | |
64 | | std::shared_ptr<SphincsPlus_PublicKeyInternal> m_public; |
65 | | }; |
66 | | |
67 | | BOTAN_DIAGNOSTIC_PUSH |
68 | | BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE |
69 | | |
70 | | class BOTAN_PUBLIC_API(3, 1) SphincsPlus_PrivateKey final : public virtual SphincsPlus_PublicKey, |
71 | | public virtual Private_Key { |
72 | | public: |
73 | | SphincsPlus_PrivateKey(std::span<const uint8_t> private_key, Sphincs_Parameter_Set type, Sphincs_Hash_Type hash); |
74 | | SphincsPlus_PrivateKey(std::span<const uint8_t> private_key, Sphincs_Parameters params); |
75 | | SphincsPlus_PrivateKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits); |
76 | | SphincsPlus_PrivateKey(RandomNumberGenerator& rng, Sphincs_Parameter_Set type, Sphincs_Hash_Type hash); |
77 | | SphincsPlus_PrivateKey(RandomNumberGenerator& rng, Sphincs_Parameters params); |
78 | | |
79 | | ~SphincsPlus_PrivateKey() override; |
80 | | |
81 | | secure_vector<uint8_t> private_key_bits() const override; |
82 | | secure_vector<uint8_t> raw_private_key_bits() const override; |
83 | | std::unique_ptr<Public_Key> public_key() const override; |
84 | | |
85 | | std::unique_ptr<PK_Ops::Signature> create_signature_op(RandomNumberGenerator& rng, |
86 | | std::string_view params, |
87 | | std::string_view provider) const override; |
88 | | |
89 | | private: |
90 | | std::shared_ptr<SphincsPlus_PrivateKeyInternal> m_private; |
91 | | }; |
92 | | |
93 | | BOTAN_DIAGNOSTIC_POP |
94 | | |
95 | | } // namespace Botan |
96 | | |
97 | | #endif |