jedisct1 / libsodium

A modern, portable, easy to use crypto library.
https://libsodium.org
Other
12.15k stars 1.73k forks source link

crypto_secretbox_open_detached crashed in a 64Bit DLL #1022

Closed berndb84 closed 3 years ago

berndb84 commented 3 years ago

I am using libsodium to decrypt a PE section in a DLL. I have build a 32Bit DLL and a 64Bit with precompiled libsodium binaries (32Bit and 64Bit). The 32Bit DLL decrypts the section as expected, but the 64Bit DLL is crashing and throwing these error:

Access violation reading location 0x806A9000

The adress mentioned belongs to the encrypted PE section and used as input into crypto_secretbox_open_detached. However, when I use the debugger the adress is shown as 0x1806A9000

The stacketrace shows that memcpy is responsible for these error. It is used in load32_le.

Stacktrace

d:\agent\_work\63\s\src\vctools\crt\vcruntime\src\string\amd64\memcpy.asm (274): memcpy
D:\a\1\s\src\libsodium\include\sodium\private\common.h (107): load32_le
D:\a\1\s\src\libsodium\crypto_onetimeauth\poly1305\donna\poly1305_donna32.h (85): poly1305_blocks
D:\a\1\s\src\libsodium\crypto_onetimeauth\poly1305\donna\poly1305_donna.c (45): poly1305_update
D:\a\1\s\src\libsodium\crypto_onetimeauth\poly1305\donna\poly1305_donna.c (67): crypto_onetimeauth_poly1305_donna
D:\a\1\s\src\libsodium\crypto_onetimeauth\poly1305\donna\poly1305_donna.c (112): crypto_onetimeauth_poly1305_donna_verify
D:\a\1\s\src\libsodium\crypto_onetimeauth\poly1305\onetimeauth_poly1305.c (31): crypto_onetimeauth_poly1305_verify
D:\a\1\s\src\libsodium\crypto_secretbox\crypto_secretbox_easy.c (97): crypto_secretbox_open_detached

I don`t know where the problem is.

jedisct1 commented 3 years ago

Hard to tell without the actual code.

Check the size of your input and output buffers; make sure these are properly allocated and of the right size. Try with a simple example first, and then gradually move it to your actual application.