aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2021-05-29 10:30:45 -0400
committerJack Lloyd <[email protected]>2021-05-29 10:30:45 -0400
commit3ef7800be909e088fc6eadd2922b31b1f91681c0 (patch)
tree51554714361fb5fb712fdb1aa0f5b0cf43cd525c /src
parent64f0382af0c38aa346ddb6905b4ba0bc805cf1d6 (diff)
Skip negative test in ECDSA
Since it cannot occur because we decoded from binary within the same function.
Diffstat (limited to 'src')
-rw-r--r--src/lib/pubkey/ecdsa/ecdsa.cpp6
-rw-r--r--src/tests/data/pubkey/ecdsa_verify.vec15
2 files changed, 20 insertions, 1 deletions
diff --git a/src/lib/pubkey/ecdsa/ecdsa.cpp b/src/lib/pubkey/ecdsa/ecdsa.cpp
index 2324edf85..2c81fa3ad 100644
--- a/src/lib/pubkey/ecdsa/ecdsa.cpp
+++ b/src/lib/pubkey/ecdsa/ecdsa.cpp
@@ -246,7 +246,11 @@ bool ECDSA_Verification_Operation::verify(const uint8_t msg[], size_t msg_len,
const BigInt r(sig, sig_len / 2);
const BigInt s(sig + sig_len / 2, sig_len / 2);
- if(r <= 0 || r >= m_group.get_order() || s <= 0 || s >= m_group.get_order())
+ // Cannot be negative here since we just decoded from binary
+ if(r.is_zero() || s.is_zero())
+ return false;
+
+ if(r >= m_group.get_order() || s >= m_group.get_order())
return false;
const BigInt w = m_group.inverse_mod_order(s);
diff --git a/src/tests/data/pubkey/ecdsa_verify.vec b/src/tests/data/pubkey/ecdsa_verify.vec
index cfac37905..601f19b1c 100644
--- a/src/tests/data/pubkey/ecdsa_verify.vec
+++ b/src/tests/data/pubkey/ecdsa_verify.vec
@@ -84,3 +84,18 @@ Px = 900997227115460875824822229028414748877714455850240840704202592780965501337
Py = 75076071959494495025084278994604071909377393876145154132462189193441939020537
Msg = 1FCB9D44AEC25877D4A5BDD5A96480D46F04BAED89313CC7B75ACE293AF2DA73
Signature = 63efe6cc6b825e3d1ca849eb6091369721ab19fafa21a4c57563e897184ea96bce99e8e4cc651fb0e8eecf13300f094706fe2a7b59abdb6c95be8518adc553d9
+
+
+Group = secp256k1
+Valid = 0
+Px = 90099722711546087582482222902841474887771445585024084070420259278096550133708
+Py = 75076071959494495025084278994604071909377393876145154132462189193441939020537
+Msg = 1FCB9D44AEC25877D4A5BDD5A96480D46F04BAED89313CC7B75ACE293AF2DA73
+Signature = 63efe6cc6b825e3d1ca849eb6091369721ab19fafa21a4c57563e897184ea96b0000000000000000000000000000000000000000000000000000000000000000
+
+Group = secp256k1
+Valid = 0
+Px = 90099722711546087582482222902841474887771445585024084070420259278096550133708
+Py = 75076071959494495025084278994604071909377393876145154132462189193441939020537
+Msg = 1FCB9D44AEC25877D4A5BDD5A96480D46F04BAED89313CC7B75ACE293AF2DA73
+Signature = 000000000000000000000000000000000000000000000000000000000000000063efe6cc6b825e3d1ca849eb6091369721ab19fafa21a4c57563e897184ea96b