public final class EdDSAEngine extends Signature
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:
Option 2:
Modifier and Type | Field and Description |
---|---|
static AlgorithmParameterSpec |
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).
|
static String |
SIGNATURE_ALGORITHM |
SIGN, state, UNINITIALIZED, VERIFY
appRandom
Constructor and Description |
---|
EdDSAEngine()
No specific EdDSA-internal hash requested, allows any EdDSA key.
|
EdDSAEngine(MessageDigest digest)
Specific EdDSA-internal hash requested, only matching keys will be allowed.
|
Modifier and Type | Method and Description |
---|---|
protected Object |
engineGetParameter(String param)
Deprecated.
|
protected void |
engineInitSign(PrivateKey privateKey) |
protected void |
engineInitVerify(PublicKey publicKey) |
protected void |
engineSetParameter(AlgorithmParameterSpec spec) |
protected void |
engineSetParameter(String param,
Object value)
Deprecated.
|
protected byte[] |
engineSign() |
protected void |
engineUpdate(byte b) |
protected void |
engineUpdate(byte[] b,
int off,
int len) |
protected boolean |
engineVerify(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.
|
boolean |
verifyOneShot(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.
|
boolean |
verifyOneShot(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.
|
boolean |
verifyOneShot(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.
|
boolean |
verifyOneShot(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.
|
clone, getAlgorithm, getInstance, getInstance, getInstance, getParameter, getParameters, getProvider, initSign, initSign, initVerify, initVerify, setParameter, setParameter, sign, sign, toString, update, update, update, update, verify, verify
engineGetParameters, engineInitSign, engineSign, engineUpdate, engineVerify
public static final String SIGNATURE_ALGORITHM
public static final AlgorithmParameterSpec ONE_SHOT_MODE
public EdDSAEngine()
public EdDSAEngine(MessageDigest digest)
digest
- the hash algorithm that keys must have to sign or verify.protected void engineInitSign(PrivateKey privateKey) throws InvalidKeyException
engineInitSign
in class SignatureSpi
InvalidKeyException
protected void engineInitVerify(PublicKey publicKey) throws InvalidKeyException
engineInitVerify
in class SignatureSpi
InvalidKeyException
protected void engineUpdate(byte b) throws SignatureException
engineUpdate
in class SignatureSpi
SignatureException
- if in one-shot modeprotected void engineUpdate(byte[] b, int off, int len) throws SignatureException
engineUpdate
in class SignatureSpi
SignatureException
- if one-shot rules are violatedprotected byte[] engineSign() throws SignatureException
engineSign
in class SignatureSpi
SignatureException
protected boolean engineVerify(byte[] sigBytes) throws SignatureException
engineVerify
in class SignatureSpi
SignatureException
public byte[] signOneShot(byte[] data) throws SignatureException
setParameter(ONE_SHOT_MODE) update(data) sig = sign()
data
- the message to be signedSignatureException
- if update() already calledONE_SHOT_MODE
public byte[] signOneShot(byte[] data, int off, int len) throws SignatureException
setParameter(ONE_SHOT_MODE) update(data, off, len) sig = sign()
data
- byte array containing the message to be signedoff
- the start of the message inside datalen
- the length of the messageSignatureException
- if update() already calledONE_SHOT_MODE
public boolean verifyOneShot(byte[] data, byte[] signature) throws SignatureException
setParameter(ONE_SHOT_MODE) update(data) ok = verify(signature)
data
- the message that was signedsignature
- of the messageSignatureException
- if update() already calledONE_SHOT_MODE
public boolean verifyOneShot(byte[] data, int off, int len, byte[] signature) throws SignatureException
setParameter(ONE_SHOT_MODE) update(data, off, len) ok = verify(signature)
data
- byte array containing the message that was signedoff
- the start of the message inside datalen
- the length of the messagesignature
- of the messageSignatureException
- if update() already calledONE_SHOT_MODE
public boolean verifyOneShot(byte[] data, byte[] signature, int sigoff, int siglen) throws SignatureException
setParameter(ONE_SHOT_MODE) update(data) ok = verify(signature, sigoff, siglen)
data
- the message that was signedsignature
- byte array containing the signaturesigoff
- the start of the signaturesiglen
- the length of the signatureSignatureException
- if update() already calledONE_SHOT_MODE
public boolean verifyOneShot(byte[] data, int off, int len, byte[] signature, int sigoff, int siglen) throws SignatureException
setParameter(ONE_SHOT_MODE) update(data, off, len) ok = verify(signature, sigoff, siglen)
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 signatureSignatureException
- if update() already calledONE_SHOT_MODE
protected void engineSetParameter(AlgorithmParameterSpec spec) throws InvalidAlgorithmParameterException
engineSetParameter
in class SignatureSpi
InvalidAlgorithmParameterException
- if spec is ONE_SHOT_MODE and update() already calledONE_SHOT_MODE
protected void engineSetParameter(String param, Object value)
engineSetParameter
in class SignatureSpi
protected Object engineGetParameter(String param)
engineGetParameter
in class SignatureSpi
Copyright © 2019. All rights reserved.