示例#1
0
        /// <summary>
        /// Initialize this class
        /// </summary>
        ///
        /// <param name="CiphersParams">The RLWEParameters instance containing the cipher settings</param>
        ///
        /// <exception cref="RLWEException">Thrown if a Prng that requires pre-initialization is specified; (wrong constructor)</exception>
        public RLWEKeyGenerator(RLWEParameters CiphersParams)
        {
            _rlweParams = CiphersParams;

            if (CiphersParams.RandomEngine == Prngs.PBPrng)
            {
                throw new RLWEException("RLWEKeyGenerator:Ctor", "Passphrase based, digest, and CTR generators must be pre-initialized, use the other constructor!", new ArgumentException());
            }

            _rngEngine = GetPrng(CiphersParams.RandomEngine);
        }
示例#2
0
        /// <summary>
        /// Initialize this class; Prng is created automatically
        /// </summary>
        ///
        /// <param name="CipherParams">The cipher engine</param>
        public RLWEEncrypt(RLWEParameters CipherParams)
        {
            _rndEngine = GetPrng(CipherParams.RandomEngine);
            _N         = CipherParams.N;
            _Q         = CipherParams.Q;
            _Sigma     = CipherParams.Sigma;
            _mFp       = CipherParams.MFP;

            if (CipherParams.N == 256)
            {
                _maxPlainText  = 32;
                _maxCipherText = 32;
            }
            else
            {
                _maxPlainText  = 64;
                _maxCipherText = 64;
            }
        }
示例#3
0
        private void Dispose(bool Disposing)
        {
            if (!_isDisposed && Disposing)
            {
                try
                {
                    if (_rlweParams != null)
                    {
                        _rlweParams.Dispose();
                        _rlweParams = null;
                    }
                    if (_rngEngine != null)
                    {
                        _rngEngine.Dispose();
                        _rngEngine = null;
                    }
                }
                catch { }

                _isDisposed = true;
            }
        }
示例#4
0
        /// <summary>
        /// Compare this object instance with another
        /// </summary>
        ///
        /// <param name="Obj">Object to compare</param>
        ///
        /// <returns>True if equal, otherwise false</returns>
        public override bool Equals(Object Obj)
        {
            if (this == Obj)
            {
                return(true);
            }
            if (Obj == null && this != null)
            {
                return(false);
            }

            RLWEParameters other = (RLWEParameters)Obj;

            if (_N != other.N)
            {
                return(false);
            }
            if (_Q != other.Q)
            {
                return(false);
            }
            if (_rndEngine != other.RandomEngine)
            {
                return(false);
            }
            if (_Sigma != other.Sigma)
            {
                return(false);
            }
            if (_mFp != other.MFP)
            {
                return(false);
            }

            return(true);
        }
示例#5
0
 /// <summary>
 /// Initialize this class with an initialized Prng
 /// </summary>
 ///
 /// <param name="CipherParams">The cipher parameters</param>
 /// <param name="Engine">The initialized cipher prng</param>
 public RLWEEncrypt(RLWEParameters CipherParams, IRandom Engine)
 {
     _rndEngine = Engine;
 }
示例#6
0
 /// <summary>
 /// Initialize this class
 /// </summary>
 ///
 /// <param name="CipherParams">The RLWE cipher used to encrypt the hash</param>
 /// <param name="Digest">The type of digest engine used</param>
 public RLWESign(RLWEParameters CipherParams, Digests Digest = Digests.SHA512)
 {
     _asyCipher = new RLWEEncrypt(CipherParams);
     _dgtEngine = GetDigest(Digest);
 }
示例#7
0
 /// <summary>
 /// Use an initialized prng to generate the key; use this constructor with an Rng that requires pre-initialization,
 /// i.e. PBPrng, DGCPrng, or CTRPrng
 /// </summary>
 ///
 /// <param name="CiphersParams">The RLWEParameters instance containing thecipher settings</param>
 /// <param name="RngEngine">An initialized Prng instance</param>
 public RLWEKeyGenerator(RLWEParameters CiphersParams, IRandom RngEngine)
 {
     _rlweParams = CiphersParams;
     _rngEngine  = RngEngine;
 }