In a current project the NaCl-library crypto_box
function has been used to encode and crypto_box_open
to authenticate and decode data.
However the library does not seem to support de- / encoding of large amounts of data, since the message and the buffer for the cipher text (plus nonce) as well have to be allocated in memory (The application has to run on smartphones and therefore must not consume too much memory).
Reading the documentation I came across the crypto_stream_xor
function which may allow to encrypt custom-sized portions of data, for example delivered through a stream. However a MAC still needs to be generated to detect message tampering.
Is there any built in way to generate and verify the MAC on a large message m
or has this to be dealt with on an upper level of communication by splitting large amounts of data in several authenticated, encrypted packages?
mmap()
files and use the NaCL functions as is.mmap()
approach seems promising, since it is transparent to the calling functions. However I'm not sure how reliable this function is on Android / iOS devices.mmap
should have issues but it never hurts to test. Of course you would need native code to use mmap. Java has alsojava.nio
but I'm not sure you could use that for this use case.mmap()
behavior is guaranteed by POSIX. It will be reliable on any compliant system.