Botan 2.19.5 Crypto and TLS for C&

Public Member Functions | List of all members
Botan::PK_Signer Class Referencefinal

`#include <pubkey.h>`

## Public Member Functions
PK_Signer & | operator= (const PK_Signer &)=delete
| PK_Signer (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="")
void | set_output_format (Signature_Format format)
template<typename Alloc >
std::vector< uint8_t > | sign_message (const std::vector< uint8_t, Alloc > &in, RandomNumberGenerator &rng)
std::vector< uint8_t > | sign_message (const uint8_t in[], size_t length, RandomNumberGenerator &rng)
std::vector< uint8_t > | signature (RandomNumberGenerator &rng)
size_t | signature_length () const
void | update (const std::string &in)
template<typename Alloc >
void | update (const std::vector< uint8_t, Alloc > &in)
void | update (const uint8_t in[], size_t length)
void | update (uint8_t 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 166 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

  key | the key to use inside this signer
  rng | the random generator to use
  emsa | the EMSA to use An example would be "EMSA1(SHA-224)".
  format | the signature format to use
  provider | the provider to use

Definition at line 232 of file pubkey.cpp.

237 {
238 m_op = key.create_signature_op(rng, emsa, provider);
239 if(!m_op)
240 throw Invalid_Argument("Key type " + key.algo_name() + " does not support signature generation");
241 m_sig_format = format;
242 m_parts = key.message_parts();
243 m_part_size = key.message_part_size();
244 check_der_format_supported(format, m_parts);
245 }

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

## ◆ ~PK_Signer()

Botan::PK_Signer::~PK_Signer | ( |  | ) |

Definition at line 247 of file pubkey.cpp.

247{ /* 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

  format | the signature format to use

Definition at line 279 of file pubkey.h.

279{ m_sig_format = format; }

## ◆ sign_message() [1/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

  in | the message to sign
  rng | the rng to use

Returns
  signature

Definition at line 228 of file pubkey.h.

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

## ◆ sign_message() [2/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

  in | the message to sign as a byte array
  length | the length of the above byte array
  rng | the rng to use

Returns
  signature

Definition at line 214 of file pubkey.h.

216 {
217 this->update(in, length);
218 return this->signature(rng);
219 }
Botan::PK_Signer::update
void update(uint8_t in)
Definition: pubkey.h:238
Botan::PK_Signer::signature
std::vector< uint8_t > signature(RandomNumberGenerator &rng)
Definition: pubkey.cpp:293

References update.

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

## ◆ 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

  rng | the rng to use

Returns
  signature of the total message

Definition at line 293 of file pubkey.cpp.

294 {
295 const std::vector<uint8_t> sig = unlock(m_op->sign(rng));
296
297 if(m_sig_format == IEEE_1363)
298 {
299 return sig;
300 }
301 else if(m_sig_format == DER_SEQUENCE)
302 {
303 return der_encode_signature(sig, m_parts, m_part_size);
304 }
305 else
306 throw Internal_Error("PK_Signer: Invalid signature format enum");
307 }
Botan::OCSP::Response_Status_Code::Internal_Error
@ Internal_Error
Botan::unlock
std::vector< T > unlock(const secure_vector< T > &in)
Definition: secmem.h:72
Botan::DER_SEQUENCE
@ DER_SEQUENCE
Definition: pk_keys.h:23
Botan::IEEE_1363
@ IEEE_1363
Definition: pk_keys.h:23

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

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

278 {
279 if(m_sig_format == IEEE_1363)
280 {
281 return m_op->signature_length();
282 }
283 else if(m_sig_format == DER_SEQUENCE)
284 {
285 // This is a large over-estimate but its easier than computing
286 // the exact value
287 return m_op->signature_length() + (8 + 4*m_parts);
288 }
289 else
290 throw Internal_Error("PK_Signer: Invalid signature format enum");
291 }

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

Referenced by botan_pk_op_sign_output_length().

## ◆ update() [1/4]

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

Add a message part.

Parameters

  in | the message part to add

Definition at line 261 of file pubkey.h.

262 {
263 update(cast_char_ptr_to_uint8(in.data()), in.size());
264 }
Botan::cast_char_ptr_to_uint8
const uint8_t * cast_char_ptr_to_uint8(const char *s)
Definition: mem_ops.h:190

References Botan::cast_char_ptr_to_uint8(), and update.

## ◆ update() [2/4]

template<typename Alloc >

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

Add a message part.

Parameters

  in | the message part to add

Definition at line 252 of file pubkey.h.

253 {
254 update(in.data(), in.size());
255 }

References update.

## ◆ update() [3/4]

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

Add a message part.

Parameters

  in | the message part to add as a byte array
  length | the length of the above byte array

Definition at line 249 of file pubkey.cpp.

250 {
251 m_op->update(in, length);
252 }

## ◆ update() [4/4]

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

Add a message part (single byte).

Parameters

  in | the byte to add

Definition at line 238 of file pubkey.h.

238{ update(&in, 1); }

References update().

Referenced by botan_pk_op_sign_update(), and update().

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

- src/lib/pubkey/pubkey.h
- src/lib/pubkey/pubkey.cpp