emp-toolkit/emp-tool

segfault in ECC test

Closed this issue · 1 comments

Hi, thanks for the great work.

After building successfully on OSX Catalina, I get a segfault in the ecc test:

benediamond@Benjamins-MBP emp-tool % ./bin/ecc   
zsh: segmentation fault  ./bin/ecc

after doing some digging, it looks like the bad line is the add_mod call:

ic = ia.add_mod(ib, G.order);

the reason is that ctx is default-assigned to nullptr here:
inline BigInt BigInt::add_mod(const BigInt & b, const BigInt &m, BN_CTX *ctx) {
BigInt ret;
BN_mod_add(ret.n, n, b.n, m.n, ctx);
return ret;
}

it can be fixed by replacing line 22 with:

    ic = ia.add_mod(ib, G.order, G.bn_ctx);

let me know if you'd like me to raise a PR. thanks.

Thank you for pointing the bug. The code has been updated to address this. Also removed the default parameters to enforce a bn_ctx has to be provided.