1515#endif
1616#include <string.h>
1717
18+ #ifdef CCAN_CRYPTO_SHA512_USE_OPENSSL
1819static 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
2824static 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
4031void 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
6354inline 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
6959inline 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+
7577static uint64_t Ch (uint64_t x , uint64_t y , uint64_t z )
7678{
7779 return z ^ (x & (y ^ z ));
0 commit comments