#include "hal.h" #include #include #include "simpleserial.h" #include "speck.h" u8 gkey[32] = {0x00}; uint8_t get_key(uint8_t* k, uint8_t len) { // Load key here simpleserial_put('o', 32, gkey); return 0x00; } uint8_t set_key(uint8_t* key, uint8_t len) { // copy keybytes memcpy(gkey, key, 32); simpleserial_put('o', 32, gkey); return 0x00; } uint8_t get_pt(uint8_t* pt, uint8_t len) { /********************************** * Start user-specific code here. */ trigger_high(); //16 hex bytes held in 'pt' were sent //from the computer. Store your response //back into 'pt', which will send 16 bytes //back to computer. Can ignore of course if //not needed volatile uint8_t ppp[] = {0x42, 0x41, 0x41, 0x41,0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41 }; trigger_low(); /* End user-specific code here. * ********************************/ simpleserial_put('r', 16, ppp); return 0x00; } uint8_t encrypt_block(uint8_t* pt, uint8_t len) { trigger_high(); // TRIGGER START //u8 pt[16] = {0x70, 0x6f, 0x6f, 0x6e, 0x65, 0x72, 0x2e, 0x20, 0x49, 0x6e, 0x20, 0x74, 0x68, 0x6f, 0x73, 0x65}; u8 key[32] = {0x00}; memcpy(key, gkey, 32); // copy the globally set encryption key u8 ct[16] = {0x00}; EncryptBlock(pt, key, ct); trigger_low(); // TRIGGER STOP simpleserial_put('c', 16, ct); return 0x00; } uint8_t reset(uint8_t* x, uint8_t len) { simpleserial_put('r', 0, NULL); // Reset key here if needed return 0x00; } int main(void) { platform_init(); init_uart(); trigger_setup(); /* Uncomment this to get a HELLO message for debug */ putch('h'); putch('e'); putch('l'); putch('l'); putch('o'); putch('\n'); simpleserial_init(); simpleserial_addcmd('p', 16, get_pt); simpleserial_addcmd('l', 0, get_pt); simpleserial_addcmd('e', 16, encrypt_block); simpleserial_addcmd('k', 16, get_key); simpleserial_addcmd('s', 32, set_key); simpleserial_addcmd('x', 0, reset); while(1) simpleserial_get(); }