Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.bouncycastle.pqc.crypto.ntru;
  
  import java.util.Arrays;
 
A set of parameters for NtruEncrypt. Several predefined parameter sets are available and new ones can be created as well.
 
     extends KeyGenerationParameters
     implements Cloneable
 {
    
A conservative (in terms of security) parameter set that gives 256 bits of security and is optimized for key size.
 
     public static final NTRUEncryptionKeyGenerationParameters EES1087EP2 = new NTRUEncryptionKeyGenerationParameters(1087, 2048, 120, 120, 256, 13, 25, 14, truenew byte[]{0, 6, 3}, truefalsenew SHA512Digest());

    
A conservative (in terms of security) parameter set that gives 256 bits of security and is a tradeoff between key size and encryption/decryption speed.
 
     public static final NTRUEncryptionKeyGenerationParameters EES1171EP1 = new NTRUEncryptionKeyGenerationParameters(1171, 2048, 106, 106, 256, 13, 20, 15, truenew byte[]{0, 6, 4}, truefalsenew SHA512Digest());

    
A conservative (in terms of security) parameter set that gives 256 bits of security and is optimized for encryption/decryption speed.
 
     public static final NTRUEncryptionKeyGenerationParameters EES1499EP1 = new NTRUEncryptionKeyGenerationParameters(1499, 2048, 79, 79, 256, 13, 17, 19, truenew byte[]{0, 6, 5}, truefalsenew SHA512Digest());

    
A parameter set that gives 128 bits of security and uses simple ternary polynomials.
 
     public static final NTRUEncryptionKeyGenerationParameters APR2011_439 = new NTRUEncryptionKeyGenerationParameters(439, 2048, 146, 130, 128, 9, 32, 9, truenew byte[]{0, 7, 101}, truefalsenew SHA256Digest());

    
Like APR2011_439, this parameter set gives 128 bits of security but uses product-form polynomials and f=1+pF.
 
     public static final NTRUEncryptionKeyGenerationParameters APR2011_439_FAST = new NTRUEncryptionKeyGenerationParameters(439, 2048, 9, 8, 5, 130, 128, 9, 32, 9, truenew byte[]{0, 7, 101}, truetruenew SHA256Digest());

    
A parameter set that gives 256 bits of security and uses simple ternary polynomials.
 
     public static final NTRUEncryptionKeyGenerationParameters APR2011_743 = new NTRUEncryptionKeyGenerationParameters(743, 2048, 248, 220, 256, 10, 27, 14, truenew byte[]{0, 7, 105}, falsefalsenew SHA512Digest());

    
Like APR2011_743, this parameter set gives 256 bits of security but uses product-form polynomials and f=1+pF.
 
     public static final NTRUEncryptionKeyGenerationParameters APR2011_743_FAST = new NTRUEncryptionKeyGenerationParameters(743, 2048, 11, 11, 15, 220, 256, 10, 27, 14, truenew byte[]{0, 7, 105}, falsetruenew SHA512Digest());
 
     public int Nqdfdf1df2df3;
     public int dr;
     public int dr1;
     public int dr2;
     public int dr3;
     public int dg;
     int llen;
     public int maxMsgLenBytes;
     public int db;
     public int bufferLenBits;
     int bufferLenTrits;
     public int dm0;
     public int pkLen;
     public int c;
     public int minCallsR;
     public int minCallsMask;
     public boolean hashSeed;
     public byte[] oid;
     public boolean sparse;
     public boolean fastFp;
     public int polyType;
     public Digest hashAlg;

    
Constructs a parameter set that uses ternary private keys (i.e. polyType=SIMPLE).

Parameters:
N number of polynomial coefficients
q modulus
df number of ones in the private polynomial f
dm0 minimum acceptable number of -1's, 0's, and 1's in the polynomial m' in the last encryption step
db number of random bits to prepend to the message
c a parameter for the Index Generation Function (IndexGenerator)
minCallsR minimum number of hash calls for the IGF to make
minCallsMask minimum number of calls to generate the masking polynomial
hashSeed whether to hash the seed in the MGF first (true) or use the seed directly (false)
oid three bytes that uniquely identify the parameter set
sparse whether to treat ternary polynomials as sparsely populated (org.bouncycastle.pqc.math.ntru.polynomial.SparseTernaryPolynomial vs org.bouncycastle.pqc.math.ntru.polynomial.DenseTernaryPolynomial)
fastFp whether f=1+p*F for a ternary F (true) or f is ternary (false)
hashAlg a valid identifier for a java.security.MessageDigest instance such as SHA-256. The MessageDigest must support the getDigestLength() method.
 
     public NTRUEncryptionKeyGenerationParameters(int Nint qint dfint dm0int dbint cint minCallsRint minCallsMaskboolean hashSeedbyte[] oidboolean sparseboolean fastFpDigest hashAlg)
     {
        super(new SecureRandom(), db);
        this. = N;
        this. = q;
        this. = df;
        this. = db;
        this. = dm0;
        this. = c;
        this. = minCallsR;
        this. = minCallsMask;
        this. = hashSeed;
        this. = oid;
        this. = sparse;
        this. = fastFp;
        this. = hashAlg;
        init();
    }

    
Constructs a parameter set that uses product-form private keys (i.e. polyType=PRODUCT).

Parameters:
N number of polynomial coefficients
q modulus
df1 number of ones in the private polynomial f1
df2 number of ones in the private polynomial f2
df3 number of ones in the private polynomial f3
dm0 minimum acceptable number of -1's, 0's, and 1's in the polynomial m' in the last encryption step
db number of random bits to prepend to the message
c a parameter for the Index Generation Function (IndexGenerator)
minCallsR minimum number of hash calls for the IGF to make
minCallsMask minimum number of calls to generate the masking polynomial
hashSeed whether to hash the seed in the MGF first (true) or use the seed directly (false)
oid three bytes that uniquely identify the parameter set
sparse whether to treat ternary polynomials as sparsely populated (org.bouncycastle.pqc.math.ntru.polynomial.SparseTernaryPolynomial vs org.bouncycastle.pqc.math.ntru.polynomial.DenseTernaryPolynomial)
fastFp whether f=1+p*F for a ternary F (true) or f is ternary (false)
hashAlg a valid identifier for a java.security.MessageDigest instance such as SHA-256
    public NTRUEncryptionKeyGenerationParameters(int Nint qint df1int df2int df3int dm0int dbint cint minCallsRint minCallsMaskboolean hashSeedbyte[] oidboolean sparseboolean fastFpDigest hashAlg)
    {
        super(new SecureRandom(), db);
        this. = N;
        this. = q;
        this. = df1;
        this. = df2;
        this. = df3;
        this. = db;
        this. = dm0;
        this. = c;
        this. = minCallsR;
        this. = minCallsMask;
        this. = hashSeed;
        this. = oid;
        this. = sparse;
        this. = fastFp;
        this. = hashAlg;
        init();
    }
    private void init()
    {
         = ;
         = ;
         = ;
         = ;
         =  / 3;
         = 1;   // ceil(log2(maxMsgLenBytes))
         =  * 3 / 2 / 8 -  -  / 8 - 1;
         = ( * 3 / 2 + 7) / 8 * 8 + 1;
         =  - 1;
         = ;
    }

    
Reads a parameter set from an input stream.

Parameters:
is an input stream
Throws:
java.io.IOException
        throws IOException
    {
        super(new SecureRandom(), -1);
        DataInputStream dis = new DataInputStream(is);
         = dis.readInt();
         = dis.readInt();
         = dis.readInt();
         = dis.readInt();
         = dis.readInt();
         = dis.readInt();
         = dis.readInt();
         = dis.readInt();
         = dis.readInt();
         = dis.readInt();
         = dis.readInt();
         = dis.readBoolean();
         = new byte[3];
        dis.read();
         = dis.readBoolean();
         = dis.readBoolean();
         = dis.read();
        String alg = dis.readUTF();
        if ("SHA-512".equals(alg))
        {
             = new SHA512Digest();
        }
        else if ("SHA-256".equals(alg))
        {
             = new SHA256Digest();
        }
        init();
    }
    {
        {
            return new NTRUEncryptionParameters();
        }
        else
        {
            return new NTRUEncryptionParameters();
        }
    }
    {
        {
            return new NTRUEncryptionKeyGenerationParameters();
        }
        else
        {
            return new NTRUEncryptionKeyGenerationParameters();
        }
    }

    
Returns the maximum length a plaintext message can be with this parameter set.

Returns:
the maximum length in bytes
    public int getMaxMessageLength()
    {
        return ;
    }

    
Writes the parameter set to an output stream

Parameters:
os an output stream
Throws:
java.io.IOException
    public void writeTo(OutputStream os)
        throws IOException
    {
        DataOutputStream dos = new DataOutputStream(os);
        dos.writeInt();
        dos.writeInt();
        dos.writeInt();
        dos.writeInt();
        dos.writeInt();
        dos.writeInt();
        dos.writeInt();
        dos.writeInt();
        dos.writeInt();
        dos.writeInt();
        dos.writeInt();
        dos.writeBoolean();
        dos.write();
        dos.writeBoolean();
        dos.writeBoolean();
        dos.write();
        dos.writeUTF(.getAlgorithmName());
    }
    public int hashCode()
    {
        final int prime = 31;
        int result = 1;
        result = prime * result + ;
        result = prime * result + ;
        result = prime * result + ;
        result = prime * result + ;
        result = prime * result + ;
        result = prime * result + ;
        result = prime * result + ;
        result = prime * result + ;
        result = prime * result + ;
        result = prime * result + ;
        result = prime * result + ;
        result = prime * result + ;
        result = prime * result + ;
        result = prime * result + ;
        result = prime * result + ;
        result = prime * result + ( ? 1231 : 1237);
        result = prime * result + (( == null) ? 0 : .getAlgorithmName().hashCode());
        result = prime * result + ( ? 1231 : 1237);
        result = prime * result + ;
        result = prime * result + ;
        result = prime * result + ;
        result = prime * result + ;
        result = prime * result + Arrays.hashCode();
        result = prime * result + ;
        result = prime * result + ;
        result = prime * result + ;
        result = prime * result + ( ? 1231 : 1237);
        return result;
    }
    public boolean equals(Object obj)
    {
        if (this == obj)
        {
            return true;
        }
        if (obj == null)
        {
            return false;
        }
        if (getClass() != obj.getClass())
        {
            return false;
        }
        if ( != other.N)
        {
            return false;
        }
        if ( != other.bufferLenBits)
        {
            return false;
        }
        if ( != other.bufferLenTrits)
        {
            return false;
        }
        if ( != other.c)
        {
            return false;
        }
        if ( != other.db)
        {
            return false;
        }
        if ( != other.df)
        {
            return false;
        }
        if ( != other.df1)
        {
            return false;
        }
        if ( != other.df2)
        {
            return false;
        }
        if ( != other.df3)
        {
            return false;
        }
        if ( != other.dg)
        {
            return false;
        }
        if ( != other.dm0)
        {
            return false;
        }
        if ( != other.dr)
        {
            return false;
        }
        if ( != other.dr1)
        {
            return false;
        }
        if ( != other.dr2)
        {
            return false;
        }
        if ( != other.dr3)
        {
            return false;
        }
        if ( != other.fastFp)
        {
            return false;
        }
        if ( == null)
        {
            if (other.hashAlg != null)
            {
                return false;
            }
        }
        else if (!.getAlgorithmName().equals(other.hashAlg.getAlgorithmName()))
        {
            return false;
        }
        if ( != other.hashSeed)
        {
            return false;
        }
        if ( != other.llen)
        {
            return false;
        }
        if ( != other.maxMsgLenBytes)
        {
            return false;
        }
        if ( != other.minCallsMask)
        {
            return false;
        }
        if ( != other.minCallsR)
        {
            return false;
        }
        if (!Arrays.equals(other.oid))
        {
            return false;
        }
        if ( != other.pkLen)
        {
            return false;
        }
        if ( != other.polyType)
        {
            return false;
        }
        if ( != other.q)
        {
            return false;
        }
        if ( != other.sparse)
        {
            return false;
        }
        return true;
    }
    public String toString()
    {
        StringBuilder output = new StringBuilder("EncryptionParameters(N=" +  + " q=" + );
        {
            output.append(" polyType=SIMPLE df=" + );
        }
        else
        {
            output.append(" polyType=PRODUCT df1=" +  + " df2=" +  + " df3=" + );
        }
        output.append(" dm0=" +  + " db=" +  + " c=" +  + " minCallsR=" +  + " minCallsMask=" +  +
            " hashSeed=" +  + " hashAlg=" +  + " oid=" + Arrays.toString() + " sparse=" +  + ")");
        return output.toString();
    }
New to GrepCode? Check out our FAQ X