Skip to content

Commit

Permalink
alg-gost3411-2012-hmac.c: Safely clear the context state.
Browse files Browse the repository at this point in the history
  • Loading branch information
besser82 committed May 31, 2023
1 parent 528ab0c commit 4321cc6
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/alg-gost3411-2012-hmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@ void
gost_hash256 (const uint8_t *t, size_t n, uint8_t *out32,
GOST34112012Context *ctx)
{
/* Clear the context state. */
explicit_bzero (ctx, sizeof (GOST34112012Context));

GOST34112012Init (ctx, GOSTR3411_2012_BITS);
GOST34112012Update (ctx, t, n);
GOST34112012Final (ctx, out32);

/* Clear the context state. */
explicit_bzero (ctx, sizeof (GOST34112012Context));
}

/* HMAC_GOSTR3411_2012_256 */
Expand All @@ -41,6 +47,9 @@ gost_hmac256 (const uint8_t *k, size_t n, const uint8_t *t, size_t len,
{
size_t i;

/* Clear the context state. */
explicit_bzero (gostbuf, sizeof (gost_hmac_256_t));

/* R 50.1.113-2016 only allowed N to be in range 256..512 bits */
assert (n >= GOSTR3411_2012_L && n <= GOSTR3411_2012_B);

Expand All @@ -57,6 +66,9 @@ gost_hmac256 (const uint8_t *k, size_t n, const uint8_t *t, size_t len,
GOST34112012Update (&gostbuf->ctx, t, len);
GOST34112012Final (&gostbuf->ctx, gostbuf->digest);

/* Clear the context state. */
explicit_bzero (&gostbuf->ctx, sizeof (GOST34112012Context));

GOST34112012Init (&gostbuf->ctx, GOSTR3411_2012_BITS);

for (i = 0; i < sizeof (gostbuf->pad); i++)
Expand All @@ -67,6 +79,9 @@ gost_hmac256 (const uint8_t *k, size_t n, const uint8_t *t, size_t len,
GOST34112012Update (&gostbuf->ctx, gostbuf->digest,
sizeof (gostbuf->digest));
GOST34112012Final (&gostbuf->ctx, out32);

/* Clear the context state. */
explicit_bzero (gostbuf, sizeof (gost_hmac_256_t));
}

#endif /* INCLUDE_gost_yescrypt */

0 comments on commit 4321cc6

Please sign in to comment.