Example #1
0
void nessie_print_item(char* name, uint8_t* buffer, uint16_t size_B){
	uint8_t name_len;
	uint8_t i;
	name_len=strlen(name);
	if(name_len>SPACES-1){
		NESSIE_PUTSTR_P(PSTR("\r\n!!! formatting error !!!\r\n"));
		return;
	}
	NESSIE_PUTSTR_P(PSTR("\r\n"));
	for(i=0; i<SPACES-name_len-1; ++i){
		NESSIE_PUTC(' ');
	}
	NESSIE_PUTSTR(name);
	NESSIE_PUTC('=');
	/* now the data printing begins */
	if(size_B<=BYTESPERLINE){
		/* one line seems sufficient */
		nessie_print_block(buffer, size_B*8);
	} else {
		/* we need more lines */
		nessie_print_block(buffer, BYTESPERLINE*8); /* first line */
		int16_t toprint = size_B - BYTESPERLINE;
		buffer += BYTESPERLINE;
		while(toprint > 0){
			NESSIE_PUTSTR_P(PSTR("\r\n"));
			for(i=0; i<SPACES; ++i){
				NESSIE_PUTC(' ');
			}
			nessie_print_block(buffer, ((toprint>BYTESPERLINE)?BYTESPERLINE:toprint)*8);
			buffer  += BYTESPERLINE;
			toprint -= BYTESPERLINE;
		}
	}
} 
Example #2
0
static
void tv4_mac(uint8_t* key){
	uint8_t ctx[nessie_mac_ctx.ctx_size_B];
	uint8_t mac[MACSIZE_B];
	uint8_t block[256/8];
	uint16_t n=256;
	uint32_t i;
	
	NESSIE_PUTSTR_P(PSTR("\r\n                       message="));
	NESSIE_PUTSTR(PSTR("256 zero bits"));
	memset(block, 0, 256/8);
	
	nessie_mac_ctx.mac_init(key, nessie_mac_ctx.keysize_b, ctx);;
	while(n>nessie_mac_ctx.blocksize_B*8){
		nessie_mac_ctx.mac_next(block, ctx);
		n    -= nessie_mac_ctx.blocksize_B*8;
	}
	nessie_mac_ctx.mac_last(block, n, key, nessie_mac_ctx.keysize_b, ctx);
	nessie_mac_ctx.mac_conv(mac, ctx);
	PRINTMAC;
	for(i=1; i<100000L; ++i){ /* this assumes BLOCKSIZE >= HASHSIZE */
		nessie_mac_ctx.mac_init(key, nessie_mac_ctx.keysize_b, ctx);;
		nessie_mac_ctx.mac_last(mac, nessie_mac_ctx.macsize_b, key, nessie_mac_ctx.keysize_b, ctx);
		nessie_mac_ctx.mac_conv(mac, ctx);
		NESSIE_SEND_ALIVE_A(i);
	}
	nessie_print_item("iterated 100000 times", mac, MACSIZE_B);
}
Example #3
0
void nessie_print_header(char* name,
                         uint16_t keysize_b, 
                         uint16_t blocksize_b,
                         uint16_t hashsize_b, 
                         uint16_t macsize_b,
                         uint16_t ivsize_b ){
	uint16_t i;
	NESSIE_PUTSTR_P(PSTR("\r\n\r\n"
	"********************************************************************************\r\n"
	"* AVR-Crypto-Lib - crypto primitives for AVR microcontrolles by Daniel Otte    *\r\n"
	"********************************************************************************\r\n"
	"\r\n"));
	NESSIE_PUTSTR_P(PSTR("Primitive Name: "));
	NESSIE_PUTSTR(name);
	NESSIE_PUTSTR_P(PSTR("\r\n"));
	/* underline */	
	for(i=0; i<16+strlen(name); ++i){
		NESSIE_PUTC('=');
	}
	char str[6]; /* must catch numbers up to 65535 + terminatin \0 */
	if(keysize_b){
		NESSIE_PUTSTR_P(PSTR("\r\nKey size: "));
		utoa(keysize_b, str, 10);
		NESSIE_PUTSTR(str);
		NESSIE_PUTSTR_P(PSTR(" bits"));
	}
	if(blocksize_b){
		NESSIE_PUTSTR_P(PSTR("\r\nBlock size: "));
		utoa(blocksize_b, str, 10);
		NESSIE_PUTSTR(str);
		NESSIE_PUTSTR_P(PSTR(" bits"));
	}
	if(hashsize_b){
		NESSIE_PUTSTR_P(PSTR("\r\nHash size: "));
		utoa(hashsize_b, str, 10);
		NESSIE_PUTSTR(str);
		NESSIE_PUTSTR_P(PSTR(" bits"));
	}
	if(macsize_b){
		NESSIE_PUTSTR_P(PSTR("\r\nMac size: "));
		utoa(macsize_b, str, 10);
		NESSIE_PUTSTR(str);
		NESSIE_PUTSTR_P(PSTR(" bits"));
	}
	if(ivsize_b){
		if(ivsize_b==(uint16_t)-1){
			NESSIE_PUTSTR_P(PSTR("\r\nNo initial value (IV) mode"));
		}else{
			NESSIE_PUTSTR_P(PSTR("\r\nIV size: "));
			utoa(ivsize_b, str, 10);
			NESSIE_PUTSTR(str);
			NESSIE_PUTSTR_P(PSTR(" bits"));
		}
	}
	NESSIE_PUTSTR_P(PSTR("\r\n"));
}
Example #4
0
static
void one_in512_mac(uint16_t pos, uint8_t* key){
	uint8_t ctx[nessie_mac_ctx.ctx_size_B];
	uint8_t mac[MACSIZE_B];
	uint8_t block[nessie_mac_ctx.blocksize_B];
	uint16_t n=512;
	char* tab[8]={"80", "40", "20", "10", 
	              "08", "04", "02", "01" };

	pos&=511;
	NESSIE_PUTSTR_P(PSTR("\r\n                       message="));
	NESSIE_PUTSTR_P(PSTR("512-bit string: "));
	if((pos/8) >=10){
		NESSIE_PUTC('0'+(pos/8/10)%10);
	} else {
		NESSIE_PUTC(' ');
	}
	NESSIE_PUTC('0'+(pos/8)%10);
	NESSIE_PUTSTR_P(PSTR("*00,"));
	NESSIE_PUTSTR(tab[pos&7]);
	NESSIE_PUTC(',');
	if(63-(pos/8) >=10){
		NESSIE_PUTC('0'+((63-pos/8)/10)%10);
	} else {
		NESSIE_PUTC(' ');
	}
	NESSIE_PUTC('0'+(63-pos/8)%10);
	NESSIE_PUTSTR_P(PSTR("*00"));
	PRINTKEY;
	
	/* now the real stuff */
	memset(block, 0, 512/8);
	block[pos>>3] = 0x80>>(pos&0x7);
	uint8_t* bp;
	bp = block;
	nessie_mac_ctx.mac_init(key, nessie_mac_ctx.keysize_b, ctx);
	while(n>nessie_mac_ctx.blocksize_B*8){
		nessie_mac_ctx.mac_next(bp, ctx);
		n   -= nessie_mac_ctx.blocksize_B*8;
		bp  += nessie_mac_ctx.blocksize_B;
	}
	nessie_mac_ctx.mac_last(bp, n, key, nessie_mac_ctx.keysize_b, ctx);
	nessie_mac_ctx.mac_conv(mac, ctx);
	PRINTMAC;
}
Example #5
0
static
void ascii_mac(char* data, char* desc, uint8_t* key){
	uint8_t ctx[nessie_mac_ctx.ctx_size_B];
	uint8_t mac[MACSIZE_B];
	uint16_t sl;
	
	NESSIE_PUTSTR_P(PSTR("\r\n                       message="));
	NESSIE_PUTSTR(desc);
	PRINTKEY;
	nessie_mac_ctx.mac_init(key, nessie_mac_ctx.keysize_b, ctx);
	sl = strlen(data);
	while(sl>nessie_mac_ctx.blocksize_B){
		nessie_mac_ctx.mac_next(data, ctx);
		data += nessie_mac_ctx.blocksize_B;
		sl   -= nessie_mac_ctx.blocksize_B;
	}
	nessie_mac_ctx.mac_last(data, sl*8, key, nessie_mac_ctx.keysize_b, ctx);
	nessie_mac_ctx.mac_conv(mac, ctx);
	PRINTMAC;
}
static
void one_in512_hash(uint16_t pos){
	uint8_t ctx[nessie_hash_ctx.ctx_size_B];
	uint8_t hash[(nessie_hash_ctx.hashsize_b+7)/8];
	uint8_t block[nessie_hash_ctx.blocksize_B];
	uint16_t n=512;
	char* tab[8]={"80", "40", "20", "10", 
	              "08", "04", "02", "01" };

	pos&=511;
	NESSIE_PUTSTR_P(PSTR("\r\n                       message="));
	NESSIE_PUTSTR_P(PSTR("512-bit string: "));
	if((pos/8) >=10){
		NESSIE_PUTC('0'+(pos/8/10)%10);
	} else {
		NESSIE_PUTC(' ');
	}
	NESSIE_PUTC('0'+(pos/8)%10);
	NESSIE_PUTSTR_P(PSTR("*00,"));
	NESSIE_PUTSTR(tab[pos&7]);
	NESSIE_PUTC(',');
	if(63-(pos/8) >=10){
		NESSIE_PUTC('0'+((63-pos/8)/10)%10);
	} else {
		NESSIE_PUTC(' ');
	}
	NESSIE_PUTC('0'+(63-pos/8)%10);
	NESSIE_PUTSTR_P(PSTR("*00"));
	
	/* now the real stuff */
	memset(block, 0, 512/8);
	block[pos>>3] = 0x80>>(pos&0x7);
	nessie_hash_ctx.hash_init(ctx);
	while(n>=nessie_hash_ctx.blocksize_B*8){
		nessie_hash_ctx.hash_next(ctx, block);
		n   -= nessie_hash_ctx.blocksize_B*8;
	}
	nessie_hash_ctx.hash_last(ctx, block, n);
	nessie_hash_ctx.hash_conv(hash, ctx);
	nessie_print_item("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8);
}