aboutsummaryrefslogtreecommitdiffstats
path: root/src/pubkey/gost_3410
diff options
context:
space:
mode:
authorlloyd <[email protected]>2010-03-05 16:10:55 +0000
committerlloyd <[email protected]>2010-03-05 16:10:55 +0000
commitdf56028cad58fad04b9866326cb62700af8f2fbe (patch)
treedcaa1a80c9f20db7b7993ac54b1aaafd488354c0 /src/pubkey/gost_3410
parent93873731f73e905d8714556f1ebe23acb32de0e1 (diff)
Add verification ops for all signature key types
Diffstat (limited to 'src/pubkey/gost_3410')
-rw-r--r--src/pubkey/gost_3410/gost_3410.cpp42
-rw-r--r--src/pubkey/gost_3410/gost_3410.h23
2 files changed, 62 insertions, 3 deletions
diff --git a/src/pubkey/gost_3410/gost_3410.cpp b/src/pubkey/gost_3410/gost_3410.cpp
index c3735c720..1c028eca3 100644
--- a/src/pubkey/gost_3410/gost_3410.cpp
+++ b/src/pubkey/gost_3410/gost_3410.cpp
@@ -110,9 +110,10 @@ GOST_3410_Signature_Operation::GOST_3410_Signature_Operation(
{
}
-SecureVector<byte> GOST_3410_Signature_Operation::sign(const byte msg[],
- u32bit msg_len,
- RandomNumberGenerator& rng)
+SecureVector<byte>
+GOST_3410_Signature_Operation::sign(const byte msg[],
+ u32bit msg_len,
+ RandomNumberGenerator& rng)
{
BigInt k;
do
@@ -142,4 +143,39 @@ SecureVector<byte> GOST_3410_Signature_Operation::sign(const byte msg[],
}
+GOST_3410_Verification_Operation::GOST_3410_Verification_Operation(const GOST_3410_PublicKey& gost) :
+ base_point(gost.domain().get_base_point()),
+ public_point(gost.public_point()),
+ order(gost.domain().get_order())
+ {
+ }
+
+bool GOST_3410_Verification_Operation::verify(const byte msg[], u32bit msg_len,
+ const byte sig[], u32bit sig_len)
+ {
+ if(sig_len != order.bytes()*2)
+ return false;
+
+ BigInt e(msg, msg_len);
+
+ BigInt r(sig, sig_len / 2);
+ BigInt s(sig + sig_len / 2, sig_len / 2);
+
+ if(r < 0 || r >= order || s < 0 || s >= order)
+ return false;
+
+ e %= order;
+ if(e == 0)
+ e = 1;
+
+ BigInt v = inverse_mod(e, order);
+
+ BigInt z1 = (s*v) % order;
+ BigInt z2 = (-r*v) % order;
+
+ PointGFp R = (z1 * base_point + z2 * public_point);
+
+ return (R.get_affine_x() == r);
+ }
+
}
diff --git a/src/pubkey/gost_3410/gost_3410.h b/src/pubkey/gost_3410/gost_3410.h
index 12abd6354..3def2cfb9 100644
--- a/src/pubkey/gost_3410/gost_3410.h
+++ b/src/pubkey/gost_3410/gost_3410.h
@@ -113,6 +113,10 @@ class BOTAN_DLL GOST_3410_Signature_Operation : public PK_Ops::Signature_Operati
public:
GOST_3410_Signature_Operation(const GOST_3410_PrivateKey& gost_3410);
+ u32bit message_parts() const { return 2; }
+ u32bit message_part_size() const { return order.bytes(); }
+ u32bit max_input_bits() const { return order.bits(); }
+
SecureVector<byte> sign(const byte msg[], u32bit msg_len,
RandomNumberGenerator& rng);
@@ -122,6 +126,25 @@ class BOTAN_DLL GOST_3410_Signature_Operation : public PK_Ops::Signature_Operati
const BigInt& x;
};
+class BOTAN_DLL GOST_3410_Verification_Operation : public PK_Ops::Verification
+ {
+ public:
+ GOST_3410_Verification_Operation(const GOST_3410_PublicKey& gost);
+
+ u32bit message_parts() const { return 2; }
+ u32bit message_part_size() const { return order.bytes(); }
+ u32bit max_input_bits() const { return order.bits(); }
+
+ bool with_recovery() const { return false; }
+
+ bool verify(const byte msg[], u32bit msg_len,
+ const byte sig[], u32bit sig_len);
+ private:
+ const PointGFp& base_point;
+ const PointGFp& public_point;
+ const BigInt& order;
+ };
+
}
#endif