synopse / mORMot

Synopse mORMot 1 ORM/SOA/MVC framework - Please upgrade to mORMot 2 !
https://synopse.info
783 stars 324 forks source link

X64 AESNI assembler routines corrupt XMM6-XMM15 which the Win64 calling convention expects to be preserved #454

Open zunzster opened 3 weeks ago

zunzster commented 3 weeks ago

This corruption can be observed when compiling with Optimization on and local Double variables are stored in XMM6 onwards.

Code blocks similar to the {$IFNDEF LINUX} blocks in sha256_sse4 from Intel are needed for the X64 assembler routines which use XMM6-XMM15.

aesni(en|de)crypt128 (xmm6-xmm11), aesni(en|de)crypt192 (xmm6-xmm13), aesni(de|en)crypt256 (xmm6-xmm15) MakeDecrKeyAesNi (xmm6-xmm7), AesNiEncryptOFB_128 (xmm6-xmm11), AesNiEncryptOFB_256 (xmm6-xmm15).

synopse commented 3 weeks ago

Please switch to mORMot 2, which already includes the fix.

zunzster commented 3 weeks ago

Thanks, Arnaud. I figured that was likely the case.

We're only using a selected few pieces of mORMot v1 so I'll look at what is involved in switching those to mORMot v2. I've coded up the required fixes in case anyone else wants them.

synopse commented 2 weeks ago

You are welcome to make a pull request here, of course!

myonlylonely commented 1 week ago

Thanks, Arnaud. I figured that was likely the case.

We're only using a selected few pieces of mORMot v1 so I'll look at what is involved in switching those to mORMot v2. I've coded up the required fixes in case anyone else wants them.

@zunzster May I ask what the fix is? Is it possible to make a pull request or just show us the fixed code? We also use mORMot V1 for few selected pieces, it will be a great help for us if the legacy V1 has fixes for bugs.

synopse commented 1 week ago

The fix exists in mormot 2.

myonlylonely commented 1 week ago

@synopse Is it possible to port it back to v1? https://github.com/synopse/mORMot2/commit/4708b03356bf64ebbc73b20b19b3715f05baeec9

zunzster commented 6 days ago

I've forked Mormot and pushed up my SynCrypto.pas changes for inspection. I've adapted my changes to be even closer to the Mormot2 changes but I'm 16-byte aligning the stack so I can use movaps for a slight speed boost.

I still have the original changes I made before seeing the v2 changes - that's the {$IFNDEF LINUX} section where I was following the Intel SHA1 convention from the example further down that file.

https://github.com/zunzster/mORMot/commit/8d6eb9991ead952c91cf2ea3cadaffc3b5a2b353

synopse commented 6 days ago

Thanks a lot for sharing! You can make a Pull Request!

I am not sure there is any benefit with using the MORMOT2 version of the code, for these procedures.