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 (7)
Showing with 946 additions and 867 deletions
......@@ -100,7 +100,7 @@ endif()
if(ANDROID)
add_subdirectory(src/android)
target_link_libraries(${PROJECT_NAME} dap_core_android)
target_link_libraries(${PROJECT_NAME} dap_core_android rt)
endif()
if (WIN32)
......
......@@ -827,7 +827,7 @@ static int s_timer_find(void *a_timer)
static void CALLBACK s_win_callback(PVOID a_arg, BOOLEAN a_always_true)
{
UNUSED(a_always_true);
s_timers[(int)a_arg].callback(s_timers[(int)a_arg].param);
s_timers[(size_t)a_arg].callback(s_timers[(size_t)a_arg].param);
}
#else
static void s_posix_callback(union sigval a_arg)
......@@ -847,16 +847,16 @@ void *dap_interval_timer_create(unsigned int a_msec, dap_timer_callback_t a_call
if (s_timers_count == DAP_INTERVAL_TIMERS_MAX) {
return NULL;
}
#ifdef _WIN32
#ifdef WIN32
if (s_timers_count == 0) {
InitializeCriticalSection(&s_timers_lock);
}
HANDLE l_timer;
if (!CreateTimerQueueTimer(&l_timer, NULL, (WAITORTIMERCALLBACK)s_win_callback, (PVOID)s_timers_count, a_msec, a_msec, 0)) {
if (!CreateTimerQueueTimer(&l_timer, NULL, (WAITORTIMERCALLBACK)s_win_callback, (PVOID)(size_t)s_timers_count, a_msec, a_msec, 0)) {
return NULL;
}
EnterCriticalSection(&s_timers_lock);
#else
#elif DAP_OS_UNIX
if (s_timers_count == 0) {
pthread_mutex_init(&s_timers_lock, NULL);
}
......@@ -873,6 +873,8 @@ 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;
......@@ -880,8 +882,10 @@ void *dap_interval_timer_create(unsigned int a_msec, dap_timer_callback_t a_call
s_timers_count++;
#ifdef _WIN32
LeaveCriticalSection(&s_timers_lock);
#else
#elif DAP_OS_UNIX
pthread_mutex_unlock(&s_timers_lock);
#else
//DARWIN
#endif
return (void *)l_timer;
}
......@@ -898,8 +902,10 @@ int dap_interval_timer_delete(void *a_timer)
}
#ifdef _WIN32
EnterCriticalSection(&s_timers_lock);
#else
#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) {
......@@ -915,10 +921,13 @@ int dap_interval_timer_delete(void *a_timer)
DeleteCriticalSection(&s_timers_lock);
}
return !DeleteTimerQueueTimer(NULL, (HANDLE)a_timer, NULL);
#else
#elif DAP_OS_UNIX
pthread_mutex_unlock(&s_timers_lock);
if (s_timers_count == 0) {
pthread_mutex_destroy(&s_timers_lock);
}
return timer_delete((timer_t)a_timer);
#else
//DARWIN
#endif
}
......@@ -92,7 +92,7 @@ endif()
add_library(${PROJECT_NAME} STATIC ${CRYPTO_SRCS} ${XKCP_SRCS} ${XKCP_SRCS2} ${CRYPTO_HEADERS} )
target_include_directories(dap_crypto PRIVATE src/rand src/iaes src/oaes src/sha3 src/msrln src/defeo_scheme src/sig_bliss src/sig_tesla src/sig_picnic src/sig_dilithium src include)
target_include_directories(dap_crypto PRIVATE src/seed src/rand src/iaes src/oaes src/sha3 src/msrln src/defeo_scheme src/sig_bliss src/sig_tesla src/sig_picnic src/sig_dilithium src include)
target_include_directories(dap_crypto INTERFACE src/ src/sha3 include/)
target_include_directories(dap_crypto PUBLIC
......
......@@ -3,7 +3,7 @@
#include <stddef.h>
#include "dap_enc_key.h"
#include "seed/seed.h"
#include "seed.h"
#ifdef __cplusplus
extern "C" {
......
......@@ -12,6 +12,7 @@ include (src/sig_picnic/sig_picnic.pri)
include (src/sig_tesla/sig_tesla.pri)
include (src/sig_dilithium/sig_dilithium.pri)
include (src/ringct20/ringct20.pri)
include (src/seed/seed.pri)
DEFINES += KeccakP1600timesN_excluded
......@@ -31,6 +32,7 @@ HEADERS += $$PWD/include/dap_enc.h \
$$PWD/include/dap_enc_dilithium.h \
$$PWD/include/dap_enc_ringct20.h \
$$PWD/include/dap_enc_salsa2012.h \
$$PWD/include/dap_enc_SEED.h \
$$PWD/include/dap_crypto_common.h \
$$PWD/include/dap_cert.h \
$$PWD/include/dap_cert_file.h \
......@@ -67,6 +69,7 @@ SOURCES += $$PWD/src/dap_enc.c \
$$PWD/src/dap_hash.c \
$$PWD/src/dap_hash_fusion.c \
$$PWD/src/dap_hash_keccak.c \
$$PWD/src/dap_enc_SEED.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
......
#include "blowfish.h"
#include "bf_local.h"
#include "memory.h"
/*
* Blowfish as implemented from 'Blowfish: Springer-Verlag paper' (From
* LECTURE NOTES IN COMPUTER SCIENCE 809, FAST SOFTWARE ENCRYPTION, CAMBRIDGE
* SECURITY WORKSHOP, CAMBRIDGE, U.K., DECEMBER 9-11, 1993)
*/
#if (BF_ROUNDS != 16) && (BF_ROUNDS != 20)
# error If you set BF_ROUNDS to some value other than 16 or 20, you will have \
to modify the code.
#endif
//#include<stdio.h>
void BF_encrypt(BF_LONG *data, const BF_KEY *key)
{
register BF_LONG l, r;
register const BF_LONG *p, *s;
p = key->P;
s = &(key->S[0]);
l = data[0];
r = data[1];
l ^= p[0];
BF_ENC(r, l, s, p[1]);
BF_ENC(l, r, s, p[2]);
BF_ENC(r, l, s, p[3]);
BF_ENC(l, r, s, p[4]);
BF_ENC(r, l, s, p[5]);
BF_ENC(l, r, s, p[6]);
BF_ENC(r, l, s, p[7]);
BF_ENC(l, r, s, p[8]);
BF_ENC(r, l, s, p[9]);
BF_ENC(l, r, s, p[10]);
BF_ENC(r, l, s, p[11]);
BF_ENC(l, r, s, p[12]);
BF_ENC(r, l, s, p[13]);
BF_ENC(l, r, s, p[14]);
BF_ENC(r, l, s, p[15]);
BF_ENC(l, r, s, p[16]);
# if BF_ROUNDS == 20
BF_ENC(r, l, s, p[17]);
BF_ENC(l, r, s, p[18]);
BF_ENC(r, l, s, p[19]);
BF_ENC(l, r, s, p[20]);
# endif
r ^= p[BF_ROUNDS + 1];
data[1] = l & 0xffffffffU;
data[0] = r & 0xffffffffU;
}
void BF_decrypt(BF_LONG *data, const BF_KEY *key)
{
register BF_LONG l, r;
register const BF_LONG *p, *s;
p = key->P;
s = &(key->S[0]);
l = data[0];
r = data[1];
l ^= p[BF_ROUNDS + 1];
# if BF_ROUNDS == 20
BF_ENC(r, l, s, p[20]);
BF_ENC(l, r, s, p[19]);
BF_ENC(r, l, s, p[18]);
BF_ENC(l, r, s, p[17]);
# endif
BF_ENC(r, l, s, p[16]);
BF_ENC(l, r, s, p[15]);
BF_ENC(r, l, s, p[14]);
BF_ENC(l, r, s, p[13]);
BF_ENC(r, l, s, p[12]);
BF_ENC(l, r, s, p[11]);
BF_ENC(r, l, s, p[10]);
BF_ENC(l, r, s, p[9]);
BF_ENC(r, l, s, p[8]);
BF_ENC(l, r, s, p[7]);
BF_ENC(r, l, s, p[6]);
BF_ENC(l, r, s, p[5]);
BF_ENC(r, l, s, p[4]);
BF_ENC(l, r, s, p[3]);
BF_ENC(r, l, s, p[2]);
BF_ENC(l, r, s, p[1]);
r ^= p[0];
data[1] = l & 0xffffffffU;
data[0] = r & 0xffffffffU;
}
void BF_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
const BF_KEY *schedule, unsigned char *ivec, int encrypt)
{
register BF_LONG tin0, tin1;
register BF_LONG tout0, tout1, xor0, xor1;
register long l = length;
BF_LONG tin[2];
if (encrypt) {
n2l(ivec, tout0);
n2l(ivec, tout1);
ivec -= 8;
for (l -= 8; l >= 0; l -= 8) {
n2l(in, tin0);
n2l(in, tin1);
tin0 ^= tout0;
tin1 ^= tout1;
tin[0] = tin0;
tin[1] = tin1;
BF_encrypt(tin, schedule);
tout0 = tin[0];
tout1 = tin[1];
l2n(tout0, out);
l2n(tout1, out);
}
if (1||l != -8) {
unsigned char tmpin[16];
unsigned char *ptmpin = tmpin;
memcpy(tmpin, in, l + 8);
memcpy(tmpin + l + 8, &length, 4);
int pad_length = (8-(l + 8 + 4 + 1)%8)%8;
for(int i = 0; i < pad_length; ++i)
{
tmpin[l+8+4+i]=16;//prng better
}
tmpin[l+8+4+pad_length]=pad_length;
// for(int i = 0; i < l + 8 + 4 +1 +pad_length; ++i)
// {
// printf("%.2x ", tmpin[i]);
// }
// printf("\n");fflush(stdout);
n2l(ptmpin, tin0);
n2l(ptmpin, tin1);
tin0 ^= tout0;
tin1 ^= tout1;
tin[0] = tin0;
tin[1] = tin1;
BF_encrypt(tin, schedule);
tout0 = tin[0];
tout1 = tin[1];
l2n(tout0, out);
l2n(tout1, out);
if(l+8+4+pad_length + 1 == 16)
{
n2l(ptmpin, tin0);
n2l(ptmpin, tin1);
tin0 ^= tout0;
tin1 ^= tout1;
tin[0] = tin0;
tin[1] = tin1;
BF_encrypt(tin, schedule);
tout0 = tin[0];
tout1 = tin[1];
l2n(tout0, out);
l2n(tout1, out);
}
// n2ln(in, tin0, tin1, l + 8);
// tin0 ^= tout0;
// tin1 ^= tout1;
// tin[0] = tin0;
// tin[1] = tin1;
// BF_encrypt(tin, schedule);
// tout0 = tin[0];
// tout1 = tin[1];
// l2n(tout0, out);
// l2n(tout1, out);
}
l2n(tout0, ivec);
l2n(tout1, ivec);
} else {
n2l(ivec, xor0);
n2l(ivec, xor1);
ivec -= 8;
for (l -= 8; l >= 0; l -= 8) {
n2l(in, tin0);
n2l(in, tin1);
tin[0] = tin0;
tin[1] = tin1;
BF_decrypt(tin, schedule);
tout0 = tin[0] ^ xor0;
tout1 = tin[1] ^ xor1;
l2n(tout0, out);
l2n(tout1, out);
xor0 = tin0;
xor1 = tin1;
}
if (l != -8) {
n2l(in, tin0);
n2l(in, tin1);
tin[0] = tin0;
tin[1] = tin1;
BF_decrypt(tin, schedule);
tout0 = tin[0] ^ xor0;
tout1 = tin[1] ^ xor1;
l2nn(tout0, tout1, out, l + 8);
xor0 = tin0;
xor1 = tin1;
}
l2n(xor0, ivec);
l2n(xor1, ivec);
}
tin0 = tin1 = tout0 = tout1 = xor0 = xor1 = 0;
tin[0] = tin[1] = 0;
}
#include "blowfish.h"
#include "bf_local.h"
/*
* The input and output encrypted as though 64bit ofb mode is being used.
* The extra state information to record how much of the 64bit block we have
* used is contained in *num;
*/
void BF_ofb64_encrypt(const unsigned char *in, unsigned char *out,
long length, const BF_KEY *schedule,
unsigned char *ivec, int *num)
{
register BF_LONG v0, v1, t;
register int n = *num;
register long l = length;
unsigned char d[8];
register char *dp;
BF_LONG ti[2];
unsigned char *iv;
int save = 0;
iv = (unsigned char *)ivec;
n2l(iv, v0);
n2l(iv, v1);
ti[0] = v0;
ti[1] = v1;
dp = (char *)d;
l2n(v0, dp);
l2n(v1, dp);
while (l--) {
if (n == 0) {
BF_encrypt((BF_LONG *)ti, schedule);
dp = (char *)d;
t = ti[0];
l2n(t, dp);
t = ti[1];
l2n(t, dp);
save++;
}
*(out++) = *(in++) ^ d[n];
n = (n + 1) & 0x07;
}
if (save) {
v0 = ti[0];
v1 = ti[1];
iv = (unsigned char *)ivec;
l2n(v0, iv);
l2n(v1, iv);
}
t = v0 = v1 = ti[0] = ti[1] = 0;
*num = n;
}
#include <stdio.h>
#include <string.h>
#include "blowfish.h"
#include "bf_local.h"
#include "bf_pi.h"
void BF_set_key(BF_KEY *key, int len, const unsigned char *data)
{
int i;
BF_LONG *p, ri, in[2];
const unsigned char *d, *end;
memcpy(key, &bf_init, sizeof(BF_KEY));
p = key->P;
if (len > ((BF_ROUNDS + 2) * 4))
len = (BF_ROUNDS + 2) * 4;
d = data;
end = &(data[len]);
for (i = 0; i < (BF_ROUNDS + 2); i++) {
ri = *(d++);
if (d >= end)
d = data;
ri <<= 8;
ri |= *(d++);
if (d >= end)
d = data;
ri <<= 8;
ri |= *(d++);
if (d >= end)
d = data;
ri <<= 8;
ri |= *(d++);
if (d >= end)
d = data;
p[i] ^= ri;
}
in[0] = 0L;
in[1] = 0L;
for (i = 0; i < (BF_ROUNDS + 2); i += 2) {
BF_encrypt(in, key);
p[i] = in[0];
p[i + 1] = in[1];
}
p = key->S;
for (i = 0; i < 4 * 256; i += 2) {
BF_encrypt(in, key);
p[i] = in[0];
p[i + 1] = in[1];
}
}
//max using key size = (BF_ROUNDS + 2)*4 bytes = 72 bytes
#ifndef BLOWFISH_H
# define BLOWFISH_H
#define BLOWFISH_H
#include "inttypes.h"
# define BF_BLOCK 8
# define BF_ENCRYPT 1
......@@ -23,11 +24,10 @@ typedef struct bf_key_st {
BF_LONG S[4 * 256];
} BF_KEY;
# ifdef __cplusplus
extern "C" {
# endif
# define BF_BLOCK 8
void BF_set_key(BF_KEY *key, int len,
const unsigned char *data);
......@@ -54,5 +54,5 @@ const char *BF_options(void);
# ifdef __cplusplus
}
# endif
# endif
#endif
INCLUDEPATH += $$PWD
HEADERS += $$PWD/blowfish.h \
$$PWD/bf_local.h \
$$PWD/bf_pi.h
$$PWD/bf_local.h
SOURCES += $$PWD/bf_cfb64.c \
$$PWD/bf_ecb.c \
$$PWD/bf_enc.c \
$$PWD/bf_ofb64.c \
$$PWD/bf_skey.c
SOURCES += $$PWD/blowfish.c
......@@ -5,13 +5,11 @@ HEADERS += $$PWD/ntt.h \
$$PWD/poly.h \
$$PWD/reduce.h \
$$PWD/ring.h \
$$PWD/ringct20_params.h \
$$PWD/verify.inc
$$PWD/ringct20_params.h
SOURCES += $$PWD/ntt.c \
$$PWD/poly.c \
$$PWD/precomp.c \
$$PWD/reduce.c \
$$PWD/ring.c \
$$PWD/ringct20_params.c \
$$PWD/verify.c
$$PWD/ringct20_params.c
INCLUDEPATH += $$PWD
HEADERS += $$PWD/modes.h $$PWD/seed.h $$PWD/seed_local.h
SOURCES += $$PWD/seed.c $$PWD/ofb128.c $$PWD/seed_ofb.c
\ No newline at end of file
......@@ -2,7 +2,6 @@ HEADERS += $$PWD/tesla_params.h
SOURCES += $$PWD/consts.c \
$$PWD/poly.c \
$$PWD/sample.c \
$$PWD/sign.c \
$$PWD/tesla_params.c
......