Botan  2.19.1
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 21 of file pssr.h.

Constructor & Destructor Documentation

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

Definition at line 128 of file pssr.cpp.

Referenced by clone().

128  :
129  m_hash(h),
130  m_salt_size(m_hash->output_length()),
131  m_required_salt_len(false)
132  {
133  }
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 135 of file pssr.cpp.

135  :
136  m_hash(h),
137  m_salt_size(salt_size),
138  m_required_salt_len(true)
139  {
140  }
size_t salt_size

Member Function Documentation

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

Implements Botan::EMSA.

Definition at line 182 of file pssr.cpp.

References PSSR().

183  {
184  return new PSSR(m_hash->clone(), m_salt_size);
185  }
PSSR(HashFunction *hash)
Definition: pssr.cpp:128
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 192 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::SEQUENCE, Botan::sig_algo_and_pad_ok(), Botan::DER_Encoder::start_cons(), and Botan::AlgorithmIdentifier::USE_NULL_PARAM.

194  {
195  if(cert_hash_name != m_hash->name())
196  throw Invalid_Argument("Hash function from opts and hash_fn argument"
197  " need to be identical");
198  // check that the signature algorithm and the padding scheme fit
199  if(!sig_algo_and_pad_ok(key.algo_name(), "EMSA4"))
200  {
201  throw Invalid_Argument("Encoding scheme with canonical name EMSA4"
202  " not supported for signature algorithm " + key.algo_name());
203  }
204 
205  const AlgorithmIdentifier hash_id(cert_hash_name, AlgorithmIdentifier::USE_NULL_PARAM);
206  const AlgorithmIdentifier mgf_id("MGF1", hash_id.BER_encode());
207 
208  std::vector<uint8_t> parameters;
209  DER_Encoder(parameters)
210  .start_cons(SEQUENCE)
211  .start_cons(ASN1_Tag(0), CONTEXT_SPECIFIC).encode(hash_id).end_cons()
212  .start_cons(ASN1_Tag(1), CONTEXT_SPECIFIC).encode(mgf_id).end_cons()
213  .start_cons(ASN1_Tag(2), CONTEXT_SPECIFIC).encode(m_salt_size).end_cons()
214  .start_cons(ASN1_Tag(3), CONTEXT_SPECIFIC).encode(size_t(1)).end_cons() // trailer field
215  .end_cons();
216 
217  // hardcoded as RSA is the only valid algorithm for EMSA4 at the moment
218  return AlgorithmIdentifier("RSA/EMSA4", parameters);
219  }
ASN1_Tag
Definition: asn1_obj.h:25
bool sig_algo_and_pad_ok(const std::string algo, const std::string padding)
Definition: padding.cpp:39
std::string Botan::PSSR::name ( ) const
overridevirtual
Returns
the SCAN name of the encoding/padding scheme

Implements Botan::EMSA.

Definition at line 187 of file pssr.cpp.

References Botan::ASN1::to_string().

188  {
189  return "EMSA4(" + m_hash->name() + ",MGF1," + std::to_string(m_salt_size) + ")";
190  }
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:213

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