Botan  2.7.0
Crypto and TLS for C++11
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

EMSAclone () override
 
virtual AlgorithmIdentifier config_for_x509 (const Private_Key &key, const std::string &cert_hash_name) const
 
 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
 
secure_vector< uint8_t > raw_data () override
 
void update (const uint8_t[], size_t) override
 
bool verify (const secure_vector< uint8_t > &, const secure_vector< uint8_t > &, size_t) override
 

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 56 of file emsa_pkcs1.h.

Constructor & Destructor Documentation

◆ EMSA_PKCS1v15_Raw()

Botan::EMSA_PKCS1v15_Raw::EMSA_PKCS1v15_Raw ( const std::string &  hash_algo = "")
Parameters
hash_algoif non-empty, the digest id for that hash is included in the signature.

Definition at line 114 of file emsa_pkcs1.cpp.

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

115  {
116  if(!hash_algo.empty())
117  {
118  m_hash_id = pkcs_hash_id(hash_algo);
119  std::unique_ptr<HashFunction> hash(HashFunction::create_or_throw(hash_algo));
120  m_hash_name = hash->name();
121  m_hash_output_len = hash->output_length();
122  }
123  else
124  {
125  m_hash_output_len = 0;
126  }
127  }
static std::unique_ptr< HashFunction > create_or_throw(const std::string &algo_spec, const std::string &provider="")
Definition: hash.cpp:345
AlgorithmIdentifier hash_algo
Definition: x509_obj.cpp:23
MechanismType hash
std::vector< uint8_t > pkcs_hash_id(const std::string &name)
Definition: hash_id.cpp:77

Member Function Documentation

◆ clone()

EMSA* Botan::EMSA_PKCS1v15_Raw::clone ( )
inlineoverridevirtual
Returns
a new object representing the same encoding method as *this

Implements Botan::EMSA.

Definition at line 59 of file emsa_pkcs1.h.

59 { return new EMSA_PKCS1v15_Raw(); }
EMSA_PKCS1v15_Raw(const std::string &hash_algo="")
Definition: emsa_pkcs1.cpp:114

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

Definition at line 38 of file emsa.cpp.

References Botan::EMSA::name().

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

◆ 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 146 of file emsa_pkcs1.cpp.

149  {
150  return emsa3_encoding(msg, output_bits, m_hash_id.data(), m_hash_id.size());
151  }

◆ 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 77 of file emsa_pkcs1.h.

78  {
79  if(m_hash_name.empty()) return "EMSA3(Raw)";
80  else return "EMSA3(Raw," + m_hash_name + ")";
81  }

◆ raw_data()

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

Implements Botan::EMSA.

Definition at line 134 of file emsa_pkcs1.cpp.

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

◆ 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 129 of file emsa_pkcs1.cpp.

130  {
131  m_message += std::make_pair(input, length);
132  }

◆ 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 153 of file emsa_pkcs1.cpp.

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

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