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

#include <ecdsa.h>

Inheritance diagram for Botan::ECDSA_Signature_Operation:
Botan::PK_Ops::Signature

Public Member Functions

 ECDSA_Signature_Operation (const ECDSA_PrivateKey &ecdsa)
 
size_t max_input_bits () const
 
size_t message_part_size () const
 
size_t message_parts () const
 
secure_vector< bytesign (const byte msg[], size_t msg_len, RandomNumberGenerator &rng)
 

Detailed Description

ECDSA signature operation

Definition at line 95 of file ecdsa.h.

Constructor & Destructor Documentation

Botan::ECDSA_Signature_Operation::ECDSA_Signature_Operation ( const ECDSA_PrivateKey ecdsa)

Definition at line 27 of file ecdsa.cpp.

27  :
28  base_point(ecdsa.domain().get_base_point()),
29  order(ecdsa.domain().get_order()),
30  x(ecdsa.private_value()),
31  mod_order(order)
32  {
33  }

Member Function Documentation

size_t Botan::ECDSA_Signature_Operation::max_input_bits ( ) const
inlinevirtual

Get the maximum message size in bits supported by this public key.

Returns
maximum message in bits

Implements Botan::PK_Ops::Signature.

Definition at line 105 of file ecdsa.h.

105 { return order.bits(); }
size_t bits() const
Definition: bigint.cpp:233
size_t Botan::ECDSA_Signature_Operation::message_part_size ( ) const
inlinevirtual

Find out the message part size supported by this scheme/key.

Returns
size of the message parts

Reimplemented from Botan::PK_Ops::Signature.

Definition at line 104 of file ecdsa.h.

104 { return order.bytes(); }
size_t bytes() const
Definition: bigint.cpp:225
size_t Botan::ECDSA_Signature_Operation::message_parts ( ) const
inlinevirtual

Find out the number of message parts supported by this scheme.

Returns
number of message parts

Reimplemented from Botan::PK_Ops::Signature.

Definition at line 103 of file ecdsa.h.

103 { return 2; }
secure_vector< byte > Botan::ECDSA_Signature_Operation::sign ( const byte  msg[],
size_t  msg_len,
RandomNumberGenerator rng 
)
virtual

Implements Botan::PK_Ops::Signature.

Definition at line 36 of file ecdsa.cpp.

References Botan::RandomNumberGenerator::add_entropy(), Botan::BigInt::binary_encode(), Botan::BigInt::bits(), Botan::BigInt::bytes(), Botan::PointGFp::get_affine_x(), Botan::inverse_mod(), Botan::mul_add(), Botan::Modular_Reducer::multiply(), r, Botan::BigInt::randomize(), Botan::Modular_Reducer::reduce(), and s.

38  {
39  rng.add_entropy(msg, msg_len);
40 
41  BigInt m(msg, msg_len);
42 
43  BigInt r = 0, s = 0;
44 
45  while(r == 0 || s == 0)
46  {
47  // This contortion is necessary for the tests
48  BigInt k;
49  k.randomize(rng, order.bits());
50 
51  while(k >= order)
52  k.randomize(rng, order.bits() - 1);
53 
54  PointGFp k_times_P = base_point * k;
55  r = mod_order.reduce(k_times_P.get_affine_x());
56  s = mod_order.multiply(inverse_mod(k, order), mul_add(x, r, m));
57  }
58 
59  secure_vector<byte> output(2*order.bytes());
60  r.binary_encode(&output[output.size() / 2 - r.bytes()]);
61  s.binary_encode(&output[output.size() - s.bytes()]);
62  return output;
63  }
void binary_encode(byte buf[]) const
Definition: bigint.cpp:318
size_t bits() const
Definition: bigint.cpp:233
BigInt multiply(const BigInt &x, const BigInt &y) const
Definition: reducer.h:31
BigInt reduce(const BigInt &x) const
Definition: reducer.cpp:32
BigInt inverse_mod(const BigInt &n, const BigInt &mod)
Definition: numthry.cpp:250
BigInt r
Definition: numthry.cpp:27
BigInt mul_add(const BigInt &a, const BigInt &b, const BigInt &c)
Definition: mp_numth.cpp:34
size_t s
Definition: numthry.cpp:28
size_t bytes() const
Definition: bigint.cpp:225

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