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_Verifier Class Referencefinal

`#include <pubkey.h>`

## Public Member Functions
bool | check_signature (const uint8_t sig[], size_t length)
template<typename Alloc >
bool | check_signature (const std::vector< uint8_t, Alloc > &sig)
PK_Verifier & | operator= (const PK_Verifier &)=delete
| PK_Verifier (const Public_Key &pub_key, const std::string &emsa, Signature_Format format=IEEE_1363, const std::string &provider="")
| PK_Verifier (const PK_Verifier &)=delete
void | set_input_format (Signature_Format format)
void | update (uint8_t in)
void | update (const uint8_t msg_part[], size_t length)
void | update (const std::vector< uint8_t > &in)
void | update (const std::string &in)
bool | verify_message (const uint8_t msg[], size_t msg_length, const uint8_t sig[], size_t sig_length)
template<typename Alloc , typename Alloc2 >
bool | verify_message (const std::vector< uint8_t, Alloc > &msg, const std::vector< uint8_t, Alloc2 > &sig)
| ~PK_Verifier ()

## Detailed Description

Public Key Verifier. Use the verify_message() functions for small messages. Use multiple calls update() to process large messages and verify the signature by finally calling check_signature().

Definition at line 288 of file pubkey.h.

## Constructor & Destructor Documentation

Botan::PK_Verifier::PK_Verifier | ( | const Public_Key & | pub_key,
|  | const std::string & | emsa,
|  | Signature_Format | format = `IEEE_1363`,
|  | const std::string & | provider = `""`
| ) |  |

Construct a PK Verifier.

Parameters

  pub_key | the public key to verify against
  emsa | the EMSA to use (eg "EMSA3(SHA-1)")
  format | the signature format to use
  provider | the provider to use

Definition at line 258 of file pubkey.cpp.

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

262 {
263 m_op = key.create_verification_op(emsa, provider);
264 if(!m_op)
265 throw Invalid_Argument("Key type " + key.algo_name() + " does not support signature verification");
266 m_sig_format = format;
267 m_parts = key.message_parts();
268 m_part_size = key.message_part_size();
269 }

Botan::PK_Verifier::~PK_Verifier | ( |  | ) |

Definition at line 271 of file pubkey.cpp.

271 { /* for unique_ptr */ }

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

## Member Function Documentation

bool Botan::PK_Verifier::check_signature | ( | const uint8_t | sig[],
|  | size_t | length
| ) |  |

Check the signature of the buffered message, i.e. the one build by successive calls to update.

Parameters

  sig | the signature to be verified as a byte array
  length | the length of the above byte array

Returns
  true if the signature is valid, false otherwise

Definition at line 292 of file pubkey.cpp.

References Botan::BER_Decoder::decode(), Botan::DER_SEQUENCE, Botan::BigInt::encode_1363(), Botan::IEEE_1363, Botan::BER_Decoder::more_items(), Botan::SEQUENCE, and Botan::BER_Decoder::start_cons().

Referenced by Botan::TLS::Server_Key_Exchange::verify(), and verify_message().

293 {
294 try {
295 if(m_sig_format == IEEE_1363)
296 {
297 return m_op->is_valid_signature(sig, length);
298 }
299 else if(m_sig_format == DER_SEQUENCE)
300 {
301 std::vector<uint8_t> real_sig;
302 BER_Decoder decoder(sig, length);
303 BER_Decoder ber_sig = decoder.start_cons(SEQUENCE);
304
305 size_t count = 0;
306 while(ber_sig.more_items())
307 {
308 BigInt sig_part;
309 ber_sig.decode(sig_part);
310 real_sig += BigInt::encode_1363(sig_part, m_part_size);
311 ++count;
312 }
313
314 if(count != m_parts)
315 throw Decoding_Error("PK_Verifier: signature size invalid");
316
317 return m_op->is_valid_signature(real_sig.data(), real_sig.size());
318 }
319 else
320 throw Internal_Error("PK_Verifier: Invalid signature format enum");
321 }
322 catch(Invalid_Argument&) { return false; }
323 }
Botan::SEQUENCE
Definition: asn1_obj.h:39
Botan::IEEE_1363
Definition: pubkey.h:29
Botan::DER_SEQUENCE
Definition: pubkey.h:29
Botan::BigInt::encode_1363
static secure_vector< uint8_t > encode_1363(const BigInt &n, size_t bytes)
Definition: big_code.cpp:82
template<typename Alloc >

bool Botan::PK_Verifier::check_signature | ( | const std::vector< uint8_t, Alloc > & | sig | ) |
| inline

Check the signature of the buffered message, i.e. the one build by successive calls to update.

Parameters

  sig | the signature to be verified

Returns
  true if the signature is valid, false otherwise

Definition at line 380 of file pubkey.h.

381 {
382 return check_signature(sig.data(), sig.size());
383 }
Botan::PK_Verifier::check_signature
bool check_signature(const uint8_t sig[], size_t length)
Definition: pubkey.cpp:292

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

void Botan::PK_Verifier::set_input_format | ( | Signature_Format | format | ) |

Set the format of the signatures fed to this verifier.

Parameters

  format | the signature format to use

Definition at line 273 of file pubkey.cpp.

References Botan::IEEE_1363.

274 {
275 if(format != IEEE_1363 && m_parts == 1)
276 throw Invalid_Argument("PK_Verifier: This algorithm does not support DER encoding");
277 m_sig_format = format;
278 }
Botan::IEEE_1363
Definition: pubkey.h:29

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

Add a message part (single byte) of the message corresponding to the signature to be verified.

Parameters

  in | the byte to add

Definition at line 337 of file pubkey.h.

References update().

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

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

void Botan::PK_Verifier::update | ( | const uint8_t | msg_part[],
|  | size_t | length
| ) |  |

Add a message part of the message corresponding to the signature to be verified.

Parameters

  msg_part | the new message part as a byte array
  length | the length of the above byte array

Definition at line 287 of file pubkey.cpp.

288 {
289 m_op->update(in, length);
290 }

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

Add a message part of the message corresponding to the signature to be verified.

Parameters

  in | the new message part

Definition at line 352 of file pubkey.h.

353 { update(in.data(), in.size()); }
Botan::PK_Verifier::update
void update(uint8_t in)
Definition: pubkey.h:337

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

Add a message part of the message corresponding to the signature to be verified.

Definition at line 359 of file pubkey.h.

360 {
361 update(reinterpret_cast<const uint8_t*>(in.data()), in.size());
362 }
Botan::PK_Verifier::update
void update(uint8_t in)
Definition: pubkey.h:337

bool Botan::PK_Verifier::verify_message | ( | const uint8_t | msg[],
|  | size_t | msg_length,
|  | const uint8_t | sig[],
|  | size_t | sig_length
| ) |  |

Verify a signature.

Parameters

  msg | the message that the signature belongs to, as a byte array
  msg_length | the length of the above byte array msg
  sig | the signature as a byte array
  sig_length | the length of the above byte array sig

Returns
  true if the signature is valid

Definition at line 280 of file pubkey.cpp.

References check_signature(), and update().

Referenced by Botan::X509_Object::check_signature(), Botan::KeyPair::signature_consistency_check(), Botan::TLS::Certificate_Verify::verify(), and Botan::OCSP::Response::verify_signature().

282 {
283 update(msg, msg_length);
284 return check_signature(sig, sig_length);
285 }
Botan::PK_Verifier::update
void update(uint8_t in)
Definition: pubkey.h:337
Botan::PK_Verifier::check_signature
bool check_signature(const uint8_t sig[], size_t length)
Definition: pubkey.cpp:292
template<typename Alloc , typename Alloc2 >

bool Botan::PK_Verifier::verify_message | ( | const std::vector< uint8_t, Alloc > & | msg,
|  | const std::vector< uint8_t, Alloc2 > & | sig
| ) |  |
| inline

Verify a signature.

Parameters

  msg | the message that the signature belongs to
  sig | the signature

Returns
  true if the signature is valid

Definition at line 325 of file pubkey.h.

327 {
328 return verify_message(msg.data(), msg.size(),
329 sig.data(), sig.size());
330 }
Botan::PK_Verifier::verify_message
bool verify_message(const uint8_t msg[], size_t msg_length, const uint8_t sig[], size_t sig_length)
Definition: pubkey.cpp:280

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

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