Botan  1.11.14
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_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 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)
 

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

References Botan::Public_Key::algo_name(), and Botan::get_emsa().

228  {
229  m_op.reset(get_pk_op<PK_Ops::Verification>(key, emsa_name));
230 
231  if(!m_op)
232  throw Lookup_Error("Verification with " + key.algo_name() + " not supported");
233 
234  m_emsa.reset(get_emsa(emsa_name));
235  m_sig_format = format;
236  }
BOTAN_DLL EMSA * get_emsa(const std::string &algo_spec)
Definition: get_pk_pad.cpp:15

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 269 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, Botan::BER_Decoder::start_cons(), and Botan::ASN1::to_string().

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

270  {
271  try {
272  if(m_sig_format == IEEE_1363)
273  return validate_signature(m_emsa->raw_data(), sig, length);
274  else if(m_sig_format == DER_SEQUENCE)
275  {
276  BER_Decoder decoder(sig, length);
277  BER_Decoder ber_sig = decoder.start_cons(SEQUENCE);
278 
279  size_t count = 0;
280  std::vector<byte> real_sig;
281  while(ber_sig.more_items())
282  {
283  BigInt sig_part;
284  ber_sig.decode(sig_part);
285  real_sig += BigInt::encode_1363(sig_part, m_op->message_part_size());
286  ++count;
287  }
288 
289  if(count != m_op->message_parts())
290  throw Decoding_Error("PK_Verifier: signature size invalid");
291 
292  return validate_signature(m_emsa->raw_data(),
293  &real_sig[0], real_sig.size());
294  }
295  else
296  throw Decoding_Error("PK_Verifier: Unknown signature format " +
297  std::to_string(m_sig_format));
298  }
299  catch(Invalid_Argument) { return false; }
300  }
static secure_vector< byte > encode_1363(const BigInt &n, size_t bytes)
Definition: big_code.cpp:82
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:46
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 281 of file pubkey.h.

282  {
283  return check_signature(&sig[0], sig.size());
284  }
bool check_signature(const byte sig[], size_t length)
Definition: pubkey.cpp:269
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 241 of file pubkey.cpp.

References Botan::IEEE_1363.

242  {
243  if(m_op->message_parts() == 1 && format != IEEE_1363)
244  throw Invalid_State("PK_Verifier: This algorithm always uses IEEE 1363");
245  m_sig_format = format;
246  }
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 247 of file pubkey.h.

References update().

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

247 { update(&in, 1); }
void update(byte in)
Definition: pubkey.h:247
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 261 of file pubkey.cpp.

262  {
263  m_emsa->update(in, length);
264  }
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 262 of file pubkey.h.

263  { update(&in[0], in.size()); }
void update(byte in)
Definition: pubkey.h:247
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 251 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().

253  {
254  update(msg, msg_length);
255  return check_signature(sig, sig_length);
256  }
bool check_signature(const byte sig[], size_t length)
Definition: pubkey.cpp:269
void update(byte in)
Definition: pubkey.h:247
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 235 of file pubkey.h.

237  {
238  return verify_message(&msg[0], msg.size(),
239  &sig[0], sig.size());
240  }
bool verify_message(const byte msg[], size_t msg_length, const byte sig[], size_t sig_length)
Definition: pubkey.cpp:251

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