Botan  2.7.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.

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::ASN1_Object::BER_encode(), Botan::CONTEXT_SPECIFIC, Botan::DER_Encoder::encode(), Botan::DER_Encoder::end_cons(), Botan::OIDS::lookup(), Botan::AlgorithmIdentifier::parameters, 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  const AlgorithmIdentifier hash_id(cert_hash_name, AlgorithmIdentifier::USE_NULL_PARAM);
190  const AlgorithmIdentifier mgf_id("MGF1", hash_id.BER_encode());
191 
192  DER_Encoder(sig_algo.parameters)
193  .start_cons(SEQUENCE)
194  .start_cons(ASN1_Tag(0), CONTEXT_SPECIFIC).encode(hash_id).end_cons()
195  .start_cons(ASN1_Tag(1), CONTEXT_SPECIFIC).encode(mgf_id).end_cons()
196  .start_cons(ASN1_Tag(2), CONTEXT_SPECIFIC).encode(m_SALT_SIZE).end_cons()
197  .start_cons(ASN1_Tag(3), CONTEXT_SPECIFIC).encode(size_t(1)).end_cons() // trailer field
198  .end_cons();
199 
200  return sig_algo;
201  }
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 lookup(const OID &oid)
Definition: oids.cpp:113

◆ 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:210

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