Botan 1.10.17

Public Member Functions | List of all members
Botan::PK_Verifier Class Reference

`#include <pubkey.h>`

## Public Member Functions
bool | check_signature (const byte sig[], size_t length)
bool | check_signature (const MemoryRegion< byte > &sig)
| PK_Verifier (const Public_Key &pub_key, const std::string &emsa, Signature_Format format=IEEE_1363)
void | set_input_format (Signature_Format format)
void | update (byte in)
void | update (const byte msg_part[], size_t length)
void | update (const MemoryRegion< byte > &in)
bool | verify_message (const byte msg[], size_t msg_length, const byte sig[], size_t sig_length)
bool | verify_message (const MemoryRegion< byte > &msg, const MemoryRegion< byte > &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 211 of file pubkey.h.

## Constructor & Destructor Documentation

## ◆ PK_Verifier()

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

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

Definition at line 248 of file pubkey.cpp.

References Botan::Public_Key::algo_name(), Botan::get_emsa(), Botan::Global_State_Management::global_state(), and Botan::Algorithm_Factory::Engine_Iterator::next().

251 {
252 Algorithm_Factory::Engine_Iterator i(global_state().algorithm_factory());
253
254 op = 0;
255
256 while(const Engine* engine = i.next())
257 {
258 op = engine->get_verify_op(key);
259 if(op)
260 break;
261 }
262
263 if(!op)
264 throw Lookup_Error("Verification with " + key.algo_name() + " not supported");
265
266 emsa = get_emsa(emsa_name);
267 sig_format = format;
268 }
Botan::get_emsa
EMSA * get_emsa(const std::string &algo_spec)
Definition: get_enc.cpp:86
Botan::Algorithm_Factory::Engine_Iterator
friend class Engine_Iterator
Definition: algo_factory.h:207
Botan::Global_State_Management::global_state
Library_State & global_state()
Definition: global_state.cpp:32

## ◆ ~PK_Verifier()

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

Definition at line 296 of file pubkey.h.

296 { delete op; delete emsa; }

## Member Function Documentation

## ◆ check_signature() [1/2]

bool Botan::PK_Verifier::check_signature | ( | const byte | 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 301 of file pubkey.cpp.

References Botan::BER_Decoder::decode(), Botan::DER_SEQUENCE, Botan::BigInt::encode_1363(), Botan::IEEE_1363, Botan::PK_Ops::Verification::message_part_size(), Botan::PK_Ops::Verification::message_parts(), Botan::BER_Decoder::more_items(), Botan::EMSA::raw_data(), Botan::SEQUENCE, Botan::MemoryRegion< T >::size(), Botan::BER_Decoder::start_cons(), and Botan::to_string().

Referenced by Botan::PK_Verifier_Filter::end_msg(), and verify_message().

302 {
303 try {
304 if(sig_format == IEEE_1363)
305 return validate_signature(emsa->raw_data(), sig, length);
306 else if(sig_format == DER_SEQUENCE)
307 {
308 BER_Decoder decoder(sig, length);
309 BER_Decoder ber_sig = decoder.start_cons(SEQUENCE);
310
311 size_t count = 0;
312 SecureVector<byte> real_sig;
313 while(ber_sig.more_items())
314 {
315 BigInt sig_part;
316 ber_sig.decode(sig_part);
317 real_sig += BigInt::encode_1363(sig_part, op->message_part_size());
318 ++count;
319 }
320
321 if(count != op->message_parts())
322 throw Decoding_Error("PK_Verifier: signature size invalid");
323
324 return validate_signature(emsa->raw_data(),
325 &real_sig[0], real_sig.size());
326 }
327 else
328 throw Decoding_Error("PK_Verifier: Unknown signature format " +
329 to_string(sig_format));
330 }
331 catch(Invalid_Argument) { return false; }
332 }
Botan::PK_Ops::Verification::message_parts
virtual size_t message_parts() const
Definition: pk_ops.h:98
Botan::Invalid_Argument
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20
Botan::PK_Ops::Verification::message_part_size
virtual size_t message_part_size() const
Definition: pk_ops.h:104
Botan::EMSA::raw_data
virtual SecureVector< byte > raw_data()=0
Botan::SEQUENCE
Definition: asn1_int.h:35
Botan::IEEE_1363
Definition: pubkey.h:24
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29
Botan::DER_SEQUENCE
Definition: pubkey.h:24
Botan::to_string
std::string to_string(u64bit n, size_t min_len)
Definition: parsing.cpp:42
Botan::BigInt::encode_1363
static SecureVector< byte > encode_1363(const BigInt &n, size_t bytes)
Definition: big_code.cpp:78

## ◆ check_signature() [2/2]

bool Botan::PK_Verifier::check_signature | ( | const MemoryRegion< byte > & | 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 275 of file pubkey.h.

References Botan::MemoryRegion< T >::size().

276 {
277 return check_signature(&sig[0], sig.size());
278 }
Botan::PK_Verifier::check_signature
bool check_signature(const byte sig[], size_t length)
Definition: pubkey.cpp:301
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29

## ◆ set_input_format()

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, and Botan::PK_Ops::Verification::message_parts().

274 {
275 if(op->message_parts() == 1 && format != IEEE_1363)
276 throw Invalid_State("PK_Verifier: This algorithm always uses IEEE 1363");
277 sig_format = format;
278 }
Botan::PK_Ops::Verification::message_parts
virtual size_t message_parts() const
Definition: pk_ops.h:98
Botan::IEEE_1363
Definition: pubkey.h:24

## ◆ update() [1/3]

void Botan::PK_Verifier::update | ( | byte | 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 242 of file pubkey.h.

References update().

Referenced by update(), verify_message(), and Botan::PK_Verifier_Filter::write().

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

## ◆ update() [2/3]

void Botan::PK_Verifier::update | ( | const byte | 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 293 of file pubkey.cpp.

References Botan::EMSA::update().

294 {
295 emsa->update(in, length);
296 }
Botan::EMSA::update
virtual void update(const byte input[], size_t length)=0

## ◆ update() [3/3]

void Botan::PK_Verifier::update | ( | const MemoryRegion< byte > & | 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 257 of file pubkey.h.

References Botan::MemoryRegion< T >::size().

258 { update(&in[0], in.size()); }
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29
Botan::PK_Verifier::update
void update(byte in)
Definition: pubkey.h:242

## ◆ verify_message() [1/2]

bool Botan::PK_Verifier::verify_message | ( | const byte | msg[],
|  | size_t | msg_length,
|  | const byte | 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 283 of file pubkey.cpp.

References check_signature(), and update().

Referenced by Botan::EAC_Signed_Object::check_signature(), and Botan::X509_Object::check_signature().

285 {
286 update(msg, msg_length);
287 return check_signature(sig, sig_length);
288 }
Botan::PK_Verifier::check_signature
bool check_signature(const byte sig[], size_t length)
Definition: pubkey.cpp:301
Botan::PK_Verifier::update
void update(byte in)
Definition: pubkey.h:242

## ◆ verify_message() [2/2]

bool Botan::PK_Verifier::verify_message | ( | const MemoryRegion< byte > & | msg,
|  | const MemoryRegion< byte > & | 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 230 of file pubkey.h.

References Botan::MemoryRegion< T >::size().

232 {
233 return verify_message(&msg[0], msg.size(),
234 &sig[0], sig.size());
235 }
Botan::PK_Verifier::verify_message
bool verify_message(const byte msg[], size_t msg_length, const byte sig[], size_t sig_length)
Definition: pubkey.cpp:283
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29

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

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