diff options
author | lloyd <[email protected]> | 2010-03-05 01:09:28 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-03-05 01:09:28 +0000 |
commit | 1c7dbb21d19702872379421e6ae44a15caf67da2 (patch) | |
tree | bd4ee9e01f8cfd9631655d0e0b0991d49c0a7e8e /src/pubkey/gost_3410 | |
parent | 78b5b103291ee668185dc71d138a50e8e7e54808 (diff) |
Add signature generation operation classes. Remove sign() from
PK_Signing_Key, though for the moment the class remains because there
are a few pieces of code that use it to detect if signatures are
supported, or for passing to functions in look_pk
Diffstat (limited to 'src/pubkey/gost_3410')
-rw-r--r-- | src/pubkey/gost_3410/gost_3410.cpp | 41 | ||||
-rw-r--r-- | src/pubkey/gost_3410/gost_3410.h | 17 |
2 files changed, 57 insertions, 1 deletions
diff --git a/src/pubkey/gost_3410/gost_3410.cpp b/src/pubkey/gost_3410/gost_3410.cpp index 25e975784..ef0bac726 100644 --- a/src/pubkey/gost_3410/gost_3410.cpp +++ b/src/pubkey/gost_3410/gost_3410.cpp @@ -141,4 +141,45 @@ GOST_3410_PrivateKey::sign(const byte msg[], return output; } +GOST_3410_Signature_Operation::GOST_3410_Signature_Operation( + const GOST_3410_PrivateKey& gost_3410) : + + base_point(gost_3410.domain().get_base_point()), + order(gost_3410.domain().get_order()), + x(gost_3410.private_value()) + { + } + +SecureVector<byte> GOST_3410_Signature_Operation::sign(const byte msg[], + u32bit msg_len, + RandomNumberGenerator& rng) + { + BigInt k; + do + k.randomize(rng, order.bits()-1); + while(k >= order); + + BigInt e(msg, msg_len); + + e %= order; + if(e == 0) + e = 1; + + PointGFp k_times_P = base_point * k; + k_times_P.check_invariants(); + + BigInt r = k_times_P.get_affine_x() % order; + + BigInt s = (r*x + k*e) % order; + + if(r == 0 || s == 0) + throw Invalid_State("GOST 34.10: r == 0 || s == 0"); + + SecureVector<byte> output(2*order.bytes()); + r.binary_encode(output + (output.size() / 2 - r.bytes())); + s.binary_encode(output + (output.size() - s.bytes())); + return output; + } + + } diff --git a/src/pubkey/gost_3410/gost_3410.h b/src/pubkey/gost_3410/gost_3410.h index 669ed130f..1bf55aa21 100644 --- a/src/pubkey/gost_3410/gost_3410.h +++ b/src/pubkey/gost_3410/gost_3410.h @@ -2,7 +2,7 @@ * GOST 34.10-2001 * (C) 2007 Falko Strenzke, FlexSecure GmbH * Manuel Hartl, FlexSecure GmbH -* (C) 2008-2009 Jack Lloyd +* (C) 2008-2010 Jack Lloyd * * Distributed under the terms of the Botan license */ @@ -11,6 +11,7 @@ #define BOTAN_GOST_3410_KEY_H__ #include <botan/ecc_key.h> +#include <botan/pk_ops.h> namespace Botan { @@ -116,6 +117,20 @@ class BOTAN_DLL GOST_3410_PrivateKey : public GOST_3410_PublicKey, RandomNumberGenerator& rng) const; }; +class BOTAN_DLL GOST_3410_Signature_Operation : public PK_Ops::Signature_Operation + { + public: + GOST_3410_Signature_Operation(const GOST_3410_PrivateKey& gost_3410); + + SecureVector<byte> sign(const byte msg[], u32bit msg_len, + RandomNumberGenerator& rng); + + private: + const PointGFp& base_point; + const BigInt& order; + const BigInt& x; + }; + } #endif |