Пример #1
0
        /// <summary>
        /// Initialize this class
        /// </summary>
        ///
        /// <param name="M">The degree of the finite field GF(2^m)</param>
        /// <param name="T">The error correction capability of the code</param>
        /// <param name="OId">Three bytes that uniquely identify the parameter set</param>
        /// <param name="CCA2Engine">The McEliece CCA2 cipher engine</param>
        /// <param name="Digest">The digest used by the cipher engine</param>
        /// <param name="Prng">The Prng used by the cipher</param>
        ///
        /// <exception cref="MPKCException">Thrown if; <c>m &lt; 1</c>, <c>m &gt; 32</c>, <c>t &lt; 0</c> or <c>t &gt; n</c></exception>
        public MPKCParameters(int M, int T, byte[] OId, McElieceCiphers CCA2Engine = McElieceCiphers.Fujisaki, Digests Digest = Digests.SHA256, Prngs Prng = Prngs.CTRPrng)
        {
            if (M < 1)
            {
                throw new MPKCException("MPKCParameters:Ctor", "M must be positive!", new ArgumentException());
            }
            if (M > 32)
            {
                throw new MPKCException("MPKCParameters:Ctor", "M is too large!", new ArgumentOutOfRangeException());
            }

            this.Digest       = Digest;
            this.CCA2Engine   = CCA2Engine;
            this.RandomEngine = Prng;

            Array.Copy(OId, this.OId, Math.Min(OId.Length, 3));
            _M = M;
            _N = 1 << M;

            if (T < 0)
            {
                throw new MPKCException("MPKCParameters:Ctor", "T must be positive!", new ArgumentException());
            }
            if (T > N)
            {
                throw new MPKCException("MPKCParameters:Ctor", "T must be less than n = 2^m!", new ArgumentOutOfRangeException());
            }

            _T         = T;
            _fieldPoly = PolynomialRingGF2.GetIrreduciblePolynomial(M);
        }
Пример #2
0
        /// <summary>
        /// Initialize this class
        /// </summary>
        ///
        /// <param name="Keysize">The length of a Goppa code</param>
        /// <param name="OId">Three bytes that uniquely identify the parameter set</param>
        /// <param name="CCA2Engine">The McEliece CCA2 cipher engine</param>
        /// <param name="Digest">The digest used by the cipher engine</param>
        /// <param name="Prng">The Prng used by the cipher</param>
        ///
        /// <exception cref="MPKCException">Thrown if <c>keysize &lt; 1</c></exception>
        public MPKCParameters(int Keysize, byte[] OId, McElieceCiphers CCA2Engine = McElieceCiphers.Fujisaki, Digests Digest = Digests.SHA256, Prngs Prng = Prngs.CTRPrng)
        {
            if (Keysize < 1)
            {
                throw new MPKCException("MPKCParameters:Ctor", "The key size must be positive!", new ArgumentException());
            }

            this.Digest       = Digest;
            this.CCA2Engine   = CCA2Engine;
            this.RandomEngine = Prng;

            Array.Copy(OId, this.OId, Math.Min(OId.Length, 3));
            _M = 0;
            _N = 1;

            while (_N < Keysize)
            {
                _N <<= 1;
                _M++;
            }
            _T  = _N >> 1;
            _T /= _M;

            _fieldPoly = PolynomialRingGF2.GetIrreduciblePolynomial(_M);
        }
Пример #3
0
        /// <summary>
        /// Initialize this class
        /// </summary>
        ///
        /// <param name="OId">OId - Unique identifier; <c>Family</c>, <c>Set</c>, <c>SubSet</c>, and <c>Designator</c>. The McEliece family must be <c>1</c> corresponding with the <see cref="AsymmetricEngines"/> enumeration.</param>
        /// <param name="Keysize">The length of a Goppa code</param>
        /// <param name="CCA2Engine">The McEliece CCA2 cipher engine</param>
        /// <param name="Digest">The digest used by the cipher engine</param>
        /// <param name="Prng">The Prng used by the cipher</param>
        ///
        /// <exception cref="CryptoAsymmetricException">Thrown if the OId is invalid, or <c>keysize &lt; 1</c></exception>
        public MPKCParameters(byte[] OId, int Keysize, CCA2Ciphers CCA2Engine = CCA2Ciphers.Fujisaki, Digests Digest = Digests.SHA256, Prngs Prng = Prngs.CTRPrng)
        {
            if (Keysize < 1)
            {
                throw new CryptoAsymmetricException("MPKCParameters:Ctor", "The key size must be positive!", new ArgumentException());
            }
            if (OId.Length != OID_SIZE)
            {
                throw new CryptoAsymmetricException("MPKCParameters:Ctor", string.Format("The OId is invalid, the OId length must be {0} bytes!", OID_SIZE, new ArgumentException()));
            }
            if (OId[0] != (byte)AsymmetricEngines.McEliece)
            {
                throw new CryptoAsymmetricException("MPKCParameters:Ctor", string.Format("The OId is invalid, first byte must be family designator ({0})!", AsymmetricEngines.McEliece, new ArgumentException()));
            }

            this.Digest       = Digest;
            this.CCA2Engine   = CCA2Engine;
            this.RandomEngine = Prng;
            Array.Copy(OId, this.OId, Math.Min(OId.Length, OID_SIZE));
            m_M = 0;
            m_N = 1;

            while (m_N < Keysize)
            {
                m_N <<= 1;
                m_M++;
            }
            m_T  = m_N >> 1;
            m_T /= m_M;

            m_fieldPoly = PolynomialRingGF2.GetIrreduciblePolynomial(m_M);
        }
Пример #4
0
        /// <summary>
        /// Initialize this class
        /// </summary>
        ///
        /// <param name="OId">OId - Unique identifier; <c>Family</c>, <c>Set</c>, <c>SubSet</c>, and <c>Designator</c>. The McEliece family must be <c>1</c> corresponding with the <see cref="AsymmetricEngines"/> enumeration.</param>
        /// <param name="M">The degree of the finite field GF(2^m)</param>
        /// <param name="T">The error correction capability of the code</param>
        /// <param name="FieldPoly">The field polynomial</param>
        /// <param name="CCA2Engine">The McEliece CCA2 cipher engine</param>
        /// <param name="Digest">The digest used by the cipher engine</param>
        /// <param name="Prng">The Prng used by the cipher</param>
        ///
        /// <exception cref="CryptoAsymmetricException">Thrown if the OId is invalid or; <c>t &lt; 0</c>, <c>t &gt; n</c>, or <c>poly</c> is not an irreducible field polynomial</exception>
        public MPKCParameters(byte[] OId, int M, int T, int FieldPoly, CCA2Ciphers CCA2Engine = CCA2Ciphers.Fujisaki, Digests Digest = Digests.SHA256, Prngs Prng = Prngs.CTRPrng)
        {
            if (OId.Length != OID_SIZE)
            {
                throw new CryptoAsymmetricException("MPKCParameters:Ctor", string.Format("The OId is invalid, the OId length must be {0} bytes!", OID_SIZE, new ArgumentException()));
            }
            if (OId[0] != (byte)AsymmetricEngines.McEliece)
            {
                throw new CryptoAsymmetricException("MPKCParameters:Ctor", string.Format("The OId is invalid, first byte must be family designator ({0})!", AsymmetricEngines.McEliece, new ArgumentException()));
            }
            if (M < 1)
            {
                throw new CryptoAsymmetricException("MPKCParameters:Ctor", "M must be positive!", new ArgumentException());
            }
            if (M > 32)
            {
                throw new CryptoAsymmetricException("MPKCParameters:Ctor", "M is too large!", new ArgumentOutOfRangeException());
            }

            m_M               = M;
            this.Digest       = Digest;
            this.CCA2Engine   = CCA2Engine;
            this.RandomEngine = Prng;

            Array.Copy(OId, this.OId, Math.Min(OId.Length, OID_SIZE));
            m_N = 1 << M;
            m_T = T;

            if (T < 0)
            {
                throw new CryptoAsymmetricException("MPKCParameters:Ctor", "T must be positive!", new ArgumentException());
            }
            if (T > N)
            {
                throw new CryptoAsymmetricException("MPKCParameters:Ctor", "T must be less than n = 2^m!", new ArgumentOutOfRangeException());
            }

            if ((PolynomialRingGF2.Degree(FieldPoly) == M) && (PolynomialRingGF2.IsIrreducible(FieldPoly)))
            {
                m_fieldPoly = FieldPoly;
            }
            else
            {
                throw new CryptoAsymmetricException("MPKCParameters:Ctor", "Polynomial is not a field polynomial for GF(2^m)", new InvalidDataException());
            }
        }
Пример #5
0
        /// <summary>
        /// Initialize this class
        /// </summary>
        ///
        /// <param name="M">The degree of the finite field GF(2^m)</param>
        /// <param name="T">The error correction capability of the code</param>
        /// <param name="FieldPoly">The field polynomial</param>
        /// <param name="OId">Three bytes that uniquely identify the parameter set</param>
        /// <param name="CCA2Engine">The McEliece CCA2 cipher engine</param>
        /// <param name="Digest">The digest used by the cipher engine</param>
        /// <param name="Prng">The Prng used by the cipher</param>
        ///
        /// <exception cref="MPKCException">Thrown if; <c>t &lt; 0</c>, <c>t &gt; n</c>, or <c>poly</c> is not an irreducible field polynomial</exception>
        public MPKCParameters(int M, int T, int FieldPoly, byte[] OId, McElieceCiphers CCA2Engine = McElieceCiphers.Fujisaki, Digests Digest = Digests.SHA256, Prngs Prng = Prngs.CTRPrng)
        {
            if (M < 1)
            {
                throw new MPKCException("MPKCParameters:Ctor", "M must be positive!", new ArgumentException());
            }
            if (M > 32)
            {
                throw new MPKCException("MPKCParameters:Ctor", "M is too large!", new ArgumentOutOfRangeException());
            }

            _M                = M;
            this.Digest       = Digest;
            this.CCA2Engine   = CCA2Engine;
            this.RandomEngine = Prng;

            Array.Copy(OId, this.OId, Math.Min(OId.Length, 3));
            _N = 1 << M;
            _T = T;

            if (T < 0)
            {
                throw new MPKCException("MPKCParameters:Ctor", "T must be positive!", new ArgumentException());
            }
            if (T > N)
            {
                throw new MPKCException("MPKCParameters:Ctor", "T must be less than n = 2^m!", new ArgumentOutOfRangeException());
            }

            if ((PolynomialRingGF2.Degree(FieldPoly) == M) && (PolynomialRingGF2.IsIrreducible(FieldPoly)))
            {
                _fieldPoly = FieldPoly;
            }
            else
            {
                throw new MPKCException("MPKCParameters:Ctor", "Polynomial is not a field polynomial for GF(2^m)", new InvalidDataException());
            }
        }