public class Nonce extends java.lang.Object implements CipherParameters
Modifier and Type | Field and Description |
---|---|
private ISAACRandomGenerator |
csprng |
private int |
cycle |
private static int |
MAXCYCLES |
private byte[] |
nonce |
Constructor and Description |
---|
Nonce(RandomGenerator csprng)
Construct the nonce with a deterministic CSPRNG, at the moment only ISAAC
engine is supported, but in the future other CSPRNG such as ISAAC+ will
also be supported.
|
Nonce(RandomGenerator csprng,
int lastCycle)
Construct the nonce with a deterministic CSPRNG, at the moment only ISAAC
engine is supported, but in the future other CSPRNG such as ISAAC+ will
also be supported.
|
Modifier and Type | Method and Description |
---|---|
int |
getCycle()
Get the current cycle, this is the number of nonces that have been
generated.
|
byte[] |
getNonce()
Accesses the current nonce, you should always execute the nextNonce()
method before accessing a nonce to ensure that a unique nonce has been
generated.
|
void |
init(byte[] seed,
int nonceLen)
Initialize the CSPRNG used by the nonce with the seed value provided so
that it is deterministic in generating random data.
|
byte[] |
nextNonce()
Generates the next nonce and returns it
|
void |
reSeed(byte[] seed)
Re-seeds the CSPRNG with the seed value specified, if your are using
this Nonce in a cryptographic system with more than one user/system
all systems must re-seed at the same state with the same seed value
in order to have the same sequence of nonces.
|
void |
reset()
Resets the CSPRNG used by the None, after resetting the CSPRNG you must
either re-initialize or re-seed it.
|
private ISAACRandomGenerator csprng
private byte[] nonce
private static final int MAXCYCLES
private int cycle
public Nonce(RandomGenerator csprng) throws java.lang.IllegalArgumentException
csprng
- Deterministic CSPRNG, currently only ISAAC is supportedjava.lang.IllegalArgumentException
- if the CSPRNG is not ISAACpublic Nonce(RandomGenerator csprng, int lastCycle) throws java.lang.IllegalArgumentException
csprng
- Deterministic CSPRNG, currently only ISAAC is supportedlastCycle
- The last cycle counter for the nonce generated during an previous
state of the Nonce object given the current CSPRNG, providing the last cycle prevents
security vulnerabilities of re-using nonce/IVs.java.lang.IllegalArgumentException
- if the CSPRNG is not ISAACpublic void init(byte[] seed, int nonceLen) throws MaxBytesExceededException, DataLengthException
seed
- The seed value for the CSPRNG, must be specifiednonceLen
- The default length of the nonce to generate, 0 to use
the length of the prior nonce value. Must be specified if Nonce was
constructed without a prior nonce value.MaxBytesExceededException
- If CSPRNG reaches MAXCYCLES trying to
return to the initial Nonce state, usually when the seed data provided is
different than the previous seed data used to generate the last nonce stateDataLengthException
- If the nonceLength was not provided and the object
was not instantiated with the prior nonce value of the last state.public byte[] nextNonce()
public byte[] getNonce()
public int getCycle()
public void reSeed(byte[] seed)
seed
- The seed value for the CSPRNG, must be specifiedpublic void reset()