Compare commits
52
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
440325f1fa | ||
|
|
44d36b0777 | ||
|
|
b6e44cf97f | ||
|
|
15eff3a60b | ||
|
|
244a3018c5 | ||
|
|
69d77fc137 | ||
|
|
0ac369da08 | ||
|
|
5c69fce733 | ||
|
|
b032f6d67b | ||
|
|
777a642667 | ||
|
|
eaaa675e99 | ||
|
|
bd11687207 | ||
|
|
4b7f867f90 | ||
|
|
a4c8e24f4c | ||
|
|
309510e33e | ||
|
|
58c45c0f97 | ||
|
|
97bf1ced2b | ||
|
|
28f17c0d70 | ||
|
|
4d25168772 | ||
|
|
912f1a8816 | ||
|
|
24829b80ac | ||
|
|
12c3fbcb0c | ||
|
|
9740bc1662 | ||
|
|
8751d32304 | ||
|
|
ac198c7f44 | ||
|
|
d17af2c703 | ||
|
|
595cb86379 | ||
|
|
334b8029ed | ||
|
|
be26adf83b | ||
|
|
c1ee80eccf | ||
|
|
6420ec98e8 | ||
|
|
1cab268c94 | ||
|
|
774c2050f1 | ||
|
|
7a1b66b00d | ||
|
|
4e994192a1 | ||
|
|
c70641a878 | ||
|
|
ffdd95d4a3 | ||
|
|
cb9018a721 | ||
|
|
3ab1f672a4 | ||
|
|
57c23073f7 | ||
|
|
245ed0c3c3 | ||
|
|
543703d4ee | ||
|
|
2865a8da13 | ||
|
|
ccc592df50 | ||
|
|
8094d33e43 | ||
|
|
95d2a7f7c0 | ||
|
|
f218c1f1eb | ||
|
|
4909a5cc24 | ||
|
|
5ee08fdf00 | ||
|
|
1e9a4512c7 | ||
|
|
0cced28f38 | ||
|
|
f720f4cad5 |
+108
-89
@@ -3,62 +3,36 @@ language: c
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- os: linux
|
||||
# Testing on Linux with various compilers
|
||||
- name: "Linux/Clang/Shared"
|
||||
os: linux
|
||||
dist: xenial
|
||||
compiler: clang
|
||||
env:
|
||||
- BUILD_DIR=unix
|
||||
- os: linux
|
||||
- name: "Linux/Clang/Static"
|
||||
os: linux
|
||||
dist: xenial
|
||||
compiler: clang
|
||||
env:
|
||||
- CFGOPT=--disable-shared
|
||||
- BUILD_DIR=unix
|
||||
- os: linux
|
||||
- name: "Linux/GCC/Shared"
|
||||
os: linux
|
||||
dist: xenial
|
||||
compiler: gcc
|
||||
env:
|
||||
- BUILD_DIR=unix
|
||||
- os: linux
|
||||
- name: "Linux/GCC/Static"
|
||||
os: linux
|
||||
dist: xenial
|
||||
compiler: gcc
|
||||
env:
|
||||
- CFGOPT=--disable-shared
|
||||
- BUILD_DIR=unix
|
||||
- os: linux
|
||||
dist: xenial
|
||||
compiler: gcc-4.9
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- g++-4.9
|
||||
env:
|
||||
- BUILD_DIR=unix
|
||||
- os: linux
|
||||
dist: xenial
|
||||
compiler: gcc-5
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- g++-5
|
||||
env:
|
||||
- BUILD_DIR=unix
|
||||
- os: linux
|
||||
dist: xenial
|
||||
compiler: gcc-6
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- g++-6
|
||||
env:
|
||||
- BUILD_DIR=unix
|
||||
- os: linux
|
||||
# Older versions of GCC...
|
||||
- name: "Linux/GCC 7/Shared"
|
||||
os: linux
|
||||
dist: xenial
|
||||
compiler: gcc-7
|
||||
addons:
|
||||
@@ -69,35 +43,86 @@ matrix:
|
||||
- g++-7
|
||||
env:
|
||||
- BUILD_DIR=unix
|
||||
- os: osx
|
||||
osx_image: xcode8
|
||||
- name: "Linux/GCC 6/Shared"
|
||||
os: linux
|
||||
dist: xenial
|
||||
compiler: gcc-6
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- g++-6
|
||||
env:
|
||||
- BUILD_DIR=unix
|
||||
- os: osx
|
||||
osx_image: xcode8
|
||||
- name: "Linux/GCC 5/Shared"
|
||||
os: linux
|
||||
dist: xenial
|
||||
compiler: gcc-5
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- g++-5
|
||||
env:
|
||||
- BUILD_DIR=unix
|
||||
- name: "Linux/GCC 4.9/Shared"
|
||||
os: linux
|
||||
dist: xenial
|
||||
compiler: gcc-4.9
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- g++-4.9
|
||||
env:
|
||||
- BUILD_DIR=unix
|
||||
# Testing on Mac, various styles
|
||||
- name: "macOS/Xcode 11/Shared/Unix-like"
|
||||
os: osx
|
||||
osx_image: xcode11
|
||||
env:
|
||||
- BUILD_DIR=unix
|
||||
- name: "macOS/Xcode 11/Shared/Mac-like"
|
||||
os: osx
|
||||
osx_image: xcode11
|
||||
env:
|
||||
- BUILD_DIR=macosx
|
||||
- NO_DIRECT_CONFIGURE=1
|
||||
- os: osx
|
||||
osx_image: xcode9
|
||||
env:
|
||||
- BUILD_DIR=macosx
|
||||
- NO_DIRECT_CONFIGURE=1
|
||||
- os: osx
|
||||
install: []
|
||||
script: &mactest
|
||||
- make all
|
||||
# The styles=develop avoids some weird problems on OSX
|
||||
- make test styles=develop
|
||||
- name: "macOS/Xcode 10/Shared/Mac-like"
|
||||
os: osx
|
||||
osx_image: xcode10.2
|
||||
env:
|
||||
- BUILD_DIR=macosx
|
||||
- NO_DIRECT_CONFIGURE=1
|
||||
### C builds not currently directly supported on Windows instances
|
||||
# - os: windows
|
||||
# env:
|
||||
# - BUILD_DIR=win
|
||||
### ... so proxy with a Mingw cross-compile
|
||||
# Test with mingw-w64 (32 bit)
|
||||
- os: linux
|
||||
install: []
|
||||
script: *mactest
|
||||
- name: "macOS/Xcode 9/Shared/Mac-like"
|
||||
os: osx
|
||||
osx_image: xcode9
|
||||
env:
|
||||
- BUILD_DIR=macosx
|
||||
install: []
|
||||
script: *mactest
|
||||
- name: "macOS/Xcode 8/Shared/Mac-like"
|
||||
os: osx
|
||||
osx_image: xcode8
|
||||
env:
|
||||
- BUILD_DIR=macosx
|
||||
install: []
|
||||
script: *mactest
|
||||
# Test with mingw-w64 (32 bit) cross-compile
|
||||
# Doesn't run tests because wine is only an imperfect Windows emulation
|
||||
- name: "Linux-cross-Windows-32/GCC/Shared/no test"
|
||||
os: linux
|
||||
dist: xenial
|
||||
compiler: i686-w64-mingw32-gcc
|
||||
addons:
|
||||
addons: &mingw32
|
||||
apt:
|
||||
packages:
|
||||
- gcc-mingw-w64-base
|
||||
@@ -109,28 +134,28 @@ matrix:
|
||||
env:
|
||||
- BUILD_DIR=win
|
||||
- CFGOPT="--host=i686-w64-mingw32 --enable-threads"
|
||||
- NO_DIRECT_TEST=1
|
||||
- os: linux
|
||||
script: &crosstest
|
||||
- make all
|
||||
- make tcltest
|
||||
# Include a high visibility marker that tests are skipped outright
|
||||
- >
|
||||
echo "`tput setaf 3`SKIPPED TEST: CROSS COMPILING`tput sgr0`"
|
||||
- name: "Linux-cross-Windows-32/GCC/Static/no test"
|
||||
os: linux
|
||||
dist: xenial
|
||||
compiler: i686-w64-mingw32-gcc
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- gcc-mingw-w64-base
|
||||
- binutils-mingw-w64-i686
|
||||
- gcc-mingw-w64-i686
|
||||
- gcc-mingw-w64
|
||||
- gcc-multilib
|
||||
- wine
|
||||
addons: *mingw32
|
||||
env:
|
||||
- BUILD_DIR=win
|
||||
- CFGOPT="--host=i686-w64-mingw32 --disable-shared --enable-threads"
|
||||
- NO_DIRECT_TEST=1
|
||||
script: *crosstest
|
||||
# Test with mingw-w64 (64 bit)
|
||||
- os: linux
|
||||
# Doesn't run tests because wine is only an imperfect Windows emulation
|
||||
- name: "Linux-cross-Windows-64/GCC/Shared/no test"
|
||||
os: linux
|
||||
dist: xenial
|
||||
compiler: x86_64-w64-mingw32-gcc
|
||||
addons:
|
||||
addons: &mingw64
|
||||
apt:
|
||||
packages:
|
||||
- gcc-mingw-w64-base
|
||||
@@ -141,29 +166,23 @@ matrix:
|
||||
env:
|
||||
- BUILD_DIR=win
|
||||
- CFGOPT="--host=x86_64-w64-mingw32 --enable-64bit --enable-threads"
|
||||
- NO_DIRECT_TEST=1
|
||||
- os: linux
|
||||
script: *crosstest
|
||||
- name: "Linux-cross-Windows-64/GCC/Static/no test"
|
||||
os: linux
|
||||
dist: xenial
|
||||
compiler: x86_64-w64-mingw32-gcc
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- gcc-mingw-w64-base
|
||||
- binutils-mingw-w64-x86-64
|
||||
- gcc-mingw-w64-x86-64
|
||||
- gcc-mingw-w64
|
||||
- wine
|
||||
addons: *mingw64
|
||||
env:
|
||||
- BUILD_DIR=win
|
||||
- CFGOPT="--host=x86_64-w64-mingw32 --enable-64bit --enable-threads --disable-shared"
|
||||
- NO_DIRECT_TEST=1
|
||||
|
||||
script: *crosstest
|
||||
before_install:
|
||||
- export ERROR_ON_FAILURES=1
|
||||
- cd ${BUILD_DIR}
|
||||
install:
|
||||
- test -n "$NO_DIRECT_CONFIGURE" || ./configure ${CFGOPT}
|
||||
- ./configure ${CFGOPT} --prefix=$HOME
|
||||
before_script:
|
||||
- export ERROR_ON_FAILURES=1
|
||||
script:
|
||||
- make
|
||||
# The styles=develop avoids some weird problems on OSX
|
||||
- test -n "$NO_DIRECT_TEST" || make test styles=develop
|
||||
- make all
|
||||
- make tcltest
|
||||
- make test
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# README: Tcl
|
||||
|
||||
This is the **Tcl 8.5.19** source distribution.
|
||||
|
||||
|
||||
You can get any source release of Tcl from [our distribution
|
||||
site](https://sourceforge.net/projects/tcl/files/Tcl/).
|
||||
|
||||
|
||||
+4
-4
@@ -329,11 +329,11 @@ trace procedures will always be invoked.
|
||||
.SH "RESTRICTIONS"
|
||||
.PP
|
||||
A trace procedure can be called at any time, even when there
|
||||
is a partially formed result in the interpreter's result area. If
|
||||
are partially formed results stored in the interpreter. If
|
||||
the trace procedure does anything that could damage this result (such
|
||||
as calling \fBTcl_Eval\fR) then it must save the original values of
|
||||
the interpreter's \fBresult\fR and \fBfreeProc\fR fields and restore
|
||||
them before it returns.
|
||||
as calling \fBTcl_Eval\fR) then it must use the \fBTcl_SaveInterpState\fR
|
||||
and related routines to save and restore the original state of
|
||||
the interpreter before it returns.
|
||||
.SH "UNDEFINED VARIABLES"
|
||||
.PP
|
||||
It is legal to set a trace on an undefined variable.
|
||||
|
||||
+65
-15
@@ -26,9 +26,11 @@ as the corresponding C operators.
|
||||
Expressions almost always yield numeric results
|
||||
(integer or floating-point values).
|
||||
For example, the expression
|
||||
.PP
|
||||
.CS
|
||||
\fBexpr 8.2 + 6\fR
|
||||
.CE
|
||||
.PP
|
||||
evaluates to 14.2.
|
||||
Tcl expressions differ from C expressions in the way that
|
||||
operands are specified. Also, Tcl expressions support
|
||||
@@ -103,8 +105,9 @@ For some examples of simple expressions, suppose the variable
|
||||
the variable \fBb\fR has the value 6.
|
||||
Then the command on the left side of each of the lines below
|
||||
will produce the value on the right side of the line:
|
||||
.PP
|
||||
.CS
|
||||
.ta 6c
|
||||
.ta 9c
|
||||
\fBexpr\fR 3.1 + $a \fI6.1\fR
|
||||
\fBexpr\fR 2 + "$a.$b" \fI5.6\fR
|
||||
\fBexpr\fR 4*[llength "6 2"] \fI8\fR
|
||||
@@ -189,16 +192,21 @@ Bit-wise OR. Valid for integer operands only.
|
||||
Logical AND. Produces a 1 result if both operands are non-zero,
|
||||
0 otherwise.
|
||||
Valid for boolean and numeric (integers or floating-point) operands only.
|
||||
This operator evaluates lazily; it only evaluates its right-hand side if it
|
||||
must in order to determine its result.
|
||||
.TP 20
|
||||
\fB||\fR
|
||||
Logical OR. Produces a 0 result if both operands are zero, 1 otherwise.
|
||||
Valid for boolean and numeric (integers or floating-point) operands only.
|
||||
This operator evaluates lazily; it only evaluates its right-hand side if it
|
||||
must in order to determine its result.
|
||||
.TP 20
|
||||
\fIx\fB?\fIy\fB:\fIz\fR
|
||||
\fIx \fB? \fIy \fB: \fIz\fR
|
||||
If-then-else, as in C. If \fIx\fR
|
||||
evaluates to non-zero, then the result is the value of \fIy\fR.
|
||||
Otherwise the result is the value of \fIz\fR.
|
||||
The \fIx\fR operand must have a boolean or numeric value.
|
||||
This operator evaluates lazily; it only evaluates one of \fIy\fR or \fIz\fR.
|
||||
.LP
|
||||
See the C manual for more details on the results
|
||||
produced by each operator.
|
||||
@@ -209,18 +217,22 @@ of the \fBpow\fR function (after any type conversions.)
|
||||
.VE 8.5
|
||||
All of the binary operators group left-to-right within the same
|
||||
precedence level. For example, the command
|
||||
.PP
|
||||
.CS
|
||||
\fBexpr\fR {4*2 < 7}
|
||||
.CE
|
||||
.PP
|
||||
returns 0.
|
||||
.PP
|
||||
The \fB&&\fR, \fB||\fR, and \fB?:\fR operators have
|
||||
.QW "lazy evaluation" ,
|
||||
just as in C, which means that operands are not evaluated if they are
|
||||
not needed to determine the outcome. For example, in the command
|
||||
.PP
|
||||
.CS
|
||||
\fBexpr {$v ? [a] : [b]}\fR
|
||||
\fBexpr\fR {$v ? [a] : [b]}
|
||||
.CE
|
||||
.PP
|
||||
only one of
|
||||
.QW \fB[a]\fR
|
||||
or
|
||||
@@ -238,18 +250,23 @@ before invoking the \fBexpr\fR command.
|
||||
.VS 8.5
|
||||
When the expression parser encounters a mathematical function
|
||||
such as \fBsin($x)\fR, it replaces it with a call to an ordinary
|
||||
Tcl function in the \fBtcl::mathfunc\fR namespace. The processing
|
||||
Tcl command in the \fBtcl::mathfunc\fR namespace. The processing
|
||||
of an expression such as:
|
||||
.PP
|
||||
.CS
|
||||
\fBexpr {sin($x+$y)}\fR
|
||||
\fBexpr\fR {sin($x+$y)}
|
||||
.CE
|
||||
.PP
|
||||
is the same in every way as the processing of:
|
||||
.PP
|
||||
.CS
|
||||
\fBexpr {[tcl::mathfunc::sin [expr {$x+$y}]]}\fR
|
||||
\fBexpr\fR {[tcl::mathfunc::sin [\fBexpr\fR {$x+$y}]]}
|
||||
.CE
|
||||
.PP
|
||||
which in turn is the same as the processing of:
|
||||
.PP
|
||||
.CS
|
||||
\fBtcl::mathfunc::sin [expr {$x+$y}]\fR
|
||||
tcl::mathfunc::sin [\fBexpr\fR {$x+$y}]
|
||||
.CE
|
||||
.PP
|
||||
The executor will search for \fBtcl::mathfunc::sin\fR using the usual
|
||||
@@ -288,23 +305,29 @@ and string operands is done automatically as needed.
|
||||
For arithmetic computations, integers are used until some
|
||||
floating-point number is introduced, after which floating-point is used.
|
||||
For example,
|
||||
.PP
|
||||
.CS
|
||||
\fBexpr\fR {5 / 4}
|
||||
.CE
|
||||
.PP
|
||||
returns 1, while
|
||||
.PP
|
||||
.CS
|
||||
\fBexpr\fR {5 / 4.0}
|
||||
\fBexpr\fR {5 / ( [string length "abcd"] + 0.0 )}
|
||||
.CE
|
||||
.PP
|
||||
both return 1.25.
|
||||
Floating-point values are always returned with a
|
||||
.QW \fB.\fR
|
||||
or an
|
||||
.QW \fBe\fR
|
||||
so that they will not look like integer values. For example,
|
||||
.PP
|
||||
.CS
|
||||
\fBexpr\fR {20.0/5.0}
|
||||
.CE
|
||||
.PP
|
||||
returns \fB4.0\fR, not \fB4\fR.
|
||||
.SS "STRING OPERATIONS"
|
||||
.PP
|
||||
@@ -320,10 +343,12 @@ Canonical string representation for integer values is a decimal string
|
||||
format. Canonical string representation for floating-point values
|
||||
is that produced by the \fB%g\fR format specifier of Tcl's
|
||||
\fBformat\fR command. For example, the commands
|
||||
.PP
|
||||
.CS
|
||||
\fBexpr {"0x03" > "2"}\fR
|
||||
\fBexpr {"0y" > "0x12"}\fR
|
||||
\fBexpr\fR {"0x03" > "2"}
|
||||
\fBexpr\fR {"0y" > "0x12"}
|
||||
.CE
|
||||
.PP
|
||||
both return 1. The first comparison is done using integer
|
||||
comparison, and the second is done using string comparison.
|
||||
Because of Tcl's tendency to treat values as numbers whenever
|
||||
@@ -340,15 +365,19 @@ This allows the Tcl bytecode compiler to generate the best code.
|
||||
As mentioned above, expressions are substituted twice:
|
||||
once by the Tcl parser and once by the \fBexpr\fR command.
|
||||
For example, the commands
|
||||
.PP
|
||||
.CS
|
||||
\fBset a 3\fR
|
||||
\fBset b {$a + 2}\fR
|
||||
\fBexpr $b*4\fR
|
||||
set a 3
|
||||
set b {$a + 2}
|
||||
\fBexpr\fR $b*4
|
||||
.CE
|
||||
.PP
|
||||
return 11, not a multiple of 4.
|
||||
This is because the Tcl parser will first substitute \fB$a + 2\fR for
|
||||
the variable \fBb\fR,
|
||||
then the \fBexpr\fR command will evaluate the expression \fB$a + 2*4\fR.
|
||||
This is because the Tcl parser will first substitute
|
||||
.QW "\fB$a + 2\fR"
|
||||
for the variable \fBb\fR,
|
||||
then the \fBexpr\fR command will evaluate the expression
|
||||
.QW "\fB$a + 2*4\fR" .
|
||||
.PP
|
||||
Most expressions do not require a second round of substitutions.
|
||||
Either they are enclosed in braces or, if not,
|
||||
@@ -362,6 +391,21 @@ The most expensive code is required for
|
||||
unbraced expressions that contain command substitutions.
|
||||
These expressions must be implemented by generating new code
|
||||
each time the expression is executed.
|
||||
.PP
|
||||
If it is necessary to include a non-constant expression string within the
|
||||
wider context of an otherwise-constant expression, the most efficient
|
||||
technique is to put the varying part inside a recursive \fBexpr\fR, as this at
|
||||
least allows for the compilation of the outer part, though it does mean that
|
||||
the varying part must itself be evaluated as a separate expression. Thus, in
|
||||
this example the result is 20 and the outer expression benefits from fully
|
||||
cached bytecode compilation.
|
||||
.PP
|
||||
.CS
|
||||
set a 3
|
||||
set b {$a + 2}
|
||||
\fBexpr\fR {[\fBexpr\fR $b] * 4}
|
||||
.CE
|
||||
.PP
|
||||
.VS 8.5
|
||||
When the expression is unbraced to allow the substitution of a function or
|
||||
operator, consider using the commands documented in the \fBmathfunc\fR(n) or
|
||||
@@ -371,6 +415,7 @@ operator, consider using the commands documented in the \fBmathfunc\fR(n) or
|
||||
Define a procedure that computes an
|
||||
.QW interesting
|
||||
mathematical function:
|
||||
.PP
|
||||
.CS
|
||||
proc tcl::mathfunc::calc {x y} {
|
||||
\fBexpr\fR { ($x**2 - $y**2) / exp($x**2 + $y**2) }
|
||||
@@ -378,6 +423,7 @@ proc tcl::mathfunc::calc {x y} {
|
||||
.CE
|
||||
.PP
|
||||
Convert polar coordinates into cartesian coordinates:
|
||||
.PP
|
||||
.CS
|
||||
# convert from ($radius,$angle)
|
||||
set x [\fBexpr\fR { $radius * cos($angle) }]
|
||||
@@ -385,6 +431,7 @@ set y [\fBexpr\fR { $radius * sin($angle) }]
|
||||
.CE
|
||||
.PP
|
||||
Convert cartesian coordinates into polar coordinates:
|
||||
.PP
|
||||
.CS
|
||||
# convert from ($x,$y)
|
||||
set radius [\fBexpr\fR { hypot($y, $x) }]
|
||||
@@ -393,12 +440,14 @@ set angle [\fBexpr\fR { atan2($y, $x) }]
|
||||
.PP
|
||||
Print a message describing the relationship of two string values to
|
||||
each other:
|
||||
.PP
|
||||
.CS
|
||||
puts "a and b are [\fBexpr\fR {$a eq $b ? {equal} : {different}}]"
|
||||
.CE
|
||||
.PP
|
||||
Set a variable to whether an environment variable is both defined at
|
||||
all and also set to a true boolean value:
|
||||
.PP
|
||||
.CS
|
||||
set isTrue [\fBexpr\fR {
|
||||
[info exists ::env(SOME_ENV_VAR)] &&
|
||||
@@ -407,6 +456,7 @@ set isTrue [\fBexpr\fR {
|
||||
.CE
|
||||
.PP
|
||||
Generate a random integer in the range 0..99 inclusive:
|
||||
.PP
|
||||
.CS
|
||||
set randNum [\fBexpr\fR { int(100 * rand()) }]
|
||||
.CE
|
||||
|
||||
+65
-48
@@ -9,16 +9,26 @@
|
||||
.BS
|
||||
'\" Note: do not modify the .SH NAME line immediately below!
|
||||
.SH NAME
|
||||
timerate \- Time-related execution resp. performance measurement of a script
|
||||
timerate \- Calibrated performance measurements of script execution time
|
||||
.SH SYNOPSIS
|
||||
\fBtimerate \fIscript\fR \fI?time ?max-count??\fR
|
||||
\fBtimerate \fIscript\fR ?\fItime\fR? ?\fImax-count\fR?
|
||||
.sp
|
||||
\fBtimerate \fI?-direct?\fR \fI?-overhead double?\fR \fIscript\fR \fI?time ?max-count??\fR
|
||||
\fBtimerate \fR?\fB\-direct\fR? ?\fB\-overhead\fI double\fR? \fIscript\fR ?\fItime\fR? ?\fImax-count\fR?
|
||||
.sp
|
||||
\fBtimerate \fI?-calibrate?\fR \fI?-direct?\fR \fIscript\fR \fI?time ?max-count??\fR
|
||||
\fBtimerate \fR?\fB\-calibrate\fR? ?\fB\-direct\fR? \fIscript\fR ?\fItime\fR? ?\fImax-count\fR?
|
||||
.BE
|
||||
.SH DESCRIPTION
|
||||
.PP
|
||||
The \fBtimerate\fR command does calibrated performance measurement of a Tcl
|
||||
command or script, \fIscript\fR. The \fIscript\fR should be written so that it
|
||||
can be executed multiple times during the performance measurement process.
|
||||
Time is measured in elapsed time using the finest timer resolution as possible,
|
||||
not CPU time; if \fIscript\fR interacts with the OS, the cost of that
|
||||
interaction is included.
|
||||
This command may be used to provide information as to how well a script or
|
||||
Tcl command is performing, and can help determine bottlenecks and fine-tune
|
||||
application performance.
|
||||
.PP
|
||||
The first and second form will evaluate \fIscript\fR until the interval
|
||||
\fItime\fR given in milliseconds elapses, or for 1000 milliseconds (1 second)
|
||||
if \fItime\fR is not specified.
|
||||
@@ -28,47 +38,48 @@ by the maximal number of iterations to evaluate the script.
|
||||
If \fImax-count\fR is specified, the evalution will stop either this count of
|
||||
iterations is reached or the time is exceeded.
|
||||
.sp
|
||||
It will then return a canonical tcl-list of the form
|
||||
It will then return a canonical tcl-list of the form:
|
||||
.PP
|
||||
.CS
|
||||
\fB0.095977 \(mcs/# 52095836 # 10419167 #/sec 5000.000 nett-ms\fR
|
||||
\fB0.095977 \(mcs/# 52095836 # 10419167 #/sec 5000.000 net-ms\fR
|
||||
.CE
|
||||
.PP
|
||||
which indicates:
|
||||
.IP \(bu
|
||||
.IP \(bu 3
|
||||
the average amount of time required per iteration, in microseconds ([\fBlindex\fR $result 0])
|
||||
.IP \(bu
|
||||
.IP \(bu 3
|
||||
the count how many times it was executed ([\fBlindex\fR $result 2])
|
||||
.IP \(bu
|
||||
.IP \(bu 3
|
||||
the estimated rate per second ([\fBlindex\fR $result 4])
|
||||
.IP \(bu
|
||||
.IP \(bu 3
|
||||
the estimated real execution time without measurement overhead ([\fBlindex\fR $result 6])
|
||||
.PP
|
||||
Time is measured in elapsed time using the finest timer resolution as possible,
|
||||
not CPU time.
|
||||
This command may be used to provide information as to how well the script or a
|
||||
tcl-command is performing and can help determine bottlenecks and fine-tune
|
||||
application performance.
|
||||
The following options may be supplied to the \fBtimerate\fR command:
|
||||
.TP
|
||||
\fI-calibrate\fR
|
||||
\fB\-calibrate\fR
|
||||
.
|
||||
To measure very fast scripts as exact as posible the calibration process
|
||||
To measure very fast scripts as exactly as possible, a calibration process
|
||||
may be required.
|
||||
|
||||
The \fI-calibrate\fR option is used to calibrate timerate, calculating the
|
||||
estimated overhead of the given script as the default overhead for future
|
||||
invocations of the \fBtimerate\fR command. If the \fItime\fR parameter is not
|
||||
specified, the calibrate procedure runs for up to 10 seconds.
|
||||
The \fB\-calibrate\fR option is used to calibrate \fBtimerate\fR itself,
|
||||
calculating the estimated overhead of the given script as the default overhead
|
||||
for future invocations of the \fBtimerate\fR command. If the \fItime\fR
|
||||
parameter is not specified, the calibrate procedure runs for up to 10 seconds.
|
||||
.RS
|
||||
.PP
|
||||
Note that calibration is not thread safe in the current implementation.
|
||||
.RE
|
||||
.TP
|
||||
\fI-overhead double\fR
|
||||
\fB\-overhead \fIdouble\fR
|
||||
.
|
||||
The \fI-overhead\fR parameter supplies an estimate (in microseconds) of the
|
||||
The \fB\-overhead\fR parameter supplies an estimate (in microseconds) of the
|
||||
measurement overhead of each iteration of the tested script. This quantity
|
||||
will be subtracted from the measured time prior to reporting results.
|
||||
will be subtracted from the measured time prior to reporting results. This can
|
||||
be useful for removing the cost of interpreter state reset commands from the
|
||||
script being measured.
|
||||
.TP
|
||||
\fI-direct\fR
|
||||
\fB\-direct\fR
|
||||
.
|
||||
The \fI-direct\fR option causes direct execution of the supplied script,
|
||||
The \fB-direct\fR option causes direct execution of the supplied script,
|
||||
without compilation, in a manner similar to the \fBtime\fR command. It can be
|
||||
used to measure the cost of \fBTcl_EvalObjEx\fR, of the invocation of canonical
|
||||
lists, and of the uncompiled versions of bytecoded commands.
|
||||
@@ -76,31 +87,33 @@ lists, and of the uncompiled versions of bytecoded commands.
|
||||
As opposed to the \fBtime\fR commmand, which runs the tested script for a fixed
|
||||
number of iterations, the timerate command runs it for a fixed time.
|
||||
Additionally, the compiled variant of the script will be used during the entire
|
||||
measurement, as if the script were part of a compiled procedure, if the \fI-direct\fR
|
||||
measurement, as if the script were part of a compiled procedure, if the \fB\-direct\fR
|
||||
option is not specified. The fixed time period and possibility of compilation allow
|
||||
for more precise results and prevent very long execution times by slow scripts, making
|
||||
it practical for measuring scripts with highly uncertain execution times.
|
||||
|
||||
.SH EXAMPLE
|
||||
.SH EXAMPLES
|
||||
Estimate how fast it takes for a simple Tcl \fBfor\fR loop (including
|
||||
operations on variable \fIi\fR) to count to a ten:
|
||||
operations on variable \fIi\fR) to count to ten:
|
||||
.PP
|
||||
.CS
|
||||
# calibrate:
|
||||
timerate -calibrate {}
|
||||
# measure:
|
||||
timerate { for {set i 0} {$i<10} {incr i} {} } 5000
|
||||
\fI# calibrate\fR
|
||||
\fBtimerate\fR -calibrate {}
|
||||
|
||||
\fI# measure\fR
|
||||
\fBtimerate\fR { for {set i 0} {$i<10} {incr i} {} } 5000
|
||||
.CE
|
||||
.PP
|
||||
Estimate how fast it takes for a simple Tcl \fBfor\fR loop, ignoring the
|
||||
overhead for to perform ten iterations, ignoring the overhead of the management
|
||||
of the variable that controls the loop:
|
||||
overhead of the management of the variable that controls the loop:
|
||||
.PP
|
||||
.CS
|
||||
# calibrate for overhead of variable operations:
|
||||
set i 0; timerate -calibrate {expr {$i<10}; incr i} 1000
|
||||
# measure:
|
||||
timerate { for {set i 0} {$i<10} {incr i} {} } 5000
|
||||
\fI# calibrate for overhead of variable operations\fR
|
||||
set i 0; \fBtimerate\fR -calibrate {expr {$i<10}; incr i} 1000
|
||||
|
||||
\fI# measure\fR
|
||||
\fBtimerate\fR {
|
||||
for {set i 0} {$i<10} {incr i} {}
|
||||
} 5000
|
||||
.CE
|
||||
.PP
|
||||
Estimate the speed of calculating the hour of the day using \fBclock format\fR only,
|
||||
@@ -108,14 +121,18 @@ ignoring overhead of the portion of the script that prepares the time for it to
|
||||
calculate:
|
||||
.PP
|
||||
.CS
|
||||
# calibrate:
|
||||
timerate -calibrate {}
|
||||
# estimate overhead:
|
||||
\fI# calibrate\fR
|
||||
\fBtimerate\fR -calibrate {}
|
||||
|
||||
\fI# estimate overhead\fR
|
||||
set tm 0
|
||||
set ovh [lindex [timerate { incr tm [expr {24*60*60}] }] 0]
|
||||
# measure using esimated overhead:
|
||||
set ovh [lindex [\fBtimerate\fR {
|
||||
incr tm [expr {24*60*60}]
|
||||
}] 0]
|
||||
|
||||
\fI# measure using estimated overhead\fR
|
||||
set tm 0
|
||||
timerate -overhead $ovh {
|
||||
\fBtimerate\fR -overhead $ovh {
|
||||
clock format $tm -format %H
|
||||
incr tm [expr {24*60*60}]; # overhead for this is ignored
|
||||
} 5000
|
||||
@@ -123,7 +140,7 @@ timerate -overhead $ovh {
|
||||
.SH "SEE ALSO"
|
||||
time(n)
|
||||
.SH KEYWORDS
|
||||
script, timerate, time
|
||||
performance measurement, script, time
|
||||
.\" Local Variables:
|
||||
.\" mode: nroff
|
||||
.\" End:
|
||||
|
||||
+1
-1
@@ -414,7 +414,7 @@ typedef unsigned TCL_WIDE_INT_TYPE Tcl_WideUInt;
|
||||
#if defined(__WIN32__)
|
||||
# ifdef __BORLANDC__
|
||||
typedef struct stati64 Tcl_StatBuf;
|
||||
# elif defined(_WIN64)
|
||||
# elif defined(_WIN64) || defined(__MINGW_USE_VC2005_COMPAT) || defined(_USE_64BIT_TIME_T)
|
||||
typedef struct __stat64 Tcl_StatBuf;
|
||||
# elif (defined(_MSC_VER) && (_MSC_VER < 1400)) || defined(_USE_32BIT_TIME_T)
|
||||
typedef struct _stati64 Tcl_StatBuf;
|
||||
|
||||
+17
-10
@@ -413,7 +413,15 @@ Tcl_CreateInterp(void)
|
||||
Tcl_Panic("Tcl_CallFrame must not be smaller than CallFrame");
|
||||
}
|
||||
|
||||
#if defined(_WIN32) && !defined(_WIN64)
|
||||
#if defined(_WIN32) && !defined(_WIN64) && !defined(_USE_64BIT_TIME_T) \
|
||||
&& !defined(__MINGW_USE_VC2005_COMPAT)
|
||||
/* If Tcl is compiled on Win32 using -D_USE_64BIT_TIME_T or
|
||||
* -D__MINGW_USE_VC2005_COMPAT, the result is a binary incompatible
|
||||
* with the 'standard' build of Tcl: All extensions using Tcl_StatBuf
|
||||
* or interal functions like TclpGetDate() need to be recompiled in
|
||||
* the same way. Therefore, this is not officially supported.
|
||||
* In stead, it is recommended to use Win64 or Tcl 9.0 (not released yet)
|
||||
*/
|
||||
if (sizeof(time_t) != 4) {
|
||||
/*NOTREACHED*/
|
||||
Tcl_Panic("<time.h> is not compatible with MSVC");
|
||||
@@ -1920,7 +1928,7 @@ Tcl_CreateCommand(
|
||||
|
||||
/* An existing command conflicts. Try to delete it.. */
|
||||
cmdPtr = Tcl_GetHashValue(hPtr);
|
||||
|
||||
|
||||
/*
|
||||
* Be careful to preserve
|
||||
* any existing import links so we can restore them down below. That
|
||||
@@ -2107,7 +2115,7 @@ Tcl_CreateObjCommand(
|
||||
cmdPtr = Tcl_GetHashValue(hPtr);
|
||||
|
||||
/*
|
||||
* [***] This is wrong. See Tcl Bug a16752c252.
|
||||
* [***] This is wrong. See Tcl Bug a16752c252.
|
||||
* However, this buggy behavior is kept under particular
|
||||
* circumstances to accommodate deployed binaries of the
|
||||
* "tclcompiler" program. http://sourceforge.net/projects/tclpro/
|
||||
@@ -5188,7 +5196,7 @@ TclEvalObjEx(
|
||||
TclStackAlloc(interp, sizeof(CmdFrame));
|
||||
|
||||
eoFramePtr->type = TCL_LOCATION_EVAL_LIST;
|
||||
eoFramePtr->level = (iPtr->cmdFramePtr == NULL? 1
|
||||
eoFramePtr->level = (iPtr->cmdFramePtr == NULL? 1
|
||||
: iPtr->cmdFramePtr->level + 1);
|
||||
eoFramePtr->framePtr = iPtr->framePtr;
|
||||
eoFramePtr->nextPtr = iPtr->cmdFramePtr;
|
||||
@@ -6346,7 +6354,7 @@ ExprIsqrtFunc(
|
||||
if (Tcl_GetBignumFromObj(interp, objv[1], &big) != TCL_OK) {
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if (SIGN(&big) == MP_NEG) {
|
||||
if (mp_isneg(&big)) {
|
||||
mp_clear(&big);
|
||||
goto negarg;
|
||||
}
|
||||
@@ -6617,8 +6625,7 @@ ExprAbsFunc(
|
||||
#endif
|
||||
|
||||
if (type == TCL_NUMBER_BIG) {
|
||||
/* TODO: const correctness ? */
|
||||
if (mp_cmp_d((mp_int *) ptr, 0) == MP_LT) {
|
||||
if (mp_cmp_d(ptr, 0) == MP_LT) {
|
||||
Tcl_GetBignumFromObj(NULL, objv[1], &big);
|
||||
tooLarge:
|
||||
mp_neg(&big, &big);
|
||||
@@ -6768,7 +6775,7 @@ ExprIntFunc(
|
||||
mp_int big;
|
||||
|
||||
Tcl_GetBignumFromObj(NULL, objPtr, &big);
|
||||
mp_mod_2d(&big, (int) CHAR_BIT * sizeof(long), &big);
|
||||
mp_mod_2d(&big, CHAR_BIT * sizeof(long), &big);
|
||||
objPtr = Tcl_NewBignumObj(&big);
|
||||
Tcl_IncrRefCount(objPtr);
|
||||
TclGetLongFromObj(NULL, objPtr, &iResult);
|
||||
@@ -6800,7 +6807,7 @@ ExprWideFunc(
|
||||
mp_int big;
|
||||
|
||||
Tcl_GetBignumFromObj(NULL, objPtr, &big);
|
||||
mp_mod_2d(&big, (int) CHAR_BIT * sizeof(Tcl_WideInt), &big);
|
||||
mp_mod_2d(&big, CHAR_BIT * sizeof(Tcl_WideInt), &big);
|
||||
objPtr = Tcl_NewBignumObj(&big);
|
||||
Tcl_IncrRefCount(objPtr);
|
||||
Tcl_GetWideIntFromObj(NULL, objPtr, &wResult);
|
||||
@@ -7007,7 +7014,7 @@ ExprSrandFunc(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
mp_mod_2d(&big, (int) CHAR_BIT * sizeof(long), &big);
|
||||
mp_mod_2d(&big, CHAR_BIT * sizeof(long), &big);
|
||||
objPtr = Tcl_NewBignumObj(&big);
|
||||
Tcl_IncrRefCount(objPtr);
|
||||
TclGetLongFromObj(NULL, objPtr, &i);
|
||||
|
||||
+8
-12
@@ -870,15 +870,11 @@ Tcl_FileObjCmd(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if (objc == 4) {
|
||||
/*
|
||||
* Need separate variable for reading longs from an object on
|
||||
* 64-bit platforms. [Bug #698146]
|
||||
*/
|
||||
Tcl_WideInt newTime;
|
||||
|
||||
long newTime;
|
||||
|
||||
if (TclGetLongFromObj(interp, objv[3], &newTime) != TCL_OK) {
|
||||
return TCL_ERROR;
|
||||
|
||||
if (Tcl_GetWideIntFromObj(interp, objv[3], &newTime) != TCL_OK) {
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
if (index == FCMD_ATIME) {
|
||||
@@ -908,7 +904,7 @@ Tcl_FileObjCmd(
|
||||
}
|
||||
}
|
||||
|
||||
Tcl_SetObjResult(interp, Tcl_NewLongObj((long)
|
||||
Tcl_SetObjResult(interp, Tcl_NewWideIntObj(
|
||||
(index == FCMD_ATIME ? buf.st_atime : buf.st_mtime)));
|
||||
return TCL_OK;
|
||||
case FCMD_ATTRIBUTES:
|
||||
@@ -1527,9 +1523,9 @@ StoreStatData(
|
||||
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
|
||||
STORE_ARY("blksize", Tcl_NewLongObj((long)statPtr->st_blksize));
|
||||
#endif
|
||||
STORE_ARY("atime", Tcl_NewLongObj((long)statPtr->st_atime));
|
||||
STORE_ARY("mtime", Tcl_NewLongObj((long)statPtr->st_mtime));
|
||||
STORE_ARY("ctime", Tcl_NewLongObj((long)statPtr->st_ctime));
|
||||
STORE_ARY("atime", Tcl_NewWideIntObj(statPtr->st_atime));
|
||||
STORE_ARY("mtime", Tcl_NewWideIntObj(statPtr->st_mtime));
|
||||
STORE_ARY("ctime", Tcl_NewWideIntObj(statPtr->st_ctime));
|
||||
mode = (unsigned short) statPtr->st_mode;
|
||||
STORE_ARY("mode", Tcl_NewIntObj(mode));
|
||||
STORE_ARY("type", Tcl_NewStringObj(GetTypeFromMode(mode), -1));
|
||||
|
||||
+327
-166
@@ -3956,12 +3956,13 @@ Tcl_TimeObjCmd(
|
||||
* Tcl_TimeRateObjCmd --
|
||||
*
|
||||
* This object-based procedure is invoked to process the "timerate" Tcl
|
||||
* command.
|
||||
* This is similar to command "time", except the execution limited by
|
||||
* command.
|
||||
*
|
||||
* This is similar to command "time", except the execution limited by
|
||||
* given time (in milliseconds) instead of repetition count.
|
||||
*
|
||||
* Example:
|
||||
* timerate {after 5} 1000 ; # equivalent for `time {after 5} [expr 1000/5]`
|
||||
* timerate {after 5} 1000; # equivalent to: time {after 5} [expr 1000/5]
|
||||
*
|
||||
* Results:
|
||||
* A standard Tcl object result.
|
||||
@@ -3979,39 +3980,40 @@ Tcl_TimeRateObjCmd(
|
||||
int objc, /* Number of arguments. */
|
||||
Tcl_Obj *const objv[]) /* Argument objects. */
|
||||
{
|
||||
static
|
||||
double measureOverhead = 0; /* global measure-overhead */
|
||||
static double measureOverhead = 0;
|
||||
/* global measure-overhead */
|
||||
double overhead = -1; /* given measure-overhead */
|
||||
register Tcl_Obj *objPtr;
|
||||
register int result, i;
|
||||
Tcl_Obj *calibrate = NULL, *direct = NULL;
|
||||
Tcl_WideUInt count = 0; /* Holds repetition count */
|
||||
Tcl_WideInt maxms = WIDE_MIN;
|
||||
TclWideMUInt count = 0; /* Holds repetition count */
|
||||
Tcl_WideInt maxms = WIDE_MIN;
|
||||
/* Maximal running time (in milliseconds) */
|
||||
Tcl_WideUInt maxcnt = WIDE_MAX;
|
||||
TclWideMUInt maxcnt = WIDE_MAX;
|
||||
/* Maximal count of iterations. */
|
||||
Tcl_WideUInt threshold = 1; /* Current threshold for check time (faster
|
||||
TclWideMUInt threshold = 1; /* Current threshold for check time (faster
|
||||
* repeat count without time check) */
|
||||
Tcl_WideUInt maxIterTm = 1; /* Max time of some iteration as max threshold
|
||||
* additionally avoid divide to zero (never < 1) */
|
||||
TclWideMUInt maxIterTm = 1; /* Max time of some iteration as max
|
||||
* threshold, additionally avoiding divide to
|
||||
* zero (i.e., never < 1) */
|
||||
unsigned short factor = 50; /* Factor (4..50) limiting threshold to avoid
|
||||
* growth of execution time. */
|
||||
register Tcl_WideInt start, middle, stop;
|
||||
#ifndef TCL_WIDE_CLICKS
|
||||
Tcl_Time now;
|
||||
#endif
|
||||
|
||||
#endif /* !TCL_WIDE_CLICKS */
|
||||
static const char *const options[] = {
|
||||
"-direct", "-overhead", "-calibrate", "--", NULL
|
||||
};
|
||||
enum options {
|
||||
TMRT_EV_DIRECT, TMRT_OVERHEAD, TMRT_CALIBRATE, TMRT_LAST
|
||||
};
|
||||
|
||||
ByteCode *codePtr = NULL;
|
||||
ByteCode *codePtr = NULL;
|
||||
int codeOptimized = 0;
|
||||
|
||||
for (i = 1; i < objc - 1; i++) {
|
||||
int index;
|
||||
int index;
|
||||
|
||||
if (Tcl_GetIndexFromObj(NULL, objv[i], options, "option", TCL_EXACT,
|
||||
&index) != TCL_OK) {
|
||||
break;
|
||||
@@ -4038,9 +4040,11 @@ Tcl_TimeRateObjCmd(
|
||||
}
|
||||
}
|
||||
|
||||
if (i >= objc || i < objc-3) {
|
||||
usage:
|
||||
Tcl_WrongNumArgs(interp, 1, objv, "?-direct? ?-calibrate? ?-overhead double? command ?time ?max-count??");
|
||||
if (i >= objc || i < objc - 3) {
|
||||
usage:
|
||||
Tcl_WrongNumArgs(interp, 1, objv,
|
||||
"?-direct? ?-calibrate? ?-overhead double? "
|
||||
"command ?time ?max-count??");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
objPtr = objv[i++];
|
||||
@@ -4051,6 +4055,7 @@ usage:
|
||||
}
|
||||
if (i < objc) { /* max-count*/
|
||||
Tcl_WideInt v;
|
||||
|
||||
result = Tcl_GetWideIntFromObj(interp, objv[i], &v);
|
||||
if (result != TCL_OK) {
|
||||
return result;
|
||||
@@ -4059,30 +4064,41 @@ usage:
|
||||
}
|
||||
}
|
||||
|
||||
/* if calibrate */
|
||||
/*
|
||||
* If we are doing calibration.
|
||||
*/
|
||||
|
||||
if (calibrate) {
|
||||
/*
|
||||
* If no time specified for the calibration.
|
||||
*/
|
||||
|
||||
/* if no time specified for the calibration */
|
||||
if (maxms == WIDE_MIN) {
|
||||
Tcl_Obj *clobjv[6];
|
||||
Tcl_WideInt maxCalTime = 5000;
|
||||
double lastMeasureOverhead = measureOverhead;
|
||||
|
||||
clobjv[0] = objv[0];
|
||||
|
||||
clobjv[0] = objv[0];
|
||||
i = 1;
|
||||
if (direct) {
|
||||
clobjv[i++] = direct;
|
||||
clobjv[i++] = direct;
|
||||
}
|
||||
clobjv[i++] = objPtr;
|
||||
clobjv[i++] = objPtr;
|
||||
|
||||
/* reset last measurement overhead */
|
||||
measureOverhead = (double)0;
|
||||
/*
|
||||
* Reset last measurement overhead.
|
||||
*/
|
||||
|
||||
measureOverhead = (double) 0;
|
||||
|
||||
/*
|
||||
* Self-call with 100 milliseconds to warm-up, before entering the
|
||||
* calibration cycle.
|
||||
*/
|
||||
|
||||
/* self-call with 100 milliseconds to warm-up,
|
||||
* before entering the calibration cycle */
|
||||
TclNewLongObj(clobjv[i], 100);
|
||||
Tcl_IncrRefCount(clobjv[i]);
|
||||
result = Tcl_TimeRateObjCmd(dummy, interp, i+1, clobjv);
|
||||
result = Tcl_TimeRateObjCmd(NULL, interp, i + 1, clobjv);
|
||||
Tcl_DecrRefCount(clobjv[i]);
|
||||
if (result != TCL_OK) {
|
||||
return result;
|
||||
@@ -4090,241 +4106,383 @@ usage:
|
||||
|
||||
i--;
|
||||
clobjv[i++] = calibrate;
|
||||
clobjv[i++] = objPtr;
|
||||
clobjv[i++] = objPtr;
|
||||
|
||||
/* set last measurement overhead to max */
|
||||
measureOverhead = (double)UWIDE_MAX;
|
||||
/*
|
||||
* Set last measurement overhead to max.
|
||||
*/
|
||||
|
||||
measureOverhead = (double) UWIDE_MAX;
|
||||
|
||||
/*
|
||||
* Run the calibration cycle until it is more precise.
|
||||
*/
|
||||
|
||||
/* calibration cycle until it'll be preciser */
|
||||
maxms = -1000;
|
||||
do {
|
||||
lastMeasureOverhead = measureOverhead;
|
||||
TclNewLongObj(clobjv[i], (int)maxms);
|
||||
TclNewLongObj(clobjv[i], (int) maxms);
|
||||
Tcl_IncrRefCount(clobjv[i]);
|
||||
result = Tcl_TimeRateObjCmd(dummy, interp, i+1, clobjv);
|
||||
result = Tcl_TimeRateObjCmd(NULL, interp, i + 1, clobjv);
|
||||
Tcl_DecrRefCount(clobjv[i]);
|
||||
if (result != TCL_OK) {
|
||||
return result;
|
||||
}
|
||||
maxCalTime += maxms;
|
||||
/* increase maxms for preciser calibration */
|
||||
maxms -= (-maxms / 4);
|
||||
/* as long as new value more as 0.05% better */
|
||||
} while ( (measureOverhead >= lastMeasureOverhead
|
||||
|
||||
/*
|
||||
* Increase maxms for more precise calibration.
|
||||
*/
|
||||
|
||||
maxms -= -maxms / 4;
|
||||
|
||||
/*
|
||||
* As long as new value more as 0.05% better
|
||||
*/
|
||||
} while ((measureOverhead >= lastMeasureOverhead
|
||||
|| measureOverhead / lastMeasureOverhead <= 0.9995)
|
||||
&& maxCalTime > 0
|
||||
);
|
||||
&& maxCalTime > 0);
|
||||
|
||||
return result;
|
||||
}
|
||||
if (maxms == 0) {
|
||||
/* reset last measurement overhead */
|
||||
/*
|
||||
* Reset last measurement overhead
|
||||
*/
|
||||
|
||||
measureOverhead = 0;
|
||||
Tcl_SetObjResult(interp, Tcl_NewLongObj(0));
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/* if time is negative - make current overhead more precise */
|
||||
/*
|
||||
* If time is negative, make current overhead more precise.
|
||||
*/
|
||||
|
||||
if (maxms > 0) {
|
||||
/* set last measurement overhead to max */
|
||||
measureOverhead = (double)UWIDE_MAX;
|
||||
/*
|
||||
* Set last measurement overhead to max.
|
||||
*/
|
||||
|
||||
measureOverhead = (double) UWIDE_MAX;
|
||||
} else {
|
||||
maxms = -maxms;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (maxms == WIDE_MIN) {
|
||||
maxms = 1000;
|
||||
maxms = 1000;
|
||||
}
|
||||
if (overhead == -1) {
|
||||
overhead = measureOverhead;
|
||||
}
|
||||
|
||||
/* be sure that resetting of result will not smudge the further measurement */
|
||||
/*
|
||||
* Ensure that resetting of result will not smudge the further
|
||||
* measurement.
|
||||
*/
|
||||
|
||||
Tcl_ResetResult(interp);
|
||||
|
||||
/* compile object */
|
||||
/*
|
||||
* Compile object if needed.
|
||||
*/
|
||||
|
||||
if (!direct) {
|
||||
if (TclInterpReady(interp) != TCL_OK) {
|
||||
return TCL_ERROR;
|
||||
}
|
||||
codePtr = TclCompileObj(interp, objPtr, NULL, 0);
|
||||
TclPreserveByteCode(codePtr);
|
||||
/*
|
||||
* Replace last compiled done instruction with continue: it's a part of
|
||||
* iteration, this way evaluation will be more similar to a cycle (also
|
||||
* avoids extra overhead to set result to interp, etc.)
|
||||
*/
|
||||
if (codePtr->codeStart[codePtr->numCodeBytes-1] == INST_DONE) {
|
||||
codePtr->codeStart[codePtr->numCodeBytes-1] = INST_CONTINUE;
|
||||
codeOptimized = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* get start and stop time */
|
||||
/*
|
||||
* Get start and stop time.
|
||||
*/
|
||||
|
||||
#ifdef TCL_WIDE_CLICKS
|
||||
start = middle = TclpGetWideClicks();
|
||||
/* time to stop execution (in wide clicks) */
|
||||
|
||||
/*
|
||||
* Time to stop execution (in wide clicks).
|
||||
*/
|
||||
|
||||
stop = start + (maxms * 1000 / TclpWideClickInMicrosec());
|
||||
#else
|
||||
Tcl_GetTime(&now);
|
||||
start = now.sec; start *= 1000000; start += now.usec;
|
||||
start = now.sec;
|
||||
start *= 1000000;
|
||||
start += now.usec;
|
||||
middle = start;
|
||||
/* time to stop execution (in microsecs) */
|
||||
|
||||
/*
|
||||
* Time to stop execution (in microsecs).
|
||||
*/
|
||||
|
||||
stop = start + maxms * 1000;
|
||||
#endif
|
||||
#endif /* TCL_WIDE_CLICKS */
|
||||
|
||||
/* start measurement */
|
||||
if (maxcnt > 0)
|
||||
while (1) {
|
||||
/* eval single iteration */
|
||||
count++;
|
||||
/*
|
||||
* Start measurement.
|
||||
*/
|
||||
|
||||
if (!direct) {
|
||||
/* precompiled */
|
||||
result = TclExecuteByteCode(interp, codePtr);
|
||||
} else {
|
||||
/* eval */
|
||||
result = TclEvalObjEx(interp, objPtr, 0, NULL, 0);
|
||||
}
|
||||
if (result != TCL_OK) {
|
||||
/* allow break from measurement cycle (used for conditional stop) */
|
||||
if (result != TCL_BREAK) {
|
||||
goto done;
|
||||
if (maxcnt > 0) {
|
||||
while (1) {
|
||||
/*
|
||||
* Evaluate a single iteration.
|
||||
*/
|
||||
|
||||
count++;
|
||||
if (!direct) { /* precompiled */
|
||||
result = TclExecuteByteCode(interp, codePtr);
|
||||
} else { /* eval */
|
||||
result = TclEvalObjEx(interp, objPtr, 0, NULL, 0);
|
||||
}
|
||||
/* force stop immediately */
|
||||
threshold = 1;
|
||||
maxcnt = 0;
|
||||
result = TCL_OK;
|
||||
}
|
||||
|
||||
/* don't check time up to threshold */
|
||||
if (--threshold > 0) continue;
|
||||
/*
|
||||
* Allow break and continue from measurement cycle (used for
|
||||
* conditional stop and flow control of iterations).
|
||||
*/
|
||||
|
||||
/* check stop time reached, estimate new threshold */
|
||||
#ifdef TCL_WIDE_CLICKS
|
||||
middle = TclpGetWideClicks();
|
||||
#else
|
||||
Tcl_GetTime(&now);
|
||||
middle = now.sec; middle *= 1000000; middle += now.usec;
|
||||
#endif
|
||||
if (middle >= stop || count >= maxcnt) {
|
||||
break;
|
||||
}
|
||||
|
||||
/* don't calculate threshold by few iterations, because sometimes first
|
||||
* iteration(s) can be too fast or slow (cached, delayed clean up, etc) */
|
||||
if (count < 10) {
|
||||
threshold = 1; continue;
|
||||
}
|
||||
|
||||
/* average iteration time in microsecs */
|
||||
threshold = (middle - start) / count;
|
||||
if (threshold > maxIterTm) {
|
||||
maxIterTm = threshold;
|
||||
/* interations seems to be longer */
|
||||
if (threshold > (maxIterTm * 2)) {
|
||||
if ((factor *= 2) > 50) factor = 50;
|
||||
} else {
|
||||
if (factor < 50) factor++;
|
||||
switch (result) {
|
||||
case TCL_OK:
|
||||
break;
|
||||
case TCL_BREAK:
|
||||
/*
|
||||
* Force stop immediately.
|
||||
*/
|
||||
threshold = 1;
|
||||
maxcnt = 0;
|
||||
case TCL_CONTINUE:
|
||||
result = TCL_OK;
|
||||
break;
|
||||
default:
|
||||
goto done;
|
||||
}
|
||||
} else if (factor > 4) {
|
||||
/* interations seems to be shorter */
|
||||
if (threshold < (maxIterTm / 2)) {
|
||||
if ((factor /= 2) < 4) factor = 4;
|
||||
} else {
|
||||
factor--;
|
||||
|
||||
/*
|
||||
* Don't check time up to threshold.
|
||||
*/
|
||||
|
||||
if (--threshold > 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check stop time reached, estimate new threshold.
|
||||
*/
|
||||
|
||||
#ifdef TCL_WIDE_CLICKS
|
||||
middle = TclpGetWideClicks();
|
||||
#else
|
||||
Tcl_GetTime(&now);
|
||||
middle = now.sec;
|
||||
middle *= 1000000;
|
||||
middle += now.usec;
|
||||
#endif /* TCL_WIDE_CLICKS */
|
||||
|
||||
if (middle >= stop || count >= maxcnt) {
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* Don't calculate threshold by few iterations, because sometimes
|
||||
* first iteration(s) can be too fast or slow (cached, delayed
|
||||
* clean up, etc).
|
||||
*/
|
||||
|
||||
if (count < 10) {
|
||||
threshold = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Average iteration time in microsecs.
|
||||
*/
|
||||
|
||||
threshold = (middle - start) / count;
|
||||
if (threshold > maxIterTm) {
|
||||
maxIterTm = threshold;
|
||||
/*
|
||||
* Iterations seem to be longer.
|
||||
*/
|
||||
if (threshold > maxIterTm * 2) {
|
||||
factor *= 2;
|
||||
if (factor > 50) {
|
||||
factor = 50;
|
||||
}
|
||||
} else {
|
||||
if (factor < 50) {
|
||||
factor++;
|
||||
}
|
||||
}
|
||||
} else if (factor > 4) {
|
||||
/*
|
||||
* Iterations seem to be shorter.
|
||||
*/
|
||||
|
||||
if (threshold < (maxIterTm / 2)) {
|
||||
factor /= 2;
|
||||
if (factor < 4) {
|
||||
factor = 4;
|
||||
}
|
||||
} else {
|
||||
factor--;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* As relation between remaining time and time since last check,
|
||||
* maximal some % of time (by factor), so avoid growing of the
|
||||
* execution time if iterations are not consistent, e.g. was
|
||||
* continuously on time).
|
||||
*/
|
||||
|
||||
threshold = ((stop - middle) / maxIterTm) / factor + 1;
|
||||
if (threshold > 100000) { /* fix for too large threshold */
|
||||
threshold = 100000;
|
||||
}
|
||||
|
||||
/*
|
||||
* Consider max-count
|
||||
*/
|
||||
|
||||
if (threshold > maxcnt - count) {
|
||||
threshold = maxcnt - count;
|
||||
}
|
||||
}
|
||||
/* as relation between remaining time and time since last check,
|
||||
* maximal some % of time (by factor), so avoid growing of the execution time
|
||||
* if iterations are not consistent, e. g. wax continuously on time) */
|
||||
threshold = ((stop - middle) / maxIterTm) / factor + 1;
|
||||
if (threshold > 100000) { /* fix for too large threshold */
|
||||
threshold = 100000;
|
||||
}
|
||||
/* consider max-count */
|
||||
if (threshold > maxcnt - count) {
|
||||
threshold = maxcnt - count;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
Tcl_Obj *objarr[8], **objs = objarr;
|
||||
Tcl_WideInt val;
|
||||
const char *fmt;
|
||||
TclWideMUInt usec, val;
|
||||
int digits;
|
||||
|
||||
middle -= start; /* execution time in microsecs */
|
||||
/*
|
||||
* Absolute execution time in microseconds or in wide clicks.
|
||||
*/
|
||||
usec = (TclWideMUInt)(middle - start);
|
||||
|
||||
#ifdef TCL_WIDE_CLICKS
|
||||
/* convert execution time in wide clicks to microsecs */
|
||||
middle *= TclpWideClickInMicrosec();
|
||||
#endif
|
||||
#ifdef TCL_WIDE_CLICKS
|
||||
/*
|
||||
* convert execution time (in wide clicks) to microsecs.
|
||||
*/
|
||||
|
||||
if (!count) { /* no iterations - avoid divide by zero */
|
||||
usec *= TclpWideClickInMicrosec();
|
||||
#endif /* TCL_WIDE_CLICKS */
|
||||
|
||||
if (!count) { /* no iterations - avoid divide by zero */
|
||||
objs[0] = objs[2] = objs[4] = Tcl_NewWideIntObj(0);
|
||||
goto retRes;
|
||||
}
|
||||
|
||||
/* if not calibrate */
|
||||
/*
|
||||
* If not calibrating...
|
||||
*/
|
||||
|
||||
if (!calibrate) {
|
||||
/* minimize influence of measurement overhead */
|
||||
/*
|
||||
* Minimize influence of measurement overhead.
|
||||
*/
|
||||
|
||||
if (overhead > 0) {
|
||||
/* estimate the time of overhead (microsecs) */
|
||||
Tcl_WideUInt curOverhead = overhead * count;
|
||||
if (middle > curOverhead) {
|
||||
middle -= curOverhead;
|
||||
/*
|
||||
* Estimate the time of overhead (microsecs).
|
||||
*/
|
||||
|
||||
TclWideMUInt curOverhead = overhead * count;
|
||||
|
||||
if (usec > curOverhead) {
|
||||
usec -= curOverhead;
|
||||
} else {
|
||||
middle = 0;
|
||||
usec = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* calibration - obtaining new measurement overhead */
|
||||
if (measureOverhead > (double)middle / count) {
|
||||
measureOverhead = (double)middle / count;
|
||||
/*
|
||||
* Calibration: obtaining new measurement overhead.
|
||||
*/
|
||||
|
||||
if (measureOverhead > ((double) usec) / count) {
|
||||
measureOverhead = ((double) usec) / count;
|
||||
}
|
||||
objs[0] = Tcl_NewDoubleObj(measureOverhead);
|
||||
TclNewLiteralStringObj(objs[1], "\xC2\xB5s/#-overhead"); /* mics */
|
||||
objs += 2;
|
||||
}
|
||||
|
||||
val = middle / count; /* microsecs per iteration */
|
||||
val = usec / count; /* microsecs per iteration */
|
||||
if (val >= 1000000) {
|
||||
objs[0] = Tcl_NewWideIntObj(val);
|
||||
} else {
|
||||
if (val < 10) { fmt = "%.6f"; } else
|
||||
if (val < 100) { fmt = "%.4f"; } else
|
||||
if (val < 1000) { fmt = "%.3f"; } else
|
||||
if (val < 10000) { fmt = "%.2f"; } else
|
||||
{ fmt = "%.1f"; };
|
||||
objs[0] = Tcl_ObjPrintf(fmt, ((double)middle)/count);
|
||||
if (val < 10) {
|
||||
digits = 6;
|
||||
} else if (val < 100) {
|
||||
digits = 4;
|
||||
} else if (val < 1000) {
|
||||
digits = 3;
|
||||
} else if (val < 10000) {
|
||||
digits = 2;
|
||||
} else {
|
||||
digits = 1;
|
||||
}
|
||||
objs[0] = Tcl_ObjPrintf("%.*f", digits, ((double) usec)/count);
|
||||
}
|
||||
|
||||
objs[2] = Tcl_NewWideIntObj(count); /* iterations */
|
||||
|
||||
/* calculate speed as rate (count) per sec */
|
||||
if (!middle) middle++; /* +1 ms, just to avoid divide by zero */
|
||||
|
||||
/*
|
||||
* Calculate speed as rate (count) per sec
|
||||
*/
|
||||
|
||||
if (!usec) {
|
||||
usec++; /* Avoid divide by zero. */
|
||||
}
|
||||
if (count < (WIDE_MAX / 1000000)) {
|
||||
val = (count * 1000000) / middle;
|
||||
val = (count * 1000000) / usec;
|
||||
if (val < 100000) {
|
||||
if (val < 100) { fmt = "%.3f"; } else
|
||||
if (val < 1000) { fmt = "%.2f"; } else
|
||||
{ fmt = "%.1f"; };
|
||||
objs[4] = Tcl_ObjPrintf(fmt, ((double)(count * 1000000)) / middle);
|
||||
if (val < 100) {
|
||||
digits = 3;
|
||||
} else if (val < 1000) {
|
||||
digits = 2;
|
||||
} else {
|
||||
digits = 1;
|
||||
}
|
||||
objs[4] = Tcl_ObjPrintf("%.*f",
|
||||
digits, ((double) (count * 1000000)) / usec);
|
||||
} else {
|
||||
objs[4] = Tcl_NewWideIntObj(val);
|
||||
}
|
||||
} else {
|
||||
objs[4] = Tcl_NewWideIntObj((count / middle) * 1000000);
|
||||
objs[4] = Tcl_NewWideIntObj((count / usec) * 1000000);
|
||||
}
|
||||
|
||||
retRes:
|
||||
/* estimated net execution time (in millisecs) */
|
||||
/*
|
||||
* Estimated net execution time (in millisecs).
|
||||
*/
|
||||
|
||||
if (!calibrate) {
|
||||
if (middle >= 1) {
|
||||
objs[6] = Tcl_ObjPrintf("%.3f", (double)middle / 1000);
|
||||
if (usec >= 1) {
|
||||
objs[6] = Tcl_ObjPrintf("%.3f", (double)usec / 1000);
|
||||
} else {
|
||||
objs[6] = Tcl_NewWideIntObj(0);
|
||||
}
|
||||
TclNewLiteralStringObj(objs[7], "nett-ms");
|
||||
TclNewLiteralStringObj(objs[7], "net-ms");
|
||||
}
|
||||
|
||||
/*
|
||||
* Construct the result as a list because many programs have always parsed
|
||||
* as such (extracting the first element, typically).
|
||||
*/
|
||||
* Construct the result as a list because many programs have always
|
||||
* parsed as such (extracting the first element, typically).
|
||||
*/
|
||||
|
||||
TclNewLiteralStringObj(objs[1], "\xC2\xB5s/#"); /* mics/# */
|
||||
TclNewLiteralStringObj(objs[3], "#");
|
||||
@@ -4332,12 +4490,15 @@ usage:
|
||||
Tcl_SetObjResult(interp, Tcl_NewListObj(8, objarr));
|
||||
}
|
||||
|
||||
done:
|
||||
|
||||
done:
|
||||
if (codePtr != NULL) {
|
||||
if ( codeOptimized
|
||||
&& codePtr->codeStart[codePtr->numCodeBytes-1] == INST_CONTINUE
|
||||
) {
|
||||
codePtr->codeStart[codePtr->numCodeBytes-1] = INST_DONE;
|
||||
}
|
||||
TclReleaseByteCode(codePtr);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
+35
-155
@@ -1361,7 +1361,7 @@ FreeExprCodeInternalRep(
|
||||
|
||||
ByteCode *
|
||||
TclCompileObj(
|
||||
Tcl_Interp *interp,
|
||||
Tcl_Interp *interp,
|
||||
Tcl_Obj *objPtr,
|
||||
const CmdFrame *invoker,
|
||||
int word)
|
||||
@@ -4938,33 +4938,30 @@ TclExecuteByteCode(
|
||||
}
|
||||
#endif
|
||||
{
|
||||
mp_int big2;
|
||||
mp_int big1, big2;
|
||||
|
||||
Tcl_TakeBignumFromObj(NULL, value2Ptr, &big2);
|
||||
|
||||
/* TODO: internals intrusion */
|
||||
if ((l1 > 0) ^ (big2.sign == MP_ZPOS)) {
|
||||
if ((l1 > 0) ^ mp_isneg(&big2)) {
|
||||
/*
|
||||
* Arguments are opposite sign; remainder is sum.
|
||||
* Arguments are same sign; remainder is first operand.
|
||||
*/
|
||||
|
||||
mp_int big1;
|
||||
|
||||
TclBNInitBignumFromLong(&big1, l1);
|
||||
mp_add(&big2, &big1, &big2);
|
||||
mp_clear(&big1);
|
||||
objResultPtr = Tcl_NewBignumObj(&big2);
|
||||
TRACE(("%s\n", O2S(objResultPtr)));
|
||||
NEXT_INST_F(1, 2, 1);
|
||||
mp_clear(&big2);
|
||||
TRACE(("%s\n", O2S(valuePtr)));
|
||||
NEXT_INST_F(1, 1, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Arguments are same sign; remainder is first operand.
|
||||
* Arguments are opposite sign; remainder is sum.
|
||||
*/
|
||||
|
||||
mp_clear(&big2);
|
||||
TRACE(("%s\n", O2S(valuePtr)));
|
||||
NEXT_INST_F(1, 1, 0);
|
||||
TclBNInitBignumFromLong(&big1, l1);
|
||||
mp_add(&big2, &big1, &big2);
|
||||
mp_clear(&big1);
|
||||
objResultPtr = Tcl_NewBignumObj(&big2);
|
||||
TRACE(("%s\n", O2S(objResultPtr)));
|
||||
NEXT_INST_F(1, 2, 1);
|
||||
}
|
||||
}
|
||||
#ifndef NO_WIDE_TYPE
|
||||
@@ -4995,32 +4992,31 @@ TclExecuteByteCode(
|
||||
NEXT_INST_F(1, 2, 1);
|
||||
}
|
||||
{
|
||||
mp_int big2;
|
||||
mp_int big1, big2;
|
||||
|
||||
Tcl_TakeBignumFromObj(NULL, value2Ptr, &big2);
|
||||
|
||||
/* TODO: internals intrusion */
|
||||
if ((w1 > ((Tcl_WideInt) 0)) ^ (big2.sign == MP_ZPOS)) {
|
||||
if ((w1 > ((Tcl_WideInt) 0)) ^ mp_isneg(&big2)) {
|
||||
/*
|
||||
* Arguments are opposite sign; remainder is sum.
|
||||
* Arguments are same sign; remainder is first operand.
|
||||
*/
|
||||
|
||||
mp_int big1;
|
||||
|
||||
TclBNInitBignumFromWideInt(&big1, w1);
|
||||
mp_add(&big2, &big1, &big2);
|
||||
mp_clear(&big1);
|
||||
objResultPtr = Tcl_NewBignumObj(&big2);
|
||||
TRACE(("%s\n", O2S(objResultPtr)));
|
||||
NEXT_INST_F(1, 2, 1);
|
||||
mp_clear(&big2);
|
||||
TRACE(("%s\n", O2S(valuePtr)));
|
||||
NEXT_INST_F(1, 1, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Arguments are same sign; remainder is first operand.
|
||||
* Arguments are opposite sign; remainder is sum.
|
||||
*/
|
||||
|
||||
mp_clear(&big2);
|
||||
TRACE(("%s\n", O2S(valuePtr)));
|
||||
NEXT_INST_F(1, 1, 0);
|
||||
TclBNInitBignumFromWideInt(&big1, w1);
|
||||
mp_add(&big2, &big1, &big2);
|
||||
mp_clear(&big1);
|
||||
objResultPtr = Tcl_NewBignumObj(&big2);
|
||||
TRACE(("%s\n", O2S(objResultPtr)));
|
||||
NEXT_INST_F(1, 2, 1);
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -5033,7 +5029,7 @@ TclExecuteByteCode(
|
||||
mp_init(&bigRemainder);
|
||||
mp_div(&big1, &big2, &bigResult, &bigRemainder);
|
||||
if (!mp_iszero(&bigRemainder)
|
||||
&& (bigRemainder.sign != big2.sign)) {
|
||||
&& (mp_isneg(&bigRemainder) != mp_isneg(&big2))) {
|
||||
/*
|
||||
* Convert to Tcl's integer division rules.
|
||||
*/
|
||||
@@ -5316,139 +5312,24 @@ TclExecuteByteCode(
|
||||
}
|
||||
|
||||
if ((type1 == TCL_NUMBER_BIG) || (type2 == TCL_NUMBER_BIG)) {
|
||||
mp_int big1, big2, bigResult, *First, *Second;
|
||||
int numPos;
|
||||
mp_int big1, big2, bigResult;
|
||||
|
||||
Tcl_TakeBignumFromObj(NULL, valuePtr, &big1);
|
||||
Tcl_TakeBignumFromObj(NULL, value2Ptr, &big2);
|
||||
|
||||
/*
|
||||
* Count how many positive arguments we have. If only one of the
|
||||
* arguments is negative, store it in 'Second'.
|
||||
*/
|
||||
|
||||
if (mp_cmp_d(&big1, 0) != MP_LT) {
|
||||
numPos = 1 + (mp_cmp_d(&big2, 0) != MP_LT);
|
||||
First = &big1;
|
||||
Second = &big2;
|
||||
} else {
|
||||
First = &big2;
|
||||
Second = &big1;
|
||||
numPos = (mp_cmp_d(First, 0) != MP_LT);
|
||||
}
|
||||
mp_init(&bigResult);
|
||||
|
||||
switch (*pc) {
|
||||
case INST_BITAND:
|
||||
switch (numPos) {
|
||||
case 2:
|
||||
/*
|
||||
* Both arguments positive, base case.
|
||||
*/
|
||||
|
||||
mp_and(First, Second, &bigResult);
|
||||
break;
|
||||
case 1:
|
||||
/*
|
||||
* First is positive; second negative:
|
||||
* P & N = P & ~~N = P&~(-N-1) = P & (P ^ (-N-1))
|
||||
*/
|
||||
|
||||
mp_neg(Second, Second);
|
||||
mp_sub_d(Second, 1, Second);
|
||||
mp_xor(First, Second, &bigResult);
|
||||
mp_and(First, &bigResult, &bigResult);
|
||||
break;
|
||||
case 0:
|
||||
/*
|
||||
* Both arguments negative:
|
||||
* a & b = ~ (~a | ~b) = -(-a-1|-b-1)-1
|
||||
*/
|
||||
|
||||
mp_neg(First, First);
|
||||
mp_sub_d(First, 1, First);
|
||||
mp_neg(Second, Second);
|
||||
mp_sub_d(Second, 1, Second);
|
||||
mp_or(First, Second, &bigResult);
|
||||
mp_neg(&bigResult, &bigResult);
|
||||
mp_sub_d(&bigResult, 1, &bigResult);
|
||||
break;
|
||||
}
|
||||
mp_and(&big1, &big2, &bigResult);
|
||||
break;
|
||||
|
||||
case INST_BITOR:
|
||||
switch (numPos) {
|
||||
case 2:
|
||||
/*
|
||||
* Both arguments positive, base case.
|
||||
*/
|
||||
|
||||
mp_or(First, Second, &bigResult);
|
||||
break;
|
||||
case 1:
|
||||
/*
|
||||
* First is positive; second negative:
|
||||
* N|P = ~(~N&~P) = ~((-N-1)&~P) = -((-N-1)&((-N-1)^P))-1
|
||||
*/
|
||||
|
||||
mp_neg(Second, Second);
|
||||
mp_sub_d(Second, 1, Second);
|
||||
mp_xor(First, Second, &bigResult);
|
||||
mp_and(Second, &bigResult, &bigResult);
|
||||
mp_neg(&bigResult, &bigResult);
|
||||
mp_sub_d(&bigResult, 1, &bigResult);
|
||||
break;
|
||||
case 0:
|
||||
/*
|
||||
* Both arguments negative:
|
||||
* a | b = ~ (~a & ~b) = -(-a-1&-b-1)-1
|
||||
*/
|
||||
|
||||
mp_neg(First, First);
|
||||
mp_sub_d(First, 1, First);
|
||||
mp_neg(Second, Second);
|
||||
mp_sub_d(Second, 1, Second);
|
||||
mp_and(First, Second, &bigResult);
|
||||
mp_neg(&bigResult, &bigResult);
|
||||
mp_sub_d(&bigResult, 1, &bigResult);
|
||||
break;
|
||||
}
|
||||
mp_or(&big1, &big2, &bigResult);
|
||||
break;
|
||||
|
||||
case INST_BITXOR:
|
||||
switch (numPos) {
|
||||
case 2:
|
||||
/*
|
||||
* Both arguments positive, base case.
|
||||
*/
|
||||
|
||||
mp_xor(First, Second, &bigResult);
|
||||
break;
|
||||
case 1:
|
||||
/*
|
||||
* First is positive; second negative:
|
||||
* P^N = ~(P^~N) = -(P^(-N-1))-1
|
||||
*/
|
||||
|
||||
mp_neg(Second, Second);
|
||||
mp_sub_d(Second, 1, Second);
|
||||
mp_xor(First, Second, &bigResult);
|
||||
mp_neg(&bigResult, &bigResult);
|
||||
mp_sub_d(&bigResult, 1, &bigResult);
|
||||
break;
|
||||
case 0:
|
||||
/*
|
||||
* Both arguments negative:
|
||||
* a ^ b = (~a ^ ~b) = (-a-1^-b-1)
|
||||
*/
|
||||
|
||||
mp_neg(First, First);
|
||||
mp_sub_d(First, 1, First);
|
||||
mp_neg(Second, Second);
|
||||
mp_sub_d(Second, 1, Second);
|
||||
mp_xor(First, Second, &bigResult);
|
||||
break;
|
||||
}
|
||||
mp_xor(&big1, &big2, &bigResult);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -6256,9 +6137,8 @@ TclExecuteByteCode(
|
||||
}
|
||||
mp_init(&bigRemainder);
|
||||
mp_div(&big1, &big2, &bigResult, &bigRemainder);
|
||||
/* TODO: internals intrusion */
|
||||
if (!mp_iszero(&bigRemainder)
|
||||
&& (bigRemainder.sign != big2.sign)) {
|
||||
&& (mp_isneg(&bigRemainder) != mp_isneg(&big2))) {
|
||||
/*
|
||||
* Convert to Tcl's integer division rules.
|
||||
*/
|
||||
|
||||
+5
-1
@@ -324,7 +324,10 @@ CreateHashEntry(
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
if (compareKeysProc((VOID *) key, hPtr)) {
|
||||
/* if keys pointers or values are equal */
|
||||
if ((key == hPtr->key.oneWordValue)
|
||||
|| compareKeysProc((VOID *) key, hPtr)
|
||||
) {
|
||||
if (newPtr) {
|
||||
*newPtr = 0;
|
||||
}
|
||||
@@ -850,6 +853,7 @@ AllocStringEntry(
|
||||
allocsize = sizeof(hPtr->key);
|
||||
}
|
||||
hPtr = (Tcl_HashEntry *) ckalloc(sizeof(Tcl_HashEntry) + allocsize - sizeof(hPtr->key));
|
||||
memset(hPtr, 0, sizeof(Tcl_HashEntry) + allocsize - sizeof(hPtr->key));
|
||||
memcpy(hPtr->key.string, string, size);
|
||||
hPtr->clientData = 0;
|
||||
return hPtr;
|
||||
|
||||
+10
-19
@@ -49,7 +49,7 @@
|
||||
#include <string.h>
|
||||
#endif
|
||||
#if defined(STDC_HEADERS) || defined(__STDC__) || defined(__C99__FUNC__) \
|
||||
|| defined(__cplusplus) || defined(_MSC_VER)
|
||||
|| defined(__cplusplus) || defined(_MSC_VER) || defined(__ICC)
|
||||
#include <stddef.h>
|
||||
#else
|
||||
typedef int ptrdiff_t;
|
||||
@@ -2638,6 +2638,8 @@ MODULE_SCOPE int TclMergeReturnOptions(Tcl_Interp *interp, int objc,
|
||||
Tcl_Obj *const objv[], Tcl_Obj **optionsPtrPtr,
|
||||
int *codePtr, int *levelPtr);
|
||||
MODULE_SCOPE int TclNokia770Doubles();
|
||||
MODULE_SCOPE void TclNsDecrRefCount(Namespace *nsPtr);
|
||||
MODULE_SCOPE int TclNamespaceDeleted(Namespace *nsPtr);
|
||||
MODULE_SCOPE void TclObjVarErrMsg(Tcl_Interp *interp, Tcl_Obj *part1Ptr,
|
||||
Tcl_Obj *part2Ptr, const char *operation,
|
||||
const char *reason, int index);
|
||||
@@ -2771,6 +2773,13 @@ MODULE_SCOPE void TclInitThreadStorage(void);
|
||||
MODULE_SCOPE void TclpFinalizeThreadDataThread(void);
|
||||
MODULE_SCOPE void TclFinalizeThreadStorage(void);
|
||||
|
||||
/* TclWideMUInt -- wide integer used for measurement calculations: */
|
||||
#if (!defined(_WIN32) || !defined(_MSC_VER) || (_MSC_VER >= 1400))
|
||||
# define TclWideMUInt Tcl_WideUInt
|
||||
#else
|
||||
/* older MSVS may not allow conversions between unsigned __int64 and double) */
|
||||
# define TclWideMUInt Tcl_WideInt
|
||||
#endif
|
||||
#ifdef TCL_WIDE_CLICKS
|
||||
MODULE_SCOPE Tcl_WideInt TclpGetWideClicks(void);
|
||||
MODULE_SCOPE double TclpWideClicksToNanoseconds(Tcl_WideInt clicks);
|
||||
@@ -3285,39 +3294,21 @@ MODULE_SCOPE int TclDivOpCmd(ClientData clientData,
|
||||
MODULE_SCOPE int TclCompileDivOpCmd(Tcl_Interp *interp,
|
||||
Tcl_Parse *parsePtr, Command *cmdPtr,
|
||||
struct CompileEnv *envPtr);
|
||||
MODULE_SCOPE int TclLessOpCmd(ClientData clientData,
|
||||
Tcl_Interp *interp, int objc,
|
||||
Tcl_Obj *const objv[]);
|
||||
MODULE_SCOPE int TclCompileLessOpCmd(Tcl_Interp *interp,
|
||||
Tcl_Parse *parsePtr, Command *cmdPtr,
|
||||
struct CompileEnv *envPtr);
|
||||
MODULE_SCOPE int TclLeqOpCmd(ClientData clientData,
|
||||
Tcl_Interp *interp, int objc,
|
||||
Tcl_Obj *const objv[]);
|
||||
MODULE_SCOPE int TclCompileLeqOpCmd(Tcl_Interp *interp,
|
||||
Tcl_Parse *parsePtr, Command *cmdPtr,
|
||||
struct CompileEnv *envPtr);
|
||||
MODULE_SCOPE int TclGreaterOpCmd(ClientData clientData,
|
||||
Tcl_Interp *interp, int objc,
|
||||
Tcl_Obj *const objv[]);
|
||||
MODULE_SCOPE int TclCompileGreaterOpCmd(Tcl_Interp *interp,
|
||||
Tcl_Parse *parsePtr, Command *cmdPtr,
|
||||
struct CompileEnv *envPtr);
|
||||
MODULE_SCOPE int TclGeqOpCmd(ClientData clientData,
|
||||
Tcl_Interp *interp, int objc,
|
||||
Tcl_Obj *const objv[]);
|
||||
MODULE_SCOPE int TclCompileGeqOpCmd(Tcl_Interp *interp,
|
||||
Tcl_Parse *parsePtr, Command *cmdPtr,
|
||||
struct CompileEnv *envPtr);
|
||||
MODULE_SCOPE int TclEqOpCmd(ClientData clientData,
|
||||
Tcl_Interp *interp, int objc,
|
||||
Tcl_Obj *const objv[]);
|
||||
MODULE_SCOPE int TclCompileEqOpCmd(Tcl_Interp *interp,
|
||||
Tcl_Parse *parsePtr, Command *cmdPtr,
|
||||
struct CompileEnv *envPtr);
|
||||
MODULE_SCOPE int TclStreqOpCmd(ClientData clientData,
|
||||
Tcl_Interp *interp, int objc,
|
||||
Tcl_Obj *const objv[]);
|
||||
MODULE_SCOPE int TclCompileStreqOpCmd(Tcl_Interp *interp,
|
||||
Tcl_Parse *parsePtr, Command *cmdPtr,
|
||||
struct CompileEnv *envPtr);
|
||||
|
||||
+17
-1
@@ -23,6 +23,7 @@
|
||||
|
||||
typedef struct Link {
|
||||
Tcl_Interp *interp; /* Interpreter containing Tcl variable. */
|
||||
Namespace *nsPtr; /* Namespace containing Tcl variable */
|
||||
Tcl_Obj *varName; /* Name of variable (must be global). This is
|
||||
* needed during trace callbacks, since the
|
||||
* actual variable may be aliased at that time
|
||||
@@ -114,6 +115,8 @@ Tcl_LinkVar(
|
||||
{
|
||||
Tcl_Obj *objPtr;
|
||||
Link *linkPtr;
|
||||
Namespace *dummy;
|
||||
const char *name;
|
||||
int code;
|
||||
|
||||
linkPtr = (Link *) Tcl_VarTraceInfo(interp, varName, TCL_GLOBAL_ONLY,
|
||||
@@ -126,6 +129,7 @@ Tcl_LinkVar(
|
||||
|
||||
linkPtr = (Link *) ckalloc(sizeof(Link));
|
||||
linkPtr->interp = interp;
|
||||
linkPtr->nsPtr = NULL;
|
||||
linkPtr->varName = Tcl_NewStringObj(varName, -1);
|
||||
Tcl_IncrRefCount(linkPtr->varName);
|
||||
linkPtr->addr = addr;
|
||||
@@ -142,11 +146,17 @@ Tcl_LinkVar(
|
||||
ckfree((char *) linkPtr);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
TclGetNamespaceForQualName(interp, varName, NULL, TCL_GLOBAL_ONLY,
|
||||
&(linkPtr->nsPtr), &dummy, &dummy, &name);
|
||||
linkPtr->nsPtr->refCount++;
|
||||
|
||||
code = Tcl_TraceVar(interp, varName, TCL_GLOBAL_ONLY|TCL_TRACE_READS
|
||||
|TCL_TRACE_WRITES|TCL_TRACE_UNSETS, LinkTraceProc,
|
||||
(ClientData) linkPtr);
|
||||
if (code != TCL_OK) {
|
||||
Tcl_DecrRefCount(linkPtr->varName);
|
||||
TclNsDecrRefCount(linkPtr->nsPtr);
|
||||
ckfree((char *) linkPtr);
|
||||
}
|
||||
return code;
|
||||
@@ -186,6 +196,9 @@ Tcl_UnlinkVar(
|
||||
TCL_GLOBAL_ONLY|TCL_TRACE_READS|TCL_TRACE_WRITES|TCL_TRACE_UNSETS,
|
||||
LinkTraceProc, (ClientData) linkPtr);
|
||||
Tcl_DecrRefCount(linkPtr->varName);
|
||||
if (linkPtr->nsPtr) {
|
||||
TclNsDecrRefCount(linkPtr->nsPtr);
|
||||
}
|
||||
ckfree((char *) linkPtr);
|
||||
}
|
||||
|
||||
@@ -279,8 +292,11 @@ LinkTraceProc(
|
||||
*/
|
||||
|
||||
if (flags & TCL_TRACE_UNSETS) {
|
||||
if (Tcl_InterpDeleted(interp)) {
|
||||
if (Tcl_InterpDeleted(interp) || TclNamespaceDeleted(linkPtr->nsPtr)) {
|
||||
Tcl_DecrRefCount(linkPtr->varName);
|
||||
if (linkPtr->nsPtr) {
|
||||
TclNsDecrRefCount(linkPtr->nsPtr);
|
||||
}
|
||||
ckfree((char *) linkPtr);
|
||||
} else if (flags & TCL_TRACE_DESTROYED) {
|
||||
Tcl_ObjSetVar2(interp, linkPtr->varName, NULL, ObjValue(linkPtr),
|
||||
|
||||
@@ -1060,6 +1060,13 @@ Tcl_DeleteNamespace(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
TclNamespaceDeleted(
|
||||
Namespace *nsPtr)
|
||||
{
|
||||
return (nsPtr->flags & NS_DYING) ? 1 : 0;
|
||||
}
|
||||
|
||||
/*
|
||||
*----------------------------------------------------------------------
|
||||
@@ -1237,6 +1244,33 @@ NamespaceFree(
|
||||
ckfree((char *) nsPtr);
|
||||
}
|
||||
|
||||
/*
|
||||
*----------------------------------------------------------------------
|
||||
*
|
||||
* TclNsDecrRefCount --
|
||||
*
|
||||
* Drops a reference to a namespace and frees it if the namespace has
|
||||
* been deleted and the last reference has just been dropped.
|
||||
*
|
||||
* Results:
|
||||
* None.
|
||||
*
|
||||
* Side effects:
|
||||
* None.
|
||||
*
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
void
|
||||
TclNsDecrRefCount(
|
||||
Namespace *nsPtr)
|
||||
{
|
||||
nsPtr->refCount--;
|
||||
if ((nsPtr->refCount == 0) && (nsPtr->flags & NS_DEAD)) {
|
||||
NamespaceFree(nsPtr);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
*----------------------------------------------------------------------
|
||||
*
|
||||
|
||||
+15
-16
@@ -189,7 +189,7 @@ static Tcl_ThreadDataKey pendingObjDataKey;
|
||||
mp_shrink(&(bignum)); \
|
||||
} \
|
||||
(objPtr)->internalRep.ptrAndLongRep.ptr = (void*) (bignum).dp; \
|
||||
(objPtr)->internalRep.ptrAndLongRep.value = ( ((bignum).sign << 30) \
|
||||
(objPtr)->internalRep.ptrAndLongRep.value = ( (mp_isneg(&bignum) << 30) \
|
||||
| ((bignum).alloc << 15) | ((bignum).used)); \
|
||||
}
|
||||
|
||||
@@ -2778,8 +2778,8 @@ Tcl_GetLongFromObj(
|
||||
mp_int big;
|
||||
|
||||
UNPACK_BIGNUM(objPtr, big);
|
||||
if ((size_t)(big.used) <= (CHAR_BIT * sizeof(long) + DIGIT_BIT - 1)
|
||||
/ DIGIT_BIT) {
|
||||
if ((size_t)(big.used) <= (CHAR_BIT * sizeof(long) + MP_DIGIT_BIT - 1)
|
||||
/ MP_DIGIT_BIT) {
|
||||
unsigned long value = 0, numBytes = sizeof(long);
|
||||
long scratch;
|
||||
unsigned char *bytes = (unsigned char *)&scratch;
|
||||
@@ -2787,7 +2787,7 @@ Tcl_GetLongFromObj(
|
||||
while (numBytes-- > 0) {
|
||||
value = (value << CHAR_BIT) | *bytes++;
|
||||
}
|
||||
if (big.sign) {
|
||||
if (mp_isneg(&big)) {
|
||||
*longPtr = - (long) value;
|
||||
} else {
|
||||
*longPtr = (long) value;
|
||||
@@ -3079,7 +3079,7 @@ Tcl_GetWideIntFromObj(
|
||||
|
||||
UNPACK_BIGNUM(objPtr, big);
|
||||
if ((size_t)(big.used) <= (CHAR_BIT * sizeof(Tcl_WideInt)
|
||||
+ DIGIT_BIT - 1) / DIGIT_BIT) {
|
||||
+ MP_DIGIT_BIT - 1) / MP_DIGIT_BIT) {
|
||||
Tcl_WideUInt value = 0;
|
||||
unsigned long numBytes = sizeof(Tcl_WideInt);
|
||||
Tcl_WideInt scratch;
|
||||
@@ -3089,7 +3089,7 @@ Tcl_GetWideIntFromObj(
|
||||
while (numBytes-- > 0) {
|
||||
value = (value << CHAR_BIT) | *bytes++;
|
||||
}
|
||||
if (big.sign) {
|
||||
if (mp_isneg(&big)) {
|
||||
*wideIntPtr = - (Tcl_WideInt) value;
|
||||
} else {
|
||||
*wideIntPtr = (Tcl_WideInt) value;
|
||||
@@ -3498,7 +3498,7 @@ Tcl_SetBignumObj(
|
||||
Tcl_Panic("%s called with shared object", "Tcl_SetBignumObj");
|
||||
}
|
||||
if ((size_t)(bignumValue->used)
|
||||
<= (CHAR_BIT * sizeof(long) + DIGIT_BIT - 1) / DIGIT_BIT) {
|
||||
<= (CHAR_BIT * sizeof(long) + MP_DIGIT_BIT - 1) / MP_DIGIT_BIT) {
|
||||
unsigned long value = 0, numBytes = sizeof(long);
|
||||
long scratch;
|
||||
unsigned char *bytes = (unsigned char *)&scratch;
|
||||
@@ -3508,10 +3508,10 @@ Tcl_SetBignumObj(
|
||||
while (numBytes-- > 0) {
|
||||
value = (value << CHAR_BIT) | *bytes++;
|
||||
}
|
||||
if (value > (((~(unsigned long)0) >> 1) + bignumValue->sign)) {
|
||||
if (value > (((~(unsigned long)0) >> 1) + mp_isneg(bignumValue))) {
|
||||
goto tooLargeForLong;
|
||||
}
|
||||
if (bignumValue->sign) {
|
||||
if (mp_isneg(bignumValue)) {
|
||||
TclSetLongObj(objPtr, -(long)value);
|
||||
} else {
|
||||
TclSetLongObj(objPtr, (long)value);
|
||||
@@ -3522,7 +3522,7 @@ Tcl_SetBignumObj(
|
||||
tooLargeForLong:
|
||||
#ifndef NO_WIDE_TYPE
|
||||
if ((size_t)(bignumValue->used)
|
||||
<= (CHAR_BIT * sizeof(Tcl_WideInt) + DIGIT_BIT - 1) / DIGIT_BIT) {
|
||||
<= (CHAR_BIT * sizeof(Tcl_WideInt) + MP_DIGIT_BIT - 1) / MP_DIGIT_BIT) {
|
||||
Tcl_WideUInt value = 0;
|
||||
unsigned long numBytes = sizeof(Tcl_WideInt);
|
||||
Tcl_WideInt scratch;
|
||||
@@ -3533,10 +3533,10 @@ Tcl_SetBignumObj(
|
||||
while (numBytes-- > 0) {
|
||||
value = (value << CHAR_BIT) | *bytes++;
|
||||
}
|
||||
if (value > (((~(Tcl_WideUInt)0) >> 1) + bignumValue->sign)) {
|
||||
if (value > (((~(Tcl_WideUInt)0) >> 1) + mp_isneg(bignumValue))) {
|
||||
goto tooLargeForWide;
|
||||
}
|
||||
if (bignumValue->sign) {
|
||||
if (mp_isneg(bignumValue)) {
|
||||
TclSetWideIntObj(objPtr, -(Tcl_WideInt)value);
|
||||
} else {
|
||||
TclSetWideIntObj(objPtr, (Tcl_WideInt)value);
|
||||
@@ -3921,11 +3921,10 @@ TclCompareObjKeys(
|
||||
|
||||
/*
|
||||
* If the object pointers are the same then they match.
|
||||
*/
|
||||
* OPT: this comparison was moved to the caller
|
||||
|
||||
if (objPtr1 == objPtr2) {
|
||||
return 1;
|
||||
}
|
||||
if (objPtr1 == objPtr2) return 1;
|
||||
*/
|
||||
|
||||
/*
|
||||
* Don't use Tcl_GetStringFromObj as it would prevent l1 and l2 being
|
||||
|
||||
+45
-45
@@ -129,7 +129,7 @@ typedef unsigned int fpu_control_t __attribute__ ((__mode__ (__HI__)));
|
||||
/* Highest power of two that is greater than
|
||||
* DBL_MAX_10_EXP, divided by 16 */
|
||||
#define DIGIT_GROUP 8
|
||||
/* floor(DIGIT_BIT*log(2)/log(10)) */
|
||||
/* floor(MP_DIGIT_BIT*log(2)/log(10)) */
|
||||
|
||||
/* Union used to dismantle floating point numbers. */
|
||||
|
||||
@@ -1447,9 +1447,9 @@ AccumulateDecimalDigit(
|
||||
* More than single digit multiplication. Multiply by the appropriate
|
||||
* small powers of 5, and then shift. Large strings of zeroes are
|
||||
* eaten 256 at a time; this is less efficient than it could be, but
|
||||
* seems implausible. We presume that DIGIT_BIT is at least 27. The
|
||||
* seems implausible. We presume that MP_DIGIT_BIT is at least 27. The
|
||||
* first multiplication, by up to 10**7, is done with a one-DIGIT
|
||||
* multiply (this presumes that DIGIT_BIT >= 24).
|
||||
* multiply (this presumes that MP_DIGIT_BIT >= 24).
|
||||
*/
|
||||
|
||||
n = numZeros + 1;
|
||||
@@ -1833,15 +1833,15 @@ RefineApproximation(
|
||||
*/
|
||||
|
||||
msb = binExponent + M2; /* 1008 */
|
||||
nDigits = msb / DIGIT_BIT + 1;
|
||||
nDigits = msb / MP_DIGIT_BIT + 1;
|
||||
mp_init_size(&twoMv, nDigits);
|
||||
i = (msb % DIGIT_BIT + 1);
|
||||
i = (msb % MP_DIGIT_BIT + 1);
|
||||
twoMv.used = nDigits;
|
||||
significand *= SafeLdExp(1.0, i);
|
||||
while (--nDigits >= 0) {
|
||||
twoMv.dp[nDigits] = (mp_digit) significand;
|
||||
significand -= (mp_digit) significand;
|
||||
significand = SafeLdExp(significand, DIGIT_BIT);
|
||||
significand = SafeLdExp(significand, MP_DIGIT_BIT);
|
||||
}
|
||||
for (i = 0; i <= 8; ++i) {
|
||||
if (M5 & (1 << i)) {
|
||||
@@ -3100,7 +3100,7 @@ StrictInt64Conversion(Double* dPtr,
|
||||
*
|
||||
* Test whether bankers' rounding should round a digit up. Assumption
|
||||
* is made that the denominator of the fraction being tested is
|
||||
* a power of 2**DIGIT_BIT.
|
||||
* a power of 2**MP_DIGIT_BIT.
|
||||
*
|
||||
* Results:
|
||||
* Returns 1 iff the fraction is more than 1/2, or if the fraction
|
||||
@@ -3112,12 +3112,12 @@ StrictInt64Conversion(Double* dPtr,
|
||||
inline static int
|
||||
ShouldBankerRoundUpPowD(mp_int* b,
|
||||
/* Numerator of the fraction */
|
||||
int sd, /* Denominator is 2**(sd*DIGIT_BIT) */
|
||||
int sd, /* Denominator is 2**(sd*MP_DIGIT_BIT) */
|
||||
int isodd)
|
||||
/* 1 if the digit is odd, 0 if even */
|
||||
{
|
||||
int i;
|
||||
static const mp_digit topbit = (1<<(DIGIT_BIT-1));
|
||||
static const mp_digit topbit = (1<<(MP_DIGIT_BIT-1));
|
||||
if (b->used < sd || (b->dp[sd-1] & topbit) == 0) {
|
||||
return 0;
|
||||
}
|
||||
@@ -3153,7 +3153,7 @@ ShouldBankerRoundUpToNextPowD(mp_int* b,
|
||||
mp_int* m,
|
||||
/* Numerator of the rounding tolerance */
|
||||
int sd,
|
||||
/* Common denominator is 2**(sd*DIGIT_BIT) */
|
||||
/* Common denominator is 2**(sd*MP_DIGIT_BIT) */
|
||||
int convType,
|
||||
/* Conversion type: STEELE defeats
|
||||
* round-to-even (Not sure why one wants to
|
||||
@@ -3168,7 +3168,7 @@ ShouldBankerRoundUpToNextPowD(mp_int* b,
|
||||
/*
|
||||
* Compare B and S-m -- which is the same as comparing B+m and S --
|
||||
* which we do by computing b+m and doing a bitwhack compare against
|
||||
* 2**(DIGIT_BIT*sd)
|
||||
* 2**(MP_DIGIT_BIT*sd)
|
||||
*/
|
||||
mp_add(b, m, temp);
|
||||
if (temp->used <= sd) { /* too few digits to be > S */
|
||||
@@ -3200,7 +3200,7 @@ ShouldBankerRoundUpToNextPowD(mp_int* b,
|
||||
* digits that reconverts exactly to the given number, or to
|
||||
* 'ilim' digits if that will yield a shorter result. The denominator
|
||||
* in David Gay's conversion algorithm is known to be a power of
|
||||
* 2**DIGIT_BIT, and hence the division in the main loop may be replaced
|
||||
* 2**MP_DIGIT_BIT, and hence the division in the main loop may be replaced
|
||||
* by a digit shift and mask.
|
||||
*
|
||||
* Results:
|
||||
@@ -3263,7 +3263,7 @@ ShorteningBignumConversionPowD(Double* dPtr,
|
||||
*/
|
||||
|
||||
TclBNInitBignumFromWideUInt(&b, bw);
|
||||
mp_init_set_int(&mminus, 1);
|
||||
mp_init_set(&mminus, 1);
|
||||
MulPow5(&b, b5, &b);
|
||||
mp_mul_2d(&b, b2, &b);
|
||||
|
||||
@@ -3289,7 +3289,7 @@ ShorteningBignumConversionPowD(Double* dPtr,
|
||||
}
|
||||
mp_init(&temp);
|
||||
|
||||
/* Loop through the digits. Do division and mod by s == 2**(sd*DIGIT_BIT)
|
||||
/* Loop through the digits. Do division and mod by s == 2**(sd*MP_DIGIT_BIT)
|
||||
* by mp_digit extraction */
|
||||
|
||||
i = 0;
|
||||
@@ -3396,7 +3396,7 @@ ShorteningBignumConversionPowD(Double* dPtr,
|
||||
* Converts a double-precision number to a fixed-lengt string of
|
||||
* 'ilim' digits (or 'ilim1' if log10(d) has been overestimated.)
|
||||
* The denominator in David Gay's conversion algorithm is known to
|
||||
* be a power of 2**DIGIT_BIT, and hence the division in the main
|
||||
* be a power of 2**MP_DIGIT_BIT, and hence the division in the main
|
||||
* loop may be replaced by a digit shift and mask.
|
||||
*
|
||||
* Results:
|
||||
@@ -3465,7 +3465,7 @@ StrictBignumConversionPowD(Double* dPtr,
|
||||
mp_init(&temp);
|
||||
|
||||
/*
|
||||
* Loop through the digits. Do division and mod by s == 2**(sd*DIGIT_BIT)
|
||||
* Loop through the digits. Do division and mod by s == 2**(sd*MP_DIGIT_BIT)
|
||||
* by mp_digit extraction
|
||||
*/
|
||||
|
||||
@@ -3666,7 +3666,7 @@ ShorteningBignumConversion(Double* dPtr,
|
||||
|
||||
TclBNInitBignumFromWideUInt(&b, bw);
|
||||
mp_mul_2d(&b, b2, &b);
|
||||
mp_init_set_int(&S, 1);
|
||||
mp_init_set(&S, 1);
|
||||
MulPow5(&S, s5, &S); mp_mul_2d(&S, s2, &S);
|
||||
|
||||
/*
|
||||
@@ -3683,7 +3683,7 @@ ShorteningBignumConversion(Double* dPtr,
|
||||
|
||||
/* mminus = 2**m2minus * 5**m5 */
|
||||
|
||||
mp_init_set_int(&mminus, minit);
|
||||
mp_init_set(&mminus, minit);
|
||||
mp_mul_2d(&mminus, m2minus, &mminus);
|
||||
if (m2plus > m2minus) {
|
||||
mp_init_copy(&mplus, &mminus);
|
||||
@@ -3879,7 +3879,7 @@ StrictBignumConversion(Double* dPtr,
|
||||
mp_init_multi(&temp, &dig, NULL);
|
||||
TclBNInitBignumFromWideUInt(&b, bw);
|
||||
mp_mul_2d(&b, b2, &b);
|
||||
mp_init_set_int(&S, 1);
|
||||
mp_init_set(&S, 1);
|
||||
MulPow5(&S, s5, &S); mp_mul_2d(&S, s2, &S);
|
||||
|
||||
/*
|
||||
@@ -4234,12 +4234,12 @@ TclDoubleDigits(double dv, /* Number to convert */
|
||||
/*
|
||||
* The denominator is a power of 2, so we can replace division
|
||||
* by digit shifts. First we round up s2 to a multiple of
|
||||
* DIGIT_BIT, and adjust m2 and b2 accordingly. Then we launch
|
||||
* MP_DIGIT_BIT, and adjust m2 and b2 accordingly. Then we launch
|
||||
* into a version of the comparison that's specialized for
|
||||
* the 'power of mp_digit in the denominator' case.
|
||||
*/
|
||||
if (s2 % DIGIT_BIT != 0) {
|
||||
int delta = DIGIT_BIT - (s2 % DIGIT_BIT);
|
||||
if (s2 % MP_DIGIT_BIT != 0) {
|
||||
int delta = MP_DIGIT_BIT - (s2 % MP_DIGIT_BIT);
|
||||
b2 += delta;
|
||||
m2plus += delta;
|
||||
m2minus += delta;
|
||||
@@ -4247,7 +4247,7 @@ TclDoubleDigits(double dv, /* Number to convert */
|
||||
}
|
||||
return ShorteningBignumConversionPowD(&d, convType, bw, b2, b5,
|
||||
m2plus, m2minus, m5,
|
||||
s2/DIGIT_BIT, k, len,
|
||||
s2/MP_DIGIT_BIT, k, len,
|
||||
ilim, ilim1, decpt, endPtr);
|
||||
} else {
|
||||
|
||||
@@ -4294,17 +4294,17 @@ TclDoubleDigits(double dv, /* Number to convert */
|
||||
/*
|
||||
* The denominator is a power of 2, so we can replace division
|
||||
* by digit shifts. First we round up s2 to a multiple of
|
||||
* DIGIT_BIT, and adjust m2 and b2 accordingly. Then we launch
|
||||
* MP_DIGIT_BIT, and adjust m2 and b2 accordingly. Then we launch
|
||||
* into a version of the comparison that's specialized for
|
||||
* the 'power of mp_digit in the denominator' case.
|
||||
*/
|
||||
if (s2 % DIGIT_BIT != 0) {
|
||||
int delta = DIGIT_BIT - (s2 % DIGIT_BIT);
|
||||
if (s2 % MP_DIGIT_BIT != 0) {
|
||||
int delta = MP_DIGIT_BIT - (s2 % MP_DIGIT_BIT);
|
||||
b2 += delta;
|
||||
s2 += delta;
|
||||
}
|
||||
return StrictBignumConversionPowD(&d, convType, bw, b2, b5,
|
||||
s2/DIGIT_BIT, k, len,
|
||||
s2/MP_DIGIT_BIT, k, len,
|
||||
ilim, ilim1, decpt, endPtr);
|
||||
} else {
|
||||
/*
|
||||
@@ -4433,7 +4433,7 @@ TclInitDoubleConversion(void)
|
||||
+ 0.5 * log(10.)) / log(10.));
|
||||
minDigits = (int) floor((DBL_MIN_EXP - DBL_MANT_DIG)
|
||||
* log((double) FLT_RADIX) / log(10.));
|
||||
log10_DIGIT_MAX = (int) floor(DIGIT_BIT * log(2.) / log(10.));
|
||||
log10_DIGIT_MAX = (int) floor(MP_DIGIT_BIT * log(2.) / log(10.));
|
||||
|
||||
/*
|
||||
* Nokia 770's software-emulated floating point is "middle endian": the
|
||||
@@ -4573,10 +4573,10 @@ TclBignumToDouble(
|
||||
bits = mp_count_bits(a);
|
||||
if (bits > DBL_MAX_EXP*log2FLT_RADIX) {
|
||||
errno = ERANGE;
|
||||
if (a->sign == MP_ZPOS) {
|
||||
return HUGE_VAL;
|
||||
} else {
|
||||
if (mp_isneg(a)) {
|
||||
return -HUGE_VAL;
|
||||
} else {
|
||||
return HUGE_VAL;
|
||||
}
|
||||
}
|
||||
shift = mantBits - bits;
|
||||
@@ -4606,10 +4606,10 @@ TclBignumToDouble(
|
||||
|
||||
mp_div_2d(a, -shift, &b, NULL);
|
||||
if (mp_isodd(&b)) {
|
||||
if (b.sign == MP_ZPOS) {
|
||||
mp_add_d(&b, 1, &b);
|
||||
} else {
|
||||
if (mp_isneg(&b)) {
|
||||
mp_sub_d(&b, 1, &b);
|
||||
} else {
|
||||
mp_add_d(&b, 1, &b);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -4619,10 +4619,10 @@ TclBignumToDouble(
|
||||
*/
|
||||
|
||||
mp_div_2d(a, -1-shift, &b, NULL);
|
||||
if (b.sign == MP_ZPOS) {
|
||||
mp_add_d(&b, 1, &b);
|
||||
} else {
|
||||
if (mp_isneg(&b)) {
|
||||
mp_sub_d(&b, 1, &b);
|
||||
} else {
|
||||
mp_add_d(&b, 1, &b);
|
||||
}
|
||||
mp_div_2d(&b, 1, &b, NULL);
|
||||
}
|
||||
@@ -4634,7 +4634,7 @@ TclBignumToDouble(
|
||||
|
||||
r = 0.0;
|
||||
for (i=b.used-1 ; i>=0 ; --i) {
|
||||
r = ldexp(r, DIGIT_BIT) + b.dp[i];
|
||||
r = ldexp(r, MP_DIGIT_BIT) + b.dp[i];
|
||||
}
|
||||
mp_clear(&b);
|
||||
|
||||
@@ -4648,10 +4648,10 @@ TclBignumToDouble(
|
||||
* Return the result with the appropriate sign.
|
||||
*/
|
||||
|
||||
if (a->sign == MP_ZPOS) {
|
||||
return r;
|
||||
} else {
|
||||
if (mp_isneg(a)) {
|
||||
return -r;
|
||||
} else {
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4703,7 +4703,7 @@ TclCeil(
|
||||
mp_add_d(&b, 1, &b);
|
||||
}
|
||||
for (i=b.used-1 ; i>=0 ; --i) {
|
||||
r = ldexp(r, DIGIT_BIT) + b.dp[i];
|
||||
r = ldexp(r, MP_DIGIT_BIT) + b.dp[i];
|
||||
}
|
||||
r = ldexp(r, bits - mantBits);
|
||||
}
|
||||
@@ -4753,7 +4753,7 @@ TclFloor(
|
||||
mp_copy(a, &b);
|
||||
}
|
||||
for (i=b.used-1 ; i>=0 ; --i) {
|
||||
r = ldexp(r, DIGIT_BIT) + b.dp[i];
|
||||
r = ldexp(r, MP_DIGIT_BIT) + b.dp[i];
|
||||
}
|
||||
r = ldexp(r, bits - mantBits);
|
||||
}
|
||||
@@ -4815,7 +4815,7 @@ BignumToBiasedFrExp(
|
||||
|
||||
r = 0.0;
|
||||
for (i=b.used-1; i>=0; --i) {
|
||||
r = ldexp(r, DIGIT_BIT) + b.dp[i];
|
||||
r = ldexp(r, MP_DIGIT_BIT) + b.dp[i];
|
||||
}
|
||||
mp_clear(&b);
|
||||
|
||||
@@ -4824,7 +4824,7 @@ BignumToBiasedFrExp(
|
||||
*/
|
||||
|
||||
*machexp = bits - mantBits + 2;
|
||||
return ((a->sign == MP_ZPOS) ? r : -r);
|
||||
return (mp_isneg(a) ? -r : r);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -2093,7 +2093,7 @@ Tcl_AppendFormatToObj(
|
||||
if (Tcl_GetBignumFromObj(interp,segment,&big) != TCL_OK) {
|
||||
goto error;
|
||||
}
|
||||
mp_mod_2d(&big, (int) CHAR_BIT*sizeof(Tcl_WideInt), &big);
|
||||
mp_mod_2d(&big, CHAR_BIT*sizeof(Tcl_WideInt), &big);
|
||||
objPtr = Tcl_NewBignumObj(&big);
|
||||
Tcl_IncrRefCount(objPtr);
|
||||
Tcl_GetWideIntFromObj(NULL, objPtr, &w);
|
||||
@@ -2107,7 +2107,7 @@ Tcl_AppendFormatToObj(
|
||||
if (Tcl_GetBignumFromObj(interp,segment,&big) != TCL_OK) {
|
||||
goto error;
|
||||
}
|
||||
mp_mod_2d(&big, (int) CHAR_BIT * sizeof(long), &big);
|
||||
mp_mod_2d(&big, CHAR_BIT * sizeof(long), &big);
|
||||
objPtr = Tcl_NewBignumObj(&big);
|
||||
Tcl_IncrRefCount(objPtr);
|
||||
TclGetLongFromObj(NULL, objPtr, &l);
|
||||
@@ -2251,11 +2251,11 @@ Tcl_AppendFormatToObj(
|
||||
uw /= base;
|
||||
}
|
||||
} else if (useBig && big.used) {
|
||||
int leftover = (big.used * DIGIT_BIT) % numBits;
|
||||
mp_digit mask = (~(mp_digit)0) << (DIGIT_BIT-leftover);
|
||||
int leftover = (big.used * MP_DIGIT_BIT) % numBits;
|
||||
mp_digit mask = (~(mp_digit)0) << (MP_DIGIT_BIT-leftover);
|
||||
|
||||
numDigits = 1 +
|
||||
(((Tcl_WideInt)big.used * DIGIT_BIT) / numBits);
|
||||
(((Tcl_WideInt)big.used * MP_DIGIT_BIT) / numBits);
|
||||
while ((mask & big.dp[big.used-1]) == 0) {
|
||||
numDigits--;
|
||||
mask >>= numBits;
|
||||
@@ -2290,9 +2290,9 @@ Tcl_AppendFormatToObj(
|
||||
|
||||
if (useBig && big.used) {
|
||||
if (index < big.used && (size_t) shift <
|
||||
CHAR_BIT*sizeof(Tcl_WideUInt) - DIGIT_BIT) {
|
||||
CHAR_BIT*sizeof(Tcl_WideUInt) - MP_DIGIT_BIT) {
|
||||
bits |= (((Tcl_WideUInt)big.dp[index++]) <<shift);
|
||||
shift += DIGIT_BIT;
|
||||
shift += MP_DIGIT_BIT;
|
||||
}
|
||||
shift -= numBits;
|
||||
}
|
||||
|
||||
+1
-1
@@ -4326,7 +4326,7 @@ TesttranslatefilenameCmd(
|
||||
*
|
||||
* TestupvarCmd --
|
||||
*
|
||||
* This procedure implements the "testupvar2" command. It is used
|
||||
* This procedure implements the "testupvar" command. It is used
|
||||
* to test Tcl_UpVar and Tcl_UpVar2.
|
||||
*
|
||||
* Results:
|
||||
|
||||
@@ -269,9 +269,9 @@ TestbignumobjCmd(
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if (!Tcl_IsShared(varPtr[varIndex])) {
|
||||
Tcl_SetIntObj(varPtr[varIndex], mp_iseven(&bignumValue));
|
||||
Tcl_SetIntObj(varPtr[varIndex], !mp_isodd(&bignumValue));
|
||||
} else {
|
||||
SetVarToObj(varIndex, Tcl_NewIntObj(mp_iseven(&bignumValue)));
|
||||
SetVarToObj(varIndex, Tcl_NewIntObj(!mp_isodd(&bignumValue)));
|
||||
}
|
||||
mp_clear(&bignumValue);
|
||||
break;
|
||||
|
||||
+71
-71
@@ -1,9 +1,8 @@
|
||||
# tclTomMath.decls --
|
||||
#
|
||||
# This file contains the declarations for the functions in
|
||||
# 'libtommath' that are contained within the Tcl library.
|
||||
# This file is used to generate the 'tclTomMathDecls.h' and
|
||||
# 'tclStubInit.c' files.
|
||||
# This file contains the declarations for the functions in 'libtommath'
|
||||
# that are contained within the Tcl library. This file is used to
|
||||
# generate the 'tclTomMathDecls.h' and 'tclStubInit.c' files.
|
||||
#
|
||||
# If you edit this file, advance the revision number (and the epoch
|
||||
# if the new stubs are not backward compatible) in tclTomMathDecls.h
|
||||
@@ -19,196 +18,197 @@ library tcl
|
||||
|
||||
interface tclTomMath
|
||||
# hooks {tclTomMathInt}
|
||||
scspec EXTERN
|
||||
|
||||
# Declare each of the functions in the Tcl tommath interface
|
||||
|
||||
declare 0 generic {
|
||||
declare 0 {
|
||||
int TclBN_epoch(void)
|
||||
}
|
||||
declare 1 generic {
|
||||
declare 1 {
|
||||
int TclBN_revision(void)
|
||||
}
|
||||
|
||||
declare 2 generic {
|
||||
declare 2 {
|
||||
int TclBN_mp_add(mp_int *a, mp_int *b, mp_int *c)
|
||||
}
|
||||
declare 3 generic {
|
||||
declare 3 {
|
||||
int TclBN_mp_add_d(mp_int *a, mp_digit b, mp_int *c)
|
||||
}
|
||||
declare 4 generic {
|
||||
int TclBN_mp_and(mp_int *a, mp_int *b, mp_int *c)
|
||||
declare 4 {
|
||||
int TclBN_mp_and(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
}
|
||||
declare 5 generic {
|
||||
declare 5 {
|
||||
void TclBN_mp_clamp(mp_int *a)
|
||||
}
|
||||
declare 6 generic {
|
||||
declare 6 {
|
||||
void TclBN_mp_clear(mp_int *a)
|
||||
}
|
||||
declare 7 generic {
|
||||
declare 7 {
|
||||
void TclBN_mp_clear_multi(mp_int *a, ...)
|
||||
}
|
||||
declare 8 generic {
|
||||
int TclBN_mp_cmp(mp_int *a, mp_int *b)
|
||||
declare 8 {
|
||||
int TclBN_mp_cmp(const mp_int *a, const mp_int *b)
|
||||
}
|
||||
declare 9 generic {
|
||||
int TclBN_mp_cmp_d(mp_int *a, mp_digit b)
|
||||
declare 9 {
|
||||
int TclBN_mp_cmp_d(const mp_int *a, mp_digit b)
|
||||
}
|
||||
declare 10 generic {
|
||||
int TclBN_mp_cmp_mag(mp_int *a, mp_int *b)
|
||||
declare 10 {
|
||||
int TclBN_mp_cmp_mag(const mp_int *a, const mp_int *b)
|
||||
}
|
||||
declare 11 generic {
|
||||
declare 11 {
|
||||
int TclBN_mp_copy(mp_int *a, mp_int *b)
|
||||
}
|
||||
declare 12 generic {
|
||||
declare 12 {
|
||||
int TclBN_mp_count_bits(mp_int *a)
|
||||
}
|
||||
declare 13 generic {
|
||||
declare 13 {
|
||||
int TclBN_mp_div(mp_int *a, mp_int *b, mp_int *q, mp_int *r)
|
||||
}
|
||||
declare 14 generic {
|
||||
declare 14 {
|
||||
int TclBN_mp_div_d(mp_int *a, mp_digit b, mp_int *q, mp_digit *r)
|
||||
}
|
||||
declare 15 generic {
|
||||
declare 15 {
|
||||
int TclBN_mp_div_2(mp_int *a, mp_int *q)
|
||||
}
|
||||
declare 16 generic {
|
||||
declare 16 {
|
||||
int TclBN_mp_div_2d(mp_int *a, int b, mp_int *q, mp_int *r)
|
||||
}
|
||||
declare 17 generic {
|
||||
declare 17 {
|
||||
int TclBN_mp_div_3(mp_int *a, mp_int *q, mp_digit *r)
|
||||
}
|
||||
declare 18 generic {
|
||||
declare 18 {
|
||||
void TclBN_mp_exch(mp_int *a, mp_int *b)
|
||||
}
|
||||
declare 19 generic {
|
||||
declare 19 {
|
||||
int TclBN_mp_expt_d(mp_int *a, mp_digit b, mp_int *c)
|
||||
}
|
||||
declare 20 generic {
|
||||
declare 20 {
|
||||
int TclBN_mp_grow(mp_int *a, int size)
|
||||
}
|
||||
declare 21 generic {
|
||||
declare 21 {
|
||||
int TclBN_mp_init(mp_int *a)
|
||||
}
|
||||
declare 22 generic {
|
||||
declare 22 {
|
||||
int TclBN_mp_init_copy(mp_int *a, mp_int *b)
|
||||
}
|
||||
declare 23 generic {
|
||||
declare 23 {
|
||||
int TclBN_mp_init_multi(mp_int *a, ...)
|
||||
}
|
||||
declare 24 generic {
|
||||
declare 24 {
|
||||
int TclBN_mp_init_set(mp_int *a, mp_digit b)
|
||||
}
|
||||
declare 25 generic {
|
||||
declare 25 {
|
||||
int TclBN_mp_init_size(mp_int *a, int size)
|
||||
}
|
||||
declare 26 generic {
|
||||
declare 26 {
|
||||
int TclBN_mp_lshd(mp_int *a, int shift)
|
||||
}
|
||||
declare 27 generic {
|
||||
declare 27 {
|
||||
int TclBN_mp_mod(mp_int *a, mp_int *b, mp_int *r)
|
||||
}
|
||||
declare 28 generic {
|
||||
declare 28 {
|
||||
int TclBN_mp_mod_2d(mp_int *a, int b, mp_int *r)
|
||||
}
|
||||
declare 29 generic {
|
||||
declare 29 {
|
||||
int TclBN_mp_mul(mp_int *a, mp_int *b, mp_int *p)
|
||||
}
|
||||
declare 30 generic {
|
||||
declare 30 {
|
||||
int TclBN_mp_mul_d(mp_int *a, mp_digit b, mp_int *p)
|
||||
}
|
||||
declare 31 generic {
|
||||
declare 31 {
|
||||
int TclBN_mp_mul_2(mp_int *a, mp_int *p)
|
||||
}
|
||||
declare 32 generic {
|
||||
declare 32 {
|
||||
int TclBN_mp_mul_2d(mp_int *a, int d, mp_int *p)
|
||||
}
|
||||
declare 33 generic {
|
||||
declare 33 {
|
||||
int TclBN_mp_neg(mp_int *a, mp_int *b)
|
||||
}
|
||||
declare 34 generic {
|
||||
int TclBN_mp_or(mp_int *a, mp_int *b, mp_int *c)
|
||||
declare 34 {
|
||||
int TclBN_mp_or(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
}
|
||||
declare 35 generic {
|
||||
declare 35 {
|
||||
int TclBN_mp_radix_size(mp_int *a, int radix, int *size)
|
||||
}
|
||||
declare 36 generic {
|
||||
declare 36 {
|
||||
int TclBN_mp_read_radix(mp_int *a, const char *str, int radix)
|
||||
}
|
||||
declare 37 generic {
|
||||
declare 37 {
|
||||
void TclBN_mp_rshd(mp_int *a, int shift)
|
||||
}
|
||||
declare 38 generic {
|
||||
declare 38 {
|
||||
int TclBN_mp_shrink(mp_int *a)
|
||||
}
|
||||
declare 39 generic {
|
||||
declare 39 {
|
||||
void TclBN_mp_set(mp_int *a, mp_digit b)
|
||||
}
|
||||
declare 40 generic {
|
||||
declare 40 {
|
||||
int TclBN_mp_sqr(mp_int *a, mp_int *b)
|
||||
}
|
||||
declare 41 generic {
|
||||
declare 41 {
|
||||
int TclBN_mp_sqrt(mp_int *a, mp_int *b)
|
||||
}
|
||||
declare 42 generic {
|
||||
declare 42 {
|
||||
int TclBN_mp_sub(mp_int *a, mp_int *b, mp_int *c)
|
||||
}
|
||||
declare 43 generic {
|
||||
declare 43 {
|
||||
int TclBN_mp_sub_d(mp_int *a, mp_digit b, mp_int *c)
|
||||
}
|
||||
declare 44 generic {
|
||||
declare 44 {
|
||||
int TclBN_mp_to_unsigned_bin(mp_int *a, unsigned char *b)
|
||||
}
|
||||
declare 45 generic {
|
||||
declare 45 {
|
||||
int TclBN_mp_to_unsigned_bin_n(mp_int *a, unsigned char *b,
|
||||
unsigned long *outlen)
|
||||
}
|
||||
declare 46 generic {
|
||||
declare 46 {
|
||||
int TclBN_mp_toradix_n(mp_int *a, char *str, int radix, int maxlen)
|
||||
}
|
||||
declare 47 generic {
|
||||
declare 47 {
|
||||
int TclBN_mp_unsigned_bin_size(mp_int *a)
|
||||
}
|
||||
declare 48 generic {
|
||||
int TclBN_mp_xor(mp_int *a, mp_int *b, mp_int *c)
|
||||
declare 48 {
|
||||
int TclBN_mp_xor(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
}
|
||||
declare 49 generic {
|
||||
declare 49 {
|
||||
void TclBN_mp_zero(mp_int *a)
|
||||
}
|
||||
|
||||
# internal routines to libtommath - should not be called but must be
|
||||
# exported to accommodate the "tommath" extension
|
||||
|
||||
declare 50 generic {
|
||||
declare 50 {
|
||||
void TclBN_reverse(unsigned char *s, int len)
|
||||
}
|
||||
declare 51 generic {
|
||||
declare 51 {
|
||||
int TclBN_fast_s_mp_mul_digs(mp_int *a, mp_int *b, mp_int *c, int digs)
|
||||
}
|
||||
declare 52 generic {
|
||||
declare 52 {
|
||||
int TclBN_fast_s_mp_sqr(mp_int *a, mp_int *b)
|
||||
}
|
||||
declare 53 generic {
|
||||
declare 53 {
|
||||
int TclBN_mp_karatsuba_mul(mp_int *a, mp_int *b, mp_int *c)
|
||||
}
|
||||
declare 54 generic {
|
||||
declare 54 {
|
||||
int TclBN_mp_karatsuba_sqr(mp_int *a, mp_int *b)
|
||||
}
|
||||
declare 55 generic {
|
||||
declare 55 {
|
||||
int TclBN_mp_toom_mul(mp_int *a, mp_int *b, mp_int *c)
|
||||
}
|
||||
declare 56 generic {
|
||||
declare 56 {
|
||||
int TclBN_mp_toom_sqr(mp_int *a, mp_int *b)
|
||||
}
|
||||
declare 57 generic {
|
||||
declare 57 {
|
||||
int TclBN_s_mp_add(mp_int *a, mp_int *b, mp_int *c)
|
||||
}
|
||||
declare 58 generic {
|
||||
declare 58 {
|
||||
int TclBN_s_mp_mul_digs(mp_int *a, mp_int *b, mp_int *c, int digs)
|
||||
}
|
||||
declare 59 generic {
|
||||
declare 59 {
|
||||
int TclBN_s_mp_sqr(mp_int *a, mp_int *b)
|
||||
}
|
||||
declare 60 generic {
|
||||
declare 60 {
|
||||
int TclBN_s_mp_sub(mp_int *a, mp_int *b, mp_int *c)
|
||||
}
|
||||
declare 61 {
|
||||
|
||||
+88
-51
@@ -1,17 +1,6 @@
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis
|
||||
*
|
||||
* LibTomMath is a library that provides multiple-precision
|
||||
* integer arithmetic as well as number theoretic functionality.
|
||||
*
|
||||
* The library was designed directly after the MPI library by
|
||||
* Michael Fromberger but has been written from scratch with
|
||||
* additional optimizations in place.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
#ifndef BN_H_
|
||||
#define BN_H_
|
||||
|
||||
@@ -148,30 +137,31 @@ extern "C" {
|
||||
#define MP_MASK ((((mp_digit)1)<<((mp_digit)DIGIT_BIT))-((mp_digit)1))
|
||||
#define MP_DIGIT_MAX MP_MASK
|
||||
|
||||
/* equalities */
|
||||
typedef int mp_sign;
|
||||
#define MP_ZPOS 0 /* positive integer */
|
||||
#define MP_NEG 1 /* negative */
|
||||
typedef int mp_ord;
|
||||
#define MP_LT -1 /* less than */
|
||||
#define MP_EQ 0 /* equal to */
|
||||
#define MP_GT 1 /* greater than */
|
||||
|
||||
#define MP_ZPOS 0 /* positive integer */
|
||||
#define MP_NEG 1 /* negative */
|
||||
|
||||
typedef int mp_bool;
|
||||
#define MP_YES 1 /* yes response */
|
||||
#define MP_NO 0 /* no response */
|
||||
typedef int mp_err;
|
||||
#define MP_OKAY 0 /* ok result */
|
||||
#define MP_ERR -1 /* unknown error */
|
||||
#define MP_MEM -2 /* out of mem */
|
||||
#define MP_VAL -3 /* invalid input */
|
||||
#define MP_RANGE MP_VAL
|
||||
|
||||
#define MP_YES 1 /* yes response */
|
||||
#define MP_NO 0 /* no response */
|
||||
#define MP_ITER -4 /* Max. iterations reached */
|
||||
|
||||
/* Primality generation flags */
|
||||
#define LTM_PRIME_BBS 0x0001 /* BBS style prime */
|
||||
#define LTM_PRIME_SAFE 0x0002 /* Safe prime (p-1)/2 == prime */
|
||||
#define LTM_PRIME_2MSB_ON 0x0008 /* force 2nd MSB to 1 */
|
||||
|
||||
typedef int mp_err;
|
||||
/* tunable cutoffs */
|
||||
|
||||
/* you'll have to tune these... */
|
||||
#if defined(BUILD_tcl) || !defined(_WIN32)
|
||||
MODULE_SCOPE int KARATSUBA_MUL_CUTOFF,
|
||||
KARATSUBA_SQR_CUTOFF,
|
||||
@@ -184,16 +174,57 @@ MODULE_SCOPE int KARATSUBA_MUL_CUTOFF,
|
||||
|
||||
/* default precision */
|
||||
#ifndef MP_PREC
|
||||
#ifndef MP_LOW_MEM
|
||||
#define MP_PREC 32 /* default digits of precision */
|
||||
#else
|
||||
#define MP_PREC 8 /* default digits of precision */
|
||||
#endif
|
||||
# ifndef MP_LOW_MEM
|
||||
# define MP_PREC 32 /* default digits of precision */
|
||||
# elif defined(MP_8BIT)
|
||||
# define MP_PREC 16 /* default digits of precision */
|
||||
# else
|
||||
# define MP_PREC 8 /* default digits of precision */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* size of comba arrays, should be at least 2 * 2**(BITS_PER_WORD - BITS_PER_DIGIT*2) */
|
||||
#define MP_WARRAY (1 << (sizeof(mp_word) * CHAR_BIT - 2 * DIGIT_BIT + 1))
|
||||
|
||||
/*
|
||||
* MP_WUR - warn unused result
|
||||
* ---------------------------
|
||||
*
|
||||
* The result of functions annotated with MP_WUR must be
|
||||
* checked and cannot be ignored.
|
||||
*
|
||||
* Most functions in libtommath return an error code.
|
||||
* This error code must be checked in order to prevent crashes or invalid
|
||||
* results.
|
||||
*
|
||||
* If you still want to avoid the error checks for quick and dirty programs
|
||||
* without robustness guarantees, you can `#define MP_WUR` before including
|
||||
* tommath.h, disabling the warnings.
|
||||
*/
|
||||
#ifndef MP_WUR
|
||||
# if defined(__GNUC__) && __GNUC__ >= 4
|
||||
# define MP_WUR __attribute__((warn_unused_result))
|
||||
# else
|
||||
# define MP_WUR
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 301)
|
||||
# define MP_DEPRECATED(x) __attribute__((deprecated("replaced by " #x)))
|
||||
# define PRIVATE_MP_DEPRECATED_PRAGMA(s) _Pragma(#s)
|
||||
# define MP_DEPRECATED_PRAGMA(s) PRIVATE_MP_DEPRECATED_PRAGMA(GCC warning s)
|
||||
#elif defined(_MSC_VER) && _MSC_VER >= 1500
|
||||
# define MP_DEPRECATED(x) __declspec(deprecated("replaced by " #x))
|
||||
# define MP_DEPRECATED_PRAGMA(s) __pragma(message(s))
|
||||
#else
|
||||
# define MP_DEPRECATED
|
||||
# define MP_DEPRECATED_PRAGMA(s)
|
||||
#endif
|
||||
|
||||
#define USED(m) ((m)->used)
|
||||
#define DIGIT(m,k) ((m)->dp[(k)])
|
||||
#define SIGN(m) ((m)->sign)
|
||||
|
||||
/* the infamous mp_int structure */
|
||||
#ifndef MP_INT_DECLARED
|
||||
#define MP_INT_DECLARED
|
||||
@@ -208,19 +239,15 @@ struct mp_int {
|
||||
typedef int ltm_prime_callback(unsigned char *dst, int len, void *dat);
|
||||
|
||||
|
||||
#define USED(m) ((m)->used)
|
||||
#define DIGIT(m,k) ((m)->dp[(k)])
|
||||
#define SIGN(m) ((m)->sign)
|
||||
|
||||
/* error code to char* string */
|
||||
/*
|
||||
char *mp_error_to_string(int code);
|
||||
const char *mp_error_to_string(mp_err code);
|
||||
*/
|
||||
|
||||
/* ---> init and deinit bignum functions <--- */
|
||||
/* init a bignum */
|
||||
/*
|
||||
int mp_init(mp_int *a);
|
||||
mp_err mp_init(mp_int *a);
|
||||
*/
|
||||
|
||||
/* free a bignum */
|
||||
@@ -230,7 +257,7 @@ void mp_clear(mp_int *a);
|
||||
|
||||
/* init a null terminated series of arguments */
|
||||
/*
|
||||
int mp_init_multi(mp_int *mp, ...);
|
||||
mp_err mp_init_multi(mp_int *mp, ...);
|
||||
*/
|
||||
|
||||
/* clear a null terminated series of arguments */
|
||||
@@ -245,23 +272,24 @@ void mp_exch(mp_int *a, mp_int *b);
|
||||
|
||||
/* shrink ram required for a bignum */
|
||||
/*
|
||||
int mp_shrink(mp_int *a);
|
||||
mp_err mp_shrink(mp_int *a);
|
||||
*/
|
||||
|
||||
/* grow an int to a given size */
|
||||
/*
|
||||
int mp_grow(mp_int *a, int size);
|
||||
mp_err mp_grow(mp_int *a, int size);
|
||||
*/
|
||||
|
||||
/* init to a given number of digits */
|
||||
/*
|
||||
int mp_init_size(mp_int *a, int size);
|
||||
mp_err mp_init_size(mp_int *a, int size);
|
||||
*/
|
||||
|
||||
/* ---> Basic Manipulations <--- */
|
||||
#define mp_iszero(a) (((a)->used == 0) ? MP_YES : MP_NO)
|
||||
#define mp_iseven(a) (((a)->used == 0 || (((a)->dp[0] & 1) == 0)) ? MP_YES : MP_NO)
|
||||
#define mp_isodd(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 1)) ? MP_YES : MP_NO)
|
||||
#define mp_isneg(a) (((a)->sign != MP_ZPOS) ? MP_YES : MP_NO)
|
||||
|
||||
/* set to zero */
|
||||
/*
|
||||
@@ -278,6 +306,16 @@ void mp_set(mp_int *a, mp_digit b);
|
||||
int mp_set_int(mp_int *a, unsigned long b);
|
||||
*/
|
||||
|
||||
/* set a platform dependent unsigned long value */
|
||||
/*
|
||||
int mp_set_long(mp_int *a, unsigned long b);
|
||||
*/
|
||||
|
||||
/* set a platform dependent unsigned long long value */
|
||||
/*
|
||||
int mp_set_long_long(mp_int *a, unsigned long long b);
|
||||
*/
|
||||
|
||||
/* get a 32-bit value */
|
||||
unsigned long mp_get_int(mp_int * a);
|
||||
|
||||
@@ -639,18 +677,18 @@ int mp_prime_is_divisible(mp_int *a, int *result);
|
||||
* Sets result to 0 if composite or 1 if probable prime
|
||||
*/
|
||||
/*
|
||||
int mp_prime_fermat(mp_int *a, mp_int *b, int *result);
|
||||
mp_err mp_prime_fermat(const mp_int *a, const mp_int *b, mp_bool *result);
|
||||
*/
|
||||
|
||||
/* performs one Miller-Rabin test of "a" using base "b".
|
||||
* Sets result to 0 if composite or 1 if probable prime
|
||||
*/
|
||||
/*
|
||||
int mp_prime_miller_rabin(mp_int *a, mp_int *b, int *result);
|
||||
mp_err mp_prime_miller_rabin(const mp_int *a, const mp_int *b, mp_bool *result);
|
||||
*/
|
||||
|
||||
/* This gives [for a given bit size] the number of trials required
|
||||
* such that Miller-Rabin gives a prob of failure lower than 2^-96
|
||||
* such that Miller-Rabin gives a prob of failure lower than 2^-96
|
||||
*/
|
||||
/*
|
||||
int mp_prime_rabin_miller_trials(int size);
|
||||
@@ -664,7 +702,7 @@ int mp_prime_rabin_miller_trials(int size);
|
||||
* Sets result to 1 if probably prime, 0 otherwise
|
||||
*/
|
||||
/*
|
||||
int mp_prime_is_prime(mp_int *a, int t, int *result);
|
||||
mp_err mp_prime_is_prime(const mp_int *a, int t, mp_bool *result);
|
||||
*/
|
||||
|
||||
/* finds the next prime after the number "a" using "t" trials
|
||||
@@ -673,11 +711,11 @@ int mp_prime_is_prime(mp_int *a, int t, int *result);
|
||||
* bbs_style = 1 means the prime must be congruent to 3 mod 4
|
||||
*/
|
||||
/*
|
||||
int mp_prime_next_prime(mp_int *a, int t, int bbs_style);
|
||||
mp_err mp_prime_next_prime(mp_int *a, int t, int bbs_style);
|
||||
*/
|
||||
|
||||
/* makes a truly random prime of a given size (bytes),
|
||||
* call with bbs = 1 if you want it to be congruent to 3 mod 4
|
||||
* call with bbs = 1 if you want it to be congruent to 3 mod 4
|
||||
*
|
||||
* You have to supply a callback which fills in a buffer with random bytes. "dat" is a parameter you can
|
||||
* have passed to the callback (e.g. a state or something). This function doesn't use "dat" itself
|
||||
@@ -690,11 +728,10 @@ int mp_prime_next_prime(mp_int *a, int t, int bbs_style);
|
||||
/* makes a truly random prime of a given size (bits),
|
||||
*
|
||||
* Flags are as follows:
|
||||
*
|
||||
* LTM_PRIME_BBS - make prime congruent to 3 mod 4
|
||||
* LTM_PRIME_SAFE - make sure (p-1)/2 is prime as well (implies LTM_PRIME_BBS)
|
||||
* LTM_PRIME_2MSB_OFF - make the 2nd highest bit zero
|
||||
* LTM_PRIME_2MSB_ON - make the 2nd highest bit one
|
||||
*
|
||||
* MP_PRIME_BBS - make prime congruent to 3 mod 4
|
||||
* MP_PRIME_SAFE - make sure (p-1)/2 is prime as well (implies MP_PRIME_BBS)
|
||||
* MP_PRIME_2MSB_ON - make the 2nd highest bit one
|
||||
*
|
||||
* You have to supply a callback which fills in a buffer with random bytes. "dat" is a parameter you can
|
||||
* have passed to the callback (e.g. a state or something). This function doesn't use "dat" itself
|
||||
@@ -830,7 +867,7 @@ MODULE_SCOPE const char *mp_s_rmap;
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
+22
-19
@@ -44,16 +44,12 @@
|
||||
#define XREALLOC(x,n) TclBNRealloc(x,n)
|
||||
#define XCALLOC(n,x) TclBNCalloc(n,x)
|
||||
|
||||
/* Rename the global symbols in libtommath to avoid linkage conflicts */
|
||||
|
||||
#define KARATSUBA_MUL_CUTOFF TclBNKaratsubaMulCutoff
|
||||
#define KARATSUBA_SQR_CUTOFF TclBNKaratsubaSqrCutoff
|
||||
#define TOOM_MUL_CUTOFF TclBNToomMulCutoff
|
||||
#define TOOM_SQR_CUTOFF TclBNToomSqrCutoff
|
||||
|
||||
#define bn_reverse TclBN_reverse
|
||||
#define s_mp_reverse TclBN_reverse
|
||||
#define fast_s_mp_mul_digs TclBN_fast_s_mp_mul_digs
|
||||
#define s_mp_mul_digs_fast TclBN_fast_s_mp_mul_digs
|
||||
#define fast_s_mp_sqr TclBN_fast_s_mp_sqr
|
||||
#define s_mp_sqr_fast TclBN_fast_s_mp_sqr
|
||||
#define mp_add TclBN_mp_add
|
||||
#define mp_add_d TclBN_mp_add_d
|
||||
#define mp_and TclBN_mp_and
|
||||
@@ -81,7 +77,9 @@
|
||||
#define mp_init_set_int TclBN_mp_init_set_int
|
||||
#define mp_init_size TclBN_mp_init_size
|
||||
#define mp_karatsuba_mul TclBN_mp_karatsuba_mul
|
||||
#define s_mp_karatsuba_mul TclBN_mp_karatsuba_mul
|
||||
#define mp_karatsuba_sqr TclBN_mp_karatsuba_sqr
|
||||
#define s_mp_karatsuba_sqr TclBN_mp_karatsuba_sqr
|
||||
#define mp_lshd TclBN_mp_lshd
|
||||
#define mp_mod TclBN_mp_mod
|
||||
#define mp_mod_2d TclBN_mp_mod_2d
|
||||
@@ -105,7 +103,9 @@
|
||||
#define mp_to_unsigned_bin TclBN_mp_to_unsigned_bin
|
||||
#define mp_to_unsigned_bin_n TclBN_mp_to_unsigned_bin_n
|
||||
#define mp_toom_mul TclBN_mp_toom_mul
|
||||
#define s_mp_toom_mul TclBN_mp_toom_mul
|
||||
#define mp_toom_sqr TclBN_mp_toom_sqr
|
||||
#define s_mp_toom_sqr TclBN_mp_toom_sqr
|
||||
#define mp_toradix_n TclBN_mp_toradix_n
|
||||
#define mp_unsigned_bin_size TclBN_mp_unsigned_bin_size
|
||||
#define mp_xor TclBN_mp_xor
|
||||
@@ -165,7 +165,8 @@ EXTERN int TclBN_mp_add_d(mp_int *a, mp_digit b, mp_int *c);
|
||||
#ifndef TclBN_mp_and_TCL_DECLARED
|
||||
#define TclBN_mp_and_TCL_DECLARED
|
||||
/* 4 */
|
||||
EXTERN int TclBN_mp_and(mp_int *a, mp_int *b, mp_int *c);
|
||||
EXTERN int TclBN_mp_and(CONST mp_int *a, CONST mp_int *b,
|
||||
mp_int *c);
|
||||
#endif
|
||||
#ifndef TclBN_mp_clamp_TCL_DECLARED
|
||||
#define TclBN_mp_clamp_TCL_DECLARED
|
||||
@@ -185,17 +186,17 @@ EXTERN void TclBN_mp_clear_multi(mp_int *a, ...);
|
||||
#ifndef TclBN_mp_cmp_TCL_DECLARED
|
||||
#define TclBN_mp_cmp_TCL_DECLARED
|
||||
/* 8 */
|
||||
EXTERN int TclBN_mp_cmp(mp_int *a, mp_int *b);
|
||||
EXTERN int TclBN_mp_cmp(CONST mp_int *a, CONST mp_int *b);
|
||||
#endif
|
||||
#ifndef TclBN_mp_cmp_d_TCL_DECLARED
|
||||
#define TclBN_mp_cmp_d_TCL_DECLARED
|
||||
/* 9 */
|
||||
EXTERN int TclBN_mp_cmp_d(mp_int *a, mp_digit b);
|
||||
EXTERN int TclBN_mp_cmp_d(CONST mp_int *a, mp_digit b);
|
||||
#endif
|
||||
#ifndef TclBN_mp_cmp_mag_TCL_DECLARED
|
||||
#define TclBN_mp_cmp_mag_TCL_DECLARED
|
||||
/* 10 */
|
||||
EXTERN int TclBN_mp_cmp_mag(mp_int *a, mp_int *b);
|
||||
EXTERN int TclBN_mp_cmp_mag(CONST mp_int *a, CONST mp_int *b);
|
||||
#endif
|
||||
#ifndef TclBN_mp_copy_TCL_DECLARED
|
||||
#define TclBN_mp_copy_TCL_DECLARED
|
||||
@@ -318,7 +319,8 @@ EXTERN int TclBN_mp_neg(mp_int *a, mp_int *b);
|
||||
#ifndef TclBN_mp_or_TCL_DECLARED
|
||||
#define TclBN_mp_or_TCL_DECLARED
|
||||
/* 34 */
|
||||
EXTERN int TclBN_mp_or(mp_int *a, mp_int *b, mp_int *c);
|
||||
EXTERN int TclBN_mp_or(CONST mp_int *a, CONST mp_int *b,
|
||||
mp_int *c);
|
||||
#endif
|
||||
#ifndef TclBN_mp_radix_size_TCL_DECLARED
|
||||
#define TclBN_mp_radix_size_TCL_DECLARED
|
||||
@@ -391,7 +393,8 @@ EXTERN int TclBN_mp_unsigned_bin_size(mp_int *a);
|
||||
#ifndef TclBN_mp_xor_TCL_DECLARED
|
||||
#define TclBN_mp_xor_TCL_DECLARED
|
||||
/* 48 */
|
||||
EXTERN int TclBN_mp_xor(mp_int *a, mp_int *b, mp_int *c);
|
||||
EXTERN int TclBN_mp_xor(CONST mp_int *a, CONST mp_int *b,
|
||||
mp_int *c);
|
||||
#endif
|
||||
#ifndef TclBN_mp_zero_TCL_DECLARED
|
||||
#define TclBN_mp_zero_TCL_DECLARED
|
||||
@@ -480,13 +483,13 @@ typedef struct TclTomMathStubs {
|
||||
int (*tclBN_revision) (void); /* 1 */
|
||||
int (*tclBN_mp_add) (mp_int *a, mp_int *b, mp_int *c); /* 2 */
|
||||
int (*tclBN_mp_add_d) (mp_int *a, mp_digit b, mp_int *c); /* 3 */
|
||||
int (*tclBN_mp_and) (mp_int *a, mp_int *b, mp_int *c); /* 4 */
|
||||
int (*tclBN_mp_and) (CONST mp_int *a, CONST mp_int *b, mp_int *c); /* 4 */
|
||||
void (*tclBN_mp_clamp) (mp_int *a); /* 5 */
|
||||
void (*tclBN_mp_clear) (mp_int *a); /* 6 */
|
||||
void (*tclBN_mp_clear_multi) (mp_int *a, ...); /* 7 */
|
||||
int (*tclBN_mp_cmp) (mp_int *a, mp_int *b); /* 8 */
|
||||
int (*tclBN_mp_cmp_d) (mp_int *a, mp_digit b); /* 9 */
|
||||
int (*tclBN_mp_cmp_mag) (mp_int *a, mp_int *b); /* 10 */
|
||||
int (*tclBN_mp_cmp) (CONST mp_int *a, CONST mp_int *b); /* 8 */
|
||||
int (*tclBN_mp_cmp_d) (CONST mp_int *a, mp_digit b); /* 9 */
|
||||
int (*tclBN_mp_cmp_mag) (CONST mp_int *a, CONST mp_int *b); /* 10 */
|
||||
int (*tclBN_mp_copy) (mp_int *a, mp_int *b); /* 11 */
|
||||
int (*tclBN_mp_count_bits) (mp_int *a); /* 12 */
|
||||
int (*tclBN_mp_div) (mp_int *a, mp_int *b, mp_int *q, mp_int *r); /* 13 */
|
||||
@@ -510,7 +513,7 @@ typedef struct TclTomMathStubs {
|
||||
int (*tclBN_mp_mul_2) (mp_int *a, mp_int *p); /* 31 */
|
||||
int (*tclBN_mp_mul_2d) (mp_int *a, int d, mp_int *p); /* 32 */
|
||||
int (*tclBN_mp_neg) (mp_int *a, mp_int *b); /* 33 */
|
||||
int (*tclBN_mp_or) (mp_int *a, mp_int *b, mp_int *c); /* 34 */
|
||||
int (*tclBN_mp_or) (CONST mp_int *a, CONST mp_int *b, mp_int *c); /* 34 */
|
||||
int (*tclBN_mp_radix_size) (mp_int *a, int radix, int *size); /* 35 */
|
||||
int (*tclBN_mp_read_radix) (mp_int *a, CONST char *str, int radix); /* 36 */
|
||||
void (*tclBN_mp_rshd) (mp_int *a, int shift); /* 37 */
|
||||
@@ -524,7 +527,7 @@ typedef struct TclTomMathStubs {
|
||||
int (*tclBN_mp_to_unsigned_bin_n) (mp_int *a, unsigned char *b, unsigned long *outlen); /* 45 */
|
||||
int (*tclBN_mp_toradix_n) (mp_int *a, char *str, int radix, int maxlen); /* 46 */
|
||||
int (*tclBN_mp_unsigned_bin_size) (mp_int *a); /* 47 */
|
||||
int (*tclBN_mp_xor) (mp_int *a, mp_int *b, mp_int *c); /* 48 */
|
||||
int (*tclBN_mp_xor) (CONST mp_int *a, CONST mp_int *b, mp_int *c); /* 48 */
|
||||
void (*tclBN_mp_zero) (mp_int *a); /* 49 */
|
||||
void (*tclBN_reverse) (unsigned char *s, int len); /* 50 */
|
||||
int (*tclBN_fast_s_mp_mul_digs) (mp_int *a, mp_int *b, mp_int *c, int digs); /* 51 */
|
||||
|
||||
@@ -196,7 +196,7 @@ TclBNInitBignumFromLong(
|
||||
*/
|
||||
|
||||
status = mp_init_size(a,
|
||||
(CHAR_BIT * sizeof(long) + DIGIT_BIT - 1) / DIGIT_BIT);
|
||||
(CHAR_BIT * sizeof(long) + MP_DIGIT_BIT - 1) / MP_DIGIT_BIT);
|
||||
if (status != MP_OKAY) {
|
||||
Tcl_Panic("initialization failure in TclBNInitBignumFromLong");
|
||||
}
|
||||
@@ -283,7 +283,7 @@ TclBNInitBignumFromWideUInt(
|
||||
*/
|
||||
|
||||
status = mp_init_size(a,
|
||||
(CHAR_BIT * sizeof(Tcl_WideUInt) + DIGIT_BIT - 1) / DIGIT_BIT);
|
||||
(CHAR_BIT * sizeof(Tcl_WideUInt) + MP_DIGIT_BIT - 1) / MP_DIGIT_BIT);
|
||||
if (status != MP_OKAY) {
|
||||
Tcl_Panic("initialization failure in TclBNInitBignumFromWideUInt");
|
||||
}
|
||||
|
||||
@@ -339,12 +339,12 @@ proc http_formatQuery {args} {
|
||||
# 2 Convert every other character to an array lookup
|
||||
# 3 Escape constructs that are "special" to the tcl parser
|
||||
# 4 "subst" the result, doing all the array substitutions
|
||||
|
||||
|
||||
proc httpMapReply {string} {
|
||||
global httpFormMap
|
||||
set alphanumeric a-zA-Z0-9
|
||||
if {![info exists httpFormMap]} {
|
||||
|
||||
|
||||
for {set i 1} {$i <= 256} {incr i} {
|
||||
set c [format %c $i]
|
||||
if {![string match \[$alphanumeric\] $c]} {
|
||||
@@ -363,7 +363,7 @@ proc http_formatQuery {args} {
|
||||
return [subst $string]
|
||||
}
|
||||
|
||||
# Default proxy filter.
|
||||
# Default proxy filter.
|
||||
proc httpProxyRequired {host} {
|
||||
global http
|
||||
if {[info exists http(-proxyhost)] && [string length $http(-proxyhost)]} {
|
||||
|
||||
+1
-1
@@ -40,5 +40,5 @@ namespace eval ::tcl::clock {
|
||||
::msgcat::mcset ja LOCALE_DATE_FORMAT "%EY\u5e74%m\u6708%d\u65e5"
|
||||
::msgcat::mcset ja LOCALE_TIME_FORMAT "%H\u6642%M\u5206%S\u79d2"
|
||||
::msgcat::mcset ja LOCALE_DATE_TIME_FORMAT "%EY\u5e74%m\u6708%d\u65e5 (%a) %H\u6642%M\u5206%S\u79d2 %z"
|
||||
::msgcat::mcset ja LOCALE_ERAS "\u007b-9223372036854775808 \u897f\u66a6 0\u007d \u007b-3061011600 \u660e\u6cbb 1867\u007d \u007b-1812186000 \u5927\u6b63 1911\u007d \u007b-1357635600 \u662d\u548c 1925\u007d \u007b600220800 \u5e73\u6210 1988\u007d"
|
||||
::msgcat::mcset ja LOCALE_ERAS "{-9223372036854775808 \u897f\u66a6 0} {-3061011600 \u660e\u6cbb 1867} {-1812186000 \u5927\u6b63 1911} {-1357635600 \u662d\u548c 1925} {600220800 \u5e73\u6210 1988} {1556668800 \u4ee4\u548c 2018}"
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace eval ::tcl {
|
||||
# Every OptProc give usage information on "procname -help".
|
||||
# Try "tcl::OptParseTest -help" and "tcl::OptParseTest -a" and
|
||||
# then other arguments.
|
||||
#
|
||||
#
|
||||
# example of 'valid' call:
|
||||
# ::tcl::OptParseTest save -4 -pr 23 -libsok SybTcl\
|
||||
# -nostatics false ch1
|
||||
@@ -84,8 +84,8 @@ namespace eval ::tcl {
|
||||
#
|
||||
# The general structure of a "program" is
|
||||
# notation (pseudo bnf like)
|
||||
# name :== definition defines "name" as being "definition"
|
||||
# { x y z } means list of x, y, and z
|
||||
# name :== definition defines "name" as being "definition"
|
||||
# { x y z } means list of x, y, and z
|
||||
# x* means x repeated 0 or more time
|
||||
# x+ means "x x*"
|
||||
# x? means optionally x
|
||||
@@ -110,7 +110,7 @@ namespace eval ::tcl {
|
||||
#
|
||||
# And for this application:
|
||||
#
|
||||
# singleStep :== { instruction varname {hasBeenSet currentValue} type
|
||||
# singleStep :== { instruction varname {hasBeenSet currentValue} type
|
||||
# typeArgs help }
|
||||
# instruction :== "flags" | "value"
|
||||
# type :== knowType | anyword
|
||||
@@ -343,7 +343,7 @@ proc ::tcl::OptProcArgGiven {argname} {
|
||||
proc OptState {item} {
|
||||
lindex $item 0
|
||||
}
|
||||
|
||||
|
||||
# current state
|
||||
proc OptCurState {descriptions} {
|
||||
OptState [OptCurDesc $descriptions];
|
||||
@@ -535,7 +535,7 @@ proc ::tcl::OptKeyParse {descKey arglist} {
|
||||
if {![Lempty $arglist]} {
|
||||
return -code error [OptTooManyArgs $desc $arglist];
|
||||
}
|
||||
|
||||
|
||||
# Analyse the result
|
||||
# Walk through the tree:
|
||||
OptTreeVars $desc "#[expr {[info level]-1}]" ;
|
||||
@@ -781,7 +781,7 @@ proc ::tcl::OptCheckType {arg type {typeArgs ""}} {
|
||||
3 {
|
||||
# varname type value
|
||||
# varname value comment
|
||||
|
||||
|
||||
if {[regexp {^-(.+)$} $arg1 x type]} {
|
||||
# flags/optValue as they are optional, need a "value",
|
||||
# on the contrary, for a variable (non optional),
|
||||
@@ -919,7 +919,7 @@ proc ::tcl::OptError {prefix desc {header 0}} {
|
||||
set desc [concat $h $desc]
|
||||
}
|
||||
OptLengths $desc nl tl dl
|
||||
# actually output
|
||||
# actually output
|
||||
return "$prefix[OptTree $desc $nl $tl $dl]"
|
||||
}
|
||||
|
||||
@@ -952,7 +952,7 @@ proc ::tcl::Lget {list indexLst} {
|
||||
# it would be even slower... needs to be written in C !)
|
||||
# (nb: there is a non trivial recursive problem with indexes 0,
|
||||
# which appear because there is no difference between a list
|
||||
# of 1 element and 1 element alone : [list "a"] == "a" while
|
||||
# of 1 element and 1 element alone : [list "a"] == "a" while
|
||||
# it should be {a} and [listp a] should be 0 while [listp {a b}] would be 1
|
||||
# and [listp "a b"] maybe 0. listp does not exist either...)
|
||||
proc ::tcl::Lvarset {listName indexLst newValue} {
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
This is makeindex, version 2.14 [02-Oct-2002] (kpathsea + Thai support).
|
||||
Scanning input file bn.idx....done (79 entries accepted, 0 rejected).
|
||||
Sorting entries....done (511 comparisons).
|
||||
Generating output file bn.ind....done (82 lines written, 0 warnings).
|
||||
Output written in bn.ind.
|
||||
Transcript written in bn.ilg.
|
||||
@@ -1,82 +0,0 @@
|
||||
\begin{theindex}
|
||||
|
||||
\item mp\_add, \hyperpage{29}
|
||||
\item mp\_add\_d, \hyperpage{52}
|
||||
\item mp\_and, \hyperpage{29}
|
||||
\item mp\_clear, \hyperpage{11}
|
||||
\item mp\_clear\_multi, \hyperpage{12}
|
||||
\item mp\_cmp, \hyperpage{24}
|
||||
\item mp\_cmp\_d, \hyperpage{25}
|
||||
\item mp\_cmp\_mag, \hyperpage{23}
|
||||
\item mp\_div, \hyperpage{30}
|
||||
\item mp\_div\_2, \hyperpage{26}
|
||||
\item mp\_div\_2d, \hyperpage{28}
|
||||
\item mp\_div\_d, \hyperpage{52}
|
||||
\item mp\_dr\_reduce, \hyperpage{40}
|
||||
\item mp\_dr\_setup, \hyperpage{40}
|
||||
\item MP\_EQ, \hyperpage{22}
|
||||
\item mp\_error\_to\_string, \hyperpage{10}
|
||||
\item mp\_expt\_d, \hyperpage{43}
|
||||
\item mp\_exptmod, \hyperpage{43}
|
||||
\item mp\_exteuclid, \hyperpage{51}
|
||||
\item mp\_gcd, \hyperpage{51}
|
||||
\item mp\_get\_int, \hyperpage{20}
|
||||
\item mp\_grow, \hyperpage{16}
|
||||
\item MP\_GT, \hyperpage{22}
|
||||
\item mp\_init, \hyperpage{11}
|
||||
\item mp\_init\_copy, \hyperpage{13}
|
||||
\item mp\_init\_multi, \hyperpage{12}
|
||||
\item mp\_init\_set, \hyperpage{21}
|
||||
\item mp\_init\_set\_int, \hyperpage{21}
|
||||
\item mp\_init\_size, \hyperpage{14}
|
||||
\item mp\_int, \hyperpage{10}
|
||||
\item mp\_invmod, \hyperpage{52}
|
||||
\item mp\_jacobi, \hyperpage{52}
|
||||
\item mp\_lcm, \hyperpage{51}
|
||||
\item mp\_lshd, \hyperpage{28}
|
||||
\item MP\_LT, \hyperpage{22}
|
||||
\item MP\_MEM, \hyperpage{9}
|
||||
\item mp\_mod, \hyperpage{35}
|
||||
\item mp\_mod\_d, \hyperpage{52}
|
||||
\item mp\_montgomery\_calc\_normalization, \hyperpage{38}
|
||||
\item mp\_montgomery\_reduce, \hyperpage{37}
|
||||
\item mp\_montgomery\_setup, \hyperpage{37}
|
||||
\item mp\_mul, \hyperpage{31}
|
||||
\item mp\_mul\_2, \hyperpage{26}
|
||||
\item mp\_mul\_2d, \hyperpage{28}
|
||||
\item mp\_mul\_d, \hyperpage{52}
|
||||
\item mp\_n\_root, \hyperpage{44}
|
||||
\item mp\_neg, \hyperpage{29}
|
||||
\item MP\_NO, \hyperpage{9}
|
||||
\item MP\_OKAY, \hyperpage{9}
|
||||
\item mp\_or, \hyperpage{29}
|
||||
\item mp\_prime\_fermat, \hyperpage{45}
|
||||
\item mp\_prime\_is\_divisible, \hyperpage{45}
|
||||
\item mp\_prime\_is\_prime, \hyperpage{46}
|
||||
\item mp\_prime\_miller\_rabin, \hyperpage{45}
|
||||
\item mp\_prime\_next\_prime, \hyperpage{46}
|
||||
\item mp\_prime\_rabin\_miller\_trials, \hyperpage{46}
|
||||
\item mp\_prime\_random, \hyperpage{47}
|
||||
\item mp\_prime\_random\_ex, \hyperpage{47}
|
||||
\item mp\_radix\_size, \hyperpage{49}
|
||||
\item mp\_read\_radix, \hyperpage{49}
|
||||
\item mp\_read\_unsigned\_bin, \hyperpage{50}
|
||||
\item mp\_reduce, \hyperpage{36}
|
||||
\item mp\_reduce\_2k, \hyperpage{41}
|
||||
\item mp\_reduce\_2k\_setup, \hyperpage{41}
|
||||
\item mp\_reduce\_setup, \hyperpage{36}
|
||||
\item mp\_rshd, \hyperpage{28}
|
||||
\item mp\_set, \hyperpage{19}
|
||||
\item mp\_set\_int, \hyperpage{20}
|
||||
\item mp\_shrink, \hyperpage{15}
|
||||
\item mp\_sqr, \hyperpage{33}
|
||||
\item mp\_sub, \hyperpage{29}
|
||||
\item mp\_sub\_d, \hyperpage{52}
|
||||
\item mp\_to\_unsigned\_bin, \hyperpage{50}
|
||||
\item mp\_toradix, \hyperpage{49}
|
||||
\item mp\_unsigned\_bin\_size, \hyperpage{50}
|
||||
\item MP\_VAL, \hyperpage{9}
|
||||
\item mp\_xor, \hyperpage{29}
|
||||
\item MP\_YES, \hyperpage{9}
|
||||
|
||||
\end{theindex}
|
||||
Binary file not shown.
-1835
File diff suppressed because it is too large
Load Diff
+46
-43
@@ -1,53 +1,56 @@
|
||||
#include <tommath.h>
|
||||
#ifdef BN_MP_AND_C
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis
|
||||
*
|
||||
* LibTomMath is a library that provides multiple-precision
|
||||
* integer arithmetic as well as number theoretic functionality.
|
||||
*
|
||||
* The library was designed directly after the MPI library by
|
||||
* Michael Fromberger but has been written from scratch with
|
||||
* additional optimizations in place.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* AND two ints together */
|
||||
int
|
||||
mp_and (mp_int * a, mp_int * b, mp_int * c)
|
||||
/* two complement and */
|
||||
mp_err mp_and(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
{
|
||||
int res, ix, px;
|
||||
mp_int t, *x;
|
||||
int used = MAX(a->used, b->used) + 1, i;
|
||||
mp_err err;
|
||||
mp_digit ac = 1, bc = 1, cc = 1;
|
||||
mp_sign csign = ((a->sign == MP_NEG) && (b->sign == MP_NEG)) ? MP_NEG : MP_ZPOS;
|
||||
|
||||
if (a->used > b->used) {
|
||||
if ((res = mp_init_copy (&t, a)) != MP_OKAY) {
|
||||
return res;
|
||||
}
|
||||
px = b->used;
|
||||
x = b;
|
||||
} else {
|
||||
if ((res = mp_init_copy (&t, b)) != MP_OKAY) {
|
||||
return res;
|
||||
}
|
||||
px = a->used;
|
||||
x = a;
|
||||
}
|
||||
if (c->alloc < used) {
|
||||
if ((err = mp_grow(c, used)) != MP_OKAY) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
for (ix = 0; ix < px; ix++) {
|
||||
t.dp[ix] &= x->dp[ix];
|
||||
}
|
||||
for (i = 0; i < used; i++) {
|
||||
mp_digit x, y;
|
||||
|
||||
/* zero digits above the last from the smallest mp_int */
|
||||
for (; ix < t.used; ix++) {
|
||||
t.dp[ix] = 0;
|
||||
}
|
||||
/* convert to two complement if negative */
|
||||
if (a->sign == MP_NEG) {
|
||||
ac += (i >= a->used) ? MP_MASK : (~a->dp[i] & MP_MASK);
|
||||
x = ac & MP_MASK;
|
||||
ac >>= MP_DIGIT_BIT;
|
||||
} else {
|
||||
x = (i >= a->used) ? 0uL : a->dp[i];
|
||||
}
|
||||
|
||||
mp_clamp (&t);
|
||||
mp_exch (c, &t);
|
||||
mp_clear (&t);
|
||||
return MP_OKAY;
|
||||
/* convert to two complement if negative */
|
||||
if (b->sign == MP_NEG) {
|
||||
bc += (i >= b->used) ? MP_MASK : (~b->dp[i] & MP_MASK);
|
||||
y = bc & MP_MASK;
|
||||
bc >>= MP_DIGIT_BIT;
|
||||
} else {
|
||||
y = (i >= b->used) ? 0uL : b->dp[i];
|
||||
}
|
||||
|
||||
c->dp[i] = x & y;
|
||||
|
||||
/* convert to to sign-magnitude if negative */
|
||||
if (csign == MP_NEG) {
|
||||
cc += ~c->dp[i] & MP_MASK;
|
||||
c->dp[i] = cc & MP_MASK;
|
||||
cc >>= MP_DIGIT_BIT;
|
||||
}
|
||||
}
|
||||
|
||||
c->used = used;
|
||||
c->sign = csign;
|
||||
mp_clamp(c);
|
||||
return MP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
||||
+19
-32
@@ -1,39 +1,26 @@
|
||||
#include <tommath.h>
|
||||
#ifdef BN_MP_CMP_C
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis
|
||||
*
|
||||
* LibTomMath is a library that provides multiple-precision
|
||||
* integer arithmetic as well as number theoretic functionality.
|
||||
*
|
||||
* The library was designed directly after the MPI library by
|
||||
* Michael Fromberger but has been written from scratch with
|
||||
* additional optimizations in place.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* compare two ints (signed)*/
|
||||
int
|
||||
mp_cmp (mp_int * a, mp_int * b)
|
||||
mp_ord mp_cmp(const mp_int *a, const mp_int *b)
|
||||
{
|
||||
/* compare based on sign */
|
||||
if (a->sign != b->sign) {
|
||||
if (a->sign == MP_NEG) {
|
||||
return MP_LT;
|
||||
} else {
|
||||
return MP_GT;
|
||||
}
|
||||
}
|
||||
|
||||
/* compare digits */
|
||||
if (a->sign == MP_NEG) {
|
||||
/* if negative compare opposite direction */
|
||||
return mp_cmp_mag(b, a);
|
||||
} else {
|
||||
return mp_cmp_mag(a, b);
|
||||
}
|
||||
/* compare based on sign */
|
||||
if (a->sign != b->sign) {
|
||||
if (a->sign == MP_NEG) {
|
||||
return MP_LT;
|
||||
} else {
|
||||
return MP_GT;
|
||||
}
|
||||
}
|
||||
|
||||
/* compare digits */
|
||||
if (a->sign == MP_NEG) {
|
||||
/* if negative compare opposite direction */
|
||||
return mp_cmp_mag(b, a);
|
||||
} else {
|
||||
return mp_cmp_mag(a, b);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
+19
-31
@@ -1,40 +1,28 @@
|
||||
#include <tommath.h>
|
||||
#ifdef BN_MP_CMP_D_C
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis
|
||||
*
|
||||
* LibTomMath is a library that provides multiple-precision
|
||||
* integer arithmetic as well as number theoretic functionality.
|
||||
*
|
||||
* The library was designed directly after the MPI library by
|
||||
* Michael Fromberger but has been written from scratch with
|
||||
* additional optimizations in place.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* compare a digit */
|
||||
int mp_cmp_d(mp_int * a, mp_digit b)
|
||||
mp_ord mp_cmp_d(const mp_int *a, mp_digit b)
|
||||
{
|
||||
/* compare based on sign */
|
||||
if (a->sign == MP_NEG) {
|
||||
return MP_LT;
|
||||
}
|
||||
/* compare based on sign */
|
||||
if (a->sign == MP_NEG) {
|
||||
return MP_LT;
|
||||
}
|
||||
|
||||
/* compare based on magnitude */
|
||||
if (a->used > 1) {
|
||||
return MP_GT;
|
||||
}
|
||||
/* compare based on magnitude */
|
||||
if (a->used > 1) {
|
||||
return MP_GT;
|
||||
}
|
||||
|
||||
/* compare the only digit of a to b */
|
||||
if (a->dp[0] > b) {
|
||||
return MP_GT;
|
||||
} else if (a->dp[0] < b) {
|
||||
return MP_LT;
|
||||
} else {
|
||||
return MP_EQ;
|
||||
}
|
||||
/* compare the only digit of a to b */
|
||||
if (a->dp[0] > b) {
|
||||
return MP_GT;
|
||||
} else if (a->dp[0] < b) {
|
||||
return MP_LT;
|
||||
} else {
|
||||
return MP_EQ;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
+28
-40
@@ -1,51 +1,39 @@
|
||||
#include <tommath.h>
|
||||
#ifdef BN_MP_CMP_MAG_C
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis
|
||||
*
|
||||
* LibTomMath is a library that provides multiple-precision
|
||||
* integer arithmetic as well as number theoretic functionality.
|
||||
*
|
||||
* The library was designed directly after the MPI library by
|
||||
* Michael Fromberger but has been written from scratch with
|
||||
* additional optimizations in place.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* compare maginitude of two ints (unsigned) */
|
||||
int mp_cmp_mag (mp_int * a, mp_int * b)
|
||||
mp_ord mp_cmp_mag(const mp_int *a, const mp_int *b)
|
||||
{
|
||||
int n;
|
||||
mp_digit *tmpa, *tmpb;
|
||||
int n;
|
||||
const mp_digit *tmpa, *tmpb;
|
||||
|
||||
/* compare based on # of non-zero digits */
|
||||
if (a->used > b->used) {
|
||||
return MP_GT;
|
||||
}
|
||||
|
||||
if (a->used < b->used) {
|
||||
return MP_LT;
|
||||
}
|
||||
|
||||
/* alias for a */
|
||||
tmpa = a->dp + (a->used - 1);
|
||||
|
||||
/* alias for b */
|
||||
tmpb = b->dp + (a->used - 1);
|
||||
|
||||
/* compare based on digits */
|
||||
for (n = 0; n < a->used; ++n, --tmpa, --tmpb) {
|
||||
if (*tmpa > *tmpb) {
|
||||
/* compare based on # of non-zero digits */
|
||||
if (a->used > b->used) {
|
||||
return MP_GT;
|
||||
}
|
||||
}
|
||||
|
||||
if (*tmpa < *tmpb) {
|
||||
if (a->used < b->used) {
|
||||
return MP_LT;
|
||||
}
|
||||
}
|
||||
return MP_EQ;
|
||||
}
|
||||
|
||||
/* alias for a */
|
||||
tmpa = a->dp + (a->used - 1);
|
||||
|
||||
/* alias for b */
|
||||
tmpb = b->dp + (a->used - 1);
|
||||
|
||||
/* compare based on digits */
|
||||
for (n = 0; n < a->used; ++n, --tmpa, --tmpb) {
|
||||
if (*tmpa > *tmpb) {
|
||||
return MP_GT;
|
||||
}
|
||||
|
||||
if (*tmpa < *tmpb) {
|
||||
return MP_LT;
|
||||
}
|
||||
}
|
||||
return MP_EQ;
|
||||
}
|
||||
#endif
|
||||
|
||||
+48
-38
@@ -1,46 +1,56 @@
|
||||
#include <tommath.h>
|
||||
#ifdef BN_MP_OR_C
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis
|
||||
*
|
||||
* LibTomMath is a library that provides multiple-precision
|
||||
* integer arithmetic as well as number theoretic functionality.
|
||||
*
|
||||
* The library was designed directly after the MPI library by
|
||||
* Michael Fromberger but has been written from scratch with
|
||||
* additional optimizations in place.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* OR two ints together */
|
||||
int mp_or (mp_int * a, mp_int * b, mp_int * c)
|
||||
/* two complement or */
|
||||
mp_err mp_or(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
{
|
||||
int res, ix, px;
|
||||
mp_int t, *x;
|
||||
int used = MAX(a->used, b->used) + 1, i;
|
||||
mp_err err;
|
||||
mp_digit ac = 1, bc = 1, cc = 1;
|
||||
mp_sign csign = ((a->sign == MP_NEG) || (b->sign == MP_NEG)) ? MP_NEG : MP_ZPOS;
|
||||
|
||||
if (a->used > b->used) {
|
||||
if ((res = mp_init_copy (&t, a)) != MP_OKAY) {
|
||||
return res;
|
||||
}
|
||||
px = b->used;
|
||||
x = b;
|
||||
} else {
|
||||
if ((res = mp_init_copy (&t, b)) != MP_OKAY) {
|
||||
return res;
|
||||
}
|
||||
px = a->used;
|
||||
x = a;
|
||||
}
|
||||
if (c->alloc < used) {
|
||||
if ((err = mp_grow(c, used)) != MP_OKAY) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
for (ix = 0; ix < px; ix++) {
|
||||
t.dp[ix] |= x->dp[ix];
|
||||
}
|
||||
mp_clamp (&t);
|
||||
mp_exch (c, &t);
|
||||
mp_clear (&t);
|
||||
return MP_OKAY;
|
||||
for (i = 0; i < used; i++) {
|
||||
mp_digit x, y;
|
||||
|
||||
/* convert to two complement if negative */
|
||||
if (a->sign == MP_NEG) {
|
||||
ac += (i >= a->used) ? MP_MASK : (~a->dp[i] & MP_MASK);
|
||||
x = ac & MP_MASK;
|
||||
ac >>= MP_DIGIT_BIT;
|
||||
} else {
|
||||
x = (i >= a->used) ? 0uL : a->dp[i];
|
||||
}
|
||||
|
||||
/* convert to two complement if negative */
|
||||
if (b->sign == MP_NEG) {
|
||||
bc += (i >= b->used) ? MP_MASK : (~b->dp[i] & MP_MASK);
|
||||
y = bc & MP_MASK;
|
||||
bc >>= MP_DIGIT_BIT;
|
||||
} else {
|
||||
y = (i >= b->used) ? 0uL : b->dp[i];
|
||||
}
|
||||
|
||||
c->dp[i] = x | y;
|
||||
|
||||
/* convert to to sign-magnitude if negative */
|
||||
if (csign == MP_NEG) {
|
||||
cc += ~c->dp[i] & MP_MASK;
|
||||
c->dp[i] = cc & MP_MASK;
|
||||
cc >>= MP_DIGIT_BIT;
|
||||
}
|
||||
}
|
||||
|
||||
c->used = used;
|
||||
c->sign = csign;
|
||||
mp_clamp(c);
|
||||
return MP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
||||
+48
-39
@@ -1,47 +1,56 @@
|
||||
#include <tommath.h>
|
||||
#ifdef BN_MP_XOR_C
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis
|
||||
*
|
||||
* LibTomMath is a library that provides multiple-precision
|
||||
* integer arithmetic as well as number theoretic functionality.
|
||||
*
|
||||
* The library was designed directly after the MPI library by
|
||||
* Michael Fromberger but has been written from scratch with
|
||||
* additional optimizations in place.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* XOR two ints together */
|
||||
int
|
||||
mp_xor (mp_int * a, mp_int * b, mp_int * c)
|
||||
/* two complement xor */
|
||||
mp_err mp_xor(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
{
|
||||
int res, ix, px;
|
||||
mp_int t, *x;
|
||||
int used = MAX(a->used, b->used) + 1, i;
|
||||
mp_err err;
|
||||
mp_digit ac = 1, bc = 1, cc = 1;
|
||||
mp_sign csign = (a->sign != b->sign) ? MP_NEG : MP_ZPOS;
|
||||
|
||||
if (a->used > b->used) {
|
||||
if ((res = mp_init_copy (&t, a)) != MP_OKAY) {
|
||||
return res;
|
||||
}
|
||||
px = b->used;
|
||||
x = b;
|
||||
} else {
|
||||
if ((res = mp_init_copy (&t, b)) != MP_OKAY) {
|
||||
return res;
|
||||
}
|
||||
px = a->used;
|
||||
x = a;
|
||||
}
|
||||
if (c->alloc < used) {
|
||||
if ((err = mp_grow(c, used)) != MP_OKAY) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
for (ix = 0; ix < px; ix++) {
|
||||
t.dp[ix] ^= x->dp[ix];
|
||||
}
|
||||
mp_clamp (&t);
|
||||
mp_exch (c, &t);
|
||||
mp_clear (&t);
|
||||
return MP_OKAY;
|
||||
for (i = 0; i < used; i++) {
|
||||
mp_digit x, y;
|
||||
|
||||
/* convert to two complement if negative */
|
||||
if (a->sign == MP_NEG) {
|
||||
ac += (i >= a->used) ? MP_MASK : (~a->dp[i] & MP_MASK);
|
||||
x = ac & MP_MASK;
|
||||
ac >>= MP_DIGIT_BIT;
|
||||
} else {
|
||||
x = (i >= a->used) ? 0uL : a->dp[i];
|
||||
}
|
||||
|
||||
/* convert to two complement if negative */
|
||||
if (b->sign == MP_NEG) {
|
||||
bc += (i >= b->used) ? MP_MASK : (~b->dp[i] & MP_MASK);
|
||||
y = bc & MP_MASK;
|
||||
bc >>= MP_DIGIT_BIT;
|
||||
} else {
|
||||
y = (i >= b->used) ? 0uL : b->dp[i];
|
||||
}
|
||||
|
||||
c->dp[i] = x ^ y;
|
||||
|
||||
/* convert to to sign-magnitude if negative */
|
||||
if (csign == MP_NEG) {
|
||||
cc += ~c->dp[i] & MP_MASK;
|
||||
c->dp[i] = cc & MP_MASK;
|
||||
cc >>= MP_DIGIT_BIT;
|
||||
}
|
||||
}
|
||||
|
||||
c->used = used;
|
||||
c->sign = csign;
|
||||
mp_clamp(c);
|
||||
return MP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,265 +0,0 @@
|
||||
#!/bin/perl
|
||||
#
|
||||
#Used to prepare the book "tommath.src" for LaTeX by pre-processing it into a .tex file
|
||||
#
|
||||
#Essentially you write the "tommath.src" as normal LaTex except where you want code snippets you put
|
||||
#
|
||||
#EXAM,file
|
||||
#
|
||||
#This preprocessor will then open "file" and insert it as a verbatim copy.
|
||||
#
|
||||
#Tom St Denis
|
||||
|
||||
#get graphics type
|
||||
if (shift =~ /PDF/) {
|
||||
$graph = "";
|
||||
} else {
|
||||
$graph = ".ps";
|
||||
}
|
||||
|
||||
open(IN,"<tommath.src") or die "Can't open source file";
|
||||
open(OUT,">tommath.tex") or die "Can't open destination file";
|
||||
|
||||
print "Scanning for sections\n";
|
||||
$chapter = $section = $subsection = 0;
|
||||
$x = 0;
|
||||
while (<IN>) {
|
||||
print ".";
|
||||
if (!(++$x % 80)) { print "\n"; }
|
||||
#update the headings
|
||||
if (~($_ =~ /\*/)) {
|
||||
if ($_ =~ /\\chapter{.+}/) {
|
||||
++$chapter;
|
||||
$section = $subsection = 0;
|
||||
} elsif ($_ =~ /\\section{.+}/) {
|
||||
++$section;
|
||||
$subsection = 0;
|
||||
} elsif ($_ =~ /\\subsection{.+}/) {
|
||||
++$subsection;
|
||||
}
|
||||
}
|
||||
|
||||
if ($_ =~ m/MARK/) {
|
||||
@m = split(",",$_);
|
||||
chomp(@m[1]);
|
||||
$index1{@m[1]} = $chapter;
|
||||
$index2{@m[1]} = $section;
|
||||
$index3{@m[1]} = $subsection;
|
||||
}
|
||||
}
|
||||
close(IN);
|
||||
|
||||
open(IN,"<tommath.src") or die "Can't open source file";
|
||||
$readline = $wroteline = 0;
|
||||
$srcline = 0;
|
||||
|
||||
while (<IN>) {
|
||||
++$readline;
|
||||
++$srcline;
|
||||
|
||||
if ($_ =~ m/MARK/) {
|
||||
} elsif ($_ =~ m/EXAM/ || $_ =~ m/LIST/) {
|
||||
if ($_ =~ m/EXAM/) {
|
||||
$skipheader = 1;
|
||||
} else {
|
||||
$skipheader = 0;
|
||||
}
|
||||
|
||||
# EXAM,file
|
||||
chomp($_);
|
||||
@m = split(",",$_);
|
||||
open(SRC,"<$m[1]") or die "Error:$srcline:Can't open source file $m[1]";
|
||||
|
||||
print "$srcline:Inserting $m[1]:";
|
||||
|
||||
$line = 0;
|
||||
$tmp = $m[1];
|
||||
$tmp =~ s/_/"\\_"/ge;
|
||||
print OUT "\\vspace{+3mm}\\begin{small}\n\\hspace{-5.1mm}{\\bf File}: $tmp\n\\vspace{-3mm}\n\\begin{alltt}\n";
|
||||
$wroteline += 5;
|
||||
|
||||
if ($skipheader == 1) {
|
||||
# scan till next end of comment, e.g. skip license
|
||||
while (<SRC>) {
|
||||
$text[$line++] = $_;
|
||||
last if ($_ =~ /math\.libtomcrypt\.org/);
|
||||
}
|
||||
<SRC>;
|
||||
}
|
||||
|
||||
$inline = 0;
|
||||
while (<SRC>) {
|
||||
next if ($_ =~ /\$Source/);
|
||||
next if ($_ =~ /\$Revision/);
|
||||
next if ($_ =~ /\$Date/);
|
||||
$text[$line++] = $_;
|
||||
++$inline;
|
||||
chomp($_);
|
||||
$_ =~ s/\t/" "/ge;
|
||||
$_ =~ s/{/"^{"/ge;
|
||||
$_ =~ s/}/"^}"/ge;
|
||||
$_ =~ s/\\/'\symbol{92}'/ge;
|
||||
$_ =~ s/\^/"\\"/ge;
|
||||
|
||||
printf OUT ("%03d ", $line);
|
||||
for ($x = 0; $x < length($_); $x++) {
|
||||
print OUT chr(vec($_, $x, 8));
|
||||
if ($x == 75) {
|
||||
print OUT "\n ";
|
||||
++$wroteline;
|
||||
}
|
||||
}
|
||||
print OUT "\n";
|
||||
++$wroteline;
|
||||
}
|
||||
$totlines = $line;
|
||||
print OUT "\\end{alltt}\n\\end{small}\n";
|
||||
close(SRC);
|
||||
print "$inline lines\n";
|
||||
$wroteline += 2;
|
||||
} elsif ($_ =~ m/@\d+,.+@/) {
|
||||
# line contains [number,text]
|
||||
# e.g. @14,for (ix = 0)@
|
||||
$txt = $_;
|
||||
while ($txt =~ m/@\d+,.+@/) {
|
||||
@m = split("@",$txt); # splits into text, one, two
|
||||
@parms = split(",",$m[1]); # splits one,two into two elements
|
||||
|
||||
# now search from $parms[0] down for $parms[1]
|
||||
$found1 = 0;
|
||||
$found2 = 0;
|
||||
for ($i = $parms[0]; $i < $totlines && $found1 == 0; $i++) {
|
||||
if ($text[$i] =~ m/\Q$parms[1]\E/) {
|
||||
$foundline1 = $i + 1;
|
||||
$found1 = 1;
|
||||
}
|
||||
}
|
||||
|
||||
# now search backwards
|
||||
for ($i = $parms[0] - 1; $i >= 0 && $found2 == 0; $i--) {
|
||||
if ($text[$i] =~ m/\Q$parms[1]\E/) {
|
||||
$foundline2 = $i + 1;
|
||||
$found2 = 1;
|
||||
}
|
||||
}
|
||||
|
||||
# now use the closest match or the first if tied
|
||||
if ($found1 == 1 && $found2 == 0) {
|
||||
$found = 1;
|
||||
$foundline = $foundline1;
|
||||
} elsif ($found1 == 0 && $found2 == 1) {
|
||||
$found = 1;
|
||||
$foundline = $foundline2;
|
||||
} elsif ($found1 == 1 && $found2 == 1) {
|
||||
$found = 1;
|
||||
if (($foundline1 - $parms[0]) <= ($parms[0] - $foundline2)) {
|
||||
$foundline = $foundline1;
|
||||
} else {
|
||||
$foundline = $foundline2;
|
||||
}
|
||||
} else {
|
||||
$found = 0;
|
||||
}
|
||||
|
||||
# if found replace
|
||||
if ($found == 1) {
|
||||
$delta = $parms[0] - $foundline;
|
||||
print "Found replacement tag for \"$parms[1]\" on line $srcline which refers to line $foundline (delta $delta)\n";
|
||||
$_ =~ s/@\Q$m[1]\E@/$foundline/;
|
||||
} else {
|
||||
print "ERROR: The tag \"$parms[1]\" on line $srcline was not found in the most recently parsed source!\n";
|
||||
}
|
||||
|
||||
# remake the rest of the line
|
||||
$cnt = @m;
|
||||
$txt = "";
|
||||
for ($i = 2; $i < $cnt; $i++) {
|
||||
$txt = $txt . $m[$i] . "@";
|
||||
}
|
||||
}
|
||||
print OUT $_;
|
||||
++$wroteline;
|
||||
} elsif ($_ =~ /~.+~/) {
|
||||
# line contains a ~text~ pair used to refer to indexing :-)
|
||||
$txt = $_;
|
||||
while ($txt =~ /~.+~/) {
|
||||
@m = split("~", $txt);
|
||||
|
||||
# word is the second position
|
||||
$word = @m[1];
|
||||
$a = $index1{$word};
|
||||
$b = $index2{$word};
|
||||
$c = $index3{$word};
|
||||
|
||||
# if chapter (a) is zero it wasn't found
|
||||
if ($a == 0) {
|
||||
print "ERROR: the tag \"$word\" on line $srcline was not found previously marked.\n";
|
||||
} else {
|
||||
# format the tag as x, x.y or x.y.z depending on the values
|
||||
$str = $a;
|
||||
$str = $str . ".$b" if ($b != 0);
|
||||
$str = $str . ".$c" if ($c != 0);
|
||||
|
||||
if ($b == 0 && $c == 0) {
|
||||
# its a chapter
|
||||
if ($a <= 10) {
|
||||
if ($a == 1) {
|
||||
$str = "chapter one";
|
||||
} elsif ($a == 2) {
|
||||
$str = "chapter two";
|
||||
} elsif ($a == 3) {
|
||||
$str = "chapter three";
|
||||
} elsif ($a == 4) {
|
||||
$str = "chapter four";
|
||||
} elsif ($a == 5) {
|
||||
$str = "chapter five";
|
||||
} elsif ($a == 6) {
|
||||
$str = "chapter six";
|
||||
} elsif ($a == 7) {
|
||||
$str = "chapter seven";
|
||||
} elsif ($a == 8) {
|
||||
$str = "chapter eight";
|
||||
} elsif ($a == 9) {
|
||||
$str = "chapter nine";
|
||||
} elsif ($a == 10) {
|
||||
$str = "chapter ten";
|
||||
}
|
||||
} else {
|
||||
$str = "chapter " . $str;
|
||||
}
|
||||
} else {
|
||||
$str = "section " . $str if ($b != 0 && $c == 0);
|
||||
$str = "sub-section " . $str if ($b != 0 && $c != 0);
|
||||
}
|
||||
|
||||
#substitute
|
||||
$_ =~ s/~\Q$word\E~/$str/;
|
||||
|
||||
print "Found replacement tag for marker \"$word\" on line $srcline which refers to $str\n";
|
||||
}
|
||||
|
||||
# remake rest of the line
|
||||
$cnt = @m;
|
||||
$txt = "";
|
||||
for ($i = 2; $i < $cnt; $i++) {
|
||||
$txt = $txt . $m[$i] . "~";
|
||||
}
|
||||
}
|
||||
print OUT $_;
|
||||
++$wroteline;
|
||||
} elsif ($_ =~ m/FIGU/) {
|
||||
# FIGU,file,caption
|
||||
chomp($_);
|
||||
@m = split(",", $_);
|
||||
print OUT "\\begin{center}\n\\begin{figure}[here]\n\\includegraphics{pics/$m[1]$graph}\n";
|
||||
print OUT "\\caption{$m[2]}\n\\label{pic:$m[1]}\n\\end{figure}\n\\end{center}\n";
|
||||
$wroteline += 4;
|
||||
} else {
|
||||
print OUT $_;
|
||||
++$wroteline;
|
||||
}
|
||||
}
|
||||
print "Read $readline lines, wrote $wroteline lines\n";
|
||||
|
||||
close (OUT);
|
||||
close (IN);
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,736 +0,0 @@
|
||||
#include <time.h>
|
||||
|
||||
#ifdef IOWNANATHLON
|
||||
#include <unistd.h>
|
||||
#define SLEEP sleep(4)
|
||||
#else
|
||||
#define SLEEP
|
||||
#endif
|
||||
|
||||
#include "tommath.h"
|
||||
|
||||
void ndraw(mp_int * a, char *name)
|
||||
{
|
||||
char buf[16000];
|
||||
|
||||
printf("%s: ", name);
|
||||
mp_toradix(a, buf, 10);
|
||||
printf("%s\n", buf);
|
||||
}
|
||||
|
||||
static void draw(mp_int * a)
|
||||
{
|
||||
ndraw(a, "");
|
||||
}
|
||||
|
||||
|
||||
unsigned long lfsr = 0xAAAAAAAAUL;
|
||||
|
||||
int lbit(void)
|
||||
{
|
||||
if (lfsr & 0x80000000UL) {
|
||||
lfsr = ((lfsr << 1) ^ 0x8000001BUL) & 0xFFFFFFFFUL;
|
||||
return 1;
|
||||
} else {
|
||||
lfsr <<= 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int myrng(unsigned char *dst, int len, void *dat)
|
||||
{
|
||||
int x;
|
||||
|
||||
for (x = 0; x < len; x++)
|
||||
dst[x] = rand() & 0xFF;
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
|
||||
char cmd[4096], buf[4096];
|
||||
int main(void)
|
||||
{
|
||||
mp_int a, b, c, d, e, f;
|
||||
unsigned long expt_n, add_n, sub_n, mul_n, div_n, sqr_n, mul2d_n, div2d_n,
|
||||
gcd_n, lcm_n, inv_n, div2_n, mul2_n, add_d_n, sub_d_n, t;
|
||||
unsigned rr;
|
||||
int i, n, err, cnt, ix, old_kara_m, old_kara_s;
|
||||
mp_digit mp;
|
||||
|
||||
|
||||
mp_init(&a);
|
||||
mp_init(&b);
|
||||
mp_init(&c);
|
||||
mp_init(&d);
|
||||
mp_init(&e);
|
||||
mp_init(&f);
|
||||
|
||||
srand(time(NULL));
|
||||
|
||||
#if 0
|
||||
// test montgomery
|
||||
printf("Testing montgomery...\n");
|
||||
for (i = 1; i < 10; i++) {
|
||||
printf("Testing digit size: %d\n", i);
|
||||
for (n = 0; n < 1000; n++) {
|
||||
mp_rand(&a, i);
|
||||
a.dp[0] |= 1;
|
||||
|
||||
// let's see if R is right
|
||||
mp_montgomery_calc_normalization(&b, &a);
|
||||
mp_montgomery_setup(&a, &mp);
|
||||
|
||||
// now test a random reduction
|
||||
for (ix = 0; ix < 100; ix++) {
|
||||
mp_rand(&c, 1 + abs(rand()) % (2*i));
|
||||
mp_copy(&c, &d);
|
||||
mp_copy(&c, &e);
|
||||
|
||||
mp_mod(&d, &a, &d);
|
||||
mp_montgomery_reduce(&c, &a, mp);
|
||||
mp_mulmod(&c, &b, &a, &c);
|
||||
|
||||
if (mp_cmp(&c, &d) != MP_EQ) {
|
||||
printf("d = e mod a, c = e MOD a\n");
|
||||
mp_todecimal(&a, buf); printf("a = %s\n", buf);
|
||||
mp_todecimal(&e, buf); printf("e = %s\n", buf);
|
||||
mp_todecimal(&d, buf); printf("d = %s\n", buf);
|
||||
mp_todecimal(&c, buf); printf("c = %s\n", buf);
|
||||
printf("compare no compare!\n"); exit(EXIT_FAILURE); }
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("done\n");
|
||||
|
||||
// test mp_get_int
|
||||
printf("Testing: mp_get_int\n");
|
||||
for (i = 0; i < 1000; ++i) {
|
||||
t = ((unsigned long) rand() * rand() + 1) & 0xFFFFFFFF;
|
||||
mp_set_int(&a, t);
|
||||
if (t != mp_get_int(&a)) {
|
||||
printf("mp_get_int() bad result!\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
mp_set_int(&a, 0);
|
||||
if (mp_get_int(&a) != 0) {
|
||||
printf("mp_get_int() bad result!\n");
|
||||
return 1;
|
||||
}
|
||||
mp_set_int(&a, 0xffffffff);
|
||||
if (mp_get_int(&a) != 0xffffffff) {
|
||||
printf("mp_get_int() bad result!\n");
|
||||
return 1;
|
||||
}
|
||||
// test mp_sqrt
|
||||
printf("Testing: mp_sqrt\n");
|
||||
for (i = 0; i < 1000; ++i) {
|
||||
printf("%6d\r", i);
|
||||
fflush(stdout);
|
||||
n = (rand() & 15) + 1;
|
||||
mp_rand(&a, n);
|
||||
if (mp_sqrt(&a, &b) != MP_OKAY) {
|
||||
printf("mp_sqrt() error!\n");
|
||||
return 1;
|
||||
}
|
||||
mp_n_root(&a, 2, &a);
|
||||
if (mp_cmp_mag(&b, &a) != MP_EQ) {
|
||||
printf("mp_sqrt() bad result!\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
printf("\nTesting: mp_is_square\n");
|
||||
for (i = 0; i < 1000; ++i) {
|
||||
printf("%6d\r", i);
|
||||
fflush(stdout);
|
||||
|
||||
/* test mp_is_square false negatives */
|
||||
n = (rand() & 7) + 1;
|
||||
mp_rand(&a, n);
|
||||
mp_sqr(&a, &a);
|
||||
if (mp_is_square(&a, &n) != MP_OKAY) {
|
||||
printf("fn:mp_is_square() error!\n");
|
||||
return 1;
|
||||
}
|
||||
if (n == 0) {
|
||||
printf("fn:mp_is_square() bad result!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* test for false positives */
|
||||
mp_add_d(&a, 1, &a);
|
||||
if (mp_is_square(&a, &n) != MP_OKAY) {
|
||||
printf("fp:mp_is_square() error!\n");
|
||||
return 1;
|
||||
}
|
||||
if (n == 1) {
|
||||
printf("fp:mp_is_square() bad result!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
printf("\n\n");
|
||||
|
||||
/* test for size */
|
||||
for (ix = 10; ix < 128; ix++) {
|
||||
printf("Testing (not safe-prime): %9d bits \r", ix);
|
||||
fflush(stdout);
|
||||
err =
|
||||
mp_prime_random_ex(&a, 8, ix,
|
||||
(rand() & 1) ? LTM_PRIME_2MSB_OFF :
|
||||
LTM_PRIME_2MSB_ON, myrng, NULL);
|
||||
if (err != MP_OKAY) {
|
||||
printf("failed with err code %d\n", err);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (mp_count_bits(&a) != ix) {
|
||||
printf("Prime is %d not %d bits!!!\n", mp_count_bits(&a), ix);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
for (ix = 16; ix < 128; ix++) {
|
||||
printf("Testing ( safe-prime): %9d bits \r", ix);
|
||||
fflush(stdout);
|
||||
err =
|
||||
mp_prime_random_ex(&a, 8, ix,
|
||||
((rand() & 1) ? LTM_PRIME_2MSB_OFF :
|
||||
LTM_PRIME_2MSB_ON) | LTM_PRIME_SAFE, myrng,
|
||||
NULL);
|
||||
if (err != MP_OKAY) {
|
||||
printf("failed with err code %d\n", err);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (mp_count_bits(&a) != ix) {
|
||||
printf("Prime is %d not %d bits!!!\n", mp_count_bits(&a), ix);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
/* let's see if it's really a safe prime */
|
||||
mp_sub_d(&a, 1, &a);
|
||||
mp_div_2(&a, &a);
|
||||
mp_prime_is_prime(&a, 8, &cnt);
|
||||
if (cnt != MP_YES) {
|
||||
printf("sub is not prime!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
printf("\n\n");
|
||||
|
||||
mp_read_radix(&a, "123456", 10);
|
||||
mp_toradix_n(&a, buf, 10, 3);
|
||||
printf("a == %s\n", buf);
|
||||
mp_toradix_n(&a, buf, 10, 4);
|
||||
printf("a == %s\n", buf);
|
||||
mp_toradix_n(&a, buf, 10, 30);
|
||||
printf("a == %s\n", buf);
|
||||
|
||||
|
||||
#if 0
|
||||
for (;;) {
|
||||
fgets(buf, sizeof(buf), stdin);
|
||||
mp_read_radix(&a, buf, 10);
|
||||
mp_prime_next_prime(&a, 5, 1);
|
||||
mp_toradix(&a, buf, 10);
|
||||
printf("%s, %lu\n", buf, a.dp[0] & 3);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* test mp_cnt_lsb */
|
||||
printf("testing mp_cnt_lsb...\n");
|
||||
mp_set(&a, 1);
|
||||
for (ix = 0; ix < 1024; ix++) {
|
||||
if (mp_cnt_lsb(&a) != ix) {
|
||||
printf("Failed at %d, %d\n", ix, mp_cnt_lsb(&a));
|
||||
return 0;
|
||||
}
|
||||
mp_mul_2(&a, &a);
|
||||
}
|
||||
|
||||
/* test mp_reduce_2k */
|
||||
printf("Testing mp_reduce_2k...\n");
|
||||
for (cnt = 3; cnt <= 128; ++cnt) {
|
||||
mp_digit tmp;
|
||||
|
||||
mp_2expt(&a, cnt);
|
||||
mp_sub_d(&a, 2, &a); /* a = 2**cnt - 2 */
|
||||
|
||||
|
||||
printf("\nTesting %4d bits", cnt);
|
||||
printf("(%d)", mp_reduce_is_2k(&a));
|
||||
mp_reduce_2k_setup(&a, &tmp);
|
||||
printf("(%d)", tmp);
|
||||
for (ix = 0; ix < 1000; ix++) {
|
||||
if (!(ix & 127)) {
|
||||
printf(".");
|
||||
fflush(stdout);
|
||||
}
|
||||
mp_rand(&b, (cnt / DIGIT_BIT + 1) * 2);
|
||||
mp_copy(&c, &b);
|
||||
mp_mod(&c, &a, &c);
|
||||
mp_reduce_2k(&b, &a, 2);
|
||||
if (mp_cmp(&c, &b)) {
|
||||
printf("FAILED\n");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* test mp_div_3 */
|
||||
printf("Testing mp_div_3...\n");
|
||||
mp_set(&d, 3);
|
||||
for (cnt = 0; cnt < 10000;) {
|
||||
mp_digit r1, r2;
|
||||
|
||||
if (!(++cnt & 127))
|
||||
printf("%9d\r", cnt);
|
||||
mp_rand(&a, abs(rand()) % 128 + 1);
|
||||
mp_div(&a, &d, &b, &e);
|
||||
mp_div_3(&a, &c, &r2);
|
||||
|
||||
if (mp_cmp(&b, &c) || mp_cmp_d(&e, r2)) {
|
||||
printf("\n\nmp_div_3 => Failure\n");
|
||||
}
|
||||
}
|
||||
printf("\n\nPassed div_3 testing\n");
|
||||
|
||||
/* test the DR reduction */
|
||||
printf("testing mp_dr_reduce...\n");
|
||||
for (cnt = 2; cnt < 32; cnt++) {
|
||||
printf("%d digit modulus\n", cnt);
|
||||
mp_grow(&a, cnt);
|
||||
mp_zero(&a);
|
||||
for (ix = 1; ix < cnt; ix++) {
|
||||
a.dp[ix] = MP_MASK;
|
||||
}
|
||||
a.used = cnt;
|
||||
a.dp[0] = 3;
|
||||
|
||||
mp_rand(&b, cnt - 1);
|
||||
mp_copy(&b, &c);
|
||||
|
||||
rr = 0;
|
||||
do {
|
||||
if (!(rr & 127)) {
|
||||
printf("%9lu\r", rr);
|
||||
fflush(stdout);
|
||||
}
|
||||
mp_sqr(&b, &b);
|
||||
mp_add_d(&b, 1, &b);
|
||||
mp_copy(&b, &c);
|
||||
|
||||
mp_mod(&b, &a, &b);
|
||||
mp_dr_reduce(&c, &a, (((mp_digit) 1) << DIGIT_BIT) - a.dp[0]);
|
||||
|
||||
if (mp_cmp(&b, &c) != MP_EQ) {
|
||||
printf("Failed on trial %lu\n", rr);
|
||||
exit(-1);
|
||||
|
||||
}
|
||||
} while (++rr < 500);
|
||||
printf("Passed DR test for %d digits\n", cnt);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* test the mp_reduce_2k_l code */
|
||||
#if 0
|
||||
#if 0
|
||||
/* first load P with 2^1024 - 0x2A434 B9FDEC95 D8F9D550 FFFFFFFF FFFFFFFF */
|
||||
mp_2expt(&a, 1024);
|
||||
mp_read_radix(&b, "2A434B9FDEC95D8F9D550FFFFFFFFFFFFFFFF", 16);
|
||||
mp_sub(&a, &b, &a);
|
||||
#elif 1
|
||||
/* p = 2^2048 - 0x1 00000000 00000000 00000000 00000000 4945DDBF 8EA2A91D 5776399B B83E188F */
|
||||
mp_2expt(&a, 2048);
|
||||
mp_read_radix(&b,
|
||||
"1000000000000000000000000000000004945DDBF8EA2A91D5776399BB83E188F",
|
||||
16);
|
||||
mp_sub(&a, &b, &a);
|
||||
#endif
|
||||
|
||||
mp_todecimal(&a, buf);
|
||||
printf("p==%s\n", buf);
|
||||
/* now mp_reduce_is_2k_l() should return */
|
||||
if (mp_reduce_is_2k_l(&a) != 1) {
|
||||
printf("mp_reduce_is_2k_l() return 0, should be 1\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
mp_reduce_2k_setup_l(&a, &d);
|
||||
/* now do a million square+1 to see if it varies */
|
||||
mp_rand(&b, 64);
|
||||
mp_mod(&b, &a, &b);
|
||||
mp_copy(&b, &c);
|
||||
printf("testing mp_reduce_2k_l...");
|
||||
fflush(stdout);
|
||||
for (cnt = 0; cnt < (1UL << 20); cnt++) {
|
||||
mp_sqr(&b, &b);
|
||||
mp_add_d(&b, 1, &b);
|
||||
mp_reduce_2k_l(&b, &a, &d);
|
||||
mp_sqr(&c, &c);
|
||||
mp_add_d(&c, 1, &c);
|
||||
mp_mod(&c, &a, &c);
|
||||
if (mp_cmp(&b, &c) != MP_EQ) {
|
||||
printf("mp_reduce_2k_l() failed at step %lu\n", cnt);
|
||||
mp_tohex(&b, buf);
|
||||
printf("b == %s\n", buf);
|
||||
mp_tohex(&c, buf);
|
||||
printf("c == %s\n", buf);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
printf("...Passed\n");
|
||||
#endif
|
||||
|
||||
div2_n = mul2_n = inv_n = expt_n = lcm_n = gcd_n = add_n =
|
||||
sub_n = mul_n = div_n = sqr_n = mul2d_n = div2d_n = cnt = add_d_n =
|
||||
sub_d_n = 0;
|
||||
|
||||
/* force KARA and TOOM to enable despite cutoffs */
|
||||
KARATSUBA_SQR_CUTOFF = KARATSUBA_MUL_CUTOFF = 8;
|
||||
TOOM_SQR_CUTOFF = TOOM_MUL_CUTOFF = 16;
|
||||
|
||||
for (;;) {
|
||||
/* randomly clear and re-init one variable, this has the affect of triming the alloc space */
|
||||
switch (abs(rand()) % 7) {
|
||||
case 0:
|
||||
mp_clear(&a);
|
||||
mp_init(&a);
|
||||
break;
|
||||
case 1:
|
||||
mp_clear(&b);
|
||||
mp_init(&b);
|
||||
break;
|
||||
case 2:
|
||||
mp_clear(&c);
|
||||
mp_init(&c);
|
||||
break;
|
||||
case 3:
|
||||
mp_clear(&d);
|
||||
mp_init(&d);
|
||||
break;
|
||||
case 4:
|
||||
mp_clear(&e);
|
||||
mp_init(&e);
|
||||
break;
|
||||
case 5:
|
||||
mp_clear(&f);
|
||||
mp_init(&f);
|
||||
break;
|
||||
case 6:
|
||||
break; /* don't clear any */
|
||||
}
|
||||
|
||||
|
||||
printf
|
||||
("%4lu/%4lu/%4lu/%4lu/%4lu/%4lu/%4lu/%4lu/%4lu/%4lu/%4lu/%4lu/%4lu/%4lu/%4lu ",
|
||||
add_n, sub_n, mul_n, div_n, sqr_n, mul2d_n, div2d_n, gcd_n, lcm_n,
|
||||
expt_n, inv_n, div2_n, mul2_n, add_d_n, sub_d_n);
|
||||
fgets(cmd, 4095, stdin);
|
||||
cmd[strlen(cmd) - 1] = 0;
|
||||
printf("%s ]\r", cmd);
|
||||
fflush(stdout);
|
||||
if (!strcmp(cmd, "mul2d")) {
|
||||
++mul2d_n;
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&a, buf, 64);
|
||||
fgets(buf, 4095, stdin);
|
||||
sscanf(buf, "%d", &rr);
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&b, buf, 64);
|
||||
|
||||
mp_mul_2d(&a, rr, &a);
|
||||
a.sign = b.sign;
|
||||
if (mp_cmp(&a, &b) != MP_EQ) {
|
||||
printf("mul2d failed, rr == %d\n", rr);
|
||||
draw(&a);
|
||||
draw(&b);
|
||||
return 0;
|
||||
}
|
||||
} else if (!strcmp(cmd, "div2d")) {
|
||||
++div2d_n;
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&a, buf, 64);
|
||||
fgets(buf, 4095, stdin);
|
||||
sscanf(buf, "%d", &rr);
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&b, buf, 64);
|
||||
|
||||
mp_div_2d(&a, rr, &a, &e);
|
||||
a.sign = b.sign;
|
||||
if (a.used == b.used && a.used == 0) {
|
||||
a.sign = b.sign = MP_ZPOS;
|
||||
}
|
||||
if (mp_cmp(&a, &b) != MP_EQ) {
|
||||
printf("div2d failed, rr == %d\n", rr);
|
||||
draw(&a);
|
||||
draw(&b);
|
||||
return 0;
|
||||
}
|
||||
} else if (!strcmp(cmd, "add")) {
|
||||
++add_n;
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&a, buf, 64);
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&b, buf, 64);
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&c, buf, 64);
|
||||
mp_copy(&a, &d);
|
||||
mp_add(&d, &b, &d);
|
||||
if (mp_cmp(&c, &d) != MP_EQ) {
|
||||
printf("add %lu failure!\n", add_n);
|
||||
draw(&a);
|
||||
draw(&b);
|
||||
draw(&c);
|
||||
draw(&d);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* test the sign/unsigned storage functions */
|
||||
|
||||
rr = mp_signed_bin_size(&c);
|
||||
mp_to_signed_bin(&c, (unsigned char *) cmd);
|
||||
memset(cmd + rr, rand() & 255, sizeof(cmd) - rr);
|
||||
mp_read_signed_bin(&d, (unsigned char *) cmd, rr);
|
||||
if (mp_cmp(&c, &d) != MP_EQ) {
|
||||
printf("mp_signed_bin failure!\n");
|
||||
draw(&c);
|
||||
draw(&d);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
rr = mp_unsigned_bin_size(&c);
|
||||
mp_to_unsigned_bin(&c, (unsigned char *) cmd);
|
||||
memset(cmd + rr, rand() & 255, sizeof(cmd) - rr);
|
||||
mp_read_unsigned_bin(&d, (unsigned char *) cmd, rr);
|
||||
if (mp_cmp_mag(&c, &d) != MP_EQ) {
|
||||
printf("mp_unsigned_bin failure!\n");
|
||||
draw(&c);
|
||||
draw(&d);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} else if (!strcmp(cmd, "sub")) {
|
||||
++sub_n;
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&a, buf, 64);
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&b, buf, 64);
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&c, buf, 64);
|
||||
mp_copy(&a, &d);
|
||||
mp_sub(&d, &b, &d);
|
||||
if (mp_cmp(&c, &d) != MP_EQ) {
|
||||
printf("sub %lu failure!\n", sub_n);
|
||||
draw(&a);
|
||||
draw(&b);
|
||||
draw(&c);
|
||||
draw(&d);
|
||||
return 0;
|
||||
}
|
||||
} else if (!strcmp(cmd, "mul")) {
|
||||
++mul_n;
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&a, buf, 64);
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&b, buf, 64);
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&c, buf, 64);
|
||||
mp_copy(&a, &d);
|
||||
mp_mul(&d, &b, &d);
|
||||
if (mp_cmp(&c, &d) != MP_EQ) {
|
||||
printf("mul %lu failure!\n", mul_n);
|
||||
draw(&a);
|
||||
draw(&b);
|
||||
draw(&c);
|
||||
draw(&d);
|
||||
return 0;
|
||||
}
|
||||
} else if (!strcmp(cmd, "div")) {
|
||||
++div_n;
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&a, buf, 64);
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&b, buf, 64);
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&c, buf, 64);
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&d, buf, 64);
|
||||
|
||||
mp_div(&a, &b, &e, &f);
|
||||
if (mp_cmp(&c, &e) != MP_EQ || mp_cmp(&d, &f) != MP_EQ) {
|
||||
printf("div %lu %d, %d, failure!\n", div_n, mp_cmp(&c, &e),
|
||||
mp_cmp(&d, &f));
|
||||
draw(&a);
|
||||
draw(&b);
|
||||
draw(&c);
|
||||
draw(&d);
|
||||
draw(&e);
|
||||
draw(&f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} else if (!strcmp(cmd, "sqr")) {
|
||||
++sqr_n;
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&a, buf, 64);
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&b, buf, 64);
|
||||
mp_copy(&a, &c);
|
||||
mp_sqr(&c, &c);
|
||||
if (mp_cmp(&b, &c) != MP_EQ) {
|
||||
printf("sqr %lu failure!\n", sqr_n);
|
||||
draw(&a);
|
||||
draw(&b);
|
||||
draw(&c);
|
||||
return 0;
|
||||
}
|
||||
} else if (!strcmp(cmd, "gcd")) {
|
||||
++gcd_n;
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&a, buf, 64);
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&b, buf, 64);
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&c, buf, 64);
|
||||
mp_copy(&a, &d);
|
||||
mp_gcd(&d, &b, &d);
|
||||
d.sign = c.sign;
|
||||
if (mp_cmp(&c, &d) != MP_EQ) {
|
||||
printf("gcd %lu failure!\n", gcd_n);
|
||||
draw(&a);
|
||||
draw(&b);
|
||||
draw(&c);
|
||||
draw(&d);
|
||||
return 0;
|
||||
}
|
||||
} else if (!strcmp(cmd, "lcm")) {
|
||||
++lcm_n;
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&a, buf, 64);
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&b, buf, 64);
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&c, buf, 64);
|
||||
mp_copy(&a, &d);
|
||||
mp_lcm(&d, &b, &d);
|
||||
d.sign = c.sign;
|
||||
if (mp_cmp(&c, &d) != MP_EQ) {
|
||||
printf("lcm %lu failure!\n", lcm_n);
|
||||
draw(&a);
|
||||
draw(&b);
|
||||
draw(&c);
|
||||
draw(&d);
|
||||
return 0;
|
||||
}
|
||||
} else if (!strcmp(cmd, "expt")) {
|
||||
++expt_n;
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&a, buf, 64);
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&b, buf, 64);
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&c, buf, 64);
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&d, buf, 64);
|
||||
mp_copy(&a, &e);
|
||||
mp_exptmod(&e, &b, &c, &e);
|
||||
if (mp_cmp(&d, &e) != MP_EQ) {
|
||||
printf("expt %lu failure!\n", expt_n);
|
||||
draw(&a);
|
||||
draw(&b);
|
||||
draw(&c);
|
||||
draw(&d);
|
||||
draw(&e);
|
||||
return 0;
|
||||
}
|
||||
} else if (!strcmp(cmd, "invmod")) {
|
||||
++inv_n;
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&a, buf, 64);
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&b, buf, 64);
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&c, buf, 64);
|
||||
mp_invmod(&a, &b, &d);
|
||||
mp_mulmod(&d, &a, &b, &e);
|
||||
if (mp_cmp_d(&e, 1) != MP_EQ) {
|
||||
printf("inv [wrong value from MPI?!] failure\n");
|
||||
draw(&a);
|
||||
draw(&b);
|
||||
draw(&c);
|
||||
draw(&d);
|
||||
mp_gcd(&a, &b, &e);
|
||||
draw(&e);
|
||||
return 0;
|
||||
}
|
||||
|
||||
} else if (!strcmp(cmd, "div2")) {
|
||||
++div2_n;
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&a, buf, 64);
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&b, buf, 64);
|
||||
mp_div_2(&a, &c);
|
||||
if (mp_cmp(&c, &b) != MP_EQ) {
|
||||
printf("div_2 %lu failure\n", div2_n);
|
||||
draw(&a);
|
||||
draw(&b);
|
||||
draw(&c);
|
||||
return 0;
|
||||
}
|
||||
} else if (!strcmp(cmd, "mul2")) {
|
||||
++mul2_n;
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&a, buf, 64);
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&b, buf, 64);
|
||||
mp_mul_2(&a, &c);
|
||||
if (mp_cmp(&c, &b) != MP_EQ) {
|
||||
printf("mul_2 %lu failure\n", mul2_n);
|
||||
draw(&a);
|
||||
draw(&b);
|
||||
draw(&c);
|
||||
return 0;
|
||||
}
|
||||
} else if (!strcmp(cmd, "add_d")) {
|
||||
++add_d_n;
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&a, buf, 64);
|
||||
fgets(buf, 4095, stdin);
|
||||
sscanf(buf, "%d", &ix);
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&b, buf, 64);
|
||||
mp_add_d(&a, ix, &c);
|
||||
if (mp_cmp(&b, &c) != MP_EQ) {
|
||||
printf("add_d %lu failure\n", add_d_n);
|
||||
draw(&a);
|
||||
draw(&b);
|
||||
draw(&c);
|
||||
printf("d == %d\n", ix);
|
||||
return 0;
|
||||
}
|
||||
} else if (!strcmp(cmd, "sub_d")) {
|
||||
++sub_d_n;
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&a, buf, 64);
|
||||
fgets(buf, 4095, stdin);
|
||||
sscanf(buf, "%d", &ix);
|
||||
fgets(buf, 4095, stdin);
|
||||
mp_read_radix(&b, buf, 64);
|
||||
mp_sub_d(&a, ix, &c);
|
||||
if (mp_cmp(&b, &c) != MP_EQ) {
|
||||
printf("sub_d %lu failure\n", sub_d_n);
|
||||
draw(&a);
|
||||
draw(&b);
|
||||
draw(&c);
|
||||
printf("d == %d\n", ix);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1,315 +0,0 @@
|
||||
#include <tommath.h>
|
||||
#include <time.h>
|
||||
|
||||
ulong64 _tt;
|
||||
|
||||
#ifdef IOWNANATHLON
|
||||
#include <unistd.h>
|
||||
#define SLEEP sleep(4)
|
||||
#else
|
||||
#define SLEEP
|
||||
#endif
|
||||
|
||||
|
||||
void ndraw(mp_int * a, char *name)
|
||||
{
|
||||
char buf[4096];
|
||||
|
||||
printf("%s: ", name);
|
||||
mp_toradix(a, buf, 64);
|
||||
printf("%s\n", buf);
|
||||
}
|
||||
|
||||
static void draw(mp_int * a)
|
||||
{
|
||||
ndraw(a, "");
|
||||
}
|
||||
|
||||
|
||||
unsigned long lfsr = 0xAAAAAAAAUL;
|
||||
|
||||
int lbit(void)
|
||||
{
|
||||
if (lfsr & 0x80000000UL) {
|
||||
lfsr = ((lfsr << 1) ^ 0x8000001BUL) & 0xFFFFFFFFUL;
|
||||
return 1;
|
||||
} else {
|
||||
lfsr <<= 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* RDTSC from Scott Duplichan */
|
||||
static ulong64 TIMFUNC(void)
|
||||
{
|
||||
#if defined __GNUC__
|
||||
#if defined(__i386__) || defined(__x86_64__)
|
||||
unsigned long long a;
|
||||
__asm__ __volatile__("rdtsc\nmovl %%eax,%0\nmovl %%edx,4+%0\n"::
|
||||
"m"(a):"%eax", "%edx");
|
||||
return a;
|
||||
#else /* gcc-IA64 version */
|
||||
unsigned long result;
|
||||
__asm__ __volatile__("mov %0=ar.itc":"=r"(result)::"memory");
|
||||
|
||||
while (__builtin_expect((int) result == -1, 0))
|
||||
__asm__ __volatile__("mov %0=ar.itc":"=r"(result)::"memory");
|
||||
|
||||
return result;
|
||||
#endif
|
||||
|
||||
// Microsoft and Intel Windows compilers
|
||||
#elif defined _M_IX86
|
||||
__asm rdtsc
|
||||
#elif defined _M_AMD64
|
||||
return __rdtsc();
|
||||
#elif defined _M_IA64
|
||||
#if defined __INTEL_COMPILER
|
||||
#include <ia64intrin.h>
|
||||
#endif
|
||||
return __getReg(3116);
|
||||
#else
|
||||
#error need rdtsc function for this build
|
||||
#endif
|
||||
}
|
||||
|
||||
#define DO(x) x; x;
|
||||
//#define DO4(x) DO2(x); DO2(x);
|
||||
//#define DO8(x) DO4(x); DO4(x);
|
||||
//#define DO(x) DO8(x); DO8(x);
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ulong64 tt, gg, CLK_PER_SEC;
|
||||
FILE *log, *logb, *logc, *logd;
|
||||
mp_int a, b, c, d, e, f;
|
||||
int n, cnt, ix, old_kara_m, old_kara_s;
|
||||
unsigned rr;
|
||||
|
||||
mp_init(&a);
|
||||
mp_init(&b);
|
||||
mp_init(&c);
|
||||
mp_init(&d);
|
||||
mp_init(&e);
|
||||
mp_init(&f);
|
||||
|
||||
srand(time(NULL));
|
||||
|
||||
|
||||
/* temp. turn off TOOM */
|
||||
TOOM_MUL_CUTOFF = TOOM_SQR_CUTOFF = 100000;
|
||||
|
||||
CLK_PER_SEC = TIMFUNC();
|
||||
sleep(1);
|
||||
CLK_PER_SEC = TIMFUNC() - CLK_PER_SEC;
|
||||
|
||||
printf("CLK_PER_SEC == %llu\n", CLK_PER_SEC);
|
||||
goto exptmod;
|
||||
log = fopen("logs/add.log", "w");
|
||||
for (cnt = 8; cnt <= 128; cnt += 8) {
|
||||
SLEEP;
|
||||
mp_rand(&a, cnt);
|
||||
mp_rand(&b, cnt);
|
||||
rr = 0;
|
||||
tt = -1;
|
||||
do {
|
||||
gg = TIMFUNC();
|
||||
DO(mp_add(&a, &b, &c));
|
||||
gg = (TIMFUNC() - gg) >> 1;
|
||||
if (tt > gg)
|
||||
tt = gg;
|
||||
} while (++rr < 100000);
|
||||
printf("Adding\t\t%4d-bit => %9llu/sec, %9llu cycles\n",
|
||||
mp_count_bits(&a), CLK_PER_SEC / tt, tt);
|
||||
fprintf(log, "%d %9llu\n", cnt * DIGIT_BIT, tt);
|
||||
fflush(log);
|
||||
}
|
||||
fclose(log);
|
||||
|
||||
log = fopen("logs/sub.log", "w");
|
||||
for (cnt = 8; cnt <= 128; cnt += 8) {
|
||||
SLEEP;
|
||||
mp_rand(&a, cnt);
|
||||
mp_rand(&b, cnt);
|
||||
rr = 0;
|
||||
tt = -1;
|
||||
do {
|
||||
gg = TIMFUNC();
|
||||
DO(mp_sub(&a, &b, &c));
|
||||
gg = (TIMFUNC() - gg) >> 1;
|
||||
if (tt > gg)
|
||||
tt = gg;
|
||||
} while (++rr < 100000);
|
||||
|
||||
printf("Subtracting\t\t%4d-bit => %9llu/sec, %9llu cycles\n",
|
||||
mp_count_bits(&a), CLK_PER_SEC / tt, tt);
|
||||
fprintf(log, "%d %9llu\n", cnt * DIGIT_BIT, tt);
|
||||
fflush(log);
|
||||
}
|
||||
fclose(log);
|
||||
|
||||
/* do mult/square twice, first without karatsuba and second with */
|
||||
multtest:
|
||||
old_kara_m = KARATSUBA_MUL_CUTOFF;
|
||||
old_kara_s = KARATSUBA_SQR_CUTOFF;
|
||||
for (ix = 0; ix < 2; ix++) {
|
||||
printf("With%s Karatsuba\n", (ix == 0) ? "out" : "");
|
||||
|
||||
KARATSUBA_MUL_CUTOFF = (ix == 0) ? 9999 : old_kara_m;
|
||||
KARATSUBA_SQR_CUTOFF = (ix == 0) ? 9999 : old_kara_s;
|
||||
|
||||
log = fopen((ix == 0) ? "logs/mult.log" : "logs/mult_kara.log", "w");
|
||||
for (cnt = 4; cnt <= 10240 / DIGIT_BIT; cnt += 2) {
|
||||
SLEEP;
|
||||
mp_rand(&a, cnt);
|
||||
mp_rand(&b, cnt);
|
||||
rr = 0;
|
||||
tt = -1;
|
||||
do {
|
||||
gg = TIMFUNC();
|
||||
DO(mp_mul(&a, &b, &c));
|
||||
gg = (TIMFUNC() - gg) >> 1;
|
||||
if (tt > gg)
|
||||
tt = gg;
|
||||
} while (++rr < 100);
|
||||
printf("Multiplying\t%4d-bit => %9llu/sec, %9llu cycles\n",
|
||||
mp_count_bits(&a), CLK_PER_SEC / tt, tt);
|
||||
fprintf(log, "%d %9llu\n", mp_count_bits(&a), tt);
|
||||
fflush(log);
|
||||
}
|
||||
fclose(log);
|
||||
|
||||
log = fopen((ix == 0) ? "logs/sqr.log" : "logs/sqr_kara.log", "w");
|
||||
for (cnt = 4; cnt <= 10240 / DIGIT_BIT; cnt += 2) {
|
||||
SLEEP;
|
||||
mp_rand(&a, cnt);
|
||||
rr = 0;
|
||||
tt = -1;
|
||||
do {
|
||||
gg = TIMFUNC();
|
||||
DO(mp_sqr(&a, &b));
|
||||
gg = (TIMFUNC() - gg) >> 1;
|
||||
if (tt > gg)
|
||||
tt = gg;
|
||||
} while (++rr < 100);
|
||||
printf("Squaring\t%4d-bit => %9llu/sec, %9llu cycles\n",
|
||||
mp_count_bits(&a), CLK_PER_SEC / tt, tt);
|
||||
fprintf(log, "%d %9llu\n", mp_count_bits(&a), tt);
|
||||
fflush(log);
|
||||
}
|
||||
fclose(log);
|
||||
|
||||
}
|
||||
exptmod:
|
||||
|
||||
{
|
||||
char *primes[] = {
|
||||
/* 2K large moduli */
|
||||
"179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639474124377767893424865485276302219601246094119453082952085005768838150682342462881473913110540827237163350510684586239334100047359817950870678242457666208137217",
|
||||
"32317006071311007300714876688669951960444102669715484032130345427524655138867890893197201411522913463688717960921898019494119559150490921095088152386448283120630877367300996091750197750389652106796057638384067568276792218642619756161838094338476170470581645852036305042887575891541065808607552399123930385521914333389668342420684974786564569494856176035326322058077805659331026192708460314150258592864177116725943603718461857357598351152301645904403697613233287231227125684710820209725157101726931323469678542580656697935045997268352998638099733077152121140120031150424541696791951097529546801429027668869927491725169",
|
||||
"1044388881413152506691752710716624382579964249047383780384233483283953907971557456848826811934997558340890106714439262837987573438185793607263236087851365277945956976543709998340361590134383718314428070011855946226376318839397712745672334684344586617496807908705803704071284048740118609114467977783598029006686938976881787785946905630190260940599579453432823469303026696443059025015972399867714215541693835559885291486318237914434496734087811872639496475100189041349008417061675093668333850551032972088269550769983616369411933015213796825837188091833656751221318492846368125550225998300412344784862595674492194617023806505913245610825731835380087608622102834270197698202313169017678006675195485079921636419370285375124784014907159135459982790513399611551794271106831134090584272884279791554849782954323534517065223269061394905987693002122963395687782878948440616007412945674919823050571642377154816321380631045902916136926708342856440730447899971901781465763473223850267253059899795996090799469201774624817718449867455659250178329070473119433165550807568221846571746373296884912819520317457002440926616910874148385078411929804522981857338977648103126085902995208257421855249796721729039744118165938433694823325696642096892124547425283",
|
||||
/* 2K moduli mersenne primes */
|
||||
"6864797660130609714981900799081393217269435300143305409394463459185543183397656052122559640661454554977296311391480858037121987999716643812574028291115057151",
|
||||
"531137992816767098689588206552468627329593117727031923199444138200403559860852242739162502265229285668889329486246501015346579337652707239409519978766587351943831270835393219031728127",
|
||||
"10407932194664399081925240327364085538615262247266704805319112350403608059673360298012239441732324184842421613954281007791383566248323464908139906605677320762924129509389220345773183349661583550472959420547689811211693677147548478866962501384438260291732348885311160828538416585028255604666224831890918801847068222203140521026698435488732958028878050869736186900714720710555703168729087",
|
||||
"1475979915214180235084898622737381736312066145333169775147771216478570297878078949377407337049389289382748507531496480477281264838760259191814463365330269540496961201113430156902396093989090226259326935025281409614983499388222831448598601834318536230923772641390209490231836446899608210795482963763094236630945410832793769905399982457186322944729636418890623372171723742105636440368218459649632948538696905872650486914434637457507280441823676813517852099348660847172579408422316678097670224011990280170474894487426924742108823536808485072502240519452587542875349976558572670229633962575212637477897785501552646522609988869914013540483809865681250419497686697771007",
|
||||
"259117086013202627776246767922441530941818887553125427303974923161874019266586362086201209516800483406550695241733194177441689509238807017410377709597512042313066624082916353517952311186154862265604547691127595848775610568757931191017711408826252153849035830401185072116424747461823031471398340229288074545677907941037288235820705892351068433882986888616658650280927692080339605869308790500409503709875902119018371991620994002568935113136548829739112656797303241986517250116412703509705427773477972349821676443446668383119322540099648994051790241624056519054483690809616061625743042361721863339415852426431208737266591962061753535748892894599629195183082621860853400937932839420261866586142503251450773096274235376822938649407127700846077124211823080804139298087057504713825264571448379371125032081826126566649084251699453951887789613650248405739378594599444335231188280123660406262468609212150349937584782292237144339628858485938215738821232393687046160677362909315071",
|
||||
"190797007524439073807468042969529173669356994749940177394741882673528979787005053706368049835514900244303495954950709725762186311224148828811920216904542206960744666169364221195289538436845390250168663932838805192055137154390912666527533007309292687539092257043362517857366624699975402375462954490293259233303137330643531556539739921926201438606439020075174723029056838272505051571967594608350063404495977660656269020823960825567012344189908927956646011998057988548630107637380993519826582389781888135705408653045219655801758081251164080554609057468028203308718724654081055323215860189611391296030471108443146745671967766308925858547271507311563765171008318248647110097614890313562856541784154881743146033909602737947385055355960331855614540900081456378659068370317267696980001187750995491090350108417050917991562167972281070161305972518044872048331306383715094854938415738549894606070722584737978176686422134354526989443028353644037187375385397838259511833166416134323695660367676897722287918773420968982326089026150031515424165462111337527431154890666327374921446276833564519776797633875503548665093914556482031482248883127023777039667707976559857333357013727342079099064400455741830654320379350833236245819348824064783585692924881021978332974949906122664421376034687815350484991",
|
||||
|
||||
/* DR moduli */
|
||||
"14059105607947488696282932836518693308967803494693489478439861164411992439598399594747002144074658928593502845729752797260025831423419686528151609940203368612079",
|
||||
"101745825697019260773923519755878567461315282017759829107608914364075275235254395622580447400994175578963163918967182013639660669771108475957692810857098847138903161308502419410142185759152435680068435915159402496058513611411688900243039",
|
||||
"736335108039604595805923406147184530889923370574768772191969612422073040099331944991573923112581267542507986451953227192970402893063850485730703075899286013451337291468249027691733891486704001513279827771740183629161065194874727962517148100775228363421083691764065477590823919364012917984605619526140821797602431",
|
||||
"38564998830736521417281865696453025806593491967131023221754800625044118265468851210705360385717536794615180260494208076605798671660719333199513807806252394423283413430106003596332513246682903994829528690198205120921557533726473585751382193953592127439965050261476810842071573684505878854588706623484573925925903505747545471088867712185004135201289273405614415899438276535626346098904241020877974002916168099951885406379295536200413493190419727789712076165162175783",
|
||||
"542189391331696172661670440619180536749994166415993334151601745392193484590296600979602378676624808129613777993466242203025054573692562689251250471628358318743978285860720148446448885701001277560572526947619392551574490839286458454994488665744991822837769918095117129546414124448777033941223565831420390846864429504774477949153794689948747680362212954278693335653935890352619041936727463717926744868338358149568368643403037768649616778526013610493696186055899318268339432671541328195724261329606699831016666359440874843103020666106568222401047720269951530296879490444224546654729111504346660859907296364097126834834235287147",
|
||||
"1487259134814709264092032648525971038895865645148901180585340454985524155135260217788758027400478312256339496385275012465661575576202252063145698732079880294664220579764848767704076761853197216563262660046602703973050798218246170835962005598561669706844469447435461092542265792444947706769615695252256130901271870341005768912974433684521436211263358097522726462083917939091760026658925757076733484173202927141441492573799914240222628795405623953109131594523623353044898339481494120112723445689647986475279242446083151413667587008191682564376412347964146113898565886683139407005941383669325997475076910488086663256335689181157957571445067490187939553165903773554290260531009121879044170766615232300936675369451260747671432073394867530820527479172464106442450727640226503746586340279816318821395210726268291535648506190714616083163403189943334431056876038286530365757187367147446004855912033137386225053275419626102417236133948503",
|
||||
"1095121115716677802856811290392395128588168592409109494900178008967955253005183831872715423151551999734857184538199864469605657805519106717529655044054833197687459782636297255219742994736751541815269727940751860670268774903340296040006114013971309257028332849679096824800250742691718610670812374272414086863715763724622797509437062518082383056050144624962776302147890521249477060215148275163688301275847155316042279405557632639366066847442861422164832655874655824221577849928863023018366835675399949740429332468186340518172487073360822220449055340582568461568645259954873303616953776393853174845132081121976327462740354930744487429617202585015510744298530101547706821590188733515880733527449780963163909830077616357506845523215289297624086914545378511082534229620116563260168494523906566709418166011112754529766183554579321224940951177394088465596712620076240067370589036924024728375076210477267488679008016579588696191194060127319035195370137160936882402244399699172017835144537488486396906144217720028992863941288217185353914991583400421682751000603596655790990815525126154394344641336397793791497068253936771017031980867706707490224041075826337383538651825493679503771934836094655802776331664261631740148281763487765852746577808019633679",
|
||||
|
||||
/* generic unrestricted moduli */
|
||||
"17933601194860113372237070562165128350027320072176844226673287945873370751245439587792371960615073855669274087805055507977323024886880985062002853331424203",
|
||||
"2893527720709661239493896562339544088620375736490408468011883030469939904368086092336458298221245707898933583190713188177399401852627749210994595974791782790253946539043962213027074922559572312141181787434278708783207966459019479487",
|
||||
"347743159439876626079252796797422223177535447388206607607181663903045907591201940478223621722118173270898487582987137708656414344685816179420855160986340457973820182883508387588163122354089264395604796675278966117567294812714812796820596564876450716066283126720010859041484786529056457896367683122960411136319",
|
||||
"47266428956356393164697365098120418976400602706072312735924071745438532218237979333351774907308168340693326687317443721193266215155735814510792148768576498491199122744351399489453533553203833318691678263241941706256996197460424029012419012634671862283532342656309677173602509498417976091509154360039893165037637034737020327399910409885798185771003505320583967737293415979917317338985837385734747478364242020380416892056650841470869294527543597349250299539682430605173321029026555546832473048600327036845781970289288898317888427517364945316709081173840186150794397479045034008257793436817683392375274635794835245695887",
|
||||
"436463808505957768574894870394349739623346440601945961161254440072143298152040105676491048248110146278752857839930515766167441407021501229924721335644557342265864606569000117714935185566842453630868849121480179691838399545644365571106757731317371758557990781880691336695584799313313687287468894148823761785582982549586183756806449017542622267874275103877481475534991201849912222670102069951687572917937634467778042874315463238062009202992087620963771759666448266532858079402669920025224220613419441069718482837399612644978839925207109870840278194042158748845445131729137117098529028886770063736487420613144045836803985635654192482395882603511950547826439092832800532152534003936926017612446606135655146445620623395788978726744728503058670046885876251527122350275750995227",
|
||||
"11424167473351836398078306042624362277956429440521137061889702611766348760692206243140413411077394583180726863277012016602279290144126785129569474909173584789822341986742719230331946072730319555984484911716797058875905400999504305877245849119687509023232790273637466821052576859232452982061831009770786031785669030271542286603956118755585683996118896215213488875253101894663403069677745948305893849505434201763745232895780711972432011344857521691017896316861403206449421332243658855453435784006517202894181640562433575390821384210960117518650374602256601091379644034244332285065935413233557998331562749140202965844219336298970011513882564935538704289446968322281451907487362046511461221329799897350993370560697505809686438782036235372137015731304779072430260986460269894522159103008260495503005267165927542949439526272736586626709581721032189532726389643625590680105784844246152702670169304203783072275089194754889511973916207",
|
||||
"1214855636816562637502584060163403830270705000634713483015101384881871978446801224798536155406895823305035467591632531067547890948695117172076954220727075688048751022421198712032848890056357845974246560748347918630050853933697792254955890439720297560693579400297062396904306270145886830719309296352765295712183040773146419022875165382778007040109957609739589875590885701126197906063620133954893216612678838507540777138437797705602453719559017633986486649523611975865005712371194067612263330335590526176087004421363598470302731349138773205901447704682181517904064735636518462452242791676541725292378925568296858010151852326316777511935037531017413910506921922450666933202278489024521263798482237150056835746454842662048692127173834433089016107854491097456725016327709663199738238442164843147132789153725513257167915555162094970853584447993125488607696008169807374736711297007473812256272245489405898470297178738029484459690836250560495461579533254473316340608217876781986188705928270735695752830825527963838355419762516246028680280988020401914551825487349990306976304093109384451438813251211051597392127491464898797406789175453067960072008590614886532333015881171367104445044718144312416815712216611576221546455968770801413440778423979",
|
||||
NULL
|
||||
};
|
||||
log = fopen("logs/expt.log", "w");
|
||||
logb = fopen("logs/expt_dr.log", "w");
|
||||
logc = fopen("logs/expt_2k.log", "w");
|
||||
logd = fopen("logs/expt_2kl.log", "w");
|
||||
for (n = 0; primes[n]; n++) {
|
||||
SLEEP;
|
||||
mp_read_radix(&a, primes[n], 10);
|
||||
mp_zero(&b);
|
||||
for (rr = 0; rr < (unsigned) mp_count_bits(&a); rr++) {
|
||||
mp_mul_2(&b, &b);
|
||||
b.dp[0] |= lbit();
|
||||
b.used += 1;
|
||||
}
|
||||
mp_sub_d(&a, 1, &c);
|
||||
mp_mod(&b, &c, &b);
|
||||
mp_set(&c, 3);
|
||||
rr = 0;
|
||||
tt = -1;
|
||||
do {
|
||||
gg = TIMFUNC();
|
||||
DO(mp_exptmod(&c, &b, &a, &d));
|
||||
gg = (TIMFUNC() - gg) >> 1;
|
||||
if (tt > gg)
|
||||
tt = gg;
|
||||
} while (++rr < 10);
|
||||
mp_sub_d(&a, 1, &e);
|
||||
mp_sub(&e, &b, &b);
|
||||
mp_exptmod(&c, &b, &a, &e); /* c^(p-1-b) mod a */
|
||||
mp_mulmod(&e, &d, &a, &d); /* c^b * c^(p-1-b) == c^p-1 == 1 */
|
||||
if (mp_cmp_d(&d, 1)) {
|
||||
printf("Different (%d)!!!\n", mp_count_bits(&a));
|
||||
draw(&d);
|
||||
exit(0);
|
||||
}
|
||||
printf("Exponentiating\t%4d-bit => %9llu/sec, %9llu cycles\n",
|
||||
mp_count_bits(&a), CLK_PER_SEC / tt, tt);
|
||||
fprintf(n < 4 ? logd : (n < 9) ? logc : (n < 16) ? logb : log,
|
||||
"%d %9llu\n", mp_count_bits(&a), tt);
|
||||
}
|
||||
}
|
||||
fclose(log);
|
||||
fclose(logb);
|
||||
fclose(logc);
|
||||
fclose(logd);
|
||||
|
||||
log = fopen("logs/invmod.log", "w");
|
||||
for (cnt = 4; cnt <= 128; cnt += 4) {
|
||||
SLEEP;
|
||||
mp_rand(&a, cnt);
|
||||
mp_rand(&b, cnt);
|
||||
|
||||
do {
|
||||
mp_add_d(&b, 1, &b);
|
||||
mp_gcd(&a, &b, &c);
|
||||
} while (mp_cmp_d(&c, 1) != MP_EQ);
|
||||
|
||||
rr = 0;
|
||||
tt = -1;
|
||||
do {
|
||||
gg = TIMFUNC();
|
||||
DO(mp_invmod(&b, &a, &c));
|
||||
gg = (TIMFUNC() - gg) >> 1;
|
||||
if (tt > gg)
|
||||
tt = gg;
|
||||
} while (++rr < 1000);
|
||||
mp_mulmod(&b, &c, &a, &d);
|
||||
if (mp_cmp_d(&d, 1) != MP_EQ) {
|
||||
printf("Failed to invert\n");
|
||||
return 0;
|
||||
}
|
||||
printf("Inverting mod\t%4d-bit => %9llu/sec, %9llu cycles\n",
|
||||
mp_count_bits(&a), CLK_PER_SEC / tt, tt);
|
||||
fprintf(log, "%d %9llu\n", cnt * DIGIT_BIT, tt);
|
||||
}
|
||||
fclose(log);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# Walk through source, add labels and make classes
|
||||
#
|
||||
#use strict;
|
||||
|
||||
my %deplist;
|
||||
|
||||
#open class file and write preamble
|
||||
open(CLASS, ">tommath_class.h") or die "Couldn't open tommath_class.h for writing\n";
|
||||
print CLASS "#if !(defined(LTM1) && defined(LTM2) && defined(LTM3))\n#if defined(LTM2)\n#define LTM3\n#endif\n#if defined(LTM1)\n#define LTM2\n#endif\n#define LTM1\n\n#if defined(LTM_ALL)\n";
|
||||
|
||||
foreach my $filename (glob "bn*.c") {
|
||||
my $define = $filename;
|
||||
|
||||
print "Processing $filename\n";
|
||||
|
||||
# convert filename to upper case so we can use it as a define
|
||||
$define =~ tr/[a-z]/[A-Z]/;
|
||||
$define =~ tr/\./_/;
|
||||
print CLASS "#define $define\n";
|
||||
|
||||
# now copy text and apply #ifdef as required
|
||||
my $apply = 0;
|
||||
open(SRC, "<$filename");
|
||||
open(OUT, ">tmp");
|
||||
|
||||
# first line will be the #ifdef
|
||||
my $line = <SRC>;
|
||||
if ($line =~ /include/) {
|
||||
print OUT $line;
|
||||
} else {
|
||||
print OUT "#include <tommath.h>\n#ifdef $define\n$line";
|
||||
$apply = 1;
|
||||
}
|
||||
while (<SRC>) {
|
||||
if (!($_ =~ /tommath\.h/)) {
|
||||
print OUT $_;
|
||||
}
|
||||
}
|
||||
if ($apply == 1) {
|
||||
print OUT "#endif\n";
|
||||
}
|
||||
close SRC;
|
||||
close OUT;
|
||||
|
||||
unlink($filename);
|
||||
rename("tmp", $filename);
|
||||
}
|
||||
print CLASS "#endif\n\n";
|
||||
|
||||
# now do classes
|
||||
|
||||
foreach my $filename (glob "bn*.c") {
|
||||
open(SRC, "<$filename") or die "Can't open source file!\n";
|
||||
|
||||
# convert filename to upper case so we can use it as a define
|
||||
$filename =~ tr/[a-z]/[A-Z]/;
|
||||
$filename =~ tr/\./_/;
|
||||
|
||||
print CLASS "#if defined($filename)\n";
|
||||
my $list = $filename;
|
||||
|
||||
# scan for mp_* and make classes
|
||||
while (<SRC>) {
|
||||
my $line = $_;
|
||||
while ($line =~ m/(fast_)*(s_)*mp\_[a-z_0-9]*/) {
|
||||
$line = $';
|
||||
# now $& is the match, we want to skip over LTM keywords like
|
||||
# mp_int, mp_word, mp_digit
|
||||
if (!($& eq "mp_digit") && !($& eq "mp_word") && !($& eq "mp_int")) {
|
||||
my $a = $&;
|
||||
$a =~ tr/[a-z]/[A-Z]/;
|
||||
$a = "BN_" . $a . "_C";
|
||||
if (!($list =~ /$a/)) {
|
||||
print CLASS " #define $a\n";
|
||||
}
|
||||
$list = $list . "," . $a;
|
||||
}
|
||||
}
|
||||
}
|
||||
@deplist{$filename} = $list;
|
||||
|
||||
print CLASS "#endif\n\n";
|
||||
close SRC;
|
||||
}
|
||||
|
||||
print CLASS "#ifdef LTM3\n#define LTM_LAST\n#endif\n#include <tommath_superclass.h>\n#include <tommath_class.h>\n#else\n#define LTM_LAST\n#endif\n";
|
||||
close CLASS;
|
||||
|
||||
#now let's make a cool call graph...
|
||||
|
||||
open(OUT,">callgraph.txt");
|
||||
$indent = 0;
|
||||
foreach (keys %deplist) {
|
||||
$list = "";
|
||||
draw_func(@deplist{$_});
|
||||
print OUT "\n\n";
|
||||
}
|
||||
close(OUT);
|
||||
|
||||
sub draw_func()
|
||||
{
|
||||
my @funcs = split(",", $_[0]);
|
||||
if ($list =~ /@funcs[0]/) {
|
||||
return;
|
||||
} else {
|
||||
$list = $list . @funcs[0];
|
||||
}
|
||||
if ($indent == 0) { }
|
||||
elsif ($indent >= 1) { print OUT "| " x ($indent - 1) . "+--->"; }
|
||||
print OUT @funcs[0] . "\n";
|
||||
shift @funcs;
|
||||
my $temp = $list;
|
||||
foreach my $i (@funcs) {
|
||||
++$indent;
|
||||
draw_func(@deplist{$i});
|
||||
--$indent;
|
||||
}
|
||||
$list = $temp;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
256-bits (k = 36113) = 115792089237316195423570985008687907853269984665640564039457584007913129603823
|
||||
512-bits (k = 38117) = 13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006045979
|
||||
@@ -1,75 +0,0 @@
|
||||
/* Makes safe primes of a 2k nature */
|
||||
#include <tommath.h>
|
||||
#include <time.h>
|
||||
|
||||
int sizes[] = {256, 512, 768, 1024, 1536, 2048, 3072, 4096};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char buf[2000];
|
||||
int x, y;
|
||||
mp_int q, p;
|
||||
FILE *out;
|
||||
clock_t t1;
|
||||
mp_digit z;
|
||||
|
||||
mp_init_multi(&q, &p, NULL);
|
||||
|
||||
out = fopen("2kprime.1", "w");
|
||||
for (x = 0; x < (int)(sizeof(sizes) / sizeof(sizes[0])); x++) {
|
||||
top:
|
||||
mp_2expt(&q, sizes[x]);
|
||||
mp_add_d(&q, 3, &q);
|
||||
z = -3;
|
||||
|
||||
t1 = clock();
|
||||
for(;;) {
|
||||
mp_sub_d(&q, 4, &q);
|
||||
z += 4;
|
||||
|
||||
if (z > MP_MASK) {
|
||||
printf("No primes of size %d found\n", sizes[x]);
|
||||
break;
|
||||
}
|
||||
|
||||
if (clock() - t1 > CLOCKS_PER_SEC) {
|
||||
printf("."); fflush(stdout);
|
||||
// sleep((clock() - t1 + CLOCKS_PER_SEC/2)/CLOCKS_PER_SEC);
|
||||
t1 = clock();
|
||||
}
|
||||
|
||||
/* quick test on q */
|
||||
mp_prime_is_prime(&q, 1, &y);
|
||||
if (y == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* find (q-1)/2 */
|
||||
mp_sub_d(&q, 1, &p);
|
||||
mp_div_2(&p, &p);
|
||||
mp_prime_is_prime(&p, 3, &y);
|
||||
if (y == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* test on q */
|
||||
mp_prime_is_prime(&q, 3, &y);
|
||||
if (y == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (y == 0) {
|
||||
++sizes[x];
|
||||
goto top;
|
||||
}
|
||||
|
||||
mp_toradix(&q, buf, 10);
|
||||
printf("\n\n%d-bits (k = %lu) = %s\n", sizes[x], z, buf);
|
||||
fprintf(out, "%d-bits (k = %lu) = %s\n", sizes[x], z, buf); fflush(out);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/* Makes safe primes of a DR nature */
|
||||
#include <tommath.h>
|
||||
|
||||
int sizes[] = { 1+256/DIGIT_BIT, 1+512/DIGIT_BIT, 1+768/DIGIT_BIT, 1+1024/DIGIT_BIT, 1+2048/DIGIT_BIT, 1+4096/DIGIT_BIT };
|
||||
int main(void)
|
||||
{
|
||||
int res, x, y;
|
||||
char buf[4096];
|
||||
FILE *out;
|
||||
mp_int a, b;
|
||||
|
||||
mp_init(&a);
|
||||
mp_init(&b);
|
||||
|
||||
out = fopen("drprimes.txt", "w");
|
||||
for (x = 0; x < (int)(sizeof(sizes)/sizeof(sizes[0])); x++) {
|
||||
top:
|
||||
printf("Seeking a %d-bit safe prime\n", sizes[x] * DIGIT_BIT);
|
||||
mp_grow(&a, sizes[x]);
|
||||
mp_zero(&a);
|
||||
for (y = 1; y < sizes[x]; y++) {
|
||||
a.dp[y] = MP_MASK;
|
||||
}
|
||||
|
||||
/* make a DR modulus */
|
||||
a.dp[0] = -1;
|
||||
a.used = sizes[x];
|
||||
|
||||
/* now loop */
|
||||
res = 0;
|
||||
for (;;) {
|
||||
a.dp[0] += 4;
|
||||
if (a.dp[0] >= MP_MASK) break;
|
||||
mp_prime_is_prime(&a, 1, &res);
|
||||
if (res == 0) continue;
|
||||
printf("."); fflush(stdout);
|
||||
mp_sub_d(&a, 1, &b);
|
||||
mp_div_2(&b, &b);
|
||||
mp_prime_is_prime(&b, 3, &res);
|
||||
if (res == 0) continue;
|
||||
mp_prime_is_prime(&a, 3, &res);
|
||||
if (res == 1) break;
|
||||
}
|
||||
|
||||
if (res != 1) {
|
||||
printf("Error not DR modulus\n"); sizes[x] += 1; goto top;
|
||||
} else {
|
||||
mp_toradix(&a, buf, 10);
|
||||
printf("\n\np == %s\n\n", buf);
|
||||
fprintf(out, "%d-bit prime:\np == %s\n\n", mp_count_bits(&a), buf); fflush(out);
|
||||
}
|
||||
}
|
||||
fclose(out);
|
||||
|
||||
mp_clear(&a);
|
||||
mp_clear(&b);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
DR safe primes for 28-bit digits.
|
||||
|
||||
224-bit prime:
|
||||
p == 26959946667150639794667015087019630673637144422540572481103341844143
|
||||
|
||||
532-bit prime:
|
||||
p == 14059105607947488696282932836518693308967803494693489478439861164411992439598399594747002144074658928593502845729752797260025831423419686528151609940203368691747
|
||||
|
||||
784-bit prime:
|
||||
p == 101745825697019260773923519755878567461315282017759829107608914364075275235254395622580447400994175578963163918967182013639660669771108475957692810857098847138903161308502419410142185759152435680068435915159402496058513611411688900243039
|
||||
|
||||
1036-bit prime:
|
||||
p == 736335108039604595805923406147184530889923370574768772191969612422073040099331944991573923112581267542507986451953227192970402893063850485730703075899286013451337291468249027691733891486704001513279827771740183629161065194874727962517148100775228363421083691764065477590823919364012917984605619526140821798437127
|
||||
|
||||
1540-bit prime:
|
||||
p == 38564998830736521417281865696453025806593491967131023221754800625044118265468851210705360385717536794615180260494208076605798671660719333199513807806252394423283413430106003596332513246682903994829528690198205120921557533726473585751382193953592127439965050261476810842071573684505878854588706623484573925925903505747545471088867712185004135201289273405614415899438276535626346098904241020877974002916168099951885406379295536200413493190419727789712076165162175783
|
||||
|
||||
2072-bit prime:
|
||||
p == 542189391331696172661670440619180536749994166415993334151601745392193484590296600979602378676624808129613777993466242203025054573692562689251250471628358318743978285860720148446448885701001277560572526947619392551574490839286458454994488665744991822837769918095117129546414124448777033941223565831420390846864429504774477949153794689948747680362212954278693335653935890352619041936727463717926744868338358149568368643403037768649616778526013610493696186055899318268339432671541328195724261329606699831016666359440874843103020666106568222401047720269951530296879490444224546654729111504346660859907296364097126834834235287147
|
||||
|
||||
3080-bit prime:
|
||||
p == 1487259134814709264092032648525971038895865645148901180585340454985524155135260217788758027400478312256339496385275012465661575576202252063145698732079880294664220579764848767704076761853197216563262660046602703973050798218246170835962005598561669706844469447435461092542265792444947706769615695252256130901271870341005768912974433684521436211263358097522726462083917939091760026658925757076733484173202927141441492573799914240222628795405623953109131594523623353044898339481494120112723445689647986475279242446083151413667587008191682564376412347964146113898565886683139407005941383669325997475076910488086663256335689181157957571445067490187939553165903773554290260531009121879044170766615232300936675369451260747671432073394867530820527479172464106442450727640226503746586340279816318821395210726268291535648506190714616083163403189943334431056876038286530365757187367147446004855912033137386225053275419626102417236133948503
|
||||
|
||||
4116-bit prime:
|
||||
p == 1095121115716677802856811290392395128588168592409109494900178008967955253005183831872715423151551999734857184538199864469605657805519106717529655044054833197687459782636297255219742994736751541815269727940751860670268774903340296040006114013971309257028332849679096824800250742691718610670812374272414086863715763724622797509437062518082383056050144624962776302147890521249477060215148275163688301275847155316042279405557632639366066847442861422164832655874655824221577849928863023018366835675399949740429332468186340518172487073360822220449055340582568461568645259954873303616953776393853174845132081121976327462740354930744487429617202585015510744298530101547706821590188733515880733527449780963163909830077616357506845523215289297624086914545378511082534229620116563260168494523906566709418166011112754529766183554579321224940951177394088465596712620076240067370589036924024728375076210477267488679008016579588696191194060127319035195370137160936882402244399699172017835144537488486396906144217720028992863941288217185353914991583400421682751000603596655790990815525126154394344641336397793791497068253936771017031980867706707490224041075826337383538651825493679503771934836094655802776331664261631740148281763487765852746577808019633679
|
||||
@@ -1,9 +0,0 @@
|
||||
300-bit prime:
|
||||
p == 2037035976334486086268445688409378161051468393665936250636140449354381298610415201576637819
|
||||
|
||||
540-bit prime:
|
||||
p == 3599131035634557106248430806148785487095757694641533306480604458089470064537190296255232548883112685719936728506816716098566612844395439751206810991770626477344739
|
||||
|
||||
780-bit prime:
|
||||
p == 6359114106063703798370219984742410466332205126109989319225557147754704702203399726411277962562135973685197744935448875852478791860694279747355800678568677946181447581781401213133886609947027230004277244697462656003655947791725966271167
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
CFLAGS += -Wall -W -Wshadow -O3 -fomit-frame-pointer -funroll-loops -I../
|
||||
|
||||
# default lib name (requires install with root)
|
||||
# LIBNAME=-ltommath
|
||||
|
||||
# libname when you can't install the lib with install
|
||||
LIBNAME=../libtommath.a
|
||||
|
||||
#provable primes
|
||||
pprime: pprime.o
|
||||
$(CC) pprime.o $(LIBNAME) -o pprime
|
||||
|
||||
# portable [well requires clock()] tuning app
|
||||
tune: tune.o
|
||||
$(CC) tune.o $(LIBNAME) -o tune
|
||||
|
||||
# same app but using RDTSC for higher precision [requires 80586+], coff based gcc installs [e.g. ming, cygwin, djgpp]
|
||||
tune86: tune.c
|
||||
nasm -f coff timer.asm
|
||||
$(CC) -DX86_TIMER $(CFLAGS) tune.c timer.o $(LIBNAME) -o tune86
|
||||
|
||||
# for cygwin
|
||||
tune86c: tune.c
|
||||
nasm -f gnuwin32 timer.asm
|
||||
$(CC) -DX86_TIMER $(CFLAGS) tune.c timer.o $(LIBNAME) -o tune86
|
||||
|
||||
#make tune86 for linux or any ELF format
|
||||
tune86l: tune.c
|
||||
nasm -f elf -DUSE_ELF timer.asm
|
||||
$(CC) -DX86_TIMER $(CFLAGS) tune.c timer.o $(LIBNAME) -o tune86l
|
||||
|
||||
# spits out mersenne primes
|
||||
mersenne: mersenne.o
|
||||
$(CC) mersenne.o $(LIBNAME) -o mersenne
|
||||
|
||||
# fines DR safe primes for the given config
|
||||
drprime: drprime.o
|
||||
$(CC) drprime.o $(LIBNAME) -o drprime
|
||||
|
||||
# fines 2k safe primes for the given config
|
||||
2kprime: 2kprime.o
|
||||
$(CC) 2kprime.o $(LIBNAME) -o 2kprime
|
||||
|
||||
mont: mont.o
|
||||
$(CC) mont.o $(LIBNAME) -o mont
|
||||
|
||||
|
||||
clean:
|
||||
rm -f *.log *.o *.obj *.exe pprime tune mersenne drprime tune86 tune86l mont 2kprime pprime.dat \
|
||||
*.da *.dyn *.dpi *~
|
||||
@@ -1,67 +0,0 @@
|
||||
CC = icc
|
||||
|
||||
CFLAGS += -I../
|
||||
|
||||
# optimize for SPEED
|
||||
#
|
||||
# -mcpu= can be pentium, pentiumpro (covers PII through PIII) or pentium4
|
||||
# -ax? specifies make code specifically for ? but compatible with IA-32
|
||||
# -x? specifies compile solely for ? [not specifically IA-32 compatible]
|
||||
#
|
||||
# where ? is
|
||||
# K - PIII
|
||||
# W - first P4 [Williamette]
|
||||
# N - P4 Northwood
|
||||
# P - P4 Prescott
|
||||
# B - Blend of P4 and PM [mobile]
|
||||
#
|
||||
# Default to just generic max opts
|
||||
CFLAGS += -O3 -xP -ip
|
||||
|
||||
# default lib name (requires install with root)
|
||||
# LIBNAME=-ltommath
|
||||
|
||||
# libname when you can't install the lib with install
|
||||
LIBNAME=../libtommath.a
|
||||
|
||||
#provable primes
|
||||
pprime: pprime.o
|
||||
$(CC) pprime.o $(LIBNAME) -o pprime
|
||||
|
||||
# portable [well requires clock()] tuning app
|
||||
tune: tune.o
|
||||
$(CC) tune.o $(LIBNAME) -o tune
|
||||
|
||||
# same app but using RDTSC for higher precision [requires 80586+], coff based gcc installs [e.g. ming, cygwin, djgpp]
|
||||
tune86: tune.c
|
||||
nasm -f coff timer.asm
|
||||
$(CC) -DX86_TIMER $(CFLAGS) tune.c timer.o $(LIBNAME) -o tune86
|
||||
|
||||
# for cygwin
|
||||
tune86c: tune.c
|
||||
nasm -f gnuwin32 timer.asm
|
||||
$(CC) -DX86_TIMER $(CFLAGS) tune.c timer.o $(LIBNAME) -o tune86
|
||||
|
||||
#make tune86 for linux or any ELF format
|
||||
tune86l: tune.c
|
||||
nasm -f elf -DUSE_ELF timer.asm
|
||||
$(CC) -DX86_TIMER $(CFLAGS) tune.c timer.o $(LIBNAME) -o tune86l
|
||||
|
||||
# spits out mersenne primes
|
||||
mersenne: mersenne.o
|
||||
$(CC) mersenne.o $(LIBNAME) -o mersenne
|
||||
|
||||
# fines DR safe primes for the given config
|
||||
drprime: drprime.o
|
||||
$(CC) drprime.o $(LIBNAME) -o drprime
|
||||
|
||||
# fines 2k safe primes for the given config
|
||||
2kprime: 2kprime.o
|
||||
$(CC) 2kprime.o $(LIBNAME) -o 2kprime
|
||||
|
||||
mont: mont.o
|
||||
$(CC) mont.o $(LIBNAME) -o mont
|
||||
|
||||
|
||||
clean:
|
||||
rm -f *.log *.o *.obj *.exe pprime tune mersenne drprime tune86 tune86l mont 2kprime pprime.dat *.il
|
||||
@@ -1,23 +0,0 @@
|
||||
#MSVC Makefile
|
||||
#
|
||||
#Tom St Denis
|
||||
|
||||
CFLAGS = /I../ /Ox /DWIN32 /W3
|
||||
|
||||
pprime: pprime.obj
|
||||
cl pprime.obj ../tommath.lib
|
||||
|
||||
mersenne: mersenne.obj
|
||||
cl mersenne.obj ../tommath.lib
|
||||
|
||||
tune: tune.obj
|
||||
cl tune.obj ../tommath.lib
|
||||
|
||||
mont: mont.obj
|
||||
cl mont.obj ../tommath.lib
|
||||
|
||||
drprime: drprime.obj
|
||||
cl drprime.obj ../tommath.lib
|
||||
|
||||
2kprime: 2kprime.obj
|
||||
cl 2kprime.obj ../tommath.lib
|
||||
@@ -1,140 +0,0 @@
|
||||
/* Finds Mersenne primes using the Lucas-Lehmer test
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com
|
||||
*/
|
||||
#include <time.h>
|
||||
#include <tommath.h>
|
||||
|
||||
int
|
||||
is_mersenne (long s, int *pp)
|
||||
{
|
||||
mp_int n, u;
|
||||
int res, k;
|
||||
|
||||
*pp = 0;
|
||||
|
||||
if ((res = mp_init (&n)) != MP_OKAY) {
|
||||
return res;
|
||||
}
|
||||
|
||||
if ((res = mp_init (&u)) != MP_OKAY) {
|
||||
goto LBL_N;
|
||||
}
|
||||
|
||||
/* n = 2^s - 1 */
|
||||
if ((res = mp_2expt(&n, s)) != MP_OKAY) {
|
||||
goto LBL_MU;
|
||||
}
|
||||
if ((res = mp_sub_d (&n, 1, &n)) != MP_OKAY) {
|
||||
goto LBL_MU;
|
||||
}
|
||||
|
||||
/* set u=4 */
|
||||
mp_set (&u, 4);
|
||||
|
||||
/* for k=1 to s-2 do */
|
||||
for (k = 1; k <= s - 2; k++) {
|
||||
/* u = u^2 - 2 mod n */
|
||||
if ((res = mp_sqr (&u, &u)) != MP_OKAY) {
|
||||
goto LBL_MU;
|
||||
}
|
||||
if ((res = mp_sub_d (&u, 2, &u)) != MP_OKAY) {
|
||||
goto LBL_MU;
|
||||
}
|
||||
|
||||
/* make sure u is positive */
|
||||
while (u.sign == MP_NEG) {
|
||||
if ((res = mp_add (&u, &n, &u)) != MP_OKAY) {
|
||||
goto LBL_MU;
|
||||
}
|
||||
}
|
||||
|
||||
/* reduce */
|
||||
if ((res = mp_reduce_2k (&u, &n, 1)) != MP_OKAY) {
|
||||
goto LBL_MU;
|
||||
}
|
||||
}
|
||||
|
||||
/* if u == 0 then its prime */
|
||||
if (mp_iszero (&u) == 1) {
|
||||
mp_prime_is_prime(&n, 8, pp);
|
||||
if (*pp != 1) printf("FAILURE\n");
|
||||
}
|
||||
|
||||
res = MP_OKAY;
|
||||
LBL_MU:mp_clear (&u);
|
||||
LBL_N:mp_clear (&n);
|
||||
return res;
|
||||
}
|
||||
|
||||
/* square root of a long < 65536 */
|
||||
long
|
||||
i_sqrt (long x)
|
||||
{
|
||||
long x1, x2;
|
||||
|
||||
x2 = 16;
|
||||
do {
|
||||
x1 = x2;
|
||||
x2 = x1 - ((x1 * x1) - x) / (2 * x1);
|
||||
} while (x1 != x2);
|
||||
|
||||
if (x1 * x1 > x) {
|
||||
--x1;
|
||||
}
|
||||
|
||||
return x1;
|
||||
}
|
||||
|
||||
/* is the long prime by brute force */
|
||||
int
|
||||
isprime (long k)
|
||||
{
|
||||
long y, z;
|
||||
|
||||
y = i_sqrt (k);
|
||||
for (z = 2; z <= y; z++) {
|
||||
if ((k % z) == 0)
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
int pp;
|
||||
long k;
|
||||
clock_t tt;
|
||||
|
||||
k = 3;
|
||||
|
||||
for (;;) {
|
||||
/* start time */
|
||||
tt = clock ();
|
||||
|
||||
/* test if 2^k - 1 is prime */
|
||||
if (is_mersenne (k, &pp) != MP_OKAY) {
|
||||
printf ("Whoa error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pp == 1) {
|
||||
/* count time */
|
||||
tt = clock () - tt;
|
||||
|
||||
/* display if prime */
|
||||
printf ("2^%-5ld - 1 is prime, test took %ld ticks\n", k, tt);
|
||||
}
|
||||
|
||||
/* goto next odd exponent */
|
||||
k += 2;
|
||||
|
||||
/* but make sure its prime */
|
||||
while (isprime (k) == 0) {
|
||||
k += 2;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/* tests the montgomery routines */
|
||||
#include <tommath.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
mp_int modulus, R, p, pp;
|
||||
mp_digit mp;
|
||||
long x, y;
|
||||
|
||||
srand(time(NULL));
|
||||
mp_init_multi(&modulus, &R, &p, &pp, NULL);
|
||||
|
||||
/* loop through various sizes */
|
||||
for (x = 4; x < 256; x++) {
|
||||
printf("DIGITS == %3ld...", x); fflush(stdout);
|
||||
|
||||
/* make up the odd modulus */
|
||||
mp_rand(&modulus, x);
|
||||
modulus.dp[0] |= 1;
|
||||
|
||||
/* now find the R value */
|
||||
mp_montgomery_calc_normalization(&R, &modulus);
|
||||
mp_montgomery_setup(&modulus, &mp);
|
||||
|
||||
/* now run through a bunch tests */
|
||||
for (y = 0; y < 1000; y++) {
|
||||
mp_rand(&p, x/2); /* p = random */
|
||||
mp_mul(&p, &R, &pp); /* pp = R * p */
|
||||
mp_montgomery_reduce(&pp, &modulus, mp);
|
||||
|
||||
/* should be equal to p */
|
||||
if (mp_cmp(&pp, &p) != MP_EQ) {
|
||||
printf("FAILURE!\n");
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
printf("PASSED\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,396 +0,0 @@
|
||||
/* Generates provable primes
|
||||
*
|
||||
* See http://gmail.com:8080/papers/pp.pdf for more info.
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com, http://tom.gmail.com
|
||||
*/
|
||||
#include <time.h>
|
||||
#include "tommath.h"
|
||||
|
||||
int n_prime;
|
||||
FILE *primes;
|
||||
|
||||
/* fast square root */
|
||||
static mp_digit
|
||||
i_sqrt (mp_word x)
|
||||
{
|
||||
mp_word x1, x2;
|
||||
|
||||
x2 = x;
|
||||
do {
|
||||
x1 = x2;
|
||||
x2 = x1 - ((x1 * x1) - x) / (2 * x1);
|
||||
} while (x1 != x2);
|
||||
|
||||
if (x1 * x1 > x) {
|
||||
--x1;
|
||||
}
|
||||
|
||||
return x1;
|
||||
}
|
||||
|
||||
|
||||
/* generates a prime digit */
|
||||
static void gen_prime (void)
|
||||
{
|
||||
mp_digit r, x, y, next;
|
||||
FILE *out;
|
||||
|
||||
out = fopen("pprime.dat", "wb");
|
||||
|
||||
/* write first set of primes */
|
||||
r = 3; fwrite(&r, 1, sizeof(mp_digit), out);
|
||||
r = 5; fwrite(&r, 1, sizeof(mp_digit), out);
|
||||
r = 7; fwrite(&r, 1, sizeof(mp_digit), out);
|
||||
r = 11; fwrite(&r, 1, sizeof(mp_digit), out);
|
||||
r = 13; fwrite(&r, 1, sizeof(mp_digit), out);
|
||||
r = 17; fwrite(&r, 1, sizeof(mp_digit), out);
|
||||
r = 19; fwrite(&r, 1, sizeof(mp_digit), out);
|
||||
r = 23; fwrite(&r, 1, sizeof(mp_digit), out);
|
||||
r = 29; fwrite(&r, 1, sizeof(mp_digit), out);
|
||||
r = 31; fwrite(&r, 1, sizeof(mp_digit), out);
|
||||
|
||||
/* get square root, since if 'r' is composite its factors must be < than this */
|
||||
y = i_sqrt (r);
|
||||
next = (y + 1) * (y + 1);
|
||||
|
||||
for (;;) {
|
||||
do {
|
||||
r += 2; /* next candidate */
|
||||
r &= MP_MASK;
|
||||
if (r < 31) break;
|
||||
|
||||
/* update sqrt ? */
|
||||
if (next <= r) {
|
||||
++y;
|
||||
next = (y + 1) * (y + 1);
|
||||
}
|
||||
|
||||
/* loop if divisible by 3,5,7,11,13,17,19,23,29 */
|
||||
if ((r % 3) == 0) {
|
||||
x = 0;
|
||||
continue;
|
||||
}
|
||||
if ((r % 5) == 0) {
|
||||
x = 0;
|
||||
continue;
|
||||
}
|
||||
if ((r % 7) == 0) {
|
||||
x = 0;
|
||||
continue;
|
||||
}
|
||||
if ((r % 11) == 0) {
|
||||
x = 0;
|
||||
continue;
|
||||
}
|
||||
if ((r % 13) == 0) {
|
||||
x = 0;
|
||||
continue;
|
||||
}
|
||||
if ((r % 17) == 0) {
|
||||
x = 0;
|
||||
continue;
|
||||
}
|
||||
if ((r % 19) == 0) {
|
||||
x = 0;
|
||||
continue;
|
||||
}
|
||||
if ((r % 23) == 0) {
|
||||
x = 0;
|
||||
continue;
|
||||
}
|
||||
if ((r % 29) == 0) {
|
||||
x = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* now check if r is divisible by x + k={1,7,11,13,17,19,23,29} */
|
||||
for (x = 30; x <= y; x += 30) {
|
||||
if ((r % (x + 1)) == 0) {
|
||||
x = 0;
|
||||
break;
|
||||
}
|
||||
if ((r % (x + 7)) == 0) {
|
||||
x = 0;
|
||||
break;
|
||||
}
|
||||
if ((r % (x + 11)) == 0) {
|
||||
x = 0;
|
||||
break;
|
||||
}
|
||||
if ((r % (x + 13)) == 0) {
|
||||
x = 0;
|
||||
break;
|
||||
}
|
||||
if ((r % (x + 17)) == 0) {
|
||||
x = 0;
|
||||
break;
|
||||
}
|
||||
if ((r % (x + 19)) == 0) {
|
||||
x = 0;
|
||||
break;
|
||||
}
|
||||
if ((r % (x + 23)) == 0) {
|
||||
x = 0;
|
||||
break;
|
||||
}
|
||||
if ((r % (x + 29)) == 0) {
|
||||
x = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (x == 0);
|
||||
if (r > 31) { fwrite(&r, 1, sizeof(mp_digit), out); printf("%9d\r", r); fflush(stdout); }
|
||||
if (r < 31) break;
|
||||
}
|
||||
|
||||
fclose(out);
|
||||
}
|
||||
|
||||
void load_tab(void)
|
||||
{
|
||||
primes = fopen("pprime.dat", "rb");
|
||||
if (primes == NULL) {
|
||||
gen_prime();
|
||||
primes = fopen("pprime.dat", "rb");
|
||||
}
|
||||
fseek(primes, 0, SEEK_END);
|
||||
n_prime = ftell(primes) / sizeof(mp_digit);
|
||||
}
|
||||
|
||||
mp_digit prime_digit(void)
|
||||
{
|
||||
int n;
|
||||
mp_digit d;
|
||||
|
||||
n = abs(rand()) % n_prime;
|
||||
fseek(primes, n * sizeof(mp_digit), SEEK_SET);
|
||||
fread(&d, 1, sizeof(mp_digit), primes);
|
||||
return d;
|
||||
}
|
||||
|
||||
|
||||
/* makes a prime of at least k bits */
|
||||
int
|
||||
pprime (int k, int li, mp_int * p, mp_int * q)
|
||||
{
|
||||
mp_int a, b, c, n, x, y, z, v;
|
||||
int res, ii;
|
||||
static const mp_digit bases[] = { 2, 3, 5, 7, 11, 13, 17, 19 };
|
||||
|
||||
/* single digit ? */
|
||||
if (k <= (int) DIGIT_BIT) {
|
||||
mp_set (p, prime_digit ());
|
||||
return MP_OKAY;
|
||||
}
|
||||
|
||||
if ((res = mp_init (&c)) != MP_OKAY) {
|
||||
return res;
|
||||
}
|
||||
|
||||
if ((res = mp_init (&v)) != MP_OKAY) {
|
||||
goto LBL_C;
|
||||
}
|
||||
|
||||
/* product of first 50 primes */
|
||||
if ((res =
|
||||
mp_read_radix (&v,
|
||||
"19078266889580195013601891820992757757219839668357012055907516904309700014933909014729740190",
|
||||
10)) != MP_OKAY) {
|
||||
goto LBL_V;
|
||||
}
|
||||
|
||||
if ((res = mp_init (&a)) != MP_OKAY) {
|
||||
goto LBL_V;
|
||||
}
|
||||
|
||||
/* set the prime */
|
||||
mp_set (&a, prime_digit ());
|
||||
|
||||
if ((res = mp_init (&b)) != MP_OKAY) {
|
||||
goto LBL_A;
|
||||
}
|
||||
|
||||
if ((res = mp_init (&n)) != MP_OKAY) {
|
||||
goto LBL_B;
|
||||
}
|
||||
|
||||
if ((res = mp_init (&x)) != MP_OKAY) {
|
||||
goto LBL_N;
|
||||
}
|
||||
|
||||
if ((res = mp_init (&y)) != MP_OKAY) {
|
||||
goto LBL_X;
|
||||
}
|
||||
|
||||
if ((res = mp_init (&z)) != MP_OKAY) {
|
||||
goto LBL_Y;
|
||||
}
|
||||
|
||||
/* now loop making the single digit */
|
||||
while (mp_count_bits (&a) < k) {
|
||||
fprintf (stderr, "prime has %4d bits left\r", k - mp_count_bits (&a));
|
||||
fflush (stderr);
|
||||
top:
|
||||
mp_set (&b, prime_digit ());
|
||||
|
||||
/* now compute z = a * b * 2 */
|
||||
if ((res = mp_mul (&a, &b, &z)) != MP_OKAY) { /* z = a * b */
|
||||
goto LBL_Z;
|
||||
}
|
||||
|
||||
if ((res = mp_copy (&z, &c)) != MP_OKAY) { /* c = a * b */
|
||||
goto LBL_Z;
|
||||
}
|
||||
|
||||
if ((res = mp_mul_2 (&z, &z)) != MP_OKAY) { /* z = 2 * a * b */
|
||||
goto LBL_Z;
|
||||
}
|
||||
|
||||
/* n = z + 1 */
|
||||
if ((res = mp_add_d (&z, 1, &n)) != MP_OKAY) { /* n = z + 1 */
|
||||
goto LBL_Z;
|
||||
}
|
||||
|
||||
/* check (n, v) == 1 */
|
||||
if ((res = mp_gcd (&n, &v, &y)) != MP_OKAY) { /* y = (n, v) */
|
||||
goto LBL_Z;
|
||||
}
|
||||
|
||||
if (mp_cmp_d (&y, 1) != MP_EQ)
|
||||
goto top;
|
||||
|
||||
/* now try base x=bases[ii] */
|
||||
for (ii = 0; ii < li; ii++) {
|
||||
mp_set (&x, bases[ii]);
|
||||
|
||||
/* compute x^a mod n */
|
||||
if ((res = mp_exptmod (&x, &a, &n, &y)) != MP_OKAY) { /* y = x^a mod n */
|
||||
goto LBL_Z;
|
||||
}
|
||||
|
||||
/* if y == 1 loop */
|
||||
if (mp_cmp_d (&y, 1) == MP_EQ)
|
||||
continue;
|
||||
|
||||
/* now x^2a mod n */
|
||||
if ((res = mp_sqrmod (&y, &n, &y)) != MP_OKAY) { /* y = x^2a mod n */
|
||||
goto LBL_Z;
|
||||
}
|
||||
|
||||
if (mp_cmp_d (&y, 1) == MP_EQ)
|
||||
continue;
|
||||
|
||||
/* compute x^b mod n */
|
||||
if ((res = mp_exptmod (&x, &b, &n, &y)) != MP_OKAY) { /* y = x^b mod n */
|
||||
goto LBL_Z;
|
||||
}
|
||||
|
||||
/* if y == 1 loop */
|
||||
if (mp_cmp_d (&y, 1) == MP_EQ)
|
||||
continue;
|
||||
|
||||
/* now x^2b mod n */
|
||||
if ((res = mp_sqrmod (&y, &n, &y)) != MP_OKAY) { /* y = x^2b mod n */
|
||||
goto LBL_Z;
|
||||
}
|
||||
|
||||
if (mp_cmp_d (&y, 1) == MP_EQ)
|
||||
continue;
|
||||
|
||||
/* compute x^c mod n == x^ab mod n */
|
||||
if ((res = mp_exptmod (&x, &c, &n, &y)) != MP_OKAY) { /* y = x^ab mod n */
|
||||
goto LBL_Z;
|
||||
}
|
||||
|
||||
/* if y == 1 loop */
|
||||
if (mp_cmp_d (&y, 1) == MP_EQ)
|
||||
continue;
|
||||
|
||||
/* now compute (x^c mod n)^2 */
|
||||
if ((res = mp_sqrmod (&y, &n, &y)) != MP_OKAY) { /* y = x^2ab mod n */
|
||||
goto LBL_Z;
|
||||
}
|
||||
|
||||
/* y should be 1 */
|
||||
if (mp_cmp_d (&y, 1) != MP_EQ)
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
|
||||
/* no bases worked? */
|
||||
if (ii == li)
|
||||
goto top;
|
||||
|
||||
{
|
||||
char buf[4096];
|
||||
|
||||
mp_toradix(&n, buf, 10);
|
||||
printf("Certificate of primality for:\n%s\n\n", buf);
|
||||
mp_toradix(&a, buf, 10);
|
||||
printf("A == \n%s\n\n", buf);
|
||||
mp_toradix(&b, buf, 10);
|
||||
printf("B == \n%s\n\nG == %d\n", buf, bases[ii]);
|
||||
printf("----------------------------------------------------------------\n");
|
||||
}
|
||||
|
||||
/* a = n */
|
||||
mp_copy (&n, &a);
|
||||
}
|
||||
|
||||
/* get q to be the order of the large prime subgroup */
|
||||
mp_sub_d (&n, 1, q);
|
||||
mp_div_2 (q, q);
|
||||
mp_div (q, &b, q, NULL);
|
||||
|
||||
mp_exch (&n, p);
|
||||
|
||||
res = MP_OKAY;
|
||||
LBL_Z:mp_clear (&z);
|
||||
LBL_Y:mp_clear (&y);
|
||||
LBL_X:mp_clear (&x);
|
||||
LBL_N:mp_clear (&n);
|
||||
LBL_B:mp_clear (&b);
|
||||
LBL_A:mp_clear (&a);
|
||||
LBL_V:mp_clear (&v);
|
||||
LBL_C:mp_clear (&c);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
mp_int p, q;
|
||||
char buf[4096];
|
||||
int k, li;
|
||||
clock_t t1;
|
||||
|
||||
srand (time (NULL));
|
||||
load_tab();
|
||||
|
||||
printf ("Enter # of bits: \n");
|
||||
fgets (buf, sizeof (buf), stdin);
|
||||
sscanf (buf, "%d", &k);
|
||||
|
||||
printf ("Enter number of bases to try (1 to 8):\n");
|
||||
fgets (buf, sizeof (buf), stdin);
|
||||
sscanf (buf, "%d", &li);
|
||||
|
||||
|
||||
mp_init (&p);
|
||||
mp_init (&q);
|
||||
|
||||
t1 = clock ();
|
||||
pprime (k, li, &p, &q);
|
||||
t1 = clock () - t1;
|
||||
|
||||
printf ("\n\nTook %ld ticks, %d bits\n", t1, mp_count_bits (&p));
|
||||
|
||||
mp_toradix (&p, buf, 10);
|
||||
printf ("P == %s\n", buf);
|
||||
mp_toradix (&q, buf, 10);
|
||||
printf ("Q == %s\n", buf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,414 +0,0 @@
|
||||
Enter # of bits:
|
||||
Enter number of bases to try (1 to 8):
|
||||
Certificate of primality for:
|
||||
36360080703173363
|
||||
|
||||
A ==
|
||||
89963569
|
||||
|
||||
B ==
|
||||
202082249
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
4851595597739856136987139
|
||||
|
||||
A ==
|
||||
36360080703173363
|
||||
|
||||
B ==
|
||||
66715963
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
19550639734462621430325731591027
|
||||
|
||||
A ==
|
||||
4851595597739856136987139
|
||||
|
||||
B ==
|
||||
2014867
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
10409036141344317165691858509923818734539
|
||||
|
||||
A ==
|
||||
19550639734462621430325731591027
|
||||
|
||||
B ==
|
||||
266207047
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
1049829549988285012736475602118094726647504414203
|
||||
|
||||
A ==
|
||||
10409036141344317165691858509923818734539
|
||||
|
||||
B ==
|
||||
50428759
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
77194737385528288387712399596835459931920358844586615003
|
||||
|
||||
A ==
|
||||
1049829549988285012736475602118094726647504414203
|
||||
|
||||
B ==
|
||||
36765367
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
35663756695365208574443215955488689578374232732893628896541201763
|
||||
|
||||
A ==
|
||||
77194737385528288387712399596835459931920358844586615003
|
||||
|
||||
B ==
|
||||
230998627
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
16711831463502165169495622246023119698415848120292671294127567620396469803
|
||||
|
||||
A ==
|
||||
35663756695365208574443215955488689578374232732893628896541201763
|
||||
|
||||
B ==
|
||||
234297127
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
6163534781560285962890718925972249753147470953579266394395432475622345597103528739
|
||||
|
||||
A ==
|
||||
16711831463502165169495622246023119698415848120292671294127567620396469803
|
||||
|
||||
B ==
|
||||
184406323
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
814258256205243497704094951432575867360065658372158511036259934640748088306764553488803787
|
||||
|
||||
A ==
|
||||
6163534781560285962890718925972249753147470953579266394395432475622345597103528739
|
||||
|
||||
B ==
|
||||
66054487
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
176469695533271657902814176811660357049007467856432383037590673407330246967781451723764079581998187
|
||||
|
||||
A ==
|
||||
814258256205243497704094951432575867360065658372158511036259934640748088306764553488803787
|
||||
|
||||
B ==
|
||||
108362239
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
44924492859445516541759485198544012102424796403707253610035148063863073596051272171194806669756971406400419
|
||||
|
||||
A ==
|
||||
176469695533271657902814176811660357049007467856432383037590673407330246967781451723764079581998187
|
||||
|
||||
B ==
|
||||
127286707
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
20600996927219343383225424320134474929609459588323857796871086845924186191561749519858600696159932468024710985371059
|
||||
|
||||
A ==
|
||||
44924492859445516541759485198544012102424796403707253610035148063863073596051272171194806669756971406400419
|
||||
|
||||
B ==
|
||||
229284691
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
6295696427695493110141186605837397185848992307978456138112526915330347715236378041486547994708748840844217371233735072572979
|
||||
|
||||
A ==
|
||||
20600996927219343383225424320134474929609459588323857796871086845924186191561749519858600696159932468024710985371059
|
||||
|
||||
B ==
|
||||
152800771
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
3104984078042317488749073016454213579257792635142218294052134804187631661145261015102617582090263808696699966840735333252107678792123
|
||||
|
||||
A ==
|
||||
6295696427695493110141186605837397185848992307978456138112526915330347715236378041486547994708748840844217371233735072572979
|
||||
|
||||
B ==
|
||||
246595759
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
26405175827665701256325699315126705508919255051121452292124404943796947287968603975320562847910946802396632302209435206627913466015741799499
|
||||
|
||||
A ==
|
||||
3104984078042317488749073016454213579257792635142218294052134804187631661145261015102617582090263808696699966840735333252107678792123
|
||||
|
||||
B ==
|
||||
4252063
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
11122146237908413610034600609460545703591095894418599759742741406628055069007082998134905595800236452010905900391505454890446585211975124558601770163
|
||||
|
||||
A ==
|
||||
26405175827665701256325699315126705508919255051121452292124404943796947287968603975320562847910946802396632302209435206627913466015741799499
|
||||
|
||||
B ==
|
||||
210605419
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
1649861642047798890580354082088712649911849362201343649289384923147797960364736011515757482030049342943790127685185806092659832129486307035500638595572396187
|
||||
|
||||
A ==
|
||||
11122146237908413610034600609460545703591095894418599759742741406628055069007082998134905595800236452010905900391505454890446585211975124558601770163
|
||||
|
||||
B ==
|
||||
74170111
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
857983367126266717607389719637086684134462613006415859877666235955788392464081914127715967940968197765042399904117392707518175220864852816390004264107201177394565363
|
||||
|
||||
A ==
|
||||
1649861642047798890580354082088712649911849362201343649289384923147797960364736011515757482030049342943790127685185806092659832129486307035500638595572396187
|
||||
|
||||
B ==
|
||||
260016763
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
175995909353623703257072120479340610010337144085688850745292031336724691277374210929188442230237711063783727092685448718515661641054886101716698390145283196296702450566161283
|
||||
|
||||
A ==
|
||||
857983367126266717607389719637086684134462613006415859877666235955788392464081914127715967940968197765042399904117392707518175220864852816390004264107201177394565363
|
||||
|
||||
B ==
|
||||
102563707
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
48486002551155667224487059713350447239190772068092630563272168418880661006593537218144160068395218642353495339720640699721703003648144463556291315694787862009052641640656933232794283
|
||||
|
||||
A ==
|
||||
175995909353623703257072120479340610010337144085688850745292031336724691277374210929188442230237711063783727092685448718515661641054886101716698390145283196296702450566161283
|
||||
|
||||
B ==
|
||||
137747527
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
13156468011529105025061495011938518171328604045212410096476697450506055664012861932372156505805788068791146986282263016790631108386790291275939575123375304599622623328517354163964228279867403
|
||||
|
||||
A ==
|
||||
48486002551155667224487059713350447239190772068092630563272168418880661006593537218144160068395218642353495339720640699721703003648144463556291315694787862009052641640656933232794283
|
||||
|
||||
B ==
|
||||
135672847
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
6355194692790533601105154341731997464407930009404822926832136060319955058388106456084549316415200519472481147942263916585428906582726749131479465958107142228236909665306781538860053107680830113869123
|
||||
|
||||
A ==
|
||||
13156468011529105025061495011938518171328604045212410096476697450506055664012861932372156505805788068791146986282263016790631108386790291275939575123375304599622623328517354163964228279867403
|
||||
|
||||
B ==
|
||||
241523587
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
3157116676535430302794438027544146642863331358530722860333745617571010460905857862561870488000265751138954271040017454405707755458702044884023184574412221802502351503929935224995314581932097706874819348858083
|
||||
|
||||
A ==
|
||||
6355194692790533601105154341731997464407930009404822926832136060319955058388106456084549316415200519472481147942263916585428906582726749131479465958107142228236909665306781538860053107680830113869123
|
||||
|
||||
B ==
|
||||
248388667
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
390533129219992506725320633489467713907837370444962163378727819939092929448752905310115311180032249230394348337568973177802874166228132778126338883671958897238722734394783244237133367055422297736215754829839364158067
|
||||
|
||||
A ==
|
||||
3157116676535430302794438027544146642863331358530722860333745617571010460905857862561870488000265751138954271040017454405707755458702044884023184574412221802502351503929935224995314581932097706874819348858083
|
||||
|
||||
B ==
|
||||
61849651
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
48583654555070224891047847050732516652910250240135992225139515777200432486685999462997073444468380434359929499498804723793106565291183220444221080449740542884172281158126259373095216435009661050109711341419005972852770440739
|
||||
|
||||
A ==
|
||||
390533129219992506725320633489467713907837370444962163378727819939092929448752905310115311180032249230394348337568973177802874166228132778126338883671958897238722734394783244237133367055422297736215754829839364158067
|
||||
|
||||
B ==
|
||||
62201707
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
25733035251905120039135866524384525138869748427727001128764704499071378939227862068500633813538831598776578372709963673670934388213622433800015759585470542686333039614931682098922935087822950084908715298627996115185849260703525317419
|
||||
|
||||
A ==
|
||||
48583654555070224891047847050732516652910250240135992225139515777200432486685999462997073444468380434359929499498804723793106565291183220444221080449740542884172281158126259373095216435009661050109711341419005972852770440739
|
||||
|
||||
B ==
|
||||
264832231
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
2804594464939948901906623499531073917980499195397462605359913717827014360538186518540781517129548650937632008683280555602633122170458773895504894807182664540529077836857897972175530148107545939211339044386106111633510166695386323426241809387
|
||||
|
||||
A ==
|
||||
25733035251905120039135866524384525138869748427727001128764704499071378939227862068500633813538831598776578372709963673670934388213622433800015759585470542686333039614931682098922935087822950084908715298627996115185849260703525317419
|
||||
|
||||
B ==
|
||||
54494047
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
738136612083433720096707308165797114449914259256979340471077690416567237592465306112484843530074782721390528773594351482384711900456440808251196845265132086486672447136822046628407467459921823150600138073268385534588238548865012638209515923513516547
|
||||
|
||||
A ==
|
||||
2804594464939948901906623499531073917980499195397462605359913717827014360538186518540781517129548650937632008683280555602633122170458773895504894807182664540529077836857897972175530148107545939211339044386106111633510166695386323426241809387
|
||||
|
||||
B ==
|
||||
131594179
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
392847529056126766528615419937165193421166694172790666626558750047057558168124866940509180171236517681470100877687445134633784815352076138790217228749332398026714192707447855731679485746120589851992221508292976900578299504461333767437280988393026452846013683
|
||||
|
||||
A ==
|
||||
738136612083433720096707308165797114449914259256979340471077690416567237592465306112484843530074782721390528773594351482384711900456440808251196845265132086486672447136822046628407467459921823150600138073268385534588238548865012638209515923513516547
|
||||
|
||||
B ==
|
||||
266107603
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
168459393231883505975876919268398655632763956627405508859662408056221544310200546265681845397346956580604208064328814319465940958080244889692368602591598503944015835190587740756859842792554282496742843600573336023639256008687581291233481455395123454655488735304365627
|
||||
|
||||
A ==
|
||||
392847529056126766528615419937165193421166694172790666626558750047057558168124866940509180171236517681470100877687445134633784815352076138790217228749332398026714192707447855731679485746120589851992221508292976900578299504461333767437280988393026452846013683
|
||||
|
||||
B ==
|
||||
214408111
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
14865774288636941404884923981945833072113667565310054952177860608355263252462409554658728941191929400198053290113492910272458441655458514080123870132092365833472436407455910185221474386718838138135065780840839893113912689594815485706154461164071775481134379794909690501684643
|
||||
|
||||
A ==
|
||||
168459393231883505975876919268398655632763956627405508859662408056221544310200546265681845397346956580604208064328814319465940958080244889692368602591598503944015835190587740756859842792554282496742843600573336023639256008687581291233481455395123454655488735304365627
|
||||
|
||||
B ==
|
||||
44122723
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
1213301773203241614897109856134894783021668292000023984098824423682568173639394290886185366993108292039068940333907505157813934962357206131450244004178619265868614859794316361031904412926604138893775068853175215502104744339658944443630407632290152772487455298652998368296998719996019
|
||||
|
||||
A ==
|
||||
14865774288636941404884923981945833072113667565310054952177860608355263252462409554658728941191929400198053290113492910272458441655458514080123870132092365833472436407455910185221474386718838138135065780840839893113912689594815485706154461164071775481134379794909690501684643
|
||||
|
||||
B ==
|
||||
40808563
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
186935245989515158127969129347464851990429060640910951266513740972248428651109062997368144722015290092846666943896556191257222521203647606911446635194198213436423080005867489516421559330500722264446765608763224572386410155413161172707802334865729654109050873820610813855041667633843601286843
|
||||
|
||||
A ==
|
||||
1213301773203241614897109856134894783021668292000023984098824423682568173639394290886185366993108292039068940333907505157813934962357206131450244004178619265868614859794316361031904412926604138893775068853175215502104744339658944443630407632290152772487455298652998368296998719996019
|
||||
|
||||
B ==
|
||||
77035759
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
83142661079751490510739960019112406284111408348732592580459037404394946037094409915127399165633756159385609671956087845517678367844901424617866988187132480585966721962585586730693443536100138246516868613250009028187662080828012497191775172228832247706080044971423654632146928165751885302331924491683
|
||||
|
||||
A ==
|
||||
186935245989515158127969129347464851990429060640910951266513740972248428651109062997368144722015290092846666943896556191257222521203647606911446635194198213436423080005867489516421559330500722264446765608763224572386410155413161172707802334865729654109050873820610813855041667633843601286843
|
||||
|
||||
B ==
|
||||
222383587
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
3892354773803809855317742245039794448230625839512638747643814927766738642436392673485997449586432241626440927010641564064764336402368634186618250134234189066179771240232458249806850838490410473462391401438160528157981942499581634732706904411807195259620779379274017704050790865030808501633772117217899534443
|
||||
|
||||
A ==
|
||||
83142661079751490510739960019112406284111408348732592580459037404394946037094409915127399165633756159385609671956087845517678367844901424617866988187132480585966721962585586730693443536100138246516868613250009028187662080828012497191775172228832247706080044971423654632146928165751885302331924491683
|
||||
|
||||
B ==
|
||||
23407687
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
1663606652988091811284014366560171522582683318514519379924950390627250155440313691226744227787921928894551755219495501365555370027257568506349958010457682898612082048959464465369892842603765280317696116552850664773291371490339084156052244256635115997453399761029567033971998617303988376172539172702246575225837054723
|
||||
|
||||
A ==
|
||||
3892354773803809855317742245039794448230625839512638747643814927766738642436392673485997449586432241626440927010641564064764336402368634186618250134234189066179771240232458249806850838490410473462391401438160528157981942499581634732706904411807195259620779379274017704050790865030808501633772117217899534443
|
||||
|
||||
B ==
|
||||
213701827
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
|
||||
|
||||
Took 33057 ticks, 1048 bits
|
||||
P == 1663606652988091811284014366560171522582683318514519379924950390627250155440313691226744227787921928894551755219495501365555370027257568506349958010457682898612082048959464465369892842603765280317696116552850664773291371490339084156052244256635115997453399761029567033971998617303988376172539172702246575225837054723
|
||||
Q == 3892354773803809855317742245039794448230625839512638747643814927766738642436392673485997449586432241626440927010641564064764336402368634186618250134234189066179771240232458249806850838490410473462391401438160528157981942499581634732706904411807195259620779379274017704050790865030808501633772117217899534443
|
||||
@@ -1,205 +0,0 @@
|
||||
Enter # of bits:
|
||||
Enter number of bases to try (1 to 8):
|
||||
Certificate of primality for:
|
||||
85933926807634727
|
||||
|
||||
A ==
|
||||
253758023
|
||||
|
||||
B ==
|
||||
169322581
|
||||
|
||||
G == 5
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
23930198825086241462113799
|
||||
|
||||
A ==
|
||||
85933926807634727
|
||||
|
||||
B ==
|
||||
139236037
|
||||
|
||||
G == 11
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
6401844647261612602378676572510019
|
||||
|
||||
A ==
|
||||
23930198825086241462113799
|
||||
|
||||
B ==
|
||||
133760791
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
269731366027728777712034888684015329354259
|
||||
|
||||
A ==
|
||||
6401844647261612602378676572510019
|
||||
|
||||
B ==
|
||||
21066691
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
37942338209025571690075025099189467992329684223707
|
||||
|
||||
A ==
|
||||
269731366027728777712034888684015329354259
|
||||
|
||||
B ==
|
||||
70333567
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
15306904714258982484473490774101705363308327436988160248323
|
||||
|
||||
A ==
|
||||
37942338209025571690075025099189467992329684223707
|
||||
|
||||
B ==
|
||||
201712723
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
1616744757018513392810355191503853040357155275733333124624513530099
|
||||
|
||||
A ==
|
||||
15306904714258982484473490774101705363308327436988160248323
|
||||
|
||||
B ==
|
||||
52810963
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
464222094814208047161771036072622485188658077940154689939306386289983787983
|
||||
|
||||
A ==
|
||||
1616744757018513392810355191503853040357155275733333124624513530099
|
||||
|
||||
B ==
|
||||
143566909
|
||||
|
||||
G == 5
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
187429931674053784626487560729643601208757374994177258429930699354770049369025096447
|
||||
|
||||
A ==
|
||||
464222094814208047161771036072622485188658077940154689939306386289983787983
|
||||
|
||||
B ==
|
||||
201875281
|
||||
|
||||
G == 5
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
100579220846502621074093727119851331775052664444339632682598589456666938521976625305832917563
|
||||
|
||||
A ==
|
||||
187429931674053784626487560729643601208757374994177258429930699354770049369025096447
|
||||
|
||||
B ==
|
||||
268311523
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
1173616081309758475197022137833792133815753368965945885089720153370737965497134878651384030219765163
|
||||
|
||||
A ==
|
||||
100579220846502621074093727119851331775052664444339632682598589456666938521976625305832917563
|
||||
|
||||
B ==
|
||||
5834287
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
191456913489905913185935197655672585713573070349044195411728114905691721186574907738081340754373032735283623
|
||||
|
||||
A ==
|
||||
1173616081309758475197022137833792133815753368965945885089720153370737965497134878651384030219765163
|
||||
|
||||
B ==
|
||||
81567097
|
||||
|
||||
G == 5
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
57856530489201750164178576399448868489243874083056587683743345599898489554401618943240901541005080049321706789987519
|
||||
|
||||
A ==
|
||||
191456913489905913185935197655672585713573070349044195411728114905691721186574907738081340754373032735283623
|
||||
|
||||
B ==
|
||||
151095433
|
||||
|
||||
G == 7
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
13790529750452576698109671710773784949185621244122040804792403407272729038377767162233653248852099545134831722512085881814803
|
||||
|
||||
A ==
|
||||
57856530489201750164178576399448868489243874083056587683743345599898489554401618943240901541005080049321706789987519
|
||||
|
||||
B ==
|
||||
119178679
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
7075985989000817742677547821106534174334812111605018857703825637170140040509067704269696198231266351631132464035671858077052876058979
|
||||
|
||||
A ==
|
||||
13790529750452576698109671710773784949185621244122040804792403407272729038377767162233653248852099545134831722512085881814803
|
||||
|
||||
B ==
|
||||
256552363
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
1227273006232588072907488910282307435921226646895131225407452056677899411162892829564455154080310937471747140942360789623819327234258162420463
|
||||
|
||||
A ==
|
||||
7075985989000817742677547821106534174334812111605018857703825637170140040509067704269696198231266351631132464035671858077052876058979
|
||||
|
||||
B ==
|
||||
86720989
|
||||
|
||||
G == 5
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
446764896913554613686067036908702877942872355053329937790398156069936255759889884246832779737114032666318220500106499161852193765380831330106375235763
|
||||
|
||||
A ==
|
||||
1227273006232588072907488910282307435921226646895131225407452056677899411162892829564455154080310937471747140942360789623819327234258162420463
|
||||
|
||||
B ==
|
||||
182015287
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
Certificate of primality for:
|
||||
5290203010849586596974953717018896543907195901082056939587768479377028575911127944611236020459652034082251335583308070846379514569838984811187823420951275243
|
||||
|
||||
A ==
|
||||
446764896913554613686067036908702877942872355053329937790398156069936255759889884246832779737114032666318220500106499161852193765380831330106375235763
|
||||
|
||||
B ==
|
||||
5920567
|
||||
|
||||
G == 2
|
||||
----------------------------------------------------------------
|
||||
|
||||
|
||||
Took 3454 ticks, 521 bits
|
||||
P == 5290203010849586596974953717018896543907195901082056939587768479377028575911127944611236020459652034082251335583308070846379514569838984811187823420951275243
|
||||
Q == 446764896913554613686067036908702877942872355053329937790398156069936255759889884246832779737114032666318220500106499161852193765380831330106375235763
|
||||
@@ -1,37 +0,0 @@
|
||||
; x86 timer in NASM
|
||||
;
|
||||
; Tom St Denis, tomstdenis@iahu.ca
|
||||
[bits 32]
|
||||
[section .data]
|
||||
time dd 0, 0
|
||||
|
||||
[section .text]
|
||||
|
||||
%ifdef USE_ELF
|
||||
[global t_start]
|
||||
t_start:
|
||||
%else
|
||||
[global _t_start]
|
||||
_t_start:
|
||||
%endif
|
||||
push edx
|
||||
push eax
|
||||
rdtsc
|
||||
mov [time+0],edx
|
||||
mov [time+4],eax
|
||||
pop eax
|
||||
pop edx
|
||||
ret
|
||||
|
||||
%ifdef USE_ELF
|
||||
[global t_read]
|
||||
t_read:
|
||||
%else
|
||||
[global _t_read]
|
||||
_t_read:
|
||||
%endif
|
||||
rdtsc
|
||||
sub eax,[time+4]
|
||||
sbb edx,[time+0]
|
||||
ret
|
||||
|
||||
@@ -1,138 +0,0 @@
|
||||
/* Tune the Karatsuba parameters
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com
|
||||
*/
|
||||
#include <tommath.h>
|
||||
#include <time.h>
|
||||
|
||||
/* how many times todo each size mult. Depends on your computer. For slow computers
|
||||
* this can be low like 5 or 10. For fast [re: Athlon] should be 25 - 50 or so
|
||||
*/
|
||||
#define TIMES (1UL<<14UL)
|
||||
|
||||
/* RDTSC from Scott Duplichan */
|
||||
static ulong64 TIMFUNC (void)
|
||||
{
|
||||
#if defined __GNUC__
|
||||
#if defined(__i386__) || defined(__x86_64__)
|
||||
unsigned long long a;
|
||||
__asm__ __volatile__ ("rdtsc\nmovl %%eax,%0\nmovl %%edx,4+%0\n"::"m"(a):"%eax","%edx");
|
||||
return a;
|
||||
#else /* gcc-IA64 version */
|
||||
unsigned long result;
|
||||
__asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory");
|
||||
while (__builtin_expect ((int) result == -1, 0))
|
||||
__asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory");
|
||||
return result;
|
||||
#endif
|
||||
|
||||
// Microsoft and Intel Windows compilers
|
||||
#elif defined _M_IX86
|
||||
__asm rdtsc
|
||||
#elif defined _M_AMD64
|
||||
return __rdtsc ();
|
||||
#elif defined _M_IA64
|
||||
#if defined __INTEL_COMPILER
|
||||
#include <ia64intrin.h>
|
||||
#endif
|
||||
return __getReg (3116);
|
||||
#else
|
||||
#error need rdtsc function for this build
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#ifndef X86_TIMER
|
||||
|
||||
/* generic ISO C timer */
|
||||
ulong64 LBL_T;
|
||||
void t_start(void) { LBL_T = TIMFUNC(); }
|
||||
ulong64 t_read(void) { return TIMFUNC() - LBL_T; }
|
||||
|
||||
#else
|
||||
extern void t_start(void);
|
||||
extern ulong64 t_read(void);
|
||||
#endif
|
||||
|
||||
ulong64 time_mult(int size, int s)
|
||||
{
|
||||
unsigned long x;
|
||||
mp_int a, b, c;
|
||||
ulong64 t1;
|
||||
|
||||
mp_init (&a);
|
||||
mp_init (&b);
|
||||
mp_init (&c);
|
||||
|
||||
mp_rand (&a, size);
|
||||
mp_rand (&b, size);
|
||||
|
||||
if (s == 1) {
|
||||
KARATSUBA_MUL_CUTOFF = size;
|
||||
} else {
|
||||
KARATSUBA_MUL_CUTOFF = 100000;
|
||||
}
|
||||
|
||||
t_start();
|
||||
for (x = 0; x < TIMES; x++) {
|
||||
mp_mul(&a,&b,&c);
|
||||
}
|
||||
t1 = t_read();
|
||||
mp_clear (&a);
|
||||
mp_clear (&b);
|
||||
mp_clear (&c);
|
||||
return t1;
|
||||
}
|
||||
|
||||
ulong64 time_sqr(int size, int s)
|
||||
{
|
||||
unsigned long x;
|
||||
mp_int a, b;
|
||||
ulong64 t1;
|
||||
|
||||
mp_init (&a);
|
||||
mp_init (&b);
|
||||
|
||||
mp_rand (&a, size);
|
||||
|
||||
if (s == 1) {
|
||||
KARATSUBA_SQR_CUTOFF = size;
|
||||
} else {
|
||||
KARATSUBA_SQR_CUTOFF = 100000;
|
||||
}
|
||||
|
||||
t_start();
|
||||
for (x = 0; x < TIMES; x++) {
|
||||
mp_sqr(&a,&b);
|
||||
}
|
||||
t1 = t_read();
|
||||
mp_clear (&a);
|
||||
mp_clear (&b);
|
||||
return t1;
|
||||
}
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
ulong64 t1, t2;
|
||||
int x, y;
|
||||
|
||||
for (x = 8; ; x += 2) {
|
||||
t1 = time_mult(x, 0);
|
||||
t2 = time_mult(x, 1);
|
||||
printf("%d: %9llu %9llu, %9llu\n", x, t1, t2, t2 - t1);
|
||||
if (t2 < t1) break;
|
||||
}
|
||||
y = x;
|
||||
|
||||
for (x = 8; ; x += 2) {
|
||||
t1 = time_sqr(x, 0);
|
||||
t2 = time_sqr(x, 1);
|
||||
printf("%d: %9llu %9llu, %9llu\n", x, t1, t2, t2 - t1);
|
||||
if (t2 < t1) break;
|
||||
}
|
||||
printf("KARATSUBA_MUL_CUTOFF = %d\n", y);
|
||||
printf("KARATSUBA_SQR_CUTOFF = %d\n", x);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
#!/usr/bin/perl -w
|
||||
#
|
||||
# Generates a "single file" you can use to quickly
|
||||
# add the whole source without any makefile troubles
|
||||
#
|
||||
use strict;
|
||||
|
||||
open( OUT, ">mpi.c" ) or die "Couldn't open mpi.c for writing: $!";
|
||||
foreach my $filename (glob "bn*.c") {
|
||||
open( SRC, "<$filename" ) or die "Couldn't open $filename for reading: $!";
|
||||
print OUT "/* Start: $filename */\n";
|
||||
print OUT while <SRC>;
|
||||
print OUT "\n/* End: $filename */\n\n";
|
||||
close SRC or die "Error closing $filename after reading: $!";
|
||||
}
|
||||
print OUT "\n/* EOF */\n";
|
||||
close OUT or die "Error closing mpi.c after writing: $!";
|
||||
@@ -1,13 +0,0 @@
|
||||
To use the pretty graphs you have to first build/run the ltmtest from the root directory of the package.
|
||||
Todo this type
|
||||
|
||||
make timing ; ltmtest
|
||||
|
||||
in the root. It will run for a while [about ten minutes on most PCs] and produce a series of .log files in logs/.
|
||||
|
||||
After doing that run "gnuplot graphs.dem" to make the PNGs. If you managed todo that all so far just open index.html to view
|
||||
them all :-)
|
||||
|
||||
Have fun
|
||||
|
||||
Tom
|
||||
@@ -1,16 +0,0 @@
|
||||
480 87
|
||||
960 111
|
||||
1440 135
|
||||
1920 159
|
||||
2400 200
|
||||
2880 224
|
||||
3360 248
|
||||
3840 272
|
||||
4320 296
|
||||
4800 320
|
||||
5280 344
|
||||
5760 368
|
||||
6240 392
|
||||
6720 416
|
||||
7200 440
|
||||
7680 464
|
||||
Binary file not shown.
@@ -1,7 +0,0 @@
|
||||
513 1435869
|
||||
769 3544970
|
||||
1025 7791638
|
||||
2049 46902238
|
||||
2561 85334899
|
||||
3073 141451412
|
||||
4097 308770310
|
||||
Binary file not shown.
@@ -1,5 +0,0 @@
|
||||
607 2109225
|
||||
1279 10148314
|
||||
2203 34126877
|
||||
3217 82716424
|
||||
4253 161569606
|
||||
@@ -1,4 +0,0 @@
|
||||
1024 7705271
|
||||
2048 34286851
|
||||
4096 165207491
|
||||
521 1618631
|
||||
@@ -1,7 +0,0 @@
|
||||
532 1928550
|
||||
784 3763908
|
||||
1036 7564221
|
||||
1540 16566059
|
||||
2072 32283784
|
||||
3080 79851565
|
||||
4116 157843530
|
||||
@@ -1,17 +0,0 @@
|
||||
set terminal png
|
||||
set size 1.75
|
||||
set ylabel "Cycles per Operation"
|
||||
set xlabel "Operand size (bits)"
|
||||
|
||||
set output "addsub.png"
|
||||
plot 'add.log' smooth bezier title "Addition", 'sub.log' smooth bezier title "Subtraction"
|
||||
|
||||
set output "mult.png"
|
||||
plot 'sqr.log' smooth bezier title "Squaring (without Karatsuba)", 'sqr_kara.log' smooth bezier title "Squaring (Karatsuba)", 'mult.log' smooth bezier title "Multiplication (without Karatsuba)", 'mult_kara.log' smooth bezier title "Multiplication (Karatsuba)"
|
||||
|
||||
set output "expt.png"
|
||||
plot 'expt.log' smooth bezier title "Exptmod (Montgomery)", 'expt_dr.log' smooth bezier title "Exptmod (Dimminished Radix)", 'expt_2k.log' smooth bezier title "Exptmod (2k Reduction)"
|
||||
|
||||
set output "invmod.png"
|
||||
plot 'invmod.log' smooth bezier title "Modular Inverse"
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>LibTomMath Log Plots</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>Addition and Subtraction</h1>
|
||||
<center><img src=addsub.png></center>
|
||||
<hr>
|
||||
|
||||
<h1>Multipliers</h1>
|
||||
<center><img src=mult.png></center>
|
||||
<hr>
|
||||
|
||||
<h1>Exptmod</h1>
|
||||
<center><img src=expt.png></center>
|
||||
<hr>
|
||||
|
||||
<h1>Modular Inverse</h1>
|
||||
<center><img src=invmod.png></center>
|
||||
<hr>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Binary file not shown.
@@ -1,84 +0,0 @@
|
||||
271 555
|
||||
390 855
|
||||
508 1161
|
||||
631 1605
|
||||
749 2117
|
||||
871 2687
|
||||
991 3329
|
||||
1108 4084
|
||||
1231 4786
|
||||
1351 5624
|
||||
1470 6392
|
||||
1586 7364
|
||||
1710 8218
|
||||
1830 9255
|
||||
1951 10217
|
||||
2067 11461
|
||||
2191 12463
|
||||
2308 13677
|
||||
2430 14800
|
||||
2551 16232
|
||||
2671 17460
|
||||
2791 18899
|
||||
2902 20247
|
||||
3028 21902
|
||||
3151 23240
|
||||
3267 24927
|
||||
3391 26441
|
||||
3511 28277
|
||||
3631 29838
|
||||
3749 31751
|
||||
3869 33673
|
||||
3989 35431
|
||||
4111 37518
|
||||
4231 39426
|
||||
4349 41504
|
||||
4471 43567
|
||||
4591 45786
|
||||
4711 47876
|
||||
4831 50299
|
||||
4951 52427
|
||||
5071 54785
|
||||
5189 57241
|
||||
5307 59730
|
||||
5431 62194
|
||||
5551 64761
|
||||
5670 67322
|
||||
5789 70073
|
||||
5907 72663
|
||||
6030 75437
|
||||
6151 78242
|
||||
6268 81202
|
||||
6389 83948
|
||||
6509 86985
|
||||
6631 89903
|
||||
6747 93184
|
||||
6869 96044
|
||||
6991 99286
|
||||
7109 102395
|
||||
7229 105917
|
||||
7351 108940
|
||||
7470 112490
|
||||
7589 115702
|
||||
7711 119508
|
||||
7831 122632
|
||||
7951 126410
|
||||
8071 129808
|
||||
8190 133895
|
||||
8311 137146
|
||||
8431 141218
|
||||
8549 144732
|
||||
8667 149131
|
||||
8790 152462
|
||||
8911 156754
|
||||
9030 160479
|
||||
9149 165138
|
||||
9271 168601
|
||||
9391 173185
|
||||
9511 176988
|
||||
9627 181976
|
||||
9751 185539
|
||||
9870 190388
|
||||
9991 194335
|
||||
10110 199605
|
||||
10228 203298
|
||||
Binary file not shown.
@@ -1,84 +0,0 @@
|
||||
271 560
|
||||
391 870
|
||||
511 1159
|
||||
631 1605
|
||||
750 2111
|
||||
871 2737
|
||||
991 3361
|
||||
1111 4054
|
||||
1231 4778
|
||||
1351 5600
|
||||
1471 6404
|
||||
1591 7323
|
||||
1710 8255
|
||||
1831 9239
|
||||
1948 10257
|
||||
2070 11397
|
||||
2190 12531
|
||||
2308 13665
|
||||
2429 14870
|
||||
2550 16175
|
||||
2671 17539
|
||||
2787 18879
|
||||
2911 20350
|
||||
3031 21807
|
||||
3150 23415
|
||||
3270 24897
|
||||
3388 26567
|
||||
3511 28205
|
||||
3627 30076
|
||||
3751 31744
|
||||
3869 33657
|
||||
3991 35425
|
||||
4111 37522
|
||||
4229 39363
|
||||
4351 41503
|
||||
4470 43491
|
||||
4590 45827
|
||||
4711 47795
|
||||
4828 50166
|
||||
4951 52318
|
||||
5070 54911
|
||||
5191 57036
|
||||
5308 58237
|
||||
5431 60248
|
||||
5551 62678
|
||||
5671 64786
|
||||
5791 67294
|
||||
5908 69343
|
||||
6031 71607
|
||||
6151 74166
|
||||
6271 76590
|
||||
6391 78734
|
||||
6511 81175
|
||||
6631 83742
|
||||
6750 86403
|
||||
6868 88873
|
||||
6990 91150
|
||||
7110 94211
|
||||
7228 96922
|
||||
7351 99445
|
||||
7469 102216
|
||||
7589 104968
|
||||
7711 108113
|
||||
7827 110758
|
||||
7950 113714
|
||||
8071 116511
|
||||
8186 119643
|
||||
8310 122679
|
||||
8425 125581
|
||||
8551 128715
|
||||
8669 131778
|
||||
8788 135116
|
||||
8910 138138
|
||||
9031 141628
|
||||
9148 144754
|
||||
9268 148367
|
||||
9391 151551
|
||||
9511 155033
|
||||
9631 158652
|
||||
9751 162125
|
||||
9871 165248
|
||||
9988 168627
|
||||
10111 172427
|
||||
10231 176412
|
||||
@@ -1,84 +0,0 @@
|
||||
265 562
|
||||
389 882
|
||||
509 1207
|
||||
631 1572
|
||||
750 1990
|
||||
859 2433
|
||||
991 2894
|
||||
1109 3555
|
||||
1230 4228
|
||||
1350 5018
|
||||
1471 5805
|
||||
1591 6579
|
||||
1709 7415
|
||||
1829 8329
|
||||
1949 9225
|
||||
2071 10139
|
||||
2188 11239
|
||||
2309 12178
|
||||
2431 13212
|
||||
2551 14294
|
||||
2671 15551
|
||||
2791 16512
|
||||
2911 17718
|
||||
3030 18876
|
||||
3150 20259
|
||||
3270 21374
|
||||
3391 22650
|
||||
3511 23948
|
||||
3631 25493
|
||||
3750 26756
|
||||
3870 28225
|
||||
3989 29705
|
||||
4110 31409
|
||||
4230 32834
|
||||
4351 34327
|
||||
4471 35818
|
||||
4591 37636
|
||||
4711 39228
|
||||
4830 40868
|
||||
4949 42393
|
||||
5070 44541
|
||||
5191 46269
|
||||
5310 48162
|
||||
5429 49728
|
||||
5548 51985
|
||||
5671 53948
|
||||
5791 55885
|
||||
5910 57584
|
||||
6031 60082
|
||||
6150 62239
|
||||
6270 64309
|
||||
6390 66014
|
||||
6511 68766
|
||||
6631 71012
|
||||
6750 73172
|
||||
6871 74952
|
||||
6991 77909
|
||||
7111 80371
|
||||
7231 82666
|
||||
7351 84531
|
||||
7469 87698
|
||||
7589 90318
|
||||
7711 225384
|
||||
7830 232428
|
||||
7950 240009
|
||||
8070 246522
|
||||
8190 253662
|
||||
8310 260961
|
||||
8431 269253
|
||||
8549 275743
|
||||
8671 283769
|
||||
8789 290811
|
||||
8911 300034
|
||||
9030 306873
|
||||
9149 315085
|
||||
9270 323944
|
||||
9390 332390
|
||||
9508 337519
|
||||
9631 348986
|
||||
9749 356904
|
||||
9871 367013
|
||||
9989 373831
|
||||
10108 381033
|
||||
10230 393475
|
||||
@@ -1,84 +0,0 @@
|
||||
271 560
|
||||
388 878
|
||||
511 1179
|
||||
629 1625
|
||||
751 1988
|
||||
871 2423
|
||||
989 2896
|
||||
1111 3561
|
||||
1231 4209
|
||||
1350 5015
|
||||
1470 5804
|
||||
1591 6556
|
||||
1709 7420
|
||||
1831 8263
|
||||
1951 9173
|
||||
2070 10153
|
||||
2191 11229
|
||||
2310 12167
|
||||
2431 13211
|
||||
2550 14309
|
||||
2671 15524
|
||||
2788 16525
|
||||
2910 17712
|
||||
3028 18822
|
||||
3148 20220
|
||||
3271 21343
|
||||
3391 22652
|
||||
3511 23944
|
||||
3630 25485
|
||||
3750 26778
|
||||
3868 28201
|
||||
3990 29653
|
||||
4111 31393
|
||||
4225 32841
|
||||
4350 34328
|
||||
4471 35786
|
||||
4590 37652
|
||||
4711 39245
|
||||
4830 40876
|
||||
4951 42433
|
||||
5068 44547
|
||||
5191 46321
|
||||
5311 48140
|
||||
5430 49727
|
||||
5550 52034
|
||||
5671 53954
|
||||
5791 55921
|
||||
5908 57597
|
||||
6031 60084
|
||||
6148 62226
|
||||
6270 64295
|
||||
6390 66045
|
||||
6511 68779
|
||||
6629 71003
|
||||
6751 73169
|
||||
6871 74992
|
||||
6991 77895
|
||||
7110 80376
|
||||
7231 82628
|
||||
7351 84468
|
||||
7470 87664
|
||||
7591 90284
|
||||
7711 91352
|
||||
7828 93995
|
||||
7950 96276
|
||||
8071 98691
|
||||
8190 101256
|
||||
8308 103631
|
||||
8431 105222
|
||||
8550 108343
|
||||
8671 110281
|
||||
8787 112764
|
||||
8911 115397
|
||||
9031 117690
|
||||
9151 120266
|
||||
9271 122715
|
||||
9391 124624
|
||||
9510 127937
|
||||
9630 130313
|
||||
9750 132914
|
||||
9871 136129
|
||||
9991 138517
|
||||
10108 141525
|
||||
10231 144225
|
||||
@@ -1,16 +0,0 @@
|
||||
480 94
|
||||
960 116
|
||||
1440 140
|
||||
1920 164
|
||||
2400 205
|
||||
2880 229
|
||||
3360 253
|
||||
3840 277
|
||||
4320 299
|
||||
4800 321
|
||||
5280 345
|
||||
5760 371
|
||||
6240 395
|
||||
6720 419
|
||||
7200 441
|
||||
7680 465
|
||||
@@ -1,44 +0,0 @@
|
||||
#
|
||||
# Borland C++Builder Makefile (makefile.bcc)
|
||||
#
|
||||
|
||||
|
||||
LIB = tlib
|
||||
CC = bcc32
|
||||
CFLAGS = -c -O2 -I.
|
||||
|
||||
OBJECTS=bncore.obj bn_mp_init.obj bn_mp_clear.obj bn_mp_exch.obj bn_mp_grow.obj bn_mp_shrink.obj \
|
||||
bn_mp_clamp.obj bn_mp_zero.obj bn_mp_set.obj bn_mp_set_int.obj bn_mp_init_size.obj bn_mp_copy.obj \
|
||||
bn_mp_init_copy.obj bn_mp_abs.obj bn_mp_neg.obj bn_mp_cmp_mag.obj bn_mp_cmp.obj bn_mp_cmp_d.obj \
|
||||
bn_mp_rshd.obj bn_mp_lshd.obj bn_mp_mod_2d.obj bn_mp_div_2d.obj bn_mp_mul_2d.obj bn_mp_div_2.obj \
|
||||
bn_mp_mul_2.obj bn_s_mp_add.obj bn_s_mp_sub.obj bn_fast_s_mp_mul_digs.obj bn_s_mp_mul_digs.obj \
|
||||
bn_fast_s_mp_mul_high_digs.obj bn_s_mp_mul_high_digs.obj bn_fast_s_mp_sqr.obj bn_s_mp_sqr.obj \
|
||||
bn_mp_add.obj bn_mp_sub.obj bn_mp_karatsuba_mul.obj bn_mp_mul.obj bn_mp_karatsuba_sqr.obj \
|
||||
bn_mp_sqr.obj bn_mp_div.obj bn_mp_mod.obj bn_mp_add_d.obj bn_mp_sub_d.obj bn_mp_mul_d.obj \
|
||||
bn_mp_div_d.obj bn_mp_mod_d.obj bn_mp_expt_d.obj bn_mp_addmod.obj bn_mp_submod.obj \
|
||||
bn_mp_mulmod.obj bn_mp_sqrmod.obj bn_mp_gcd.obj bn_mp_lcm.obj bn_fast_mp_invmod.obj bn_mp_invmod.obj \
|
||||
bn_mp_reduce.obj bn_mp_montgomery_setup.obj bn_fast_mp_montgomery_reduce.obj bn_mp_montgomery_reduce.obj \
|
||||
bn_mp_exptmod_fast.obj bn_mp_exptmod.obj bn_mp_2expt.obj bn_mp_n_root.obj bn_mp_jacobi.obj bn_reverse.obj \
|
||||
bn_mp_count_bits.obj bn_mp_read_unsigned_bin.obj bn_mp_read_signed_bin.obj bn_mp_to_unsigned_bin.obj \
|
||||
bn_mp_to_signed_bin.obj bn_mp_unsigned_bin_size.obj bn_mp_signed_bin_size.obj \
|
||||
bn_mp_xor.obj bn_mp_and.obj bn_mp_or.obj bn_mp_rand.obj bn_mp_montgomery_calc_normalization.obj \
|
||||
bn_mp_prime_is_divisible.obj bn_prime_tab.obj bn_mp_prime_fermat.obj bn_mp_prime_miller_rabin.obj \
|
||||
bn_mp_prime_is_prime.obj bn_mp_prime_next_prime.obj bn_mp_dr_reduce.obj \
|
||||
bn_mp_dr_is_modulus.obj bn_mp_dr_setup.obj bn_mp_reduce_setup.obj \
|
||||
bn_mp_toom_mul.obj bn_mp_toom_sqr.obj bn_mp_div_3.obj bn_s_mp_exptmod.obj \
|
||||
bn_mp_reduce_2k.obj bn_mp_reduce_is_2k.obj bn_mp_reduce_2k_setup.obj \
|
||||
bn_mp_reduce_2k_l.obj bn_mp_reduce_is_2k_l.obj bn_mp_reduce_2k_setup_l.obj \
|
||||
bn_mp_radix_smap.obj bn_mp_read_radix.obj bn_mp_toradix.obj bn_mp_radix_size.obj \
|
||||
bn_mp_fread.obj bn_mp_fwrite.obj bn_mp_cnt_lsb.obj bn_error.obj \
|
||||
bn_mp_init_multi.obj bn_mp_clear_multi.obj bn_mp_exteuclid.obj bn_mp_toradix_n.obj \
|
||||
bn_mp_prime_random_ex.obj bn_mp_get_int.obj bn_mp_sqrt.obj bn_mp_is_square.obj \
|
||||
bn_mp_init_set.obj bn_mp_init_set_int.obj bn_mp_invmod_slow.obj bn_mp_prime_rabin_miller_trials.obj \
|
||||
bn_mp_to_signed_bin_n.obj bn_mp_to_unsigned_bin_n.obj
|
||||
|
||||
TARGET = libtommath.lib
|
||||
|
||||
$(TARGET): $(OBJECTS)
|
||||
|
||||
.c.obj:
|
||||
$(CC) $(CFLAGS) $<
|
||||
$(LIB) $(TARGET) -+$@
|
||||
@@ -1,51 +0,0 @@
|
||||
#Makefile for Cygwin-GCC
|
||||
#
|
||||
#This makefile will build a Windows DLL [doesn't require cygwin to run] in the file
|
||||
#libtommath.dll. The import library is in libtommath.dll.a. Remember to add
|
||||
#"-Wl,--enable-auto-import" to your client build to avoid the auto-import warnings
|
||||
#
|
||||
#Tom St Denis
|
||||
CFLAGS += -I./ -Wall -W -Wshadow -O3 -funroll-loops -mno-cygwin
|
||||
|
||||
#x86 optimizations [should be valid for any GCC install though]
|
||||
CFLAGS += -fomit-frame-pointer
|
||||
|
||||
default: windll
|
||||
|
||||
OBJECTS=bncore.o bn_mp_init.o bn_mp_clear.o bn_mp_exch.o bn_mp_grow.o bn_mp_shrink.o \
|
||||
bn_mp_clamp.o bn_mp_zero.o bn_mp_set.o bn_mp_set_int.o bn_mp_init_size.o bn_mp_copy.o \
|
||||
bn_mp_init_copy.o bn_mp_abs.o bn_mp_neg.o bn_mp_cmp_mag.o bn_mp_cmp.o bn_mp_cmp_d.o \
|
||||
bn_mp_rshd.o bn_mp_lshd.o bn_mp_mod_2d.o bn_mp_div_2d.o bn_mp_mul_2d.o bn_mp_div_2.o \
|
||||
bn_mp_mul_2.o bn_s_mp_add.o bn_s_mp_sub.o bn_fast_s_mp_mul_digs.o bn_s_mp_mul_digs.o \
|
||||
bn_fast_s_mp_mul_high_digs.o bn_s_mp_mul_high_digs.o bn_fast_s_mp_sqr.o bn_s_mp_sqr.o \
|
||||
bn_mp_add.o bn_mp_sub.o bn_mp_karatsuba_mul.o bn_mp_mul.o bn_mp_karatsuba_sqr.o \
|
||||
bn_mp_sqr.o bn_mp_div.o bn_mp_mod.o bn_mp_add_d.o bn_mp_sub_d.o bn_mp_mul_d.o \
|
||||
bn_mp_div_d.o bn_mp_mod_d.o bn_mp_expt_d.o bn_mp_addmod.o bn_mp_submod.o \
|
||||
bn_mp_mulmod.o bn_mp_sqrmod.o bn_mp_gcd.o bn_mp_lcm.o bn_fast_mp_invmod.o bn_mp_invmod.o \
|
||||
bn_mp_reduce.o bn_mp_montgomery_setup.o bn_fast_mp_montgomery_reduce.o bn_mp_montgomery_reduce.o \
|
||||
bn_mp_exptmod_fast.o bn_mp_exptmod.o bn_mp_2expt.o bn_mp_n_root.o bn_mp_jacobi.o bn_reverse.o \
|
||||
bn_mp_count_bits.o bn_mp_read_unsigned_bin.o bn_mp_read_signed_bin.o bn_mp_to_unsigned_bin.o \
|
||||
bn_mp_to_signed_bin.o bn_mp_unsigned_bin_size.o bn_mp_signed_bin_size.o \
|
||||
bn_mp_xor.o bn_mp_and.o bn_mp_or.o bn_mp_rand.o bn_mp_montgomery_calc_normalization.o \
|
||||
bn_mp_prime_is_divisible.o bn_prime_tab.o bn_mp_prime_fermat.o bn_mp_prime_miller_rabin.o \
|
||||
bn_mp_prime_is_prime.o bn_mp_prime_next_prime.o bn_mp_dr_reduce.o \
|
||||
bn_mp_dr_is_modulus.o bn_mp_dr_setup.o bn_mp_reduce_setup.o \
|
||||
bn_mp_toom_mul.o bn_mp_toom_sqr.o bn_mp_div_3.o bn_s_mp_exptmod.o \
|
||||
bn_mp_reduce_2k.o bn_mp_reduce_is_2k.o bn_mp_reduce_2k_setup.o \
|
||||
bn_mp_reduce_2k_l.o bn_mp_reduce_is_2k_l.o bn_mp_reduce_2k_setup_l.o \
|
||||
bn_mp_radix_smap.o bn_mp_read_radix.o bn_mp_toradix.o bn_mp_radix_size.o \
|
||||
bn_mp_fread.o bn_mp_fwrite.o bn_mp_cnt_lsb.o bn_error.o \
|
||||
bn_mp_init_multi.o bn_mp_clear_multi.o bn_mp_exteuclid.o bn_mp_toradix_n.o \
|
||||
bn_mp_prime_random_ex.o bn_mp_get_int.o bn_mp_sqrt.o bn_mp_is_square.o bn_mp_init_set.o \
|
||||
bn_mp_init_set_int.o bn_mp_invmod_slow.o bn_mp_prime_rabin_miller_trials.o \
|
||||
bn_mp_to_signed_bin_n.o bn_mp_to_unsigned_bin_n.o
|
||||
|
||||
# make a Windows DLL via Cygwin
|
||||
windll: $(OBJECTS)
|
||||
gcc -mno-cygwin -mdll -o libtommath.dll -Wl,--out-implib=libtommath.dll.a -Wl,--export-all-symbols *.o
|
||||
ranlib libtommath.dll.a
|
||||
|
||||
# build the test program using the windows DLL
|
||||
test: $(OBJECTS) windll
|
||||
gcc $(CFLAGS) demo/demo.c libtommath.dll.a -Wl,--enable-auto-import -o test -s
|
||||
cd mtest ; $(CC) -O3 -fomit-frame-pointer -funroll-loops mtest.c -o mtest -s
|
||||
@@ -1,116 +0,0 @@
|
||||
#Makefile for ICC
|
||||
#
|
||||
#Tom St Denis
|
||||
CC=icc
|
||||
|
||||
CFLAGS += -I./
|
||||
|
||||
# optimize for SPEED
|
||||
#
|
||||
# -mcpu= can be pentium, pentiumpro (covers PII through PIII) or pentium4
|
||||
# -ax? specifies make code specifically for ? but compatible with IA-32
|
||||
# -x? specifies compile solely for ? [not specifically IA-32 compatible]
|
||||
#
|
||||
# where ? is
|
||||
# K - PIII
|
||||
# W - first P4 [Williamette]
|
||||
# N - P4 Northwood
|
||||
# P - P4 Prescott
|
||||
# B - Blend of P4 and PM [mobile]
|
||||
#
|
||||
# Default to just generic max opts
|
||||
CFLAGS += -O3 -xP -ip
|
||||
|
||||
#install as this user
|
||||
USER=root
|
||||
GROUP=root
|
||||
|
||||
default: libtommath.a
|
||||
|
||||
#default files to install
|
||||
LIBNAME=libtommath.a
|
||||
HEADERS=tommath.h
|
||||
|
||||
#LIBPATH-The directory for libtomcrypt to be installed to.
|
||||
#INCPATH-The directory to install the header files for libtommath.
|
||||
#DATAPATH-The directory to install the pdf docs.
|
||||
DESTDIR=
|
||||
LIBPATH=/usr/lib
|
||||
INCPATH=/usr/include
|
||||
DATAPATH=/usr/share/doc/libtommath/pdf
|
||||
|
||||
OBJECTS=bncore.o bn_mp_init.o bn_mp_clear.o bn_mp_exch.o bn_mp_grow.o bn_mp_shrink.o \
|
||||
bn_mp_clamp.o bn_mp_zero.o bn_mp_set.o bn_mp_set_int.o bn_mp_init_size.o bn_mp_copy.o \
|
||||
bn_mp_init_copy.o bn_mp_abs.o bn_mp_neg.o bn_mp_cmp_mag.o bn_mp_cmp.o bn_mp_cmp_d.o \
|
||||
bn_mp_rshd.o bn_mp_lshd.o bn_mp_mod_2d.o bn_mp_div_2d.o bn_mp_mul_2d.o bn_mp_div_2.o \
|
||||
bn_mp_mul_2.o bn_s_mp_add.o bn_s_mp_sub.o bn_fast_s_mp_mul_digs.o bn_s_mp_mul_digs.o \
|
||||
bn_fast_s_mp_mul_high_digs.o bn_s_mp_mul_high_digs.o bn_fast_s_mp_sqr.o bn_s_mp_sqr.o \
|
||||
bn_mp_add.o bn_mp_sub.o bn_mp_karatsuba_mul.o bn_mp_mul.o bn_mp_karatsuba_sqr.o \
|
||||
bn_mp_sqr.o bn_mp_div.o bn_mp_mod.o bn_mp_add_d.o bn_mp_sub_d.o bn_mp_mul_d.o \
|
||||
bn_mp_div_d.o bn_mp_mod_d.o bn_mp_expt_d.o bn_mp_addmod.o bn_mp_submod.o \
|
||||
bn_mp_mulmod.o bn_mp_sqrmod.o bn_mp_gcd.o bn_mp_lcm.o bn_fast_mp_invmod.o bn_mp_invmod.o \
|
||||
bn_mp_reduce.o bn_mp_montgomery_setup.o bn_fast_mp_montgomery_reduce.o bn_mp_montgomery_reduce.o \
|
||||
bn_mp_exptmod_fast.o bn_mp_exptmod.o bn_mp_2expt.o bn_mp_n_root.o bn_mp_jacobi.o bn_reverse.o \
|
||||
bn_mp_count_bits.o bn_mp_read_unsigned_bin.o bn_mp_read_signed_bin.o bn_mp_to_unsigned_bin.o \
|
||||
bn_mp_to_signed_bin.o bn_mp_unsigned_bin_size.o bn_mp_signed_bin_size.o \
|
||||
bn_mp_xor.o bn_mp_and.o bn_mp_or.o bn_mp_rand.o bn_mp_montgomery_calc_normalization.o \
|
||||
bn_mp_prime_is_divisible.o bn_prime_tab.o bn_mp_prime_fermat.o bn_mp_prime_miller_rabin.o \
|
||||
bn_mp_prime_is_prime.o bn_mp_prime_next_prime.o bn_mp_dr_reduce.o \
|
||||
bn_mp_dr_is_modulus.o bn_mp_dr_setup.o bn_mp_reduce_setup.o \
|
||||
bn_mp_toom_mul.o bn_mp_toom_sqr.o bn_mp_div_3.o bn_s_mp_exptmod.o \
|
||||
bn_mp_reduce_2k.o bn_mp_reduce_is_2k.o bn_mp_reduce_2k_setup.o \
|
||||
bn_mp_reduce_2k_l.o bn_mp_reduce_is_2k_l.o bn_mp_reduce_2k_setup_l.o \
|
||||
bn_mp_radix_smap.o bn_mp_read_radix.o bn_mp_toradix.o bn_mp_radix_size.o \
|
||||
bn_mp_fread.o bn_mp_fwrite.o bn_mp_cnt_lsb.o bn_error.o \
|
||||
bn_mp_init_multi.o bn_mp_clear_multi.o bn_mp_exteuclid.o bn_mp_toradix_n.o \
|
||||
bn_mp_prime_random_ex.o bn_mp_get_int.o bn_mp_sqrt.o bn_mp_is_square.o bn_mp_init_set.o \
|
||||
bn_mp_init_set_int.o bn_mp_invmod_slow.o bn_mp_prime_rabin_miller_trials.o \
|
||||
bn_mp_to_signed_bin_n.o bn_mp_to_unsigned_bin_n.o
|
||||
|
||||
libtommath.a: $(OBJECTS)
|
||||
$(AR) $(ARFLAGS) libtommath.a $(OBJECTS)
|
||||
ranlib libtommath.a
|
||||
|
||||
#make a profiled library (takes a while!!!)
|
||||
#
|
||||
# This will build the library with profile generation
|
||||
# then run the test demo and rebuild the library.
|
||||
#
|
||||
# So far I've seen improvements in the MP math
|
||||
profiled:
|
||||
make -f makefile.icc CFLAGS="$(CFLAGS) -prof_gen -DTESTING" timing
|
||||
./ltmtest
|
||||
rm -f *.a *.o ltmtest
|
||||
make -f makefile.icc CFLAGS="$(CFLAGS) -prof_use"
|
||||
|
||||
#make a single object profiled library
|
||||
profiled_single:
|
||||
perl gen.pl
|
||||
$(CC) $(CFLAGS) -prof_gen -DTESTING -c mpi.c -o mpi.o
|
||||
$(CC) $(CFLAGS) -DTESTING -DTIMER demo/demo.c mpi.o -o ltmtest
|
||||
./ltmtest
|
||||
rm -f *.o ltmtest
|
||||
$(CC) $(CFLAGS) -prof_use -ip -DTESTING -c mpi.c -o mpi.o
|
||||
$(AR) $(ARFLAGS) libtommath.a mpi.o
|
||||
ranlib libtommath.a
|
||||
|
||||
install: libtommath.a
|
||||
install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(LIBPATH)
|
||||
install -d -g $(GROUP) -o $(USER) $(DESTDIR)$(INCPATH)
|
||||
install -g $(GROUP) -o $(USER) $(LIBNAME) $(DESTDIR)$(LIBPATH)
|
||||
install -g $(GROUP) -o $(USER) $(HEADERS) $(DESTDIR)$(INCPATH)
|
||||
|
||||
test: libtommath.a demo/demo.o
|
||||
$(CC) demo/demo.o libtommath.a -o test
|
||||
|
||||
mtest: test
|
||||
cd mtest ; $(CC) $(CFLAGS) mtest.c -o mtest
|
||||
|
||||
timing: libtommath.a
|
||||
$(CC) $(CFLAGS) -DTIMER demo/timing.c libtommath.a -o ltmtest
|
||||
|
||||
clean:
|
||||
rm -f *.bat *.pdf *.o *.a *.obj *.lib *.exe *.dll etclib/*.o demo/demo.o test ltmtest mpitest mtest/mtest mtest/mtest.exe \
|
||||
*.idx *.toc *.log *.aux *.dvi *.lof *.ind *.ilg *.ps *.log *.s mpi.c *.il etc/*.il *.dyn
|
||||
cd etc ; make clean
|
||||
cd pics ; make clean
|
||||
@@ -1,4 +0,0 @@
|
||||
#!/bin/bash
|
||||
if cvs log $1 >/dev/null 2>/dev/null; then exit 0; else echo "$1 shouldn't be here" ; exit 1; fi
|
||||
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
const float s_logv_2[] = {
|
||||
0.000000000, 0.000000000, 1.000000000, 0.630929754, /* 0 1 2 3 */
|
||||
0.500000000, 0.430676558, 0.386852807, 0.356207187, /* 4 5 6 7 */
|
||||
0.333333333, 0.315464877, 0.301029996, 0.289064826, /* 8 9 10 11 */
|
||||
0.278942946, 0.270238154, 0.262649535, 0.255958025, /* 12 13 14 15 */
|
||||
0.250000000, 0.244650542, 0.239812467, 0.235408913, /* 16 17 18 19 */
|
||||
0.231378213, 0.227670249, 0.224243824, 0.221064729, /* 20 21 22 23 */
|
||||
0.218104292, 0.215338279, 0.212746054, 0.210309918, /* 24 25 26 27 */
|
||||
0.208014598, 0.205846832, 0.203795047, 0.201849087, /* 28 29 30 31 */
|
||||
0.200000000, 0.198239863, 0.196561632, 0.194959022, /* 32 33 34 35 */
|
||||
0.193426404, 0.191958720, 0.190551412, 0.189200360, /* 36 37 38 39 */
|
||||
0.187901825, 0.186652411, 0.185449023, 0.184288833, /* 40 41 42 43 */
|
||||
0.183169251, 0.182087900, 0.181042597, 0.180031327, /* 44 45 46 47 */
|
||||
0.179052232, 0.178103594, 0.177183820, 0.176291434, /* 48 49 50 51 */
|
||||
0.175425064, 0.174583430, 0.173765343, 0.172969690, /* 52 53 54 55 */
|
||||
0.172195434, 0.171441601, 0.170707280, 0.169991616, /* 56 57 58 59 */
|
||||
0.169293808, 0.168613099, 0.167948779, 0.167300179, /* 60 61 62 63 */
|
||||
0.166666667
|
||||
};
|
||||
@@ -1,85 +0,0 @@
|
||||
/* Default configuration for MPI library */
|
||||
|
||||
#ifndef MPI_CONFIG_H_
|
||||
#define MPI_CONFIG_H_
|
||||
|
||||
/*
|
||||
For boolean options,
|
||||
0 = no
|
||||
1 = yes
|
||||
|
||||
Other options are documented individually.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef MP_IOFUNC
|
||||
#define MP_IOFUNC 0 /* include mp_print() ? */
|
||||
#endif
|
||||
|
||||
#ifndef MP_MODARITH
|
||||
#define MP_MODARITH 1 /* include modular arithmetic ? */
|
||||
#endif
|
||||
|
||||
#ifndef MP_NUMTH
|
||||
#define MP_NUMTH 1 /* include number theoretic functions? */
|
||||
#endif
|
||||
|
||||
#ifndef MP_LOGTAB
|
||||
#define MP_LOGTAB 1 /* use table of logs instead of log()? */
|
||||
#endif
|
||||
|
||||
#ifndef MP_MEMSET
|
||||
#define MP_MEMSET 1 /* use memset() to zero buffers? */
|
||||
#endif
|
||||
|
||||
#ifndef MP_MEMCPY
|
||||
#define MP_MEMCPY 1 /* use memcpy() to copy buffers? */
|
||||
#endif
|
||||
|
||||
#ifndef MP_CRYPTO
|
||||
#define MP_CRYPTO 1 /* erase memory on free? */
|
||||
#endif
|
||||
|
||||
#ifndef MP_ARGCHK
|
||||
/*
|
||||
0 = no parameter checks
|
||||
1 = runtime checks, continue execution and return an error to caller
|
||||
2 = assertions; dump core on parameter errors
|
||||
*/
|
||||
#define MP_ARGCHK 2 /* how to check input arguments */
|
||||
#endif
|
||||
|
||||
#ifndef MP_DEBUG
|
||||
#define MP_DEBUG 0 /* print diagnostic output? */
|
||||
#endif
|
||||
|
||||
#ifndef MP_DEFPREC
|
||||
#define MP_DEFPREC 64 /* default precision, in digits */
|
||||
#endif
|
||||
|
||||
#ifndef MP_MACRO
|
||||
#define MP_MACRO 1 /* use macros for frequent calls? */
|
||||
#endif
|
||||
|
||||
#ifndef MP_SQUARE
|
||||
#define MP_SQUARE 1 /* use separate squaring code? */
|
||||
#endif
|
||||
|
||||
#ifndef MP_PTAB_SIZE
|
||||
/*
|
||||
When building mpprime.c, we build in a table of small prime
|
||||
values to use for primality testing. The more you include,
|
||||
the more space they take up. See primes.c for the possible
|
||||
values (currently 16, 32, 64, 128, 256, and 6542)
|
||||
*/
|
||||
#define MP_PTAB_SIZE 128 /* how many built-in primes? */
|
||||
#endif
|
||||
|
||||
#ifndef MP_COMPAT_MACROS
|
||||
#define MP_COMPAT_MACROS 1 /* define compatibility macros? */
|
||||
#endif
|
||||
|
||||
#endif /* ifndef MPI_CONFIG_H_ */
|
||||
|
||||
|
||||
/* crc==3287762869, version==2, Sat Feb 02 06:43:53 2002 */
|
||||
@@ -1,15 +0,0 @@
|
||||
/* Type definitions generated by 'types.pl' */
|
||||
typedef char mp_sign;
|
||||
typedef unsigned short mp_digit; /* 2 byte type */
|
||||
typedef unsigned int mp_word; /* 4 byte type */
|
||||
typedef unsigned int mp_size;
|
||||
typedef int mp_err;
|
||||
|
||||
#define MP_DIGIT_BIT (CHAR_BIT*sizeof(mp_digit))
|
||||
#define MP_DIGIT_MAX USHRT_MAX
|
||||
#define MP_WORD_BIT (CHAR_BIT*sizeof(mp_word))
|
||||
#define MP_WORD_MAX UINT_MAX
|
||||
|
||||
#define MP_DIGIT_SIZE 2
|
||||
#define DIGIT_FMT "%04X"
|
||||
#define RADIX (MP_DIGIT_MAX+1)
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,225 +0,0 @@
|
||||
/*
|
||||
mpi.h
|
||||
|
||||
by Michael J. Fromberger <sting@linguist.dartmouth.edu>
|
||||
Copyright (C) 1998 Michael J. Fromberger, All Rights Reserved
|
||||
|
||||
Arbitrary precision integer arithmetic library
|
||||
*/
|
||||
|
||||
#ifndef _H_MPI_
|
||||
#define _H_MPI_
|
||||
|
||||
#include "mpi-config.h"
|
||||
|
||||
#define MP_LT -1
|
||||
#define MP_EQ 0
|
||||
#define MP_GT 1
|
||||
|
||||
#if MP_DEBUG
|
||||
#undef MP_IOFUNC
|
||||
#define MP_IOFUNC 1
|
||||
#endif
|
||||
|
||||
#if MP_IOFUNC
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#define MP_NEG 1
|
||||
#define MP_ZPOS 0
|
||||
|
||||
/* Included for compatibility... */
|
||||
#define NEG MP_NEG
|
||||
#define ZPOS MP_ZPOS
|
||||
|
||||
#define MP_OKAY 0 /* no error, all is well */
|
||||
#define MP_YES 0 /* yes (boolean result) */
|
||||
#define MP_NO -1 /* no (boolean result) */
|
||||
#define MP_MEM -2 /* out of memory */
|
||||
#define MP_RANGE -3 /* argument out of range */
|
||||
#define MP_BADARG -4 /* invalid parameter */
|
||||
#define MP_UNDEF -5 /* answer is undefined */
|
||||
#define MP_LAST_CODE MP_UNDEF
|
||||
|
||||
#include "mpi-types.h"
|
||||
|
||||
/* Included for compatibility... */
|
||||
#define DIGIT_BIT MP_DIGIT_BIT
|
||||
#define DIGIT_MAX MP_DIGIT_MAX
|
||||
|
||||
/* Macros for accessing the mp_int internals */
|
||||
#define SIGN(MP) ((MP)->sign)
|
||||
#define USED(MP) ((MP)->used)
|
||||
#define ALLOC(MP) ((MP)->alloc)
|
||||
#define DIGITS(MP) ((MP)->dp)
|
||||
#define DIGIT(MP,N) (MP)->dp[(N)]
|
||||
|
||||
#if MP_ARGCHK == 1
|
||||
#define ARGCHK(X,Y) {if(!(X)){return (Y);}}
|
||||
#elif MP_ARGCHK == 2
|
||||
#include <assert.h>
|
||||
#define ARGCHK(X,Y) assert(X)
|
||||
#else
|
||||
#define ARGCHK(X,Y) /* */
|
||||
#endif
|
||||
|
||||
/* This defines the maximum I/O base (minimum is 2) */
|
||||
#define MAX_RADIX 64
|
||||
|
||||
typedef struct {
|
||||
mp_sign sign; /* sign of this quantity */
|
||||
mp_size alloc; /* how many digits allocated */
|
||||
mp_size used; /* how many digits used */
|
||||
mp_digit *dp; /* the digits themselves */
|
||||
} mp_int;
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Default precision */
|
||||
|
||||
unsigned int mp_get_prec(void);
|
||||
void mp_set_prec(unsigned int prec);
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Memory management */
|
||||
|
||||
mp_err mp_init(mp_int *mp);
|
||||
mp_err mp_init_array(mp_int mp[], int count);
|
||||
mp_err mp_init_size(mp_int *mp, mp_size prec);
|
||||
mp_err mp_init_copy(mp_int *mp, mp_int *from);
|
||||
mp_err mp_copy(mp_int *from, mp_int *to);
|
||||
void mp_exch(mp_int *mp1, mp_int *mp2);
|
||||
void mp_clear(mp_int *mp);
|
||||
void mp_clear_array(mp_int mp[], int count);
|
||||
void mp_zero(mp_int *mp);
|
||||
void mp_set(mp_int *mp, mp_digit d);
|
||||
mp_err mp_set_int(mp_int *mp, long z);
|
||||
mp_err mp_shrink(mp_int *a);
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Single digit arithmetic */
|
||||
|
||||
mp_err mp_add_d(mp_int *a, mp_digit d, mp_int *b);
|
||||
mp_err mp_sub_d(mp_int *a, mp_digit d, mp_int *b);
|
||||
mp_err mp_mul_d(mp_int *a, mp_digit d, mp_int *b);
|
||||
mp_err mp_mul_2(mp_int *a, mp_int *c);
|
||||
mp_err mp_div_d(mp_int *a, mp_digit d, mp_int *q, mp_digit *r);
|
||||
mp_err mp_div_2(mp_int *a, mp_int *c);
|
||||
mp_err mp_expt_d(mp_int *a, mp_digit d, mp_int *c);
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Sign manipulations */
|
||||
|
||||
mp_err mp_abs(mp_int *a, mp_int *b);
|
||||
mp_err mp_neg(mp_int *a, mp_int *b);
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Full arithmetic */
|
||||
|
||||
mp_err mp_add(mp_int *a, mp_int *b, mp_int *c);
|
||||
mp_err mp_sub(mp_int *a, mp_int *b, mp_int *c);
|
||||
mp_err mp_mul(mp_int *a, mp_int *b, mp_int *c);
|
||||
mp_err mp_mul_2d(mp_int *a, mp_digit d, mp_int *c);
|
||||
#if MP_SQUARE
|
||||
mp_err mp_sqr(mp_int *a, mp_int *b);
|
||||
#else
|
||||
#define mp_sqr(a, b) mp_mul(a, a, b)
|
||||
#endif
|
||||
mp_err mp_div(mp_int *a, mp_int *b, mp_int *q, mp_int *r);
|
||||
mp_err mp_div_2d(mp_int *a, mp_digit d, mp_int *q, mp_int *r);
|
||||
mp_err mp_expt(mp_int *a, mp_int *b, mp_int *c);
|
||||
mp_err mp_2expt(mp_int *a, mp_digit k);
|
||||
mp_err mp_sqrt(mp_int *a, mp_int *b);
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Modular arithmetic */
|
||||
|
||||
#if MP_MODARITH
|
||||
mp_err mp_mod(mp_int *a, mp_int *m, mp_int *c);
|
||||
mp_err mp_mod_d(mp_int *a, mp_digit d, mp_digit *c);
|
||||
mp_err mp_addmod(mp_int *a, mp_int *b, mp_int *m, mp_int *c);
|
||||
mp_err mp_submod(mp_int *a, mp_int *b, mp_int *m, mp_int *c);
|
||||
mp_err mp_mulmod(mp_int *a, mp_int *b, mp_int *m, mp_int *c);
|
||||
#if MP_SQUARE
|
||||
mp_err mp_sqrmod(mp_int *a, mp_int *m, mp_int *c);
|
||||
#else
|
||||
#define mp_sqrmod(a, m, c) mp_mulmod(a, a, m, c)
|
||||
#endif
|
||||
mp_err mp_exptmod(mp_int *a, mp_int *b, mp_int *m, mp_int *c);
|
||||
mp_err mp_exptmod_d(mp_int *a, mp_digit d, mp_int *m, mp_int *c);
|
||||
#endif /* MP_MODARITH */
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Comparisons */
|
||||
|
||||
int mp_cmp_z(mp_int *a);
|
||||
int mp_cmp_d(mp_int *a, mp_digit d);
|
||||
int mp_cmp(mp_int *a, mp_int *b);
|
||||
int mp_cmp_mag(mp_int *a, mp_int *b);
|
||||
int mp_cmp_int(mp_int *a, long z);
|
||||
int mp_isodd(mp_int *a);
|
||||
int mp_iseven(mp_int *a);
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Number theoretic */
|
||||
|
||||
#if MP_NUMTH
|
||||
mp_err mp_gcd(mp_int *a, mp_int *b, mp_int *c);
|
||||
mp_err mp_lcm(mp_int *a, mp_int *b, mp_int *c);
|
||||
mp_err mp_xgcd(mp_int *a, mp_int *b, mp_int *g, mp_int *x, mp_int *y);
|
||||
mp_err mp_invmod(mp_int *a, mp_int *m, mp_int *c);
|
||||
#endif /* end MP_NUMTH */
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Input and output */
|
||||
|
||||
#if MP_IOFUNC
|
||||
void mp_print(mp_int *mp, FILE *ofp);
|
||||
#endif /* end MP_IOFUNC */
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Base conversion */
|
||||
|
||||
#define BITS 1
|
||||
#define BYTES CHAR_BIT
|
||||
|
||||
mp_err mp_read_signed_bin(mp_int *mp, unsigned char *str, int len);
|
||||
int mp_signed_bin_size(mp_int *mp);
|
||||
mp_err mp_to_signed_bin(mp_int *mp, unsigned char *str);
|
||||
|
||||
mp_err mp_read_unsigned_bin(mp_int *mp, unsigned char *str, int len);
|
||||
int mp_unsigned_bin_size(mp_int *mp);
|
||||
mp_err mp_to_unsigned_bin(mp_int *mp, unsigned char *str);
|
||||
|
||||
int mp_count_bits(mp_int *mp);
|
||||
|
||||
#if MP_COMPAT_MACROS
|
||||
#define mp_read_raw(mp, str, len) mp_read_signed_bin((mp), (str), (len))
|
||||
#define mp_raw_size(mp) mp_signed_bin_size(mp)
|
||||
#define mp_toraw(mp, str) mp_to_signed_bin((mp), (str))
|
||||
#define mp_read_mag(mp, str, len) mp_read_unsigned_bin((mp), (str), (len))
|
||||
#define mp_mag_size(mp) mp_unsigned_bin_size(mp)
|
||||
#define mp_tomag(mp, str) mp_to_unsigned_bin((mp), (str))
|
||||
#endif
|
||||
|
||||
mp_err mp_read_radix(mp_int *mp, unsigned char *str, int radix);
|
||||
int mp_radix_size(mp_int *mp, int radix);
|
||||
int mp_value_radix_size(int num, int qty, int radix);
|
||||
mp_err mp_toradix(mp_int *mp, unsigned char *str, int radix);
|
||||
|
||||
int mp_char2value(char ch, int r);
|
||||
|
||||
#define mp_tobinary(M, S) mp_toradix((M), (S), 2)
|
||||
#define mp_tooctal(M, S) mp_toradix((M), (S), 8)
|
||||
#define mp_todecimal(M, S) mp_toradix((M), (S), 10)
|
||||
#define mp_tohex(M, S) mp_toradix((M), (S), 16)
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Error strings */
|
||||
|
||||
const char *mp_strerror(mp_err ec);
|
||||
|
||||
#endif /* end _H_MPI_ */
|
||||
@@ -1,304 +0,0 @@
|
||||
/* makes a bignum test harness with NUM tests per operation
|
||||
*
|
||||
* the output is made in the following format [one parameter per line]
|
||||
|
||||
operation
|
||||
operand1
|
||||
operand2
|
||||
[... operandN]
|
||||
result1
|
||||
result2
|
||||
[... resultN]
|
||||
|
||||
So for example "a * b mod n" would be
|
||||
|
||||
mulmod
|
||||
a
|
||||
b
|
||||
n
|
||||
a*b mod n
|
||||
|
||||
e.g. if a=3, b=4 n=11 then
|
||||
|
||||
mulmod
|
||||
3
|
||||
4
|
||||
11
|
||||
1
|
||||
|
||||
*/
|
||||
|
||||
#ifdef MP_8BIT
|
||||
#define THE_MASK 127
|
||||
#else
|
||||
#define THE_MASK 32767
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include "mpi.c"
|
||||
|
||||
FILE *rng;
|
||||
|
||||
void rand_num(mp_int *a)
|
||||
{
|
||||
int n, size;
|
||||
unsigned char buf[2048];
|
||||
|
||||
size = 1 + ((fgetc(rng)<<8) + fgetc(rng)) % 101;
|
||||
buf[0] = (fgetc(rng)&1)?1:0;
|
||||
fread(buf+1, 1, size, rng);
|
||||
while (buf[1] == 0) buf[1] = fgetc(rng);
|
||||
mp_read_raw(a, buf, 1+size);
|
||||
}
|
||||
|
||||
void rand_num2(mp_int *a)
|
||||
{
|
||||
int n, size;
|
||||
unsigned char buf[2048];
|
||||
|
||||
size = 10 + ((fgetc(rng)<<8) + fgetc(rng)) % 101;
|
||||
buf[0] = (fgetc(rng)&1)?1:0;
|
||||
fread(buf+1, 1, size, rng);
|
||||
while (buf[1] == 0) buf[1] = fgetc(rng);
|
||||
mp_read_raw(a, buf, 1+size);
|
||||
}
|
||||
|
||||
#define mp_to64(a, b) mp_toradix(a, b, 64)
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int n, tmp;
|
||||
mp_int a, b, c, d, e;
|
||||
clock_t t1;
|
||||
char buf[4096];
|
||||
|
||||
mp_init(&a);
|
||||
mp_init(&b);
|
||||
mp_init(&c);
|
||||
mp_init(&d);
|
||||
mp_init(&e);
|
||||
|
||||
|
||||
/* initial (2^n - 1)^2 testing, makes sure the comba multiplier works [it has the new carry code] */
|
||||
/*
|
||||
mp_set(&a, 1);
|
||||
for (n = 1; n < 8192; n++) {
|
||||
mp_mul(&a, &a, &c);
|
||||
printf("mul\n");
|
||||
mp_to64(&a, buf);
|
||||
printf("%s\n%s\n", buf, buf);
|
||||
mp_to64(&c, buf);
|
||||
printf("%s\n", buf);
|
||||
|
||||
mp_add_d(&a, 1, &a);
|
||||
mp_mul_2(&a, &a);
|
||||
mp_sub_d(&a, 1, &a);
|
||||
}
|
||||
*/
|
||||
|
||||
rng = fopen("/dev/urandom", "rb");
|
||||
if (rng == NULL) {
|
||||
rng = fopen("/dev/random", "rb");
|
||||
if (rng == NULL) {
|
||||
fprintf(stderr, "\nWarning: stdin used as random source\n\n");
|
||||
rng = stdin;
|
||||
}
|
||||
}
|
||||
|
||||
t1 = clock();
|
||||
for (;;) {
|
||||
#if 0
|
||||
if (clock() - t1 > CLOCKS_PER_SEC) {
|
||||
sleep(2);
|
||||
t1 = clock();
|
||||
}
|
||||
#endif
|
||||
n = fgetc(rng) % 15;
|
||||
|
||||
if (n == 0) {
|
||||
/* add tests */
|
||||
rand_num(&a);
|
||||
rand_num(&b);
|
||||
mp_add(&a, &b, &c);
|
||||
printf("add\n");
|
||||
mp_to64(&a, buf);
|
||||
printf("%s\n", buf);
|
||||
mp_to64(&b, buf);
|
||||
printf("%s\n", buf);
|
||||
mp_to64(&c, buf);
|
||||
printf("%s\n", buf);
|
||||
} else if (n == 1) {
|
||||
/* sub tests */
|
||||
rand_num(&a);
|
||||
rand_num(&b);
|
||||
mp_sub(&a, &b, &c);
|
||||
printf("sub\n");
|
||||
mp_to64(&a, buf);
|
||||
printf("%s\n", buf);
|
||||
mp_to64(&b, buf);
|
||||
printf("%s\n", buf);
|
||||
mp_to64(&c, buf);
|
||||
printf("%s\n", buf);
|
||||
} else if (n == 2) {
|
||||
/* mul tests */
|
||||
rand_num(&a);
|
||||
rand_num(&b);
|
||||
mp_mul(&a, &b, &c);
|
||||
printf("mul\n");
|
||||
mp_to64(&a, buf);
|
||||
printf("%s\n", buf);
|
||||
mp_to64(&b, buf);
|
||||
printf("%s\n", buf);
|
||||
mp_to64(&c, buf);
|
||||
printf("%s\n", buf);
|
||||
} else if (n == 3) {
|
||||
/* div tests */
|
||||
rand_num(&a);
|
||||
rand_num(&b);
|
||||
mp_div(&a, &b, &c, &d);
|
||||
printf("div\n");
|
||||
mp_to64(&a, buf);
|
||||
printf("%s\n", buf);
|
||||
mp_to64(&b, buf);
|
||||
printf("%s\n", buf);
|
||||
mp_to64(&c, buf);
|
||||
printf("%s\n", buf);
|
||||
mp_to64(&d, buf);
|
||||
printf("%s\n", buf);
|
||||
} else if (n == 4) {
|
||||
/* sqr tests */
|
||||
rand_num(&a);
|
||||
mp_sqr(&a, &b);
|
||||
printf("sqr\n");
|
||||
mp_to64(&a, buf);
|
||||
printf("%s\n", buf);
|
||||
mp_to64(&b, buf);
|
||||
printf("%s\n", buf);
|
||||
} else if (n == 5) {
|
||||
/* mul_2d test */
|
||||
rand_num(&a);
|
||||
mp_copy(&a, &b);
|
||||
n = fgetc(rng) & 63;
|
||||
mp_mul_2d(&b, n, &b);
|
||||
mp_to64(&a, buf);
|
||||
printf("mul2d\n");
|
||||
printf("%s\n", buf);
|
||||
printf("%d\n", n);
|
||||
mp_to64(&b, buf);
|
||||
printf("%s\n", buf);
|
||||
} else if (n == 6) {
|
||||
/* div_2d test */
|
||||
rand_num(&a);
|
||||
mp_copy(&a, &b);
|
||||
n = fgetc(rng) & 63;
|
||||
mp_div_2d(&b, n, &b, NULL);
|
||||
mp_to64(&a, buf);
|
||||
printf("div2d\n");
|
||||
printf("%s\n", buf);
|
||||
printf("%d\n", n);
|
||||
mp_to64(&b, buf);
|
||||
printf("%s\n", buf);
|
||||
} else if (n == 7) {
|
||||
/* gcd test */
|
||||
rand_num(&a);
|
||||
rand_num(&b);
|
||||
a.sign = MP_ZPOS;
|
||||
b.sign = MP_ZPOS;
|
||||
mp_gcd(&a, &b, &c);
|
||||
printf("gcd\n");
|
||||
mp_to64(&a, buf);
|
||||
printf("%s\n", buf);
|
||||
mp_to64(&b, buf);
|
||||
printf("%s\n", buf);
|
||||
mp_to64(&c, buf);
|
||||
printf("%s\n", buf);
|
||||
} else if (n == 8) {
|
||||
/* lcm test */
|
||||
rand_num(&a);
|
||||
rand_num(&b);
|
||||
a.sign = MP_ZPOS;
|
||||
b.sign = MP_ZPOS;
|
||||
mp_lcm(&a, &b, &c);
|
||||
printf("lcm\n");
|
||||
mp_to64(&a, buf);
|
||||
printf("%s\n", buf);
|
||||
mp_to64(&b, buf);
|
||||
printf("%s\n", buf);
|
||||
mp_to64(&c, buf);
|
||||
printf("%s\n", buf);
|
||||
} else if (n == 9) {
|
||||
/* exptmod test */
|
||||
rand_num2(&a);
|
||||
rand_num2(&b);
|
||||
rand_num2(&c);
|
||||
// if (c.dp[0]&1) mp_add_d(&c, 1, &c);
|
||||
a.sign = b.sign = c.sign = 0;
|
||||
mp_exptmod(&a, &b, &c, &d);
|
||||
printf("expt\n");
|
||||
mp_to64(&a, buf);
|
||||
printf("%s\n", buf);
|
||||
mp_to64(&b, buf);
|
||||
printf("%s\n", buf);
|
||||
mp_to64(&c, buf);
|
||||
printf("%s\n", buf);
|
||||
mp_to64(&d, buf);
|
||||
printf("%s\n", buf);
|
||||
} else if (n == 10) {
|
||||
/* invmod test */
|
||||
rand_num2(&a);
|
||||
rand_num2(&b);
|
||||
b.sign = MP_ZPOS;
|
||||
a.sign = MP_ZPOS;
|
||||
mp_gcd(&a, &b, &c);
|
||||
if (mp_cmp_d(&c, 1) != 0) continue;
|
||||
if (mp_cmp_d(&b, 1) == 0) continue;
|
||||
mp_invmod(&a, &b, &c);
|
||||
printf("invmod\n");
|
||||
mp_to64(&a, buf);
|
||||
printf("%s\n", buf);
|
||||
mp_to64(&b, buf);
|
||||
printf("%s\n", buf);
|
||||
mp_to64(&c, buf);
|
||||
printf("%s\n", buf);
|
||||
} else if (n == 11) {
|
||||
rand_num(&a);
|
||||
mp_mul_2(&a, &a);
|
||||
mp_div_2(&a, &b);
|
||||
printf("div2\n");
|
||||
mp_to64(&a, buf);
|
||||
printf("%s\n", buf);
|
||||
mp_to64(&b, buf);
|
||||
printf("%s\n", buf);
|
||||
} else if (n == 12) {
|
||||
rand_num2(&a);
|
||||
mp_mul_2(&a, &b);
|
||||
printf("mul2\n");
|
||||
mp_to64(&a, buf);
|
||||
printf("%s\n", buf);
|
||||
mp_to64(&b, buf);
|
||||
printf("%s\n", buf);
|
||||
} else if (n == 13) {
|
||||
rand_num2(&a);
|
||||
tmp = abs(rand()) & THE_MASK;
|
||||
mp_add_d(&a, tmp, &b);
|
||||
printf("add_d\n");
|
||||
mp_to64(&a, buf);
|
||||
printf("%s\n%d\n", buf, tmp);
|
||||
mp_to64(&b, buf);
|
||||
printf("%s\n", buf);
|
||||
} else if (n == 14) {
|
||||
rand_num2(&a);
|
||||
tmp = abs(rand()) & THE_MASK;
|
||||
mp_sub_d(&a, tmp, &b);
|
||||
printf("sub_d\n");
|
||||
mp_to64(&a, buf);
|
||||
printf("%s\n%d\n", buf, tmp);
|
||||
mp_to64(&b, buf);
|
||||
printf("%s\n", buf);
|
||||
}
|
||||
}
|
||||
fclose(rng);
|
||||
return 0;
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,35 +0,0 @@
|
||||
# makes the images... yeah
|
||||
|
||||
default: pses
|
||||
|
||||
design_process.ps: design_process.tif
|
||||
tiff2ps -s -e design_process.tif > design_process.ps
|
||||
|
||||
sliding_window.ps: sliding_window.tif
|
||||
tiff2ps -s -e sliding_window.tif > sliding_window.ps
|
||||
|
||||
expt_state.ps: expt_state.tif
|
||||
tiff2ps -s -e expt_state.tif > expt_state.ps
|
||||
|
||||
primality.ps: primality.tif
|
||||
tiff2ps -s -e primality.tif > primality.ps
|
||||
|
||||
design_process.pdf: design_process.ps
|
||||
epstopdf design_process.ps
|
||||
|
||||
sliding_window.pdf: sliding_window.ps
|
||||
epstopdf sliding_window.ps
|
||||
|
||||
expt_state.pdf: expt_state.ps
|
||||
epstopdf expt_state.ps
|
||||
|
||||
primality.pdf: primality.ps
|
||||
epstopdf primality.ps
|
||||
|
||||
|
||||
pses: sliding_window.ps expt_state.ps primality.ps design_process.ps
|
||||
pdfes: sliding_window.pdf expt_state.pdf primality.pdf design_process.pdf
|
||||
|
||||
clean:
|
||||
rm -rf *.ps *.pdf .xvpics
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,35 +0,0 @@
|
||||
\documentclass[landscape,11pt]{article}
|
||||
\usepackage{amsmath, amssymb}
|
||||
\usepackage{hyperref}
|
||||
\begin{document}
|
||||
\hspace*{-3in}
|
||||
\begin{tabular}{llllll}
|
||||
$c = a + b$ & {\tt mp\_add(\&a, \&b, \&c)} & $b = 2a$ & {\tt mp\_mul\_2(\&a, \&b)} & \\
|
||||
$c = a - b$ & {\tt mp\_sub(\&a, \&b, \&c)} & $b = a/2$ & {\tt mp\_div\_2(\&a, \&b)} & \\
|
||||
$c = ab $ & {\tt mp\_mul(\&a, \&b, \&c)} & $c = 2^ba$ & {\tt mp\_mul\_2d(\&a, b, \&c)} \\
|
||||
$b = a^2 $ & {\tt mp\_sqr(\&a, \&b)} & $c = a/2^b, d = a \mod 2^b$ & {\tt mp\_div\_2d(\&a, b, \&c, \&d)} \\
|
||||
$c = \lfloor a/b \rfloor, d = a \mod b$ & {\tt mp\_div(\&a, \&b, \&c, \&d)} & $c = a \mod 2^b $ & {\tt mp\_mod\_2d(\&a, b, \&c)} \\
|
||||
&& \\
|
||||
$a = b $ & {\tt mp\_set\_int(\&a, b)} & $c = a \vee b$ & {\tt mp\_or(\&a, \&b, \&c)} \\
|
||||
$b = a $ & {\tt mp\_copy(\&a, \&b)} & $c = a \wedge b$ & {\tt mp\_and(\&a, \&b, \&c)} \\
|
||||
&& $c = a \oplus b$ & {\tt mp\_xor(\&a, \&b, \&c)} \\
|
||||
& \\
|
||||
$b = -a $ & {\tt mp\_neg(\&a, \&b)} & $d = a + b \mod c$ & {\tt mp\_addmod(\&a, \&b, \&c, \&d)} \\
|
||||
$b = |a| $ & {\tt mp\_abs(\&a, \&b)} & $d = a - b \mod c$ & {\tt mp\_submod(\&a, \&b, \&c, \&d)} \\
|
||||
&& $d = ab \mod c$ & {\tt mp\_mulmod(\&a, \&b, \&c, \&d)} \\
|
||||
Compare $a$ and $b$ & {\tt mp\_cmp(\&a, \&b)} & $c = a^2 \mod b$ & {\tt mp\_sqrmod(\&a, \&b, \&c)} \\
|
||||
Is Zero? & {\tt mp\_iszero(\&a)} & $c = a^{-1} \mod b$ & {\tt mp\_invmod(\&a, \&b, \&c)} \\
|
||||
Is Even? & {\tt mp\_iseven(\&a)} & $d = a^b \mod c$ & {\tt mp\_exptmod(\&a, \&b, \&c, \&d)} \\
|
||||
Is Odd ? & {\tt mp\_isodd(\&a)} \\
|
||||
&\\
|
||||
$\vert \vert a \vert \vert$ & {\tt mp\_unsigned\_bin\_size(\&a)} & $res$ = 1 if $a$ prime to $t$ rounds? & {\tt mp\_prime\_is\_prime(\&a, t, \&res)} \\
|
||||
$buf \leftarrow a$ & {\tt mp\_to\_unsigned\_bin(\&a, buf)} & Next prime after $a$ to $t$ rounds. & {\tt mp\_prime\_next\_prime(\&a, t, bbs\_style)} \\
|
||||
$a \leftarrow buf[0..len-1]$ & {\tt mp\_read\_unsigned\_bin(\&a, buf, len)} \\
|
||||
&\\
|
||||
$b = \sqrt{a}$ & {\tt mp\_sqrt(\&a, \&b)} & $c = \mbox{gcd}(a, b)$ & {\tt mp\_gcd(\&a, \&b, \&c)} \\
|
||||
$c = a^{1/b}$ & {\tt mp\_n\_root(\&a, b, \&c)} & $c = \mbox{lcm}(a, b)$ & {\tt mp\_lcm(\&a, \&b, \&c)} \\
|
||||
&\\
|
||||
Greater Than & MP\_GT & Equal To & MP\_EQ \\
|
||||
Less Than & MP\_LT & Bits per digit & DIGIT\_BIT \\
|
||||
\end{tabular}
|
||||
\end{document}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,66 +0,0 @@
|
||||
#!/bin/perl -w
|
||||
#
|
||||
# Cute little builder for perl
|
||||
# Total waste of development time...
|
||||
#
|
||||
# This will build all the object files and then the archive .a file
|
||||
# requires GCC, GNU make and a sense of humour.
|
||||
#
|
||||
# Tom St Denis
|
||||
use strict;
|
||||
|
||||
my $count = 0;
|
||||
my $starttime = time;
|
||||
my $rate = 0;
|
||||
print "Scanning for source files...\n";
|
||||
foreach my $filename (glob "*.c") {
|
||||
++$count;
|
||||
}
|
||||
print "Source files to build: $count\nBuilding...\n";
|
||||
my $i = 0;
|
||||
my $lines = 0;
|
||||
my $filesbuilt = 0;
|
||||
foreach my $filename (glob "*.c") {
|
||||
printf("Building %3.2f%%, ", (++$i/$count)*100.0);
|
||||
if ($i % 4 == 0) { print "/, "; }
|
||||
if ($i % 4 == 1) { print "-, "; }
|
||||
if ($i % 4 == 2) { print "\\, "; }
|
||||
if ($i % 4 == 3) { print "|, "; }
|
||||
if ($rate > 0) {
|
||||
my $tleft = ($count - $i) / $rate;
|
||||
my $tsec = $tleft%60;
|
||||
my $tmin = ($tleft/60)%60;
|
||||
my $thour = ($tleft/3600)%60;
|
||||
printf("%2d:%02d:%02d left, ", $thour, $tmin, $tsec);
|
||||
}
|
||||
my $cnt = ($i/$count)*30.0;
|
||||
my $x = 0;
|
||||
print "[";
|
||||
for (; $x < $cnt; $x++) { print "#"; }
|
||||
for (; $x < 30; $x++) { print " "; }
|
||||
print "]\r";
|
||||
my $tmp = $filename;
|
||||
$tmp =~ s/\.c/".o"/ge;
|
||||
if (open(SRC, "<$tmp")) {
|
||||
close SRC;
|
||||
} else {
|
||||
!system("make $tmp > /dev/null 2>/dev/null") or die "\nERROR: Failed to make $tmp!!!\n";
|
||||
open( SRC, "<$filename" ) or die "Couldn't open $filename for reading: $!";
|
||||
++$lines while (<SRC>);
|
||||
close SRC or die "Error closing $filename after reading: $!";
|
||||
++$filesbuilt;
|
||||
}
|
||||
|
||||
# update timer
|
||||
if (time != $starttime) {
|
||||
my $delay = time - $starttime;
|
||||
$rate = $i/$delay;
|
||||
}
|
||||
}
|
||||
|
||||
# finish building the library
|
||||
printf("\nFinished building source (%d seconds, %3.2f files per second).\n", time - $starttime, $rate);
|
||||
print "Compiled approximately $filesbuilt files and $lines lines of code.\n";
|
||||
print "Doing final make (building archive...)\n";
|
||||
!system("make > /dev/null 2>/dev/null") or die "\nERROR: Failed to perform last make command!!!\n";
|
||||
print "done.\n";
|
||||
@@ -1,35 +0,0 @@
|
||||
program := program statement | statement | empty
|
||||
statement := { statement } |
|
||||
identifier = numexpression; |
|
||||
identifier[numexpression] = numexpression; |
|
||||
function(expressionlist); |
|
||||
for (identifer = numexpression; numexpression; identifier = numexpression) { statement } |
|
||||
while (numexpression) { statement } |
|
||||
if (numexpresion) { statement } elif |
|
||||
break; |
|
||||
continue;
|
||||
|
||||
elif := else statement | empty
|
||||
function := abs | countbits | exptmod | jacobi | print | isprime | nextprime | issquare | readinteger | exit
|
||||
expressionlist := expressionlist, expression | expression
|
||||
|
||||
// LR(1) !!!?
|
||||
expression := string | numexpression
|
||||
numexpression := cmpexpr && cmpexpr | cmpexpr \|\| cmpexpr | cmpexpr
|
||||
cmpexpr := boolexpr < boolexpr | boolexpr > boolexpr | boolexpr == boolexpr |
|
||||
boolexpr <= boolexpr | boolexpr >= boolexpr | boolexpr
|
||||
boolexpr := shiftexpr & shiftexpr | shiftexpr ^ shiftexpr | shiftexpr \| shiftexpr | shiftexpr
|
||||
shiftexpr := addsubexpr << addsubexpr | addsubexpr >> addsubexpr | addsubexpr
|
||||
addsubexpr := mulexpr + mulexpr | mulexpr - mulexpr | mulexpr
|
||||
mulexpr := expr * expr | expr / expr | expr % expr | expr
|
||||
expr := -nexpr | nexpr
|
||||
nexpr := integer | identifier | ( numexpression ) | identifier[numexpression]
|
||||
|
||||
identifier := identifer digits | identifier alpha | alpha
|
||||
alpha := a ... z | A ... Z
|
||||
integer := hexnumber | digits
|
||||
hexnumber := 0xhexdigits
|
||||
hexdigits := hexdigits hexdigit | hexdigit
|
||||
hexdigit := 0 ... 9 | a ... f | A ... F
|
||||
digits := digits digit | digit
|
||||
digit := 0 ... 9
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user