Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.bouncycastle.pqc.crypto.ntru;
  
 
A set of parameters for NtruSign. Several predefined parameter sets are available and new ones can be created as well.
 
     extends KeyGenerationParameters
     implements Cloneable
 {   
     public static final int BASIS_TYPE_STANDARD = 0;
     public static final int BASIS_TYPE_TRANSPOSE = 1;
 
     public static final int KEY_GEN_ALG_RESULTANT = 0;
     public static final int KEY_GEN_ALG_FLOAT = 1;
    
    
Gives 128 bits of security
 
     public static final NTRUSigningKeyGenerationParameters APR2011_439 = new NTRUSigningKeyGenerationParameters(439, 2048, 146, 1, , 0.165, 490, 280, falsetruenew SHA256Digest());

    
Like APR2011_439, this parameter set gives 128 bits of security but uses product-form polynomials
 
     public static final NTRUSigningKeyGenerationParameters APR2011_439_PROD = new NTRUSigningKeyGenerationParameters(439, 2048, 9, 8, 5, 1, , 0.165, 490, 280, falsetruenew SHA256Digest());

    
Gives 256 bits of security
 
     public static final NTRUSigningKeyGenerationParameters APR2011_743 = new NTRUSigningKeyGenerationParameters(743, 2048, 248, 1, , 0.127, 560, 360, truefalsenew SHA512Digest());

    
Like APR2011_439, this parameter set gives 256 bits of security but uses product-form polynomials
 
     public static final NTRUSigningKeyGenerationParameters APR2011_743_PROD = new NTRUSigningKeyGenerationParameters(743, 2048, 11, 11, 15, 1, , 0.127, 560, 360, truefalsenew SHA512Digest());

    
Generates key pairs quickly. Use for testing only.
 
     public static final NTRUSigningKeyGenerationParameters TEST157 = new NTRUSigningKeyGenerationParameters(157, 256, 29, 1, , 0.38, 200, 80, falsefalsenew SHA256Digest());
    
Generates key pairs quickly. Use for testing only.
 
     public static final NTRUSigningKeyGenerationParameters TEST157_PROD = new NTRUSigningKeyGenerationParameters(157, 256, 5, 5, 8, 1, , 0.38, 200, 80, falsefalsenew SHA256Digest());
 
 
     public int N;
     public int q;
     public int dd1d2d3B;
     double beta;
     public double betaSq;
     double normBound;
     public double normBoundSq;
     public int signFailTolerance = 100;
     double keyNormBound;
     public double keyNormBoundSq;
     public boolean primeCheck;   // true if N and 2N+1 are prime
     public int basisType;
     int bitsF = 6;   // max #bits needed to encode one coefficient of the polynomial F
     public boolean sparse;   // whether to treat ternary polynomials as sparsely populated
     public int keyGenAlg;
     public Digest hashAlg;
     public int polyType;

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

Parameters:
N number of polynomial coefficients
q modulus
d number of -1's in the private polynomials f and g
B number of perturbations
basisType whether to use the standard or transpose lattice
beta balancing factor for the transpose lattice
normBound maximum norm for valid signatures
keyNormBound maximum norm for the ploynomials F and G
primeCheck whether 2N+1 is prime
sparse whether to treat ternary polynomials as sparsely populated (org.bouncycastle.pqc.math.ntru.polynomial.SparseTernaryPolynomial vs org.bouncycastle.pqc.math.ntru.polynomial.DenseTernaryPolynomial)
keyGenAlg RESULTANT produces better bases, FLOAT is slightly faster. RESULTANT follows the EESS standard while FLOAT is described in Hoffstein et al: An Introduction to Mathematical Cryptography.
hashAlg a valid identifier for a java.security.MessageDigest instance such as SHA-256. The MessageDigest must support the getDigestLength() method.
 
     public NTRUSigningKeyGenerationParameters(int Nint qint dint Bint basisTypedouble betadouble normBounddouble keyNormBoundboolean primeCheckboolean sparseint keyGenAlgDigest hashAlg)
     {
         super(new SecureRandom(), N);
         this. = N;
         this. = q;
         this. = d;
         this. = B;
        this. = basisType;
        this. = beta;
        this. = normBound;
        this. = keyNormBound;
        this. = primeCheck;
        this. = sparse;
        this. = keyGenAlg;
        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
d1 number of -1's in the private polynomials f and g
d2 number of -1's in the private polynomials f and g
d3 number of -1's in the private polynomials f and g
B number of perturbations
basisType whether to use the standard or transpose lattice
beta balancing factor for the transpose lattice
normBound maximum norm for valid signatures
keyNormBound maximum norm for the ploynomials F and G
primeCheck whether 2N+1 is prime
sparse whether to treat ternary polynomials as sparsely populated (org.bouncycastle.pqc.math.ntru.polynomial.SparseTernaryPolynomial vs org.bouncycastle.pqc.math.ntru.polynomial.DenseTernaryPolynomial)
keyGenAlg RESULTANT produces better bases, FLOAT is slightly faster. RESULTANT follows the EESS standard while FLOAT is described in Hoffstein et al: An Introduction to Mathematical Cryptography.
hashAlg a valid identifier for a java.security.MessageDigest instance such as SHA-256. The MessageDigest must support the getDigestLength() method.
    public NTRUSigningKeyGenerationParameters(int Nint qint d1int d2int d3int Bint basisTypedouble betadouble normBounddouble keyNormBoundboolean primeCheckboolean sparseint keyGenAlgDigest hashAlg)
    {
        super(new SecureRandom(), N);
        this. = N;
        this. = q;
        this. = d1;
        this. = d2;
        this. = d3;
        this. = B;
        this. = basisType;
        this. = beta;
        this. = normBound;
        this. = keyNormBound;
        this. = primeCheck;
        this. = sparse;
        this. = keyGenAlg;
        this. = hashAlg;
        init();
    }
    private void init()
    {
         =  * ;
         =  * ;
    }

    
Reads a parameter set from an input stream.

Parameters:
is an input stream
Throws:
java.io.IOException
        throws IOException
    {
        super(new SecureRandom(), 0);     // TODO:
        DataInputStream dis = new DataInputStream(is);
         = dis.readInt();
         = dis.readInt();
         = dis.readInt();
         = dis.readInt();
         = dis.readInt();
         = dis.readInt();
         = dis.readInt();
         = dis.readInt();
         = dis.readDouble();
         = dis.readDouble();
         = dis.readDouble();
         = dis.readInt();
         = dis.readBoolean();
         = dis.readBoolean();
         = dis.readInt();
         = dis.read();
        String alg = dis.readUTF();
        if ("SHA-512".equals(alg))
        {
             = new SHA512Digest();
        }
        else if ("SHA-256".equals(alg))
        {
             = new SHA256Digest();
        }
         = dis.read();
        init();
    }

    
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.writeDouble();
        dos.writeDouble();
        dos.writeDouble();
        dos.writeInt();
        dos.writeBoolean();
        dos.writeBoolean();
        dos.writeInt();
        dos.write();
        dos.writeUTF(.getAlgorithmName());
        dos.write();
    }
    {
        return new NTRUSigningParameters();
    }
    {
        {
            return new NTRUSigningKeyGenerationParameters();
        }
        else
        {
            return new NTRUSigningKeyGenerationParameters();
        }
    }
    public int hashCode()
    {
        final int prime = 31;
        int result = 1;
        result = prime * result + ;
        result = prime * result + ;
        result = prime * result + ;
        long temp;
        temp = Double.doubleToLongBits();
        result = prime * result + (int)(temp ^ (temp >>> 32));
        temp = Double.doubleToLongBits();
        result = prime * result + (int)(temp ^ (temp >>> 32));
        result = prime * result + ;
        result = prime * result + ;
        result = prime * result + ;
        result = prime * result + ;
        result = prime * result + ;
        result = prime * result + (( == null) ? 0 : .getAlgorithmName().hashCode());
        result = prime * result + ;
        temp = Double.doubleToLongBits();
        result = prime * result + (int)(temp ^ (temp >>> 32));
        temp = Double.doubleToLongBits();
        result = prime * result + (int)(temp ^ (temp >>> 32));
        temp = Double.doubleToLongBits();
        result = prime * result + (int)(temp ^ (temp >>> 32));
        temp = Double.doubleToLongBits();
        result = prime * result + (int)(temp ^ (temp >>> 32));
        result = prime * result + ;
        result = prime * result + ( ? 1231 : 1237);
        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 (!(obj instanceof NTRUSigningKeyGenerationParameters))
        {
            return false;
        }
        if ( != other.B)
        {
            return false;
        }
        if ( != other.N)
        {
            return false;
        }
        if ( != other.basisType)
        {
            return false;
        }
        if (Double.doubleToLongBits() != Double.doubleToLongBits(other.beta))
        {
            return false;
        }
        if (Double.doubleToLongBits() != Double.doubleToLongBits(other.betaSq))
        {
            return false;
        }
        if ( != other.bitsF)
        {
            return false;
        }
        if ( != other.d)
        {
            return false;
        }
        if ( != other.d1)
        {
            return false;
        }
        if ( != other.d2)
        {
            return false;
        }
        if ( != other.d3)
        {
            return false;
        }
        if ( == null)
        {
            if (other.hashAlg != null)
            {
                return false;
            }
        }
        else if (!.getAlgorithmName().equals(other.hashAlg.getAlgorithmName()))
        {
            return false;
        }
        if ( != other.keyGenAlg)
        {
            return false;
        }
        if (Double.doubleToLongBits() != Double.doubleToLongBits(other.keyNormBound))
        {
            return false;
        }
        if (Double.doubleToLongBits() != Double.doubleToLongBits(other.keyNormBoundSq))
        {
            return false;
        }
        if (Double.doubleToLongBits() != Double.doubleToLongBits(other.normBound))
        {
            return false;
        }
        if (Double.doubleToLongBits() != Double.doubleToLongBits(other.normBoundSq))
        {
            return false;
        }
        if ( != other.polyType)
        {
            return false;
        }
        if ( != other.primeCheck)
        {
            return false;
        }
        if ( != other.q)
        {
            return false;
        }
        if ( != other.signFailTolerance)
        {
            return false;
        }
        if ( != other.sparse)
        {
            return false;
        }
        return true;
    }
    public String toString()
    {
        DecimalFormat format = new DecimalFormat("0.00");
        StringBuilder output = new StringBuilder("SignatureParameters(N=" +  + " q=" + );
        {
            output.append(" polyType=SIMPLE d=" + );
        }
        else
        {
            output.append(" polyType=PRODUCT d1=" +  + " d2=" +  + " d3=" + );
        }
        output.append(" B=" +  + " basisType=" +  + " beta=" + format.format() +
            " normBound=" + format.format() + " keyNormBound=" + format.format() +
            " prime=" +  + " sparse=" +  + " keyGenAlg=" +  + " hashAlg=" +  + ")");
        return output.toString();
    }
New to GrepCode? Check out our FAQ X