示例#1
0
 /// <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();
 }
示例#2
0
 /// <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();
 }
示例#3
0
        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();
            }
        }
示例#4
0
        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();
                }
            }
        }