Example #1
0
void test_square_bigint(void){
	bigint_t a, c;
	cli_putstr_P(PSTR("\r\nsquare test\r\n"));
	for(;;){
		cli_putstr_P(PSTR("\r\nenter a:"));
		if(bigint_read_hex_echo(&a)){
			cli_putstr_P(PSTR("\r\n end square test"));
			return;
		}
		cli_putstr_P(PSTR("\r\n "));
		bigint_print_hex(&a);
		cli_putstr_P(PSTR("**2 = "));
		uint8_t *c_b;
		c_b = malloc(a.length_B*2);
		if(c_b==NULL){
			cli_putstr_P(PSTR("\n\rERROR: Out of memory!"));
			free(a.wordv);
			continue;
		}
		c.wordv = c_b;
		bigint_square(&c, &a);
		bigint_print_hex(&c);
		cli_putstr_P(PSTR("\r\n"));
		free(a.wordv);
		free(c_b);
	}
}
Example #2
0
void testrun_square(void){
    bigint_word_t a_w[] = {
        0x82, 0x6f, 0x79, 0x39, 0x47, 0x06, 0x26, 0x9f,
        0x4b, 0xe2, 0x15, 0x61, 0x6f, 0xa1, 0xd4, 0x0c,
        0x1f, 0x24, 0x3a, 0xd4, 0xc2, 0x6d, 0xe8, 0xb6
    };

    bigint_word_t b_w[2 * 192 / BIGINT_WORD_SIZE];
    bigint_t a, b;

    a.wordv = a_w;
    a.length_W = sizeof(a_w);
    a.info = 7;

    b.wordv = b_w;
    b.info = 0;
    b.length_W = 0;

    printf_P(PSTR("\n a = "));
    bigint_print_hex(&a);
    bigint_square(&b, &a);
    printf_P(PSTR("\n a^2 = "));
    bigint_print_hex(&b);
    bigint_reduce_p192(&b);
    printf_P(PSTR("\n a^2 %% p = "));
    bigint_print_hex(&b);
    putchar('\n');


}
Example #3
0
void test_square_simple(void){
	bigint_t a, c;

	uint8_t a_b[11] = {0xe6, 0x70, 0x7d, 0x43, 0x74, 0x07, 0x20, 0x22, 0x6a, 0xb8, 0xf4};
	uint8_t c_b[22];
	a.wordv=a_b;
	c.wordv=c_b;
	a.length_B = 11;
	a.info=0x00;
	bigint_adjust(&a);
	bigint_square(&c, &a);
	cli_putstr_P(PSTR("\r\n test: "));
	bigint_print_hex(&a);
	cli_putstr_P(PSTR("**2 = "));
	bigint_print_hex(&c);
}