Botan
1.11.15
|
#include <pubkey.h>
Public Member Functions | |
PK_Signer (const Private_Key &key, const std::string &emsa, Signature_Format format=IEEE_1363, Fault_Protection prot=ENABLE_FAULT_PROTECTION) | |
void | set_output_format (Signature_Format format) |
std::vector< byte > | sign_message (const byte in[], size_t length, RandomNumberGenerator &rng) |
std::vector< byte > | sign_message (const std::vector< byte > &in, RandomNumberGenerator &rng) |
std::vector< byte > | sign_message (const secure_vector< byte > &in, RandomNumberGenerator &rng) |
std::vector< byte > | signature (RandomNumberGenerator &rng) |
void | update (byte in) |
void | update (const byte in[], size_t length) |
void | update (const std::vector< byte > &in) |
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().
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.
key | the key to use inside this signer |
emsa | the EMSA to use An example would be "EMSA1(SHA-224)". |
format | the signature format to use |
prot | says if fault protection should be enabled |
Definition at line 118 of file pubkey.cpp.
References Botan::Public_Key::algo_name(), Botan::ENABLE_FAULT_PROTECTION, and Botan::get_emsa().
{ m_op.reset(get_pk_op<PK_Ops::Signature>(key, emsa_name)); if(prot == ENABLE_FAULT_PROTECTION) m_verify_op.reset(get_pk_op<PK_Ops::Verification>(key, emsa_name)); if(!m_op || (prot == ENABLE_FAULT_PROTECTION && !m_verify_op)) throw Lookup_Error("Signing with " + key.algo_name() + " not supported"); m_emsa.reset(get_emsa(emsa_name)); m_sig_format = format; }
void Botan::PK_Signer::set_output_format | ( | Signature_Format | format | ) | [inline] |
std::vector< byte > Botan::PK_Signer::sign_message | ( | const byte | in[], |
size_t | length, | ||
RandomNumberGenerator & | rng | ||
) |
Sign a message.
in | the message to sign as a byte array |
length | the length of the above byte array |
rng | the rng to use |
Definition at line 138 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().
std::vector<byte> Botan::PK_Signer::sign_message | ( | const std::vector< byte > & | in, |
RandomNumberGenerator & | rng | ||
) | [inline] |
Sign a message.
in | the message to sign |
rng | the rng to use |
Definition at line 147 of file pubkey.h.
References sign_message().
Referenced by sign_message().
{ 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 sign_message().
Referenced by sign_message().
{ 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()).
rng | the rng to use |
Definition at line 188 of file pubkey.cpp.
References BOTAN_ASSERT, Botan::DER_SEQUENCE, Botan::DER_Encoder::encode_list(), Botan::DER_Encoder::end_cons(), Botan::DER_Encoder::get_contents_unlocked(), Botan::IEEE_1363, Botan::SEQUENCE, Botan::DER_Encoder::start_cons(), Botan::ASN1::to_string(), and Botan::unlock().
Referenced by Botan::TLS::Server_Key_Exchange::Server_Key_Exchange(), and sign_message().
{ std::vector<byte> encoded = unlock(m_emsa->encoding_of(m_emsa->raw_data(), m_op->max_input_bits(), rng)); std::vector<byte> plain_sig = unlock(m_op->sign(&encoded[0], encoded.size(), rng)); BOTAN_ASSERT(self_test_signature(encoded, plain_sig), "Signature was consistent"); if(m_op->message_parts() == 1 || m_sig_format == IEEE_1363) return plain_sig; if(m_sig_format == DER_SEQUENCE) { if(plain_sig.size() % m_op->message_parts()) throw Encoding_Error("PK_Signer: strange signature size found"); const size_t SIZE_OF_PART = plain_sig.size() / m_op->message_parts(); std::vector<BigInt> sig_parts(m_op->message_parts()); for(size_t j = 0; j != sig_parts.size(); ++j) sig_parts[j].binary_decode(&plain_sig[SIZE_OF_PART*j], SIZE_OF_PART); return DER_Encoder() .start_cons(SEQUENCE) .encode_list(sig_parts) .end_cons() .get_contents_unlocked(); } else throw Encoding_Error("PK_Signer: Unknown signature format " + std::to_string(m_sig_format)); }
void Botan::PK_Signer::update | ( | byte | in | ) | [inline] |
Add a message part (single byte).
in | the byte to add |
Definition at line 159 of file pubkey.h.
References update().
Referenced by botan_pk_op_sign_update(), Botan::TLS::Server_Key_Exchange::Server_Key_Exchange(), sign_message(), and update().
{ update(&in, 1); }
void Botan::PK_Signer::update | ( | const byte | in[], |
size_t | length | ||
) |
Add a message part.
in | the message part to add as a byte array |
length | the length of the above byte array |
Definition at line 148 of file pubkey.cpp.
{ m_emsa->update(in, length); }
void Botan::PK_Signer::update | ( | const std::vector< byte > & | in | ) | [inline] |