Botan  1.11.26
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, const std::string &provider="")
 
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)
 
void update (const std::string &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,
const std::string &  provider = "" 
)

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

191  {
192  m_op.reset(get_pk_op<PK_Ops::Verification>("Verification", key, emsa_name, provider));
193  m_sig_format = format;
194  }

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

References Botan::DER_SEQUENCE, Botan::IEEE_1363, and Botan::ASN1::to_string().

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

216  {
217  try {
218  if(m_sig_format == IEEE_1363)
219  {
220  return m_op->is_valid_signature(sig, length);
221  }
222  else if(m_sig_format == DER_SEQUENCE)
223  {
224  std::vector<byte> real_sig = der_decode_signature(sig, length,
225  m_op->message_part_size(),
226  m_op->message_parts());
227 
228  return m_op->is_valid_signature(real_sig.data(), real_sig.size());
229  }
230  else
231  throw Decoding_Error("PK_Verifier: Unknown signature format " +
232  std::to_string(m_sig_format));
233  }
234  catch(Invalid_Argument) { return false; }
235  }
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:47
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 301 of file pubkey.h.

302  {
303  return check_signature(sig.data(), sig.size());
304  }
bool check_signature(const byte sig[], size_t length)
Definition: pubkey.cpp:215
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 196 of file pubkey.cpp.

References Botan::IEEE_1363.

197  {
198  if(m_op->message_parts() == 1 && format != IEEE_1363)
199  throw Invalid_State("PK_Verifier: This algorithm always uses IEEE 1363");
200  m_sig_format = format;
201  }
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 258 of file pubkey.h.

References update().

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

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

211  {
212  m_op->update(in, length);
213  }
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 273 of file pubkey.h.

274  { update(in.data(), in.size()); }
void update(byte in)
Definition: pubkey.h:258
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 280 of file pubkey.h.

281  {
282  update(reinterpret_cast<const byte*>(in.data()), in.size());
283  }
void update(byte in)
Definition: pubkey.h:258
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 203 of file pubkey.cpp.

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

205  {
206  update(msg, msg_length);
207  return check_signature(sig, sig_length);
208  }
bool check_signature(const byte sig[], size_t length)
Definition: pubkey.cpp:215
void update(byte in)
Definition: pubkey.h:258
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 246 of file pubkey.h.

248  {
249  return verify_message(msg.data(), msg.size(),
250  sig.data(), sig.size());
251  }
bool verify_message(const byte msg[], size_t msg_length, const byte sig[], size_t sig_length)
Definition: pubkey.cpp:203

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