No description
Find a file
Steffen Jaeckel ae40a87a92
Merge pull request #597 from czurnieden/subin_check
Check size of argument
2026-04-20 15:01:53 +02:00
.github/workflows Run deploy job also for ARM. 2026-04-07 12:32:51 +02:00
demo Use Thread Local Storage for warray buffer 2024-03-29 10:57:20 +01:00
doc Replace locking by atomic operations 2024-03-27 16:25:27 +01:00
etc Use cryptographic RNG 2024-03-11 11:32:38 +01:00
logs slightly edit, update and run typos.sh 2022-10-03 12:13:21 +02:00
modulemap Add Swift Package Manager support 2021-11-25 13:37:24 +08:00
mtest slightly edit, update and run typos.sh 2022-10-03 12:13:21 +02:00
.gitattributes Update content of tarball 2023-06-22 16:52:18 +02:00
.gitignore git: ignore cmake build directories 2024-03-14 09:40:01 +01:00
appveyor.yml Disable MP_SMALL_STACK_SIZE on MSVC 2024-04-03 16:23:42 +02:00
astylerc slightly edit, update and run typos.sh 2022-10-03 12:13:21 +02:00
changes.txt v1.3.0 2024-03-27 14:41:25 +01:00
CMakeLists.txt Run deploy job also for ARM. 2026-04-07 12:32:51 +02:00
helper.pl Generate import library in CMake 2025-03-15 20:27:55 +08:00
libtommath.pc.in Align header install path 2024-03-27 11:26:23 +01:00
libtommath_VS2008.sln make libtommath_VS2008 better upgradable to the newer visual studio 2018-12-08 11:56:08 +01:00
libtommath_VS2008.vcproj regen 2025-01-30 14:59:53 +01:00
LICENSE Re-license 2018-12-27 15:41:16 +01:00
makefile regen 2025-01-30 14:59:53 +01:00
makefile.mingw regen 2025-01-30 14:59:53 +01:00
makefile.msvc regen 2025-01-30 14:59:53 +01:00
makefile.shared regen 2025-01-30 14:59:53 +01:00
makefile.unix regen 2025-01-30 14:59:53 +01:00
makefile_include.mk Add multi-threaded tests 2024-03-27 16:25:27 +01:00
mp_2expt.c Fix possible integer overflow 2023-09-05 07:14:54 +02:00
mp_abs.c simplifications: remove unnecessary optimization 2019-11-04 15:41:33 +01:00
mp_add.c first batch of simplifications 2019-10-29 19:30:23 +01:00
mp_add_d.c better use of mp_isneg() and mp_iszero() 2019-11-11 21:52:20 +01:00
mp_addmod.c simplify mod functions 2019-11-07 01:01:19 +01:00
mp_and.c better use of mp_isneg() and mp_iszero() 2019-11-11 21:52:20 +01:00
mp_clamp.c slightly edit, update and run typos.sh 2022-10-03 12:13:21 +02:00
mp_clear.c simplifications: add s_mp_zero_(digs|buf) and s_mp_copy_digs 2019-11-04 15:41:32 +01:00
mp_clear_multi.c first batch of simplifications 2019-10-29 19:30:23 +01:00
mp_cmp.c better use of mp_isneg() and mp_iszero() 2019-11-11 21:52:20 +01:00
mp_cmp_d.c better use of mp_isneg() and mp_iszero() 2019-11-11 21:52:20 +01:00
mp_cmp_mag.c slightly edit, update and run typos.sh 2022-10-03 12:13:21 +02:00
mp_cnt_lsb.c first batch of simplifications 2019-10-29 19:30:23 +01:00
mp_complement.c simplify mp_complement 2019-11-04 15:41:33 +01:00
mp_copy.c simplifications: remove unnecessary optimization 2019-11-04 15:41:33 +01:00
mp_count_bits.c remove MP_IS_* macros 2019-10-27 18:36:55 +01:00
mp_cutoffs.c rename mul/sqr functions for consistency, comba instead of fast suffix 2019-11-04 15:41:33 +01:00
mp_div.c corrected startvalue for sigma and cutoff in mp_div 2019-11-24 05:44:29 +01:00
mp_div_2.c simplifications: remove unnecessary optimization 2019-11-04 15:41:33 +01:00
mp_div_2d.c simplifications: basic arithmetic functions 2019-11-04 15:41:31 +01:00
mp_div_d.c add macro MP_IS_2EXPT 2019-11-09 06:43:59 +01:00
mp_dr_is_modulus.c replace mp_bool by stdbool 2019-10-27 18:36:56 +01:00
mp_dr_reduce.c simplifications: remove unnecessary optimization 2019-11-04 15:41:33 +01:00
mp_dr_setup.c Execute move.sh - Rename files from bn_* to match the function names. 2019-10-19 16:24:39 +02:00
mp_error_to_string.c add error code MP_OVF for integer overflow (too many digits) 2019-12-23 11:12:42 +01:00
mp_exch.c first batch of simplifications 2019-10-29 19:30:23 +01:00
mp_expt_n.c suffix _u32 -> _n of mp_(expt|log|root) functions, use int for now 2019-11-14 09:16:00 +01:00
mp_exptmod.c slightly edit, update and run typos.sh 2022-10-03 12:13:21 +02:00
mp_exteuclid.c better use of mp_isneg() and mp_iszero() 2019-11-11 21:52:20 +01:00
mp_fread.c better use of mp_isneg() and mp_iszero() 2019-11-11 21:52:20 +01:00
mp_from_sbin.c Input check added 2026-04-20 14:43:31 +02:00
mp_from_ubin.c simplifications: remove unnecessary optimization 2019-11-04 15:41:33 +01:00
mp_fwrite.c Removed trailing zero from mp_fwrite output 2023-03-21 01:26:21 +01:00
mp_gcd.c Fix wrongly ordered cleanup. 2025-02-24 13:28:51 +01:00
mp_get_double.c better use of mp_isneg() and mp_iszero() 2019-11-11 21:52:20 +01:00
mp_get_i32.c Execute move.sh - Rename files from bn_* to match the function names. 2019-10-19 16:24:39 +02:00
mp_get_i64.c Execute move.sh - Rename files from bn_* to match the function names. 2019-10-19 16:24:39 +02:00
mp_get_l.c Execute move.sh - Rename files from bn_* to match the function names. 2019-10-19 16:24:39 +02:00
mp_get_mag_u32.c Execute move.sh - Rename files from bn_* to match the function names. 2019-10-19 16:24:39 +02:00
mp_get_mag_u64.c Execute move.sh - Rename files from bn_* to match the function names. 2019-10-19 16:24:39 +02:00
mp_get_mag_ul.c Execute move.sh - Rename files from bn_* to match the function names. 2019-10-19 16:24:39 +02:00
mp_grow.c Fix possible integer overflow 2023-09-05 07:14:54 +02:00
mp_hash.c Make the arg of mp_hash() const 2023-08-26 13:12:44 +02:00
mp_init.c introduce MP_MAX_DIGIT_COUNT to prevent overflow 2019-12-05 10:52:41 +01:00
mp_init_copy.c Execute move.sh - Rename files from bn_* to match the function names. 2019-10-19 16:24:39 +02:00
mp_init_i32.c Execute move.sh - Rename files from bn_* to match the function names. 2019-10-19 16:24:39 +02:00
mp_init_i64.c Execute move.sh - Rename files from bn_* to match the function names. 2019-10-19 16:24:39 +02:00
mp_init_l.c Execute move.sh - Rename files from bn_* to match the function names. 2019-10-19 16:24:39 +02:00
mp_init_multi.c add error code MP_OVF for integer overflow (too many digits) 2019-12-23 11:12:42 +01:00
mp_init_set.c Execute move.sh - Rename files from bn_* to match the function names. 2019-10-19 16:24:39 +02:00
mp_init_size.c Fix possible integer overflow 2023-09-05 07:14:54 +02:00
mp_init_u32.c Execute move.sh - Rename files from bn_* to match the function names. 2019-10-19 16:24:39 +02:00
mp_init_u64.c Execute move.sh - Rename files from bn_* to match the function names. 2019-10-19 16:24:39 +02:00
mp_init_ul.c Execute move.sh - Rename files from bn_* to match the function names. 2019-10-19 16:24:39 +02:00
mp_invmod.c Give correct values for invmod with modulus of 1 2020-03-05 15:52:28 -05:00
mp_is_square.c Introduced 0 (zero) to mp_is_square as a perfect square 2021-12-13 21:08:49 +01:00
mp_kronecker.c Fix type used. 2025-06-11 12:26:31 +02:00
mp_lcm.c Execute move.sh - Rename files from bn_* to match the function names. 2019-10-19 16:24:39 +02:00
mp_log.c make both mp_log() variants testable and add CI jobs 2023-04-11 13:53:22 +02:00
mp_log_n.c Expansion of mp_log to the full range together with the extension of mp_log to bigint bases. 2023-04-09 05:45:38 +02:00
mp_lshd.c slightly edit, update and run typos.sh 2022-10-03 12:13:21 +02:00
mp_mod.c simplify mod functions 2019-11-07 01:01:19 +01:00
mp_mod_2d.c simplifications: add s_mp_zero_(digs|buf) and s_mp_copy_digs 2019-11-04 15:41:32 +01:00
mp_montgomery_calc_normalization.c slightly edit, update and run typos.sh 2022-10-03 12:13:21 +02:00
mp_montgomery_reduce.c rename MP_MAXFAST to MP_MAX_COMBA 2019-11-05 20:09:23 +01:00
mp_montgomery_setup.c Execute move.sh - Rename files from bn_* to match the function names. 2019-10-19 16:24:39 +02:00
mp_mul.c Addition of extensive tests for s_mp_sqr_comba 2023-04-04 20:02:16 +02:00
mp_mul_2.c slightly edit, update and run typos.sh 2022-10-03 12:13:21 +02:00
mp_mul_2d.c simplifications: remove unnecessary optimization 2019-11-04 15:41:33 +01:00
mp_mul_d.c add macro MP_IS_2EXPT 2019-11-09 06:43:59 +01:00
mp_mulmod.c simplify mod functions 2019-11-07 01:01:19 +01:00
mp_neg.c better use of mp_isneg() and mp_iszero() 2019-11-11 21:52:20 +01:00
mp_or.c better use of mp_isneg() and mp_iszero() 2019-11-11 21:52:20 +01:00
mp_pack.c use uint8_t instead of unsigned char 2019-10-29 17:40:59 +01:00
mp_pack_count.c Execute move.sh - Rename files from bn_* to match the function names. 2019-10-19 16:24:39 +02:00
mp_prime_fermat.c simplifications: prime functions 2019-11-04 15:41:32 +01:00
mp_prime_frobenius_underwood.c simplifications: prime functions 2019-11-04 15:41:32 +01:00
mp_prime_is_prime.c slightly edit, update and run typos.sh 2022-10-03 12:13:21 +02:00
mp_prime_miller_rabin.c simplifications: prime functions 2019-11-04 15:41:32 +01:00
mp_prime_next_prime.c simplifications: prime functions 2019-11-04 15:41:32 +01:00
mp_prime_rabin_miller_trials.c first batch of simplifications 2019-10-29 19:30:23 +01:00
mp_prime_rand.c Correct sanitation of mp_prime_rand 2024-03-11 11:52:10 +01:00
mp_prime_strong_lucas_selfridge.c Fix compilation of mp_prime_strong_lucas_selfridge 2024-04-08 14:13:51 +03:00
mp_radix_size.c suffix _u32 -> _n of mp_(expt|log|root) functions, use int for now 2019-11-14 09:16:00 +01:00
mp_radix_size_overestimate.c Introduction of a fast but slightly over-estimating radix_size 2019-12-04 21:39:02 +01:00
mp_rand.c split-up mp_rand.c 2020-09-19 16:04:50 +02:00
mp_rand_source.c Split up mp_rand_source.c 2025-01-30 14:59:53 +01:00
mp_read_radix.c better use of mp_isneg() and mp_iszero() 2019-11-11 21:52:20 +01:00
mp_reduce.c rename mul/sqr functions for consistency, comba instead of fast suffix 2019-11-04 15:41:33 +01:00
mp_reduce_2k.c simplifications: reduce functions 2019-11-04 15:41:32 +01:00
mp_reduce_2k_l.c simplifications: reduce functions 2019-11-04 15:41:32 +01:00
mp_reduce_2k_setup.c simplifications: reduce functions 2019-11-04 15:41:32 +01:00
mp_reduce_2k_setup_l.c Execute move.sh - Rename files from bn_* to match the function names. 2019-10-19 16:24:39 +02:00
mp_reduce_is_2k.c Deny 2k-reduce if lsd is zero 2024-03-11 10:05:57 +01:00
mp_reduce_is_2k_l.c better use of mp_isneg() and mp_iszero() 2019-11-11 21:52:20 +01:00
mp_reduce_setup.c slightly edit, update and run typos.sh 2022-10-03 12:13:21 +02:00
mp_root_n.c suffix _u32 -> _n of mp_(expt|log|root) functions, use int for now 2019-11-14 09:16:00 +01:00
mp_rshd.c simplifications: add s_mp_zero_(digs|buf) and s_mp_copy_digs 2019-11-04 15:41:32 +01:00
mp_sbin_size.c Execute move.sh - Rename files from bn_* to match the function names. 2019-10-19 16:24:39 +02:00
mp_set.c simplifications: add s_mp_zero_(digs|buf) and s_mp_copy_digs 2019-11-04 15:41:32 +01:00
mp_set_double.c introduce MP_HAS_SET_DOUBLE 2020-03-05 14:11:13 +01:00
mp_set_i32.c Execute move.sh - Rename files from bn_* to match the function names. 2019-10-19 16:24:39 +02:00
mp_set_i64.c Execute move.sh - Rename files from bn_* to match the function names. 2019-10-19 16:24:39 +02:00
mp_set_l.c Execute move.sh - Rename files from bn_* to match the function names. 2019-10-19 16:24:39 +02:00
mp_set_u32.c Execute move.sh - Rename files from bn_* to match the function names. 2019-10-19 16:24:39 +02:00
mp_set_u64.c Execute move.sh - Rename files from bn_* to match the function names. 2019-10-19 16:24:39 +02:00
mp_set_ul.c Execute move.sh - Rename files from bn_* to match the function names. 2019-10-19 16:24:39 +02:00
mp_shrink.c introduce MP_MAX_DIGIT_COUNT to prevent overflow 2019-12-05 10:52:41 +01:00
mp_signed_rsh.c better use of mp_isneg() and mp_iszero() 2019-11-11 21:52:20 +01:00
mp_sqrmod.c simplify mod functions 2019-11-07 01:01:19 +01:00
mp_sqrt.c better use of mp_isneg() and mp_iszero() 2019-11-11 21:52:20 +01:00
mp_sqrtmod_prime.c Additional input checks and a test for b \cong 0 (mod a) in test_mp_sqrtmod_prime 2020-09-15 23:49:09 +02:00
mp_sub.c better use of mp_isneg() and mp_iszero() 2019-11-11 21:52:20 +01:00
mp_sub_d.c better use of mp_isneg() and mp_iszero() 2019-11-11 21:52:20 +01:00
mp_submod.c simplify mod functions 2019-11-07 01:01:19 +01:00
mp_to_radix.c docs: fix simple typo, exluding -> excluding 2020-12-19 19:09:57 +11:00
mp_to_sbin.c better use of mp_isneg() and mp_iszero() 2019-11-11 21:52:20 +01:00
mp_to_ubin.c use uint8_t instead of unsigned char 2019-10-29 17:40:59 +01:00
mp_ubin_size.c Execute move.sh - Rename files from bn_* to match the function names. 2019-10-19 16:24:39 +02:00
mp_unpack.c use uint8_t instead of unsigned char 2019-10-29 17:40:59 +01:00
mp_warray_free.c Use Thread Local Storage for warray buffer 2024-03-29 10:57:20 +01:00
mp_xor.c better use of mp_isneg() and mp_iszero() 2019-11-11 21:52:20 +01:00
mp_zero.c simplifications: add s_mp_zero_(digs|buf) and s_mp_copy_digs 2019-11-04 15:41:32 +01:00
Package.swift Add testTarget for SwiftPM 2021-12-01 22:43:45 +08:00
README.md Clarify what happened to tommath.pdf 2024-03-11 18:13:31 +01:00
s_mp_add.c simplifications: remove unnecessary optimization 2019-11-04 15:41:33 +01:00
s_mp_copy_digs.c simplifications: add s_mp_zero_(digs|buf) and s_mp_copy_digs 2019-11-04 15:41:32 +01:00
s_mp_div_3.c make mp_div_3 private 2019-11-09 06:43:58 +01:00
s_mp_div_recursive.c corrected startvalue for sigma and cutoff in mp_div 2019-11-24 05:44:29 +01:00
s_mp_div_school.c Do not assume that more than enough memory is automatically allocated and set to '0' 2023-03-31 13:27:02 +02:00
s_mp_div_small.c better use of mp_isneg() and mp_iszero() 2019-11-11 21:52:20 +01:00
s_mp_exptmod.c Execute move.sh - Rename files from bn_* to match the function names. 2019-10-19 16:24:39 +02:00
s_mp_exptmod_fast.c Work around false-positive warning. 2025-02-24 13:39:00 +01:00
s_mp_fp_log.c Refactored 2023-04-09 05:45:38 +02:00
s_mp_fp_log_d.c fix build of amalgamated library 2023-04-11 15:03:20 +02:00
s_mp_get_bit.c simplifications: prime functions 2019-11-04 15:41:32 +01:00
s_mp_invmod.c Fix: removed sign operation in s_mp_invmod_odd 2022-10-04 12:30:10 +02:00
s_mp_invmod_odd.c Fix: removed sign operation in s_mp_invmod_odd 2022-10-04 12:30:10 +02:00
s_mp_log_2expt.c suffix _u32 -> _n of mp_(expt|log|root) functions, use int for now 2019-11-14 09:16:00 +01:00
s_mp_montgomery_reduce_comba.c add MP_SMALL_STACK_SIZE option 2024-03-27 16:12:02 +01:00
s_mp_mul.c Fix possible integer overflow 2023-09-05 07:14:54 +02:00
s_mp_mul_balance.c rename mul/sqr functions for consistency, comba instead of fast suffix 2019-11-04 15:41:33 +01:00
s_mp_mul_comba.c add MP_SMALL_STACK_SIZE option 2024-03-27 16:12:02 +01:00
s_mp_mul_high.c Fix possible integer overflow 2023-09-05 07:14:54 +02:00
s_mp_mul_high_comba.c add MP_SMALL_STACK_SIZE option 2024-03-27 16:12:02 +01:00
s_mp_mul_karatsuba.c slightly edit, update and run typos.sh 2022-10-03 12:13:21 +02:00
s_mp_mul_toom.c make mp_div_3 private 2019-11-09 06:43:58 +01:00
s_mp_prime_is_divisible.c simplifications: prime functions 2019-11-04 15:41:32 +01:00
s_mp_prime_tab.c fix generate_def, rename some internal files 2019-11-05 21:11:58 +01:00
s_mp_radix_map.c fix generate_def, rename some internal files 2019-11-05 21:11:58 +01:00
s_mp_radix_size_overestimate.c s_mp_radix_size_overestimate: remove overflow check 2019-12-05 00:40:04 +01:00
s_mp_rand_platform.c Use bcrypt.h on Windows 2025-01-30 14:21:58 +08:00
s_mp_rand_source.c Split up mp_rand_source.c 2025-01-30 14:59:53 +01:00
s_mp_sqr.c optimized s_mp_sqr 2023-04-05 09:54:02 +02:00
s_mp_sqr_comba.c add MP_SMALL_STACK_SIZE option 2024-03-27 16:12:02 +01:00
s_mp_sqr_karatsuba.c rename mul/sqr functions for consistency, comba instead of fast suffix 2019-11-04 15:41:33 +01:00
s_mp_sqr_toom.c rename mul/sqr functions for consistency, comba instead of fast suffix 2019-11-04 15:41:33 +01:00
s_mp_sub.c simplifications: remove unnecessary optimization 2019-11-04 15:41:33 +01:00
s_mp_warray.c Use Thread Local Storage for warray buffer 2024-03-29 10:57:20 +01:00
s_mp_warray_get.c Use Thread Local Storage for warray buffer 2024-03-29 10:57:20 +01:00
s_mp_warray_put.c Use Thread Local Storage for warray buffer 2024-03-29 10:57:20 +01:00
s_mp_zero_buf.c simplifications: add s_mp_zero_(digs|buf) and s_mp_copy_digs 2019-11-04 15:41:32 +01:00
s_mp_zero_digs.c simplifications: add s_mp_zero_(digs|buf) and s_mp_copy_digs 2019-11-04 15:41:32 +01:00
sources.cmake Generate import library in CMake 2025-03-15 20:27:55 +08:00
testme.sh Add multi-threaded tests 2024-03-27 16:25:27 +01:00
tommath.def regen 2024-03-29 10:57:20 +01:00
tommath.h Use Thread Local Storage for warray buffer 2024-03-29 10:57:20 +01:00
tommath_c89.h Add tests for MSVC multi-threading 2024-03-27 16:25:27 +01:00
tommath_class.h regen 2025-01-30 14:59:53 +01:00
tommath_cutoffs.h rename mul/sqr functions for consistency, comba instead of fast suffix 2019-11-04 15:41:33 +01:00
tommath_private.h Disable MP_SMALL_STACK_SIZE on MSVC 2024-04-03 16:23:42 +02:00
tommath_superclass.h Split up mp_rand_source.c 2025-01-30 14:59:53 +01:00

libtommath

This is the git repository for LibTomMath, a free open source portable number theoretic multiple-precision integer (MPI) library written entirely in C.

Build Status

Travis CI

master: Build Status

develop: Build Status

AppVeyor

master: Build status

develop: Build status

ABI Laboratory

API/ABI changes: check here

Pre-built packages

We sometimes upload deb packages of the latest state from the develop branch to packagecloud.io.

Use those packages with caution and at your own discretion.

Summary

The develop branch contains the in-development version. Stable releases are tagged.

Documentation is built from the LaTeX file doc/bn.tex and available as PDF for each release. This PDF is also created as build artifact on each CI run.

There is also limited documentation in tommath.h.

Originally the library contained a document, tommath.pdf, which describes the goals of the project and many of the algorithms used at the time. This document has been removed since it can't be built anymore and nobody spent the time to fix and update it. The latest valid update to that document was done in version 0.39 of the library and it is contained within that tarball.

The project can be build by using make. Along with the usual make, make clean and make install, there are several other build targets, see the makefile for details. There are also makefiles for certain specific platforms.

Testing

Tests are located in demo/ and can be built in two flavors.

  • make test creates a stand-alone test binary that executes several test routines.
  • make mtest_opponent creates a test binary that is intended to be run against mtest. mtest can be built with make mtest and test execution is done like ./mtest/mtest | ./mtest_opponent. mtest is creating test vectors using an alternative MPI library and test is consuming these vectors to verify correct behavior of ltm

Building and Installing

Building is straightforward for GNU Linux only, the section "Building LibTomMath" in the documentation in doc/bn.pdf has the details.

CMake support

The project provides support for the CMake build system.

git clone https://github.com/libtom/libtommath.git
mkdir -p libtommath/build
cd libtommath/build
cmake ..
make -j$(nproc)

A shared library build can be done by setting -DBUILD_SHARED_LIBS=On when invoking the cmake command.