added encryption keys for l0dables

This commit is contained in:
schneider 2011-08-05 17:39:00 +02:00
parent 31deb031f5
commit 05fc825df8
4 changed files with 34 additions and 46 deletions

View File

@ -21,7 +21,7 @@ void fancyNickname();
void main_final(void) { void main_final(void) {
init_nick(); init_nick();
if(GLOBAL(privacy)>2){ //firstboot if(GLOBAL(privacy)>2){ //firstboot
if(execute_file("1boot.int",0,0)){ if(execute_file("1boot.int")){
lcdPrintln("Badge SETUP"); lcdPrintln("Badge SETUP");
lcdPrintln("error."); lcdPrintln("error.");
lcdPrintln("Features may"); lcdPrintln("Features may");

View File

@ -21,7 +21,7 @@ void simpleNickname(void);
void fancyNickname(void) { void fancyNickname(void) {
if(GLOBAL(l0nick)){ if(GLOBAL(l0nick)){
if(execute_file(GLOBAL(nickl0),0,0)) if(execute_file(GLOBAL(nickl0)))
GLOBAL(l0nick)=0; GLOBAL(l0nick)=0;
} }

View File

@ -12,15 +12,13 @@
#include "basic/xxtea.h" #include "basic/xxtea.h"
const uint32_t signature_key[4] = {0x123456,0,0,0x234567}; #include "SECRETS"
const uint32_t decode_key[4] = {0x123456,0,0,0x234567};
//const uint32_t decode_key[4] = {0,0,0,0};
extern void * sram_top; //extern void * sram_top;
/**************************************************************************/ /**************************************************************************/
uint8_t execute_file (const char * fname, uint8_t checksignature, uint8_t decode){ uint8_t execute_file (const char * fname){
FRESULT res; FRESULT res;
FIL file; FIL file;
UINT readbytes; UINT readbytes;
@ -48,45 +46,35 @@ uint8_t execute_file (const char * fname, uint8_t checksignature, uint8_t decode
if(res){ if(res){
return -1; return -1;
}; };
if( decode || checksignature ) #ifdef ENCRYPT_L0DABLE
//only accept files with fixed length uint32_t *data;
//if( readbytes != 2048 ) uint32_t len;
if( readbytes & 0x3 ){ if( readbytes & 0x3 ){
lcdPrint("readbytes&3"); lcdPrint("readbytes&3");
lcdRefresh(); lcdRefresh();
while(1); while(1);
return -1; return -1;
}
if( checksignature ){
uint32_t mac[4];
uint32_t *data = (uint32_t*)dst;
uint32_t len = readbytes/4;
xxtea_cbcmac(mac, (uint32_t*)dst, len-4, signature_key);
if( data[len-4] != mac[0] || data[len-3] != mac[1]
|| data[len-2] != mac[2] || data[len-1] != mac[3] ){
lcdClear();
lcdPrint("mac wrong");lcdNl();
lcdPrintIntHex(mac[0]); lcdNl();
lcdPrintIntHex(mac[1]); lcdNl();
lcdPrintIntHex(mac[2]); lcdNl();
lcdPrintIntHex(mac[3]); lcdNl();
lcdRefresh();
while(1);
return -1;
}
//lcdPrint("macok");
//lcdRefresh();
//while(1);
} }
uint32_t mac[4];
if( decode ){ data = (uint32_t*)dst;
uint32_t *data = (uint32_t*)dst; len = readbytes/4;
uint32_t len = readbytes/4; xxtea_cbcmac(mac, (uint32_t*)dst, len-4, l0dable_sign_key);
xxtea_decode_words(data, len-4, decode_key); if( data[len-4] != mac[0] || data[len-3] != mac[1]
|| data[len-2] != mac[2] || data[len-1] != mac[3] ){
lcdClear();
lcdPrint("mac wrong");lcdNl();
lcdPrintIntHex(mac[0]); lcdNl();
lcdPrintIntHex(mac[1]); lcdNl();
lcdPrintIntHex(mac[2]); lcdNl();
lcdPrintIntHex(mac[3]); lcdNl();
lcdRefresh();
while(1);
return -1;
} }
//lcdPrintInt(readbytes); data = (uint32_t*)dst;
//lcdPrintln(" bytes"); len = readbytes/4;
//lcdRefresh(); xxtea_decode_words(data, len-4, l0dable_crypt_key);
#endif
dst=(void (*)(void)) ((uint32_t)(dst) | 1); // Enable Thumb mode! dst=(void (*)(void)) ((uint32_t)(dst) | 1); // Enable Thumb mode!
dst(); dst();
@ -103,6 +91,6 @@ void executeSelect(char *ext){
filename[2]=0; filename[2]=0;
if( selectFile(filename+2,ext) == 0) if( selectFile(filename+2,ext) == 0)
execute_file(filename,0,0); execute_file(filename);
}; };

View File

@ -1,7 +1,7 @@
#ifndef _EXECUTE_H_ #ifndef _EXECUTE_H_
#define _EXECUTE_H_ #define _EXECUTE_H_
uint8_t execute_file (const char * fname, uint8_t checksignature, uint8_t decode); uint8_t execute_file (const char * fname);
void executeSelect(char *ext); void executeSelect(char *ext);
#endif #endif