コード例 #1
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);
}
コード例 #2
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);
}
コード例 #3
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);
}
コード例 #4
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);
	
}
コード例 #5
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);
}
コード例 #6
0
ファイル: nessie_mac_test.c プロジェクト: azilly-de/openkubus
static
void amillion_mac(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];
	uint32_t n=1000000LL;
	uint16_t i=0;
	
	NESSIE_PUTSTR_P(PSTR("\r\n                       message="));
	NESSIE_PUTSTR_P(PSTR("1 million times \"a\""));
	PRINTKEY;
	
	memset(block, 'a', nessie_mac_ctx.blocksize_B);
	nessie_mac_ctx.mac_init(key, nessie_mac_ctx.keysize_b, ctx);
	while(n>nessie_mac_ctx.blocksize_B){
		nessie_mac_ctx.mac_next(block, ctx);
		n    -= nessie_mac_ctx.blocksize_B;
		NESSIE_SEND_ALIVE_A(i++);
	}
	nessie_mac_ctx.mac_last(block, n*8, key, nessie_mac_ctx.keysize_b, ctx);
	nessie_mac_ctx.mac_conv(mac, ctx);
	PRINTMAC;
}