mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-29 09:24:18 +01:00
Rm mbedtls_ prefix form static functions
- prefix is no necessary for static ids and makes lines longer - most often omitted (even though we're not fully consistent)
This commit is contained in:
parent
c22e61a081
commit
9620f9b99e
@ -76,11 +76,11 @@
|
|||||||
* \param c The index of 'c' in the state.
|
* \param c The index of 'c' in the state.
|
||||||
* \param d The index of 'd' in the state.
|
* \param d The index of 'd' in the state.
|
||||||
*/
|
*/
|
||||||
static inline void mbedtls_chacha20_quarter_round( uint32_t state[16],
|
static inline void chacha20_quarter_round( uint32_t state[16],
|
||||||
size_t a,
|
size_t a,
|
||||||
size_t b,
|
size_t b,
|
||||||
size_t c,
|
size_t c,
|
||||||
size_t d )
|
size_t d )
|
||||||
{
|
{
|
||||||
/* a += b; d ^= a; d <<<= 16; */
|
/* a += b; d ^= a; d <<<= 16; */
|
||||||
state[a] += state[b];
|
state[a] += state[b];
|
||||||
@ -111,17 +111,17 @@ static inline void mbedtls_chacha20_quarter_round( uint32_t state[16],
|
|||||||
*
|
*
|
||||||
* \param state The ChaCha20 state to update.
|
* \param state The ChaCha20 state to update.
|
||||||
*/
|
*/
|
||||||
static void mbedtls_chacha20_inner_block( uint32_t state[16] )
|
static void chacha20_inner_block( uint32_t state[16] )
|
||||||
{
|
{
|
||||||
mbedtls_chacha20_quarter_round( state, 0, 4, 8, 12 );
|
chacha20_quarter_round( state, 0, 4, 8, 12 );
|
||||||
mbedtls_chacha20_quarter_round( state, 1, 5, 9, 13 );
|
chacha20_quarter_round( state, 1, 5, 9, 13 );
|
||||||
mbedtls_chacha20_quarter_round( state, 2, 6, 10, 14 );
|
chacha20_quarter_round( state, 2, 6, 10, 14 );
|
||||||
mbedtls_chacha20_quarter_round( state, 3, 7, 11, 15 );
|
chacha20_quarter_round( state, 3, 7, 11, 15 );
|
||||||
|
|
||||||
mbedtls_chacha20_quarter_round( state, 0, 5, 10, 15 );
|
chacha20_quarter_round( state, 0, 5, 10, 15 );
|
||||||
mbedtls_chacha20_quarter_round( state, 1, 6, 11, 12 );
|
chacha20_quarter_round( state, 1, 6, 11, 12 );
|
||||||
mbedtls_chacha20_quarter_round( state, 2, 7, 8, 13 );
|
chacha20_quarter_round( state, 2, 7, 8, 13 );
|
||||||
mbedtls_chacha20_quarter_round( state, 3, 4, 9, 14 );
|
chacha20_quarter_round( state, 3, 4, 9, 14 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -131,9 +131,9 @@ static void mbedtls_chacha20_inner_block( uint32_t state[16] )
|
|||||||
* \param working_state This state is used as a temporary working area.
|
* \param working_state This state is used as a temporary working area.
|
||||||
* \param keystream Generated keystream bytes are written to this buffer.
|
* \param keystream Generated keystream bytes are written to this buffer.
|
||||||
*/
|
*/
|
||||||
static void mbedtls_chacha20_block( const uint32_t initial_state[16],
|
static void chacha20_block( const uint32_t initial_state[16],
|
||||||
uint32_t working_state[16],
|
uint32_t working_state[16],
|
||||||
unsigned char keystream[64] )
|
unsigned char keystream[64] )
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
size_t offset;
|
size_t offset;
|
||||||
@ -143,9 +143,7 @@ static void mbedtls_chacha20_block( const uint32_t initial_state[16],
|
|||||||
CHACHA20_BLOCK_SIZE_BYTES );
|
CHACHA20_BLOCK_SIZE_BYTES );
|
||||||
|
|
||||||
for ( i = 0U; i < 10U; i++ )
|
for ( i = 0U; i < 10U; i++ )
|
||||||
{
|
chacha20_inner_block( working_state );
|
||||||
mbedtls_chacha20_inner_block( working_state );
|
|
||||||
}
|
|
||||||
|
|
||||||
working_state[0] += initial_state[0];
|
working_state[0] += initial_state[0];
|
||||||
working_state[1] += initial_state[1];
|
working_state[1] += initial_state[1];
|
||||||
@ -281,7 +279,7 @@ int mbedtls_chacha20_update( mbedtls_chacha20_context *ctx,
|
|||||||
while ( size >= CHACHA20_BLOCK_SIZE_BYTES )
|
while ( size >= CHACHA20_BLOCK_SIZE_BYTES )
|
||||||
{
|
{
|
||||||
/* Generate new keystream block and increment counter */
|
/* Generate new keystream block and increment counter */
|
||||||
mbedtls_chacha20_block( ctx->initial_state, ctx->working_state, ctx->keystream8 );
|
chacha20_block( ctx->initial_state, ctx->working_state, ctx->keystream8 );
|
||||||
ctx->initial_state[CHACHA20_CTR_INDEX]++;
|
ctx->initial_state[CHACHA20_CTR_INDEX]++;
|
||||||
|
|
||||||
for ( i = 0U; i < 64U; i += 8U )
|
for ( i = 0U; i < 64U; i += 8U )
|
||||||
@ -304,7 +302,7 @@ int mbedtls_chacha20_update( mbedtls_chacha20_context *ctx,
|
|||||||
if ( size > 0U )
|
if ( size > 0U )
|
||||||
{
|
{
|
||||||
/* Generate new keystream block and increment counter */
|
/* Generate new keystream block and increment counter */
|
||||||
mbedtls_chacha20_block( ctx->initial_state, ctx->working_state, ctx->keystream8 );
|
chacha20_block( ctx->initial_state, ctx->working_state, ctx->keystream8 );
|
||||||
ctx->initial_state[CHACHA20_CTR_INDEX]++;
|
ctx->initial_state[CHACHA20_CTR_INDEX]++;
|
||||||
|
|
||||||
for ( i = 0U; i < size; i++)
|
for ( i = 0U; i < size; i++)
|
||||||
|
@ -54,7 +54,7 @@
|
|||||||
*
|
*
|
||||||
* \param ctx The ChaCha20-Poly1305 context.
|
* \param ctx The ChaCha20-Poly1305 context.
|
||||||
*/
|
*/
|
||||||
static void mbedtls_chachapoly_pad_aad( mbedtls_chachapoly_context *ctx )
|
static void chachapoly_pad_aad( mbedtls_chachapoly_context *ctx )
|
||||||
{
|
{
|
||||||
uint32_t partial_block_len = (uint32_t) ( ctx->aad_len % 16U );
|
uint32_t partial_block_len = (uint32_t) ( ctx->aad_len % 16U );
|
||||||
unsigned char zeroes[15];
|
unsigned char zeroes[15];
|
||||||
@ -73,7 +73,7 @@ static void mbedtls_chachapoly_pad_aad( mbedtls_chachapoly_context *ctx )
|
|||||||
*
|
*
|
||||||
* \param ctx The ChaCha20-Poly1305 context.
|
* \param ctx The ChaCha20-Poly1305 context.
|
||||||
*/
|
*/
|
||||||
static void mbedtls_chachapoly_pad_ciphertext( mbedtls_chachapoly_context *ctx )
|
static void chachapoly_pad_ciphertext( mbedtls_chachapoly_context *ctx )
|
||||||
{
|
{
|
||||||
uint32_t partial_block_len = (uint32_t) ( ctx->ciphertext_len % 16U );
|
uint32_t partial_block_len = (uint32_t) ( ctx->ciphertext_len % 16U );
|
||||||
unsigned char zeroes[15];
|
unsigned char zeroes[15];
|
||||||
@ -218,7 +218,7 @@ int mbedtls_chachapoly_update( mbedtls_chachapoly_context *ctx,
|
|||||||
{
|
{
|
||||||
ctx->state = CHACHAPOLY_STATE_CIPHERTEXT;
|
ctx->state = CHACHAPOLY_STATE_CIPHERTEXT;
|
||||||
|
|
||||||
mbedtls_chachapoly_pad_aad( ctx );
|
chachapoly_pad_aad( ctx );
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->ciphertext_len += len;
|
ctx->ciphertext_len += len;
|
||||||
@ -257,11 +257,11 @@ int mbedtls_chachapoly_finish( mbedtls_chachapoly_context *ctx,
|
|||||||
|
|
||||||
if ( ctx->state == CHACHAPOLY_STATE_AAD )
|
if ( ctx->state == CHACHAPOLY_STATE_AAD )
|
||||||
{
|
{
|
||||||
mbedtls_chachapoly_pad_aad( ctx );
|
chachapoly_pad_aad( ctx );
|
||||||
}
|
}
|
||||||
else if ( ctx->state == CHACHAPOLY_STATE_CIPHERTEXT )
|
else if ( ctx->state == CHACHAPOLY_STATE_CIPHERTEXT )
|
||||||
{
|
{
|
||||||
mbedtls_chachapoly_pad_ciphertext( ctx );
|
chachapoly_pad_ciphertext( ctx );
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->state = CHACHAPOLY_STATE_FINISHED;
|
ctx->state = CHACHAPOLY_STATE_FINISHED;
|
||||||
|
@ -64,10 +64,10 @@
|
|||||||
* to the input data before calling this function.
|
* to the input data before calling this function.
|
||||||
* Otherwise, set this parameter to 1.
|
* Otherwise, set this parameter to 1.
|
||||||
*/
|
*/
|
||||||
static void mbedtls_poly1305_process( mbedtls_poly1305_context *ctx,
|
static void poly1305_process( mbedtls_poly1305_context *ctx,
|
||||||
size_t nblocks,
|
size_t nblocks,
|
||||||
const unsigned char *input,
|
const unsigned char *input,
|
||||||
uint32_t needs_padding )
|
uint32_t needs_padding )
|
||||||
{
|
{
|
||||||
uint64_t d0, d1, d2, d3;
|
uint64_t d0, d1, d2, d3;
|
||||||
uint32_t acc0, acc1, acc2, acc3, acc4;
|
uint32_t acc0, acc1, acc2, acc3, acc4;
|
||||||
@ -167,8 +167,8 @@ static void mbedtls_poly1305_process( mbedtls_poly1305_context *ctx,
|
|||||||
* \param mac The buffer to where the MAC is written. Must be
|
* \param mac The buffer to where the MAC is written. Must be
|
||||||
* big enough to contain the 16-byte MAC.
|
* big enough to contain the 16-byte MAC.
|
||||||
*/
|
*/
|
||||||
static void mbedtls_poly1305_compute_mac( const mbedtls_poly1305_context *ctx,
|
static void poly1305_compute_mac( const mbedtls_poly1305_context *ctx,
|
||||||
unsigned char mac[16] )
|
unsigned char mac[16] )
|
||||||
{
|
{
|
||||||
uint64_t d;
|
uint64_t d;
|
||||||
uint32_t g0, g1, g2, g3, g4;
|
uint32_t g0, g1, g2, g3, g4;
|
||||||
@ -330,10 +330,7 @@ int mbedtls_poly1305_update( mbedtls_poly1305_context *ctx,
|
|||||||
|
|
||||||
ctx->queue_len = 0U;
|
ctx->queue_len = 0U;
|
||||||
|
|
||||||
mbedtls_poly1305_process( ctx,
|
poly1305_process( ctx, 1U, ctx->queue, 1U ); /* add padding bit */
|
||||||
1U,
|
|
||||||
ctx->queue,
|
|
||||||
1U ); /* add padding bit */
|
|
||||||
|
|
||||||
offset += queue_free_len;
|
offset += queue_free_len;
|
||||||
remaining -= queue_free_len;
|
remaining -= queue_free_len;
|
||||||
@ -344,7 +341,7 @@ int mbedtls_poly1305_update( mbedtls_poly1305_context *ctx,
|
|||||||
{
|
{
|
||||||
nblocks = remaining / POLY1305_BLOCK_SIZE_BYTES;
|
nblocks = remaining / POLY1305_BLOCK_SIZE_BYTES;
|
||||||
|
|
||||||
mbedtls_poly1305_process( ctx, nblocks, &input[offset], 1U );
|
poly1305_process( ctx, nblocks, &input[offset], 1U );
|
||||||
|
|
||||||
offset += nblocks * POLY1305_BLOCK_SIZE_BYTES;
|
offset += nblocks * POLY1305_BLOCK_SIZE_BYTES;
|
||||||
remaining %= POLY1305_BLOCK_SIZE_BYTES;
|
remaining %= POLY1305_BLOCK_SIZE_BYTES;
|
||||||
@ -380,13 +377,11 @@ int mbedtls_poly1305_finish( mbedtls_poly1305_context *ctx,
|
|||||||
0,
|
0,
|
||||||
POLY1305_BLOCK_SIZE_BYTES - ctx->queue_len );
|
POLY1305_BLOCK_SIZE_BYTES - ctx->queue_len );
|
||||||
|
|
||||||
mbedtls_poly1305_process( ctx,
|
poly1305_process( ctx, 1U, /* Process 1 block */
|
||||||
1U, /* Process 1 block */
|
ctx->queue, 0U ); /* Don't add padding bit (it was just added above) */
|
||||||
ctx->queue,
|
|
||||||
0U ); /* Don't add padding bit (it was just added above) */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mbedtls_poly1305_compute_mac( ctx, mac );
|
poly1305_compute_mac( ctx, mac );
|
||||||
|
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user