executor: made encryption work
This commit is contained in:
parent
5c6f9e2f76
commit
b07eb7c577
|
@ -57,7 +57,7 @@ void xxtea_cbcmac(uint32_t mac[4], uint32_t *data,
|
||||||
|
|
||||||
void xxtea_encode_words(uint32_t *v, int n, uint32_t const k[4])
|
void xxtea_encode_words(uint32_t *v, int n, uint32_t const k[4])
|
||||||
{
|
{
|
||||||
if(k[0] == 0 && k[1] == 0 && k[2] == 0 && k[3] == 0) return;
|
//if(k[0] == 0 && k[1] == 0 && k[2] == 0 && k[3] == 0) return;
|
||||||
uint32_t y, z, sum;
|
uint32_t y, z, sum;
|
||||||
unsigned p, rounds, e;
|
unsigned p, rounds, e;
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ void xxtea_encode_words(uint32_t *v, int n, uint32_t const k[4])
|
||||||
|
|
||||||
void xxtea_decode_words(uint32_t *v, int n, uint32_t const k[4])
|
void xxtea_decode_words(uint32_t *v, int n, uint32_t const k[4])
|
||||||
{
|
{
|
||||||
if(k[0] == 0 && k[1] == 0 && k[2] == 0 && k[3] == 0) return;
|
//if(k[0] == 0 && k[1] == 0 && k[2] == 0 && k[3] == 0) return;
|
||||||
uint32_t y, z, sum;
|
uint32_t y, z, sum;
|
||||||
unsigned p, rounds, e;
|
unsigned p, rounds, e;
|
||||||
htonlp(v ,n);
|
htonlp(v ,n);
|
||||||
|
|
|
@ -12,8 +12,9 @@
|
||||||
|
|
||||||
#include "basic/xxtea.h"
|
#include "basic/xxtea.h"
|
||||||
|
|
||||||
const uint32_t signature_key[4] = {0,0,0,0};
|
const uint32_t signature_key[4] = {0x123456,0,0,0x234567};
|
||||||
const uint32_t decode_key[4] = {0,0,0,0};
|
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;
|
||||||
|
|
||||||
|
@ -39,7 +40,7 @@ void execute_file (const char * fname, uint8_t checksignature, uint8_t decode){
|
||||||
if(res){
|
if(res){
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
res = f_read(&file, (char *)dst, RAMCODE, &readbytes);
|
res = f_read(&file, (char *)dst, RAMCODE, &readbytes);
|
||||||
//lcdPrint("read: ");
|
//lcdPrint("read: ");
|
||||||
//lcdPrintln(f_get_rc_string(res));
|
//lcdPrintln(f_get_rc_string(res));
|
||||||
|
@ -47,11 +48,15 @@ void execute_file (const char * fname, uint8_t checksignature, uint8_t decode){
|
||||||
if(res){
|
if(res){
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
if( decode || checksignature )
|
if( decode || checksignature )
|
||||||
if( readbytes & 0x03 )
|
//only accept files with fixed length
|
||||||
|
//if( readbytes != 2048 )
|
||||||
|
if( readbytes & 0x3 ){
|
||||||
|
lcdPrint("readbytes&3");
|
||||||
|
lcdRefresh();
|
||||||
|
while(1);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
if( checksignature ){
|
if( checksignature ){
|
||||||
uint32_t mac[4];
|
uint32_t mac[4];
|
||||||
uint32_t *data = (uint32_t*)dst;
|
uint32_t *data = (uint32_t*)dst;
|
||||||
|
@ -59,14 +64,25 @@ void execute_file (const char * fname, uint8_t checksignature, uint8_t decode){
|
||||||
xxtea_cbcmac(mac, (uint32_t*)dst, len-4, signature_key);
|
xxtea_cbcmac(mac, (uint32_t*)dst, len-4, signature_key);
|
||||||
if( data[len-4] != mac[0] || data[len-3] != mac[1]
|
if( data[len-4] != mac[0] || data[len-3] != mac[1]
|
||||||
|| data[len-2] != mac[2] || data[len-1] != mac[3] ){
|
|| 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;
|
return;
|
||||||
}
|
}
|
||||||
|
//lcdPrint("macok");
|
||||||
|
//lcdRefresh();
|
||||||
|
//while(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if( decode ){
|
if( decode ){
|
||||||
uint32_t *data = (uint32_t*)dst;
|
uint32_t *data = (uint32_t*)dst;
|
||||||
uint32_t len = readbytes/4;
|
uint32_t len = readbytes/4;
|
||||||
xxtea_decode_words(data, len, decode_key);
|
xxtea_decode_words(data, len-4, decode_key);
|
||||||
}
|
}
|
||||||
//lcdPrintInt(readbytes);
|
//lcdPrintInt(readbytes);
|
||||||
//lcdPrintln(" bytes");
|
//lcdPrintln(" bytes");
|
||||||
|
|
Loading…
Reference in New Issue