Exemple #1
0
        /// <summary>
        /// Generate an encryption Key pair
        /// </summary>
        ///
        /// <returns>A McElieceKeyPair containing public and private keys</returns>
        public IAsymmetricKeyPair GenerateKeyPair()
        {
            // finite field GF(2^m)
            GF2mField field = new GF2mField(_M, _fieldPoly);
            // irreducible Goppa polynomial
            PolynomialGF2mSmallM gp   = new PolynomialGF2mSmallM(field, _T, PolynomialGF2mSmallM.RANDOM_IRREDUCIBLE_POLYNOMIAL, _rndEngine);
            PolynomialRingGF2m   ring = new PolynomialRingGF2m(field, gp);

            // matrix for computing square roots in (GF(2^m))^t
            PolynomialGF2mSmallM[] qInv = ring.SquareRootMatrix;
            // generate canonical check matrix
            GF2Matrix h = GoppaCode.CreateCanonicalCheckMatrix(field, gp);

            // compute short systematic form of check matrix
            GoppaCode.MaMaPe mmp    = GoppaCode.ComputeSystematicForm(h, _rndEngine);
            GF2Matrix        shortH = mmp.SecondMatrix;
            Permutation      p      = mmp.Permutation;
            // compute short systematic form of generator matrix
            GF2Matrix shortG = (GF2Matrix)shortH.ComputeTranspose();
            // obtain number of rows of G (= dimension of the code)
            int k = shortG.RowCount;
            // generate keys
            IAsymmetricKey pubKey  = new MPKCPublicKey(_N, _T, shortG);
            IAsymmetricKey privKey = new MPKCPrivateKey(_N, k, field, gp, p, h, qInv);

            // return key pair
            return(new MPKCKeyPair(pubKey, privKey));
        }
Exemple #2
0
        /// <summary>
        /// Decides whether the given object <c>other</c> is the same as this field
        /// </summary>
        ///
        /// <param name="Obj">The object for comparison</param>
        ///
        /// <returns>Returns <c>(this == other)</c></returns>
        public override bool Equals(Object Obj)
        {
            if (Obj == null || !(Obj is MPKCPublicKey))
            {
                return(false);
            }
            MPKCPublicKey key = (MPKCPublicKey)Obj;

            if (N != key.N)
            {
                return(false);
            }
            if (T != key.T)
            {
                return(false);
            }
            if (!G.Equals(key.G))
            {
                return(false);
            }

            return(true);
        }
Exemple #3
0
        /// <summary>
        /// Get the asymmetric public key from a stream
        /// </summary>
        /// 
        /// <param name="KeyStream">The encoded public key</param>
        /// <param name="Parameters">The cipher parameters</param>
        /// 
        /// <returns>The public key</returns>
        private IAsymmetricKey GetAsymmetricPublicKey(Stream KeyStream, IAsymmetricParameters Parameters)
        {
            IAsymmetricKey key = null;

            try
            {
                if (Parameters.GetType().Equals(typeof(NTRUParameters)))
                    key = new NTRUPublicKey(KeyStream);
                else if (Parameters.GetType().Equals(typeof(MPKCParameters)))
                    key = new MPKCPublicKey(KeyStream);
                else if (Parameters.GetType().Equals(typeof(RLWEParameters)))
                    key = new RLWEPublicKey(KeyStream);

                return key;
            }
            catch (Exception ex)
            {
                throw new CryptoProcessingException("DtmKex:GetAsymmetricPublicKey", "The public key could not be loaded!", ex);
            }
        }
        /// <summary>
        /// Generate an encryption Key pair
        /// </summary>
        /// 
        /// <returns>A McElieceKeyPair containing public and private keys</returns>
        public IAsymmetricKeyPair GenerateKeyPair()
        {
            // finite field GF(2^m)
            GF2mField field = new GF2mField(_M, _fieldPoly);
            // irreducible Goppa polynomial
            PolynomialGF2mSmallM gp = new PolynomialGF2mSmallM(field, _T, PolynomialGF2mSmallM.RANDOM_IRREDUCIBLE_POLYNOMIAL, _rndEngine);
            PolynomialRingGF2m ring = new PolynomialRingGF2m(field, gp);
            // matrix for computing square roots in (GF(2^m))^t
            PolynomialGF2mSmallM[] qInv = ring.SquareRootMatrix;
            // generate canonical check matrix
            GF2Matrix h = GoppaCode.CreateCanonicalCheckMatrix(field, gp);
            // compute short systematic form of check matrix
            GoppaCode.MaMaPe mmp = GoppaCode.ComputeSystematicForm(h, _rndEngine);
            GF2Matrix shortH = mmp.SecondMatrix;
            Permutation p = mmp.Permutation;
            // compute short systematic form of generator matrix
            GF2Matrix shortG = (GF2Matrix)shortH.ComputeTranspose();
            // obtain number of rows of G (= dimension of the code)
            int k = shortG.RowCount;
            // generate keys
            IAsymmetricKey pubKey = new MPKCPublicKey(_N, _T, shortG);
            IAsymmetricKey privKey = new MPKCPrivateKey(_N, k, field, gp, p, h, qInv);

            // return key pair
            return new MPKCKeyPair(pubKey, privKey);
        }