<s> import binascii <EOL> import codecs <EOL> import os <EOL> import pytest <EOL> import ed25519 <EOL> def ed25519_known_answers ( ) : <EOL> path = os . path . join ( os . path . dirname ( __file__ ) , "<STR_LIT>" , "<STR_LIT>" ) <EOL> with codecs . open ( path , "<STR_LIT:r>" , encoding = "<STR_LIT:utf-8>" ) as fp : <EOL> for line in fp : <EOL> x = line . split ( "<STR_LIT::>" ) <EOL> yield ( <EOL> x [ <NUM_LIT:0> ] [ <NUM_LIT:0> : <NUM_LIT:64> ] . encode ( "<STR_LIT:ascii>" ) , <EOL> x [ <NUM_LIT:1> ] . encode ( "<STR_LIT:ascii>" ) , <EOL> x [ <NUM_LIT:2> ] . encode ( "<STR_LIT:ascii>" ) , <EOL> x [ <NUM_LIT:3> ] . encode ( "<STR_LIT:ascii>" ) , <EOL> binascii . hexlify ( <EOL> binascii . unhexlify ( x [ <NUM_LIT:3> ] . encode ( "<STR_LIT:ascii>" ) ) [ : <NUM_LIT:64> ] <EOL> ) , <EOL> ) <EOL> @ pytest . mark . parametrize ( <EOL> ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:message>" , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ed25519_known_answers ( ) , <EOL> ) <EOL> def test_ed25519_kat ( secret_key , public_key , message , signed , signature ) : <EOL> sk = binascii . unhexlify ( secret_key ) <EOL> m = binascii . unhexlify ( message ) <EOL> pk = ed25519 . publickey_unsafe ( sk ) <EOL> sig = ed25519 . signature_unsafe ( m , sk , pk ) <EOL> assert binascii . hexlify ( pk ) == public_key <EOL> assert binascii . hexlify ( sig ) == signature <EOL> ed25519 . checkvalid ( sig , m , pk ) <EOL> try : <EOL> if len ( m ) == <NUM_LIT:0> : <EOL> forgedm = b"<STR_LIT:x>" <EOL> else : <EOL> forgedm = ed25519 . intlist2bytes ( [ <EOL> ed25519 . indexbytes ( m , i ) + ( i == len ( m ) - <NUM_LIT:1> ) <EOL> for i in range ( len ( m ) ) <EOL> ] ) <EOL> except ValueError : <EOL> pass <EOL> else : <EOL> with pytest . raises ( ed25519 . SignatureMismatch ) : <EOL> ed25519 . checkvalid ( sig , forgedm , pk ) <EOL> def test_checkparams ( ) : <EOL> assert ed25519 . b >= <NUM_LIT:10> <EOL> assert <NUM_LIT:8> * len ( ed25519 . H ( b"<STR_LIT>" ) ) == <NUM_LIT:2> * ed25519 . b <EOL> assert pow ( <NUM_LIT:2> , ed25519 . q - <NUM_LIT:1> , ed25519 . q ) == <NUM_LIT:1> <EOL> assert ed25519 . q % <NUM_LIT:4> == <NUM_LIT:1> <EOL> assert pow ( <NUM_LIT:2> , ed25519 . l - <NUM_LIT:1> , ed25519 . l ) == <NUM_LIT:1> <EOL> assert ed25519 . l >= <NUM_LIT:2> ** ( ed25519 . b - <NUM_LIT:4> ) <EOL> assert ed25519 . l <= <NUM_LIT:2> ** ( ed25519 . b - <NUM_LIT:3> ) <EOL> assert pow ( ed25519 . d , ( ed25519 . q - <NUM_LIT:1> ) // <NUM_LIT:2> , ed25519 . q ) == ed25519 . q - <NUM_LIT:1> <EOL> assert pow ( ed25519 . I , <NUM_LIT:2> , ed25519 . q ) == ed25519 . q - <NUM_LIT:1> <EOL> assert ed25519 . isoncurve ( ed25519 . B ) <EOL> x , y , z , t = P = ed25519 . scalarmult ( ed25519 . B , ed25519 . l ) <EOL> assert ed25519 . isoncurve ( P ) <EOL> assert ( x , y ) == ( <NUM_LIT:0> , z ) </s>
