Example #1
0
        /// <summary>
        /// Retrieve a parameter set by its enumeration name
        /// </summary>
        ///
        /// <param name="Name">The enumeration name</param>
        ///
        /// <returns>A populated parameter set</returns>
        ///
        /// <exception cref="MPKCException">Thrown if an invalid or unknown OId is specified</exception>
        public static MPKCParameters FromName(MPKCParamNames Name)
        {
            switch (Name)
            {
            case MPKCParamNames.FM11T40S256:
                return((MPKCParameters)MPKCFM11T40S256.Clone());

            case MPKCParamNames.FM11T48S256:
                return((MPKCParameters)MPKCFM11T48S256.Clone());

            case MPKCParamNames.FM12T31S256:
                return((MPKCParameters)MPKCFM12T31S256.Clone());

            case MPKCParamNames.FM12T41S256:
                return((MPKCParameters)MPKCFM12T41S256.Clone());

            case MPKCParamNames.FM12T48S256:
                return((MPKCParameters)MPKCFM12T48S256.Clone());

            case MPKCParamNames.FM12T54K256:
                return((MPKCParameters)MPKCFM12T54K256.Clone());

            case MPKCParamNames.FM12T67S256:
                return((MPKCParameters)MPKCFM12T67S256.Clone());

            case MPKCParamNames.FM13T29S256:
                return((MPKCParameters)MPKCFM13T29S256.Clone());

            case MPKCParamNames.FM13T44K256:
                return((MPKCParameters)MPKCFM13T44K256.Clone());

            case MPKCParamNames.FM13T95S256:
                return((MPKCParameters)MPKCFM13T95S256.Clone());

            case MPKCParamNames.FM14T24K256:
                return((MPKCParameters)MPKCFM14T24K256.Clone());

            default:
                throw new MPKCException("MPKCParamSets:FromName", "The Parameter Name is not recognized!", new ArgumentException());
            }
        }
Example #2
0
        /// <summary>
        /// Retrieve a parameter set by its identity code
        /// </summary>
        ///
        /// <param name="OId">The 3 byte parameter set identity code</param>
        ///
        /// <returns>A populated parameter set</returns>
        ///
        /// <exception cref="MPKCException">Thrown if an invalid or unknown OId is specified</exception>
        public static MPKCParameters FromId(byte[] OId)
        {
            if (OId == null)
            {
                throw new MPKCException("MPKCParamSets:FromId", "OId can not be null!", new ArgumentException());
            }
            if (OId.Length != 3)
            {
                throw new MPKCException("MPKCParamSets:FromId", "OId must be 3 bytes in length!", new ArgumentException());
            }
            if (OId[0] != 1)
            {
                throw new MPKCException("MPKCParamSets:FromId", "OId is not a valid MPKC parameter id!", new ArgumentException());
            }

            if (OId[1] == 1)
            {
                if (OId[2] == 0)
                {
                    return((MPKCParameters)MPKCFM11T40S256.Clone());
                }
                else if (OId[2] == 1)
                {
                    return((MPKCParameters)MPKCFM11T48S256.Clone());
                }
            }
            else if (OId[1] == 2)
            {
                if (OId[2] == 0)
                {
                    return((MPKCParameters)MPKCFM12T31S256.Clone());
                }
                else if (OId[2] == 1)
                {
                    return((MPKCParameters)MPKCFM12T41S256.Clone());
                }
                else if (OId[2] == 2)
                {
                    return((MPKCParameters)MPKCFM12T48S256.Clone());
                }
                else if (OId[2] == 3)
                {
                    return((MPKCParameters)MPKCFM12T54K256.Clone());
                }
                else if (OId[2] == 4)
                {
                    return((MPKCParameters)MPKCFM12T67S256.Clone());
                }
            }
            else if (OId[1] == 3)
            {
                if (OId[2] == 0)
                {
                    return((MPKCParameters)MPKCFM13T29S256.Clone());
                }
                else if (OId[2] == 1)
                {
                    return((MPKCParameters)MPKCFM13T44K256.Clone());
                }
                else if (OId[2] == 2)
                {
                    return((MPKCParameters)MPKCFM13T95S256.Clone());
                }
            }
            else if (OId[1] == 4)
            {
                if (OId[2] == 0)
                {
                    return((MPKCParameters)MPKCFM14T24K256.Clone());
                }
            }

            throw new MPKCException("MPKCParamSets:FromId", "OId does not identify a valid param set!", new ArgumentException());
        }
Example #3
0
        /// <summary>
        /// Retrieve a parameter set by its identity code
        /// </summary>
        ///
        /// <param name="OId">The 4 byte parameter set identity code</param>
        ///
        /// <returns>A populated parameter set</returns>
        ///
        /// <exception cref="CryptoAsymmetricException">Thrown if an invalid or unknown OId is specified</exception>
        public static MPKCParameters FromId(byte[] OId)
        {
            if (OId == null)
            {
                throw new CryptoAsymmetricException("MPKCParamSets:FromId", "OId can not be null!", new ArgumentException());
            }
            if (OId.Length != 4)
            {
                throw new CryptoAsymmetricException("MPKCParamSets:FromId", "OId must be 4 bytes in length!", new ArgumentException());
            }
            if (OId[0] != (byte)AsymmetricEngines.McEliece)
            {
                throw new CryptoAsymmetricException("MPKCParamSets:FromId", "OId is not a valid MPKC parameter id!", new ArgumentException());
            }

            if (OId[2] == 11)
            {
                if (OId[3] == 1)
                {
                    return((MPKCParameters)MPKCFM11T40S256.DeepCopy());
                }
                else if (OId[3] == 2)
                {
                    return((MPKCParameters)MPKCFM11T48S256.DeepCopy());
                }
            }
            else if (OId[2] == 12)
            {
                if (OId[3] == 1)
                {
                    return((MPKCParameters)MPKCFM12T31S256.DeepCopy());
                }
                else if (OId[3] == 2)
                {
                    return((MPKCParameters)MPKCFM12T41S256.DeepCopy());
                }
                else if (OId[3] == 3)
                {
                    return((MPKCParameters)MPKCFM12T48S256.DeepCopy());
                }
                else if (OId[3] == 4)
                {
                    return((MPKCParameters)MPKCFM12T54K256.DeepCopy());
                }
                else if (OId[3] == 5)
                {
                    return((MPKCParameters)MPKCFM12T67S256.DeepCopy());
                }
            }
            else if (OId[2] == 13)
            {
                if (OId[3] == 1)
                {
                    return((MPKCParameters)MPKCFM13T29S256.DeepCopy());
                }
                else if (OId[3] == 2)
                {
                    return((MPKCParameters)MPKCFM13T44K256.DeepCopy());
                }
                else if (OId[3] == 3)
                {
                    return((MPKCParameters)MPKCFM13T95S256.DeepCopy());
                }
            }
            else if (OId[2] == 14)
            {
                if (OId[3] == 1)
                {
                    return((MPKCParameters)MPKCFM14T24K256.DeepCopy());
                }
            }

            throw new CryptoAsymmetricException("MPKCParamSets:FromId", "OId does not identify a valid param set!", new ArgumentException());
        }