Botan 3.13.0
Crypto and TLS for C&
Botan::X931_SignaturePadding Class Referencefinal

#include <x931_sig_padding.h>

Inheritance diagram for Botan::X931_SignaturePadding:
Botan::SignaturePaddingScheme

Public Member Functions

std::string hash_function () const override
std::string name () const override
 X931_SignaturePadding (std::unique_ptr< HashFunction > hash)

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

Padding scheme from X9.31 (aka EMSA2 in IEEE 1363)

Historically used for signature padding with Rabin-Williams, which is not implemented by Botan anymore.

Sometimes used with RSA in odd protocols.

Definition at line 24 of file x931_sig_padding.h.

Constructor & Destructor Documentation

◆ X931_SignaturePadding()

Botan::X931_SignaturePadding::X931_SignaturePadding ( std::unique_ptr< HashFunction > hash)
explicit
Parameters
Hashesthe hash function to use

Definition at line 93 of file x931_sig_padding.cpp.

93 : m_hash(std::move(hash)) {
94 m_empty_hash = m_hash->final_stdvec();
95
96 m_hash_id = ieee1363_hash_id(m_hash->name());
97
98 if(m_hash_id == 0) {
99 throw Encoding_Error("X931_SignaturePadding no hash identifier for " + m_hash->name());
100 }
101}
uint8_t ieee1363_hash_id(std::string_view name)
Definition hash_id.cpp:144

References Botan::ieee1363_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 const 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 const std::string trailer = req.arg(1, "exp");
91 if(trailer != "imp" && trailer != "exp") {
92 return nullptr;
93 }
94 if(auto hash = HashFunction::create(req.arg(0))) {
95 const size_t salt_size = req.arg_as_integer(2, hash->output_length());
96 return std::make_unique<ISO_9796_DS2>(std::move(hash), trailer == "imp", salt_size);
97 }
98 }
99 }
100 //ISO-9796-2 DS 3 is deterministic and DS2 without a salt
101 if(req.algo_name() == "ISO_9796_DS3") {
102 if(req.arg_count_between(1, 2)) {
103 const std::string trailer = req.arg(1, "exp");
104 if(trailer != "imp" && trailer != "exp") {
105 return nullptr;
106 }
107 if(auto hash = HashFunction::create(req.arg(0))) {
108 return std::make_unique<ISO_9796_DS3>(std::move(hash), trailer == "imp");
109 }
110 }
111 }
112#endif
113
114#if defined(BOTAN_HAS_X931_SIGNATURE_PADDING)
115 // TODO(Botan4) Remove all but "X9.31"
116 if(req.algo_name() == "EMSA_X931" || req.algo_name() == "EMSA2" || req.algo_name() == "X9.31") {
117 if(req.arg_count() == 1) {
118 if(auto hash = HashFunction::create(req.arg(0))) {
119 return std::make_unique<X931_SignaturePadding>(std::move(hash));
120 }
121 }
122 }
123#endif
124
125#if defined(BOTAN_HAS_RAW_SIGNATURE_PADDING)
126 if(req.algo_name() == "Raw") {
127 if(req.arg_count() == 0) {
128 return std::make_unique<SignRawBytes>();
129 } else {
130 auto hash = HashFunction::create(req.arg(0));
131 if(hash) {
132 return std::make_unique<SignRawBytes>(hash->output_length());
133 }
134 }
135 }
136#endif
137
138 return nullptr;
139}
static std::unique_ptr< HashFunction > create(std::string_view algo_spec, std::string_view provider="")
Definition hash.cpp:111

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 141 of file sig_padding.cpp.

141 {
142 if(auto padding = SignaturePaddingScheme::create(algo_spec)) {
143 return padding;
144 } else {
145 throw Algorithm_Not_Found(algo_spec);
146 }
147}
static std::unique_ptr< SignaturePaddingScheme > create(std::string_view algo_spec)

References create().

Referenced by ~SignaturePaddingScheme().

◆ hash_function()

std::string Botan::X931_SignaturePadding::hash_function ( ) const
overridevirtual

Return the hash function being used by this padding scheme

Implements Botan::SignaturePaddingScheme.

Definition at line 53 of file x931_sig_padding.cpp.

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

◆ name()

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

Implements Botan::SignaturePaddingScheme.

Definition at line 57 of file x931_sig_padding.cpp.

57 {
58 return fmt("X9.31({})", m_hash->name());
59}
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53

References Botan::fmt().


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