/** * Multiplies two binary field elements using right-to-left comb multiplication. * * @param c - the result. * @param a - the first binary field element. * @param b - the second binary field element. * @param size - the number of digits to multiply. */ static void fb_mul_rcomb_imp(dig_t *c, const dig_t *a, const dig_t *b, int size) { dv_t _b; dv_null(_b); TRY { dv_new(_b); dv_zero(c, 2 * size); for (int i = 0; i < size; i++) _b[i] = b[i]; _b[size] = 0; for (int i = 0; i < FB_DIGIT; i++) { for (int j = 0; j < size; j++) { if (a[j] & ((dig_t)1 << i)) { fb_addd_low(c + j, c + j, _b, size + 1); } } if (i != FB_DIGIT - 1) { bn_lsh1_low(_b, _b, size + 1); } } } CATCH_ANY { THROW(ERR_CAUGHT); } FINALLY { dv_free(_b); } }
/** * Multiplies two binary field elements using left-to-right comb multiplication. * * @param c - the result. * @param a - the first binary field element. * @param b - the second binary field element. * @param size - the number of digits to multiply. */ static void fb_mul_lcomb_imp(dig_t *c, const dig_t *a, const dig_t *b, int size) { dv_zero(c, 2 * size); for (int i = FB_DIGIT - 1; i >= 0; i--) { for (int j = 0; j < size; j++) { if (a[j] & ((dig_t)1 << i)) { fb_addd_low(c + j, c + j, b, size); } } if (i != 0) { bn_lsh1_low(c, c, 2 * size); } } }
void bn_dbl(bn_t c, bn_t a) { dig_t carry; bn_grow(c, a->used + 1); c->used = a->used; carry = bn_lsh1_low(c->dp, a->dp, c->used); /* If there is an additional carry. */ if (carry != 0) { c->dp[c->used] = carry; (c->used)++; } c->sign = a->sign; }