removed use of Java 7 class (see also github
import java.security.SecureRandom;
import java.security.SecureRandomSpi;
import java.security.Security;
-import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.LinkedList;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
@@ -188,7 +188,6 @@ private static SecureRandom createBaseRandom(boolean isPredictionResistant)
return new SP800SecureRandomBuilder(new EntropySourceProvider()
{
- @Override
public EntropySource get(int bitsRequired)
{
return new HybridEntropySource(entropyDaemon, bitsRequired);
@@ -303,19 +302,25 @@ public EntropySourceProvider run()
private static class EntropyDaemon
implements Runnable
{
- private final ConcurrentLinkedQueue<Runnable> tasks = new ConcurrentLinkedQueue<Runnable>();
+ private final LinkedList<Runnable> tasks = new LinkedList<Runnable>();
void addTask(Runnable task)
+ {
+ synchronized (tasks)
{
tasks.add(task);
}
+ }
- @Override
public void run()
{
while (!Thread.currentThread().isInterrupted())
{
- Runnable task = tasks.poll();
+ Runnable task;
+ synchronized (tasks)
+ {
+ task = tasks.poll();
+ }
if (task != null)
{
@@ -519,13 +524,11 @@ public EntropySource get(final int bitsRequired)
.buildHMAC(new HMac(new SHA512Digest()), entropySource.getEntropy(), false); // 32 byte nonce
}
- @Override
public boolean isPredictionResistant()
{
return true;
}
- @Override
public byte[] getEntropy()
{
byte[] entropy = new byte[bytesRequired];
@@ -549,7 +552,6 @@ public boolean isPredictionResistant()
return entropy;
}
- @Override
public int entropySize()
{
return bytesRequired * 8;
