diff --git a/src/jdk.crypto.ec/share/classes/sun/security/ec/ECPrivateKeyImpl.java b/src/jdk.crypto.ec/share/classes/sun/security/ec/ECPrivateKeyImpl.java index 8af69a4f8cd..0f68ffe4ec1 100644 --- a/src/jdk.crypto.ec/share/classes/sun/security/ec/ECPrivateKeyImpl.java +++ b/src/jdk.crypto.ec/share/classes/sun/security/ec/ECPrivateKeyImpl.java @@ -228,9 +228,9 @@ boolean isECFieldF2m() { * @return the native EC public key context pointer or -1 on error */ long getNativePtr() { - if (nativeECKey == 0x0) { + if (this.nativeECKey == 0x0) { synchronized (this) { - if (nativeECKey == 0x0) { + if (this.nativeECKey == 0x0) { ECPoint generator = this.params.getGenerator(); EllipticCurve curve = this.params.getCurve(); ECField field = curve.getField(); @@ -240,26 +240,27 @@ long getNativePtr() { byte[] gy = generator.getAffineY().toByteArray(); byte[] n = this.params.getOrder().toByteArray(); byte[] h = BigInteger.valueOf(this.params.getCofactor()).toByteArray(); - byte[] p = new byte[0]; + long nativePointer; if (field instanceof ECFieldFp) { - p = ((ECFieldFp)field).getP().toByteArray(); - nativeECKey = nativeCrypto.ECEncodeGFp(a, a.length, b, b.length, p, p.length, gx, gx.length, gy, gy.length, n, n.length, h, h.length); + byte[] p = ((ECFieldFp)field).getP().toByteArray(); + nativePointer = nativeCrypto.ECEncodeGFp(a, a.length, b, b.length, p, p.length, gx, gx.length, gy, gy.length, n, n.length, h, h.length); } else if (field instanceof ECFieldF2m) { - p = ((ECFieldF2m)field).getReductionPolynomial().toByteArray(); - nativeECKey = nativeCrypto.ECEncodeGF2m(a, a.length, b, b.length, p, p.length, gx, gx.length, gy, gy.length, n, n.length, h, h.length); + byte[] p = ((ECFieldF2m)field).getReductionPolynomial().toByteArray(); + nativePointer = nativeCrypto.ECEncodeGF2m(a, a.length, b, b.length, p, p.length, gx, gx.length, gy, gy.length, n, n.length, h, h.length); } else { - nativeECKey = -1; + nativePointer = -1; } - if (nativeECKey != -1) { - nativeCrypto.createECKeyCleaner(this, nativeECKey); + if (nativePointer != -1) { + nativeCrypto.createECKeyCleaner(this, nativePointer); byte[] value = this.getS().toByteArray(); - if (nativeCrypto.ECCreatePrivateKey(nativeECKey, value, value.length) == -1) { - nativeECKey = -1; + if (nativeCrypto.ECCreatePrivateKey(nativePointer, value, value.length) == -1) { + nativePointer = -1; } } + this.nativeECKey = nativePointer; } } } - return nativeECKey; + return this.nativeECKey; } } diff --git a/src/jdk.crypto.ec/share/classes/sun/security/ec/ECPublicKeyImpl.java b/src/jdk.crypto.ec/share/classes/sun/security/ec/ECPublicKeyImpl.java index 3ae0a567b4f..1a963e79003 100644 --- a/src/jdk.crypto.ec/share/classes/sun/security/ec/ECPublicKeyImpl.java +++ b/src/jdk.crypto.ec/share/classes/sun/security/ec/ECPublicKeyImpl.java @@ -154,9 +154,9 @@ boolean isECFieldF2m() { * @return the native EC public key context pointer or -1 on error */ long getNativePtr() { - if (nativeECKey == 0x0) { + if (this.nativeECKey == 0x0) { synchronized (this) { - if (nativeECKey == 0x0) { + if (this.nativeECKey == 0x0) { ECPoint generator = this.params.getGenerator(); EllipticCurve curve = this.params.getCurve(); ECField field = curve.getField(); @@ -166,29 +166,30 @@ long getNativePtr() { byte[] gy = generator.getAffineY().toByteArray(); byte[] n = this.params.getOrder().toByteArray(); byte[] h = BigInteger.valueOf(this.params.getCofactor()).toByteArray(); - byte[] p = new byte[0]; + long nativePointer; int fieldType = 0; if (field instanceof ECFieldFp) { - p = ((ECFieldFp)field).getP().toByteArray(); - nativeECKey = nativeCrypto.ECEncodeGFp(a, a.length, b, b.length, p, p.length, gx, gx.length, gy, gy.length, n, n.length, h, h.length); + byte[] p = ((ECFieldFp)field).getP().toByteArray(); + nativePointer = nativeCrypto.ECEncodeGFp(a, a.length, b, b.length, p, p.length, gx, gx.length, gy, gy.length, n, n.length, h, h.length); } else if (field instanceof ECFieldF2m) { fieldType = 1; - p = ((ECFieldF2m)field).getReductionPolynomial().toByteArray(); - nativeECKey = nativeCrypto.ECEncodeGF2m(a, a.length, b, b.length, p, p.length, gx, gx.length, gy, gy.length, n, n.length, h, h.length); + byte[] p = ((ECFieldF2m)field).getReductionPolynomial().toByteArray(); + nativePointer = nativeCrypto.ECEncodeGF2m(a, a.length, b, b.length, p, p.length, gx, gx.length, gy, gy.length, n, n.length, h, h.length); } else { - nativeECKey = -1; + nativePointer = -1; } - if (nativeECKey != -1) { - nativeCrypto.createECKeyCleaner(this, nativeECKey); + if (nativePointer != -1) { + nativeCrypto.createECKeyCleaner(this, nativePointer); byte[] x = this.w.getAffineX().toByteArray(); byte[] y = this.w.getAffineY().toByteArray(); - if (nativeCrypto.ECCreatePublicKey(nativeECKey, x, x.length, y, y.length, fieldType) == -1) { - nativeECKey = -1; + if (nativeCrypto.ECCreatePublicKey(nativePointer, x, x.length, y, y.length, fieldType) == -1) { + nativePointer = -1; } } + this.nativeECKey = nativePointer; } } } - return nativeECKey; + return this.nativeECKey; } }