Botan 2.19.2
Crypto and TLS for C&
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 23 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 105 of file emsa_pkcs1.cpp.

105 : m_hash(hash)
106 {
107 m_hash_id = pkcs_hash_id(m_hash->name());
108 }
std::vector< uint8_t > pkcs_hash_id(const std::string &name)
Definition: hash_id.cpp:77
MechanismType hash

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

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

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

88 {
89 if(cert_hash_name != m_hash->name())
90 throw Invalid_Argument("Hash function from opts and hash_fn argument"
91 " need to be identical");
92 // check that the signature algorithm and the padding scheme fit
93 if(!sig_algo_and_pad_ok(key.algo_name(), "EMSA3"))
94 {
95 throw Invalid_Argument("Encoding scheme with canonical name EMSA3"
96 " not supported for signature algorithm " + key.algo_name());
97 }
98
99 // for RSA PKCSv1.5 parameters "SHALL" be NULL
100
101 const OID oid = OID::from_string(key.algo_name() + "/" + name());
102 return AlgorithmIdentifier(oid, AlgorithmIdentifier::USE_NULL_PARAM);
103 }
std::string name() const override
Definition: emsa_pkcs1.h:43
static OID from_string(const std::string &str)
Definition: asn1_oid.cpp:62
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::OID::from_string(), name(), Botan::sig_algo_and_pad_ok(), and Botan::AlgorithmIdentifier::USE_NULL_PARAM.

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

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

◆ name()

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

Implements Botan::EMSA.

Definition at line 43 of file emsa_pkcs1.h.

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

Referenced by config_for_x509().

◆ raw_data()

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

Implements Botan::EMSA.

Definition at line 51 of file emsa_pkcs1.cpp.

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

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

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

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

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

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