bc-java icon indicating copy to clipboard operation
bc-java copied to clipboard

Cannot build HashMLDSA65-Ed25519-SHA512 from PKCS#8

Open wangweij opened this issue 8 months ago • 1 comments

        var g = KeyPairGenerator.getInstance("HashMLDSA65-Ed25519-SHA512");
        var sk = g.generateKeyPair().getPrivate();
        var f = KeyFactory.getInstance("HashMLDSA65-Ed25519-SHA512");
        System.out.println(sk.getFormat()); // it is "PKCS#8"
        f.generatePrivate(new PKCS8EncodedKeySpec(sk.getEncoded()));

The last line failed with

Exception in thread "main" java.security.spec.InvalidKeySpecException: encoded key spec not recognized: encoded key spec not recognized: Extra data detected in stream
	at org.bouncycastle.jcajce.provider.asymmetric.util.BaseKeyFactorySpi.engineGeneratePrivate(BaseKeyFactorySpi.java:31)
	at java.base/java.security.KeyFactory.generatePrivate(KeyFactory.java:395)

Looks like KeyFactorySpi::generatePrivate has not treated the OID as a composite one.

wangweij avatar May 04 '25 18:05 wangweij

Thank you for supporting Bouncy Castle. I have a question regarding the HashMLDSA65-Ed25519-SHA512 algorithm.

Does this variant originate from the composite signature structures defined in draft-ietf-lamps-pq-composite-sigs? If so, it looks like the latest version of the draft has removed the HashMLDSA series from the list of supported algorithms.

ligefeiBouncycastle avatar Jun 19 '25 00:06 ligefeiBouncycastle