poly1305: adjust parameter order
This module used (len, pointer) while (pointer, len) is more common in the
rest of the library, in particular it's what's used in the CMAC API that is
very comparable to Poly1305, so switch to (pointer, len) for consistency.
diff --git a/include/mbedtls/poly1305.h b/include/mbedtls/poly1305.h
index c2e2655..19f5237 100644
--- a/include/mbedtls/poly1305.h
+++ b/include/mbedtls/poly1305.h
@@ -121,8 +121,8 @@
* if ctx or input are NULL.
*/
int mbedtls_poly1305_update( mbedtls_poly1305_context *ctx,
- size_t ilen,
- const unsigned char *input );
+ const unsigned char *input,
+ size_t ilen );
/**
* \brief This function generates the Poly1305 Message
@@ -158,8 +158,8 @@
* if key, input, or mac are NULL.
*/
int mbedtls_poly1305_mac( const unsigned char key[32],
- size_t ilen,
const unsigned char *input,
+ size_t ilen,
unsigned char mac[16] );
/**
diff --git a/library/chachapoly.c b/library/chachapoly.c
index 0dba5ed..d599c52 100644
--- a/library/chachapoly.c
+++ b/library/chachapoly.c
@@ -66,8 +66,8 @@
{
memset( zeroes, 0, sizeof( zeroes ) );
(void) mbedtls_poly1305_update( &ctx->poly1305_ctx,
- 16U - partial_block_len,
- zeroes );
+ zeroes,
+ 16U - partial_block_len );
}
}
@@ -85,8 +85,8 @@
{
memset( zeroes, 0, sizeof( zeroes ) );
(void) mbedtls_poly1305_update( &ctx->poly1305_ctx,
- 16U - partial_block_len,
- zeroes );
+ zeroes,
+ 16U - partial_block_len );
}
}
@@ -194,7 +194,7 @@
ctx->aad_len += aad_len;
- return( mbedtls_poly1305_update( &ctx->poly1305_ctx, aad_len, aad ) );
+ return( mbedtls_poly1305_update( &ctx->poly1305_ctx, aad, aad_len ) );
}
int mbedtls_chachapoly_update( mbedtls_chachapoly_context *ctx,
@@ -233,11 +233,11 @@
* above, we can safety ignore the return value.
*/
(void) mbedtls_chacha20_update( &ctx->chacha20_ctx, len, input, output );
- (void) mbedtls_poly1305_update( &ctx->poly1305_ctx, len, output );
+ (void) mbedtls_poly1305_update( &ctx->poly1305_ctx, output, len );
}
else /* DECRYPT */
{
- (void) mbedtls_poly1305_update( &ctx->poly1305_ctx, len, input );
+ (void) mbedtls_poly1305_update( &ctx->poly1305_ctx, input, len );
(void) mbedtls_chacha20_update( &ctx->chacha20_ctx, len, input, output );
}
@@ -289,7 +289,7 @@
len_block[14] = (unsigned char) ( ctx->ciphertext_len >> 48 );
len_block[15] = (unsigned char) ( ctx->ciphertext_len >> 56 );
- (void) mbedtls_poly1305_update( &ctx->poly1305_ctx, 16U, len_block );
+ (void) mbedtls_poly1305_update( &ctx->poly1305_ctx, len_block, 16U );
(void) mbedtls_poly1305_finish( &ctx->poly1305_ctx, mac );
return( 0 );
diff --git a/library/poly1305.c b/library/poly1305.c
index 66f932c..14c362d 100644
--- a/library/poly1305.c
+++ b/library/poly1305.c
@@ -285,8 +285,8 @@
}
int mbedtls_poly1305_update( mbedtls_poly1305_context *ctx,
- size_t ilen,
- const unsigned char* input )
+ const unsigned char *input,
+ size_t ilen )
{
size_t offset = 0U;
size_t remaining = ilen;
@@ -391,9 +391,9 @@
}
int mbedtls_poly1305_mac( const unsigned char key[32],
- size_t ilen,
- const unsigned char *input,
- unsigned char mac[16] )
+ const unsigned char *input,
+ size_t ilen,
+ unsigned char mac[16] )
{
mbedtls_poly1305_context ctx;
int result;
@@ -404,7 +404,7 @@
if ( result != 0 )
goto cleanup;
- result = mbedtls_poly1305_update( &ctx, ilen, input );
+ result = mbedtls_poly1305_update( &ctx, input, ilen );
if ( result != 0 )
goto cleanup;
@@ -496,8 +496,8 @@
}
result = mbedtls_poly1305_mac( test_keys[i],
- test_data_len[i],
test_data[i],
+ test_data_len[i],
mac );
if ( result != 0 )
{
diff --git a/programs/test/benchmark.c b/programs/test/benchmark.c
index c419665..17f9d0e 100644
--- a/programs/test/benchmark.c
+++ b/programs/test/benchmark.c
@@ -538,7 +538,7 @@
#if defined(MBEDTLS_POLY1305_C)
if ( todo.poly1305 )
{
- TIME_AND_TSC( "Poly1305", mbedtls_poly1305_mac( buf, BUFSIZE, buf, buf ) );
+ TIME_AND_TSC( "Poly1305", mbedtls_poly1305_mac( buf, buf, BUFSIZE, buf ) );
}
#endif
diff --git a/tests/suites/test_suite_poly1305.function b/tests/suites/test_suite_poly1305.function
index af69a03..a633c2b 100644
--- a/tests/suites/test_suite_poly1305.function
+++ b/tests/suites/test_suite_poly1305.function
@@ -20,7 +20,7 @@
src_len = unhexify( src_str, hex_src_string );
unhexify( key, hex_key_string );
- mbedtls_poly1305_mac( key, src_len, src_str, mac );
+ mbedtls_poly1305_mac( key, src_str, src_len, mac );
hexify( mac_str, mac, 16 );
TEST_ASSERT( strcmp( (char *) mac_str, hex_mac_string ) == 0 );