Minor fixes to Camellia parameter validation

This commit is contained in:
Hanno Becker 2018-12-13 15:39:24 +00:00
parent f10905a6a7
commit e939de7247
2 changed files with 32 additions and 28 deletions

View File

@ -96,7 +96,7 @@ void mbedtls_camellia_free( mbedtls_camellia_context *ctx );
*
* \param ctx The CAMELLIA context to use. This must be initialized.
* \param key The encryption key to use. This must be a readable buffer
* of size \p keybits bits.
* of size \p keybits Bits.
* \param keybits The length of \p key in Bits. This must be either \c 128,
* \c 192 or \c 256.
*
@ -112,7 +112,7 @@ int mbedtls_camellia_setkey_enc( mbedtls_camellia_context *ctx,
*
* \param ctx The CAMELLIA context to use. This must be initialized.
* \param key The decryption key. This must be a readable buffer
* of size \p keybits bits.
* of size \p keybits Bits.
* \param keybits The length of \p key in Bits. This must be either \c 128,
* \c 192 or \c 256.
*
@ -157,7 +157,7 @@ int mbedtls_camellia_crypt_ecb( mbedtls_camellia_context *ctx,
*
* \param ctx The CAMELLIA context to use. This must be initialized
* and bound to a key.
* \param mode The mode of operation. Possible values are
* \param mode The mode of operation. This must be either
* #MBEDTLS_CAMELLIA_ENCRYPT or #MBEDTLS_CAMELLIA_DECRYPT.
* \param length The length in Bytes of the input data.
* Must be a multiple of \c 16.
@ -202,7 +202,7 @@ int mbedtls_camellia_crypt_cbc( mbedtls_camellia_context *ctx,
*
* \param ctx The CAMELLIA context to use. This must be initialized
* and bound to a key.
* \param mode The mode of operation. Possible values are
* \param mode The mode of operation. This must be either
* #MBEDTLS_CAMELLIA_ENCRYPT or #MBEDTLS_CAMELLIA_DECRYPT.
* \param length The length of the input data. Any value is allowed.
* \param iv_off The current offset in the IV. This must be smaller

View File

@ -12,6 +12,10 @@ void camellia_invalid_param( )
{
mbedtls_camellia_context ctx;
unsigned char buf[16] = { 0 };
const size_t valid_keybits = 128;
const size_t invalid_keybits = 42;
const int invalid_mode = 42;
const int valid_mode = MBEDTLS_CAMELLIA_ENCRYPT;
size_t off;
((void) off);
@ -21,70 +25,70 @@ void camellia_invalid_param( )
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
mbedtls_camellia_setkey_enc( NULL,
buf,
128 ) );
valid_keybits ) );
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
mbedtls_camellia_setkey_enc( &ctx,
NULL,
128 ) );
valid_keybits ) );
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
mbedtls_camellia_setkey_enc( &ctx,
buf,
42 ) );
invalid_keybits ) );
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
mbedtls_camellia_setkey_dec( NULL,
buf,
128 ) );
valid_keybits ) );
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
mbedtls_camellia_setkey_dec( &ctx,
NULL,
128 ) );
valid_keybits ) );
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
mbedtls_camellia_setkey_dec( &ctx,
buf,
42 ) );
invalid_keybits ) );
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
mbedtls_camellia_crypt_ecb( NULL,
MBEDTLS_CAMELLIA_ENCRYPT,
buf, buf ) );
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
mbedtls_camellia_crypt_ecb( &ctx,
42,
valid_mode,
buf, buf ) );
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
mbedtls_camellia_crypt_ecb( &ctx,
MBEDTLS_CAMELLIA_ENCRYPT,
invalid_mode,
buf, buf ) );
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
mbedtls_camellia_crypt_ecb( &ctx,
valid_mode,
NULL, buf ) );
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
mbedtls_camellia_crypt_ecb( &ctx,
MBEDTLS_CAMELLIA_ENCRYPT,
valid_mode,
buf, NULL ) );
#if defined(MBEDTLS_CIPHER_MODE_CBC)
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
mbedtls_camellia_crypt_cbc( NULL,
MBEDTLS_CAMELLIA_ENCRYPT,
valid_mode,
sizeof( buf ),
buf, buf, buf ) );
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
mbedtls_camellia_crypt_cbc( &ctx,
42,
invalid_mode,
sizeof( buf ),
buf, buf, buf ) );
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
mbedtls_camellia_crypt_cbc( &ctx,
MBEDTLS_CAMELLIA_ENCRYPT,
valid_mode,
sizeof( buf ),
NULL, buf, buf ) );
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
mbedtls_camellia_crypt_cbc( &ctx,
MBEDTLS_CAMELLIA_ENCRYPT,
valid_mode,
sizeof( buf ),
buf, NULL, buf ) );
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
mbedtls_camellia_crypt_cbc( &ctx,
MBEDTLS_CAMELLIA_ENCRYPT,
valid_mode,
sizeof( buf ),
buf, buf, NULL ) );
#endif /* MBEDTLS_CIPHER_MODE_CBC */
@ -92,37 +96,37 @@ void camellia_invalid_param( )
#if defined(MBEDTLS_CIPHER_MODE_CFB)
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
mbedtls_camellia_crypt_cfb128( NULL,
MBEDTLS_CAMELLIA_ENCRYPT,
valid_mode,
sizeof( buf ),
&off, buf,
buf, buf ) );
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
mbedtls_camellia_crypt_cfb128( &ctx,
42,
invalid_mode,
sizeof( buf ),
&off, buf,
buf, buf ) );
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
mbedtls_camellia_crypt_cfb128( &ctx,
MBEDTLS_CAMELLIA_ENCRYPT,
valid_mode,
sizeof( buf ),
NULL, buf,
buf, buf ) );
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
mbedtls_camellia_crypt_cfb128( &ctx,
MBEDTLS_CAMELLIA_ENCRYPT,
valid_mode,
sizeof( buf ),
&off, NULL,
buf, buf ) );
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
mbedtls_camellia_crypt_cfb128( &ctx,
MBEDTLS_CAMELLIA_ENCRYPT,
valid_mode,
sizeof( buf ),
&off, buf,
NULL, buf ) );
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_CAMELLIA_BAD_INPUT_DATA,
mbedtls_camellia_crypt_cfb128( &ctx,
MBEDTLS_CAMELLIA_ENCRYPT,
valid_mode,
sizeof( buf ),
&off, buf,
buf, NULL ) );