- Small code rewrite

This commit is contained in:
Paul Bakker 2012-04-18 14:16:09 +00:00
parent 7890405856
commit 369e14bbf1
3 changed files with 16 additions and 26 deletions

View File

@ -888,7 +888,7 @@ int aes_crypt_ctr( aes_context *ctx,
const unsigned char *input, const unsigned char *input,
unsigned char *output ) unsigned char *output )
{ {
int c, i, cb; int c, i;
size_t n = *nc_off; size_t n = *nc_off;
while( length-- ) while( length-- )
@ -896,12 +896,9 @@ int aes_crypt_ctr( aes_context *ctx,
if( n == 0 ) { if( n == 0 ) {
aes_crypt_ecb( ctx, AES_ENCRYPT, nonce_counter, stream_block ); aes_crypt_ecb( ctx, AES_ENCRYPT, nonce_counter, stream_block );
i = 15; for( i = 16; i > 0; i-- )
do { if( ++nonce_counter[i - 1] != 0 )
nonce_counter[i]++; break;
cb = nonce_counter[i] == 0;
} while( i-- && cb );
} }
c = *input++; c = *input++;
*output++ = (unsigned char)( c ^ stream_block[n] ); *output++ = (unsigned char)( c ^ stream_block[n] );

View File

@ -633,7 +633,7 @@ int camellia_crypt_ctr( camellia_context *ctx,
const unsigned char *input, const unsigned char *input,
unsigned char *output ) unsigned char *output )
{ {
int c, i, cb; int c, i;
size_t n = *nc_off; size_t n = *nc_off;
while( length-- ) while( length-- )
@ -641,12 +641,9 @@ int camellia_crypt_ctr( camellia_context *ctx,
if( n == 0 ) { if( n == 0 ) {
camellia_crypt_ecb( ctx, CAMELLIA_ENCRYPT, nonce_counter, stream_block ); camellia_crypt_ecb( ctx, CAMELLIA_ENCRYPT, nonce_counter, stream_block );
i = 15; for( i = 16; i > 0; i-- )
do { if( ++nonce_counter[i - 1] != 0 )
nonce_counter[i]++; break;
cb = nonce_counter[i] == 0;
} while( i-- && cb );
} }
c = *input++; c = *input++;
*output++ = (unsigned char)( c ^ stream_block[n] ); *output++ = (unsigned char)( c ^ stream_block[n] );

View File

@ -185,7 +185,7 @@ int ctr_drbg_update_internal( ctr_drbg_context *ctx,
{ {
unsigned char tmp[CTR_DRBG_SEEDLEN]; unsigned char tmp[CTR_DRBG_SEEDLEN];
unsigned char *p = tmp; unsigned char *p = tmp;
int cb, i, j; int i, j;
memset( tmp, 0, CTR_DRBG_SEEDLEN ); memset( tmp, 0, CTR_DRBG_SEEDLEN );
@ -194,11 +194,9 @@ int ctr_drbg_update_internal( ctr_drbg_context *ctx,
/* /*
* Increase counter * Increase counter
*/ */
i = CTR_DRBG_BLOCKSIZE - 1; for( i = CTR_DRBG_BLOCKSIZE; i >= 0; i-- )
do { if( ++ctx->counter[i - 1] != 0 )
ctx->counter[i]++; break;
cb = ctx->counter[i] == 0;
} while( i-- && cb );
/* /*
* Crypt counter block * Crypt counter block
@ -286,7 +284,7 @@ int ctr_drbg_random_with_add( void *p_rng,
unsigned char add_input[CTR_DRBG_SEEDLEN]; unsigned char add_input[CTR_DRBG_SEEDLEN];
unsigned char *p = output; unsigned char *p = output;
unsigned char tmp[CTR_DRBG_BLOCKSIZE]; unsigned char tmp[CTR_DRBG_BLOCKSIZE];
int cb, i; int i;
size_t use_len; size_t use_len;
if( output_len > CTR_DRBG_MAX_REQUEST ) if( output_len > CTR_DRBG_MAX_REQUEST )
@ -317,11 +315,9 @@ int ctr_drbg_random_with_add( void *p_rng,
/* /*
* Increase counter * Increase counter
*/ */
i = CTR_DRBG_BLOCKSIZE - 1; for( i = CTR_DRBG_BLOCKSIZE; i > 0; i-- )
do { if( ++ctx->counter[i - 1] != 0 )
ctx->counter[i]++; break;
cb = ctx->counter[i] == 0;
} while( i-- && cb );
/* /*
* Crypt counter block * Crypt counter block