/// <summary> /// Abstract base class for Elliptic Curve / AES-256 hybrid ciphers.s /// </summary> /// <param name="Curve">Curve instance</param> public EcAes256(CurvePrimeField Curve) : base() { this.curve = Curve; this.publicKey = Curve.PublicKey; this.hasPrivateKey = true; this.keyString = this.publicKey.X.ToString() + "," + this.publicKey.Y.ToString(); }
/// <summary> /// Abstract base class for Elliptic Curve / AES-256 hybrid ciphers.s /// </summary> /// <param name="X">X-coordinate of remote public key.</param> /// <param name="Y">Y-coordinate of remote public key.</param> /// <param name="ReferenceCurve">Reference curve</param> public EcAes256(byte[] X, byte[] Y, CurvePrimeField ReferenceCurve) : base() { this.publicKey = new PointOnCurve(FromNetwork(X), FromNetwork(Y)); this.curve = ReferenceCurve; this.hasPrivateKey = false; this.keyString = this.publicKey.X.ToString() + "," + this.publicKey.Y.ToString(); }
public void Test_ECDH(CurvePrimeField Curve1, CurvePrimeField Curve2) { int n; for (n = 0; n < 100; n++) { byte[] Key1 = Curve1.GetSharedKey(Curve2.PublicKey, HashFunction.SHA256); byte[] Key2 = Curve2.GetSharedKey(Curve1.PublicKey, HashFunction.SHA256); int i, c; Assert.AreEqual(c = Key1.Length, Key2.Length); for (i = 0; i < c; i++) { Assert.AreEqual(Key1[i], Key2[i]); } Curve1.GenerateKeys(); Curve2.GenerateKeys(); } }
public void Test_ECDSA(CurvePrimeField Curve1, CurvePrimeField Curve2, HashFunction HashFunction) { int n; using (RandomNumberGenerator rnd = RandomNumberGenerator.Create()) { for (n = 0; n < 100; n++) { byte[] Data = new byte[1024]; rnd.GetBytes(Data); KeyValuePair <BigInteger, BigInteger> Signature = Curve1.Sign(Data, HashFunction); bool Valid = Curve2.Verify(Data, Curve1.PublicKey, HashFunction, Signature); Assert.IsTrue(Valid); Curve1.GenerateKeys(); Curve2.GenerateKeys(); } } }