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

#include <pubkey.h>

Public Member Functions

PK_Signeroperator= (const PK_Signer &)=delete
 
 PK_Signer (const Private_Key &key, RandomNumberGenerator &rng, const std::string &emsa, Signature_Format format=IEEE_1363, const std::string &provider="")
 
 PK_Signer (const PK_Signer &)=delete
 
void set_output_format (Signature_Format format)
 
std::vector< uint8_t > sign_message (const uint8_t in[], size_t length, RandomNumberGenerator &rng)
 
template<typename Alloc >
std::vector< uint8_t > sign_message (const std::vector< uint8_t, Alloc > &in, RandomNumberGenerator &rng)
 
std::vector< uint8_t > signature (RandomNumberGenerator &rng)
 
size_t signature_length () const
 
void update (uint8_t in)
 
void update (const uint8_t in[], size_t length)
 
template<typename Alloc >
void update (const std::vector< uint8_t, Alloc > &in)
 
void update (const std::string &in)
 
 ~PK_Signer ()
 

Detailed Description

Public Key Signer. Use the sign_message() functions for small messages. Use multiple calls update() to process large messages and generate the signature by finally calling signature().

Definition at line 170 of file pubkey.h.

Constructor & Destructor Documentation

◆ PK_Signer() [1/2]

Botan::PK_Signer::PK_Signer ( const Private_Key key,
RandomNumberGenerator rng,
const std::string &  emsa,
Signature_Format  format = IEEE_1363,
const std::string &  provider = "" 
)

Construct a PK Signer.

Parameters
keythe key to use inside this signer
rngthe random generator to use
emsathe EMSA to use An example would be "EMSA1(SHA-224)".
formatthe signature format to use
providerthe provider to use

Definition at line 226 of file pubkey.cpp.

References Botan::Public_Key::algo_name(), Botan::Private_Key::create_signature_op(), Botan::Public_Key::message_part_size(), and Botan::Public_Key::message_parts().

231  {
232  m_op = key.create_signature_op(rng, emsa, provider);
233  if(!m_op)
234  throw Invalid_Argument("Key type " + key.algo_name() + " does not support signature generation");
235  m_sig_format = format;
236  m_parts = key.message_parts();
237  m_part_size = key.message_part_size();
238  }

◆ ~PK_Signer()

Botan::PK_Signer::~PK_Signer ( )

Definition at line 240 of file pubkey.cpp.

240 { /* for unique_ptr */ }

◆ PK_Signer() [2/2]

Botan::PK_Signer::PK_Signer ( const PK_Signer )
delete

Member Function Documentation

◆ operator=()

PK_Signer& Botan::PK_Signer::operator= ( const PK_Signer )
delete

◆ set_output_format()

void Botan::PK_Signer::set_output_format ( Signature_Format  format)
inline

Set the output format of the signature.

Parameters
formatthe signature format to use

Definition at line 283 of file pubkey.h.

283 { m_sig_format = format; }

◆ sign_message() [1/2]

std::vector<uint8_t> Botan::PK_Signer::sign_message ( const uint8_t  in[],
size_t  length,
RandomNumberGenerator rng 
)
inline

Sign a message all in one go

Parameters
inthe message to sign as a byte array
lengththe length of the above byte array
rngthe rng to use
Returns
signature

Definition at line 218 of file pubkey.h.

References update.

Referenced by Botan::X509_Object::make_signed(), Botan::KeyPair::signature_consistency_check(), and Botan::TLS::Callbacks::tls_sign_message().

220  {
221  this->update(in, length);
222  return this->signature(rng);
223  }
std::vector< uint8_t > signature(RandomNumberGenerator &rng)
Definition: pubkey.cpp:286
void update(uint8_t in)
Definition: pubkey.h:242

◆ sign_message() [2/2]

template<typename Alloc >
std::vector<uint8_t> Botan::PK_Signer::sign_message ( const std::vector< uint8_t, Alloc > &  in,
RandomNumberGenerator rng 
)
inline

Sign a message.

Parameters
inthe message to sign
rngthe rng to use
Returns
signature

Definition at line 232 of file pubkey.h.

234  {
235  return sign_message(in.data(), in.size(), rng);
236  }
std::vector< uint8_t > sign_message(const uint8_t in[], size_t length, RandomNumberGenerator &rng)
Definition: pubkey.h:218

◆ signature()

std::vector< uint8_t > Botan::PK_Signer::signature ( RandomNumberGenerator rng)

Get the signature of the so far processed message (provided by the calls to update()).

Parameters
rngthe rng to use
Returns
signature of the total message

Definition at line 286 of file pubkey.cpp.

References Botan::DER_SEQUENCE, Botan::IEEE_1363, and Botan::unlock().

287  {
288  const std::vector<uint8_t> sig = unlock(m_op->sign(rng));
289 
290  if(m_sig_format == IEEE_1363)
291  {
292  return sig;
293  }
294  else if(m_sig_format == DER_SEQUENCE)
295  {
296  return der_encode_signature(sig, m_parts, m_part_size);
297  }
298  else
299  throw Internal_Error("PK_Signer: Invalid signature format enum");
300  }
std::vector< T > unlock(const secure_vector< T > &in)
Definition: secmem.h:95

◆ signature_length()

size_t Botan::PK_Signer::signature_length ( ) const

Return an upper bound on the length of the signatures this PK_Signer will produce

Definition at line 270 of file pubkey.cpp.

References Botan::DER_SEQUENCE, and Botan::IEEE_1363.

Referenced by botan_pk_op_sign_output_length().

271  {
272  if(m_sig_format == IEEE_1363)
273  {
274  return m_op->signature_length();
275  }
276  else if(m_sig_format == DER_SEQUENCE)
277  {
278  // This is a large over-estimate but its easier than computing
279  // the exact value
280  return m_op->signature_length() + (8 + 4*m_parts);
281  }
282  else
283  throw Internal_Error("PK_Signer: Invalid signature format enum");
284  }

◆ update() [1/4]

void Botan::PK_Signer::update ( uint8_t  in)
inline

Add a message part (single byte).

Parameters
inthe byte to add

Definition at line 242 of file pubkey.h.

References update().

Referenced by botan_pk_op_sign_update(), and update().

242 { update(&in, 1); }
void update(uint8_t in)
Definition: pubkey.h:242

◆ update() [2/4]

void Botan::PK_Signer::update ( const uint8_t  in[],
size_t  length 
)

Add a message part.

Parameters
inthe message part to add as a byte array
lengththe length of the above byte array

Definition at line 242 of file pubkey.cpp.

243  {
244  m_op->update(in, length);
245  }

◆ update() [3/4]

template<typename Alloc >
void Botan::PK_Signer::update ( const std::vector< uint8_t, Alloc > &  in)
inline

Add a message part.

Parameters
inthe message part to add

Definition at line 256 of file pubkey.h.

References update.

257  {
258  update(in.data(), in.size());
259  }
void update(uint8_t in)
Definition: pubkey.h:242

◆ update() [4/4]

void Botan::PK_Signer::update ( const std::string &  in)
inline

Add a message part.

Parameters
inthe message part to add

Definition at line 265 of file pubkey.h.

References Botan::cast_char_ptr_to_uint8(), and update.

266  {
267  update(cast_char_ptr_to_uint8(in.data()), in.size());
268  }
const uint8_t * cast_char_ptr_to_uint8(const char *s)
Definition: mem_ops.h:131
void update(uint8_t in)
Definition: pubkey.h:242

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