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

#include <emsa_raw.h>

Inheritance diagram for Botan::EMSA_Raw:
Botan::EMSA

Public Member Functions

virtual AlgorithmIdentifier config_for_x509 (const Private_Key &key, const std::string &cert_hash_name) const
 
 EMSA_Raw (size_t expected_hash_size=0)
 
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

EMSA-Raw - sign inputs directly Don't use this unless you know what you are doing.

Definition at line 19 of file emsa_raw.h.

Constructor & Destructor Documentation

◆ EMSA_Raw()

Botan::EMSA_Raw::EMSA_Raw ( size_t  expected_hash_size = 0)
inlineexplicit

Definition at line 24 of file emsa_raw.h.

24 :
25 m_expected_size(expected_hash_size) {}

Member Function Documentation

◆ config_for_x509()

AlgorithmIdentifier Botan::EMSA::config_for_x509 ( const Private_Key key,
const std::string &  cert_hash_name 
) const
virtualinherited

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 in Botan::EMSA1, Botan::EMSA_PKCS1v15, and Botan::PSSR.

Definition at line 38 of file emsa.cpp.

40 {
41 throw Not_Implemented("Encoding " + name() + " not supported for signing X509 objects");
42 }
virtual std::string name() const =0

References Botan::EMSA::name().

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

Implements Botan::EMSA.

Definition at line 13 of file emsa_raw.cpp.

14 {
15 if(m_expected_size > 0)
16 return "Raw(" + std::to_string(m_expected_size) + ")";
17 return "Raw";
18 }
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::EMSA_Raw::new_object ( )
inlineoverridevirtual
Returns
a new object representing the same encoding method as *this

Implements Botan::EMSA.

Definition at line 22 of file emsa_raw.h.

22{ return std::make_unique<EMSA_Raw>(); }

◆ requires_message_recovery()

bool Botan::EMSA_Raw::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 29 of file emsa_raw.h.

29{ return false; }

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