void testrun_performance_rabbit(void){
	uint64_t t;
	char str[16];
	uint8_t key[16];
	rabbit_ctx_t ctx;

	calibrateTimer();
	print_overhead();

	memset(key,  0, 16);

	startTimer(1);
	rabbit_init(key, 128, NULL, &ctx);
	t = stopTimer();
	cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
	ultoa((unsigned long)t, str, 10);
	cli_putstr(str);

	startTimer(1);
	rabbit_gen(&ctx);
	t = stopTimer();
	cli_putstr_P(PSTR("\r\n\tencrypt time: "));
	ultoa((unsigned long)t, str, 10);
	cli_putstr(str);

	cli_putstr_P(PSTR("\r\n"));
}
void testrun_performance_grain(void) {
    uint64_t t;
    char str[16];
    uint8_t key[10], iv[8];
    grain_ctx_t ctx;

    calibrateTimer();
    print_overhead();

    memset(key,  0, 10);
    memset(iv,  0, 8);

    startTimer(1);
    grain_init(key, iv, &ctx);
    t = stopTimer();
    cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
    ultoa((unsigned long)t, str, 10);
    cli_putstr(str);

    startTimer(1);
    grain_enc(&ctx);
    t = stopTimer();
    cli_putstr_P(PSTR("\r\n\tencrypt time: "));
    ultoa((unsigned long)t, str, 10);
    cli_putstr(str);

    cli_putstr_P(PSTR("\r\n"));
}
void testrun_performance_entropium(void){
	uint64_t t;
	char str[16];
	uint8_t data[32];
	
	calibrateTimer();
	print_overhead();
	
	startTimer(1);
	entropium_addEntropy(128, data);
	t = stopTimer();
	cli_putstr_P(PSTR("\r\n\tadd entropy time: "));
	ultoa((unsigned long)t, str, 10);
	cli_putstr(str);
	
	
	startTimer(1);
	entropium_getRandomBlock(data);
	t = stopTimer();
	cli_putstr_P(PSTR("\r\n\tget random time:  "));
	ultoa((unsigned long)t, str, 10);
	cli_putstr(str);
	
	cli_putstr_P(PSTR("\r\n"));
}
Beispiel #4
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"));
}
void testrun_performance_noekeon(void){
	uint64_t t;
	char str[16];
	uint8_t key[16], data[16];
	noekeon_ctx_t ctx;
	
	calibrateTimer();
	print_overhead();
	
	memset(key,  0, 16);
	memset(data, 0, 16);
	
	startTimer(1);
	noekeon_init(key, &ctx);
	t = stopTimer();
	uart_putstr_P(PSTR("\r\n\tctx-gen time: "));
	ultoa((unsigned long)t, str, 10);
	uart_putstr(str);	
	
	startTimer(1);
	noekeon_enc(data, &ctx);
	t = stopTimer();
	uart_putstr_P(PSTR("\r\n\tencrypt time: "));
	ultoa((unsigned long)t, str, 10);
	uart_putstr(str);	
	
	startTimer(1);
	noekeon_dec(data, &ctx);
	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"));
}
void testrun_performance_shabea(void){
	uint64_t t;
	char str[16];
	uint8_t key[32], data[32];
	
	calibrateTimer();
	print_overhead();
	
	memset(key,  0, 32);
	memset(data, 0, 32);
	
	startTimer(1);
	shabea256(data, key, 256, 1, 16);
	t = stopTimer();
	cli_putstr_P(PSTR("\r\n\tencrypt time: "));
	ultoa((unsigned long)t, str, 10);
	cli_putstr(str);
	
	
	startTimer(1);
	shabea256(data, key, 256, 0, 16);
	t = stopTimer();
	cli_putstr_P(PSTR("\r\n\tdecrypt time: "));
	ultoa((unsigned long)t, str, 10);
	cli_putstr(str);
	
	cli_putstr_P(PSTR("\r\n"));
}
int main (void){
    int8_t r;
    main_setup();
    calibrateTimer();
    for(;;){
        welcome_msg(algo_name);
        r = cmd_interface(cmdlist);
        printf("r = %"PRId8"\n", r);
        cli_putstr_P(PSTR("\r\nHello!\r\n"));
	}
}
void testrun_performance_shacal2enc(void){
	uint64_t t;
	uint8_t key[SHACAL2_KEYSIZE_B], data[SHACAL2_BLOCKSIZE_B];
	
	calibrateTimer();
	print_overhead();
	
	memset(key,  0, SHACAL2_KEYSIZE_B);
	memset(data, 0, SHACAL2_BLOCKSIZE_B);
	
	
	startTimer(1);
	shacal2_enc(data, key, SHACAL2_KEYSIZE);
	t = stopTimer();
	print_time_P(PSTR("\tencrypt time: "), t);
	
	cli_putstr_P(PSTR("\r\n"));
}
void testrun_performance_twister512(void){
	uint64_t t;
	char str[16];
	uint8_t data[64];
	twister_big_ctx_t ctx;
	
	calibrateTimer();
	print_overhead();
	
	memset(data, 0, 64);
	
	startTimer(1);
	twister_big_init(&ctx, 512);
	t = stopTimer();
	uart_putstr_P(PSTR("\r\n\tctx-gen time: "));
	ultoa((unsigned long)t, str, 10);
	uart_putstr(str);
	
	
	startTimer(1);
	twister_big_nextBlock(&ctx, data);
	t = stopTimer();
	uart_putstr_P(PSTR("\r\n\tone-block time: "));
	ultoa((unsigned long)t, str, 10);
	uart_putstr(str);
	
	
	startTimer(1);
	twister_big_lastBlock(&ctx, data, 0);
	t = stopTimer();
	uart_putstr_P(PSTR("\r\n\tlast block time: "));
	ultoa((unsigned long)t, str, 10);
	uart_putstr(str);
	
	startTimer(1);
	twister_big_ctx2hash(data, &ctx, 512);
	t = stopTimer();
	uart_putstr_P(PSTR("\r\n\tctx2hash time: "));
	ultoa((unsigned long)t, str, 10);
	uart_putstr(str);

	uart_putstr_P(PSTR("\r\n"));
}
Beispiel #10
0
void testrun_performance_sha256(void){
	uint64_t t;
	char str[16];
	uint8_t data[32];
	sha256_ctx_t ctx;
	
	calibrateTimer();
	print_overhead();
	
	memset(data, 0, 32);
	
	startTimer(1);
	sha256_init(&ctx);
	t = stopTimer();
	uart_putstr_P(PSTR("\r\n\tctx-gen time: "));
	ultoa((unsigned long)t, str, 10);
	uart_putstr(str);
	
	
	startTimer(1);
	sha256_nextBlock(&ctx, data);
	t = stopTimer();
	uart_putstr_P(PSTR("\r\n\tone-block time: "));
	ultoa((unsigned long)t, str, 10);
	uart_putstr(str);
	
	
	startTimer(1);
	sha256_lastBlock(&ctx, data, 0);
	t = stopTimer();
	uart_putstr_P(PSTR("\r\n\tlast block time: "));
	ultoa((unsigned long)t, str, 10);
	uart_putstr(str);
	
	uart_putstr_P(PSTR("\r\n"));
}
void testrun_performance_reduce_bigint(void){
    printf_P(PSTR("\n=== performance measurement (reduce) ===\n"));
    unsigned i, j;
    bigint_t a,b,v;
    bigint_word_t v_w[192 * 2 / BIGINT_WORD_SIZE];
    bigint_word_t a_w[192 * 2 / BIGINT_WORD_SIZE];
    bigint_word_t b_w[192 * 2 / BIGINT_WORD_SIZE];
    uint32_t time_a, time_b;
    int32_t time_diff;
    int16_t faster_percent;
    v.wordv = v_w;
    for(j = 0; j < 32; ++j){
        do{
            for(i = 0; i < 192 * 2 / BIGINT_WORD_SIZE; ++i){
                ((uint8_t*)v_w)[i] = random();
            }
            v.length_W = 192 * 2 / BIGINT_WORD_SIZE;
            v.info = 0;
            bigint_adjust(&v);
        }while(0);

    //    printf_P(PSTR("candidate:\n"));
    //    bigint_print_hex(&v);
        a.wordv = a_w;
        b.wordv = b_w;
        calibrateTimer();

    //    printf_P(PSTR("\n  going to test optimized version: ...\n"));
        uart0_flush();
        time_a = 0;
        for(i = 0; i < 16; ++i){
            bigint_copy(&a, &v);
            startTimer(1);
            START_TIMER;
            bigint_reduce_p192(&a);
            STOP_TIMER;
            time_a += stopTimer();
        }
    //    printf_P(PSTR("    took: %"PRIu32" cycles\nresult:"), time);
    //    bigint_print_hex(&a);


    //    printf_P(PSTR("\n  going to test not-optimized version: ...\n"));
    //    uart0_flush();
        time_b = 0;
        for(i = 0; i < 16; ++i){
            bigint_copy(&b, &v);
            startTimer(1);
            START_TIMER;
            bigint_reduce(&b, &nist_curve_p192_p);
            STOP_TIMER;
            time_b += stopTimer();
        }
    //    printf_P(PSTR("    took: %"PRIu32" cycles\nresult:"), time);
    //    bigint_print_hex(&b);

        time_diff = time_b - time_a;
        faster_percent = (time_diff * 100) / time_b;

        printf_P(PSTR("  delta: %7"PRId32"  (%3"PRId16"%%)  :-"), time_diff, faster_percent);
        if(bigint_cmp_u(&a, &b)){
            printf_P(PSTR("(\n"));
        } else {
            printf_P(PSTR(")\n"));
        }
        uart0_flush();
    }
}
Beispiel #12
0
void bcal_performance(const bcdesc_t* bcd){
	bcdesc_t bc;
	memcpy_P(&bc, bcd, sizeof(bcdesc_t));
	uint8_t ctx[bc.ctxsize_B];
	uint8_t data[(bc.blocksize_b+7)/8];
	uint16_t keysize = get_keysize(bc.valid_keysize_desc);
	uint8_t key[(keysize+7)/8];
	uint64_t t;
	uint8_t i;

	if(bc.type!=BCDESC_TYPE_BLOCKCIPHER)
		return;
	calibrateTimer();
	print_overhead();
	cli_putstr_P(PSTR("\r\n\r\n === "));
	cli_putstr_P(bc.name);
	cli_putstr_P(PSTR(" performance === "
	                  "\r\n    type:             blockcipher"
	                  "\r\n    keysize (bits):     "));
	printvalue(keysize);

	cli_putstr_P(PSTR("\r\n    ctxsize (bytes):    "));
	printvalue(bc.ctxsize_B);

	cli_putstr_P(PSTR("\r\n    blocksize (bits):   "));
	printvalue(bc.blocksize_b);



	t=0;
	if(bc.init.init1){
		if((bc.flags&BC_INIT_TYPE)==BC_INIT_TYPE_1){
			for(i=0; i<32; ++i){
				startTimer(0);
				START_TIMER;
				(bc.init.init1)(key, &ctx);
				STOP_TIMER;
				t += stopTimer();
				if(i!=31 && bc.free){
					bc.free(&ctx);
				}
			}
		} else {
			for(i=0; i<32; ++i){
				startTimer(0);
				START_TIMER;
				(bc.init.init2)(key, keysize, &ctx);
				STOP_TIMER;
				t += stopTimer();
				if(i!=31 && bc.free){
					bc.free(&ctx);
				}
			}
		}
		t>>=5;
		cli_putstr_P(PSTR("\r\n    init (cycles):      "));
		printvalue(t);
	}
	t=0;
	for(i=0; i<32; ++i){
		startTimer(0);
		START_TIMER;
		bc.enc.enc1(data, &ctx);
		STOP_TIMER;
		t += stopTimer();
	}
	t>>=5;
	cli_putstr_P(PSTR("\r\n    encrypt (cycles):   "));
	printvalue(t);

	t=0;
	for(i=0; i<32; ++i){
		startTimer(0);
		START_TIMER;
		bc.dec.dec1(data, &ctx);
		STOP_TIMER;
		t += stopTimer();
	}
	t>>=5;
	cli_putstr_P(PSTR("\r\n    decrypt (cycles):   "));
	printvalue(t);

	if(bc.free){
		bc.free(&ctx);
	}
}