示例#1
0
/*
Klen = 16
Mlen = 18
Tlen = 2
Key = 3250974e306b4b678f914b514d1e90f6
Msg = cf132fd4ebc25fd3866f1a95a6193a1a9cdf
*/
void testrun_aes128_cmac72(void){
	uint8_t key[16]= {
			0x32, 0x50, 0x97, 0x4e, 0x30, 0x6b, 0x4b, 0x67,
			0x8f, 0x91, 0x4b, 0x51, 0x4d, 0x1e, 0x90, 0xf6
	};
	uint8_t tag[2];
	uint8_t plain[18] = {
			0xcf, 0x13, 0x2f, 0xd4, 0xeb, 0xc2, 0x5f, 0xd3,
			0x86, 0x6f, 0x1a, 0x95, 0xa6, 0x19, 0x3a, 0x1a,
			0x9c, 0xdf,
	};
	bcal_cmac_ctx_t ctx;
	uint8_t r;


	cli_putstr("\r\n** AES128-CMAC-72-TEST **");

	cli_putstr("\r\n  key:   ");
	cli_hexdump(key, 128/8);
	r = bcal_cmac_init(&aes128_desc, key, 128, &ctx);
	cli_putstr("\r\n  init = 0x");
	cli_hexdump(&r, 1);
	cli_putstr("\r\n  message: ");
	cli_hexdump_block(plain, 18, 4, 16);
	if(r)
		return;
	bcal_cmac(tag, 16, plain, 18*8, &ctx);
	cli_putstr("\r\n  tag:     ");
	cli_hexdump_block(tag, 2, 4, 16);
	bcal_cmac_free(&ctx);
}
void testrun_aes128_ofb(void){
	uint8_t key[16];
	uint8_t iv[16];
	uint8_t plain[64];

	bcal_ofb_ctx_t ctx;
	uint8_t r;

	memcpy_P(key,   modes_key,   16);
	memcpy_P(iv,    modes_iv,    16);
	memcpy_P(plain, modes_plain, 64);

	cli_putstr_P(PSTR("\r\n** AES128-OFB-TEST **"));
	r = bcal_ofb_init(&aes128_desc, key, 128, &ctx);
	cli_putstr_P(PSTR("\r\n  init = 0x"));
	cli_hexdump(&r, 1);
	cli_putstr_P(PSTR("\r\n  key:   "));
	cli_hexdump(key, 128/8);
	cli_putstr_P(PSTR("\r\n  IV:    "));
	cli_hexdump(iv, 128/8);
	cli_putstr_P(PSTR("\r\n  plaintext:"));
	cli_hexdump_block(plain, 4*128/8, 4, 16);
	if(r)
		return;
	bcal_ofb_encMsg(iv, plain, 4*128, &ctx);
	cli_putstr_P(PSTR("\r\n  ciphertext:  "));
	cli_hexdump_block(plain, 4*128/8, 4, 16);
	bcal_ofb_decMsg(iv, plain, 4*128, &ctx);
	cli_putstr_P(PSTR("\r\n  plaintext:   "));
	cli_hexdump_block(plain, 4*128/8, 4, 16);
	bcal_ofb_free(&ctx);
}
void testrun_md5(void){
	md5_hash_t hash;
	char* testv[]={
		"", 
		"a", 
		"abc", 
		"message digest", 
		"abcdefghijklmnopqrstuvwxyz", 
		"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 
		"12345678901234567890123456789012345678901234567890123456789012345678901234567890"};
	uint16_t i;
	
	cli_putstr("\r\n=== MD5 test suit ===");
	for(i=0; i<7; ++i){
		cli_putstr("\r\n MD5 (\"");
		cli_putstr(testv[i]);
		cli_putstr("\") = \r\n\t");
		md5(&hash, testv[i], strlen(testv[i])*8);
		cli_hexdump(hash, 16);
	}
	uint8_t buffer[512/8];
	char str[5];
	for(i=505; i<512; ++i){
		memset(buffer, 0, 512/8);
		cli_putstr_P(PSTR("\r\nMD5("));
		utoa(i, str, 10);
		cli_putstr(str);
		cli_putstr_P(PSTR(" zero bits) = "));
		md5(&hash, buffer, i);
		cli_hexdump(hash, 16);
	}
}
示例#4
0
void cscipher_enc(void* buffer, const cscipher_ctx_t* ctx){
	uint8_t i,j,k;
	uint8_t tmp[8];
	for(i=0; i<8; ++i){
#if DEBUG
		cli_putstr("\r\nDBG: round ");
		cli_hexdump(&i, 1);
		cli_putstr(" buffer:");
		cli_hexdump(buffer, 8);
#endif
		for(j=0; j<3; ++j){
			if(j==0){
				memxor(buffer, ctx->keys[i], 8);
			}else{
				memxor(buffer, round_const+((j==1)?0:8), 8);
			}
			for(k=0; k<4; ++k){
				((uint16_t*)tmp)[k] = m(((uint16_t*)buffer)[k]);
			}
			for(k=0; k<4; ++k){
				((uint8_t*)buffer)[k]   = tmp[2*k];
				((uint8_t*)buffer)[k+4] = tmp[2*k+1];
			}
		}
	}
	memxor(buffer, ctx->keys[8], 8);
}
示例#5
0
/*
Count = 0
Klen = 24
Mlen = 0
Tlen = 2
Key = 2b2aaa666be161ed16648e862ac9bd1e317f71bc69e268b5
Msg = 00
*/
void testrun_aes192_cmac0(void){
	uint8_t key[24]= {
			0x2b, 0x2a, 0xaa, 0x66, 0x6b, 0xe1, 0x61, 0xed,
			0x16, 0x64, 0x8e, 0x86, 0x2a, 0xc9, 0xbd, 0x1e,
			0x31, 0x7f, 0x71, 0xbc, 0x69, 0xe2, 0x68, 0xb5
	};
	uint8_t tag[2];
	uint8_t plain[1] = {
			0x00
	};
	bcal_cmac_ctx_t ctx;
	uint8_t r;


	cli_putstr("\r\n** AES192-CMAC-0-TEST **");

	cli_putstr("\r\n  key:   ");
	cli_hexdump(key, 192/8);
	r = bcal_cmac_init(&aes192_desc, key, 192, &ctx);
	cli_putstr("\r\n  init = 0x");
	cli_hexdump(&r, 1);
	if(r)
		return;
	bcal_cmac(tag, 16, plain, 0*8, &ctx);
	cli_putstr("\r\n  tag:     ");
	cli_hexdump_block(tag, 2, 4, 16);
	bcal_cmac_free(&ctx);
}
示例#6
0
void cscipher_init(const void* key, cscipher_ctx_t* ctx){
	uint8_t tmp_key[16], tmp[8];
	uint8_t i,j,k,t=0;
	memcpy(tmp_key, key, 16);
	for(i=0; i<9; ++i){
#if DEBUG
		cli_putstr("\r\nDBG: round ");
		cli_hexdump(&i, 1);
		cli_putstr(" key state:");
		cli_hexdump(tmp_key, 16);
#endif
		memcpy(tmp, tmp_key+(((i&1)==0)?0:8), 8);
		memxor(tmp, ks_const+8*i, 8);
		for(j=0; j<8; ++j){
			tmp[j] = P(tmp[j]);
		}
		for(j=0; j<8; ++j){
			for(k=0; k<8; ++k){
				t<<=1;
				t |= tmp[k]>>7;
				tmp[k]<<=1;
			}
			tmp_key[j+(((i&1)==0)?8:0)] ^= t;
		}
		memcpy(ctx->keys[i], tmp_key+(((i&1)==0)?8:0), 8);
	}
}
示例#7
0
void testrun_aes128_ctr(void){
	uint8_t key[16];
	uint8_t iv[16];
	uint8_t plain[64];

	bcal_ctr_ctx_t ctx;
	uint8_t r;

	memcpy(key,   modes_key,   16);
	memcpy(iv,    modes_ctriv, 16);
	memcpy(plain, modes_plain, 64);

	cli_putstr("\r\n** AES128-CTR-TEST **");
	r = bcal_ctr_init(&aes128_desc, key, 128, NULL, &ctx);
	cli_putstr("\r\n  init = 0x");
	cli_hexdump(&r, 1);
	cli_putstr("\r\n  key:   ");
	cli_hexdump(key, 128/8);
	cli_putstr("\r\n  IV:    ");
	cli_hexdump(iv, 128/8);
	cli_putstr("\r\n  plaintext:");
	cli_hexdump_block(plain, 4*128/8, 4, 16);
	if(r)
		return;
	bcal_ctr_encMsg(iv, plain, 4*128, &ctx);
	cli_putstr("\r\n  ciphertext:  ");
	cli_hexdump_block(plain, 4*128/8, 4, 16);
	bcal_ctr_decMsg(iv, plain, 4*128, &ctx);
	cli_putstr("\r\n  plaintext:   ");
	cli_hexdump_block(plain, 4*128/8, 4, 16);
	bcal_ctr_free(&ctx);
}
示例#8
0
void shabal_ctx_dump(shabal_ctx_t *ctx){
	uint8_t i;
	void *p;
	cli_putstr_P(PSTR("\r\n=== shabal ctx dump ===\r\n  size = "));
	i=sizeof(shabal_ctx_t);
	if(i>=100)
		cli_putc('0'+i/100);
	if(i>=10)
		cli_putc('0'+(i/10)%10);
	cli_putc('0'+i%10);
	cli_putstr_P(PSTR("\r\n  a = "));
	cli_hexdump_block(ctx->a, 12*4, 5, 4*8);
	cli_putstr_P(PSTR("\r\n  b_buffer = "));
	cli_hexdump_block(ctx->b_buffer, 12*4, 5, 4*8);
	cli_putstr_P(PSTR("\r\n  c_buffer = "));
	cli_hexdump_block(ctx->c_buffer, 12*4, 5, 4*8);
	if(ctx->b == &(ctx->b_buffer[0]))
		cli_putstr_P(PSTR("\r\nb --> b_buffer"));
	if(ctx->b == &(ctx->c_buffer[0]))
		cli_putstr_P(PSTR("\r\nb --> c_buffer"));
	if(ctx->c == &(ctx->b_buffer[0]))
		cli_putstr_P(PSTR("\r\nc --> b_buffer"));
	if(ctx->c == &(ctx->c_buffer[0]))
		cli_putstr_P(PSTR("\r\nc --> c_buffer"));
	cli_putstr_P(PSTR("\r\n b = "));
	cli_hexdump(&(ctx->b), 2);
	p = ctx->b_buffer;
	cli_putstr_P(PSTR("\r\n b (should) = "));
	cli_hexdump(&p, 2);
	cli_putstr_P(PSTR("\r\n c = "));
	cli_hexdump(&(ctx->c), 2);
	p = ctx->c_buffer;
	cli_putstr_P(PSTR("\r\n c (should) = "));
	cli_hexdump(&p, 2);
}
/*
128-bit key
key         01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10
plaintext   01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10
ciphertext  67 67 31 38 54 96 69 73 08 57 06 56 48 ea be 43
*/
void testrun_camellia(void){

  uint8_t data[16] = { 0x01, 0x23, 0x45, 0x67, 
                       0x89, 0xab, 0xcd, 0xef, 
                       0xfe, 0xdc, 0xba, 0x98, 
                       0x76, 0x54, 0x32, 0x10 };

  uint8_t key[16] = { 0x01, 0x23, 0x45, 0x67, 
                       0x89, 0xab, 0xcd, 0xef, 
                       0xfe, 0xdc, 0xba, 0x98, 
                       0x76, 0x54, 0x32, 0x10 };


  camellia128_ctx_t ctx;
  camellia128_init(key, &ctx);
  cli_putstr_P(PSTR("\r\n key:        "));
  cli_hexdump(data, 16);
  cli_putstr_P(PSTR("\r\n plaintext:  "));
  cli_hexdump(data, 16);
  camellia128_enc(data, &ctx);
  cli_putstr_P(PSTR("\r\n ciphertext: "));
  cli_hexdump(data, 16);
  camellia128_dec(data, &ctx);
  cli_putstr_P(PSTR("\r\n decrypted:  "));
  cli_hexdump(data, 16);

}
示例#10
0
void testrun_aes128_cmac(void){
	uint8_t key[16];
	uint8_t tag[16];
	uint8_t plain[64];
	uint16_t length[] = { 0, 128, 320, 512 };
	bcal_cmac_ctx_t ctx;
	uint8_t r,i;

	memcpy(key,   modes_key,   16);
	memcpy(plain, modes_plain, 64);

	cli_putstr("\r\n** AES128-CMAC-TEST **");

	cli_putstr("\r\n  key:   ");
	cli_hexdump(key, 128/8);
	for(i=0; i<4; ++i){
		r = bcal_cmac_init(&aes128_desc, key, 128, &ctx);
		cli_putstr("\r\n  init = 0x");
		cli_hexdump(&r, 1);
		cli_putstr("\r\n  message: ");
		cli_hexdump_block(plain, length[i]/8, 4, 16);
		if(r)
			return;
		bcal_cmac(tag, 128, plain, length[i], &ctx);
		cli_putstr("\r\n  tag:     ");
		cli_hexdump_block(tag, 128/8, 4, 16);
		bcal_cmac_free(&ctx);
	}
}
示例#11
0
void testencrypt(uint8_t *block, uint8_t *key){
	cli_putstr("\r\n==testy-encrypt==\r\n key: ");
	cli_hexdump(key,16);
	cli_putstr("\r\n plain: ");
	cli_hexdump(block,32);
	shabea256(block,key,128,1,16);
	cli_putstr("\r\n crypt: ");
	cli_hexdump(block,32);
}
示例#12
0
void testdecrypt(uint8_t *block, uint8_t *key){
	cli_putstr("\r\n==testy-decrypt==\r\n key: ");
	cli_hexdump(key,10);
	cli_putstr("\r\n crypt: ");
	cli_hexdump(block,8);
	skipjack_dec(block,key);
	cli_putstr("\r\n plain: ");
	cli_hexdump(block,8);
}
 void ctx_dump(const bmw_small_ctx_t* ctx){
 	uint8_t i;
	cli_putstr("\r\n==== ctx dump ====");
	for(i=0; i<16;++i){
		cli_putstr("\r\n h[");
		cli_hexdump(&i, 1);
		cli_putstr("] = ");
		cli_hexdump_rev(&(ctx->h[i]), 4);
	}
	cli_putstr("\r\n counter = ");
	cli_hexdump(&(ctx->counter), 4);
 }
示例#14
0
void testrun_test_serpent(void){
	uint8_t key[32];
	serpent_ctx_t ctx;
	uint8_t i;
	memset(key, 0, 16);
	serpent_init(key, 128, &ctx);
	for(i=0; i<33; ++i){
		cli_putstr_P(PSTR("\r\n subkekey "));	
		cli_hexdump(&i, 1);
		cli_putstr_P(PSTR(" : "));	
		cli_hexdump(ctx.k[i], 16);
	}
}
void md5_nextBlock(md5_ctx_t *state, const void* block){
	uint32_t	a[4];
	uint8_t		m,n,i=0;
	/* this requires other mixed sboxes */
#ifdef DEBUG
	cli_putstr("\r\n DBG: md5_nextBlock: block:\r\n");
	cli_hexdump(block, 16);	cli_putstr("\r\n");
	cli_hexdump(block+16, 16);	cli_putstr("\r\n");
	cli_hexdump(block+32, 16);	cli_putstr("\r\n");
	cli_hexdump(block+48, 16);	cli_putstr("\r\n");
#endif	
	
	a[0]=state->a[0];
	a[1]=state->a[1];
	a[2]=state->a[2];
	a[3]=state->a[3];
	
	/* round 1 */
	uint8_t s1t[]={7,12,17,22}; // 1,-1   1,4   2,-1   3,-2
	for(m=0;m<4;++m){
		for(n=0;n<4;++n){
			md5_core(a, &(((uint32_t*)block)[m*4+n]), 4-n, s1t[n],i++,0);
		}
	}
	/* round 2 */
	uint8_t s2t[]={5,9,14,20}; // 1,-3   1,1   2,-2   2,4
	for(m=0;m<4;++m){
		for(n=0;n<4;++n){
			md5_core(a, &(((uint32_t*)block)[(1+m*4+n*5)&0xf]), 4-n, s2t[n],i++,1);
		}
	}
	/* round 3 */
	uint8_t s3t[]={4,11,16,23}; // 0,4   1,3   2,0   3,-1
	for(m=0;m<4;++m){
		for(n=0;n<4;++n){
			md5_core(a, &(((uint32_t*)block)[(5-m*4+n*3)&0xf]), 4-n, s3t[n],i++,2);
		}
	}
	/* round 4 */
	uint8_t s4t[]={6,10,15,21}; // 1,-2   1,2   2,-1   3,-3
	for(m=0;m<4;++m){
		for(n=0;n<4;++n){
			md5_core(a, &(((uint32_t*)block)[(0-m*4+n*7)&0xf]), 4-n, s4t[n],i++,3);
		}
	}
	state->a[0] += a[0];
	state->a[1] += a[1];
	state->a[2] += a[2];
	state->a[3] += a[3];
	state->counter++;
}
示例#16
0
void testrun_nessie2(void){
	uint16_t i;
	uint8_t j;
	uint8_t data[128], hash[64];
	whirlpool_ctx_t ctx;
	char str[8];
	memset(data, 0, 128);
	cli_putstr_P(PSTR("\r\nMessage digests of strings of 0-bits and length L:"));
	for(i=0; i<1024; ++i){
		cli_putstr_P(PSTR("\r\n    L = "));
		itoa(i, str, 10);
		j=4;
		j-= strlen(str);
		if(j>3){
			j=0;
		}
		while(j--){
			cli_putc(' ');
		}
		cli_putstr(str);
		cli_putstr_P(PSTR(": "));
		whirlpool_init(&ctx);
		whirlpool_lastBlock(&ctx, data, i);
		whirlpool_ctx2hash(hash, &ctx);
		cli_hexdump(hash, 64);
	}
	cli_putstr_P(PSTR("\r\nMessage digests of all 512-bit strings S containing a single 1-bit:"));
	for(i=0; i<512; ++i){
		cli_putstr_P(PSTR("\r\n    S = "));
		data[i/8] = 0x80>>(i&7);
		cli_hexdump(data, 64);
		cli_putstr_P(PSTR(": "));
		whirlpool_init(&ctx);
		whirlpool_lastBlock(&ctx, data, 512);
		whirlpool_ctx2hash(hash, &ctx);
		data[i/8] = 0x00;
		cli_hexdump(hash, 64);
	}
	cli_putstr_P(PSTR("\r\nIterated message digest computation (100000000 times): "));
	uint32_t c;
	memset(hash, 0, 64);
	for(c=0; c<1000000; ++c){
		whirlpool_init(&ctx);
		whirlpool_lastBlock(&ctx, hash, 512);
		whirlpool_ctx2hash(hash, &ctx);
	}
	cli_hexdump(hash, 64);
	cli_putstr_P(PSTR("\r\n/* finish generating testvectors */\r\n"));
}
示例#17
0
void quick_test(void){
	dsa_signature_t dsa_sig;
	uint8_t i, t=0, message[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};
	load_fix_dsa();
	bigint_word_t dsa_sig_s_b[dsa_ctx.domain.q.length_W],
	        dsa_sig_r_b[dsa_ctx.domain.q.length_W];
	dsa_print_ctx(&dsa_ctx);
	dsa_sig.r.wordv = dsa_sig_r_b;
	dsa_sig.s.wordv = dsa_sig_s_b;
	cli_putstr("\r\n\r\n=== DSA QUICK TEST ===");
	for(i=0; i<9; ++i){
		cli_putstr("\r\n");
		cli_putc('1'+i);
		cli_putstr(": message: ");
		if (i){
			cli_hexdump(message, i);
		}else{
			cli_putstr("<empty>");
		}
		cli_putstr("\r\n computing signature ... ");
		dsa_sign_message(&dsa_sig, message, i*8, &sha1_desc, &dsa_ctx, random8);
		dsa_print_signature(&dsa_sig);
		cli_putstr("\r\n base64:\r\n--- SIGNATURE ---\r\n ");
		dsa_print_signature_b64(&dsa_sig);
		cli_putstr("\r\n verifying signature ... ");
		t = dsa_verify_message(&dsa_sig, message, i*8, &sha1_desc, &dsa_ctx);
		cli_putstr("\r\n verification: ");
		if(t==DSA_SIGNATURE_OK){
			cli_putstr("[PASS]");
		}else{
			cli_putstr("[FAIL]");
		}
	}
}
void hexdump128(void* data){
	uint8_t i;
	for(i=0; i<16; ++i){
		cli_hexdump(data, 1);
		cli_putc(' ');
		data = (uint8_t*)data +1;
	}
}
示例#19
0
void testrun_serpent256(void){
	uint8_t key[32];
	uint8_t data[16];
	serpent_ctx_t ctx;
	memset(key, 0, 32);
	memset(data, 0, 16);
	key[0] = 0x80;
	cli_putstr("\r\n== small test Serpent-256 ==");
	cli_putstr("\r\n  key    = ");
	cli_hexdump(key, 32);
	cli_putstr("\r\n  plain  = ");
	cli_hexdump(data, 16);
	serpent_init(key, 256, &ctx);
	serpent_enc(data, &ctx);
	cli_putstr("\r\n  cipher = ");
	cli_hexdump(data, 16);
}
示例#20
0
void testrun_long_cscipher(void){
	uint8_t data[8];
	char str[10];
	uint16_t i;
	uint8_t j;
	uint8_t key[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
					 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 };
	cscipher_ctx_t ctx;
	cli_putstr("\r\n== CS-Cipher test==\r\nkey: ");
	cli_hexdump(key, 16);
	cscipher_init(key, &ctx);
	memset(data, 0, 8);
	cli_putstr("\r\nplain:  ");
	cli_hexdump(data, 8);
	cli_putstr("\r\nencrypting 1,000,000 times:\r\n");
	for(i=0; i<10000;++i){
		for(j=0;j<100;++j){
			cscipher_enc(data, &ctx);
		}
		if(i%128==0){
			sprintf(str, "%d", i);
			cli_putstr("\r\n");
			cli_putstr(str);
			cli_putstr(": ");
		}
		cli_putc('*');

	}
	cli_putstr("\r\ncipher: ");
	cli_hexdump(data, 8);
	cli_putstr("\r\ndecrypting 1,000,000 times:");
	for(i=0; i<10000;++i){
		for(j=0;j<100;++j){
			cscipher_dec(data, &ctx);
		}
		if(i%128==0){
			sprintf(str, "%d", i);
			cli_putstr("\r\n");
			cli_putstr(str);
			cli_putstr(": ");
		}
		cli_putc('*');
	}
	cli_putstr("\r\nplain:  ");
	cli_hexdump(data, 8);
}
示例#21
0
void testrun_testkey_aes128(void){
	uint8_t key[16] = { 0x2b, 0x7e, 0x15, 0x16,
	                    0x28, 0xae, 0xd2, 0xa6,
	                    0xab, 0xf7, 0x15, 0x88,
	                    0x09, 0xcf, 0x4f, 0x3c};
	aes128_ctx_t ctx;
	uint8_t i;
	aes128_init(key, &ctx);
	cli_putstr("\r\n\r\n keyschedule test (FIPS 197):\r\n key:   ");
	cli_hexdump(key, 16);
	for(i=0; i<11; ++i){
		cli_putstr("\r\n index: ");
		cli_putc('0'+i/10);
		cli_putc('0'+i%10);
		cli_putstr(" roundkey ");
		cli_hexdump(ctx.key[i].ks, 16);
	}
}
void testrun_stdtest_rundirect(void* data, void* key) {
    cli_putstr_P(PSTR("\r\n                     "));
    cli_putstr_P(PSTR("k = "));
    cli_hexdump(key,16);

    cli_putstr_P(PSTR("\r\n                     "));
    cli_putstr_P(PSTR("a = "));
    cli_hexdump(data,16);

    noekeon_enc(data, key);
    cli_putstr_P(PSTR("\r\nafter NESSIEencrypt, b = "));
    cli_hexdump(data,16);

    noekeon_dec(data, key);
    cli_putstr_P(PSTR("\r\nafter NESSIEdecrypt, a?= "));
    cli_hexdump(data,16);
    cli_putstr_P(PSTR("\r\n"));
}
示例#23
0
 void dump_m(const uint8_t* m){
	 uint8_t i,j;
	 for(i=0; i<8; ++i){
		cli_putstr("\r\n");
		for(j=0; j<8; ++j){
			cli_putc(' ');
			cli_hexdump(m+8*i+j, 1);
		}
	 }
 }
static
void md5_core(uint32_t* a, void* block, uint8_t as, uint8_t s, uint8_t i, uint8_t fi){
	uint32_t t;
	md5_func_t* funcs[]={md5_F, md5_G, md5_H, md5_I};
	as &= 0x3;
	/* a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */
#ifdef DEBUG
	char funcc[]={'*', '-', '+', '~'};
	cli_putstr("\r\n DBG: md5_core [");
	cli_putc(funcc[fi]);
	cli_hexdump(&as, 1); cli_putc(' ');
	cli_hexdump(&k, 1); cli_putc(' ');
	cli_hexdump(&s, 1); cli_putc(' ');
	cli_hexdump(&i, 1); cli_putc(']');
#endif	
	t = a[as] + funcs[fi](a[(as+1)&3], a[(as+2)&3], a[(as+3)&3]) 
	    + *((uint32_t*)block) + pgm_read_dword(md5_T+i) ;
	a[as]=a[(as+1)&3] + ROTL32(t, s);
}
void cubehash256_test0(void){
	cubehash_ctx_t ctx;
	uint8_t hash[32];
	cubehash256_init(&ctx);
	cli_putstr_P(PSTR("\r\ninit done "));
	cubehash_lastBlock(&ctx, NULL, 0);
	cli_putstr_P(PSTR("\r\nlastblock done "));
	cubehash256_ctx2hash(hash, &ctx);
	cli_putstr_P(PSTR("\r\nhash = "));
	cli_hexdump(hash, 32);
}
示例#26
0
void md5_interactive(void){
	char msg[101];
	uint8_t hash[MD5_HASH_BYTES];
	uint8_t msg_len;
	cli_putstr_P(PSTR("\r\nmsg: "));
	cli_getsn(msg, 100);
	msg_len = strlen(msg);
	md5((void*)hash, msg, msg_len*8);
	cli_putstr_P(PSTR("\r\nmd5: "));
	cli_hexdump(hash, MD5_HASH_BYTES);
}
示例#27
0
void dsa_print_item(bigint_t *a, PGM_P pstr){
	uint8_t *p;
	cli_putstr_P(PSTR("\r\n"));
	cli_putstr_P(pstr);
	cli_putstr_P(PSTR(": "));
	uint16_t i;
	p = a->wordv + a->length_W -1;
	for(i=0; i<a->length_W-1; ++i){
		if(i%16==0){
			cli_putstr_P(PSTR("\r\n    "));
		}
		cli_hexdump(p, 1);
		cli_putc(':');
		--p;
	}
	if(i%16==0){
		cli_putstr_P(PSTR("\r\n    "));
	}
	cli_hexdump(p, 1);
}
示例#28
0
void dsa_print_item(bigint_t* a, const char* pstr){
	uint8_t *p;
	cli_putstr("\r\n");
	cli_putstr(pstr);
	cli_putstr(": ");
	uint16_t i;
	p = (uint8_t*)a->wordv + a->length_W*sizeof(bigint_word_t) -1;
	for(i=0; i<a->length_W*sizeof(bigint_word_t)-1; ++i){
		if(i%16==0){
			cli_putstr("\r\n    ");
		}
		cli_hexdump(p, 1);
		cli_putc(':');
		--p;
	}
	if(i%16==0){
		cli_putstr("\r\n    ");
	}
	cli_hexdump(p, 1);
}
示例#29
0
void testrun_cscipher(void){
	uint8_t data[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef };
	uint8_t key[] =  {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
					  0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 };
	cscipher_ctx_t ctx;
	cli_putstr("\r\n== CS-Cipher test==\r\nkey: ");
	cli_hexdump(key, 16);
	memset(&ctx, 0, 8*9);
	cscipher_init(key, &ctx);
	cli_putstr("\r\nround keys:\r\n");
	cli_hexdump_block(&ctx, 8*9, 4, 8);
	cli_putstr("\r\nplain:  ");
	cli_hexdump(data, 8);
	cscipher_enc(data, &ctx);
	cli_putstr("\r\ncipher: ");
	cli_hexdump(data, 8);
	cscipher_dec(data, &ctx);
	cli_putstr("\r\nplain:  ");
	cli_hexdump(data, 8);
}
示例#30
0
void echo256_test0(void){
	echo_small_ctx_t ctx;
	uint8_t hash[32];
	echo256_init(&ctx);
	cli_putstr("\r\ninit done ");
	echo_small_lastBlock(&ctx, NULL, 0);
	cli_putstr("\r\nlastblock done ");
	echo256_ctx2hash(hash, &ctx);
	cli_putstr("\r\nhash = ");
	cli_hexdump(hash, 32);
}