Exemplo n.º 1
0
        /**
         * Constructs a new index generator.
         *
         * @param seed   a seed of arbitrary length to initialize the index generator with
         * @param params NtruEncrypt parameters
         */
        IndexGenerator(byte[] seed, NTRUEncryptionParameters encryptionParameters)
        {
            this.seed = seed;
            N         = encryptionParameters.N;
            c         = encryptionParameters.c;
            minCallsR = encryptionParameters.minCallsR;

            totLen  = 0;
            remLen  = 0;
            counter = 0;
            hashAlg = encryptionParameters.hashAlg;

            hLen        = hashAlg.GetDigestSize(); // hash length
            initialized = false;
        }
        /**
         * Reads a polynomial <code>f</code> from an input stream and constructs a new private key
         *
         * @param is     an input stream
         * @param params the NtruEncrypt parameters to use
         * @see #writeTo(OutputStream)
         */
        public NTRUEncryptionPrivateKeyParameters(Stream stream, NTRUEncryptionParameters parameters) : base(true, parameters)
        {
            if (parameters.polyType == NTRUParameters.TERNARY_POLYNOMIAL_TYPE_PRODUCT)
            {
                int N          = parameters.N;
                int df1        = parameters.df1;
                int df2        = parameters.df2;
                int df3Ones    = parameters.df3;
                int df3NegOnes = parameters.fastFp ? parameters.df3 : parameters.df3 - 1;
                h = IntegerPolynomial.FromBinary(stream, parameters.N, parameters.q);
                t = ProductFormPolynomial.FromBinary(stream, N, df1, df2, df3Ones, df3NegOnes);
            }
            else
            {
                h = IntegerPolynomial.FromBinary(stream, parameters.N, parameters.q);
                IntegerPolynomial fInt = IntegerPolynomial.FromBinary3Tight(stream, parameters.N);
                t = parameters.sparse ? new SparseTernaryPolynomial(fInt) : (IPolynomial) new DenseTernaryPolynomial(fInt);
            }

            Init();
        }
Exemplo n.º 3
0
 public NTRUEncryptionKeyParameters(bool privateKey, NTRUEncryptionParameters parameters) : base(privateKey)
 {
     this.parameters = parameters;
 }
Exemplo n.º 4
0
        public override bool Equals(Object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (obj == null)
            {
                return(false);
            }
            if (GetType() != obj.GetType())
            {
                return(false);
            }
            NTRUEncryptionParameters other = (NTRUEncryptionParameters)obj;

            if (N != other.N)
            {
                return(false);
            }
            if (bufferLenBits != other.bufferLenBits)
            {
                return(false);
            }
            if (bufferLenTrits != other.bufferLenTrits)
            {
                return(false);
            }
            if (c != other.c)
            {
                return(false);
            }
            if (db != other.db)
            {
                return(false);
            }
            if (df != other.df)
            {
                return(false);
            }
            if (df1 != other.df1)
            {
                return(false);
            }
            if (df2 != other.df2)
            {
                return(false);
            }
            if (df3 != other.df3)
            {
                return(false);
            }
            if (dg != other.dg)
            {
                return(false);
            }
            if (dm0 != other.dm0)
            {
                return(false);
            }
            if (dr != other.dr)
            {
                return(false);
            }
            if (dr1 != other.dr1)
            {
                return(false);
            }
            if (dr2 != other.dr2)
            {
                return(false);
            }
            if (dr3 != other.dr3)
            {
                return(false);
            }
            if (fastFp != other.fastFp)
            {
                return(false);
            }
            if (hashAlg == null)
            {
                if (other.hashAlg != null)
                {
                    return(false);
                }
            }
            else if (!hashAlg.AlgorithmName.Equals(other.hashAlg.AlgorithmName))
            {
                return(false);
            }
            if (hashSeed != other.hashSeed)
            {
                return(false);
            }
            if (llen != other.llen)
            {
                return(false);
            }
            if (maxMsgLenBytes != other.maxMsgLenBytes)
            {
                return(false);
            }
            if (minCallsMask != other.minCallsMask)
            {
                return(false);
            }
            if (minCallsR != other.minCallsR)
            {
                return(false);
            }
            if (!oid.SequenceEqual(other.oid))
            {
                return(false);
            }
            if (pkLen != other.pkLen)
            {
                return(false);
            }
            if (polyType != other.polyType)
            {
                return(false);
            }
            if (q != other.q)
            {
                return(false);
            }
            if (sparse != other.sparse)
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 5
0
 /**
  * Reads a polynomial <code>h</code> from an input stream and constructs a new public key
  *
  * @param is     an input stream
  * @param params the NtruEncrypt parameters to use
  * @see #writeTo(OutputStream)
  */
 public NTRUEncryptionPublicKeyParameters(Stream stream, NTRUEncryptionParameters parameters) : base(false, parameters)
 {
     h = IntegerPolynomial.FromBinary(stream, parameters.N, parameters.q);
 }
Exemplo n.º 6
0
 /**
  * Converts a byte array to a polynomial <code>h</code> and constructs a new public key
  *
  * @param b      an encoded polynomial
  * @param params the NtruEncrypt parameters to use
  * @see #getEncoded()
  */
 public NTRUEncryptionPublicKeyParameters(byte[] b, NTRUEncryptionParameters parameters) : base(false, parameters)
 {
     h = IntegerPolynomial.FromBinary(b, parameters.N, parameters.q);
 }
Exemplo n.º 7
0
 /**
  * Constructs a new public key from a polynomial
  *
  * @param h      the polynomial <code>h</code> which determines the key
  * @param params the NtruEncrypt parameters to use
  */
 public NTRUEncryptionPublicKeyParameters(IntegerPolynomial h, NTRUEncryptionParameters parameters) : base(false, parameters)
 {
     this.h = h;
 }
 /**
  * Converts a byte array to a polynomial <code>f</code> and constructs a new private key
  *
  * @param b      an encoded polynomial
  * @param params the NtruEncrypt parameters to use
  * @see #getEncoded()
  */
 public NTRUEncryptionPrivateKeyParameters(byte[] b, NTRUEncryptionParameters parameters) : this(new MemoryStream(b), parameters)
 {
 }
 /**
  * Constructs a new private key from a polynomial
  *
  * @param h the public polynomial for the key.
  * @param t      the polynomial which determines the key: if <code>fastFp=true</code>, <code>f=1+3t</code>; otherwise, <code>f=t</code>
  * @param fp     the inverse of <code>f</code>
  * @param params the NtruEncrypt parameters to use
  */
 public NTRUEncryptionPrivateKeyParameters(IntegerPolynomial h, IPolynomial t, IntegerPolynomial fp, NTRUEncryptionParameters parameters) : base(true, parameters)
 {
     this.h  = h;
     this.t  = t;
     this.fp = fp;
 }