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.
 
 public class NTRUSigningParameters
     implements Cloneable
 {
     public int N;
     public int q;
     public int dd1d2d3B;
     double beta;
     public double betaSq;
     double normBound;
     public double normBoundSq;
     public int signFailTolerance = 100;
     int bitsF = 6;   // max #bits needed to encode one coefficient of the polynomial F
     public Digest hashAlg;

    
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
beta balancing factor for the transpose lattice
normBound maximum norm for valid signatures
hashAlg a valid identifier for a java.security.MessageDigest instance such as SHA-256. The MessageDigest must support the getDigestLength() method.
 
     public NTRUSigningParameters(int Nint qint dint Bdouble betadouble normBoundDigest hashAlg)
     {
         this. = N;
         this. = q;
         this. = d;
         this. = B;
         this. = beta;
         this. = normBound;
         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
beta balancing factor for the transpose lattice
normBound maximum norm for valid signatures
keyNormBound maximum norm for the ploynomials F and G
hashAlg a valid identifier for a java.security.MessageDigest instance such as SHA-256. The MessageDigest must support the getDigestLength() method.
 
     public NTRUSigningParameters(int Nint qint d1int d2int d3int Bdouble betadouble normBounddouble keyNormBoundDigest hashAlg)
     {
         this. = N;
         this. = q;
         this. = d1;
         this. = d2;
         this. = d3;
         this. = B;
         this. = beta;
         this. = normBound;
         this. = hashAlg;
         init();
     }
 
     private void init()
     {
          =  * ;
          =  * ;
     }

    
Reads a parameter set from an input stream.

Parameters:
is an input stream
Throws:
java.io.IOException
 
     public NTRUSigningParameters(InputStream is)
         throws IOException
     {
         DataInputStream dis = new DataInputStream(is);
          = dis.readInt();
          = dis.readInt();
         = dis.readInt();
         = dis.readInt();
         = dis.readInt();
         = dis.readInt();
         = dis.readInt();
         = dis.readDouble();
         = dis.readDouble();
         = dis.readInt();
         = dis.readInt();
        String alg = dis.readUTF();
        if ("SHA-512".equals(alg))
        {
             = new SHA512Digest();
        }
        else if ("SHA-256".equals(alg))
        {
             = new SHA256Digest();
        }
        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.writeDouble();
        dos.writeDouble();
        dos.writeInt();
        dos.writeInt();
        dos.writeUTF(.getAlgorithmName());
    }
    public NTRUSigningParameters clone()
    {
        return new NTRUSigningParameters();
    }
    public int hashCode()
    {
        final int prime = 31;
        int result = 1;
        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());
        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 + ;
        return result;
    }
    public boolean equals(Object obj)
    {
        if (this == obj)
        {
            return true;
        }
        if (obj == null)
        {
            return false;
        }
        if (!(obj instanceof NTRUSigningParameters))
        {
            return false;
        }
        NTRUSigningParameters other = (NTRUSigningParameters)obj;
        if ( != other.B)
        {
            return false;
        }
        if ( != other.N)
        {
            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 (Double.doubleToLongBits() != Double.doubleToLongBits(other.normBound))
        {
            return false;
        }
        if (Double.doubleToLongBits() != Double.doubleToLongBits(other.normBoundSq))
        {
            return false;
        }
        if ( != other.q)
        {
            return false;
        }
        if ( != other.signFailTolerance)
        {
            return false;
        }
        return true;
    }
    public String toString()
    {
        DecimalFormat format = new DecimalFormat("0.00");
        StringBuilder output = new StringBuilder("SignatureParameters(N=" +  + " q=" + );
        output.append(" B=" +  + " beta=" + format.format() +
            " normBound=" + format.format() +
            " hashAlg=" +  + ")");
        return output.toString();
    }
New to GrepCode? Check out our FAQ X