Class HpkeUtil


  • public final class HpkeUtil
    extends java.lang.Object
    Collection of helper functions for HPKE.
    • Field Detail

      • BASE_MODE

        public static final byte[] BASE_MODE
      • AUTH_MODE

        public static final byte[] AUTH_MODE
      • X25519_HKDF_SHA256_KEM_ID

        public static final byte[] X25519_HKDF_SHA256_KEM_ID
      • P256_HKDF_SHA256_KEM_ID

        public static final byte[] P256_HKDF_SHA256_KEM_ID
      • P384_HKDF_SHA384_KEM_ID

        public static final byte[] P384_HKDF_SHA384_KEM_ID
      • P521_HKDF_SHA512_KEM_ID

        public static final byte[] P521_HKDF_SHA512_KEM_ID
      • HKDF_SHA256_KDF_ID

        public static final byte[] HKDF_SHA256_KDF_ID
      • HKDF_SHA384_KDF_ID

        public static final byte[] HKDF_SHA384_KDF_ID
      • HKDF_SHA512_KDF_ID

        public static final byte[] HKDF_SHA512_KDF_ID
      • AES_128_GCM_AEAD_ID

        public static final byte[] AES_128_GCM_AEAD_ID
      • AES_256_GCM_AEAD_ID

        public static final byte[] AES_256_GCM_AEAD_ID
      • CHACHA20_POLY1305_AEAD_ID

        public static final byte[] CHACHA20_POLY1305_AEAD_ID
      • EMPTY_SALT

        public static final byte[] EMPTY_SALT
    • Method Detail

      • intToByteArray

        public static byte[] intToByteArray​(int capacity,
                                            int value)
        Transforms a passed value to an MSB first byte array with the size of the specified capacity. (i.e., Bytes.intToByteArray(int, int) with MSB first instead of LSB first).

        The HPKE standard defines this function as I2OSP(n, w) where w = capacity and n = value.

        https://www.rfc-editor.org/rfc/rfc9180.html#name-notation

        Parameters:
        capacity - size of the resulting byte array
        value - that should be represented as a byte array
      • getEncodedPublicKeyLength

        public static int getEncodedPublicKeyLength​(HpkeParameters.KemId kemId)
                                             throws java.security.GeneralSecurityException
        Lengths from 'Npk' column in https://www.rfc-editor.org/rfc/rfc9180.html#table-2.
        Throws:
        java.security.GeneralSecurityException
      • encodingSizeInBytes

        public static int encodingSizeInBytes​(HpkeParameters.KemId kemId)
        Returns the encapsulated key length (in bytes) for the specified kemId. This value corresponds to the 'Nenc' column in the following table.

        https://www.rfc-editor.org/rfc/rfc9180.html#name-key-encapsulation-mechanism.

      • getEncodedPrivateKeyLength

        public static int getEncodedPrivateKeyLength​(HpkeParameters.KemId kemId)
                                              throws java.security.GeneralSecurityException
        Lengths from 'Nsk' column in https://www.rfc-editor.org/rfc/rfc9180.html#table-2.
        Throws:
        java.security.GeneralSecurityException