Class PublicKeyUtils

java.lang.Object
org.bouncycastle.bcpg.PublicKeyUtils

public class PublicKeyUtils extends Object
Utility methods related to OpenPGP public key algorithms.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    isAlgorithmAllowedForKeyVersion(int publicKeyAlgorithm, int keyVersion)
    Return true, if RFC 9980 permits the public key algorithm in a key packet of the given version.
    static boolean
    isEncryptionAlgorithm(int publicKeyAlgorithm)
    Return true, if the public key algorithm that corresponds to the given ID is capable of encryption.
    static boolean
    isMLDSACompositeAlgorithm(int publicKeyAlgorithm)
    Return true, if the public key algorithm is one of the ML-DSA + EdDSA composite signature algorithms of RFC 9980 sec.
    static boolean
    isMLKEMCompositeAlgorithm(int publicKeyAlgorithm)
    Return true, if the public key algorithm is one of the ML-KEM + ECDH composite encryption algorithms of RFC 9980 sec.
    static boolean
    isPQCAlgorithm(int publicKeyAlgorithm)
    Return true, if the public key algorithm is one of the post-quantum (PQ) or post-quantum/traditional (PQ/T) algorithms of RFC 9980: the ML-DSA + EdDSA and ML-KEM + ECDH composites and the SLH-DSA code points.
    static boolean
    isSigningAlgorithm(int publicKeyAlgorithm)
    Return true, if the public key algorithm that corresponds to the given ID is capable of signing.
    static boolean
    isSLHDSAAlgorithm(int publicKeyAlgorithm)
    Return true, if the public key algorithm is one of the SLH-DSA signature algorithms of RFC 9980 sec.
    static boolean
    isX25519Key(PublicKeyPacket publicKeyPacket)
    Return true, if the passed in PublicKeyPacket is based on X25519, either the legacy variant via PublicKeyAlgorithmTags.ECDH over curve25519, or the modern PublicKeyAlgorithmTags.X25519.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PublicKeyUtils

      public PublicKeyUtils()
  • Method Details

    • isSigningAlgorithm

      public static boolean isSigningAlgorithm(int publicKeyAlgorithm)
      Return true, if the public key algorithm that corresponds to the given ID is capable of signing.
      Parameters:
      publicKeyAlgorithm - public key algorithm id
      Returns:
      true if algorithm can sign
    • isEncryptionAlgorithm

      public static boolean isEncryptionAlgorithm(int publicKeyAlgorithm)
      Return true, if the public key algorithm that corresponds to the given ID is capable of encryption.
      Parameters:
      publicKeyAlgorithm - public key algorithm id
      Returns:
      true if algorithm can encrypt
    • isPQCAlgorithm

      public static boolean isPQCAlgorithm(int publicKeyAlgorithm)
      Return true, if the public key algorithm is one of the post-quantum (PQ) or post-quantum/traditional (PQ/T) algorithms of RFC 9980: the ML-DSA + EdDSA and ML-KEM + ECDH composites and the SLH-DSA code points.
      Parameters:
      publicKeyAlgorithm - public key algorithm id
      Returns:
      true if the algorithm is specified by RFC 9980
      See Also:
    • isMLDSACompositeAlgorithm

      public static boolean isMLDSACompositeAlgorithm(int publicKeyAlgorithm)
      Return true, if the public key algorithm is one of the ML-DSA + EdDSA composite signature algorithms of RFC 9980 sec. 5.
      Parameters:
      publicKeyAlgorithm - public key algorithm id
      Returns:
      true for PublicKeyAlgorithmTags.MLDSA65_Ed25519 and PublicKeyAlgorithmTags.MLDSA87_Ed448
    • isSLHDSAAlgorithm

      public static boolean isSLHDSAAlgorithm(int publicKeyAlgorithm)
      Return true, if the public key algorithm is one of the SLH-DSA signature algorithms of RFC 9980 sec. 6.
      Parameters:
      publicKeyAlgorithm - public key algorithm id
      Returns:
      true for PublicKeyAlgorithmTags.SLHDSA_SHAKE_128s, PublicKeyAlgorithmTags.SLHDSA_SHAKE_128f and PublicKeyAlgorithmTags.SLHDSA_SHAKE_256s
    • isMLKEMCompositeAlgorithm

      public static boolean isMLKEMCompositeAlgorithm(int publicKeyAlgorithm)
      Return true, if the public key algorithm is one of the ML-KEM + ECDH composite encryption algorithms of RFC 9980 sec. 4.
      Parameters:
      publicKeyAlgorithm - public key algorithm id
      Returns:
      true for PublicKeyAlgorithmTags.MLKEM768_X25519 and PublicKeyAlgorithmTags.MLKEM1024_X448
    • isAlgorithmAllowedForKeyVersion

      public static boolean isAlgorithmAllowedForKeyVersion(int publicKeyAlgorithm, int keyVersion)
      Return true, if RFC 9980 permits the public key algorithm in a key packet of the given version. All PQ(/T) algorithms are to be used only in v6 keys, with the single exception of PublicKeyAlgorithmTags.MLKEM768_X25519, which is also allowed in v4 encryption-capable subkeys (RFC 9980 sec. 3.5 and 4.3.2). The method has no opinion on algorithms outside RFC 9980 and returns true for them.
      Parameters:
      publicKeyAlgorithm - public key algorithm id
      keyVersion - key packet version
      Returns:
      false if RFC 9980 forbids the algorithm in a key of that version, true otherwise
      See Also:
    • isX25519Key

      public static boolean isX25519Key(PublicKeyPacket publicKeyPacket)
      Return true, if the passed in PublicKeyPacket is based on X25519, either the legacy variant via PublicKeyAlgorithmTags.ECDH over curve25519, or the modern PublicKeyAlgorithmTags.X25519.
      Parameters:
      publicKeyPacket - public key packet
      Returns:
      true if the key is an X25519 key