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

#include <emsa_pkcs1.h>

Inheritance diagram for Botan::EMSA_PKCS1v15_Raw:
Botan::EMSA

Public Member Functions

virtual AlgorithmIdentifier config_for_x509 (const Private_Key &key, const std::string &cert_hash_name) const
 
 EMSA_PKCS1v15_Raw ()
 
 EMSA_PKCS1v15_Raw (const std::string &hash_algo)
 
secure_vector< uint8_t > encoding_of (const secure_vector< uint8_t > &, size_t, RandomNumberGenerator &rng) override
 
std::string name () const override
 
std::unique_ptr< EMSAnew_object () override
 
secure_vector< uint8_t > raw_data () override
 
bool requires_message_recovery () const override
 
void update (const uint8_t[], size_t) override
 
bool verify (const secure_vector< uint8_t > &, const secure_vector< uint8_t > &, size_t) 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_PKCS1v15_Raw which is EMSA_PKCS1v15 without a hash or digest id (which according to QCA docs is "identical to PKCS#11's CKM_RSA_PKCS mechanism", something I have not confirmed)

Definition at line 61 of file emsa_pkcs1.h.

Constructor & Destructor Documentation

◆ EMSA_PKCS1v15_Raw() [1/2]

Botan::EMSA_PKCS1v15_Raw::EMSA_PKCS1v15_Raw ( )

Definition at line 111 of file emsa_pkcs1.cpp.

112 {
113 m_hash_output_len = 0;
114 // m_hash_id, m_hash_name left empty
115 }

◆ EMSA_PKCS1v15_Raw() [2/2]

Botan::EMSA_PKCS1v15_Raw::EMSA_PKCS1v15_Raw ( const std::string &  hash_algo)
Parameters
hash_algothe digest id for that hash is included in the signature.

Definition at line 117 of file emsa_pkcs1.cpp.

118 {
119 std::unique_ptr<HashFunction> hash(HashFunction::create_or_throw(hash_algo));
120 m_hash_id = pkcs_hash_id(hash_algo);
121 m_hash_name = hash->name();
122 m_hash_output_len = hash->output_length();
123 }
static std::unique_ptr< HashFunction > create_or_throw(const std::string &algo_spec, const std::string &provider="")
Definition: hash.cpp:312
std::vector< uint8_t > pkcs_hash_id(const std::string &name)
Definition: hash_id.cpp:73
MechanismType hash
AlgorithmIdentifier hash_algo
Definition: x509_obj.cpp:22

References Botan::HashFunction::create_or_throw(), hash, hash_algo, and Botan::pkcs_hash_id().

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
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().

◆ encoding_of()

secure_vector< uint8_t > Botan::EMSA_PKCS1v15_Raw::encoding_of ( const secure_vector< uint8_t > &  msg,
size_t  output_bits,
RandomNumberGenerator rng 
)
overridevirtual

Return the encoding of a message

Parameters
msgthe result of raw_data()
output_bitsthe desired output bit size
rnga random number generator
Returns
encoded signature

Implements Botan::EMSA.

Definition at line 142 of file emsa_pkcs1.cpp.

145 {
146 return emsa3_encoding(msg, output_bits, m_hash_id.data(), m_hash_id.size());
147 }

◆ name()

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

Implements Botan::EMSA.

Definition at line 84 of file emsa_pkcs1.h.

85 {
86 if(m_hash_name.empty()) return "EMSA3(Raw)";
87 else return "EMSA3(Raw," + m_hash_name + ")";
88 }

◆ new_object()

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

Implements Botan::EMSA.

Definition at line 64 of file emsa_pkcs1.h.

64{ return std::make_unique<EMSA_PKCS1v15_Raw>(); }

◆ raw_data()

secure_vector< uint8_t > Botan::EMSA_PKCS1v15_Raw::raw_data ( )
overridevirtual
Returns
raw hash

Implements Botan::EMSA.

Definition at line 130 of file emsa_pkcs1.cpp.

131 {
132 secure_vector<uint8_t> ret;
133 std::swap(ret, m_message);
134
135 if(m_hash_output_len > 0 && ret.size() != m_hash_output_len)
136 throw Encoding_Error("EMSA_PKCS1v15_Raw::encoding_of: Bad input length");
137
138 return ret;
139 }

◆ requires_message_recovery()

bool Botan::EMSA_PKCS1v15_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 90 of file emsa_pkcs1.h.

90{ return true; }

◆ update()

void Botan::EMSA_PKCS1v15_Raw::update ( const uint8_t  input[],
size_t  length 
)
overridevirtual

Add more data to the signature computation

Parameters
inputsome data
lengthlength of input in bytes

Implements Botan::EMSA.

Definition at line 125 of file emsa_pkcs1.cpp.

126 {
127 m_message += std::make_pair(input, length);
128 }

◆ verify()

bool Botan::EMSA_PKCS1v15_Raw::verify ( const secure_vector< uint8_t > &  coded,
const secure_vector< uint8_t > &  raw,
size_t  key_bits 
)
overridevirtual

Verify the encoding

Parameters
codedthe received (coded) message representative
rawthe computed (local, uncoded) message representative
key_bitsthe size of the key in bits
Returns
true if coded is a valid encoding of raw, otherwise false

Implements Botan::EMSA.

Definition at line 149 of file emsa_pkcs1.cpp.

152 {
153 if(m_hash_output_len > 0 && raw.size() != m_hash_output_len)
154 return false;
155
156 try
157 {
158 return (coded == emsa3_encoding(raw, key_bits, m_hash_id.data(), m_hash_id.size()));
159 }
160 catch(...)
161 {
162 return false;
163 }
164 }

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