Skip to content

Commit de21207

Browse files
Sync up engineGenerateSecret(String) in key agreement classes
A check in engineGenerateSecret(String) was updated in ECDHKeyAgreement and XDHKeyAgreement. The equivalent native classes (i.e., NativeECDHKeyAgreement and NativeXDHKeyAgreement) are updated to reflect that change. Signed-off-by: Kostas Tsiounis <[email protected]>
1 parent 2a33f06 commit de21207

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

closed/src/java.base/share/classes/sun/security/ec/NativeECDHKeyAgreement.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
/*
2727
* ===========================================================================
28-
* (c) Copyright IBM Corp. 2022, 2024 All Rights Reserved
28+
* (c) Copyright IBM Corp. 2022, 2025 All Rights Reserved
2929
* ===========================================================================
3030
*/
3131

@@ -60,6 +60,7 @@
6060
import sun.security.util.ArrayUtil;
6161
import sun.security.util.CurveDB;
6262
import sun.security.util.ECUtil;
63+
import sun.security.util.KeyUtil;
6364
import sun.security.util.NamedCurve;
6465

6566
/**
@@ -343,11 +344,11 @@ protected SecretKey engineGenerateSecret(String algorithm)
343344
if (algorithm == null) {
344345
throw new NoSuchAlgorithmException("Algorithm must not be null");
345346
}
346-
if (!(algorithm.equals("TlsPremasterSecret"))) {
347-
throw new NoSuchAlgorithmException
348-
("Only supported for algorithm TlsPremasterSecret");
347+
if (!KeyUtil.isSupportedKeyAgreementOutputAlgorithm(algorithm)) {
348+
throw new NoSuchAlgorithmException(
349+
"Unsupported secret key algorithm: " + algorithm);
349350
}
350-
return new SecretKeySpec(engineGenerateSecret(), "TlsPremasterSecret");
351+
return new SecretKeySpec(engineGenerateSecret(), algorithm);
351352
}
352353

353354
/**

closed/src/java.base/share/classes/sun/security/ec/NativeXDHKeyAgreement.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
/*
2727
* ===========================================================================
28-
* (c) Copyright IBM Corp. 2023, 2023 All Rights Reserved
28+
* (c) Copyright IBM Corp. 2023, 2025 All Rights Reserved
2929
* ===========================================================================
3030
*/
3131

@@ -49,6 +49,7 @@
4949

5050
import jdk.crypto.jniprovider.NativeCrypto;
5151

52+
import sun.security.util.KeyUtil;
5253
import sun.security.x509.X509Key;
5354

5455
public class NativeXDHKeyAgreement extends KeyAgreementSpi {
@@ -259,8 +260,9 @@ protected SecretKey engineGenerateSecret(String algorithm)
259260
throw new NoSuchAlgorithmException("Algorithm must not be null");
260261
}
261262

262-
if (!(algorithm.equals("TlsPremasterSecret"))) {
263-
throw new NoSuchAlgorithmException("Only supported for algorithm TlsPremasterSecret");
263+
if (!KeyUtil.isSupportedKeyAgreementOutputAlgorithm(algorithm)) {
264+
throw new NoSuchAlgorithmException(
265+
"Unsupported secret key algorithm: " + algorithm);
264266
}
265267
return new SecretKeySpec(engineGenerateSecret(), algorithm);
266268
}

0 commit comments

Comments
 (0)