using Renci.SshNet.Messages.Transport;
namespace Renci.SshNet.Security
{
internal abstract class KeyExchangeEC : KeyExchange
{
#pragma warning disable SA1401 // Fields should be private
///
/// Specifies client payload.
///
protected byte[] _clientPayload;
///
/// Specifies server payload.
///
protected byte[] _serverPayload;
///
/// Specifies client exchange.
///
protected byte[] _clientExchangeValue;
///
/// Specifies server exchange.
///
protected byte[] _serverExchangeValue;
///
/// Specifies host key data.
///
protected byte[] _hostKey;
///
/// Specifies signature data.
///
protected byte[] _signature;
#pragma warning restore SA1401 // Fields should be private
///
/// Gets the size, in bits, of the computed hash code.
///
///
/// The size, in bits, of the computed hash code.
///
protected abstract int HashSize { get; }
///
/// Calculates key exchange hash value.
///
///
/// Key exchange hash.
///
protected override byte[] CalculateHash()
{
var hashData = new KeyExchangeHashData
{
ClientVersion = Session.ClientVersion,
ServerVersion = Session.ServerVersion,
ClientPayload = _clientPayload,
ServerPayload = _serverPayload,
HostKey = _hostKey,
ClientExchangeValue = _clientExchangeValue,
ServerExchangeValue = _serverExchangeValue,
SharedKey = SharedKey,
};
return Hash(hashData.GetBytes());
}
///
/// Validates the exchange hash.
///
///
/// true if exchange hash is valid; otherwise false.
///
protected override bool ValidateExchangeHash()
{
return ValidateExchangeHash(_hostKey, _signature);
}
///
public override void Start(Session session, KeyExchangeInitMessage message, bool sendClientInitMessage)
{
base.Start(session, message, sendClientInitMessage);
_serverPayload = message.GetBytes();
_clientPayload = Session.ClientInitMessage.GetBytes();
}
}
}