Botan  2.4.0
Crypto and TLS for C++11
Public Member Functions | List of all members
Botan::EMSA_PKCS1v15 Class Referencefinal

#include <emsa_pkcs1.h>

Inheritance diagram for Botan::EMSA_PKCS1v15:
Botan::EMSA

Public Member Functions

EMSAclone () override
 
AlgorithmIdentifier config_for_x509 (const Private_Key &key, const std::string &cert_hash_name) const override
 
 EMSA_PKCS1v15 (HashFunction *hash)
 
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

PKCS #1 v1.5 signature padding aka PKCS #1 block type 1 aka EMSA3 from IEEE 1363

Definition at line 21 of file emsa_pkcs1.h.

Constructor & Destructor Documentation

◆ EMSA_PKCS1v15()

Botan::EMSA_PKCS1v15::EMSA_PKCS1v15 ( HashFunction hash)
explicit
Parameters
hashthe hash function to use

Definition at line 109 of file emsa_pkcs1.cpp.

References Botan::pkcs_hash_id().

109  : m_hash(hash)
110  {
111  m_hash_id = pkcs_hash_id(m_hash->name());
112  }
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::clone ( )
inlineoverridevirtual
Returns
a new object representing the same encoding method as *this

Implements Botan::EMSA.

Definition at line 29 of file emsa_pkcs1.h.

29 { return new EMSA_PKCS1v15(m_hash->clone()); }
EMSA_PKCS1v15(HashFunction *hash)
Definition: emsa_pkcs1.cpp:109

◆ config_for_x509()

AlgorithmIdentifier Botan::EMSA_PKCS1v15::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 87 of file emsa_pkcs1.cpp.

References Botan::Public_Key::algo_name(), Botan::Public_Key::algorithm_identifier(), Botan::OIDS::lookup(), name(), Botan::AlgorithmIdentifier::oid, Botan::AlgorithmIdentifier::parameters, and Botan::sig_algo_and_pad_ok().

89  {
90  if(cert_hash_name != m_hash->name())
91  throw Invalid_Argument("Hash function from opts and hash_fn argument"
92  " need to be identical");
93  // check that the signature algorithm and the padding scheme fit
94  if(!sig_algo_and_pad_ok(key.algo_name(), "EMSA3"))
95  {
96  throw Invalid_Argument("Encoding scheme with canonical name EMSA3"
97  " not supported for signature algorithm " + key.algo_name());
98  }
99 
100 
101  AlgorithmIdentifier sig_algo;
102  sig_algo.oid = OIDS::lookup( key.algo_name() + "/" + name() );
103  // for RSA PKCSv1.5 parameters "SHALL" be NULL as configured by
104  // RSA_PublicKey::algorithm_identifier()
105  sig_algo.parameters = key.algorithm_identifier().parameters;
106  return sig_algo;
107  }
bool sig_algo_and_pad_ok(const std::string algo, const std::string padding)
Definition: padding.cpp:37
std::string name() const override
Definition: emsa_pkcs1.h:41
std::string lookup(const OID &oid)
Definition: oids.cpp:18

◆ encoding_of()

secure_vector< uint8_t > Botan::EMSA_PKCS1v15::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 58 of file emsa_pkcs1.cpp.

61  {
62  if(msg.size() != m_hash->output_length())
63  throw Encoding_Error("EMSA_PKCS1v15::encoding_of: Bad input length");
64 
65  return emsa3_encoding(msg, output_bits,
66  m_hash_id.data(), m_hash_id.size());
67  }

◆ name()

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

Implements Botan::EMSA.

Definition at line 41 of file emsa_pkcs1.h.

Referenced by config_for_x509().

42  { return "EMSA3(" + m_hash->name() + ")"; }

◆ raw_data()

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

Implements Botan::EMSA.

Definition at line 52 of file emsa_pkcs1.cpp.

53  {
54  return m_hash->final();
55  }

◆ update()

void Botan::EMSA_PKCS1v15::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 47 of file emsa_pkcs1.cpp.

48  {
49  m_hash->update(input, length);
50  }

◆ verify()

bool Botan::EMSA_PKCS1v15::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 69 of file emsa_pkcs1.cpp.

72  {
73  if(raw.size() != m_hash->output_length())
74  return false;
75 
76  try
77  {
78  return (coded == emsa3_encoding(raw, key_bits,
79  m_hash_id.data(), m_hash_id.size()));
80  }
81  catch(...)
82  {
83  return false;
84  }
85  }

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