using GostCryptography.Asn1.Gost.Gost_R3410_2001;
using GostCryptography.Base;
using GostCryptography.Config;
using GostCryptography.Gost_R3411;
using GostCryptography.Native;
using GostCryptography.Properties;
using System.Security;
using System.Security.Cryptography;
namespace GostCryptography.Gost_R3410
{
///
/// Реализация алгоритма ГОСТ Р 34.10-2001
///
public sealed class Gost_R3410_2001_AsymmetricAlgorithm : Gost_R3410_AsymmetricAlgorithm
{
///
/// Размер ключа ГОСТ Р 34.10-2001
///
public const int DefaultKeySizeValue = 512;
///
/// Наименование алгоритма цифровой подписи ГОСТ Р 34.10-2001
///
public const string SignatureAlgorithmValue = "urn:ietf:params:xml:ns:cpxmlsec:algorithms:gostr34102001-gostr3411";
///
/// Устаревшее наименование алгоритма цифровой подписи ГОСТ Р 34.10-2001
///
public const string ObsoleteSignatureAlgorithmValue = "http://www.w3.org/2001/04/xmldsig-more#gostr34102001-gostr3411";
///
/// Наименование алгоритма обмена ключами ГОСТ Р 34.10-2001
///
public const string KeyExchangeAlgorithmValue = "urn:ietf:params:xml:ns:cpxmlsec:algorithms:transport-gost2001";
///
/// Известные наименования алгоритма цифровой подписи ГОСТ Р 34.10-2001
///
public static readonly string[] KnownSignatureAlgorithmNames = { SignatureAlgorithmValue, ObsoleteSignatureAlgorithmValue };
///
[SecuritySafeCritical]
public Gost_R3410_2001_AsymmetricAlgorithm() : this(GostCryptoConfig.ProviderType)
{
}
///
[SecuritySafeCritical]
public Gost_R3410_2001_AsymmetricAlgorithm(ProviderType providerType) : base(providerType, DefaultKeySizeValue)
{
}
///
[SecuritySafeCritical]
public Gost_R3410_2001_AsymmetricAlgorithm(CspParameters providerParameters) : base(providerParameters, DefaultKeySizeValue)
{
}
///
public override string AlgorithmName => SignatureAlgorithmValue;
///
public override string SignatureAlgorithm => SignatureAlgorithmValue;
///
public override string KeyExchangeAlgorithm => KeyExchangeAlgorithmValue;
///
protected override int ExchangeAlgId => Constants.CALG_DH_EL_SF;
///
protected override int SignatureAlgId => Constants.CALG_GR3410EL;
///
protected override Gost_R3410_2001_KeyExchangeParams CreateKeyExchangeParams()
{
return new Gost_R3410_2001_KeyExchangeParams();
}
///
[SecuritySafeCritical]
protected override Gost_R3410_2001_KeyExchangeAlgorithm CreateKeyExchangeAlgorithm(ProviderType providerType, SafeProvHandleImpl provHandle, SafeKeyHandleImpl keyHandle, Gost_R3410_2001_KeyExchangeParams keyExchangeParameters)
{
return new Gost_R3410_2001_KeyExchangeAlgorithm(providerType, provHandle, keyHandle, keyExchangeParameters, KeySizeValue, SignatureAlgId);
}
///
[SecuritySafeCritical]
public override GostHashAlgorithm CreateHashAlgorithm()
{
return new Gost_R3411_94_HashAlgorithm(ProviderType, this.GetSafeHandle());
}
///
protected override void ValidateHashParameter(byte[] hash)
{
if (hash == null)
{
throw ExceptionUtility.ArgumentNull(nameof(hash));
}
if (hash.Length != Gost_R3411_94_HashAlgorithm.DefaultHashSizeValue / 8)
{
throw ExceptionUtility.ArgumentOutOfRange(nameof(hash), Resources.InvalidHashSize, Gost_R3411_94_HashAlgorithm.DefaultHashSizeValue / 8);
}
}
///
public override GostKeyExchangeFormatter CreateKeyExchangeFormatter()
{
return new Gost_R3410_2001_KeyExchangeFormatter(this);
}
///
public override GostKeyExchangeDeformatter CreateKeyExchangeDeformatter()
{
return new Gost_R3410_2001_KeyExchangeDeformatter(this);
}
///
protected override Gost_R3410_KeyExchangeXmlSerializer CreateKeyExchangeXmlSerializer()
{
return new Gost_R3410_2001_KeyExchangeXmlSerializer();
}
}
}