Botan 3.0.0
Crypto and TLS for C&
Public Member Functions | List of all members
Botan::PK_Signer Class Referencefinal

#include <pubkey.h>

Public Member Functions

AlgorithmIdentifier algorithm_identifier () const
 
std::string hash_function () const
 
PK_Signeroperator= (const PK_Signer &)=delete
 
PK_Signeroperator= (PK_Signer &&) noexcept=delete
 
 PK_Signer (const PK_Signer &)=delete
 
 PK_Signer (const Private_Key &key, RandomNumberGenerator &rng, std::string_view padding, Signature_Format format=Signature_Format::Standard, std::string_view provider="")
 
 PK_Signer (PK_Signer &&) noexcept=delete
 
void set_output_format (Signature_Format format)
 
std::vector< uint8_t > sign_message (const uint8_t in[], size_t length, RandomNumberGenerator &rng)
 
std::vector< uint8_t > sign_message (std::span< const uint8_t > in, RandomNumberGenerator &rng)
 
std::vector< uint8_t > signature (RandomNumberGenerator &rng)
 
size_t signature_length () const
 
void update (const uint8_t in[], size_t length)
 
void update (std::span< const uint8_t > in)
 
void update (std::string_view in)
 
void update (uint8_t 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 166 of file pubkey.h.

Constructor & Destructor Documentation

◆ PK_Signer() [1/3]

Botan::PK_Signer::PK_Signer ( const Private_Key key,
RandomNumberGenerator rng,
std::string_view  padding,
Signature_Format  format = Signature_Format::Standard,
std::string_view  provider = "" 
)

Construct a PK Signer.

Parameters
keythe key to use inside this signer
rngthe random generator to use
paddingthe padding/hash to use, eg "EMSA_PKCS1(SHA-256)"
formatthe signature format to use
providerthe provider to use

Definition at line 250 of file pubkey.cpp.

255 {
256 m_op = key.create_signature_op(rng, emsa, provider);
257 if(!m_op)
258 {
259 throw Invalid_Argument(fmt("Key type {} does not support signature generation", key.algo_name()));
260 }
261 m_sig_format = format;
262 m_parts = key.message_parts();
263 m_part_size = key.message_part_size();
264 check_der_format_supported(format, m_parts);
265 }
std::string fmt(std::string_view format, const T &... args)
Definition: fmt.h:60

References Botan::Asymmetric_Key::algo_name(), Botan::Private_Key::create_signature_op(), Botan::fmt(), Botan::Public_Key::message_part_size(), and Botan::Public_Key::message_parts().

◆ ~PK_Signer()

Botan::PK_Signer::~PK_Signer ( )
default

◆ PK_Signer() [2/3]

Botan::PK_Signer::PK_Signer ( const PK_Signer )
delete

◆ PK_Signer() [3/3]

Botan::PK_Signer::PK_Signer ( PK_Signer &&  )
deletenoexcept

Member Function Documentation

◆ algorithm_identifier()

AlgorithmIdentifier Botan::PK_Signer::algorithm_identifier ( ) const

Return an AlgorithmIdentifier appropriate for identifying the signature method being generated by this PK_Signer. Throws an exception if this is not available for the current signature scheme.

Definition at line 267 of file pubkey.cpp.

268 {
269 return m_op->algorithm_identifier();
270 }

◆ hash_function()

std::string Botan::PK_Signer::hash_function ( ) const

Return the hash function which is being used to create signatures. This should never return an empty string however it may return a string which does not map directly to a hash function, in particular if "Raw" (unhashed) encoding is being used.

Definition at line 272 of file pubkey.cpp.

273 {
274 return m_op->hash_function();
275 }

◆ operator=() [1/2]

PK_Signer & Botan::PK_Signer::operator= ( const PK_Signer )
delete

◆ operator=() [2/2]

PK_Signer & Botan::PK_Signer::operator= ( PK_Signer &&  )
deletenoexcept

◆ set_output_format()

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 261 of file pubkey.h.

261{ m_sig_format = format; }

◆ sign_message() [1/2]

std::vector< uint8_t > Botan::PK_Signer::sign_message ( const uint8_t  in[],
size_t  length,
RandomNumberGenerator rng 
)
inline

Sign a message all in one go

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 198 of file pubkey.h.

200 {
201 this->update(in, length);
202 return this->signature(rng);
203 }
std::vector< uint8_t > signature(RandomNumberGenerator &rng)
Definition: pubkey.cpp:323
int(* update)(CTX *, const void *, CC_LONG len)

References update.

Referenced by Botan::X509_Object::make_signed(), Botan::KeyPair::signature_consistency_check(), and Botan::TLS::Callbacks::tls_sign_message().

◆ sign_message() [2/2]

std::vector< uint8_t > Botan::PK_Signer::sign_message ( std::span< const uint8_t >  in,
RandomNumberGenerator rng 
)
inline

Sign a message.

Parameters
inthe message to sign
rngthe rng to use
Returns
signature

Definition at line 211 of file pubkey.h.

213 {
214 return sign_message(in.data(), in.size(), rng);
215 }
std::vector< uint8_t > sign_message(const uint8_t in[], size_t length, RandomNumberGenerator &rng)
Definition: pubkey.h:198

◆ signature()

std::vector< uint8_t > 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 323 of file pubkey.cpp.

324 {
325 std::vector<uint8_t> sig = unlock(m_op->sign(rng));
326
327 if(m_sig_format == Signature_Format::Standard)
328 {
329 return sig;
330 }
331 else if(m_sig_format == Signature_Format::DerSequence)
332 {
333 return der_encode_signature(sig, m_parts, m_part_size);
334 }
335 else
336 throw Internal_Error("PK_Signer: Invalid signature format enum");
337 }
std::vector< T > unlock(const secure_vector< T > &in)
Definition: secmem.h:77

References Botan::DerSequence, Botan::Standard, and Botan::unlock().

◆ signature_length()

size_t Botan::PK_Signer::signature_length ( ) const

Return an upper bound on the length of the signatures this PK_Signer will produce

Definition at line 307 of file pubkey.cpp.

308 {
309 if(m_sig_format == Signature_Format::Standard)
310 {
311 return m_op->signature_length();
312 }
313 else if(m_sig_format == Signature_Format::DerSequence)
314 {
315 // This is a large over-estimate but its easier than computing
316 // the exact value
317 return m_op->signature_length() + (8 + 4*m_parts);
318 }
319 else
320 throw Internal_Error("PK_Signer: Invalid signature format enum");
321 }

References Botan::DerSequence, and Botan::Standard.

◆ update() [1/4]

void Botan::PK_Signer::update ( const uint8_t  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 279 of file pubkey.cpp.

280 {
281 m_op->update(in, length);
282 }

◆ update() [2/4]

void Botan::PK_Signer::update ( std::span< const uint8_t >  in)
inline

Add a message part.

Parameters
inthe message part to add

Definition at line 234 of file pubkey.h.

235 {
236 update(in.data(), in.size());
237 }

References update.

◆ update() [3/4]

void Botan::PK_Signer::update ( std::string_view  in)
inline

Add a message part.

Parameters
inthe message part to add

Definition at line 243 of file pubkey.h.

244 {
245 update(cast_char_ptr_to_uint8(in.data()), in.size());
246 }
const uint8_t * cast_char_ptr_to_uint8(const char *s)
Definition: mem_ops.h:183

References Botan::cast_char_ptr_to_uint8(), and update.

◆ update() [4/4]

void Botan::PK_Signer::update ( uint8_t  in)
inline

Add a message part (single byte).

Parameters
inthe byte to add

Definition at line 221 of file pubkey.h.

221{ update(&in, 1); }

References update().

Referenced by update().


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