Ejemplo n.º 1
0
void testrun_performance_des(void){
	uint64_t t;
	char str[16];
	uint8_t key[8], data[8];
	
	
	calibrateTimer();
	print_overhead();
	
	memset(key,  0, 8);
	memset(data, 0, 8);
	
	startTimer(1);
	des_enc(data, data, key);
	t = stopTimer();
	uart_putstr_P(PSTR("\r\n\tencrypt time: "));
	ultoa((unsigned long)t, str, 10);
	uart_putstr(str);
	
	startTimer(1);
	des_dec(data, data, key);
	t = stopTimer();
	uart_putstr_P(PSTR("\r\n\tdecrypt time: "));
	ultoa((unsigned long)t, str, 10);
	uart_putstr(str);
	uart_putstr_P(PSTR("\r\n"));
}
Ejemplo n.º 2
0
int main()
{
	unsigned char key[8]   = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};
	unsigned char block[8] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xe7};
	unsigned char tmp_block[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
	unsigned char zero_block[8] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

	uint64_t k_arr[16]={
		0, 0, 0, 0, 0, 0, 0, 0,
		0, 0, 0, 0, 0, 0, 0, 0};
	des_ctx ctx={
		{	0, 0, 0, 0, 0, 0, 0, 0, 	0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 	0, 0, 0, 0, 0, 0, 0, 0},
		{	0, 0, 0, 0, 0, 0, 0, 0, 	0, 0, 0, 0, 0, 0, 0, 0,
			0, 0, 0, 0, 0, 0, 0, 0, 	0, 0, 0, 0, 0, 0, 0, 0}
	};
	uint64_t tmp;
	int i;
	
	des_key(&ctx, key);
	des_gen_ks(des_byte2key(key), k_arr);
	
//	print_block("k[0] my", k_arr);
//	print_block("k[0] work", ctx.ek);
/*	tmp = des_f(0,k_arr[0]);
	print_block32("des_f(0,k[1])", &tmp);
	tmp = des_ssl_f(0,ctx.ek);
	print_block32("ssl_f(0,k[1])", &tmp);
	
	tmp = des_work_f(0,ctx.ek);
	print_block32("work_f(0,k[1])", &tmp);
*/	
	des_enc(&ctx, block, 1);
	print_block("Encrypted", block);
	des_dec(&ctx, block, 1);
	print_block("Decrypted", block);

	puts("===============================================");
	print_block("Plain", block);

	//*(uint64_t*)block = des_byte2key(block);
	des_block_crypt((uint64_t*)block, k_arr, DES_ENCRYPT_ACT);
	print_block("Encrypted", block);

	reverse_bit_buff(tmp_block, block, 8);
	print_block("Mirrored", tmp_block);

	for(i=0; i<8; i++) tmp_block[i]=reverse_bit_byte(block[i]);
	print_block("ByBitMirrored", tmp_block);

	des_block_crypt((uint64_t*)block, k_arr, DES_DECRYPT_ACT);
	print_block("Decrypted", block);

	return 0;
}
Ejemplo n.º 3
0
int
brute_force (des_key_manager km, uint64_t pt, uint64_t ct)
{
  uint64_t dummy, key, ks[16];

  des_km_init_for_unknown (km);  /* Initialize the iterator over unknown bits */
  do        /* Iterate over the possible keys */
    {
      key = des_km_get_key (km, &dummy);  /* Get current key, ignore the mask */
      des_ks (ks, key);    /* Compute key schedule with current key */
      if (des_enc (ks, pt) == ct)  /* If we are lucky... cheers. */
        {
          printf ("%016" PRIx64 "\n", key);
          return 1;    /* Stop iterating and return success indicator. */
        }
    }
  while (des_km_for_unknown (km));  /* Continue until we tried them all */
  return 0;      /* Return failure indicator. */
}
Ejemplo n.º 4
0
static
void des_dummy_enc(void *block, void *key)
{
    des_enc(block, block, key);
}
Ejemplo n.º 5
0
void des_enc_dummy(void* buffer, void* ctx){
	des_enc(buffer, buffer, ctx);
}