Skip to content

Commit 4101144

Browse files
authored
HashAlgorithmName one-shots (#92430)
* Implement HMAC and hash one-shot for HashAlgorithmName. * Use throw helper for destination length. Also change the variable name for the hash length to be consistent accross all methods.
1 parent f68bbe2 commit 4101144

33 files changed

+1344
-216
lines changed

src/libraries/Common/src/System/Security/Cryptography/DSAAndroid.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,14 @@ protected override byte[] HashData(byte[] data, int offset, int count, HashAlgor
193193
Debug.Assert(count >= 0 && count <= data.Length);
194194
Debug.Assert(!string.IsNullOrEmpty(hashAlgorithm.Name));
195195

196-
return HashOneShotHelpers.HashData(hashAlgorithm, new ReadOnlySpan<byte>(data, offset, count));
196+
return CryptographicOperations.HashData(hashAlgorithm, new ReadOnlySpan<byte>(data, offset, count));
197197
}
198198

199199
protected override byte[] HashData(Stream data, HashAlgorithmName hashAlgorithm) =>
200-
HashOneShotHelpers.HashData(hashAlgorithm, data);
200+
CryptographicOperations.HashData(hashAlgorithm, data);
201201

202202
protected override bool TryHashData(ReadOnlySpan<byte> data, Span<byte> destination, HashAlgorithmName hashAlgorithm, out int bytesWritten) =>
203-
HashOneShotHelpers.TryHashData(hashAlgorithm, data, destination, out bytesWritten);
203+
CryptographicOperations.TryHashData(hashAlgorithm, data, destination, out bytesWritten);
204204

205205
public override byte[] CreateSignature(byte[] rgbHash)
206206
{

src/libraries/Common/src/System/Security/Cryptography/DSASecurityTransforms.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ protected override byte[] HashData(byte[] data, int offset, int count, HashAlgor
120120
throw new CryptographicException(SR.Cryptography_UnknownHashAlgorithm, hashAlgorithm.Name);
121121
}
122122

123-
return HashOneShotHelpers.HashData(hashAlgorithm, new ReadOnlySpan<byte>(data, offset, count));
123+
return CryptographicOperations.HashData(hashAlgorithm, new ReadOnlySpan<byte>(data, offset, count));
124124
}
125125

126126
protected override void Dispose(bool disposing)

src/libraries/Common/src/System/Security/Cryptography/HashOneShotHelpers.cs

Lines changed: 0 additions & 153 deletions
This file was deleted.

src/libraries/System.Security.Cryptography/ref/System.Security.Cryptography.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,24 @@ public static void AddOID(string oid, params string[] names) { }
542542
public static partial class CryptographicOperations
543543
{
544544
public static bool FixedTimeEquals(System.ReadOnlySpan<byte> left, System.ReadOnlySpan<byte> right) { throw null; }
545+
public static byte[] HashData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, byte[] source) { throw null; }
546+
public static byte[] HashData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, System.IO.Stream source) { throw null; }
547+
public static int HashData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, System.IO.Stream source, System.Span<byte> destination) { throw null; }
548+
public static byte[] HashData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, System.ReadOnlySpan<byte> source) { throw null; }
549+
public static int HashData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, System.ReadOnlySpan<byte> source, System.Span<byte> destination) { throw null; }
550+
public static System.Threading.Tasks.ValueTask<int> HashDataAsync(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, System.IO.Stream source, System.Memory<byte> destination, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
551+
public static System.Threading.Tasks.ValueTask<byte[]> HashDataAsync(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, System.IO.Stream source, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
552+
public static byte[] HmacData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, byte[] key, byte[] source) { throw null; }
553+
public static byte[] HmacData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, byte[] key, System.IO.Stream source) { throw null; }
554+
public static byte[] HmacData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, System.ReadOnlySpan<byte> key, System.IO.Stream source) { throw null; }
555+
public static int HmacData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, System.ReadOnlySpan<byte> key, System.IO.Stream source, System.Span<byte> destination) { throw null; }
556+
public static byte[] HmacData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, System.ReadOnlySpan<byte> key, System.ReadOnlySpan<byte> source) { throw null; }
557+
public static int HmacData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, System.ReadOnlySpan<byte> key, System.ReadOnlySpan<byte> source, System.Span<byte> destination) { throw null; }
558+
public static System.Threading.Tasks.ValueTask<byte[]> HmacDataAsync(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, byte[] key, System.IO.Stream source, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
559+
public static System.Threading.Tasks.ValueTask<int> HmacDataAsync(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, System.ReadOnlyMemory<byte> key, System.IO.Stream source, System.Memory<byte> destination, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
560+
public static System.Threading.Tasks.ValueTask<byte[]> HmacDataAsync(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, System.ReadOnlyMemory<byte> key, System.IO.Stream source, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
561+
public static bool TryHashData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, System.ReadOnlySpan<byte> source, System.Span<byte> destination, out int bytesWritten) { throw null; }
562+
public static bool TryHmacData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, System.ReadOnlySpan<byte> key, System.ReadOnlySpan<byte> source, System.Span<byte> destination, out int bytesWritten) { throw null; }
545563
public static void ZeroMemory(System.Span<byte> buffer) { }
546564
}
547565
public partial class CryptographicUnexpectedOperationException : System.Security.Cryptography.CryptographicException

src/libraries/System.Security.Cryptography/src/System.Security.Cryptography.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,6 @@
297297
Link="Common\System\Security\Cryptography\KdfWorkLimiter.cs" />
298298
<Compile Include="$(CommonPath)System\Security\Cryptography\KeyBlobHelpers.cs"
299299
Link="Common\System\Security\Cryptography\KeyBlobHelpers.cs" />
300-
<Compile Include="$(CommonPath)System\Security\Cryptography\HashOneShotHelpers.cs"
301-
Link="Common\System\Security\Cryptography\HashOneShotHelpers.cs" />
302300
<Compile Include="$(CommonPath)System\Security\Cryptography\IRuntimeAlgorithm.cs"
303301
Link="Common\System\Security\Cryptography\IRuntimeAlgorithm.cs" />
304302
<Compile Include="$(CommonPath)System\Security\Cryptography\KeyFormatHelper.cs"

0 commit comments

Comments
 (0)