1 package org
.asamk
.signal
.util
;
3 import java
.security
.NoSuchAlgorithmException
;
4 import java
.security
.SecureRandom
;
6 public class RandomUtils
{
8 private static final ThreadLocal
<SecureRandom
> LOCAL_RANDOM
= ThreadLocal
.withInitial(() -> {
9 var rand
= getSecureRandomUnseeded();
11 // Let the SecureRandom seed it self initially
17 private static SecureRandom
getSecureRandomUnseeded() {
19 return SecureRandom
.getInstance("NativePRNG");
20 } catch (NoSuchAlgorithmException e
) {
21 // Fallback to SHA1PRNG if NativePRNG is not available (e.g. on windows)
23 return SecureRandom
.getInstance("SHA1PRNG");
24 } catch (NoSuchAlgorithmException e1
) {
25 // Fallback to default
26 return new SecureRandom();
31 public static SecureRandom
getSecureRandom() {
32 return LOCAL_RANDOM
.get();