From d0f94f65f9a0e7da4dc2e82017409fcccf96a42c Mon Sep 17 00:00:00 2001
From: Dmitriy Gerasimov <dm@cifercom.com>
Date: Thu, 11 Jan 2018 12:03:26 +0700
Subject: [PATCH] [+] Few missed general files from Monero [+] NewHope
 alghorythm declarations [*] Renames, build fixes [+] SSE2, SSE3, SSE4 and
 NEON compile flags detection

---
 CMakeLists.txt                        |   6 +-
 client/CMakeLists.txt                 |  11 +-
 client/dap_client.c                   |   6 +-
 client/dap_client.h                   |   5 +-
 client/dap_client_remote.c            |  16 +-
 client/dap_client_remote.h            |  18 +-
 core/CMakeLists.txt                   |   4 +-
 core/dap_common.h                     |   9 +-
 core/dap_config.c                     |  91 +++++
 core/dap_config.h                     |  39 ++
 crypt/CMakeLists.txt                  |   8 +-
 crypt/dap_enc_aes.c                   |   7 +-
 crypt/dap_enc_aes.h                   |   4 +-
 crypt/dap_enc_key.c                   | 122 +++---
 crypt/dap_enc_key.h                   |  41 +-
 crypt/dap_enc_newhope.c               |  92 +++++
 crypt/dap_enc_newhope.h               |  19 +
 crypt/monero_crypto/CMakeLists.txt    | 309 +++++++++++++-
 crypt/monero_crypto/common/int-util.h | 249 ++++++++++++
 crypt/monero_crypto/common/memwipe.c  | 106 +++++
 crypt/monero_crypto/common/memwipe.h  |  36 ++
 crypt/monero_crypto/crypto.cpp        | 564 --------------------------
 crypt/monero_crypto/crypto.h          | 289 -------------
 crypt/monero_crypto/warnings.h        |  33 ++
 http/CMakeLists.txt                   |   6 +-
 http/dap_http_client.c                |  34 +-
 http/dap_http_client.h                |  31 +-
 27 files changed, 1170 insertions(+), 985 deletions(-)
 create mode 100644 core/dap_config.c
 create mode 100644 core/dap_config.h
 create mode 100644 crypt/dap_enc_newhope.c
 create mode 100644 crypt/dap_enc_newhope.h
 create mode 100644 crypt/monero_crypto/common/int-util.h
 create mode 100644 crypt/monero_crypto/common/memwipe.c
 create mode 100644 crypt/monero_crypto/common/memwipe.h
 delete mode 100644 crypt/monero_crypto/crypto.cpp
 delete mode 100644 crypt/monero_crypto/crypto.h
 create mode 100644 crypt/monero_crypto/warnings.h

diff --git a/CMakeLists.txt b/CMakeLists.txt
index b1bce72dd7..f6183dacb0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,10 +3,6 @@ cmake_minimum_required(VERSION 2.8)
 
 add_subdirectory(core)
 add_subdirectory(crypt)
-add_subdirectory(client)
 add_subdirectory(http)
+add_subdirectory(client)
 
-include_directories("${INCLUDE_DIRECTORIES} ${dapcrypt_INCLUDE_DIRS}")
-include_directories("${INCLUDE_DIRECTORIES} ${dapcore_INCLUDE_DIRS}")
-include_directories("${INCLUDE_DIRECTORIES} ${daphttp_INCLUDE_DIRS}")
-include_directories("${INCLUDE_DIRECTORIES} ${dapclient_INCLUDE_DIRS}")
diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt
index 92e4c3b1dd..c8a3bee84e 100644
--- a/client/CMakeLists.txt
+++ b/client/CMakeLists.txt
@@ -1,10 +1,17 @@
 cmake_minimum_required(VERSION 2.8)
-project (dapclient)
+project (dap_client)
   
-set(CLIENT_SRCS dap_client.c dap_client_internal.c)
+set(CLIENT_SRCS dap_client.c dap_client_internal.c dap_client_remote.c)
  
 add_library(${PROJECT_NAME} STATIC ${CLIENT_SRCS})
 
+include_directories("${dap_core_INCLUDE_DIRS}")
+include_directories("${dap_crypto_INCLUDE_DIRS}")
+include_directories("${dap_http_INCLUDE_DIRS}")
+add_definitions ("${dap_core_DEFINITIONS}")
+add_definitions ("${dap_crypto_DEFINITIONS}")
+add_definitions ("${dap_http_DEFINITIONS}")
+
 set(${PROJECT_NAME}_DEFINITIONS CACHE INTERNAL "${PROJECT_NAME}: Definitions" FORCE)
 
 set(${PROJECT_NAME}_INCLUDE_DIRS ${PROJECT_SOURCE_DIR} CACHE INTERNAL "${PROJECT_NAME}: Include Directories" FORCE)
diff --git a/client/dap_client.c b/client/dap_client.c
index ab6eb6f219..abf594bbe9 100644
--- a/client/dap_client.c
+++ b/client/dap_client.c
@@ -1,7 +1,8 @@
 #include <stddef.h>
-#include "common.h"
+#include "dap_common.h"
 
 #include "dap_client.h"
+#include "dap_client_remote.h"
 #include "dap_client_internal.h"
 
 #define LOG_TAG "dap_client"
@@ -12,6 +13,7 @@
  */
 int dap_client_init()
 {
+    dap_client_remote();
     log_it(L_INFO, "Init DAP client module");
     return 0;
 }
@@ -96,7 +98,7 @@ void dap_client_set_credentials(dap_client_t * a_client,const char* a_user, cons
  * @param a_client_error
  * @return
  */
-const char * dap_client_error_str(sap_client_error_t a_client_error)
+const char * dap_client_error_str(dap_client_error_t a_client_error)
 {
     switch(a_client_error){
         case DAP_CLIENT_ERROR_ENC_NO_KEY: return "ENC_NO_KEY";
diff --git a/client/dap_client.h b/client/dap_client.h
index 14206d30b0..1d706c3fbf 100644
--- a/client/dap_client.h
+++ b/client/dap_client.h
@@ -1,7 +1,8 @@
 #ifndef _DAP_CLIENT_H_
 #define _DAP_CLIENT_H_
-#include <stdint.h>
 
+#include <stdint.h>
+#include <stddef.h>
 
 /**
  * @brief The dap_client_stage enum. Top level of client's state machine
@@ -35,7 +36,7 @@ typedef enum dap_client_error {
 /**
  * @brief The dap_client struct
  */
-typedef struct sap_client{
+typedef struct dap_client{
     void * _internal;
     void * _inheritor;
 } dap_client_t;
diff --git a/client/dap_client_remote.c b/client/dap_client_remote.c
index d730d16407..cc44acb862 100644
--- a/client/dap_client_remote.c
+++ b/client/dap_client_remote.c
@@ -24,11 +24,13 @@
 #include <stdarg.h>
 #include <unistd.h>
 #include <string.h>
-#include "common.h"
+
+
+#include "dap_common.h"
 #include "dap_loop.h"
-#include "dap_client.h"
+#include "dap_client_remote.h"
 #include <ev.h>
-#define LOG_TAG "client"
+#define LOG_TAG "dap_client_remote"
 
 
 /**
@@ -37,7 +39,7 @@
  */
 int dap_client_init()
 {
-    log_it(NOTICE,"Initialized socket client module");
+    log_it(L_NOTICE,"Initialized socket client module");
     return 0;
 }
 
@@ -50,15 +52,15 @@ void dap_client_deinit()
 }
 
 /**
- * @brief safe_client_create Create new client and add it to the list
+ * @brief dap_client_remote_create Create new client and add it to the list
  * @param sh Server instance
  * @param s Client's socket
  * @return Pointer to the new list's node
  */
-dap_client_t * dap_client_create(dap_server_t * sh, int s, ev_io* w_client)
+dap_client_remote_t * dap_client_remote_create(dap_server_t * sh, int s, ev_io* w_client)
 {
     pthread_mutex_lock(&sh->mutex_on_hash);
-    log_it(DEBUG,"Client structure create");
+    log_it(L_DEBUG,"Client structure create");
 
     dap_client_t * ret=(dap_client_t *) calloc(1,sizeof(dap_client_t));
     ret->socket=s;
diff --git a/client/dap_client_remote.h b/client/dap_client_remote.h
index 1868b4ddb2..e72b691b3c 100644
--- a/client/dap_client_remote.h
+++ b/client/dap_client_remote.h
@@ -29,13 +29,13 @@
 
 
 struct dap_server;
-struct dap_client;
+struct dap_client_remote;
 
-typedef void (*dap_client_callback_t) (struct dap_client *,void * arg); // Callback for specific client operations
+typedef void (*dap_client_remote_callback_t) (struct dap_client_remote *,void * arg); // Callback for specific client operations
 
-#define DAP_CLIENT_BUF 100000
+#define DAP_CLIENT_REMOTE_BUF 100000
 
-typedef struct dap_client{
+typedef struct dap_client_remote{
     int socket;
     bool signal_close;
 
@@ -43,10 +43,10 @@ typedef struct dap_client{
     bool _ready_to_read;
 
     uint32_t buf_out_zero_count;
-    char buf_in[DAP_CLIENT_BUF+1]; // Internal buffer for input data
+    char buf_in[DAP_CLIENT_REMOTE_BUF+1]; // Internal buffer for input data
     size_t buf_in_size; // size of data that is in the input buffer
 
-    char buf_out[DAP_CLIENT_BUF+1]; // Internal buffer for output data
+    char buf_out[DAP_CLIENT_REMOTE_BUF+1]; // Internal buffer for output data
 
     char hostaddr[1024]; // Address
     char service[128];
@@ -60,12 +60,12 @@ typedef struct dap_client{
     UT_hash_handle hh;
 
     void * internal; // Internal data to specific client type, usualy states for state machine
-} dap_client_t; // Node of bidirectional list of clients
+} dap_client_remote_t; // Node of bidirectional list of clients
 
 
 
-extern int dap_client_init(); //  Init clients module
-extern void dap_client_deinit(); // Deinit clients module
+int dap_client_remote_init(); //  Init clients module
+void dap_client_remote_deinit(); // Deinit clients module
 
 extern dap_client_t * dap_client_create(struct dap_server * sh, int s, ev_io* w_client); // Create new client and add it to the list
 extern dap_client_t * dap_client_find(int sock, struct dap_server * sh); // Find client by socket
diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt
index ec9cd642ca..ac24e0d8e3 100644
--- a/core/CMakeLists.txt
+++ b/core/CMakeLists.txt
@@ -1,7 +1,7 @@
 cmake_minimum_required(VERSION 2.8)
-project (dapcore)
+project (dap_core)
   
-set(CORE_SRCS dap_common.c )
+set(CORE_SRCS dap_common.c dap_config.c)
  
 add_library(${PROJECT_NAME} STATIC ${CORE_SRCS})
 
diff --git a/core/dap_common.h b/core/dap_common.h
index 023cdd7d86..cce8b58cd5 100644
--- a/core/dap_common.h
+++ b/core/dap_common.h
@@ -6,9 +6,12 @@
 #include <stdlib.h>
 #include <time.h>
 
-#define MALLOC(a) ((a *) malloc(sizeof(a)))
-#define CALLOC(a) ((a *) calloc(1,sizeof(a)))
-#define DUP(a) (__typeof(a) ret = memcpy(ret,a,sizeof(*a)) )
+#define DAP_NEW(a)    ( (a*) malloc(sizeof(a)))
+#define DAP_NEW_SIZE(a,b)    ( (a*) malloc(b))
+#define DAP_NEW_Z(a) ( (a*) calloc(1,sizeof(a)))
+#define DAP_NEW_Z_SIZE(a,b) ( (a*) calloc(1,b))
+
+#define DAP_DUP(a) (__typeof(a) ret = memcpy(ret,a,sizeof(*a)) )
 
 enum log_level{L_CRITICAL=5,L_ERROR=4, L_WARNING=3,L_NOTICE=2,L_INFO=1,L_DEBUG=0};
 extern enum log_level log_level;
diff --git a/core/dap_config.c b/core/dap_config.c
new file mode 100644
index 0000000000..444c9fb936
--- /dev/null
+++ b/core/dap_config.c
@@ -0,0 +1,91 @@
+#include <stdio.h>
+#include <string.h>
+#include "dap_common.h"
+#include "dap_config.h"
+
+#define LOG_TAG "dap_config"
+
+/**
+ * @brief dap_config_init
+ * @param a_configs_path
+ * @return
+ */
+int dap_config_init(const char * a_configs_path)
+{
+
+}
+
+/**
+ * @brief dap_config_deinit
+ */
+void dap_config_deinit()
+{
+
+}
+
+/**
+ * @brief dap_config_open
+ * @param a_config
+ */
+void dap_config_open(dap_config_t * a_config)
+{
+
+}
+
+/**
+ * @brief dap_config_close
+ * @param a_config
+ */
+void dap_config_close(dap_config_t * a_config)
+{
+
+}
+
+/**
+ * @brief dap_config_get_item_int32
+ * @param a_config
+ * @param a_section_path
+ * @param a_item_name
+ * @return
+ */
+int32_t dap_config_get_item_int32(dap_config_t * a_config, const char * a_section_path, const char * a_item_name)
+{
+
+}
+
+/**
+ * @brief dap_config_get_item_str
+ * @param a_config
+ * @param a_section_path
+ * @param a_item_name
+ * @return
+ */
+const char * dap_config_get_item_str(dap_config_t * a_config, const char * a_section_path, const char * a_item_name)
+{
+
+}
+
+/**
+ * @brief dap_config_get_item_bool
+ * @param a_config
+ * @param a_section_path
+ * @param a_item_name
+ * @return
+ */
+bool dap_config_get_item_bool(dap_config_t * a_config, const char * a_section_path, const char * a_item_name)
+{
+
+}
+
+/**
+ * @brief dap_config_get_item_double
+ * @param a_config
+ * @param a_section_path
+ * @param a_item_name
+ * @return
+ */
+double dap_config_get_item_double(dap_config_t * a_config, const char * a_section_path, const char * a_item_name)
+{
+
+}
+
diff --git a/core/dap_config.h b/core/dap_config.h
new file mode 100644
index 0000000000..37da2dfe80
--- /dev/null
+++ b/core/dap_config.h
@@ -0,0 +1,39 @@
+#ifndef _DAP_CONFIG_H_
+#define _DAP_CONFIG_H_
+#include <stdbool.h>
+#include <stdint.h>
+
+/**
+ * @brief The dap_config_item struct
+ */
+typedef struct dap_config_item{
+    struct {
+        char * name;
+        struct dap_config_item * childs;
+        struct dap_config_item * next;
+    } header;
+    union{
+        char *data_str;
+        uint8_t data_uint8;
+        bool data_bool;
+        double data_double;
+        int32_t data_int32;
+    };
+} dap_config_item_t;
+
+typedef struct dap_config{
+    void * _internal;
+} dap_config_t;
+
+int dap_config_init(const char * a_configs_path);
+void dap_config_deinit();
+void dap_config_open(dap_config_t * a_config);
+void dap_config_close(dap_config_t * a_config);
+
+int32_t dap_config_get_item_int32(dap_config_t * a_config, const char * a_section_path, const char * a_item_name);
+const char * dap_config_get_item_str(dap_config_t * a_config, const char * a_section_path, const char * a_item_name);
+bool dap_config_get_item_bool(dap_config_t * a_config, const char * a_section_path, const char * a_item_name);
+double dap_config_get_item_double(dap_config_t * a_config, const char * a_section_path, const char * a_item_name);
+
+
+#endif
diff --git a/crypt/CMakeLists.txt b/crypt/CMakeLists.txt
index e944c08149..0a45aaaddd 100644
--- a/crypt/CMakeLists.txt
+++ b/crypt/CMakeLists.txt
@@ -1,13 +1,13 @@
 cmake_minimum_required(VERSION 2.8)
-project (dapcrypt)
+project (dap_crypto)
   
-set(CRYPT_SRCS dap_enc.c dap_enc_aes.c dap_enc_key.c  )
+set(CRYPT_SRCS dap_enc.c dap_enc_aes.c dap_enc_newhope.c dap_enc_key.c  )
 
 add_subdirectory(monero_crypto)
 
-include_directories("${dapcore_INCLUDE_DIRS}")
+include_directories("${dap_core_INCLUDE_DIRS}")
 include_directories("${monero_crypto_INCLUDE_DIRS}")
-add_definitions ("${dapcore_DEFINITIONS}")
+add_definitions ("${dap_core_DEFINITIONS}")
 add_definitions ("${monero_crypto_DEFINITIONS}")
 add_library(${PROJECT_NAME} STATIC ${CRYPT_SRCS} ${crypto_sources} )
 
diff --git a/crypt/dap_enc_aes.c b/crypt/dap_enc_aes.c
index 1c1d70c9dc..5f1fa1182e 100755
--- a/crypt/dap_enc_aes.c
+++ b/crypt/dap_enc_aes.c
@@ -24,19 +24,20 @@ void dap_enc_aes_key_delete(struct dap_enc_key *a_key)
 /**
  * @brief dap_enc_aes_key_new_generate
  * @param a_key
+ * @param a_size
  */
-void dap_enc_aes_key_new_generate(struct dap_enc_key * a_key)
+void dap_enc_aes_key_new_generate(struct dap_enc_key * a_key,size_t a_size)
 {
 
 }
 
 /**
- * @brief dap_enc_aes_key_new_from
+ * @brief dap_enc_aes_key_new_from_data
  * @param a_key
  * @param a_in
  * @param a_in_size
  */
-void dap_enc_aes_key_new_from(struct dap_enc_key * a_key, const void * a_in, size_t a_in_size)
+void dap_enc_aes_key_new_from_data(struct dap_enc_key * a_key, const void * a_in, size_t a_in_size)
 {
 
 }
diff --git a/crypt/dap_enc_aes.h b/crypt/dap_enc_aes.h
index 7c5fb93909..1eb99c3e46 100755
--- a/crypt/dap_enc_aes.h
+++ b/crypt/dap_enc_aes.h
@@ -5,8 +5,8 @@
 
 struct dap_enc_key;
 
-void dap_enc_aes_key_new_generate(struct dap_enc_key * a_key);
-void dap_enc_aes_key_new_from(struct dap_enc_key * a_key, const void * a_in, size_t a_in_size);
+void dap_enc_aes_key_new_generate(struct dap_enc_key * a_key,size_t a_size);
+void dap_enc_aes_key_new_from_data(struct dap_enc_key * a_key, const void * a_in, size_t a_in_size);
 void dap_enc_aes_key_delete(struct dap_enc_key *a_key);
 
 size_t dap_enc_aes_decode(struct dap_enc_key* a_key, const void * a_in, size_t a_in_size,void * a_out);
diff --git a/crypt/dap_enc_key.c b/crypt/dap_enc_key.c
index 13563c08e5..498cf8b17b 100644
--- a/crypt/dap_enc_key.c
+++ b/crypt/dap_enc_key.c
@@ -21,8 +21,10 @@
 
 #include <stdlib.h>
 #include <string.h>
+#include "dap_common.h"
 
 #include "dap_enc_aes.h"
+#include "dap_enc_newhope.h"
 
 #include "dap_enc_key.h"
 
@@ -30,46 +32,54 @@
 
 struct dap_enc_key_callbacks{
     const char * name;
+    size_t size_max;
     dap_enc_callback_dataop_t enc;
     dap_enc_callback_dataop_t dec;
-    dap_enc_callback_data_t new_from_callback;
-    dap_enc_callback_t new_generate_callback;
+    dap_enc_callback_pptr_r_size_t key_public_raw_callback;
+
+    dap_enc_callback_t new_callback;
+    dap_enc_callback_data_t new_from_data_callback;
+    dap_enc_callback_data_t new_from_data_public_callback;
+    dap_enc_callback_size_t new_generate_callback;
+
     dap_enc_callback_t delete_callback;
 } s_callbacks[]={
+    // AES
     [DAP_ENC_KEY_TYPE_AES]={
                             .name = "AES",
+                            .size_max = 8,
                             .enc = dap_enc_aes_encode,
                             .dec = dap_enc_aes_decode,
+                            .new_callback = NULL,
+                            .delete_callback = NULL,
                             .new_generate_callback = dap_enc_aes_key_new_generate,
-                            .new_from_callback = dap_enc_aes_key_new_from
+                            .new_from_data_callback = dap_enc_aes_key_new_from_data
+                           },
+    // NEW HOPE
+    [DAP_ENC_KEY_TYPE_RLWE_NEWHOPE]={
+                            .name = "NEWHOPE",
+                            .size_max = 64,
+                            .enc = dap_enc_newhope_encode,
+                            .dec = dap_enc_newhope_decode,
+                            .new_callback = NULL,
+                            .delete_callback = NULL,
+                            .new_generate_callback = dap_enc_newhope_key_new_generate,
+                            .new_from_data_callback = dap_enc_newhope_key_new_from_data,
+                            .key_public_raw_callback = dap_enc_newhope_key_public_raw,
+                            .new_from_data_public_callback = dap_enc_newhope_key_new_from_data_public
                            }
 };
 
+const size_t c_callbacks_size = sizeof(s_callbacks) / sizeof(s_callbacks[0]);
+
+
 /**
  * @brief dap_enc_key_init
  * @return
  */
 int dap_enc_key_init()
 {
-    size_t i;
-    for( i = 0; i< sizeof(s_callbacks)/sizeof(s_callbacks[0]); i++ ){
-        switch ((dap_enc_key_type_t) i) {
-        case DAP_ENC_KEY_CODE_MCBITS:
-        case DAP_ENC_KEY_LWE_FRODO:
-        case DAP_ENC_KEY_MLWE_KYBER:
-        case DAP_ENC_KEY_NTRU:
-        case DAP_ENC_KEY_RLWE_BCNS15:
-        case DAP_ENC_KEY_RLWE_MSRLN16:
-        case DAP_ENC_KEY_RLWE_NEWHOPE:
-        case DAP_ENC_KEY_SIDH_CLN16:
-        case DAP_ENC_KEY_SIDH_IQC_REF:
-        case DAP_ENC_KEY_SIG_PICNIC:
-        case DAP_ENC_KEY_TYPE_AES:
-            continue;
-        default:
-            memset(&s_callbacks[i],0,sizeof(s_callbacks[0]));
-        }
-    }
+
     return 0;
 }
 
@@ -83,56 +93,72 @@ void dap_enc_key_deinit()
 
 /**
  * @brief dap_enc_key_new
- * @param key_type
+ * @param a_key_type
  * @return
  */
-dap_enc_key_t *dap_enc_key_new(dap_enc_key_type_t key_type)
+dap_enc_key_t *dap_enc_key_new(dap_enc_key_type_t a_key_type)
 {
-
+    dap_enc_key_t * ret = NULL;
+    if(a_key_type< c_callbacks_size ){
+        dap_enc_key_t * ret = DAP_NEW_Z(dap_enc_key_t);
+        if(s_callbacks[a_key_type].new_callback){
+            s_callbacks[a_key_type].new_callback(ret);
+        }
+    }
+    return ret;
 }
 
 /**
  * @brief dap_enc_key_new_generate
- * @param key_type
- * @param key_size
+ * @param a_key_type
+ * @param a_key_size
  * @return
  */
-dap_enc_key_t *dap_enc_key_new_generate(dap_enc_key_type_t key_type, size_t key_size)
+dap_enc_key_t *dap_enc_key_new_generate(dap_enc_key_type_t a_key_type, size_t a_key_size)
 {
-    if(s_callbacks[key_type].name ){
-        dap_enc_key_t * ret = dap_enc_ke_n
-        s_callbacks[key_type].new_generate_callback()
+    dap_enc_key_t * ret = NULL;
+
+    if(a_key_type< c_callbacks_size ){
+        ret = dap_enc_key_new (a_key_type);
+        if( s_callbacks[a_key_type].new_generate_callback ){
+            s_callbacks[a_key_type].new_generate_callback(ret,a_key_size);
+        }
     }
-    return NULL;
+    return ret;
 }
 
-dap_enc_key_t *dap_enc_key_new_from_str(dap_enc_key_type_t a_type, const char *a_key_str)
+/**
+ * @brief dap_enc_key_new_from_str
+ * @param a_keyt_type
+ * @param a_key_str
+ * @return
+ */
+dap_enc_key_t *dap_enc_key_new_from_str(dap_enc_key_type_t a_key_type, const char *a_key_str)
 {
-   enc_key_t * ret= (enc_key_t *) calloc(1,sizeof(enc_key_t) );
-   size_t input_size=strlen(key_input);
-   switch(v_type){
-        case ENC_KEY_TYPE_AES:{
-            enc_aes_key_create(ret,key_input);
-        }break;
-        case ENC_KEY_TYPE_FNAM2:{
-           ret->data = (unsigned char*) calloc(1,input_size*2);
-           ret->data_size= enc_base64_decode(key_input,input_size,ret->data);
-        }break;
-   }
-   ret->type=v_type;
-   return ret;
+    dap_enc_key_t * ret = NULL;
+
+    if(a_key_type< c_callbacks_size ){
+        ret = DAP_NEW_Z(dap_enc_key_t);
+    }
+    return ret;
 }
 
 /**
  * @brief dap_enc_key_new_from_data
- * @param a_type
+ * @param a_key_type
  * @param a_key_input
  * @param a_key_input_size
  * @return
  */
-dap_enc_key_t *dap_enc_key_new_from_data(dap_enc_key_type_t a_type, void * a_key_input, size_t a_key_input_size)
+dap_enc_key_t *dap_enc_key_new_from_data(dap_enc_key_type_t a_key_type, void * a_key_input, size_t a_key_input_size)
 {
+    dap_enc_key_t * ret = NULL;
 
+    if(a_key_type< c_callbacks_size ){
+        ret = DAP_NEW_Z(dap_enc_key_t);
+        s_callbacks[a_key_type].new_from_data_callback(ret,a_key_input, a_key_input_size);
+    }
+    return ret;
 }
 
 
diff --git a/crypt/dap_enc_key.h b/crypt/dap_enc_key.h
index 8b111abd26..6c01bca5de 100644
--- a/crypt/dap_enc_key.h
+++ b/crypt/dap_enc_key.h
@@ -29,52 +29,52 @@ typedef enum dap_enc_data_type{DAP_ENC_DATA_TYPE_RAW,
 
 typedef enum dap_enc_key_type{ DAP_ENC_KEY_TYPE_AES, // Symmetric AES
 
-                           DAP_ENC_KEY_RLWE_BCNS15, // key exchange from the ring learning with errors problem
+                           DAP_ENC_KEY_TYPE_RLWE_BCNS15, // key exchange from the ring learning with errors problem
                                                 // (Bos, Costello, Naehrig, Stebila,
                                                 // IEEE Symposium on Security & Privacy 2015,
                                                 // https://eprint.iacr.org/2014/599)
 
-                           DAP_ENC_KEY_RLWE_NEWHOPE, // "NewHope": key exchange from the ring learning with errors problem
+                           DAP_ENC_KEY_TYPE_RLWE_NEWHOPE, // "NewHope": key exchange from the ring learning with errors problem
                                                 //  (Alkim, Ducas, Pöppelmann, Schwabe, USENIX Security 2016 )
                                                 //  Using the reference C implementation of NewHope
                                                 // from https://github.com/tpoeppelmann/newhop
                                                 // https://eprint.iacr.org/2015/1092
 
-                           DAP_ENC_KEY_RLWE_MSRLN16, // Microsoft Research implementation of Peikert's ring-LWE key exchange
+                           DAP_ENC_KEY_TYPE_RLWE_MSRLN16, // Microsoft Research implementation of Peikert's ring-LWE key exchange
                                                // (Longa, Naehrig, CANS 2016, https://eprint.iacr.org/2016/504)
                                                // based on the implementation of Alkim, Ducas, Pöppelmann, and Schwabe,
                                                // with improvements from Longa and Naehrig,
                                                //  https://www.microsoft.com/en-us/research/project/lattice-cryptography-library/
 
-                           DAP_ENC_KEY_LWE_FRODO ,  // "Frodo": key exchange from the learning with errors problem
+                           DAP_ENC_KEY_TYPE_LWE_FRODO ,  // "Frodo": key exchange from the learning with errors problem
                                                // Bos, Costello, Ducas, Mironov, Naehrig, Nikolaenko, Raghunathan, Stebila
                                                // ACM Conference on Computer and Communications Security 2016
                                                // https://eprint.iacr.org/2016/659
 
-                           DAP_ENC_KEY_SIDH_CLN16 , // Key exchange from the supersingular isogeny Diffie-Hellman problem
+                           DAP_ENC_KEY_TYPE_SIDH_CLN16 , // Key exchange from the supersingular isogeny Diffie-Hellman problem
                                                // (Costello, Naehrig, Longa, CRYPTO 2016, https://eprint.iacr.org/2016/413)
                                                // using the implementation of Microsoft Research
                                                // https://www.microsoft.com/en-us/research/project/sidh-library/
 
-                           DAP_ENC_KEY_SIDH_IQC_REF, // key exchange from the supersingular isogeny Diffie-Hellman problem
+                           DAP_ENC_KEY_TYPE_SIDH_IQC_REF, // key exchange from the supersingular isogeny Diffie-Hellman problem
                                                  // (De Feo, Jao, Plût, J. Math. Cryptol. 8(3):209, 2014
                                                  // https://eprint.iacr.org/2011/506
                                                  //
-                           DAP_ENC_KEY_CODE_MCBITS, // "McBits": key exchange from the error correcting codes,
+                           DAP_ENC_KEY_TYPE_CODE_MCBITS, // "McBits": key exchange from the error correcting codes,
                                                 // specifically Niederreiter's form of McEliece public key encryption
                                                 //  using hidden Goppa codes (Bernstein, Chou, Schwabe, CHES 2013, https://eprint.iacr.org/2015/610)
                                                 // using the implementation of McBits from https://www.win.tue.nl/~tchou/mcbits/
 
-                           DAP_ENC_KEY_NTRU,   // NTRU: key transport using NTRU public key encryption
+                           DAP_ENC_KEY_TYPE_NTRU,   // NTRU: key transport using NTRU public key encryption
                                                // (Hoffstein, Pipher, Silverman, ANTS 1998) with the EES743EP1 parameter set
                                                //  wrapper around the implementation from the NTRU Open Source project
                                                // https://github.com/NTRUOpenSourceProject/NTRUEncrypt)
 
-                           DAP_ENC_KEY_MLWE_KYBER, // Kyber: a CCA-secure module-lattice-based key exchange mechanism
+                           DAP_ENC_KEY_TYPE_MLWE_KYBER, // Kyber: a CCA-secure module-lattice-based key exchange mechanism
                                                // (Bos, Ducas, Kiltz, Lepoint, Lyubashevsky, Schwabe, Shanck, Stehlé)
                                                // Real World Crypto 2017, https://eprint.iacr.org/2017/634)
                                                // using the reference C implementation of Kyber from pq-crystals/kyber
-                           DAP_ENC_KEY_SIG_PICNIC , // signature based on zero-knowledge proof as specified in
+                           DAP_ENC_KEY_TYPE_SIG_PICNIC  // signature based on zero-knowledge proof as specified in
                                                // Post-Quantum Zero-Knowledge and Signatures from Symmetric-Key Primitives
                                                // (Melissa Chase and David Derler and Steven Goldfeder and Claudio Orlandi
                                                // and Sebastian Ramacher and Christian Rechberger and Daniel Slamanig and Greg Zaverucha
@@ -85,13 +85,20 @@ typedef enum dap_enc_key_type{ DAP_ENC_KEY_TYPE_AES, // Symmetric AES
 struct dap_enc_key;
 
 typedef void (*dap_enc_callback_t)(struct dap_enc_key *);
-typedef void (*dap_enc_callback_arg_t)(struct dap_enc_key *, void *);
+typedef void (*dap_enc_callback_ptr_t)(struct dap_enc_key *, void *);
+typedef size_t (*dap_enc_callback_pptr_r_size_t)(struct dap_enc_key *, void **);
 typedef void (*dap_enc_callback_data_t)(struct dap_enc_key *, const void * , size_t);
+typedef void (*dap_enc_callback_size_t)(struct dap_enc_key *, size_t);
+
+typedef void (*dap_enc_callback_str_t)(struct dap_enc_key *, const char*);
+typedef char* (*dap_enc_callback_r_str_t)(struct dap_enc_key *);
+
+
 typedef size_t (*dap_enc_callback_dataop_t)(struct dap_enc_key *, const void * , const size_t ,void *);
 
 typedef struct dap_enc_key{
-    unsigned char * data;
     size_t data_size;
+    unsigned char * data;
     dap_enc_key_type_t type;
 
     dap_enc_callback_dataop_t enc;
@@ -104,11 +111,11 @@ typedef struct dap_enc_key{
 int dap_enc_key_init();
 void dap_enc_key_deinit();
 
-dap_enc_key_t *dap_enc_key_new(dap_enc_key_type_t key_type);
+dap_enc_key_t *dap_enc_key_new(dap_enc_key_type_t a_key_type);
 
-dap_enc_key_t *dap_enc_key_new_generate(dap_enc_key_type_t key_type, size_t key_size);
-dap_enc_key_t *dap_enc_key_new_from_data(dap_enc_key_type_t a_type, void * a_key_input, size_t a_key_input_size);
-dap_enc_key_t *dap_enc_key_new_from_str(dap_enc_key_type_t a_type, const char *a_key_str);
-void dap_enc_key_delete(dap_enc_key_t * key);
+dap_enc_key_t *dap_enc_key_new_generate(dap_enc_key_type_t a_key_type, size_t a_key_size);
+dap_enc_key_t *dap_enc_key_new_from_data(dap_enc_key_type_t a_key_type, void * a_key_input, size_t a_key_input_size);
+dap_enc_key_t *dap_enc_key_new_from_str(dap_enc_key_type_t a_key_type, const char *a_key_str);
+void dap_enc_key_delete(dap_enc_key_t * a_key);
 
 #endif
diff --git a/crypt/dap_enc_newhope.c b/crypt/dap_enc_newhope.c
new file mode 100644
index 0000000000..30856c55e7
--- /dev/null
+++ b/crypt/dap_enc_newhope.c
@@ -0,0 +1,92 @@
+#include "dap_common.h"
+#include "dap_enc_newhope.h"
+
+#define LOG_TAG "dap_enc_newhope"
+
+/**
+ * @brief dap_enc_newhope_key_new_generate
+ * @param a_key
+ * @param a_size
+ */
+void dap_enc_newhope_key_new_generate(dap_enc_key_t * a_key, size_t a_size)
+{
+
+}
+
+/**
+ * @brief dap_enc_newhope_key_new_from_data
+ * @param a_key
+ * @param a_in
+ * @param a_in_size
+ */
+void dap_enc_newhope_key_new_from_data(dap_enc_key_t * a_key, const void * a_in, size_t a_in_size)
+{
+
+}
+
+/**
+ * @brief dap_enc_newhope_key_new_from_data_public
+ * @param a_key
+ * @param a_in
+ * @param a_in_size
+ */
+void dap_enc_newhope_key_new_from_data_public(dap_enc_key_t * a_key, const void * a_in, size_t a_in_size)
+{
+
+}
+
+/**
+ * @brief dap_enc_newhope_key_delete
+ * @param a_key
+ */
+void dap_enc_newhope_key_delete(dap_enc_key_t *a_key)
+{
+
+}
+
+/**
+ * @brief dap_enc_newhope_key_public_base64
+ * @param a_key
+ * @return
+ */
+char* dap_enc_newhope_key_public_base64(dap_enc_key_t *a_key)
+{
+
+}
+
+/**
+ * @brief dap_enc_newhope_key_public_raw
+ * @param a_key
+ * @param a_key_public
+ * @return
+ */
+size_t dap_enc_newhope_key_public_raw(dap_enc_key_t *a_key, void ** a_key_public)
+{
+
+}
+
+/**
+ * @brief dap_enc_newhope_decode
+ * @param a_key
+ * @param a_in
+ * @param a_in_size
+ * @param a_out
+ * @return
+ */
+size_t dap_enc_newhope_decode(dap_enc_key_t* a_key, const void * a_in, size_t a_in_size,void * a_out)
+{
+
+}
+
+/**
+ * @brief dap_enc_newhope_encode
+ * @param a_key
+ * @param a_in
+ * @param a_in_size
+ * @param a_out
+ * @return
+ */
+size_t dap_enc_newhope_encode(dap_enc_key_t* a_key, const void * a_in, size_t a_in_size,void * a_out)
+{
+
+}
diff --git a/crypt/dap_enc_newhope.h b/crypt/dap_enc_newhope.h
new file mode 100644
index 0000000000..55bfba711c
--- /dev/null
+++ b/crypt/dap_enc_newhope.h
@@ -0,0 +1,19 @@
+#ifndef _DAP_ENC_NEWHOPE_H_
+#define _DAP_ENC_NEWHOPE_H_
+
+#include <stddef.h>
+
+typedef struct dap_enc_key dap_enc_key_t;
+
+void dap_enc_newhope_key_new_generate(dap_enc_key_t * a_key, size_t a_size);
+void dap_enc_newhope_key_new_from_data(dap_enc_key_t * a_key, const void * a_in, size_t a_in_size);
+void dap_enc_newhope_key_new_from_data_public(dap_enc_key_t* a_key, const void * a_in, size_t a_in_size);
+
+void dap_enc_newhope_key_delete(dap_enc_key_t *a_key);
+
+size_t dap_enc_newhope_key_public_raw(dap_enc_key_t *a_key, void ** a_key_public);
+
+size_t dap_enc_newhope_decode(dap_enc_key_t* a_key, const void * a_in, size_t a_in_size,void * a_out);
+size_t dap_enc_newhope_encode(dap_enc_key_t* a_key, const void * a_in, size_t a_in_size,void * a_out);
+
+#endif
diff --git a/crypt/monero_crypto/CMakeLists.txt b/crypt/monero_crypto/CMakeLists.txt
index c2f19dd0e6..1662c77c62 100644
--- a/crypt/monero_crypto/CMakeLists.txt
+++ b/crypt/monero_crypto/CMakeLists.txt
@@ -1,5 +1,5 @@
 # Copyright (c) 2014-2017, The Monero Project
-#
+# Copyright (c) 2018, DapCash Project
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without modification, are
@@ -28,13 +28,317 @@
 
 project (monero_crypto)
 
+# ARCH defines the target architecture, either by an explicit identifier or
+# one of the following two keywords. By default, ARCH a value of 'native':
+# target arch = host arch, binary is not portable. When ARCH is set to the
+# string 'default', no -march arg is passed, which creates a binary that is
+# portable across processors in the same family as host processor.  In cases
+# when ARCH is not set to an explicit identifier, cmake's builtin is used
+# to identify the target architecture, to direct logic in this cmake script.
+# Since ARCH is a cached variable, it will not be set on first cmake invocation.
+set(STATIC 1)
+
+if (NOT ARCH OR ARCH STREQUAL "" OR ARCH STREQUAL "native" OR ARCH STREQUAL "default")
+  set(ARCH_ID "${CMAKE_SYSTEM_PROCESSOR}")
+else()
+  set(ARCH_ID "${ARCH}")
+endif()
+string(TOLOWER "${ARCH_ID}" ARM_ID)
+string(SUBSTRING "${ARM_ID}" 0 3 ARM_TEST)
+if (ARM_TEST STREQUAL "arm")
+  set(ARM 1)
+  string(SUBSTRING "${ARM_ID}" 0 5 ARM_TEST)
+  if (ARM_TEST STREQUAL "armv6")
+    set(ARM6 1)
+  endif()
+  if (ARM_TEST STREQUAL "armv7")
+    set(ARM7 1)
+  endif()
+endif()
+
+if (ARM_ID STREQUAL "aarch64" OR ARM_ID STREQUAL "arm64" OR ARM_ID STREQUAL "armv8-a")
+  set(ARM 1)
+  set(ARM8 1)
+  set(ARCH "armv8-a")
+endif()
+
+if(ARCH_ID STREQUAL "ppc64le")
+  set(PPC64LE 1)
+endif()
+
+if(WIN32 OR ARM)
+  set(OPT_FLAGS_RELEASE "-O2")
+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
+if(CMAKE_SYSTEM_NAME MATCHES "kFreeBSD.*|FreeBSD")
+  set(FREEBSD TRUE)
+endif()
+
+# Check if we're on DragonFly BSD. See the README.md for build instructions.
+if(CMAKE_SYSTEM_NAME MATCHES "DragonFly.*")
+  set(DRAGONFLY TRUE)
+endif()
+
+# Check if we're on OpenBSD. See the README.md for build instructions.
+if(CMAKE_SYSTEM_NAME MATCHES "kOpenBSD.*|OpenBSD.*")
+  set(OPENBSD TRUE)
+endif()
+
+if(APPLE)
+  include_directories(SYSTEM /usr/include/malloc)
+  if(POLICY CMP0042)
+    cmake_policy(SET CMP0042 NEW)
+  endif()
+endif()
+
+if(MSVC)
+  add_definitions("/bigobj /MP /W3 /GS- /D_CRT_SECURE_NO_WARNINGS /wd4996 /wd4345 /D_WIN32_WINNT=0x0600 /DWIN32_LEAN_AND_MEAN /DGTEST_HAS_TR1_TUPLE=0 /FIinline_c.h /D__SSE4_1__")
+  # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Dinline=__inline")
+  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:10485760")
+  foreach(VAR CMAKE_C_FLAGS_DEBUG CMAKE_CXX_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_CXX_FLAGS_RELEASE)
+    string(REPLACE "/MD" "/MT" ${VAR} "${${VAR}}")
+  endforeach()
+  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}")
+    if(ARCH STREQUAL "default")
+      set(ARCH_FLAG "")
+    elseif(PPC64LE)
+      set(ARCH_FLAG "-mcpu=${ARCH}")
+    elseif(IOS AND ARCH STREQUAL "arm64")
+      message(STATUS "IOS: Changing arch from arm64 to armv8")
+      set(ARCH_FLAG "-march=armv8")
+    else()
+      set(ARCH_FLAG "-march=${ARCH}")
+    endif()
+    set(WARNINGS "-Wall -Wextra -Wpointer-arith -Wundef -Wvla -Wwrite-strings -Wno-error=extra -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-unused-variable -W
+  no-error=unused-variable -Wno-error=undef -Wno-error=uninitialized")
+    if(NOT MINGW)
+      set(WARNINGS_AS_ERRORS_FLAG "-Werror")
+    endif()
+    if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
+      if(ARM)
+        set(WARNINGS "${WARNINGS} -Wno-error=inline-asm")
+      endif()
+    else()
+      set(WARNINGS "${WARNINGS} -Wlogical-op -Wno-error=maybe-uninitialized -Wno-error=cpp")
+    endif()
+    if(MINGW)
+        set(WARNINGS "${WARNINGS} -Wno-error=unused-value -Wno-error=unused-but-set-variable")
+        set(MINGW_FLAG "${MINGW_FLAG} -DWIN32_LEAN_AND_MEAN")
+        set(Boost_THREADAPI win32)
+        include_directories(SYSTEM src/platform/mingw)
+        # mingw doesn't support LTO (multiple definition errors at link time)
+        set(USE_LTO_DEFAULT false)
+        set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--stack,10485760")
+        if(NOT BUILD_64)
+          add_definitions(-DWINVER=0x0501 -D_WIN32_WINNT=0x0501)
+        endif()
+      endif()
+      set(C_WARNINGS "-Waggregate-return -Wnested-externs -Wold-style-definition -Wstrict-prototypes")
+      set(CXX_WARNINGS "-Wno-reorder -Wno-missing-field-initializers")
+
+      if(COVERAGE)
+        message(STATUS "Building with profiling for test coverage report")
+        set(COVERAGE_FLAGS "-fprofile-arcs -ftest-coverage --coverage")
+      endif()
+
+      # With GCC 6.1.1 the compiled binary malfunctions due to aliasing. Until that
+      # is fixed in the code (Issue #847), force compiler to be conservative.
+      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})
+
+      if(NO_AES)
+        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")
+        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")
+      elseif(ARM6)
+        message(STATUS "AES support not available on ARMv6")
+      elseif(ARM7)
+        message(STATUS "AES support not available on ARMv7")
+      elseif(ARM8)
+        CHECK_CXX_ACCEPTS_FLAG("-march=${ARCH}+crypto" ARCH_PLUS_CRYPTO)
+        if(ARCH_PLUS_CRYPTO)
+          message(STATUS "Crypto extensions enabled for ARMv8")
+          set(ARCH_FLAG "-march=${ARCH}+crypto")
+        else()
+          message(STATUS "Crypto extensions unavailable on your ARMv8 device")
+        endif()
+      else()
+        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}")
+
+      # With GCC 6.1.1 the compiled binary malfunctions due to aliasing. Until that
+      # is fixed in the code (Issue #847), force compiler to be conservative.
+      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")
+
+        #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
+
+        #Cortex-A5/9  -mfpu=neon-fp16
+        #Cortex-A7/15 -mfpu=neon-vfpv4
+        #Cortex-A8    -mfpu=neon
+        #ARMv8        -FP and SIMD on by default for all ARM8v-A series, NO -mfpu setting needed
+
+        #For custom -mtune, processor IDs for ARMv8-A series:
+        #0xd04 - Cortex-A35
+        #0xd07 - Cortex-A57
+        #0xd08 - Cortex-A72
+        #0xd03 - Cortex-A73
+
+        if(NOT ARM8)
+          CHECK_CXX_ACCEPTS_FLAG(-mfpu=vfp3-d16 CXX_ACCEPTS_VFP3_D16)
+          CHECK_CXX_ACCEPTS_FLAG(-mfpu=vfp4 CXX_ACCEPTS_VFP4)
+          CHECK_CXX_ACCEPTS_FLAG(-mfloat-abi=hard CXX_ACCEPTS_MFLOAT_HARD)
+          CHECK_CXX_ACCEPTS_FLAG(-mfloat-abi=softfp CXX_ACCEPTS_MFLOAT_SOFTFP)
+        endif()
+
+        if(ARM8)
+          CHECK_CXX_ACCEPTS_FLAG(-mfix-cortex-a53-835769 CXX_ACCEPTS_MFIX_CORTEX_A53_835769)
+          CHECK_CXX_ACCEPTS_FLAG(-mfix-cortex-a53-843419 CXX_ACCEPTS_MFIX_CORTEX_A53_843419)
+        endif()
+
+        if(ARM6)
+          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")
+            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")
+            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")
+            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")
+            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")
+             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")
+             set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfix-cortex-a53-843419")
+             set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfix-cortex-a53-843419")
+           endif()
+         endif(ARM8)
+
+       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")
+         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")
+       endif()
+
+       if(APPLE)
+         set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DGTEST_HAS_TR1_TUPLE=0")
+       endif()
+
+       set(DEBUG_FLAGS "-g3")
+       if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND NOT (CMAKE_C_COMPILER_VERSION VERSION_LESS 4.8))
+         set(DEBUG_FLAGS "${DEBUG_FLAGS} -Og ")
+       else()
+         set(DEBUG_FLAGS "${DEBUG_FLAGS} -O0 ")
+       endif()
+
+       if(NOT DEFINED USE_LTO_DEFAULT)
+         set(USE_LTO_DEFAULT false)
+       endif()
+       set(USE_LTO ${USE_LTO_DEFAULT} CACHE BOOL "Use Link-Time Optimization (Release mode only)")
+
+       if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
+         # There is a clang bug that does not allow to compile code that uses AES-NI intrinsics if -flto is enabled, so explicitly disable
+         set(USE_LTO false)
+       endif()
+       if(USE_LTO)
+         set(RELEASE_FLAGS "${RELEASE_FLAGS} -flto")
+         if(STATIC)
+           set(RELEASE_FLAGS "${RELEASE_FLAGS} -ffat-lto-objects")
+         endif()
+         # Since gcc 4.9 the LTO format is non-standard (slim), so we need the gcc-specific ar and ranlib binaries
+         if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.0) AND NOT OPENBSD AND NOT DRAGONFLY)
+           # When invoking cmake on distributions on which gcc's binaries are prefixed
+           # with an arch-specific triplet, the user must specify -DCHOST=<prefix>
+           if (DEFINED CHOST)
+             set(CMAKE_AR "${CHOST}-gcc-ar")
+             set(CMAKE_RANLIB "${CHOST}-gcc-ranlib")
+           else()
+             set(CMAKE_AR "gcc-ar")
+             set(CMAKE_RANLIB "gcc-ranlib")
+           endif()
+         endif()
+       endif()
+
+       set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${DEBUG_FLAGS}")
+       set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${DEBUG_FLAGS}")
+       set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${RELEASE_FLAGS}")
+       set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${RELEASE_FLAGS}")
+endif()
+
+
+
+
+
 set(monero_crypto_sources
   aesb.c
   blake256.c
   chacha8.c
   crypto-ops-data.c
   crypto-ops.c
-  crypto.cpp
   groestl.c
   hash-extra-blake.c
   hash-extra-groestl.c
@@ -92,7 +396,6 @@ if (ANDROID OR IOS)
 endif()
 
 
-
 add_library(${PROJECT_NAME} STATIC ${monero_crypto_sources})
 
 set(${PROJECT_NAME}_DEFINITIONS CACHE INTERNAL "${PROJECT_NAME}: Definitions" FORCE)
diff --git a/crypt/monero_crypto/common/int-util.h b/crypt/monero_crypto/common/int-util.h
new file mode 100644
index 0000000000..7cec571ad8
--- /dev/null
+++ b/crypt/monero_crypto/common/int-util.h
@@ -0,0 +1,249 @@
+// Copyright (c) 2014-2017, The Monero Project
+// 
+// All rights reserved.
+// 
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+// 
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+//    conditions and the following disclaimer.
+// 
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+//    of conditions and the following disclaimer in the documentation and/or other
+//    materials provided with the distribution.
+// 
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+//    used to endorse or promote products derived from this software without specific
+//    prior written permission.
+// 
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+// 
+// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
+
+#pragma once
+
+#include <assert.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <string.h>
+#include <sys/param.h>
+
+#if defined(__ANDROID__)
+#include <byteswap.h>
+#endif
+
+#if defined(__sun) && defined(__SVR4)
+#include <endian.h>
+#endif
+
+#if defined(_MSC_VER)
+#include <stdlib.h>
+
+static inline uint32_t rol32(uint32_t x, int r) {
+  static_assert(sizeof(uint32_t) == sizeof(unsigned int), "this code assumes 32-bit integers");
+  return _rotl(x, r);
+}
+
+static inline uint64_t rol64(uint64_t x, int r) {
+  return _rotl64(x, r);
+}
+
+#else
+
+static inline uint32_t rol32(uint32_t x, int r) {
+  return (x << (r & 31)) | (x >> (-r & 31));
+}
+
+static inline uint64_t rol64(uint64_t x, int r) {
+  return (x << (r & 63)) | (x >> (-r & 63));
+}
+
+#endif
+
+static inline uint64_t hi_dword(uint64_t val) {
+  return val >> 32;
+}
+
+static inline uint64_t lo_dword(uint64_t val) {
+  return val & 0xFFFFFFFF;
+}
+
+static inline uint64_t mul128(uint64_t multiplier, uint64_t multiplicand, uint64_t* product_hi) {
+  // multiplier   = ab = a * 2^32 + b
+  // multiplicand = cd = c * 2^32 + d
+  // ab * cd = a * c * 2^64 + (a * d + b * c) * 2^32 + b * d
+  uint64_t a = hi_dword(multiplier);
+  uint64_t b = lo_dword(multiplier);
+  uint64_t c = hi_dword(multiplicand);
+  uint64_t d = lo_dword(multiplicand);
+
+  uint64_t ac = a * c;
+  uint64_t ad = a * d;
+  uint64_t bc = b * c;
+  uint64_t bd = b * d;
+
+  uint64_t adbc = ad + bc;
+  uint64_t adbc_carry = adbc < ad ? 1 : 0;
+
+  // multiplier * multiplicand = product_hi * 2^64 + product_lo
+  uint64_t product_lo = bd + (adbc << 32);
+  uint64_t product_lo_carry = product_lo < bd ? 1 : 0;
+  *product_hi = ac + (adbc >> 32) + (adbc_carry << 32) + product_lo_carry;
+  assert(ac <= *product_hi);
+
+  return product_lo;
+}
+
+static inline uint64_t div_with_reminder(uint64_t dividend, uint32_t divisor, uint32_t* remainder) {
+  dividend |= ((uint64_t)*remainder) << 32;
+  *remainder = dividend % divisor;
+  return dividend / divisor;
+}
+
+// Long division with 2^32 base
+static inline uint32_t div128_32(uint64_t dividend_hi, uint64_t dividend_lo, uint32_t divisor, uint64_t* quotient_hi, uint64_t* quotient_lo) {
+  uint64_t dividend_dwords[4];
+  uint32_t remainder = 0;
+
+  dividend_dwords[3] = hi_dword(dividend_hi);
+  dividend_dwords[2] = lo_dword(dividend_hi);
+  dividend_dwords[1] = hi_dword(dividend_lo);
+  dividend_dwords[0] = lo_dword(dividend_lo);
+
+  *quotient_hi  = div_with_reminder(dividend_dwords[3], divisor, &remainder) << 32;
+  *quotient_hi |= div_with_reminder(dividend_dwords[2], divisor, &remainder);
+  *quotient_lo  = div_with_reminder(dividend_dwords[1], divisor, &remainder) << 32;
+  *quotient_lo |= div_with_reminder(dividend_dwords[0], divisor, &remainder);
+
+  return remainder;
+}
+
+#define IDENT32(x) ((uint32_t) (x))
+#define IDENT64(x) ((uint64_t) (x))
+
+#define SWAP32(x) ((((uint32_t) (x) & 0x000000ff) << 24) | \
+  (((uint32_t) (x) & 0x0000ff00) <<  8) | \
+  (((uint32_t) (x) & 0x00ff0000) >>  8) | \
+  (((uint32_t) (x) & 0xff000000) >> 24))
+#define SWAP64(x) ((((uint64_t) (x) & 0x00000000000000ff) << 56) | \
+  (((uint64_t) (x) & 0x000000000000ff00) << 40) | \
+  (((uint64_t) (x) & 0x0000000000ff0000) << 24) | \
+  (((uint64_t) (x) & 0x00000000ff000000) <<  8) | \
+  (((uint64_t) (x) & 0x000000ff00000000) >>  8) | \
+  (((uint64_t) (x) & 0x0000ff0000000000) >> 24) | \
+  (((uint64_t) (x) & 0x00ff000000000000) >> 40) | \
+  (((uint64_t) (x) & 0xff00000000000000) >> 56))
+
+static inline uint32_t ident32(uint32_t x) { return x; }
+static inline uint64_t ident64(uint64_t x) { return x; }
+
+#ifndef __OpenBSD__
+#  if defined(__ANDROID__) && defined(__swap32) && !defined(swap32)
+#      define swap32 __swap32
+#  elif !defined(swap32)
+static inline uint32_t swap32(uint32_t x) {
+  x = ((x & 0x00ff00ff) << 8) | ((x & 0xff00ff00) >> 8);
+  return (x << 16) | (x >> 16);
+}
+#  endif
+#  if defined(__ANDROID__) && defined(__swap64) && !defined(swap64)
+#      define swap64 __swap64
+#  elif !defined(swap64)
+static inline uint64_t swap64(uint64_t x) {
+  x = ((x & 0x00ff00ff00ff00ff) <<  8) | ((x & 0xff00ff00ff00ff00) >>  8);
+  x = ((x & 0x0000ffff0000ffff) << 16) | ((x & 0xffff0000ffff0000) >> 16);
+  return (x << 32) | (x >> 32);
+}
+#  endif
+#endif /* __OpenBSD__ */
+
+#if defined(__GNUC__)
+#define UNUSED __attribute__((unused))
+#else
+#define UNUSED
+#endif
+static inline void mem_inplace_ident(void *mem UNUSED, size_t n UNUSED) { }
+#undef UNUSED
+
+static inline void mem_inplace_swap32(void *mem, size_t n) {
+  size_t i;
+  for (i = 0; i < n; i++) {
+    ((uint32_t *) mem)[i] = swap32(((const uint32_t *) mem)[i]);
+  }
+}
+static inline void mem_inplace_swap64(void *mem, size_t n) {
+  size_t i;
+  for (i = 0; i < n; i++) {
+    ((uint64_t *) mem)[i] = swap64(((const uint64_t *) mem)[i]);
+  }
+}
+
+static inline void memcpy_ident32(void *dst, const void *src, size_t n) {
+  memcpy(dst, src, 4 * n);
+}
+static inline void memcpy_ident64(void *dst, const void *src, size_t n) {
+  memcpy(dst, src, 8 * n);
+}
+
+static inline void memcpy_swap32(void *dst, const void *src, size_t n) {
+  size_t i;
+  for (i = 0; i < n; i++) {
+    ((uint32_t *) dst)[i] = swap32(((const uint32_t *) src)[i]);
+  }
+}
+static inline void memcpy_swap64(void *dst, const void *src, size_t n) {
+  size_t i;
+  for (i = 0; i < n; i++) {
+    ((uint64_t *) dst)[i] = swap64(((const uint64_t *) src)[i]);
+  }
+}
+
+#if !defined(BYTE_ORDER) || !defined(LITTLE_ENDIAN) || !defined(BIG_ENDIAN)
+static_assert(false, "BYTE_ORDER is undefined. Perhaps, GNU extensions are not enabled");
+#endif
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+#define SWAP32LE IDENT32
+#define SWAP32BE SWAP32
+#define swap32le ident32
+#define swap32be swap32
+#define mem_inplace_swap32le mem_inplace_ident
+#define mem_inplace_swap32be mem_inplace_swap32
+#define memcpy_swap32le memcpy_ident32
+#define memcpy_swap32be memcpy_swap32
+#define SWAP64LE IDENT64
+#define SWAP64BE SWAP64
+#define swap64le ident64
+#define swap64be swap64
+#define mem_inplace_swap64le mem_inplace_ident
+#define mem_inplace_swap64be mem_inplace_swap64
+#define memcpy_swap64le memcpy_ident64
+#define memcpy_swap64be memcpy_swap64
+#endif
+
+#if BYTE_ORDER == BIG_ENDIAN
+#define SWAP32BE IDENT32
+#define SWAP32LE SWAP32
+#define swap32be ident32
+#define swap32le swap32
+#define mem_inplace_swap32be mem_inplace_ident
+#define mem_inplace_swap32le mem_inplace_swap32
+#define memcpy_swap32be memcpy_ident32
+#define memcpy_swap32le memcpy_swap32
+#define SWAP64BE IDENT64
+#define SWAP64LE SWAP64
+#define swap64be ident64
+#define swap64le swap64
+#define mem_inplace_swap64be mem_inplace_ident
+#define mem_inplace_swap64le mem_inplace_swap64
+#define memcpy_swap64be memcpy_ident64
+#define memcpy_swap64le memcpy_swap64
+#endif
diff --git a/crypt/monero_crypto/common/memwipe.c b/crypt/monero_crypto/common/memwipe.c
new file mode 100644
index 0000000000..da7e9f3461
--- /dev/null
+++ b/crypt/monero_crypto/common/memwipe.c
@@ -0,0 +1,106 @@
+// Copyright (c) 2017, The Monero Project
+// 
+// All rights reserved.
+// 
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+// 
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+//    conditions and the following disclaimer.
+// 
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+//    of conditions and the following disclaimer in the documentation and/or other
+//    materials provided with the distribution.
+// 
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+//    used to endorse or promote products derived from this software without specific
+//    prior written permission.
+// 
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// Parts of this file Copyright (c) 2009-2015 The Bitcoin Core developers
+
+#define __STDC_WANT_LIB_EXT1__ 1
+#include <string.h>
+#include <stdlib.h>
+#ifdef HAVE_EXPLICIT_BZERO
+#include <strings.h>
+#endif
+#include "memwipe.h"
+
+#if defined(_MSC_VER)
+#define SCARECROW \
+    __asm;
+#else
+#define SCARECROW \
+    __asm__ __volatile__("" : : "r"(ptr) : "memory");
+#endif
+
+#ifdef HAVE_MEMSET_S
+
+void *memwipe(void *ptr, size_t n)
+{
+  if (memset_s(ptr, n, 0, n))
+  {
+    abort();
+  }
+  SCARECROW // might as well...
+  return ptr;
+}
+
+#elif defined HAVE_EXPLICIT_BZERO
+
+void *memwipe(void *ptr, size_t n)
+{
+  explicit_bzero(ptr, n);
+  SCARECROW
+  return ptr;
+}
+
+#else
+
+/* The memory_cleanse implementation is taken from Bitcoin */
+
+/* Compilers have a bad habit of removing "superfluous" memset calls that
+ * are trying to zero memory. For example, when memset()ing a buffer and
+ * then free()ing it, the compiler might decide that the memset is
+ * unobservable and thus can be removed.
+ *
+ * Previously we used OpenSSL which tried to stop this by a) implementing
+ * memset in assembly on x86 and b) putting the function in its own file
+ * for other platforms.
+ *
+ * This change removes those tricks in favour of using asm directives to
+ * scare the compiler away. As best as our compiler folks can tell, this is
+ * sufficient and will continue to be so.
+ *
+ * Adam Langley <agl@google.com>
+ * Commit: ad1907fe73334d6c696c8539646c21b11178f20f
+ * BoringSSL (LICENSE: ISC)
+ */
+static void memory_cleanse(void *ptr, size_t len)
+{
+    memset(ptr, 0, len);
+
+    /* As best as we can tell, this is sufficient to break any optimisations that
+       might try to eliminate "superfluous" memsets. If there's an easy way to
+       detect memset_s, it would be better to use that. */
+    SCARECROW
+}
+
+void *memwipe(void *ptr, size_t n)
+{
+  memory_cleanse(ptr, n);
+  SCARECROW
+  return ptr;
+}
+
+#endif
diff --git a/crypt/monero_crypto/common/memwipe.h b/crypt/monero_crypto/common/memwipe.h
new file mode 100644
index 0000000000..46cd131f3d
--- /dev/null
+++ b/crypt/monero_crypto/common/memwipe.h
@@ -0,0 +1,36 @@
+// Copyright (c) 2017, The Monero Project
+// Copyrught (c) 2018, DapCash Project
+// 
+// All rights reserved.
+// 
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+// 
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+//    conditions and the following disclaimer.
+// 
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+//    of conditions and the following disclaimer in the documentation and/or other
+//    materials provided with the distribution.
+// 
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+//    used to endorse or promote products derived from this software without specific
+//    prior written permission.
+// 
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+// 
+// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
+#ifndef _MEMWIPE_H_
+#define _MEMWIPE_H_
+
+void *memwipe(void *src, size_t n);
+
+#endif
\ No newline at end of file
diff --git a/crypt/monero_crypto/crypto.cpp b/crypt/monero_crypto/crypto.cpp
deleted file mode 100644
index 95ba34828d..0000000000
--- a/crypt/monero_crypto/crypto.cpp
+++ /dev/null
@@ -1,564 +0,0 @@
-// Copyright (c) 2014-2017, The Monero Project
-// 
-// All rights reserved.
-// 
-// Redistribution and use in source and binary forms, with or without modification, are
-// permitted provided that the following conditions are met:
-// 
-// 1. Redistributions of source code must retain the above copyright notice, this list of
-//    conditions and the following disclaimer.
-// 
-// 2. Redistributions in binary form must reproduce the above copyright notice, this list
-//    of conditions and the following disclaimer in the documentation and/or other
-//    materials provided with the distribution.
-// 
-// 3. Neither the name of the copyright holder nor the names of its contributors may be
-//    used to endorse or promote products derived from this software without specific
-//    prior written permission.
-// 
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
-// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
-// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
-// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
-// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// 
-// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
-
-#include <cassert>
-#include <cstddef>
-#include <cstdint>
-#include <cstdlib>
-#include <cstring>
-#include <memory>
-#include <boost/thread/mutex.hpp>
-#include <boost/thread/lock_guard.hpp>
-#include <boost/shared_ptr.hpp>
-
-#include "common/varint.h"
-#include "warnings.h"
-#include "crypto.h"
-#include "hash.h"
-
-namespace crypto {
-
-  using std::abort;
-  using std::int32_t;
-  using std::int64_t;
-  using std::size_t;
-  using std::uint32_t;
-  using std::uint64_t;
-
-  extern "C" {
-#include "crypto-ops.h"
-#include "random.h"
-  }
-
-  boost::mutex random_lock;
-
-  static inline unsigned char *operator &(ec_point &point) {
-    return &reinterpret_cast<unsigned char &>(point);
-  }
-
-  static inline const unsigned char *operator &(const ec_point &point) {
-    return &reinterpret_cast<const unsigned char &>(point);
-  }
-
-  static inline unsigned char *operator &(ec_scalar &scalar) {
-    return &reinterpret_cast<unsigned char &>(scalar);
-  }
-
-  static inline const unsigned char *operator &(const ec_scalar &scalar) {
-    return &reinterpret_cast<const unsigned char &>(scalar);
-  }
-
-  /* generate a random 32-byte (256-bit) integer and copy it to res */
-  static inline void random_scalar_not_thread_safe(ec_scalar &res) {
-    unsigned char tmp[64];
-    generate_random_bytes_not_thread_safe(64, tmp);
-    sc_reduce(tmp);
-    memcpy(&res, tmp, 32);
-  }
-  static inline void random_scalar(ec_scalar &res) {
-    boost::lock_guard<boost::mutex> lock(random_lock);
-    random_scalar_not_thread_safe(res);
-  }
-
-  void hash_to_scalar(const void *data, size_t length, ec_scalar &res) {
-    cn_fast_hash(data, length, reinterpret_cast<hash &>(res));
-    sc_reduce32(&res);
-  }
-
-  /* 
-   * generate public and secret keys from a random 256-bit integer
-   * TODO: allow specifiying random value (for wallet recovery)
-   * 
-   */
-  secret_key crypto_ops::generate_keys(public_key &pub, secret_key &sec, const secret_key& recovery_key, bool recover) {
-    ge_p3 point;
-
-    secret_key rng;
-
-    if (recover)
-    {
-      rng = recovery_key;
-    }
-    else
-    {
-      random_scalar(rng);
-    }
-    sec = rng;
-    sc_reduce32(&sec);  // reduce in case second round of keys (sendkeys)
-
-    ge_scalarmult_base(&point, &sec);
-    ge_p3_tobytes(&pub, &point);
-
-    return rng;
-  }
-
-  bool crypto_ops::check_key(const public_key &key) {
-    ge_p3 point;
-    return ge_frombytes_vartime(&point, &key) == 0;
-  }
-
-  bool crypto_ops::secret_key_to_public_key(const secret_key &sec, public_key &pub) {
-    ge_p3 point;
-    if (sc_check(&sec) != 0) {
-      return false;
-    }
-    ge_scalarmult_base(&point, &sec);
-    ge_p3_tobytes(&pub, &point);
-    return true;
-  }
-
-  bool crypto_ops::generate_key_derivation(const public_key &key1, const secret_key &key2, key_derivation &derivation) {
-    ge_p3 point;
-    ge_p2 point2;
-    ge_p1p1 point3;
-    assert(sc_check(&key2) == 0);
-    if (ge_frombytes_vartime(&point, &key1) != 0) {
-      return false;
-    }
-    ge_scalarmult(&point2, &key2, &point);
-    ge_mul8(&point3, &point2);
-    ge_p1p1_to_p2(&point2, &point3);
-    ge_tobytes(&derivation, &point2);
-    return true;
-  }
-
-  void crypto_ops::derivation_to_scalar(const key_derivation &derivation, size_t output_index, ec_scalar &res) {
-    struct {
-      key_derivation derivation;
-      char output_index[(sizeof(size_t) * 8 + 6) / 7];
-    } buf;
-    char *end = buf.output_index;
-    buf.derivation = derivation;
-    tools::write_varint(end, output_index);
-    assert(end <= buf.output_index + sizeof buf.output_index);
-    hash_to_scalar(&buf, end - reinterpret_cast<char *>(&buf), res);
-  }
-
-  bool crypto_ops::derive_public_key(const key_derivation &derivation, size_t output_index,
-    const public_key &base, public_key &derived_key) {
-    ec_scalar scalar;
-    ge_p3 point1;
-    ge_p3 point2;
-    ge_cached point3;
-    ge_p1p1 point4;
-    ge_p2 point5;
-    if (ge_frombytes_vartime(&point1, &base) != 0) {
-      return false;
-    }
-    derivation_to_scalar(derivation, output_index, scalar);
-    ge_scalarmult_base(&point2, &scalar);
-    ge_p3_to_cached(&point3, &point2);
-    ge_add(&point4, &point1, &point3);
-    ge_p1p1_to_p2(&point5, &point4);
-    ge_tobytes(&derived_key, &point5);
-    return true;
-  }
-
-  void crypto_ops::derive_secret_key(const key_derivation &derivation, size_t output_index,
-    const secret_key &base, secret_key &derived_key) {
-    ec_scalar scalar;
-    assert(sc_check(&base) == 0);
-    derivation_to_scalar(derivation, output_index, scalar);
-    sc_add(&derived_key, &base, &scalar);
-  }
-
-  bool crypto_ops::derive_subaddress_public_key(const public_key &out_key, const key_derivation &derivation, std::size_t output_index, public_key &derived_key) {
-    ec_scalar scalar;
-    ge_p3 point1;
-    ge_p3 point2;
-    ge_cached point3;
-    ge_p1p1 point4;
-    ge_p2 point5;
-    if (ge_frombytes_vartime(&point1, &out_key) != 0) {
-      return false;
-    }
-    derivation_to_scalar(derivation, output_index, scalar);
-    ge_scalarmult_base(&point2, &scalar);
-    ge_p3_to_cached(&point3, &point2);
-    ge_sub(&point4, &point1, &point3);
-    ge_p1p1_to_p2(&point5, &point4);
-    ge_tobytes(&derived_key, &point5);
-    return true;
-  }
-
-  struct s_comm {
-    hash h;
-    ec_point key;
-    ec_point comm;
-  };
-
-  struct s_comm_2 {
-    hash msg;
-    ec_point D;
-    ec_point X;
-    ec_point Y;
-  };
-
-  void crypto_ops::generate_signature(const hash &prefix_hash, const public_key &pub, const secret_key &sec, signature &sig) {
-    ge_p3 tmp3;
-    ec_scalar k;
-    s_comm buf;
-#if !defined(NDEBUG)
-    {
-      ge_p3 t;
-      public_key t2;
-      assert(sc_check(&sec) == 0);
-      ge_scalarmult_base(&t, &sec);
-      ge_p3_tobytes(&t2, &t);
-      assert(pub == t2);
-    }
-#endif
-    buf.h = prefix_hash;
-    buf.key = pub;
-    random_scalar(k);
-    ge_scalarmult_base(&tmp3, &k);
-    ge_p3_tobytes(&buf.comm, &tmp3);
-    hash_to_scalar(&buf, sizeof(s_comm), sig.c);
-    sc_mulsub(&sig.r, &sig.c, &sec, &k);
-  }
-
-  bool crypto_ops::check_signature(const hash &prefix_hash, const public_key &pub, const signature &sig) {
-    ge_p2 tmp2;
-    ge_p3 tmp3;
-    ec_scalar c;
-    s_comm buf;
-    assert(check_key(pub));
-    buf.h = prefix_hash;
-    buf.key = pub;
-    if (ge_frombytes_vartime(&tmp3, &pub) != 0) {
-      return false;
-    }
-    if (sc_check(&sig.c) != 0 || sc_check(&sig.r) != 0) {
-      return false;
-    }
-    ge_double_scalarmult_base_vartime(&tmp2, &sig.c, &tmp3, &sig.r);
-    ge_tobytes(&buf.comm, &tmp2);
-    hash_to_scalar(&buf, sizeof(s_comm), c);
-    sc_sub(&c, &c, &sig.c);
-    return sc_isnonzero(&c) == 0;
-  }
-
-  void crypto_ops::generate_tx_proof(const hash &prefix_hash, const public_key &R, const public_key &A, const boost::optional<public_key> &B, const public_key &D, const secret_key &r, signature &sig) {
-    // sanity check
-    ge_p3 R_p3;
-    ge_p3 A_p3;
-    ge_p3 B_p3;
-    ge_p3 D_p3;
-    if (ge_frombytes_vartime(&R_p3, &R) != 0) throw std::runtime_error("tx pubkey is invalid");
-    if (ge_frombytes_vartime(&A_p3, &A) != 0) throw std::runtime_error("recipient view pubkey is invalid");
-    if (B && ge_frombytes_vartime(&B_p3, &*B) != 0) throw std::runtime_error("recipient spend pubkey is invalid");
-    if (ge_frombytes_vartime(&D_p3, &D) != 0) throw std::runtime_error("key derivation is invalid");
-#if !defined(NDEBUG)
-    {
-      assert(sc_check(&r) == 0);
-      // check R == r*G or R == r*B
-      public_key dbg_R;
-      if (B)
-      {
-        ge_p2 dbg_R_p2;
-        ge_scalarmult(&dbg_R_p2, &r, &B_p3);
-        ge_tobytes(&dbg_R, &dbg_R_p2);
-      }
-      else
-      {
-        ge_p3 dbg_R_p3;
-        ge_scalarmult_base(&dbg_R_p3, &r);
-        ge_p3_tobytes(&dbg_R, &dbg_R_p3);
-      }
-      assert(R == dbg_R);
-      // check D == r*A
-      ge_p2 dbg_D_p2;
-      ge_scalarmult(&dbg_D_p2, &r, &A_p3);
-      public_key dbg_D;
-      ge_tobytes(&dbg_D, &dbg_D_p2);
-      assert(D == dbg_D);
-    }
-#endif
-
-    // pick random k
-    ec_scalar k;
-    random_scalar(k);
-    
-    s_comm_2 buf;
-    buf.msg = prefix_hash;
-    buf.D = D;
-
-    if (B)
-    {
-      // compute X = k*B
-      ge_p2 X_p2;
-      ge_scalarmult(&X_p2, &k, &B_p3);
-      ge_tobytes(&buf.X, &X_p2);
-    }
-    else
-    {
-      // compute X = k*G
-      ge_p3 X_p3;
-      ge_scalarmult_base(&X_p3, &k);
-      ge_p3_tobytes(&buf.X, &X_p3);
-    }
-    
-    // compute Y = k*A
-    ge_p2 Y_p2;
-    ge_scalarmult(&Y_p2, &k, &A_p3);
-    ge_tobytes(&buf.Y, &Y_p2);
-
-    // sig.c = Hs(Msg || D || X || Y)
-    hash_to_scalar(&buf, sizeof(buf), sig.c);
-
-    // sig.r = k - sig.c*r
-    sc_mulsub(&sig.r, &sig.c, &r, &k);
-  }
-
-  bool crypto_ops::check_tx_proof(const hash &prefix_hash, const public_key &R, const public_key &A, const boost::optional<public_key> &B, const public_key &D, const signature &sig) {
-    // sanity check
-    ge_p3 R_p3;
-    ge_p3 A_p3;
-    ge_p3 B_p3;
-    ge_p3 D_p3;
-    if (ge_frombytes_vartime(&R_p3, &R) != 0) return false;
-    if (ge_frombytes_vartime(&A_p3, &A) != 0) return false;
-    if (B && ge_frombytes_vartime(&B_p3, &*B) != 0) return false;
-    if (ge_frombytes_vartime(&D_p3, &D) != 0) return false;
-    if (sc_check(&sig.c) != 0 || sc_check(&sig.r) != 0) return false;
-
-    // compute sig.c*R
-    ge_p3 cR_p3;
-    {
-      ge_p2 cR_p2;
-      ge_scalarmult(&cR_p2, &sig.c, &R_p3);
-      public_key cR;
-      ge_tobytes(&cR, &cR_p2);
-      if (ge_frombytes_vartime(&cR_p3, &cR) != 0) return false;
-    }
-
-    ge_p1p1 X_p1p1;
-    if (B)
-    {
-      // compute X = sig.c*R + sig.r*B
-      ge_p2 rB_p2;
-      ge_scalarmult(&rB_p2, &sig.r, &B_p3);
-      public_key rB;
-      ge_tobytes(&rB, &rB_p2);
-      ge_p3 rB_p3;
-      if (ge_frombytes_vartime(&rB_p3, &rB) != 0) return false;
-      ge_cached rB_cached;
-      ge_p3_to_cached(&rB_cached, &rB_p3);
-      ge_add(&X_p1p1, &cR_p3, &rB_cached);
-    }
-    else
-    {
-      // compute X = sig.c*R + sig.r*G
-      ge_p3 rG_p3;
-      ge_scalarmult_base(&rG_p3, &sig.r);
-      ge_cached rG_cached;
-      ge_p3_to_cached(&rG_cached, &rG_p3);
-      ge_add(&X_p1p1, &cR_p3, &rG_cached);
-    }
-    ge_p2 X_p2;
-    ge_p1p1_to_p2(&X_p2, &X_p1p1);
-
-    // compute sig.c*D
-    ge_p2 cD_p2;
-    ge_scalarmult(&cD_p2, &sig.c, &D_p3);
-
-    // compute sig.r*A
-    ge_p2 rA_p2;
-    ge_scalarmult(&rA_p2, &sig.r, &A_p3);
-
-    // compute Y = sig.c*D + sig.r*A
-    public_key cD;
-    public_key rA;
-    ge_tobytes(&cD, &cD_p2);
-    ge_tobytes(&rA, &rA_p2);
-    ge_p3 cD_p3;
-    ge_p3 rA_p3;
-    if (ge_frombytes_vartime(&cD_p3, &cD) != 0) return false;
-    if (ge_frombytes_vartime(&rA_p3, &rA) != 0) return false;
-    ge_cached rA_cached;
-    ge_p3_to_cached(&rA_cached, &rA_p3);
-    ge_p1p1 Y_p1p1;
-    ge_add(&Y_p1p1, &cD_p3, &rA_cached);
-    ge_p2 Y_p2;
-    ge_p1p1_to_p2(&Y_p2, &Y_p1p1);
-
-    // compute c2 = Hs(Msg || D || X || Y)
-    s_comm_2 buf;
-    buf.msg = prefix_hash;
-    buf.D = D;
-    ge_tobytes(&buf.X, &X_p2);
-    ge_tobytes(&buf.Y, &Y_p2);
-    ec_scalar c2;
-    hash_to_scalar(&buf, sizeof(s_comm_2), c2);
-
-    // test if c2 == sig.c
-    sc_sub(&c2, &c2, &sig.c);
-    return sc_isnonzero(&c2) == 0;
-  }
-
-  static void hash_to_ec(const public_key &key, ge_p3 &res) {
-    hash h;
-    ge_p2 point;
-    ge_p1p1 point2;
-    cn_fast_hash(std::addressof(key), sizeof(public_key), h);
-    ge_fromfe_frombytes_vartime(&point, reinterpret_cast<const unsigned char *>(&h));
-    ge_mul8(&point2, &point);
-    ge_p1p1_to_p3(&res, &point2);
-  }
-
-  void crypto_ops::generate_key_image(const public_key &pub, const secret_key &sec, key_image &image) {
-    ge_p3 point;
-    ge_p2 point2;
-    assert(sc_check(&sec) == 0);
-    hash_to_ec(pub, point);
-    ge_scalarmult(&point2, &sec, &point);
-    ge_tobytes(&image, &point2);
-  }
-
-PUSH_WARNINGS
-DISABLE_VS_WARNINGS(4200)
-  struct ec_point_pair {
-    ec_point a, b;
-  };
-  struct rs_comm {
-    hash h;
-    struct ec_point_pair ab[];
-  };
-POP_WARNINGS
-
-  static inline size_t rs_comm_size(size_t pubs_count) {
-    return sizeof(rs_comm) + pubs_count * sizeof(ec_point_pair);
-  }
-
-  void crypto_ops::generate_ring_signature(const hash &prefix_hash, const key_image &image,
-    const public_key *const *pubs, size_t pubs_count,
-    const secret_key &sec, size_t sec_index,
-    signature *sig) {
-    size_t i;
-    ge_p3 image_unp;
-    ge_dsmp image_pre;
-    ec_scalar sum, k, h;
-    boost::shared_ptr<rs_comm> buf(reinterpret_cast<rs_comm *>(malloc(rs_comm_size(pubs_count))), free);
-    if (!buf)
-      abort();
-    assert(sec_index < pubs_count);
-#if !defined(NDEBUG)
-    {
-      ge_p3 t;
-      public_key t2;
-      key_image t3;
-      assert(sc_check(&sec) == 0);
-      ge_scalarmult_base(&t, &sec);
-      ge_p3_tobytes(&t2, &t);
-      assert(*pubs[sec_index] == t2);
-      generate_key_image(*pubs[sec_index], sec, t3);
-      assert(image == t3);
-      for (i = 0; i < pubs_count; i++) {
-        assert(check_key(*pubs[i]));
-      }
-    }
-#endif
-    if (ge_frombytes_vartime(&image_unp, &image) != 0) {
-      abort();
-    }
-    ge_dsm_precomp(image_pre, &image_unp);
-    sc_0(&sum);
-    buf->h = prefix_hash;
-    for (i = 0; i < pubs_count; i++) {
-      ge_p2 tmp2;
-      ge_p3 tmp3;
-      if (i == sec_index) {
-        random_scalar(k);
-        ge_scalarmult_base(&tmp3, &k);
-        ge_p3_tobytes(&buf->ab[i].a, &tmp3);
-        hash_to_ec(*pubs[i], tmp3);
-        ge_scalarmult(&tmp2, &k, &tmp3);
-        ge_tobytes(&buf->ab[i].b, &tmp2);
-      } else {
-        random_scalar(sig[i].c);
-        random_scalar(sig[i].r);
-        if (ge_frombytes_vartime(&tmp3, &*pubs[i]) != 0) {
-          abort();
-        }
-        ge_double_scalarmult_base_vartime(&tmp2, &sig[i].c, &tmp3, &sig[i].r);
-        ge_tobytes(&buf->ab[i].a, &tmp2);
-        hash_to_ec(*pubs[i], tmp3);
-        ge_double_scalarmult_precomp_vartime(&tmp2, &sig[i].r, &tmp3, &sig[i].c, image_pre);
-        ge_tobytes(&buf->ab[i].b, &tmp2);
-        sc_add(&sum, &sum, &sig[i].c);
-      }
-    }
-    hash_to_scalar(buf.get(), rs_comm_size(pubs_count), h);
-    sc_sub(&sig[sec_index].c, &h, &sum);
-    sc_mulsub(&sig[sec_index].r, &sig[sec_index].c, &sec, &k);
-  }
-
-  bool crypto_ops::check_ring_signature(const hash &prefix_hash, const key_image &image,
-    const public_key *const *pubs, size_t pubs_count,
-    const signature *sig) {
-    size_t i;
-    ge_p3 image_unp;
-    ge_dsmp image_pre;
-    ec_scalar sum, h;
-    boost::shared_ptr<rs_comm> buf(reinterpret_cast<rs_comm *>(malloc(rs_comm_size(pubs_count))), free);
-    if (!buf)
-      return false;
-#if !defined(NDEBUG)
-    for (i = 0; i < pubs_count; i++) {
-      assert(check_key(*pubs[i]));
-    }
-#endif
-    if (ge_frombytes_vartime(&image_unp, &image) != 0) {
-      return false;
-    }
-    ge_dsm_precomp(image_pre, &image_unp);
-    sc_0(&sum);
-    buf->h = prefix_hash;
-    for (i = 0; i < pubs_count; i++) {
-      ge_p2 tmp2;
-      ge_p3 tmp3;
-      if (sc_check(&sig[i].c) != 0 || sc_check(&sig[i].r) != 0) {
-        return false;
-      }
-      if (ge_frombytes_vartime(&tmp3, &*pubs[i]) != 0) {
-        return false;
-      }
-      ge_double_scalarmult_base_vartime(&tmp2, &sig[i].c, &tmp3, &sig[i].r);
-      ge_tobytes(&buf->ab[i].a, &tmp2);
-      hash_to_ec(*pubs[i], tmp3);
-      ge_double_scalarmult_precomp_vartime(&tmp2, &sig[i].r, &tmp3, &sig[i].c, image_pre);
-      ge_tobytes(&buf->ab[i].b, &tmp2);
-      sc_add(&sum, &sum, &sig[i].c);
-    }
-    hash_to_scalar(buf.get(), rs_comm_size(pubs_count), h);
-    sc_sub(&h, &h, &sum);
-    return sc_isnonzero(&h) == 0;
-  }
-}
diff --git a/crypt/monero_crypto/crypto.h b/crypt/monero_crypto/crypto.h
deleted file mode 100644
index 0ce5e6d7a9..0000000000
--- a/crypt/monero_crypto/crypto.h
+++ /dev/null
@@ -1,289 +0,0 @@
-// Copyright (c) 2014-2017, The Monero Project
-// 
-// All rights reserved.
-// 
-// Redistribution and use in source and binary forms, with or without modification, are
-// permitted provided that the following conditions are met:
-// 
-// 1. Redistributions of source code must retain the above copyright notice, this list of
-//    conditions and the following disclaimer.
-// 
-// 2. Redistributions in binary form must reproduce the above copyright notice, this list
-//    of conditions and the following disclaimer in the documentation and/or other
-//    materials provided with the distribution.
-// 
-// 3. Neither the name of the copyright holder nor the names of its contributors may be
-//    used to endorse or promote products derived from this software without specific
-//    prior written permission.
-// 
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
-// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
-// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
-// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
-// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-// 
-// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
-
-#pragma once
-
-#include <cstddef>
-#include <iostream>
-#include <boost/thread/mutex.hpp>
-#include <boost/thread/lock_guard.hpp>
-#include <boost/utility/value_init.hpp>
-#include <boost/optional.hpp>
-#include <type_traits>
-#include <vector>
-
-#include "common/pod-class.h"
-#include "common/util.h"
-#include "common/memwipe.h"
-#include "generic-ops.h"
-#include "hex.h"
-#include "span.h"
-#include "hash.h"
-
-namespace crypto {
-
-  extern "C" {
-#include "random.h"
-  }
-
-  extern boost::mutex random_lock;
-
-#pragma pack(push, 1)
-  POD_CLASS ec_point {
-    char data[32];
-  };
-
-  POD_CLASS ec_scalar {
-    char data[32];
-  };
-
-  POD_CLASS public_key: ec_point {
-    friend class crypto_ops;
-  };
-
-  using secret_key = tools::scrubbed<ec_scalar>;
-
-  POD_CLASS public_keyV {
-    std::vector<public_key> keys;
-    int rows;
-  };
-
-  POD_CLASS secret_keyV {
-    std::vector<secret_key> keys;
-    int rows;
-  };
-
-  POD_CLASS public_keyM {
-    int cols;
-    int rows;
-    std::vector<secret_keyV> column_vectors;
-  };
-
-  POD_CLASS key_derivation: ec_point {
-    friend class crypto_ops;
-  };
-
-  POD_CLASS key_image: ec_point {
-    friend class crypto_ops;
-  };
-
-  POD_CLASS signature {
-    ec_scalar c, r;
-    friend class crypto_ops;
-  };
-#pragma pack(pop)
-
-  void hash_to_scalar(const void *data, size_t length, ec_scalar &res);
-
-  static_assert(sizeof(ec_point) == 32 && sizeof(ec_scalar) == 32 &&
-    sizeof(public_key) == 32 && sizeof(secret_key) == 32 &&
-    sizeof(key_derivation) == 32 && sizeof(key_image) == 32 &&
-    sizeof(signature) == 64, "Invalid structure size");
-
-  class crypto_ops {
-    crypto_ops();
-    crypto_ops(const crypto_ops &);
-    void operator=(const crypto_ops &);
-    ~crypto_ops();
-
-    static secret_key generate_keys(public_key &pub, secret_key &sec, const secret_key& recovery_key = secret_key(), bool recover = false);
-    friend secret_key generate_keys(public_key &pub, secret_key &sec, const secret_key& recovery_key, bool recover);
-    static bool check_key(const public_key &);
-    friend bool check_key(const public_key &);
-    static bool secret_key_to_public_key(const secret_key &, public_key &);
-    friend bool secret_key_to_public_key(const secret_key &, public_key &);
-    static bool generate_key_derivation(const public_key &, const secret_key &, key_derivation &);
-    friend bool generate_key_derivation(const public_key &, const secret_key &, key_derivation &);
-    static void derivation_to_scalar(const key_derivation &derivation, size_t output_index, ec_scalar &res);
-    friend void derivation_to_scalar(const key_derivation &derivation, size_t output_index, ec_scalar &res);
-    static bool derive_public_key(const key_derivation &, std::size_t, const public_key &, public_key &);
-    friend bool derive_public_key(const key_derivation &, std::size_t, const public_key &, public_key &);
-    static void derive_secret_key(const key_derivation &, std::size_t, const secret_key &, secret_key &);
-    friend void derive_secret_key(const key_derivation &, std::size_t, const secret_key &, secret_key &);
-    static bool derive_subaddress_public_key(const public_key &, const key_derivation &, std::size_t, public_key &);
-    friend bool derive_subaddress_public_key(const public_key &, const key_derivation &, std::size_t, public_key &);
-    static void generate_signature(const hash &, const public_key &, const secret_key &, signature &);
-    friend void generate_signature(const hash &, const public_key &, const secret_key &, signature &);
-    static bool check_signature(const hash &, const public_key &, const signature &);
-    friend bool check_signature(const hash &, const public_key &, const signature &);
-    static void generate_tx_proof(const hash &, const public_key &, const public_key &, const boost::optional<public_key> &, const public_key &, const secret_key &, signature &);
-    friend void generate_tx_proof(const hash &, const public_key &, const public_key &, const boost::optional<public_key> &, const public_key &, const secret_key &, signature &);
-    static bool check_tx_proof(const hash &, const public_key &, const public_key &, const boost::optional<public_key> &, const public_key &, const signature &);
-    friend bool check_tx_proof(const hash &, const public_key &, const public_key &, const boost::optional<public_key> &, const public_key &, const signature &);
-    static void generate_key_image(const public_key &, const secret_key &, key_image &);
-    friend void generate_key_image(const public_key &, const secret_key &, key_image &);
-    static void generate_ring_signature(const hash &, const key_image &,
-      const public_key *const *, std::size_t, const secret_key &, std::size_t, signature *);
-    friend void generate_ring_signature(const hash &, const key_image &,
-      const public_key *const *, std::size_t, const secret_key &, std::size_t, signature *);
-    static bool check_ring_signature(const hash &, const key_image &,
-      const public_key *const *, std::size_t, const signature *);
-    friend bool check_ring_signature(const hash &, const key_image &,
-      const public_key *const *, std::size_t, const signature *);
-  };
-
-  /* Generate N random bytes
-   */
-  inline void rand(size_t N, uint8_t *bytes) {
-    boost::lock_guard<boost::mutex> lock(random_lock);
-    generate_random_bytes_not_thread_safe(N, bytes);
-  }
-
-  /* Generate a value filled with random bytes.
-   */
-  template<typename T>
-  typename std::enable_if<std::is_pod<T>::value, T>::type rand() {
-    typename std::remove_cv<T>::type res;
-    boost::lock_guard<boost::mutex> lock(random_lock);
-    generate_random_bytes_not_thread_safe(sizeof(T), &res);
-    return res;
-  }
-
-  /* Generate a new key pair
-   */
-  inline secret_key generate_keys(public_key &pub, secret_key &sec, const secret_key& recovery_key = secret_key(), bool recover = false) {
-    return crypto_ops::generate_keys(pub, sec, recovery_key, recover);
-  }
-
-  /* Check a public key. Returns true if it is valid, false otherwise.
-   */
-  inline bool check_key(const public_key &key) {
-    return crypto_ops::check_key(key);
-  }
-
-  /* Checks a private key and computes the corresponding public key.
-   */
-  inline bool secret_key_to_public_key(const secret_key &sec, public_key &pub) {
-    return crypto_ops::secret_key_to_public_key(sec, pub);
-  }
-
-  /* To generate an ephemeral key used to send money to:
-   * * The sender generates a new key pair, which becomes the transaction key. The public transaction key is included in "extra" field.
-   * * Both the sender and the receiver generate key derivation from the transaction key, the receivers' "view" key and the output index.
-   * * The sender uses key derivation and the receivers' "spend" key to derive an ephemeral public key.
-   * * The receiver can either derive the public key (to check that the transaction is addressed to him) or the private key (to spend the money).
-   */
-  inline bool generate_key_derivation(const public_key &key1, const secret_key &key2, key_derivation &derivation) {
-    return crypto_ops::generate_key_derivation(key1, key2, derivation);
-  }
-  inline bool derive_public_key(const key_derivation &derivation, std::size_t output_index,
-    const public_key &base, public_key &derived_key) {
-    return crypto_ops::derive_public_key(derivation, output_index, base, derived_key);
-  }
-  inline void derivation_to_scalar(const key_derivation &derivation, size_t output_index, ec_scalar &res) {
-    return crypto_ops::derivation_to_scalar(derivation, output_index, res);
-  }
-  inline void derive_secret_key(const key_derivation &derivation, std::size_t output_index,
-    const secret_key &base, secret_key &derived_key) {
-    crypto_ops::derive_secret_key(derivation, output_index, base, derived_key);
-  }
-  inline bool derive_subaddress_public_key(const public_key &out_key, const key_derivation &derivation, std::size_t output_index, public_key &result) {
-    return crypto_ops::derive_subaddress_public_key(out_key, derivation, output_index, result);
-  }
-
-  /* Generation and checking of a standard signature.
-   */
-  inline void generate_signature(const hash &prefix_hash, const public_key &pub, const secret_key &sec, signature &sig) {
-    crypto_ops::generate_signature(prefix_hash, pub, sec, sig);
-  }
-  inline bool check_signature(const hash &prefix_hash, const public_key &pub, const signature &sig) {
-    return crypto_ops::check_signature(prefix_hash, pub, sig);
-  }
-
-  /* Generation and checking of a tx proof; given a tx pubkey R, the recipient's view pubkey A, and the key 
-   * derivation D, the signature proves the knowledge of the tx secret key r such that R=r*G and D=r*A
-   * When the recipient's address is a subaddress, the tx pubkey R is defined as R=r*B where B is the recipient's spend pubkey
-   */
-  inline void generate_tx_proof(const hash &prefix_hash, const public_key &R, const public_key &A, const boost::optional<public_key> &B, const public_key &D, const secret_key &r, signature &sig) {
-    crypto_ops::generate_tx_proof(prefix_hash, R, A, B, D, r, sig);
-  }
-  inline bool check_tx_proof(const hash &prefix_hash, const public_key &R, const public_key &A, const boost::optional<public_key> &B, const public_key &D, const signature &sig) {
-    return crypto_ops::check_tx_proof(prefix_hash, R, A, B, D, sig);
-  }
-
-  /* To send money to a key:
-   * * The sender generates an ephemeral key and includes it in transaction output.
-   * * To spend the money, the receiver generates a key image from it.
-   * * Then he selects a bunch of outputs, including the one he spends, and uses them to generate a ring signature.
-   * To check the signature, it is necessary to collect all the keys that were used to generate it. To detect double spends, it is necessary to check that each key image is used at most once.
-   */
-  inline void generate_key_image(const public_key &pub, const secret_key &sec, key_image &image) {
-    crypto_ops::generate_key_image(pub, sec, image);
-  }
-  inline void generate_ring_signature(const hash &prefix_hash, const key_image &image,
-    const public_key *const *pubs, std::size_t pubs_count,
-    const secret_key &sec, std::size_t sec_index,
-    signature *sig) {
-    crypto_ops::generate_ring_signature(prefix_hash, image, pubs, pubs_count, sec, sec_index, sig);
-  }
-  inline bool check_ring_signature(const hash &prefix_hash, const key_image &image,
-    const public_key *const *pubs, std::size_t pubs_count,
-    const signature *sig) {
-    return crypto_ops::check_ring_signature(prefix_hash, image, pubs, pubs_count, sig);
-  }
-
-  /* Variants with vector<const public_key *> parameters.
-   */
-  inline void generate_ring_signature(const hash &prefix_hash, const key_image &image,
-    const std::vector<const public_key *> &pubs,
-    const secret_key &sec, std::size_t sec_index,
-    signature *sig) {
-    generate_ring_signature(prefix_hash, image, pubs.data(), pubs.size(), sec, sec_index, sig);
-  }
-  inline bool check_ring_signature(const hash &prefix_hash, const key_image &image,
-    const std::vector<const public_key *> &pubs,
-    const signature *sig) {
-    return check_ring_signature(prefix_hash, image, pubs.data(), pubs.size(), sig);
-  }
-
-  inline std::ostream &operator <<(std::ostream &o, const crypto::public_key &v) {
-    epee::to_hex::formatted(o, epee::as_byte_span(v)); return o;
-  }
-  inline std::ostream &operator <<(std::ostream &o, const crypto::secret_key &v) {
-    epee::to_hex::formatted(o, epee::as_byte_span(v)); return o;
-  }
-  inline std::ostream &operator <<(std::ostream &o, const crypto::key_derivation &v) {
-    epee::to_hex::formatted(o, epee::as_byte_span(v)); return o;
-  }
-  inline std::ostream &operator <<(std::ostream &o, const crypto::key_image &v) {
-    epee::to_hex::formatted(o, epee::as_byte_span(v)); return o;
-  }
-  inline std::ostream &operator <<(std::ostream &o, const crypto::signature &v) {
-    epee::to_hex::formatted(o, epee::as_byte_span(v)); return o;
-  }
-
-  const static crypto::public_key null_pkey = boost::value_initialized<crypto::public_key>();
-  const static crypto::secret_key null_skey = boost::value_initialized<crypto::secret_key>();
-}
-
-CRYPTO_MAKE_HASHABLE(public_key)
-CRYPTO_MAKE_HASHABLE(secret_key)
-CRYPTO_MAKE_HASHABLE(key_image)
-CRYPTO_MAKE_COMPARABLE(signature)
diff --git a/crypt/monero_crypto/warnings.h b/crypt/monero_crypto/warnings.h
new file mode 100644
index 0000000000..196434db13
--- /dev/null
+++ b/crypt/monero_crypto/warnings.h
@@ -0,0 +1,33 @@
+#ifndef _WARNINGS_H_
+#define _WARNINGS_H_
+
+#if defined(_MSC_VER)
+
+#define PUSH_WARNINGS __pragma(warning(push))
+#define POP_WARNINGS __pragma(warning(pop))
+#define DISABLE_VS_WARNINGS(w) __pragma(warning(disable: w))
+#define DISABLE_GCC_WARNING(w)
+#define DISABLE_CLANG_WARNING(w)
+#define DISABLE_GCC_AND_CLANG_WARNING(w)
+
+#else
+
+#include <boost/preprocessor/stringize.hpp>
+
+#define PUSH_WARNINGS _Pragma("GCC diagnostic push")
+#define POP_WARNINGS _Pragma("GCC diagnostic pop")
+#define DISABLE_VS_WARNINGS(w)
+
+#if defined(__clang__)
+#define DISABLE_GCC_WARNING(w)
+#define DISABLE_CLANG_WARNING DISABLE_GCC_AND_CLANG_WARNING
+#else
+#define DISABLE_GCC_WARNING DISABLE_GCC_AND_CLANG_WARNING
+#define DISABLE_CLANG_WARNING(w)
+#endif
+
+#define DISABLE_GCC_AND_CLANG_WARNING(w) _Pragma(BOOST_PP_STRINGIZE(GCC diagnostic ignored BOOST_PP_STRINGIZE(-W##w)))
+
+#endif
+
+#endif
diff --git a/http/CMakeLists.txt b/http/CMakeLists.txt
index 949cee38a0..f91259352c 100644
--- a/http/CMakeLists.txt
+++ b/http/CMakeLists.txt
@@ -1,9 +1,13 @@
 cmake_minimum_required(VERSION 2.8)
-project (daphttp)
+project (dap_http)
   
 set(HTTP_SRCS dap_http_client.c dap_http_header.c)
  
 add_library(${PROJECT_NAME} STATIC ${HTTP_SRCS})
+include_directories("${dap_core_INCLUDE_DIRS}")
+add_definitions ("${dap_core_DEFINITIONS}")
+include_directories("${dap_client_INCLUDE_DIRS}")
+add_definitions ("${dap_client_DEFINITIONS}")
 
 set(${PROJECT_NAME}_DEFINITIONS CACHE INTERNAL "${PROJECT_NAME}: Definitions" FORCE)
 
diff --git a/http/dap_http_client.c b/http/dap_http_client.c
index 79d621cbc2..d3947dbdfd 100644
--- a/http/dap_http_client.c
+++ b/http/dap_http_client.c
@@ -20,12 +20,17 @@
 
 
 #include <stdio.h>
+#include <string.h>
 #include <ctype.h>
 #include <libgen.h>
-#include "common.h"
-#include "dap_client.h"
+#include "dap_common.h"
+#include "dap_client_remote.h"
+
+#ifdef DAP_SERVER
 #include "dap_server.h"
 #include "dap_http.h"
+#endif
+#include "dap_http_header.h"
 #include "dap_http_client.h"
 
 #define LOG_TAG "http_client"
@@ -40,7 +45,7 @@ void dap_http_client_out_header_generate(dap_http_client_t *cl_ht);
  */
 int dap_http_client_init()
 {
-    log_it(NOTICE,"Initialized HTTP client module");
+    log_it(L_NOTICE,"Initialized HTTP client module");
     return 0;
 }
 
@@ -49,7 +54,7 @@ int dap_http_client_init()
  */
 void dap_http_client_deinit()
 {
-    log_it(INFO,"HTTP client module deinit");
+    log_it(L_INFO,"HTTP client module deinit");
 }
 
 /**
@@ -57,13 +62,15 @@ void dap_http_client_deinit()
  * @param cl HTTP Client instance
  * @param arg Additional argument (usualy not used)
  */
-void dap_http_client_new(dap_client_t * cl,void * arg)
+void dap_http_client_new(dap_client_remote_t * cl,void * arg)
 {
     (void) arg;
-    cl->internal=calloc(1,sizeof(dap_http_client_t));
+    cl->_inheritor = DAP_NEW_Z(dap_http_client_t);
     dap_http_client_t * cl_ht=DAP_HTTP_CLIENT(cl);
     cl_ht->client=cl;
+#ifdef DAP_SERVER
     cl_ht->http= DAP_HTTP(cl->server);
+#endif
     cl_ht->state_read=DAP_HTTP_CLIENT_STATE_START;
     cl_ht->state_write=DAP_HTTP_CLIENT_STATE_NONE;
 
@@ -74,7 +81,7 @@ void dap_http_client_new(dap_client_t * cl,void * arg)
  * @param cl HTTP Client instance
  * @param arg Additional argument (usualy not used)
  */
-void dap_http_client_delete(dap_client_t * cl,void * arg)
+void dap_http_client_delete(dap_client_remote_t * cl,void * arg)
 {
     dap_http_client_t * cl_ht=DAP_HTTP_CLIENT(cl);
     while(cl_ht->in_headers)
@@ -83,12 +90,14 @@ void dap_http_client_delete(dap_client_t * cl,void * arg)
     while(cl_ht->out_headers)
         dap_http_header_remove(&cl_ht->out_headers,cl_ht->out_headers);
 
+#ifdef DAP_SERVER
     if(cl_ht->proc)
         if(cl_ht->proc->delete_callback)
             cl_ht->proc->delete_callback(cl_ht,NULL);
+#endif
 
-    if(cl_ht->internal)
-        free(cl_ht->internal);
+    if(cl_ht->_inheritor)
+        free(cl_ht->_inheritor);
     (void) arg;
 }
 
@@ -158,7 +167,7 @@ bool dap_http_request_line_parse(dap_http_client_t * cl_ht, char * buf, size_t b
  * @param cl HTTP Client instance
  * @param arg Additional argument (usualy not used)
  */
-void dap_http_client_read(dap_client_t * cl,void * arg)
+void dap_http_client_read(dap_client_remote_t * cl,void * arg)
 {
 
     (void) arg;
@@ -204,7 +213,7 @@ cnt:switch(cl_ht->state_read){
                     b_name=basename(url_cpy2);
 
                     strncpy(cl_ht->url_path,b_name,sizeof(cl_ht->url_path));
-
+#ifdef DAP_SERVER
                     dap_http_url_proc_t * url_proc;
 
                     HASH_FIND_STR(cl_ht->http->url_proc, d_name , url_proc);  // Find URL processor
@@ -226,6 +235,9 @@ cnt:switch(cl_ht->state_read){
                         free(url_cpy2);
                         break;
                     }
+#else
+                    cl_ht->state_read=DAP_HTTP_CLIENT_STATE_HEADERS;
+#endif
                     //free(d_name);
                     //free(b_name);
                     free(url_cpy1);
diff --git a/http/dap_http_client.h b/http/dap_http_client.h
index 5dcc0aa1d2..4402ea73ea 100644
--- a/http/dap_http_client.h
+++ b/http/dap_http_client.h
@@ -25,7 +25,7 @@
 #include <stdint.h>
 #include <time.h>
 #include <stdbool.h>
-struct dap_client;
+typedef struct dap_client_remote dap_client_remote_t;
 struct dap_http_client;
 struct dap_http;
 struct dap_http_url_proc;
@@ -65,7 +65,7 @@ typedef struct dap_http_client
     bool out_connection_close;
 
 
-    struct dap_client * client;
+    dap_client_remote_t * client;
     struct dap_http * http;
 
     uint32_t reply_status_code;
@@ -73,21 +73,30 @@ typedef struct dap_http_client
 
     struct dap_http_url_proc * proc;
 
-    void * internal;
+    void * _inheritor;
 
 } dap_http_client_t;
-#define DAP_HTTP_CLIENT(a)  ((dap_http_client_t *) (a)->internal )
 
-extern int dap_http_client_init();
-extern void dap_http_client_deinit();
+#define DAP_HTTP_CLIENT(a)  ((dap_http_client_t *) (a)->_inheritor )
 
 
-extern void dap_http_client_new(struct dap_client * cl,void * arg); // Creates HTTP client's internal structure
-extern void dap_http_client_delete(struct dap_client * cl,void * arg); // Free memory for HTTP client's internal structure
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int dap_http_client_init();
+void dap_http_client_deinit();
+
 
-extern void dap_http_client_read(struct dap_client * cl,void * arg); // Process read event
-extern void dap_http_client_write(struct dap_client * cl,void * arg); // Process write event
-extern void dap_http_client_error(struct dap_client * cl,void * arg); // Process error event
+void dap_http_client_new(dap_client_remote_t * cl,void * arg); // Creates HTTP client's internal structure
+void dap_http_client_delete(dap_client_remote_t * cl,void * arg); // Free memory for HTTP client's internal structure
 
+void dap_http_client_read( dap_client_remote_t * cl,void * arg); // Process read event
+void dap_http_client_write( dap_client_remote_t * cl,void * arg); // Process write event
+void dap_http_client_error( dap_client_remote_t * cl,void * arg); // Process error event
+
+#ifdef __cplusplus
+}
+#endif
 
 #endif
-- 
GitLab