From 6d08a82c05e6929323e22c1bac2b6dcca7bd6d65 Mon Sep 17 00:00:00 2001 From: Michael Cardell Widerkrantz Date: Thu, 13 Oct 2022 15:15:53 +0200 Subject: [PATCH] Pass the blake2s_ctx to blake2s() as arg Instead of allocating the blake2s_ctx in the blake2s() function we pass it as a pointer as an argument to be able to better control where the variable is in memory. --- hw/application_fpga/fw/mta1_mkdf/blake2s/blake2s.c | 11 +++++------ hw/application_fpga/fw/mta1_mkdf/blake2s/blake2s.h | 3 ++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/hw/application_fpga/fw/mta1_mkdf/blake2s/blake2s.c b/hw/application_fpga/fw/mta1_mkdf/blake2s/blake2s.c index 009bf27..b46ad8a 100644 --- a/hw/application_fpga/fw/mta1_mkdf/blake2s/blake2s.c +++ b/hw/application_fpga/fw/mta1_mkdf/blake2s/blake2s.c @@ -334,16 +334,15 @@ void blake2s_final(blake2s_ctx *ctx, void *out) //------------------------------------------------------------------ int blake2s(void *out, size_t outlen, const void *key, size_t keylen, - const void *in, size_t inlen) + const void *in, size_t inlen, + blake2s_ctx *ctx) { - blake2s_ctx ctx; - - if (blake2s_init(&ctx, outlen, key, keylen)) + if (blake2s_init(ctx, outlen, key, keylen)) return -1; - blake2s_update(&ctx, in, inlen); + blake2s_update(ctx, in, inlen); - blake2s_final(&ctx, out); + blake2s_final(ctx, out); return 0; } diff --git a/hw/application_fpga/fw/mta1_mkdf/blake2s/blake2s.h b/hw/application_fpga/fw/mta1_mkdf/blake2s/blake2s.h index 9094550..3156669 100644 --- a/hw/application_fpga/fw/mta1_mkdf/blake2s/blake2s.h +++ b/hw/application_fpga/fw/mta1_mkdf/blake2s/blake2s.h @@ -32,7 +32,8 @@ void blake2s_final(blake2s_ctx *ctx, void *out); // All-in-one convenience function. int blake2s(void *out, size_t outlen, // return buffer for digest const void *key, size_t keylen, // optional secret key - const void *in, size_t inlen); // data to be hashed + const void *in, size_t inlen, // data to be hashed + blake2s_ctx *ctx); #endif