+/* d = a**b % c */
+void test_expmod_bigint(void){
+ bigint_t a, b, c, d;
+ bigint_word_t *d_b;
+ cli_putstr_P(PSTR("\r\nexpnonentiation-modulo 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_W * sizeof(bigint_word_t));
+ 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_sam(&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);
+
+ }
+}
+
+/* d = a**b % c */
+void test_expmod_mont_bigint(void){
+ bigint_t a, b, c, d;
+ bigint_word_t *d_b;
+ cli_putstr_P(PSTR("\r\nexpnonentiation-modulo-montgomory 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_W * sizeof(bigint_word_t));
+ 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_mont_sam(&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(MIN(a.length_W, b.length_W) * sizeof(bigint_word_t));
+ d.wordv = malloc((MAX(a.length_W, b.length_W) + 1) * sizeof(bigint_word_t));
+ e.wordv = malloc((MAX(a.length_W, b.length_W) + 1) * sizeof(bigint_word_t));
+
+ 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);
+ }
+}