Subject: | crypto_box() adds zero padding |
Date: | Mon, 26 May 2014 23:07:01 +0200 |
To: | bug-Crypt-Sodium [...] rt.cpan.org |
From: | "Steinar H. Gunderson" <sgunderson [...] bigfoot.com> |
Hi,
It seems that crypto_box() adds a bunch of zero bytes that do not serve any
obvious useful purpose. Example:
cirkus:~> perl -le 'use Crypt::Sodium; $z = crypto_box("0123456789", "nnnnnnnnnnnnnnnnnnnnnnnn", "pppppppppppppppppppppppppppppppp", "ssssssssssssssssssssssssssssssss"); print unpack("H*", $z);'
00000000000000000000000000000000d1455f47cdc5f9cb6b3ea3dd2cb073a5a5cc3e149673e5a7965e
which means there are 16 extra zero bytes at the start.
The value afterwards (d1455f...) is indeed the correct output as produced by
libnacl from C++.
The padding is an artifact of the fact that the C library (as opposed to the
C++ library) needs some temporary space for the Poly1305 cipher.
http://nacl.cr.yp.to/box.html specifically says “Typical higher-level
applications will work with the remaining bytes of the message”; in
particular, it's not something that one should really transmit over the wire.
Thus, it should probably be stripped away from the ciphertext before sending
it on to the Perl program.
/* Steinar */
--
Homepage: http://www.sesse.net/