Skip to content

Commit 969f603

Browse files
author
Zainab Fatmi
committed
Use OpenSSL for the ECDH key agreement
Signed-off-by: Zainab Fatmi <[email protected]>
1 parent 7348b10 commit 969f603

File tree

12 files changed

+1179
-10
lines changed

12 files changed

+1179
-10
lines changed

closed/src/java.base/share/classes/jdk/crypto/jniprovider/NativeCrypto.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,20 @@
2323
*/
2424
package jdk.crypto.jniprovider;
2525

26+
import java.lang.ref.Cleaner;
2627
import java.security.*;
2728

2829
import com.ibm.oti.vm.VM;
2930

3031
import jdk.internal.misc.Unsafe;
32+
import jdk.internal.ref.CleanerFactory;
3133
import jdk.internal.reflect.Reflection;
3234
import jdk.internal.reflect.CallerSensitive;
3335

3436
public class NativeCrypto {
3537

38+
private static final Cleaner ECKeyCleaner = CleanerFactory.cleaner();
39+
3640
//ossl_vers:
3741
// -1 : library load failed
3842
// 0 : openssl 1.0.x
@@ -80,6 +84,15 @@ public static NativeCrypto getNativeCrypto() {
8084
throw new SecurityException("NativeCrypto");
8185
}
8286

87+
public void createECKeyCleaner(Object owner, long key) {
88+
ECKeyCleaner.register(owner, new Runnable() {
89+
@Override
90+
public void run() {
91+
NativeCrypto.this.ECDestroyKey(key);
92+
}
93+
});
94+
}
95+
8396
/* Native digest interfaces */
8497
private static final native int loadCrypto(boolean traceEnabled);
8598

@@ -230,4 +243,56 @@ public final native int ChaCha20FinalDecrypt(long context,
230243
int aadLen,
231244
int tagLen);
232245

246+
/* Native EC interfaces */
247+
public final native int ECCreatePublicKey(long key,
248+
byte[] x,
249+
int xLen,
250+
byte[] y,
251+
int yLen,
252+
int field);
253+
254+
public final native int ECCreatePrivateKey(long key,
255+
byte[] s,
256+
int sLen);
257+
258+
public final native long ECEncodeGFp(byte[] a,
259+
int aLen,
260+
byte[] b,
261+
int bLen,
262+
byte[] p,
263+
int pLen,
264+
byte[] x,
265+
int xLen,
266+
byte[] y,
267+
int yLen,
268+
byte[] n,
269+
int nLen,
270+
byte[] h,
271+
int hLen);
272+
273+
public final native long ECEncodeGF2m(byte[] a,
274+
int aLen,
275+
byte[] b,
276+
int bLen,
277+
byte[] p,
278+
int pLen,
279+
byte[] x,
280+
int xLen,
281+
byte[] y,
282+
int yLen,
283+
byte[] n,
284+
int nLen,
285+
byte[] h,
286+
int hLen);
287+
288+
public final native int ECDestroyKey(long key);
289+
290+
public final native int ECDeriveKey(long publicKey,
291+
long privateKey,
292+
byte[] secret,
293+
int secretOffset,
294+
int secretLen);
295+
296+
public final native boolean ECNativeGF2m();
297+
233298
}

0 commit comments

Comments
 (0)