Skip to content

Commit 7f2bac3

Browse files
Set default keysize for ECKeyPairGenerator to match OpenJDK (#883)
The default keysize used by the ECKeyPairGenerator, if not explicitly initialized is changed from 256 to 384. This change is made to match OpenJDK's behaviour. An additional testcase is added to verify the default keysize. Signed-off-by: Kostas Tsiounis <[email protected]>
1 parent 3ca597e commit 7f2bac3

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/main/java/com/ibm/crypto/plus/provider/ECKeyPairGenerator.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121

2222
public final class ECKeyPairGenerator extends KeyPairGeneratorSpi {
2323

24+
private static final String EC_LEGACY_DEFAULT_KEYSIZE = "openjceplus.ec.legacy.defaultKeysize";
25+
private static final boolean legacyECdefault = Boolean.parseBoolean(System.getProperty(EC_LEGACY_DEFAULT_KEYSIZE));
26+
2427
private OpenJCEPlusProvider provider = null;
25-
private int keysize = 256;
28+
private int keysize = legacyECdefault? 256 : 384;
2629
private SecureRandom cryptoRandom = null;
2730
ECParameterSpec ecSpec;
2831
private ObjectIdentifier oid = null;

src/test/java/ibm/jceplus/junit/base/BaseTestECKeyPairGenerator.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.junit.jupiter.api.Test;
2525
import sun.security.util.InternalPrivateKey;
2626
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
27+
import static org.junit.jupiter.api.Assertions.assertEquals;
2728
import static org.junit.jupiter.api.Assertions.assertTrue;
2829

2930
public class BaseTestECKeyPairGenerator extends BaseTestJunit5 {
@@ -72,6 +73,19 @@ public void testECKeyGen_521() throws Exception {
7273
doECKeyGen(521);
7374
}
7475

76+
@Test
77+
public void testECKeyGen_default() throws Exception {
78+
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", getProviderName());
79+
KeyPair kp = kpg.generateKeyPair();
80+
ECParameterSpec publicKeyParams = ((ECPublicKey) kp.getPublic()).getParams();
81+
// The order of the curve's base point determines the key size
82+
assertEquals(384, publicKeyParams.getOrder().bitLength(), "Default keysize is not as expected.");
83+
84+
ECParameterSpec privateKeyParams = ((ECPrivateKey) kp.getPrivate()).getParams();
85+
// The order of the curve's base point determines the key size
86+
assertEquals(384, privateKeyParams.getOrder().bitLength(), "Default keysize is not as expected.");
87+
}
88+
7589
public void doECKeyGen(int keypairSize) throws Exception {
7690
kpg.initialize(keypairSize);
7791
KeyPair kp = kpg.generateKeyPair();

0 commit comments

Comments
 (0)