Ejemplo n.º 1
0
int main(int argc, char **argv) {
	long int tbase = 10;
	long int buflen = 128 * 1024;
	long int ns, samples;
	PICO_STATUS res;

	res = ps5000OpenUnit(&handle);
	assert(res == PICO_OK);

	res = ps5000SetChannel(handle, PS5000_CHANNEL_A, 1, 0, PS5000_20V);
	assert(res == PICO_OK);

	res = ps5000GetTimebase(handle, tbase, buflen, &ns, 0, &samples, 0);
	assert(res == PICO_OK);

	if(argc>1) {
		trigger_setup();
		fputs("trigger set\n", stderr);
	}

	fputs("press Ctrl+D to quit\n", stderr);
	
	while(!feof(stdin)) {

		fputs("run\n", stderr);
		fflush(stderr);
		
		res = ps5000RunBlock(handle, buflen/2, buflen-(buflen/2), tbase, 0, NULL, 0, CallBackBlock, NULL);
		assert(res == PICO_OK);

		fputs("stop\n", stderr);
		fflush(stderr);

		res = ps5000Stop(handle);
		assert(res == PICO_OK);
		
		if(argc>2)
			trigger_setup();	
	}

	ps5000CloseUnit(handle);

	return 0;
}
Ejemplo n.º 2
0
void x_connective_setup(void)
{
    pdint_setup();
    pdfloat_setup();
    pdsymbol_setup();
    bang_setup();
    send_setup();
    receive_setup();
    select_setup();
    route_setup();
    pack_setup();
    unpack_setup();
    trigger_setup();
    spigot_setup();
    moses_setup();
    until_setup();
    makefilename_setup();
    swap_setup();
    change_setup();
    value_setup();
}
Ejemplo n.º 3
0
int main(void) 
{

    uint8_t command;

    serial_init();
    trigger_setup();
    aes_setup();
#ifdef DELAYS
    random_setup();
#endif

    while(1) {
        command = usart_recv_byte();

        switch(command) {
            case 'e':
                fill_buf();
                random_setup();
                encrypt();
                send_buf();
                break;

            case 'd':
                fill_buf();
                random_setup();
                decrypt();
                send_buf();
                break;

            default:
                continue;
        }
    }
    return 0;
}
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;
	}
Ejemplo n.º 5
0
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;
	}
Ejemplo n.º 6
0
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');
	*/
	    
	//Load Super-Secret key
    aes256_context ctx; 
    uint8_t tmp32[32] = SECRET_KEY;
    aes256_init(&ctx, tmp32);

    //Load super-secret IV
    uint8_t iv[16] = IV;
       
    //Do this forever (we don't actually have a jumper to bootloader)
    uint8_t i;
    uint16_t crc;
    uint8_t c;
    while(1){
        c = (uint8_t)getch();
        if (c == 0){
        
            //Initial Value
            crc = 0x0000;
    
            //Read 16 Bytes now            
            for(i = 0; i < 16; i++){
                c = (uint8_t)getch();
                crc = _crc_xmodem_update(crc, c);
                //Save two copies, as one used for IV
                tmp32[i] = c;                
                tmp32[i+16] = c;
            }
            
            //Validate CRC-16
            uint16_t inpcrc = (uint16_t)getch() << 8;
            inpcrc |= (uint8_t)getch();
            
            if (inpcrc == crc){                  
                
                //CRC is OK - continue with decryption
                trigger_high();                
				aes256_decrypt_ecb(&ctx, tmp32); /* encrypting the data block */
				trigger_low();
                             
                //Apply IV (first 16 bytes)
                for (i = 0; i < 16; i++){
                    tmp32[i] ^= iv[i];
                }

                /* Comment this block out to always use initial IV, instead
                   of performing actual CBC mode operation */
                //Save IV for next time from original ciphertext                
                for (i = 0; i < 16; i++){
                    iv[i] = tmp32[i+16];
                }
                

                //Always send OK, done before checking
                //signature to ensure there is no timing
                //attack. This does mean user needs to
                //add some delay before sending next packet
                putch(COMM_OK);
                putch(COMM_OK);

                //Check the signature
                if ((tmp32[0] == SIGNATURE1) &&
                   (tmp32[1] == SIGNATURE2) &&
                   (tmp32[2] == SIGNATURE3) &&
                   (tmp32[3] == SIGNATURE4)){
                   
                   //We now have 12 bytes of useful data to write to flash memory.
                   //We don't actually write anything here though in real life would
                   //probably do more than just delay a moment
                   _delay_ms(1);
                }   
            } else {
                putch(COMM_BADCHECKSUM);
                putch(COMM_BADCHECKSUM);
            }            
        }         
    }
	 
	return 1;
	}
Ejemplo n.º 7
0
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;
	}