aboutsummaryrefslogtreecommitdiffstats
path: root/src/pubkey/ecdsa/ecdsa.cpp
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/ecdsa/ecdsa.cpp
parent93873731f73e905d8714556f1ebe23acb32de0e1 (diff)
Add verification ops for all signature key types
Diffstat (limited to 'src/pubkey/ecdsa/ecdsa.cpp')
-rw-r--r--src/pubkey/ecdsa/ecdsa.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/pubkey/ecdsa/ecdsa.cpp b/src/pubkey/ecdsa/ecdsa.cpp
index ba8c20571..143389751 100644
--- a/src/pubkey/ecdsa/ecdsa.cpp
+++ b/src/pubkey/ecdsa/ecdsa.cpp
@@ -78,4 +78,34 @@ SecureVector<byte> ECDSA_Signature_Operation::sign(const byte msg[],
return output;
}
+ECDSA_Verification_Operation::ECDSA_Verification_Operation(const ECDSA_PublicKey& ecdsa) :
+ base_point(ecdsa.domain().get_base_point()),
+ public_point(ecdsa.public_point()),
+ order(ecdsa.domain().get_order())
+ {
+ }
+
+bool ECDSA_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;
+
+ BigInt w = inverse_mod(s, order);
+
+ PointGFp R = w * (e * base_point + r * public_point);
+ if(R.is_zero())
+ return false;
+
+ return (R.get_affine_x() % order == r);
+ }
+
}