java.lang.Object
net.i2p.crypto.HKDF

public final class HKDFextends Object
HMAC-based Key Derivation Function (HKDF) implementation using HMAC-SHA256.

This class implements the HKDF algorithm as specified in RFC 5869 for deriving cryptographic keys from input key material. It provides secure key expansion functionality essential for I2P's cryptographic operations including session key generation and key derivation.

Features and capabilities:

  • HMAC-SHA256 based derivation for cryptographic security
  • Support for one or two output keys with optional info parameter
  • Thread-safe operation with no internal state
  • Fixed 32-byte output size for consistency across I2P
  • Reusable instances for performance optimization
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create an instance bound to an application context.
  • Method Summary

    All Methods
    Modifier and Type
    Method
    Description
    void
    calculate(byte[] key, byte[] data, byte[] out)
    One output, no info.
    void
    calculate(byte[] key, byte[] data, byte[] out, byte[] out2, int off2)
    Two outputs, no info.
    void
    calculate(byte[] key, byte[] data, String info, byte[] out)
    One output with info.
    void
    calculate(byte[] key, byte[] data, String info, byte[] out, byte[] out2, int off2)
    Two outputs with info.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • HKDF

      public HKDF(I2PAppContext context)
      Create an instance bound to an application context.
      Parameters:
      context - the app context
  • Method Details

    • calculate

      public void calculate(byte[] key, byte[] data, byte[] out)
      One output, no info.
      Parameters:
      key - first 32 bytes used as the key
      data - the input data
      out - must be exactly 32 bytes
    • calculate

      public void calculate(byte[] key, byte[] data, String info, byte[] out)
      One output with info.
      Parameters:
      key - first 32 bytes used as the key
      data - the input data
      info - non-null ASCII, "" if none
      out - must be exactly 32 bytes
    • calculate

      public void calculate(byte[] key, byte[] data, byte[] out, byte[] out2, int off2)
      Two outputs, no info.
      Parameters:
      key - first 32 bytes used as the key
      data - the input data the output keys are derived from
      out - 32 bytes will be copied to here
      out2 - 32 bytes will be copied to here, may be the same as out
      off2 - offset for copy to out2
    • calculate

      public void calculate(byte[] key, byte[] data, String info, byte[] out, byte[] out2, int off2)
      Two outputs with info.
      Parameters:
      key - first 32 bytes used as the key
      data - the input data the output keys are derived from
      info - non-null ASCII, "" if none
      out - 32 bytes will be copied to here
      out2 - 32 bytes will be copied to here, may be the same as out
      off2 - offset for copy to out2