From 12ec5719e7db105ecdeb2182161aecc6d065bafc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Tue, 1 Feb 2022 09:47:46 +0100 Subject: [PATCH] Fix bug in md_hmac_demo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Manuel Pégourié-Gonnard --- programs/hash/md_hmac_demo.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/programs/hash/md_hmac_demo.c b/programs/hash/md_hmac_demo.c index cae6224012..0f6495c866 100644 --- a/programs/hash/md_hmac_demo.c +++ b/programs/hash/md_hmac_demo.c @@ -108,21 +108,22 @@ int hmac_demo(void) /* prepare context and load key */ // the last argument to setup is 1 to enable HMAC (not just hashing) - CHK( mbedtls_md_setup( &ctx, mbedtls_md_info_from_type( alg ), 1 ) ); + const mbedtls_md_info_t *info = mbedtls_md_info_from_type( alg ); + CHK( mbedtls_md_setup( &ctx, info, 1 ) ); CHK( mbedtls_md_hmac_starts( &ctx, key_bytes, sizeof( key_bytes ) ) ); /* compute HMAC(key, msg1_part1 | msg1_part2) */ CHK( mbedtls_md_hmac_update( &ctx, msg1_part1, sizeof( msg1_part1 ) ) ); CHK( mbedtls_md_hmac_update( &ctx, msg1_part2, sizeof( msg1_part2 ) ) ); CHK( mbedtls_md_hmac_finish( &ctx, out ) ); - print_buf( "msg1", out, sizeof( out ) ); + print_buf( "msg1", out, mbedtls_md_get_size( info ) ); /* compute HMAC(key, msg2_part1 | msg2_part2) */ CHK( mbedtls_md_hmac_reset( &ctx ) ); // prepare for new operation CHK( mbedtls_md_hmac_update( &ctx, msg2_part1, sizeof( msg2_part1 ) ) ); CHK( mbedtls_md_hmac_update( &ctx, msg2_part2, sizeof( msg2_part2 ) ) ); CHK( mbedtls_md_hmac_finish( &ctx, out ) ); - print_buf( "msg2", out, sizeof( out ) ); + print_buf( "msg2", out, mbedtls_md_get_size( info ) ); exit: mbedtls_md_free( &ctx );