chacha20: add test for parameter validation
This commit is contained in:
parent
fce88b2533
commit
2aca236881
@ -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:
|
||||
|
@ -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()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user