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

crypto_kdf_derive_from_key segfaults on ARM #123

Closed
encukou opened this issue Apr 2, 2020 · 0 comments · Fixed by #130
Closed

crypto_kdf_derive_from_key segfaults on ARM #123

encukou opened this issue Apr 2, 2020 · 0 comments · Fixed by #130

Comments

@encukou
Copy link

encukou commented Apr 2, 2020

test_crypto_kdf_derive_from_key segfaults on the ARM architecture due to incorrect use of ctypes.

The information about argument/return types of C function is present in .h files that aren't available at run time. So, when using ctypes, you need to declare argument types (technically only if different from defaults – but it's better to do it always). See ctypes documentation.

For kdf_derive_from_key specifically, this should probably be:

    nacl.crypto_kdf_derive_from_key.argtypes = [
        ctypes.c_char_p, ctypes.c_size_t, ctypes.c_ulonglong, ctypes.c_char_p, ctypes.c_char_p,
    ]

Without that, subkey_id is treated as C int instead of uint64_t. This is most likely causing #122 (Cannot use 64bit subkey ID) and the segfault on ARM architecture.

Take the above fix with a grain of NaCl though. I'm not really a ctypes expert.
You probably know about tools like Cython or CFFI, which can use info in .h files to avoid problems like this.

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

Successfully merging a pull request may close this issue.

1 participant