Botan  2.4.0
Crypto and TLS for C++11
Public Member Functions | List of all members
Botan::PSSR Class Referencefinal

#include <pssr.h>

Inheritance diagram for Botan::PSSR:
Botan::EMSA

Public Member Functions

EMSAclone () override
 
AlgorithmIdentifier config_for_x509 (const Private_Key &key, const std::string &cert_hash_name) const override
 
std::string name () const override
 
 PSSR (HashFunction *hash)
 
 PSSR (HashFunction *hash, size_t salt_size)
 

Detailed Description

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

Definition at line 19 of file pssr.h.

Constructor & Destructor Documentation

◆ PSSR() [1/2]

Botan::PSSR::PSSR ( HashFunction hash)
explicit
Parameters
hashthe hash function to use

Definition at line 123 of file pssr.cpp.

123  :
124  m_hash(h), m_SALT_SIZE(m_hash->output_length())
125  {
126  }

◆ PSSR() [2/2]

Botan::PSSR::PSSR ( HashFunction hash,
size_t  salt_size 
)
Parameters
hashthe hash function to use
salt_sizethe size of the salt to use in bytes

Definition at line 128 of file pssr.cpp.

References Botan::RandomNumberGenerator::random_vec().

128  :
129  m_hash(h), m_SALT_SIZE(salt_size)
130  {
131  }
size_t salt_size

Member Function Documentation

◆ clone()

EMSA* Botan::PSSR::clone ( )
inlineoverridevirtual
Returns
a new object representing the same encoding method as *this

Implements Botan::EMSA.

Definition at line 34 of file pssr.h.

34 { return new PSSR(m_hash->clone(), m_SALT_SIZE); }
PSSR(HashFunction *hash)
Definition: pssr.cpp:123

◆ config_for_x509()

AlgorithmIdentifier Botan::PSSR::config_for_x509 ( const Private_Key key,
const std::string &  cert_hash_name 
) const
overridevirtual

Prepare sig_algo for use in choose_sig_format for x509 certs

Parameters
keyused for checking compatibility with the encoding scheme
cert_hash_nameis 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 172 of file pssr.cpp.

References Botan::Public_Key::algo_name(), Botan::CONTEXT_SPECIFIC, Botan::PEM_Code::encode(), Botan::DER_Encoder::encode(), Botan::DER_Encoder::end_cons(), Botan::DER_Encoder::get_contents_unlocked(), Botan::OIDS::lookup(), Botan::AlgorithmIdentifier::oid, Botan::SEQUENCE, Botan::sig_algo_and_pad_ok(), Botan::DER_Encoder::start_cons(), and Botan::AlgorithmIdentifier::USE_NULL_PARAM.

174  {
175  if(cert_hash_name != m_hash->name())
176  throw Invalid_Argument("Hash function from opts and hash_fn argument"
177  " need to be identical");
178  // check that the signature algorithm and the padding scheme fit
179  if(!sig_algo_and_pad_ok(key.algo_name(), "EMSA4"))
180  {
181  throw Invalid_Argument("Encoding scheme with canonical name EMSA4"
182  " not supported for signature algorithm " + key.algo_name());
183  }
184 
185  AlgorithmIdentifier sig_algo;
186  // hardcoded as RSA is the only valid algorithm for EMSA4 at the moment
187  sig_algo.oid = OIDS::lookup( "RSA/EMSA4" );
188 
189  sig_algo.parameters = DER_Encoder()
190  .start_cons( SEQUENCE )
191  .start_cons( ASN1_Tag(0), CONTEXT_SPECIFIC )
192  .encode( AlgorithmIdentifier( cert_hash_name, AlgorithmIdentifier::USE_NULL_PARAM ) )
193  .end_cons()
194  .start_cons( ASN1_Tag(1), CONTEXT_SPECIFIC )
195  .encode( AlgorithmIdentifier( "MGF1", DER_Encoder()
196  .encode( AlgorithmIdentifier( cert_hash_name, AlgorithmIdentifier::USE_NULL_PARAM ) )
197  .get_contents_unlocked() ) )
198  .end_cons()
199  .start_cons( ASN1_Tag(2), CONTEXT_SPECIFIC )
200  .encode( size_t( m_SALT_SIZE ) )
201  .end_cons()
202  .start_cons( ASN1_Tag(3), CONTEXT_SPECIFIC )
203  .encode( size_t( 1 ) ) // trailer field
204  .end_cons()
205  .end_cons()
206  .get_contents_unlocked();
207 
208  return sig_algo;
209  }
ASN1_Tag
Definition: asn1_obj.h:22
bool sig_algo_and_pad_ok(const std::string algo, const std::string padding)
Definition: padding.cpp:37
std::string encode(const uint8_t der[], size_t length, const std::string &label, size_t width)
Definition: pem.cpp:43
std::string lookup(const OID &oid)
Definition: oids.cpp:18

◆ name()

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

Implements Botan::EMSA.

Definition at line 167 of file pssr.cpp.

References Botan::ASN1::to_string().

168  {
169  return "EMSA4(" + m_hash->name() + ",MGF1," + std::to_string(m_SALT_SIZE) + ")";
170  }
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:108

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