Skip to content

Bug in SLHDSA KeyPairGenerator when algorithm name is already parameterized #22

@Ali-Sayedsalehi

Description

@Ali-Sayedsalehi

When using SLHDSA algorithm, If the algorithm name is already parameterized (e.g. SLH-DSA-SHA2-128S) and initialization is skipped, we get this error:

Cannot invoke "org.openssl.jostle.jcajce.spec.OSSLKeyType.getKsType()" because "this.keyType" is null
java.lang.NullPointerException: Cannot invoke "org.openssl.jostle.jcajce.spec.OSSLKeyType.getKsType()" because "this.keyType" is null
	at org.openssl.jostle.jcajce.provider.slhdsa.SLHDSAKeyPairGenerator.generateKeyPair(SLHDSAKeyPairGenerator.java:99)
	at org.openssl.jostle.test.slhdsa.SLHDSATest.testSignVerifyWithContextAndReuse(SLHDSATest.java:303)

To reproduce:

KeyPairGenerator keyGen = KeyPairGenerator.getInstance("SLH-DSA-SHA2-128s", JostleProvider.PROVIDER_NAME);

// we should skip this step
// keyGen.initialize(SLHDSAParameterSpec.slh_dsa_sha2_128s);

KeyPair keyPair = keyGen.generateKeyPair();

The fix would be to add this section:

if (forcedType != OSSLKeyType.NONE)
{
    keyType = forcedType;
}

to the constructor:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions