Botan 3.14.1
Crypto and TLS for C&
Botan::PSSR Class Referencefinal

#include <pssr.h>

Inheritance diagram for Botan::PSSR:
Botan::SignaturePaddingScheme

Public Member Functions

std::string hash_function () const override
std::string name () const override
 PSSR (const PK_Signature_Options_Reader &options)

Static Public Member Functions

static std::unique_ptr< SignaturePaddingScheme > create_or_throw (const PK_Signature_Options_Reader &options)

Detailed Description

PSSR (called EMSA4 in IEEE 1363 and in old versions of the library)

Definition at line 25 of file pssr.h.

Constructor & Destructor Documentation

◆ PSSR()

Botan::PSSR::PSSR ( const PK_Signature_Options_Reader & options)
explicit

Definition at line 151 of file pssr.cpp.

151 :
152 m_hash(HashFunction::create_or_throw(options.hash_function_name())),
153 m_salt_size(options.salt_size().value_or(m_hash->output_length())),
154 m_required_salt_len(options.using_salt_size()) {
155 if(options.using_deterministic_signature() && m_salt_size > 0) {
156 throw Invalid_Argument("PSS with a non-zero salt cannot produce deterministic signatures");
157 }
158}
static std::unique_ptr< HashFunction > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition hash.cpp:311

References Botan::SignaturePaddingScheme::create_or_throw(), and Botan::PK_Signature_Options_Reader::using_deterministic_signature().

Member Function Documentation

◆ create_or_throw()

std::unique_ptr< SignaturePaddingScheme > Botan::SignaturePaddingScheme::create_or_throw ( const PK_Signature_Options_Reader & options)
staticinherited

Factory method for SignaturePaddingScheme objects

Parameters
optionsthe algorithm parameters
Returns
pointer to newly allocated object of that type, or throws

Definition at line 36 of file sig_padding.cpp.

37 {
38 // Signing without padding is dangerous, so it must be requested explicitly
39 if(!options.using_padding()) {
40 throw Lookup_Error("RSA signatures require specifying a padding scheme");
41 }
42
43 const std::string padding = options.padding().value();
44
45 if(padding == "Raw") {
46#if defined(BOTAN_HAS_EMSA_RAW)
47 // Raw padding signs the input directly, so no hash function is involved
48 return std::make_unique<SignRawBytes>(options);
49#endif
50 } else {
51#if defined(BOTAN_HAS_EMSA_PKCS1)
52 // PKCS1v15 can also sign a digest the caller computed
53 if(padding == "PKCS1v15" && options.using_externally_computed_prehash()) {
54 return std::make_unique<PKCS1v15_Raw_SignaturePaddingScheme>(options);
55 }
56#endif
57
58 if(!options.using_hash()) {
59 throw Lookup_Error(fmt("RSA/{} signatures require specifying a hash function", padding));
60 }
61
62 const std::string& hash_fn = options.hash_function_name();
63 const bool hash_available = HashFunction::create(hash_fn) != nullptr;
64
65#if defined(BOTAN_HAS_EMSA_PKCS1)
66 if(padding == "PKCS1v15" && hash_available) {
67 return std::make_unique<PKCS1v15_SignaturePaddingScheme>(options);
68 }
69#endif
70
71#if defined(BOTAN_HAS_PSS)
72 if(padding == "PSS_Raw" && hash_available) {
73 return std::make_unique<PSS_Raw>(options);
74 }
75
76 if(padding == "PSS" && hash_available) {
77 return std::make_unique<PSSR>(options);
78 }
79#endif
80
81#if defined(BOTAN_HAS_ISO_9796)
82 if(padding == "ISO_9796_DS2" && hash_available) {
83 return std::make_unique<ISO_9796_DS2>(options);
84 }
85
86 if(padding == "ISO_9796_DS3" && hash_available) {
87 return std::make_unique<ISO_9796_DS3>(options);
88 }
89#endif
90
91#if defined(BOTAN_HAS_EMSA_X931)
92 if(padding == "X9.31" && hash_available) {
93 return std::make_unique<X931_SignaturePadding>(options);
94 }
95#endif
96 }
97
98 throw Lookup_Error("Invalid or unavailable signature padding scheme " + options.to_string());
99}
static std::unique_ptr< HashFunction > create(std::string_view algo_spec, std::string_view provider="")
Definition hash.cpp:112
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53

References Botan::HashFunction::create(), Botan::fmt(), Botan::PK_Signature_Options_Reader::hash_function_name(), Botan::PK_Signature_Options_Reader::padding(), Botan::PK_Signature_Options_Reader::to_string(), Botan::PK_Signature_Options_Reader::using_externally_computed_prehash(), Botan::PK_Signature_Options_Reader::using_hash(), and Botan::PK_Signature_Options_Reader::using_padding().

Referenced by Botan::ISO_9796_DS2::ISO_9796_DS2(), Botan::ISO_9796_DS3::ISO_9796_DS3(), Botan::PKCS1v15_SignaturePaddingScheme::PKCS1v15_SignaturePaddingScheme(), Botan::PSS_Raw::PSS_Raw(), Botan::PSSR::PSSR(), Botan::X931_SignaturePadding::X931_SignaturePadding(), and ~SignaturePaddingScheme().

◆ hash_function()

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

Return the hash function being used by this padding scheme

Implements Botan::SignaturePaddingScheme.

Definition at line 193 of file pssr.cpp.

193 {
194 return m_hash->name();
195}

◆ name()

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

Implements Botan::SignaturePaddingScheme.

Definition at line 197 of file pssr.cpp.

197 {
198 return fmt("PSS({},MGF1,{})", m_hash->name(), m_salt_size);
199}

References Botan::fmt().


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