Exemplo n.º 1
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="RLWEException">Thrown if an invalid or unknown OId is used.</exception>
        public static RLWEParameters FromId(byte[] OId)
        {
            if (OId == null)
            {
                throw new RLWEException("RLWEParamSets:FromId", "OId can not be null!", new ArgumentNullException());
            }
            if (OId.Length != 3)
            {
                throw new RLWEException("RLWEParamSets:FromId", "OId must be 3 bytes in length!", new ArgumentOutOfRangeException());
            }
            if (OId[0] != 2)
            {
                throw new RLWEException("RLWEParamSets:FromId", "OId is not a valid RLWE parameter id!", new ArgumentException());
            }

            if (OId[2] == 0)
            {
                return((RLWEParameters)RLWEN256Q7681.Clone());
            }
            else if (OId[2] == 1)
            {
                return((RLWEParameters)RLWEN512Q12289.Clone());
            }

            throw new RLWEException("RLWEParamSets:FromId", "OId does not identify a valid param set!", new ArgumentOutOfRangeException());
        }
Exemplo 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 populated parameter set</returns>
        ///
        /// <exception cref="CryptoAsymmetricException">Thrown if an invalid or unknown OId is used.</exception>
        public static RLWEParameters FromId(byte[] OId)
        {
            if (OId == null)
            {
                throw new CryptoAsymmetricException("RLWEParamSets:FromId", "OId can not be null!", new ArgumentNullException());
            }
            if (OId.Length != 4)
            {
                throw new CryptoAsymmetricException("RLWEParamSets:FromId", "OId must be 4 bytes in length!", new ArgumentOutOfRangeException());
            }
            if (OId[0] != (byte)AsymmetricEngines.RingLWE)
            {
                throw new CryptoAsymmetricException("RLWEParamSets:FromId", "OId is not a valid RLWE parameter id!", new ArgumentException());
            }

            if (OId[3] == 1)
            {
                return((RLWEParameters)RLWEN256Q7681.DeepCopy());
            }
            else if (OId[3] == 2)
            {
                return((RLWEParameters)RLWEN512Q12289.DeepCopy());
            }

            throw new CryptoAsymmetricException("RLWEParamSets:FromId", "OId does not identify a valid param set!", new ArgumentOutOfRangeException());
        }
Exemplo n.º 3
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="RLWEException">Thrown if an invalid or unknown parameter name is used.</exception>
        public static RLWEParameters FromName(RLWEParamNames Name)
        {
            switch (Name)
            {
            case RLWEParamNames.N256Q7681:
                return((RLWEParameters)RLWEN256Q7681.Clone());

            case RLWEParamNames.N512Q12289:
                return((RLWEParameters)RLWEN512Q12289.Clone());

            default:
                throw new RLWEException("RLWEParamSets:FromName", "The enumeration name is unknown!", new ArgumentException());
            }
        }
Exemplo n.º 4
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 parameter name is used.</exception>
        public static RLWEParameters FromName(RLWEParamNames ParamName)
        {
            switch (ParamName)
            {
            case RLWEParamNames.N256Q7681:
                return((RLWEParameters)RLWEN256Q7681.DeepCopy());

            case RLWEParamNames.N512Q12289:
                return((RLWEParameters)RLWEN512Q12289.DeepCopy());

            default:
                throw new CryptoAsymmetricException("RLWEParamSets:FromName", "The enumeration name is unknown!", new ArgumentException());
            }
        }