summaryrefslogtreecommitdiffstats
path: root/luni/src
diff options
context:
space:
mode:
Diffstat (limited to 'luni/src')
-rw-r--r--luni/src/test/java/org/apache/harmony/security/tests/provider/crypto/SHA1PRNG_SecureRandomTest.java29
1 files changed, 29 insertions, 0 deletions
diff --git a/luni/src/test/java/org/apache/harmony/security/tests/provider/crypto/SHA1PRNG_SecureRandomTest.java b/luni/src/test/java/org/apache/harmony/security/tests/provider/crypto/SHA1PRNG_SecureRandomTest.java
index ffdbe92..0db5ee1 100644
--- a/luni/src/test/java/org/apache/harmony/security/tests/provider/crypto/SHA1PRNG_SecureRandomTest.java
+++ b/luni/src/test/java/org/apache/harmony/security/tests/provider/crypto/SHA1PRNG_SecureRandomTest.java
@@ -17,6 +17,8 @@
package org.apache.harmony.security.tests.provider.crypto;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.SecureRandom;
@@ -400,4 +402,31 @@ public class SHA1PRNG_SecureRandomTest extends TestCase {
assertFalse("sequences are equal i=" + i, b);
}
}
+
+ public void testSeedIsFullLength() throws Exception {
+ Class<?> srClass = Class.forName(
+ "org.apache.harmony.security.provider.crypto.SHA1PRNG_SecureRandomImpl");
+ Field seedField = srClass.getDeclaredField("seed");
+ seedField.setAccessible(true);
+
+ Method nextBytesMethod = srClass.getDeclaredMethod("engineNextBytes", byte[].class);
+ nextBytesMethod.setAccessible(true);
+
+ byte[] bytes = new byte[1];
+
+ // Iterate 8 times to make sure the probability of a false positive is
+ // extremely rare.
+ for (int i = 0; i < 8; i++) {
+ Object sr = srClass.newInstance();
+ nextBytesMethod.invoke(sr, bytes);
+ int[] seed = (int[]) seedField.get(sr);
+
+ // If the first integer is not zero, it is fixed.
+ if (seed[0] != 0) {
+ return; // Success
+ }
+ }
+
+ fail("Fallback SHA1PRNG_SecureRandomImpl should not clobber seed internally");
+ }
}