Class MLKEMCompositePublicBCPGKey

All Implemented Interfaces:
BCPGKey, org.bouncycastle.util.Encodable

public class MLKEMCompositePublicBCPGKey extends OctetArrayBCPGKey
Public key of the ML-KEM + ECDH composite encryption algorithms PublicKeyAlgorithmTags.MLKEM768_X25519 and PublicKeyAlgorithmTags.MLKEM1024_X448 (RFC 9980 sec. 4.3.2.1): the fixed-length ECDH public key in the RFC 7748 encoding of its curve, followed by the fixed-length ML-KEM encapsulation key in the FIPS 203 encoding.

The component lengths are fixed by the algorithm ID (RFC 9980 Tables 3 and 4), so the key knows which algorithm it belongs to and the two components can be read back with getECDHPublicKey() and getMLKEMPublicKey().

See Also:
  • Constructor Details

    • MLKEMCompositePublicBCPGKey

      public MLKEMCompositePublicBCPGKey(int algorithm, BCPGInputStream in) throws IOException
      Parse the public key of the given composite algorithm from the packet stream.
      Parameters:
      algorithm - public key algorithm ID, PublicKeyAlgorithmTags.MLKEM768_X25519 or PublicKeyAlgorithmTags.MLKEM1024_X448
      in - packet input stream positioned at the algorithm-specific key material
      Throws:
      IOException - if the key cannot be read
    • MLKEMCompositePublicBCPGKey

      public MLKEMCompositePublicBCPGKey(int algorithm, byte[] ecdhPublicKey, byte[] mlkemPublicKey)
      Construct the public key of the given composite algorithm from its two components.
      Parameters:
      algorithm - public key algorithm ID, PublicKeyAlgorithmTags.MLKEM768_X25519 or PublicKeyAlgorithmTags.MLKEM1024_X448
      ecdhPublicKey - the X25519 (32 octets) or X448 (56 octets) public key
      mlkemPublicKey - the ML-KEM-768 (1184 octets) or ML-KEM-1024 (1568 octets) encapsulation key
  • Method Details

    • getAlgorithm

      public int getAlgorithm()
      Return the public key algorithm ID this key belongs to.
      Returns:
      PublicKeyAlgorithmTags.MLKEM768_X25519 or PublicKeyAlgorithmTags.MLKEM1024_X448
    • getECDHPublicKey

      public byte[] getECDHPublicKey()
      Return the ECDH (X25519 or X448) public key component.
      Returns:
      ECDH public key in RFC 7748 encoding
    • getMLKEMPublicKey

      public byte[] getMLKEMPublicKey()
      Return the ML-KEM encapsulation key component.
      Returns:
      ML-KEM public key in FIPS 203 encoding
    • getLength

      public static int getLength(int algorithm)
      Return the length of the algorithm-specific public key material for the given composite algorithm.
      Parameters:
      algorithm - public key algorithm ID
      Returns:
      total octet length of the ECDH and ML-KEM public keys
    • getECDHPublicKeyLength

      public static int getECDHPublicKeyLength(int algorithm)
      Return the length of the ECDH public key component (RFC 9980 Table 3).
      Parameters:
      algorithm - public key algorithm ID
      Returns:
      32 for X25519, 56 for X448
    • getMLKEMPublicKeyLength

      public static int getMLKEMPublicKeyLength(int algorithm)
      Return the length of the ML-KEM encapsulation key component (RFC 9980 Table 4).
      Parameters:
      algorithm - public key algorithm ID
      Returns:
      1184 for ML-KEM-768, 1568 for ML-KEM-1024
    • getMLKEMCiphertextLength

      public static int getMLKEMCiphertextLength(int algorithm)
      Return the length of the ML-KEM ciphertext carried in a PKESK packet (RFC 9980 Table 4).
      Parameters:
      algorithm - public key algorithm ID
      Returns:
      1088 for ML-KEM-768, 1568 for ML-KEM-1024