Class WfCryptoUtil
java.lang.Object
org.whiteflagprotocol.java.crypto.WfCryptoUtil
Whiteflag cryptographic utility class
This is a non-instantiatable utility class that performs cryptographic support functions. No implementation specific properties and methods are defined by this class.
- Since:
- 1.1
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Pattern
The regex pattern describing a valid hexadecimnal stringstatic final String
The "0x" prefix of a hexadecimal stringstatic final int
The radix of a hexadecimal digitstatic final String
The hash algorithm for the HKDF functionstatic final int
The bit size of a quadbit -
Method Summary
Modifier and TypeMethodDescriptionstatic final byte[]
convertToByteArray
(String hexstr) Converts a hexadecimal string to a byte arraystatic final String
convertToHexString
(byte[] byteArray) Converts a byte array to a hexadecimal stringstatic final byte[]
hkdf
(byte[] ikm, byte[] salt, byte[] info, int keyLength) Performs HKDF key and token derivation for Whiteflagstatic final String
Performs HKDF key and token derivation for Whiteflagprotected static final byte[]
hkdfExpand
(byte[] prk, byte[] info, int keyLength) Performs RFC 5869 HKDF Step 2: expandprotected static final byte[]
hkdfExtract
(byte[] ikm, byte[] salt) Performs RFC 5869 HKDF Step 1: extractstatic final void
zeroise
(byte[] byteArray) Zeroises a byte array
-
Field Details
-
HKDF_HASHALG
The hash algorithm for the HKDF function- See Also:
-
HEXPATTERN
The regex pattern describing a valid hexadecimnal string -
HEXPREFIX
The "0x" prefix of a hexadecimal string- See Also:
-
HEXRADIX
public static final int HEXRADIXThe radix of a hexadecimal digit- See Also:
-
QUADBIT
public static final int QUADBITThe bit size of a quadbit- See Also:
-
-
Method Details
-
zeroise
public static final void zeroise(byte[] byteArray) Zeroises a byte array- Parameters:
byteArray
- the byte array to be zeroised
-
convertToByteArray
Converts a hexadecimal string to a byte array- Parameters:
hexstr
- the hexadecimal string- Returns:
- a byte array
- Throws:
IllegalArgumentException
- if argument is not a hexadecimal string
-
convertToHexString
Converts a byte array to a hexadecimal string- Parameters:
byteArray
- the byte array- Returns:
- a hexadecimal string
-
hkdf
public static final byte[] hkdf(byte[] ikm, byte[] salt, byte[] info, int keyLength) Performs HKDF key and token derivation for WhiteflagThe HKDF function as defined in RFC 5869 to derive the tokens and encryption keys used for Whiteflag. This function performs the full HKDF expand and extract.
- Parameters:
ikm
- byte array with the input key materialsalt
- byte array with the cryptographic saltinfo
- byte array with information to bind the derived key to an intended contextkeyLength
- integer with the output key length in bytes- Returns:
- the output key material, i.e. the generated secret cryptographic key
- Whiteflag version:
- v1-draft.6
- Whiteflag standard x-reference:
- 5.2.3 Key and Token Derivation
-
hkdf
Performs HKDF key and token derivation for WhiteflagThis is a wrapper for the HKDF function allowing to provide the input as hexadecimal strings.
- Parameters:
ikm
- hexadecimal string with the input key materialsalt
- hexadecimal string the cryptographic saltinfo
- hexadecimal string information to bind the derived key to an intended contextkeyLength
- integer with the output key length in bytes- Returns:
- the output key material, i.e. the generated secret cryptographic key
-
hkdfExtract
protected static final byte[] hkdfExtract(byte[] ikm, byte[] salt) Performs RFC 5869 HKDF Step 1: extract- Parameters:
ikm
- the input key materialsalt
- the cryptographic salt- Returns:
- an intermediate pseudo random key
-
hkdfExpand
protected static final byte[] hkdfExpand(byte[] prk, byte[] info, int keyLength) Performs RFC 5869 HKDF Step 2: expand- Parameters:
prk
- the intermediate pseudo random keyinfo
- information to bind the derived key to an intended contextkeyLength
- the output key length in bytes- Returns:
- the output key material
-