- All Implemented Interfaces:
Serializable
This class provides a crytpographically strong true random number generated based on cryptographic hardware. In this implementation of the SecureRandom class bytes are prefetched from cryptographic hardware to create a cache of random numbers available for a caller. This implementation of the SecureRandom class can be leveraged by setting the ibm.hwrandom.useicsfcache Java environment variable to true. If the ibm.hwrandom.useicsfcache Java environment variable is set to true when the IBMJCECCA provider is loaded then all subsequent calls to the SecureRandom class in the IBMJCECCA provider will be routed to this caching implementation. An additional environment variable of ibm.hwrandom.cachesize may also be specified to set the size of the cache to be used. Note a seed is not necessary for hardware random number generation and if one is passed it is not used. (Allowing the passing of a seed is to allow backwards compatibility with software generated random numbers)
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new instance of this class.SecureRandomWithCache
(byte[] seed) Constructor that requires a seed. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
engineGenerateSeed
(int numBytes) As hardware crypto does not need a seed value this method has no purpose, but is defined in SecureRandomSpi.void
engineNextBytes
(byte[] bytes) Generates a user-specified number of random bytes.void
engineSetSeed
(byte[] seed) As hardware crypto does not need a seed value this method has no purpose, but is defined in SecureRandomSpi.Methods inherited from class java.security.SecureRandomSpi
engineGetParameters, engineNextBytes, engineReseed, toString
-
Constructor Details
-
SecureRandomWithCache
public SecureRandomWithCache()Constructs a new instance of this class. The Java envionrment variable ibm.hwrandom.cachesize will be used to set the size of the cache to be used. If not specified the default size of 14400 bytes will be used. -
SecureRandomWithCache
public SecureRandomWithCache(byte[] seed) Constructor that requires a seed. Note: The seed has no real meaning in hardware and this constructor only exists for compatibility with SecureRandomSpi.- Parameters:
seed
- a series of bytes used as seed. This value will be ignored.
-
-
Method Details
-
engineSetSeed
public void engineSetSeed(byte[] seed) As hardware crypto does not need a seed value this method has no purpose, but is defined in SecureRandomSpi. This method is a no-op whenever called.- Specified by:
engineSetSeed
in classSecureRandomSpi
- Parameters:
seed
- a series of bytes used as seed. This parameter is ignored.
-
engineNextBytes
Generates a user-specified number of random bytes. A cache is used to cache the bytes fetched from the underlying hardware implementation.- Specified by:
engineNextBytes
in classSecureRandomSpi
- Parameters:
bytes
- the array to be filled in with random bytes.- Throws:
InternalError
- is thrown when an unexpected error occurs or bytes is equal to null.BufferUnderflowException
- is thrown when an unexpected internal error occurs while fetching bytes from the cache.
-
engineGenerateSeed
As hardware crypto does not need a seed value this method has no purpose, but is defined in SecureRandomSpi.- Specified by:
engineGenerateSeed
in classSecureRandomSpi
- Throws:
UnsupportedOperationException
- is always thrown if this method is invoked.
-