Skip to content

[release/5.0-rc2] WASM: Add SHA* hash functions - #41761

Merged
akoeplinger merged 1 commit into
release/5.0-rc2from
backport/pr-40486-to-release/5.0-rc2
Sep 3, 2020
Merged

akoeplinger merged 1 commit into
release/5.0-rc2from
backport/pr-40486-to-release/5.0-rc2

Conversation

@github-actions

@github-actions github-actions Bot commented Sep 2, 2020 •

Copy link
Copy Markdown
Contributor

Backport of #40486 to release/5.0-rc2

Fixes #40076

/cc @akoeplinger

Customer Impact

Unblocks customer apps that used SHA hashing functions (like Roslyn) in Blazor WASM apps. Those worked in the 3.2 Blazor release since it was based on Mono's BCL which had managed implementations for the algorithms. Updating to the 5.0 previews with .NET BCL caused the apps to fail with PlatformNotSupportedException since we don't support OpenSSL on browser.

Examples: #40080 , #39893 , dotnet/aspnetcore#24362 and #39756.

Adding the managed SHA* implementations is a temporary step until we can replace them with interop to the SubtleCrypto API the browser provides, #40074 tracks that.

Testing

Tested in CI and manually.

Risk

Low, just ports managed implementations for SHA algorithms from referencesource.

This ports the managed SHA* hash functions from https://github.com/microsoft/referencesource so we can use them on Browser/WASM where we don't have OpenSSL.

Enables the System.Security.Cryptography.Algorithms tests for these classes: `Tests run: 271, Errors: 0, Failures: 0, Skipped: 1. Time: 11.028473s`

Resolves #40076
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the area-Infrastructure-coreclr Only use for closed issues label Sep 2, 2020
@akoeplinger akoeplinger added arch-wasm WebAssembly architecture area-System.Security and removed area-Infrastructure-coreclr Only use for closed issues labels Sep 2, 2020
@ghost

ghost commented Sep 2, 2020

Copy link
Copy Markdown

Tagging subscribers to this area: @bartonjs, @vcsjones, @krwq
See info in area-owners.md if you want to be subscribed.

@akoeplinger akoeplinger added the Servicing-consider Issue for next servicing release review label Sep 2, 2020
@danmoseley

Copy link
Copy Markdown
Contributor

What tests do we have that the hashing functions produce the correct result? If I understand right, until now we were relying on OpenSSL/Windows and testing their implementation's correctness presumably wasn't a goal so we don't have tests for it?

@akoeplinger

Copy link
Copy Markdown
Member

@danmosemsft we do have tests that verify the correct SHA value is produced:

public void Sha1_Empty()
{
Verify(Array.Empty<byte>(), "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709");
}
// SHA1 tests are defined somewhat obliquely within RFC 3174, section 7.3
// The same tests appear in http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf Appendix A
[Fact]
public void Sha1_Rfc3174_1()
{
Verify("abc", "A9993E364706816ABA3E25717850C26C9CD0D89D");
}
[Fact]
public void Sha1_Rfc3174_MultiBlock()
{
VerifyMultiBlock("ab", "c", "A9993E364706816ABA3E25717850C26C9CD0D89D", "DA39A3EE5E6B4B0D3255BFEF95601890AFD80709");
}
[Fact]
public void Sha1_Rfc3174_2()
{
Verify("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", "84983E441C3BD26EBAAE4AA1F95129E5E54670F1");
}
[Fact]
public void Sha1_Rfc3174_3()
{
VerifyRepeating("a", 1000000, "34AA973CD4C4DAA4F61EEB2BDBAD27316534016F");
}
[Fact]
public void Sha1_Rfc3174_4()
{
VerifyRepeating("0123456701234567012345670123456701234567012345670123456701234567", 10, "DEA356A2CDDD90C7A7ECEDC5EBB563934F460452");
}

@jamshedd

jamshedd commented Sep 3, 2020

Copy link
Copy Markdown
Member

Approved for RC2.

@jamshedd jamshedd added this to the 5.0.0 rc2 milestone Sep 3, 2020
@jamshedd jamshedd added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Sep 3, 2020
@akoeplinger
akoeplinger merged commit 922afaf into release/5.0-rc2 Sep 3, 2020
@akoeplinger
akoeplinger deleted the backport/pr-40486-to-release/5.0-rc2 branch September 3, 2020 17:54
@karelz karelz modified the milestones: 5.0.0 rc2, 5.0.0 Sep 9, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

arch-wasm WebAssembly architecture area-System.Security Servicing-approved Approved for servicing release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants