mirror of
				https://github.com/Mbed-TLS/mbedtls.git
				synced 2025-11-03 20:33:16 +03:00 
			
		
		
		
	Fix bug in md_hmac_demo
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
This commit is contained in:
		@@ -108,21 +108,22 @@ int hmac_demo(void)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    /* prepare context and load key */
 | 
					    /* prepare context and load key */
 | 
				
			||||||
    // the last argument to setup is 1 to enable HMAC (not just hashing)
 | 
					    // 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 ) ) );
 | 
					    CHK( mbedtls_md_hmac_starts( &ctx, key_bytes, sizeof( key_bytes ) ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* compute HMAC(key, msg1_part1 | msg1_part2) */
 | 
					    /* 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_part1, sizeof( msg1_part1 ) ) );
 | 
				
			||||||
    CHK( mbedtls_md_hmac_update( &ctx, msg1_part2, sizeof( msg1_part2 ) ) );
 | 
					    CHK( mbedtls_md_hmac_update( &ctx, msg1_part2, sizeof( msg1_part2 ) ) );
 | 
				
			||||||
    CHK( mbedtls_md_hmac_finish( &ctx, out ) );
 | 
					    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) */
 | 
					    /* compute HMAC(key, msg2_part1 | msg2_part2) */
 | 
				
			||||||
    CHK( mbedtls_md_hmac_reset( &ctx ) ); // prepare for new operation
 | 
					    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_part1, sizeof( msg2_part1 ) ) );
 | 
				
			||||||
    CHK( mbedtls_md_hmac_update( &ctx, msg2_part2, sizeof( msg2_part2 ) ) );
 | 
					    CHK( mbedtls_md_hmac_update( &ctx, msg2_part2, sizeof( msg2_part2 ) ) );
 | 
				
			||||||
    CHK( mbedtls_md_hmac_finish( &ctx, out ) );
 | 
					    CHK( mbedtls_md_hmac_finish( &ctx, out ) );
 | 
				
			||||||
    print_buf( "msg2", out, sizeof( out ) );
 | 
					    print_buf( "msg2", out, mbedtls_md_get_size( info ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exit:
 | 
					exit:
 | 
				
			||||||
    mbedtls_md_free( &ctx );
 | 
					    mbedtls_md_free( &ctx );
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user