Ejemplo n.º 1
0
        private void TestSign(RNBWParameters CipherParam)
        {
            RNBWKeyGenerator mkgen = new RNBWKeyGenerator(CipherParam);
            IAsymmetricKeyPair akp = mkgen.GenerateKeyPair();
            byte[] data = new byte[200];
            new VTDev.Libraries.CEXEngine.Crypto.Prng.CSPRng().GetBytes(data);

            using (RNBWSign sgn = new RNBWSign(CipherParam))
            {
                // sign the array
                sgn.Initialize(akp.PrivateKey);
                byte[] code = sgn.Sign(data, 0, data.Length);
                // verify the signature
                sgn.Initialize(akp.PublicKey);
                if (!sgn.Verify(data, 0, data.Length, code))
                    throw new Exception("RLWESignTest: Sign operation failed!");

                // sign and test stream ctor
                sgn.Initialize(akp.PrivateKey);
                code = sgn.Sign(new MemoryStream(data));
                // verify the signature
                sgn.Initialize(akp.PublicKey);
                if (!sgn.Verify(new MemoryStream(data), code))
                    throw new Exception("RLWESignTest: Verify test failed!");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initialize this class
        /// </summary>
        ///
        /// <param name="CipherParams">The RNBWParameters instance containing the cipher settings</param>
        ///
        /// <exception cref="CryptoAsymmetricSignException">Thrown if a Prng that requires pre-initialization is specified; (wrong constructor)</exception>
        public RNBWKeyGenerator(RNBWParameters CipherParams)
        {
            if (CipherParams.RandomEngine == Prngs.PBPrng)
            {
                throw new CryptoAsymmetricSignException("RNBWKeyGenerator:Ctor", "Passphrase based digest and CTR generators must be pre-initialized, use the other constructor!", new ArgumentException());
            }

            m_rlweParams = CipherParams;
            m_rngEngine  = GetPrng(CipherParams.RandomEngine);
        }
Ejemplo n.º 3
0
        static double KeyGenerator(int Iterations, RNBWParameters Param)
        {
            // new SP20Prng(SeedGenerators.CSPRsg, 16384, 32, 10) // salsa20
            RNBWKeyGenerator mkgen = new RNBWKeyGenerator(Param, new CTRPrng(BlockCiphers.RDX, SeedGenerators.CSPRsg, 16384, 16));
            IAsymmetricKeyPair akp;
            Stopwatch runTimer = new Stopwatch();

            runTimer.Start();
            for (int i = 0; i < Iterations; i++)
                akp = mkgen.GenerateKeyPair();
            runTimer.Stop();

            return runTimer.Elapsed.TotalMilliseconds;
        }
Ejemplo n.º 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);
            }

            RNBWParameters other = (RNBWParameters)Obj;

            if (!Compare.IsEqual(_VI, other.Vi))
            {
                return(false);
            }
            if (m_rndEngine != other.RandomEngine)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Use an initialized prng to generate the key; use this constructor with an Rng that requires pre-initialization, i.e. PBPrng
 /// </summary>
 /// 
 /// <param name="CipherParams">The RNBWParameters instance containing the cipher settings</param>
 /// <param name="RngEngine">An initialized Prng instance</param>
 public RNBWKeyGenerator(RNBWParameters CipherParams, IRandom RngEngine)
 {
     _rlweParams = CipherParams;
     _rngEngine = RngEngine;
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Initialize this class
        /// </summary>
        /// 
        /// <param name="CipherParams">The RNBWParameters instance containing the cipher settings</param>
        /// 
        /// <exception cref="CryptoAsymmetricSignException">Thrown if a Prng that requires pre-initialization is specified; (wrong constructor)</exception>
        public RNBWKeyGenerator(RNBWParameters CipherParams)
        {
            if (CipherParams.RandomEngine == Prngs.PBPrng)
                throw new CryptoAsymmetricSignException("RNBWKeyGenerator:Ctor", "Passphrase based digest and CTR generators must be pre-initialized, use the other constructor!", new ArgumentException());

            _rlweParams = CipherParams;
            _rngEngine = GetPrng(CipherParams.RandomEngine);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Initialize this class
 /// </summary>
 ///
 /// <param name="CipherParams">The RNBW cipher used to encrypt the hash</param>
 public RNBWSign(RNBWParameters CipherParams)
 {
     m_rndEngine     = GetPrng(CipherParams.RandomEngine);
     _signableLength = CipherParams.DocLength;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Use an initialized prng to generate the key; use this constructor with an Rng that requires pre-initialization, i.e. PBPrng
 /// </summary>
 ///
 /// <param name="CipherParams">The RNBWParameters instance containing the cipher settings</param>
 /// <param name="RngEngine">An initialized Prng instance</param>
 public RNBWKeyGenerator(RNBWParameters CipherParams, IRandom RngEngine)
 {
     m_rlweParams = CipherParams;
     m_rngEngine  = RngEngine;
 }
Ejemplo n.º 9
0
        static double SignTest(int Iterations, RNBWParameters Param, bool Sign = true)
        {
            Stopwatch runTimer = new Stopwatch();
            byte[] code;
            RNBWKeyGenerator mkgen = new RNBWKeyGenerator(Param, new CTRPrng(BlockCiphers.RDX, SeedGenerators.CSPRsg, 16384, 16));
            IAsymmetricKeyPair akp = mkgen.GenerateKeyPair();
            byte[] data = new byte[200];
            new CSPRng().GetBytes(data);

            using (RNBWSign sgn = new RNBWSign(Param))
            {
                if (Sign)
                {
                    sgn.Initialize(akp.PrivateKey);

                    runTimer.Start();
                    for (int i = 0; i < Iterations; i++)
                        code = sgn.Sign(data, 0, data.Length);
                    runTimer.Stop();
                }
                else
                {
                    // sign the array first
                    sgn.Initialize(akp.PrivateKey);
                    code = sgn.Sign(data, 0, data.Length);
                    // init for verify
                    sgn.Initialize(akp.PublicKey);

                    runTimer.Start();
                    for (int i = 0; i < Iterations; i++)
                        sgn.Verify(data, 0, data.Length, code);
                    runTimer.Stop();
                }
            }

            return runTimer.Elapsed.TotalMilliseconds;
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Initialize this class
 /// </summary>
 /// 
 /// <param name="CipherParams">The RNBW cipher used to encrypt the hash</param>
 public RNBWSign(RNBWParameters CipherParams)
 {
     _rndEngine = GetPrng(CipherParams.RandomEngine);
     _signableLength = CipherParams.DocLength;
 }