1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-18 20:38:10 +00:00

tests: fix curve25519 unittests (#78)

This commit is contained in:
Roman Zeyde 2016-10-24 22:35:30 +03:00 committed by Pavol Rusnak
parent fa8772dfee
commit 5ecb8574cc

View File

@ -409,9 +409,9 @@ def test_curve25519(r):
pub2 = curve25519.Private(sec2).get_public()
session1 = r.randbytes(32)
lib.curve25519_scalarmult(session1, sec2, pub1.public)
lib.curve25519_donna(session1, sec2, pub1.public)
session2 = r.randbytes(32)
lib.curve25519_scalarmult(session2, sec1, pub2.public)
lib.curve25519_donna(session2, sec1, pub2.public)
assert bytearray(session1) == bytearray(session2)
shared1 = curve25519.Private(sec2).get_shared_key(pub1, hashfunc=lambda x: x)
@ -425,7 +425,7 @@ def test_curve25519_pubkey(r):
sec = bytes(bytearray(r.randbytes(32)))
pub = curve25519.Private(sec).get_public()
res = r.randbytes(32)
lib.curve25519_publickey(res, sec)
lib.curve25519_donna_basepoint(res, sec)
assert bytearray(res) == pub.public
@ -433,6 +433,6 @@ def test_curve25519_scalarmult_from_gpg(r):
sec = binascii.unhexlify('4a1e76f133afb29dbc7860bcbc16d0e829009cc15c2f81ed26de1179b1d9c938')
pub = binascii.unhexlify('5d6fc75c016e85b17f54e0128a216d5f9229f25bac1ec85cecab8daf48621b31')
res = r.randbytes(32)
lib.curve25519_scalarmult(res, sec[::-1], pub[::-1])
lib.curve25519_donna(res, sec[::-1], pub[::-1])
expected = 'a93dbdb23e5c99da743e203bd391af79f2b83fb8d0fd6ec813371c71f08f2d4d'
assert binascii.hexlify(bytearray(res)) == expected