· 9 years ago · Nov 02, 2016, 04:37 PM
1package schnorr;
2
3import java.math.BigInteger;
4import java.util.Random;
5
6import org.bouncycastle.jce.ECNamedCurveTable;
7import org.bouncycastle.jce.spec.ECParameterSpec;
8import org.bouncycastle.math.ec.ECCurve;
9import org.bouncycastle.math.ec.ECPoint;
10import org.bouncycastle.math.ec.ECCurve.Fp;
11
12public class TestClass2 {
13
14 static BigInteger Q;
15 static BigInteger A;
16 static BigInteger B;
17 static BigInteger Gx;
18 static BigInteger Gy;
19 static BigInteger N ;
20 static BigInteger publicKeyx ;
21 static BigInteger publicKeyy;
22 static BigInteger Xx, Xy;
23 static BigInteger secretKey;
24 static BigInteger x;
25 static ECCurve.Fp ec;
26 static ECPoint G;
27 static ECPoint publicKey, X;
28 static ECParameterSpec ecSpecification;
29 static BigInteger c,s;
30
31 public static void main(String[]args ){
32 Gx = new BigInteger("6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296", 16);
33 Gy = new BigInteger("4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5", 16);
34 N = new BigInteger("FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551", 16);
35 A = new BigInteger("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC", 16);
36 B = new BigInteger("5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B",16);
37 Q = new BigInteger("FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF", 16);
38 ec = new ECCurve.Fp(Q, A, B);
39 G = ec.createPoint(Gx, Gy);
40 ecSpecification = new ECParameterSpec(ec, G, N);
41
42 //Prover generates secret key (random) in Group Q
43 secretKey = new BigInteger("105748609587977974810509465673464352338083341287173949206887318622687701377459");
44 System.out.println("secretKey " + secretKey);
45
46 publicKeyx = new BigInteger("B976E333B37C341553919EA73B8862A942DF24E27E1D4C4E9726800DD99E80C0", 16);
47 publicKeyy = new BigInteger("6F05A739F008B1480B69F190FBEE9A5F8F617DA607F29E6FE70A9BB18A1162B6", 16);
48 publicKey = ec.createPoint(publicKeyx, publicKeyy);
49 //Prover generates X
50 Xx = new BigInteger("48A36158108651D8308D7D96E47766364F161F7220ACE54F09891E6C796D4453", 16);
51 Xy = new BigInteger("2C2B189E08F20343AB901FFF8D8D628D2A850E7E6576D96DFEB58024F91D8B80", 16);
52 X = ec.createPoint(Xx, Xy);
53
54 //Verifier generates c
55 c = new BigInteger("7206EDFF16B8AE64200A8BA7841FF4FBFDC30F708CB631FB456E3646DCBD9FBC", 16);
56 //Prover generates s
57 s = new BigInteger("4AAB67A4266722C36E661631879063478DDFC0ED57463583A277B34FCB63206C", 16);
58 //
59 ECPoint left = G.multiply(s);
60 ECPoint right = X;
61 right = right.add(publicKey.multiply(c));
62 System.out.println(left);
63 System.out.println(right);
64
65
66
67
68
69
70
71
72
73 /*Q = new BigInteger("6277101735386680763835789423207666416083908700390324961279");
74 BigInteger A = new BigInteger("6277101735386680763835789423207666416083908700390324961276");
75 BigInteger B = new BigInteger("2455155546008943817740293915197451784769108058161191238065");
76 BigInteger Gx = new BigInteger("602046282375688656758213480587526111916698976636884684818");
77 BigInteger Gy = new BigInteger("174050332293622031404857552280219410364023488927386650641");
78 BigInteger N = new BigInteger("6277101735386680763835789423176059013767194773182842284081");
79 BigInteger Pkx = new BigInteger("2356983434083109014050591473978381057678123121207580793978");
80 BigInteger Pky =
81 secret= new BigInteger("780881775213329116233352149091119097783327157603970575016");
82 */
83 }
84 public static BigInteger generateRandomInTheWorld() {
85 Random r = new Random();
86 BigInteger result = new BigInteger(Q.bitLength(), r);
87 while( result.compareTo(Q) >= 0 ) {
88 result = new BigInteger(Q.bitLength(), r);
89 }
90 return result;
91 }
92}