Class RandomData
- java.lang.Object
-
- javacard.security.RandomData
-
- Direct Known Subclasses:
RandomData.OneShot
public abstract class RandomData extends Object
TheRandomData
abstract class is the base class for random number generation. Implementations ofRandomData
algorithms must extend this class and implement all the abstract methods.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RandomData.OneShot
TheOneShot
class is a specialization of theRandomData
class intended to support efficient one-shot random data generation operations that may avoid persistent memory writes entirely.
-
Field Summary
Fields Modifier and Type Field Description static byte
ALG_FAST
Utility random number generation algorithm.static byte
ALG_KEYGENERATION
This algorithm creates random numbers suitable to be used for key and nonce generation.static byte
ALG_PRESEEDED_DRBG
Deterministic Random Bit Generator (DRBG) algorithm.static byte
ALG_PSEUDO_RANDOM
Deprecated.As of release 3.0.5.static byte
ALG_SECURE_RANDOM
Deprecated.As of release 3.0.5.static byte
ALG_TRNG
True Random Number Generation (TRNG) algorithm.
-
Constructor Summary
Constructors Modifier Constructor Description protected
RandomData()
Protected constructor for subclassing.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description abstract void
generateData(byte[] buffer, short offset, short length)
Deprecated.As of release 3.0.5, replaced bynextBytes(byte[], short, short)
.abstract byte
getAlgorithm()
Gets the random number generation algorithm.static RandomData
getInstance(byte algorithm)
Creates aRandomData
instance of the selected algorithm.abstract short
nextBytes(byte[] buffer, short offset, short length)
Generates random data.abstract void
setSeed(byte[] buffer, short offset, short length)
Seeds the random data generator.
-
-
-
Field Detail
-
ALG_PSEUDO_RANDOM
public static final byte ALG_PSEUDO_RANDOM
Deprecated.As of release 3.0.5.Utility pseudo-random number generation algorithms. The random number sequence generated by this algorithm need not be the same even if seeded with the same seed data.Even if a transaction is in progress, the update of the internal state shall not participate in the transaction.
The security level and the standards conformance of the pseudo random number algorithm is implementation dependant
- See Also:
- Constant Field Values
-
ALG_SECURE_RANDOM
public static final byte ALG_SECURE_RANDOM
Deprecated.As of release 3.0.5.Cryptographically secure random number generation algorithms.- See Also:
- Constant Field Values
-
ALG_TRNG
public static final byte ALG_TRNG
True Random Number Generation (TRNG) algorithm. The random number sequence generated by this algorithm MUST not be the same even if seeded with the same seed data.The security level and the standards conformance of the TRNG algorithm is implementation dependant.
- Since:
- 3.0.5
- See Also:
- Constant Field Values
-
ALG_PRESEEDED_DRBG
public static final byte ALG_PRESEEDED_DRBG
Deterministic Random Bit Generator (DRBG) algorithm. The algorithm is pre-seeded by an entropy source yet may by re-seeded usingsetSeed
method.The security level and the standards conformance of the DRBG algorithm is implementation dependant.
- Since:
- 3.0.5
- See Also:
- Constant Field Values
-
ALG_FAST
public static final byte ALG_FAST
Utility random number generation algorithm. Random number generated by this algorithm are not suitable for key and nonce generation. The security level of this algorithm is implementation dependant.- Since:
- 3.0.5
- See Also:
- Constant Field Values
-
ALG_KEYGENERATION
public static final byte ALG_KEYGENERATION
This algorithm creates random numbers suitable to be used for key and nonce generation.The security level and the standards conformance of the this algorithm is implementation dependant.
- Since:
- 3.0.5
- See Also:
- Constant Field Values
-
-
Method Detail
-
getInstance
public static final RandomData getInstance(byte algorithm) throws CryptoException
Creates aRandomData
instance of the selected algorithm. The pseudo randomRandomData
instance's seed is initialized to a internal default value.- Parameters:
algorithm
- the desired random number algorithm. Valid codes listed inALG_*
constants above, for exampleALG_PRESEEDED_DRBG
.- Returns:
- the
RandomData
object instance of the requested algorithm - Throws:
CryptoException
- with the following reason codes:CryptoException.NO_SUCH_ALGORITHM
if the requested algorithm is not supported.
-
generateData
public abstract void generateData(byte[] buffer, short offset, short length) throws CryptoException
Deprecated.As of release 3.0.5, replaced bynextBytes(byte[], short, short)
.Generates random data.- Parameters:
buffer
- the output bufferoffset
- the offset into the output bufferlength
- the length of random data to generate- Throws:
CryptoException
- with the following reason codes:CryptoException.ILLEGAL_VALUE
if thelength
parameter is zero.
-
nextBytes
public abstract short nextBytes(byte[] buffer, short offset, short length) throws CryptoException
Generates random data.In addition to returning a
short
result, this method sets the result in an internal state which can be rechecked using assertion methods of theSensitiveResult
class, if supported by the platform.- Parameters:
buffer
- the output bufferoffset
- the offset into the output bufferlength
- the length of random data to generate- Returns:
offset+length
- Throws:
CryptoException
- with the following reason codes:CryptoException.ILLEGAL_VALUE
if thelength
parameter is zero.
- Since:
- 3.0.5
-
setSeed
public abstract void setSeed(byte[] buffer, short offset, short length)
Seeds the random data generator. This method alters the state of this random number generator so as to be in exactly the same state as if it had just been created with the seed provided as argument to this method.- Parameters:
buffer
- the input bufferoffset
- the offset into the input bufferlength
- the length of the seed data
-
getAlgorithm
public abstract byte getAlgorithm()
Gets the random number generation algorithm. Valid codes listed inALG_*
constants above, for example,ALG_PRESEEDED_DRBG
.In addition to returning a
byte
result, this method sets the result in an internal state which can be rechecked using assertion methods of theSensitiveResult
class, if supported by the platform.- Returns:
- the algorithm code defined above
- Since:
- 3.0.5
-
-