mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
Externals: Update mbedtls to 2.16.1
On a few of our buildbot instances, we get warnings about the usage of deprecated functions. We should correct these, especially if we're delegating to system versions of the libraries if they're available. However, in order to do that, we need to update our library variant from 2.1.1 so that the non-deprecated alternatives are actually available.
This commit is contained in:
71
Externals/mbedtls/library/cmac.c
vendored
71
Externals/mbedtls/library/cmac.c
vendored
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/**
|
||||
* \file cmac.c
|
||||
*
|
||||
* \brief NIST SP800-38B compliant CMAC implementation for AES and 3DES
|
||||
@ -49,6 +49,7 @@
|
||||
#if defined(MBEDTLS_CMAC_C)
|
||||
|
||||
#include "mbedtls/cmac.h"
|
||||
#include "mbedtls/platform_util.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@ -62,13 +63,10 @@
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
#include <stdio.h>
|
||||
#define mbedtls_printf printf
|
||||
#endif /* MBEDTLS_SELF_TEST && MBEDTLS_AES_C || MBEDTLS_DES_C */
|
||||
#endif /* MBEDTLS_SELF_TEST */
|
||||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
|
||||
/* Implementation that should never be optimized out by the compiler */
|
||||
static void mbedtls_zeroize( void *v, size_t n ) {
|
||||
volatile unsigned char *p = (unsigned char*)v; while( n-- ) *p++ = 0;
|
||||
}
|
||||
#if !defined(MBEDTLS_CMAC_ALT) || defined(MBEDTLS_SELF_TEST)
|
||||
|
||||
/*
|
||||
* Multiplication by u in the Galois field of GF(2^n)
|
||||
@ -80,7 +78,7 @@ static void mbedtls_zeroize( void *v, size_t n ) {
|
||||
* with R_64 = 0x1B and R_128 = 0x87
|
||||
*
|
||||
* Input and output MUST NOT point to the same buffer
|
||||
* Block size must be 8 byes or 16 bytes - the block sizes for DES and AES.
|
||||
* Block size must be 8 bytes or 16 bytes - the block sizes for DES and AES.
|
||||
*/
|
||||
static int cmac_multiply_by_u( unsigned char *output,
|
||||
const unsigned char *input,
|
||||
@ -105,7 +103,7 @@ static int cmac_multiply_by_u( unsigned char *output,
|
||||
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
||||
}
|
||||
|
||||
for( i = blocksize - 1; i >= 0; i-- )
|
||||
for( i = (int)blocksize - 1; i >= 0; i-- )
|
||||
{
|
||||
output[i] = input[i] << 1 | overflow;
|
||||
overflow = input[i] >> 7;
|
||||
@ -142,7 +140,7 @@ static int cmac_generate_subkeys( mbedtls_cipher_context_t *ctx,
|
||||
unsigned char L[MBEDTLS_CIPHER_BLKSIZE_MAX];
|
||||
size_t olen, block_size;
|
||||
|
||||
mbedtls_zeroize( L, sizeof( L ) );
|
||||
mbedtls_platform_zeroize( L, sizeof( L ) );
|
||||
|
||||
block_size = ctx->cipher_info->block_size;
|
||||
|
||||
@ -160,19 +158,21 @@ static int cmac_generate_subkeys( mbedtls_cipher_context_t *ctx,
|
||||
goto exit;
|
||||
|
||||
exit:
|
||||
mbedtls_zeroize( L, sizeof( L ) );
|
||||
mbedtls_platform_zeroize( L, sizeof( L ) );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
#endif /* !defined(MBEDTLS_CMAC_ALT) || defined(MBEDTLS_SELF_TEST) */
|
||||
|
||||
#if !defined(MBEDTLS_CMAC_ALT)
|
||||
static void cmac_xor_block( unsigned char *output, const unsigned char *input1,
|
||||
const unsigned char *input2,
|
||||
const size_t block_size )
|
||||
{
|
||||
size_t index;
|
||||
size_t idx;
|
||||
|
||||
for( index = 0; index < block_size; index++ )
|
||||
output[ index ] = input1[ index ] ^ input2[ index ];
|
||||
for( idx = 0; idx < block_size; idx++ )
|
||||
output[ idx ] = input1[ idx ] ^ input2[ idx ];
|
||||
}
|
||||
|
||||
/*
|
||||
@ -209,7 +209,7 @@ int mbedtls_cipher_cmac_starts( mbedtls_cipher_context_t *ctx,
|
||||
if( ctx == NULL || ctx->cipher_info == NULL || key == NULL )
|
||||
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
||||
|
||||
if( ( retval = mbedtls_cipher_setkey( ctx, key, keybits,
|
||||
if( ( retval = mbedtls_cipher_setkey( ctx, key, (int)keybits,
|
||||
MBEDTLS_ENCRYPT ) ) != 0 )
|
||||
return( retval );
|
||||
|
||||
@ -234,7 +234,7 @@ int mbedtls_cipher_cmac_starts( mbedtls_cipher_context_t *ctx,
|
||||
|
||||
ctx->cmac_ctx = cmac_ctx;
|
||||
|
||||
mbedtls_zeroize( cmac_ctx->state, sizeof( cmac_ctx->state ) );
|
||||
mbedtls_platform_zeroize( cmac_ctx->state, sizeof( cmac_ctx->state ) );
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -244,8 +244,8 @@ int mbedtls_cipher_cmac_update( mbedtls_cipher_context_t *ctx,
|
||||
{
|
||||
mbedtls_cmac_context_t* cmac_ctx;
|
||||
unsigned char *state;
|
||||
int n, j, ret = 0;
|
||||
size_t olen, block_size;
|
||||
int ret = 0;
|
||||
size_t n, j, olen, block_size;
|
||||
|
||||
if( ctx == NULL || ctx->cipher_info == NULL || input == NULL ||
|
||||
ctx->cmac_ctx == NULL )
|
||||
@ -280,8 +280,9 @@ int mbedtls_cipher_cmac_update( mbedtls_cipher_context_t *ctx,
|
||||
/* n is the number of blocks including any final partial block */
|
||||
n = ( ilen + block_size - 1 ) / block_size;
|
||||
|
||||
/* Iterate across the input data in block sized chunks */
|
||||
for( j = 0; j < n - 1; j++ )
|
||||
/* Iterate across the input data in block sized chunks, excluding any
|
||||
* final partial or complete block */
|
||||
for( j = 1; j < n; j++ )
|
||||
{
|
||||
cmac_xor_block( state, input, state, block_size );
|
||||
|
||||
@ -325,8 +326,8 @@ int mbedtls_cipher_cmac_finish( mbedtls_cipher_context_t *ctx,
|
||||
block_size = ctx->cipher_info->block_size;
|
||||
state = cmac_ctx->state;
|
||||
|
||||
mbedtls_zeroize( K1, sizeof( K1 ) );
|
||||
mbedtls_zeroize( K2, sizeof( K2 ) );
|
||||
mbedtls_platform_zeroize( K1, sizeof( K1 ) );
|
||||
mbedtls_platform_zeroize( K2, sizeof( K2 ) );
|
||||
cmac_generate_subkeys( ctx, K1, K2 );
|
||||
|
||||
last_block = cmac_ctx->unprocessed_block;
|
||||
@ -356,14 +357,14 @@ int mbedtls_cipher_cmac_finish( mbedtls_cipher_context_t *ctx,
|
||||
exit:
|
||||
/* Wipe the generated keys on the stack, and any other transients to avoid
|
||||
* side channel leakage */
|
||||
mbedtls_zeroize( K1, sizeof( K1 ) );
|
||||
mbedtls_zeroize( K2, sizeof( K2 ) );
|
||||
mbedtls_platform_zeroize( K1, sizeof( K1 ) );
|
||||
mbedtls_platform_zeroize( K2, sizeof( K2 ) );
|
||||
|
||||
cmac_ctx->unprocessed_len = 0;
|
||||
mbedtls_zeroize( cmac_ctx->unprocessed_block,
|
||||
sizeof( cmac_ctx->unprocessed_block ) );
|
||||
mbedtls_platform_zeroize( cmac_ctx->unprocessed_block,
|
||||
sizeof( cmac_ctx->unprocessed_block ) );
|
||||
|
||||
mbedtls_zeroize( state, MBEDTLS_CIPHER_BLKSIZE_MAX );
|
||||
mbedtls_platform_zeroize( state, MBEDTLS_CIPHER_BLKSIZE_MAX );
|
||||
return( ret );
|
||||
}
|
||||
|
||||
@ -378,10 +379,10 @@ int mbedtls_cipher_cmac_reset( mbedtls_cipher_context_t *ctx )
|
||||
|
||||
/* Reset the internal state */
|
||||
cmac_ctx->unprocessed_len = 0;
|
||||
mbedtls_zeroize( cmac_ctx->unprocessed_block,
|
||||
sizeof( cmac_ctx->unprocessed_block ) );
|
||||
mbedtls_zeroize( cmac_ctx->state,
|
||||
sizeof( cmac_ctx->state ) );
|
||||
mbedtls_platform_zeroize( cmac_ctx->unprocessed_block,
|
||||
sizeof( cmac_ctx->unprocessed_block ) );
|
||||
mbedtls_platform_zeroize( cmac_ctx->state,
|
||||
sizeof( cmac_ctx->state ) );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
@ -461,12 +462,14 @@ int mbedtls_aes_cmac_prf_128( const unsigned char *key, size_t key_length,
|
||||
output );
|
||||
|
||||
exit:
|
||||
mbedtls_zeroize( int_key, sizeof( int_key ) );
|
||||
mbedtls_platform_zeroize( int_key, sizeof( int_key ) );
|
||||
|
||||
return( ret );
|
||||
}
|
||||
#endif /* MBEDTLS_AES_C */
|
||||
|
||||
#endif /* !MBEDTLS_CMAC_ALT */
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
/*
|
||||
* CMAC test data for SP800-38B
|
||||
@ -764,7 +767,7 @@ static int cmac_test_subkeys( int verbose,
|
||||
int block_size,
|
||||
int num_tests )
|
||||
{
|
||||
int i, ret;
|
||||
int i, ret = 0;
|
||||
mbedtls_cipher_context_t ctx;
|
||||
const mbedtls_cipher_info_t *cipher_info;
|
||||
unsigned char K1[MBEDTLS_CIPHER_BLKSIZE_MAX];
|
||||
@ -825,6 +828,7 @@ static int cmac_test_subkeys( int verbose,
|
||||
mbedtls_cipher_free( &ctx );
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
goto exit;
|
||||
|
||||
cleanup:
|
||||
@ -846,7 +850,7 @@ static int cmac_test_wth_cipher( int verbose,
|
||||
int num_tests )
|
||||
{
|
||||
const mbedtls_cipher_info_t *cipher_info;
|
||||
int i, ret;
|
||||
int i, ret = 0;
|
||||
unsigned char output[MBEDTLS_CIPHER_BLKSIZE_MAX];
|
||||
|
||||
cipher_info = mbedtls_cipher_info_from_type( cipher_type );
|
||||
@ -880,6 +884,7 @@ static int cmac_test_wth_cipher( int verbose,
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
}
|
||||
ret = 0;
|
||||
|
||||
exit:
|
||||
return( ret );
|
||||
|
Reference in New Issue
Block a user