Skip to content

Commit f5fc513

Browse files
committed
ccan: call mbedtls_sha512_free in sha512_done
Rearrange the code slightly to match the sha256 impl.
1 parent e0e4c0e commit f5fc513

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/ccan/ccan/crypto/sha512/sha512.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,19 @@
1515
#endif
1616
#include <string.h>
1717

18+
#ifdef CCAN_CRYPTO_SHA512_USE_OPENSSL
1819
static void invalidate_sha512(struct sha512_ctx *ctx)
1920
{
20-
#ifdef CCAN_CRYPTO_SHA512_USE_OPENSSL
2121
ctx->c.md_len = 0;
22-
#elif defined(CCAN_CRYPTO_SHA512_USE_MBEDTLS)
23-
#else
24-
ctx->bytes = (size_t)-1;
25-
#endif
2622
}
2723

2824
static void check_sha512(struct sha512_ctx *ctx UNUSED)
2925
{
3026
#if 0
31-
#ifdef CCAN_CRYPTO_SHA512_USE_OPENSSL
3227
assert(ctx->c.md_len != 0);
33-
#else
34-
assert(ctx->bytes != (size_t)-1);
35-
#endif
3628
#endif
3729
}
3830

39-
#ifdef CCAN_CRYPTO_SHA512_USE_OPENSSL
4031
void sha512_init(struct sha512_ctx *ctx)
4132
{
4233
SHA512_Init(&ctx->c);
@@ -62,16 +53,27 @@ inline void sha512_init(struct sha512_ctx *ctx)
6253

6354
inline void sha512_update(struct sha512_ctx *ctx, const void *p, size_t size)
6455
{
65-
check_sha512(ctx);
6656
mbedtls_sha512_update(&ctx->c, p, size);
6757
}
6858

6959
inline void sha512_done(struct sha512_ctx *ctx, struct sha512* res)
7060
{
7161
mbedtls_sha512_finish(&ctx->c, res->u.u8);
72-
invalidate_sha512(ctx);
62+
mbedtls_sha512_free(&ctx->c);
7363
}
7464
#else
65+
static void invalidate_sha512(struct sha512_ctx *ctx)
66+
{
67+
ctx->bytes = (size_t)-1;
68+
}
69+
70+
static void check_sha512(struct sha512_ctx *ctx UNUSED)
71+
{
72+
#if 0
73+
assert(ctx->bytes != (size_t)-1);
74+
#endif
75+
}
76+
7577
static uint64_t Ch(uint64_t x, uint64_t y, uint64_t z)
7678
{
7779
return z ^ (x & (y ^ z));

0 commit comments

Comments
 (0)