|
1 | 1 | /*
|
2 |
| - * Copyright IBM Corp. 2023, 2024 |
| 2 | + * Copyright IBM Corp. 2023, 2025 |
3 | 3 | *
|
4 | 4 | * This code is free software; you can redistribute it and/or modify it
|
5 | 5 | * under the terms provided by IBM in the LICENSE file that accompanied
|
|
25 | 25 | import java.security.spec.EllipticCurve;
|
26 | 26 | import java.security.spec.InvalidParameterSpecException;
|
27 | 27 | import java.util.Arrays;
|
| 28 | +import java.util.List; |
28 | 29 | import javax.crypto.KeyAgreement;
|
29 | 30 | import org.junit.jupiter.api.BeforeEach;
|
30 | 31 | import org.junit.jupiter.api.Test;
|
| 32 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
31 | 33 | import static org.junit.jupiter.api.Assertions.assertNotNull;
|
32 | 34 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
33 | 35 | import static org.junit.jupiter.api.Assertions.fail;
|
@@ -301,6 +303,23 @@ public void testEC_engineInit_AlgorithmParameterSpec_paramSpec() throws Exceptio
|
301 | 303 | fail("InvalidParameterSpecException expected but no exception was thrown");
|
302 | 304 | }
|
303 | 305 |
|
| 306 | + @Test |
| 307 | + public void test_engineGenerateSecret() throws Exception { |
| 308 | + try { |
| 309 | + KeyPairGenerator g = KeyPairGenerator.getInstance("DH", getProviderName()); |
| 310 | + KeyPair kp1 = g.generateKeyPair(); |
| 311 | + KeyPair kp2 = g.generateKeyPair(); |
| 312 | + KeyAgreement ka = KeyAgreement.getInstance("DH", getProviderName()); |
| 313 | + for (String alg : List.of("TlsPremasterSecret", "Generic")) { |
| 314 | + ka.init(kp1.getPrivate()); |
| 315 | + ka.doPhase(kp2.getPublic(), true); |
| 316 | + assertEquals(ka.generateSecret(alg).getAlgorithm(), alg); |
| 317 | + } |
| 318 | + } catch (Exception e) { |
| 319 | + throw e; |
| 320 | + } |
| 321 | + } |
| 322 | + |
304 | 323 | void compute_ecdh_key_with_global_key(String idString, AlgorithmParameterSpec algParameterSpec)
|
305 | 324 | throws NoSuchAlgorithmException, InvalidAlgorithmParameterException,
|
306 | 325 | NoSuchProviderException, InvalidKeyException {
|
|
0 commit comments