According to the answers to a previous question, the 512 version should be faster on x64 devices. And even if it were executed on an x86 (32 bit) device - there shouldn't be such a big difference.
Is there some explanation for this difference? (Or must it be an implementation issue.)
The following code returns almost 5 seconds for the HMACSHA512, and almost 2 seconds for HMACSHA256: (It's run on a Samsung J5 (2015) which has a Snapdragon 410 Processor with "CPU Bit Architecture 64-bit". Using Xamarin.Forms PCL, the Droid project.):
private void Button_Clicked(object sender, EventArgs e)
{
ICrypto crypto = DependencyService.Get<ICrypto>();
Stopwatch watch = new Stopwatch();
byte[] b = new byte[64];
watch.Start();
for (int i = 0; i < 10000; i++)
{
b = crypto.CalculateHmac512(b);
}
watch.Stop();
label.Text = watch.ElapsedMilliseconds.ToString();
}
And
class Crypto : ICrypto
{
//HMACSHA256 hmac = new HMACSHA256();
HMACSHA512 hmac = new HMACSHA512();
public byte[] CalculateHmac512(byte[] m)
{
return hmac.ComputeHash(m);
}
}
(On a 64 bit PC for 100,000 iterations I get around 200ms for 512, and around 130ms for 256. So I guess that Xamarin itself is 32 bit. But that still doesn't explain the x2.5 difference on Android.)