예제 #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="NTRUException">Thrown if an invalid or unknown OId is used</exception>
        public static NTRUParameters FromName(NTRUParamNames Name)
        {
            switch (Name)
            {
            case NTRUParamNames.A2011439:
                return((NTRUParameters)APR2011439.Clone());

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

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

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

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

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

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

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

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

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

            case NTRUParamNames.CX1861:
                return((NTRUParameters)CX1861SH512.Clone());

            case NTRUParamNames.CX1931:
                return((NTRUParameters)CX1931SH512.Clone());

            default:
                throw new NTRUException("NTRUParameters:FromName", "The enumeration name is unknown!", new ArgumentException());
            }
        }
예제 #2
0
        /// <summary>
        /// Retrieve a parameter set by its identity code
        /// </summary>
        ///
        /// <param name="OId">The 3 byte parameter set identity code</param>
        /// <param name="UseProduct">Use the product form parameters</param>
        ///
        /// <returns>A parameter set</returns>
        ///
        /// <exception cref="NTRUException">Thrown if an invalid or unknown OId is used</exception>
        public static NTRUParameters FromId(byte[] OId, bool UseProduct = true)
        {
            if (OId == null)
            {
                throw new NTRUException("NTRUParameters:FromId", "OId can not be null!", new ArgumentNullException());
            }
            if (OId.Length != 3)
            {
                throw new NTRUException("NTRUParameters:FromId", "OId must be 3 bytes in length!", new ArgumentOutOfRangeException());
            }
            if (OId[0] != 0)
            {
                throw new NTRUException("NTRUParameters:FromId", "OId is not a valid NTRU parameter id!", new ArgumentException());
            }

            if (UseProduct)
            {
                if (OId[2] == 3)
                {
                    return((NTRUParameters)EES1087EP2FAST.Clone());
                }
                else if (OId[2] == 4)
                {
                    return((NTRUParameters)EES1171EP1FAST.Clone());
                }
                else if (OId[2] == 5)
                {
                    return((NTRUParameters)EES1499EP1FAST.Clone());
                }
                else if (OId[2] == 101)
                {
                    return((NTRUParameters)APR2011439FAST.Clone());
                }
                else if (OId[2] == 105)
                {
                    return((NTRUParameters)APR2011743FAST.Clone());
                }
            }
            else
            {
                if (OId[2] == 3)
                {
                    return((NTRUParameters)EES1087EP2.Clone());
                }
                else if (OId[2] == 4)
                {
                    return((NTRUParameters)EES1171EP1.Clone());
                }
                else if (OId[2] == 5)
                {
                    return((NTRUParameters)EES1499EP1.Clone());
                }
                else if (OId[2] == 101)
                {
                    return((NTRUParameters)APR2011439.Clone());
                }
                else if (OId[2] == 105)
                {
                    return((NTRUParameters)APR2011743.Clone());
                }
                else if (OId[2] == 7)
                {
                    return((NTRUParameters)CX1861SH512.Clone());
                }
                else if (OId[2] == 8)
                {
                    return((NTRUParameters)CX1931SH512.Clone());
                }
            }

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