Пример #1
0
void nessie_hash_run(void){
	uint16_t i;
	uint8_t set;
	
	nessie_print_header(nessie_hash_ctx.name, 0, 0, nessie_hash_ctx.hashsize_b, 0, 0);
	/* test set 1 */
	const char *challange_dbz= PSTR(
		  "\0"
		"\"\" (empty string)\0"
		  "a\0"
		"\"a\"\0"
		  "abc\0"
		"\"abc\"\0"
		  "message digest\0"
		"\"message digest\"\0"
		  "abcdefghijklmnopqrstuvwxyz\0"
		"\"abcdefghijklmnopqrstuvwxyz\"\0"
		  "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\0"
		"\"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\"\0"
		  "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
		  "abcdefghijklmnopqrstuvwxyz"
		  "0123456789\0"	 
		 "\"A...Za...z0...9\"\0"
		 "1234567890123456789012345678901234567890" 
		 "1234567890123456789012345678901234567890\0"
		 "8 times \"1234567890\"\0"
	);
	PGM_P challange[16];
	set=1;
	nessie_print_setheader(set);
	dbz_splitup_P(challange_dbz, challange);
	for(i=0; i<8; ++i){
		nessie_print_set_vector(set, i);
		ascii_hash_P(challange[2*i], challange[2*i+1]);
	}
	nessie_print_set_vector(set, i);
	if(!nessie_hash_quick)
		amillion_hash();
	/* test set 2 */
	set=2;
	nessie_print_setheader(set);
	for(i=0; i<1024; ++i){
		nessie_print_set_vector(set, i);
		zero_hash(i);
	}
	/* test set 3 */
	set=3;
	nessie_print_setheader(set);
	for(i=0; i<512; ++i){
		nessie_print_set_vector(set, i);
		one_in512_hash(i);
	}
	/* test set 4 */
	set=4;
	nessie_print_setheader(set);
	nessie_print_set_vector(set, 0);
	tv4_hash();

	nessie_print_footer();
}
Пример #2
0
void nessie_stream_run(void){
	uint16_t i;
	uint8_t set;
	uint8_t key[(nessie_stream_ctx.keysize_b+7)/8];
	
	nessie_print_header(nessie_stream_ctx.name, nessie_stream_ctx.keysize_b,
	                    0, 0, 0, nessie_stream_ctx.ivsize_b);
	/* test set 1 */
	set=1;
	nessie_print_setheader(set);
	for(i=0; i<nessie_stream_ctx.keysize_b; ++i){
		nessie_print_set_vector(set, i);
		memset(key, 0, (nessie_stream_ctx.keysize_b+7)/8);
		key[i/8] |= 0x80>>(i%8);
		nessie_stream_enc(key);
	}
	/* test set 2 */
	set=2;
	nessie_print_setheader(set);
	for(i=0; i<256; ++i){
		nessie_print_set_vector(set, i);
		memset(key, i, (nessie_stream_ctx.keysize_b+7)/8);
		nessie_stream_enc(key);
	}
	/* test set 3 */
	set=3;
	nessie_print_setheader(set);
	for(i=0; i<256; ++i){
		uint8_t j;
		nessie_print_set_vector(set, i);
		for(j=0; j<(nessie_stream_ctx.keysize_b+7)/8; ++j){
			key[j]=(i+j)&0xff;
		}
		nessie_stream_enc(key);
	}
	/* test set 4 */
	set=4;
	nessie_print_setheader(set);
	for(i=0; i<4; ++i){
		uint8_t j;
		nessie_print_set_vector(set, i);
		for(j=0; j<(nessie_stream_ctx.keysize_b+7)/8; ++j){
			key[j]=(i*5+j*0x53)&0xff;
		}
		nessie_stream_enc_large(key);
	}

	nessie_print_footer();
}
Пример #3
0
void nessie_mac_run(void){
	uint16_t i;
	uint8_t set;
	uint8_t keyproto[] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
                          0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff,
                          0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
	uint8_t key[KEYSIZE_B];
	
	nessie_print_header(nessie_mac_ctx.name, nessie_mac_ctx.keysize_b, 0, 0,
	                    nessie_mac_ctx.macsize_b, 0);
	/* test set 1 */
	char* challange[10][2]= {
		{"", "\"\" (empty string)"},
		{"a", "\"a\""},
		{"abc", "\"abc\""},
		{"message digest", "\"message digest\""},
		{"abcdefghijklmnopqrstuvwxyz","\"abcdefghijklmnopqrstuvwxyz\""},
		{"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
			"\"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\""},
		{"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
		 "abcdefghijklmnopqrstuvwxyz"
		 "0123456789"	, "\"A...Za...z0...9\""},
		{"1234567890" "1234567890" "1234567890" "1234567890" 
		 "1234567890" "1234567890" "1234567890" "1234567890",
		 "8 times \"1234567890\""},
		{"Now is the time for all ", "\"Now is the time for all \""},
		{"Now is the time for it", "\"Now is the time for it\""}
	};

	set=1;
	nessie_print_setheader(set);
	for(i=0; i<KEYSIZE_B; ++i){
		key[i] = keyproto[i%sizeof(keyproto)];
	}
	for(i=0; i<10; ++i){
		nessie_print_set_vector(set, i);
		ascii_mac(challange[i][0], challange[i][1], key);
	}
	nessie_print_set_vector(set, i);
	amillion_mac(key);
	for(i=0; i<KEYSIZE_B; ++i){
		key[i] = keyproto[16+i%8];
	}
	for(i=0; i<10; ++i){
		nessie_print_set_vector(set, 11+i);
		ascii_mac(challange[i][0], challange[i][1], key);
	}
	nessie_print_set_vector(set, 11+i);
	amillion_mac(key);
	/* test set 2 */
	set=2;
	for(i=0; i<KEYSIZE_B; ++i){
		key[i] = keyproto[i%sizeof(keyproto)];
	}
	nessie_print_setheader(set);
	for(i=0; i<1024; ++i){
		nessie_print_set_vector(set, i);
		zero_mac(i, key);
	}
	/* test set 3 */
	set=3;
	nessie_print_setheader(set);
	/* we use the same key as above */
	for(i=0; i<512; ++i){
		nessie_print_set_vector(set, i);
		one_in512_mac(i, key);
	}
	/* test set 4 */
	set=4;
	nessie_print_setheader(set);
	/* we use the same key as above */
	nessie_print_set_vector(set, 0);
	tv4_mac(key);
	/* test set 5 */
	for(i=0; i<nessie_mac_ctx.keysize_b; ++i){
		nessie_print_set_vector(set, i);
		memset(key, 0, KEYSIZE_B);
		key[i>>3]=0x80>>(i&0x7);
		ascii_mac("ABC", "\"ABC\"", key);
	}
	nessie_print_footer();
}
Пример #4
0
void nessie_bc_run(void){
	uint16_t i;
	uint8_t set;
	uint8_t key[(nessie_bc_ctx.keysize_b+7)/8];
	uint8_t buffer[nessie_bc_ctx.blocksize_B];
	
	nessie_print_header(nessie_bc_ctx.name, nessie_bc_ctx.keysize_b,
	                    nessie_bc_ctx.blocksize_B*8, 0, 0, 0);
	/* test set 1 */
	set=1;
	nessie_print_setheader(set);
	for(i=0; i<nessie_bc_ctx.keysize_b; ++i){
		nessie_print_set_vector(set, i);
		memset(key, 0, (nessie_bc_ctx.keysize_b+7)/8);
		key[i/8] |= 0x80>>(i%8);
		memset(buffer, 0, nessie_bc_ctx.blocksize_B);
		nessie_bc_enc(key, buffer);
	}
	/* test set 2 */
	set=2;
	nessie_print_setheader(set);
	for(i=0; i<nessie_bc_ctx.blocksize_B*8; ++i){
		nessie_print_set_vector(set, i);
		memset(key, 0, (nessie_bc_ctx.keysize_b+7)/8);
		memset(buffer, 0, nessie_bc_ctx.blocksize_B);
		buffer[i/8] |= 0x80>>(i%8);
		nessie_bc_enc(key, buffer);
	}
	/* test set 3 */
	set=3;
	nessie_print_setheader(set);
	for(i=0; i<256; ++i){
		nessie_print_set_vector(set, i);
		memset(key, i, (nessie_bc_ctx.keysize_b+7)/8);
		memset(buffer, i, nessie_bc_ctx.blocksize_B);
		nessie_bc_enc(key, buffer);
	}
	/* test set 4 */
	set=4;
	nessie_print_setheader(set);
	/* 4 - 0*/
	nessie_print_set_vector(set, 0);
	for(i=0; i<(nessie_bc_ctx.keysize_b+7)/8; ++i){
		key[i]=i;
	}
	for(i=0; i<nessie_bc_ctx.blocksize_B; ++i){
		buffer[i]=i*0x11;
	}
	nessie_bc_enc(key, buffer);
	/* 4 - 1 */
	nessie_print_set_vector(set, 1);	
    /* This is the test vectors in Kasumi */
    static uint8_t kasumi_key[] = {
           0x2B, 0xD6, 0x45, 0x9F, 0x82, 0xC5, 0xB3, 0x00,
           0x95, 0x2C, 0x49, 0x10, 0x48, 0x81, 0xFF, 0x48 };
    static uint8_t kasumi_plain[]={
           0xEA, 0x02, 0x47, 0x14, 0xAD, 0x5C, 0x4D, 0x84 };
	for(i=0; i<(nessie_bc_ctx.keysize_b+7)/8; ++i){
		key[i]=kasumi_key[i%sizeof(kasumi_key)];
	}
	for(i=0; i<nessie_bc_ctx.blocksize_B; ++i){
		buffer[i]=kasumi_plain[i%sizeof(kasumi_plain)];
	}
	nessie_bc_enc(key, buffer);
	/* half done ;-) */
	if(nessie_bc_ctx.cipher_dec==NULL)
		return;
	/* test set 5 */
	set=5;
	nessie_print_setheader(set);
	for(i=0; i<nessie_bc_ctx.keysize_b; ++i){
		nessie_print_set_vector(set, i);
		memset(key, 0, (nessie_bc_ctx.keysize_b+7)/8);
		key[i/8] |= 0x80>>(i%8);
		memset(buffer, 0, nessie_bc_ctx.blocksize_B);
		nessie_bc_dec(key, buffer);
	}
	/* test set 6 */
	set=6;
	nessie_print_setheader(set);
	for(i=0; i<nessie_bc_ctx.blocksize_B*8; ++i){
		nessie_print_set_vector(set, i);
		memset(key, 0, (nessie_bc_ctx.keysize_b+7)/8);
		memset(buffer, 0, nessie_bc_ctx.blocksize_B);
		buffer[i/8] |= 0x80>>(i%8);
		nessie_bc_dec(key, buffer);
	}
	/* test set 7 */
	set=7;
	nessie_print_setheader(set);
	for(i=0; i<256; ++i){
		nessie_print_set_vector(set, i);
		memset(key, i, (nessie_bc_ctx.keysize_b+7)/8);
		memset(buffer, i, nessie_bc_ctx.blocksize_B);
		nessie_bc_dec(key, buffer);
	}
	/* test set 8 */
	set=8;
	nessie_print_setheader(set);
	/* 8 - 0*/
	nessie_print_set_vector(set, 0);
	for(i=0; i<(nessie_bc_ctx.keysize_b+7)/8; ++i){
		key[i]=i;
	}
	for(i=0; i<nessie_bc_ctx.blocksize_B; ++i){
		buffer[i]=i*0x11;
	}
	nessie_bc_dec(key, buffer);
	/* 8 - 1 */
	nessie_print_set_vector(set, 1);	
 	for(i=0; i<(nessie_bc_ctx.keysize_b+7)/8; ++i){
		key[i]=kasumi_key[i%sizeof(kasumi_key)];
	}
	for(i=0; i<nessie_bc_ctx.blocksize_B; ++i){
		buffer[i]=kasumi_plain[i%sizeof(kasumi_plain)];
	}
	nessie_bc_dec(key, buffer);
	nessie_print_footer();
}
Пример #5
0
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();
}