intel / cryptography-primitives

Apache License 2.0
319 stars 86 forks source link

xmm6 overwritten/not restored by HashUpdate #22

Closed ventrebd closed 4 years ago

ventrebd commented 4 years ago

Root problem: xmm6 is not being restored after a call to ippsHashUpdate (& ippsHashUpdate_rmf) in certain circumstances.

I recently upgraded from 2020.0 to 2020.1 (as downloaded from Intel web site). My unit tests which verify hash computation began to fail in certain configurations (Release mode SHA hashes) but pass in others (all Debug modes, all MD5 hashes). This occurs in both AVX (e9) & AVX2 (l9) modes of the crypto library.

My unit test does the following (with run-time arguments for hash type):

  1. Call ippsHashGetSize
  2. Call ippsHashInit
  3. Calls ippsHashUpdate in a loop with a single byte value & length of 1
  4. Calls ippsHashFinal
  5. Verifies hash result against a "pre-computed" value.

In release mode only, the compiler (MSVC 1926, Windows x64) creates a temporary object and stores it into xmm6; this is used as part of the call tree in my test code & is restored as arguments to the ippsHashUpdate call on each loop pass. For MD5, this register is never affected, but after a certain number of calls to ippsHashUpdate with the SHA functions, the register is zero-ized by ippsHashUpdate (which then breaks the remainder of the hash computation loop, because further calls are made with a null pointer & length of zero as loaded from xmm6). Per the x64 ABI, xmm6-xmm15 are non-volatile across function calls and should be restored by the callee.

My guess is that something about the restoration of xmm registers is not working, and that it is tied to crossing a certain block boundary within ippsHashUpdate.

amatyuko-intc commented 4 years ago

Hi Brian,

Thanks for reporting it. Yes, we confirm such issue with non-volatile xmm registers. We fixed it, and the fix will be available in upcoming 2020 Update 2.

Regards, Andrey

ventrebd commented 4 years ago

Excellent, thank you. I'll keep an eye out for that update. Request to leave this issue open until release of 2020 Update 2 for awareness.

amatyuko-intc commented 4 years ago

Sure, I'll make an update here once it is out, so that you can check.

amatyuko-intc commented 4 years ago

Hi Brian,

The 2020u2 is uploaded, so you can take a look on it. Please let me know if the fix works for you.

Regards, Andrey

ventrebd commented 4 years ago

Yes, updating to 2020 update 2 worked. Thank you.