/src/Botan-3.13.0/build/include/public/botan/pss_params.h
Line | Count | Source |
1 | | /* |
2 | | * (C) 2017 Daniel Neus |
3 | | * 2023 Jack Lloyd |
4 | | * |
5 | | * Botan is released under the Simplified BSD License (see license.txt) |
6 | | */ |
7 | | |
8 | | #ifndef BOTAN_PSS_PARAMS_H_ |
9 | | #define BOTAN_PSS_PARAMS_H_ |
10 | | |
11 | | #include <botan/asn1_obj.h> |
12 | | #include <string> |
13 | | |
14 | | namespace Botan { |
15 | | |
16 | | /** |
17 | | * PSS parameters type |
18 | | * |
19 | | * Handles encoding/decoding of RSASSA-PSS-params from RFC 3447 |
20 | | * |
21 | | * Only MGF1 is supported, and the trailer field must 1 (ie the variant |
22 | | * from IEEE 1363a using a hash identifier is not supported) |
23 | | */ |
24 | | class BOTAN_PUBLIC_API(3, 7) PSS_Params final : public ASN1_Object { |
25 | | public: |
26 | | /** |
27 | | * Note that the only valid strings you can pass to this function |
28 | | * are values returned by SignaturePaddingScheme::name() and |
29 | | * these may change in a minor release. |
30 | | */ |
31 | | static PSS_Params from_padding_name(std::string_view padding_name); |
32 | | |
33 | | /** |
34 | | * Note that the only valid strings you can pass to this function |
35 | | * are values returned by SignaturePaddingScheme::name() and |
36 | | * these may change in a minor release. |
37 | | */ |
38 | | BOTAN_DEPRECATED("Use PSS_Params::from_padding_name") |
39 | 0 | static PSS_Params from_emsa_name(std::string_view padding_name) { |
40 | 0 | return PSS_Params::from_padding_name(padding_name); |
41 | 0 | } |
42 | | |
43 | | /** |
44 | | * Create PSS parameters using MGF1 with the same hash as the message hash |
45 | | * |
46 | | * @param hash_fn the name of the hash function to use |
47 | | * @param salt_len the salt length in bytes |
48 | | */ |
49 | | PSS_Params(std::string_view hash_fn, size_t salt_len); |
50 | | |
51 | | /** |
52 | | * Decode an encoded RSASSA-PSS-params |
53 | | */ |
54 | | BOTAN_FUTURE_EXPLICIT PSS_Params(std::span<const uint8_t> der); |
55 | | |
56 | | /** |
57 | | * Return the AlgorithmIdentifier of the hash used to hash the message |
58 | | */ |
59 | 0 | const AlgorithmIdentifier& hash_algid() const { return m_hash; } |
60 | | |
61 | | /** |
62 | | * Return the AlgorithmIdentifier of the mask generation function |
63 | | */ |
64 | 0 | const AlgorithmIdentifier& mgf_algid() const { return m_mgf; } |
65 | | |
66 | | /** |
67 | | * Return the AlgorithmIdentifier of the hash used within the mask generation function |
68 | | */ |
69 | 0 | const AlgorithmIdentifier& mgf_hash_algid() const { return m_mgf_hash; } |
70 | | |
71 | | /** |
72 | | * Return the salt length in bytes |
73 | | */ |
74 | 0 | size_t salt_length() const { return m_salt_len; } |
75 | | |
76 | | /** |
77 | | * Return the trailer field; only a value of 1 is supported |
78 | | */ |
79 | 0 | size_t trailer_field() const { return m_trailer_field; } |
80 | | |
81 | | /** |
82 | | * Return the name of the hash used to hash the message |
83 | | */ |
84 | 0 | std::string hash_function() const { return hash_algid().oid().to_formatted_string(); } |
85 | | |
86 | | /** |
87 | | * Return the name of the mask generation function; only MGF1 is supported |
88 | | */ |
89 | 0 | std::string mgf_function() const { return mgf_algid().oid().to_formatted_string(); } |
90 | | |
91 | | /** |
92 | | * Return the DER encoding of these RSASSA-PSS-params |
93 | | */ |
94 | | std::vector<uint8_t> serialize() const; |
95 | | |
96 | | void encode_into(DER_Encoder& to) const override; |
97 | | |
98 | | private: |
99 | | // We don't currently support uninitialized PSS_Params |
100 | | void decode_from(BER_Decoder& from) override; |
101 | | |
102 | | AlgorithmIdentifier m_hash; |
103 | | AlgorithmIdentifier m_mgf; |
104 | | AlgorithmIdentifier m_mgf_hash; |
105 | | size_t m_salt_len; |
106 | | size_t m_trailer_field; |
107 | | }; |
108 | | |
109 | | } // namespace Botan |
110 | | |
111 | | #endif |