Botan 3.13.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 // RFC 9846 4.3.3
47 // ECDSA algorithms: Indicates a signature algorithm using ECDSA,
48 // the corresponding curve as defined in NIST SP 800-186.
49 //
50 // In TLS 1.3 these code points specifically refer to the NIST curves
51 // P-256, P-384, and P-521. In contrast TLS 1.2 uses these code points
52 // for ECDSA on any curve paired with the specified hash function.
56
57 // RFC 5246 7.4.1.4.1
58 // The client uses the "signature_algorithms" extension to indicate
59 // to the server which signature/hash algorithm pairs may be used in
60 // digital signatures.
61 //
62 // In TLS 1.2 the signature_algorithms extension contains pairs of hash
63 // and signature algorithms. For ECDSA these code points are not bound
64 // to a specific curve in contrast to TLS 1.3, where these code points
65 // imply the usage of NIST's P-256, P-384, and P-521 curves.
66 ECDSA_SHA1 = 0x0203, // not implemented
70
74
75 // RFC 8734
79
80 EDDSA_25519 = 0x0807,
81 EDDSA_448 = 0x0808,
82 };
83
84 public:
85 /**
86 * @return all available signature schemes
87 */
88 static const std::vector<Signature_Scheme>& all_available_schemes();
89
90 /**
91 * @return the signature scheme corresponding to the given string
92 */
93 static Signature_Scheme from_string(std::string_view str);
94
95 /**
96 * Construct an uninitialized / invalid scheme
97 */
99
100 /* NOLINT(*-explicit-conversions) */ Signature_Scheme(uint16_t wire_code);
101
102 /* NOLINT(*-explicit-conversions) */ Signature_Scheme(Signature_Scheme::Code wire_code);
103
104 Signature_Scheme::Code wire_code() const noexcept { return m_code; }
105
106 /**
107 * @return true if support for this scheme is implemented in this Botan build
108 */
109 bool is_available() const noexcept;
110
111 /**
112 * @return true if the wire_code is set to any value other than `NONE`
113 */
114 bool is_set() const noexcept;
115
116 std::string to_string() const;
117 std::string hash_function_name() const;
118 std::string padding_string() const;
119 std::string algorithm_name() const;
120 AlgorithmIdentifier key_algorithm_identifier() const;
121 AlgorithmIdentifier algorithm_identifier() const;
122 std::optional<Signature_Format> format() const noexcept;
123
124 bool is_compatible_with(const Protocol_Version& protocol_version) const noexcept;
125
126 /**
127 * Checks that @p private_key is suitable for use with this signature
128 * scheme, enforcing the curve-hash binding required by TLS 1.3 (e.g.
129 * ECDSA_SHA256 only with P-256 keys). This must not be used for TLS
130 * 1.2 scheme selection, where signature schemes are (hash, algorithm)
131 * pairs with no curve binding -- any hash may be used with any ECDSA
132 * curve per RFC 5246.
133 */
134 bool is_suitable_for(const Private_Key& private_key) const;
135
136 bool operator==(const Signature_Scheme& rhs) const { return m_code == rhs.m_code; }
137
138 bool operator!=(const Signature_Scheme& rhs) const { return !(*this == rhs); }
139
140 private:
142};
143
144std::vector<AlgorithmIdentifier> to_algorithm_identifiers(const std::vector<Signature_Scheme>& schemes);
145
146} // namespace Botan::TLS
147
148#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