-
Notifications
You must be signed in to change notification settings - Fork 89
Open
Description
Sorry for not submitting a pull request, I'm working on a bignum library and I saw your implementation of multiplication so I just want to point out that you can simplify it by doing the multiply and the add in one loop into the result bn as follow:
typedef unsigned int u32;
typedef unsigned long long int u64;
void _bn_add_mul_u32(u32 *out, u32 *a, size_t a_len, u32 b)
{
u64 c = 0;
size_t i;
for(i=0; i<a_len; i++)
{
u64 a_w = a[i];
u64 out_w = out[i];
u64 o = out_w + a_w * b + c;
c = o >> 32;
out[i] = o & 0xffffffff;
}
for(; c; i++)
{
u64 o = out[i] + c;
c = o >> 32;
out[i] = o & 0xffffffff;
}
}
void _bn_mul(u32 *out, u32 *a, size_t a_len, u32 *b, size_t b_len)
{
for(size_t i=0; i<b_len; i++)
{
u32 b_w = b[i];
_bn_add_mul_u32(out+i, a, a_len, b_w);
}
}