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

#include <emsa1.h>

Inheritance diagram for Botan::EMSA1:
Botan::EMSA

Public Member Functions

AlgorithmIdentifier config_for_x509 (const Private_Key &key, const std::string &cert_hash_name) const override
 
 EMSA1 (std::unique_ptr< HashFunction > hash)
 
std::string name () const override
 
std::unique_ptr< EMSAnew_object () override
 
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

EMSA1 from IEEE 1363 Essentially, sign the hash directly

Definition at line 20 of file emsa1.h.

Constructor & Destructor Documentation

◆ EMSA1()

Botan::EMSA1::EMSA1 ( std::unique_ptr< HashFunction hash)
inlineexplicit
Parameters
hashthe hash function to use

Definition at line 26 of file emsa1.h.

26: m_hash(std::move(hash)) {}
MechanismType hash

Member Function Documentation

◆ config_for_x509()

AlgorithmIdentifier Botan::EMSA1::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 100 of file emsa1.cpp.

102 {
103 if(cert_hash_name != m_hash->name())
104 throw Invalid_Argument("Hash function from opts and hash_fn argument"
105 " need to be identical");
106 // check that the signature algorithm and the padding scheme fit
107 if(!sig_algo_and_pad_ok(key.algo_name(), "EMSA1"))
108 {
109 throw Invalid_Argument("Encoding scheme with canonical name EMSA1"
110 " not supported for signature algorithm " + key.algo_name());
111 }
112
113 const OID oid = OID::from_string(key.algo_name() + "/" + name());
114
115 const std::string algo_name = key.algo_name();
116 std::vector<uint8_t> parameters;
117 if(algo_name == "DSA" ||
118 algo_name == "ECDSA" ||
119 algo_name == "ECGDSA" ||
120 algo_name == "ECKCDSA" ||
121 algo_name == "GOST-34.10" ||
122 algo_name == "GOST-34.10-2012-256" ||
123 algo_name == "GOST-34.10-2012-512")
124 {
125 // for DSA, ECDSA, GOST parameters "SHALL" be empty
126 }
127 else
128 {
129 parameters = key.algorithm_identifier().get_parameters();
130 }
131
132 return AlgorithmIdentifier(oid, parameters);
133 }
std::string name() const override
Definition: emsa1.cpp:48
static OID from_string(const std::string &str)
Definition: asn1_oid.cpp:61
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::Public_Key::algorithm_identifier(), Botan::OID::from_string(), Botan::AlgorithmIdentifier::get_parameters(), name(), and Botan::sig_algo_and_pad_ok().

◆ 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
size_t salt_size

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::EMSA1::name ( ) const
overridevirtual
Returns
the SCAN name of the encoding/padding scheme

Implements Botan::EMSA.

Definition at line 48 of file emsa1.cpp.

49 {
50 return "EMSA1(" + m_hash->name() + ")";
51 }

Referenced by config_for_x509().

◆ new_object()

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

Implements Botan::EMSA.

Definition at line 53 of file emsa1.cpp.

54 {
55 return std::make_unique<EMSA1>(m_hash->new_object());
56 }

◆ requires_message_recovery()

bool Botan::EMSA1::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 32 of file emsa1.h.

32{ return false; }

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