int main(void) { uint8_t key[16] = {0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c}; uint8_t pt[16] = {0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a}; uint8_t ct[16] = {0x3a,0xd7,0x7b,0xb4,0x0d,0x7a,0x36,0x60,0xa8,0x9e,0xca,0xf3,0x24,0x66,0xef,0x97}; aes_indep_init(); aes_indep_key(key); aes_indep_enc(pt); if(memcmp(pt,ct,16)) { printf("error\n"); } }
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'); */ /* Super-Crappy Protocol works like this: Send kKEY Send pPLAINTEXT *** Encryption Occurs *** receive rRESPONSE e.g.: kE8E9EAEBEDEEEFF0F2F3F4F5F7F8F9FA\n p014BAF2278A69D331D5180103643E99A\n r6743C3D1519AB4F2CD9A78AB09A511BD\n */ char c; int ptr = 0; //Initial key aes_indep_init(); aes_indep_key(tmp); char state = 0; while(1){ c = getch(); if (c == 'x') { ptr = 0; state = IDLE; continue; } if (c == 'k') { ptr = 0; state = KEY; continue; } else if (c == 'p') { ptr = 0; state = PLAIN; continue; } else if (state == KEY) { if ((c == '\n') || (c == '\r')) { asciibuf[ptr] = 0; hex_decode(asciibuf, ptr, tmp); aes_indep_key(tmp); state = IDLE; } else { asciibuf[ptr++] = c; } } else if (state == PLAIN) { if ((c == '\n') || (c == '\r')) { asciibuf[ptr] = 0; hex_decode(asciibuf, ptr, pt); /* Do Encryption */ trigger_high(); aes_indep_enc(pt); /* encrypting the data block */ trigger_low(); /* Print Results */ hex_print(pt, 16, asciibuf); putch('r'); for(int i = 0; i < 32; i++){ putch(asciibuf[i]); } putch('\n'); state = IDLE; } else { if (ptr >= BUFLEN){ state = IDLE; } else { asciibuf[ptr++] = c; } } } } return 1; }
int main ( void ) { platform_init(); init_uart(); trigger_setup(); putch('P'); putch('a'); putch('s'); putch('s'); putch('w'); putch('o'); putch('r'); putch('d'); putch(':'); putch(' '); /* Require password to unlock simple serial protocol. */ trigger_high(); if (read_pass() || test_pass()) { _delay_ms(BAD_PASS_DELAY); trigger_low(); soft_reset(); } trigger_low(); putch('\n'); putch('W'); putch('e'); putch('l'); putch('c'); putch('o'); putch('m'); putch('e'); putch('!'); putch('\n'); /* Super-Crappy Protocol works like this: Send kKEY Send pPLAINTEXT *** Encryption Occurs *** receive rRESPONSE e.g.: kE8E9EAEBEDEEEFF0F2F3F4F5F7F8F9FA\n p014BAF2278A69D331D5180103643E99A\n r6743C3D1519AB4F2CD9A78AB09A511BD\n */ char c; int ptr = 0; //Initial key aes_indep_init(); aes_indep_key(tmp); char state = 0; while(1){ c = getch(); if (c == 'x') { ptr = 0; state = IDLE; continue; } if (c == 'k') { ptr = 0; state = KEY; continue; } else if (c == 'p') { ptr = 0; state = PLAIN; continue; } else if (state == KEY) { if ((c == '\n') || (c == '\r')) { asciibuf[ptr] = 0; hex_decode(asciibuf, ptr, tmp); aes_indep_key(tmp); state = IDLE; } else { asciibuf[ptr++] = c; } } else if (state == PLAIN) { if ((c == '\n') || (c == '\r')) { asciibuf[ptr] = 0; hex_decode(asciibuf, ptr, pt); /* Do Encryption */ trigger_high(); aes_indep_enc(pt); /* encrypting the data block */ trigger_low(); /* Print Results */ hex_print(pt, 16, asciibuf); putch('r'); for(int i = 0; i < 32; i++){ putch(asciibuf[i]); } putch('\n'); state = IDLE; } else { if (ptr >= BUFLEN){ state = IDLE; } else { asciibuf[ptr++] = c; } } } } return 1; }
int main ( void ) { init_uart0(); /* For 2 MHz crystal use this hack */ //BAUD0L_REG = 12; trigger_setup(); //OSCCAL only needed for internal oscillator mode, doesn't hurt anyway #ifdef OSCCAL OSCCAL = OSCCAL_UARTGOOD; _delay_ms(500); #else #ifdef VARYING_CLOCK #error "VARYING_CLOCK requested but target does not have OSCCAL register" #endif #endif /* Uncomment this to get a HELLO message for debug */ /* output_ch_0('h'); output_ch_0('e'); output_ch_0('l'); output_ch_0('l'); output_ch_0('o'); output_ch_0('\n'); */ /* Super-Crappy Protocol works like this: Send kKEY Send pPLAINTEXT *** Encryption Occurs *** receive rRESPONSE e.g.: kE8E9EAEBEDEEEFF0F2F3F4F5F7F8F9FA\n p014BAF2278A69D331D5180103643E99A\n r6743C3D1519AB4F2CD9A78AB09A511BD\n */ char c; int ptr = 0; //Initial key aes_indep_init(); aes_indep_key(tmp); char state = 0; #ifdef VARYING_CLOCK uint8_t newosc; #endif while(1){ c = input_ch_0(); if (c == 'x') { ptr = 0; state = IDLE; continue; } if (c == 'k') { ptr = 0; state = KEY; continue; } else if (c == 'p') { ptr = 0; state = PLAIN; continue; } else if (state == KEY) { if ((c == '\n') || (c == '\r')) { asciibuf[ptr] = 0; hex_decode(asciibuf, ptr, tmp); aes_indep_key(tmp); state = IDLE; } else { asciibuf[ptr++] = c; } } else if (state == PLAIN) { if ((c == '\n') || (c == '\r')) { asciibuf[ptr] = 0; hex_decode(asciibuf, ptr, pt); /* Do Encryption */ //The following is used for varying the clock #ifdef VARYING_CLOCK _delay_ms(25); #ifdef OSCCAL_CENTER newosc = (rand() & OSCCAL_VARY); OSCCAL = OSCCAL_CENTER + (int8_t)((int8_t)(OSCCAL_VARY/2) - (int8_t)newosc); #else OSCCAL = rand() & OSCMAX; #endif _delay_ms(1); #endif trigger_high(); aes_indep_enc(pt); /* encrypting the data block */ trigger_low(); #ifdef VARYING_CLOCK OSCCAL = OSCCAL_UARTGOOD; _delay_ms(100); #endif /* Print Results */ hex_print(pt, 16, asciibuf); output_ch_0('r'); for(int i = 0; i < 32; i++){ output_ch_0(asciibuf[i]); } output_ch_0('\n'); state = IDLE; } else { if (ptr >= BUFLEN){ state = IDLE; } else { asciibuf[ptr++] = c; } } } } return 1; }