private int nextInt(SP80090DRBG drbg, int range) { if ((range & -range) == range) // i.e., range is a power of 2 { return (int)((range * (long)makePositiveInt(drbg)) >> 31); } int bits, val; do { bits = makePositiveInt(drbg); val = bits % range; } while (bits - val + (range - 1) < 0); return val; }
private BitSet buildBitSet(int size, SP80090DRBG drbg) { BitSet bitSet = new BitSet(size); int nBits = size / 2; int upper = size - 1; int lower = 0; for (int i = 0; i != nBits; i++) { int nIndex = nextInt(drbg, upper - lower + 1) + lower; if (bitSet.get(nIndex)) { if ((nIndex & 1) != 0) { while (bitSet.get(upper)) { upper--; } nIndex = upper--; } else { while (bitSet.get(lower)) { lower++; } nIndex = lower++; } } bitSet.set(nIndex); } return bitSet; }
private int makePositiveInt(SP80090DRBG drbg) { byte[] bytes = new byte[4]; drbg.generate(bytes, null, false); return ((bytes[0] & 0x7f) << 24) | ((bytes[1] & 0xff) << 16) | ((bytes[2] & 0xff) << 8) | (bytes[3] & 0xff); }
public SP80090DRBG get(EntropySource entropySource) { return new HashSP800DRBG(digest, securityStrength, entropySource, personalizationString, nonce); }
public SP80090DRBG get(EntropySource entropySource) { return new DualECSP800DRBG(digest, securityStrength, entropySource, personalizationString, nonce); }
public SP80090DRBG get(EntropySource entropySource) { return new HMacSP800DRBG(hMac, securityStrength, entropySource, personalizationString, nonce); }
public SP80090DRBG get(EntropySource entropySource) { return new CTRSP800DRBG(blockCipher, keySizeInBits, securityStrength, entropySource, personalizationString, nonce); }
public SP80090DRBG get(EntropySource entropySource) { return new DualECSP800DRBG(pointSet, digest, securityStrength, entropySource, personalizationString, nonce); }