Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zunzster opened this issue Jun 27, 2024 · 8 comments

Comments

@zunzster
Copy link

zunzster commented Jun 27, 2024

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).

@zunzster zunzster changed the title AES-NI assembler routines for X64 corrupt XMM6-XMM15 which are expected to be preserved X64 AESNI assembler routines corrupt XMM6-XMM15 in Win64 which are expected to be preserved Jun 27, 2024
@zunzster zunzster changed the title X64 AESNI assembler routines corrupt XMM6-XMM15 in Win64 which are expected to be preserved X64 AESNI assembler routines corrupt XMM6-XMM15 which the Win64 calling convention expected to be preserved Jun 27, 2024
@zunzster zunzster changed the title X64 AESNI assembler routines corrupt XMM6-XMM15 which the Win64 calling convention expected to be preserved X64 AESNI assembler routines corrupt XMM6-XMM15 which the Win64 calling convention expects to be preserved Jun 27, 2024
@synopse
Copy link
Owner

synopse commented Jun 27, 2024

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

@zunzster
Copy link
Author

zunzster commented Jun 27, 2024

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
Copy link
Owner

synopse commented Jul 2, 2024

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

@myonlylonely
Copy link

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
Copy link
Owner

synopse commented Jul 13, 2024

The fix exists in mormot 2.

@myonlylonely
Copy link

@synopse Is it possible to port it back to v1? synopse/mORMot2@4708b03

@zunzster
Copy link
Author

zunzster commented Jul 14, 2024

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.

zunzster@8d6eb99

@synopse
Copy link
Owner

synopse commented Jul 15, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants