From 76c7082ba069b57e9200c97c8c0ed2f2d6bd2a6f Mon Sep 17 00:00:00 2001
From: Dorian Stoll <dorian.stoll@uni-potsdam.de>
Date: Sun, 9 Jun 2024 22:01:02 +0200
Subject: [PATCH] zellularautomat: c: Drop custom hash calculation

By writing the result to stdout the code gets simpler. A hash can still
be calculated by piping stdout into the md5sum program.
---
 src/benchmarks/zellularautomat/c/ca_common.c | 38 ++------------------
 src/benchmarks/zellularautomat/c/ca_common.h |  2 +-
 src/benchmarks/zellularautomat/c/ca_openmp.c |  2 +-
 src/benchmarks/zellularautomat/c/meson.build |  3 --
 4 files changed, 4 insertions(+), 41 deletions(-)

diff --git a/src/benchmarks/zellularautomat/c/ca_common.c b/src/benchmarks/zellularautomat/c/ca_common.c
index 4793064d..7f44e97c 100644
--- a/src/benchmarks/zellularautomat/c/ca_common.c
+++ b/src/benchmarks/zellularautomat/c/ca_common.c
@@ -12,9 +12,6 @@
 #include <stdio.h>
 #include <assert.h>
 
-#include "openssl/md5.h"
-#include "openssl/evp.h"
-
 #include "ca_common.h"
 
 void ca_init(int argc, char** argv, int *lines, int *its)
@@ -48,24 +45,6 @@ void ca_init_config(line_t *buf, int lines, int skip_lines)
 	}
 }
 
-static char* ca_buffer_to_hex_str(const uint8_t* buf, size_t buf_size)
-{
-  char *retval, *ptr;
-
-  retval = ptr = calloc(MD5_DIGEST_LENGTH * 2 + 1, sizeof(*retval));
-  for (size_t i = 0; i < MD5_DIGEST_LENGTH; i++) {
-    snprintf(ptr, 3, "%02X", buf[i]);
-    ptr += 2;
-  }
-
-  return retval;
-}
-
-static void ca_print_hash(const char *hash)
-{
-	printf("hash: %s\n", (hash ? hash : "ERROR"));
-}
-
 static void ca_clean_ghost_zones(line_t *buf, int lines)
 {
 	for (int y = 0; y < lines; y++) {
@@ -74,21 +53,8 @@ static void ca_clean_ghost_zones(line_t *buf, int lines)
 	}
 }
 
-void ca_hash_and_report(line_t *buf, int lines)
+void ca_report(line_t *buf, int lines)
 {
-	uint8_t hash[MD5_DIGEST_LENGTH];
-	uint32_t md_len;
-	EVP_MD_CTX *ctx = EVP_MD_CTX_new();
-	EVP_DigestInit_ex(ctx, EVP_md5(), NULL);
-
 	ca_clean_ghost_zones(buf, lines);
-
-	EVP_DigestUpdate(ctx, buf, lines * sizeof(*buf));
-	EVP_DigestFinal_ex(ctx, hash, &md_len);
-
-	char* hash_str = ca_buffer_to_hex_str(hash, MD5_DIGEST_LENGTH);
-	ca_print_hash(hash_str);
-	free(hash_str);
-
-	EVP_MD_CTX_free(ctx);
+	fwrite(buf, sizeof(*buf), lines, stdout);
 }
diff --git a/src/benchmarks/zellularautomat/c/ca_common.h b/src/benchmarks/zellularautomat/c/ca_common.h
index 532da415..7d764f91 100644
--- a/src/benchmarks/zellularautomat/c/ca_common.h
+++ b/src/benchmarks/zellularautomat/c/ca_common.h
@@ -26,7 +26,7 @@ typedef cell_state_t line_t[XSIZE + 2];
 
 void ca_init(int argc, char** argv, int *lines, int *its);
 void ca_init_config(line_t *buf, int lines, int skip_lines);
-void ca_hash_and_report(line_t *buf, int lines);
+void ca_report(line_t *buf, int lines);
 
 #ifdef __cplusplus
 }
diff --git a/src/benchmarks/zellularautomat/c/ca_openmp.c b/src/benchmarks/zellularautomat/c/ca_openmp.c
index ad9166fb..4e0e9480 100644
--- a/src/benchmarks/zellularautomat/c/ca_openmp.c
+++ b/src/benchmarks/zellularautomat/c/ca_openmp.c
@@ -86,7 +86,7 @@ int main(int argc, char** argv)
 		to = temp;
 	}
 
-	ca_hash_and_report(from + 1, lines);
+	ca_report(from + 1, lines);
 
 	free(from);
 	free(to);
diff --git a/src/benchmarks/zellularautomat/c/meson.build b/src/benchmarks/zellularautomat/c/meson.build
index f3642e62..0552fee1 100644
--- a/src/benchmarks/zellularautomat/c/meson.build
+++ b/src/benchmarks/zellularautomat/c/meson.build
@@ -1,5 +1,3 @@
-cc = meson.get_compiler('c')
-
 sources = [
 	'ca_common.c',
 	'ca_openmp.c',
@@ -7,7 +5,6 @@ sources = [
 
 dependencies = [
 	dependency('openmp'),
-	cc.find_library('crypto'),
 ]
 
 options = [
-- 
GitLab