forked from crocs-muni/ECTester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NativeECPrivateKey.java
171 lines (139 loc) · 4.35 KB
/
NativeECPrivateKey.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
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package cz.crcs.ectester.standalone.libs.jni;
import cz.crcs.ectester.common.util.ByteUtil;
import org.bouncycastle.util.Arrays;
import java.math.BigInteger;
import java.security.interfaces.ECPrivateKey;
import java.security.spec.ECParameterSpec;
/**
* @author Jan Jancar [email protected]
*/
public abstract class NativeECPrivateKey implements ECPrivateKey {
private String algorithm;
private String format;
ECParameterSpec params;
public NativeECPrivateKey(String algorithm, String format, ECParameterSpec params) {
this.algorithm = algorithm;
this.format = format;
this.params = params;
}
@Override
public String getAlgorithm() {
return algorithm;
}
@Override
public String getFormat() {
return format;
}
@Override
public ECParameterSpec getParams() {
return params;
}
public abstract byte[] getData();
private static class Raw extends NativeECPrivateKey {
byte[] keyData;
public Raw(byte[] keyData, ECParameterSpec params) {
super("EC", "raw", params);
this.keyData = Arrays.clone(keyData);
}
@Override
public BigInteger getS() {
return new BigInteger(1, keyData);
}
@Override
public byte[] getEncoded() {
return Arrays.clone(keyData);
}
public byte[] getData() {
return getEncoded();
}
}
public static class TomCrypt extends Raw {
public TomCrypt(byte[] keyData, ECParameterSpec params) {
super(keyData, params);
}
}
public static class Botan extends Raw {
public Botan(byte[] keyData, ECParameterSpec params) {
super(keyData, params);
}
}
public static class Cryptopp extends Raw {
public Cryptopp(byte[] keyData, ECParameterSpec params) {
super(keyData, params);
}
}
public static class Openssl extends Raw {
public Openssl(byte[] keyData, ECParameterSpec params) {
super(keyData, params);
}
}
public static class Boringssl extends Raw {
public Boringssl(byte[] keyData, ECParameterSpec params) {
super(keyData, params);
}
}
public static class Gcrypt extends Raw {
public Gcrypt(byte[] keyData, ECParameterSpec params) {
super(keyData, params);
}
}
public static class MbedTLS extends Raw {
public MbedTLS(byte[] keyData, ECParameterSpec params) {
super(keyData, params);
}
}
public static class Ippcp extends Raw {
public Ippcp(byte[] keyData, ECParameterSpec params) {
super(keyData, params);
}
}
public static class Matrixssl extends Raw {
public Matrixssl(byte[] keyData, ECParameterSpec params) {
super(keyData, params);
}
}
public static class Libressl extends Raw {
public Libressl(byte[] keyData, ECParameterSpec params) {
super(keyData, params);
}
}
public static class Mscng extends Raw {
// 0 -> implicit (meta = curveName UTF16, header = full);
// 1 -> explicit (meta = null, header = full);
// 2 -> nist (meta = null, header = full)
private int flag;
private byte[] meta = null;
private byte[] header;
private byte[] x;
private byte[] y;
public Mscng(int flag, byte[] meta, byte[] header, byte[] x, byte[] y, byte[] keyData, ECParameterSpec params) {
super(keyData, params);
this.flag = flag;
this.meta = Arrays.clone(meta);
this.header = Arrays.clone(header);
this.x = Arrays.clone(x);
this.y = Arrays.clone(y);
}
public int getFlag() {
return flag;
}
public byte[] getMeta() {
return Arrays.clone(meta);
}
public byte[] getHeader() {
return Arrays.clone(header);
}
public byte[] getBlob() {
return ByteUtil.concatenate(header, x, y, keyData);
}
@Override
public byte[] getData() {
return getBlob();
}
}
public static class Nettle extends Raw {
public Nettle(byte[] keyData, ECParameterSpec params) {
super(keyData, params);
}
}
}