Botan  2.8.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 129 of file pssr.cpp.

Referenced by clone().

129  :
130  m_hash(h),
131  m_salt_size(m_hash->output_length()),
132  m_required_salt_len(false)
133  {
134  }

◆ 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 136 of file pssr.cpp.

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

Member Function Documentation

◆ clone()

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

Implements Botan::EMSA.

Definition at line 183 of file pssr.cpp.

References PSSR().

184  {
185  return new PSSR(m_hash->clone(), m_salt_size);
186  }
PSSR(HashFunction *hash)
Definition: pssr.cpp:129

◆ 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 193 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.

195  {
196  if(cert_hash_name != m_hash->name())
197  throw Invalid_Argument("Hash function from opts and hash_fn argument"
198  " need to be identical");
199  // check that the signature algorithm and the padding scheme fit
200  if(!sig_algo_and_pad_ok(key.algo_name(), "EMSA4"))
201  {
202  throw Invalid_Argument("Encoding scheme with canonical name EMSA4"
203  " not supported for signature algorithm " + key.algo_name());
204  }
205 
206  AlgorithmIdentifier sig_algo;
207  // hardcoded as RSA is the only valid algorithm for EMSA4 at the moment
208  sig_algo.oid = OIDS::lookup( "RSA/EMSA4" );
209 
210  const AlgorithmIdentifier hash_id(cert_hash_name, AlgorithmIdentifier::USE_NULL_PARAM);
211  const AlgorithmIdentifier mgf_id("MGF1", hash_id.BER_encode());
212 
213  DER_Encoder(sig_algo.parameters)
214  .start_cons(SEQUENCE)
215  .start_cons(ASN1_Tag(0), CONTEXT_SPECIFIC).encode(hash_id).end_cons()
216  .start_cons(ASN1_Tag(1), CONTEXT_SPECIFIC).encode(mgf_id).end_cons()
217  .start_cons(ASN1_Tag(2), CONTEXT_SPECIFIC).encode(m_salt_size).end_cons()
218  .start_cons(ASN1_Tag(3), CONTEXT_SPECIFIC).encode(size_t(1)).end_cons() // trailer field
219  .end_cons();
220 
221  return sig_algo;
222  }
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 188 of file pssr.cpp.

References Botan::ASN1::to_string().

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

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