Advertisement
Proxima

write_eeprom_with_0x30

Sep 17th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.22 KB | None | 0 0
  1. void __fastcall update_eeprom_with_key_0x30(int in_eeprom_wr_offset, unsigned __int8 *in_key_seed, int in_tweak_val, unsigned int in_num_blocks, unsigned __int8 *in_data_buf)
  2. {
  3.   int _14; // ST14_4
  4.   unsigned __int8 *_18; // ST18_4
  5.   int eeprom_block_offset10; // r6
  6.   unsigned int counter0; // r5
  7.   int in_block_calc_offset; // r0
  8.   signed int v10; // r1
  9.   unsigned int in_interations; // r6
  10.   int tweak_val; // r6
  11.   unsigned int counter1; // r5
  12.   int offset; // [sp+4h] [bp-4h]
  13.   int in_tweak; // [sp+1Ch] [bp+14h]
  14.   unsigned int num_blocks; // [sp+20h] [bp+18h]
  15.  
  16.   _14 = in_eeprom_wr_offset;
  17.   _18 = in_key_seed;
  18.   in_tweak = in_tweak_val;
  19.   num_blocks = in_num_blocks;
  20.   eeprom_block_offset10 = in_eeprom_wr_offset;
  21.   counter0 = 0;
  22.   in_block_calc_offset = 0x10 * in_tweak_val;
  23.   if ( eeprom_block_offset10 == 0xFF )
  24.   {
  25.     v10 = 0x2560;
  26.   }
  27.   else if ( eeprom_block_offset10 == 0x81 )
  28.   {
  29.     v10 = 0x2800;
  30.   }
  31.   else
  32.   {
  33.     if ( eeprom_block_offset10 != 0x82 )
  34.     {
  35.       offset = (eeprom_block_offset10 << 0xA) + in_block_calc_offset + 0x560;
  36.       memcpy(&key_seed_data, in_key_seed + 0x150, 0x10);
  37.       if ( !get_key_from_secure_vault(0x30, &skey_0x30, 0x10) )
  38.       {
  39.         aes_ebc_encrypt_init_wrapper((unsigned __int8 *)&skey_0x30, &aes_ctx_30);
  40.         in_interations = eeprom_block_offset10 + 1;
  41.         while ( counter0 < in_interations )
  42.         {
  43.           aes_ecb_encrypt_wrapper((unsigned __int8 *)&key_seed_data, &aes_ctx_30);
  44.           ++counter0;
  45.         }
  46.         aes_ebc_encrypt_init_wrapper((unsigned __int8 *)&key_seed_data, &aes_ctx_30);
  47.         tweak_val = in_tweak;
  48.         counter1 = 0;
  49.         while ( counter1 < num_blocks )
  50.         {
  51.           *(_DWORD *)&in_data_buf[0x10 * counter1] ^= tweak_val;
  52.           aes_ecb_encrypt_wrapper(&in_data_buf[0x10 * counter1++], &aes_ctx_30);
  53.           ++tweak_val;
  54.         }
  55.         write_eprom2(offset, in_data_buf, 0x10 * num_blocks);
  56.       }
  57. LABEL_16:
  58.       memset_func(&skey_0x30, 0, 0x10);
  59.       memset_func(&key_seed_data, 0, 0x10);
  60.       memset_func(&aes_ctx_30, 0, 0xC0);
  61.       JUMPOUT(loc_D5A);
  62.     }
  63.     v10 = 0x7400;
  64.   }
  65.   write_eprom2(in_block_calc_offset + v10, in_data_buf, 0x10 * in_num_blocks);
  66.   goto LABEL_16;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement