java.lang.Object
java.security.SignatureSpi
java.security.Signature
net.i2p.crypto.eddsa.EdDSAEngine
- Direct Known Subclasses:
RedDSAEngine
EdDSA signature engine implementing the Java Signature API. Supports both standard streaming and one-shot operation modes for efficiency.
Field Summary
FieldsModifier and TypeFieldDescriptionprotected MessageDigestThe message digest used for signing/verification.static final AlgorithmParameterSpecTo efficiently sign or verify data in one shot, pass this to setParameters() after initSign() or initVerify() but BEFORE THE FIRST AND ONLY update(data) or update(data, off, len).static final StringThe signature algorithm name.Fields inherited from class Signature
SIGN, state, UNINITIALIZED, VERIFYFields inherited from class SignatureSpi
appRandomConstructor Summary
ConstructorsConstructorDescriptionNo specific EdDSA-internal hash requested, allows any EdDSA key.EdDSAEngine(MessageDigest digest) Specific EdDSA-internal hash requested, only matching keys will be allowed.Method Summary
All MethodsModifier and TypeMethodDescriptionprotected voiddigestInitSign(EdDSAPrivateKey privKey) Initialize the digest for signing.protected voidengineInitSign(PrivateKey privateKey) protected voidengineInitVerify(PublicKey publicKey) protected voidOnly the one-shot mode parameter specification is supported.protected byte[]protected voidengineUpdate(byte b) Update the signature with one byte.protected voidengineUpdate(byte[] b, int off, int len) Update the signature with the given bytes.protected booleanengineVerify(byte[] sigBytes) byte[]signOneShot(byte[] data) To efficiently sign all the data in one shot, if it is available, use this method, which will avoid copying the data.byte[]signOneShot(byte[] data, int off, int len) To efficiently sign all the data in one shot, if it is available, use this method, which will avoid copying the data.booleanverifyOneShot(byte[] data, byte[] signature) To efficiently verify all the data in one shot, if it is available, use this method, which will avoid copying the data.booleanverifyOneShot(byte[] data, byte[] signature, int sigoff, int siglen) To efficiently verify all the data in one shot, if it is available, use this method, which will avoid copying the data.booleanverifyOneShot(byte[] data, int off, int len, byte[] signature) To efficiently verify all the data in one shot, if it is available, use this method, which will avoid copying the data.booleanverifyOneShot(byte[] data, int off, int len, byte[] signature, int sigoff, int siglen) To efficiently verify all the data in one shot, if it is available, use this method, which will avoid copying the data.Methods inherited from class Signature
clone, getAlgorithm, getInstance, getInstance, getInstance, getParameters, getProvider, initSign, initSign, initVerify, initVerify, setParameter, sign, sign, toString, update, update, update, update, verify, verifyMethods inherited from class SignatureSpi
engineGetParameters, engineInitSign, engineSign, engineUpdate, engineVerify
Field Details
SIGNATURE_ALGORITHM
The signature algorithm name.- See Also:
digest
The message digest used for signing/verification.ONE_SHOT_MODE
To efficiently sign or verify data in one shot, pass this to setParameters() after initSign() or initVerify() but BEFORE THE FIRST AND ONLY update(data) or update(data, off, len). The data reference will be saved and then used in sign() or verify() without copying the data. Violate these rules and you will get a SignatureException.
Constructor Details
EdDSAEngine
public EdDSAEngine()No specific EdDSA-internal hash requested, allows any EdDSA key.EdDSAEngine
Specific EdDSA-internal hash requested, only matching keys will be allowed.- Parameters:
digest- the hash algorithm that keys must have to sign or verify.
Method Details
engineInitSign
- Specified by:
engineInitSignin classSignatureSpi- Throws:
InvalidKeyException
digestInitSign
Initialize the digest for signing.- Parameters:
privKey- the private key
engineInitVerify
- Specified by:
engineInitVerifyin classSignatureSpi- Throws:
InvalidKeyException
engineUpdate
Update the signature with one byte.- Specified by:
engineUpdatein classSignatureSpi- Throws:
SignatureException- if in one-shot mode
engineUpdate
Update the signature with the given bytes.- Specified by:
engineUpdatein classSignatureSpi- Throws:
SignatureException- if one-shot rules are violated
engineSign
- Specified by:
engineSignin classSignatureSpi- Throws:
SignatureException
engineVerify
- Specified by:
engineVerifyin classSignatureSpi- Throws:
SignatureException
signOneShot
To efficiently sign all the data in one shot, if it is available, use this method, which will avoid copying the data.Same as:
setParameter(ONE_SHOT_MODE) update(data) sig = sign()
- Parameters:
data- the message to be signed- Returns:
- the R and S components, 2 * b/4 bytes long
- Throws:
SignatureException- if update() already called- See Also:
signOneShot
To efficiently sign all the data in one shot, if it is available, use this method, which will avoid copying the data.Same as:
setParameter(ONE_SHOT_MODE) update(data, off, len) sig = sign()
- Parameters:
data- byte array containing the message to be signedoff- the start of the message inside datalen- the length of the message- Returns:
- the R and S components, 2 * b/4 bytes long
- Throws:
SignatureException- if update() already called- See Also:
verifyOneShot
To efficiently verify all the data in one shot, if it is available, use this method, which will avoid copying the data.Same as:
setParameter(ONE_SHOT_MODE) update(data) ok = verify(signature)
- Parameters:
data- the message that was signedsignature- of the message- Returns:
- true if the signature is valid, false otherwise
- Throws:
SignatureException- if update() already called- See Also:
verifyOneShot
public boolean verifyOneShot(byte[] data, int off, int len, byte[] signature) throws SignatureException To efficiently verify all the data in one shot, if it is available, use this method, which will avoid copying the data.Same as:
setParameter(ONE_SHOT_MODE) update(data, off, len) ok = verify(signature)
- Parameters:
data- byte array containing the message that was signedoff- the start of the message inside datalen- the length of the messagesignature- of the message- Returns:
- true if the signature is valid, false otherwise
- Throws:
SignatureException- if update() already called- See Also:
verifyOneShot
public boolean verifyOneShot(byte[] data, byte[] signature, int sigoff, int siglen) throws SignatureException To efficiently verify all the data in one shot, if it is available, use this method, which will avoid copying the data.Same as:
setParameter(ONE_SHOT_MODE) update(data) ok = verify(signature, sigoff, siglen)
- Parameters:
data- the message that was signedsignature- byte array containing the signaturesigoff- the start of the signaturesiglen- the length of the signature- Returns:
- true if the signature is valid, false otherwise
- Throws:
SignatureException- if update() already called- See Also:
verifyOneShot
public boolean verifyOneShot(byte[] data, int off, int len, byte[] signature, int sigoff, int siglen) throws SignatureException To efficiently verify all the data in one shot, if it is available, use this method, which will avoid copying the data.Same as:
setParameter(ONE_SHOT_MODE) update(data, off, len) ok = verify(signature, sigoff, siglen)
- Parameters:
data- byte array containing the message that was signedoff- the start of the message inside datalen- the length of the messagesignature- byte array containing the signaturesigoff- the start of the signaturesiglen- the length of the signature- Returns:
- true if the signature is valid, false otherwise
- Throws:
SignatureException- if update() already called- See Also:
engineSetParameter
protected void engineSetParameter(AlgorithmParameterSpec spec) throws InvalidAlgorithmParameterException Only the one-shot mode parameter specification is supported.- Overrides:
engineSetParameterin classSignatureSpi- Throws:
InvalidAlgorithmParameterException- if spec is ONE_SHOT_MODE and update() already called- See Also: