Botan  1.11.4
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)
 
template<typename Alloc >
bool check_signature (const std::vector< byte, Alloc > &sig)
 
PK_Verifieroperator= (const PK_Verifier &)=delete
 
 PK_Verifier (const Public_Key &pub_key, const std::string &emsa, Signature_Format format=IEEE_1363)
 
 PK_Verifier (const PK_Verifier &)=delete
 
void set_input_format (Signature_Format format)
 
void update (byte in)
 
void update (const byte msg_part[], size_t length)
 
void update (const std::vector< byte > &in)
 
bool verify_message (const byte msg[], size_t msg_length, const byte sig[], size_t sig_length)
 
template<typename Alloc , typename Alloc2 >
bool verify_message (const std::vector< byte, Alloc > &msg, const std::vector< byte, 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 220 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 
)

Construct a PK Verifier.

Parameters
pub_keythe public key to verify against
emsathe EMSA to use (eg "EMSA3(SHA-1)")
formatthe signature format to use

Definition at line 245 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().

248  {
249  Algorithm_Factory::Engine_Iterator i(global_state().algorithm_factory());
250 
251  while(const Engine* engine = i.next())
252  {
253  op = engine->get_verify_op(key);
254  if(op)
255  break;
256  }
257 
258  if(!op)
259  throw Lookup_Error("PK_Verifier: No working engine for " +
260  key.algo_name());
261 
262  emsa = get_emsa(emsa_name);
263  sig_format = format;
264  }
Botan::PK_Verifier::PK_Verifier ( const PK_Verifier )
delete
Botan::PK_Verifier::~PK_Verifier ( )
inline

Definition at line 310 of file pubkey.h.

310 { delete op; delete emsa; }

Member Function Documentation

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
sigthe signature to be verified as a byte array
lengththe length of the above byte array
Returns
true if the signature is valid, false otherwise

Definition at line 297 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::BER_Decoder::start_cons(), and Botan::ASN1::to_string().

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

298  {
299  try {
300  if(sig_format == IEEE_1363)
301  return validate_signature(emsa->raw_data(), sig, length);
302  else if(sig_format == DER_SEQUENCE)
303  {
304  BER_Decoder decoder(sig, length);
305  BER_Decoder ber_sig = decoder.start_cons(SEQUENCE);
306 
307  size_t count = 0;
308  std::vector<byte> real_sig;
309  while(ber_sig.more_items())
310  {
311  BigInt sig_part;
312  ber_sig.decode(sig_part);
313  real_sig += BigInt::encode_1363(sig_part, op->message_part_size());
314  ++count;
315  }
316 
317  if(count != op->message_parts())
318  throw Decoding_Error("PK_Verifier: signature size invalid");
319 
320  return validate_signature(emsa->raw_data(),
321  &real_sig[0], real_sig.size());
322  }
323  else
324  throw Decoding_Error("PK_Verifier: Unknown signature format " +
325  std::to_string(sig_format));
326  }
327  catch(Invalid_Argument) { return false; }
328  }
template<typename Alloc >
bool Botan::PK_Verifier::check_signature ( const std::vector< byte, Alloc > &  sig)
inline

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

Parameters
sigthe signature to be verified
Returns
true if the signature is valid, false otherwise

Definition at line 286 of file pubkey.h.

287  {
288  return check_signature(&sig[0], sig.size());
289  }
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
formatthe signature format to use

Definition at line 269 of file pubkey.cpp.

References Botan::IEEE_1363, and Botan::PK_Ops::Verification::message_parts().

270  {
271  if(op->message_parts() == 1 && format != IEEE_1363)
272  throw Invalid_State("PK_Verifier: This algorithm always uses IEEE 1363");
273  sig_format = format;
274  }
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
inthe byte to add

Definition at line 252 of file pubkey.h.

References update().

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

252 { update(&in, 1); }
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_partthe new message part as a byte array
lengththe length of the above byte array

Definition at line 289 of file pubkey.cpp.

References Botan::EMSA::update().

290  {
291  emsa->update(in, length);
292  }
void Botan::PK_Verifier::update ( const std::vector< byte > &  in)
inline

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

Parameters
inthe new message part

Definition at line 267 of file pubkey.h.

References update().

Referenced by update().

268  { update(&in[0], in.size()); }
bool Botan::PK_Verifier::verify_message ( const byte  msg[],
size_t  msg_length,
const byte  sig[],
size_t  sig_length 
)

Verify a signature.

Parameters
msgthe message that the signature belongs to, as a byte array
msg_lengththe length of the above byte array msg
sigthe signature as a byte array
sig_lengththe length of the above byte array sig
Returns
true if the signature is valid

Definition at line 279 of file pubkey.cpp.

References check_signature(), and update().

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

281  {
282  update(msg, msg_length);
283  return check_signature(sig, sig_length);
284  }
template<typename Alloc , typename Alloc2 >
bool Botan::PK_Verifier::verify_message ( const std::vector< byte, Alloc > &  msg,
const std::vector< byte, Alloc2 > &  sig 
)
inline

Verify a signature.

Parameters
msgthe message that the signature belongs to
sigthe signature
Returns
true if the signature is valid

Definition at line 240 of file pubkey.h.

242  {
243  return verify_message(&msg[0], msg.size(),
244  &sig[0], sig.size());
245  }

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