jedisct1/libsodium — pull request #185 by TehWan (2014-08-27 17:11:37+00:00)
Title: Fix for assertion failure in randombytes on Linux x86

On Linux x86, I get the following assertion failure: ``randombytes/randombytes.c:63: randombytes: Assertion `buf_len <= (4294967295U)' failed.``

On Linux x86, ``SIZE_MAX`` is 2^32, but an ``unsigned long long int`` is 2^64. In ``randombytes.h``, the ``struct randombytes_implementation`` defines ``buf`` with the second parameter being a ``size_t`` (2^32), but the ``randombytes()`` function is defined using a ``long long unsigned int`` (2^64). This causes the library to only send 32 bits for the ``buf_len`` (``size_t``) but it tries to read 64 bits of data (``long long unsigned int``), which causes a failed assertion when memory following the 4 bytes is non-zero.

All tests passed before and after this patch. I am using libsodium through Python with proprietary software, which worked on my co-workers' computers (Mac OSX 64-bit) but not on mine (Xubuntu 12.10 32-bit).