Skip to content

Commit

Permalink
added libtommath-0.08
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom St Denis authored and sjaeckel committed Jul 15, 2010
1 parent 3cd7000 commit 2cfbb89
Show file tree
Hide file tree
Showing 11 changed files with 655 additions and 115 deletions.
389 changes: 304 additions & 85 deletions bn.c

Large diffs are not rendered by default.

13 changes: 5 additions & 8 deletions bn.h
Expand Up @@ -50,7 +50,7 @@
typedef unsigned long mp_digit;
typedef ulong64 mp_word;

#define DIGIT_BIT 28U
#define DIGIT_BIT 28
#endif

#ifndef DIGIT_BIT
Expand All @@ -77,13 +77,10 @@
typedef int mp_err;

/* you'll have to tune these... */
#ifdef FAST_FPU
#define KARATSUBA_MUL_CUTOFF 100 /* Min. number of digits before Karatsuba multiplication is used. */
#define KARATSUBA_SQR_CUTOFF 100 /* Min. number of digits before Karatsuba squaring is used. */
#else
#define KARATSUBA_MUL_CUTOFF 80 /* Min. number of digits before Karatsuba multiplication is used. */
#define KARATSUBA_SQR_CUTOFF 80 /* Min. number of digits before Karatsuba squaring is used. */
#endif
#define KARATSUBA_MUL_CUTOFF 80 /* Min. number of digits before Karatsuba multiplication is used. */
#define KARATSUBA_SQR_CUTOFF 80 /* Min. number of digits before Karatsuba squaring is used. */

#define MP_PREC 64 /* default digits of precision */

typedef struct {
int used, alloc, sign;
Expand Down
Binary file modified bn.pdf
Binary file not shown.
22 changes: 11 additions & 11 deletions bn.tex
@@ -1,7 +1,7 @@
\documentclass{article}
\begin{document}

\title{LibTomMath v0.07 \\ A Free Multiple Precision Integer Library}
\title{LibTomMath v0.08 \\ A Free Multiple Precision Integer Library}
\author{Tom St Denis \\ tomstdenis@iahu.ca}
\maketitle
\newpage
Expand Down Expand Up @@ -484,23 +484,23 @@ \subsection{Observed Timings}
Multiply & 256 & 2,551 & 958 \\
Multiply & 512 & 7,913 & 2,476 \\
Multiply & 1024 & 28,496 & 7,927 \\
Multiply & 2048 & 109,897 & 282,24 \\
Multiply & 4096 & 469,970 & 104,681 \\
Multiply & 2048 & 109,897 & 28,224 \\
Multiply & 4096 & 469,970 & 101,171 \\
\hline
Square & 128 & 1,319 & 511 \\
Square & 256 & 1,776 & 947 \\
Square & 512 & 5,399 & 2,153 \\
Square & 1024 & 18,991 & 5,733 \\
Square & 2048 & 72,126 & 17,621 \\
Square & 4096 & 306,269 & 70,168 \\
Square & 4096 & 306,269 & 67,576 \\
\hline
Exptmod & 512 & 32,021,586 & 4,472,406 \\
Exptmod & 768 & 97,595,492 & 10,427,845 \\
Exptmod & 1024 & 223,302,532 & 20,561,722 \\
Exptmod & 2048 & 1,682,223,369 & 113,978,803 \\
Exptmod & 2560 & 3,268,615,571 & 236,650,133 \\
Exptmod & 3072 & 5,597,240,141 & 373,449,291 \\
Exptmod & 4096 & 13,347,270,891 & 787,568,457
Exptmod & 512 & 32,021,586 & 4,138,354 \\
Exptmod & 768 & 97,595,492 & 9,840,233 \\
Exptmod & 1024 & 223,302,532 & 20,624,553 \\
Exptmod & 2048 & 1,682,223,369 & 114,936,361 \\
Exptmod & 2560 & 3,268,615,571 & 229,402,426 \\
Exptmod & 3072 & 5,597,240,141 & 367,403,840 \\
Exptmod & 4096 & 13,347,270,891 & 779,058,433

\end{tabular}
\end{center}
Expand Down
8 changes: 8 additions & 0 deletions changes.txt
@@ -1,3 +1,11 @@
Jan 2nd, 2003
v0.08 -- Sped up the multipliers by moving the inner loop variables into a smaller scope
-- Corrected a bunch of small "warnings"
-- Added more comments
-- Made "mtest" be able to use /dev/random, /dev/urandom or stdin for RNG data
-- Corrected some bugs where error messages were potentially ignored
-- add etc/pprime.c program which makes numbers which are provably prime.

Jan 1st, 2003
v0.07 -- Removed alot of heap operations from core functions to speed them up
-- Added a root finding function [and mp_sqrt macro like from MPI]
Expand Down
26 changes: 21 additions & 5 deletions demo.c
Expand Up @@ -23,7 +23,6 @@ extern ulong64 rdtsc(void);
extern void reset(void);
#else


ulong64 _tt;
void reset(void) { _tt = clock(); }
ulong64 rdtsc(void) { return clock() - _tt; }
Expand All @@ -33,6 +32,8 @@ ulong64 rdtsc(void) { return clock() - _tt; }
int _ifuncs;
#else
extern int _ifuncs;
extern void dump_timings(void);
extern void reset_timings(void);
#endif

void ndraw(mp_int *a, char *name)
Expand Down Expand Up @@ -103,11 +104,25 @@ int main(void)

mp_read_radix(&b, "4982748972349724892742", 10);
mp_sub_d(&a, 1, &c);

#ifdef DEBUG
mp_sqr(&a, &a);mp_sqr(&c, &c);
mp_sqr(&a, &a);mp_sqr(&c, &c);
mp_sqr(&a, &a);mp_sqr(&c, &c);
reset_timings();
#endif
mp_exptmod(&b, &c, &a, &d);
mp_toradix(&d, buf, 10);
printf("b^p-1 == %s\n", buf);
#ifdef DEBUG
dump_timings();
return 0;

#ifdef TIMER
#endif

mp_toradix(&d, buf, 10);
printf("b^p-1 == %s\n", buf);


#ifdef TIMER
mp_read_radix(&a, "340282366920938463463374607431768211455", 10);
mp_read_radix(&b, "340282366920938463463574607431768211455", 10);
while (a.used * DIGIT_BIT < 8192) {
Expand Down Expand Up @@ -194,7 +209,8 @@ int main(void)
}
printf("Exponentiating %d-bit took %llu cycles\n", mp_count_bits(&a), tt / ((ulong64)35));
}
}
}


mp_read_radix(&a, "340282366920938463463374607431768211455", 10);
mp_read_radix(&b, "234892374891378913789237289378973232333", 10);
Expand Down
1 change: 1 addition & 0 deletions etc/makefile
@@ -0,0 +1 @@
CFLAGS += -I../ -Wall -W -O3 -fomit-frame-pointer -funroll-loops ../bn.c

0 comments on commit 2cfbb89

Please sign in to comment.