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