From 114f28b3d9b8f032fffca38967874e894a7cd9a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Thu, 10 May 2018 10:11:42 +0200 Subject: [PATCH] chacha20: add test for parameter validation --- tests/suites/test_suite_chacha20.data | 3 ++ tests/suites/test_suite_chacha20.function | 50 +++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/tests/suites/test_suite_chacha20.data b/tests/suites/test_suite_chacha20.data index 86094604b..3f9033eeb 100644 --- a/tests/suites/test_suite_chacha20.data +++ b/tests/suites/test_suite_chacha20.data @@ -22,5 +22,8 @@ chacha20_crypt:"1c9240a5eb55d38af333888604f6b5f0473917c1402b80099dca5cbc207075c0 ChaCha20 RFC 7539 Test Vector #3 (Decrypt) chacha20_crypt:"1c9240a5eb55d38af333888604f6b5f0473917c1402b80099dca5cbc207075c0":"000000000000000000000002":42:"62e6347f95ed87a45ffae7426f27a1df5fb69110044c0d73118effa95b01e5cf166d3df2d721caf9b21e5fb14c616871fd84c54f9d65b283196c7fe4f60553ebf39c6402c42234e32a356b3e764312a61a5532055716ead6962568f87d3f3f7704c6a8d1bcd1bf4d50d6154b6da731b187b58dfd728afa36757a797ac188d1":"2754776173206272696c6c69672c20616e642074686520736c6974687920746f7665730a446964206779726520616e642067696d626c6520696e2074686520776162653a0a416c6c206d696d737920776572652074686520626f726f676f7665732c0a416e6420746865206d6f6d65207261746873206f757467726162652e" +ChaCha20 Paremeter Validation +chacha20_bad_params: + ChaCha20 Selftest chacha20_self_test: diff --git a/tests/suites/test_suite_chacha20.function b/tests/suites/test_suite_chacha20.function index 124e51003..669d91e79 100644 --- a/tests/suites/test_suite_chacha20.function +++ b/tests/suites/test_suite_chacha20.function @@ -82,6 +82,56 @@ void chacha20_crypt( char *hex_key_string, } /* END_CASE */ +/* BEGIN_CASE */ +void chacha20_bad_params() +{ + unsigned char key[32]; + unsigned char nonce[12]; + unsigned char src[1]; + unsigned char dst[1]; + uint32_t counter = 0; + size_t len = sizeof( src ); + mbedtls_chacha20_context ctx; + + mbedtls_chacha20_init( NULL ); + mbedtls_chacha20_free( NULL ); + + mbedtls_chacha20_init( &ctx ); + + TEST_ASSERT( mbedtls_chacha20_setkey( NULL, key ) + == MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA ); + TEST_ASSERT( mbedtls_chacha20_setkey( &ctx, NULL ) + == MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA ); + + TEST_ASSERT( mbedtls_chacha20_starts( NULL, nonce, counter ) + == MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA ); + TEST_ASSERT( mbedtls_chacha20_starts( &ctx, NULL, counter ) + == MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA ); + + TEST_ASSERT( mbedtls_chacha20_update( NULL, 0, src, dst ) + == MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA ); + TEST_ASSERT( mbedtls_chacha20_update( &ctx, len, NULL, dst ) + == MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA ); + TEST_ASSERT( mbedtls_chacha20_update( &ctx, len, src, NULL ) + == MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA ); + TEST_ASSERT( mbedtls_chacha20_update( &ctx, 0, NULL, NULL ) + == 0 ); + + mbedtls_chacha20_free( &ctx ); + + TEST_ASSERT( mbedtls_chacha20_crypt( NULL, nonce, counter, 0, src, dst ) + == MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA ); + TEST_ASSERT( mbedtls_chacha20_crypt( key, NULL, counter, 0, src, dst ) + == MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA ); + TEST_ASSERT( mbedtls_chacha20_crypt( key, nonce, counter, len, NULL, dst ) + == MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA ); + TEST_ASSERT( mbedtls_chacha20_crypt( key, nonce, counter, len, src, NULL ) + == MBEDTLS_ERR_CHACHA20_BAD_INPUT_DATA ); + TEST_ASSERT( mbedtls_chacha20_crypt( key, nonce, counter, 0, NULL, NULL ) + == 0 ); +} +/* END_CASE */ + /* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */ void chacha20_self_test() {