From 1ef71dffc7f33c9cee95d6f39ea8fac3986cc3d6 Mon Sep 17 00:00:00 2001 From: Paul Bakker Date: Thu, 9 Jun 2011 14:14:58 +0000 Subject: [PATCH] - Updated unsignedness in some missed cases --- include/polarssl/aes.h | 6 ++--- include/polarssl/camellia.h | 27 ++++++++++++++++++++++- library/camellia.c | 14 +++++++----- tests/suites/test_suite_camellia.function | 4 ++-- 4 files changed, 39 insertions(+), 12 deletions(-) diff --git a/include/polarssl/aes.h b/include/polarssl/aes.h index 7404e4eef0..efc13daf5b 100644 --- a/include/polarssl/aes.h +++ b/include/polarssl/aes.h @@ -124,7 +124,7 @@ int aes_crypt_cbc( aes_context *ctx, int aes_crypt_cfb128( aes_context *ctx, int mode, size_t length, - int *iv_off, + size_t *iv_off, unsigned char iv[16], const unsigned char *input, unsigned char *output ); @@ -147,8 +147,8 @@ int aes_crypt_cfb128( aes_context *ctx, * \return 0 if successful */ int aes_crypt_ctr( aes_context *ctx, - int length, - int *nc_off, + size_t length, + size_t *nc_off, unsigned char nonce_counter[16], unsigned char stream_block[16], const unsigned char *input, diff --git a/include/polarssl/camellia.h b/include/polarssl/camellia.h index 0dcb830741..c81066c89a 100644 --- a/include/polarssl/camellia.h +++ b/include/polarssl/camellia.h @@ -130,11 +130,36 @@ int camellia_crypt_cbc( camellia_context *ctx, int camellia_crypt_cfb128( camellia_context *ctx, int mode, size_t length, - int *iv_off, + size_t *iv_off, unsigned char iv[16], const unsigned char *input, unsigned char *output ); +/* + * \brief CAMELLIA-CTR buffer encryption/decryption + * + * Warning: You have to keep the maximum use of your counter in mind! + * + * \param length The length of the data + * \param nc_off The offset in the current stream_block (for resuming + * within current cipher stream). The offset pointer to + * should be 0 at the start of a stream. + * \param nonce_counter The 128-bit nonce and counter. + * \param stream_block The saved stream-block for resuming. Is overwritten + * by the function. + * \param input The input data stream + * \param output The output data stream + * + * \return 0 if successful + */ +int camellia_crypt_ctr( camellia_context *ctx, + size_t length, + size_t *nc_off, + unsigned char nonce_counter[16], + unsigned char stream_block[16], + const unsigned char *input, + unsigned char *output ); + /** * \brief Checkup routine * diff --git a/library/camellia.c b/library/camellia.c index d725c19304..e4c3259e9a 100644 --- a/library/camellia.c +++ b/library/camellia.c @@ -580,12 +580,13 @@ int camellia_crypt_cbc( camellia_context *ctx, int camellia_crypt_cfb128( camellia_context *ctx, int mode, size_t length, - int *iv_off, + size_t *iv_off, unsigned char iv[16], const unsigned char *input, unsigned char *output ) { - int c, n = *iv_off; + int c; + size_t n = *iv_off; if( mode == CAMELLIA_DECRYPT ) { @@ -625,14 +626,15 @@ int camellia_crypt_cfb128( camellia_context *ctx, * Camellia-CTR buffer encryption/decryption */ int camellia_crypt_ctr( camellia_context *ctx, - int length, - int *nc_off, + size_t length, + size_t *nc_off, unsigned char nonce_counter[16], unsigned char stream_block[16], const unsigned char *input, unsigned char *output ) { - int c, n = *nc_off, i, cb; + int c, i, cb; + size_t n = *nc_off; while( length-- ) { @@ -867,7 +869,7 @@ int camellia_self_test( int verbose ) unsigned char dst[16]; unsigned char iv[16]; #if defined(POLARSSL_CIPHER_MODE_CTR) - int offset, len; + size_t offset, len; unsigned char nonce_counter[16]; unsigned char stream_block[16]; #endif diff --git a/tests/suites/test_suite_camellia.function b/tests/suites/test_suite_camellia.function index 172f849183..15bedceb72 100644 --- a/tests/suites/test_suite_camellia.function +++ b/tests/suites/test_suite_camellia.function @@ -137,7 +137,7 @@ camellia_encrypt_cfb128:hex_key_string:hex_iv_string:hex_src_string:hex_dst_stri unsigned char dst_str[100]; unsigned char output[100]; camellia_context ctx; - int iv_offset = 0; + size_t iv_offset = 0; int key_len; memset(key_str, 0x00, 100); @@ -167,7 +167,7 @@ camellia_decrypt_cfb128:hex_key_string:hex_iv_string:hex_src_string:hex_dst_stri unsigned char dst_str[100]; unsigned char output[100]; camellia_context ctx; - int iv_offset = 0; + size_t iv_offset = 0; int key_len; memset(key_str, 0x00, 100);