java.lang.Object
org.apache.xml.security.encryption.keys.content.derivedKey.ConcatKDF
All Implemented Interfaces:
DerivationAlgorithm<ConcatKDFParams>

public class ConcatKDF extends Object implements DerivationAlgorithm<ConcatKDFParams>
Key DerivationAlgorithm implementation, defined in Section 5.8.1 of NIST SP 800-56A [SP800-56A], and is equivalent to the KDF3 function defined in ANSI X9.44-2007 [ANSI-X9-44-2007] when the contents of the OtherInfo parameter is structured as in NIST SP 800-56A.

Identifier of the key derivation algorithm: http://www.w3.org/2009/xmlenc11#ConcatKDF

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final System.Logger
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private static byte[]
    concatParameters(String... parameters)
    Simple method to concatenate non-padded bitstream ConcatKDF parameters.
    byte[]
    deriveKey(byte[] sharedSecret, ConcatKDFParams concatKDFParams)
    Derives a key from the shared secret and other concat kdf parameters.
    private static int
    getSize(byte[] array)
    Method returns the size of the array or 0 if the array is null.
    private static byte[]
    parseBitString(String kdfParameter)
    The method validates the bitstring parameter structure and returns byte array of the parameter.

    Methods inherited from class java.lang.Object

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

  • Constructor Details

    • ConcatKDF

      public ConcatKDF()
  • Method Details

    • deriveKey

      public byte[] deriveKey(byte[] sharedSecret, ConcatKDFParams concatKDFParams) throws XMLSecurityException
      Derives a key from the shared secret and other concat kdf parameters.
      Specified by:
      deriveKey in interface DerivationAlgorithm<ConcatKDFParams>
      Parameters:
      sharedSecret - The "shared" secret used for the key derivation (e.g. the secret key)
      concatKDFParams - The concat key derivation parameters
      Returns:
      the derived key bytes
      Throws:
      IllegalArgumentException - if the concat KDF parameters are not set
      XMLSecurityException - if the key derivation parameters are invalid
    • concatParameters

      private static byte[] concatParameters(String... parameters) throws XMLEncryptionException
      Simple method to concatenate non-padded bitstream ConcatKDF parameters. If parameters are null the value is ignored.
      Parameters:
      parameters - the parameters to concatenate
      Returns:
      the concatenated parameters as byte array
      Throws:
      XMLEncryptionException
    • parseBitString

      private static byte[] parseBitString(String kdfParameter) throws XMLEncryptionException
      The method validates the bitstring parameter structure and returns byte array of the parameter.

      The bitstring is divided into octets using big-endian encoding. Parameter starts with two characters (hex number) defining the number of padding bits followed by hex-string. The length of the bitstring is not a multiple of 8 then add padding bits (value 0) as necessary to the last octet to make it a multiple of 8.

      Parameters:
      kdfParameter - the parameter to parse
      Returns:
      the parsed parameter as byte array
      Throws:
      XMLEncryptionException
    • getSize

      private static int getSize(byte[] array)
      Method returns the size of the array or 0 if the array is null.
      Parameters:
      array - the array to get the size from
      Returns:
      the size of the array or 0 if the array is null