Problem: use of libsodium vs. tweetnacl is confused

It's unclear which we need and in the source code, conditional code
treats tweetnacl as a subclass of libsodium, which is inaccurate.

Solution: redesign the configure/cmake API for this:

* tweetnacl is present by default and cannot be enabled
* libsodium can be enabled using --with-libsodium, which replaces
  the built-in tweetnacl
* CURVE encryption can be disabled entirely using --enable-curve=no

The macros we define in platform.hpp are:

    ZMQ_HAVE_CURVE    1        //  When CURVE is enabled
    HAVE_LIBSODIUM    1        //  When we are using libsodium
    HAVE_TWEETNACL    1        //  When we're using tweetnacl (default)

As of this patch, the default build of libzmq always has CURVE
security, and always uses tweetnacl.
This commit is contained in:
Pieter Hintjens
2016-02-11 13:32:01 +01:00
parent 42ab88e486
commit b49a60410a
16 changed files with 610 additions and 610 deletions

View File

@@ -43,14 +43,12 @@
#include "windows.hpp"
#endif
#ifdef HAVE_LIBSODIUM
#ifdef HAVE_TWEETNACL
#include "tweetnacl_base.h"
#else
#include "sodium.h"
#if defined (HAVE_TWEETNACL)
# include "tweetnacl_base.h"
# include "randombytes.h"
#elif defined (HAVE_LIBSODIUM)
# include "sodium.h"
#endif
#endif
void zmq_sleep (int seconds_)
{
@@ -185,17 +183,17 @@ uint8_t *zmq_z85_decode (uint8_t *dest, const char *string)
}
// --------------------------------------------------------------------------
// Generate a public/private keypair with libsodium.
// Generate a public/private keypair with tweetnacl or libsodium.
// Generated keys will be 40 byte z85-encoded strings.
// Returns 0 on success, -1 on failure, setting errno.
// Sets errno = ENOTSUP in the absence of libsodium.
// Sets errno = ENOTSUP in the absence of a CURVE library.
int zmq_curve_keypair (char *z85_public_key, char *z85_secret_key)
{
#ifdef HAVE_LIBSODIUM
#if defined (ZMQ_HAVE_CURVE)
# if crypto_box_PUBLICKEYBYTES != 32 \
|| crypto_box_SECRETKEYBYTES != 32
# error "libsodium not built correctly"
# error "CURVE encryption library not built correctly"
# endif
uint8_t public_key [32];
@@ -210,7 +208,7 @@ int zmq_curve_keypair (char *z85_public_key, char *z85_secret_key)
zmq_z85_encode (z85_secret_key, secret_key, 32);
return 0;
#else // requires libsodium
#else
(void) z85_public_key, (void) z85_secret_key;
errno = ENOTSUP;
return -1;