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

Crash with parameter passing in crypto_aead_aes256gcm_decrypt and crypto_aead_chacha20poly1305_ietf_decrypt #103

Closed
andreasbaumann opened this issue Sep 14, 2017 · 1 comment

Comments

@andreasbaumann
Copy link
Contributor

Tests fail on 32-bit Intel:

==> Starting check()...
test_gcm_aead (unit.test_aead.TestAEAD) ... /startdir/PKGBUILD: line 30:   424 Aborted                 (core dumped) python -m unittest discover --start-directory tests -v
==> ERROR: A failure occurred in check().
    Aborting...

In sodium/crypto_aead_aes256gcm.h I see that mlen_p is a pointer to a 64-bit long long:

int crypto_aead_aes256gcm_decrypt(unsigned char *m,
                                  unsigned long long *mlen_p,
                                  unsigned char *nsec,
                                  const unsigned char *c,
                                  unsigned long long clen,
                                  const unsigned char *ad,
                                  unsigned long long adlen,
                                  const unsigned char *npub,
                                  const unsigned char *k)

In __init.py__ in the 'ctypes' wrapper I see:

mlen = ctypes.c_ulonglong()
..
   ret = nacl.crypto_aead_aes256gcm_decrypt(
        m, mlen,
        None,
        ctxt, ctypes.c_ulonglong(len(ctxt)),
        aad, ctypes.c_ulonglong(len(aad)),
        nonce, key)
...
    ret = nacl.crypto_aead_chacha20poly1305_ietf_decrypt(
        m, mlen,
        None,
        ctxt, ctypes.c_ulonglong(len(ctxt)),
        aad, ctypes.c_ulonglong(len(aad)),
        nonce, key)
...

This works fine on 64-bit, but not on 32-bit. The tests crash with segfault.

When I change the calls to use a ctypes.byref the tests work fine:

    ret = nacl.crypto_aead_aes256gcm_decrypt(
        m, ctypes.byref(mlen),
        None,
        ctxt, ctypes.c_ulonglong(len(ctxt)),
        aad, ctypes.c_ulonglong(len(aad)),
        nonce, key)
...
   ret = nacl.crypto_aead_chacha20poly1305_ietf_decrypt(
        m, ctypes.byref(mlen),
        None,
        ctxt, ctypes.c_ulonglong(len(ctxt)),
        aad, ctypes.c_ulonglong(len(aad)),
        nonce, key)

See also debugging session on https://bbs.archlinux32.org/viewtopic.php?pid=219#p219.

@andreasbaumann andreasbaumann changed the title Crash with parameter passing in crypto_aead_aes256gcm_decrypt and rypto_aead_chacha20poly1305_ietf_decrypt Crash with parameter passing in crypto_aead_aes256gcm_decrypt and crypto_aead_chacha20poly1305_ietf_decrypt Sep 15, 2017
thatch45 added a commit that referenced this issue Oct 3, 2017
added ctypes.byref(mlen) for 32-bit (issue #103)
@andreasbaumann
Copy link
Contributor Author

merged pull request

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

1 participant