Class RFC9980Utils
java.lang.Object
org.bouncycastle.openpgp.operator.RFC9980Utils
Byte-level building blocks of the ML-KEM + ECDH composite encryption schemes of RFC 9980 that are shared by
the lightweight (
.bc) and JCA (.jcajce) operators: the key combiner of sec. 4.2.1
and the PKESK algorithm-specific field layout of sec. 4.3.1. The composite signature schemes need no such
helpers - their signatures are the plain concatenation of the two component signatures.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final byte[]The domain separation constant of the key combiner (RFC 9980 sec.static final intThe symmetric algorithm the composite schemes wrap the session key with (RFC 9980 sec. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckV3SessionKey(int symmetricKeyAlgorithm, byte[] sessionKey) Check that a session key unwrapped from a v3 PKESK packet of a composite scheme is consistent with the symmetric algorithm octet the packet carries in the clear: the algorithm MUST be an AES variant and the key length MUST match it (RFC 9980 sec.static byte[]deriveKEK(PGPDigestCalculator sha3_256, byte[] mlkemKeyShare, byte[] ecdhKeyShare, byte[] ecdhCipherText, byte[] ecdhPublicKey, int algorithmId) Compute the key encryption key of the composite scheme (RFC 9980 sec.static intgetV3SymmetricAlgorithmOffset(int algorithmId) Return the offset of the symmetric algorithm octet in the algorithm-specific field of a v3 PKESK packet of a composite scheme: just past the two ciphertexts and the size octet.static booleanisAllowedV3PKESKSymmetricAlgorithm(int symmetricKeyAlgorithm) Return true if the symmetric algorithm may be named by a v3 PKESK packet of a composite scheme.static byte[][]parseEncryptedSessionKey(byte[] enc, int algorithmId, boolean containsSKAlg) Parse the algorithm-specific field of a PKESK packet of a composite scheme (RFC 9980 sec.
-
Field Details
-
DOM_SEP
public static final byte[] DOM_SEPThe domain separation constant of the key combiner (RFC 9980 sec. 4.2.1): the UTF-8 encoding of "OpenPGPCompositeKDFv1". -
KEY_WRAP_ALGORITHM
public static final int KEY_WRAP_ALGORITHMThe symmetric algorithm the composite schemes wrap the session key with (RFC 9980 sec. 4.2): AES-256 key wrap as per RFC 3394.- See Also:
-
-
Method Details
-
deriveKEK
public static byte[] deriveKEK(PGPDigestCalculator sha3_256, byte[] mlkemKeyShare, byte[] ecdhKeyShare, byte[] ecdhCipherText, byte[] ecdhPublicKey, int algorithmId) throws PGPException Compute the key encryption key of the composite scheme (RFC 9980 sec. 4.2.1):KEK = SHA3-256(mlkemKeyShare || ecdhKeyShare || ecdhCipherText || ecdhPublicKey || algId || domSep || len(domSep))
- Parameters:
sha3_256- a fresh digest calculator forHashAlgorithmTags.SHA3_256mlkemKeyShare- the ML-KEM key share (shared secret key) as an octet stringecdhKeyShare- the ECDH key share as an octet stringecdhCipherText- the ECDH ciphertext (the ephemeral public key) as an octet stringecdhPublicKey- the ECDH public key of the recipient as an octet stringalgorithmId- the OpenPGP algorithm ID of the public key encryption algorithm- Returns:
- the 32 octet KEK
- Throws:
PGPException- if the digest calculator is not SHA3-256 or the KEK cannot be computed
-
isAllowedV3PKESKSymmetricAlgorithm
public static boolean isAllowedV3PKESKSymmetricAlgorithm(int symmetricKeyAlgorithm) Return true if the symmetric algorithm may be named by a v3 PKESK packet of a composite scheme. RFC 9980 sec. 4.3.1 restricts it to AES-128, AES-192 and AES-256.- Parameters:
symmetricKeyAlgorithm- symmetric key algorithm ID- Returns:
- true for the three AES key sizes
-
checkV3SessionKey
public static void checkV3SessionKey(int symmetricKeyAlgorithm, byte[] sessionKey) throws PGPException Check that a session key unwrapped from a v3 PKESK packet of a composite scheme is consistent with the symmetric algorithm octet the packet carries in the clear: the algorithm MUST be an AES variant and the key length MUST match it (RFC 9980 sec. 4.3.1).- Parameters:
symmetricKeyAlgorithm- symmetric key algorithm ID from the PKESK packetsessionKey- the unwrapped session key- Throws:
PGPException- if the algorithm is not AES or the key length does not match it
-
parseEncryptedSessionKey
public static byte[][] parseEncryptedSessionKey(byte[] enc, int algorithmId, boolean containsSKAlg) throws PGPException Parse the algorithm-specific field of a PKESK packet of a composite scheme (RFC 9980 sec. 4.3.1):ecdhCipherText || mlkemCipherText || len(C, symAlgId) (|| symAlgId) || C
where the one-octet symAlgId is present only in a v3 packet.- Parameters:
enc- the PKESK's encrypted session key dataalgorithmId- the public key algorithm ID of the packet, which fixes the two ciphertext lengthscontainsSKAlg- whether the packet version carries the symmetric-key algorithm octet (v3)- Returns:
- a four-element array of the ECDH ciphertext, the ML-KEM ciphertext, the wrapped session key C, and the symmetric algorithm octet (a one-element array for a v3 packet, empty otherwise)
- Throws:
PGPException- if the data is shorter than its declared lengths require
-
getV3SymmetricAlgorithmOffset
public static int getV3SymmetricAlgorithmOffset(int algorithmId) Return the offset of the symmetric algorithm octet in the algorithm-specific field of a v3 PKESK packet of a composite scheme: just past the two ciphertexts and the size octet.- Parameters:
algorithmId- the public key algorithm ID of the packet- Returns:
- offset of the symmetric algorithm octet
-