10 #include <botan/gost_3410.h>
11 #include <botan/der_enc.h>
12 #include <botan/ber_dec.h>
13 #include <botan/internal/assert.h>
23 size_t part_size = std::max(x.
bytes(), y.
bytes());
31 for(
size_t i = 0; i != part_size / 2; ++i)
34 std::swap(bits[part_size+i], bits[2*part_size-1-i]);
64 const size_t part_size = bits.
size() / 2;
67 for(
size_t i = 0; i != part_size / 2; ++i)
70 std::swap(bits[part_size+i], bits[2*part_size-1-i]);
73 BigInt x(&bits[0], part_size);
74 BigInt y(&bits[part_size], part_size);
79 "Loaded GOST 34.10 public key not on the curve");
84 BigInt decode_le(
const byte msg[],
size_t msg_len)
88 for(
size_t i = 0; i != msg_le.size() / 2; ++i)
89 std::swap(msg_le[i], msg_le[msg_le.size()-1-i]);
91 return BigInt(&msg_le[0], msg_le.size());
99 base_point(gost_3410.domain().get_base_point()),
100 order(gost_3410.domain().get_order()),
101 x(gost_3410.private_value())
114 BigInt e = decode_le(msg, msg_len);
120 PointGFp k_times_P = base_point * k;
123 "GOST 34.10 k*g not on the curve");
127 BigInt s = (r*x + k*e) % order;
134 r.binary_encode(&output[output.size() - r.bytes()]);
139 base_point(gost.domain().get_base_point()),
140 public_point(gost.public_point()),
141 order(gost.domain().get_order())
146 const byte sig[],
size_t sig_len)
148 if(sig_len != order.
bytes()*2)
151 BigInt e = decode_le(msg, msg_len);
154 BigInt r(sig + sig_len / 2, sig_len / 2);
156 if(r <= 0 || r >= order || s <= 0 || s >= order)
165 BigInt z1 = (s*v) % order;
166 BigInt z2 = (-r*v) % order;
void binary_encode(byte buf[]) const
SecureVector< byte > get_contents()
BigInt get_affine_y() const
const EC_Group & domain() const
BER_Decoder & decode(bool &)
SecureVector< byte > sign(const byte msg[], size_t msg_len, RandomNumberGenerator &rng)
GOST_3410_Verification_Operation(const GOST_3410_PublicKey &gost)
AlgorithmIdentifier algorithm_identifier() const
SecureVector< byte > parameters
BER_Decoder start_cons(ASN1_Tag, ASN1_Tag=UNIVERSAL)
#define BOTAN_ASSERT(expr, msg)
virtual OID get_oid() const
const PointGFp & public_point() const
BigInt get_affine_x() const
DER_Encoder & encode(bool b)
RandomNumberGenerator * rng
void randomize(RandomNumberGenerator &rng, size_t bitsize=0)
MemoryVector< byte > x509_subject_public_key() const
bool verify(const byte msg[], size_t msg_len, const byte sig[], size_t sig_len)
BigInt inverse_mod(const BigInt &n, const BigInt &mod)
bool on_the_curve() const
DER_Encoder & start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag=UNIVERSAL)
void swap(Botan::MemoryRegion< T > &x, Botan::MemoryRegion< T > &y)
GOST_3410_Signature_Operation(const GOST_3410_PrivateKey &gost_3410)
PointGFp multi_exponentiate(const PointGFp &p1, const BigInt &z1, const PointGFp &p2, const BigInt &z2)