Botan  1.11.11
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, const std::string &hash)
 
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,
const std::string &  hash 
)

Definition at line 28 of file ecdsa.cpp.

28  :
29  base_point(ecdsa.domain().get_base_point()),
30  order(ecdsa.domain().get_order()),
31  x(ecdsa.private_value()),
32  mod_order(order),
34  {
35  }
std::string hash_for_deterministic_signature(const std::string &emsa)
Definition: rfc6979.cpp:15

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 106 of file ecdsa.h.

106 { 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 105 of file ecdsa.h.

105 { 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 104 of file ecdsa.h.

104 { 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 38 of file ecdsa.cpp.

References Botan::BigInt::binary_encode(), BOTAN_ASSERT, Botan::BigInt::bytes(), Botan::generate_rfc6979_nonce(), Botan::PointGFp::get_affine_x(), Botan::inverse_mod(), Botan::mul_add(), Botan::Modular_Reducer::multiply(), and Botan::Modular_Reducer::reduce().

40  {
41  const BigInt m(msg, msg_len);
42 
43  const BigInt k = generate_rfc6979_nonce(x, order, m, m_hash);
44 
45  const PointGFp k_times_P = base_point * k;
46  const BigInt r = mod_order.reduce(k_times_P.get_affine_x());
47  const BigInt s = mod_order.multiply(inverse_mod(k, order), mul_add(x, r, m));
48 
49  // With overwhelming probability, a bug rather than actual zero r/s
50  BOTAN_ASSERT(s != 0, "invalid s");
51  BOTAN_ASSERT(r != 0, "invalid r");
52 
53  secure_vector<byte> output(2*order.bytes());
54  r.binary_encode(&output[output.size() / 2 - r.bytes()]);
55  s.binary_encode(&output[output.size() - s.bytes()]);
56  return output;
57  }
#define BOTAN_ASSERT(expr, assertion_made)
Definition: assert.h:27
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:128
BigInt generate_rfc6979_nonce(const BigInt &x, const BigInt &q, const BigInt &h, const std::string &hash)
Definition: rfc6979.cpp:29
BigInt mul_add(const BigInt &a, const BigInt &b, const BigInt &c)
Definition: mp_numth.cpp:34
size_t bytes() const
Definition: bigint.cpp:225

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