github.com/zhiqiangxu/util@v0.0.0-20230112053021-0a7aee056cd5/crypto/wnaf/lr_test.go (about) 1 package wnaf 2 3 import ( 4 "math/big" 5 "reflect" 6 "testing" 7 ) 8 9 func TestToWnafLR(t *testing.T) { 10 testCases := []struct { 11 D *big.Int 12 Wnaf []int64 13 W uint8 14 }{ 15 // quoted from https://rd.springer.com/content/pdf/10.1007/978-3-540-68914-0_26.pdf Page 11 16 { 17 D: big.NewInt(0b11101001100100010101110101010111), 18 Wnaf: []int64{0, 0, 7, 0, 0, 0, 5, 0, 0, 0, 0, -7, 0, 0, 0, 0, 0, 5, 0, 0, 0, 7, 0, 0, 0, 5, 0, 0, 3, 0, 0, 0, -2}, 19 W: 4, 20 }, 21 { 22 D: big.NewInt(0b11101001100100010101110101010111), 23 Wnaf: []int64{2, 0, 0, 0, -3, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 0, 3, 0, -1, 0, 0, 0, 0, -3, 0, 0, 3, 0, -1, 0, 0, 0, -2}, 24 W: 3, 25 }, 26 { 27 D: big.NewInt(0b1110), 28 Wnaf: []int64{0, 0, 7, 0}, 29 W: 4, 30 }, 31 { 32 D: big.NewInt(0b111), 33 Wnaf: []int64{0, 0, 7}, 34 W: 4, 35 }, 36 } 37 38 for _, testCase := range testCases { 39 ret := ToWnafLR(testCase.D, testCase.W) 40 if !reflect.DeepEqual(ret, testCase.Wnaf) { 41 t.Fatalf("actual %v vs expected %v, w %d", ret, testCase.Wnaf, testCase.W) 42 } 43 } 44 45 }