public class RFC9980Utils
extends java.lang.Object
.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.| Modifier and Type | Field and Description |
|---|---|
static byte[] |
DOM_SEP
The domain separation constant of the key combiner (RFC 9980 sec. 4.2.1): the UTF-8 encoding of
"OpenPGPCompositeKDFv1".
|
static int |
KEY_WRAP_ALGORITHM
The symmetric algorithm the composite schemes wrap the session key with (RFC 9980 sec. 4.2):
AES-256 key wrap as per RFC 3394.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
checkV3SessionKey(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. 4.3.1).
|
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. 4.2.1):
KEK = SHA3-256(mlkemKeyShare || ecdhKeyShare || ecdhCipherText || ecdhPublicKey || algId || domSep || len(domSep))
|
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.
|
static boolean |
isAllowedV3PKESKSymmetricAlgorithm(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. 4.3.1):
ecdhCipherText || mlkemCipherText || len(C, symAlgId) (|| symAlgId) || C
where the one-octet symAlgId is present only in a v3 packet.
|
public static final byte[] DOM_SEP
public static final int KEY_WRAP_ALGORITHM
public static byte[] deriveKEK(PGPDigestCalculator sha3_256, byte[] mlkemKeyShare, byte[] ecdhKeyShare, byte[] ecdhCipherText, byte[] ecdhPublicKey, int algorithmId) throws PGPException
KEK = SHA3-256(mlkemKeyShare || ecdhKeyShare || ecdhCipherText || ecdhPublicKey || algId || domSep || len(domSep))
sha3_256 - a fresh digest calculator for HashAlgorithmTags.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 algorithmPGPException - if the digest calculator is not SHA3-256 or the KEK cannot be computedpublic static boolean isAllowedV3PKESKSymmetricAlgorithm(int symmetricKeyAlgorithm)
symmetricKeyAlgorithm - symmetric key algorithm IDpublic static void checkV3SessionKey(int symmetricKeyAlgorithm,
byte[] sessionKey)
throws PGPException
symmetricKeyAlgorithm - symmetric key algorithm ID from the PKESK packetsessionKey - the unwrapped session keyPGPException - if the algorithm is not AES or the key length does not match itpublic static byte[][] parseEncryptedSessionKey(byte[] enc,
int algorithmId,
boolean containsSKAlg)
throws PGPException
ecdhCipherText || mlkemCipherText || len(C, symAlgId) (|| symAlgId) || Cwhere the one-octet symAlgId is present only in a v3 packet.
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)PGPException - if the data is shorter than its declared lengths requirepublic static int getV3SymmetricAlgorithmOffset(int algorithmId)
algorithmId - the public key algorithm ID of the packet