Botan 3.6.1
Crypto and TLS for C&
Botan::EMSA_PKCS1v15_Raw Class Referencefinal

#include <emsa_pkcs1.h>

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

Public Member Functions

 EMSA_PKCS1v15_Raw ()
 
 EMSA_PKCS1v15_Raw (std::string_view hash_algo)
 
std::vector< uint8_t > encoding_of (const std::vector< uint8_t > &, size_t, RandomNumberGenerator &rng) override
 
std::string hash_function () const override
 
std::string name () const override
 
std::vector< uint8_t > raw_data () override
 
void update (const uint8_t[], size_t) override
 
bool verify (const std::vector< uint8_t > &, const std::vector< uint8_t > &, size_t) override
 

Static Public Member Functions

static std::unique_ptr< EMSAcreate (std::string_view algo_spec)
 
static std::unique_ptr< EMSAcreate_or_throw (std::string_view 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 50 of file emsa_pkcs1.h.

Constructor & Destructor Documentation

◆ EMSA_PKCS1v15_Raw() [1/2]

Botan::EMSA_PKCS1v15_Raw::EMSA_PKCS1v15_Raw ( )

Definition at line 76 of file emsa_pkcs1.cpp.

76 {
77 m_hash_output_len = 0;
78 // m_hash_id, m_hash_name left empty
79}

◆ EMSA_PKCS1v15_Raw() [2/2]

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

Definition at line 81 of file emsa_pkcs1.cpp.

81 {
82 std::unique_ptr<HashFunction> hash(HashFunction::create_or_throw(hash_algo));
83 m_hash_id = pkcs_hash_id(hash_algo);
84 m_hash_name = hash->name();
85 m_hash_output_len = hash->output_length();
86}
static std::unique_ptr< HashFunction > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition hash.cpp:298
std::vector< uint8_t > pkcs_hash_id(std::string_view name)
Definition hash_id.cpp:78

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

Member Function Documentation

◆ create()

std::unique_ptr< EMSA > Botan::EMSA::create ( std::string_view 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 35 of file emsa.cpp.

35 {
36 SCAN_Name req(algo_spec);
37
38#if defined(BOTAN_HAS_EMSA_PKCS1)
39 if(req.algo_name() == "EMSA_PKCS1" || req.algo_name() == "PKCS1v15" || req.algo_name() == "EMSA-PKCS1-v1_5" ||
40 req.algo_name() == "EMSA3") {
41 if(req.arg_count() == 2 && req.arg(0) == "Raw") {
42 return std::make_unique<EMSA_PKCS1v15_Raw>(req.arg(1));
43 } else if(req.arg_count() == 1) {
44 if(req.arg(0) == "Raw") {
45 return std::make_unique<EMSA_PKCS1v15_Raw>();
46 } else {
47 if(auto hash = HashFunction::create(req.arg(0))) {
48 return std::make_unique<EMSA_PKCS1v15>(std::move(hash));
49 }
50 }
51 }
52 }
53#endif
54
55#if defined(BOTAN_HAS_EMSA_PSSR)
56 if(req.algo_name() == "PSS_Raw" || req.algo_name() == "PSSR_Raw") {
57 if(req.arg_count_between(1, 3) && req.arg(1, "MGF1") == "MGF1") {
58 if(auto hash = HashFunction::create(req.arg(0))) {
59 if(req.arg_count() == 3) {
60 const size_t salt_size = req.arg_as_integer(2, 0);
61 return std::make_unique<PSSR_Raw>(std::move(hash), salt_size);
62 } else {
63 return std::make_unique<PSSR_Raw>(std::move(hash));
64 }
65 }
66 }
67 }
68
69 if(req.algo_name() == "PSS" || req.algo_name() == "PSSR" || req.algo_name() == "EMSA-PSS" ||
70 req.algo_name() == "PSS-MGF1" || req.algo_name() == "EMSA4") {
71 if(req.arg_count_between(1, 3) && req.arg(1, "MGF1") == "MGF1") {
72 if(auto hash = HashFunction::create(req.arg(0))) {
73 if(req.arg_count() == 3) {
74 const size_t salt_size = req.arg_as_integer(2, 0);
75 return std::make_unique<PSSR>(std::move(hash), salt_size);
76 } else {
77 return std::make_unique<PSSR>(std::move(hash));
78 }
79 }
80 }
81 }
82#endif
83
84#if defined(BOTAN_HAS_ISO_9796)
85 if(req.algo_name() == "ISO_9796_DS2") {
86 if(req.arg_count_between(1, 3)) {
87 if(auto hash = HashFunction::create(req.arg(0))) {
88 const size_t salt_size = req.arg_as_integer(2, hash->output_length());
89 const bool implicit = req.arg(1, "exp") == "imp";
90 return std::make_unique<ISO_9796_DS2>(std::move(hash), implicit, salt_size);
91 }
92 }
93 }
94 //ISO-9796-2 DS 3 is deterministic and DS2 without a salt
95 if(req.algo_name() == "ISO_9796_DS3") {
96 if(req.arg_count_between(1, 2)) {
97 if(auto hash = HashFunction::create(req.arg(0))) {
98 const bool implicit = req.arg(1, "exp") == "imp";
99 return std::make_unique<ISO_9796_DS3>(std::move(hash), implicit);
100 }
101 }
102 }
103#endif
104
105#if defined(BOTAN_HAS_EMSA_X931)
106 if(req.algo_name() == "EMSA_X931" || req.algo_name() == "EMSA2" || req.algo_name() == "X9.31") {
107 if(req.arg_count() == 1) {
108 if(auto hash = HashFunction::create(req.arg(0))) {
109 return std::make_unique<EMSA_X931>(std::move(hash));
110 }
111 }
112 }
113#endif
114
115#if defined(BOTAN_HAS_EMSA_RAW)
116 if(req.algo_name() == "Raw") {
117 if(req.arg_count() == 0) {
118 return std::make_unique<EMSA_Raw>();
119 } else {
120 auto hash = HashFunction::create(req.arg(0));
121 if(hash) {
122 return std::make_unique<EMSA_Raw>(hash->output_length());
123 }
124 }
125 }
126#endif
127
128 return nullptr;
129}
static std::unique_ptr< HashFunction > create(std::string_view algo_spec, std::string_view provider="")
Definition hash.cpp:107

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(), and Botan::HashFunction::create().

Referenced by Botan::EMSA::create_or_throw().

◆ create_or_throw()

std::unique_ptr< EMSA > Botan::EMSA::create_or_throw ( std::string_view 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 131 of file emsa.cpp.

131 {
132 auto emsa = EMSA::create(algo_spec);
133 if(emsa) {
134 return emsa;
135 }
136 throw Algorithm_Not_Found(algo_spec);
137}
static std::unique_ptr< EMSA > create(std::string_view algo_spec)
Definition emsa.cpp:35

References Botan::EMSA::create().

◆ encoding_of()

std::vector< uint8_t > Botan::EMSA_PKCS1v15_Raw::encoding_of ( const std::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 103 of file emsa_pkcs1.cpp.

105 {
106 return pkcs1v15_sig_encoding(msg, output_bits, m_hash_id);
107}

◆ hash_function()

std::string Botan::EMSA_PKCS1v15_Raw::hash_function ( ) const
inlineoverridevirtual

Return the hash function being used by this padding scheme

Implements Botan::EMSA.

Definition at line 68 of file emsa_pkcs1.h.

68{ return m_hash_name; }

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

70 {
71 if(m_hash_name.empty()) {
72 return "EMSA3(Raw)";
73 } else {
74 return "EMSA3(Raw," + m_hash_name + ")";
75 }
76 }

◆ raw_data()

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

Implements Botan::EMSA.

Definition at line 92 of file emsa_pkcs1.cpp.

92 {
93 std::vector<uint8_t> ret;
94 std::swap(ret, m_message);
95
96 if(m_hash_output_len > 0 && ret.size() != m_hash_output_len) {
97 throw Encoding_Error("EMSA_PKCS1v15_Raw::encoding_of: Bad input length");
98 }
99
100 return ret;
101}

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

88 {
89 m_message += std::make_pair(input, length);
90}

◆ verify()

bool Botan::EMSA_PKCS1v15_Raw::verify ( const std::vector< uint8_t > & coded,
const std::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 109 of file emsa_pkcs1.cpp.

109 {
110 if(m_hash_output_len > 0 && raw.size() != m_hash_output_len) {
111 return false;
112 }
113
114 try {
115 return coded == pkcs1v15_sig_encoding(raw, key_bits, m_hash_id);
116 } catch(...) {
117 return false;
118 }
119}

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