Jūs esate

Montgomery's Multiplication

Based on "Handbook of Applied Cryptography". Montgomery's multiplication in C programming language. void mpa_mod_mon_mult(bignum_t *res, bignum_t *m, bignum_t *x, bignum_t *y, const digit_t map) { int i = 0; digit_t ui; bignum_t *uim = mpa_create_bignum(); xrealloc_bignum(uim, ALL_DIGITS(m) + 1); bignum_t *xiy = mpa_create_bignum(); xrealloc_bignum(uim, ALL_DIGITS(m) + 1); if (m->all_digits > x->all_digits) xrealloc_bignum(x, ALL_DIGITS(m)); zero_number(res); xrealloc_bignum(res, ALL_DIGITS(m) + 1); for (i = 0; i < m->all_digits; i++) { ui = (res->digits[0] + x->digits[i] * y->digits[0]) * map; /* 2.1 */ hpa_mul(uim, m, ui); /* 2.2 */ hpa_mul(xiy, y, x->digits[i]); mpa_add2(res, uim); mpa_add2(res, xiy); rshift(res, 1); printf("\n"); } if (greaterorequal(res, m)) mpa_sub2(res, m); mpa_free_bignum(xiy); mpa_free_bignum(uim); }

Komentuoti