Skip to content

Commit

Permalink
Merge pull request #3 from mahmudhera/main
Browse files Browse the repository at this point in the history
Add md5sum code
  • Loading branch information
mahmudhera authored Nov 3, 2024
2 parents 07dc013 + 2803c9a commit e891599
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.o
*.o
.vscode/settings.json
21 changes: 20 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,25 @@ CFLAGS = -Wall -O3 -fsigned-char $(CPU_FLAGS) $(STATIC_CFLAGS) -std=c++14
CLINK = -lm $(STATIC_LFLAGS) -O3 -std=c++14
PY_KMC_API_CFLAGS = $(PY_FLAGS) -Wall -shared -std=c++14 -O3


# Find OpenSSL path using "which"
OPENSSL_PATH := $(shell which openssl)

# if open ssl is not found, then exit
ifeq ($(OPENSSL_PATH),)
$(error "OpenSSL not found. Please install OpenSSL")
endif

# Extract directory path from the full path
OPENSSL_DIR := $(dir $(OPENSSL_PATH))

# Set flags using the directory path
CFLAGS += -I$(OPENSSL_DIR)/../include -lssl -lcrypto
LDFLAGS += -L$(OPENSSL_DIR)/../lib -lssl -lcrypto

# export LD_LIBRARY_PATH appropriately
export LD_LIBRARY_PATH := $(OPENSSL_DIR)/../lib:$(LD_LIBRARY_PATH)

KMC_CLI_OBJS = \
$(KMC_CLI_DIR)/kmc.o

Expand Down Expand Up @@ -173,7 +192,7 @@ frackmc: $(KMC_CLI_OBJS) $(LIB_KMC_CORE) $(LIB_ZLIB)

frackmcdump: $(KMC_DUMP_OBJS) $(KMC_API_OBJS)
-mkdir -p $(OUT_BIN_DIR)
$(CC) $(CLINK) -o $(OUT_BIN_DIR)/$@ $^
$(CC) $(CLINK) -o $(OUT_BIN_DIR)/$@ $^ -lssl -lcrypto

# frac_kmc: g++ -Wall -O3 wrappers/sketch/frac_kmc_sketch.cpp -o fracKmcSketch
fracKmcSketch: wrappers/sketch/frac_kmc_sketch.cpp
Expand Down
28 changes: 27 additions & 1 deletion kmc_dump/kmc_dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#include "../kmc_api/kmc_file.h"
#include "nc_utils.h"
#include <map>
#include <openssl/md5.h>
#include <sstream>
#include <iomanip>

using namespace std;

Expand Down Expand Up @@ -357,7 +360,30 @@ int main(int argc, char* argv[])

}

output_string = "], \"molecule\":\"dna\", \"md5sum\":\"abcd\"}], \"version\":0.1}]\n";

// compute md5sum
MD5_CTX md5_ctx;
MD5_Init(&md5_ctx);
// add ksize to md5sum
string ksize_str = to_string(ksize);
MD5_Update(&md5_ctx, ksize_str.c_str(), ksize_str.length());
// add the hashes to md5sum
for (int i=0; i<hashes.size(); i++)
{
string hash_str = to_string(hashes[i]);
MD5_Update(&md5_ctx, hash_str.c_str(), hash_str.length());
}
unsigned char md5sum[MD5_DIGEST_LENGTH];
MD5_Final(md5sum, &md5_ctx);
string md5sum_str = "";
std::ostringstream oss;
for(int i = 0; i < MD5_DIGEST_LENGTH; i++)
{
oss << std::hex << std::setw(2) << std::setfill('0') << (int)md5sum[i];
}
md5sum_str = oss.str();

output_string = "], \"molecule\":\"dna\", \"md5sum\":\"" + md5sum_str + "\"}], \"version\":0.1}]\n";
strcpy(str, output_string.c_str());
fwrite(str, 1, output_string.length(), out_file);

Expand Down

0 comments on commit e891599

Please sign in to comment.