Generic 512+513 key decryptor: 5D Mark II 1.0.7 keys inside

  • 5 Replies
Generic 512+513 key decryptor: 5D Mark II 1.0.7 keys inside
« on: 09 / February / 2009, 01:46:59 »
Hi all,

I'm a professional Engineer / web developer and hobbyist photographer.  I recently got a 5D2 and became interested in the intersection of these two passions.  I've read about the 512+513 byte encryption scheme and became fascinated with the math involved in the encryption.  With help from a guy who deciphered the 40D keys (thanks Lex!), I wrote a program which attempts to decipher the 512+513 byte keys automatically on a .fir file.

The generic decryptor, naturally, depends on strings and is targeted to those found in DSLR firmware.

I've only tried it on the 40D and 5D2 firmware - I actually have no idea which other cameras use the encryption scheme - probably most of the dSLRs...  But it works surprisingly well.  Below is a quick program (not the generic decryptor) which uses the keys I discovered to decrypt (and subsequently encrypt) the 5D2 v1.0.7 firmware file, 5d200107.fir.

Obviously the next step is to have at the firmware with a good disassembler, and having never played with one, I'm hoping others can work on this in parallel.  If anyone uses this in their quest to obtain the reward, I'd appreciate a little kickback.   :D

Personally I'm very interested in the possibility of minimally modifying the firmware to be able to execute arbitrary code from the CF card.  This is probably obvious, given the cost of the camera - bricking it is not an option.  I'll be watching these forums for developments.


BTW, being very new here, if someone wants to brief me on CHDK and the most probable developments for DSLRs, that'd be great.   :)

PS - Use this or any firmware modification at your own risk!   :D

Code: (cpp) [Select]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>

unsigned char a[512] = {
 0x69, 0xbf, 0xf8, 0xf0, 0x4c, 0x22, 0xdf, 0x8c, 0xe4, 0x2f, 0xb1, 0x42, 0x81, 0x67, 0x1b, 0xb4,
 0x34, 0xf2, 0xde, 0x0d, 0x92, 0xf4, 0x2f, 0x83, 0x25, 0xda, 0xed, 0x40, 0x85, 0x09, 0xbe, 0xb9,
 0xf9, 0x6d, 0xd4, 0x4a, 0xcf, 0x71, 0x16, 0x1a, 0xf2, 0xe5, 0xf6, 0x5d, 0x35, 0xe8, 0x8f, 0x78,
 0x77, 0x29, 0x9b, 0x6d, 0x4e,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d, 0x59, 0x34, 0xf7, 0xbf, 0x03, 0x9a, 0xae, 0xe4, 0x23, 0x18, 0xc8, 0xc4,
 0xed, 0x57, 0x2b, 0x7b, 0x0a, 0xda, 0x5f, 0x3c, 0x87, 0x2d, 0x8e, 0x36, 0x03, 0xbd, 0xdd, 0x00,
 0xb6, 0xc2, 0xf6, 0xe0, 0x87, 0x34, 0x02, 0xe1, 0x94, 0x3c, 0x3f, 0xb7, 0x59, 0xda, 0x43, 0x21,
 0x74, 0x4f, 0xe0, 0x3d, 0x02, 0x3b, 0xf7, 0x2c, 0x4e, 0x1e, 0xa3, 0x81, 0x4e, 0x44, 0x08, 0x2b,

typedef unsigned short uint16;

int main(int argc, char *argv[])
  FILE *in;
  FILE *out;
  int i = 0, j = 0, val;

  if (argc != 3) {
    printf("Usage: decrypt inputfile outfile\n");
    return -1;

  if ((in = fopen(argv[1], "rb")) == NULL) {
    printf("Cant't open file name %s\n", argv[1]);
    return -1;

  if ((out = fopen(argv[2], "wb")) == NULL) {
    printf("Cant't open file name %s\n", argv[2]);
    return -1;

  while ((val = fgetc(in)) != EOF) {
    fputc(val ^ a[i] ^ b[j], out);
    if (i >= 512) i=0;
    if (j >= 513) j=0;
  return 0;

Re: Generic 512+513 key decryptor: 5D Mark II 1.0.7 keys inside
« Reply #2 on: 09 / February / 2009, 08:36:36 »
Thanks for the link.  I hadn't seen that thread because it barely mentions 5D2, and fore me that was the whole point.   :)  Nice work.

What are you using to disassemble?  Can the free version of IDA be used?  It seems it may not support ARM architectures, though again, I haven't played with it much.

ETA: I see that the actual firmware payload is still encrypted...  Mmm, more games to play.   :)
« Last Edit: 09 / February / 2009, 08:53:50 by jeffco »

Re: Generic 512+513 key decryptor: 5D Mark II 1.0.7 keys inside
« Reply #3 on: 09 / February / 2009, 11:41:48 »
Try IDA pro V 5.2, this has ARM support

Re: Generic 512+513 key decryptor: 5D Mark II 1.0.7 keys inside
« Reply #4 on: 16 / February / 2009, 18:10:18 »
Does anyone have a program to do the reverse for a 50D/5D2?  ie reencrypt the update and fix any checksums?

I'm also very anxious not to brick my 5D2 but I understand this method can be used to run user code without updating the firmware.

Re: Generic 512+513 key decryptor: 5D Mark II 1.0.7 keys inside
« Reply #5 on: 17 / February / 2009, 02:50:55 »
The 512/513 keys to de-crypt the FW are also used to en-crypt the FW :D.


Related Topics