Beispiel #1
0
		private void DoTest(DSA dsa)
		{
			Console.WriteLine("seed");
			Console.WriteLine(BitConverter.ToString(seed));
			Console.WriteLine("counter={0} h={1}", dsa.Counter, dsa.H);

			Console.WriteLine(dsa);
			
			Assert.AreEqual(105, dsa.Counter);
			Assert.AreEqual(2, dsa.H.ToInt32());

			using (BigNumber q = BigNumber.FromArray(this.out_q)) {
				Assert.IsTrue(q == dsa.Q);
			}

			using (BigNumber p = BigNumber.FromArray(this.out_p)) {
				Assert.IsTrue(p == dsa.P);
			}

			using (BigNumber g = BigNumber.FromArray(this.out_g)) {
				Assert.IsTrue(g == dsa.G);
			}

			byte[] msg = Encoding.ASCII.GetBytes(str1);

			dsa.ConstantTime = true;
			dsa.GenerateKeys();

			byte[] sig = dsa.Sign(msg);
			Assert.IsTrue(dsa.Verify(msg, sig));

			dsa.ConstantTime = false;
			dsa.GenerateKeys();
			sig = dsa.Sign(msg);
			Assert.IsTrue(dsa.Verify(msg, sig));
		}
Beispiel #2
0
		private void DoTest(DSA dsa)
		{
			Console.WriteLine("seed");
			Console.WriteLine(BitConverter.ToString(seed));
			Console.WriteLine("counter={0} h={1}", dsa.Counter, dsa.H);

			Console.WriteLine(dsa);

			if (dsa.Counter != 105)
				throw new Exception("counter should be 105");

			if (dsa.H != 2)
				throw new Exception("h should be 2");

			using (BigNumber q = BigNumber.FromArray(this.out_q))
			{
				if (dsa.Q != q)
					throw new Exception("q value is wrong");
			}

			using (BigNumber p = BigNumber.FromArray(this.out_p))
			{
				if (dsa.P != p)
					throw new Exception("p value is wrong");
			}

			using (BigNumber g = BigNumber.FromArray(this.out_g))
			{
				if (dsa.G != g)
					throw new Exception("g value is wrong");
			}

			byte[] msg = Encoding.ASCII.GetBytes(str1);

			dsa.ConstantTime = true;
			dsa.GenerateKeys();

			byte[] sig = dsa.Sign(msg);
			if (!dsa.Verify(msg, sig))
				throw new Exception("DSA signature failed to verify");

			dsa.ConstantTime = false;
			dsa.GenerateKeys();
			sig = dsa.Sign(msg);
			if (!dsa.Verify(msg, sig))
				throw new Exception("DSA signature failed to verify");
		}