예제 #1
0
        public override byte[] DeriveKeyMaterial(ECDiffieHellmanPublicKey otherPartyPublicKey)
        {
            var d = privateKey.D;

            // read the other side's public key.
            var     opp = otherPartyPublicKey.ToByteArray();
            ECPoint Qs  = ECPoint.FromBlob(opp);

            // multiply their public key with our private d to get the shared secret.
            var p = Qs * d;
            var z = p.X.ToByteArray().Reverse().ToArray();

            return(z);
        }
예제 #2
0
        public override byte[] SignHash(byte[] hash)
        {
            var ephemeral = new ECDiffieHellmanManagedPrivateKey(curve);
            var n         = curve.n;
            var k         = ephemeral.D;
            var R         = ECPoint.FromBlob(ephemeral.PublicKey.ToByteArray());
            var r         = R.X % n;

            var e   = CalculateE(hash);
            var d   = D;
            var val = k.ModInverse(n);
            var s   = (val * (e + (r * d))) % n;

            using (var pw = new PacketWriter())
            {
                pw.WriteString(r.ToByteArray().Reverse().ToArray());
                pw.WriteString(s.ToByteArray().Reverse().ToArray());
                return(((MemoryStream)pw.BaseStream).ToArray());
            }
        }
예제 #3
0
 public void ImportParameters(ECDiffieHellmanManagedPrivateKey privateKey)
 {
     D = privateKey.D;
     q = ECPoint.FromBlob(privateKey.PublicKey.ToByteArray());
 }
예제 #4
0
        public void ImportParameters(ECDiffieHellmanPublicKey otherPartyPublicKey)
        {
            var opp = otherPartyPublicKey.ToByteArray();

            q = ECPoint.FromBlob(opp);
        }