#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#define SIA_KEYMGR_CHAR_BIT 8u
#define SIA_KEYMGR_AES_BLOCK_BYTE_LEN 16u
uint8_t buf_0[ ] = { 11 , 12 , 13 , 14 , 15 , 17 , 18 , 19 , 0xfe } ;
uint8_t buf_test[ ] = { 1 , 2 , 3 , 4 , 5 , 7 , 20 , 1 , 0xfe , 44 , 55 , 66 , 77 , 88 , 99 , 10 , 11 , 24 , 0xfe , 1 , 2 , 3 , 4 , 5 , 7 , 20 , 1 , 2 , 0xfe , 0xfe , 43 } ;
uint8_t buf_test_2[ 256 ] ;
uint8_t length_check_for_eeprom_2( uint8_t * buff) ;
void data_process( uint8_t * old_data, uint8_t old_data_size, uint8_t * old_al, uint8_t * new_data) ;
void Sia_Keymgr_u32_to_n( uint8_t * out, uint32_t in)
{
unsigned int i;
for ( i = sizeof ( in) ; i > 0u; -- i)
{
out[ i - 1u] = ( uint8_t ) in;
in >>= SIA_KEYMGR_CHAR_BIT;
}
}
int main( void ) {
uint8_t m4lh_plain[ SIA_KEYMGR_AES_BLOCK_BYTE_LEN] ;
Sia_Keymgr_u32_to_n( m4lh_plain, ( 1u << 4 ) | 8u) ; /* set 32bit on the 128bit */
for ( int i = 0 ; i< SIA_KEYMGR_AES_BLOCK_BYTE_LEN; i++ )
{
printf ( "current val = 0x%x, \r \n " , m4lh_plain
[ i
] ) ; }
return 0 ;
}
uint8_t length_check_for_eeprom_2( uint8_t * buff)
{
uint8_t length= 0 ;
bool valid_data = false ;
uint8_t out;
for ( int i = 0 ; i< 256 ; i++ )
{
if ( ( * ( buff + i) != 0xfe ) || ( * ( buff + i + 1 ) != 0xfe ) )
{
//printf("current val = %d, next val = %d, length = %d \r\n",*(buff + i),*(buff + i + 1),length);
length= length+ 1 ;
}
// else if((*(buff + i)==0xfe)&&(*(buff + i + 1)==0xfe))
// {
// length++;
// valid_data = true;
// break;
// }
else
{ length= length+ 1 ;
valid_data = true ;
break ;
}
}
return ( valid_data== true ) ? length+ 1 : 0 ;
}
//must decalre array new_data[] with correct size before call this function
void data_process( uint8_t * old_data, uint8_t old_data_size, uint8_t * old_al, uint8_t * new_data)
{
if ( old_data_size == 0 )
{
* ( new_data+ 9 ) = 0xfe ;
}
else
{
memcpy ( new_data
, old_data
, old_data_size
) ; memcpy ( new_data
+ old_data_size
- 1 , old_al
, 9 ) ; * ( new_data+ old_data_size+ 8 ) = 0xfe ;
}
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRpbnQuaD4KI2luY2x1ZGUgPHN0ZGJvb2wuaD4KCiNkZWZpbmUgU0lBX0tFWU1HUl9DSEFSX0JJVCA4dQojZGVmaW5lIFNJQV9LRVlNR1JfQUVTX0JMT0NLX0JZVEVfTEVOIDE2dQp1aW50OF90IGJ1Zl8wW10gPSB7MTEsMTIsMTMsMTQsMTUsMTcsMTgsMTksMHhmZX07CnVpbnQ4X3QgYnVmX3Rlc3RbXSA9IHsxLDIsMyw0LDUsNywyMCwxLDB4ZmUsNDQsNTUsNjYsNzcsODgsOTksMTAsMTEsMjQsMHhmZSwxLDIsMyw0LDUsNywyMCwxLDIsMHhmZSwweGZlLDQzfTsKdWludDhfdCBidWZfdGVzdF8yWzI1Nl0gOwoKdWludDhfdCBsZW5ndGhfY2hlY2tfZm9yX2VlcHJvbV8yKHVpbnQ4X3QgKmJ1ZmYpOwp2b2lkIGRhdGFfcHJvY2Vzcyh1aW50OF90ICpvbGRfZGF0YSwgdWludDhfdCBvbGRfZGF0YV9zaXplLCB1aW50OF90ICpvbGRfYWwsdWludDhfdCAqbmV3X2RhdGEpOwoKdm9pZCBTaWFfS2V5bWdyX3UzMl90b19uKHVpbnQ4X3QgKm91dCwgdWludDMyX3QgaW4pCnsKICAgIHVuc2lnbmVkIGludCBpOwoKICAgIGZvciAoaSA9IHNpemVvZihpbik7IGkgPiAwdTsgLS1pKQogICAgewogICAgICAgIG91dFtpIC0gMXVdID0gKHVpbnQ4X3QpIGluOwogIC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