Skip to content
Snippets Groups Projects
Verified Commit 76c7082b authored by Dorian Stoll's avatar Dorian Stoll
Browse files

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.
parent d52849cb
No related branches found
No related tags found
No related merge requests found
...@@ -12,9 +12,6 @@ ...@@ -12,9 +12,6 @@
#include <stdio.h> #include <stdio.h>
#include <assert.h> #include <assert.h>
#include "openssl/md5.h"
#include "openssl/evp.h"
#include "ca_common.h" #include "ca_common.h"
void ca_init(int argc, char** argv, int *lines, int *its) 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) ...@@ -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) static void ca_clean_ghost_zones(line_t *buf, int lines)
{ {
for (int y = 0; y < lines; y++) { for (int y = 0; y < lines; y++) {
...@@ -74,21 +53,8 @@ static void ca_clean_ghost_zones(line_t *buf, int lines) ...@@ -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); ca_clean_ghost_zones(buf, lines);
fwrite(buf, sizeof(*buf), lines, stdout);
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);
} }
...@@ -26,7 +26,7 @@ typedef cell_state_t line_t[XSIZE + 2]; ...@@ -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(int argc, char** argv, int *lines, int *its);
void ca_init_config(line_t *buf, int lines, int skip_lines); 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 #ifdef __cplusplus
} }
......
...@@ -86,7 +86,7 @@ int main(int argc, char** argv) ...@@ -86,7 +86,7 @@ int main(int argc, char** argv)
to = temp; to = temp;
} }
ca_hash_and_report(from + 1, lines); ca_report(from + 1, lines);
free(from); free(from);
free(to); free(to);
......
cc = meson.get_compiler('c')
sources = [ sources = [
'ca_common.c', 'ca_common.c',
'ca_openmp.c', 'ca_openmp.c',
...@@ -7,7 +5,6 @@ sources = [ ...@@ -7,7 +5,6 @@ sources = [
dependencies = [ dependencies = [
dependency('openmp'), dependency('openmp'),
cc.find_library('crypto'),
] ]
options = [ options = [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment