Class Sha2Sha3Algorithm


public final class Sha2Sha3Algorithm extends AbstractCryptoAlgorithm

SHA-2, SHA-3, and SHAKE digest algorithms

Implementation of the CryptoAlgorithm abstraction for unkeyed hash functions from the SHA-2 and SHA-3 families, including extendable-output functions (XOFs) such as SHAKE128 and SHAKE256.

This algorithm is registered under the canonical identifier "DIGEST" with the display name "SHA-2/SHA-3/SHAKE".

Capabilities

The algorithm declares a single capability:

Provider model

Internally, this class delegates to the JCA MessageDigest implementation corresponding to the chosen digest variant. The constructor performs lookup via MessageDigest.getInstance(String), and wraps the result in a JcaDigestContext.

Usage example


 // Acquire algorithm via static registry
 CryptoAlgorithm algo = CryptoAlgorithms.require("DIGEST");

 // Create a digest context for SHA3-512
 DigestContext ctx = CryptoAlgorithms.create(
         "DIGEST", KeyUsage.DIGEST, NullKey.INSTANCE, DigestSpec.sha3_512());

 // Stream data into the digest
 ctx.update(inputStream);

 byte[] hash = ctx.doFinal();
 

The NullKey sentinel must always be provided for the key argument since digests are unkeyed functions. The DigestSpec determines the exact digest variant (SHA-256, SHA-512, SHA3-256, SHAKE128, etc.).

Thread-safety

The Sha2Sha3Algorithm instance is immutable and can be shared across threads. The created DigestContext objects are not thread-safe and must not be used concurrently.
Since:
1.0
  • Constructor Details

    • Sha2Sha3Algorithm

      public Sha2Sha3Algorithm()
      Constructs the SHA-2/SHA-3/SHAKE digest algorithm definition and registers its Capability.

      The default digest specification is DigestSpec.sha256(), ensuring compatibility with common tests and catalog listings.