Advertisement
Reisyukaku

N3DS 9.5 decrypt

Jul 10th, 2015
2,147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.74 KB | None | 0 0
  1. //Decrypts N3DS 9.5 arm9bin by passing arm9 header address to it.
  2. void decryptArm9Bin(void *armHdr){
  3.     unsigned char keyX[0x10];
  4.     unsigned char keyY[0x10];
  5.     unsigned char CTR[0x10];
  6.     memcpy(keyY, armHdr+0x10, 0x10);
  7.     memcpy(CTR, armHdr+0x20, 0x10);
  8.     size_t size = atoi(armHdr+0x30);
  9.    
  10.     aes_use_keyslot(0x11);
  11.     aes(keyX, armHdr+0x60, 1, NULL, AES_ECB_DECRYPT_MODE, 0);
  12.    
  13.     aes_setkey(0x16, keyX, AES_KEYX, AES_INPUT_BE | AES_INPUT_NORMAL);
  14.     aes_setkey(0x16, keyY, AES_KEYY, AES_INPUT_BE | AES_INPUT_NORMAL);
  15.     aes_setiv(CTR, AES_INPUT_BE | AES_INPUT_NORMAL);
  16.     aes_use_keyslot(0x16);
  17.    
  18.     aes(armHdr+0x800, armHdr+0x800, size/AES_BLOCK_SIZE, CTR, AES_CTR_MODE, AES_INPUT_BE | AES_INPUT_NORMAL);
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement