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.
This commit is contained in:
Michael Cardell Widerkrantz 2022-10-13 15:15:53 +02:00
parent e0d68f3dae
commit 6d08a82c05
No known key found for this signature in database
GPG Key ID: D3DB3DDF57E704E5
2 changed files with 7 additions and 7 deletions

View File

@ -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;
}

View File

@ -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