|
23 | 23 | */ |
24 | 24 | package jdk.crypto.jniprovider; |
25 | 25 |
|
| 26 | +import java.lang.ref.Cleaner; |
26 | 27 | import java.security.*; |
27 | 28 |
|
28 | 29 | import com.ibm.oti.vm.VM; |
29 | 30 |
|
30 | 31 | import jdk.internal.misc.Unsafe; |
| 32 | +import jdk.internal.ref.CleanerFactory; |
31 | 33 | import jdk.internal.reflect.Reflection; |
32 | 34 | import jdk.internal.reflect.CallerSensitive; |
33 | 35 |
|
34 | 36 | public class NativeCrypto { |
35 | 37 |
|
| 38 | + private static final Cleaner ECKeyCleaner = CleanerFactory.cleaner(); |
| 39 | + |
36 | 40 | //ossl_vers: |
37 | 41 | // -1 : library load failed |
38 | 42 | // 0 : openssl 1.0.x |
@@ -80,6 +84,15 @@ public static NativeCrypto getNativeCrypto() { |
80 | 84 | throw new SecurityException("NativeCrypto"); |
81 | 85 | } |
82 | 86 |
|
| 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 | + |
83 | 96 | /* Native digest interfaces */ |
84 | 97 | private static final native int loadCrypto(boolean traceEnabled); |
85 | 98 |
|
@@ -230,4 +243,56 @@ public final native int ChaCha20FinalDecrypt(long context, |
230 | 243 | int aadLen, |
231 | 244 | int tagLen); |
232 | 245 |
|
| 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 | + |
233 | 298 | } |
0 commit comments