aboutsummaryrefslogtreecommitdiffstats
path: root/shared/librelational_engine
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--shared/librelational_engine/CMakeLists.txt (renamed from CMakeLists.txt)10
-rw-r--r--shared/librelational_engine/flake.nix0
-rw-r--r--shared/librelational_engine/library.cpp30
-rw-r--r--shared/librelational_engine/library.h9
4 files changed, 42 insertions, 7 deletions
diff --git a/CMakeLists.txt b/shared/librelational_engine/CMakeLists.txt
index 98dbfc4..d22d0d0 100644
--- a/CMakeLists.txt
+++ b/shared/librelational_engine/CMakeLists.txt
@@ -1,16 +1,12 @@
cmake_minimum_required(VERSION 3.29)
-project(relational_engine_ocaml)
-
-set(CMAKE_CXX_STANDARD 20)
+project(relational_engine)
include_directories($ENV{LIBRESSL_INCLUDE_PATH})
include_directories($ENV{MERKLECPP_INCLUDE_PATH})
-include_directories($ENV{CAML_INCLUDE_PATH})
-add_library(relational_engine_ocaml STATIC
- lib/merklecpp_stubs.cpp)
+add_library(relational_engine SHARED library.cpp)
-target_link_libraries(relational_engine_ocaml
+target_link_libraries(relational_engine
$ENV{LIBRESSL_LIB_PATH}/libssl.$ENV{OS_LIB_EXTENSION}
$ENV{LIBRESSL_LIB_PATH}/libcrypto.$ENV{OS_LIB_EXTENSION}
) \ No newline at end of file
diff --git a/shared/librelational_engine/flake.nix b/shared/librelational_engine/flake.nix
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/shared/librelational_engine/flake.nix
diff --git a/shared/librelational_engine/library.cpp b/shared/librelational_engine/library.cpp
new file mode 100644
index 0000000..8048486
--- /dev/null
+++ b/shared/librelational_engine/library.cpp
@@ -0,0 +1,30 @@
+#include <iostream>
+#include <merklecpp.h>
+#include <openssl/sha.h>
+#include <iomanip>
+extern "C" {
+#include "library.h"
+ extern void merkle_generate_root(char** hashes, const int n, char* root) {
+ merkle::Tree tree;
+ for (int i = 0; i < n; i++){
+ tree.insert(merkle::Hash(hashes[i]));
+ }
+ std::memcpy(root, tree.root().to_string().c_str(), HASH_SIZE);
+ }
+ extern void compute_hash(char* computed_hash, const char *content) {
+
+ unsigned char hash[SHA256_DIGEST_LENGTH];
+ SHA256_CTX sha256;
+ SHA256_Init(&sha256);
+ SHA256_Update(&sha256, content, sizeof(content));
+ SHA256_Final(hash, &sha256);
+ std::stringstream ss;
+ for (int i = 0; i < SHA256_DIGEST_LENGTH; i++)
+ ss << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(hash[i]);
+
+ std::memcpy(computed_hash, ss.str().c_str(), HASH_SIZE);
+ std::cout << "⚙️ COMPUTED HASH: " << computed_hash << std::endl;
+ }
+
+ extern int trash() { return 100; }
+} \ No newline at end of file
diff --git a/shared/librelational_engine/library.h b/shared/librelational_engine/library.h
new file mode 100644
index 0000000..ebf8497
--- /dev/null
+++ b/shared/librelational_engine/library.h
@@ -0,0 +1,9 @@
+#ifndef MERKLECPP_STUB_LIBRARY_H
+#define MERKLECPP_STUB_LIBRARY_H
+
+#define HASH_SIZE 64
+
+extern void merkle_generate_root(char**, const int, char*);
+extern void compute_hash(char*, const char*);
+
+#endif //MERKLECPP_STUB_LIBRARY_H