public void TestCase() { OpenSSL.Core.Random.Seed(rnd_seed); BigNumber.GeneratorHandler cb = new BigNumber.GeneratorHandler(this.OnStatus); DH a = new DH(64, DH.Generator5, cb, Console.Out); DH.CheckCode check = a.Check(); if ((check & DH.CheckCode.CheckP_NotPrime) != 0) Console.WriteLine("p value is not prime"); if ((check & DH.CheckCode.CheckP_NotSafePrime) != 0) Console.WriteLine("p value is not safe prime"); if ((check & DH.CheckCode.UnableToCheckGenerator) != 0) Console.WriteLine("unable to check the generator value"); if ((check & DH.CheckCode.NotSuitableGenerator) != 0) Console.WriteLine("the g value is not a generator"); Console.WriteLine(); Console.WriteLine("p ={0}", a.P); Console.WriteLine("g ={0}", a.G); DH b = new DH(a.P, a.G); a.NoExpConstantTime = false; b.NoExpConstantTime = true; a.GenerateKeys(); Console.WriteLine("pri 1={0}", a.PrivateKey); Console.WriteLine("pub 1={0}", a.PublicKey); b.GenerateKeys(); Console.WriteLine("pri 2={0}", b.PrivateKey); Console.WriteLine("pub 2={0}", b.PublicKey); byte[] aout = a.ComputeKey(b.PublicKey); string astr = BitConverter.ToString(aout); Console.WriteLine("key1 ={0}", astr); byte[] bout = b.ComputeKey(a.PublicKey); string bstr = BitConverter.ToString(bout); Console.WriteLine("key2 ={0}", bstr); if (aout.Length < 4 || astr != bstr) throw new Exception("Error in DH routines"); a.Dispose(); b.Dispose(); }
public void CanCreateFromDH() { using (DH dh = new DH()) { dh.GenerateKeys(); using (CryptoKey key = new CryptoKey(dh)) { Assert.AreEqual(CryptoKey.KeyType.DH, key.Type); } } }
public void CanCompareDH() { using (var dh = new DH()) { dh.GenerateKeys(); using (var lhs = new CryptoKey(dh)) { Assert.AreEqual(lhs, lhs); using (var rhs = new CryptoKey(dh)) { Assert.AreEqual(lhs, rhs); } using (var dh2 = new DH(1, 5)) { dh2.GenerateKeys(); using (var other = new CryptoKey(dh2)) { Assert.AreNotEqual(lhs, other); } } } } }
public void CanCreateFromDH() { using (var dh = new DH()) { dh.GenerateKeys(); using (var key = new CryptoKey(dh)) { Assert.AreEqual(CryptoKey.KeyType.DH, key.Type); Assert.AreEqual(dh.Handle, key.GetDH().Handle); } using (var key = new CryptoKey()) { key.Assign(dh); Assert.AreEqual(dh.Handle, key.GetDH().Handle); } } }