Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<SignAssembly>true</SignAssembly>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
<AssemblyOriginatorKeyFile>$(ProductSnkPath)</AssemblyOriginatorKeyFile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ namespace Java.Interop.Tools.JavaCallableWrappers
{
partial class Crc64Helper
{
static readonly ulong[,] table = {
{
static readonly ulong [] table = {
0x0000000000000000, 0x7ad870c830358979, 0xf5b0e190606b12f2, 0x8f689158505e9b8b,
0xc038e5739841b68f, 0xbae095bba8743ff6, 0x358804e3f82aa47d, 0x4f50742bc81f2d04,
0xab28ecb46814fe75, 0xd1f09c7c5821770c, 0x5e980d24087fec87, 0x24407dec384a65fe,
Expand Down Expand Up @@ -67,9 +66,7 @@ partial class Crc64Helper
0xcdcf48d84fe75459, 0xb71738107fd2dd20, 0x387fa9482f8c46ab, 0x42a7d9801fb9cfd2,
0x0df7adabd7a6e2d6, 0x772fdd63e7936baf, 0xf8474c3bb7cdf024, 0x829f3cf387f8795d,
0x66e7a46c27f3aa2c, 0x1c3fd4a417c62355, 0x935745fc4798b8de, 0xe98f353477ad31a7,
0xa6df411fbfb21ca3, 0xdc0731d78f8795da, 0x536fa08fdfd90e51, 0x29b7d047efec8728
},
{
0xa6df411fbfb21ca3, 0xdc0731d78f8795da, 0x536fa08fdfd90e51, 0x29b7d047efec8728,
0x0000000000000000, 0x89e99ffd73bddf69, 0x388a19a9bfec2db9, 0xb1638654cc51f2d0,
0x711433537fd85b72, 0xf8fdacae0c65841b, 0x499e2afac03476cb, 0xc077b507b389a9a2,
0xe22866a6ffb0b6e4, 0x6bc1f95b8c0d698d, 0xdaa27f0f405c9b5d, 0x534be0f233e14434,
Expand Down Expand Up @@ -133,9 +130,7 @@ partial class Crc64Helper
0x734f76b272bed2b6, 0xfaa6e94f01030ddf, 0x4bc56f1bcd52ff0f, 0xc22cf0e6beef2066,
0x025b45e10d6689c4, 0x8bb2da1c7edb56ad, 0x3ad15c48b28aa47d, 0xb338c3b5c1377b14,
0x916710148d0e6452, 0x188e8fe9feb3bb3b, 0xa9ed09bd32e249eb, 0x20049640415f9682,
0xe0732347f2d63f20, 0x699abcba816be049, 0xd8f93aee4d3a1299, 0x5110a5133e87cdf0
},
{
0xe0732347f2d63f20, 0x699abcba816be049, 0xd8f93aee4d3a1299, 0x5110a5133e87cdf0,
0x0000000000000000, 0xf4125129ce4038be, 0xc37d8400c417e217, 0x376fd5290a57daa9,
0xada22e52d0b85745, 0x59b07f7b1ef86ffb, 0x6edfaa5214afb552, 0x9acdfb7bdaef8dec,
0x701d7af6f9e73de1, 0x840f2bdf37a7055f, 0xb360fef63df0dff6, 0x4772afdff3b0e748,
Expand Down Expand Up @@ -199,9 +194,7 @@ partial class Crc64Helper
0x274ed9f07fd16399, 0xd35c88d9b1915b27, 0xe4335df0bbc6818e, 0x10210cd97586b930,
0x8aecf7a2af6934dc, 0x7efea68b61290c62, 0x499173a26b7ed6cb, 0xbd83228ba53eee75,
0x5753a30686365e78, 0xa341f22f487666c6, 0x942e27064221bc6f, 0x603c762f8c6184d1,
0xfaf18d54568e093d, 0x0ee3dc7d98ce3183, 0x398c09549299eb2a, 0xcd9e587d5cd9d394
},
{
0xfaf18d54568e093d, 0x0ee3dc7d98ce3183, 0x398c09549299eb2a, 0xcd9e587d5cd9d394,
0x0000000000000000, 0x8ce168638c796306, 0x329bf69440655567, 0xbe7a9ef7cc1c3661,
0x6537ed2880caaace, 0xe9d6854b0cb3c9c8, 0x57ac1bbcc0afffa9, 0xdb4d73df4cd69caf,
0xca6fda510195559c, 0x468eb2328dec369a, 0xf8f42cc541f000fb, 0x741544a6cd8963fd,
Expand Down Expand Up @@ -265,9 +258,7 @@ partial class Crc64Helper
0x3973beb78cab005b, 0xb592d6d400d2635d, 0x0be84823ccce553c, 0x8709204040b7363a,
0x5c44539f0c61aa95, 0xd0a53bfc8018c993, 0x6edfa50b4c04fff2, 0xe23ecd68c07d9cf4,
0xf31c64e68d3e55c7, 0x7ffd0c85014736c1, 0xc1879272cd5b00a0, 0x4d66fa11412263a6,
0x962b89ce0df4ff09, 0x1acae1ad818d9c0f, 0xa4b07f5a4d91aa6e, 0x28511739c1e8c968
},
{
0x962b89ce0df4ff09, 0x1acae1ad818d9c0f, 0xa4b07f5a4d91aa6e, 0x28511739c1e8c968,
0x0000000000000000, 0x3504e58b9ba6dd1e, 0x6a09cb17374dba3c, 0x5f0d2e9caceb6722,
0xd413962e6e9b7478, 0xe11773a5f53da966, 0xbe1a5d3959d6ce44, 0x8b1eb8b2c270135a,
0x837e0a0f85a17b9b, 0xb67aef841e07a685, 0xe977c118b2ecc1a7, 0xdc732493294a1cb9,
Expand Down Expand Up @@ -331,9 +322,7 @@ partial class Crc64Helper
0x860b2bd47d168c10, 0xb30fce5fe6b0510e, 0xec02e0c34a5b362c, 0xd9060548d1fdeb32,
0x5218bdfa138df868, 0x671c5871882b2576, 0x381176ed24c04254, 0x0d159366bf669f4a,
0x057521dbf8b7f78b, 0x3071c45063112a95, 0x6f7ceacccffa4db7, 0x5a780f47545c90a9,
0xd166b7f5962c83f3, 0xe462527e0d8a5eed, 0xbb6f7ce2a16139cf, 0x8e6b99693ac7e4d1
},
{
0xd166b7f5962c83f3, 0xe462527e0d8a5eed, 0xbb6f7ce2a16139cf, 0x8e6b99693ac7e4d1,
0x0000000000000000, 0xe39d1389931b9354, 0xec6301407ea0b5c3, 0x0ffe12c9edbb2697,
0xf39f24d3a5d6f8ed, 0x1002375a36cd6bb9, 0x1ffc2593db764d2e, 0xfc61361a486dde7a,
0xcc676ff4133a62b1, 0x2ffa7c7d8021f1e5, 0x20046eb46d9ad772, 0xc3997d3dfe814426,
Expand Down Expand Up @@ -397,9 +386,7 @@ partial class Crc64Helper
0x7d8ef4105cc3790d, 0x9e13e799cfd8ea59, 0x91edf5502263ccce, 0x7270e6d9b1785f9a,
0x8e11d0c3f91581e0, 0x6d8cc34a6a0e12b4, 0x6272d18387b53423, 0x81efc20a14aea777,
0xb1e99be44ff91bbc, 0x5274886ddce288e8, 0x5d8a9aa43159ae7f, 0xbe17892da2423d2b,
0x4276bf37ea2fe351, 0xa1ebacbe79347005, 0xae15be77948f5692, 0x4d88adfe0794c5c6
},
{
0x4276bf37ea2fe351, 0xa1ebacbe79347005, 0xae15be77948f5692, 0x4d88adfe0794c5c6,
0x0000000000000000, 0x62a95de6e302eff2, 0xc552bbcdc605dfe4, 0xa7fbe62b25073016,
0xa1fc51c8d49c2ca3, 0xc3550c2e379ec351, 0x64aeea051299f347, 0x0607b7e3f19b1cb5,
0x68a185c2f1afca2d, 0x0a08d82412ad25df, 0xadf33e0f37aa15c9, 0xcf5a63e9d4a8fa3b,
Expand Down Expand Up @@ -463,9 +450,7 @@ partial class Crc64Helper
0x11b5f7fbd03c02fa, 0x731caa1d333eed08, 0xd4e74c361639dd1e, 0xb64e11d0f53b32ec,
0xb049a63304a02e59, 0xd2e0fbd5e7a2c1ab, 0x751b1dfec2a5f1bd, 0x17b2401821a71e4f,
0x791472392193c8d7, 0x1bbd2fdfc2912725, 0xbc46c9f4e7961733, 0xdeef94120494f8c1,
0xd8e823f1f50fe474, 0xba417e17160d0b86, 0x1dba983c330a3b90, 0x7f13c5dad008d462
},
{
0xd8e823f1f50fe474, 0xba417e17160d0b86, 0x1dba983c330a3b90, 0x7f13c5dad008d462,
0x0000000000000000, 0x381d0015c96f4444, 0x703a002b92de8888, 0x4827003e5bb1cccc,
0xe074005725bd1110, 0xd8690042ecd25554, 0x904e007cb7639998, 0xa85300697e0cdddc,
0xebb126fd13edb14b, 0xd3ac26e8da82f50f, 0x9b8b26d6813339c3, 0xa39626c3485c7d87,
Expand Down Expand Up @@ -530,7 +515,6 @@ partial class Crc64Helper
0x7332f05c99f595cc, 0x4b2ff049509ad188, 0x0308f0770b2b1d44, 0x3b15f062c2445900,
0x78f7d6f6afa53597, 0x40ead6e366ca71d3, 0x08cdd6dd3d7bbd1f, 0x30d0d6c8f414f95b,
0x9883d6a18a182487, 0xa09ed6b4437760c3, 0xe8b9d68a18c6ac0f, 0xd0a4d69fd1a9e84b
},
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public override void Initialize ()
length = 0;
}

protected override unsafe void HashCore (byte [] array, int ibStart, int cbSize)
protected override void HashCore (byte [] array, int ibStart, int cbSize)
{
Crc64Helper.HashCore (array, ibStart, cbSize, ref crc, ref length);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,34 +55,37 @@ internal static byte [] Compute (byte [] array)
return BitConverter.GetBytes (crc ^ length);
}

internal static unsafe void HashCore (byte [] array, int ibStart, int cbSize, ref ulong crc, ref ulong length)
internal static void HashCore (byte [] array, int ibStart, int cbSize, ref ulong crc, ref ulong length)
{
if (array == null)
throw new ArgumentNullException (nameof (array));
if (ibStart < 0 || ibStart > array.Length)
throw new ArgumentOutOfRangeException (nameof (ibStart));
if (cbSize < 0 || cbSize > array.Length - ibStart)
Comment thread
simonrozsival marked this conversation as resolved.
throw new ArgumentOutOfRangeException (nameof (cbSize));

int len = cbSize;
int idx = ibStart;

fixed (ulong* tptr = table) {
fixed (byte* aptr = array) {
while (len >= 8) {
crc ^= *((ulong*) (aptr + idx));
crc =
tptr [7 * 256 + (crc & 0xff)] ^
tptr [6 * 256 + ((crc >> 8) & 0xff)] ^
tptr [5 * 256 + ((crc >> 16) & 0xff)] ^
tptr [4 * 256 + ((crc >> 24) & 0xff)] ^
tptr [3 * 256 + ((crc >> 32) & 0xff)] ^
tptr [2 * 256 + ((crc >> 40) & 0xff)] ^
tptr [1 * 256 + ((crc >> 48) & 0xff)] ^
tptr [0 * 256 + (crc >> 56)];
idx += 8;
len -= 8;
}
while (len >= 8) {
crc ^= BitConverter.ToUInt64 (array, idx);
crc =
table [7 * 256 + (crc & 0xff)] ^
table [6 * 256 + ((crc >> 8) & 0xff)] ^
table [5 * 256 + ((crc >> 16) & 0xff)] ^
table [4 * 256 + ((crc >> 24) & 0xff)] ^
table [3 * 256 + ((crc >> 32) & 0xff)] ^
table [2 * 256 + ((crc >> 40) & 0xff)] ^
table [1 * 256 + ((crc >> 48) & 0xff)] ^
table [0 * 256 + (crc >> 56)];
idx += 8;
len -= 8;
}

while (len > 0) {
crc = tptr [0 * 256 + ((crc ^ aptr [idx]) & 0xff)] ^ (crc >> 8);
idx++;
len--;
}
}
while (len > 0) {
crc = table [0 * 256 + ((crc ^ array [idx]) & 0xff)] ^ (crc >> 8);
idx++;
len--;
}

length += (ulong) cbSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<PropertyGroup>
<TargetFramework>$(DotNetTargetFramework)</TargetFramework>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DefineConstants>$(DefineConstants);JCW_ONLY_TYPE_NAMES;HAVE_CECIL</DefineConstants>
</PropertyGroup>

Expand Down
32 changes: 8 additions & 24 deletions src/Microsoft.Android.Build.BaseTasks/Crc64.Table.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ namespace Microsoft.Android.Build.Tasks
{
partial class Crc64Helper
{
static readonly ulong[,] table = {
{
static readonly ulong [] table = {
0x0000000000000000, 0x7ad870c830358979, 0xf5b0e190606b12f2, 0x8f689158505e9b8b,
0xc038e5739841b68f, 0xbae095bba8743ff6, 0x358804e3f82aa47d, 0x4f50742bc81f2d04,
0xab28ecb46814fe75, 0xd1f09c7c5821770c, 0x5e980d24087fec87, 0x24407dec384a65fe,
Expand Down Expand Up @@ -69,9 +68,7 @@ partial class Crc64Helper
0xcdcf48d84fe75459, 0xb71738107fd2dd20, 0x387fa9482f8c46ab, 0x42a7d9801fb9cfd2,
0x0df7adabd7a6e2d6, 0x772fdd63e7936baf, 0xf8474c3bb7cdf024, 0x829f3cf387f8795d,
0x66e7a46c27f3aa2c, 0x1c3fd4a417c62355, 0x935745fc4798b8de, 0xe98f353477ad31a7,
0xa6df411fbfb21ca3, 0xdc0731d78f8795da, 0x536fa08fdfd90e51, 0x29b7d047efec8728
},
{
0xa6df411fbfb21ca3, 0xdc0731d78f8795da, 0x536fa08fdfd90e51, 0x29b7d047efec8728,
0x0000000000000000, 0x89e99ffd73bddf69, 0x388a19a9bfec2db9, 0xb1638654cc51f2d0,
0x711433537fd85b72, 0xf8fdacae0c65841b, 0x499e2afac03476cb, 0xc077b507b389a9a2,
0xe22866a6ffb0b6e4, 0x6bc1f95b8c0d698d, 0xdaa27f0f405c9b5d, 0x534be0f233e14434,
Expand Down Expand Up @@ -135,9 +132,7 @@ partial class Crc64Helper
0x734f76b272bed2b6, 0xfaa6e94f01030ddf, 0x4bc56f1bcd52ff0f, 0xc22cf0e6beef2066,
0x025b45e10d6689c4, 0x8bb2da1c7edb56ad, 0x3ad15c48b28aa47d, 0xb338c3b5c1377b14,
0x916710148d0e6452, 0x188e8fe9feb3bb3b, 0xa9ed09bd32e249eb, 0x20049640415f9682,
0xe0732347f2d63f20, 0x699abcba816be049, 0xd8f93aee4d3a1299, 0x5110a5133e87cdf0
},
{
0xe0732347f2d63f20, 0x699abcba816be049, 0xd8f93aee4d3a1299, 0x5110a5133e87cdf0,
0x0000000000000000, 0xf4125129ce4038be, 0xc37d8400c417e217, 0x376fd5290a57daa9,
0xada22e52d0b85745, 0x59b07f7b1ef86ffb, 0x6edfaa5214afb552, 0x9acdfb7bdaef8dec,
0x701d7af6f9e73de1, 0x840f2bdf37a7055f, 0xb360fef63df0dff6, 0x4772afdff3b0e748,
Expand Down Expand Up @@ -201,9 +196,7 @@ partial class Crc64Helper
0x274ed9f07fd16399, 0xd35c88d9b1915b27, 0xe4335df0bbc6818e, 0x10210cd97586b930,
0x8aecf7a2af6934dc, 0x7efea68b61290c62, 0x499173a26b7ed6cb, 0xbd83228ba53eee75,
0x5753a30686365e78, 0xa341f22f487666c6, 0x942e27064221bc6f, 0x603c762f8c6184d1,
0xfaf18d54568e093d, 0x0ee3dc7d98ce3183, 0x398c09549299eb2a, 0xcd9e587d5cd9d394
},
{
0xfaf18d54568e093d, 0x0ee3dc7d98ce3183, 0x398c09549299eb2a, 0xcd9e587d5cd9d394,
0x0000000000000000, 0x8ce168638c796306, 0x329bf69440655567, 0xbe7a9ef7cc1c3661,
0x6537ed2880caaace, 0xe9d6854b0cb3c9c8, 0x57ac1bbcc0afffa9, 0xdb4d73df4cd69caf,
0xca6fda510195559c, 0x468eb2328dec369a, 0xf8f42cc541f000fb, 0x741544a6cd8963fd,
Expand Down Expand Up @@ -267,9 +260,7 @@ partial class Crc64Helper
0x3973beb78cab005b, 0xb592d6d400d2635d, 0x0be84823ccce553c, 0x8709204040b7363a,
0x5c44539f0c61aa95, 0xd0a53bfc8018c993, 0x6edfa50b4c04fff2, 0xe23ecd68c07d9cf4,
0xf31c64e68d3e55c7, 0x7ffd0c85014736c1, 0xc1879272cd5b00a0, 0x4d66fa11412263a6,
0x962b89ce0df4ff09, 0x1acae1ad818d9c0f, 0xa4b07f5a4d91aa6e, 0x28511739c1e8c968
},
{
0x962b89ce0df4ff09, 0x1acae1ad818d9c0f, 0xa4b07f5a4d91aa6e, 0x28511739c1e8c968,
0x0000000000000000, 0x3504e58b9ba6dd1e, 0x6a09cb17374dba3c, 0x5f0d2e9caceb6722,
0xd413962e6e9b7478, 0xe11773a5f53da966, 0xbe1a5d3959d6ce44, 0x8b1eb8b2c270135a,
0x837e0a0f85a17b9b, 0xb67aef841e07a685, 0xe977c118b2ecc1a7, 0xdc732493294a1cb9,
Expand Down Expand Up @@ -333,9 +324,7 @@ partial class Crc64Helper
0x860b2bd47d168c10, 0xb30fce5fe6b0510e, 0xec02e0c34a5b362c, 0xd9060548d1fdeb32,
0x5218bdfa138df868, 0x671c5871882b2576, 0x381176ed24c04254, 0x0d159366bf669f4a,
0x057521dbf8b7f78b, 0x3071c45063112a95, 0x6f7ceacccffa4db7, 0x5a780f47545c90a9,
0xd166b7f5962c83f3, 0xe462527e0d8a5eed, 0xbb6f7ce2a16139cf, 0x8e6b99693ac7e4d1
},
{
0xd166b7f5962c83f3, 0xe462527e0d8a5eed, 0xbb6f7ce2a16139cf, 0x8e6b99693ac7e4d1,
0x0000000000000000, 0xe39d1389931b9354, 0xec6301407ea0b5c3, 0x0ffe12c9edbb2697,
0xf39f24d3a5d6f8ed, 0x1002375a36cd6bb9, 0x1ffc2593db764d2e, 0xfc61361a486dde7a,
0xcc676ff4133a62b1, 0x2ffa7c7d8021f1e5, 0x20046eb46d9ad772, 0xc3997d3dfe814426,
Expand Down Expand Up @@ -399,9 +388,7 @@ partial class Crc64Helper
0x7d8ef4105cc3790d, 0x9e13e799cfd8ea59, 0x91edf5502263ccce, 0x7270e6d9b1785f9a,
0x8e11d0c3f91581e0, 0x6d8cc34a6a0e12b4, 0x6272d18387b53423, 0x81efc20a14aea777,
0xb1e99be44ff91bbc, 0x5274886ddce288e8, 0x5d8a9aa43159ae7f, 0xbe17892da2423d2b,
0x4276bf37ea2fe351, 0xa1ebacbe79347005, 0xae15be77948f5692, 0x4d88adfe0794c5c6
},
{
0x4276bf37ea2fe351, 0xa1ebacbe79347005, 0xae15be77948f5692, 0x4d88adfe0794c5c6,
0x0000000000000000, 0x62a95de6e302eff2, 0xc552bbcdc605dfe4, 0xa7fbe62b25073016,
0xa1fc51c8d49c2ca3, 0xc3550c2e379ec351, 0x64aeea051299f347, 0x0607b7e3f19b1cb5,
0x68a185c2f1afca2d, 0x0a08d82412ad25df, 0xadf33e0f37aa15c9, 0xcf5a63e9d4a8fa3b,
Expand Down Expand Up @@ -465,9 +452,7 @@ partial class Crc64Helper
0x11b5f7fbd03c02fa, 0x731caa1d333eed08, 0xd4e74c361639dd1e, 0xb64e11d0f53b32ec,
0xb049a63304a02e59, 0xd2e0fbd5e7a2c1ab, 0x751b1dfec2a5f1bd, 0x17b2401821a71e4f,
0x791472392193c8d7, 0x1bbd2fdfc2912725, 0xbc46c9f4e7961733, 0xdeef94120494f8c1,
0xd8e823f1f50fe474, 0xba417e17160d0b86, 0x1dba983c330a3b90, 0x7f13c5dad008d462
},
{
0xd8e823f1f50fe474, 0xba417e17160d0b86, 0x1dba983c330a3b90, 0x7f13c5dad008d462,
0x0000000000000000, 0x381d0015c96f4444, 0x703a002b92de8888, 0x4827003e5bb1cccc,
0xe074005725bd1110, 0xd8690042ecd25554, 0x904e007cb7639998, 0xa85300697e0cdddc,
0xebb126fd13edb14b, 0xd3ac26e8da82f50f, 0x9b8b26d6813339c3, 0xa39626c3485c7d87,
Expand Down Expand Up @@ -532,7 +517,6 @@ partial class Crc64Helper
0x7332f05c99f595cc, 0x4b2ff049509ad188, 0x0308f0770b2b1d44, 0x3b15f062c2445900,
0x78f7d6f6afa53597, 0x40ead6e366ca71d3, 0x08cdd6dd3d7bbd1f, 0x30d0d6c8f414f95b,
0x9883d6a18a182487, 0xa09ed6b4437760c3, 0xe8b9d68a18c6ac0f, 0xd0a4d69fd1a9e84b
},
};
}
}
2 changes: 1 addition & 1 deletion src/Microsoft.Android.Build.BaseTasks/Crc64.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public override void Initialize ()
length = 0;
}

protected override unsafe void HashCore (byte [] array, int ibStart, int cbSize)
protected override void HashCore (byte [] array, int ibStart, int cbSize)
{
Crc64Helper.HashCore (array, ibStart, cbSize, ref crc, ref length);
}
Expand Down
49 changes: 26 additions & 23 deletions src/Microsoft.Android.Build.BaseTasks/Crc64Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,34 +57,37 @@ internal static byte [] Compute (byte [] array)
return BitConverter.GetBytes (crc ^ length);
}

internal static unsafe void HashCore (byte [] array, int ibStart, int cbSize, ref ulong crc, ref ulong length)
internal static void HashCore (byte [] array, int ibStart, int cbSize, ref ulong crc, ref ulong length)
{
if (array == null)
throw new ArgumentNullException (nameof (array));
if (ibStart < 0 || ibStart > array.Length)
throw new ArgumentOutOfRangeException (nameof (ibStart));
if (cbSize < 0 || cbSize > array.Length - ibStart)
throw new ArgumentOutOfRangeException (nameof (cbSize));

int len = cbSize;
int idx = ibStart;

fixed (ulong* tptr = table) {
fixed (byte* aptr = array) {
while (len >= 8) {
crc ^= *((ulong*) (aptr + idx));
crc =
tptr [7 * 256 + (crc & 0xff)] ^
tptr [6 * 256 + ((crc >> 8) & 0xff)] ^
tptr [5 * 256 + ((crc >> 16) & 0xff)] ^
tptr [4 * 256 + ((crc >> 24) & 0xff)] ^
tptr [3 * 256 + ((crc >> 32) & 0xff)] ^
tptr [2 * 256 + ((crc >> 40) & 0xff)] ^
tptr [1 * 256 + ((crc >> 48) & 0xff)] ^
tptr [0 * 256 + (crc >> 56)];
idx += 8;
len -= 8;
}
while (len >= 8) {
crc ^= BitConverter.ToUInt64 (array, idx);
crc =
table [7 * 256 + (crc & 0xff)] ^
table [6 * 256 + ((crc >> 8) & 0xff)] ^
table [5 * 256 + ((crc >> 16) & 0xff)] ^
table [4 * 256 + ((crc >> 24) & 0xff)] ^
table [3 * 256 + ((crc >> 32) & 0xff)] ^
table [2 * 256 + ((crc >> 40) & 0xff)] ^
table [1 * 256 + ((crc >> 48) & 0xff)] ^
table [0 * 256 + (crc >> 56)];
idx += 8;
len -= 8;
}

while (len > 0) {
crc = tptr [0 * 256 + ((crc ^ aptr [idx]) & 0xff)] ^ (crc >> 8);
idx++;
len--;
}
}
while (len > 0) {
crc = table [0 * 256 + ((crc ^ array [idx]) & 0xff)] ^ (crc >> 8);
idx++;
len--;
}

length += (ulong) cbSize;
Expand Down
6 changes: 3 additions & 3 deletions src/Microsoft.Android.Build.BaseTasks/Files.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// https://github.com/dotnet/android/blob/34acbbae6795854cc4e9f8eb7167ab011e0266b4/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs#L409

using System;
using System.Buffers.Binary;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using System.Text;
using Microsoft.Build.Utilities;
Expand Down Expand Up @@ -694,8 +694,8 @@ public static string HashStream (Stream stream)
/// XOR the data length into the hash to avoid collisions on zero-filled inputs.
static void XorLength (Span<byte> hash, ulong length)
{
ref var crc = ref Unsafe.As<byte, ulong> (ref hash [0]);
crc ^= length;
ulong crc = BinaryPrimitives.ReadUInt64LittleEndian (hash);
BinaryPrimitives.WriteUInt64LittleEndian (hash, crc ^ length);
Comment thread
simonrozsival marked this conversation as resolved.
}

public static string ToHexString (byte[] hash)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>Microsoft.Android.Build.Tasks</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>
<AssemblyName>$(VendorPrefix)Microsoft.Android.Build.BaseTasks$(VendorSuffix)</AssemblyName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<OutputPath>$(MicrosoftAndroidSdkOutDir)</OutputPath>
<Nullable>annotations</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<!--
We share $(OutputPath) with Xamarin.Android.Build.Tasks.csproj. Letting NuGet
copy this project's transitive runtime assets there (e.g. the Mono.Cecil.dll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<TargetFramework>$(DotNetTargetFramework)</TargetFramework>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RootNamespace>Microsoft.Android.Sdk.TrimmableTypeMap</RootNamespace>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>
Expand Down
Loading
Loading