コード例 #1
0
static
void tv4_hash(void){
	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.hashsize_b/8];
	uint16_t n=nessie_hash_ctx.hashsize_b;
	uint32_t i;
	
	fputs_P(PSTR("\r\n                       message="), stdout);
	fprintf_P(stdout, PSTR("%"PRIu16" zero bits"), nessie_hash_ctx.hashsize_b);

	memset(block, 0, nessie_hash_ctx.hashsize_b/8);
	
	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);
	if(nessie_hash_quick)
		return;
	for(i=1; i<100000L; ++i){ /* this assumes BLOCKSIZE >= HASHSIZE */
		nessie_hash_ctx.hash_init(ctx);
		nessie_hash_ctx.hash_last(ctx, hash, nessie_hash_ctx.hashsize_b);
		nessie_hash_ctx.hash_conv(hash, ctx);
		NESSIE_SEND_ALIVE_A(i);
	}
	nessie_print_item("iterated 100000 times", hash, (nessie_hash_ctx.hashsize_b+7)/8);
}
コード例 #2
0
void nessie_bc_dec(uint8_t *key, uint8_t *ct){
	uint8_t ctx[nessie_bc_ctx.ctx_size_B];
	uint8_t buffer[nessie_bc_ctx.blocksize_B];
	
	/* single test */
	nessie_print_item("key", key, (nessie_bc_ctx.keysize_b+7)/8);
	nessie_bc_ctx.cipher_genctx(key, nessie_bc_ctx.keysize_b, ctx);
	memcpy(buffer, ct, nessie_bc_ctx.blocksize_B);
	nessie_print_item("cipher", buffer, nessie_bc_ctx.blocksize_B);
	nessie_bc_ctx.cipher_dec(buffer, ctx);
	nessie_print_item("plain", buffer, nessie_bc_ctx.blocksize_B);
	nessie_bc_ctx.cipher_enc(buffer, ctx);
	nessie_print_item("encrypted", buffer, nessie_bc_ctx.blocksize_B);
	nessie_bc_free(ctx);
}
コード例 #3
0
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;
	fputs_P(PSTR("\n                       message="), stdout);
	fputs_P(PSTR("512-bit string: "), stdout);

	fprintf_P(stdout, PSTR("%2"PRIu16"*00,%s,%2"PRIu16"*00"), pos / 8, tab[pos & 7], 63 - pos / 8);
	
	/* 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);
}
static
void zero_hash(uint16_t n){
	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];
	
	NESSIE_PUTSTR_P(PSTR("\r\n                       message="));
	if(n>=10000)
		NESSIE_PUTC('0'+n/10000);
	if(n>=1000)
		NESSIE_PUTC('0'+(n/1000)%10);
	if(n>=100)
		NESSIE_PUTC('0'+(n/100)%10);
	if(n>=10)
		NESSIE_PUTC('0'+(n/10)%10);
	NESSIE_PUTC('0'+n%10);
	NESSIE_PUTSTR_P(PSTR(" zero bits"));
	
	memset(block, 0, nessie_hash_ctx.blocksize_B); 
	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);
}
コード例 #5
0
ファイル: nessie_mac_test.c プロジェクト: azilly-de/openkubus
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);
}
コード例 #6
0
ファイル: scal-nessie.c プロジェクト: nerilex/arm-crypto-lib
static
void normal_block(scgen_ctx_t *ctx){
	uint8_t xor_block[64];
	uint8_t block[64];
	const uint8_t* hook_ptr = normal_hooks;
	const char* *hook_str_ptr = stream_n_str;
	uint8_t i;

	memset(xor_block, 0, 64);
	for(i=0; i<=448/64; ++i){
		scal_cipher_gen_fillblock(block, 64, ctx);
		memxor(xor_block, block, 64);
		if(i==*hook_ptr){
			++hook_ptr;
			nessie_print_item(*(hook_str_ptr++), block, 64);
		}
	}
	nessie_print_item(*(hook_str_ptr), xor_block, 64);
}
コード例 #7
0
void nessie_bc_enc(uint8_t *key, uint8_t *pt){
	uint8_t ctx[nessie_bc_ctx.ctx_size_B];
	uint8_t buffer[nessie_bc_ctx.blocksize_B];
	uint16_t i;
	
	/* single test */
	nessie_print_item("key", key, (nessie_bc_ctx.keysize_b+7)/8);
	nessie_bc_ctx.cipher_genctx(key, nessie_bc_ctx.keysize_b, ctx);
	
	memcpy(buffer, pt, nessie_bc_ctx.blocksize_B);
	nessie_print_item("plain", buffer, nessie_bc_ctx.blocksize_B);
	nessie_bc_ctx.cipher_enc(buffer, ctx);
	nessie_print_item("cipher", buffer, nessie_bc_ctx.blocksize_B);
	if(nessie_bc_ctx.cipher_dec){
		nessie_bc_ctx.cipher_dec(buffer, ctx);
		nessie_print_item("decrypted", buffer, nessie_bc_ctx.blocksize_B);
	}
	/* 100 times test */
	memcpy(buffer, pt, nessie_bc_ctx.blocksize_B);
	for(i=0; i<100; ++i){
		nessie_bc_ctx.cipher_enc(buffer, ctx);
		NESSIE_SEND_ALIVE_A(i);
	}
	nessie_print_item("Iterated 100 times", buffer, nessie_bc_ctx.blocksize_B);
#ifndef NESSIE_NO1KTEST	
	/* 1000 times test, we use the 100 precedig steps to fasten things a bit */
	for(; i<1000; ++i){
		nessie_bc_ctx.cipher_enc(buffer, ctx);
		NESSIE_SEND_ALIVE_A(i);
	}
	nessie_print_item("Iterated 1000 times", buffer, nessie_bc_ctx.blocksize_B);
#endif
	nessie_bc_free(ctx);
}
コード例 #8
0
ファイル: scal-nessie.c プロジェクト: nerilex/arm-crypto-lib
static
void long_block(scgen_ctx_t *ctx){
	uint8_t xor_block[64];
	uint8_t block[64];
	const uint16_t* hook_ptr = long_hooks;
	const char* *hook_str_ptr = stream_l_str;
	uint16_t i;

	memset(xor_block, 0, 64);
	for(i=0; i<=131008/64; ++i){
		scal_cipher_gen_fillblock(block, 64, ctx);
		memxor(xor_block, block, 64);
		if(i==*hook_ptr){
			++hook_ptr;
			nessie_print_item(*(hook_str_ptr++), block, 64);
		}
		if(i%64==0){
			NESSIE_SEND_ALIVE;
		}
	}
	nessie_print_item(*(hook_str_ptr), xor_block, 64);
}
コード例 #9
0
static
void zero_hash(uint16_t n){
	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];
	
	fputs_P(PSTR("\n                       message="), stdout);
	fprintf_P(stdout, PSTR("%"PRIu16" zero bits"));
	
	memset(block, 0, nessie_hash_ctx.blocksize_B); 
	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);
}
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);
}
コード例 #11
0
static
void amillion_hash(void){
	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];
	uint32_t n=1000000LL;
	uint16_t i=0;
	
	fputs_P(PSTR("\n                       message="), stdout);
	fputs_P(PSTR("1 million times \"a\""), stdout);
	memset(block, 'a', nessie_hash_ctx.blocksize_B);
	nessie_hash_ctx.hash_init(ctx);
	while(n>=nessie_hash_ctx.blocksize_B){
		nessie_hash_ctx.hash_next(ctx, block);
		n    -= nessie_hash_ctx.blocksize_B;
		NESSIE_SEND_ALIVE_A(i++);
	}
	nessie_hash_ctx.hash_last(ctx, block, n*8);
	nessie_hash_ctx.hash_conv(hash, ctx);
	nessie_print_item("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8);
}
コード例 #12
0
static
void ascii_hash_P(PGM_P data, PGM_P desc){
	uint8_t ctx[nessie_hash_ctx.ctx_size_B];
	uint8_t hash[HASHSIZE_B];
	uint16_t sl;
	uint8_t buffer[BLOCKSIZE_B];
	
	fputs_P(PSTR("\n                       message="), stdout);
	fputs_P(desc, stdout);
	nessie_hash_ctx.hash_init(ctx);
	sl = strlen_P(data);
	while(sl>=BLOCKSIZE_B){
		memcpy_P(buffer, data, BLOCKSIZE_B);
		nessie_hash_ctx.hash_next(ctx, buffer);
		data += BLOCKSIZE_B;
		sl   -= BLOCKSIZE_B;
	}
	memcpy_P(buffer, data, sl);
	nessie_hash_ctx.hash_last(ctx, buffer, sl*8);
	nessie_hash_ctx.hash_conv(hash, ctx);
	nessie_print_item("hash", hash, (nessie_hash_ctx.hashsize_b+7)/8);
}
コード例 #13
0
static
void nessie_stream_enc_large(uint8_t *key){
	uint8_t ctx[nessie_stream_ctx.ctx_size_B];
	uint8_t buffer[BLOCKSIZE_B];
	uint8_t xorbuffer[BLOCKSIZE_B];
	uint32_t i;
	
	memset(xorbuffer, 0, BLOCKSIZE_B);
	
	nessie_print_item("key", key, (nessie_stream_ctx.keysize_b+7)/8);
	
	nessie_stream_ctx.cipher_genctx(key, nessie_stream_ctx.keysize_b, ctx);
	
	nessie_gen_block(ctx, buffer);
	memxor(xorbuffer, buffer, BLOCKSIZE_B);
	nessie_print_item("stream[0..63]", buffer, BLOCKSIZE_B);
	
	for(i=0; i<((65472-0)/BLOCKSIZE_B-1); ++i){
		nessie_gen_block(ctx, buffer);
		memxor(xorbuffer, buffer, BLOCKSIZE_B);
		NESSIE_SEND_ALIVE_A(i);
	}
	
	nessie_gen_block(ctx, buffer);
	memxor(xorbuffer, buffer, BLOCKSIZE_B);
	nessie_print_item("stream[65472..65535]", buffer, BLOCKSIZE_B);
	
	nessie_gen_block(ctx, buffer);
	memxor(xorbuffer, buffer, BLOCKSIZE_B);
	nessie_print_item("stream[65536..65599]", buffer, BLOCKSIZE_B);
	
	for(i=0; i<((131008-65536)/BLOCKSIZE_B-1); ++i){
		nessie_gen_block(ctx, buffer);
		memxor(xorbuffer, buffer, BLOCKSIZE_B);
		NESSIE_SEND_ALIVE_A(i);
	}
	
	nessie_gen_block(ctx, buffer);
	memxor(xorbuffer, buffer, BLOCKSIZE_B);
	nessie_print_item("stream[131008..131071]", buffer, BLOCKSIZE_B);
	
	nessie_print_item("stream[0..131071]xored", xorbuffer, BLOCKSIZE_B);
	
}
コード例 #14
0
static
void nessie_stream_enc(uint8_t *key){
	uint8_t ctx[nessie_stream_ctx.ctx_size_B];
	uint8_t buffer[BLOCKSIZE_B];
	uint8_t xorbuffer[BLOCKSIZE_B];
	uint8_t i;
	
	memset(xorbuffer, 0, BLOCKSIZE_B);
	
	nessie_print_item("key", key, (nessie_stream_ctx.keysize_b+7)/8);
	
	nessie_stream_ctx.cipher_genctx(key, nessie_stream_ctx.keysize_b, ctx);
	
	nessie_gen_block(ctx, buffer);
	memxor(xorbuffer, buffer, BLOCKSIZE_B);
	nessie_print_item("stream[0..63]", buffer, BLOCKSIZE_B);
	
	for(i=0; i<((192-0)/BLOCKSIZE_B-1); ++i){
		nessie_gen_block(ctx, buffer);
		memxor(xorbuffer, buffer, BLOCKSIZE_B);
	}
	
	nessie_gen_block(ctx, buffer);
	memxor(xorbuffer, buffer, BLOCKSIZE_B);
	nessie_print_item("stream[192..255]", buffer, BLOCKSIZE_B);
	
	nessie_gen_block(ctx, buffer);
	memxor(xorbuffer, buffer, BLOCKSIZE_B);
	nessie_print_item("stream[256..319]", buffer, BLOCKSIZE_B);
	
	for(i=0; i<((448-256)/BLOCKSIZE_B-1); ++i){
		nessie_gen_block(ctx, buffer);
		memxor(xorbuffer, buffer, BLOCKSIZE_B);
	}
	
	nessie_gen_block(ctx, buffer);
	memxor(xorbuffer, buffer, BLOCKSIZE_B);
	nessie_print_item("stream[448..511]", buffer, BLOCKSIZE_B);
	
	nessie_print_item("stream[0..511]xored", xorbuffer, BLOCKSIZE_B);
	
}
コード例 #15
0
ファイル: scal-nessie.c プロジェクト: nerilex/arm-crypto-lib
void scal_nessie_stream_run(const scdesc_t *desc, uint16_t keysize_b, uint16_t ivsize_b){
	uint8_t key[(keysize_b+7)/8];
	uint8_t iv[(ivsize_b+7)/8];
	uint16_t v;
	scgen_ctx_t ctx;
	nessie_print_header(desc->name, keysize_b, 0, 0, 0, ivsize_b?ivsize_b:((uint16_t)-1));
	if(estream_flag){
		stream_n_str[4] = streamX_n_estream;
		stream_l_str[4] = streamX_l_estream;
	}else{
		stream_n_str[4] = streamX_n_nessie;
		stream_l_str[4] = streamX_l_nessie;
	}
	memset(iv, 0, (ivsize_b+7)/8);
	memset(key, 0, (keysize_b+7)/8);
	/***  Test SET 1 ***/
	nessie_print_setheader(1);
	for(v=0;v<keysize_b; v+=estream_flag?9:1){
		nessie_print_set_vector(1,v);
		key[v/8] |= 0x80>>(v&7);
		nessie_print_item("key", key, (keysize_b+7)/8);
		if(ivsize_b){
			nessie_print_item("IV", iv, (ivsize_b+7)/8);
		}
		scal_cipher_init(desc, key, keysize_b, iv, ivsize_b, &ctx);
		normal_block(&ctx);
		key[v/8] = 0;
		scal_cipher_free(&ctx);
	}
	/***  Test SET 2 ***/
	nessie_print_setheader(2);
	for(v=0;v<256; v+=estream_flag?9:1){
		nessie_print_set_vector(2,v);
		memset(key, v&0xff, (keysize_b+7)/8);
		nessie_print_item("key", key, (keysize_b+7)/8);
		if(ivsize_b){
			nessie_print_item("IV", iv, (ivsize_b+7)/8);
		}
		scal_cipher_init(desc, key, keysize_b, iv, ivsize_b, &ctx);
		normal_block(&ctx);
		scal_cipher_free(&ctx);
	}
	/***  Test SET 3 ***/
	nessie_print_setheader(3);
	for(v=0;v<256; v+=estream_flag?9:1){
		uint8_t i;
		nessie_print_set_vector(3,v);
		for(i=0; i<((keysize_b+7)/8); ++i){
			key[i]=(i+v)&0xff;
		}
		nessie_print_item("key", key, (keysize_b+7)/8);
		if(ivsize_b){
			nessie_print_item("IV", iv, (ivsize_b+7)/8);
		}
		scal_cipher_init(desc, key, keysize_b, iv, ivsize_b, &ctx);
		normal_block(&ctx);
		scal_cipher_free(&ctx);
	}
	/***  Test SET 4 ***/
	nessie_print_setheader(4);
	for(v=0;v<4; ++v){
		uint8_t i;
		nessie_print_set_vector(4,v);
		for(i=0; i<((keysize_b+7)/8); ++i){
			key[i]=(i*0x53+v*5)&0xff;
		}
		nessie_print_item("key", key, (keysize_b+7)/8);
		if(ivsize_b){
			nessie_print_item("IV", iv, (ivsize_b+7)/8);
		}
		scal_cipher_init(desc, key, keysize_b, iv, ivsize_b, &ctx);
		long_block(&ctx);
		scal_cipher_free(&ctx);
	}
	if(ivsize_b==0){ /* exit if there is no IV */
		nessie_print_footer();
		return;
	}
	/***  Test SET 5 ***/
	nessie_print_setheader(5);
	memset(key, 0, (keysize_b+7)/8);
	for(v=0;v<ivsize_b; v+=estream_flag?9:1){
		nessie_print_set_vector(5,v);
		iv[v/8] |= 0x80>>(v&7);
		nessie_print_item("key", key, (keysize_b+7)/8);
		nessie_print_item("IV", iv, (ivsize_b+7)/8);
		scal_cipher_init(desc, key, keysize_b, iv, ivsize_b, &ctx);
		normal_block(&ctx);
		scal_cipher_free(&ctx);
		iv[v/8] = 0;
	}
	/***  Test SET 6 ***/
	nessie_print_setheader(6);
	for(v=0;v<4; ++v){
		uint8_t i;
		nessie_print_set_vector(6,v);
		for(i=0; i<((keysize_b+7)/8); ++i){
			key[i]=(i*0x53+v*5)&0xff;
		}
		for(i=0; i<((ivsize_b+7)/8); ++i){
			iv[i]=(i*0x67+v*9+13)&0xff;
		}
		nessie_print_item("key", key, (keysize_b+7)/8);
		nessie_print_item("IV", iv, (ivsize_b+7)/8);
		scal_cipher_init(desc, key, keysize_b, iv, ivsize_b, &ctx);
		long_block(&ctx);
		scal_cipher_free(&ctx);
	}
	/***  Test SET 7 ***/
	if(!estream_flag){
		nessie_print_setheader(7);
		uint8_t u;
		for(v=0;v<3; ++v){
			for(u=0; u<3; ++u){
				uint8_t i;
				nessie_print_set_vector(7,v*3+u);
				for(i=0; i<((keysize_b+7)/8); ++i){
					key[i]=list_of_keys[v][i%20];
				}
				for(i=0; i<((ivsize_b+7)/8); ++i){
					key[i]=*((uint8_t*)list_of_keys+4*u+(i%4));
				}
			}
			nessie_print_item("key", key, (keysize_b+7)/8);
			nessie_print_item("IV", iv, (ivsize_b+7)/8);
			scal_cipher_init(desc, key, keysize_b, iv, ivsize_b, &ctx);
			long_block(&ctx);
			scal_cipher_free(&ctx);
		}
	}
	nessie_print_footer();
}