Commit e5a294ec authored by Frank's avatar Frank

tweetnacl integration

parent 49f18d55
......@@ -123,3 +123,4 @@ foreign/openpgm/*
zeromq-*.tar.gz
zeromq-*.zip
core
build
......@@ -9,6 +9,25 @@ if(APPLE)
option(ZMQ_BUILD_FRAMEWORK "Build as OS X framework" ON)
endif()
option(WITH_TWEETNACL "Build with tweetnacl" ON)
if(WITH_TWEETNACL)
add_definitions(-DHAVE_TWEETNACL -DHAVE_LIBSODIUM)
include_directories(
tweetnacl/contrib/randombytes
tweetnacl/src
)
set(TWEETNACL_SOURCES
tweetnacl/src/tweetnacl.c
)
if(WIN32)
else()
list(APPEND TWEETNACL_SOURCES tweetnacl/contrib/randombytes/devurandom.c)
endif()
endif()
set(POLLER "" CACHE STRING "Choose polling system. valid values are
kqueue, epoll, devpoll, poll or select [default=autodetect]")
......@@ -469,6 +488,10 @@ foreach(source ${cxx-sources})
list(APPEND sources ${CMAKE_CURRENT_SOURCE_DIR}/src/${source})
endforeach()
foreach(source ${TWEETNACL_SOURCES})
list(APPEND sources ${CMAKE_CURRENT_SOURCE_DIR}/${source})
endforeach()
foreach(source ${rc-sources})
list(APPEND sources ${CMAKE_CURRENT_BINARY_DIR}/${source})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/${source}.in ${CMAKE_CURRENT_BINARY_DIR}/${source})
......@@ -701,7 +724,7 @@ if(ZMQ_BUILD_TESTS)
target_link_libraries(${test} libzmq)
if(RT_LIBRARY)
target_link_libraries(${test} ${RT_LIBRARY})
target_link_libraries(${test} ${RT_LIBRARY} )
endif()
if(WIN32)
add_test(NAME ${test} WORKING_DIRECTORY ${LIBRARY_OUTPUT_PATH} COMMAND ${test})
......
......@@ -21,8 +21,6 @@
#ifdef HAVE_LIBSODIUM
#include <sodium.h>
#ifdef ZMQ_HAVE_WINDOWS
#include "windows.hpp"
#endif
......
......@@ -23,7 +23,12 @@
#include "platform.hpp"
#ifdef HAVE_LIBSODIUM
#include <sodium.h>
#ifdef HAVE_TWEETNACL
#include "tweetnacl_base.h"
#include "randombytes.h"
#else
#include "sodium.h"
#endif
#if crypto_box_NONCEBYTES != 24 \
|| crypto_box_PUBLICKEYBYTES != 32 \
......
......@@ -20,7 +20,6 @@
#include "platform.hpp"
#ifdef HAVE_LIBSODIUM
#include <sodium.h>
#ifdef ZMQ_HAVE_WINDOWS
#include "windows.hpp"
......
......@@ -23,8 +23,12 @@
#include "platform.hpp"
#ifdef HAVE_LIBSODIUM
#include <sodium.h>
#ifdef HAVE_TWEETNACL
#include "tweetnacl_base.h"
#include "randombytes.h"
#else
#include "sodium.h"
#endif
#if crypto_box_NONCEBYTES != 24 \
|| crypto_box_PUBLICKEYBYTES != 32 \
|| crypto_box_SECRETKEYBYTES != 32 \
......@@ -118,4 +122,3 @@ namespace zmq
#endif
#endif
......@@ -30,8 +30,13 @@
#else
#include "windows.hpp"
#endif
#ifdef HAVE_LIBSODIUM
# include <sodium.h>
#ifdef HAVE_TWEETNACL
#include "tweetnacl_base.h"
#else
#include "sodium.h"
#endif
#endif
......
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
/* it's really stupid that there isn't a syscall for this */
static int fd = -1;
void randombytes(unsigned char *x,unsigned long long xlen)
{
int i;
if (fd == -1) {
for (;;) {
fd = open("/dev/urandom",O_RDONLY);
if (fd != -1) break;
sleep(1);
}
}
while (xlen > 0) {
if (xlen < 1048576) i = xlen; else i = 1048576;
i = read(fd,x,i);
if (i < 1) {
sleep(1);
continue;
}
x += i;
xlen -= i;
}
}
/*
randombytes/devurandom.h version 20080713
D. J. Bernstein
Public domain.
*/
#ifndef randombytes_devurandom_H
#define randombytes_devurandom_H
#ifdef __cplusplus
extern "C" {
#endif
extern void randombytes(unsigned char *,unsigned long long);
#ifdef __cplusplus
}
#endif
#ifndef randombytes_implementation
#define randombytes_implementation "devurandom"
#endif
#endif
#ifndef randombytes_H
#define randombytes_H
#include "devurandom.h"
#endif
This diff is collapsed.
This diff is collapsed.
#ifndef TWEETNACL_BASE_H
#define TWEETNACL_BASE_H
/* the original file seems to be a compability layer for NaCL */
/* This here is for direct tweetnacl usage */
#define crypto_box_SECRETKEYBYTES 32
#define crypto_box_BOXZEROBYTES 16
#define crypto_box_NONCEBYTES 24
#define crypto_box_ZEROBYTES 32
#define crypto_box_PUBLICKEYBYTES 32
#define crypto_box_BEFORENMBYTES 32
#define crypto_secretbox_KEYBYTES 32
#define crypto_secretbox_NONCEBYTES 24
#define crypto_secretbox_ZEROBYTES 32
#define crypto_secretbox_BOXZEROBYTES 16
typedef unsigned char u8;
typedef unsigned long u32;
typedef unsigned long long u64;
typedef long long i64;
typedef i64 gf[16];
#ifdef __cplusplus
extern "C" {
#endif
int crypto_box_keypair(u8 *y,u8 *x);
int crypto_box_afternm(u8 *c,const u8 *m,u64 d,const u8 *n,const u8 *k);
int crypto_box_open_afternm(u8 *m,const u8 *c,u64 d,const u8 *n,const u8 *k);
int crypto_box(u8 *c,const u8 *m,u64 d,const u8 *n,const u8 *y,const u8 *x);
int crypto_box_open(u8 *m,const u8 *c,u64 d,const u8 *n,const u8 *y,const u8 *x);
int crypto_box_beforenm(u8 *k,const u8 *y,const u8 *x);
int crypto_secretbox(u8 *c,const u8 *m,u64 d,const u8 *n,const u8 *k);
int crypto_secretbox_open(u8 *m,const u8 *c,u64 d,const u8 *n,const u8 *k);
#ifdef __cplusplus
}
#endif
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment