diff --git a/aws-crt-checksums/Crc.cs b/aws-crt-checksums/Crc.cs index f1639bc..d5b7378 100644 --- a/aws-crt-checksums/Crc.cs +++ b/aws-crt-checksums/Crc.cs @@ -18,9 +18,14 @@ public delegate UInt32 aws_dotnet_crc32([In, MarshalAs(UnmanagedType.LPArray, Si [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] public delegate UInt32 aws_dotnet_crc32c([In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2, ArraySubType = UnmanagedType.U1)] byte[] buffer, Int32 length, UInt32 previous); + + [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)] + public delegate UInt64 aws_dotnet_crc64nvme([In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2, ArraySubType = UnmanagedType.U1)] byte[] buffer, + Int32 length, UInt64 previous); public static aws_dotnet_crc32 crc32 = NativeAPI.Bind(); public static aws_dotnet_crc32c crc32c = NativeAPI.Bind(); + public static aws_dotnet_crc64nvme crc64nvme = NativeAPI.Bind(); } public static uint crc32(byte[] buffer, uint previous = 0) { @@ -30,5 +35,9 @@ public static uint crc32c(byte[] buffer, uint previous = 0) { return API.crc32c(buffer, buffer.Length, previous); } + public static ulong crc64nvme(byte[] buffer, ulong previous = 0) + { + return API.crc64nvme(buffer, buffer.Length, previous); + } } } diff --git a/crt/aws-checksums b/crt/aws-checksums index aac442a..ce04ab0 160000 --- a/crt/aws-checksums +++ b/crt/aws-checksums @@ -1 +1 @@ -Subproject commit aac442a2dbbb5e72d0a3eca8313cf65e7e1cac2f +Subproject commit ce04ab00b3ecc41912f478bfedca39f8e1919d6b diff --git a/native/src/crc.c b/native/src/crc.c index 83aa151..5c5d50c 100644 --- a/native/src/crc.c +++ b/native/src/crc.c @@ -9,10 +9,15 @@ AWS_DOTNET_API uint32_t aws_dotnet_crc32(const uint8_t *input, int length, uint32_t previous) { - return aws_checksums_crc32(input, length, previous); + return aws_checksums_crc32_ex(input, (size_t)length, previous); } AWS_DOTNET_API uint32_t aws_dotnet_crc32c(const uint8_t *input, int length, uint32_t previous) { - return aws_checksums_crc32c(input, length, previous); + return aws_checksums_crc32c_ex(input, (size_t)length, previous); +} + +AWS_DOTNET_API +uint64_t aws_dotnet_crc64nvme(const uint8_t *input, int length, uint64_t previous) { + return aws_checksums_crc64nvme_ex(input, (size_t)length, previous); } diff --git a/tests/CrcTest.cs b/tests/CrcTest.cs index 1224abc..1026faf 100644 --- a/tests/CrcTest.cs +++ b/tests/CrcTest.cs @@ -107,5 +107,23 @@ public void TestCrc32cLargeBuffer() uint expected = 0xfb5b991d; Assert.Equal(expected, res); } + [Fact] + public void TestCrc64NVMEZeroes() + { + byte[] zeroes = new byte[32]; + ulong res = Crc.crc64nvme(zeroes); + ulong expected = 0xCF3473434D4ECF3B; + Assert.Equal(expected, res); + } + [Fact] + public void TestCrc64NVMEZeroesIterated() + { + ulong res = 0; + for (int i = 0; i < 32; i++) { + res = Crc.crc64nvme(new byte[1], res); + } + ulong expected = 0xCF3473434D4ECF3B; + Assert.Equal(expected, res); + } } }