fork(1) download
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #include <stdbool.h>
  4.  
  5. #define SIA_KEYMGR_CHAR_BIT 8u
  6. #define SIA_KEYMGR_AES_BLOCK_BYTE_LEN 16u
  7. uint8_t buf_0[] = {11,12,13,14,15,17,18,19,0xfe};
  8. 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};
  9. uint8_t buf_test_2[256] ;
  10.  
  11. uint8_t length_check_for_eeprom_2(uint8_t *buff);
  12. void data_process(uint8_t *old_data, uint8_t old_data_size, uint8_t *old_al,uint8_t *new_data);
  13.  
  14. void Sia_Keymgr_u32_to_n(uint8_t *out, uint32_t in)
  15. {
  16. unsigned int i;
  17.  
  18. for (i = sizeof(in); i > 0u; --i)
  19. {
  20. out[i - 1u] = (uint8_t) in;
  21. in >>= SIA_KEYMGR_CHAR_BIT;
  22. }
  23. }
  24.  
  25. int main(void) {
  26.  
  27. printf("Begin \r\n");
  28. uint8_t m4lh_plain[SIA_KEYMGR_AES_BLOCK_BYTE_LEN];
  29. Sia_Keymgr_u32_to_n(m4lh_plain, (1u << 4) | 8u); /* set 32bit on the 128bit */
  30. for(int i = 0; i<SIA_KEYMGR_AES_BLOCK_BYTE_LEN; i++)
  31. {
  32. printf("current val = 0x%x, \r\n",m4lh_plain[i]);
  33. }
  34. return 0;
  35. }
  36.  
  37.  
  38. uint8_t length_check_for_eeprom_2(uint8_t *buff)
  39. {
  40. uint8_t length=0;
  41. bool valid_data = false;
  42. uint8_t out;
  43.  
  44. for(int i = 0; i<256; i++)
  45. {
  46. if((*(buff + i)!=0xfe)||(*(buff + i + 1)!=0xfe))
  47. {
  48. //printf("current val = %d, next val = %d, length = %d \r\n",*(buff + i),*(buff + i + 1),length);
  49. length=length+1;
  50. }
  51. // else if((*(buff + i)==0xfe)&&(*(buff + i + 1)==0xfe))
  52. // {
  53. // length++;
  54. // valid_data = true;
  55. // break;
  56. // }
  57. else
  58. { length=length+1;
  59. valid_data = true;
  60. break;
  61. }
  62. }
  63. return (valid_data==true)? length+1 : 0;
  64. }
  65.  
  66. //must decalre array new_data[] with correct size before call this function
  67. void data_process(uint8_t *old_data, uint8_t old_data_size, uint8_t *old_al,uint8_t *new_data)
  68. {
  69. if(old_data_size == 0)
  70. {
  71. memcpy(new_data,old_al,9);
  72. *(new_data+9) = 0xfe;
  73. }
  74. else
  75. {
  76. memcpy(new_data,old_data,old_data_size);
  77. memcpy(new_data+old_data_size-1,old_al,9);
  78. *(new_data+old_data_size+8) = 0xfe;
  79. }
  80. }
  81.  
Success #stdin #stdout 0s 5268KB
stdin
Standard input is empty
stdout
Begin 
current val = 0x0,  
current val = 0x0,  
current val = 0x0,  
current val = 0x18,  
current val = 0xe0,  
current val = 0x14,  
current val = 0x0,  
current val = 0x0,  
current val = 0x0,  
current val = 0x0,  
current val = 0x0,  
current val = 0x0,  
current val = 0x0,  
current val = 0x0,  
current val = 0x0,  
current val = 0x0,