예제 #1
0
		private void x9_62_test_internal(Asn1Object obj, string r_in, string s_in) {
			byte[] message = Encoding.ASCII.GetBytes("abc");
			
			using(MessageDigestContext md_ctx = new MessageDigestContext(MessageDigest.ECDSA)) {
				byte[] digest = md_ctx.Digest(message);
				
				Console.Write("testing {0}: ", obj.ShortName);
	
				using(Key key = Key.FromCurveName(obj)) {
					key.GenerateKey();
					Console.Write(".");
					using(DSASignature signature = key.Sign(digest)) {
						Console.Write(".");
						BigNumber r = BigNumber.FromDecimalString(r_in);
						BigNumber s = BigNumber.FromDecimalString(s_in);
						Assert.AreEqual(r, signature.R);
						Assert.AreEqual(s, signature.S);
						Console.Write(".");
						Assert.IsTrue(key.Verify(digest, signature));
						Console.Write(".");
					}
				}
			}
			Console.WriteLine(" ok");
		}
예제 #2
0
		private void test_ecdh_curve(Asn1Object obj, string text, BigNumber.Context ctx) {
			Key a = Key.FromCurveName(obj);
			Key b = Key.FromCurveName(obj);
			BigNumber x_a = new BigNumber();
			BigNumber y_a = new BigNumber();
			BigNumber x_b = new BigNumber();
			BigNumber y_b = new BigNumber();
			
			try {
				Console.Write("Testing key generation with {0}", text);
				
				a.GenerateKey();
				if (a.Group.Method.FieldType == Objects.NID.X9_62_prime_field.NID) {
					a.PublicKey.GetAffineCoordinatesGFp(x_a, y_a, ctx);
				}
				else {
					a.PublicKey.GetAffineCoordinatesGF2m(x_a, y_a, ctx);
				}
				Console.Write(".");
				
				b.GenerateKey();
				if (b.Group.Method.FieldType == Objects.NID.X9_62_prime_field.NID) {
					b.PublicKey.GetAffineCoordinatesGFp(x_b, y_b, ctx);
				}
				else {
					b.PublicKey.GetAffineCoordinatesGF2m(x_b, y_b, ctx);
				}
				Console.Write(".");
				
				byte[] abuf = new byte[MessageDigest.SHA1.Size];
				int aout = a.ComputeKey(b, abuf, KDF1_SHA1);
				Console.Write(".");
				
				byte[] bbuf = new byte[MessageDigest.SHA1.Size];
				int bout = b.ComputeKey(a, bbuf, KDF1_SHA1);
				Console.Write(".");
				
				Assert.Greater(aout, 4);
				Assert.AreEqual(aout, bout);
				Assert.IsTrue(Compare(abuf, bbuf));

				Console.Write(" ok");
			}
			finally {
				a.Dispose();
				b.Dispose();
				x_a.Dispose();
				y_a.Dispose();
				x_b.Dispose();
				y_b.Dispose();
			}
			
			Console.WriteLine();
		}
예제 #3
0
		/// <summary>
		/// Calls EC_KEY_new_by_curve_name()
		/// </summary>
		/// <returns>The curve name.</returns>
		/// <param name="obj">Object.</param>
		public static Key FromCurveName(Asn1Object obj)
		{
			return new Key(Native.ExpectNonNull(Native.EC_KEY_new_by_curve_name(obj.NID)), true);
		}
예제 #4
0
		private BuiltinCurve(int nid, string comment) {
			this.obj = new Asn1Object(nid);
			this.comment = comment;
		}
예제 #5
0
파일: Group.cs 프로젝트: challal/scallion
		public static Group FromCurveName(Asn1Object obj) {
			return new Group(Native.ExpectNonNull(Native.EC_GROUP_new_by_curve_name(obj.NID)), true);
		}