+/* d = a**b % c */
+void test_expmod_bigint(void){
+ bigint_t a, b, c, d;
+ uint8_t *d_b;
+ cli_putstr_P(PSTR("\r\nreduce test\r\n"));
+ for(;;){
+ cli_putstr_P(PSTR("\r\nenter a:"));
+ if(bigint_read_hex_echo(&a)){
+ cli_putstr_P(PSTR("\r\n end expmod test"));
+ return;
+ }
+ cli_putstr_P(PSTR("\r\nenter b:"));
+ if(bigint_read_hex_echo(&b)){
+ free(a.wordv);
+ cli_putstr_P(PSTR("\r\n end expmod test"));
+ return;
+ }
+ cli_putstr_P(PSTR("\r\nenter c:"));
+ if(bigint_read_hex_echo(&c)){
+ free(a.wordv);
+ free(b.wordv);
+ cli_putstr_P(PSTR("\r\n end expmod test"));
+ return;
+ }
+ d_b = malloc(c.length_B);
+ if(d_b==NULL){
+ cli_putstr_P(PSTR("\n\rERROR: Out of memory!"));
+ free(a.wordv);
+ free(b.wordv);
+ free(c.wordv);
+ continue;
+ }
+ d.wordv = d_b;
+ cli_putstr_P(PSTR("\r\n "));
+ bigint_print_hex(&a);
+ cli_putstr_P(PSTR("**"));
+ bigint_print_hex(&b);
+ cli_putstr_P(PSTR(" % "));
+ bigint_print_hex(&c);
+ cli_putstr_P(PSTR(" = "));
+ bigint_expmod_u(&d, &a, &b, &c);
+ bigint_print_hex(&d);
+ cli_putstr_P(PSTR("\r\n"));
+ free(a.wordv);
+ free(b.wordv);
+ free(c.wordv);
+ free(d.wordv);
+
+ }
+}
+
+void test_gcdext_bigint(void){
+ bigint_t a, b, c, d, e;
+ cli_putstr_P(PSTR("\r\ngcdext test\r\n"));
+ for(;;){
+ cli_putstr_P(PSTR("\r\nenter a:"));
+ if(bigint_read_hex_echo(&a)){
+ cli_putstr_P(PSTR("\r\n end gcdext test"));
+ return;
+ }
+ cli_putstr_P(PSTR("\r\nenter b:"));
+ if(bigint_read_hex_echo(&b)){
+ free(a.wordv);
+ cli_putstr_P(PSTR("\r\n end gcdext test"));
+ return;
+ }
+ c.wordv = malloc((a.length_B<b.length_B)?a.length_B:b.length_B);
+ d.wordv = malloc(1+(a.length_B>b.length_B)?a.length_B:b.length_B);
+ e.wordv = malloc(1+(a.length_B>b.length_B)?a.length_B:b.length_B);
+
+ cli_putstr_P(PSTR("\r\n gcdext( "));
+ bigint_print_hex(&a);
+ cli_putstr_P(PSTR(", "));
+ bigint_print_hex(&b);
+ cli_putstr_P(PSTR(") => "));
+ bigint_gcdext(&c, &d, &e, &a, &b);
+ cli_putstr_P(PSTR("a = "));
+ bigint_print_hex(&d);
+ cli_putstr_P(PSTR("; b = "));
+ bigint_print_hex(&e);
+ cli_putstr_P(PSTR("; gcd = "));
+ bigint_print_hex(&c);
+
+ cli_putstr_P(PSTR("\r\n"));
+ free(a.wordv);
+ free(b.wordv);
+ free(c.wordv);
+ free(d.wordv);
+ free(e.wordv);
+ }
+}