Skip to content

Commit

Permalink
fix: CRC32 X86 doesn't process remaining data
Browse files Browse the repository at this point in the history
  • Loading branch information
HMBSbige committed Jul 28, 2021
1 parent 67d1775 commit d97996f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
7 changes: 3 additions & 4 deletions CryptoBase/Digests/CRC32/Crc32X86.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,11 @@ public unsafe void Update(ReadOnlySpan<byte> source)
fixed (byte* p = source)
{
_state = Update(p, source.Length, _state);
source = source[^(source.Length % 0x10)..];
}
}
else
{
_state = ~Crc32Table.Crc32.Append(~_state, source);
}

_state = ~Crc32Table.Crc32.Append(~_state, source);
}

public void GetHash(Span<byte> destination)
Expand Down
15 changes: 7 additions & 8 deletions CryptoBase/Digests/CRC32C/Crc32CX86.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,17 @@ public unsafe void Update(ReadOnlySpan<byte> source)
fixed (byte* p = source)
{
_state = Update(p, source.Length, _state);
source = source[^(source.Length % 0x10)..];
}
}

if (Sse42.IsSupported)
{
UpdateSse42(source);
}
else
{
if (Sse42.IsSupported)
{
UpdateSse42(source);
}
else
{
_state = ~Crc32Table.Crc32C.Append(~_state, source);
}
_state = ~Crc32Table.Crc32C.Append(~_state, source);
}
}

Expand Down
4 changes: 2 additions & 2 deletions UnitTest/CRC32Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private static void TestC(IHash hash, string message, string expected)
[DataRow(@"12345678901234567890123456789012345678901234567890123456789012345678901234567890", @"7ca94a72")]
[DataRow(@"123456789", @"cbf43926")]
[DataRow(@"The quick brown fox jumps over the lazy dog", @"414fa339")]
[DataRow(@"e9ee3d0a4cc14560a54def3b5a34661eaff800cd6cb64b508c6570a4b4fbaee9c66406137d6640bcb73069c74e99fe5c70d769e7a50340158634d3ec32fad9f15b551e43c36d44fab418d4a2e09349edfce7a4f6547d4745aeb9c62a9e903c697d0fd3301d42497890d160be3301cc001e20ef15d9a2457ea52d312fbbea8ea05692c82743ee44aba3d235eb3bddcdb625f1a4177ae3417bb19fd5bc2e80ec10592599598f6046bca94c77ed61ebdd1084a78f5c8878482a9b583258efdf62f6f23a1fddb69f4574950632b4fd10413f1c53337b7aeb4a56b42695f6687a0782", @"48b84b16")]
[DataRow(@"5c6f1913817f054beaa45c911b141120ad3822a5d1d27c38362b0b0498bc1e82d7806444f7d25b2ac8581626b6c4c37811c3e5a85e6007fc4dce60e9ab257349281db35eeef273ce326942deec8f9f046240e61072b32733e4be09e8753e53a2294b7bd7b3b1474fcd4bafa88ab0c8fc36ce4696ee093e4a3300064303430eff32d41657783a660fe72086f94db23b194b1d96f44283323a67e80e475c1afe08b910a1e2e5c242a5ed33c9a26135a66ecb766e514f20bd4a631d80f886408d7507238f5b505b2cc1df4092f4c400955de89dfc2136bad7e292ba6091c19c64d86cfa6870bb35af7930a730362b0c0deace27b46f48cdccd02231c1f22f8029", @"76472786")]
public void CRC32(string message, string expected)
{
Test(new Crc32SF(), message, expected);
Expand All @@ -73,7 +73,7 @@ public void CRC32(string message, string expected)
[DataRow(@"12345678901234567890123456789012345678901234567890123456789012345678901234567890", @"477a6781")]
[DataRow(@"123456789", @"e3069283")]
[DataRow(@"The quick brown fox jumps over the lazy dog", @"22620404")]
[DataRow(@"e9ee3d0a4cc14560a54def3b5a34661eaff800cd6cb64b508c6570a4b4fbaee9c66406137d6640bcb73069c74e99fe5c70d769e7a50340158634d3ec32fad9f15b551e43c36d44fab418d4a2e09349edfce7a4f6547d4745aeb9c62a9e903c697d0fd3301d42497890d160be3301cc001e20ef15d9a2457ea52d312fbbea8ea05692c82743ee44aba3d235eb3bddcdb625f1a4177ae3417bb19fd5bc2e80ec10592599598f6046bca94c77ed61ebdd1084a78f5c8878482a9b583258efdf62f6f23a1fddb69f4574950632b4fd10413f1c53337b7aeb4a56b42695f6687a0782", @"c9c156ee")]
[DataRow(@"5c6f1913817f054beaa45c911b141120ad3822a5d1d27c38362b0b0498bc1e82d7806444f7d25b2ac8581626b6c4c37811c3e5a85e6007fc4dce60e9ab257349281db35eeef273ce326942deec8f9f046240e61072b32733e4be09e8753e53a2294b7bd7b3b1474fcd4bafa88ab0c8fc36ce4696ee093e4a3300064303430eff32d41657783a660fe72086f94db23b194b1d96f44283323a67e80e475c1afe08b910a1e2e5c242a5ed33c9a26135a66ecb766e514f20bd4a631d80f886408d7507238f5b505b2cc1df4092f4c400955de89dfc2136bad7e292ba6091c19c64d86cfa6870bb35af7930a730362b0c0deace27b46f48cdccd02231c1f22f8029", @"83c1318e")]
public void CRC32C(string message, string expected)
{
TestC(new Crc32CSF(), message, expected);
Expand Down
2 changes: 1 addition & 1 deletion common.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Version>1.5.0</Version>
<Version>1.5.1</Version>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Authors>HMBSbige</Authors>
Expand Down

0 comments on commit d97996f

Please sign in to comment.