Botan 2.13.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)
template<typename Alloc >
void | update (const std::vector< uint8_t, Alloc > &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 298 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 302 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().

306 {
307 m_op = key.create_verification_op(emsa, provider);
308 if(!m_op)
309 throw Invalid_Argument("Key type " + key.algo_name() + " does not support signature verification");
310 m_sig_format = format;
311 m_parts = key.message_parts();
312 m_part_size = key.message_part_size();
313 }

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

Definition at line 315 of file pubkey.cpp.

315 { /* 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 336 of file pubkey.cpp.

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

Referenced by botan_pk_op_verify_finish(), Botan::Roughtime::Response::validate(), and verify_message().

337 {
338 try {
339 if(m_sig_format == IEEE_1363)
340 {
341 return m_op->is_valid_signature(sig, length);
342 }
343 else if(m_sig_format == DER_SEQUENCE)
344 {
345 std::vector<uint8_t> real_sig;
346 BER_Decoder decoder(sig, length);
347 BER_Decoder ber_sig = decoder.start_cons(SEQUENCE);
348
349 BOTAN_ASSERT_NOMSG(m_parts != 0 && m_part_size != 0);
350
351 size_t count = 0;
352
353 while(ber_sig.more_items())
354 {
355 BigInt sig_part;
356 ber_sig.decode(sig_part);
357 real_sig += BigInt::encode_1363(sig_part, m_part_size);
358 ++count;
359 }
360
361 if(count != m_parts)
362 throw Decoding_Error("PK_Verifier: signature size invalid");
363
364 const std::vector<uint8_t> reencoded =
365 der_encode_signature(real_sig, m_parts, m_part_size);
366
367 if(reencoded.size() != length ||
368 same_mem(reencoded.data(), sig, reencoded.size()) == false)
369 {
370 throw Decoding_Error("PK_Verifier: signature is not the canonical DER encoding");
371 }
372
373 return m_op->is_valid_signature(real_sig.data(), real_sig.size());
374 }
375 else
376 throw Internal_Error("PK_Verifier: Invalid signature format enum");
377 }
378 catch(Invalid_Argument&) { return false; }
379 }
Botan::same_mem
bool same_mem(const T *p1, const T *p2, size_t n)
Definition: mem_ops.h:216
BOTAN_ASSERT_NOMSG
#define BOTAN_ASSERT_NOMSG(expr)
Definition: assert.h:68
Botan::SEQUENCE
Definition: asn1_obj.h:40
Botan::IEEE_1363
Definition: pk_keys.h:24
Botan::DER_SEQUENCE
Definition: pk_keys.h:24
Botan::BigInt::encode_1363
static secure_vector< uint8_t > encode_1363(const BigInt &n, size_t bytes)
Definition: big_code.cpp:111
Botan::OCSP::Response_Status_Code::Internal_Error
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 393 of file pubkey.h.

394 {
395 return check_signature(sig.data(), sig.size());
396 }
Botan::PK_Verifier::check_signature
bool check_signature(const uint8_t sig[], size_t length)
Definition: pubkey.cpp:336

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

References Botan::IEEE_1363.

318 {
319 if(format != IEEE_1363 && m_parts == 1)
320 throw Invalid_Argument("PK_Verifier: This algorithm does not support DER encoding");
321 m_sig_format = format;
322 }
Botan::IEEE_1363
Definition: pk_keys.h:24

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

References update().

Referenced by botan_pk_op_verify_update(), update(), Botan::Roughtime::Response::validate(), and verify_message().

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

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

332 {
333 m_op->update(in, length);
334 }
template<typename Alloc >

void Botan::PK_Verifier::update | ( | const std::vector< uint8_t, Alloc > & | 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 363 of file pubkey.h.

References update.

364 {
365 update(in.data(), in.size());
366 }
Botan::PK_Verifier::update
void update(uint8_t in)
Definition: pubkey.h:347

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

References Botan::cast_char_ptr_to_uint8(), and update.

373 {
374 update(cast_char_ptr_to_uint8(in.data()), in.size());
375 }
Botan::cast_char_ptr_to_uint8
const uint8_t * cast_char_ptr_to_uint8(const char *s)
Definition: mem_ops.h:189
Botan::PK_Verifier::update
void update(uint8_t in)
Definition: pubkey.h:347

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

References check_signature(), and update().

Referenced by Botan::KeyPair::signature_consistency_check(), Botan::TLS::Callbacks::tls_verify_message(), Botan::X509_Object::verify_signature(), and Botan::OCSP::Response::verify_signature().

326 {
327 update(msg, msg_length);
328 return check_signature(sig, sig_length);
329 }
Botan::PK_Verifier::update
void update(uint8_t in)
Definition: pubkey.h:347
Botan::PK_Verifier::check_signature
bool check_signature(const uint8_t sig[], size_t length)
Definition: pubkey.cpp:336
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 335 of file pubkey.h.

337 {
338 return verify_message(msg.data(), msg.size(),
339 sig.data(), sig.size());
340 }
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:324

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

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