Class DigestSpec

java.lang.Object
zeroecho.core.alg.digest.DigestSpec
All Implemented Interfaces:
Describable, ContextSpec

public final class DigestSpec extends Object implements ContextSpec, Describable

Digest parameters for SHA-2, SHA-3, and SHAKE

DigestSpec is a context specification for the Sha2Sha3Algorithm, selecting which digest algorithm variant to use and, for extendable-output functions (XOFs), the desired output length.

Algorithm selection

The nested DigestSpec.Algorithm enum defines the supported digest families:

For fixed-length digests, the outputLenBytes() is always 0 (the digest length is implicit). For XOFs, a positive output length must be supplied at construction time.

Construction

Factory methods are provided for common cases:

Usage example

// Create a spec for SHAKE256 with 64-byte output
DigestSpec spec = DigestSpec.shake256(64);

// Use in context creation
DigestContext ctx = session.createContext(
        "DIGEST", KeyUsage.DIGEST, NullKey.INSTANCE, spec);

byte[] digest = ctx.doFinal(data);

Thread-safety

Instances are immutable and can be safely reused across threads.
Since:
1.0
See Also:
  • Method Details

    • sha256

      public static DigestSpec sha256()
      Returns a DigestSpec for SHA-256.
      Returns:
      spec for SHA-256
    • sha384

      public static DigestSpec sha384()
      Returns a DigestSpec for SHA-384.
      Returns:
      spec for SHA-384
    • sha512

      public static DigestSpec sha512()
      Returns a DigestSpec for SHA-512.
      Returns:
      spec for SHA-512
    • sha3_256

      public static DigestSpec sha3_256()
      Returns a DigestSpec for SHA3-256.
      Returns:
      spec for SHA3-256
    • sha3_512

      public static DigestSpec sha3_512()
      Returns a DigestSpec for SHA3-512.
      Returns:
      spec for SHA3-512
    • shake128

      public static DigestSpec shake128(int outLen)
      Returns a DigestSpec for SHAKE128 with the given output length.
      Parameters:
      outLen - desired output length in bytes (must be > 0)
      Returns:
      spec for SHAKE128 with the specified output length
      Throws:
      IllegalArgumentException - if outLen <= 0
    • shake256

      public static DigestSpec shake256(int outLen)
      Returns a DigestSpec for SHAKE256 with the given output length.
      Parameters:
      outLen - desired output length in bytes (must be > 0)
      Returns:
      spec for SHAKE256 with the specified output length
      Throws:
      IllegalArgumentException - if outLen <= 0
    • algorithm

      public DigestSpec.Algorithm algorithm()
      Returns the digest algorithm.
      Returns:
      algorithm enum constant
    • outputLenBytes

      public int outputLenBytes()
      Returns the requested output length in bytes.

      For fixed-length digests, this value is 0. For XOFs, this is the explicit length requested at construction.

      Returns:
      output length in bytes (0 if not applicable)
    • description

      public String description()
      Returns a human-readable description of this specification.

      For XOFs, the description includes the chosen output length, e.g., "SHAKE128(64B)".

      Specified by:
      description in interface Describable
      Returns:
      description string