Skip to content

Commit 7ae9df7

Browse files
sipajl2012
authored andcommitted
Make test framework produce lowS signatures
1 parent e3d2f85 commit 7ae9df7

File tree

1 file changed

+10
-2
lines changed
  • qa/rpc-tests/test_framework

1 file changed

+10
-2
lines changed

qa/rpc-tests/test_framework/key.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,16 @@ def sign(self, hash):
157157
sig_size0 = ctypes.c_uint32()
158158
sig_size0.value = ssl.ECDSA_size(self.k)
159159
mb_sig = ctypes.create_string_buffer(sig_size0.value)
160-
result = ssl.ECDSA_sign(0, hash, len(hash), mb_sig, ctypes.byref(sig_size0), self.k)
161-
assert 1 == result
160+
ok = False
161+
while not ok:
162+
result = ssl.ECDSA_sign(0, hash, len(hash), mb_sig, ctypes.byref(sig_size0), self.k)
163+
assert 1 == result
164+
assert mb_sig.raw[0] == 0x30
165+
assert mb_sig.raw[1] == sig_size0.value - 2
166+
assert mb_sig.raw[2] == 2
167+
assert mb_sig.raw[4 + mb_sig.raw[3]] == 2
168+
# Hacky test for lowS DER signature
169+
ok = (mb_sig.raw[5 + mb_sig.raw[3]] < 33) and (mb_sig.raw[6 + mb_sig.raw[3]] <= 0xFE)
162170
return mb_sig.raw[:sig_size0.value]
163171

164172
def verify(self, hash, sig):

0 commit comments

Comments
 (0)