Skip to content

Specific ML-KEM should not accept a key from a different parameter set #1666

Description

@JinhangZhang

I got failure when run the following code

import java.security.*;
import java.security.spec.NamedParameterSpec;
import javax.crypto.KEM;

public class TestMLKEMDowngrade {

    public static void main(String[] args) throws Exception {
        KeyPairGenerator kpg = KeyPairGenerator.getInstance("ML-KEM", "SunJCE");
        kpg.initialize(NamedParameterSpec.ML_KEM_512);
        KeyPair keyPair = kpg.generateKeyPair();

        KEM kem = KEM.getInstance("ML-KEM-1024", "OpenJCEPlus");
        System.out.println("External key algorithm: "+ keyPair.getPublic().getAlgorithm());

        try {
            KEM.Encapsulator encapsulator = kem.newEncapsulator(keyPair.getPublic());
            System.out.println("a ML-KEM-1024 KEM instance should not accept "+ "an ML-KEM-512 key");
            System.out.println("Encapsulation size: "+ encapsulator.encapsulationSize());

        } catch (InvalidKeyException e) {
            System.out.println("Mismatched parameter set was rejected");
            e.printStackTrace();
        }
    }
}

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