Class WfCryptoUtil

java.lang.Object
org.whiteflagprotocol.java.crypto.WfCryptoUtil

public final class WfCryptoUtil extends Object
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

    Fields
    Modifier and Type
    Field
    Description
    static final Pattern
    The regex pattern describing a valid hexadecimnal string
    static final String
    The "0x" prefix of a hexadecimal string
    static final int
    The radix of a hexadecimal digit
    static final String
    The hash algorithm for the HKDF function
    static final int
    The bit size of a quadbit
  • Method Summary

    Modifier and Type
    Method
    Description
    static final byte[]
    Converts a hexadecimal string to a byte array
    static final String
    convertToHexString(byte[] byteArray)
    Converts a byte array to a hexadecimal string
    static final byte[]
    hkdf(byte[] ikm, byte[] salt, byte[] info, int keyLength)
    Performs HKDF key and token derivation for Whiteflag
    static final String
    hkdf(String ikm, String salt, String info, int keyLength)
    Performs HKDF key and token derivation for Whiteflag
    protected static final byte[]
    hkdfExpand(byte[] prk, byte[] info, int keyLength)
    Performs RFC 5869 HKDF Step 2: expand
    protected static final byte[]
    hkdfExtract(byte[] ikm, byte[] salt)
    Performs RFC 5869 HKDF Step 1: extract
    static final void
    zeroise(byte[] byteArray)
    Zeroises a byte array

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • HKDF_HASHALG

      public static final String HKDF_HASHALG
      The hash algorithm for the HKDF function
      See Also:
    • HEXPATTERN

      public static final Pattern HEXPATTERN
      The regex pattern describing a valid hexadecimnal string
    • HEXPREFIX

      public static final String HEXPREFIX
      The "0x" prefix of a hexadecimal string
      See Also:
    • HEXRADIX

      public static final int HEXRADIX
      The radix of a hexadecimal digit
      See Also:
    • QUADBIT

      public static final int QUADBIT
      The 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

      public static final byte[] convertToByteArray(String hexstr)
      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

      public static final String convertToHexString(byte[] byteArray)
      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 Whiteflag

      The 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 material
      salt - byte array with the cryptographic salt
      info - byte array with information to bind the derived key to an intended context
      keyLength - 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

      public static final String hkdf(String ikm, String salt, String info, int keyLength)
      Performs HKDF key and token derivation for Whiteflag

      This is a wrapper for the HKDF function allowing to provide the input as hexadecimal strings.

      Parameters:
      ikm - hexadecimal string with the input key material
      salt - hexadecimal string the cryptographic salt
      info - hexadecimal string information to bind the derived key to an intended context
      keyLength - 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 material
      salt - 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 key
      info - information to bind the derived key to an intended context
      keyLength - the output key length in bytes
      Returns:
      the output key material