You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Importing an ML-DSA public key from a previously generated key that has been exported with GetEncoded() method, does not import - instead throws ArgumentException "invalid encoding". The check in MLDsaPublicKeyParameters FromEncoded method on the length of the encoding parameter only checks against the public key length - it needs to include the length of the seed key. The encoded data length is 1984 bytes (1952 public key length + 32 seed length).
Create a new ML-DSA key pair, export the public key and create a new ML-DSA public key from the encoded data.
var mlDsaKeyGenerationParameters =
new MLDsaKeyGenerationParameters(new SecureRandom(),
MLDsaParameters.ml_dsa_65);
var keyPairGenerator = new MLDsaKeyPairGenerator();
keyPairGenerator.Init(mlDsaKeyGenerationParameters);
var key = keyPairGenerator.GenerateKeyPair();
var privateKey = (MLDsaPrivateKeyParameters)key.Private;
var publicKey = (MLDsaPublicKeyParameters)key.Public;
var privateKeyEncoded = privateKey.GetEncoded();
var publicKeyEncoded = publicKey.GetEncoded();
var newPrivateKey = MLDsaPrivateKeyParameters.FromEncoding(
MLDsaParameters.ml_dsa_65, privateKeyEncoded);
var newPublicKey = MLDsaPublicKeyParameters.FromEncoding(
MLDsaParameters.ml_dsa_65, publicKeyEncoded);
The final call to MLDsaPublicKeyParameters.FromEncoding throws ArgumentException("invalid encoding").
Using BouncyCastle.Cryptography nuget package v2.5.0
The text was updated successfully, but these errors were encountered:
I don't get an exception running the above code, and the lengths involved are correct; encoded PK length for ML-DSA-65 is 1952 i.e. 32 (rho) + 32610 (t1). We also have test coverage based on NIST test vectors.
Importing an ML-DSA public key from a previously generated key that has been exported with GetEncoded() method, does not import - instead throws ArgumentException "invalid encoding". The check in MLDsaPublicKeyParameters FromEncoded method on the length of the encoding parameter only checks against the public key length - it needs to include the length of the seed key. The encoded data length is 1984 bytes (1952 public key length + 32 seed length).
Create a new ML-DSA key pair, export the public key and create a new ML-DSA public key from the encoded data.
The final call to MLDsaPublicKeyParameters.FromEncoding throws ArgumentException("invalid encoding").
Using BouncyCastle.Cryptography nuget package v2.5.0
The text was updated successfully, but these errors were encountered: