bcgit / bc-java

Bouncy Castle Java Distribution (Mirror)
https://www.bouncycastle.org/java.html
MIT License
2.22k stars 1.1k forks source link

Cannot generate BcPGPKeyPair for X448 #1584

Open hbs opened 4 months ago

hbs commented 4 months ago

Attempting to do the following fails with a ClassCastException when BcPGKeyConverter wrongly assumes its input parameter not being ECPrivateKeyParameters means they are X25519.

X448KeyPairGenerator xkpg = new X448KeyPairGenerator();
xkpg.init(new KeyGenerationParameters(new SecureRandom(), 0));
BcPGPKeyPair kp = new BcPGPKeyPair(PublicKeyAlgorithmTags.ECDH, xkpg.generateKeyPair(), new Date());
vanitasvitae commented 2 months ago

I might have a patch for this issue :)

vanitasvitae commented 1 month ago

This is now fixed, though you should note that X448 + PublicKeyAlgorithmTags.ECDH is not a valid combination according to the OpenPGP specification. GnuPG might be able to deal with such keys, but other implementations following the official spec might not.

Consider using X448 + PublicKeyAlgorithmTags.X448 instead (though GnuPG migh not support this combination -.-).