-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect value returned from cx_bn_cnt_bits
#487
Comments
cx_bn_cnt_bits
cx_bn_cnt_bits
Apologies, This is an accidental duplicate issue. However. following on from my comment above, if the uint32_t cx_mpi_cnt_bits(const cx_mpi_t *x)
{
uint32_t nbits = BN_num_bits(x);
return nbits;
} but if, as the documentation suggests, it is supposed to return the number of bits set to 1 would this work instead? uint32_t cx_mpi_cnt_bits(const cx_mpi_t *x)
{
uint32_t nbits = BN_num_bits(x);
uint32_t count = 0;
for (int i = 0; i < nbits; ++i) {
count += BN_is_bit_set(x, i);
}
return count;
} |
Yes |
The following function seems to return the bit position of the most significant bit in a big number:
speculos/src/bolos/cx_mpi.c
Lines 599 to 637 in 56ed996
Whereas the documentation suggests that it should instead return the number of bits set to 1 in a big number:
https://github.com/LedgerHQ/ledger-secure-sdk/blob/b82be6fd5a082132ee08bf0d105d1bb7bb4d0b41/include/ox_bn.h#L490-L502
Is the function incorrect or the documentation?
The text was updated successfully, but these errors were encountered: