mirror of
https://github.com/cryb-to/cryb-to.git
synced 2024-12-23 13:01:08 +00:00
a09cdc6318
The count we passed to memcmp() in mpi_eq() and mpi_eq_abs() was actually the number of significant words in the MPI, rather than the number of bytes we wanted to compare. Multiply by 4 to get the correct value. To make the intent of the code more apparent, introduce a private MPI_MSW() macro which evaluates to the number of significant words (or 1-based index of the most significant word). This also comes in handy in mpi_{add,sub,mul}_abs(). Add a couple of test cases which not only demonstrate the bug we fixed here but also demonstrate why we must compare whole words: on a big-endian machine, we would be comparing the unused upper bytes of the first and only word instead of the lower bytes which actually hold a value... |
||
---|---|---|
.. | ||
cryb-mpi.pc.in | ||
cryb_mpi.c | ||
cryb_mpi_add.c | ||
cryb_mpi_add_abs.c | ||
cryb_mpi_cmp.c | ||
cryb_mpi_cmp_abs.c | ||
cryb_mpi_cmp_i32.c | ||
cryb_mpi_cmp_i64.c | ||
cryb_mpi_copy.c | ||
cryb_mpi_dec.c | ||
cryb_mpi_dec_abs.c | ||
cryb_mpi_destroy.c | ||
cryb_mpi_div.c | ||
cryb_mpi_div_abs.c | ||
cryb_mpi_eq.c | ||
cryb_mpi_eq_abs.c | ||
cryb_mpi_eq_i32.c | ||
cryb_mpi_eq_i64.c | ||
cryb_mpi_gcd_abs.c | ||
cryb_mpi_grow.c | ||
cryb_mpi_impl.h | ||
cryb_mpi_inc.c | ||
cryb_mpi_inc_abs.c | ||
cryb_mpi_init.c | ||
cryb_mpi_load.c | ||
cryb_mpi_lsb.c | ||
cryb_mpi_lshift.c | ||
cryb_mpi_msb.c | ||
cryb_mpi_mul.c | ||
cryb_mpi_mul_abs.c | ||
cryb_mpi_negate.c | ||
cryb_mpi_rshift.c | ||
cryb_mpi_set.c | ||
cryb_mpi_sub.c | ||
cryb_mpi_sub_abs.c | ||
cryb_mpi_swap.c | ||
cryb_mpi_zero.c | ||
Makefile.am | ||
README |
Portable multiple-precision integer library. The interface is loosely based on XySSL's MPI library. The implementation was written from scratch based on the algorithms described in Menezes, van Oorschot and Vanstone: _Handbook of Applied Cryptography_, CRC Press, 1996. The full text of the HAC is available for personal use at http://www.cacr.math.uwaterloo.ca/hac/. This implementation sacrifices performance for portability and readability, but attempts have been made to structure it in such a way that critical portions can easily be replaced with machine-dependent optimized versions. The code assumes a 64-bit machine or a 32-bit machine where 64-bit integer arithmetic is supported but not necessarily efficient; 64-bit operations are used only to simplify overflow handling.