Verified Commit a8ec7a99 authored by RobLoach's avatar RobLoach
Browse files

md5: Update to use libretro-common

parent d12b9c0d
......@@ -139,9 +139,9 @@ FLAGS += -I$(CORE_DIR)/vendor/Snippets
# STB
FLAGS += -I$(CORE_DIR)/vendor/stb
# Hash Library
FLAGS += -I$(CORE_DIR)/vendor/robloach-hash-library
SOURCES_CXX += $(CORE_DIR)/vendor/robloach-hash-library/md5.cpp
# MD5
FLAGS += -I$(CORE_DIR)/vendor/libretro-common/include
SOURCES_C += $(CORE_DIR)/vendor/libretro-common/utils/md5.c
# ChaiScript
ifeq ($(HAVE_CHAISCRIPT),)
......
......@@ -6,7 +6,7 @@
#include <sstream>
#include <iostream>
#include "zlib.h"
#include "md5.h"
#include "utils/md5.h"
namespace love {
......@@ -94,8 +94,24 @@ std::string data::decompress(const std::string& str) {
std::string data::hash(const std::string& hashFunction, const std::string& data) {
if (hashFunction == "md5") {
MD5 md5;
return md5(data);
const char* input = data.c_str();
unsigned char digest[16];
// Calculate the MD5 hash using libretro-common.
MD5_CTX context;
MD5_Init(&context);
MD5_Update(&context, input, strlen(input));
MD5_Final(digest, &context);
// Construct the MD5 hash string.
char md5string[33];
for (int i = 0; i < 16; ++i) {
snprintf(&md5string[i * 2], sizeof(&md5string[i * 2]), "%02x", (unsigned int)digest[i]);
}
// Output the hash.
std::string output(md5string);
return output;
}
std::cout << "[ChaiLove] Error: Hash function not found: " << hashFunction << "." << std::endl;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment