Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

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

## Constructor & Destructor Documentation

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 210 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().

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

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

Definition at line 224 of file pubkey.cpp.

224 { /* for unique_ptr */ }

Botan::PK_Signer::PK_Signer | ( | const PK_Signer & |  | ) |
| delete

## Member Function Documentation

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

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

276 { m_sig_format = format; }

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

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

211 {
212 this->update(in, length);
213 return this->signature(rng);
214 }
Botan::PK_Signer::signature
std::vector< uint8_t > signature(RandomNumberGenerator &rng)
Definition: pubkey.cpp:231
Botan::PK_Signer::update
void update(uint8_t in)
Definition: pubkey.h:240

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

Sign a message.

Parameters

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

Returns
  signature

Definition at line 222 of file pubkey.h.

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

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

Sign a message.

Parameters

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

Returns
  signature

Definition at line 232 of file pubkey.h.

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

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 231 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().

Referenced by Botan::TLS::Server_Key_Exchange::Server_Key_Exchange().

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

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

Add a message part (single byte).

Parameters

  in | the byte to add

Definition at line 240 of file pubkey.h.

References update().

Referenced by Botan::TLS::Server_Key_Exchange::Server_Key_Exchange(), and update().

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

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

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

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

Add a message part.

Parameters

  in | the message part to add

Definition at line 253 of file pubkey.h.

References update().

Referenced by update().

253 { update(in.data(), in.size()); }
Botan::PK_Signer::update
void update(uint8_t in)
Definition: pubkey.h:240

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

Add a message part.

Parameters

  in | the message part to add

Definition at line 259 of file pubkey.h.

260 {
261 update(reinterpret_cast<const uint8_t*>(in.data()), in.size());
262 }
Botan::PK_Signer::update
void update(uint8_t in)
Definition: pubkey.h:240

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

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