diff --git a/CryptoBase/Digests/CRC32/Crc32X86.cs b/CryptoBase/Digests/CRC32/Crc32X86.cs index 29c2053..b5e559a 100644 --- a/CryptoBase/Digests/CRC32/Crc32X86.cs +++ b/CryptoBase/Digests/CRC32/Crc32X86.cs @@ -50,12 +50,11 @@ public unsafe void Update(ReadOnlySpan 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 destination) diff --git a/CryptoBase/Digests/CRC32C/Crc32CX86.cs b/CryptoBase/Digests/CRC32C/Crc32CX86.cs index bae9902..cea355c 100644 --- a/CryptoBase/Digests/CRC32C/Crc32CX86.cs +++ b/CryptoBase/Digests/CRC32C/Crc32CX86.cs @@ -53,18 +53,17 @@ public unsafe void Update(ReadOnlySpan 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); } } diff --git a/UnitTest/CRC32Test.cs b/UnitTest/CRC32Test.cs index 890f818..0b97af4 100644 --- a/UnitTest/CRC32Test.cs +++ b/UnitTest/CRC32Test.cs @@ -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); @@ -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); diff --git a/common.props b/common.props index 636bea8..2671726 100644 --- a/common.props +++ b/common.props @@ -2,7 +2,7 @@ net5.0 latest - 1.5.0 + 1.5.1 enable true HMBSbige