Skip to content

Commit

Permalink
Emulator actual embodiment: addressing pre-C99 requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
divanchykhin committed May 15, 2015
1 parent 78a105f commit 51005f6
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 24 deletions.
9 changes: 6 additions & 3 deletions tests/emulator/sa-aes-128.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ void sa_aes_128_nextKeyExp(uint8_t* ksc, uint8_t* rcon)
ksc[2] ^= rijndael_sbox[ksc[15]];
ksc[3] ^= rijndael_sbox[ksc[12]]; // RotWord

for (uint8_t i = 4; i < 16; i += 4)
uint8_t i;
for ( i= 4; i < 16; i += 4)
{
ksc[i] ^= ksc[i-4];
ksc[i+1] ^= ksc[i-3];
Expand Down Expand Up @@ -86,7 +87,8 @@ void sa_aes_128_shiftRows(uint8_t* block)
void sa_aes_128_mixColumns(uint8_t* block)
{
uint8_t a, b, c, d, e;
for (uint8_t i = 0; i < 16; i += 4)
uint8_t i;
for ( i = 0; i < 16; i += 4)
{
a = block[i];
b = block[i + 1];
Expand All @@ -113,7 +115,8 @@ void sa_aes_128_encrypt_block( const uint8_t* key, const uint8_t* _block, uint8_
for (i = 0; i < 16; (i)++) // add round key
block[i] ^= ksc[i];

for ( uint8_t round=0; round<9; round++ )
uint8_t round;
for ( round=0; round<9; round++ )
{
for (i = 0; i < 16; (i)++) // subBytes
block[i] = rijndael_sbox[block[i]];
Expand Down
6 changes: 4 additions & 2 deletions tests/emulator/sa-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ Copyright (C) 2015 OLogN Technologies AG
/*
INLINE void memset( void* dest, uint8_t val, uint8_t cnt )
{
for ( uint8_t i=0; i<cnt; i++ )
uint8_t i;
for ( i=0; i<cnt; i++ )
((uint8_t*)dest)[i] = val;
}
INLINE void memcpy( void* dest, const void* src, uint8_t cnt )
{
for ( uint8_t i=0; i<cnt; i++ )
uint8_t i;
for ( i=0; i<cnt; i++ )
((uint8_t*)dest)[i] = ((uint8_t*)src)[i];
}
*/
Expand Down
9 changes: 6 additions & 3 deletions tests/emulator/sa-eax-128.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ Copyright (C) 2015 OLogN Technologies AG
void eax_128_galois_times_2( uint8_t * buff )
{
bool xor_required = *buff &0x80; // MSB
for ( uint8_t i=0; i<15; i++ )
uint8_t i;
for ( i=0; i<15; i++ )
{
buff[i] <<= 1;
buff[i] |= buff[i+1]>>7;
Expand Down Expand Up @@ -80,7 +81,8 @@ void eax_128_init_cbc( uint8_t* state )
void eax_128_update_cbc( const uint8_t* key, const uint8_t* block, uint8_t* cbc )
{
uint8_t temp_blk[16];
for ( uint8_t i=0; i<16; i++ )
uint8_t i;
for ( i=0; i<16; i++ )
temp_blk[i] = cbc[i] ^ block[i];
sa_aes_128_encrypt_block( key, temp_blk, cbc);
}
Expand Down Expand Up @@ -185,7 +187,8 @@ void eax_128_calc_tag( /*const uint8_t* key,*/ uint8_t* header_prim, uint8_t* ms
/* sa_aes_print_block_16("nonce_prim: ", tag_out);
sa_aes_print_block_16("header_prim: ", header_prim);
sa_aes_print_block_16("t_blk_out_omac: ", msg_cbc_val);*/
for ( uint8_t i=0; i<tag_out_sz; i++ )
uint8_t i;
for ( i=0; i<tag_out_sz; i++ )
tag_out[i] ^= header_prim[i] ^ msg_cbc_val[i];
}

Expand Down
6 changes: 4 additions & 2 deletions tests/emulator/sa_test_control_prog.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ uint8_t default_test_control_program_start_new( void* control_prog_state, MEMORY

char tail[256];
uint16_t varln = 6 - ps->self_id % 7; // 0:6
for ( uint8_t i=0;i<varln; i++ )
uint8_t i;
for ( i=0;i<varln; i++ )
tail[ i] = '-';
tail[ varln ] = '>';
tail[ varln + 1 ] = 0;
Expand Down Expand Up @@ -136,7 +137,8 @@ uint8_t default_test_control_program_accept_reply_continue( void* control_prog_s

char tail[256];
uint16_t varln = 6 - ps->self_id % 7; // 0:6
for ( uint8_t i=0;i<varln; i++ )
uint8_t i;
for ( i=0;i<varln; i++ )
tail[ i] = '-';
tail[ varln ] = '>';
tail[ varln + 1 ] = 0;
Expand Down
3 changes: 2 additions & 1 deletion tests/emulator/sa_test_plugins.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ uint8_t default_test_plugin_handler_continue( const void* plugin_config, void* p

char tail[256];
uint16_t varln = 6 - ps->self_id % 7; // 0:6
for ( uint8_t i=0;i<varln; i++ )
uint8_t i;
for ( i=0;i<varln; i++ )
tail[ i] = '-';
tail[ varln ] = '>';
tail[ varln + 1 ] = 0;
Expand Down
2 changes: 1 addition & 1 deletion tests/emulator/sagdp_protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void sagdp_init( SAGDP_DATA* sagdp_data )
if (sec_pow > SAGDP_LTO_POW_MAX) sec_pow = SAGDP_LTO_POW_MAX; \
SA_TIME_LOAD_TICKS_FOR_1_SEC( tmp_t ); \
SA_TIME_MUL_TICKS_BY_2( tmp_t ) \
for ( uint8_t i=0; i<=sec_pow; i++) SA_TIME_MUL_TICKS_BY_1_AND_A_HALF( tmp_t ) \
uint8_t i; for ( i=0; i<=sec_pow; i++) SA_TIME_MUL_TICKS_BY_1_AND_A_HALF( tmp_t ) \
SA_TIME_INCREMENT_BY_TICKS( tval, tmp_t ) \
}

Expand Down
9 changes: 6 additions & 3 deletions tests/emulator/sasp_protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ INLINE
void sasp_make_nonce_for_encryption( const sasp_nonce_type packet_id, uint8_t master_slave_bit, uint8_t nonce[16] )
{
memset( nonce, 0, 16 );
for ( int8_t i=0; i<sizeof(sasp_nonce_type); i++ )
int8_t i;
for ( i=0; i<sizeof(sasp_nonce_type); i++ )
{
nonce[i] = sa_uint48_get_byte( packet_id, i );
}
Expand Down Expand Up @@ -169,7 +170,8 @@ bool SASP_IntraPacketAuthenticateAndDecrypt( const uint8_t* key, REQUEST_REPLY_H
return false; // if any bytes, then the whole block

// now we have a decrypted data as output, and a tag "calculated"; check the tag
for ( uint8_t i=0; i<SASP_TAG_SIZE; i++ )
uint8_t i;
for ( i=0; i<SASP_TAG_SIZE; i++ )
if ( tag_calculted[i] != block[i] ) return false;

return true;
Expand Down Expand Up @@ -246,7 +248,8 @@ void DEBUG_SASP_EncryptAndAddAuthenticationDataChecked( MEMORY_HANDLE mem_h, con
assert( ipaad );
assert( decr_sz == inisz );
assert( memcmp( nonce, dbg_nonce, 6 ) == 0 );
for ( int k=0; k<decr_sz; k++ )
uint8_t k;
for ( k=0; k<decr_sz; k++ )
assert( inimsg[k] == checkedMsg[k] );
}

Expand Down
3 changes: 2 additions & 1 deletion tests/emulator/test-counters.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ const char* CTRS_NAMES_D[MAX_COUNTERS_CNT];
void printCounters()
{
printf( "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" );
for ( int i=0; i<MAX_COUNTERS_CNT; i++ )
uint16_t i;
for ( i=0; i<MAX_COUNTERS_CNT; i++ )
{
if ( CTRS_NAMES[ i ] )
printf( "%d:\t[%d] %s\n", COUNTERS[ i ], i, CTRS_NAMES[ i ] );
Expand Down
6 changes: 4 additions & 2 deletions tests/emulator/test-generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ uint16_t tester_get_rand_val()
void tester_registerIncomingPacketCore( const uint8_t* packet, uint16_t size )
{
assert( size <= PACKET_MAX_SIZE );
for ( int8_t i=MAX_IPACKETS_TO_STORE-1; i; i-- )
int8_t i;
for ( i=MAX_IPACKETS_TO_STORE-1; i; i-- )
memcpy( incomingPackets + i * PACKET_MAX_SIZE, incomingPackets + (i-1)*PACKET_MAX_SIZE, PACKET_MAX_SIZE );
*(uint16_t*)incomingPackets = size;
memcpy( incomingPackets + 2, packet, size );
Expand All @@ -210,7 +211,8 @@ void tester_registerIncomingPacketCore( const uint8_t* packet, uint16_t size )
void tester_registerOutgoingPacketCore( const uint8_t* packet, uint16_t size )
{
assert( size <= PACKET_MAX_SIZE );
for ( int8_t i=MAX_IPACKETS_TO_STORE-1; i; i-- )
int8_t i;
for ( i=MAX_IPACKETS_TO_STORE-1; i; i-- )
memcpy( outgoingPackets + i * PACKET_MAX_SIZE, outgoingPackets + (i-1)*PACKET_MAX_SIZE, PACKET_MAX_SIZE );
*(uint16_t*)outgoingPackets = size;
memcpy( outgoingPackets + 2, packet, size );
Expand Down
9 changes: 6 additions & 3 deletions tests/emulator/yoctovm_protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ uint8_t slave_process_continue( REQUEST_REPLY_HANDLE mem_h/*, int buffOutSize, u

char tail[256];
uint16_t varln = 6 - self_id % 7; // 0:6
for ( uint8_t i=0;i<varln; i++ )
uint8_t i;
for ( i=0;i<varln; i++ )
tail[ i] = '-';
tail[ varln ] = '>';
tail[ varln + 1 ] = 0;
Expand Down Expand Up @@ -226,7 +227,8 @@ uint8_t master_start( REQUEST_REPLY_HANDLE mem_h/*, int buffOutSize, uint8_t* st

char tail[256];
uint16_t varln = 6 - self_id % 7; // 0:6
for ( uint8_t i=0;i<varln; i++ )
uint8_t i;
for ( i=0;i<varln; i++ )
tail[ i] = '-';
tail[ varln ] = '>';
tail[ varln + 1 ] = 0;
Expand Down Expand Up @@ -353,7 +355,8 @@ uint8_t master_process_continue( REQUEST_REPLY_HANDLE mem_h/*, int buffOutSize,

char tail[256];
uint16_t varln = 6 - self_id % 7; // 0:6
for ( uint8_t i=0;i<varln; i++ )
uint8_t i;
for ( i=0;i<varln; i++ )
tail[ i] = '-';
tail[ varln ] = '>';
tail[ varln + 1 ] = 0;
Expand Down
9 changes: 6 additions & 3 deletions tests/emulator/zepto-mem-mngmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ void zepto_mem_man_check_sanity()

void zepto_mem_man_init_memory_management()
{
for ( uint8_t i=0; i<MEMORY_HANDLE_MAX; i++ )
uint8_t i;
for ( i=0; i<MEMORY_HANDLE_MAX; i++ )
{
memset( &(memory_objects[i]), 0, sizeof( request_reply_mem_obj ) );
}
Expand Down Expand Up @@ -1172,7 +1173,8 @@ void zepto_parser_encode_uint( const uint8_t* num_bytes, uint8_t num_sz_max, uin
(*bytes_out)++;
interm >>= 7;
for ( uint8_t i=1; i<8; i++ )
uint8_t i;
for ( i=1; i<8; i++ )
{
if ( num_bytes < num_bytes_end )
{
Expand Down Expand Up @@ -1217,7 +1219,8 @@ void zepto_parser_decode_uint_core( uint8_t** packed_num_bytes, uint8_t* bytes_o
bytes_out++;
interm >>= 8;

for ( uint8_t i=1; i<8; i++ )
uint8_t i;
for ( i=1; i<8; i++ )
{
if ( (**packed_num_bytes & 0x80) == 0 )
{
Expand Down

0 comments on commit 51005f6

Please sign in to comment.