Class PublicKeyUtils
java.lang.Object
org.bouncycastle.bcpg.PublicKeyUtils
Utility methods related to OpenPGP public key algorithms.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanisAlgorithmAllowedForKeyVersion(int publicKeyAlgorithm, int keyVersion) Return true, if RFC 9980 permits the public key algorithm in a key packet of the given version.static booleanisEncryptionAlgorithm(int publicKeyAlgorithm) Return true, if the public key algorithm that corresponds to the given ID is capable of encryption.static booleanisMLDSACompositeAlgorithm(int publicKeyAlgorithm) Return true, if the public key algorithm is one of the ML-DSA + EdDSA composite signature algorithms of RFC 9980 sec.static booleanisMLKEMCompositeAlgorithm(int publicKeyAlgorithm) Return true, if the public key algorithm is one of the ML-KEM + ECDH composite encryption algorithms of RFC 9980 sec.static booleanisPQCAlgorithm(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 booleanisSigningAlgorithm(int publicKeyAlgorithm) Return true, if the public key algorithm that corresponds to the given ID is capable of signing.static booleanisSLHDSAAlgorithm(int publicKeyAlgorithm) Return true, if the public key algorithm is one of the SLH-DSA signature algorithms of RFC 9980 sec.static booleanisX25519Key(PublicKeyPacket publicKeyPacket) Return true, if the passed inPublicKeyPacketis based on X25519, either the legacy variant viaPublicKeyAlgorithmTags.ECDHover curve25519, or the modernPublicKeyAlgorithmTags.X25519.
-
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_Ed25519andPublicKeyAlgorithmTags.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_128fandPublicKeyAlgorithmTags.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_X25519andPublicKeyAlgorithmTags.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 ofPublicKeyAlgorithmTags.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 idkeyVersion- key packet version- Returns:
- false if RFC 9980 forbids the algorithm in a key of that version, true otherwise
- See Also:
-
isX25519Key
Return true, if the passed inPublicKeyPacketis based on X25519, either the legacy variant viaPublicKeyAlgorithmTags.ECDHover curve25519, or the modernPublicKeyAlgorithmTags.X25519.- Parameters:
publicKeyPacket- public key packet- Returns:
- true if the key is an X25519 key
-