-
Notifications
You must be signed in to change notification settings - Fork 8
/
SidhPrivateKey.java
78 lines (55 loc) · 1.67 KB
/
SidhPrivateKey.java
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
package sidh;
/**************************************************************************************************
*
* Implements private keys for the Supersingular Isogeny Diffie-Hellman key exchange algorithm.
*
**************************************************************************************************/
import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.Arrays;
public class SidhPrivateKey {
private final BigInteger m;
public SidhPrivateKey (BigInteger mIn) {
m = mIn;
}
public SidhPrivateKey (SidhPrivateKey kIn) {
m = kIn.getKey ();
}
public SidhPrivateKey (byte[] bytesIn) {
m = new BigInteger (bytesIn);
}
public SidhPrivateKey (int aOrB, BigInteger order) {
// Generate a random private key
BigInteger temp, randmod, three = BigInteger.valueOf(3);
boolean condition;
temp = Felm.genRandom (order);
if (aOrB == SidhKeyExchange.ALICE)
condition = temp.testBit(0);
else {
randmod = temp.mod(three);
condition = randmod.intValue() != 0;
}
while (temp.equals(BigInteger.ZERO) || condition) {
temp = Felm.genRandom (order);
if (aOrB == SidhKeyExchange.ALICE)
condition = temp.testBit(0);
else {
randmod = temp.mod(three);
condition = randmod.intValue() != 0;
}
}
m = temp;
}
public BigInteger getKey() {
return m;
}
public boolean privateKeyEquals (SidhPrivateKey otherKey) {
return m.compareTo (otherKey.getKey ()) == 0;
}
public byte[] serialize() {
return m.toByteArray();
}
public String toString() {
return m.toString();
}
}