Use custom SecureRandom instance

- Use NativePRNG algorithm instead of using SHA1PRNG if available
- Register a custom security provider to use the same SecureRandom everywhere
This commit is contained in:
AsamK 2018-11-21 00:07:05 +01:00
parent cf972e5b6c
commit 5f2190713a
4 changed files with 88 additions and 14 deletions

View file

@ -1,10 +1,8 @@
package org.asamk.signal.manager;
import org.asamk.signal.util.RandomUtils;
import org.whispersystems.signalservice.internal.util.Base64;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
class KeyUtils {
private KeyUtils() {
@ -33,15 +31,7 @@ class KeyUtils {
private static byte[] getSecretBytes(int size) {
byte[] secret = new byte[size];
getSecureRandom().nextBytes(secret);
RandomUtils.getSecureRandom().nextBytes(secret);
return secret;
}
private static SecureRandom getSecureRandom() {
try {
return SecureRandom.getInstance("SHA1PRNG");
} catch (NoSuchAlgorithmException e) {
throw new AssertionError(e);
}
}
}