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

#include <pubkey.h>

Public Member Functions

PK_Signeroperator= (const PK_Signer &)=delete
 
 PK_Signer (const Private_Key &key, const std::string &emsa, Signature_Format format=IEEE_1363, Fault_Protection prot=ENABLE_FAULT_PROTECTION)
 
 PK_Signer (const PK_Signer &)=delete
 
void set_output_format (Signature_Format format)
 
std::vector< bytesign_message (const byte in[], size_t length, RandomNumberGenerator &rng)
 
std::vector< bytesign_message (const std::vector< byte > &in, RandomNumberGenerator &rng)
 
std::vector< bytesign_message (const secure_vector< byte > &in, RandomNumberGenerator &rng)
 
std::vector< bytesignature (RandomNumberGenerator &rng)
 
void update (byte in)
 
void update (const byte in[], size_t length)
 
void update (const std::vector< byte > &in)
 
 ~PK_Signer ()
 

Detailed Description

Public Key Signer. Use the sign_message() functions for small messages. Use multiple calls update() to process large messages and generate the signature by finally calling signature().

Definition at line 128 of file pubkey.h.

Constructor & Destructor Documentation

Botan::PK_Signer::PK_Signer ( const Private_Key key,
const std::string &  emsa,
Signature_Format  format = IEEE_1363,
Fault_Protection  prot = ENABLE_FAULT_PROTECTION 
)

Construct a PK Signer.

Parameters
keythe key to use inside this signer
emsathe EMSA to use An example would be "EMSA1(SHA-224)".
formatthe signature format to use
protsays if fault protection should be enabled

Definition at line 125 of file pubkey.cpp.

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

129  {
130  Algorithm_Factory::Engine_Iterator i(global_state().algorithm_factory());
131 
132  op = nullptr;
133  verify_op = nullptr;
134 
135  while(const Engine* engine = i.next())
136  {
137  if(!op)
138  op = engine->get_signature_op(key);
139 
140  if(!verify_op && prot == ENABLE_FAULT_PROTECTION)
141  verify_op = engine->get_verify_op(key);
142 
143  if(op && (verify_op || prot == DISABLE_FAULT_PROTECTION))
144  break;
145  }
146 
147  if(!op || (!verify_op && prot == ENABLE_FAULT_PROTECTION))
148  throw Lookup_Error("PK_Signer: No working engine for " +
149  key.algo_name());
150 
151  emsa = get_emsa(emsa_name);
152  sig_format = format;
153  }
Botan::PK_Signer::PK_Signer ( const PK_Signer )
delete
Botan::PK_Signer::~PK_Signer ( )
inline

Definition at line 204 of file pubkey.h.

204 { delete op; delete verify_op; delete emsa; }

Member Function Documentation

PK_Signer& Botan::PK_Signer::operator= ( const PK_Signer )
delete
void Botan::PK_Signer::set_output_format ( Signature_Format  format)
inline

Set the output format of the signature.

Parameters
formatthe signature format to use

Definition at line 186 of file pubkey.h.

186 { sig_format = format; }
std::vector< byte > Botan::PK_Signer::sign_message ( const byte  in[],
size_t  length,
RandomNumberGenerator rng 
)

Sign a message.

Parameters
inthe message to sign as a byte array
lengththe length of the above byte array
rngthe rng to use
Returns
signature

Definition at line 158 of file pubkey.cpp.

References signature(), and update().

Referenced by Botan::TLS::Certificate_Verify::Certificate_Verify(), Botan::EAC1_1_ADO::make_signed(), Botan::X509_Object::make_signed(), Botan::EAC1_1_gen_CVC< Derived >::make_signed(), and Botan::KeyPair::signature_consistency_check().

160  {
161  update(msg, length);
162  return signature(rng);
163  }
std::vector<byte> Botan::PK_Signer::sign_message ( const std::vector< byte > &  in,
RandomNumberGenerator rng 
)
inline

Sign a message.

Parameters
inthe message to sign
rngthe rng to use
Returns
signature

Definition at line 147 of file pubkey.h.

References rng, and sign_message().

Referenced by sign_message().

149  { return sign_message(&in[0], in.size(), rng); }
std::vector<byte> Botan::PK_Signer::sign_message ( const secure_vector< byte > &  in,
RandomNumberGenerator rng 
)
inline

Definition at line 151 of file pubkey.h.

References rng, and sign_message().

Referenced by sign_message().

153  { return sign_message(&in[0], in.size(), rng); }
std::vector< byte > Botan::PK_Signer::signature ( RandomNumberGenerator rng)

Get the signature of the so far processed message (provided by the calls to update()).

Parameters
rngthe rng to use
Returns
signature of the total message

Definition at line 208 of file pubkey.cpp.

References BOTAN_ASSERT, Botan::DER_SEQUENCE, Botan::DER_Encoder::encode_list(), Botan::EMSA::encoding_of(), Botan::DER_Encoder::end_cons(), Botan::DER_Encoder::get_contents_unlocked(), Botan::IEEE_1363, Botan::PK_Ops::Signature::max_input_bits(), Botan::PK_Ops::Signature::message_parts(), Botan::EMSA::raw_data(), rng, Botan::SEQUENCE, Botan::PK_Ops::Signature::sign(), Botan::DER_Encoder::start_cons(), Botan::ASN1::to_string(), and Botan::unlock().

Referenced by Botan::PK_Signer_Filter::end_msg(), Botan::TLS::Server_Key_Exchange::Server_Key_Exchange(), and sign_message().

209  {
210  std::vector<byte> encoded = unlock(emsa->encoding_of(emsa->raw_data(),
211  op->max_input_bits(),
212  rng));
213 
214  std::vector<byte> plain_sig = unlock(op->sign(&encoded[0], encoded.size(), rng));
215 
216  BOTAN_ASSERT(self_test_signature(encoded, plain_sig), "Signature was consistent");
217 
218  if(op->message_parts() == 1 || sig_format == IEEE_1363)
219  return plain_sig;
220 
221  if(sig_format == DER_SEQUENCE)
222  {
223  if(plain_sig.size() % op->message_parts())
224  throw Encoding_Error("PK_Signer: strange signature size found");
225  const size_t SIZE_OF_PART = plain_sig.size() / op->message_parts();
226 
227  std::vector<BigInt> sig_parts(op->message_parts());
228  for(size_t j = 0; j != sig_parts.size(); ++j)
229  sig_parts[j].binary_decode(&plain_sig[SIZE_OF_PART*j], SIZE_OF_PART);
230 
231  return DER_Encoder()
232  .start_cons(SEQUENCE)
233  .encode_list(sig_parts)
234  .end_cons()
235  .get_contents_unlocked();
236  }
237  else
238  throw Encoding_Error("PK_Signer: Unknown signature format " +
239  std::to_string(sig_format));
240  }
void Botan::PK_Signer::update ( byte  in)
inline

Add a message part (single byte).

Parameters
inthe byte to add

Definition at line 159 of file pubkey.h.

References update().

Referenced by Botan::TLS::Server_Key_Exchange::Server_Key_Exchange(), sign_message(), update(), and Botan::PK_Signer_Filter::write().

159 { update(&in, 1); }
void Botan::PK_Signer::update ( const byte  in[],
size_t  length 
)

Add a message part.

Parameters
inthe message part to add as a byte array
lengththe length of the above byte array

Definition at line 168 of file pubkey.cpp.

References Botan::EMSA::update().

169  {
170  emsa->update(in, length);
171  }
void Botan::PK_Signer::update ( const std::vector< byte > &  in)
inline

Add a message part.

Parameters
inthe message part to add

Definition at line 172 of file pubkey.h.

References update().

Referenced by update().

172 { update(&in[0], in.size()); }

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