public void Init( ICipherParameters parameters) { AsymmetricKeyParameter kParam; if (parameters is ParametersWithRandom) { ParametersWithRandom rParam = (ParametersWithRandom)parameters; this.random = rParam.Random; kParam = (AsymmetricKeyParameter)rParam.Parameters; } else { this.random = new SecureRandom(); kParam = (AsymmetricKeyParameter)parameters; } if (!(kParam is DHPrivateKeyParameters)) { throw new ArgumentException("DHEngine expects DHPrivateKeyParameters"); } this.key = (DHPrivateKeyParameters)kParam; this.dhParams = key.Parameters; }
public void Init( ICipherParameters parameters) { if (parameters is ParametersWithRandom) { parameters = ((ParametersWithRandom) parameters).Parameters; } if (!(parameters is DHPrivateKeyParameters)) { throw new ArgumentException("DHEngine expects DHPrivateKeyParameters"); } this.key = (DHPrivateKeyParameters) parameters; this.dhParams = key.Parameters; }
protected virtual void GenerateEphemeralClientKeyExchange(DHParameters dhParams, Stream output) { AsymmetricCipherKeyPair dhAgreeClientKeyPair = GenerateDHKeyPair(dhParams); this.dhAgreeClientPrivateKey = (DHPrivateKeyParameters)dhAgreeClientKeyPair.Private; BigInteger Yc = ((DHPublicKeyParameters)dhAgreeClientKeyPair.Public).Y; byte[] keData = BigIntegers.AsUnsignedByteArray(Yc); TlsUtilities.WriteUint24(keData.Length + 2, output); TlsUtilities.WriteOpaque16(keData, output); }
protected bool Equals( DHPrivateKeyParameters other) { return x.Equals(other.x) && base.Equals(other); }
protected virtual byte[] CalculateDHBasicAgreement(DHPublicKeyParameters publicKey, DHPrivateKeyParameters privateKey) { DHBasicAgreement dhAgree = new DHBasicAgreement(); dhAgree.Init(dhAgreeClientPrivateKey); BigInteger agreement = dhAgree.CalculateAgreement(dhAgreeServerPublicKey); return BigIntegers.AsUnsignedByteArray(agreement); }