@@ -2,7 +2,6 @@ package ed521
22
33import (
44 "fmt"
5- "bytes"
65 "testing"
76 "crypto"
87 "crypto/rand"
@@ -71,6 +70,16 @@ func Test_NewPrivateKey(t *testing.T) {
7170
7271 // ======
7372
73+ privBytes2 := priv .Bytes ()
74+ priv22 , err := NewKeyFromBytes (privBytes2 )
75+ if err != nil {
76+ t .Fatal (err )
77+ }
78+
79+ cryptobin_test .Equal (t , priv22 , priv , "NewKeyFromBytes Equal error" )
80+
81+ // ======
82+
7483 pub := & priv .PublicKey
7584
7685 pubBytes := PublicKeyTo (pub )
@@ -338,86 +347,6 @@ func Test_Random_Private_Keys(t *testing.T) {
338347
339348}
340349
341- func Test_Vec_Check (t * testing.T ) {
342- for i , td := range testSigVec {
343- t .Run (fmt .Sprintf ("index %d" , i ), func (t * testing.T ) {
344- curve := ed521 .ED521 ()
345-
346- if len (td .secretKey ) > 0 {
347- priv , err := NewPrivateKey (td .secretKey )
348- if err != nil {
349- t .Fatal (err )
350- }
351-
352- pub := & priv .PublicKey
353-
354- pubBytes := ed521 .MarshalCompressed (pub .Curve , pub .X , pub .Y )
355-
356- // check publicKey
357- if ! bytes .Equal (pubBytes , td .publicKey ) {
358- t .Errorf ("PublicKey got: %x, want: %x" , pubBytes , td .publicKey )
359- }
360-
361- // check sig
362- sig , err := priv .Sign (rand .Reader , td .message , nil )
363- if err != nil {
364- t .Error ("encode sig fail" )
365- }
366-
367- if bytes .Equal (sig , td .signature ) != td .verification {
368- t .Errorf ("sig fail, got: %x, want: %x" , sig , td .signature )
369- }
370-
371- }
372-
373- x , y := ed521 .UnmarshalCompressed (curve , td .publicKey )
374- if x == nil || y == nil {
375- t .Fatal ("publicKey error" )
376- }
377-
378- pubkey := & PublicKey {
379- Curve : curve ,
380- X : x ,
381- Y : y ,
382- }
383-
384- veri := pubkey .Verify (td .message , td .signature )
385- if veri != td .verification {
386- t .Error ("Verify fail" )
387- }
388-
389- })
390- }
391-
392- }
393-
394- type testVec struct {
395- secretKey []byte
396- publicKey []byte
397- message []byte
398- signature []byte
399- verification bool
400- }
401-
402- var testSigVec = []testVec {
403- {
404- secretKey : fromHex ("22713dc2f3d8a4611e9266d8a2a9e3d237505dc34c65d87d598b9a4e6c41b35e3d090458e66c8213a4af011e5614377960c99d9f84e379fdd1f1e168b163b5d93012" ),
405- publicKey : fromHex ("020006be6a2ea17441c94e25799154b049ebae2fedcedfb27355ab03f9eb802d239677c340392fe113ffb18138b95dc8ba3efd766401cabfc4cc30d0ccdce7b178d954" ),
406- message : fromHex ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" ),
407- signature : fromHex ("e6309d7d752de236179d694954f9345a73b1abcbe7ebde16e5e0fa1a4ed60003839a13f03fe1fccfecdac66614b8aff731e7956678be247b8f19795b20351a578301780dd7e6d41db086ef9bdc4658cbcc3d86d259b7e36ea399b075da86f2559489c64f59d196c5a439b3c5442609912dee28721d82dd08c71884b7f406961510110e00" ),
408- verification : true ,
409- },
410-
411- // fail
412- {
413- secretKey : fromHex ("22713dc2f3d8a4611e9266d8a2a9e3d237505dc34c65d87d598b9a4e6c41b35e3d090458e66c8213a4af011e5614377960c99d9f84e379fdd1f1e168b163b5d93012" ),
414- publicKey : fromHex ("020006be6a2ea17441c94e25799154b049ebae2fedcedfb27355ab03f9eb802d239677c340392fe113ffb18138b95dc8ba3efd766401cabfc4cc30d0ccdce7b178d954" ),
415- message : fromHex ("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" ),
416- signature : fromHex ("3bd0454bd7a48f25fa40e0ebd76c1eb48e7fff63f606f35f9a8de9fc6d8fde0f75c10c0d97b7dc3001c5da6da681ff95d1a6ace65c19134ca727b99b1c349752ee01e8c9d1f325ab430511bcbf1e009d37418f56f132383ed55e43d97c04feff5a6f875fa64458ab73f9e4d1ad93cc978a7939a9afe532e8e6162b7bcb986f04a2282a00" ),
417- verification : false ,
418- },
419- }
420-
421350func Test_ED521_Vec_Check (t * testing.T ) {
422351 var message []byte
423352 var privateKeyBytes []byte
0 commit comments