// Need to override since base methods throw a "override me" exception: makes SignData/VerifyData function.
protected override byte[] HashData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm) =>
- CngCommon.HashData(data, offset, count, hashAlgorithm);
+ HashOneShotHelpers.HashData(hashAlgorithm, new ReadOnlySpan<byte>(data, offset, count));
protected override byte[] HashData(Stream data, HashAlgorithmName hashAlgorithm) =>
- CngCommon.HashData(data, hashAlgorithm);
+ HashOneShotHelpers.HashData(hashAlgorithm, data);
protected override bool TryHashData(ReadOnlySpan<byte> source, Span<byte> destination, HashAlgorithmName hashAlgorithm, out int bytesWritten) =>
- CngCommon.TryHashData(source, destination, hashAlgorithm, out bytesWritten);
+ HashOneShotHelpers.TryHashData(hashAlgorithm, source, destination, out bytesWritten);
private void ForceSetKeySize(int newKeySize)
{
public sealed partial class ECDsaCng : ECDsa
{
protected override byte[] HashData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm) =>
- CngCommon.HashData(data, offset, count, hashAlgorithm);
+ HashOneShotHelpers.HashData(hashAlgorithm, new ReadOnlySpan<byte>(data, offset, count));
protected override byte[] HashData(Stream data, HashAlgorithmName hashAlgorithm) =>
- CngCommon.HashData(data, hashAlgorithm);
+ HashOneShotHelpers.HashData(hashAlgorithm, data);
protected override bool TryHashData(ReadOnlySpan<byte> source, Span<byte> destination, HashAlgorithmName hashAlgorithm, out int bytesWritten) =>
- CngCommon.TryHashData(source, destination, hashAlgorithm, out bytesWritten);
+ HashOneShotHelpers.TryHashData(hashAlgorithm, source, destination, out bytesWritten);
}
}
}
protected override byte[] HashData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm) =>
- CngCommon.HashData(data, offset, count, hashAlgorithm);
+ HashOneShotHelpers.HashData(hashAlgorithm, new ReadOnlySpan<byte>(data, offset, count));
protected override bool TryHashData(ReadOnlySpan<byte> data, Span<byte> destination, HashAlgorithmName hashAlgorithm, out int bytesWritten) =>
- CngCommon.TryHashData(data, destination, hashAlgorithm, out bytesWritten);
+ HashOneShotHelpers.TryHashData(hashAlgorithm, data, destination, out bytesWritten);
protected override byte[] HashData(Stream data, HashAlgorithmName hashAlgorithm) =>
- CngCommon.HashData(data, hashAlgorithm);
+ HashOneShotHelpers.HashData(hashAlgorithm, data);
private void ForceSetKeySize(int newKeySize)
{
<Compile Include="System\Security\Cryptography\ChaCha20Poly1305.Windows.cs" />
<Compile Include="System\Security\Cryptography\CngAlgorithmCore.cs" />
<Compile Include="System\Security\Cryptography\CngAsnFormatter.cs" />
- <Compile Include="System\Security\Cryptography\CngCommon.Hash.cs" />
<Compile Include="System\Security\Cryptography\CngCommon.SignVerify.cs" />
<Compile Include="System\Security\Cryptography\CngHelpers.cs" />
<Compile Include="System\Security\Cryptography\CngKey.cs" />
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System;
-using System.Diagnostics;
-using System.IO;
-
-namespace System.Security.Cryptography
-{
- internal static partial class CngCommon
- {
- public static byte[] HashData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm)
- {
- // The classes that call us are sealed and their base class has checked this already.
- Debug.Assert(data != null);
- Debug.Assert(offset >= 0 && offset <= data.Length);
- Debug.Assert(count >= 0 && count <= data.Length);
- Debug.Assert(!string.IsNullOrEmpty(hashAlgorithm.Name));
-
- using (var hashProvider = new HashProviderCng(hashAlgorithm.Name, null))
- {
- hashProvider.AppendHashData(data, offset, count);
- return hashProvider.FinalizeHashAndReset();
- }
- }
-
- public static bool TryHashData(ReadOnlySpan<byte> source, Span<byte> destination, HashAlgorithmName hashAlgorithm, out int bytesWritten)
- {
- Debug.Assert(!string.IsNullOrEmpty(hashAlgorithm.Name));
-
- using (var hashProvider = new HashProviderCng(hashAlgorithm.Name, null))
- {
- if (destination.Length < hashProvider.HashSizeInBytes)
- {
- bytesWritten = 0;
- return false;
- }
-
- hashProvider.AppendHashData(source);
- return hashProvider.TryFinalizeHashAndReset(destination, out bytesWritten);
- }
- }
-
- public static byte[] HashData(Stream data, HashAlgorithmName hashAlgorithm)
- {
- // The classes that call us are sealed and their base class has checked this already.
- Debug.Assert(data != null);
- Debug.Assert(!string.IsNullOrEmpty(hashAlgorithm.Name));
-
- using (var hashProvider = new HashProviderCng(hashAlgorithm.Name, null))
- {
- // Default the buffer size to 4K.
- byte[] buffer = new byte[4096];
- int bytesRead;
- while ((bytesRead = data.Read(buffer, 0, buffer.Length)) > 0)
- {
- hashProvider.AppendHashData(buffer, 0, bytesRead);
- }
- byte[] hash = hashProvider.FinalizeHashAndReset();
- return hash;
- }
- }
- }
-}