Botan 3.9.0
Crypto and TLS for C&
Botan::PKCS1v15_Raw_SignaturePaddingScheme Class Referencefinal

#include <pkcs1_sig_padding.h>

Inheritance diagram for Botan::PKCS1v15_Raw_SignaturePaddingScheme:
Botan::SignaturePaddingScheme

Public Member Functions

std::vector< uint8_t > encoding_of (std::span< const uint8_t > msg, size_t output_bits, RandomNumberGenerator &rng) override
std::string hash_function () const override
std::string name () const override
 PKCS1v15_Raw_SignaturePaddingScheme ()
 PKCS1v15_Raw_SignaturePaddingScheme (std::string_view hash_algo)
std::vector< uint8_t > raw_data () override
void update (const uint8_t input[], size_t length) override
bool verify (std::span< const uint8_t > coded, std::span< const uint8_t > raw, size_t key_bits) override

Static Public Member Functions

static std::unique_ptr< SignaturePaddingSchemecreate (std::string_view algo_spec)
static std::unique_ptr< SignaturePaddingSchemecreate_or_throw (std::string_view algo_spec)

Detailed Description

PKCS1v15_SignaturePaddingScheme_Raw which is PKCS1v15_SignaturePaddingScheme 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 58 of file pkcs1_sig_padding.h.

Constructor & Destructor Documentation

◆ PKCS1v15_Raw_SignaturePaddingScheme() [1/2]

Botan::PKCS1v15_Raw_SignaturePaddingScheme::PKCS1v15_Raw_SignaturePaddingScheme ( )

Definition at line 99 of file pkcs1_sig_padding.cpp.

99 : m_hash_output_len(0) {
100 // m_hash_id, m_hash_name left empty
101}

◆ PKCS1v15_Raw_SignaturePaddingScheme() [2/2]

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

Definition at line 103 of file pkcs1_sig_padding.cpp.

103 {
104 std::unique_ptr<HashFunction> hash(HashFunction::create_or_throw(hash_algo));
105 m_hash_id = pkcs_hash_id(hash_algo);
106 m_hash_name = hash->name();
107 m_hash_output_len = hash->output_length();
108}
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< SignaturePaddingScheme > Botan::SignaturePaddingScheme::create ( std::string_view algo_spec)
staticinherited

Factory method for SignaturePaddingScheme (message-encoding methods for signatures with appendix) objects

Parameters
algo_specthe name of the SignaturePaddingScheme to create
Returns
pointer to newly allocated object of that type, or nullptr

Definition at line 35 of file sig_padding.cpp.

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

◆ create_or_throw()

std::unique_ptr< SignaturePaddingScheme > Botan::SignaturePaddingScheme::create_or_throw ( std::string_view algo_spec)
staticinherited

Factory method for SignaturePaddingScheme (message-encoding methods for signatures with appendix) objects

Parameters
algo_specthe name of the SignaturePaddingScheme to create
Returns
pointer to newly allocated object of that type, or throws

Definition at line 135 of file sig_padding.cpp.

135 {
136 if(auto padding = SignaturePaddingScheme::create(algo_spec)) {
137 return padding;
138 } else {
139 throw Algorithm_Not_Found(algo_spec);
140 }
141}
static std::unique_ptr< SignaturePaddingScheme > create(std::string_view algo_spec)

References create().

Referenced by ~SignaturePaddingScheme().

◆ encoding_of()

std::vector< uint8_t > Botan::PKCS1v15_Raw_SignaturePaddingScheme::encoding_of ( std::span< const 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::SignaturePaddingScheme.

Definition at line 125 of file pkcs1_sig_padding.cpp.

127 {
128 return pkcs1v15_sig_encoding(msg, output_bits, m_hash_id);
129}

◆ hash_function()

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

Return the hash function being used by this padding scheme

Implements Botan::SignaturePaddingScheme.

Definition at line 78 of file pkcs1_sig_padding.h.

78{ return m_hash_name; }

◆ name()

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

Implements Botan::SignaturePaddingScheme.

Definition at line 91 of file pkcs1_sig_padding.cpp.

91 {
92 if(m_hash_name.empty()) {
93 return "PKCS1v15(Raw)";
94 } else {
95 return fmt("PKCS1v15(Raw,{})", m_hash_name);
96 }
97}
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53

References Botan::fmt().

◆ raw_data()

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

Implements Botan::SignaturePaddingScheme.

Definition at line 114 of file pkcs1_sig_padding.cpp.

114 {
115 std::vector<uint8_t> ret;
116 std::swap(ret, m_message);
117
118 if(m_hash_output_len > 0 && ret.size() != m_hash_output_len) {
119 throw Encoding_Error("PKCS1v15_Raw_SignaturePaddingScheme::encoding_of: Bad input length");
120 }
121
122 return ret;
123}

◆ update()

void Botan::PKCS1v15_Raw_SignaturePaddingScheme::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::SignaturePaddingScheme.

Definition at line 110 of file pkcs1_sig_padding.cpp.

110 {
111 m_message += std::make_pair(input, length);
112}

◆ verify()

bool Botan::PKCS1v15_Raw_SignaturePaddingScheme::verify ( std::span< const uint8_t > encoding,
std::span< const uint8_t > raw_hash,
size_t key_bits )
overridevirtual

Verify the encoding

Parameters
encodingthe received (coded) message representative
raw_hashthe 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::SignaturePaddingScheme.

Definition at line 131 of file pkcs1_sig_padding.cpp.

133 {
134 if(m_hash_output_len > 0 && raw.size() != m_hash_output_len) {
135 return false;
136 }
137
138 try {
139 const auto pkcs1 = pkcs1v15_sig_encoding(raw, key_bits, m_hash_id);
140 return constant_time_compare(coded, pkcs1);
141 } catch(...) {
142 return false;
143 }
144}
bool constant_time_compare(std::span< const uint8_t > x, std::span< const uint8_t > y)
Definition mem_ops.cpp:17

References Botan::constant_time_compare().


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