+void test_mul_mont_bigint(void){
+ bigint_t a, b, c, a_, b_, m_, res;
+ bigint_length_t s;
+ cli_putstr_P(PSTR("\r\nmul-mont test ( (a * b) % c )\r\n"));
+ for (;;) {
+ cli_putstr_P(PSTR("\r\nenter a:"));
+ if (bigint_read_hex_echo(&a)) {
+ cli_putstr_P(PSTR("\r\n end mul 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 mul 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 mul test"));
+ return;
+ }
+ s = c.length_W;
+ 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_word_t res_w[s], a_w_[s], b_w_[s], m_w_[s + 1];
+ res.wordv = res_w;
+ a_.wordv = a_w_;
+ b_.wordv = b_w_;
+ m_.wordv = m_w_;
+ bigint_mont_gen_m_(&m_, &c);
+ bigint_mont_trans(&a_, &a, &c);
+ bigint_mont_trans(&b_, &b, &c);
+ bigint_mont_mul(&res, &a_, &b_, &c, &m_);
+ bigint_mont_red(&res, &res, &c, &m_);
+ bigint_print_hex(&res);
+ putchar('\n');
+ free(a.wordv);
+ free(b.wordv);
+ free(c.wordv);
+ }
+}
+
+void test_mul_word_bigint(void){
+ bigint_t a, b;
+ bigint_word_t *t;
+ cli_putstr_P(PSTR("\r\nmul test\r\n"));
+ for (;;) {
+ cli_putstr_P(PSTR("\r\nenter a:"));
+ if (bigint_read_hex_echo(&a)) {
+ cli_putstr_P(PSTR("\r\n end mul 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 mul test"));
+ return;
+ }
+ cli_putstr_P(PSTR("\r\n "));
+ bigint_print_hex(&a);
+ cli_putstr_P(PSTR(" * "));
+ bigint_print_hex(&b);
+ cli_putstr_P(PSTR(" = "));
+
+ if (b.length_W > 1) {
+ free(a.wordv);
+ free(b.wordv);
+ cli_putstr_P(PSTR("\r\n end mul test"));
+ }
+
+ t = realloc(a.wordv, (a.length_W + 3) * sizeof(bigint_word_t));
+ if (t == NULL) {
+ cli_putstr_P(PSTR("\n\rERROR: Out of memory!"));
+ free(a.wordv);
+ free(b.wordv);
+ continue;
+ }
+ a.wordv = t;
+ bigint_mul_word_u(&a, b.wordv[0]);
+ bigint_print_hex(&a);
+ cli_putstr_P(PSTR("\r\n"));
+ free(a.wordv);
+ free(b.wordv);
+ }
+}
+