Class CommonEdDSASignatureContext

java.lang.Object
zeroecho.core.alg.common.eddsa.CommonEdDSASignatureContext
All Implemented Interfaces:
Closeable, AutoCloseable, CryptoContext, SignatureContext, TagEngine<Signature>
Direct Known Subclasses:
Ed25519SignatureContext, Ed448SignatureContext

public class CommonEdDSASignatureContext extends Object implements SignatureContext
Base class for EdDSA signature contexts that adapts a JCA Signature for streaming sign and verify.

This class is a thin adapter over GenericJcaSignatureContext: it wires the JCA signature name (for example, "Ed25519" or "Ed448") and a fixed tag length, then delegates all SignatureContext operations to the internal delegate. Concrete subclasses such as Ed25519SignatureContext and Ed448SignatureContext expose role-specific contexts for signing or verifying.

Responsibilities

Thread-safety

Instances are stateful and not guaranteed to be thread-safe. Use one context per signing or verification pipeline.

Since:
1.0
  • Constructor Details

    • CommonEdDSASignatureContext

      protected CommonEdDSASignatureContext(CryptoAlgorithm algorithm, PrivateKey privateKey, String jcaSignatureName, int tagLength) throws GeneralSecurityException
      Constructs a signing context for the given EdDSA algorithm.

      The created context operates in SIGN mode. The JCA engine is obtained using the supplied jcaSignatureName, and the produced signature length is fixed to tagLength.

      Parameters:
      algorithm - associated algorithm descriptor; must not be null
      privateKey - private key used for signing; must not be null
      jcaSignatureName - JCA signature name (for example, "Ed25519" or "Ed448"); must not be null
      tagLength - fixed signature length in bytes (64 for Ed25519, 114 for Ed448)
      Throws:
      GeneralSecurityException - if the JCA provider cannot initialize the signature engine
      NullPointerException - if any argument is null
    • CommonEdDSASignatureContext

      protected CommonEdDSASignatureContext(CryptoAlgorithm algorithm, PublicKey publicKey, String jcaSignatureName, int tagLength) throws GeneralSecurityException
      Constructs a verification context for the given EdDSA algorithm.

      The created context operates in VERIFY mode. The JCA engine is obtained using the supplied jcaSignatureName, and the expected signature length is fixed to tagLength.

      Parameters:
      algorithm - associated algorithm descriptor; must not be null
      publicKey - public key used for verification; must not be null
      jcaSignatureName - JCA signature name (for example, "Ed25519" or "Ed448"); must not be null
      tagLength - fixed signature length in bytes (64 for Ed25519, 114 for Ed448)
      Throws:
      GeneralSecurityException - if the JCA provider cannot initialize the signature engine
      NullPointerException - if any argument is null
  • Method Details

    • algorithm

      public CryptoAlgorithm algorithm()
      Returns the algorithm associated with this context.
      Specified by:
      algorithm in interface CryptoContext
      Returns:
      the CryptoAlgorithm descriptor
    • key

      public Key key()
      Returns the signing or verification key bound to this context.
      Specified by:
      key in interface CryptoContext
      Returns:
      the Key in use
    • close

      public void close()
      Releases resources associated with this context.

      After calling close(), further use of this context is undefined.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface CryptoContext
    • wrap

      public InputStream wrap(InputStream upstream) throws IOException
      Wraps an upstream InputStream so that all data read from it is processed by the underlying signature engine.

      In SIGN mode the wrapped stream emits the original data followed by a detached signature trailer at end-of-stream. In VERIFY mode the wrapped stream emits only the body and performs verification at end-of-stream against the expected tag.

      Specified by:
      wrap in interface TagEngine<Signature>
      Parameters:
      upstream - input stream supplying data to be signed or verified; must not be null
      Returns:
      a wrapped stream that updates the signature engine on read
      Throws:
      IOException - if stream wrapping fails
    • tagLength

      public int tagLength()
      Returns the fixed tag (signature) length in bytes for this algorithm.
      Specified by:
      tagLength in interface TagEngine<Signature>
      Returns:
      the signature length in bytes
    • setExpectedTag

      public void setExpectedTag(byte[] expected)
      Sets the expected signature (tag) used in VERIFY mode.

      Passing null clears the expected tag.

      Specified by:
      setExpectedTag in interface TagEngine<Signature>
      Parameters:
      expected - the signature bytes to verify against, or null to clear
    • setVerificationApproach

      public void setVerificationApproach(ThrowingBiPredicate.VerificationBiPredicate<Signature> strategy)
      Sets the verification approach used to compare the computed and expected signatures.
      Specified by:
      setVerificationApproach in interface TagEngine<Signature>
      Parameters:
      strategy - verification predicate to apply in VERIFY mode; may be decorated to throw or flag
    • getVerificationCore

      Returns the core verification predicate used by this context.

      The returned predicate typically delegates to Signature.verify(byte[]).

      Specified by:
      getVerificationCore in interface TagEngine<Signature>
      Returns:
      the base verification predicate