Botan: Botan::PK_Signer Class Reference

Botan 1.10.16

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

`#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)
SecureVector< byte > | sign_message (const byte in[], size_t length, RandomNumberGenerator &rng)
SecureVector< byte > | sign_message (const MemoryRegion< byte > &in, RandomNumberGenerator &rng)
SecureVector< byte > | signature (RandomNumberGenerator &rng)
void | update (byte in)
void | update (const byte in[], size_t length)
void | update (const MemoryRegion< 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 123 of file pubkey.h.

## Constructor & Destructor Documentation

## ◆ PK_Signer()

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

  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 128 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().

132 {
133 Algorithm_Factory::Engine_Iterator i(global_state().algorithm_factory());
134
135 op = 0;
136 verify_op = 0;
137
138 while(const Engine* engine = i.next())
139 {
140 if(!op)
141 op = engine->get_signature_op(key);
142
143 if(!verify_op && prot == ENABLE_FAULT_PROTECTION)
144 verify_op = engine->get_verify_op(key);
145
146 if(op && (verify_op || prot == DISABLE_FAULT_PROTECTION))
147 break;
148 }
149
150 if(!op || (!verify_op && prot == ENABLE_FAULT_PROTECTION))
151 throw Lookup_Error("Signing with " + key.algo_name() + " not supported");
152
153 emsa = get_emsa(emsa_name);
154 sig_format = format;
155 }
Botan::get_emsa
EMSA * get_emsa(const std::string &algo_spec)
Definition: get_enc.cpp:86
Botan::Algorithm_Factory::Engine_Iterator
friend class Engine_Iterator
Definition: algo_factory.h:207
Botan::Global_State_Management::global_state
Library_State & global_state()
Definition: global_state.cpp:32
Botan::ENABLE_FAULT_PROTECTION
Definition: pubkey.h:30
Botan::DISABLE_FAULT_PROTECTION
Definition: pubkey.h:31

## ◆ ~PK_Signer()

Botan::PK_Signer::~PK_Signer | ( |  | ) |
| inline

Definition at line 192 of file pubkey.h.

192 { delete op; delete verify_op; delete emsa; }

## Member Function Documentation

## ◆ set_output_format()

void Botan::PK_Signer::set_output_format | ( | Signature_Format | format | ) |
| inline

Set the output format of the signature.

Parameters

  format | the signature format to use

Definition at line 177 of file pubkey.h.

References Botan::ENABLE_FAULT_PROTECTION, and Botan::IEEE_1363.

177 { sig_format = format; }

## ◆ sign_message() [1/2]

SecureVector< byte > Botan::PK_Signer::sign_message | ( | const byte | in[],
|  | size_t | length,
|  | RandomNumberGenerator & | rng
| ) |  |

Sign a message.

Parameters

  in | the message to sign as a byte array
  length | the length of the above byte array
  rng | the rng to use

Returns
  signature

Definition at line 160 of file pubkey.cpp.

162 {
163 update(msg, length);
164 return signature(rng);
165 }
Botan::PK_Signer::signature
SecureVector< byte > signature(RandomNumberGenerator &rng)
Definition: pubkey.cpp:210
Botan::PK_Signer::update
void update(byte in)
Definition: pubkey.h:150

## ◆ sign_message() [2/2]

SecureVector<byte> Botan::PK_Signer::sign_message | ( | const MemoryRegion< byte > & | in,
|  | RandomNumberGenerator & | rng
| ) |  |
| inline

Sign a message.

Parameters

  in | the message to sign
  rng | the rng to use

Returns
  signature

Definition at line 142 of file pubkey.h.

References Botan::MemoryRegion< T >::size().

144 { return sign_message(&in[0], in.size(), rng); }
Botan::PK_Signer::sign_message
SecureVector< byte > sign_message(const byte in[], size_t length, RandomNumberGenerator &rng)
Definition: pubkey.cpp:160
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29

## ◆ signature()

SecureVector< byte > Botan::PK_Signer::signature | ( | RandomNumberGenerator & | rng | ) |

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

Parameters

  rng | the rng to use

Returns
  signature of the total message

Definition at line 210 of file pubkey.cpp.

References Botan::PK_Ops::Encryption::max_input_bits().

Referenced by Botan::CMS_Encoder::sign().

211 {
212 SecureVector<byte> encoded = emsa->encoding_of(emsa->raw_data(),
213 op->max_input_bits(),
214 rng);
215
216 SecureVector<byte> plain_sig = op->sign(&encoded[0], encoded.size(), rng);
217
218 BOTAN_ASSERT(self_test_signature(encoded, plain_sig),
219 "PK_Signer consistency check failed");
220
221 if(op->message_parts() == 1 || sig_format == IEEE_1363)
222 return plain_sig;
223
224 if(sig_format == DER_SEQUENCE)
225 {
226 if(plain_sig.size() % op->message_parts())
227 throw Encoding_Error("PK_Signer: strange signature size found");
228 const size_t SIZE_OF_PART = plain_sig.size() / op->message_parts();
229
230 std::vector<BigInt> sig_parts(op->message_parts());
231 for(size_t j = 0; j != sig_parts.size(); ++j)
232 sig_parts[j].binary_decode(&plain_sig[SIZE_OF_PART*j], SIZE_OF_PART);
233
234 return DER_Encoder()
235 .start_cons(SEQUENCE)
236 .encode_list(sig_parts)
237 .end_cons()
238 .get_contents();
239 }
240 else
241 throw Encoding_Error("PK_Signer: Unknown signature format " +
242 to_string(sig_format));
243 }
Botan::PK_Ops::Signature::message_parts
virtual size_t message_parts() const
Definition: pk_ops.h:56
Botan::PK_Ops::Signature::sign
virtual SecureVector< byte > sign(const byte msg[], size_t msg_len, RandomNumberGenerator &rng)=0
Botan::PK_Ops::Signature::max_input_bits
virtual size_t max_input_bits() const =0
Botan::EMSA::encoding_of
virtual SecureVector< byte > encoding_of(const MemoryRegion< byte > &msg, size_t output_bits, RandomNumberGenerator &rng)=0
BOTAN_ASSERT
#define BOTAN_ASSERT(expr, msg)
Definition: assert.h:19
Botan::EMSA::raw_data
virtual SecureVector< byte > raw_data()=0
Botan::SEQUENCE
Definition: asn1_int.h:35
Botan::IEEE_1363
Definition: pubkey.h:24
Botan::DER_SEQUENCE
Definition: pubkey.h:24
Botan::to_string
std::string to_string(u64bit n, size_t min_len)
Definition: parsing.cpp:42

## ◆ update() [1/3]

void Botan::PK_Signer::update | ( | byte | in | ) |
| inline

Add a message part (single byte).

Parameters

  in | the byte to add

Definition at line 150 of file pubkey.h.

References update().

Referenced by Botan::CMS_Encoder::sign(), and update().

150 { update(&in, 1); }
Botan::PK_Signer::update
void update(byte in)
Definition: pubkey.h:150

## ◆ update() [2/3]

void Botan::PK_Signer::update | ( | const byte | in[],
|  | size_t | length
| ) |  |

Add a message part.

Parameters

  in | the message part to add as a byte array
  length | the length of the above byte array

Definition at line 170 of file pubkey.cpp.

References Botan::same_mem(), and Botan::MemoryRegion< T >::size().

171 {
172 emsa->update(in, length);
173 }
Botan::EMSA::update
virtual void update(const byte input[], size_t length)=0

## ◆ update() [3/3]

void Botan::PK_Signer::update | ( | const MemoryRegion< byte > & | in | ) |
| inline

Add a message part.

Parameters

  in | the message part to add

Definition at line 163 of file pubkey.h.

References Botan::MemoryRegion< T >::size(), and update().

Referenced by update().

163 { update(&in[0], in.size()); }
Botan::MemoryRegion::size
size_t size() const
Definition: secmem.h:29
Botan::PK_Signer::update
void update(byte in)
Definition: pubkey.h:150

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

- src/pubkey/pubkey.h
- src/pubkey/pubkey.cpp