Botan 3.0.0-alpha0
Crypto and TLS for C&
Public Member Functions | Static Public Member Functions | List of all members
Botan::PSSR Class Referencefinal

#include <pssr.h>

Inheritance diagram for Botan::PSSR:
Botan::EMSA

Public Member Functions

AlgorithmIdentifier config_for_x509 (const Private_Key &key, const std::string &cert_hash_name) const override
 
std::string name () const override
 
std::unique_ptr< EMSAnew_object () override
 
 PSSR (std::unique_ptr< HashFunction > hash)
 
 PSSR (std::unique_ptr< HashFunction > hash, size_t salt_size)
 
bool requires_message_recovery () const override
 

Static Public Member Functions

static std::unique_ptr< EMSAcreate (const std::string &algo_spec)
 
static std::unique_ptr< EMSAcreate_or_throw (const std::string &algo_spec)
 

Detailed Description

PSSR (called EMSA4 in IEEE 1363 and in old versions of the library)

Definition at line 19 of file pssr.h.

Constructor & Destructor Documentation

◆ PSSR() [1/2]

Botan::PSSR::PSSR ( std::unique_ptr< HashFunction hash)
explicit
Parameters
hashthe hash function to use

Definition at line 128 of file pssr.cpp.

128 :
129 m_hash(std::move(hash)),
130 m_salt_size(m_hash->output_length()),
131 m_required_salt_len(false)
132 {
133 }
MechanismType hash

◆ PSSR() [2/2]

Botan::PSSR::PSSR ( std::unique_ptr< HashFunction hash,
size_t  salt_size 
)
Parameters
hashthe hash function to use
salt_sizethe size of the salt to use in bytes

Definition at line 135 of file pssr.cpp.

135 :
136 m_hash(std::move(hash)),
137 m_salt_size(salt_size),
138 m_required_salt_len(true)
139 {
140 }
size_t salt_size

Member Function Documentation

◆ config_for_x509()

AlgorithmIdentifier Botan::PSSR::config_for_x509 ( const Private_Key key,
const std::string &  cert_hash_name 
) const
overridevirtual

Prepare sig_algo for use in choose_sig_format for x509 certs

Parameters
keyused for checking compatibility with the encoding scheme
cert_hash_nameis checked to equal the hash for the encoding
Returns
algorithm identifier to signatures created using this key, padding method and hash.

Reimplemented from Botan::EMSA.

Definition at line 192 of file pssr.cpp.

194 {
195 if(cert_hash_name != m_hash->name())
196 throw Invalid_Argument("Hash function from opts and hash_fn argument"
197 " need to be identical");
198 // check that the signature algorithm and the padding scheme fit
199 if(!sig_algo_and_pad_ok(key.algo_name(), "EMSA4"))
200 {
201 throw Invalid_Argument("Encoding scheme with canonical name EMSA4"
202 " not supported for signature algorithm " + key.algo_name());
203 }
204
205 const AlgorithmIdentifier hash_id(cert_hash_name, AlgorithmIdentifier::USE_NULL_PARAM);
206 const AlgorithmIdentifier mgf_id("MGF1", hash_id.BER_encode());
207
208 std::vector<uint8_t> parameters;
209 DER_Encoder(parameters)
210 .start_sequence()
211 .start_context_specific(0).encode(hash_id).end_cons()
212 .start_context_specific(1).encode(mgf_id).end_cons()
213 .start_context_specific(2).encode(m_salt_size).end_cons()
214 .start_context_specific(3).encode(size_t(1)).end_cons() // trailer field
215 .end_cons();
216
217 // hardcoded as RSA is the only valid algorithm for EMSA4 at the moment
218 return AlgorithmIdentifier("RSA/EMSA4", parameters);
219 }
bool sig_algo_and_pad_ok(const std::string &algo, const std::string &padding)
Definition: padding.cpp:39

References Botan::Public_Key::algo_name(), Botan::ASN1_Object::BER_encode(), Botan::DER_Encoder::encode(), Botan::DER_Encoder::end_cons(), Botan::sig_algo_and_pad_ok(), Botan::DER_Encoder::start_context_specific(), Botan::DER_Encoder::start_sequence(), and Botan::AlgorithmIdentifier::USE_NULL_PARAM.

◆ create()

std::unique_ptr< EMSA > Botan::EMSA::create ( const std::string &  algo_spec)
staticinherited

Factory method for EMSA (message-encoding methods for signatures with appendix) objects

Parameters
algo_specthe name of the EMSA to create
Returns
pointer to newly allocated object of that type, or nullptr

Definition at line 44 of file emsa.cpp.

45 {
46 SCAN_Name req(algo_spec);
47
48#if defined(BOTAN_HAS_EMSA1)
49 if(req.algo_name() == "EMSA1" && req.arg_count() == 1)
50 {
51 if(auto hash = HashFunction::create(req.arg(0)))
52 return std::make_unique<EMSA1>(std::move(hash));
53 }
54#endif
55
56#if defined(BOTAN_HAS_EMSA_PKCS1)
57 if(req.algo_name() == "EMSA_PKCS1" ||
58 req.algo_name() == "PKCS1v15" ||
59 req.algo_name() == "EMSA-PKCS1-v1_5" ||
60 req.algo_name() == "EMSA3")
61 {
62 if(req.arg_count() == 2 && req.arg(0) == "Raw")
63 {
64 return std::make_unique<EMSA_PKCS1v15_Raw>(req.arg(1));
65 }
66 else if(req.arg_count() == 1)
67 {
68 if(req.arg(0) == "Raw")
69 {
70 return std::make_unique<EMSA_PKCS1v15_Raw>();
71 }
72 else
73 {
74 if(auto hash = HashFunction::create(req.arg(0)))
75 {
76 return std::make_unique<EMSA_PKCS1v15>(std::move(hash));
77 }
78 }
79 }
80 }
81#endif
82
83#if defined(BOTAN_HAS_EMSA_PSSR)
84 if(req.algo_name() == "PSS_Raw" ||
85 req.algo_name() == "PSSR_Raw")
86 {
87 if(req.arg_count_between(1, 3) && req.arg(1, "MGF1") == "MGF1")
88 {
89 if(auto hash = HashFunction::create(req.arg(0)))
90 {
91 if(req.arg_count() == 3)
92 {
93 const size_t salt_size = req.arg_as_integer(2, 0);
94 return std::make_unique<PSSR_Raw>(std::move(hash), salt_size);
95 }
96 else
97 {
98 return std::make_unique<PSSR_Raw>(std::move(hash));
99 }
100 }
101 }
102 }
103
104 if(req.algo_name() == "PSS" ||
105 req.algo_name() == "PSSR" ||
106 req.algo_name() == "EMSA-PSS" ||
107 req.algo_name() == "PSS-MGF1" ||
108 req.algo_name() == "EMSA4")
109 {
110 if(req.arg_count_between(1, 3) && req.arg(1, "MGF1") == "MGF1")
111 {
112 if(auto hash = HashFunction::create(req.arg(0)))
113 {
114 if(req.arg_count() == 3)
115 {
116 const size_t salt_size = req.arg_as_integer(2, 0);
117 return std::make_unique<PSSR>(std::move(hash), salt_size);
118 }
119 else
120 {
121 return std::make_unique<PSSR>(std::move(hash));
122 }
123 }
124 }
125 }
126#endif
127
128#if defined(BOTAN_HAS_ISO_9796)
129 if(req.algo_name() == "ISO_9796_DS2")
130 {
131 if(req.arg_count_between(1, 3))
132 {
133 if(auto hash = HashFunction::create(req.arg(0)))
134 {
135 const size_t salt_size = req.arg_as_integer(2, hash->output_length());
136 const bool implicit = req.arg(1, "exp") == "imp";
137 return std::make_unique<ISO_9796_DS2>(std::move(hash), implicit, salt_size);
138 }
139 }
140 }
141 //ISO-9796-2 DS 3 is deterministic and DS2 without a salt
142 if(req.algo_name() == "ISO_9796_DS3")
143 {
144 if(req.arg_count_between(1, 2))
145 {
146 if(auto hash = HashFunction::create(req.arg(0)))
147 {
148 const bool implicit = req.arg(1, "exp") == "imp";
149 return std::make_unique<ISO_9796_DS3>(std::move(hash), implicit);
150 }
151 }
152 }
153#endif
154
155#if defined(BOTAN_HAS_EMSA_X931)
156 if(req.algo_name() == "EMSA_X931" ||
157 req.algo_name() == "EMSA2" ||
158 req.algo_name() == "X9.31")
159 {
160 if(req.arg_count() == 1)
161 {
162 if(auto hash = HashFunction::create(req.arg(0)))
163 {
164 return std::make_unique<EMSA_X931>(std::move(hash));
165 }
166 }
167 }
168#endif
169
170#if defined(BOTAN_HAS_EMSA_RAW)
171 if(req.algo_name() == "Raw")
172 {
173 if(req.arg_count() == 0)
174 {
175 return std::make_unique<EMSA_Raw>();
176 }
177 else
178 {
179 auto hash = HashFunction::create(req.arg(0));
180 if(hash)
181 return std::make_unique<EMSA_Raw>(hash->output_length());
182 }
183 }
184#endif
185
186 return nullptr;
187 }
static std::unique_ptr< HashFunction > create(const std::string &algo_spec, const std::string &provider="")
Definition: hash.cpp:98

References Botan::SCAN_Name::algo_name(), Botan::SCAN_Name::arg(), Botan::SCAN_Name::arg_as_integer(), Botan::SCAN_Name::arg_count(), Botan::SCAN_Name::arg_count_between(), Botan::HashFunction::create(), hash, and salt_size.

Referenced by Botan::EMSA::create_or_throw().

◆ create_or_throw()

std::unique_ptr< EMSA > Botan::EMSA::create_or_throw ( const std::string &  algo_spec)
staticinherited

Factory method for EMSA (message-encoding methods for signatures with appendix) objects

Parameters
algo_specthe name of the EMSA to create
Returns
pointer to newly allocated object of that type, or throws

Definition at line 189 of file emsa.cpp.

190 {
191 auto emsa = EMSA::create(algo_spec);
192 if(emsa)
193 return emsa;
194 throw Algorithm_Not_Found(algo_spec);
195 }
static std::unique_ptr< EMSA > create(const std::string &algo_spec)
Definition: emsa.cpp:44

References Botan::EMSA::create().

◆ name()

std::string Botan::PSSR::name ( ) const
overridevirtual
Returns
the SCAN name of the encoding/padding scheme

Implements Botan::EMSA.

Definition at line 187 of file pssr.cpp.

188 {
189 return "EMSA4(" + m_hash->name() + ",MGF1," + std::to_string(m_salt_size) + ")";
190 }
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:209

References Botan::ASN1::to_string().

◆ new_object()

std::unique_ptr< EMSA > Botan::PSSR::new_object ( )
overridevirtual
Returns
a new object representing the same encoding method as *this

Implements Botan::EMSA.

Definition at line 182 of file pssr.cpp.

183 {
184 return std::make_unique<PSSR>(m_hash->new_object(), m_salt_size);
185 }

◆ requires_message_recovery()

bool Botan::PSSR::requires_message_recovery ( ) const
inlineoverridevirtual

Return true if using this EMSA correctly requires a signature scheme with message recovery

Implements Botan::EMSA.

Definition at line 41 of file pssr.h.

41{ return true; }

The documentation for this class was generated from the following files: