1
$\begingroup$

In order to avoid memory errors, I always write safe C++ wrappers with strong type-safety for any C encryption library I use.

To test my wrapper of crypto_secretbox_xsalsa20poly1305 of libsodium and make sure I'm using it correctly, I need a set of messages, nonces and keys that someone used and encrypted and the outcome of that. This is necessary for unit tests.

In OpenSSL, when I do that, I usually use the terminal, and pipe from the terminal to my unit tests and compare the output of my result.

There doesn't seem to be a terminal tool for libsodium. So I'm hoping there's either an online service that does this (take msg + nonce + key and produce cipher + mac), or someone here could provide a few test messages and their expected mac + cipher in hex.

$\endgroup$
1

1 Answer 1

1
$\begingroup$

Just use the test vector specified by DJB himself, specified here, chapter 4 (just XSalsa20) and chapter 10 for the box. This will already test all your primitives.

To perform boundary tests, I would strongly suggest you first document the boundaries. These are the places where there is a difference in e.g. buffer handling for the MAC function. If you test those boundaries against your own library then the MAC will still generate the same wrong value.

There seems to be TweetNaCl.js available online, so you can generate your own vectors after establishing your boundaries.

$\endgroup$
1
  • $\begingroup$ Comments are not for extended discussion; this conversation has been moved to chat. $\endgroup$
    – Maarten Bodewes
    Apr 24, 2019 at 15:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.