Ejemplo n.º 1
0
        /// <summary>
        /// Retrieve a parameter set by its enumeration name
        /// </summary>
        ///
        /// <param name="ParamName">The enumeration name</param>
        ///
        /// <returns>A populated parameter set</returns>
        ///
        /// <exception cref="CryptoAsymmetricException">Thrown if an invalid or unknown OId is used</exception>
        public static NTRUParameters FromName(NTRUParamNames ParamName)
        {
            switch (ParamName)
            {
            case NTRUParamNames.A2011439:
                return((NTRUParameters)APR2011439.DeepCopy());

            case NTRUParamNames.A2011743:
                return((NTRUParameters)APR2011743.DeepCopy());

            case NTRUParamNames.E1087EP2:
                return((NTRUParameters)EES1087EP2.DeepCopy());

            case NTRUParamNames.E1171EP1:
                return((NTRUParameters)EES1171EP1.DeepCopy());

            case NTRUParamNames.E1499EP1:
                return((NTRUParameters)EES1499EP1.DeepCopy());

            case NTRUParamNames.FA2011439:
                return((NTRUParameters)APR2011439FAST.DeepCopy());

            case NTRUParamNames.FA2011743:
                return((NTRUParameters)APR2011743FAST.DeepCopy());

            case NTRUParamNames.FE1087EP2:
                return((NTRUParameters)EES1087EP2FAST.DeepCopy());

            case NTRUParamNames.FE1171EP1:
                return((NTRUParameters)EES1171EP1FAST.DeepCopy());

            case NTRUParamNames.FE1499EP1:
                return((NTRUParameters)EES1499EP1FAST.DeepCopy());

            case NTRUParamNames.CX1861:
                return((NTRUParameters)CX1861SK512.DeepCopy());

            case NTRUParamNames.CX1931:
                return((NTRUParameters)CX1931SK512.DeepCopy());

            default:
                throw new CryptoAsymmetricException("NTRUParameters:FromName", "The enumeration name is unknown!", new ArgumentException());
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Retrieve a parameter set by its identity code
        /// </summary>
        ///
        /// <param name="OId">The 4 byte parameter set identity code</param>
        ///
        /// <returns>A parameter set</returns>
        ///
        /// <exception cref="CryptoAsymmetricException">Thrown if an invalid or unknown OId is used</exception>
        public static NTRUParameters FromId(byte[] OId)
        {
            if (OId == null)
            {
                throw new CryptoAsymmetricException("NTRUParameters:FromId", "OId can not be null!", new ArgumentNullException());
            }
            if (OId.Length != 4)
            {
                throw new CryptoAsymmetricException("NTRUParameters:FromId", "OId must be 4 bytes in length!", new ArgumentOutOfRangeException());
            }
            if (OId[0] != (byte)AsymmetricEngines.NTRU)
            {
                throw new CryptoAsymmetricException("NTRUParameters:FromId", "OId is not a valid NTRU parameter id!", new ArgumentException());
            }

            if (OId[2] == 2)
            {
                if (OId[3] == 63)
                {
                    return((NTRUParameters)EES1087EP2FAST.DeepCopy());
                }
                else if (OId[3] == 64)
                {
                    return((NTRUParameters)EES1171EP1FAST.DeepCopy());
                }
                else if (OId[3] == 65)
                {
                    return((NTRUParameters)EES1499EP1FAST.DeepCopy());
                }
                else if (OId[3] == 101)
                {
                    return((NTRUParameters)APR2011439FAST.DeepCopy());
                }
                else if (OId[3] == 105)
                {
                    return((NTRUParameters)APR2011743FAST.DeepCopy());
                }
            }
            else if (OId[2] == 1)
            {
                if (OId[3] == 63)
                {
                    return((NTRUParameters)EES1087EP2.DeepCopy());
                }
                else if (OId[3] == 64)
                {
                    return((NTRUParameters)EES1171EP1.DeepCopy());
                }
                else if (OId[3] == 65)
                {
                    return((NTRUParameters)EES1499EP1.DeepCopy());
                }
                else if (OId[3] == 101)
                {
                    return((NTRUParameters)APR2011439.DeepCopy());
                }
                else if (OId[3] == 105)
                {
                    return((NTRUParameters)APR2011743.DeepCopy());
                }
                else if (OId[3] == 7)
                {
                    return((NTRUParameters)CX1861SK512.DeepCopy());
                }
                else if (OId[3] == 8)
                {
                    return((NTRUParameters)CX1931SK512.DeepCopy());
                }
            }

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