mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-26 06:25:43 +01:00
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.
This commit is contained in:
parent
6048e05d5c
commit
9b7a93cf1f
@ -121,8 +121,8 @@ int mbedtls_poly1305_starts( mbedtls_poly1305_context *ctx,
|
|||||||
* if ctx or input are NULL.
|
* if ctx or input are NULL.
|
||||||
*/
|
*/
|
||||||
int mbedtls_poly1305_update( mbedtls_poly1305_context *ctx,
|
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
|
* \brief This function generates the Poly1305 Message
|
||||||
@ -158,8 +158,8 @@ int mbedtls_poly1305_finish( mbedtls_poly1305_context *ctx,
|
|||||||
* if key, input, or mac are NULL.
|
* if key, input, or mac are NULL.
|
||||||
*/
|
*/
|
||||||
int mbedtls_poly1305_mac( const unsigned char key[32],
|
int mbedtls_poly1305_mac( const unsigned char key[32],
|
||||||
size_t ilen,
|
|
||||||
const unsigned char *input,
|
const unsigned char *input,
|
||||||
|
size_t ilen,
|
||||||
unsigned char mac[16] );
|
unsigned char mac[16] );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -66,8 +66,8 @@ static void mbedtls_chachapoly_pad_aad( mbedtls_chachapoly_context *ctx )
|
|||||||
{
|
{
|
||||||
memset( zeroes, 0, sizeof( zeroes ) );
|
memset( zeroes, 0, sizeof( zeroes ) );
|
||||||
(void) mbedtls_poly1305_update( &ctx->poly1305_ctx,
|
(void) mbedtls_poly1305_update( &ctx->poly1305_ctx,
|
||||||
16U - partial_block_len,
|
zeroes,
|
||||||
zeroes );
|
16U - partial_block_len );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,8 +85,8 @@ static void mbedtls_chachapoly_pad_ciphertext( mbedtls_chachapoly_context *ctx )
|
|||||||
{
|
{
|
||||||
memset( zeroes, 0, sizeof( zeroes ) );
|
memset( zeroes, 0, sizeof( zeroes ) );
|
||||||
(void) mbedtls_poly1305_update( &ctx->poly1305_ctx,
|
(void) mbedtls_poly1305_update( &ctx->poly1305_ctx,
|
||||||
16U - partial_block_len,
|
zeroes,
|
||||||
zeroes );
|
16U - partial_block_len );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,7 +194,7 @@ int mbedtls_chachapoly_update_aad( mbedtls_chachapoly_context *ctx,
|
|||||||
|
|
||||||
ctx->aad_len += aad_len;
|
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,
|
int mbedtls_chachapoly_update( mbedtls_chachapoly_context *ctx,
|
||||||
@ -233,11 +233,11 @@ int mbedtls_chachapoly_update( mbedtls_chachapoly_context *ctx,
|
|||||||
* above, we can safety ignore the return value.
|
* above, we can safety ignore the return value.
|
||||||
*/
|
*/
|
||||||
(void) mbedtls_chacha20_update( &ctx->chacha20_ctx, len, input, output );
|
(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 */
|
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 );
|
(void) mbedtls_chacha20_update( &ctx->chacha20_ctx, len, input, output );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,7 +289,7 @@ int mbedtls_chachapoly_finish( mbedtls_chachapoly_context *ctx,
|
|||||||
len_block[14] = (unsigned char) ( ctx->ciphertext_len >> 48 );
|
len_block[14] = (unsigned char) ( ctx->ciphertext_len >> 48 );
|
||||||
len_block[15] = (unsigned char) ( ctx->ciphertext_len >> 56 );
|
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 );
|
(void) mbedtls_poly1305_finish( &ctx->poly1305_ctx, mac );
|
||||||
|
|
||||||
return( 0 );
|
return( 0 );
|
||||||
|
@ -285,8 +285,8 @@ int mbedtls_poly1305_starts( mbedtls_poly1305_context *ctx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int mbedtls_poly1305_update( mbedtls_poly1305_context *ctx,
|
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 offset = 0U;
|
||||||
size_t remaining = ilen;
|
size_t remaining = ilen;
|
||||||
@ -391,9 +391,9 @@ int mbedtls_poly1305_finish( mbedtls_poly1305_context *ctx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int mbedtls_poly1305_mac( const unsigned char key[32],
|
int mbedtls_poly1305_mac( const unsigned char key[32],
|
||||||
size_t ilen,
|
const unsigned char *input,
|
||||||
const unsigned char *input,
|
size_t ilen,
|
||||||
unsigned char mac[16] )
|
unsigned char mac[16] )
|
||||||
{
|
{
|
||||||
mbedtls_poly1305_context ctx;
|
mbedtls_poly1305_context ctx;
|
||||||
int result;
|
int result;
|
||||||
@ -404,7 +404,7 @@ int mbedtls_poly1305_mac( const unsigned char key[32],
|
|||||||
if ( result != 0 )
|
if ( result != 0 )
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
result = mbedtls_poly1305_update( &ctx, ilen, input );
|
result = mbedtls_poly1305_update( &ctx, input, ilen );
|
||||||
if ( result != 0 )
|
if ( result != 0 )
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
@ -496,8 +496,8 @@ int mbedtls_poly1305_self_test( int verbose )
|
|||||||
}
|
}
|
||||||
|
|
||||||
result = mbedtls_poly1305_mac( test_keys[i],
|
result = mbedtls_poly1305_mac( test_keys[i],
|
||||||
test_data_len[i],
|
|
||||||
test_data[i],
|
test_data[i],
|
||||||
|
test_data_len[i],
|
||||||
mac );
|
mac );
|
||||||
if ( result != 0 )
|
if ( result != 0 )
|
||||||
{
|
{
|
||||||
|
@ -538,7 +538,7 @@ int main( int argc, char *argv[] )
|
|||||||
#if defined(MBEDTLS_POLY1305_C)
|
#if defined(MBEDTLS_POLY1305_C)
|
||||||
if ( todo.poly1305 )
|
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
|
#endif
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ void mbedtls_poly1305( char *hex_key_string, char *hex_mac_string, char *hex_src
|
|||||||
src_len = unhexify( src_str, hex_src_string );
|
src_len = unhexify( src_str, hex_src_string );
|
||||||
unhexify( key, hex_key_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 );
|
hexify( mac_str, mac, 16 );
|
||||||
|
|
||||||
TEST_ASSERT( strcmp( (char *) mac_str, hex_mac_string ) == 0 );
|
TEST_ASSERT( strcmp( (char *) mac_str, hex_mac_string ) == 0 );
|
||||||
|
Loading…
Reference in New Issue
Block a user