Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Signature size of the PQC algorithms dilithium3 and dilithium5 do not match NIST 204 (Draft) #1597

Closed
xipki opened this issue Mar 7, 2024 · 1 comment

Comments

@xipki
Copy link
Contributor

xipki commented Mar 7, 2024

I am testing the dilithium (ML-DSA) signatures using bcprov version 1.77, and find out that the signatures of dilithium3 and dilithium5 have different size than NIST FIPS 204 (Draft), published August 24, 2023 (available under https://doi.org/10.6028/NIST.FIPS.204.ipd), "Table 2. Sizes (in bytes) of keys and signatures of ML-DSA.".

Bouncycastle (dilithium3) : 3309 bytes vs FIPS 204 (ML-DSA-65): 3293 bytes
Bouncycastle (dilithium5) : 4627 bytes vs FIPS 204 (ML-DSA-87): 4595 bytes.

Below is the code to reproduce the result:

    public void testNist204() throws Exception {
        DilithiumParameterSpec[] keySpecs = {DilithiumParameterSpec.dilithium2,
            DilithiumParameterSpec.dilithium3, DilithiumParameterSpec.dilithium5};

        for (DilithiumParameterSpec keySpec : keySpecs) {
            KeyPairGenerator kpg = KeyPairGenerator.getInstance("Dilithium", "BC");
            kpg.initialize(keySpec, new SecureRandom());
            KeyPair kp = kpg.generateKeyPair();
            byte[] encodedPubKey1 = kp.getPublic().getEncoded();

            System.out.println("\n=====" + keySpec.getName() + "=====\npublic key size: " +
                SubjectPublicKeyInfo.getInstance(encodedPubKey1).getPublicKeyData().getOctets().length);

            Signature sig = Signature.getInstance("Dilithium", "BC");
            sig.initSign(kp.getPrivate(), new SecureRandom());
            sig.update(new byte[256], 0, 256);
            byte[] sigValue = sig.sign();
            System.out.println("signature size: " + sigValue.length);
        }
    }
@roy-basmacier
Copy link

Hey @xipki,
The values in Bouncy Castle are correct.
NIST's comment about FIPS 204 for Table 2:

Note on the intermediate values for ML-DSA:
We recognize that Table 2 of the draft FIPS 204 gives incorrect values for the sizes of the signature and private key.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants