Botan  2.4.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)
 
std::vector< uint8_t > sign_message (const std::vector< uint8_t > &in, RandomNumberGenerator &rng)
 
std::vector< uint8_t > sign_message (const secure_vector< uint8_t > &in, RandomNumberGenerator &rng)
 
std::vector< uint8_t > signature (RandomNumberGenerator &rng)
 
void update (uint8_t in)
 
void update (const uint8_t in[], size_t length)
 
void update (const std::vector< uint8_t > &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 159 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 211 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().

216  {
217  m_op = key.create_signature_op(rng, emsa, provider);
218  if(!m_op)
219  throw Invalid_Argument("Key type " + key.algo_name() + " does not support signature generation");
220  m_sig_format = format;
221  m_parts = key.message_parts();
222  m_part_size = key.message_part_size();
223  }

◆ ~PK_Signer()

Botan::PK_Signer::~PK_Signer ( )

Definition at line 225 of file pubkey.cpp.

225 { /* 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 274 of file pubkey.h.

274 { m_sig_format = format; }

◆ sign_message() [1/3]

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 207 of file pubkey.h.

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

209  {
210  this->update(in, length);
211  return this->signature(rng);
212  }
std::vector< uint8_t > signature(RandomNumberGenerator &rng)
Definition: pubkey.cpp:232
void update(uint8_t in)
Definition: pubkey.h:238

◆ sign_message() [2/3]

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

Sign a message.

Parameters
inthe message to sign
rngthe rng to use
Returns
signature

Definition at line 220 of file pubkey.h.

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

◆ sign_message() [3/3]

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

Sign a message.

Parameters
inthe message to sign
rngthe rng to use
Returns
signature

Definition at line 230 of file pubkey.h.

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

◆ 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 232 of file pubkey.cpp.

References Botan::DER_SEQUENCE, Botan::DER_Encoder::encode_list(), Botan::DER_Encoder::end_cons(), Botan::DER_Encoder::get_contents_unlocked(), Botan::IEEE_1363, Botan::SEQUENCE, Botan::DER_Encoder::start_cons(), and Botan::unlock().

233  {
234  const std::vector<uint8_t> sig = unlock(m_op->sign(rng));
235 
236  if(m_sig_format == IEEE_1363)
237  {
238  return sig;
239  }
240  else if(m_sig_format == DER_SEQUENCE)
241  {
242  if(sig.size() % m_parts != 0 || sig.size() != m_parts * m_part_size)
243  throw Internal_Error("PK_Signer: DER signature sizes unexpected, cannot encode");
244 
245  std::vector<BigInt> sig_parts(m_parts);
246  for(size_t i = 0; i != sig_parts.size(); ++i)
247  sig_parts[i].binary_decode(&sig[m_part_size*i], m_part_size);
248 
249  return DER_Encoder()
250  .start_cons(SEQUENCE)
251  .encode_list(sig_parts)
252  .end_cons()
253  .get_contents_unlocked();
254  }
255  else
256  throw Internal_Error("PK_Signer: Invalid signature format enum");
257  }
std::vector< T > unlock(const secure_vector< T > &in)
Definition: secmem.h:95

◆ 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 238 of file pubkey.h.

References update().

Referenced by botan_pk_op_sign_update(), and update().

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

◆ 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 227 of file pubkey.cpp.

228  {
229  m_op->update(in, length);
230  }

◆ update() [3/4]

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

Add a message part.

Parameters
inthe message part to add

Definition at line 251 of file pubkey.h.

References update().

Referenced by update().

251 { update(in.data(), in.size()); }
void update(uint8_t in)
Definition: pubkey.h:238

◆ 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 257 of file pubkey.h.

References Botan::cast_char_ptr_to_uint8().

258  {
259  update(cast_char_ptr_to_uint8(in.data()), in.size());
260  }
const uint8_t * cast_char_ptr_to_uint8(const char *s)
Definition: mem_ops.h:120
void update(uint8_t in)
Definition: pubkey.h:238

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