mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-27 08:38:07 +00:00
modtrezorcrypto: add test_sign_verify_random to curve unit tests
This commit is contained in:
parent
9c921c073f
commit
7404a76aeb
@ -43,7 +43,7 @@ class TestCryptoEd25519(unittest.TestCase):
|
||||
self.assertTrue(len(sk) == 32)
|
||||
self.assertTrue(sk[0] & 7 == 0 and sk[31] & 128 == 0 and sk[31] & 64 == 64)
|
||||
|
||||
def test_random(self):
|
||||
def test_sign_verify_random(self):
|
||||
for l in range(1, 300):
|
||||
sk = ed25519.generate_secret()
|
||||
pk = ed25519.publickey(sk)
|
||||
|
@ -5,6 +5,7 @@ import unittest
|
||||
from ubinascii import hexlify, unhexlify
|
||||
|
||||
from trezor.crypto.curve import nist256p1
|
||||
from trezor.crypto import random
|
||||
|
||||
class TestCryptoNist256p1(unittest.TestCase):
|
||||
|
||||
@ -85,5 +86,13 @@ class TestCryptoNist256p1(unittest.TestCase):
|
||||
else:
|
||||
self.assertEqual(pk33, '03' + pk[:64])
|
||||
|
||||
def test_sign_verify_random(self):
|
||||
for l in range(1, 300):
|
||||
sk = nist256p1.generate_secret()
|
||||
pk = nist256p1.publickey(sk)
|
||||
msg = random.bytes(l)
|
||||
sig = nist256p1.sign(sk, msg)
|
||||
self.assertTrue(nist256p1.verify(pk, sig, msg))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
@ -5,6 +5,7 @@ import unittest
|
||||
from ubinascii import hexlify, unhexlify
|
||||
|
||||
from trezor.crypto.curve import secp256k1
|
||||
from trezor.crypto import random
|
||||
|
||||
class TestCryptoSecp256k1(unittest.TestCase):
|
||||
|
||||
@ -78,5 +79,13 @@ class TestCryptoSecp256k1(unittest.TestCase):
|
||||
else:
|
||||
self.assertEqual(pk33, '03' + pk[:64])
|
||||
|
||||
def test_sign_verify_random(self):
|
||||
for l in range(1, 300):
|
||||
sk = secp256k1.generate_secret()
|
||||
pk = secp256k1.publickey(sk)
|
||||
msg = random.bytes(l)
|
||||
sig = secp256k1.sign(sk, msg)
|
||||
self.assertTrue(secp256k1.verify(pk, sig, msg))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
Reference in New Issue
Block a user