Added new math library based on TFM.
authorPekka Riikonen <priikone@silcnet.org>
Wed, 5 Mar 2008 18:46:42 +0000 (20:46 +0200)
committerPekka Riikonen <priikone@silcnet.org>
Wed, 5 Mar 2008 18:46:42 +0000 (20:46 +0200)
commitabd261065eac46a2d2c970833f3fa701bc1516e3
treea8cd12cec53ddfbb5c737ff5e88847fbf156eff9
parent63da89e60c01aa62254648b3aafc88261181da65
Added new math library based on TFM.

We've changed the TFM to support dynamically allocated integers.  As good
and fast as the TFM is its main flaw is that it uses pre-allocated
integers.  This doesn't work in real life, unless of course you know
exactly how much memory you are going to use and need, or you don't care
about how much your program consumes memory.  On systems that need to work
in environments from few integers to tens of thousands allocated at the
same time, the dynamic allocation is the only right way to go to keep the
memory consumption in line.  It also has the added benefit that there is
no artificial limit to integer size.

The dynamically allocated integer can be initialized exactly the same
way as the original TFM integer.  It can be memset'ed to initialize, if
needed, but tfm_fp_init should be used.  However, tfm_fp_zero must always
be called to avoid memory leaks.  The integer thus is initialized to
no memory at first and will grow automatically.  It also supports
SilcStack.  With SilcStack integer reallocations are very fast and is
ideal to use in temp integers that are used only for computations and
not for storing integers for a long time.

Integers can be copied with tfm_fp_copy and it will automatically allocate
memory for the copied integer.  The contents of the integer can be
directly exchanged by exchanging the pointers with tfm_fp_exch, which is
much faster that the copy that must be used in original TFM to do the
same.

We've also added missing routines like bitwise AND, OR and XOR, sqrt,
expt_d and others.
15 files changed:
TODO
configure.ad
lib/silccrypt/dsa.c
lib/silccrypt/silcpkcs1.c
lib/silcmath/Makefile.ad
lib/silcmath/modinv.c
lib/silcmath/mp_gmp.c
lib/silcmath/mp_tfm.c
lib/silcmath/mp_tfm.h
lib/silcmath/mp_tma.c
lib/silcmath/silcmp.h
lib/silcmath/tests/Makefile.am [new file with mode: 0644]
lib/silcmath/tests/test_silcmp.c [new file with mode: 0644]
lib/silcmath/tfm.c
lib/silcmath/tfm.h