diff options
Diffstat (limited to 'src/main/java/org/bouncycastle/pqc/crypto/ntru/NTRUSignerPrng.java')
-rw-r--r-- | src/main/java/org/bouncycastle/pqc/crypto/ntru/NTRUSignerPrng.java | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/main/java/org/bouncycastle/pqc/crypto/ntru/NTRUSignerPrng.java b/src/main/java/org/bouncycastle/pqc/crypto/ntru/NTRUSignerPrng.java index 79113e4a..77ed63a2 100644 --- a/src/main/java/org/bouncycastle/pqc/crypto/ntru/NTRUSignerPrng.java +++ b/src/main/java/org/bouncycastle/pqc/crypto/ntru/NTRUSignerPrng.java @@ -7,31 +7,37 @@ import org.bouncycastle.crypto.Digest; /** * An implementation of the deterministic pseudo-random generator in EESS section 3.7.3.1 */ -public class NTRUSignerPrng { +public class NTRUSignerPrng +{ private int counter; private byte[] seed; private Digest hashAlg; - + /** * Constructs a new PRNG and seeds it with a byte array. - * @param seed a seed + * + * @param seed a seed * @param hashAlg the hash algorithm to use */ - NTRUSignerPrng(byte[] seed, Digest hashAlg) { + NTRUSignerPrng(byte[] seed, Digest hashAlg) + { counter = 0; this.seed = seed; this.hashAlg = hashAlg; } - + /** * Returns <code>n</code> random bytes + * * @param n number of bytes to return * @return the next <code>n</code> random bytes */ - byte[] nextBytes(int n) { + byte[] nextBytes(int n) + { ByteBuffer buf = ByteBuffer.allocate(n); - - while (buf.hasRemaining()) { + + while (buf.hasRemaining()) + { ByteBuffer cbuf = ByteBuffer.allocate(seed.length + 4); cbuf.put(seed); cbuf.putInt(counter); @@ -43,12 +49,16 @@ public class NTRUSignerPrng { hashAlg.doFinal(hash, 0); if (buf.remaining() < hash.length) + { buf.put(hash, 0, buf.remaining()); + } else + { buf.put(hash); + } counter++; } - + return buf.array(); } }
\ No newline at end of file |