java.lang.Object
java.security.SignatureSpi
java.security.Signature
net.i2p.crypto.eddsa.EdDSAEngine
net.i2p.crypto.eddsa.RedDSAEngine
Signing and verification for REdDSA using SHA-512 and the Ed25519 curve. Ref: Zcash Protocol Specification, Version 2018.0-beta-33 [Overwinter+Sapling] Sections 4.1.6.1, 4.1.6.2, 5.4.6
The EdDSA sign and verify algorithms do not interact well with the Java Signature API, as one or more update() methods must be called before sign() or verify(). Using the standard API, this implementation must copy and buffer all data passed in via update().
This implementation offers two ways to avoid this copying, but only if all data to be signed or verified is available in a single byte array.
Option 1:
- Call initSign() or initVerify() as usual.
- Call setParameter(ONE_SHOT_MODE)
- Call update(byte[]) or update(byte[], int, int) exactly once
- Call sign() or verify() as usual.
- If doing additional one-shot signs or verifies with this object, you must call setParameter(ONE_SHOT_MODE) each time
Option 2:
- Call initSign() or initVerify() as usual.
- Call one of the signOneShot() or verifyOneShot() methods.
- If doing additional one-shot signs or verifies with this object, just call signOneShot() or verifyOneShot() again.
Field Summary
Fields inherited from class EdDSAEngine
digest, ONE_SHOT_MODE, SIGNATURE_ALGORITHMModifier 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.RedDSAEngine(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.Methods inherited from class EdDSAEngine
engineInitSign, engineInitVerify, engineSetParameter, engineSign, engineUpdate, engineUpdate, engineVerify, signOneShot, signOneShot, verifyOneShot, verifyOneShot, verifyOneShot, verifyOneShotModifier and TypeMethodDescriptionprotected 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
Constructor Details
RedDSAEngine
public RedDSAEngine()No specific EdDSA-internal hash requested, allows any EdDSA key.RedDSAEngine
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
digestInitSign
Description copied from class:EdDSAEngineInitialize the digest for signing.- Overrides:
digestInitSignin classEdDSAEngine- Parameters:
privKey- the private key