public void TestECDH() { byte[] kA = new byte[X448.ScalarSize]; byte[] kB = new byte[X448.ScalarSize]; byte[] qA = new byte[X448.PointSize]; byte[] qB = new byte[X448.PointSize]; byte[] sA = new byte[X448.PointSize]; byte[] sB = new byte[X448.PointSize]; for (int i = 1; i <= 100; ++i) { // Each party generates an ephemeral private key, ... Random.NextBytes(kA); Random.NextBytes(kB); // ... publishes their public key, ... X448.ScalarMultBase(kA, 0, qA, 0); X448.ScalarMultBase(kB, 0, qB, 0); // ... computes the shared secret, ... X448.ScalarMult(kA, 0, qB, 0, sA, 0); X448.ScalarMult(kB, 0, qA, 0, sB, 0); // ... which is the same for both parties. Assert.IsTrue(Arrays.AreEqual(sA, sB), "ECDH #" + i); } }
public void TestConsistency() { byte[] u = new byte[X448.PointSize]; u[0] = 5; byte[] k = new byte[X448.ScalarSize]; byte[] rF = new byte[X448.PointSize]; byte[] rV = new byte[X448.PointSize]; for (int i = 1; i <= 100; ++i) { Random.NextBytes(k); X448.ScalarMultBase(k, 0, rF, 0); X448.ScalarMult(k, 0, u, 0, rV, 0); Assert.IsTrue(Arrays.AreEqual(rF, rV), "Consistency #" + i); } }
private static void CheckECDHVector(string sA, string sAPub, string sB, string sBPub, string sK, string text) { byte[] a = Hex.Decode(sA); byte[] b = Hex.Decode(sB); byte[] aPub = new byte[56]; X448.ScalarMultBase(a, 0, aPub, 0); CheckValue(aPub, text, sAPub); byte[] bPub = new byte[56]; X448.ScalarMultBase(b, 0, bPub, 0); CheckValue(bPub, text, sBPub); byte[] aK = new byte[56]; X448.ScalarMult(a, 0, bPub, 0, aK, 0); CheckValue(aK, text, sK); byte[] bK = new byte[56]; X448.ScalarMult(b, 0, aPub, 0, bK, 0); CheckValue(bK, text, sK); }
private static void CheckECDHVector(string sA, string sAPub, string sB, string sBPub, string sK, string text) { byte[] a = Hex.Decode(sA); Assert.AreEqual(X448.ScalarSize, a.Length); byte[] b = Hex.Decode(sB); Assert.AreEqual(X448.ScalarSize, b.Length); byte[] aPub = new byte[X448.PointSize]; X448.ScalarMultBase(a, 0, aPub, 0); CheckValue(aPub, text, sAPub); byte[] bPub = new byte[X448.PointSize]; X448.ScalarMultBase(b, 0, bPub, 0); CheckValue(bPub, text, sBPub); byte[] aK = new byte[X448.PointSize]; X448.ScalarMult(a, 0, bPub, 0, aK, 0); CheckValue(aK, text, sK); byte[] bK = new byte[X448.PointSize]; X448.ScalarMult(b, 0, aPub, 0, bK, 0); CheckValue(bK, text, sK); }
public X448PublicKeyParameters GeneratePublicKey() { byte[] publicKey = new byte[X448.PointSize]; X448.ScalarMultBase(data, 0, publicKey, 0); return(new X448PublicKeyParameters(publicKey, 0)); }