/** * given a message from a given party and the corresponding public key * calculate the next message in the agreement sequence. In this case * this will represent the shared secret. */ public BigInteger CalculateAgreement( DHPublicKeyParameters pub, BigInteger message) { if (pub == null) throw new ArgumentNullException("pub"); if (message == null) throw new ArgumentNullException("message"); if (!pub.Parameters.Equals(dhParams)) { throw new ArgumentException("Diffie-Hellman public key has wrong parameters."); } BigInteger p = dhParams.P; return message.ModPow(key.X, p).Multiply(pub.Y.ModPow(privateValue, p)).Mod(p); }
protected bool Equals( DHPublicKeyParameters other) { return y.Equals(other.y) && base.Equals(other); }