Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TnafTest.java « test « ec « math « bouncycastle « org « java « test « src « core - gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9400f6c5e7322e82827c4ec485dfb44b84c74e5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
//package org.bouncycastle.math.ec.test;
//
//import java.math.BigInteger;
//import java.util.Random;
//
//import junit.framework.TestCase;
//
//import org.bouncycastle.asn1.sec.SECNamedCurves;
//import org.bouncycastle.asn1.x9.X9ECParameters;
//import org.bouncycastle.math.ec.ECCurve;
//import org.bouncycastle.math.ec.ECPoint;
//import org.bouncycastle.math.ec.NafL2RMultiplier;
//import org.bouncycastle.math.ec.ReferenceMultiplier;
//import org.bouncycastle.math.ec.WNafL2RMultiplier;
//import org.bouncycastle.math.ec.WTauNafMultiplier;
//
//public class TnafTest extends TestCase
//{
//    private Random m_rand = new Random();
//
//    private String ecPointToString(ECPoint p) {
//        StringBuffer sb = new StringBuffer("x = ");
//        sb.append(p.getX().toBigInteger().toString());
//        sb.append("; y = ");
//        sb.append(p.getY().toBigInteger().toString());
//        return sb.toString();
//    }
//
//    private ECPoint repeatedMultiply(ECPoint p, BigInteger k)
//    {
//        ECPoint result = p.multiply(k);
//        for (int i = 1; i < 10; ++i)
//        {
//            ECPoint check = p.multiply(k);
//            assertEquals(result, check);
//        }
//        return result;
//    }
//
//    private void implTestMultiplyTnaf(String curveName) {
//        X9ECParameters x9ECParameters = SECNamedCurves.getByName(curveName);
//
//        ECCurve.F2m curve = (ECCurve.F2m)x9ECParameters.getCurve();
//        BigInteger n = curve.getN();
//
//        // The generator is multiplied by random b to get random q
//        BigInteger b = new BigInteger(n.bitLength(), m_rand);
//        ECPoint g = x9ECParameters.getG();
//        ECPoint.F2m p = (ECPoint.F2m)g.multiply(b);
//
//        BigInteger k = new BigInteger(n.bitLength(), m_rand);
//        long now1 = System.currentTimeMillis();
//        p.setECMultiplier(new WTauNafMultiplier());
//        ECPoint refRWTnaf = repeatedMultiply(p, k);
//        long now2 = System.currentTimeMillis();
//        p.setECMultiplier(new WNafL2RMultiplier());
//        ECPoint refWnaf = repeatedMultiply(p, k);
//        long now3 = System.currentTimeMillis();
//        p.setECMultiplier(new NafL2RMultiplier());
//        ECPoint refFpNaf = repeatedMultiply(p, k);
//        long now4 = System.currentTimeMillis();
//        p.setECMultiplier(new ReferenceMultiplier());
//        ECPoint reference = repeatedMultiply(p, k);
//        long now5 = System.currentTimeMillis();
//
//        assertEquals("WTNAF multiplication is incorrect", refRWTnaf, reference);
//        assertEquals("FPNAF multiplication is incorrect", refFpNaf, reference);
//        assertEquals("WNAF multiplication is incorrect", refWnaf, reference);
//
//        System.out.println(curveName + ": Multiply WTNAF took millis:  " + (now2 - now1));
//        System.out.println(curveName + ": Multiply WNAF took millis:   " + (now3 - now2));
//        System.out.println(curveName + ": Multiply FPNAF took millis:  " + (now4 - now3));
//        System.out.println(curveName + ": Multiply REFE took millis:   " + (now5 - now4));
//
////        System.out.println(curveName + ": refRWTnaf  = " + ecPointToString(refRWTnaf));
////        System.out.println(curveName + ": refWnaf    = " + ecPointToString(refWnaf));
////        System.out.println(curveName + ": refFpNaf   = " + ecPointToString(refFpNaf));
////        System.out.println(curveName + ": reference  = " + ecPointToString(reference) + "\n");
//        System.out.println();
//    }
//
//    public void testMultiplyTnaf() {
//        System.out.println("\n\n\n*****  Start test multiplications on F2m (Koblitz) *****");
//        implTestMultiplyTnaf("sect163k1");
//        implTestMultiplyTnaf("sect233k1");
//        implTestMultiplyTnaf("sect239k1");
//        implTestMultiplyTnaf("sect283k1");
//        implTestMultiplyTnaf("sect409k1");
//        implTestMultiplyTnaf("sect571k1");
//    }
//
//    private void implTestMultiplyWnaf(String curveName) {
//        X9ECParameters x9ECParameters = SECNamedCurves.getByName(curveName);
//
//        BigInteger r = x9ECParameters.getN();
//
//        // The generator is multiplied by random b to get random q
//        BigInteger b = new BigInteger(r.bitLength(), m_rand);
//        ECPoint g = x9ECParameters.getG();
//        ECPoint p = g.multiply(b);
//
//        BigInteger k = new BigInteger(r.bitLength(), m_rand);
//        long now1 = System.currentTimeMillis();
//        p.setECMultiplier(new WNafL2RMultiplier());
//        ECPoint refWnaf = repeatedMultiply(p, k);
//        long now2 = System.currentTimeMillis();
//        p.setECMultiplier(new NafL2RMultiplier());
//        ECPoint refFpNaf = repeatedMultiply(p, k);
//        long now3 = System.currentTimeMillis();
//        p.setECMultiplier(new ReferenceMultiplier());
//        ECPoint reference = repeatedMultiply(p, k);
//        long now4 = System.currentTimeMillis();
//
//        assertEquals("WNAF multiplication is incorrect", refWnaf, reference);
//        assertEquals("FPNAF multiplication is incorrect", refFpNaf, reference);
//
//        System.out.println(curveName + ": Multiply WNAF took millis:   " + (now2 - now1));
//        System.out.println(curveName + ": Multiply FPNAF took millis:  " + (now3 - now2));
//        System.out.println(curveName + ": Multiply REFE took millis:   " + (now4 - now3));
//
////        System.out.println(curveName + ": refWnaf    = " + ecPointToString(refWnaf));
////        System.out.println(curveName + ": refFpNaf   = " + ecPointToString(refFpNaf));
////        System.out.println(curveName + ": reference  = " + ecPointToString(reference));
//        System.out.println();
//    }
//
//    public void testMultiplyWnaf() {
//        System.out.println("\n\n\n*****  Start test multiplications on F2m *****");
//        implTestMultiplyWnaf("sect113r1");
//        implTestMultiplyWnaf("sect113r2");
//        implTestMultiplyWnaf("sect131r1");
//        implTestMultiplyWnaf("sect131r2");
//        implTestMultiplyWnaf("sect163r1");
//        implTestMultiplyWnaf("sect163r2");
//        implTestMultiplyWnaf("sect193r1");
//        implTestMultiplyWnaf("sect193r2");
//        implTestMultiplyWnaf("sect233r1");
//        implTestMultiplyWnaf("sect283r1");
//        implTestMultiplyWnaf("sect409r1");
//        implTestMultiplyWnaf("sect571r1");
//
//        System.out.println("\n\n\n*****  Start test multiplications on Fp  *****");
//        implTestMultiplyWnaf("secp112r1");
//        implTestMultiplyWnaf("secp128r1");
//        implTestMultiplyWnaf("secp160r1");
//        implTestMultiplyWnaf("secp192r1");
//        implTestMultiplyWnaf("secp224r1");
//        implTestMultiplyWnaf("secp256r1");
//        implTestMultiplyWnaf("secp384r1");
//        implTestMultiplyWnaf("secp521r1");
//    }
//}