Botan 3.12.0
Crypto and TLS for C&
tls_signature_scheme.h
Go to the documentation of this file.
1/*
2* TLS Signature Scheme
3* (C) 2022 Jack Lloyd
4* 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_TLS_SIGNATURE_SCHEME_H_
10#define BOTAN_TLS_SIGNATURE_SCHEME_H_
11
12#include <botan/asn1_obj.h>
13#include <botan/types.h>
14#include <optional>
15#include <string>
16#include <vector>
17
18namespace Botan {
19
20enum class Signature_Format : uint8_t;
21class Private_Key;
22
23} // namespace Botan
24
25namespace Botan::TLS {
26
28
30 public:
31 /**
32 * Matches with wire encoding
33 *
34 * Note that this is intentionally left as a bare enum. It emulates the Botan 2
35 * API where `Signature_Scheme` was an enum class with associated free-standing
36 * functions. Leaving it as a bare enum resembles the legacy user-facing API.
37 */
38 enum Code : uint16_t /* NOLINT(*-use-enum-class) */ {
39 NONE = 0x0000,
40
41 RSA_PKCS1_SHA1 = 0x0201, // not implemented
45
46 ECDSA_SHA1 = 0x0203, // not implemented
47 ECDSA_SHA256 = 0x0403,
48 ECDSA_SHA384 = 0x0503,
49 ECDSA_SHA512 = 0x0603,
50
54
55 EDDSA_25519 = 0x0807,
56 EDDSA_448 = 0x0808,
57 };
58
59 public:
60 /**
61 * @return all available signature schemes
62 */
63 static const std::vector<Signature_Scheme>& all_available_schemes();
64
65 /**
66 * Construct an uninitialized / invalid scheme
67 */
69
70 /* NOLINT(*-explicit-conversions) */ Signature_Scheme(uint16_t wire_code);
71
72 /* NOLINT(*-explicit-conversions) */ Signature_Scheme(Signature_Scheme::Code wire_code);
73
74 Signature_Scheme::Code wire_code() const noexcept { return m_code; }
75
76 /**
77 * @return true if support for this scheme is implemented in this Botan build
78 */
79 bool is_available() const noexcept;
80
81 /**
82 * @return true if the wire_code is set to any value other than `NONE`
83 */
84 bool is_set() const noexcept;
85
86 std::string to_string() const noexcept;
87 std::string hash_function_name() const noexcept;
88 std::string padding_string() const noexcept;
89 std::string algorithm_name() const noexcept;
90 AlgorithmIdentifier key_algorithm_identifier() const noexcept;
91 AlgorithmIdentifier algorithm_identifier() const noexcept;
92 std::optional<Signature_Format> format() const noexcept;
93
94 bool is_compatible_with(const Protocol_Version& protocol_version) const noexcept;
95
96 /**
97 * Checks that @p private_key is suitable for use with this signature
98 * scheme, enforcing the curve-hash binding required by TLS 1.3 (e.g.
99 * ECDSA_SHA256 only with P-256 keys). This must not be used for TLS
100 * 1.2 scheme selection, where signature schemes are (hash, algorithm)
101 * pairs with no curve binding -- any hash may be used with any ECDSA
102 * curve per RFC 5246.
103 */
104 bool is_suitable_for(const Private_Key& private_key) const noexcept;
105
106 bool operator==(const Signature_Scheme& rhs) const { return m_code == rhs.m_code; }
107
108 bool operator!=(const Signature_Scheme& rhs) const { return !(*this == rhs); }
109
110 private:
112};
113
114std::vector<AlgorithmIdentifier> to_algorithm_identifiers(const std::vector<Signature_Scheme>& schemes);
115
116} // namespace Botan::TLS
117
118#endif // BOTAN_TLS_SIGNATURE_SCHEME_H_
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:21
Signature_Scheme::Code wire_code() const noexcept
bool operator!=(const Signature_Scheme &rhs) const
std::vector< AlgorithmIdentifier > to_algorithm_identifiers(const std::vector< Signature_Scheme > &schemes)
Signature_Format
Definition pk_keys.h:32
std::string to_string(ErrorType type)
Convert an ErrorType to string.
Definition exceptn.cpp:13