Botan 2.19.5 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:

## Public Member Functions
EMSA * | clone () 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

  hash | the 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 }
Botan::pkcs_hash_id
std::vector< uint8_t > pkcs_hash_id(const std::string &name)
Definition: hash_id.cpp:77
hash
MechanismType hash
Definition: p11_mechanism.cpp:64

## Member Function Documentation

## ◆ clone()

EMSA * Botan::EMSA_PKCS1v15::clone | ( |  | ) |
| inline override virtual

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()); }
Botan::EMSA_PKCS1v15::EMSA_PKCS1v15
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
| override virtual

Prepare sig_algo for use in choose_sig_format for x509 certs

Parameters

  key | used for checking compatibility with the encoding scheme
  cert_hash_name | is 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 }
Botan::AlgorithmIdentifier::USE_NULL_PARAM
@ USE_NULL_PARAM
Definition: asn1_obj.h:432
Botan::EMSA_PKCS1v15::name
std::string name() const override
Definition: emsa_pkcs1.h:43
Botan::OID::from_string
static OID from_string(const std::string &str)
Definition: asn1_oid.cpp:62
Botan::sig_algo_and_pad_ok
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
| ) |  |
| override virtual

Return the encoding of a message

Parameters

  msg | the result of raw_data()
  output_bits | the desired output bit size
  rng | a 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
| inline override virtual

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 | ( |  | ) |
| override virtual

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
| ) |  |
| override virtual

Add more data to the signature computation

Parameters

  input | some data
  length | length 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
| ) |  |
| override virtual

Verify the encoding

Parameters

  coded | the received (coded) message representative
  raw | the computed (local, uncoded) message representative
  key_bits | the 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:

- src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.h
- src/lib/pk_pad/emsa_pkcs1/emsa_pkcs1.cpp