src/share/classes/sun/security/ec/ECKeyPairGenerator.java

Print this page

        

*** 121,133 **** if (random == null) { random = JCAUtil.getSecureRandom(); } random.nextBytes(seed); try { ! long[] handles = generateECKeyPair(keySize, encodedParams, seed); // The 'params' object supplied above is equivalent to the native // one so there is no need to fetch it. // handles[0] points to the native private key --- 121,134 ---- if (random == null) { random = JCAUtil.getSecureRandom(); } random.nextBytes(seed); + long[] handles = null; try { ! handles = generateECKeyPair(keySize, encodedParams, seed); // The 'params' object supplied above is equivalent to the native // one so there is no need to fetch it. // handles[0] points to the native private key
*** 144,153 **** --- 145,160 ---- return new KeyPair(publicKey, privateKey); } catch (Exception e) { throw new ProviderException(e); + } finally { + if (handles != null) { + // handles[2] points to the data structure containing + // both the native public and private key. + releaseECKeyPairData(handles[2]); + } } } private void checkKeySize(int keySize) throws InvalidParameterException { if (keySize < KEY_SIZE_MIN) {
*** 166,175 **** --- 173,188 ---- * The first handle points to the private key, the second to the public key. */ private static native long[] generateECKeyPair(int keySize, byte[] encodedParams, byte[] seed) throws GeneralSecurityException; + + /* + * Releases the native memory allocated by generateECKeyPair. + */ + private static native void releaseECKeyPairData(long privKeyHandle); + /* * Extracts the encoded key data using the supplied handle. */ private static native byte[] getEncodedBytes(long handle); }