Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • cellframe/cellframe-sdk
  • MIKA83/cellframe-sdk
2 results
Show changes
Commits on Source (22)
Showing
with 379 additions and 186 deletions
......@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.1)
project(dap_cuttdb C)
add_definitions ("-D_GNU_SOURCE")
set(CMAKE_C_FLAGS " -Wall -Wextra -fPIC")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
file(GLOB cuttdb_src src/*.c)
file(GLOB cuttdb_h src/*.h)
......
......@@ -1016,7 +1016,7 @@ int cdb_set2(CDB *db, const char *key, int ksize, const char *val, int vsize, in
if (cret < 0)
continue;
if (ksize == rrec->ksize && memcmp(rrec->key, key, ksize) == 0) {
if ((uint32_t) ksize == rrec->ksize && memcmp(rrec->key, key, ksize) == 0) {
/* got its old meta info */
rec.osize = rrec->osize;
rec.ooff = rrec->ooff;
......@@ -1092,7 +1092,7 @@ int cdb_is(CDB *db, const char *key, int ksize)
FOFF *offs;
int dupnum, ret = -3;
uint64_t hash;
uint32_t now = time(NULL);
//uint32_t now = time(NULL);
uint32_t lockid;
if (db->rcache) {
......@@ -1212,7 +1212,7 @@ int cdb_get(CDB *db, const char *key, int ksize, void **val, int *vsize)
if (cret < 0)
continue;
if (ksize == rec->ksize && memcmp(rec->key, key, ksize) == 0) {
if ((uint32_t) ksize == rec->ksize && memcmp(rec->key, key, ksize) == 0) {
if (rec->expire && rec->expire <= now) {
break;
}
......@@ -1337,7 +1337,7 @@ int cdb_del(CDB *db, const char *key, int ksize)
if (cret < 0)
continue;
if (ksize == rrec->ksize && memcmp(rrec->key, key, ksize) == 0) {
if ((uint32_t) ksize == rrec->ksize && memcmp(rrec->key, key, ksize) == 0) {
/* got its old meta info */
rec.osize = rrec->osize;
rec.ooff = rrec->ooff;
......@@ -1357,8 +1357,9 @@ int cdb_del(CDB *db, const char *key, int ksize)
struct timespec ts;
_cdb_timerreset(&ts);
if (db->vio->drec(db->vio, &rec, ooff) < 0)
; // return -1; succeed or not doesn't matter
db->vio->drec(db->vio, &rec, ooff);
//if ( < 0)
// return -1; succeed or not doesn't matter
db->wcount++;
db->wtime += _cdb_timermicrosec(&ts);
cdb_seterrno(db, CDB_SUCCESS, __FILE__, __LINE__);
......@@ -1425,6 +1426,7 @@ int cdb_close(CDB *db)
void cdb_deferrorcb(void *arg, int errno, const char *file, int line)
{
(void) arg;
fprintf(stderr, "DBERR: [%s:%d] %d - %s\n", file, line, errno, cdb_errmsg(errno));
}
......
......@@ -496,7 +496,7 @@ CDBHTITEM *cdb_ht_iternext(CDBHASHTABLE *ht, CDBHTITEM *cur)
CDBHTBUCKET *bucket = &(ht->buckets[i]);
if (!bucket->rnum)
continue;
for(int j = 0; j < bucket->bnum; j++)
for(uint32_t j = 0; j < bucket->bnum; j++)
if (bucket->items[j])
return bucket->items[j];
}
......
......@@ -298,6 +298,7 @@ void vio_apnd2_init(CDBVIO *vio)
/* the hash table used in VIOAPND2 need not rehash, just use the key id is OK */
static uint32_t _directhash(const void *key, int size)
{
(void) size;
return *(uint32_t*)key;
}
......@@ -603,7 +604,7 @@ static int _vio_apnd2_readmeta(CDBVIO *vio, bool overwrite)
return -1;
}
for(int i = 0; i < myio->ifnum; i++) {
for(uint32_t i = 0; i < myio->ifnum; i++) {
VIOAPND2FINFO finfo, *finfo2;
finfo.fid = *(uint32_t*)(hbuf + pos);
pos += SI4;
......@@ -638,7 +639,7 @@ static int _vio_apnd2_readmeta(CDBVIO *vio, bool overwrite)
}
}
for(int i = 0; i < myio->dfnum; i++) {
for(uint32_t i = 0; i < myio->dfnum; i++) {
VIOAPND2FINFO finfo, *finfo2;
finfo.fid = *(uint32_t*)(hbuf + pos);
pos += SI4;
......@@ -709,8 +710,8 @@ static int _vio_apnd2_flushbuf(CDBVIO *vio, int dtype)
/* buffer for deletion is special */
if (myio->delbufpos == 0)
return 0;
if (write(myio->dfd, myio->delbuf, sizeof(FOFF) * myio->delbufpos)
!= sizeof(FOFF) * myio->delbufpos) {
if ( (size_t) write(myio->dfd, myio->delbuf, sizeof(FOFF) * (size_t) myio->delbufpos)
!= sizeof(FOFF) * (size_t) myio->delbufpos) {
cdb_seterrno(vio->db, CDB_WRITEERR, __FILE__, __LINE__);
return -1;
}
......@@ -732,9 +733,8 @@ static int _vio_apnd2_flushbuf(CDBVIO *vio, int dtype)
/* write out if buffered */
if (iobuf->pos > 0) {
if (pwrite(iobuf->fd, iobuf->buf, iobuf->pos, iobuf->off) != iobuf->pos) {
/* to avoid compile warning */
if (ftruncate(iobuf->fd, iobuf->off) < 0) ;
cdb_seterrno(vio->db, CDB_WRITEERR, __FILE__, __LINE__);
if (ftruncate(iobuf->fd, iobuf->off) < 0)
cdb_seterrno(vio->db, CDB_WRITEERR, __FILE__, __LINE__);
return -1;
}
}
......@@ -948,8 +948,8 @@ static int _vio_apnd2_write(CDBVIO *vio, int fd, void *buf, uint32_t size, bool
off = OFFALIGNED(off);
if (pwrite(fd, buf, size, off) != size) {
/* to avoid compile warning */
if (ftruncate(myio->ibuf.fd, off) < 0) ;
cdb_seterrno(vio->db, CDB_WRITEERR, __FILE__, __LINE__);
if (ftruncate(myio->ibuf.fd, off) < 0)
cdb_seterrno(vio->db, CDB_WRITEERR, __FILE__, __LINE__);
return -1;
}
......@@ -1160,7 +1160,7 @@ static int _vio_apnd2_loadfd(CDBVIO *vio, uint32_t fid, int dtype)
/* cache the fd, close the oldest file not touched */
cdb_ht_insert2(myio->fdcache, &vfid, SI4, &fd, sizeof(int));
while(myio->fdcache->num > myio->maxfds) {
while(myio->fdcache->num > (uint32_t) myio->maxfds) {
CDBHTITEM *item = cdb_ht_poptail(myio->fdcache);
close(*(int*)cdb_ht_itemval(myio->fdcache, item));
free(item);
......@@ -1217,7 +1217,7 @@ static int _vio_apnd2_readpage(CDBVIO *vio, CDBPAGE **page, FOFF off)
}
psize = PAGESIZE(*page);
if (ret < areadsize && ret < psize) {
if ((uint32_t) ret < areadsize && (uint32_t) ret < psize) {
cdb_lock_unlock(myio->lock);
cdb_seterrno(vio->db, CDB_DATAERRIDX, __FILE__, __LINE__);
return ret;
......@@ -1232,7 +1232,7 @@ static int _vio_apnd2_readpage(CDBVIO *vio, CDBPAGE **page, FOFF off)
ret = _vio_apnd2_read(vio, fd, (char*)&(*page)->magic + areadsize,
psize - areadsize, roff + areadsize);
if (ret < psize - areadsize) {
if ((uint32_t) ret < psize - areadsize) {
cdb_lock_unlock(myio->lock);
cdb_seterrno(vio->db, CDB_DATAERRIDX, __FILE__, __LINE__);
return -1;
......@@ -1302,7 +1302,7 @@ static int _vio_apnd2_readrec(CDBVIO *vio, CDBREC** rec, FOFF off, bool readval)
(*rec)->vsize = 0;
rsize = RECSIZE(*rec);
if (ret < areadsize && ret < rsize) {
if ((uint32_t) ret < areadsize && (uint32_t) ret < rsize) {
cdb_lock_unlock(myio->lock);
cdb_seterrno(vio->db, CDB_DATAERRDAT, __FILE__, __LINE__);
return -1;
......@@ -1316,7 +1316,7 @@ static int _vio_apnd2_readrec(CDBVIO *vio, CDBREC** rec, FOFF off, bool readval)
}
ret = _vio_apnd2_read(vio, fd, (char*)&(*rec)->magic + areadsize,
rsize - areadsize, roff + areadsize);
if (ret != rsize - areadsize) {
if ((uint32_t) ret != rsize - areadsize) {
cdb_lock_unlock(myio->lock);
cdb_seterrno(vio->db, CDB_DATAERRDAT, __FILE__, __LINE__);
return -1;
......@@ -1578,7 +1578,7 @@ static int _vio_apnd2_writehead(CDBVIO *vio, bool wtable)
return -1;
}
if (wtable && pwrite(myio->hfd, db->mtable, sizeof(FOFF) * db->hsize, FILEMETASIZE)
if (wtable && (size_t) pwrite(myio->hfd, db->mtable, sizeof(FOFF) * db->hsize, FILEMETASIZE)
!= sizeof(FOFF) * db->hsize) {
cdb_seterrno(vio->db, CDB_WRITEERR, __FILE__, __LINE__);
return -1;
......@@ -1638,7 +1638,7 @@ static int _vio_apnd2_readhead(CDBVIO *vio, bool rtable)
if (db->mtable)
free(db->mtable);
db->mtable = (FOFF *)malloc(sizeof(FOFF) * db->hsize);
if (pread(myio->hfd, db->mtable, sizeof(FOFF) * db->hsize, FILEMETASIZE) !=
if ( (size_t) pread(myio->hfd, db->mtable, sizeof(FOFF) * db->hsize, FILEMETASIZE) !=
sizeof(FOFF) * db->hsize) {
free(db->mtable);
cdb_seterrno(db, CDB_READERR, __FILE__, __LINE__);
......@@ -2088,11 +2088,11 @@ static int _vio_apnd2_recovery(CDBVIO *vio, bool force)
lfinfo->fnext = NULL;
lfinfo = NULL;
if (myio->ibuf.fid == -1) {
if (myio->ibuf.fid == (uint32_t) -1) {
myio->ibuf.fid = 0;
_vio_apnd2_shiftnew(vio, VIOAPND2_INDEX);
}
if (myio->dbuf.fid == -1) {
if (myio->dbuf.fid == (uint32_t) -1) {
myio->dbuf.fid = 0;
_vio_apnd2_shiftnew(vio, VIOAPND2_DATA);
}
......@@ -2190,7 +2190,7 @@ static int _vio_apnd2_recovery(CDBVIO *vio, bool force)
for(; myio->dfd > 0;) {
int ret = read(myio->dfd, delitems, 1024 * sizeof(FOFF));
if (ret > 0) {
for(int j = 0; j * sizeof(FOFF) < ret; j++) {
for(uint32_t j = 0; j * sizeof(FOFF) < (uint32_t) ret; j++) {
char sbuf[SBUFSIZE];
uint32_t ofid, roff;
CDBREC *rec = (CDBREC *)sbuf;
......@@ -2326,7 +2326,7 @@ static int _vio_apnd2_iterfirst(CDBVIO *vio, VIOAPND2ITOR *it, int dtype, int64_
it->off += ALIGNBYTES;
continue;
}
if (page->oid >= oid)
if (page->oid >= (uint64_t) oid)
break;
it->off += OFFALIGNED(PAGESIZE(page));
} else if (dtype == VIOAPND2_DATA) {
......@@ -2335,7 +2335,7 @@ static int _vio_apnd2_iterfirst(CDBVIO *vio, VIOAPND2ITOR *it, int dtype, int64_
it->off += ALIGNBYTES;
continue;
}
if (rec->oid >= oid)
if (rec->oid >= (uint64_t) oid)
break;
it->off += OFFALIGNED(RECSIZE(rec));
}
......
......@@ -72,20 +72,6 @@ else()
set(OPT_FLAGS_RELEASE "-Ofast")
endif()
# Check whether we're on a 32-bit or 64-bit system
if(CMAKE_SIZEOF_VOID_P EQUAL "8")
set(DEFAULT_BUILD_64 ON)
else()
set(DEFAULT_BUILD_64 OFF)
endif()
option(BUILD_64 "Build for 64-bit? 'OFF' builds for 32-bit." ${DEFAULT_BUILD_64})
if(BUILD_64)
set(ARCH_WIDTH "64")
else()
set(ARCH_WIDTH "32")
endif()
message(STATUS "Building for a ${ARCH_WIDTH}-bit system")
# Check if we're on FreeBSD so we can exclude the local miniupnpc (it should be installed from ports instead)
# CMAKE_SYSTEM_NAME checks are commonly known, but specifically taken from libsdl's CMakeLists
......@@ -120,7 +106,7 @@ if(MSVC)
include_directories(SYSTEM src/platform/msc)
else()
set(ARCH native CACHE STRING "CPU to build for: -march value or 'default' to not pass -march at all")
message(STATUS "Building on ${CMAKE_SYSTEM_PROCESSOR} for ${ARCH}")
message(STATUS "[*] Building on ${CMAKE_SYSTEM_PROCESSOR} for ${ARCH}")
if(ARCH STREQUAL "default")
set(ARCH_FLAG "")
elseif(PPC64LE)
......@@ -167,32 +153,32 @@ else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing")
option(NO_AES "Explicitly disable AES support" ${NO_AES})
option(NO_AES "[!] Explicitly disable AES support" ${NO_AES})
if(NO_AES)
message(STATUS "AES support explicitly disabled")
message(STATUS "[!] AES support explicitly disabled")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNO_AES")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNO_AES")
elseif(NOT ARM AND NOT PPC64LE)
message(STATUS "AES support enabled")
message(STATUS "[ ] AES support enabled")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -maes")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -maes")
elseif(PPC64LE)
message(STATUS "AES support not available on ppc64le")
message(STATUS "[!] AES support not available on ppc64le")
elseif(ARM6)
message(STATUS "AES support not available on ARMv6")
message(STATUS "[!] AES support not available on ARMv6")
elseif(ARM7)
message(STATUS "AES support not available on ARMv7")
message(STATUS "[!] AES support not available on ARMv7")
elseif(ARM8 AND NOT ANDROID)
CHECK_CXX_ACCEPTS_FLAG("-march=${ARCH}+crypto" ARCH_PLUS_CRYPTO)
if(ARCH_PLUS_CRYPTO)
message(STATUS "Crypto extensions enabled for ARMv8")
message(STATUS "[*] Crypto extensions enabled for ARMv8")
set(ARCH_FLAG "-march=${ARCH}+crypto")
else()
message(STATUS "Crypto extensions unavailable on your ARMv8 device")
message(STATUS "[!] Crypto extensions unavailable on your ARMv8 device")
endif()
else()
message(STATUS "AES support disabled")
message(STATUS "[!] AES support disabled")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -D_GNU_SOURCE ${MINGW_FLAG} ${STATIC_ASSERT_FLAG} ${WARNINGS} ${C_WARNINGS} ${ARCH_FLAG} ${COVERAGE_FLAGS} ${PIC_FLAG}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -D_GNU_SOURCE ${MINGW_FLAG} ${STATIC_ASSERT_CPP_FLAG} ${WARNINGS} ${CXX_WARNINGS} ${ARCH_FLAG} ${COVERAGE_FLAGS} ${PIC_FLAG}")
......@@ -202,7 +188,7 @@ else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing")
if(ARM)
message(STATUS "Setting FPU Flags for ARM Processors")
message(STATUS "[ ] Setting FPU Flags for ARM Processors")
#NB NEON hardware does not fully implement the IEEE 754 standard for floating-point arithmetic
#Need custom assembly code to take full advantage of NEON SIMD
......@@ -231,44 +217,44 @@ else()
endif()
if(ARM6)
message(STATUS "Selecting VFP for ARMv6")
message(STATUS "[ ] Selecting VFP for ARMv6")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=vfp")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=vfp")
endif(ARM6)
if(ARM7)
if(CXX_ACCEPTS_VFP3_D16 AND NOT CXX_ACCEPTS_VFP4)
message(STATUS "Selecting VFP3 for ARMv7")
message(STATUS "[ ] Selecting VFP3 for ARMv7")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=vfp3-d16")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=vfp3-d16")
endif()
if(CXX_ACCEPTS_VFP4)
message(STATUS "Selecting VFP4 for ARMv7")
message(STATUS "[ ] Selecting VFP4 for ARMv7")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfpu=vfp4")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=vfp4")
endif()
if(CXX_ACCEPTS_MFLOAT_HARD)
message(STATUS "Setting Hardware ABI for Floating Point")
message(STATUS "[ ] Setting Hardware ABI for Floating Point")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfloat-abi=hard")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfloat-abi=hard")
endif()
if(CXX_ACCEPTS_MFLOAT_SOFTFP AND NOT CXX_ACCEPTS_MFLOAT_HARD)
message(STATUS "Setting Software ABI for Floating Point")
message(STATUS "[ ] Setting Software ABI for Floating Point")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfloat-abi=softfp")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfloat-abi=softfp")
endif()
endif(ARM7)
if(ARM8)
if(CXX_ACCEPTS_MFIX_CORTEX_A53_835769)
message(STATUS "Enabling Cortex-A53 workaround 835769")
message(STATUS "[ ] Enabling Cortex-A53 workaround 835769")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfix-cortex-a53-835769")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfix-cortex-a53-835769")
endif()
if(CXX_ACCEPTS_MFIX_CORTEX_A53_843419)
message(STATUS "Enabling Cortex-A53 workaround 843419")
message(STATUS "[ ] Enabling Cortex-A53 workaround 843419")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfix-cortex-a53-843419")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfix-cortex-a53-843419")
endif()
......@@ -277,7 +263,7 @@ else()
endif(ARM)
if(ANDROID AND NOT BUILD_GUI_DEPS STREQUAL "ON" OR IOS)
#From Android 5: "only position independent executables (PIE) are supported"
message(STATUS "Enabling PIE executable")
message(STATUS "[ ] Enabling PIE executable")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_CXX_FLAGS} -fPIE -pie")
......@@ -379,7 +365,7 @@ if (ARM)
option(NO_OPTIMIZED_MULTIPLY_ON_ARM
"Compute multiply using generic C implementation instead of ARM ASM" OFF)
if(NO_OPTIMIZED_MULTIPLY_ON_ARM)
message(STATUS "Using generic C implementation for multiply")
message(STATUS "[ ] Using generic C implementation for multiply")
set_property(SOURCE slow-hash.c
PROPERTY COMPILE_DEFINITIONS "NO_OPTIMIZED_MULTIPLY_ON_ARM")
endif()
......
......@@ -2,8 +2,7 @@ project(cellframe-sdk C)
cmake_minimum_required(VERSION 2.8)
set(CMAKE_C_STANDARD 11)
set(CELLFRAME_SDK_NATIVE_VERSION "2.1-4")
include(cmake/OS_Detection.cmake)
set(CELLFRAME_SDK_NATIVE_VERSION "2.3-1")
add_definitions ("-DCELLFRAME_SDK_VERSION=\"${CELLFRAME_SDK_NATIVE_VERSION}\"")
set(DAPSDK_MODULES "")
......@@ -12,6 +11,7 @@ if (CELLFRAME_MODULES MATCHES "core")
SET(DAPSDK_MODULES "${DAPSDK_MODULES} core crypto")
endif()
if (CELLFRAME_MODULES MATCHES "network")
set(DAPSDK_MODULES "${DAPSDK_MODULES} network-core network-client network-server")
endif()
......@@ -26,6 +26,15 @@ if (BUILD_CRYPTO_TESTS)
set(BUILD_TESTS ON)
endif()
if(BUILD_TESTS)
include(cmake/OS_Detection.cmake)
endif()
if(DAP_TUN_NEW_WORKER)
message("[*] New TUN worker processor enabled")
add_definitions ("-DDAP_TUN_IN_WORKER")
endif()
add_subdirectory(dap-sdk)
add_subdirectory(3rdparty/monero_crypto)
add_subdirectory(3rdparty/cuttdb)
......
......@@ -6,27 +6,25 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
EXECUTE_PROCESS( COMMAND cat /etc/os-release COMMAND grep VERSION_ID COMMAND sed s/VERSION_ID=// COMMAND tr -d '\n' COMMAND sed s/\\x22// COMMAND sed s/\\x22// OUTPUT_VARIABLE L_DEBIAN_OS_VERSION)
SET(DEBIAN_OS_NAME "${L_DEBIAN_OS_NAME}")
SET(DEBIAN_OS_VERSION ${L_DEBIAN_OS_VERSION})
message("Debian OS ${DEBIAN_OS_VERSION} (${DEBIAN_OS_NAME})")
message("[ ] Debian OS ${DEBIAN_OS_VERSION} (${DEBIAN_OS_NAME})")
# check if we're building natively on Android (TERMUX)
EXECUTE_PROCESS( COMMAND uname -o COMMAND tr -d '\n' OUTPUT_VARIABLE OPERATING_SYSTEM)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Android")
message("ANDROID")
set(ANDROID ON)
set(UNIX ON)
set(LINUX ON)
set(OS_TYPE_MOBILE ON)
message("ANDROID build")
message("[*] ANDROID build")
add_definitions(-DANDROID -DDAP_OS_ANDROID)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Win")
message("Win build")
set(OS_TYPE_DESKTOP ON)
endif()
if((CMAKE_BUILD_TYPE STREQUAL "Debug") OR (DAP_DEBUG))
message("Debug build")
message("[!] Debug build")
SET(DAP_DEBUG ON)
else()
message("Release build")
message("[!] Release build")
SET(DAP_RELEASE ON)
endif()
......@@ -42,17 +40,25 @@ if(BUILD_64)
else()
set(ARCH_WIDTH "32")
endif()
message(STATUS "Building for a ${ARCH_WIDTH}-bit system")
message(STATUS "[*] Building for a ${ARCH_WIDTH}-bit system")
if(UNIX)
add_definitions ("-DDAP_OS_UNIX")
if (APPLE)
add_definitions ("-DDAP_OS_DARWIN -DDARWIN")
set(DARWIN ON)
else()
add_definitions ("-DDAP_OS_LINUX")
endif()
add_definitions ("-DDAP_OS_LINUX -DDAP_OS_UNIX")
# add_definitions ("-DDAP_LOG_MT")
if(DAP_DEBUG)
set(_CCOPT "-DDAP_DEBUG -Wall -Wno-unused-local-typedefs -Wno-unused-function -Wno-implicit-fallthrough -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable -pg -g3 -ggdb -fno-eliminate-unused-debug-symbols")
set(_CCOPT "-DDAP_DEBUG -Wall -Wno-deprecated-declarations -Wno-unused-local-typedefs -Wno-unused-function -Wno-implicit-fallthrough -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable -pg -g3 -ggdb -fno-eliminate-unused-debug-symbols")
set(_LOPT "-pg")
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg")
else()
set(_CCOPT "-Wno-unused-local-typedefs -Wno-unused-function -Wno-implicit-fallthrough -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable -O3 -fPIC -fno-ident -ffast-math -ftree-vectorize -fno-asynchronous-unwind-tables -ffunction-sections -Wl,--gc-sections -Wl,--strip-all -std=gnu11")
set(_CCOPT "-Wno-deprecated-declarations -Wno-unused-local-typedefs -Wno-unused-function -Wno-implicit-fallthrough -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable -O3 -fPIC -fno-ident -ffast-math -ftree-vectorize -fno-asynchronous-unwind-tables -ffunction-sections -Wl,--gc-sections -Wl,--strip-all -std=gnu11")
endif()
if (ANDROID)
......@@ -73,7 +79,7 @@ if(UNIX)
endif()
if(WIN32)
message(STATUS "Building for Windows")
message(STATUS "[*] Building for Windows")
add_definitions("-DHAVE_PREAD")
add_definitions("-DHAVE_MMAP")
add_definitions("-DHAVE_STRNDUP")
......@@ -93,10 +99,10 @@ if(WIN32)
add_definitions ("-DDAP_OS_WINDOWS")
if(DAP_DEBUG)
set(_CCOPT "-mconsole -static -Wall -std=gnu11 -Wextra -Wno-unused-local-typedefs -Wno-unused-function -Wno-implicit-fallthrough -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable -g3 -ggdb -fno-eliminate-unused-debug-symbols -pg")
set(_CCOPT "-mconsole -static -Wall -std=gnu11 -Wextra -Wno-deprecated-declarations -Wno-unused-local-typedefs -Wno-unused-function -Wno-implicit-fallthrough -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable -g3 -ggdb -fno-eliminate-unused-debug-symbols -pg")
set(_LOPT "-mconsole -static -pg")
else()
set(_CCOPT "-static -std=gnu11 -Wall -Wextra -Wno-unused-local-typedefs -Wno-unused-function -Wno-implicit-fallthrough -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable -O3 -fno-ident -ffast-math -ftree-vectorize -mfpmath=sse -mmmx -msse2 -fno-asynchronous-unwind-tables -ffunction-sections -Wl,--gc-sections -Wl,--strip-all")
set(_CCOPT "-static -std=gnu11 -Wall -Wextra -Wno-deprecated-declarations -Wno-unused-local-typedefs -Wno-unused-function -Wno-implicit-fallthrough -Wno-unused-variable -Wno-unused-parameter -Wno-unused-but-set-variable -O3 -fno-ident -ffast-math -ftree-vectorize -mfpmath=sse -mmmx -msse2 -fno-asynchronous-unwind-tables -ffunction-sections -Wl,--gc-sections -Wl,--strip-all")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_CCOPT} ")
......
......@@ -28,53 +28,6 @@ if(WIN32)
)
endif()
if(NOT SUBMODULES_NO_BUILD)
# Check whether we're on a 32-bit or 64-bit system
if(CMAKE_SIZEOF_VOID_P EQUAL "8")
set(DEFAULT_BUILD_64 ON)
else()
set(DEFAULT_BUILD_64 OFF)
endif()
option(BUILD_64 "Build for 64-bit? 'OFF' builds for 32-bit." ${DEFAULT_BUILD_64})
if(WIN32)
add_definitions ("-DUNDEBUG")
add_definitions ("-DNDEBUG")
add_definitions ("-DWIN32")
add_definitions ("-D_WINDOWS")
add_definitions ("-D__WINDOWS__")
add_definitions ("-D_CRT_SECURE_NO_WARNINGS")
# if(DAP_RELEASE)
set(_CCOPT "-mwindows -static -Wall -O3 -fno-ident -ffast-math -ftree-vectorize -mfpmath=sse -mmmx -msse2 -fno-asynchronous-unwind-tables -ffunction-sections -Wl,--gc-sections -Wl,--strip-all")
# else()
# set(_CCOPT "-mconsole -static -Wall -pg")
# set(_LOPT "-mconsole -static -pg")
# endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_CCOPT}")
set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} ${_LOPT}")
endif()
if(UNIX)
add_definitions ("-DDAP_OS_LINUX")
if(DAP_RELEASE)
set(_CCOPT "-Wall -O3 -fPIC -fno-pie -no-pie -fno-ident -ffast-math -ftree-vectorize -mfpmath=sse -mmmx -msse2 -fno-asynchronous-unwind-tables -ffunction-sections -Wl,--gc-sections -Wl,--strip-all")
else()
set(_CCOPT "-Wall -pg -fPIC -fno-pie -no-pie")
set(_LOPT "-pg")
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_CCOPT}")
set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} ${_LOPT}")
endif()
endif()
add_library(${PROJECT_NAME} STATIC ${CORE_SRCS} ${CORE_HEADERS})
#This paths will be used by project-dependent project libraries
......@@ -84,10 +37,6 @@ if(WIN32)
include_directories(include/)
endif()
if ( ${CMAKE_SYSTEM_NAME} MATCHES "Linux" )
set(LINUX "Linux")
endif()
if(UNIX)
add_subdirectory(src/unix)
target_link_libraries(${PROJECT_NAME} dap_core_unix rt)
......
......@@ -22,7 +22,7 @@
You should have received a copy of the GNU General Public License
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/
#define _XOPEN_SOURCE 700
//#define _XOPEN_SOURCE 700
#pragma once
......@@ -33,7 +33,9 @@
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#ifdef __MACH__
#include <dispatch/dispatch.h>
#endif
#include "portable_endian.h"
typedef uint8_t byte_t;
......
......@@ -2,18 +2,21 @@ QMAKE_CFLAGS_DEBUG = -std=gnu11
QMAKE_CFLAGS_RELEASE = -std=gnu11
unix {
include(src/unix/unix.pri)
DEFINES += DAP_OS_UNIX
LIBS += -lrt
}
darwin {
include(src/darwin/darwin.pri)
DEFINES += DAP_OS_DARWIN
LIBS -= -lrt
}
win32 {
include(src/win32/win32.pri)
LIBS += -lpsapi
DEFINES += DAP_OS_WINDOWS
}
DEFINES += DAP_LOG_MT
HEADERS += $$PWD/include/dap_common.h \
$$PWD/include/dap_config.h \
$$PWD/include/dap_math_ops.h \
......
......@@ -358,7 +358,9 @@ void _log_it(const char *a_log_tag, enum dap_log_level a_ll, const char *a_fmt,
*/
char *dap_log_get_item(time_t a_start_time, int a_limit)
{
return NULL; // TODO
UNUSED(a_start_time);
UNUSED(a_limit);
return NULL; // TODO
}
/**
......@@ -801,7 +803,7 @@ int exec_silent(const char * a_cmd) {
return -1;
}
#else
return execl(".",a_cmd);
return execl(".","%s",a_cmd,NULL);
#endif
}
......@@ -829,6 +831,11 @@ static void CALLBACK s_win_callback(PVOID a_arg, BOOLEAN a_always_true)
UNUSED(a_always_true);
s_timers[(size_t)a_arg].callback(s_timers[(size_t)a_arg].param);
}
#elif defined __MACH__
static void s_bsd_callback(int a_arg)
{
s_timers[a_arg].callback(s_timers[a_arg].param);
}
#else
static void s_posix_callback(union sigval a_arg)
{
......@@ -856,7 +863,19 @@ void *dap_interval_timer_create(unsigned int a_msec, dap_timer_callback_t a_call
return NULL;
}
EnterCriticalSection(&s_timers_lock);
#elif DAP_OS_UNIX
#elif defined DAP_OS_DARWIN
if (s_timers_count == 0) {
pthread_mutex_init(&s_timers_lock, NULL);
}
pthread_mutex_lock(&s_timers_lock);
dispatch_queue_t l_queue = dispatch_queue_create("tqueue", 0);
dispatch_source_t l_timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, l_queue);
dispatch_source_set_event_handler(l_timer, ^(void){s_bsd_callback(s_timers_count);});
dispatch_time_t start = dispatch_time(DISPATCH_TIME_NOW, a_msec * 1000000);
dispatch_source_set_timer(l_timer, start, a_msec * 1000000, 0);
dispatch_resume(l_timer);
#else
if (s_timers_count == 0) {
pthread_mutex_init(&s_timers_lock, NULL);
}
......@@ -873,8 +892,6 @@ void *dap_interval_timer_create(unsigned int a_msec, dap_timer_callback_t a_call
l_period.it_interval.tv_nsec = l_period.it_value.tv_nsec = (a_msec % 1000) * 1000000;
timer_settime(l_timer, 0, &l_period, NULL);
pthread_mutex_lock(&s_timers_lock);
#else
//DARWIN
#endif
s_timers[s_timers_count].timer = (void *)l_timer;
s_timers[s_timers_count].callback = a_callback;
......@@ -884,8 +901,6 @@ void *dap_interval_timer_create(unsigned int a_msec, dap_timer_callback_t a_call
LeaveCriticalSection(&s_timers_lock);
#elif DAP_OS_UNIX
pthread_mutex_unlock(&s_timers_lock);
#else
//DARWIN
#endif
return (void *)l_timer;
}
......@@ -904,8 +919,6 @@ int dap_interval_timer_delete(void *a_timer)
EnterCriticalSection(&s_timers_lock);
#elif DAP_OS_UNIX
pthread_mutex_lock(&s_timers_lock);
#else
//DARWIN
#endif
int l_timer_idx = s_timer_find(a_timer);
if (l_timer_idx == -1) {
......@@ -926,8 +939,11 @@ int dap_interval_timer_delete(void *a_timer)
if (s_timers_count == 0) {
pthread_mutex_destroy(&s_timers_lock);
}
return timer_delete((timer_t)a_timer);
#else
//DARWIN
#ifdef DAP_OS_DARWIN
dispatch_source_cancel(a_timer);
return 0;
#else
return timer_delete((timer_t)a_timer);
#endif
#endif
}
......@@ -3,3 +3,4 @@ HEADERS += $$PWD/dap_network_monitor.h \
SOURCES += $$PWD/dap_network_monitor.c \
INCLUDEPATH += $$PWD
DEFINES += DAP_OS_LINUX
......@@ -3,27 +3,6 @@ project (dap_crypto)
# fix implicit declaration warnings
add_definitions ("-D_GNU_SOURCE")
if(NOT SUBMODULES_NO_BUILD)
# Check whether we're on a 32-bit or 64-bit system
if(CMAKE_SIZEOF_VOID_P EQUAL "8")
set(DEFAULT_BUILD_64 ON)
else()
set(DEFAULT_BUILD_64 OFF)
endif()
option(BUILD_64 "Build for 64-bit? 'OFF' builds for 32-bit." ${DEFAULT_BUILD_64})
set(_CCOPT "-Wall -O2 -pg -fPIC -fno-pie -no-pie")
set(_LOPT "-pg")
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_CCOPT}")
set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} ${_LOPT}")
if (NOT (TARGET dap_core))
add_subdirectory(libdap)
endif()
endif()
file( GLOB CRYPTO_SRCS
src/*.c
......@@ -37,6 +16,7 @@ file( GLOB CRYPTO_SRCS
src/sha3/*.c
src/msrln/*.c
src/defeo_scheme/*.c
src/newhope/*.c
src/sig_bliss/*.c
src/sig_tesla/*.c
src/sig_picnic/*.c
......@@ -56,6 +36,7 @@ file( GLOB CRYPTO_HEADERS
src/sha3/*.h
src/msrln/*.h
src/defeo_scheme/*.h
src/newhope/*.h
src/sig_bliss/*.h
src/sig_tesla/*.h
src/sig_picnic/*.h
......
......@@ -3,7 +3,7 @@
#include <stddef.h>
#include "dap_enc_key.h"
#include "seed.h"
#include "seed/seed.h"
#ifdef __cplusplus
extern "C" {
......
/*
* Authors:
* Dmitriy A. Gearasimov <naeper@demlabs.net>
* Demlabs Limited https://demlabs.net
* Sources community https://gitlab.demlabs.net/cellframe/cellframe-sdk/dap-sdk
* Copyright (c) 2017-2020
* All rights reserved.
This file is part of DAP SDK the open source project
DAP SDK is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DAP is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "newhope/newhope_cpakem.h"
#include "dap_enc_key.h"
///========================================================================
typedef enum{
NEWHOPE_TOY = 0, NEWHOPE_1024
}DAP_NEWHOPE_SIGN_SECURITY;
typedef struct {
DAP_NEWHOPE_SIGN_SECURITY kind; /* the kind of ringct20 */
unsigned char *data;
}newhope_public_key_t;
typedef struct {
DAP_NEWHOPE_SIGN_SECURITY kind; // the kind of Dilithium (i.e. *this* choice of parameters)
} newhope_param_t;
///==========================================================================================
typedef struct {
DAP_NEWHOPE_SIGN_SECURITY kind; /* the kind of ringct20 */
unsigned char *data;
} newhope_private_key_t;
typedef struct {
DAP_NEWHOPE_SIGN_SECURITY kind; /* the kind of ringct20 */
unsigned char *sig_data;
unsigned long long sig_len;
} newhope_signature_t;
void dap_enc_newhope_pke_set_type(DAP_NEWHOPE_SIGN_SECURITY type);
void dap_enc_newhope_kem_key_new(struct dap_enc_key *key);
void dap_enc_newhope_kem_key_new_generate(struct dap_enc_key * key, const void *kex_buf,
size_t kex_size, const void * seed, size_t seed_size,
size_t key_size);
size_t dap_enc_newhope_pbk_enc(struct dap_enc_key * a_key, const void * a_pub,
size_t a_pub_size, void ** b_pub);
size_t dap_enc_newhope_prk_dec(struct dap_enc_key * a_key, const void *a_priv,
size_t b_pub_size, unsigned char *b_pub);
void dap_enc_newhope_kem_key_delete(struct dap_enc_key * key);
//size_t dap_enc_newhope_calc_signature_unserialized_size(void);
//static inline size_t dap_enc_newhope_calc_signagture_size(newhope_signature_t* a_sign)
//{
// return sizeof(size_t) + sizeof(newhope_kind_t) + a_sign->sig_len + sizeof(unsigned long long);
//}
//uint8_t* dap_enc_newhope_write_signature(newhope_signature_t* a_sign, size_t *a_sign_out);
//newhope_signature_t* dap_enc_newhope_read_signature(uint8_t *a_buf, size_t a_buflen);
//uint8_t* dap_enc_newhope_write_private_key(const newhope_private_key_t* a_private_key, size_t *a_buflen_out);
//uint8_t* dap_enc_newhope_write_public_key(const newhope_public_key_t* a_public_key, size_t *a_buflen_out);
//newhope_private_key_t* dap_enc_newhope_read_private_key(const uint8_t *a_buf, size_t a_buflen);
//newhope_public_key_t* dap_enc_newhope_read_public_key(const uint8_t *a_buf, size_t a_buflen);
......@@ -13,6 +13,7 @@ include (src/sig_tesla/sig_tesla.pri)
include (src/sig_dilithium/sig_dilithium.pri)
include (src/ringct20/ringct20.pri)
include (src/seed/seed.pri)
include (src/newhope/newhope.pri)
DEFINES += KeccakP1600timesN_excluded
......@@ -33,6 +34,7 @@ HEADERS += $$PWD/include/dap_enc.h \
$$PWD/include/dap_enc_ringct20.h \
$$PWD/include/dap_enc_salsa2012.h \
$$PWD/include/dap_enc_SEED.h \
$$PWD/include/dap_enc_newhope.h \
$$PWD/include/dap_crypto_common.h \
$$PWD/include/dap_cert.h \
$$PWD/include/dap_cert_file.h \
......@@ -70,6 +72,7 @@ SOURCES += $$PWD/src/dap_enc.c \
$$PWD/src/dap_hash_fusion.c \
$$PWD/src/dap_hash_keccak.c \
$$PWD/src/dap_enc_SEED.c \
$$PWD/src/dap_enc_newhope.c \
$$PWD/src/XKCP/lib/high/Keccak/FIPS202/SimpleFIPS202.c \
$$PWD/src/XKCP/lib/high/Keccak/SP800-185/SP800-185.c \
$$PWD/src/XKCP/lib/high/Keccak/SP800-185/SP800-185.inc
......
......@@ -6,7 +6,11 @@
#include <stdio.h>
#include <memory.h>
#ifdef __MACH__
#include <sys/malloc.h>
#else
#include <malloc.h>
#endif
#include <stdlib.h>
#include "28147_14.h"
......
......@@ -36,7 +36,7 @@
#include "dap_enc_bliss.h"
#include "dap_enc_tesla.h"
#include "dap_enc_dilithium.h"
//#include "dap_enc_newhope.h"
#include "dap_enc_newhope.h"
#include "dap_enc_ringct20.h"
......@@ -236,24 +236,24 @@ struct dap_enc_key_callbacks{
.sign_get = NULL,
.sign_verify = NULL
},
// [DAP_ENC_KEY_TYPE_RLWE_NEWHOPE_CPA_KEM]={
// .name = "NEWHOPE_CPA_KEM",
// .enc = NULL,
// .dec = NULL,
// .enc_na = NULL,
// .dec_na = NULL,
// .gen_key_public = NULL,
// .gen_key_public_size = NULL,
// .gen_bob_shared_key = dap_enc_newhope_pbk_enc,
// .gen_alice_shared_key = dap_enc_newhope_prk_dec,
// .new_callback = dap_enc_newhope_kem_key_new,
// .delete_callback = dap_enc_newhope_kem_key_delete,
// .new_generate_callback = dap_enc_newhope_kem_key_new_generate,
// .enc_out_size = NULL,
// .dec_out_size = NULL,
// .sign_get = NULL,
// .sign_verify = NULL
// },
[DAP_ENC_KEY_TYPE_RLWE_NEWHOPE_CPA_KEM]={
.name = "NEWHOPE_CPA_KEM",
.enc = NULL,
.dec = NULL,
.enc_na = NULL,
.dec_na = NULL,
.gen_key_public = NULL,
.gen_key_public_size = NULL,
.gen_bob_shared_key = dap_enc_newhope_pbk_enc,
.gen_alice_shared_key = dap_enc_newhope_prk_dec,
.new_callback = dap_enc_newhope_kem_key_new,
.delete_callback = dap_enc_newhope_kem_key_delete,
.new_generate_callback = dap_enc_newhope_kem_key_new_generate,
.enc_out_size = NULL,
.dec_out_size = NULL,
.sign_get = NULL,
.sign_verify = NULL
},
//------Signatures---------------------------
[DAP_ENC_KEY_TYPE_SIG_PICNIC]={
.name = "PICNIC",
......
/*
* Authors:
* Dmitriy A. Gearasimov <naeper@demlabs.net>
* Demlabs Limited https://demlabs.net
* Sources community https://gitlab.demlabs.net/cellframe/cellframe-sdk/dap-sdk
* Copyright (c) 2017-2020
* All rights reserved.
This file is part of DAP SDK the open source project
DAP SDK is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
DAP is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with any DAP based project. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <inttypes.h>
#include "dap_enc_newhope.h"
#include "dap_common.h"
#include "rand/dap_rand.h"
#include "newhope/newhope_cpapke.h"
#include "newhope/newhope_params.h"
#define LOG_TAG "dap_enc_newhope_pke"
DAP_NEWHOPE_SIGN_SECURITY _newhope_type = NEWHOPE_1024; // by default
void dap_enc_newhope_pke_set_type(DAP_NEWHOPE_SIGN_SECURITY type)
{
_newhope_type = type;
}
void dap_enc_newhope_kem_key_new(struct dap_enc_key *key) {
key->type = DAP_ENC_KEY_TYPE_RLWE_NEWHOPE_CPA_KEM;
key->enc = NULL;
key->enc_na = NULL;
key->dec_na = NULL;
key->gen_bob_shared_key= dap_enc_newhope_pbk_enc;
key->gen_alice_shared_key = dap_enc_newhope_prk_dec;
key->priv_key_data = NULL;
key->pub_key_data = NULL;
}
void dap_enc_newhope_kem_key_new_generate(struct dap_enc_key * a_key, const void *kex_buf,
size_t kex_size, const void * seed, size_t seed_size,
size_t key_size)
{
UNUSED(kex_buf);
UNUSED(key_size);
UNUSED(seed);
DAP_NEWHOPE_SIGN_SECURITY newhope_type = NEWHOPE_1024;
dap_enc_newhope_pke_set_type(newhope_type);
a_key->priv_key_data_size = sizeof(newhope_private_key_t);
a_key->pub_key_data_size = sizeof(newhope_public_key_t);
a_key->priv_key_data = DAP_NEW_SIZE(uint8_t, a_key->priv_key_data_size);
a_key->pub_key_data = DAP_NEW_SIZE(uint8_t, a_key->pub_key_data_size);
newhope_private_key_t *sk = (newhope_private_key_t *)a_key->priv_key_data;
newhope_public_key_t *pk = (newhope_public_key_t *)a_key->pub_key_data;
sk->kind = newhope_type;
sk->data = DAP_NEW_SIZE(uint8_t, NEWHOPE_CPAPKE_SECRETKEYBYTES);
pk->kind = newhope_type;
pk->data = DAP_NEW_SIZE(uint8_t, NEWHOPE_CPAPKE_PUBLICKEYBYTES);
cpapke_keypair(pk->data, sk->data);
return;
}
size_t dap_enc_newhope_pbk_enc(struct dap_enc_key * a_key, const void * a_pub,
size_t a_pub_size, void ** a_sendb)
{
if(a_pub_size != sizeof (newhope_public_key_t))
{
log_it(L_ERROR, "newhope wrong a_pub_size");
return 0;
}
newhope_public_key_t *pk = (newhope_public_key_t*)a_pub;
*a_sendb = DAP_NEW_SIZE(uint8_t, NEWHOPE_CPAKEM_CIPHERTEXTBYTES);
//Bob derives a secret key and creates a response
uint8_t key_b[NEWHOPE_SYMBYTES];
crypto_kem_enc(*a_sendb, key_b, pk->data);
//Save Bob shared key
a_key->priv_key_data_size = NEWHOPE_SYMBYTES;
a_key->priv_key_data = DAP_NEW_SIZE(uint8_t, a_key->priv_key_data_size);
a_key->pub_key_data_size = sizeof(newhope_public_key_t);
a_key->pub_key_data = DAP_NEW_SIZE(uint8_t, a_key->pub_key_data_size);
newhope_public_key_t *cur_pk = (newhope_public_key_t*)a_key->pub_key_data;
cur_pk->data = NULL;
cur_pk->kind = pk->kind;
memcpy(a_key->priv_key_data, key_b, a_key->priv_key_data_size);
return NEWHOPE_CPAKEM_CIPHERTEXTBYTES;
}
size_t dap_enc_newhope_prk_dec(struct dap_enc_key * a_key, const void *a_priv,
size_t a_sendb_size, unsigned char *a_sendb)
{
if(a_sendb_size != NEWHOPE_CPAKEM_CIPHERTEXTBYTES)
{
log_it(L_ERROR, "newhope wrong size of ciphertext (Bob send");
return 0;
}
newhope_private_key_t *sk = a_key->priv_key_data;
uint8_t key_a[NEWHOPE_SYMBYTES];
uint8_t sendb[NEWHOPE_CPAKEM_CIPHERTEXTBYTES];
memcpy(sendb, a_sendb, NEWHOPE_CPAKEM_CIPHERTEXTBYTES);
crypto_kem_dec(key_a, sendb, sk->data);
DAP_DEL_Z(sk->data);
a_key->priv_key_data_size = NEWHOPE_SYMBYTES;
a_key->priv_key_data = DAP_NEW_SIZE(uint8_t,a_key->priv_key_data_size);
memcpy(a_key->priv_key_data, key_a, a_key->priv_key_data_size);
return NEWHOPE_SYMBYTES;//return (newhope_crypto_sign_open( (unsigned char *) msg, msg_size, (newhope_signature_t *) signature, a_key->pub_key_data));
}
void dap_enc_newhope_kem_key_delete(struct dap_enc_key * a_key)
{
newhope_private_key_t *sk = (newhope_private_key_t *)a_key->priv_key_data;
newhope_public_key_t *pk = (newhope_public_key_t *)a_key->pub_key_data;
if(sk != NULL && a_key->priv_key_data_size != NEWHOPE_SYMBYTES)
DAP_DEL_Z(sk->data);
if(pk != NULL)
DAP_DEL_Z(pk->data);
}
......@@ -32,10 +32,12 @@
#define NBYTES_TO_NWORDS(nbytes) (((nbytes)+sizeof(digit_t)-1)/sizeof(digit_t)) // Conversion macro from number of bytes to number of computer words
// Macro to avoid compiler warnings when detecting unreferenced parameters
#ifndef UNREFERENCED_PARAMETER
#define UNREFERENCED_PARAMETER(PAR) ((void)(PAR))
#endif
#define PASSED 0
#define FAILED 1
#define PASSED_DEFEO 0
#define FAILED_DEFEO 1
/********************** Constant-time unsigned comparisons ***********************/
......