From 446227a1bd177e988091acb84d338316262f4924 Mon Sep 17 00:00:00 2001 From: Ron Eldor Date: Mon, 13 Aug 2018 14:46:45 +0300 Subject: [PATCH] Enhance nist_kw with some NULL buffers tests Enhance the nist_kw test suite, with setting zero length input\output buffers. Resolves #1882. --- tests/suites/test_suite_nist_kw.data | 21 ++++++++++++++++ tests/suites/test_suite_nist_kw.function | 32 +++++++++++++----------- 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/tests/suites/test_suite_nist_kw.data b/tests/suites/test_suite_nist_kw.data index eee45743e..446255857 100644 --- a/tests/suites/test_suite_nist_kw.data +++ b/tests/suites/test_suite_nist_kw.data @@ -69,6 +69,27 @@ nist_kw_ciphertext_lengths:32:16:MBEDTLS_KW_MODE_KW:MBEDTLS_ERR_CIPHER_BAD_INPUT NIST KW lengths #16 KWP unwrapping output buffer too short nist_kw_ciphertext_lengths:24:12:MBEDTLS_KW_MODE_KWP:MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA +NIST KW lengths #17 KW plaintext NULL (2 to 2^54 - 1 semiblocks) +nist_kw_plaintext_lengths:0:8:MBEDTLS_KW_MODE_KW:MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA + +NIST KW lengths #18 KW wrapping output NULL +nist_kw_plaintext_lengths:8:0:MBEDTLS_KW_MODE_KW:MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA + +NIST KW lengths #19 KWP wrapping output NULL +nist_kw_plaintext_lengths:8:0:MBEDTLS_KW_MODE_KWP:MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA + +NIST KW lengths #20 KW ciphertext NULL +nist_kw_ciphertext_lengths:0:8:MBEDTLS_KW_MODE_KW:MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA + +NIST KW lengths #21 KWP ciphertext NULL +nist_kw_ciphertext_lengths:0:8:MBEDTLS_KW_MODE_KWP:MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA + +NIST KW lengths #15 KW unwrapping output NULL +nist_kw_ciphertext_lengths:32:0:MBEDTLS_KW_MODE_KW:MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA + +NIST KW lengths #16 KWP unwrapping output NULL +nist_kw_ciphertext_lengths:24:0:MBEDTLS_KW_MODE_KWP:MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA + NIST KW wrap AES-128 CAVS 17.4 PLAINTEXT LENGTH = 128 count 7 depends_on:MBEDTLS_AES_C mbedtls_nist_kw_wrap:MBEDTLS_CIPHER_ID_AES:MBEDTLS_KW_MODE_KW:"095e293f31e317ba6861114b95c90792":"64349d506ae85ecd84459c7a5c423f55":"97de4425572274bd7fb2d6688d5afd4454d992348d42a643" diff --git a/tests/suites/test_suite_nist_kw.function b/tests/suites/test_suite_nist_kw.function index eb67c03f0..ff5bb8be0 100644 --- a/tests/suites/test_suite_nist_kw.function +++ b/tests/suites/test_suite_nist_kw.function @@ -158,19 +158,17 @@ void nist_kw_plaintext_lengths( int in_len, int out_len, int mode, int res ) memset( key, 0, sizeof( key ) ); - if (in_len == 0) - { - /* mbedtls_calloc can return NULL for zero-length buffers. Make sure we - * always have a plaintext buffer, even if the length is 0. */ - plaintext = mbedtls_calloc( 1, 1 ); - } - else + if( in_len != 0 ) { plaintext = mbedtls_calloc( 1, in_len ); } - TEST_ASSERT( plaintext != NULL ); - ciphertext = mbedtls_calloc( 1, output_len ); - TEST_ASSERT( ciphertext != NULL ); + TEST_ASSERT( in_len == 0 || plaintext != NULL ); + + if( out_len != 0 ) + { + ciphertext = mbedtls_calloc( 1, output_len ); + } + TEST_ASSERT( out_len == 0 || ciphertext != NULL ); memset( plaintext, 0, in_len ); memset( ciphertext, 0, output_len ); @@ -216,10 +214,16 @@ void nist_kw_ciphertext_lengths( int in_len, int out_len, int mode, int res ) memset( key, 0, sizeof( key ) ); - plaintext = mbedtls_calloc( 1, output_len ); - TEST_ASSERT( plaintext != NULL ); - ciphertext = mbedtls_calloc( 1, in_len ); - TEST_ASSERT( ciphertext != NULL ); + if( out_len != 0 ) + { + plaintext = mbedtls_calloc( 1, output_len ); + } + TEST_ASSERT( out_len == 0 || plaintext != NULL ); + if( in_len != 0 ) + { + ciphertext = mbedtls_calloc( 1, in_len ); + } + TEST_ASSERT( in_len == 0 || ciphertext != NULL ); memset( plaintext, 0, output_len ); memset( ciphertext, 0, in_len );