Skip to content

Commit

Permalink
add Gost28147
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodriges Hechicero committed Oct 25, 2018
1 parent 886552e commit 895e89f
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ public abstract partial class Gost3410 : System.Security.Cryptography.Asymmetric
public abstract byte[] SignHash(byte[] hash, HashAlgorithmName hashAlgorithm);
public abstract bool VerifyHash(byte[] hash, byte[] signature, HashAlgorithmName hashAlgorithm);
protected abstract byte[] HashData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm);
protected abstract byte[] HashData(IO.Stream data, HashAlgorithmName hashAlgorithm);
protected abstract byte[] HashData(IO.Stream data, HashAlgorithmName hashAlgorithm);
public virtual bool TryDecrypt(ReadOnlySpan<byte> data, Span<byte> destination, out int bytesWritten) { throw null; }
public virtual bool TryEncrypt(ReadOnlySpan<byte> data, Span<byte> destination, out int bytesWritten) { throw null; }
protected virtual bool TryHashData(ReadOnlySpan<byte> data, Span<byte> destination, HashAlgorithmName hashAlgorithm, out int bytesWritten) { throw null; }
Expand Down Expand Up @@ -726,5 +726,28 @@ protected Gost3411() { }
public static new System.Security.Cryptography.Gost3411 Create(string hashName) { throw null; }
}

public enum GostKeyExchangeExportMethod
{
GostKeyExport,
CryptoProKeyExport
}

public abstract class Gost28147 : SymmetricAlgorithm
{
protected Gost28147() { }

public const int DefaultIvSize = 8;
public const int DefaultKeySize = 256;
public const int DefaultBlockSize = 64;
public const int DefaultFeedbackSize = 64;
public static readonly KeySizes[] DefaultLegalKeySizes = { };
public static readonly KeySizes[] DefaultLegalBlockSizes = { };
public static new System.Security.Cryptography.Gost28147 Create() { throw null; }
public static new System.Security.Cryptography.Gost28147 Create(string algName) { throw null; }
public abstract byte[] ComputeHash(HashAlgorithm hash);
public abstract byte[] EncodePrivateKey(System.Security.Cryptography.Gost28147 keyExchangeAlgorithm, System.Security.Cryptography.GostKeyExchangeExportMethod keyExchangeExportMethod);
public abstract SymmetricAlgorithm DecodePrivateKey(byte[] encodedKeyExchangeData, System.Security.Cryptography.GostKeyExchangeExportMethod keyExchangeExportMethod);
}

//end: SK
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<NoWarn>CS3016;CA5351;$(NoWarn)</NoWarn>
<Configurations>netcoreapp-OSX-Debug;netcoreapp-OSX-Release;netcoreapp-Unix-Debug;netcoreapp-Unix-Release;netcoreapp-Windows_NT-Debug;netcoreapp-Windows_NT-Release;uap-Windows_NT-Debug;uap-Windows_NT-Release</Configurations>
</PropertyGroup>
<Import Project="$(CommonPath)\System\Security\Cryptography\Asn1\AsnXml.targets"/>
<Import Project="$(CommonPath)\System\Security\Cryptography\Asn1\AsnXml.targets" />
<ItemGroup>
<Compile Include="Internal\Cryptography\AesImplementation.cs" />
<Compile Include="Internal\Cryptography\DesImplementation.cs" />
Expand All @@ -28,6 +28,7 @@
<Compile Include="System\Security\Cryptography\AsymmetricSignatureFormatter.cs" />
<Compile Include="System\Security\Cryptography\CryptoConfig.cs" />
<Compile Include="System\Security\Cryptography\DeriveBytes.cs" />
<Compile Include="System\Security\Cryptography\Gost28147.cs" />
<Compile Include="System\Security\Cryptography\DES.cs" />
<Compile Include="System\Security\Cryptography\DSA.cs" />
<Compile Include="System\Security\Cryptography\DSA.Xml.cs" />
Expand All @@ -45,6 +46,7 @@
<Compile Include="System\Security\Cryptography\ECDsa.Xml.cs" />
<Compile Include="System\Security\Cryptography\ECParameters.cs" />
<Compile Include="System\Security\Cryptography\ECPoint.cs" />
<Compile Include="System\Security\Cryptography\GostKeyExchangeExportMethod.cs" />
<Compile Include="System\Security\Cryptography\MaskGenerationMethod.cs" />
<Compile Include="System\Security\Cryptography\MD5.cs" />
<Compile Include="System\Security\Cryptography\SHA1.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Internal.Cryptography;
using System.ComponentModel;

namespace System.Security.Cryptography
{
[EditorBrowsable(EditorBrowsableState.Never)]
public abstract class Gost28147 : SymmetricAlgorithm
{
protected Gost28147()
{
KeySizeValue = DefaultKeySize;
BlockSizeValue = DefaultBlockSize;
FeedbackSizeValue = DefaultFeedbackSize;
LegalBlockSizesValue = DefaultLegalBlockSizes;
LegalKeySizesValue = DefaultLegalKeySizes;
}

/// <summary>
/// Ðàçìåð êëþ÷à 256 áèò.
/// </summary>
internal const int DefaultBlockSize = 64;
/// <summary>
/// Ðàçìåð áëîêà 64 áèòà.
/// </summary>
internal const int DefaultKeySize = 256;
/// <summary>
/// Ðàçìåð çàöåïëåíèÿ 64 áèòà.
/// </summary>
internal const int DefaultFeedbackSize = 64;
/// <summary>
/// Ðàçìåð ñèíõðîïîñûëêè 64 áèòà.
/// </summary>
internal const int DefaultIvSize = 64;

public static readonly KeySizes[] DefaultLegalKeySizes = { new KeySizes(DefaultKeySize, DefaultKeySize, 0) };
public static readonly KeySizes[] DefaultLegalBlockSizes = { new KeySizes(DefaultBlockSize, DefaultBlockSize, 0) };


/// <summary>
/// Ñîçäàíèå îáúåêòà, ðåàëèçóåùåãî àëãîðèòì øèôðîâàíèÿ ÃÎÑÒ-28147.
/// </summary>
///
/// <returns>Êðèïòîãðàôè÷åñêèé îáúåêò, ðåàëèçóþùèé àëãîðèòì ÃÎÑÒ
/// 28147.</returns>
///
/// <remarks><para>Ñîçäàíèå îáúåêòà àëãîðèòìà øèôðîâàíèÿ ÃÎÑÒ 28147.
/// Îáúåêò ìîæåò èñïîëüçîâàòüñÿ
/// äëÿ ñèììåòðè÷íîãî çàøèôðîâàíèÿ è ðàñøèôðîâàíèÿ.</para></remarks>
///
/// <doc-sample path="Simple\Encrypt" name="EncryptDecryptRandomFile"
/// region="EncryptDecryptRandomFile">Ïðèìåð çàøèôðîâàíèÿ è
/// ðàñøèôðîâàíèÿ ôàéëà ïðè ïîìîùè
/// ïîðîæäåííîãî êëàññà <see cref="Gost28147CryptoServiceProvider"/>.
/// </doc-sample>
public static new Gost28147 Create()
{
// Ñîçäàíèå îáúåêòà èäåò ïî êîíôèãóðàöèè äëÿ àëãîðèòìà çàäàííîãî
// ïîëíûì èìåíåì êëàññà Gost28147.
return Gost28147.Create(typeof(Gost28147).FullName);
}

/// <summary>
/// Ñîçäàíèå îáúåêòà, ðåàëèçóþùåãî àëãîðèòì øèôðîâàíèÿ ÃÎÑÒ-28147
/// ñ çàäàííûì èìåíåì ðåàëèçàöèè.
/// </summary>
///
/// <param name="algName">Èìÿ ðåàëèçàöèè àëãîðèòìà.</param>
///
/// <returns>Êðèïòîãðàôè÷åñêèé îáúåêò, ðåàëèçóþùèé àëãîðèòì
/// ÃÎÑÒ 28147.</returns>
///
/// <doc-sample path="Simple\Encrypt" name="EncryptDecryptRandomFile"
/// region="EncryptDecryptRandomFile">Ïðèìåð çàøèôðîâàíèÿ è
/// ðàñøèôðîâàíèÿ ôàéëà ïðè ïîìîùè
/// ïîðîæäåííîãî êëàññà <see cref="Gost28147CryptoServiceProvider"/>.
/// </doc-sample>
public static new Gost28147 Create(string algName)
{
// Ñîçäàíèå îáúåêòà èäåò ïî êîíôèãóðàöèè äëÿ àëãîðèòìà çàäàííîãî
// ïàðàìåòðîì.
return (Gost28147)CryptoConfig.CreateFromName(algName);
}

/// <summary>
/// Õýøèðóåò ñåêðåòíûé êëþ÷.
/// </summary>
///
/// <param name="hash">Êëàññ, ðåàëèçóþùèé ôóíêöèþ õýøèðîâàíèÿ.</param>
///
/// <returns>Õýø-çíà÷åíèå ñåêðåòíîãî êëþ÷à</returns>
public abstract byte[] ComputeHash(HashAlgorithm hash);

/// <summary>
/// Ýêñïîðòèðóåò (øèôðóåò) ñåêðåòíûé êëþ÷.
/// </summary>
/// <param name="keyExchangeAlgorithm">Îáùèé ñåêðåòíûé êëþ÷.</param>
/// <param name="keyExchangeExportMethod">Àëãîðèòì ýêñïîðòà îáùåãî ñåêðåòíîãî êëþ÷à.</param>
public abstract byte[] EncodePrivateKey(Gost28147 keyExchangeAlgorithm, GostKeyExchangeExportMethod keyExchangeExportMethod);

/// <summary>
/// Èìïîðòèðóåò (äåøèôðóåò) ñåêðåòíûé êëþ÷.
/// </summary>
/// <param name="encodedKeyExchangeData">Çàøèôðîâàííûé îáùèé ñåêðåòíûé êëþ÷.</param>
/// <param name="keyExchangeExportMethod">Àëãîðèòì ýêñïîðòà îáùåãî ñåêðåòíîãî êëþ÷à.</param>
public abstract SymmetricAlgorithm DecodePrivateKey(byte[] encodedKeyExchangeData, GostKeyExchangeExportMethod keyExchangeExportMethod);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Runtime.InteropServices;

namespace System.Security.Cryptography
{
/// <summary>
/// Àëãîðèòì ýêñïîðòà îáùåãî ñåêðåòíîãî êëþ÷à.
/// </summary>
public enum GostKeyExchangeExportMethod
{
/// <summary>
/// Ïðîñòîé ýêñïîðò êëþ÷à ïî ÃÎÑÒ 28147-89.
/// </summary>
GostKeyExport,

/// <summary>
/// Çàùèù¸ííûé ýêñïîðò êëþ÷à ïî àëãîðèòìó ÊðèïòîÏðî.
/// </summary>
CryptoProKeyExport
}
}

0 comments on commit 895e89f

Please sign in to comment.