Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.bouncycastle.pqc.crypto.ntru;
 
 
An implementation of the deterministic pseudo-random generator in EESS section 3.7.3.1
 
public class NTRUSignerPrng
    private int counter;
    private byte[] seed;
    private Digest hashAlg;

    
Constructs a new PRNG and seeds it with a byte array.

Parameters:
seed a seed
hashAlg the hash algorithm to use
    NTRUSignerPrng(byte[] seedDigest hashAlg)
    {
         = 0;
        this. = seed;
        this. = hashAlg;
    }

    
Returns n random bytes

Parameters:
n number of bytes to return
Returns:
the next n random bytes
    byte[] nextBytes(int n)
    {
        ByteBuffer buf = ByteBuffer.allocate(n);
        while (buf.hasRemaining())
        {
            ByteBuffer cbuf = ByteBuffer.allocate(. + 4);
            cbuf.put();
            cbuf.putInt();
            byte[] array = cbuf.array();
            byte[] hash = new byte[.getDigestSize()];
            .update(array, 0, array.length);
            .doFinal(hash, 0);
            if (buf.remaining() < hash.length)
            {
                buf.put(hash, 0, buf.remaining());
            }
            else
            {
                buf.put(hash);
            }
            ++;
        }
        return buf.array();
    }
New to GrepCode? Check out our FAQ X