Skip to content

Commit

Permalink
HashAlgorithmName one-shots (#92430)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
vcsjones authored Sep 24, 2023
1 parent f68bbe2 commit 4101144
Show file tree
Hide file tree
Showing 33 changed files with 1,344 additions and 216 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,14 @@ protected override byte[] HashData(byte[] data, int offset, int count, HashAlgor
Debug.Assert(count >= 0 && count <= data.Length);
Debug.Assert(!string.IsNullOrEmpty(hashAlgorithm.Name));

return HashOneShotHelpers.HashData(hashAlgorithm, new ReadOnlySpan<byte>(data, offset, count));
return CryptographicOperations.HashData(hashAlgorithm, new ReadOnlySpan<byte>(data, offset, count));
}

protected override byte[] HashData(Stream data, HashAlgorithmName hashAlgorithm) =>
HashOneShotHelpers.HashData(hashAlgorithm, data);
CryptographicOperations.HashData(hashAlgorithm, data);

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

public override byte[] CreateSignature(byte[] rgbHash)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ protected override byte[] HashData(byte[] data, int offset, int count, HashAlgor
throw new CryptographicException(SR.Cryptography_UnknownHashAlgorithm, hashAlgorithm.Name);
}

return HashOneShotHelpers.HashData(hashAlgorithm, new ReadOnlySpan<byte>(data, offset, count));
return CryptographicOperations.HashData(hashAlgorithm, new ReadOnlySpan<byte>(data, offset, count));
}

protected override void Dispose(bool disposing)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,24 @@ public static void AddOID(string oid, params string[] names) { }
public static partial class CryptographicOperations
{
public static bool FixedTimeEquals(System.ReadOnlySpan<byte> left, System.ReadOnlySpan<byte> right) { throw null; }
public static byte[] HashData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, byte[] source) { throw null; }
public static byte[] HashData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, System.IO.Stream source) { throw null; }
public static int HashData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, System.IO.Stream source, System.Span<byte> destination) { throw null; }
public static byte[] HashData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, System.ReadOnlySpan<byte> source) { throw null; }
public static int HashData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, System.ReadOnlySpan<byte> source, System.Span<byte> destination) { throw null; }
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; }
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; }
public static byte[] HmacData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, byte[] key, byte[] source) { throw null; }
public static byte[] HmacData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, byte[] key, System.IO.Stream source) { throw null; }
public static byte[] HmacData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, System.ReadOnlySpan<byte> key, System.IO.Stream source) { throw null; }
public static int HmacData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, System.ReadOnlySpan<byte> key, System.IO.Stream source, System.Span<byte> destination) { throw null; }
public static byte[] HmacData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, System.ReadOnlySpan<byte> key, System.ReadOnlySpan<byte> source) { throw null; }
public static int HmacData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, System.ReadOnlySpan<byte> key, System.ReadOnlySpan<byte> source, System.Span<byte> destination) { throw null; }
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; }
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; }
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; }
public static bool TryHashData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, System.ReadOnlySpan<byte> source, System.Span<byte> destination, out int bytesWritten) { throw null; }
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; }
public static void ZeroMemory(System.Span<byte> buffer) { }
}
public partial class CryptographicUnexpectedOperationException : System.Security.Cryptography.CryptographicException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,6 @@
Link="Common\System\Security\Cryptography\KdfWorkLimiter.cs" />
<Compile Include="$(CommonPath)System\Security\Cryptography\KeyBlobHelpers.cs"
Link="Common\System\Security\Cryptography\KeyBlobHelpers.cs" />
<Compile Include="$(CommonPath)System\Security\Cryptography\HashOneShotHelpers.cs"
Link="Common\System\Security\Cryptography\HashOneShotHelpers.cs" />
<Compile Include="$(CommonPath)System\Security\Cryptography\IRuntimeAlgorithm.cs"
Link="Common\System\Security\Cryptography\IRuntimeAlgorithm.cs" />
<Compile Include="$(CommonPath)System\Security\Cryptography\KeyFormatHelper.cs"
Expand Down
Loading

0 comments on commit 4101144

Please sign in to comment.