Class DigestSpec
java.lang.Object
zeroecho.core.alg.digest.DigestSpec
- All Implemented Interfaces:
Describable, ContextSpec
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 nestedDigestSpec.Algorithm enum defines the
supported digest families:
DigestSpec.Algorithm.SHA_256,DigestSpec.Algorithm.SHA_384,DigestSpec.Algorithm.SHA_512- fixed-length SHA-2 digests.DigestSpec.Algorithm.SHA3_256,DigestSpec.Algorithm.SHA3_512- fixed-length SHA-3 digests.DigestSpec.Algorithm.SHAKE128,DigestSpec.Algorithm.SHAKE256- extendable-output functions (XOFs).
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:sha256(),sha384(),sha512()sha3_256(),sha3_512()shake128(int),shake256(int)(require explicit output length)
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnumeration of supported digest algorithms. -
Method Summary
Modifier and TypeMethodDescriptionReturns the digest algorithm.Returns a human-readable description of this specification.intReturns the requested output length in bytes.static DigestSpecsha256()Returns aDigestSpecfor SHA-256.static DigestSpecsha3_256()Returns aDigestSpecfor SHA3-256.static DigestSpecsha3_512()Returns aDigestSpecfor SHA3-512.static DigestSpecsha384()Returns aDigestSpecfor SHA-384.static DigestSpecsha512()Returns aDigestSpecfor SHA-512.static DigestSpecshake128(int outLen) Returns aDigestSpecfor SHAKE128 with the given output length.static DigestSpecshake256(int outLen) Returns aDigestSpecfor SHAKE256 with the given output length.
-
Method Details
-
sha256
-
sha384
-
sha512
-
sha3_256
-
sha3_512
-
shake128
Returns aDigestSpecfor 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- ifoutLen <= 0
-
shake256
Returns aDigestSpecfor 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- ifoutLen <= 0
-
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
Returns a human-readable description of this specification.For XOFs, the description includes the chosen output length, e.g.,
"SHAKE128(64B)".- Specified by:
descriptionin interfaceDescribable- Returns:
- description string
-