Skip to content

Commit 99e0195

Browse files
HSM: Add map for signing and verifying
1 parent 2914204 commit 99e0195

6 files changed

Lines changed: 245 additions & 137 deletions

File tree

hsm-server/CMakeLists.txt

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
cmake_minimum_required(VERSION 3.10)
22
# Set the project name
33
project(grpc_server)
4+
45
# Find GMP library
56
find_path(GMP_INCLUDE_DIR NAMES gmp.h)
67
find_library(GMP_LIBRARY NAMES gmp)
@@ -10,25 +11,30 @@ if(NOT GMP_INCLUDE_DIR OR NOT GMP_LIBRARY OR NOT GMPXX_LIBRARY)
1011
endif()
1112
include_directories(${GMP_INCLUDE_DIR})
1213
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
14+
1315
# Specify C++ standard
1416
set(CMAKE_CXX_STANDARD 17)
1517
set(CMAKE_CXX_STANDARD_REQUIRED ON)
18+
1619
# Find Protobuf and gRPC packages
1720
find_package(Protobuf REQUIRED)
1821
find_package(gRPC REQUIRED)
22+
1923
# Gather all source files in src directory
20-
file(GLOB SOURCES "src/*.cpp" )
24+
file(GLOB SOURCES "src/*.cpp")
25+
2126
# Specify the path to the proto files
2227
set(PROTO_FILES
2328
${CMAKE_SOURCE_DIR}/proto/encryption.proto
2429
)
30+
2531
# Paths to the protoc and grpc_cpp_plugin binaries
2632
set(PROTOC_PATH "/usr/local/bin/protoc")
2733
set(GRPC_CPP_PLUGIN_PATH "/usr/local/bin/grpc_cpp_plugin")
34+
2835
# Specify output directory for generated files
29-
# set(PROTO_GEN_DIR "${CMAKE_BINARY_DIR}/generated")
3036
set(PROTO_GEN_DIR ${CMAKE_CURRENT_BINARY_DIR})
31-
# file(MAKE_DIRECTORY ${PROTO_GEN_DIR})
37+
3238
# Generate C++ source files from proto files
3339
foreach(proto_file ${PROTO_FILES})
3440
get_filename_component(proto_name ${proto_file} NAME_WE)
@@ -52,27 +58,35 @@ foreach(proto_file ${PROTO_FILES})
5258
list(APPEND PROTO_SRCS ${PROTO_GEN_DIR}/${proto_name}.pb.cc ${PROTO_GEN_DIR}/${proto_name}.grpc.pb.cc)
5359
list(APPEND PROTO_HDRS ${PROTO_GEN_DIR}/${proto_name}.pb.h ${PROTO_GEN_DIR}/${proto_name}.grpc.pb.h)
5460
endforeach()
61+
5562
# Include the generated files directory
5663
include_directories(${PROTO_GEN_DIR})
64+
5765
# Include directories for protobuf and gRPC
5866
include_directories(${Protobuf_INCLUDE_DIRS} ${GRPC_INCLUDE_DIRS})
5967

6068
# Add the logger library
6169
file(GLOB LOGGER_SOURCES "logger/*.cpp")
6270
add_library(logger STATIC ${LOGGER_SOURCES})
71+
6372
# Add the executable
6473
add_executable(grpc_server src/my_logger.cpp ${SOURCES} ${PROTO_SRCS})
74+
6575
# Link against protobuf, gRPC, GMP, and logger libraries
6676
target_link_libraries(grpc_server ${Protobuf_LIBRARIES} ${GMP_LIBRARY} ${GMPXX_LIBRARY} gRPC::grpc++ logger)
77+
6778
# Ensure that protobuf and gRPC code generation is properly configured
6879
add_custom_target(proto_gen ALL
6980
DEPENDS ${PROTO_SRCS} ${PROTO_HDRS}
7081
COMMENT "Generating protobuf and gRPC code"
7182
)
83+
7284
# Add dependencies to ensure proper build order
7385
add_dependencies(grpc_server proto_gen)
74-
# Set build type to Debug
75-
set(CMAKE_BUILD_TYPE Debug)
76-
# Add debug flags
77-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
78-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
86+
87+
# Set build type to Release for optimizations
88+
set(CMAKE_BUILD_TYPE Release)
89+
90+
# Set optimization flags for Release mode
91+
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3")
92+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")

hsm-server/include/crypto_api.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414

1515
int getCountFromEncryptions(int userID);
1616
int getCountFromDecryptions(int userID);
17-
int getCountFromHashing(int userID);
17+
int getCountFromSigning(int userID);
18+
int getCountFromVerifying(int userID);
1819
CK_RV bootSystem(
1920
const std::map<int, std::vector<KeyPermission>> &usersIdspermissions);
2021
// generate key pair to each coponnet cinfigure the

hsm-server/include/debug_utils.h

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <chrono>
55
#include <iostream>
66
#include <string>
7+
#include <fstream>
8+
#include <ctime>
79
#include "general.h"
810

911
#define START_TIMER \
@@ -19,10 +21,24 @@ void printBufferHexa(const uint8_t *buffer, size_t len, std::string message);
1921
void debugLog(const std::string &message,
2022
const std::string &functionName); // Macro for easier use
2123
#define DEBUG_LOG(msg) debugLog(msg, __func__)
22-
#define LOG_BUFFER_HEXA(buffer, len, message) \
23-
logBufferHexa(buffer, len, message, __func__, __LINE__)
24+
#define LOG_BUFFER_HEXA(buffer, len, message, id) \
25+
logBufferHexa(buffer, len, message, id, __func__, __LINE__)
2426
void logBufferHexa(const void *voidBuffer, size_t len,
25-
const std::string &message, const char *callingFunction,
26-
int line);
27+
const std::string &message, int id,
28+
const char *callingFunction, int line);
29+
#define LOG_FUNCTION_ENTRY() DEBUG_LOG("entered")
30+
class DebugLogger {
31+
public:
32+
static DebugLogger& getInstance() ;
33+
DebugLogger(const DebugLogger&) = delete;
34+
DebugLogger& operator=(const DebugLogger&) = delete;
35+
void log(const std::string &message);
36+
37+
private:
38+
DebugLogger();
39+
std::ofstream logFile;
40+
//Function to get the current date/time as a string
41+
std::string currentDateTime();
42+
};
2743

2844
#endif // __DEBUG_UTILS_H__

0 commit comments

Comments
 (0)