Compare commits
143
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1b6526afd2 | ||
|
|
d48b9f7839 | ||
|
|
f19d3d1f63 | ||
|
|
c26994f746 | ||
|
|
e722bb7121 | ||
|
|
8afc392129 | ||
|
|
c53c54cec4 | ||
|
|
cf11c42355 | ||
|
|
5997f60c9a | ||
|
|
bab811ce01 | ||
|
|
12a2241641 | ||
|
|
88e67d27d8 | ||
|
|
e404d07959 | ||
|
|
b99314020d | ||
|
|
e00ef49560 | ||
|
|
4a0d55e4c9 | ||
|
|
bb1eeada78 | ||
|
|
b350e6ad91 | ||
|
|
434361c3c6 | ||
|
|
05b4cb2080 | ||
|
|
b098fb3279 | ||
|
|
f00d9f9d02 | ||
|
|
3707688157 | ||
|
|
2ab36cc28a | ||
|
|
ed907ec2d1 | ||
|
|
db160493de | ||
|
|
d3315530e8 | ||
|
|
3181ee9123 | ||
|
|
de04d595fa | ||
|
|
589c6b9de8 | ||
|
|
e85c33074d | ||
|
|
c1f8c02900 | ||
|
|
65946d3f86 | ||
|
|
09776ae196 | ||
|
|
208e4fd87b | ||
|
|
bdf8f9cc31 | ||
|
|
41cd7b2754 | ||
|
|
ae33d6bbf6 | ||
|
|
f8d95ed6e3 | ||
|
|
25091201d6 | ||
|
|
bbbc406887 | ||
|
|
0db44b0516 | ||
|
|
8bc7833ed3 | ||
|
|
0125995766 | ||
|
|
92be9569b8 | ||
|
|
939e6b3a1a | ||
|
|
4ba2b4fbdf | ||
|
|
84ba09182d | ||
|
|
757964d7fa | ||
|
|
0f43a76273 | ||
|
|
e52ace05d3 | ||
|
|
f594ed900c | ||
|
|
00a23c159d | ||
|
|
047122995d | ||
|
|
7b7cb95a11 | ||
|
|
4bcbf9fc65 | ||
|
|
4f6ff8445f | ||
|
|
507395df2c | ||
|
|
6926f5bdc9 | ||
|
|
c5aa761ded | ||
|
|
71c3d83e9d | ||
|
|
d31b63df9c | ||
|
|
6ca9f62bb5 | ||
|
|
0d122fd177 | ||
|
|
1d042a78a8 | ||
|
|
94ef14f2fe | ||
|
|
5837fdc42c | ||
|
|
07f720d567 | ||
|
|
a1e06f4b0a | ||
|
|
d6513e05a7 | ||
|
|
2df6f12a99 | ||
|
|
481c3a3fd5 | ||
|
|
03475f0648 | ||
|
|
13e2682646 | ||
|
|
539ae1750f | ||
|
|
5de6de238c | ||
|
|
18c563f161 | ||
|
|
2922b99f62 | ||
|
|
9943a8a579 | ||
|
|
783d209ab7 | ||
|
|
fe24e890ab | ||
|
|
414826083b | ||
|
|
c2a49a6f27 | ||
|
|
49c58637ba | ||
|
|
b03d00e307 | ||
|
|
9ac86b7c6c | ||
|
|
601e71d7fc | ||
|
|
4da52405ca | ||
|
|
12c8a0c839 | ||
|
|
6c9ba2c3e1 | ||
|
|
f58aaebc26 | ||
|
|
e70b0460ea | ||
|
|
357548f682 | ||
|
|
6893ec40c9 | ||
|
|
6dd152f040 | ||
|
|
6e9d74fa78 | ||
|
|
c9d50be3b9 | ||
|
|
62cba4649f | ||
|
|
d7304e379d | ||
|
|
fafaee2a19 | ||
|
|
ddbba194c5 | ||
|
|
4edaedf1b0 | ||
|
|
2e674796fc | ||
|
|
180d5e31c9 | ||
|
|
16a6b9c3c1 | ||
|
|
1e29c4f4ad | ||
|
|
dd3033a0ce | ||
|
|
92816a0c35 | ||
|
|
1b0be70377 | ||
|
|
aaa0152aeb | ||
|
|
dc81b2efaf | ||
|
|
f512f6d8d5 | ||
|
|
f96662305e | ||
|
|
2b53ba06dc | ||
|
|
c3d5218595 | ||
|
|
379c5166ff | ||
|
|
9fd52465aa | ||
|
|
71342a5742 | ||
|
|
791a16b48e | ||
|
|
df6c6b5747 | ||
|
|
9b14adeeea | ||
|
|
adee2e475d | ||
|
|
e5c5cd920b | ||
|
|
1cb1fee6ed | ||
|
|
c5da22ebff | ||
|
|
fbf9737123 | ||
|
|
c7329913d9 | ||
|
|
42dff1d622 | ||
|
|
508e022fa9 | ||
|
|
459aa94020 | ||
|
|
93c913d132 | ||
|
|
722cda78a9 | ||
|
|
e06dc8eb8d | ||
|
|
3f2b427970 | ||
|
|
ce1a0a923b | ||
|
|
65e3c9b74d | ||
|
|
8884cc7dae | ||
|
|
bd858e0017 | ||
|
|
c3c72d902f | ||
|
|
15e17d01d5 | ||
|
|
db7fa65dce | ||
|
|
505f963287 | ||
|
|
233d558b1e |
@@ -3,7 +3,9 @@
|
||||
*.dylib
|
||||
*.exe
|
||||
*.exp
|
||||
*.la
|
||||
*.lib
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
*.pdb
|
||||
@@ -19,6 +21,8 @@
|
||||
*/tcltest*
|
||||
*/versions.vc
|
||||
*/version.vc
|
||||
*/libtcl.vfs
|
||||
*/libtcl_*.zip
|
||||
html
|
||||
libtommath/bn.ilg
|
||||
libtommath/bn.ind
|
||||
@@ -26,7 +30,7 @@ libtommath/pretty.build
|
||||
libtommath/tommath.src
|
||||
libtommath/*.log
|
||||
libtommath/*.pdf
|
||||
libtommath/*.pl
|
||||
libtommath/gen.pl
|
||||
libtommath/*.sh
|
||||
libtommath/doc/*
|
||||
libtommath/tombc/*
|
||||
@@ -45,6 +49,8 @@ unix/tclIndex
|
||||
unix/pkgs/*
|
||||
win/Debug*
|
||||
win/Release*
|
||||
win/*.manifest
|
||||
win/pkgs/*
|
||||
win/coffbase.txt
|
||||
win/tcl.hpj
|
||||
win/nmhlp-out.txt
|
||||
|
||||
Executable → Regular
Executable → Regular
+4
@@ -19,6 +19,8 @@
|
||||
*/tcltest*
|
||||
*/versions.vc
|
||||
*/version.vc
|
||||
*/libtcl.vfs
|
||||
*/libtcl_*.zip
|
||||
html
|
||||
libtommath/bn.ilg
|
||||
libtommath/bn.ind
|
||||
@@ -45,6 +47,8 @@ unix/tclIndex
|
||||
unix/pkgs/*
|
||||
win/Debug*
|
||||
win/Release*
|
||||
win/*.manifest
|
||||
win/pkgs/*
|
||||
win/coffbase.txt
|
||||
win/tcl.hpj
|
||||
win/nmhlp-out.txt
|
||||
|
||||
+37
-80
@@ -6,20 +6,20 @@ matrix:
|
||||
# Testing on Linux with various compilers
|
||||
- name: "Linux/GCC/Shared"
|
||||
os: linux
|
||||
dist: xenial
|
||||
dist: bionic
|
||||
compiler: gcc
|
||||
env:
|
||||
- BUILD_DIR=unix
|
||||
- name: "Linux/GCC/Static"
|
||||
os: linux
|
||||
dist: xenial
|
||||
dist: bionic
|
||||
compiler: gcc
|
||||
env:
|
||||
- CFGOPT="--disable-shared"
|
||||
- BUILD_DIR=unix
|
||||
- name: "Linux/GCC/Debug"
|
||||
os: linux
|
||||
dist: xenial
|
||||
dist: bionic
|
||||
compiler: gcc
|
||||
env:
|
||||
- BUILD_DIR=unix
|
||||
@@ -27,7 +27,7 @@ matrix:
|
||||
# Older versions of GCC...
|
||||
- name: "Linux/GCC 7/Shared"
|
||||
os: linux
|
||||
dist: xenial
|
||||
dist: bionic
|
||||
compiler: gcc-7
|
||||
addons:
|
||||
apt:
|
||||
@@ -39,7 +39,7 @@ matrix:
|
||||
- BUILD_DIR=unix
|
||||
- name: "Linux/GCC 6/Shared"
|
||||
os: linux
|
||||
dist: xenial
|
||||
dist: bionic
|
||||
compiler: gcc-6
|
||||
addons:
|
||||
apt:
|
||||
@@ -51,7 +51,7 @@ matrix:
|
||||
- BUILD_DIR=unix
|
||||
- name: "Linux/GCC 5/Shared"
|
||||
os: linux
|
||||
dist: xenial
|
||||
dist: bionic
|
||||
compiler: gcc-5
|
||||
addons:
|
||||
apt:
|
||||
@@ -61,48 +61,36 @@ matrix:
|
||||
- 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
|
||||
# Clang
|
||||
- name: "Linux/Clang/Shared"
|
||||
os: linux
|
||||
dist: xenial
|
||||
dist: bionic
|
||||
compiler: clang
|
||||
env:
|
||||
- BUILD_DIR=unix
|
||||
- name: "Linux/Clang/Static"
|
||||
os: linux
|
||||
dist: xenial
|
||||
dist: bionic
|
||||
compiler: clang
|
||||
env:
|
||||
- CFGOPT="--disable-shared"
|
||||
- BUILD_DIR=unix
|
||||
- name: "Linux/Clang/Debug"
|
||||
os: linux
|
||||
dist: xenial
|
||||
dist: bionic
|
||||
compiler: clang
|
||||
env:
|
||||
- BUILD_DIR=unix
|
||||
- CFGOPT="--enable-symbols"
|
||||
# Testing on Mac, various styles
|
||||
- name: "macOS/Xcode 11/Shared/Unix-like"
|
||||
- name: "macOS/Xcode 11.3/Shared/Unix-like"
|
||||
os: osx
|
||||
osx_image: xcode11
|
||||
osx_image: xcode11.3
|
||||
env:
|
||||
- BUILD_DIR=unix
|
||||
- name: "macOS/Xcode 11/Shared"
|
||||
- name: "macOS/Xcode 11.3/Shared"
|
||||
os: osx
|
||||
osx_image: xcode11
|
||||
osx_image: xcode11.3
|
||||
env:
|
||||
- BUILD_DIR=macosx
|
||||
install: []
|
||||
@@ -110,6 +98,13 @@ matrix:
|
||||
- make all
|
||||
# The styles=develop avoids some weird problems on OSX
|
||||
- make test styles=develop
|
||||
- name: "macOS/Xcode 11/Shared"
|
||||
os: osx
|
||||
osx_image: xcode11
|
||||
env:
|
||||
- BUILD_DIR=macosx
|
||||
install: []
|
||||
script: *mactest
|
||||
- name: "macOS/Xcode 10/Shared"
|
||||
os: osx
|
||||
osx_image: xcode10.3
|
||||
@@ -135,16 +130,15 @@ matrix:
|
||||
# Doesn't run tests because wine is only an imperfect Windows emulation
|
||||
- name: "Linux-cross-Windows/GCC/Shared/no test"
|
||||
os: linux
|
||||
dist: xenial
|
||||
dist: bionic
|
||||
compiler: x86_64-w64-mingw32-gcc
|
||||
addons: &mingw64
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- gcc-mingw-w64-base
|
||||
- binutils-mingw-w64-x86-64
|
||||
- gcc-mingw-w64-x86-64
|
||||
- gcc-mingw-w64
|
||||
- wine
|
||||
env:
|
||||
- BUILD_DIR=win
|
||||
- CFGOPT="--host=x86_64-w64-mingw32 --enable-64bit"
|
||||
@@ -153,31 +147,13 @@ matrix:
|
||||
# Include a high visibility marker that tests are skipped outright
|
||||
- >
|
||||
echo "`tput setaf 3`SKIPPED TEST: CROSS COMPILING`tput sgr0`"
|
||||
- name: "Linux-cross-Windows/GCC/Static/no test"
|
||||
os: linux
|
||||
dist: xenial
|
||||
compiler: x86_64-w64-mingw32-gcc
|
||||
addons: *mingw64
|
||||
env:
|
||||
- BUILD_DIR=win
|
||||
- CFGOPT="--host=x86_64-w64-mingw32 --enable-64bit --disable-shared"
|
||||
script: *crosstest
|
||||
- name: "Linux-cross-Windows/GCC/Debug/no test"
|
||||
os: linux
|
||||
dist: xenial
|
||||
compiler: x86_64-w64-mingw32-gcc
|
||||
addons: *mingw64
|
||||
env:
|
||||
- BUILD_DIR=win
|
||||
- CFGOPT="--host=x86_64-w64-mingw32 --enable-64bit --enable-symbols"
|
||||
script: *crosstest
|
||||
# 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
|
||||
dist: bionic
|
||||
compiler: i686-w64-mingw32-gcc
|
||||
addons: &mingw32
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- gcc-mingw-w64-base
|
||||
@@ -185,28 +161,9 @@ matrix:
|
||||
- gcc-mingw-w64-i686
|
||||
- gcc-mingw-w64
|
||||
- gcc-multilib
|
||||
- wine
|
||||
env:
|
||||
- BUILD_DIR=win
|
||||
- CFGOPT="--host=i686-w64-mingw32"
|
||||
script: *crosstest
|
||||
- name: "Linux-cross-Windows-32/GCC/Static/no test"
|
||||
os: linux
|
||||
dist: xenial
|
||||
compiler: i686-w64-mingw32-gcc
|
||||
addons: *mingw32
|
||||
env:
|
||||
- BUILD_DIR=win
|
||||
- CFGOPT="--host=i686-w64-mingw32 --disable-shared"
|
||||
script: *crosstest
|
||||
- name: "Linux-cross-Windows-32/GCC/Debug/no test"
|
||||
os: linux
|
||||
dist: xenial
|
||||
compiler: i686-w64-mingw32-gcc
|
||||
addons: *mingw32
|
||||
env:
|
||||
- BUILD_DIR=win
|
||||
- CFGOPT="--host=i686-w64-mingw32 --enable-symbols"
|
||||
- CFGOPT=--host=i686-w64-mingw32
|
||||
script: *crosstest
|
||||
# Test on Windows with MSVC native
|
||||
- name: "Windows/MSVC/Shared"
|
||||
@@ -220,8 +177,8 @@ matrix:
|
||||
- cd ${BUILD_DIR}
|
||||
install: []
|
||||
script:
|
||||
- cmd.exe /C 'vcvarsall.bat x64 && nmake OPTS=threads -f makefile.vc all tcltest'
|
||||
- cmd.exe /C 'vcvarsall.bat x64 && nmake OPTS=threads -f makefile.vc test'
|
||||
- cmd.exe //C vcvarsall.bat x64 '&&' nmake '-f' makefile.vc all tcltest
|
||||
- cmd.exe //C vcvarsall.bat x64 '&&' nmake '-f' makefile.vc test
|
||||
- name: "Windows/MSVC/Static"
|
||||
os: windows
|
||||
compiler: cl
|
||||
@@ -229,8 +186,8 @@ matrix:
|
||||
before_install: *vcpreinst
|
||||
install: []
|
||||
script:
|
||||
- cmd.exe /C 'vcvarsall.bat x64 && nmake OPTS=static,msvcrt,threads -f makefile.vc all tcltest'
|
||||
- cmd.exe /C 'vcvarsall.bat x64 && nmake OPTS=static,msvcrt,threads -f makefile.vc test'
|
||||
- cmd.exe //C vcvarsall.bat x64 '&&' nmake 'OPTS=static,msvcrt' '-f' makefile.vc all tcltest
|
||||
- cmd.exe //C vcvarsall.bat x64 '&&' nmake 'OPTS=static,msvcrt' '-f' makefile.vc test
|
||||
- name: "Windows/MSVC/Debug"
|
||||
os: windows
|
||||
compiler: cl
|
||||
@@ -238,8 +195,8 @@ matrix:
|
||||
before_install: *vcpreinst
|
||||
install: []
|
||||
script:
|
||||
- cmd.exe /C 'vcvarsall.bat x64 && nmake OPTS=symbols,msvcrt,threads -f makefile.vc all tcltest'
|
||||
- cmd.exe /C 'vcvarsall.bat x64 && nmake OPTS=symbols,msvcrt,threads -f makefile.vc test'
|
||||
- cmd.exe //C vcvarsall.bat x64 '&&' nmake 'OPTS=symbols' '-f' makefile.vc all tcltest
|
||||
- cmd.exe //C vcvarsall.bat x64 '&&' nmake 'OPTS=symbols' '-f' makefile.vc test
|
||||
# Test on Windows with MSVC native (32-bit)
|
||||
- name: "Windows/MSVC-x86/Shared"
|
||||
os: windows
|
||||
@@ -248,8 +205,8 @@ matrix:
|
||||
before_install: *vcpreinst
|
||||
install: []
|
||||
script:
|
||||
- cmd.exe /C 'vcvarsall.bat x86 && nmake OPTS=threads -f makefile.vc all tcltest'
|
||||
- cmd.exe /C 'vcvarsall.bat x86 && nmake OPTS=threads -f makefile.vc test'
|
||||
- cmd.exe //C vcvarsall.bat x86 '&&' nmake '-f' makefile.vc all tcltest
|
||||
- cmd.exe //C vcvarsall.bat x86 '&&' nmake '-f' makefile.vc test
|
||||
- name: "Windows/MSVC-x86/Static"
|
||||
os: windows
|
||||
compiler: cl
|
||||
@@ -257,8 +214,8 @@ matrix:
|
||||
before_install: *vcpreinst
|
||||
install: []
|
||||
script:
|
||||
- cmd.exe /C 'vcvarsall.bat x86 && nmake OPTS=static,msvcrt,threads -f makefile.vc all tcltest'
|
||||
- cmd.exe /C 'vcvarsall.bat x86 && nmake OPTS=static,msvcrt,threads -f makefile.vc test'
|
||||
- cmd.exe //C vcvarsall.bat x86 '&&' nmake 'OPTS=static,msvcrt' '-f' makefile.vc all tcltest
|
||||
- cmd.exe //C vcvarsall.bat x86 '&&' nmake 'OPTS=static,msvcrt' '-f' makefile.vc test
|
||||
- name: "Windows/MSVC-x86/Debug"
|
||||
os: windows
|
||||
compiler: cl
|
||||
@@ -266,8 +223,8 @@ matrix:
|
||||
before_install: *vcpreinst
|
||||
install: []
|
||||
script:
|
||||
- cmd.exe /C 'vcvarsall.bat x86 && nmake OPTS=symbols,msvcrt,threads -f makefile.vc all tcltest'
|
||||
- cmd.exe /C 'vcvarsall.bat x86 && nmake OPTS=symbols,msvcrt,threads -f makefile.vc test'
|
||||
- cmd.exe //C vcvarsall.bat x86 '&&' nmake 'OPTS=symbols' '-f' makefile.vc all tcltest
|
||||
- cmd.exe //C vcvarsall.bat x86 '&&' nmake 'OPTS=symbols' '-f' makefile.vc test
|
||||
# Test on Windows with GCC native
|
||||
- name: "Windows/GCC/Shared"
|
||||
os: windows
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# README: Tcl
|
||||
|
||||
This is the **Tcl 8.6.9** source distribution.
|
||||
This is the **Tcl 8.6.10** source distribution.
|
||||
|
||||
You can get any source release of Tcl from [our distribution
|
||||
site](https://sourceforge.net/projects/tcl/files/Tcl/).
|
||||
|
||||
@@ -8303,7 +8303,7 @@ reported usage of large expressions (porter)
|
||||
|
||||
Many optmizations, improvements, and tightened stack management in bytecode.
|
||||
|
||||
--- Released 8.6.1, September 20, 2013 --- http://core.tcl.tk/tcl/ for details
|
||||
--- Released 8.6.1, September 20, 2013 --- https://core.tcl-lang.org/tcl/ for details
|
||||
|
||||
2013-09-27 (enhancement) improved ::env synchronization (fellows)
|
||||
|
||||
@@ -8451,7 +8451,7 @@ include ::oo::class (fellows)
|
||||
|
||||
2014-08-25 (TIP 429) New command [string cat] (leitgeb,ferrieux)
|
||||
|
||||
--- Released 8.6.2, August 27, 2014 --- http://core.tcl.tk/tcl/ for details
|
||||
--- Released 8.6.2, August 27, 2014 --- https://core.tcl-lang.org/tcl/ for details
|
||||
|
||||
2014-08-28 (bug)[b9e1a3] Correct Method Search Order (nadkarni,fellows)
|
||||
=> TclOO 1.0.3
|
||||
@@ -8491,7 +8491,7 @@ include ::oo::class (fellows)
|
||||
|
||||
2014-11-06 (bug)[5adc35] Stop forcing EOF to be permanent (porter)
|
||||
|
||||
--- Released 8.6.3, November 12, 2014 --- http://core.tcl.tk/tcl/ for details
|
||||
--- Released 8.6.3, November 12, 2014 --- https://core.tcl-lang.org/tcl/ for details
|
||||
|
||||
2014-11-21 (bug)[743338] Win: socket error encoding (ladayaroslav,nijtmans)
|
||||
|
||||
@@ -8527,7 +8527,7 @@ include ::oo::class (fellows)
|
||||
2015-03-10 (enhancement) Revise OS X notifier for better Cocoa (walzer)
|
||||
*** POTENTIAL INCOMPATIBILITY ***
|
||||
|
||||
--- Released 8.6.4, March 12, 2015 --- http://core.tcl.tk/tcl/ for details
|
||||
--- Released 8.6.4, March 12, 2015 --- https://core.tcl-lang.org/tcl/ for details
|
||||
|
||||
2015-03-19 (bug)[e66e44] Win: Ctrl-C/Ctrl-Break in console not EOF (nadkarni)
|
||||
|
||||
@@ -8623,7 +8623,7 @@ improvements to regexp engine from Postgres (lane,porter,fellows,seltenreich)
|
||||
|
||||
2016-02-22 (bug)[9b4702] [info exists env(missing)] kills trace (nijtmans)
|
||||
|
||||
--- Released 8.6.5, February 29, 2016 --- http://core.tcl.tk/tcl/ for details
|
||||
--- Released 8.6.5, February 29, 2016 --- https://core.tcl-lang.org/tcl/ for details
|
||||
|
||||
2016-03-01 (bug)[803042] mem leak due to reference cycle (porter)
|
||||
|
||||
@@ -8697,7 +8697,7 @@ improvements to regexp engine from Postgres (lane,porter,fellows,seltenreich)
|
||||
|
||||
2016-07-20 tzdata updated to Olson's tzdata2016f (venkat)
|
||||
|
||||
--- Released 8.6.6, July 27, 2016 --- http://core.tcl.tk/tcl/ for details
|
||||
--- Released 8.6.6, July 27, 2016 --- https://core.tcl-lang.org/tcl/ for details
|
||||
|
||||
2016-09-07 (bug)[c09edf] Bad caching with custom resolver (neumann,nijtmans)
|
||||
|
||||
@@ -8794,7 +8794,7 @@ improvements to regexp engine from Postgres (lane,porter,fellows,seltenreich)
|
||||
|
||||
2017-07-17 (bug)[fb2208] Repeatable tclIndex generation (wiedemann,nijtmans)
|
||||
|
||||
--- Released 8.6.7, August 9, 2017 --- http://core.tcl.tk/tcl/ for details
|
||||
--- Released 8.6.7, August 9, 2017 --- https://core.tcl-lang.org/tcl/ for details
|
||||
|
||||
2017-08-10 [array names -regexp] supports backrefs (goth)
|
||||
|
||||
@@ -8829,7 +8829,7 @@ improvements to regexp engine from Postgres (lane,porter,fellows,seltenreich)
|
||||
|
||||
2017-12-19 (bug)[586e71] EvalObjv exception handling at level #0 (sebres,porter)
|
||||
|
||||
--- Released 8.6.8, December 22, 2017 --- http://core.tcl.tk/tcl/ for details
|
||||
--- Released 8.6.8, December 22, 2017 --- https://core.tcl-lang.org/tcl/ for details
|
||||
|
||||
2018-02-11 (enhance) stop blocking conversion of object to/from class (coulter)
|
||||
|
||||
@@ -8894,3 +8894,54 @@ improvements to regexp engine from Postgres (lane,porter,fellows,seltenreich)
|
||||
2018-11-16 (bug)[00d04c] Repair [binary encode base64] (sebres)
|
||||
|
||||
- Released 8.6.9, November 16, 2018 - details at http://core.tcl-lang.org/tcl/ -
|
||||
|
||||
2018-11-22 (bug)[7a9dc5] [file normalize ~/~foo] segfault (sebres)
|
||||
|
||||
2018-12-30 (bug)[3cf3a9] variable 'timezone' deprecated in vc2017 (nijtmans)
|
||||
|
||||
2019-01-09 (bug)[cc1e91] [list [list {*}[set a " "]]] regression (sebres)
|
||||
|
||||
2019-02-01 (bug)[e3f481] tests var-1.2[01] (sebres)
|
||||
|
||||
2019-03-01 (new) Update to Unicode 12.0 (nijtmans)
|
||||
|
||||
2019-03-05 (new)[TIP 527] New command [timerate] (sebres)
|
||||
|
||||
2019-03-08 (bug)[39fed4] [package require] memory validity (hume,porter)
|
||||
|
||||
2019-04-23 (new) New command tcl::unsupported::corotype (fellows)
|
||||
|
||||
2019-05-04 (bug) memlink when namespace deletion kills linked var (porter)
|
||||
|
||||
2019-05-28 (new) README file converted to README.md in Markdown (nijtmans)
|
||||
|
||||
2019-06-17 (bug)[8b9854] [info level 0] regression with ensembles (porter)
|
||||
|
||||
2019-06-20 (bug)[6bdadf] crash multi-arg write-traced [lappend] (fellows,porter)
|
||||
|
||||
2019-06-21 (bug)[f8a33c] crash Tcl_Exit before init (brooks,sebres)
|
||||
|
||||
2019-08-27 (bug)[fa6bf3] Bytecode fails epoch recovery at numLevel=0 (sebres)
|
||||
|
||||
2019-08-29 (bug)[fec0c1] C stack overflow compiling bytecode (ade,sebres)
|
||||
|
||||
2019-09-12 tzdata updated to Olson's tzdata2019c (jima)
|
||||
|
||||
2019-09-20 (new) registry/dde no longer need -DUNICODE (nijtmans)
|
||||
=> registry 1.3.4
|
||||
=> dde 1.4.2
|
||||
|
||||
2019-10-02 (bug)[16768d] Fix [info hostname] on NetBSD (rytaro)
|
||||
|
||||
2019-10-23 (new) libtommath updated to release 1.2.0 (nijtmans)
|
||||
|
||||
2019-10-25 OSX: system Tcl deprecated. End default use of its packages. (walzer)
|
||||
|
||||
2019-10-28 (bug)[bcd100] bad fs cache when system encoding changes (coulter)
|
||||
|
||||
2019-11-15 (bug)[135804] segfault in [next] after destroy (coulter,sebres)
|
||||
|
||||
2019-11-18 (bug)[13657a] application/json us text, not binary (noe,nijtmans)
|
||||
=> http 2.9.1
|
||||
|
||||
- Released 8.6.10, Nov 21, 2019 - details at http://core.tcl-lang.org/tcl/ -
|
||||
|
||||
@@ -14,7 +14,11 @@
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__) || defined(IOAPI_NO_64)
|
||||
#if defined(_WIN32)
|
||||
#define FOPEN_FUNC(filename, mode) fopen(filename, mode)
|
||||
#define FTELLO_FUNC(stream) _ftelli64(stream)
|
||||
#define FSEEKO_FUNC(stream, offset, origin) _fseeki64(stream, offset, origin)
|
||||
#elif defined(__APPLE__) || defined(IOAPI_NO_64)
|
||||
// In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions
|
||||
#define FOPEN_FUNC(filename, mode) fopen(filename, mode)
|
||||
#define FTELLO_FUNC(stream) ftello(stream)
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
|
||||
*/
|
||||
|
||||
|
||||
#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__))
|
||||
#ifndef __USE_FILE_OFFSET64
|
||||
#define __USE_FILE_OFFSET64
|
||||
@@ -28,7 +27,11 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
#if defined(_WIN32)
|
||||
#define FOPEN_FUNC(filename, mode) fopen(filename, mode)
|
||||
#define FTELLO_FUNC(stream) _ftelli64(stream)
|
||||
#define FSEEKO_FUNC(stream, offset, origin) _fseeki64(stream, offset, origin)
|
||||
#elif defined(__APPLE__) || defined(IOAPI_NO_64)
|
||||
// In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions
|
||||
#define FOPEN_FUNC(filename, mode) fopen(filename, mode)
|
||||
#define FTELLO_FUNC(stream) ftello(stream)
|
||||
@@ -39,8 +42,7 @@
|
||||
#define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#include "tinydir.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -72,8 +74,8 @@
|
||||
|
||||
#ifdef _WIN32
|
||||
uLong filetime(f, tmzip, dt)
|
||||
char *f; /* name of file to get info on */
|
||||
tm_zip *tmzip; /* return value: access, modific. and creation times */
|
||||
const char *f; /* name of file to get info on */
|
||||
tm_zip *tmzip; /* return value: access, modific. and creation times */
|
||||
uLong *dt; /* dostime */
|
||||
{
|
||||
int ret = 0;
|
||||
@@ -96,7 +98,7 @@ uLong filetime(f, tmzip, dt)
|
||||
#else
|
||||
#if defined(unix) || defined(__APPLE__)
|
||||
uLong filetime(f, tmzip, dt)
|
||||
char *f; /* name of file to get info on */
|
||||
const char *f; /* name of file to get info on */
|
||||
tm_zip *tmzip; /* return value: access, modific. and creation times */
|
||||
uLong *dt; /* dostime */
|
||||
{
|
||||
@@ -138,8 +140,8 @@ uLong filetime(f, tmzip, dt)
|
||||
}
|
||||
#else
|
||||
uLong filetime(f, tmzip, dt)
|
||||
char *f; /* name of file to get info on */
|
||||
tm_zip *tmzip; /* return value: access, modific. and creation times */
|
||||
const char *f; /* name of file to get info on */
|
||||
tm_zip *tmzip; /* return value: access, modific. and creation times */
|
||||
uLong *dt; /* dostime */
|
||||
{
|
||||
return 0;
|
||||
@@ -172,6 +174,7 @@ void do_banner()
|
||||
void do_help()
|
||||
{
|
||||
printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] [-j] file.zip [files_to_add]\n\n" \
|
||||
" -r Scan directories recursively\n" \
|
||||
" -o Overwrite existing file.zip\n" \
|
||||
" -a Append to existing file.zip\n" \
|
||||
" -0 Store only\n" \
|
||||
@@ -243,12 +246,153 @@ int isLargeFile(const char* filename)
|
||||
return largeFile;
|
||||
}
|
||||
|
||||
void addFileToZip(zipFile zf, const char *filenameinzip, const char *password, int opt_exclude_path,int opt_compress_level) {
|
||||
FILE * fin;
|
||||
int size_read;
|
||||
const char *savefilenameinzip;
|
||||
zip_fileinfo zi;
|
||||
unsigned long crcFile=0;
|
||||
int zip64 = 0;
|
||||
int err=0;
|
||||
int size_buf=WRITEBUFFERSIZE;
|
||||
unsigned char buf[WRITEBUFFERSIZE];
|
||||
zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour =
|
||||
zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0;
|
||||
zi.dosDate = 0;
|
||||
zi.internal_fa = 0;
|
||||
zi.external_fa = 0;
|
||||
filetime(filenameinzip,&zi.tmz_date,&zi.dosDate);
|
||||
|
||||
/*
|
||||
err = zipOpenNewFileInZip(zf,filenameinzip,&zi,
|
||||
NULL,0,NULL,0,NULL / * comment * /,
|
||||
(opt_compress_level != 0) ? Z_DEFLATED : 0,
|
||||
opt_compress_level);
|
||||
*/
|
||||
if ((password != NULL) && (err==ZIP_OK))
|
||||
err = getFileCrc(filenameinzip,buf,size_buf,&crcFile);
|
||||
|
||||
zip64 = isLargeFile(filenameinzip);
|
||||
|
||||
/* The path name saved, should not include a leading slash. */
|
||||
/*if it did, windows/xp and dynazip couldn't read the zip file. */
|
||||
savefilenameinzip = filenameinzip;
|
||||
while( savefilenameinzip[0] == '\\' || savefilenameinzip[0] == '/' )
|
||||
{
|
||||
savefilenameinzip++;
|
||||
}
|
||||
|
||||
/*should the zip file contain any path at all?*/
|
||||
if( opt_exclude_path )
|
||||
{
|
||||
const char *tmpptr;
|
||||
const char *lastslash = 0;
|
||||
for( tmpptr = savefilenameinzip; *tmpptr; tmpptr++)
|
||||
{
|
||||
if( *tmpptr == '\\' || *tmpptr == '/')
|
||||
{
|
||||
lastslash = tmpptr;
|
||||
}
|
||||
}
|
||||
if( lastslash != NULL )
|
||||
{
|
||||
savefilenameinzip = lastslash+1; // base filename follows last slash.
|
||||
}
|
||||
}
|
||||
|
||||
/**/
|
||||
err = zipOpenNewFileInZip3_64(zf,savefilenameinzip,&zi,
|
||||
NULL,0,NULL,0,NULL /* comment*/,
|
||||
(opt_compress_level != 0) ? Z_DEFLATED : 0,
|
||||
opt_compress_level,0,
|
||||
/* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */
|
||||
-MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
|
||||
password,crcFile, zip64);
|
||||
|
||||
if (err != ZIP_OK)
|
||||
printf("error in opening %s in zipfile\n",filenameinzip);
|
||||
else
|
||||
{
|
||||
fin = FOPEN_FUNC(filenameinzip,"rb");
|
||||
if (fin==NULL)
|
||||
{
|
||||
err=ZIP_ERRNO;
|
||||
printf("error in opening %s for reading\n",filenameinzip);
|
||||
}
|
||||
}
|
||||
|
||||
if (err == ZIP_OK)
|
||||
do
|
||||
{
|
||||
err = ZIP_OK;
|
||||
size_read = (int)fread(buf,1,size_buf,fin);
|
||||
if (size_read < size_buf)
|
||||
if (feof(fin)==0)
|
||||
{
|
||||
printf("error in reading %s\n",filenameinzip);
|
||||
err = ZIP_ERRNO;
|
||||
}
|
||||
|
||||
if (size_read>0)
|
||||
{
|
||||
err = zipWriteInFileInZip (zf,buf,size_read);
|
||||
if (err<0)
|
||||
{
|
||||
printf("error in writing %s in the zipfile\n",
|
||||
filenameinzip);
|
||||
}
|
||||
|
||||
}
|
||||
} while ((err == ZIP_OK) && (size_read>0));
|
||||
|
||||
if (fin)
|
||||
fclose(fin);
|
||||
|
||||
if (err<0)
|
||||
err=ZIP_ERRNO;
|
||||
else
|
||||
{
|
||||
err = zipCloseFileInZip(zf);
|
||||
if (err!=ZIP_OK)
|
||||
printf("error in closing %s in the zipfile\n",
|
||||
filenameinzip);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void addPathToZip(zipFile zf, const char *filenameinzip, const char *password, int opt_exclude_path,int opt_compress_level) {
|
||||
tinydir_dir dir;
|
||||
int i;
|
||||
char newname[512];
|
||||
|
||||
tinydir_open_sorted(&dir, filenameinzip);
|
||||
|
||||
for (i = 0; i < dir.n_files; i++)
|
||||
{
|
||||
tinydir_file file;
|
||||
tinydir_readfile_n(&dir, &file, i);
|
||||
if(strcmp(file.name,".")==0) continue;
|
||||
if(strcmp(file.name,"..")==0) continue;
|
||||
sprintf(newname,"%s/%s",dir.path,file.name);
|
||||
if (file.is_dir)
|
||||
{
|
||||
addPathToZip(zf,newname,password,opt_exclude_path,opt_compress_level);
|
||||
} else {
|
||||
addFileToZip(zf,newname,password,opt_exclude_path,opt_compress_level);
|
||||
}
|
||||
}
|
||||
|
||||
tinydir_close(&dir);
|
||||
}
|
||||
|
||||
|
||||
int main(argc,argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
int i;
|
||||
int opt_overwrite=0;
|
||||
int opt_recursive=0;
|
||||
int opt_overwrite=1;
|
||||
int opt_compress_level=Z_DEFAULT_COMPRESSION;
|
||||
int opt_exclude_path=0;
|
||||
int zipfilenamearg = 0;
|
||||
@@ -285,7 +429,8 @@ int main(argc,argv)
|
||||
opt_compress_level = c-'0';
|
||||
if ((c=='j') || (c=='J'))
|
||||
opt_exclude_path = 1;
|
||||
|
||||
if ((c=='r') || (c=='R'))
|
||||
opt_recursive = 1;
|
||||
if (((c=='p') || (c=='P')) && (i+1<argc))
|
||||
{
|
||||
password=argv[i+1];
|
||||
@@ -392,117 +537,14 @@ int main(argc,argv)
|
||||
((argv[i][1]=='o') || (argv[i][1]=='O') ||
|
||||
(argv[i][1]=='a') || (argv[i][1]=='A') ||
|
||||
(argv[i][1]=='p') || (argv[i][1]=='P') ||
|
||||
(argv[i][1]=='r') || (argv[i][1]=='R') ||
|
||||
((argv[i][1]>='0') || (argv[i][1]<='9'))) &&
|
||||
(strlen(argv[i]) == 2)))
|
||||
{
|
||||
FILE * fin;
|
||||
int size_read;
|
||||
const char* filenameinzip = argv[i];
|
||||
const char *savefilenameinzip;
|
||||
zip_fileinfo zi;
|
||||
unsigned long crcFile=0;
|
||||
int zip64 = 0;
|
||||
|
||||
zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour =
|
||||
zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0;
|
||||
zi.dosDate = 0;
|
||||
zi.internal_fa = 0;
|
||||
zi.external_fa = 0;
|
||||
filetime(filenameinzip,&zi.tmz_date,&zi.dosDate);
|
||||
|
||||
/*
|
||||
err = zipOpenNewFileInZip(zf,filenameinzip,&zi,
|
||||
NULL,0,NULL,0,NULL / * comment * /,
|
||||
(opt_compress_level != 0) ? Z_DEFLATED : 0,
|
||||
opt_compress_level);
|
||||
*/
|
||||
if ((password != NULL) && (err==ZIP_OK))
|
||||
err = getFileCrc(filenameinzip,buf,size_buf,&crcFile);
|
||||
|
||||
zip64 = isLargeFile(filenameinzip);
|
||||
|
||||
/* The path name saved, should not include a leading slash. */
|
||||
/*if it did, windows/xp and dynazip couldn't read the zip file. */
|
||||
savefilenameinzip = filenameinzip;
|
||||
while( savefilenameinzip[0] == '\\' || savefilenameinzip[0] == '/' )
|
||||
{
|
||||
savefilenameinzip++;
|
||||
}
|
||||
|
||||
/*should the zip file contain any path at all?*/
|
||||
if( opt_exclude_path )
|
||||
{
|
||||
const char *tmpptr;
|
||||
const char *lastslash = 0;
|
||||
for( tmpptr = savefilenameinzip; *tmpptr; tmpptr++)
|
||||
{
|
||||
if( *tmpptr == '\\' || *tmpptr == '/')
|
||||
{
|
||||
lastslash = tmpptr;
|
||||
}
|
||||
}
|
||||
if( lastslash != NULL )
|
||||
{
|
||||
savefilenameinzip = lastslash+1; // base filename follows last slash.
|
||||
}
|
||||
}
|
||||
|
||||
/**/
|
||||
err = zipOpenNewFileInZip3_64(zf,savefilenameinzip,&zi,
|
||||
NULL,0,NULL,0,NULL /* comment*/,
|
||||
(opt_compress_level != 0) ? Z_DEFLATED : 0,
|
||||
opt_compress_level,0,
|
||||
/* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */
|
||||
-MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
|
||||
password,crcFile, zip64);
|
||||
|
||||
if (err != ZIP_OK)
|
||||
printf("error in opening %s in zipfile\n",filenameinzip);
|
||||
else
|
||||
{
|
||||
fin = FOPEN_FUNC(filenameinzip,"rb");
|
||||
if (fin==NULL)
|
||||
{
|
||||
err=ZIP_ERRNO;
|
||||
printf("error in opening %s for reading\n",filenameinzip);
|
||||
}
|
||||
}
|
||||
|
||||
if (err == ZIP_OK)
|
||||
do
|
||||
{
|
||||
err = ZIP_OK;
|
||||
size_read = (int)fread(buf,1,size_buf,fin);
|
||||
if (size_read < size_buf)
|
||||
if (feof(fin)==0)
|
||||
{
|
||||
printf("error in reading %s\n",filenameinzip);
|
||||
err = ZIP_ERRNO;
|
||||
}
|
||||
|
||||
if (size_read>0)
|
||||
{
|
||||
err = zipWriteInFileInZip (zf,buf,size_read);
|
||||
if (err<0)
|
||||
{
|
||||
printf("error in writing %s in the zipfile\n",
|
||||
filenameinzip);
|
||||
}
|
||||
|
||||
}
|
||||
} while ((err == ZIP_OK) && (size_read>0));
|
||||
|
||||
if (fin)
|
||||
fclose(fin);
|
||||
|
||||
if (err<0)
|
||||
err=ZIP_ERRNO;
|
||||
else
|
||||
{
|
||||
err = zipCloseFileInZip(zf);
|
||||
if (err!=ZIP_OK)
|
||||
printf("error in closing %s in the zipfile\n",
|
||||
filenameinzip);
|
||||
if(opt_recursive) {
|
||||
addPathToZip(zf,argv[i],password,opt_exclude_path,opt_compress_level);
|
||||
} else {
|
||||
addFileToZip(zf,argv[i],password,opt_exclude_path,opt_compress_level);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -103,7 +103,7 @@ the argument's value. The following values are acceptable values for
|
||||
\fBTCL_ARGV_CONSTANT\fR
|
||||
.
|
||||
The argument does not take any following value argument. If this argument is
|
||||
present, the \fIsrcPtr\fR field (casted to \fIint\fR) is copied to the variable
|
||||
present, the (integer) value of the \fIsrcPtr\fR field is copied to the variable
|
||||
pointed to by the \fIdstPtr\fR field. The \fIclientData\fR field is ignored.
|
||||
.TP
|
||||
\fBTCL_ARGV_END\fR
|
||||
|
||||
@@ -243,6 +243,7 @@ struct vars {
|
||||
#define EMPTYARC(x, y) newarc(v->nfa, EMPTY, 0, x, y)
|
||||
|
||||
/* token type codes, some also used as NFA arc types */
|
||||
#undef DIGIT /* prevent conflict with libtommath */
|
||||
#define EMPTY 'n' /* no token present */
|
||||
#define EOS 'e' /* end of string */
|
||||
#define PLAIN 'p' /* ordinary character */
|
||||
|
||||
@@ -2323,6 +2323,10 @@ declare 630 {
|
||||
Tcl_Obj *compressionDictionaryObj)
|
||||
}
|
||||
|
||||
declare 648 {
|
||||
void TclUnusedStubEntry(void)
|
||||
}
|
||||
|
||||
# ----- BASELINE -- FOR -- 8.6.0 ----- #
|
||||
|
||||
##############################################################################
|
||||
|
||||
+2
-2
@@ -51,10 +51,10 @@ extern "C" {
|
||||
#define TCL_MAJOR_VERSION 8
|
||||
#define TCL_MINOR_VERSION 6
|
||||
#define TCL_RELEASE_LEVEL TCL_FINAL_RELEASE
|
||||
#define TCL_RELEASE_SERIAL 9
|
||||
#define TCL_RELEASE_SERIAL 10
|
||||
|
||||
#define TCL_VERSION "8.6"
|
||||
#define TCL_PATCH_LEVEL "8.6.9"
|
||||
#define TCL_PATCH_LEVEL "8.6.10"
|
||||
|
||||
/*
|
||||
*----------------------------------------------------------------------------
|
||||
|
||||
+1
-1
@@ -1513,7 +1513,7 @@ GetJulianDayFromEraYearMonthDay(
|
||||
* Try an initial conversion in the Gregorian calendar.
|
||||
*/
|
||||
|
||||
#if 0 /* BUG http://core.tcl.tk/tcl/tktview?name=da340d4f32 */
|
||||
#if 0 /* BUG https://core.tcl-lang.org/tcl/tktview?name=da340d4f32 */
|
||||
ym1o4 = ym1 / 4;
|
||||
#else
|
||||
/*
|
||||
|
||||
@@ -1816,6 +1816,25 @@ EXTERN int Tcl_FSUnloadFile(Tcl_Interp *interp,
|
||||
EXTERN void Tcl_ZlibStreamSetCompressionDictionary(
|
||||
Tcl_ZlibStream zhandle,
|
||||
Tcl_Obj *compressionDictionaryObj);
|
||||
/* Slot 631 is reserved */
|
||||
/* Slot 632 is reserved */
|
||||
/* Slot 633 is reserved */
|
||||
/* Slot 634 is reserved */
|
||||
/* Slot 635 is reserved */
|
||||
/* Slot 636 is reserved */
|
||||
/* Slot 637 is reserved */
|
||||
/* Slot 638 is reserved */
|
||||
/* Slot 639 is reserved */
|
||||
/* Slot 640 is reserved */
|
||||
/* Slot 641 is reserved */
|
||||
/* Slot 642 is reserved */
|
||||
/* Slot 643 is reserved */
|
||||
/* Slot 644 is reserved */
|
||||
/* Slot 645 is reserved */
|
||||
/* Slot 646 is reserved */
|
||||
/* Slot 647 is reserved */
|
||||
/* 648 */
|
||||
EXTERN void TclUnusedStubEntry(void);
|
||||
|
||||
typedef struct {
|
||||
const struct TclPlatStubs *tclPlatStubs;
|
||||
@@ -2482,6 +2501,24 @@ typedef struct TclStubs {
|
||||
void * (*tcl_FindSymbol) (Tcl_Interp *interp, Tcl_LoadHandle handle, const char *symbol); /* 628 */
|
||||
int (*tcl_FSUnloadFile) (Tcl_Interp *interp, Tcl_LoadHandle handlePtr); /* 629 */
|
||||
void (*tcl_ZlibStreamSetCompressionDictionary) (Tcl_ZlibStream zhandle, Tcl_Obj *compressionDictionaryObj); /* 630 */
|
||||
void (*reserved631)(void);
|
||||
void (*reserved632)(void);
|
||||
void (*reserved633)(void);
|
||||
void (*reserved634)(void);
|
||||
void (*reserved635)(void);
|
||||
void (*reserved636)(void);
|
||||
void (*reserved637)(void);
|
||||
void (*reserved638)(void);
|
||||
void (*reserved639)(void);
|
||||
void (*reserved640)(void);
|
||||
void (*reserved641)(void);
|
||||
void (*reserved642)(void);
|
||||
void (*reserved643)(void);
|
||||
void (*reserved644)(void);
|
||||
void (*reserved645)(void);
|
||||
void (*reserved646)(void);
|
||||
void (*reserved647)(void);
|
||||
void (*tclUnusedStubEntry) (void); /* 648 */
|
||||
} TclStubs;
|
||||
|
||||
extern const TclStubs *tclStubsPtr;
|
||||
@@ -3774,11 +3811,32 @@ extern const TclStubs *tclStubsPtr;
|
||||
(tclStubsPtr->tcl_FSUnloadFile) /* 629 */
|
||||
#define Tcl_ZlibStreamSetCompressionDictionary \
|
||||
(tclStubsPtr->tcl_ZlibStreamSetCompressionDictionary) /* 630 */
|
||||
/* Slot 631 is reserved */
|
||||
/* Slot 632 is reserved */
|
||||
/* Slot 633 is reserved */
|
||||
/* Slot 634 is reserved */
|
||||
/* Slot 635 is reserved */
|
||||
/* Slot 636 is reserved */
|
||||
/* Slot 637 is reserved */
|
||||
/* Slot 638 is reserved */
|
||||
/* Slot 639 is reserved */
|
||||
/* Slot 640 is reserved */
|
||||
/* Slot 641 is reserved */
|
||||
/* Slot 642 is reserved */
|
||||
/* Slot 643 is reserved */
|
||||
/* Slot 644 is reserved */
|
||||
/* Slot 645 is reserved */
|
||||
/* Slot 646 is reserved */
|
||||
/* Slot 647 is reserved */
|
||||
#define TclUnusedStubEntry \
|
||||
(tclStubsPtr->tclUnusedStubEntry) /* 648 */
|
||||
|
||||
#endif /* defined(USE_TCL_STUBS) */
|
||||
|
||||
/* !END!: Do not edit above this line. */
|
||||
|
||||
#undef TclUnusedStubEntry
|
||||
|
||||
#if defined(USE_TCL_STUBS)
|
||||
# undef Tcl_CreateInterp
|
||||
# undef Tcl_FindExecutable
|
||||
|
||||
+25
-12
@@ -2155,7 +2155,7 @@ BinaryProc(
|
||||
/*
|
||||
*-------------------------------------------------------------------------
|
||||
*
|
||||
* UtfExtToUtfIntProc --
|
||||
* UtfIntToUtfExtProc --
|
||||
*
|
||||
* Convert from UTF-8 to UTF-8. While converting null-bytes from the
|
||||
* Tcl's internal representation (0xc0, 0x80) to the official
|
||||
@@ -2296,7 +2296,7 @@ UtfToUtfProc(
|
||||
* output buffer. */
|
||||
int pureNullMode) /* Convert embedded nulls from internal
|
||||
* representation to real null-bytes or vice
|
||||
* versa. */
|
||||
* versa. Also combine or separate surrogate pairs */
|
||||
{
|
||||
const char *srcStart, *srcEnd, *srcClose;
|
||||
const char *dstStart, *dstEnd;
|
||||
@@ -2312,14 +2312,14 @@ UtfToUtfProc(
|
||||
srcEnd = src + srcLen;
|
||||
srcClose = srcEnd;
|
||||
if ((flags & TCL_ENCODING_END) == 0) {
|
||||
srcClose -= TCL_UTF_MAX;
|
||||
srcClose -= 6;
|
||||
}
|
||||
if (flags & TCL_ENCODING_CHAR_LIMIT) {
|
||||
charLimit = *dstCharsPtr;
|
||||
}
|
||||
|
||||
dstStart = dst;
|
||||
dstEnd = dst + dstLen - TCL_UTF_MAX;
|
||||
dstEnd = dst + dstLen - ((pureNullMode == 1) ? 4 : TCL_UTF_MAX);
|
||||
|
||||
for (numChars = 0; src < srcEnd && numChars <= charLimit; numChars++) {
|
||||
if ((src > srcClose) && (!Tcl_UtfCharComplete(src, srcEnd - src))) {
|
||||
@@ -2361,15 +2361,28 @@ UtfToUtfProc(
|
||||
src += 1;
|
||||
dst += Tcl_UniCharToUtf(*chPtr, dst);
|
||||
} else {
|
||||
int len = TclUtfToUniChar(src, chPtr);
|
||||
src += len;
|
||||
dst += Tcl_UniCharToUtf(*chPtr, dst);
|
||||
#if TCL_UTF_MAX == 4
|
||||
if ((*chPtr >= 0xD800) && (len < 3)) {
|
||||
src += TclUtfToUniChar(src + len, chPtr);
|
||||
dst += Tcl_UniCharToUtf(*chPtr, dst);
|
||||
src += TclUtfToUniChar(src, chPtr);
|
||||
if ((*chPtr & 0xFC00) == 0xD800) {
|
||||
/* A high surrogate character is detected, handle especially */
|
||||
Tcl_UniChar low = *chPtr;
|
||||
size_t len = (src <= srcEnd-3) ? Tcl_UtfToUniChar(src, &low) : 0;
|
||||
if ((low & 0xFC00) != 0xDC00) {
|
||||
*dst++ = (char) (((*chPtr >> 12) | 0xE0) & 0xEF);
|
||||
*dst++ = (char) (((*chPtr >> 6) | 0x80) & 0xBF);
|
||||
*dst++ = (char) ((*chPtr | 0x80) & 0xBF);
|
||||
continue;
|
||||
} else if (pureNullMode == 1) {
|
||||
int full = (((*chPtr & 0x3FF) << 10) | (low & 0x3FF)) + 0x10000;
|
||||
*dst++ = (char) (((full >> 18) | 0xF0) & 0xF7);
|
||||
*dst++ = (char) (((full >> 12) | 0x80) & 0xBF);
|
||||
*dst++ = (char) (((full >> 6) | 0x80) & 0xBF);
|
||||
*dst++ = (char) ((full | 0x80) & 0xBF);
|
||||
*chPtr = 0;
|
||||
src += len;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
dst += Tcl_UniCharToUtf(*chPtr, dst);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8497,7 +8497,7 @@ ExecuteExtendedBinaryMathOp(
|
||||
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.
|
||||
*/
|
||||
@@ -9028,7 +9028,7 @@ ExecuteExtendedBinaryMathOp(
|
||||
}
|
||||
Tcl_TakeBignumFromObj(NULL, valuePtr, &big1);
|
||||
mp_init(&bigResult);
|
||||
mp_expt_d(&big1, (mp_digit)w2, &bigResult);
|
||||
mp_expt_u32(&big1, (unsigned int)w2, &bigResult);
|
||||
mp_clear(&big1);
|
||||
BIG_RESULT(&bigResult);
|
||||
}
|
||||
|
||||
+1
-1
@@ -2897,7 +2897,7 @@ FlushChannel(
|
||||
* there is some kind failure in the writable event machinery.
|
||||
*
|
||||
* The tls extension indeed suffers from flaws in its channel
|
||||
* event mgmt. See http://core.tcl.tk/tcl/info/c31ca233ca.
|
||||
* event mgmt. See https://core.tcl-lang.org/tcl/info/c31ca233ca.
|
||||
* Until that patch is broadly distributed, disable the
|
||||
* assertion checking here, so that programs using Tcl and
|
||||
* tls can be debugged.
|
||||
|
||||
@@ -1037,6 +1037,9 @@ declare 256 {
|
||||
int TclPtrUnsetVar(Tcl_Interp *interp, Tcl_Var varPtr, Tcl_Var arrayPtr,
|
||||
Tcl_Obj *part1Ptr, Tcl_Obj *part2Ptr, const int flags)
|
||||
}
|
||||
declare 258 {
|
||||
void TclUnusedStubEntry(void)
|
||||
}
|
||||
|
||||
##############################################################################
|
||||
|
||||
|
||||
+3
-1
@@ -4039,6 +4039,8 @@ MODULE_SCOPE int TclIndexEncode(Tcl_Interp *interp, Tcl_Obj *objPtr,
|
||||
int before, int after, int *indexPtr);
|
||||
MODULE_SCOPE int TclIndexDecode(int encoded, int endValue);
|
||||
|
||||
MODULE_SCOPE void TclBN_s_mp_reverse(unsigned char *s, size_t len);
|
||||
|
||||
/* Constants used in index value encoding routines. */
|
||||
#define TCL_INDEX_END (-2)
|
||||
#define TCL_INDEX_BEFORE (-1)
|
||||
@@ -4427,7 +4429,7 @@ MODULE_SCOPE void TclDbInitNewObj(Tcl_Obj *objPtr, const char *file,
|
||||
*/
|
||||
|
||||
#define TclUtfToUniChar(str, chPtr) \
|
||||
((((unsigned char) *(str)) < 0xC0) ? \
|
||||
((((unsigned char) *(str)) < 0x80) ? \
|
||||
((*(chPtr) = (unsigned char) *(str)), 1) \
|
||||
: Tcl_UtfToUniChar(str, chPtr))
|
||||
|
||||
|
||||
@@ -638,6 +638,9 @@ EXTERN int TclPtrObjMakeUpvar(Tcl_Interp *interp,
|
||||
EXTERN int TclPtrUnsetVar(Tcl_Interp *interp, Tcl_Var varPtr,
|
||||
Tcl_Var arrayPtr, Tcl_Obj *part1Ptr,
|
||||
Tcl_Obj *part2Ptr, const int flags);
|
||||
/* Slot 257 is reserved */
|
||||
/* 258 */
|
||||
EXTERN void TclUnusedStubEntry(void);
|
||||
|
||||
typedef struct TclIntStubs {
|
||||
int magic;
|
||||
@@ -900,6 +903,8 @@ typedef struct TclIntStubs {
|
||||
Tcl_Obj * (*tclPtrIncrObjVar) (Tcl_Interp *interp, Tcl_Var varPtr, Tcl_Var arrayPtr, Tcl_Obj *part1Ptr, Tcl_Obj *part2Ptr, Tcl_Obj *incrPtr, const int flags); /* 254 */
|
||||
int (*tclPtrObjMakeUpvar) (Tcl_Interp *interp, Tcl_Var otherPtr, Tcl_Obj *myNamePtr, int myFlags); /* 255 */
|
||||
int (*tclPtrUnsetVar) (Tcl_Interp *interp, Tcl_Var varPtr, Tcl_Var arrayPtr, Tcl_Obj *part1Ptr, Tcl_Obj *part2Ptr, const int flags); /* 256 */
|
||||
void (*reserved257)(void);
|
||||
void (*tclUnusedStubEntry) (void); /* 258 */
|
||||
} TclIntStubs;
|
||||
|
||||
extern const TclIntStubs *tclIntStubsPtr;
|
||||
@@ -1341,6 +1346,9 @@ extern const TclIntStubs *tclIntStubsPtr;
|
||||
(tclIntStubsPtr->tclPtrObjMakeUpvar) /* 255 */
|
||||
#define TclPtrUnsetVar \
|
||||
(tclIntStubsPtr->tclPtrUnsetVar) /* 256 */
|
||||
/* Slot 257 is reserved */
|
||||
#define TclUnusedStubEntry \
|
||||
(tclIntStubsPtr->tclUnusedStubEntry) /* 258 */
|
||||
|
||||
#endif /* defined(USE_TCL_STUBS) */
|
||||
|
||||
|
||||
+29
-15
@@ -226,7 +226,7 @@ MODULE_SCOPE const TclOOStubs tclOOStubs;
|
||||
* ROOT_CLASS respectively.
|
||||
*/
|
||||
|
||||
#define Deleted(oPtr) ((oPtr)->flags & OBJECT_DELETED)
|
||||
#define Destructing(oPtr) ((oPtr)->flags & OBJECT_DESTRUCTING)
|
||||
#define IsRootObject(ocPtr) ((ocPtr)->flags & ROOT_OBJECT)
|
||||
#define IsRootClass(ocPtr) ((ocPtr)->flags & ROOT_CLASS)
|
||||
#define IsRoot(ocPtr) ((ocPtr)->flags & (ROOT_OBJECT|ROOT_CLASS))
|
||||
@@ -839,7 +839,7 @@ ObjectRenamedTrace(
|
||||
* 2950259].
|
||||
*/
|
||||
|
||||
if (!Deleted(oPtr)) {
|
||||
if (!Destructing(oPtr)) {
|
||||
Tcl_DeleteNamespace(oPtr->namespacePtr);
|
||||
}
|
||||
oPtr->command = NULL;
|
||||
@@ -879,7 +879,7 @@ TclOODeleteDescendants(
|
||||
* clsPtr
|
||||
*/
|
||||
|
||||
if (!Deleted(mixinSubclassPtr->thisPtr)
|
||||
if (!Destructing(mixinSubclassPtr->thisPtr)
|
||||
&& !(mixinSubclassPtr->thisPtr->flags & DONT_DELETE)) {
|
||||
Tcl_DeleteCommandFromToken(interp,
|
||||
mixinSubclassPtr->thisPtr->command);
|
||||
@@ -898,7 +898,7 @@ TclOODeleteDescendants(
|
||||
if (clsPtr->subclasses.num > 0) {
|
||||
while (clsPtr->subclasses.num > 0) {
|
||||
subclassPtr = clsPtr->subclasses.list[clsPtr->subclasses.num - 1];
|
||||
if (!Deleted(subclassPtr->thisPtr) && !IsRoot(subclassPtr)
|
||||
if (!Destructing(subclassPtr->thisPtr) && !IsRoot(subclassPtr)
|
||||
&& !(subclassPtr->thisPtr->flags & DONT_DELETE)) {
|
||||
Tcl_DeleteCommandFromToken(interp,
|
||||
subclassPtr->thisPtr->command);
|
||||
@@ -924,7 +924,7 @@ TclOODeleteDescendants(
|
||||
* This condition also covers the case where instancePtr == oPtr
|
||||
*/
|
||||
|
||||
if (!Deleted(instancePtr) && !IsRoot(instancePtr) &&
|
||||
if (!Destructing(instancePtr) && !IsRoot(instancePtr) &&
|
||||
!(instancePtr->flags & DONT_DELETE)) {
|
||||
Tcl_DeleteCommandFromToken(interp, instancePtr->command);
|
||||
}
|
||||
@@ -965,7 +965,7 @@ TclOOReleaseClassContents(
|
||||
* Sanity check!
|
||||
*/
|
||||
|
||||
if (!Deleted(oPtr)) {
|
||||
if (!Destructing(oPtr)) {
|
||||
if (IsRootClass(oPtr)) {
|
||||
Tcl_Panic("deleting class structure for non-deleted %s",
|
||||
"::oo::class");
|
||||
@@ -1063,7 +1063,7 @@ TclOOReleaseClassContents(
|
||||
ckfree(clsPtr->variables.list);
|
||||
}
|
||||
|
||||
if (IsRootClass(oPtr) && !Deleted(fPtr->objectCls->thisPtr)) {
|
||||
if (IsRootClass(oPtr) && !Destructing(fPtr->objectCls->thisPtr)) {
|
||||
Tcl_DeleteCommandFromToken(interp, fPtr->objectCls->thisPtr->command);
|
||||
}
|
||||
}
|
||||
@@ -1095,7 +1095,7 @@ ObjectNamespaceDeleted(
|
||||
Tcl_Interp *interp = oPtr->fPtr->interp;
|
||||
int i;
|
||||
|
||||
if (Deleted(oPtr)) {
|
||||
if (Destructing(oPtr)) {
|
||||
/*
|
||||
* TODO: Can ObjectNamespaceDeleted ever be called twice? If not,
|
||||
* this guard could be removed.
|
||||
@@ -1108,7 +1108,7 @@ ObjectNamespaceDeleted(
|
||||
* process of being deleted, nothing else may modify its bookeeping
|
||||
* records. This is the flag that
|
||||
*/
|
||||
oPtr->flags |= OBJECT_DELETED;
|
||||
oPtr->flags |= OBJECT_DESTRUCTING;
|
||||
|
||||
/*
|
||||
* Let the dominoes fall!
|
||||
@@ -1242,7 +1242,7 @@ ObjectNamespaceDeleted(
|
||||
* sometimes not go away automatically; we force it here. [Bug 2962664]
|
||||
*/
|
||||
|
||||
if (IsRootObject(oPtr) && !Deleted(fPtr->classCls->thisPtr)
|
||||
if (IsRootObject(oPtr) && !Destructing(fPtr->classCls->thisPtr)
|
||||
&& !Tcl_InterpDeleted(interp)) {
|
||||
|
||||
Tcl_DeleteCommandFromToken(interp, fPtr->classCls->thisPtr->command);
|
||||
@@ -1286,6 +1286,20 @@ int TclOODecrRefCount(Object *oPtr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* ----------------------------------------------------------------------
|
||||
*
|
||||
* TclOOObjectDestroyed --
|
||||
*
|
||||
* Returns TCL_OK if an object is entirely deleted, i.e. the destruction
|
||||
* sequence has completed.
|
||||
*
|
||||
* ----------------------------------------------------------------------
|
||||
*/
|
||||
int TclOOObjectDestroyed(Object *oPtr) {
|
||||
return (oPtr->namespacePtr == NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Setting the "empty" location to NULL makes debugging a little easier.
|
||||
*/
|
||||
@@ -1446,7 +1460,7 @@ TclOOAddToSubclasses(
|
||||
* is assumed that the class is not already
|
||||
* present as a subclass in the superclass. */
|
||||
{
|
||||
if (Deleted(superPtr->thisPtr)) {
|
||||
if (Destructing(superPtr->thisPtr)) {
|
||||
return;
|
||||
}
|
||||
if (superPtr->subclasses.num >= superPtr->subclasses.size) {
|
||||
@@ -1511,7 +1525,7 @@ TclOOAddToMixinSubs(
|
||||
* is assumed that the class is not already
|
||||
* present as a subclass in the superclass. */
|
||||
{
|
||||
if (Deleted(superPtr->thisPtr)) {
|
||||
if (Destructing(superPtr->thisPtr)) {
|
||||
return;
|
||||
}
|
||||
if (superPtr->mixinSubs.num >= superPtr->mixinSubs.size) {
|
||||
@@ -1809,7 +1823,7 @@ FinalizeAlloc(
|
||||
* Don't want to lose errors by accident. [Bug 2903011]
|
||||
*/
|
||||
|
||||
if (result != TCL_ERROR && Deleted(oPtr)) {
|
||||
if (result != TCL_ERROR && Destructing(oPtr)) {
|
||||
Tcl_SetObjResult(interp, Tcl_NewStringObj(
|
||||
"object deleted in constructor", -1));
|
||||
Tcl_SetErrorCode(interp, "TCL", "OO", "STILLBORN", NULL);
|
||||
@@ -1824,7 +1838,7 @@ FinalizeAlloc(
|
||||
* command before we delete it. [Bug 9dd1bd7a74]
|
||||
*/
|
||||
|
||||
if (!Deleted(oPtr)) {
|
||||
if (!Destructing(oPtr)) {
|
||||
(void) TclOOObjectName(interp, oPtr);
|
||||
Tcl_DeleteCommandFromToken(interp, oPtr->command);
|
||||
}
|
||||
@@ -1961,7 +1975,7 @@ Tcl_CopyObjectInstance(
|
||||
*/
|
||||
|
||||
o2Ptr->flags = oPtr->flags & ~(
|
||||
OBJECT_DELETED | ROOT_OBJECT | ROOT_CLASS | FILTER_HANDLING);
|
||||
OBJECT_DESTRUCTING | ROOT_OBJECT | ROOT_CLASS | FILTER_HANDLING);
|
||||
|
||||
/*
|
||||
* Copy the object's metadata.
|
||||
|
||||
+6
-8
@@ -189,14 +189,11 @@ typedef struct Object {
|
||||
LIST_STATIC(Tcl_Obj *) variables;
|
||||
} Object;
|
||||
|
||||
#define OBJECT_DELETED 1 /* Flag to say that an object has been
|
||||
* destroyed. */
|
||||
#define DESTRUCTOR_CALLED 2 /* Flag to say that the destructor has been
|
||||
* called. */
|
||||
#define CLASS_GONE 4 /* Obsolete. Indicates that the class of this
|
||||
* object has been deleted, and so the object
|
||||
* should not attempt to remove itself from its
|
||||
* class. */
|
||||
#define OBJECT_DESTRUCTING 1 /* Indicates that an object is being or has
|
||||
* been destroyed */
|
||||
#define DESTRUCTOR_CALLED 2 /* Indicates that evaluation of destructor script for the
|
||||
object has began */
|
||||
#define OO_UNUSED_4 4 /* No longer used. */
|
||||
#define ROOT_OBJECT 0x1000 /* Flag to say that this object is the root of
|
||||
* the class hierarchy and should be treated
|
||||
* specially during teardown. */
|
||||
@@ -497,6 +494,7 @@ MODULE_SCOPE Object * TclNewObjectInstanceCommon(Tcl_Interp *interp,
|
||||
const char *nameStr,
|
||||
const char *nsNameStr);
|
||||
MODULE_SCOPE int TclOODecrRefCount(Object *oPtr);
|
||||
MODULE_SCOPE int TclOOObjectDestroyed(Object *oPtr);
|
||||
MODULE_SCOPE int TclOODefineSlots(Foundation *fPtr);
|
||||
MODULE_SCOPE void TclOODeleteChain(CallChain *callPtr);
|
||||
MODULE_SCOPE void TclOODeleteChainCache(Tcl_HashTable *tablePtr);
|
||||
|
||||
@@ -671,11 +671,13 @@ InvokeProcedureMethod(
|
||||
* call frame's lifetime). */
|
||||
|
||||
/*
|
||||
* If the interpreter was deleted, we just skip to the next thing in the
|
||||
* chain.
|
||||
* If the object namespace (or interpreter) were deleted, we just skip to
|
||||
* the next thing in the chain.
|
||||
*/
|
||||
|
||||
if (Tcl_InterpDeleted(interp)) {
|
||||
if (TclOOObjectDestroyed(((CallContext *)context)->oPtr) ||
|
||||
Tcl_InterpDeleted(interp)
|
||||
) {
|
||||
return TclNRObjectContextInvokeNext(interp, context, objc, objv,
|
||||
Tcl_ObjectContextSkippedArgs(context));
|
||||
}
|
||||
|
||||
+11
-9
@@ -2806,11 +2806,12 @@ Tcl_GetLongFromObj(
|
||||
UNPACK_BIGNUM(objPtr, big);
|
||||
if ((size_t) big.used <= (CHAR_BIT * sizeof(long) + MP_DIGIT_BIT - 1)
|
||||
/ MP_DIGIT_BIT) {
|
||||
unsigned long value = 0, numBytes = sizeof(long);
|
||||
unsigned long value = 0;
|
||||
size_t numBytes;
|
||||
long scratch;
|
||||
unsigned char *bytes = (unsigned char *) &scratch;
|
||||
|
||||
if (mp_to_unsigned_bin_n(&big, bytes, &numBytes) == MP_OKAY) {
|
||||
if (mp_to_ubin(&big, bytes, sizeof(long), &numBytes) == MP_OKAY) {
|
||||
while (numBytes-- > 0) {
|
||||
value = (value << CHAR_BIT) | *bytes++;
|
||||
}
|
||||
@@ -3106,11 +3107,11 @@ Tcl_GetWideIntFromObj(
|
||||
if ((size_t) big.used <= (CHAR_BIT * sizeof(Tcl_WideInt)
|
||||
+ MP_DIGIT_BIT - 1) / MP_DIGIT_BIT) {
|
||||
Tcl_WideUInt value = 0;
|
||||
unsigned long numBytes = sizeof(Tcl_WideInt);
|
||||
size_t numBytes;
|
||||
Tcl_WideInt scratch;
|
||||
unsigned char *bytes = (unsigned char *) &scratch;
|
||||
|
||||
if (mp_to_unsigned_bin_n(&big, bytes, &numBytes) == MP_OKAY) {
|
||||
if (mp_to_ubin(&big, bytes, sizeof(Tcl_WideInt), &numBytes) == MP_OKAY) {
|
||||
while (numBytes-- > 0) {
|
||||
value = (value << CHAR_BIT) | *bytes++;
|
||||
}
|
||||
@@ -3269,7 +3270,7 @@ UpdateStringOfBignum(
|
||||
Tcl_Panic("UpdateStringOfBignum: string length limit exceeded");
|
||||
}
|
||||
stringVal = ckalloc(size);
|
||||
status = mp_toradix_n(&bignumVal, stringVal, 10, size);
|
||||
status = mp_to_radix(&bignumVal, stringVal, size, NULL, 10);
|
||||
if (status != MP_OKAY) {
|
||||
Tcl_Panic("conversion failure in UpdateStringOfBignum");
|
||||
}
|
||||
@@ -3524,11 +3525,12 @@ Tcl_SetBignumObj(
|
||||
}
|
||||
if ((size_t) bignumValue->used
|
||||
<= (CHAR_BIT * sizeof(long) + MP_DIGIT_BIT - 1) / MP_DIGIT_BIT) {
|
||||
unsigned long value = 0, numBytes = sizeof(long);
|
||||
unsigned long value = 0;
|
||||
size_t numBytes;
|
||||
long scratch;
|
||||
unsigned char *bytes = (unsigned char *) &scratch;
|
||||
|
||||
if (mp_to_unsigned_bin_n(bignumValue, bytes, &numBytes) != MP_OKAY) {
|
||||
if (mp_to_ubin(bignumValue, bytes, sizeof(long), &numBytes) != MP_OKAY) {
|
||||
goto tooLargeForLong;
|
||||
}
|
||||
while (numBytes-- > 0) {
|
||||
@@ -3550,11 +3552,11 @@ Tcl_SetBignumObj(
|
||||
if ((size_t) bignumValue->used
|
||||
<= (CHAR_BIT * sizeof(Tcl_WideInt) + MP_DIGIT_BIT - 1) / MP_DIGIT_BIT) {
|
||||
Tcl_WideUInt value = 0;
|
||||
unsigned long numBytes = sizeof(Tcl_WideInt);
|
||||
size_t numBytes;
|
||||
Tcl_WideInt scratch;
|
||||
unsigned char *bytes = (unsigned char *)&scratch;
|
||||
|
||||
if (mp_to_unsigned_bin_n(bignumValue, bytes, &numBytes) != MP_OKAY) {
|
||||
if (mp_to_ubin(bignumValue, bytes, sizeof(Tcl_WideInt), &numBytes) != MP_OKAY) {
|
||||
goto tooLargeForWide;
|
||||
}
|
||||
while (numBytes-- > 0) {
|
||||
|
||||
@@ -2148,6 +2148,7 @@ Tcl_FSGetInternalRep(
|
||||
nativePathPtr = proc(pathPtr);
|
||||
srcFsPathPtr = PATHOBJ(pathPtr);
|
||||
srcFsPathPtr->nativePathPtr = nativePathPtr;
|
||||
srcFsPathPtr->filesystemEpoch = TclFSEpoch();
|
||||
}
|
||||
|
||||
return srcFsPathPtr->nativePathPtr;
|
||||
|
||||
+10
-8
@@ -585,9 +585,6 @@ Tcl_ScanObjCmd(
|
||||
Tcl_UniChar ch = 0, sch = 0;
|
||||
Tcl_Obj **objs = NULL, *objPtr = NULL;
|
||||
int flags;
|
||||
char buf[513]; /* Temporary buffer to hold scanned number
|
||||
* strings before they are passed to
|
||||
* strtoul. */
|
||||
|
||||
if (objc < 3) {
|
||||
Tcl_WrongNumArgs(interp, 1, objv,
|
||||
@@ -937,9 +934,9 @@ Tcl_ScanObjCmd(
|
||||
}
|
||||
}
|
||||
if ((flags & SCAN_UNSIGNED) && (wideValue < 0)) {
|
||||
sprintf(buf, "%" TCL_LL_MODIFIER "u",
|
||||
(Tcl_WideUInt)wideValue);
|
||||
Tcl_SetStringObj(objPtr, buf, -1);
|
||||
mp_int big;
|
||||
TclBNInitBignumFromWideUInt(&big, (Tcl_WideUInt)wideValue);
|
||||
Tcl_SetBignumObj(objPtr, &big);
|
||||
} else {
|
||||
Tcl_SetWideIntObj(objPtr, wideValue);
|
||||
}
|
||||
@@ -952,8 +949,13 @@ Tcl_ScanObjCmd(
|
||||
}
|
||||
}
|
||||
if ((flags & SCAN_UNSIGNED) && (value < 0)) {
|
||||
sprintf(buf, "%lu", value); /* INTL: ISO digit */
|
||||
Tcl_SetStringObj(objPtr, buf, -1);
|
||||
#ifdef TCL_WIDE_INT_IS_LONG
|
||||
mp_int big;
|
||||
TclBNInitBignumFromWideUInt(&big, (unsigned long)value);
|
||||
Tcl_SetBignumObj(objPtr, &big);
|
||||
#else
|
||||
Tcl_SetWideIntObj(objPtr, (unsigned long)value);
|
||||
#endif
|
||||
} else {
|
||||
Tcl_SetLongObj(objPtr, value);
|
||||
}
|
||||
|
||||
+26
-26
@@ -152,7 +152,7 @@ typedef unsigned int fpu_control_t __attribute__ ((__mode__ (__HI__)));
|
||||
#define QUICK_MAX 14 /* floor((FP_PRECISION-1)*log(2)/log(10))-1 */
|
||||
#define BLETCH 0x10 /* 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)) */
|
||||
#define DIGIT_GROUP 8 /* floor(MP_DIGIT_BIT*log(2)/log(10)) */
|
||||
|
||||
/*
|
||||
* Union used to dismantle floating point numbers.
|
||||
@@ -1491,9 +1491,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;
|
||||
@@ -3146,7 +3146,7 @@ StrictInt64Conversion(
|
||||
*
|
||||
* 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.
|
||||
* 2**MP_DIGIT_BIT.
|
||||
*
|
||||
* Results:
|
||||
* Returns 1 iff the fraction is more than 1/2, or if the fraction is
|
||||
@@ -3158,7 +3158,7 @@ StrictInt64Conversion(
|
||||
static inline 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;
|
||||
@@ -3197,7 +3197,7 @@ static inline int
|
||||
ShouldBankerRoundUpToNextPowD(
|
||||
mp_int *b, /* Numerator of the fraction. */
|
||||
mp_int *m, /* Numerator of the rounding tolerance. */
|
||||
int sd, /* Common denominator is 2**(sd*DIGIT_BIT). */
|
||||
int sd, /* Common denominator is 2**(sd*MP_DIGIT_BIT). */
|
||||
int convType, /* Conversion type: STEELE defeats
|
||||
* round-to-even (not sure why one wants to do
|
||||
* this; I copied it from Gay). FIXME */
|
||||
@@ -3209,7 +3209,7 @@ ShouldBankerRoundUpToNextPowD(
|
||||
/*
|
||||
* 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);
|
||||
@@ -3241,7 +3241,7 @@ ShouldBankerRoundUpToNextPowD(
|
||||
* Converts a double-precision number to the shortest string of 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
|
||||
* conversion algorithm is known to 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.
|
||||
*
|
||||
@@ -3323,7 +3323,7 @@ ShorteningBignumConversionPowD(
|
||||
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.
|
||||
*/
|
||||
|
||||
@@ -3435,7 +3435,7 @@ ShorteningBignumConversionPowD(
|
||||
* 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 loop may be
|
||||
* of 2**MP_DIGIT_BIT, and hence the division in the main loop may be
|
||||
* replaced by a digit shift and mask.
|
||||
*
|
||||
* Results:
|
||||
@@ -3496,7 +3496,7 @@ StrictBignumConversionPowD(
|
||||
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.
|
||||
*/
|
||||
|
||||
@@ -4262,7 +4262,7 @@ TclDoubleDigits(
|
||||
} else if (s5 == 0) {
|
||||
/*
|
||||
* 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,
|
||||
* digit shifts. First we round up s2 to a multiple of 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.
|
||||
@@ -4318,7 +4318,7 @@ TclDoubleDigits(
|
||||
} else if (s5 == 0) {
|
||||
/*
|
||||
* 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,
|
||||
* digit shifts. First we round up s2 to a multiple of 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.
|
||||
@@ -4599,10 +4599,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;
|
||||
@@ -4632,10 +4632,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 {
|
||||
@@ -4645,10 +4645,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);
|
||||
}
|
||||
@@ -4674,10 +4674,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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4850,7 +4850,7 @@ BignumToBiasedFrExp(
|
||||
*/
|
||||
|
||||
*machexp = bits - mantBits + 2;
|
||||
return ((a->sign == MP_ZPOS) ? r : -r);
|
||||
return (mp_isneg(a) ? -r : r);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
+81
-4
@@ -10,7 +10,7 @@
|
||||
*/
|
||||
|
||||
#include "tclInt.h"
|
||||
#include "tommath.h"
|
||||
#include "tommath_private.h"
|
||||
|
||||
#ifdef __CYGWIN__
|
||||
# include <wchar.h>
|
||||
@@ -57,6 +57,7 @@
|
||||
#define TclBN_mp_tc_and TclBN_mp_and
|
||||
#define TclBN_mp_tc_or TclBN_mp_or
|
||||
#define TclBN_mp_tc_xor TclBN_mp_xor
|
||||
#define TclUnusedStubEntry NULL
|
||||
|
||||
/* See bug 510001: TclSockMinimumBuffers needs plat imp */
|
||||
#ifdef _WIN64
|
||||
@@ -69,6 +70,29 @@ static int TclSockMinimumBuffersOld(int sock, int size)
|
||||
}
|
||||
#endif
|
||||
|
||||
MP_SET_UNSIGNED(mp_set_ull, Tcl_WideUInt)
|
||||
|
||||
|
||||
mp_err TclBN_mp_set_int(mp_int *a, unsigned long i)
|
||||
{
|
||||
mp_set_ull(a, i);
|
||||
return MP_OKAY;
|
||||
}
|
||||
|
||||
mp_err TclBN_mp_init_set_int(mp_int *a, unsigned long i)
|
||||
{
|
||||
mp_err result = mp_init(a);
|
||||
if (result == MP_OKAY) {
|
||||
mp_set_ull(a, i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int TclBN_mp_expt_d_ex(const mp_int *a, mp_digit b, mp_int *c, int fast)
|
||||
{
|
||||
return mp_expt_u32(a, b, c);
|
||||
}
|
||||
|
||||
#define TclSetStartupScriptPath setStartupScriptPath
|
||||
static void TclSetStartupScriptPath(Tcl_Obj *path)
|
||||
{
|
||||
@@ -399,6 +423,36 @@ static int formatInt(char *buffer, int n){
|
||||
# define TclpGmtime_unix TclpGmtime
|
||||
#endif
|
||||
|
||||
mp_err mp_to_unsigned_bin(const mp_int *a, unsigned char *b)
|
||||
{
|
||||
return mp_to_ubin(a, b, INT_MAX, NULL);
|
||||
}
|
||||
|
||||
mp_err mp_to_unsigned_bin_n(const mp_int *a, unsigned char *b, unsigned long *outlen)
|
||||
{
|
||||
size_t n = mp_ubin_size(a);
|
||||
if (*outlen < (unsigned long)n) {
|
||||
return MP_VAL;
|
||||
}
|
||||
*outlen = (unsigned long)n;
|
||||
return mp_to_ubin(a, b, n, NULL);
|
||||
}
|
||||
|
||||
mp_err mp_toradix_n(const mp_int *a, char *str, int radix, int maxlen)
|
||||
{
|
||||
if (maxlen < 0) {
|
||||
return MP_VAL;
|
||||
}
|
||||
return mp_to_radix(a, str, (size_t)maxlen, NULL, radix);
|
||||
}
|
||||
|
||||
void bn_reverse(unsigned char *s, int len)
|
||||
{
|
||||
if (len > 0) {
|
||||
s_mp_reverse(s, (size_t)len);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* WARNING: The contents of this file is automatically generated by the
|
||||
* tools/genStubs.tcl script. Any modifications to the function declarations
|
||||
@@ -670,6 +724,8 @@ static const TclIntStubs tclIntStubs = {
|
||||
TclPtrIncrObjVar, /* 254 */
|
||||
TclPtrObjMakeUpvar, /* 255 */
|
||||
TclPtrUnsetVar, /* 256 */
|
||||
0, /* 257 */
|
||||
TclUnusedStubEntry, /* 258 */
|
||||
};
|
||||
|
||||
static const TclIntPlatStubs tclIntPlatStubs = {
|
||||
@@ -860,16 +916,19 @@ const TclTomMathStubs tclTomMathStubs = {
|
||||
TclBNInitBignumFromWideInt, /* 65 */
|
||||
TclBNInitBignumFromWideUInt, /* 66 */
|
||||
TclBN_mp_expt_d_ex, /* 67 */
|
||||
0, /* 68 */
|
||||
TclBN_mp_set_ull, /* 68 */
|
||||
0, /* 69 */
|
||||
TclBN_mp_set_long, /* 70 */
|
||||
0, /* 70 */
|
||||
0, /* 71 */
|
||||
0, /* 72 */
|
||||
TclBN_mp_tc_and, /* 73 */
|
||||
TclBN_mp_tc_or, /* 74 */
|
||||
TclBN_mp_tc_xor, /* 75 */
|
||||
TclBN_mp_signed_rsh, /* 76 */
|
||||
TclBN_mp_get_bit, /* 77 */
|
||||
0, /* 77 */
|
||||
TclBN_mp_to_ubin, /* 78 */
|
||||
0, /* 79 */
|
||||
TclBN_mp_to_radix, /* 80 */
|
||||
};
|
||||
|
||||
static const TclStubHooks tclStubHooks = {
|
||||
@@ -1536,6 +1595,24 @@ const TclStubs tclStubs = {
|
||||
Tcl_FindSymbol, /* 628 */
|
||||
Tcl_FSUnloadFile, /* 629 */
|
||||
Tcl_ZlibStreamSetCompressionDictionary, /* 630 */
|
||||
0, /* 631 */
|
||||
0, /* 632 */
|
||||
0, /* 633 */
|
||||
0, /* 634 */
|
||||
0, /* 635 */
|
||||
0, /* 636 */
|
||||
0, /* 637 */
|
||||
0, /* 638 */
|
||||
0, /* 639 */
|
||||
0, /* 640 */
|
||||
0, /* 641 */
|
||||
0, /* 642 */
|
||||
0, /* 643 */
|
||||
0, /* 644 */
|
||||
0, /* 645 */
|
||||
0, /* 646 */
|
||||
0, /* 647 */
|
||||
TclUnusedStubEntry, /* 648 */
|
||||
};
|
||||
|
||||
/* !END!: Do not edit above this line. */
|
||||
|
||||
@@ -131,7 +131,7 @@ TclObjTest_Init(
|
||||
*
|
||||
* TestbignumobjCmd --
|
||||
*
|
||||
* This function implmenets the "testbignumobj" command. It is used
|
||||
* This function implements the "testbignumobj" command. It is used
|
||||
* to exercise the bignum Tcl object type implementation.
|
||||
*
|
||||
* Results:
|
||||
|
||||
+69
-65
@@ -30,13 +30,13 @@ declare 1 {
|
||||
}
|
||||
|
||||
declare 2 {
|
||||
int TclBN_mp_add(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
mp_err TclBN_mp_add(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
}
|
||||
declare 3 {
|
||||
int TclBN_mp_add_d(const mp_int *a, mp_digit b, mp_int *c)
|
||||
mp_err TclBN_mp_add_d(const mp_int *a, mp_digit b, mp_int *c)
|
||||
}
|
||||
declare 4 {
|
||||
int TclBN_mp_and(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
mp_err TclBN_mp_and(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
}
|
||||
declare 5 {
|
||||
void TclBN_mp_clamp(mp_int *a)
|
||||
@@ -48,128 +48,128 @@ declare 7 {
|
||||
void TclBN_mp_clear_multi(mp_int *a, ...)
|
||||
}
|
||||
declare 8 {
|
||||
int TclBN_mp_cmp(const mp_int *a, const mp_int *b)
|
||||
mp_ord TclBN_mp_cmp(const mp_int *a, const mp_int *b)
|
||||
}
|
||||
declare 9 {
|
||||
int TclBN_mp_cmp_d(const mp_int *a, mp_digit b)
|
||||
mp_ord TclBN_mp_cmp_d(const mp_int *a, mp_digit b)
|
||||
}
|
||||
declare 10 {
|
||||
int TclBN_mp_cmp_mag(const mp_int *a, const mp_int *b)
|
||||
mp_ord TclBN_mp_cmp_mag(const mp_int *a, const mp_int *b)
|
||||
}
|
||||
declare 11 {
|
||||
int TclBN_mp_copy(const mp_int *a, mp_int *b)
|
||||
mp_err TclBN_mp_copy(const mp_int *a, mp_int *b)
|
||||
}
|
||||
declare 12 {
|
||||
int TclBN_mp_count_bits(const mp_int *a)
|
||||
}
|
||||
declare 13 {
|
||||
int TclBN_mp_div(const mp_int *a, const mp_int *b, mp_int *q, mp_int *r)
|
||||
mp_err TclBN_mp_div(const mp_int *a, const mp_int *b, mp_int *q, mp_int *r)
|
||||
}
|
||||
declare 14 {
|
||||
int TclBN_mp_div_d(const mp_int *a, mp_digit b, mp_int *q, mp_digit *r)
|
||||
mp_err TclBN_mp_div_d(const mp_int *a, mp_digit b, mp_int *q, mp_digit *r)
|
||||
}
|
||||
declare 15 {
|
||||
int TclBN_mp_div_2(const mp_int *a, mp_int *q)
|
||||
mp_err TclBN_mp_div_2(const mp_int *a, mp_int *q)
|
||||
}
|
||||
declare 16 {
|
||||
int TclBN_mp_div_2d(const mp_int *a, int b, mp_int *q, mp_int *r)
|
||||
mp_err TclBN_mp_div_2d(const mp_int *a, int b, mp_int *q, mp_int *r)
|
||||
}
|
||||
declare 17 {
|
||||
int TclBN_mp_div_3(const mp_int *a, mp_int *q, mp_digit *r)
|
||||
mp_err TclBN_mp_div_3(const mp_int *a, mp_int *q, mp_digit *r)
|
||||
}
|
||||
declare 18 {
|
||||
void TclBN_mp_exch(mp_int *a, mp_int *b)
|
||||
}
|
||||
declare 19 {
|
||||
int TclBN_mp_expt_d(const mp_int *a, mp_digit b, mp_int *c)
|
||||
mp_err TclBN_mp_expt_d(const mp_int *a, unsigned int b, mp_int *c)
|
||||
}
|
||||
declare 20 {
|
||||
int TclBN_mp_grow(mp_int *a, int size)
|
||||
mp_err TclBN_mp_grow(mp_int *a, int size)
|
||||
}
|
||||
declare 21 {
|
||||
int TclBN_mp_init(mp_int *a)
|
||||
mp_err TclBN_mp_init(mp_int *a)
|
||||
}
|
||||
declare 22 {
|
||||
int TclBN_mp_init_copy(mp_int *a, const mp_int *b)
|
||||
mp_err TclBN_mp_init_copy(mp_int *a, const mp_int *b)
|
||||
}
|
||||
declare 23 {
|
||||
int TclBN_mp_init_multi(mp_int *a, ...)
|
||||
mp_err TclBN_mp_init_multi(mp_int *a, ...)
|
||||
}
|
||||
declare 24 {
|
||||
int TclBN_mp_init_set(mp_int *a, mp_digit b)
|
||||
mp_err TclBN_mp_init_set(mp_int *a, mp_digit b)
|
||||
}
|
||||
declare 25 {
|
||||
int TclBN_mp_init_size(mp_int *a, int size)
|
||||
mp_err TclBN_mp_init_size(mp_int *a, int size)
|
||||
}
|
||||
declare 26 {
|
||||
int TclBN_mp_lshd(mp_int *a, int shift)
|
||||
mp_err TclBN_mp_lshd(mp_int *a, int shift)
|
||||
}
|
||||
declare 27 {
|
||||
int TclBN_mp_mod(const mp_int *a, const mp_int *b, mp_int *r)
|
||||
mp_err TclBN_mp_mod(const mp_int *a, const mp_int *b, mp_int *r)
|
||||
}
|
||||
declare 28 {
|
||||
int TclBN_mp_mod_2d(const mp_int *a, int b, mp_int *r)
|
||||
mp_err TclBN_mp_mod_2d(const mp_int *a, int b, mp_int *r)
|
||||
}
|
||||
declare 29 {
|
||||
int TclBN_mp_mul(const mp_int *a, const mp_int *b, mp_int *p)
|
||||
mp_err TclBN_mp_mul(const mp_int *a, const mp_int *b, mp_int *p)
|
||||
}
|
||||
declare 30 {
|
||||
int TclBN_mp_mul_d(const mp_int *a, mp_digit b, mp_int *p)
|
||||
mp_err TclBN_mp_mul_d(const mp_int *a, mp_digit b, mp_int *p)
|
||||
}
|
||||
declare 31 {
|
||||
int TclBN_mp_mul_2(const mp_int *a, mp_int *p)
|
||||
mp_err TclBN_mp_mul_2(const mp_int *a, mp_int *p)
|
||||
}
|
||||
declare 32 {
|
||||
int TclBN_mp_mul_2d(const mp_int *a, int d, mp_int *p)
|
||||
mp_err TclBN_mp_mul_2d(const mp_int *a, int d, mp_int *p)
|
||||
}
|
||||
declare 33 {
|
||||
int TclBN_mp_neg(const mp_int *a, mp_int *b)
|
||||
mp_err TclBN_mp_neg(const mp_int *a, mp_int *b)
|
||||
}
|
||||
declare 34 {
|
||||
int TclBN_mp_or(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
mp_err TclBN_mp_or(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
}
|
||||
declare 35 {
|
||||
int TclBN_mp_radix_size(const mp_int *a, int radix, int *size)
|
||||
mp_err TclBN_mp_radix_size(const mp_int *a, int radix, int *size)
|
||||
}
|
||||
declare 36 {
|
||||
int TclBN_mp_read_radix(mp_int *a, const char *str, int radix)
|
||||
mp_err TclBN_mp_read_radix(mp_int *a, const char *str, int radix)
|
||||
}
|
||||
declare 37 {
|
||||
void TclBN_mp_rshd(mp_int *a, int shift)
|
||||
}
|
||||
declare 38 {
|
||||
int TclBN_mp_shrink(mp_int *a)
|
||||
mp_err TclBN_mp_shrink(mp_int *a)
|
||||
}
|
||||
declare 39 {
|
||||
void TclBN_mp_set(mp_int *a, mp_digit b)
|
||||
}
|
||||
declare 40 {
|
||||
int TclBN_mp_sqr(const mp_int *a, mp_int *b)
|
||||
mp_err TclBN_mp_sqr(const mp_int *a, mp_int *b)
|
||||
}
|
||||
declare 41 {
|
||||
int TclBN_mp_sqrt(const mp_int *a, mp_int *b)
|
||||
mp_err TclBN_mp_sqrt(const mp_int *a, mp_int *b)
|
||||
}
|
||||
declare 42 {
|
||||
int TclBN_mp_sub(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
mp_err TclBN_mp_sub(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
}
|
||||
declare 43 {
|
||||
int TclBN_mp_sub_d(const mp_int *a, mp_digit b, mp_int *c)
|
||||
mp_err TclBN_mp_sub_d(const mp_int *a, mp_digit b, mp_int *c)
|
||||
}
|
||||
declare 44 {
|
||||
int TclBN_mp_to_unsigned_bin(const mp_int *a, unsigned char *b)
|
||||
mp_err TclBN_mp_to_unsigned_bin(const mp_int *a, unsigned char *b)
|
||||
}
|
||||
declare 45 {
|
||||
int TclBN_mp_to_unsigned_bin_n(const mp_int *a, unsigned char *b,
|
||||
mp_err TclBN_mp_to_unsigned_bin_n(const mp_int *a, unsigned char *b,
|
||||
unsigned long *outlen)
|
||||
}
|
||||
declare 46 {
|
||||
int TclBN_mp_toradix_n(const mp_int *a, char *str, int radix, int maxlen)
|
||||
mp_err TclBN_mp_toradix_n(const mp_int *a, char *str, int radix, int maxlen)
|
||||
}
|
||||
declare 47 {
|
||||
int TclBN_mp_unsigned_bin_size(const mp_int *a)
|
||||
size_t TclBN_mp_unsigned_bin_size(const mp_int *a)
|
||||
}
|
||||
declare 48 {
|
||||
int TclBN_mp_xor(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
mp_err TclBN_mp_xor(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
}
|
||||
declare 49 {
|
||||
void TclBN_mp_zero(mp_int *a)
|
||||
@@ -182,40 +182,40 @@ declare 50 {
|
||||
void TclBN_reverse(unsigned char *s, int len)
|
||||
}
|
||||
declare 51 {
|
||||
int TclBN_fast_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs)
|
||||
mp_err TclBN_fast_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs)
|
||||
}
|
||||
declare 52 {
|
||||
int TclBN_fast_s_mp_sqr(const mp_int *a, mp_int *b)
|
||||
mp_err TclBN_fast_s_mp_sqr(const mp_int *a, mp_int *b)
|
||||
}
|
||||
declare 53 {
|
||||
int TclBN_mp_karatsuba_mul(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
mp_err TclBN_mp_karatsuba_mul(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
}
|
||||
declare 54 {
|
||||
int TclBN_mp_karatsuba_sqr(const mp_int *a, mp_int *b)
|
||||
mp_err TclBN_mp_karatsuba_sqr(const mp_int *a, mp_int *b)
|
||||
}
|
||||
declare 55 {
|
||||
int TclBN_mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
mp_err TclBN_mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
}
|
||||
declare 56 {
|
||||
int TclBN_mp_toom_sqr(const mp_int *a, mp_int *b)
|
||||
mp_err TclBN_mp_toom_sqr(const mp_int *a, mp_int *b)
|
||||
}
|
||||
declare 57 {
|
||||
int TclBN_s_mp_add(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
mp_err TclBN_s_mp_add(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
}
|
||||
declare 58 {
|
||||
int TclBN_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs)
|
||||
mp_err TclBN_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs)
|
||||
}
|
||||
declare 59 {
|
||||
int TclBN_s_mp_sqr(const mp_int *a, mp_int *b)
|
||||
mp_err TclBN_s_mp_sqr(const mp_int *a, mp_int *b)
|
||||
}
|
||||
declare 60 {
|
||||
int TclBN_s_mp_sub(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
mp_err TclBN_s_mp_sub(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
}
|
||||
declare 61 {
|
||||
int TclBN_mp_init_set_int(mp_int *a, unsigned long i)
|
||||
mp_err TclBN_mp_init_set_int(mp_int *a, unsigned long i)
|
||||
}
|
||||
declare 62 {
|
||||
int TclBN_mp_set_int(mp_int *a, unsigned long i)
|
||||
mp_err TclBN_mp_set_int(mp_int *a, unsigned long i)
|
||||
}
|
||||
declare 63 {
|
||||
int TclBN_mp_cnt_lsb(const mp_int *a)
|
||||
@@ -224,39 +224,43 @@ declare 63 {
|
||||
# Formerly internal API to allow initialisation of bignums without knowing the
|
||||
# typedefs of how a bignum works internally.
|
||||
declare 64 {
|
||||
void TclBNInitBignumFromLong(mp_int *bignum, long initVal)
|
||||
int TclBNInitBignumFromLong(mp_int *bignum, long initVal)
|
||||
}
|
||||
declare 65 {
|
||||
void TclBNInitBignumFromWideInt(mp_int *bignum, Tcl_WideInt initVal)
|
||||
int TclBNInitBignumFromWideInt(mp_int *bignum, Tcl_WideInt initVal)
|
||||
}
|
||||
declare 66 {
|
||||
void TclBNInitBignumFromWideUInt(mp_int *bignum, Tcl_WideUInt initVal)
|
||||
int TclBNInitBignumFromWideUInt(mp_int *bignum, Tcl_WideUInt initVal)
|
||||
}
|
||||
|
||||
# Added in libtommath 1.0
|
||||
declare 67 {
|
||||
int TclBN_mp_expt_d_ex(const mp_int *a, mp_digit b, mp_int *c, int fast)
|
||||
mp_err TclBN_mp_expt_d_ex(const mp_int *a, mp_digit b, mp_int *c, int fast)
|
||||
}
|
||||
declare 70 {
|
||||
int TclBN_mp_set_long(mp_int *a, unsigned long i)
|
||||
# Added in libtommath 1.0.1
|
||||
declare 68 {
|
||||
void TclBN_mp_set_ull(mp_int *a, Tcl_WideUInt i)
|
||||
}
|
||||
|
||||
# Added in libtommath 1.1.0
|
||||
declare 73 {
|
||||
int TclBN_mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
mp_err TclBN_mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
}
|
||||
declare 74 {
|
||||
int TclBN_mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
mp_err TclBN_mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
}
|
||||
declare 75 {
|
||||
int TclBN_mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
mp_err TclBN_mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
}
|
||||
declare 76 {
|
||||
int TclBN_mp_signed_rsh(const mp_int *a, int b, mp_int *c)
|
||||
mp_err TclBN_mp_signed_rsh(const mp_int *a, int b, mp_int *c)
|
||||
}
|
||||
|
||||
declare 77 {
|
||||
int TclBN_mp_get_bit(const mp_int *a, int b)
|
||||
# Added in libtommath 1.2.0
|
||||
declare 78 {
|
||||
int TclBN_mp_to_ubin(const mp_int *a, unsigned char *buf, size_t maxlen, size_t *written)
|
||||
}
|
||||
declare 80 {
|
||||
int TclBN_mp_to_radix(const mp_int *a, char *str, size_t maxlen, size_t *written, int radix)
|
||||
}
|
||||
|
||||
|
||||
|
||||
+479
-207
File diff suppressed because it is too large
Load Diff
+219
-154
@@ -16,6 +16,9 @@
|
||||
#define _TCLTOMMATHDECLS
|
||||
|
||||
#include "tcl.h"
|
||||
#ifndef BN_H_
|
||||
#include "tclTomMath.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Define the version of the Stubs table that's exported for tommath
|
||||
@@ -32,24 +35,22 @@
|
||||
|
||||
/* MODULE_SCOPE void* TclBNAlloc( size_t ); */
|
||||
#define TclBNAlloc(s) ((void*)ckalloc((size_t)(s)))
|
||||
/* MODULE_SCOPE void* TclBNCalloc( size_t, size_t ); */
|
||||
#define TclBNCalloc(m,s) memset(ckalloc((size_t)(m)*(size_t)(s)),0,(size_t)(m)*(size_t)(s))
|
||||
/* MODULE_SCOPE void* TclBNRealloc( void*, size_t ); */
|
||||
#define TclBNRealloc(x,s) ((void*)ckrealloc((char*)(x),(size_t)(s)))
|
||||
/* MODULE_SCOPE void TclBNFree( void* ); */
|
||||
#define TclBNFree(x) (ckfree((char*)(x)))
|
||||
|
||||
#define XMALLOC(size) TclBNAlloc(size)
|
||||
#define XFREE(mem, size) TclBNFree(mem)
|
||||
#define XREALLOC(mem, oldsize, newsize) TclBNRealloc(mem, newsize)
|
||||
#define MP_MALLOC(size) TclBNAlloc(size)
|
||||
#define MP_CALLOC(nmemb, size) TclBNCalloc(nmemb, size)
|
||||
#define MP_REALLOC(mem, oldsize, newsize) TclBNRealloc(mem, newsize)
|
||||
#define MP_FREE(mem, size) TclBNFree(mem)
|
||||
|
||||
|
||||
/* Rename the global symbols in libtommath to avoid linkage conflicts */
|
||||
|
||||
#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
|
||||
@@ -70,8 +71,7 @@
|
||||
#define mp_exch TclBN_mp_exch
|
||||
#define mp_expt_d TclBN_mp_expt_d
|
||||
#define mp_expt_d_ex TclBN_mp_expt_d_ex
|
||||
#define mp_get_bit TclBN_mp_get_bit
|
||||
#define s_mp_get_bit TclBN_mp_get_bit
|
||||
#define mp_expt_u32 TclBN_mp_expt_d
|
||||
#define mp_grow TclBN_mp_grow
|
||||
#define mp_init TclBN_mp_init
|
||||
#define mp_init_copy TclBN_mp_init_copy
|
||||
@@ -79,10 +79,6 @@
|
||||
#define mp_init_set TclBN_mp_init_set
|
||||
#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
|
||||
@@ -96,8 +92,11 @@
|
||||
#define mp_read_radix TclBN_mp_read_radix
|
||||
#define mp_rshd TclBN_mp_rshd
|
||||
#define mp_set TclBN_mp_set
|
||||
#define mp_set_int TclBN_mp_set_int
|
||||
#define mp_set_long TclBN_mp_set_long
|
||||
#define mp_set_int(a,b) (TclBN_mp_set_int(a,(unsigned int)(b)),MP_OKAY)
|
||||
#define mp_set_long(a,b) (TclBN_mp_set_int(a,b),MP_OKAY)
|
||||
#define mp_set_ul(a,b) (void)TclBN_mp_set_int(a,b)
|
||||
#define mp_set_ull TclBN_mp_set_ull
|
||||
#define mp_set_u64 TclBN_mp_set_ull
|
||||
#define mp_shrink TclBN_mp_shrink
|
||||
#define mp_sqr TclBN_mp_sqr
|
||||
#define mp_sqrt TclBN_mp_sqrt
|
||||
@@ -110,18 +109,25 @@
|
||||
#define mp_tc_xor TclBN_mp_xor
|
||||
#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_to_radix TclBN_mp_to_radix
|
||||
#define mp_to_ubin TclBN_mp_to_ubin
|
||||
#define mp_ubin_size TclBN_mp_unsigned_bin_size
|
||||
#define mp_unsigned_bin_size(a) ((int)TclBN_mp_unsigned_bin_size(a))
|
||||
#define mp_xor TclBN_mp_xor
|
||||
#define mp_zero TclBN_mp_zero
|
||||
#define s_mp_add TclBN_s_mp_add
|
||||
#define s_mp_balance_mul TclBN_mp_balance_mul
|
||||
#define s_mp_karatsuba_mul TclBN_mp_karatsuba_mul
|
||||
#define s_mp_karatsuba_sqr TclBN_mp_karatsuba_sqr
|
||||
#define s_mp_mul_digs TclBN_s_mp_mul_digs
|
||||
#define s_mp_mul_digs_fast TclBN_fast_s_mp_mul_digs
|
||||
#define s_mp_reverse TclBN_s_mp_reverse
|
||||
#define s_mp_sqr TclBN_s_mp_sqr
|
||||
#define s_mp_sqr_fast TclBN_fast_s_mp_sqr
|
||||
#define s_mp_sub TclBN_s_mp_sub
|
||||
#define s_mp_toom_mul TclBN_mp_toom_mul
|
||||
#define s_mp_toom_sqr TclBN_mp_toom_sqr
|
||||
|
||||
#undef TCL_STORAGE_CLASS
|
||||
#ifdef BUILD_tcl
|
||||
@@ -155,13 +161,13 @@ EXTERN int TclBN_epoch(void);
|
||||
/* 1 */
|
||||
EXTERN int TclBN_revision(void);
|
||||
/* 2 */
|
||||
EXTERN int TclBN_mp_add(const mp_int *a, const mp_int *b,
|
||||
EXTERN mp_err TclBN_mp_add(const mp_int *a, const mp_int *b,
|
||||
mp_int *c);
|
||||
/* 3 */
|
||||
EXTERN int TclBN_mp_add_d(const mp_int *a, mp_digit b,
|
||||
EXTERN mp_err TclBN_mp_add_d(const mp_int *a, mp_digit b,
|
||||
mp_int *c);
|
||||
/* 4 */
|
||||
EXTERN int TclBN_mp_and(const mp_int *a, const mp_int *b,
|
||||
EXTERN mp_err TclBN_mp_and(const mp_int *a, const mp_int *b,
|
||||
mp_int *c);
|
||||
/* 5 */
|
||||
EXTERN void TclBN_mp_clamp(mp_int *a);
|
||||
@@ -170,171 +176,177 @@ EXTERN void TclBN_mp_clear(mp_int *a);
|
||||
/* 7 */
|
||||
EXTERN void TclBN_mp_clear_multi(mp_int *a, ...);
|
||||
/* 8 */
|
||||
EXTERN int TclBN_mp_cmp(const mp_int *a, const mp_int *b);
|
||||
EXTERN mp_ord TclBN_mp_cmp(const mp_int *a, const mp_int *b);
|
||||
/* 9 */
|
||||
EXTERN int TclBN_mp_cmp_d(const mp_int *a, mp_digit b);
|
||||
EXTERN mp_ord TclBN_mp_cmp_d(const mp_int *a, mp_digit b);
|
||||
/* 10 */
|
||||
EXTERN int TclBN_mp_cmp_mag(const mp_int *a, const mp_int *b);
|
||||
EXTERN mp_ord TclBN_mp_cmp_mag(const mp_int *a, const mp_int *b);
|
||||
/* 11 */
|
||||
EXTERN int TclBN_mp_copy(const mp_int *a, mp_int *b);
|
||||
EXTERN mp_err TclBN_mp_copy(const mp_int *a, mp_int *b);
|
||||
/* 12 */
|
||||
EXTERN int TclBN_mp_count_bits(const mp_int *a);
|
||||
/* 13 */
|
||||
EXTERN int TclBN_mp_div(const mp_int *a, const mp_int *b,
|
||||
EXTERN mp_err TclBN_mp_div(const mp_int *a, const mp_int *b,
|
||||
mp_int *q, mp_int *r);
|
||||
/* 14 */
|
||||
EXTERN int TclBN_mp_div_d(const mp_int *a, mp_digit b,
|
||||
EXTERN mp_err TclBN_mp_div_d(const mp_int *a, mp_digit b,
|
||||
mp_int *q, mp_digit *r);
|
||||
/* 15 */
|
||||
EXTERN int TclBN_mp_div_2(const mp_int *a, mp_int *q);
|
||||
EXTERN mp_err TclBN_mp_div_2(const mp_int *a, mp_int *q);
|
||||
/* 16 */
|
||||
EXTERN int TclBN_mp_div_2d(const mp_int *a, int b, mp_int *q,
|
||||
EXTERN mp_err TclBN_mp_div_2d(const mp_int *a, int b, mp_int *q,
|
||||
mp_int *r);
|
||||
/* 17 */
|
||||
EXTERN int TclBN_mp_div_3(const mp_int *a, mp_int *q,
|
||||
EXTERN mp_err TclBN_mp_div_3(const mp_int *a, mp_int *q,
|
||||
mp_digit *r);
|
||||
/* 18 */
|
||||
EXTERN void TclBN_mp_exch(mp_int *a, mp_int *b);
|
||||
/* 19 */
|
||||
EXTERN int TclBN_mp_expt_d(const mp_int *a, mp_digit b,
|
||||
EXTERN mp_err TclBN_mp_expt_d(const mp_int *a, unsigned int b,
|
||||
mp_int *c);
|
||||
/* 20 */
|
||||
EXTERN int TclBN_mp_grow(mp_int *a, int size);
|
||||
EXTERN mp_err TclBN_mp_grow(mp_int *a, int size);
|
||||
/* 21 */
|
||||
EXTERN int TclBN_mp_init(mp_int *a);
|
||||
EXTERN mp_err TclBN_mp_init(mp_int *a);
|
||||
/* 22 */
|
||||
EXTERN int TclBN_mp_init_copy(mp_int *a, const mp_int *b);
|
||||
EXTERN mp_err TclBN_mp_init_copy(mp_int *a, const mp_int *b);
|
||||
/* 23 */
|
||||
EXTERN int TclBN_mp_init_multi(mp_int *a, ...);
|
||||
EXTERN mp_err TclBN_mp_init_multi(mp_int *a, ...);
|
||||
/* 24 */
|
||||
EXTERN int TclBN_mp_init_set(mp_int *a, mp_digit b);
|
||||
EXTERN mp_err TclBN_mp_init_set(mp_int *a, mp_digit b);
|
||||
/* 25 */
|
||||
EXTERN int TclBN_mp_init_size(mp_int *a, int size);
|
||||
EXTERN mp_err TclBN_mp_init_size(mp_int *a, int size);
|
||||
/* 26 */
|
||||
EXTERN int TclBN_mp_lshd(mp_int *a, int shift);
|
||||
EXTERN mp_err TclBN_mp_lshd(mp_int *a, int shift);
|
||||
/* 27 */
|
||||
EXTERN int TclBN_mp_mod(const mp_int *a, const mp_int *b,
|
||||
EXTERN mp_err TclBN_mp_mod(const mp_int *a, const mp_int *b,
|
||||
mp_int *r);
|
||||
/* 28 */
|
||||
EXTERN int TclBN_mp_mod_2d(const mp_int *a, int b, mp_int *r);
|
||||
EXTERN mp_err TclBN_mp_mod_2d(const mp_int *a, int b, mp_int *r);
|
||||
/* 29 */
|
||||
EXTERN int TclBN_mp_mul(const mp_int *a, const mp_int *b,
|
||||
EXTERN mp_err TclBN_mp_mul(const mp_int *a, const mp_int *b,
|
||||
mp_int *p);
|
||||
/* 30 */
|
||||
EXTERN int TclBN_mp_mul_d(const mp_int *a, mp_digit b,
|
||||
EXTERN mp_err TclBN_mp_mul_d(const mp_int *a, mp_digit b,
|
||||
mp_int *p);
|
||||
/* 31 */
|
||||
EXTERN int TclBN_mp_mul_2(const mp_int *a, mp_int *p);
|
||||
EXTERN mp_err TclBN_mp_mul_2(const mp_int *a, mp_int *p);
|
||||
/* 32 */
|
||||
EXTERN int TclBN_mp_mul_2d(const mp_int *a, int d, mp_int *p);
|
||||
EXTERN mp_err TclBN_mp_mul_2d(const mp_int *a, int d, mp_int *p);
|
||||
/* 33 */
|
||||
EXTERN int TclBN_mp_neg(const mp_int *a, mp_int *b);
|
||||
EXTERN mp_err TclBN_mp_neg(const mp_int *a, mp_int *b);
|
||||
/* 34 */
|
||||
EXTERN int TclBN_mp_or(const mp_int *a, const mp_int *b,
|
||||
EXTERN mp_err TclBN_mp_or(const mp_int *a, const mp_int *b,
|
||||
mp_int *c);
|
||||
/* 35 */
|
||||
EXTERN int TclBN_mp_radix_size(const mp_int *a, int radix,
|
||||
EXTERN mp_err TclBN_mp_radix_size(const mp_int *a, int radix,
|
||||
int *size);
|
||||
/* 36 */
|
||||
EXTERN int TclBN_mp_read_radix(mp_int *a, const char *str,
|
||||
EXTERN mp_err TclBN_mp_read_radix(mp_int *a, const char *str,
|
||||
int radix);
|
||||
/* 37 */
|
||||
EXTERN void TclBN_mp_rshd(mp_int *a, int shift);
|
||||
/* 38 */
|
||||
EXTERN int TclBN_mp_shrink(mp_int *a);
|
||||
EXTERN mp_err TclBN_mp_shrink(mp_int *a);
|
||||
/* 39 */
|
||||
EXTERN void TclBN_mp_set(mp_int *a, mp_digit b);
|
||||
/* 40 */
|
||||
EXTERN int TclBN_mp_sqr(const mp_int *a, mp_int *b);
|
||||
EXTERN mp_err TclBN_mp_sqr(const mp_int *a, mp_int *b);
|
||||
/* 41 */
|
||||
EXTERN int TclBN_mp_sqrt(const mp_int *a, mp_int *b);
|
||||
EXTERN mp_err TclBN_mp_sqrt(const mp_int *a, mp_int *b);
|
||||
/* 42 */
|
||||
EXTERN int TclBN_mp_sub(const mp_int *a, const mp_int *b,
|
||||
EXTERN mp_err TclBN_mp_sub(const mp_int *a, const mp_int *b,
|
||||
mp_int *c);
|
||||
/* 43 */
|
||||
EXTERN int TclBN_mp_sub_d(const mp_int *a, mp_digit b,
|
||||
EXTERN mp_err TclBN_mp_sub_d(const mp_int *a, mp_digit b,
|
||||
mp_int *c);
|
||||
/* 44 */
|
||||
EXTERN int TclBN_mp_to_unsigned_bin(const mp_int *a,
|
||||
EXTERN mp_err TclBN_mp_to_unsigned_bin(const mp_int *a,
|
||||
unsigned char *b);
|
||||
/* 45 */
|
||||
EXTERN int TclBN_mp_to_unsigned_bin_n(const mp_int *a,
|
||||
EXTERN mp_err TclBN_mp_to_unsigned_bin_n(const mp_int *a,
|
||||
unsigned char *b, unsigned long *outlen);
|
||||
/* 46 */
|
||||
EXTERN int TclBN_mp_toradix_n(const mp_int *a, char *str,
|
||||
EXTERN mp_err TclBN_mp_toradix_n(const mp_int *a, char *str,
|
||||
int radix, int maxlen);
|
||||
/* 47 */
|
||||
EXTERN int TclBN_mp_unsigned_bin_size(const mp_int *a);
|
||||
EXTERN size_t TclBN_mp_unsigned_bin_size(const mp_int *a);
|
||||
/* 48 */
|
||||
EXTERN int TclBN_mp_xor(const mp_int *a, const mp_int *b,
|
||||
EXTERN mp_err TclBN_mp_xor(const mp_int *a, const mp_int *b,
|
||||
mp_int *c);
|
||||
/* 49 */
|
||||
EXTERN void TclBN_mp_zero(mp_int *a);
|
||||
/* 50 */
|
||||
EXTERN void TclBN_reverse(unsigned char *s, int len);
|
||||
/* 51 */
|
||||
EXTERN int TclBN_fast_s_mp_mul_digs(const mp_int *a,
|
||||
EXTERN mp_err TclBN_fast_s_mp_mul_digs(const mp_int *a,
|
||||
const mp_int *b, mp_int *c, int digs);
|
||||
/* 52 */
|
||||
EXTERN int TclBN_fast_s_mp_sqr(const mp_int *a, mp_int *b);
|
||||
EXTERN mp_err TclBN_fast_s_mp_sqr(const mp_int *a, mp_int *b);
|
||||
/* 53 */
|
||||
EXTERN int TclBN_mp_karatsuba_mul(const mp_int *a,
|
||||
EXTERN mp_err TclBN_mp_karatsuba_mul(const mp_int *a,
|
||||
const mp_int *b, mp_int *c);
|
||||
/* 54 */
|
||||
EXTERN int TclBN_mp_karatsuba_sqr(const mp_int *a, mp_int *b);
|
||||
EXTERN mp_err TclBN_mp_karatsuba_sqr(const mp_int *a, mp_int *b);
|
||||
/* 55 */
|
||||
EXTERN int TclBN_mp_toom_mul(const mp_int *a, const mp_int *b,
|
||||
EXTERN mp_err TclBN_mp_toom_mul(const mp_int *a, const mp_int *b,
|
||||
mp_int *c);
|
||||
/* 56 */
|
||||
EXTERN int TclBN_mp_toom_sqr(const mp_int *a, mp_int *b);
|
||||
EXTERN mp_err TclBN_mp_toom_sqr(const mp_int *a, mp_int *b);
|
||||
/* 57 */
|
||||
EXTERN int TclBN_s_mp_add(const mp_int *a, const mp_int *b,
|
||||
EXTERN mp_err TclBN_s_mp_add(const mp_int *a, const mp_int *b,
|
||||
mp_int *c);
|
||||
/* 58 */
|
||||
EXTERN int TclBN_s_mp_mul_digs(const mp_int *a, const mp_int *b,
|
||||
EXTERN mp_err TclBN_s_mp_mul_digs(const mp_int *a, const mp_int *b,
|
||||
mp_int *c, int digs);
|
||||
/* 59 */
|
||||
EXTERN int TclBN_s_mp_sqr(const mp_int *a, mp_int *b);
|
||||
EXTERN mp_err TclBN_s_mp_sqr(const mp_int *a, mp_int *b);
|
||||
/* 60 */
|
||||
EXTERN int TclBN_s_mp_sub(const mp_int *a, const mp_int *b,
|
||||
EXTERN mp_err TclBN_s_mp_sub(const mp_int *a, const mp_int *b,
|
||||
mp_int *c);
|
||||
/* 61 */
|
||||
EXTERN int TclBN_mp_init_set_int(mp_int *a, unsigned long i);
|
||||
EXTERN mp_err TclBN_mp_init_set_int(mp_int *a, unsigned long i);
|
||||
/* 62 */
|
||||
EXTERN int TclBN_mp_set_int(mp_int *a, unsigned long i);
|
||||
EXTERN mp_err TclBN_mp_set_int(mp_int *a, unsigned long i);
|
||||
/* 63 */
|
||||
EXTERN int TclBN_mp_cnt_lsb(const mp_int *a);
|
||||
/* 64 */
|
||||
EXTERN void TclBNInitBignumFromLong(mp_int *bignum, long initVal);
|
||||
EXTERN int TclBNInitBignumFromLong(mp_int *bignum, long initVal);
|
||||
/* 65 */
|
||||
EXTERN void TclBNInitBignumFromWideInt(mp_int *bignum,
|
||||
EXTERN int TclBNInitBignumFromWideInt(mp_int *bignum,
|
||||
Tcl_WideInt initVal);
|
||||
/* 66 */
|
||||
EXTERN void TclBNInitBignumFromWideUInt(mp_int *bignum,
|
||||
EXTERN int TclBNInitBignumFromWideUInt(mp_int *bignum,
|
||||
Tcl_WideUInt initVal);
|
||||
/* 67 */
|
||||
EXTERN int TclBN_mp_expt_d_ex(const mp_int *a, mp_digit b,
|
||||
EXTERN mp_err TclBN_mp_expt_d_ex(const mp_int *a, mp_digit b,
|
||||
mp_int *c, int fast);
|
||||
/* Slot 68 is reserved */
|
||||
/* 68 */
|
||||
EXTERN void TclBN_mp_set_ull(mp_int *a, Tcl_WideUInt i);
|
||||
/* Slot 69 is reserved */
|
||||
/* 70 */
|
||||
EXTERN int TclBN_mp_set_long(mp_int *a, unsigned long i);
|
||||
/* Slot 70 is reserved */
|
||||
/* Slot 71 is reserved */
|
||||
/* Slot 72 is reserved */
|
||||
/* 73 */
|
||||
EXTERN int TclBN_mp_tc_and(const mp_int *a, const mp_int *b,
|
||||
EXTERN mp_err TclBN_mp_tc_and(const mp_int *a, const mp_int *b,
|
||||
mp_int *c);
|
||||
/* 74 */
|
||||
EXTERN int TclBN_mp_tc_or(const mp_int *a, const mp_int *b,
|
||||
EXTERN mp_err TclBN_mp_tc_or(const mp_int *a, const mp_int *b,
|
||||
mp_int *c);
|
||||
/* 75 */
|
||||
EXTERN int TclBN_mp_tc_xor(const mp_int *a, const mp_int *b,
|
||||
EXTERN mp_err TclBN_mp_tc_xor(const mp_int *a, const mp_int *b,
|
||||
mp_int *c);
|
||||
/* 76 */
|
||||
EXTERN int TclBN_mp_signed_rsh(const mp_int *a, int b,
|
||||
EXTERN mp_err TclBN_mp_signed_rsh(const mp_int *a, int b,
|
||||
mp_int *c);
|
||||
/* 77 */
|
||||
EXTERN int TclBN_mp_get_bit(const mp_int *a, int b);
|
||||
/* Slot 77 is reserved */
|
||||
/* 78 */
|
||||
EXTERN int TclBN_mp_to_ubin(const mp_int *a, unsigned char *buf,
|
||||
size_t maxlen, size_t *written);
|
||||
/* Slot 79 is reserved */
|
||||
/* 80 */
|
||||
EXTERN int TclBN_mp_to_radix(const mp_int *a, char *str,
|
||||
size_t maxlen, size_t *written, int radix);
|
||||
|
||||
typedef struct TclTomMathStubs {
|
||||
int magic;
|
||||
@@ -342,82 +354,85 @@ typedef struct TclTomMathStubs {
|
||||
|
||||
int (*tclBN_epoch) (void); /* 0 */
|
||||
int (*tclBN_revision) (void); /* 1 */
|
||||
int (*tclBN_mp_add) (const mp_int *a, const mp_int *b, mp_int *c); /* 2 */
|
||||
int (*tclBN_mp_add_d) (const mp_int *a, mp_digit b, mp_int *c); /* 3 */
|
||||
int (*tclBN_mp_and) (const mp_int *a, const mp_int *b, mp_int *c); /* 4 */
|
||||
mp_err (*tclBN_mp_add) (const mp_int *a, const mp_int *b, mp_int *c); /* 2 */
|
||||
mp_err (*tclBN_mp_add_d) (const mp_int *a, mp_digit b, mp_int *c); /* 3 */
|
||||
mp_err (*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) (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) (const mp_int *a, mp_int *b); /* 11 */
|
||||
mp_ord (*tclBN_mp_cmp) (const mp_int *a, const mp_int *b); /* 8 */
|
||||
mp_ord (*tclBN_mp_cmp_d) (const mp_int *a, mp_digit b); /* 9 */
|
||||
mp_ord (*tclBN_mp_cmp_mag) (const mp_int *a, const mp_int *b); /* 10 */
|
||||
mp_err (*tclBN_mp_copy) (const mp_int *a, mp_int *b); /* 11 */
|
||||
int (*tclBN_mp_count_bits) (const mp_int *a); /* 12 */
|
||||
int (*tclBN_mp_div) (const mp_int *a, const mp_int *b, mp_int *q, mp_int *r); /* 13 */
|
||||
int (*tclBN_mp_div_d) (const mp_int *a, mp_digit b, mp_int *q, mp_digit *r); /* 14 */
|
||||
int (*tclBN_mp_div_2) (const mp_int *a, mp_int *q); /* 15 */
|
||||
int (*tclBN_mp_div_2d) (const mp_int *a, int b, mp_int *q, mp_int *r); /* 16 */
|
||||
int (*tclBN_mp_div_3) (const mp_int *a, mp_int *q, mp_digit *r); /* 17 */
|
||||
mp_err (*tclBN_mp_div) (const mp_int *a, const mp_int *b, mp_int *q, mp_int *r); /* 13 */
|
||||
mp_err (*tclBN_mp_div_d) (const mp_int *a, mp_digit b, mp_int *q, mp_digit *r); /* 14 */
|
||||
mp_err (*tclBN_mp_div_2) (const mp_int *a, mp_int *q); /* 15 */
|
||||
mp_err (*tclBN_mp_div_2d) (const mp_int *a, int b, mp_int *q, mp_int *r); /* 16 */
|
||||
mp_err (*tclBN_mp_div_3) (const mp_int *a, mp_int *q, mp_digit *r); /* 17 */
|
||||
void (*tclBN_mp_exch) (mp_int *a, mp_int *b); /* 18 */
|
||||
int (*tclBN_mp_expt_d) (const mp_int *a, mp_digit b, mp_int *c); /* 19 */
|
||||
int (*tclBN_mp_grow) (mp_int *a, int size); /* 20 */
|
||||
int (*tclBN_mp_init) (mp_int *a); /* 21 */
|
||||
int (*tclBN_mp_init_copy) (mp_int *a, const mp_int *b); /* 22 */
|
||||
int (*tclBN_mp_init_multi) (mp_int *a, ...); /* 23 */
|
||||
int (*tclBN_mp_init_set) (mp_int *a, mp_digit b); /* 24 */
|
||||
int (*tclBN_mp_init_size) (mp_int *a, int size); /* 25 */
|
||||
int (*tclBN_mp_lshd) (mp_int *a, int shift); /* 26 */
|
||||
int (*tclBN_mp_mod) (const mp_int *a, const mp_int *b, mp_int *r); /* 27 */
|
||||
int (*tclBN_mp_mod_2d) (const mp_int *a, int b, mp_int *r); /* 28 */
|
||||
int (*tclBN_mp_mul) (const mp_int *a, const mp_int *b, mp_int *p); /* 29 */
|
||||
int (*tclBN_mp_mul_d) (const mp_int *a, mp_digit b, mp_int *p); /* 30 */
|
||||
int (*tclBN_mp_mul_2) (const mp_int *a, mp_int *p); /* 31 */
|
||||
int (*tclBN_mp_mul_2d) (const mp_int *a, int d, mp_int *p); /* 32 */
|
||||
int (*tclBN_mp_neg) (const mp_int *a, mp_int *b); /* 33 */
|
||||
int (*tclBN_mp_or) (const mp_int *a, const mp_int *b, mp_int *c); /* 34 */
|
||||
int (*tclBN_mp_radix_size) (const mp_int *a, int radix, int *size); /* 35 */
|
||||
int (*tclBN_mp_read_radix) (mp_int *a, const char *str, int radix); /* 36 */
|
||||
mp_err (*tclBN_mp_expt_d) (const mp_int *a, unsigned int b, mp_int *c); /* 19 */
|
||||
mp_err (*tclBN_mp_grow) (mp_int *a, int size); /* 20 */
|
||||
mp_err (*tclBN_mp_init) (mp_int *a); /* 21 */
|
||||
mp_err (*tclBN_mp_init_copy) (mp_int *a, const mp_int *b); /* 22 */
|
||||
mp_err (*tclBN_mp_init_multi) (mp_int *a, ...); /* 23 */
|
||||
mp_err (*tclBN_mp_init_set) (mp_int *a, mp_digit b); /* 24 */
|
||||
mp_err (*tclBN_mp_init_size) (mp_int *a, int size); /* 25 */
|
||||
mp_err (*tclBN_mp_lshd) (mp_int *a, int shift); /* 26 */
|
||||
mp_err (*tclBN_mp_mod) (const mp_int *a, const mp_int *b, mp_int *r); /* 27 */
|
||||
mp_err (*tclBN_mp_mod_2d) (const mp_int *a, int b, mp_int *r); /* 28 */
|
||||
mp_err (*tclBN_mp_mul) (const mp_int *a, const mp_int *b, mp_int *p); /* 29 */
|
||||
mp_err (*tclBN_mp_mul_d) (const mp_int *a, mp_digit b, mp_int *p); /* 30 */
|
||||
mp_err (*tclBN_mp_mul_2) (const mp_int *a, mp_int *p); /* 31 */
|
||||
mp_err (*tclBN_mp_mul_2d) (const mp_int *a, int d, mp_int *p); /* 32 */
|
||||
mp_err (*tclBN_mp_neg) (const mp_int *a, mp_int *b); /* 33 */
|
||||
mp_err (*tclBN_mp_or) (const mp_int *a, const mp_int *b, mp_int *c); /* 34 */
|
||||
mp_err (*tclBN_mp_radix_size) (const mp_int *a, int radix, int *size); /* 35 */
|
||||
mp_err (*tclBN_mp_read_radix) (mp_int *a, const char *str, int radix); /* 36 */
|
||||
void (*tclBN_mp_rshd) (mp_int *a, int shift); /* 37 */
|
||||
int (*tclBN_mp_shrink) (mp_int *a); /* 38 */
|
||||
mp_err (*tclBN_mp_shrink) (mp_int *a); /* 38 */
|
||||
void (*tclBN_mp_set) (mp_int *a, mp_digit b); /* 39 */
|
||||
int (*tclBN_mp_sqr) (const mp_int *a, mp_int *b); /* 40 */
|
||||
int (*tclBN_mp_sqrt) (const mp_int *a, mp_int *b); /* 41 */
|
||||
int (*tclBN_mp_sub) (const mp_int *a, const mp_int *b, mp_int *c); /* 42 */
|
||||
int (*tclBN_mp_sub_d) (const mp_int *a, mp_digit b, mp_int *c); /* 43 */
|
||||
int (*tclBN_mp_to_unsigned_bin) (const mp_int *a, unsigned char *b); /* 44 */
|
||||
int (*tclBN_mp_to_unsigned_bin_n) (const mp_int *a, unsigned char *b, unsigned long *outlen); /* 45 */
|
||||
int (*tclBN_mp_toradix_n) (const mp_int *a, char *str, int radix, int maxlen); /* 46 */
|
||||
int (*tclBN_mp_unsigned_bin_size) (const mp_int *a); /* 47 */
|
||||
int (*tclBN_mp_xor) (const mp_int *a, const mp_int *b, mp_int *c); /* 48 */
|
||||
mp_err (*tclBN_mp_sqr) (const mp_int *a, mp_int *b); /* 40 */
|
||||
mp_err (*tclBN_mp_sqrt) (const mp_int *a, mp_int *b); /* 41 */
|
||||
mp_err (*tclBN_mp_sub) (const mp_int *a, const mp_int *b, mp_int *c); /* 42 */
|
||||
mp_err (*tclBN_mp_sub_d) (const mp_int *a, mp_digit b, mp_int *c); /* 43 */
|
||||
mp_err (*tclBN_mp_to_unsigned_bin) (const mp_int *a, unsigned char *b); /* 44 */
|
||||
mp_err (*tclBN_mp_to_unsigned_bin_n) (const mp_int *a, unsigned char *b, unsigned long *outlen); /* 45 */
|
||||
mp_err (*tclBN_mp_toradix_n) (const mp_int *a, char *str, int radix, int maxlen); /* 46 */
|
||||
size_t (*tclBN_mp_unsigned_bin_size) (const mp_int *a); /* 47 */
|
||||
mp_err (*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) (const mp_int *a, const mp_int *b, mp_int *c, int digs); /* 51 */
|
||||
int (*tclBN_fast_s_mp_sqr) (const mp_int *a, mp_int *b); /* 52 */
|
||||
int (*tclBN_mp_karatsuba_mul) (const mp_int *a, const mp_int *b, mp_int *c); /* 53 */
|
||||
int (*tclBN_mp_karatsuba_sqr) (const mp_int *a, mp_int *b); /* 54 */
|
||||
int (*tclBN_mp_toom_mul) (const mp_int *a, const mp_int *b, mp_int *c); /* 55 */
|
||||
int (*tclBN_mp_toom_sqr) (const mp_int *a, mp_int *b); /* 56 */
|
||||
int (*tclBN_s_mp_add) (const mp_int *a, const mp_int *b, mp_int *c); /* 57 */
|
||||
int (*tclBN_s_mp_mul_digs) (const mp_int *a, const mp_int *b, mp_int *c, int digs); /* 58 */
|
||||
int (*tclBN_s_mp_sqr) (const mp_int *a, mp_int *b); /* 59 */
|
||||
int (*tclBN_s_mp_sub) (const mp_int *a, const mp_int *b, mp_int *c); /* 60 */
|
||||
int (*tclBN_mp_init_set_int) (mp_int *a, unsigned long i); /* 61 */
|
||||
int (*tclBN_mp_set_int) (mp_int *a, unsigned long i); /* 62 */
|
||||
mp_err (*tclBN_fast_s_mp_mul_digs) (const mp_int *a, const mp_int *b, mp_int *c, int digs); /* 51 */
|
||||
mp_err (*tclBN_fast_s_mp_sqr) (const mp_int *a, mp_int *b); /* 52 */
|
||||
mp_err (*tclBN_mp_karatsuba_mul) (const mp_int *a, const mp_int *b, mp_int *c); /* 53 */
|
||||
mp_err (*tclBN_mp_karatsuba_sqr) (const mp_int *a, mp_int *b); /* 54 */
|
||||
mp_err (*tclBN_mp_toom_mul) (const mp_int *a, const mp_int *b, mp_int *c); /* 55 */
|
||||
mp_err (*tclBN_mp_toom_sqr) (const mp_int *a, mp_int *b); /* 56 */
|
||||
mp_err (*tclBN_s_mp_add) (const mp_int *a, const mp_int *b, mp_int *c); /* 57 */
|
||||
mp_err (*tclBN_s_mp_mul_digs) (const mp_int *a, const mp_int *b, mp_int *c, int digs); /* 58 */
|
||||
mp_err (*tclBN_s_mp_sqr) (const mp_int *a, mp_int *b); /* 59 */
|
||||
mp_err (*tclBN_s_mp_sub) (const mp_int *a, const mp_int *b, mp_int *c); /* 60 */
|
||||
mp_err (*tclBN_mp_init_set_int) (mp_int *a, unsigned long i); /* 61 */
|
||||
mp_err (*tclBN_mp_set_int) (mp_int *a, unsigned long i); /* 62 */
|
||||
int (*tclBN_mp_cnt_lsb) (const mp_int *a); /* 63 */
|
||||
void (*tclBNInitBignumFromLong) (mp_int *bignum, long initVal); /* 64 */
|
||||
void (*tclBNInitBignumFromWideInt) (mp_int *bignum, Tcl_WideInt initVal); /* 65 */
|
||||
void (*tclBNInitBignumFromWideUInt) (mp_int *bignum, Tcl_WideUInt initVal); /* 66 */
|
||||
int (*tclBN_mp_expt_d_ex) (const mp_int *a, mp_digit b, mp_int *c, int fast); /* 67 */
|
||||
void (*reserved68)(void);
|
||||
int (*tclBNInitBignumFromLong) (mp_int *bignum, long initVal); /* 64 */
|
||||
int (*tclBNInitBignumFromWideInt) (mp_int *bignum, Tcl_WideInt initVal); /* 65 */
|
||||
int (*tclBNInitBignumFromWideUInt) (mp_int *bignum, Tcl_WideUInt initVal); /* 66 */
|
||||
mp_err (*tclBN_mp_expt_d_ex) (const mp_int *a, mp_digit b, mp_int *c, int fast); /* 67 */
|
||||
void (*tclBN_mp_set_ull) (mp_int *a, Tcl_WideUInt i); /* 68 */
|
||||
void (*reserved69)(void);
|
||||
int (*tclBN_mp_set_long) (mp_int *a, unsigned long i); /* 70 */
|
||||
void (*reserved70)(void);
|
||||
void (*reserved71)(void);
|
||||
void (*reserved72)(void);
|
||||
int (*tclBN_mp_tc_and) (const mp_int *a, const mp_int *b, mp_int *c); /* 73 */
|
||||
int (*tclBN_mp_tc_or) (const mp_int *a, const mp_int *b, mp_int *c); /* 74 */
|
||||
int (*tclBN_mp_tc_xor) (const mp_int *a, const mp_int *b, mp_int *c); /* 75 */
|
||||
int (*tclBN_mp_signed_rsh) (const mp_int *a, int b, mp_int *c); /* 76 */
|
||||
int (*tclBN_mp_get_bit) (const mp_int *a, int b); /* 77 */
|
||||
mp_err (*tclBN_mp_tc_and) (const mp_int *a, const mp_int *b, mp_int *c); /* 73 */
|
||||
mp_err (*tclBN_mp_tc_or) (const mp_int *a, const mp_int *b, mp_int *c); /* 74 */
|
||||
mp_err (*tclBN_mp_tc_xor) (const mp_int *a, const mp_int *b, mp_int *c); /* 75 */
|
||||
mp_err (*tclBN_mp_signed_rsh) (const mp_int *a, int b, mp_int *c); /* 76 */
|
||||
void (*reserved77)(void);
|
||||
int (*tclBN_mp_to_ubin) (const mp_int *a, unsigned char *buf, size_t maxlen, size_t *written); /* 78 */
|
||||
void (*reserved79)(void);
|
||||
int (*tclBN_mp_to_radix) (const mp_int *a, char *str, size_t maxlen, size_t *written, int radix); /* 80 */
|
||||
} TclTomMathStubs;
|
||||
|
||||
extern const TclTomMathStubs *tclTomMathStubsPtr;
|
||||
@@ -568,10 +583,10 @@ extern const TclTomMathStubs *tclTomMathStubsPtr;
|
||||
(tclTomMathStubsPtr->tclBNInitBignumFromWideUInt) /* 66 */
|
||||
#define TclBN_mp_expt_d_ex \
|
||||
(tclTomMathStubsPtr->tclBN_mp_expt_d_ex) /* 67 */
|
||||
/* Slot 68 is reserved */
|
||||
#define TclBN_mp_set_ull \
|
||||
(tclTomMathStubsPtr->tclBN_mp_set_ull) /* 68 */
|
||||
/* Slot 69 is reserved */
|
||||
#define TclBN_mp_set_long \
|
||||
(tclTomMathStubsPtr->tclBN_mp_set_long) /* 70 */
|
||||
/* Slot 70 is reserved */
|
||||
/* Slot 71 is reserved */
|
||||
/* Slot 72 is reserved */
|
||||
#define TclBN_mp_tc_and \
|
||||
@@ -582,8 +597,12 @@ extern const TclTomMathStubs *tclTomMathStubsPtr;
|
||||
(tclTomMathStubsPtr->tclBN_mp_tc_xor) /* 75 */
|
||||
#define TclBN_mp_signed_rsh \
|
||||
(tclTomMathStubsPtr->tclBN_mp_signed_rsh) /* 76 */
|
||||
#define TclBN_mp_get_bit \
|
||||
(tclTomMathStubsPtr->tclBN_mp_get_bit) /* 77 */
|
||||
/* Slot 77 is reserved */
|
||||
#define TclBN_mp_to_ubin \
|
||||
(tclTomMathStubsPtr->tclBN_mp_to_ubin) /* 78 */
|
||||
/* Slot 79 is reserved */
|
||||
#define TclBN_mp_to_radix \
|
||||
(tclTomMathStubsPtr->tclBN_mp_to_radix) /* 80 */
|
||||
|
||||
#endif /* defined(USE_TCL_STUBS) */
|
||||
|
||||
@@ -592,4 +611,50 @@ extern const TclTomMathStubs *tclTomMathStubsPtr;
|
||||
#undef TCL_STORAGE_CLASS
|
||||
#define TCL_STORAGE_CLASS DLLIMPORT
|
||||
|
||||
#ifdef USE_TCL_STUBS
|
||||
#undef TclBNInitBignumFromLong
|
||||
#define TclBNInitBignumFromLong(a,b) \
|
||||
do { \
|
||||
(a)->dp = NULL; \
|
||||
(void)tclTomMathStubsPtr->tclBNInitBignumFromLong((a),(b)); \
|
||||
if ((a)->dp == NULL) { \
|
||||
Tcl_Panic("initialization failure in TclBNInitBignumFromLong"); \
|
||||
} \
|
||||
} while (0)
|
||||
#undef TclBNInitBignumFromWideInt
|
||||
#define TclBNInitBignumFromWideInt(a,b) \
|
||||
do { \
|
||||
(a)->dp = NULL; \
|
||||
(void)tclTomMathStubsPtr->tclBNInitBignumFromWideInt((a),(b)); \
|
||||
if ((a)->dp == NULL) { \
|
||||
Tcl_Panic("initialization failure in TclBNInitBignumFromWideInt"); \
|
||||
} \
|
||||
} while (0)
|
||||
#undef TclBNInitBignumFromWideUInt
|
||||
#define TclBNInitBignumFromWideUInt(a,b) \
|
||||
do { \
|
||||
(a)->dp = NULL; \
|
||||
(void)tclTomMathStubsPtr->tclBNInitBignumFromWideUInt((a),(b)); \
|
||||
if ((a)->dp == NULL) { \
|
||||
Tcl_Panic("initialization failure in TclBNInitBignumFromWideUInt"); \
|
||||
} \
|
||||
} while (0)
|
||||
#define mp_init_i32(a,b) (((a)->dp=NULL,tclTomMathStubsPtr->tclBNInitBignumFromLong((a),(int32_t)(b)),(a)->dp)?MP_OKAY:MP_ERR)
|
||||
#define mp_init_l(a,b) (((a)->dp=NULL,tclTomMathStubsPtr->tclBNInitBignumFromLong((a),(b)),(a)->dp)?MP_OKAY:MP_ERR)
|
||||
#define mp_init_ll(a,b) (((a)->dp=NULL,tclTomMathStubsPtr->tclBNInitBignumFromWideInt((a),(b)),(a)->dp)?MP_OKAY:MP_ERR)
|
||||
#define mp_init_i64(a,b) (((a)->dp=NULL,tclTomMathStubsPtr->tclBNInitBignumFromWideInt((a),(b)),(a)->dp)?MP_OKAY:MP_ERR)
|
||||
#define mp_init_u32(a,b) (((a)->dp=NULL,tclTomMathStubsPtr->tclBNInitBignumFromWideUInt((a),(uint32_t)(b)),(a)->dp)?MP_OKAY:MP_ERR)
|
||||
#define mp_init_ul(a,b) (((a)->dp=NULL,tclTomMathStubsPtr->tclBNInitBignumFromWideUInt((a),(unsigned long)(b)),(a)->dp)?MP_OKAY:MP_ERR)
|
||||
#define mp_init_ull(a,b) (((a)->dp=NULL,tclTomMathStubsPtr->tclBNInitBignumFromWideUInt((a),(b)),(a)->dp)?MP_OKAY:MP_ERR)
|
||||
#define mp_init_u64(a,b) (((a)->dp=NULL,tclTomMathStubsPtr->tclBNInitBignumFromWideUInt((a),(b)),(a)->dp)?MP_OKAY:MP_ERR)
|
||||
#else
|
||||
#define mp_init_i32(a,b) (((a)->dp=NULL,(TclBNInitBignumFromLong)((a),(int32_t)(b)),(a)->dp)?MP_OKAY:MP_ERR)
|
||||
#define mp_init_l(a,b) (((a)->dp=NULL,(TclBNInitBignumFromLong)((a),(b)),(a)->dp)?MP_OKAY:MP_ERR)
|
||||
#define mp_init_ll(a,b) (((a)->dp=NULL,(TclBNInitBignumFromWideInt)((a),(b)),(a)->dp)?MP_OKAY:MP_ERR)
|
||||
#define mp_init_i64(a,b) (((a)->dp=NULL,(TclBNInitBignumFromWideInt)((a),(b)),(a)->dp)?MP_OKAY:MP_ERR)
|
||||
#define mp_init_u32(a,b) (((a)->dp=NULL,(TclBNInitBignumFromWideUInt)((a),(uint32_t)(b)),(a)->dp)?MP_OKAY:MP_ERR)
|
||||
#define mp_init_ul(a,b) (((a)->dp=NULL,(TclBNInitBignumFromWideUInt)((a),(unsigned long)(b)),(a)->dp)?MP_OKAY:MP_ERR)
|
||||
#define mp_init_ull(a,b) (((a)->dp=NULL,(TclBNInitBignumFromWideUInt)((a),(b)),(a)->dp)?MP_OKAY:MP_ERR)
|
||||
#define mp_init_u64(a,b) (((a)->dp=NULL,(TclBNInitBignumFromWideUInt)((a),(b)),(a)->dp)?MP_OKAY:MP_ERR)
|
||||
#endif /* USE_TCL_STUBS */
|
||||
#endif /* _TCLINTDECLS */
|
||||
|
||||
@@ -106,7 +106,7 @@ TclBN_revision(void)
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
extern void
|
||||
int
|
||||
TclBNInitBignumFromLong(
|
||||
mp_int *a,
|
||||
long initVal)
|
||||
@@ -146,6 +146,7 @@ TclBNInitBignumFromLong(
|
||||
v >>= MP_DIGIT_BIT;
|
||||
}
|
||||
a->used = p - a->dp;
|
||||
return MP_OKAY;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -164,7 +165,7 @@ TclBNInitBignumFromLong(
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
extern void
|
||||
int
|
||||
TclBNInitBignumFromWideInt(
|
||||
mp_int *a, /* Bignum to initialize */
|
||||
Tcl_WideInt v) /* Initial value */
|
||||
@@ -175,6 +176,7 @@ TclBNInitBignumFromWideInt(
|
||||
} else {
|
||||
TclBNInitBignumFromWideUInt(a, (Tcl_WideUInt)v);
|
||||
}
|
||||
return MP_OKAY;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -193,7 +195,7 @@ TclBNInitBignumFromWideInt(
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
extern void
|
||||
int
|
||||
TclBNInitBignumFromWideUInt(
|
||||
mp_int *a, /* Bignum to initialize */
|
||||
Tcl_WideUInt v) /* Initial value */
|
||||
@@ -222,6 +224,7 @@ TclBNInitBignumFromWideUInt(
|
||||
v >>= MP_DIGIT_BIT;
|
||||
}
|
||||
a->used = p - a->dp;
|
||||
return MP_OKAY;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -81,6 +81,13 @@ proc tcl_findLibrary {basename version patch initScript enVarName varName} {
|
||||
lappend dirs [::${basename}::pkgconfig get scriptdir,runtime]
|
||||
}
|
||||
|
||||
# 2a. As a sibling of Tcl's script directory
|
||||
if {[catch {
|
||||
::tcl::pkgconfig get scriptdir,runtime
|
||||
} value] == 0} {
|
||||
lappend dirs [file join [file dirname $value] $basename$version]
|
||||
}
|
||||
|
||||
# 3. Relative to auto_path directories. This checks relative to the
|
||||
# Tcl library as well as allowing loading of libraries added to the
|
||||
# auto_path that is not relative to the core library or binary paths.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
if {![package vsatisfies [package provide Tcl] 8.5]} return
|
||||
if {[info sharedlibextension] != ".dll"} return
|
||||
if {[::tcl::pkgconfig get debug]} {
|
||||
package ifneeded dde 1.4.1 [list load [file join $dir tcldde14g.dll] dde]
|
||||
package ifneeded dde 1.4.2 [list load [file join $dir tcldde14g.dll] dde]
|
||||
} else {
|
||||
package ifneeded dde 1.4.1 [list load [file join $dir tcldde14.dll] dde]
|
||||
package ifneeded dde 1.4.2 [list load [file join $dir tcldde14.dll] dde]
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
package require Tcl 8.6-
|
||||
# Keep this in sync with pkgIndex.tcl and with the install directories in
|
||||
# Makefiles
|
||||
package provide http 2.9.0
|
||||
package provide http 2.9.1
|
||||
|
||||
namespace eval http {
|
||||
# Allow resourcing to not clobber existing data
|
||||
@@ -2978,7 +2978,7 @@ proc http::IsBinaryContentType {type} {
|
||||
# and so on.
|
||||
if {$major eq "application"} {
|
||||
set minor [string trimright $minor]
|
||||
if {$minor in {"xml" "xml-external-parsed-entity" "xml-dtd"}} {
|
||||
if {$minor in {"json" "xml" "xml-external-parsed-entity" "xml-dtd"}} {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
if {![package vsatisfies [package provide Tcl] 8.6-]} {return}
|
||||
package ifneeded http 2.9.0 [list tclPkgSetup $dir http 2.9.0 {{http.tcl source {::http::config ::http::formatQuery ::http::geturl ::http::reset ::http::wait ::http::register ::http::unregister ::http::mapReply}}}]
|
||||
package ifneeded http 2.9.1 [list tclPkgSetup $dir http 2.9.1 {{http.tcl source {::http::config ::http::formatQuery ::http::geturl ::http::reset ::http::wait ::http::register ::http::unregister ::http::mapReply}}}]
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
if {[info commands package] == ""} {
|
||||
error "version mismatch: library\nscripts expect Tcl version 7.5b1 or later but the loaded version is\nonly [info patchlevel]"
|
||||
}
|
||||
package require -exact Tcl 8.6.9
|
||||
package require -exact Tcl 8.6.10
|
||||
|
||||
# Compute the auto path to use in this interpreter.
|
||||
# The values on the path come from several locations:
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
if {![package vsatisfies [package provide Tcl] 8.5]} return
|
||||
if {[info sharedlibextension] != ".dll"} return
|
||||
if {[::tcl::pkgconfig get debug]} {
|
||||
package ifneeded registry 1.3.3 \
|
||||
package ifneeded registry 1.3.4 \
|
||||
[list load [file join $dir tclreg13g.dll] registry]
|
||||
} else {
|
||||
package ifneeded registry 1.3.3 \
|
||||
package ifneeded registry 1.3.4 \
|
||||
[list load [file join $dir tclreg13.dll] registry]
|
||||
}
|
||||
|
||||
+23
-4
@@ -4,22 +4,41 @@ This is the git repository for [LibTomMath](http://www.libtom.net/LibTomMath/),
|
||||
|
||||
## Build Status
|
||||
|
||||
### Travis CI
|
||||
|
||||
master: [](https://travis-ci.org/libtom/libtommath)
|
||||
|
||||
develop: [](https://travis-ci.org/libtom/libtommath)
|
||||
|
||||
### AppVeyor
|
||||
|
||||
master: [](https://ci.appveyor.com/project/libtom/libtommath/branch/master)
|
||||
|
||||
develop: [](https://ci.appveyor.com/project/libtom/libtommath/branch/develop)
|
||||
|
||||
### ABI Laboratory
|
||||
|
||||
API/ABI changes: [check here](https://abi-laboratory.pro/tracker/timeline/libtommath/)
|
||||
|
||||
## Summary
|
||||
|
||||
The `develop` branch contains the in-development version. Stable releases are tagged.
|
||||
|
||||
Documentation is built from the LaTeX file `bn.tex`. There is also limited documentation in `tommath.h`. There is also a document, `tommath.pdf`, which describes the goals of the project and many of the algorithms used.
|
||||
Documentation is built from the LaTeX file `bn.tex`. There is also limited documentation in `tommath.h`.
|
||||
There is also a document, `tommath.pdf`, which describes the goals of the project and many of the algorithms used.
|
||||
|
||||
The project can be build by using `make`. Along with the usual `make`, `make clean` and `make install`, there are several other build targets, see the makefile for details. There are also makefiles for certain specific platforms.
|
||||
The project can be build by using `make`. Along with the usual `make`, `make clean` and `make install`,
|
||||
there are several other build targets, see the makefile for details.
|
||||
There are also makefiles for certain specific platforms.
|
||||
|
||||
## Testing
|
||||
|
||||
Tests are located in `demo/` and can be built in two flavors.
|
||||
* `make test` creates a test binary that is intended to be run against `mtest`. `mtest` can be built with `make mtest` and test execution is done like `./mtest/mtest | ./test`. `mtest` is creating test vectors using an alternative MPI library and `test` is consuming these vectors to verify correct behavior of ltm
|
||||
* `make test_standalone` creates a stand-alone test binary that executes several test routines.
|
||||
* `make test` creates a stand-alone test binary that executes several test routines.
|
||||
* `make mtest_opponent` creates a test binary that is intended to be run against `mtest`.
|
||||
`mtest` can be built with `make mtest` and test execution is done like `./mtest/mtest | ./mtest_opponent`.
|
||||
`mtest` is creating test vectors using an alternative MPI library and `test` is consuming these vectors to verify correct behavior of ltm
|
||||
|
||||
## Building and Installing
|
||||
|
||||
Building is straightforward for GNU Linux only, the section "Building LibTomMath" in the documentation in `doc/bn.pdf` has the details.
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
version: 1.2.0-{build}
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- develop
|
||||
- /^release/
|
||||
- /^travis/
|
||||
image:
|
||||
- Visual Studio 2019
|
||||
- Visual Studio 2017
|
||||
- Visual Studio 2015
|
||||
build_script:
|
||||
- cmd: >-
|
||||
if "Visual Studio 2019"=="%APPVEYOR_BUILD_WORKER_IMAGE%" call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"
|
||||
if "Visual Studio 2017"=="%APPVEYOR_BUILD_WORKER_IMAGE%" call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
|
||||
if "Visual Studio 2015"=="%APPVEYOR_BUILD_WORKER_IMAGE%" call "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64
|
||||
if "Visual Studio 2015"=="%APPVEYOR_BUILD_WORKER_IMAGE%" call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" x86_amd64
|
||||
nmake -f makefile.msvc all
|
||||
test_script:
|
||||
- cmd: test.exe
|
||||
@@ -4,6 +4,9 @@
|
||||
# usage:
|
||||
# astyle --options=astylerc *.[ch]
|
||||
|
||||
# Do not create backup, annonying in the times of git
|
||||
suffix=none
|
||||
|
||||
## Bracket Style Options
|
||||
style=kr
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_CUTOFFS_C
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
#ifndef MP_FIXED_CUTOFFS
|
||||
#include "tommath_cutoffs.h"
|
||||
int KARATSUBA_MUL_CUTOFF = MP_DEFAULT_KARATSUBA_MUL_CUTOFF,
|
||||
KARATSUBA_SQR_CUTOFF = MP_DEFAULT_KARATSUBA_SQR_CUTOFF,
|
||||
TOOM_MUL_CUTOFF = MP_DEFAULT_TOOM_MUL_CUTOFF,
|
||||
TOOM_SQR_CUTOFF = MP_DEFAULT_TOOM_SQR_CUTOFF;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,321 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_DEPRECATED_C
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
#ifdef BN_MP_GET_BIT_C
|
||||
int mp_get_bit(const mp_int *a, int b)
|
||||
{
|
||||
if (b < 0) {
|
||||
return MP_VAL;
|
||||
}
|
||||
return (s_mp_get_bit(a, (unsigned int)b) == MP_YES) ? MP_YES : MP_NO;
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_JACOBI_C
|
||||
mp_err mp_jacobi(const mp_int *a, const mp_int *n, int *c)
|
||||
{
|
||||
if (a->sign == MP_NEG) {
|
||||
return MP_VAL;
|
||||
}
|
||||
if (mp_cmp_d(n, 0uL) != MP_GT) {
|
||||
return MP_VAL;
|
||||
}
|
||||
return mp_kronecker(a, n, c);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_PRIME_RANDOM_EX_C
|
||||
mp_err mp_prime_random_ex(mp_int *a, int t, int size, int flags, private_mp_prime_callback cb, void *dat)
|
||||
{
|
||||
return s_mp_prime_random_ex(a, t, size, flags, cb, dat);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_RAND_DIGIT_C
|
||||
mp_err mp_rand_digit(mp_digit *r)
|
||||
{
|
||||
mp_err err = s_mp_rand_source(r, sizeof(mp_digit));
|
||||
*r &= MP_MASK;
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_FAST_MP_INVMOD_C
|
||||
mp_err fast_mp_invmod(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
{
|
||||
return s_mp_invmod_fast(a, b, c);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_FAST_MP_MONTGOMERY_REDUCE_C
|
||||
mp_err fast_mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho)
|
||||
{
|
||||
return s_mp_montgomery_reduce_fast(x, n, rho);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_FAST_S_MP_MUL_DIGS_C
|
||||
mp_err fast_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs)
|
||||
{
|
||||
return s_mp_mul_digs_fast(a, b, c, digs);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_FAST_S_MP_MUL_HIGH_DIGS_C
|
||||
mp_err fast_s_mp_mul_high_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs)
|
||||
{
|
||||
return s_mp_mul_high_digs_fast(a, b, c, digs);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_FAST_S_MP_SQR_C
|
||||
mp_err fast_s_mp_sqr(const mp_int *a, mp_int *b)
|
||||
{
|
||||
return s_mp_sqr_fast(a, b);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_BALANCE_MUL_C
|
||||
mp_err mp_balance_mul(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
{
|
||||
return s_mp_balance_mul(a, b, c);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_EXPTMOD_FAST_C
|
||||
mp_err mp_exptmod_fast(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y, int redmode)
|
||||
{
|
||||
return s_mp_exptmod_fast(G, X, P, Y, redmode);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_INVMOD_SLOW_C
|
||||
mp_err mp_invmod_slow(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
{
|
||||
return s_mp_invmod_slow(a, b, c);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_KARATSUBA_MUL_C
|
||||
mp_err mp_karatsuba_mul(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
{
|
||||
return s_mp_karatsuba_mul(a, b, c);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_KARATSUBA_SQR_C
|
||||
mp_err mp_karatsuba_sqr(const mp_int *a, mp_int *b)
|
||||
{
|
||||
return s_mp_karatsuba_sqr(a, b);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_TOOM_MUL_C
|
||||
mp_err mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
{
|
||||
return s_mp_toom_mul(a, b, c);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_TOOM_SQR_C
|
||||
mp_err mp_toom_sqr(const mp_int *a, mp_int *b)
|
||||
{
|
||||
return s_mp_toom_sqr(a, b);
|
||||
}
|
||||
#endif
|
||||
#ifdef S_MP_REVERSE_C
|
||||
void bn_reverse(unsigned char *s, int len)
|
||||
{
|
||||
if (len > 0) {
|
||||
s_mp_reverse(s, (size_t)len);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_TC_AND_C
|
||||
mp_err mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
{
|
||||
return mp_and(a, b, c);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_TC_OR_C
|
||||
mp_err mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
{
|
||||
return mp_or(a, b, c);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_TC_XOR_C
|
||||
mp_err mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
{
|
||||
return mp_xor(a, b, c);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_TC_DIV_2D_C
|
||||
mp_err mp_tc_div_2d(const mp_int *a, int b, mp_int *c)
|
||||
{
|
||||
return mp_signed_rsh(a, b, c);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_INIT_SET_INT_C
|
||||
mp_err mp_init_set_int(mp_int *a, unsigned long b)
|
||||
{
|
||||
return mp_init_u32(a, (uint32_t)b);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_SET_INT_C
|
||||
mp_err mp_set_int(mp_int *a, unsigned long b)
|
||||
{
|
||||
mp_set_u32(a, (uint32_t)b);
|
||||
return MP_OKAY;
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_SET_LONG_C
|
||||
mp_err mp_set_long(mp_int *a, unsigned long b)
|
||||
{
|
||||
mp_set_u64(a, b);
|
||||
return MP_OKAY;
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_SET_LONG_LONG_C
|
||||
mp_err mp_set_long_long(mp_int *a, unsigned long long b)
|
||||
{
|
||||
mp_set_u64(a, b);
|
||||
return MP_OKAY;
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_GET_INT_C
|
||||
unsigned long mp_get_int(const mp_int *a)
|
||||
{
|
||||
return (unsigned long)mp_get_mag_u32(a);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_GET_LONG_C
|
||||
unsigned long mp_get_long(const mp_int *a)
|
||||
{
|
||||
return (unsigned long)mp_get_mag_ul(a);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_GET_LONG_LONG_C
|
||||
unsigned long long mp_get_long_long(const mp_int *a)
|
||||
{
|
||||
return mp_get_mag_ull(a);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_PRIME_IS_DIVISIBLE_C
|
||||
mp_err mp_prime_is_divisible(const mp_int *a, mp_bool *result)
|
||||
{
|
||||
return s_mp_prime_is_divisible(a, result);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_EXPT_D_EX_C
|
||||
mp_err mp_expt_d_ex(const mp_int *a, mp_digit b, mp_int *c, int fast)
|
||||
{
|
||||
(void)fast;
|
||||
if (b > MP_MIN(MP_DIGIT_MAX, UINT32_MAX)) {
|
||||
return MP_VAL;
|
||||
}
|
||||
return mp_expt_u32(a, (uint32_t)b, c);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_EXPT_D_C
|
||||
mp_err mp_expt_d(const mp_int *a, mp_digit b, mp_int *c)
|
||||
{
|
||||
if (b > MP_MIN(MP_DIGIT_MAX, UINT32_MAX)) {
|
||||
return MP_VAL;
|
||||
}
|
||||
return mp_expt_u32(a, (uint32_t)b, c);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_N_ROOT_EX_C
|
||||
mp_err mp_n_root_ex(const mp_int *a, mp_digit b, mp_int *c, int fast)
|
||||
{
|
||||
(void)fast;
|
||||
if (b > MP_MIN(MP_DIGIT_MAX, UINT32_MAX)) {
|
||||
return MP_VAL;
|
||||
}
|
||||
return mp_root_u32(a, (unsigned int)b, c);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_N_ROOT_C
|
||||
mp_err mp_n_root(const mp_int *a, mp_digit b, mp_int *c)
|
||||
{
|
||||
if (b > MP_MIN(MP_DIGIT_MAX, UINT32_MAX)) {
|
||||
return MP_VAL;
|
||||
}
|
||||
return mp_root_u32(a, (unsigned int)b, c);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_UNSIGNED_BIN_SIZE_C
|
||||
int mp_unsigned_bin_size(const mp_int *a)
|
||||
{
|
||||
return (int)mp_ubin_size(a);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_READ_UNSIGNED_BIN_C
|
||||
mp_err mp_read_unsigned_bin(mp_int *a, const unsigned char *b, int c)
|
||||
{
|
||||
return mp_from_ubin(a, b, (size_t) c);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_TO_UNSIGNED_BIN_C
|
||||
mp_err mp_to_unsigned_bin(const mp_int *a, unsigned char *b)
|
||||
{
|
||||
return mp_to_ubin(a, b, SIZE_MAX, NULL);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_TO_UNSIGNED_BIN_N_C
|
||||
mp_err mp_to_unsigned_bin_n(const mp_int *a, unsigned char *b, unsigned long *outlen)
|
||||
{
|
||||
size_t n = mp_ubin_size(a);
|
||||
if (*outlen < (unsigned long)n) {
|
||||
return MP_VAL;
|
||||
}
|
||||
*outlen = (unsigned long)n;
|
||||
return mp_to_ubin(a, b, n, NULL);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_SIGNED_BIN_SIZE_C
|
||||
int mp_signed_bin_size(const mp_int *a)
|
||||
{
|
||||
return (int)mp_sbin_size(a);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_READ_SIGNED_BIN_C
|
||||
mp_err mp_read_signed_bin(mp_int *a, const unsigned char *b, int c)
|
||||
{
|
||||
return mp_from_sbin(a, b, (size_t) c);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_TO_SIGNED_BIN_C
|
||||
mp_err mp_to_signed_bin(const mp_int *a, unsigned char *b)
|
||||
{
|
||||
return mp_to_sbin(a, b, SIZE_MAX, NULL);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_TO_SIGNED_BIN_N_C
|
||||
mp_err mp_to_signed_bin_n(const mp_int *a, unsigned char *b, unsigned long *outlen)
|
||||
{
|
||||
size_t n = mp_sbin_size(a);
|
||||
if (*outlen < (unsigned long)n) {
|
||||
return MP_VAL;
|
||||
}
|
||||
*outlen = (unsigned long)n;
|
||||
return mp_to_sbin(a, b, n, NULL);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_TORADIX_N_C
|
||||
mp_err mp_toradix_n(const mp_int *a, char *str, int radix, int maxlen)
|
||||
{
|
||||
if (maxlen < 0) {
|
||||
return MP_VAL;
|
||||
}
|
||||
return mp_to_radix(a, str, (size_t)maxlen, NULL, radix);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_TORADIX_C
|
||||
mp_err mp_toradix(const mp_int *a, char *str, int radix)
|
||||
{
|
||||
return mp_to_radix(a, str, SIZE_MAX, NULL, radix);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_IMPORT_C
|
||||
mp_err mp_import(mp_int *rop, size_t count, int order, size_t size, int endian, size_t nails,
|
||||
const void *op)
|
||||
{
|
||||
return mp_unpack(rop, count, order, size, endian, nails, op);
|
||||
}
|
||||
#endif
|
||||
#ifdef BN_MP_EXPORT_C
|
||||
mp_err mp_export(void *rop, size_t *countp, int order, size_t size,
|
||||
int endian, size_t nails, const mp_int *op)
|
||||
{
|
||||
return mp_pack(rop, SIZE_MAX, countp, order, size, endian, nails, op);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,44 +0,0 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_ERROR_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
|
||||
static const struct {
|
||||
int code;
|
||||
const char *msg;
|
||||
} msgs[] = {
|
||||
{ MP_OKAY, "Successful" },
|
||||
{ MP_MEM, "Out of heap" },
|
||||
{ MP_VAL, "Value out of range" }
|
||||
};
|
||||
|
||||
/* return a char * string for a given code */
|
||||
const char *mp_error_to_string(int code)
|
||||
{
|
||||
size_t x;
|
||||
|
||||
/* scan the lookup table for the given message */
|
||||
for (x = 0; x < (sizeof(msgs) / sizeof(msgs[0])); x++) {
|
||||
if (msgs[x].code == code) {
|
||||
return msgs[x].msg;
|
||||
}
|
||||
}
|
||||
|
||||
/* generic reply for invalid code */
|
||||
return "Invalid error code";
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
@@ -1,160 +0,0 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_FAST_MP_INVMOD_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
|
||||
/* computes the modular inverse via binary extended euclidean algorithm,
|
||||
* that is c = 1/a mod b
|
||||
*
|
||||
* Based on slow invmod except this is optimized for the case where b is
|
||||
* odd as per HAC Note 14.64 on pp. 610
|
||||
*/
|
||||
int fast_mp_invmod(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
{
|
||||
mp_int x, y, u, v, B, D;
|
||||
int res, neg;
|
||||
|
||||
/* 2. [modified] b must be odd */
|
||||
if (mp_iseven(b) == MP_YES) {
|
||||
return MP_VAL;
|
||||
}
|
||||
|
||||
/* init all our temps */
|
||||
if ((res = mp_init_multi(&x, &y, &u, &v, &B, &D, NULL)) != MP_OKAY) {
|
||||
return res;
|
||||
}
|
||||
|
||||
/* x == modulus, y == value to invert */
|
||||
if ((res = mp_copy(b, &x)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
|
||||
/* we need y = |a| */
|
||||
if ((res = mp_mod(a, b, &y)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
|
||||
/* if one of x,y is zero return an error! */
|
||||
if ((mp_iszero(&x) == MP_YES) || (mp_iszero(&y) == MP_YES)) {
|
||||
res = MP_VAL;
|
||||
goto LBL_ERR;
|
||||
}
|
||||
|
||||
/* 3. u=x, v=y, A=1, B=0, C=0,D=1 */
|
||||
if ((res = mp_copy(&x, &u)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
if ((res = mp_copy(&y, &v)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
mp_set(&D, 1uL);
|
||||
|
||||
top:
|
||||
/* 4. while u is even do */
|
||||
while (mp_iseven(&u) == MP_YES) {
|
||||
/* 4.1 u = u/2 */
|
||||
if ((res = mp_div_2(&u, &u)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
/* 4.2 if B is odd then */
|
||||
if (mp_isodd(&B) == MP_YES) {
|
||||
if ((res = mp_sub(&B, &x, &B)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
}
|
||||
/* B = B/2 */
|
||||
if ((res = mp_div_2(&B, &B)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
/* 5. while v is even do */
|
||||
while (mp_iseven(&v) == MP_YES) {
|
||||
/* 5.1 v = v/2 */
|
||||
if ((res = mp_div_2(&v, &v)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
/* 5.2 if D is odd then */
|
||||
if (mp_isodd(&D) == MP_YES) {
|
||||
/* D = (D-x)/2 */
|
||||
if ((res = mp_sub(&D, &x, &D)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
}
|
||||
/* D = D/2 */
|
||||
if ((res = mp_div_2(&D, &D)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
/* 6. if u >= v then */
|
||||
if (mp_cmp(&u, &v) != MP_LT) {
|
||||
/* u = u - v, B = B - D */
|
||||
if ((res = mp_sub(&u, &v, &u)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
|
||||
if ((res = mp_sub(&B, &D, &B)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
} else {
|
||||
/* v - v - u, D = D - B */
|
||||
if ((res = mp_sub(&v, &u, &v)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
|
||||
if ((res = mp_sub(&D, &B, &D)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
/* if not zero goto step 4 */
|
||||
if (mp_iszero(&u) == MP_NO) {
|
||||
goto top;
|
||||
}
|
||||
|
||||
/* now a = C, b = D, gcd == g*v */
|
||||
|
||||
/* if v != 1 then there is no inverse */
|
||||
if (mp_cmp_d(&v, 1uL) != MP_EQ) {
|
||||
res = MP_VAL;
|
||||
goto LBL_ERR;
|
||||
}
|
||||
|
||||
/* b is now the inverse */
|
||||
neg = a->sign;
|
||||
while (D.sign == MP_NEG) {
|
||||
if ((res = mp_add(&D, b, &D)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
/* too big */
|
||||
while (mp_cmp_mag(&D, b) != MP_LT) {
|
||||
if ((res = mp_sub(&D, b, &D)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
mp_exch(&D, c);
|
||||
c->sign = neg;
|
||||
res = MP_OKAY;
|
||||
|
||||
LBL_ERR:
|
||||
mp_clear_multi(&x, &y, &u, &v, &B, &D, NULL);
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
@@ -1,44 +1,31 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_2EXPT_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* computes a = 2**b
|
||||
*
|
||||
* Simple algorithm which zeroes the int, grows it then just sets one bit
|
||||
* as required.
|
||||
*/
|
||||
int mp_2expt(mp_int *a, int b)
|
||||
mp_err mp_2expt(mp_int *a, int b)
|
||||
{
|
||||
int res;
|
||||
mp_err err;
|
||||
|
||||
/* zero a as per default */
|
||||
mp_zero(a);
|
||||
|
||||
/* grow a to accomodate the single bit */
|
||||
if ((res = mp_grow(a, (b / DIGIT_BIT) + 1)) != MP_OKAY) {
|
||||
return res;
|
||||
if ((err = mp_grow(a, (b / MP_DIGIT_BIT) + 1)) != MP_OKAY) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* set the used count of where the bit will go */
|
||||
a->used = (b / DIGIT_BIT) + 1;
|
||||
a->used = (b / MP_DIGIT_BIT) + 1;
|
||||
|
||||
/* put the single bit in its place */
|
||||
a->dp[b / DIGIT_BIT] = (mp_digit)1 << (mp_digit)(b % DIGIT_BIT);
|
||||
a->dp[b / MP_DIGIT_BIT] = (mp_digit)1 << (mp_digit)(b % MP_DIGIT_BIT);
|
||||
|
||||
return MP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
|
||||
+6
-19
@@ -1,29 +1,20 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_ABS_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* b = |a|
|
||||
*
|
||||
* Simple function copies the input and fixes the sign to positive
|
||||
*/
|
||||
int mp_abs(const mp_int *a, mp_int *b)
|
||||
mp_err mp_abs(const mp_int *a, mp_int *b)
|
||||
{
|
||||
int res;
|
||||
mp_err err;
|
||||
|
||||
/* copy a to b */
|
||||
if (a != b) {
|
||||
if ((res = mp_copy(a, b)) != MP_OKAY) {
|
||||
return res;
|
||||
if ((err = mp_copy(a, b)) != MP_OKAY) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +24,3 @@ int mp_abs(const mp_int *a, mp_int *b)
|
||||
return MP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
|
||||
+9
-21
@@ -1,21 +1,13 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_ADD_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* high level addition (handles signs) */
|
||||
int mp_add(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
mp_err mp_add(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
{
|
||||
int sa, sb, res;
|
||||
mp_sign sa, sb;
|
||||
mp_err err;
|
||||
|
||||
/* get sign of both inputs */
|
||||
sa = a->sign;
|
||||
@@ -26,7 +18,7 @@ int mp_add(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
/* both positive or both negative */
|
||||
/* add their magnitudes, copy the sign */
|
||||
c->sign = sa;
|
||||
res = s_mp_add(a, b, c);
|
||||
err = s_mp_add(a, b, c);
|
||||
} else {
|
||||
/* one positive, the other negative */
|
||||
/* subtract the one with the greater magnitude from */
|
||||
@@ -34,17 +26,13 @@ int mp_add(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
/* the sign of the one with the greater magnitude. */
|
||||
if (mp_cmp_mag(a, b) == MP_LT) {
|
||||
c->sign = sb;
|
||||
res = s_mp_sub(b, a, c);
|
||||
err = s_mp_sub(b, a, c);
|
||||
} else {
|
||||
c->sign = sa;
|
||||
res = s_mp_sub(a, b, c);
|
||||
err = s_mp_sub(a, b, c);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
return err;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
|
||||
+15
-35
@@ -1,27 +1,19 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_ADD_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* single digit addition */
|
||||
int mp_add_d(const mp_int *a, mp_digit b, mp_int *c)
|
||||
mp_err mp_add_d(const mp_int *a, mp_digit b, mp_int *c)
|
||||
{
|
||||
int res, ix, oldused;
|
||||
mp_digit *tmpa, *tmpc, mu;
|
||||
mp_err err;
|
||||
int ix, oldused;
|
||||
mp_digit *tmpa, *tmpc;
|
||||
|
||||
/* grow c as required */
|
||||
if (c->alloc < (a->used + 1)) {
|
||||
if ((res = mp_grow(c, a->used + 1)) != MP_OKAY) {
|
||||
return res;
|
||||
if ((err = mp_grow(c, a->used + 1)) != MP_OKAY) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +24,7 @@ int mp_add_d(const mp_int *a, mp_digit b, mp_int *c)
|
||||
a_.sign = MP_ZPOS;
|
||||
|
||||
/* c = |a| - b */
|
||||
res = mp_sub_d(&a_, b, c);
|
||||
err = mp_sub_d(&a_, b, c);
|
||||
|
||||
/* fix sign */
|
||||
c->sign = MP_NEG;
|
||||
@@ -40,7 +32,7 @@ int mp_add_d(const mp_int *a, mp_digit b, mp_int *c)
|
||||
/* clamp */
|
||||
mp_clamp(c);
|
||||
|
||||
return res;
|
||||
return err;
|
||||
}
|
||||
|
||||
/* old number of used digits in c */
|
||||
@@ -54,17 +46,11 @@ int mp_add_d(const mp_int *a, mp_digit b, mp_int *c)
|
||||
|
||||
/* if a is positive */
|
||||
if (a->sign == MP_ZPOS) {
|
||||
/* add digit, after this we're propagating
|
||||
* the carry.
|
||||
*/
|
||||
*tmpc = *tmpa++ + b;
|
||||
mu = *tmpc >> DIGIT_BIT;
|
||||
*tmpc++ &= MP_MASK;
|
||||
|
||||
/* now handle rest of the digits */
|
||||
for (ix = 1; ix < a->used; ix++) {
|
||||
/* add digits, mu is carry */
|
||||
mp_digit mu = b;
|
||||
for (ix = 0; ix < a->used; ix++) {
|
||||
*tmpc = *tmpa++ + mu;
|
||||
mu = *tmpc >> DIGIT_BIT;
|
||||
mu = *tmpc >> MP_DIGIT_BIT;
|
||||
*tmpc++ &= MP_MASK;
|
||||
}
|
||||
/* set final carry */
|
||||
@@ -94,16 +80,10 @@ int mp_add_d(const mp_int *a, mp_digit b, mp_int *c)
|
||||
c->sign = MP_ZPOS;
|
||||
|
||||
/* now zero to oldused */
|
||||
while (ix++ < oldused) {
|
||||
*tmpc++ = 0;
|
||||
}
|
||||
MP_ZERO_DIGITS(tmpc, oldused - ix);
|
||||
mp_clamp(c);
|
||||
|
||||
return MP_OKAY;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
|
||||
+12
-24
@@ -1,37 +1,25 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_ADDMOD_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* d = a + b (mod c) */
|
||||
int mp_addmod(const mp_int *a, const mp_int *b, const mp_int *c, mp_int *d)
|
||||
mp_err mp_addmod(const mp_int *a, const mp_int *b, const mp_int *c, mp_int *d)
|
||||
{
|
||||
int res;
|
||||
mp_err err;
|
||||
mp_int t;
|
||||
|
||||
if ((res = mp_init(&t)) != MP_OKAY) {
|
||||
return res;
|
||||
if ((err = mp_init(&t)) != MP_OKAY) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if ((res = mp_add(a, b, &t)) != MP_OKAY) {
|
||||
mp_clear(&t);
|
||||
return res;
|
||||
if ((err = mp_add(a, b, &t)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
res = mp_mod(&t, c, d);
|
||||
err = mp_mod(&t, c, d);
|
||||
|
||||
LBL_ERR:
|
||||
mp_clear(&t);
|
||||
return res;
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* two complement and */
|
||||
mp_err mp_and(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
{
|
||||
int used = MAX(a->used, b->used) + 1, i;
|
||||
int used = MP_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;
|
||||
|
||||
@@ -1,16 +1,7 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_CLAMP_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* trim unused digits
|
||||
*
|
||||
@@ -34,7 +25,3 @@ void mp_clamp(mp_int *a)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
|
||||
@@ -1,31 +1,15 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_CLEAR_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* clear one (frees) */
|
||||
void mp_clear(mp_int *a)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* only do anything if a hasn't been freed previously */
|
||||
if (a->dp != NULL) {
|
||||
/* first zero the digits */
|
||||
for (i = 0; i < a->used; i++) {
|
||||
a->dp[i] = 0;
|
||||
}
|
||||
|
||||
/* free ram */
|
||||
XFREE(a->dp, sizeof (mp_digit) * (size_t)a->alloc);
|
||||
MP_FREE_DIGITS(a->dp, a->alloc);
|
||||
|
||||
/* reset members to make debugging easier */
|
||||
a->dp = NULL;
|
||||
@@ -34,7 +18,3 @@ void mp_clear(mp_int *a)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
|
||||
@@ -1,16 +1,7 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_CLEAR_MULTI_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
@@ -26,7 +17,3 @@ void mp_clear_multi(mp_int *mp, ...)
|
||||
va_end(args);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
|
||||
@@ -1,16 +1,7 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_CNT_LSB_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
static const int lnz[16] = {
|
||||
4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0
|
||||
@@ -23,14 +14,14 @@ int mp_cnt_lsb(const mp_int *a)
|
||||
mp_digit q, qq;
|
||||
|
||||
/* easy out */
|
||||
if (mp_iszero(a) == MP_YES) {
|
||||
if (MP_IS_ZERO(a)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* scan lower digits until non-zero */
|
||||
for (x = 0; (x < a->used) && (a->dp[x] == 0u); x++) {}
|
||||
q = a->dp[x];
|
||||
x *= DIGIT_BIT;
|
||||
x *= MP_DIGIT_BIT;
|
||||
|
||||
/* now scan this digit until a 1 is found */
|
||||
if ((q & 1u) == 0u) {
|
||||
@@ -44,7 +35,3 @@ int mp_cnt_lsb(const mp_int *a)
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
|
||||
@@ -1,25 +1,12 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_COMPLEMENT_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* b = ~a */
|
||||
int mp_complement(const mp_int *a, mp_int *b)
|
||||
mp_err mp_complement(const mp_int *a, mp_int *b)
|
||||
{
|
||||
int res = mp_neg(a, b);
|
||||
return (res == MP_OKAY) ? mp_sub_d(b, 1uL, b) : res;
|
||||
mp_err err = mp_neg(a, b);
|
||||
return (err == MP_OKAY) ? mp_sub_d(b, 1uL, b) : err;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
|
||||
+19
-36
@@ -1,21 +1,14 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_COPY_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* copy, b = a */
|
||||
int mp_copy(const mp_int *a, mp_int *b)
|
||||
mp_err mp_copy(const mp_int *a, mp_int *b)
|
||||
{
|
||||
int res, n;
|
||||
int n;
|
||||
mp_digit *tmpa, *tmpb;
|
||||
mp_err err;
|
||||
|
||||
/* if dst == src do nothing */
|
||||
if (a == b) {
|
||||
@@ -24,41 +17,31 @@ int mp_copy(const mp_int *a, mp_int *b)
|
||||
|
||||
/* grow dest */
|
||||
if (b->alloc < a->used) {
|
||||
if ((res = mp_grow(b, a->used)) != MP_OKAY) {
|
||||
return res;
|
||||
if ((err = mp_grow(b, a->used)) != MP_OKAY) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
/* zero b and copy the parameters over */
|
||||
{
|
||||
mp_digit *tmpa, *tmpb;
|
||||
/* pointer aliases */
|
||||
|
||||
/* pointer aliases */
|
||||
/* source */
|
||||
tmpa = a->dp;
|
||||
|
||||
/* source */
|
||||
tmpa = a->dp;
|
||||
/* destination */
|
||||
tmpb = b->dp;
|
||||
|
||||
/* destination */
|
||||
tmpb = b->dp;
|
||||
|
||||
/* copy all the digits */
|
||||
for (n = 0; n < a->used; n++) {
|
||||
*tmpb++ = *tmpa++;
|
||||
}
|
||||
|
||||
/* clear high digits */
|
||||
for (; n < b->used; n++) {
|
||||
*tmpb++ = 0;
|
||||
}
|
||||
/* copy all the digits */
|
||||
for (n = 0; n < a->used; n++) {
|
||||
*tmpb++ = *tmpa++;
|
||||
}
|
||||
|
||||
/* clear high digits */
|
||||
MP_ZERO_DIGITS(tmpb, b->used - n);
|
||||
|
||||
/* copy used count and sign */
|
||||
b->used = a->used;
|
||||
b->sign = a->sign;
|
||||
return MP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
|
||||
@@ -1,16 +1,7 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_COUNT_BITS_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* returns the number of bits in an int */
|
||||
int mp_count_bits(const mp_int *a)
|
||||
@@ -19,23 +10,19 @@ int mp_count_bits(const mp_int *a)
|
||||
mp_digit q;
|
||||
|
||||
/* shortcut */
|
||||
if (a->used == 0) {
|
||||
if (MP_IS_ZERO(a)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* get number of digits and add that */
|
||||
r = (a->used - 1) * DIGIT_BIT;
|
||||
r = (a->used - 1) * MP_DIGIT_BIT;
|
||||
|
||||
/* take the last digit and count the bits in it */
|
||||
q = a->dp[a->used - 1];
|
||||
while (q > (mp_digit)0) {
|
||||
while (q > 0u) {
|
||||
++r;
|
||||
q >>= (mp_digit)1;
|
||||
q >>= 1u;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_DECR_C
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* Decrement "a" by one like "a--". Changes input! */
|
||||
mp_err mp_decr(mp_int *a)
|
||||
{
|
||||
if (MP_IS_ZERO(a)) {
|
||||
mp_set(a,1uL);
|
||||
a->sign = MP_NEG;
|
||||
return MP_OKAY;
|
||||
} else if (a->sign == MP_NEG) {
|
||||
mp_err err;
|
||||
a->sign = MP_ZPOS;
|
||||
if ((err = mp_incr(a)) != MP_OKAY) {
|
||||
return err;
|
||||
}
|
||||
/* There is no -0 in LTM */
|
||||
if (!MP_IS_ZERO(a)) {
|
||||
a->sign = MP_NEG;
|
||||
}
|
||||
return MP_OKAY;
|
||||
} else if (a->dp[0] > 1uL) {
|
||||
a->dp[0]--;
|
||||
if (a->dp[0] == 0u) {
|
||||
mp_zero(a);
|
||||
}
|
||||
return MP_OKAY;
|
||||
} else {
|
||||
return mp_sub_d(a, 1uL,a);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
+58
-105
@@ -1,69 +1,55 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_DIV_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
#ifdef BN_MP_DIV_SMALL
|
||||
|
||||
/* slower bit-bang division... also smaller */
|
||||
int mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d)
|
||||
mp_err mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d)
|
||||
{
|
||||
mp_int ta, tb, tq, q;
|
||||
int res, n, n2;
|
||||
int n, n2;
|
||||
mp_err err;
|
||||
|
||||
/* is divisor zero ? */
|
||||
if (mp_iszero(b) == MP_YES) {
|
||||
if (MP_IS_ZERO(b)) {
|
||||
return MP_VAL;
|
||||
}
|
||||
|
||||
/* if a < b then q=0, r = a */
|
||||
if (mp_cmp_mag(a, b) == MP_LT) {
|
||||
if (d != NULL) {
|
||||
res = mp_copy(a, d);
|
||||
err = mp_copy(a, d);
|
||||
} else {
|
||||
res = MP_OKAY;
|
||||
err = MP_OKAY;
|
||||
}
|
||||
if (c != NULL) {
|
||||
mp_zero(c);
|
||||
}
|
||||
return res;
|
||||
return err;
|
||||
}
|
||||
|
||||
/* init our temps */
|
||||
if ((res = mp_init_multi(&ta, &tb, &tq, &q, NULL)) != MP_OKAY) {
|
||||
return res;
|
||||
if ((err = mp_init_multi(&ta, &tb, &tq, &q, NULL)) != MP_OKAY) {
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
mp_set(&tq, 1uL);
|
||||
n = mp_count_bits(a) - mp_count_bits(b);
|
||||
if (((res = mp_abs(a, &ta)) != MP_OKAY) ||
|
||||
((res = mp_abs(b, &tb)) != MP_OKAY) ||
|
||||
((res = mp_mul_2d(&tb, n, &tb)) != MP_OKAY) ||
|
||||
((res = mp_mul_2d(&tq, n, &tq)) != MP_OKAY)) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
if ((err = mp_abs(a, &ta)) != MP_OKAY) goto LBL_ERR;
|
||||
if ((err = mp_abs(b, &tb)) != MP_OKAY) goto LBL_ERR;
|
||||
if ((err = mp_mul_2d(&tb, n, &tb)) != MP_OKAY) goto LBL_ERR;
|
||||
if ((err = mp_mul_2d(&tq, n, &tq)) != MP_OKAY) goto LBL_ERR;
|
||||
|
||||
while (n-- >= 0) {
|
||||
if (mp_cmp(&tb, &ta) != MP_GT) {
|
||||
if (((res = mp_sub(&ta, &tb, &ta)) != MP_OKAY) ||
|
||||
((res = mp_add(&q, &tq, &q)) != MP_OKAY)) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
}
|
||||
if (((res = mp_div_2d(&tb, 1, &tb, NULL)) != MP_OKAY) ||
|
||||
((res = mp_div_2d(&tq, 1, &tq, NULL)) != MP_OKAY)) {
|
||||
goto LBL_ERR;
|
||||
if ((err = mp_sub(&ta, &tb, &ta)) != MP_OKAY) goto LBL_ERR;
|
||||
if ((err = mp_add(&q, &tq, &q)) != MP_OKAY) goto LBL_ERR;
|
||||
}
|
||||
if ((err = mp_div_2d(&tb, 1, &tb, NULL)) != MP_OKAY) goto LBL_ERR;
|
||||
if ((err = mp_div_2d(&tq, 1, &tq, NULL)) != MP_OKAY) goto LBL_ERR;
|
||||
}
|
||||
|
||||
/* now q == quotient and ta == remainder */
|
||||
@@ -71,15 +57,15 @@ int mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d)
|
||||
n2 = (a->sign == b->sign) ? MP_ZPOS : MP_NEG;
|
||||
if (c != NULL) {
|
||||
mp_exch(c, &q);
|
||||
c->sign = (mp_iszero(c) == MP_YES) ? MP_ZPOS : n2;
|
||||
c->sign = MP_IS_ZERO(c) ? MP_ZPOS : n2;
|
||||
}
|
||||
if (d != NULL) {
|
||||
mp_exch(d, &ta);
|
||||
d->sign = (mp_iszero(d) == MP_YES) ? MP_ZPOS : n;
|
||||
d->sign = MP_IS_ZERO(d) ? MP_ZPOS : n;
|
||||
}
|
||||
LBL_ERR:
|
||||
mp_clear_multi(&ta, &tb, &tq, &q, NULL);
|
||||
return res;
|
||||
return err;
|
||||
}
|
||||
|
||||
#else
|
||||
@@ -97,64 +83,54 @@ LBL_ERR:
|
||||
* The overall algorithm is as described as
|
||||
* 14.20 from HAC but fixed to treat these cases.
|
||||
*/
|
||||
int mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d)
|
||||
mp_err mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d)
|
||||
{
|
||||
mp_int q, x, y, t1, t2;
|
||||
int res, n, t, i, norm, neg;
|
||||
int n, t, i, norm;
|
||||
mp_sign neg;
|
||||
mp_err err;
|
||||
|
||||
/* is divisor zero ? */
|
||||
if (mp_iszero(b) == MP_YES) {
|
||||
if (MP_IS_ZERO(b)) {
|
||||
return MP_VAL;
|
||||
}
|
||||
|
||||
/* if a < b then q=0, r = a */
|
||||
if (mp_cmp_mag(a, b) == MP_LT) {
|
||||
if (d != NULL) {
|
||||
res = mp_copy(a, d);
|
||||
err = mp_copy(a, d);
|
||||
} else {
|
||||
res = MP_OKAY;
|
||||
err = MP_OKAY;
|
||||
}
|
||||
if (c != NULL) {
|
||||
mp_zero(c);
|
||||
}
|
||||
return res;
|
||||
return err;
|
||||
}
|
||||
|
||||
if ((res = mp_init_size(&q, a->used + 2)) != MP_OKAY) {
|
||||
return res;
|
||||
if ((err = mp_init_size(&q, a->used + 2)) != MP_OKAY) {
|
||||
return err;
|
||||
}
|
||||
q.used = a->used + 2;
|
||||
|
||||
if ((res = mp_init(&t1)) != MP_OKAY) {
|
||||
goto LBL_Q;
|
||||
}
|
||||
if ((err = mp_init(&t1)) != MP_OKAY) goto LBL_Q;
|
||||
|
||||
if ((res = mp_init(&t2)) != MP_OKAY) {
|
||||
goto LBL_T1;
|
||||
}
|
||||
if ((err = mp_init(&t2)) != MP_OKAY) goto LBL_T1;
|
||||
|
||||
if ((res = mp_init_copy(&x, a)) != MP_OKAY) {
|
||||
goto LBL_T2;
|
||||
}
|
||||
if ((err = mp_init_copy(&x, a)) != MP_OKAY) goto LBL_T2;
|
||||
|
||||
if ((res = mp_init_copy(&y, b)) != MP_OKAY) {
|
||||
goto LBL_X;
|
||||
}
|
||||
if ((err = mp_init_copy(&y, b)) != MP_OKAY) goto LBL_X;
|
||||
|
||||
/* fix the sign */
|
||||
neg = (a->sign == b->sign) ? MP_ZPOS : MP_NEG;
|
||||
x.sign = y.sign = MP_ZPOS;
|
||||
|
||||
/* normalize both x and y, ensure that y >= b/2, [b == 2**DIGIT_BIT] */
|
||||
norm = mp_count_bits(&y) % DIGIT_BIT;
|
||||
if (norm < (DIGIT_BIT - 1)) {
|
||||
norm = (DIGIT_BIT - 1) - norm;
|
||||
if ((res = mp_mul_2d(&x, norm, &x)) != MP_OKAY) {
|
||||
goto LBL_Y;
|
||||
}
|
||||
if ((res = mp_mul_2d(&y, norm, &y)) != MP_OKAY) {
|
||||
goto LBL_Y;
|
||||
}
|
||||
/* normalize both x and y, ensure that y >= b/2, [b == 2**MP_DIGIT_BIT] */
|
||||
norm = mp_count_bits(&y) % MP_DIGIT_BIT;
|
||||
if (norm < (MP_DIGIT_BIT - 1)) {
|
||||
norm = (MP_DIGIT_BIT - 1) - norm;
|
||||
if ((err = mp_mul_2d(&x, norm, &x)) != MP_OKAY) goto LBL_Y;
|
||||
if ((err = mp_mul_2d(&y, norm, &y)) != MP_OKAY) goto LBL_Y;
|
||||
} else {
|
||||
norm = 0;
|
||||
}
|
||||
@@ -164,15 +140,12 @@ int mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d)
|
||||
t = y.used - 1;
|
||||
|
||||
/* while (x >= y*b**n-t) do { q[n-t] += 1; x -= y*b**{n-t} } */
|
||||
if ((res = mp_lshd(&y, n - t)) != MP_OKAY) { /* y = y*b**{n-t} */
|
||||
goto LBL_Y;
|
||||
}
|
||||
/* y = y*b**{n-t} */
|
||||
if ((err = mp_lshd(&y, n - t)) != MP_OKAY) goto LBL_Y;
|
||||
|
||||
while (mp_cmp(&x, &y) != MP_LT) {
|
||||
++(q.dp[n - t]);
|
||||
if ((res = mp_sub(&x, &y, &x)) != MP_OKAY) {
|
||||
goto LBL_Y;
|
||||
}
|
||||
if ((err = mp_sub(&x, &y, &x)) != MP_OKAY) goto LBL_Y;
|
||||
}
|
||||
|
||||
/* reset y by shifting it back down */
|
||||
@@ -187,10 +160,10 @@ int mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d)
|
||||
/* step 3.1 if xi == yt then set q{i-t-1} to b-1,
|
||||
* otherwise set q{i-t-1} to (xi*b + x{i-1})/yt */
|
||||
if (x.dp[i] == y.dp[t]) {
|
||||
q.dp[(i - t) - 1] = ((mp_digit)1 << (mp_digit)DIGIT_BIT) - (mp_digit)1;
|
||||
q.dp[(i - t) - 1] = ((mp_digit)1 << (mp_digit)MP_DIGIT_BIT) - (mp_digit)1;
|
||||
} else {
|
||||
mp_word tmp;
|
||||
tmp = (mp_word)x.dp[i] << (mp_word)DIGIT_BIT;
|
||||
tmp = (mp_word)x.dp[i] << (mp_word)MP_DIGIT_BIT;
|
||||
tmp |= (mp_word)x.dp[i - 1];
|
||||
tmp /= (mp_word)y.dp[t];
|
||||
if (tmp > (mp_word)MP_MASK) {
|
||||
@@ -213,41 +186,27 @@ int mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d)
|
||||
t1.dp[0] = ((t - 1) < 0) ? 0u : y.dp[t - 1];
|
||||
t1.dp[1] = y.dp[t];
|
||||
t1.used = 2;
|
||||
if ((res = mp_mul_d(&t1, q.dp[(i - t) - 1], &t1)) != MP_OKAY) {
|
||||
goto LBL_Y;
|
||||
}
|
||||
if ((err = mp_mul_d(&t1, q.dp[(i - t) - 1], &t1)) != MP_OKAY) goto LBL_Y;
|
||||
|
||||
/* find right hand */
|
||||
t2.dp[0] = ((i - 2) < 0) ? 0u : x.dp[i - 2];
|
||||
t2.dp[1] = ((i - 1) < 0) ? 0u : x.dp[i - 1];
|
||||
t2.dp[1] = x.dp[i - 1]; /* i >= 1 always holds */
|
||||
t2.dp[2] = x.dp[i];
|
||||
t2.used = 3;
|
||||
} while (mp_cmp_mag(&t1, &t2) == MP_GT);
|
||||
|
||||
/* step 3.3 x = x - q{i-t-1} * y * b**{i-t-1} */
|
||||
if ((res = mp_mul_d(&y, q.dp[(i - t) - 1], &t1)) != MP_OKAY) {
|
||||
goto LBL_Y;
|
||||
}
|
||||
if ((err = mp_mul_d(&y, q.dp[(i - t) - 1], &t1)) != MP_OKAY) goto LBL_Y;
|
||||
|
||||
if ((res = mp_lshd(&t1, (i - t) - 1)) != MP_OKAY) {
|
||||
goto LBL_Y;
|
||||
}
|
||||
if ((err = mp_lshd(&t1, (i - t) - 1)) != MP_OKAY) goto LBL_Y;
|
||||
|
||||
if ((res = mp_sub(&x, &t1, &x)) != MP_OKAY) {
|
||||
goto LBL_Y;
|
||||
}
|
||||
if ((err = mp_sub(&x, &t1, &x)) != MP_OKAY) goto LBL_Y;
|
||||
|
||||
/* if x < 0 then { x = x + y*b**{i-t-1}; q{i-t-1} -= 1; } */
|
||||
if (x.sign == MP_NEG) {
|
||||
if ((res = mp_copy(&y, &t1)) != MP_OKAY) {
|
||||
goto LBL_Y;
|
||||
}
|
||||
if ((res = mp_lshd(&t1, (i - t) - 1)) != MP_OKAY) {
|
||||
goto LBL_Y;
|
||||
}
|
||||
if ((res = mp_add(&x, &t1, &x)) != MP_OKAY) {
|
||||
goto LBL_Y;
|
||||
}
|
||||
if ((err = mp_copy(&y, &t1)) != MP_OKAY) goto LBL_Y;
|
||||
if ((err = mp_lshd(&t1, (i - t) - 1)) != MP_OKAY) goto LBL_Y;
|
||||
if ((err = mp_add(&x, &t1, &x)) != MP_OKAY) goto LBL_Y;
|
||||
|
||||
q.dp[(i - t) - 1] = (q.dp[(i - t) - 1] - 1uL) & MP_MASK;
|
||||
}
|
||||
@@ -267,13 +226,11 @@ int mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d)
|
||||
}
|
||||
|
||||
if (d != NULL) {
|
||||
if ((res = mp_div_2d(&x, norm, &x, NULL)) != MP_OKAY) {
|
||||
goto LBL_Y;
|
||||
}
|
||||
if ((err = mp_div_2d(&x, norm, &x, NULL)) != MP_OKAY) goto LBL_Y;
|
||||
mp_exch(&x, d);
|
||||
}
|
||||
|
||||
res = MP_OKAY;
|
||||
err = MP_OKAY;
|
||||
|
||||
LBL_Y:
|
||||
mp_clear(&y);
|
||||
@@ -285,13 +242,9 @@ LBL_T1:
|
||||
mp_clear(&t1);
|
||||
LBL_Q:
|
||||
mp_clear(&q);
|
||||
return res;
|
||||
return err;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
|
||||
+25
-41
@@ -1,65 +1,49 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_DIV_2_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* b = a/2 */
|
||||
int mp_div_2(const mp_int *a, mp_int *b)
|
||||
mp_err mp_div_2(const mp_int *a, mp_int *b)
|
||||
{
|
||||
int x, res, oldused;
|
||||
int x, oldused;
|
||||
mp_digit r, rr, *tmpa, *tmpb;
|
||||
mp_err err;
|
||||
|
||||
/* copy */
|
||||
if (b->alloc < a->used) {
|
||||
if ((res = mp_grow(b, a->used)) != MP_OKAY) {
|
||||
return res;
|
||||
if ((err = mp_grow(b, a->used)) != MP_OKAY) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
oldused = b->used;
|
||||
b->used = a->used;
|
||||
{
|
||||
mp_digit r, rr, *tmpa, *tmpb;
|
||||
|
||||
/* source alias */
|
||||
tmpa = a->dp + b->used - 1;
|
||||
/* source alias */
|
||||
tmpa = a->dp + b->used - 1;
|
||||
|
||||
/* dest alias */
|
||||
tmpb = b->dp + b->used - 1;
|
||||
/* dest alias */
|
||||
tmpb = b->dp + b->used - 1;
|
||||
|
||||
/* carry */
|
||||
r = 0;
|
||||
for (x = b->used - 1; x >= 0; x--) {
|
||||
/* get the carry for the next iteration */
|
||||
rr = *tmpa & 1u;
|
||||
/* carry */
|
||||
r = 0;
|
||||
for (x = b->used - 1; x >= 0; x--) {
|
||||
/* get the carry for the next iteration */
|
||||
rr = *tmpa & 1u;
|
||||
|
||||
/* shift the current digit, add in carry and store */
|
||||
*tmpb-- = (*tmpa-- >> 1) | (r << (DIGIT_BIT - 1));
|
||||
/* shift the current digit, add in carry and store */
|
||||
*tmpb-- = (*tmpa-- >> 1) | (r << (MP_DIGIT_BIT - 1));
|
||||
|
||||
/* forward carry to next iteration */
|
||||
r = rr;
|
||||
}
|
||||
|
||||
/* zero excess digits */
|
||||
tmpb = b->dp + b->used;
|
||||
for (x = b->used; x < oldused; x++) {
|
||||
*tmpb++ = 0;
|
||||
}
|
||||
/* forward carry to next iteration */
|
||||
r = rr;
|
||||
}
|
||||
|
||||
/* zero excess digits */
|
||||
MP_ZERO_DIGITS(b->dp + b->used, oldused - b->used);
|
||||
|
||||
b->sign = a->sign;
|
||||
mp_clamp(b);
|
||||
return MP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
|
||||
+16
-28
@@ -1,52 +1,44 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_DIV_2D_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* shift right by a certain bit count (store quotient in c, optional remainder in d) */
|
||||
int mp_div_2d(const mp_int *a, int b, mp_int *c, mp_int *d)
|
||||
mp_err mp_div_2d(const mp_int *a, int b, mp_int *c, mp_int *d)
|
||||
{
|
||||
mp_digit D, r, rr;
|
||||
int x, res;
|
||||
int x;
|
||||
mp_err err;
|
||||
|
||||
/* if the shift count is <= 0 then we do no work */
|
||||
if (b <= 0) {
|
||||
res = mp_copy(a, c);
|
||||
err = mp_copy(a, c);
|
||||
if (d != NULL) {
|
||||
mp_zero(d);
|
||||
}
|
||||
return res;
|
||||
return err;
|
||||
}
|
||||
|
||||
/* copy */
|
||||
if ((res = mp_copy(a, c)) != MP_OKAY) {
|
||||
return res;
|
||||
if ((err = mp_copy(a, c)) != MP_OKAY) {
|
||||
return err;
|
||||
}
|
||||
/* 'a' should not be used after here - it might be the same as d */
|
||||
|
||||
/* get the remainder */
|
||||
if (d != NULL) {
|
||||
if ((res = mp_mod_2d(a, b, d)) != MP_OKAY) {
|
||||
return res;
|
||||
if ((err = mp_mod_2d(a, b, d)) != MP_OKAY) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
/* shift by as many digits in the bit count */
|
||||
if (b >= DIGIT_BIT) {
|
||||
mp_rshd(c, b / DIGIT_BIT);
|
||||
if (b >= MP_DIGIT_BIT) {
|
||||
mp_rshd(c, b / MP_DIGIT_BIT);
|
||||
}
|
||||
|
||||
/* shift any bit count < DIGIT_BIT */
|
||||
D = (mp_digit)(b % DIGIT_BIT);
|
||||
/* shift any bit count < MP_DIGIT_BIT */
|
||||
D = (mp_digit)(b % MP_DIGIT_BIT);
|
||||
if (D != 0u) {
|
||||
mp_digit *tmpc, mask, shift;
|
||||
|
||||
@@ -54,7 +46,7 @@ int mp_div_2d(const mp_int *a, int b, mp_int *c, mp_int *d)
|
||||
mask = ((mp_digit)1 << D) - 1uL;
|
||||
|
||||
/* shift for lsb */
|
||||
shift = (mp_digit)DIGIT_BIT - D;
|
||||
shift = (mp_digit)MP_DIGIT_BIT - D;
|
||||
|
||||
/* alias */
|
||||
tmpc = c->dp + (c->used - 1);
|
||||
@@ -77,7 +69,3 @@ int mp_div_2d(const mp_int *a, int b, mp_int *c, mp_int *d)
|
||||
return MP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
|
||||
+12
-24
@@ -1,41 +1,33 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_DIV_3_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* divide by three (based on routine from MPI and the GMP manual) */
|
||||
int mp_div_3(const mp_int *a, mp_int *c, mp_digit *d)
|
||||
mp_err mp_div_3(const mp_int *a, mp_int *c, mp_digit *d)
|
||||
{
|
||||
mp_int q;
|
||||
mp_word w, t;
|
||||
mp_digit b;
|
||||
int res, ix;
|
||||
mp_err err;
|
||||
int ix;
|
||||
|
||||
/* b = 2**DIGIT_BIT / 3 */
|
||||
b = ((mp_word)1 << (mp_word)DIGIT_BIT) / (mp_word)3;
|
||||
/* b = 2**MP_DIGIT_BIT / 3 */
|
||||
b = ((mp_word)1 << (mp_word)MP_DIGIT_BIT) / (mp_word)3;
|
||||
|
||||
if ((res = mp_init_size(&q, a->used)) != MP_OKAY) {
|
||||
return res;
|
||||
if ((err = mp_init_size(&q, a->used)) != MP_OKAY) {
|
||||
return err;
|
||||
}
|
||||
|
||||
q.used = a->used;
|
||||
q.sign = a->sign;
|
||||
w = 0;
|
||||
for (ix = a->used - 1; ix >= 0; ix--) {
|
||||
w = (w << (mp_word)DIGIT_BIT) | (mp_word)a->dp[ix];
|
||||
w = (w << (mp_word)MP_DIGIT_BIT) | (mp_word)a->dp[ix];
|
||||
|
||||
if (w >= 3u) {
|
||||
/* multiply w by [1/3] */
|
||||
t = (w * (mp_word)b) >> (mp_word)DIGIT_BIT;
|
||||
t = (w * (mp_word)b) >> (mp_word)MP_DIGIT_BIT;
|
||||
|
||||
/* now subtract 3 * [w/3] from w, to get the remainder */
|
||||
w -= t+t+t;
|
||||
@@ -65,11 +57,7 @@ int mp_div_3(const mp_int *a, mp_int *c, mp_digit *d)
|
||||
}
|
||||
mp_clear(&q);
|
||||
|
||||
return res;
|
||||
return err;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
|
||||
+15
-30
@@ -1,24 +1,16 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_DIV_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* single digit division (based on routine from MPI) */
|
||||
int mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d)
|
||||
mp_err mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d)
|
||||
{
|
||||
mp_int q;
|
||||
mp_word w;
|
||||
mp_digit t;
|
||||
int res, ix;
|
||||
mp_err err;
|
||||
int ix;
|
||||
|
||||
/* cannot divide by zero */
|
||||
if (b == 0u) {
|
||||
@@ -26,7 +18,7 @@ int mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d)
|
||||
}
|
||||
|
||||
/* quick outs */
|
||||
if ((b == 1u) || (mp_iszero(a) == MP_YES)) {
|
||||
if ((b == 1u) || MP_IS_ZERO(a)) {
|
||||
if (d != NULL) {
|
||||
*d = 0;
|
||||
}
|
||||
@@ -37,11 +29,10 @@ int mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d)
|
||||
}
|
||||
|
||||
/* power of two ? */
|
||||
if (((b & (b-1)) == 0)) {
|
||||
for (ix = 1; ix < DIGIT_BIT; ix++) {
|
||||
if (b == (((mp_digit)1)<<ix)) {
|
||||
break;
|
||||
}
|
||||
if ((b & (b - 1u)) == 0u) {
|
||||
ix = 1;
|
||||
while ((ix < MP_DIGIT_BIT) && (b != (((mp_digit)1)<<ix))) {
|
||||
ix++;
|
||||
}
|
||||
if (d != NULL) {
|
||||
*d = a->dp[0] & (((mp_digit)1<<(mp_digit)ix) - 1uL);
|
||||
@@ -52,23 +43,21 @@ int mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d)
|
||||
return MP_OKAY;
|
||||
}
|
||||
|
||||
#ifdef BN_MP_DIV_3_C
|
||||
/* three? */
|
||||
if (b == 3u) {
|
||||
if (MP_HAS(MP_DIV_3) && (b == 3u)) {
|
||||
return mp_div_3(a, c, d);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* no easy answer [c'est la vie]. Just division */
|
||||
if ((res = mp_init_size(&q, a->used)) != MP_OKAY) {
|
||||
return res;
|
||||
if ((err = mp_init_size(&q, a->used)) != MP_OKAY) {
|
||||
return err;
|
||||
}
|
||||
|
||||
q.used = a->used;
|
||||
q.sign = a->sign;
|
||||
w = 0;
|
||||
for (ix = a->used - 1; ix >= 0; ix--) {
|
||||
w = (w << (mp_word)DIGIT_BIT) | (mp_word)a->dp[ix];
|
||||
w = (w << (mp_word)MP_DIGIT_BIT) | (mp_word)a->dp[ix];
|
||||
|
||||
if (w >= b) {
|
||||
t = (mp_digit)(w / b);
|
||||
@@ -89,11 +78,7 @@ int mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d)
|
||||
}
|
||||
mp_clear(&q);
|
||||
|
||||
return res;
|
||||
return err;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
|
||||
@@ -1,25 +1,16 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_DR_IS_MODULUS_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* determines if a number is a valid DR modulus */
|
||||
int mp_dr_is_modulus(const mp_int *a)
|
||||
mp_bool mp_dr_is_modulus(const mp_int *a)
|
||||
{
|
||||
int ix;
|
||||
|
||||
/* must be at least two digits */
|
||||
if (a->used < 2) {
|
||||
return 0;
|
||||
return MP_NO;
|
||||
}
|
||||
|
||||
/* must be of the form b**k - a [a <= b] so all
|
||||
@@ -27,14 +18,10 @@ int mp_dr_is_modulus(const mp_int *a)
|
||||
*/
|
||||
for (ix = 1; ix < a->used; ix++) {
|
||||
if (a->dp[ix] != MP_MASK) {
|
||||
return 0;
|
||||
return MP_NO;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
return MP_YES;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
|
||||
@@ -1,16 +1,7 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_DR_REDUCE_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* reduce "x" in place modulo "n" using the Diminished Radix algorithm.
|
||||
*
|
||||
@@ -26,9 +17,10 @@
|
||||
*
|
||||
* Input x must be in the range 0 <= x <= (n-1)**2
|
||||
*/
|
||||
int mp_dr_reduce(mp_int *x, const mp_int *n, mp_digit k)
|
||||
mp_err mp_dr_reduce(mp_int *x, const mp_int *n, mp_digit k)
|
||||
{
|
||||
int err, i, m;
|
||||
mp_err err;
|
||||
int i, m;
|
||||
mp_word r;
|
||||
mp_digit mu, *tmpx1, *tmpx2;
|
||||
|
||||
@@ -60,16 +52,14 @@ top:
|
||||
for (i = 0; i < m; i++) {
|
||||
r = ((mp_word)*tmpx2++ * (mp_word)k) + *tmpx1 + mu;
|
||||
*tmpx1++ = (mp_digit)(r & MP_MASK);
|
||||
mu = (mp_digit)(r >> ((mp_word)DIGIT_BIT));
|
||||
mu = (mp_digit)(r >> ((mp_word)MP_DIGIT_BIT));
|
||||
}
|
||||
|
||||
/* set final carry */
|
||||
*tmpx1++ = mu;
|
||||
|
||||
/* zero words above m */
|
||||
for (i = m + 1; i < x->used; i++) {
|
||||
*tmpx1++ = 0;
|
||||
}
|
||||
MP_ZERO_DIGITS(tmpx1, (x->used - m) - 1);
|
||||
|
||||
/* clamp, sub and return */
|
||||
mp_clamp(x);
|
||||
@@ -86,7 +76,3 @@ top:
|
||||
return MP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
|
||||
@@ -1,28 +1,15 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_DR_SETUP_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* determines the setup value */
|
||||
void mp_dr_setup(const mp_int *a, mp_digit *d)
|
||||
{
|
||||
/* the casts are required if DIGIT_BIT is one less than
|
||||
* the number of bits in a mp_digit [e.g. DIGIT_BIT==31]
|
||||
/* the casts are required if MP_DIGIT_BIT is one less than
|
||||
* the number of bits in a mp_digit [e.g. MP_DIGIT_BIT==31]
|
||||
*/
|
||||
*d = (mp_digit)(((mp_word)1 << (mp_word)DIGIT_BIT) - (mp_word)a->dp[0]);
|
||||
*d = (mp_digit)(((mp_word)1 << (mp_word)MP_DIGIT_BIT) - (mp_word)a->dp[0]);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_ERROR_TO_STRING_C
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* return a char * string for a given code */
|
||||
const char *mp_error_to_string(mp_err code)
|
||||
{
|
||||
switch (code) {
|
||||
case MP_OKAY:
|
||||
return "Successful";
|
||||
case MP_ERR:
|
||||
return "Unknown error";
|
||||
case MP_MEM:
|
||||
return "Out of heap";
|
||||
case MP_VAL:
|
||||
return "Value out of range";
|
||||
case MP_ITER:
|
||||
return "Max. iterations reached";
|
||||
case MP_BUF:
|
||||
return "Buffer overflow";
|
||||
default:
|
||||
return "Invalid error code";
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
+2
-15
@@ -1,16 +1,7 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_EXCH_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* swap the elements of two integers, for cases where you can't simply swap the
|
||||
* mp_int pointers around
|
||||
@@ -24,7 +15,3 @@ void mp_exch(mp_int *a, mp_int *b)
|
||||
*b = t;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_EXPORT_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
|
||||
/* based on gmp's mpz_export.
|
||||
* see http://gmplib.org/manual/Integer-Import-and-Export.html
|
||||
*/
|
||||
int mp_export(void *rop, size_t *countp, int order, size_t size,
|
||||
int endian, size_t nails, const mp_int *op)
|
||||
{
|
||||
int result;
|
||||
size_t odd_nails, nail_bytes, i, j, bits, count;
|
||||
unsigned char odd_nail_mask;
|
||||
|
||||
mp_int t;
|
||||
|
||||
if ((result = mp_init_copy(&t, op)) != MP_OKAY) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (endian == 0) {
|
||||
union {
|
||||
unsigned int i;
|
||||
char c[4];
|
||||
} lint;
|
||||
lint.i = 0x01020304;
|
||||
|
||||
endian = (lint.c[0] == '\x04') ? -1 : 1;
|
||||
}
|
||||
|
||||
odd_nails = (nails % 8u);
|
||||
odd_nail_mask = 0xff;
|
||||
for (i = 0; i < odd_nails; ++i) {
|
||||
odd_nail_mask ^= (unsigned char)(1u << (7u - i));
|
||||
}
|
||||
nail_bytes = nails / 8u;
|
||||
|
||||
bits = (size_t)mp_count_bits(&t);
|
||||
count = (bits / ((size * 8u) - nails)) + (((bits % ((size * 8u) - nails)) != 0u) ? 1u : 0u);
|
||||
|
||||
for (i = 0; i < count; ++i) {
|
||||
for (j = 0; j < size; ++j) {
|
||||
unsigned char *byte = (unsigned char *)rop +
|
||||
(((order == -1) ? i : ((count - 1u) - i)) * size) +
|
||||
((endian == -1) ? j : ((size - 1u) - j));
|
||||
|
||||
if (j >= (size - nail_bytes)) {
|
||||
*byte = 0;
|
||||
continue;
|
||||
}
|
||||
|
||||
*byte = (unsigned char)((j == ((size - nail_bytes) - 1u)) ? (t.dp[0] & odd_nail_mask) : (t.dp[0] & 0xFFuL));
|
||||
|
||||
if ((result = mp_div_2d(&t, (j == ((size - nail_bytes) - 1u)) ? (int)(8u - odd_nails) : 8, &t, NULL)) != MP_OKAY) {
|
||||
mp_clear(&t);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mp_clear(&t);
|
||||
|
||||
if (countp != NULL) {
|
||||
*countp = count;
|
||||
}
|
||||
|
||||
return MP_OKAY;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
@@ -1,25 +0,0 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_EXPT_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
|
||||
/* wrapper function for mp_expt_d_ex() */
|
||||
int mp_expt_d(const mp_int *a, mp_digit b, mp_int *c)
|
||||
{
|
||||
return mp_expt_d_ex(a, b, c, 0);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
@@ -1,79 +0,0 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_EXPT_D_EX_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
|
||||
/* calculate c = a**b using a square-multiply algorithm */
|
||||
int mp_expt_d_ex(const mp_int *a, mp_digit b, mp_int *c, int fast)
|
||||
{
|
||||
int res;
|
||||
unsigned int x;
|
||||
|
||||
mp_int g;
|
||||
|
||||
if ((res = mp_init_copy(&g, a)) != MP_OKAY) {
|
||||
return res;
|
||||
}
|
||||
|
||||
/* set initial result */
|
||||
mp_set(c, 1uL);
|
||||
|
||||
if (fast != 0) {
|
||||
while (b > 0u) {
|
||||
/* if the bit is set multiply */
|
||||
if ((b & 1u) != 0u) {
|
||||
if ((res = mp_mul(c, &g, c)) != MP_OKAY) {
|
||||
mp_clear(&g);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
/* square */
|
||||
if (b > 1u) {
|
||||
if ((res = mp_sqr(&g, &g)) != MP_OKAY) {
|
||||
mp_clear(&g);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
/* shift to next bit */
|
||||
b >>= 1;
|
||||
}
|
||||
} else {
|
||||
for (x = 0; x < (unsigned)DIGIT_BIT; x++) {
|
||||
/* square */
|
||||
if ((res = mp_sqr(c, c)) != MP_OKAY) {
|
||||
mp_clear(&g);
|
||||
return res;
|
||||
}
|
||||
|
||||
/* if the bit is set multiply */
|
||||
if ((b & ((mp_digit)1 << (DIGIT_BIT - 1))) != 0u) {
|
||||
if ((res = mp_mul(c, &g, c)) != MP_OKAY) {
|
||||
mp_clear(&g);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
/* shift to next bit */
|
||||
b <<= 1;
|
||||
}
|
||||
} /* if ... else */
|
||||
|
||||
mp_clear(&g);
|
||||
return MP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
@@ -0,0 +1,46 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_EXPT_U32_C
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* calculate c = a**b using a square-multiply algorithm */
|
||||
mp_err mp_expt_u32(const mp_int *a, unsigned int b, mp_int *c)
|
||||
{
|
||||
mp_err err;
|
||||
|
||||
mp_int g;
|
||||
|
||||
if ((err = mp_init_copy(&g, a)) != MP_OKAY) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* set initial result */
|
||||
mp_set(c, 1uL);
|
||||
|
||||
while (b > 0u) {
|
||||
/* if the bit is set multiply */
|
||||
if ((b & 1u) != 0u) {
|
||||
if ((err = mp_mul(c, &g, c)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
/* square */
|
||||
if (b > 1u) {
|
||||
if ((err = mp_sqr(&g, &g)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
}
|
||||
|
||||
/* shift to next bit */
|
||||
b >>= 1;
|
||||
}
|
||||
|
||||
err = MP_OKAY;
|
||||
|
||||
LBL_ERR:
|
||||
mp_clear(&g);
|
||||
return err;
|
||||
}
|
||||
|
||||
#endif
|
||||
+24
-57
@@ -1,24 +1,14 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_EXPTMOD_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* this is a shell function that calls either the normal or Montgomery
|
||||
* exptmod functions. Originally the call to the montgomery code was
|
||||
* embedded in the normal function but that wasted alot of stack space
|
||||
* for nothing (since 99% of the time the Montgomery code would be called)
|
||||
*/
|
||||
int mp_exptmod(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y)
|
||||
mp_err mp_exptmod(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y)
|
||||
{
|
||||
int dr;
|
||||
|
||||
@@ -29,81 +19,58 @@ int mp_exptmod(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y)
|
||||
|
||||
/* if exponent X is negative we have to recurse */
|
||||
if (X->sign == MP_NEG) {
|
||||
#ifdef BN_MP_INVMOD_C
|
||||
mp_int tmpG, tmpX;
|
||||
int err;
|
||||
mp_err err;
|
||||
|
||||
/* first compute 1/G mod P */
|
||||
if ((err = mp_init(&tmpG)) != MP_OKAY) {
|
||||
if (!MP_HAS(MP_INVMOD)) {
|
||||
return MP_VAL;
|
||||
}
|
||||
|
||||
if ((err = mp_init_multi(&tmpG, &tmpX, NULL)) != MP_OKAY) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* first compute 1/G mod P */
|
||||
if ((err = mp_invmod(G, P, &tmpG)) != MP_OKAY) {
|
||||
mp_clear(&tmpG);
|
||||
return err;
|
||||
goto LBL_ERR;
|
||||
}
|
||||
|
||||
/* now get |X| */
|
||||
if ((err = mp_init(&tmpX)) != MP_OKAY) {
|
||||
mp_clear(&tmpG);
|
||||
return err;
|
||||
}
|
||||
if ((err = mp_abs(X, &tmpX)) != MP_OKAY) {
|
||||
mp_clear_multi(&tmpG, &tmpX, NULL);
|
||||
return err;
|
||||
goto LBL_ERR;
|
||||
}
|
||||
|
||||
/* and now compute (1/G)**|X| instead of G**X [X < 0] */
|
||||
err = mp_exptmod(&tmpG, &tmpX, P, Y);
|
||||
LBL_ERR:
|
||||
mp_clear_multi(&tmpG, &tmpX, NULL);
|
||||
return err;
|
||||
#else
|
||||
/* no invmod */
|
||||
return MP_VAL;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* modified diminished radix reduction */
|
||||
#if defined(BN_MP_REDUCE_IS_2K_L_C) && defined(BN_MP_REDUCE_2K_L_C) && defined(BN_S_MP_EXPTMOD_C)
|
||||
if (mp_reduce_is_2k_l(P) == MP_YES) {
|
||||
if (MP_HAS(MP_REDUCE_IS_2K_L) && MP_HAS(MP_REDUCE_2K_L) && MP_HAS(S_MP_EXPTMOD) &&
|
||||
(mp_reduce_is_2k_l(P) == MP_YES)) {
|
||||
return s_mp_exptmod(G, X, P, Y, 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef BN_MP_DR_IS_MODULUS_C
|
||||
/* is it a DR modulus? */
|
||||
dr = mp_dr_is_modulus(P);
|
||||
#else
|
||||
/* default to no */
|
||||
dr = 0;
|
||||
#endif
|
||||
/* is it a DR modulus? default to no */
|
||||
dr = (MP_HAS(MP_DR_IS_MODULUS) && (mp_dr_is_modulus(P) == MP_YES)) ? 1 : 0;
|
||||
|
||||
#ifdef BN_MP_REDUCE_IS_2K_C
|
||||
/* if not, is it a unrestricted DR modulus? */
|
||||
if (dr == 0) {
|
||||
dr = mp_reduce_is_2k(P) << 1;
|
||||
if (MP_HAS(MP_REDUCE_IS_2K) && (dr == 0)) {
|
||||
dr = (mp_reduce_is_2k(P) == MP_YES) ? 2 : 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* if the modulus is odd or dr != 0 use the montgomery method */
|
||||
#ifdef BN_MP_EXPTMOD_FAST_C
|
||||
if ((mp_isodd(P) == MP_YES) || (dr != 0)) {
|
||||
return mp_exptmod_fast(G, X, P, Y, dr);
|
||||
} else {
|
||||
#endif
|
||||
#ifdef BN_S_MP_EXPTMOD_C
|
||||
if (MP_HAS(S_MP_EXPTMOD_FAST) && (MP_IS_ODD(P) || (dr != 0))) {
|
||||
return s_mp_exptmod_fast(G, X, P, Y, dr);
|
||||
} else if (MP_HAS(S_MP_EXPTMOD)) {
|
||||
/* otherwise use the generic Barrett reduction technique */
|
||||
return s_mp_exptmod(G, X, P, Y, 0);
|
||||
#else
|
||||
} else {
|
||||
/* no exptmod for evens */
|
||||
return MP_VAL;
|
||||
#endif
|
||||
#ifdef BN_MP_EXPTMOD_FAST_C
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
|
||||
@@ -1,24 +1,15 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_EXTEUCLID_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* Extended euclidean algorithm of (a, b) produces
|
||||
a*u1 + b*u2 = u3
|
||||
*/
|
||||
int mp_exteuclid(const mp_int *a, const mp_int *b, mp_int *U1, mp_int *U2, mp_int *U3)
|
||||
mp_err mp_exteuclid(const mp_int *a, const mp_int *b, mp_int *U1, mp_int *U2, mp_int *U3)
|
||||
{
|
||||
mp_int u1, u2, u3, v1, v2, v3, t1, t2, t3, q, tmp;
|
||||
int err;
|
||||
mp_err err;
|
||||
|
||||
if ((err = mp_init_multi(&u1, &u2, &u3, &v1, &v2, &v3, &t1, &t2, &t3, &q, &tmp, NULL)) != MP_OKAY) {
|
||||
return err;
|
||||
@@ -26,77 +17,41 @@ int mp_exteuclid(const mp_int *a, const mp_int *b, mp_int *U1, mp_int *U2, mp_in
|
||||
|
||||
/* initialize, (u1,u2,u3) = (1,0,a) */
|
||||
mp_set(&u1, 1uL);
|
||||
if ((err = mp_copy(a, &u3)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
if ((err = mp_copy(a, &u3)) != MP_OKAY) goto LBL_ERR;
|
||||
|
||||
/* initialize, (v1,v2,v3) = (0,1,b) */
|
||||
mp_set(&v2, 1uL);
|
||||
if ((err = mp_copy(b, &v3)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
if ((err = mp_copy(b, &v3)) != MP_OKAY) goto LBL_ERR;
|
||||
|
||||
/* loop while v3 != 0 */
|
||||
while (mp_iszero(&v3) == MP_NO) {
|
||||
while (!MP_IS_ZERO(&v3)) {
|
||||
/* q = u3/v3 */
|
||||
if ((err = mp_div(&u3, &v3, &q, NULL)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
if ((err = mp_div(&u3, &v3, &q, NULL)) != MP_OKAY) goto LBL_ERR;
|
||||
|
||||
/* (t1,t2,t3) = (u1,u2,u3) - (v1,v2,v3)q */
|
||||
if ((err = mp_mul(&v1, &q, &tmp)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
if ((err = mp_sub(&u1, &tmp, &t1)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
if ((err = mp_mul(&v2, &q, &tmp)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
if ((err = mp_sub(&u2, &tmp, &t2)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
if ((err = mp_mul(&v3, &q, &tmp)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
if ((err = mp_sub(&u3, &tmp, &t3)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
if ((err = mp_mul(&v1, &q, &tmp)) != MP_OKAY) goto LBL_ERR;
|
||||
if ((err = mp_sub(&u1, &tmp, &t1)) != MP_OKAY) goto LBL_ERR;
|
||||
if ((err = mp_mul(&v2, &q, &tmp)) != MP_OKAY) goto LBL_ERR;
|
||||
if ((err = mp_sub(&u2, &tmp, &t2)) != MP_OKAY) goto LBL_ERR;
|
||||
if ((err = mp_mul(&v3, &q, &tmp)) != MP_OKAY) goto LBL_ERR;
|
||||
if ((err = mp_sub(&u3, &tmp, &t3)) != MP_OKAY) goto LBL_ERR;
|
||||
|
||||
/* (u1,u2,u3) = (v1,v2,v3) */
|
||||
if ((err = mp_copy(&v1, &u1)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
if ((err = mp_copy(&v2, &u2)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
if ((err = mp_copy(&v3, &u3)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
if ((err = mp_copy(&v1, &u1)) != MP_OKAY) goto LBL_ERR;
|
||||
if ((err = mp_copy(&v2, &u2)) != MP_OKAY) goto LBL_ERR;
|
||||
if ((err = mp_copy(&v3, &u3)) != MP_OKAY) goto LBL_ERR;
|
||||
|
||||
/* (v1,v2,v3) = (t1,t2,t3) */
|
||||
if ((err = mp_copy(&t1, &v1)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
if ((err = mp_copy(&t2, &v2)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
if ((err = mp_copy(&t3, &v3)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
if ((err = mp_copy(&t1, &v1)) != MP_OKAY) goto LBL_ERR;
|
||||
if ((err = mp_copy(&t2, &v2)) != MP_OKAY) goto LBL_ERR;
|
||||
if ((err = mp_copy(&t3, &v3)) != MP_OKAY) goto LBL_ERR;
|
||||
}
|
||||
|
||||
/* make sure U3 >= 0 */
|
||||
if (u3.sign == MP_NEG) {
|
||||
if ((err = mp_neg(&u1, &u1)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
if ((err = mp_neg(&u2, &u2)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
if ((err = mp_neg(&u3, &u3)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
if ((err = mp_neg(&u1, &u1)) != MP_OKAY) goto LBL_ERR;
|
||||
if ((err = mp_neg(&u2, &u2)) != MP_OKAY) goto LBL_ERR;
|
||||
if ((err = mp_neg(&u3, &u3)) != MP_OKAY) goto LBL_ERR;
|
||||
}
|
||||
|
||||
/* copy result out */
|
||||
@@ -116,7 +71,3 @@ LBL_ERR:
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
|
||||
+20
-28
@@ -1,29 +1,17 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_FREAD_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
#ifndef LTM_NO_FILE
|
||||
#ifndef MP_NO_FILE
|
||||
/* read a bigint from a file stream in ASCII */
|
||||
int mp_fread(mp_int *a, int radix, FILE *stream)
|
||||
mp_err mp_fread(mp_int *a, int radix, FILE *stream)
|
||||
{
|
||||
int err, ch, neg, y;
|
||||
unsigned pos;
|
||||
|
||||
/* clear a */
|
||||
mp_zero(a);
|
||||
mp_err err;
|
||||
mp_sign neg;
|
||||
|
||||
/* if first digit is - then set negative */
|
||||
ch = fgetc(stream);
|
||||
int ch = fgetc(stream);
|
||||
if (ch == (int)'-') {
|
||||
neg = MP_NEG;
|
||||
ch = fgetc(stream);
|
||||
@@ -31,8 +19,17 @@ int mp_fread(mp_int *a, int radix, FILE *stream)
|
||||
neg = MP_ZPOS;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
pos = (unsigned)(ch - (int)'(');
|
||||
/* no digits, return error */
|
||||
if (ch == EOF) {
|
||||
return MP_ERR;
|
||||
}
|
||||
|
||||
/* clear a */
|
||||
mp_zero(a);
|
||||
|
||||
do {
|
||||
int y;
|
||||
unsigned pos = (unsigned)(ch - (int)'(');
|
||||
if (mp_s_rmap_reverse_sz < pos) {
|
||||
break;
|
||||
}
|
||||
@@ -50,10 +47,9 @@ int mp_fread(mp_int *a, int radix, FILE *stream)
|
||||
if ((err = mp_add_d(a, (mp_digit)y, a)) != MP_OKAY) {
|
||||
return err;
|
||||
}
|
||||
} while ((ch = fgetc(stream)) != EOF);
|
||||
|
||||
ch = fgetc(stream);
|
||||
}
|
||||
if (mp_cmp_d(a, 0uL) != MP_EQ) {
|
||||
if (a->used != 0) {
|
||||
a->sign = neg;
|
||||
}
|
||||
|
||||
@@ -62,7 +58,3 @@ int mp_fread(mp_int *a, int radix, FILE *stream)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_FROM_SBIN_C
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* read signed bin, big endian, first byte is 0==positive or 1==negative */
|
||||
mp_err mp_from_sbin(mp_int *a, const unsigned char *buf, size_t size)
|
||||
{
|
||||
mp_err err;
|
||||
|
||||
/* read magnitude */
|
||||
if ((err = mp_from_ubin(a, buf + 1, size - 1u)) != MP_OKAY) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* first byte is 0 for positive, non-zero for negative */
|
||||
if (buf[0] == (unsigned char)0) {
|
||||
a->sign = MP_ZPOS;
|
||||
} else {
|
||||
a->sign = MP_NEG;
|
||||
}
|
||||
|
||||
return MP_OKAY;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,39 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_FROM_UBIN_C
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* reads a unsigned char array, assumes the msb is stored first [big endian] */
|
||||
mp_err mp_from_ubin(mp_int *a, const unsigned char *buf, size_t size)
|
||||
{
|
||||
mp_err err;
|
||||
|
||||
/* make sure there are at least two digits */
|
||||
if (a->alloc < 2) {
|
||||
if ((err = mp_grow(a, 2)) != MP_OKAY) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
/* zero the int */
|
||||
mp_zero(a);
|
||||
|
||||
/* read the bytes in */
|
||||
while (size-- > 0u) {
|
||||
if ((err = mp_mul_2d(a, 8, a)) != MP_OKAY) {
|
||||
return err;
|
||||
}
|
||||
|
||||
#ifndef MP_8BIT
|
||||
a->dp[0] |= *buf++;
|
||||
a->used += 1;
|
||||
#else
|
||||
a->dp[0] = (*buf & MP_MASK);
|
||||
a->dp[1] |= ((*buf++ >> 7) & 1u);
|
||||
a->used += 2;
|
||||
#endif
|
||||
}
|
||||
mp_clamp(a);
|
||||
return MP_OKAY;
|
||||
}
|
||||
#endif
|
||||
+25
-31
@@ -1,51 +1,45 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_FWRITE_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
#ifndef LTM_NO_FILE
|
||||
int mp_fwrite(const mp_int *a, int radix, FILE *stream)
|
||||
#ifndef MP_NO_FILE
|
||||
mp_err mp_fwrite(const mp_int *a, int radix, FILE *stream)
|
||||
{
|
||||
char *buf;
|
||||
int err, len, x;
|
||||
mp_err err;
|
||||
int len;
|
||||
size_t written;
|
||||
|
||||
if ((err = mp_radix_size(a, radix, &len)) != MP_OKAY) {
|
||||
return err;
|
||||
/* TODO: this function is not in this PR */
|
||||
if (MP_HAS(MP_RADIX_SIZE_OVERESTIMATE)) {
|
||||
/* if ((err = mp_radix_size_overestimate(&t, base, &len)) != MP_OKAY) goto LBL_ERR; */
|
||||
} else {
|
||||
if ((err = mp_radix_size(a, radix, &len)) != MP_OKAY) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
buf = (char *) XMALLOC((size_t)len);
|
||||
buf = (char *) MP_MALLOC((size_t)len);
|
||||
if (buf == NULL) {
|
||||
return MP_MEM;
|
||||
}
|
||||
|
||||
if ((err = mp_toradix(a, buf, radix)) != MP_OKAY) {
|
||||
XFREE(buf, len);
|
||||
return err;
|
||||
if ((err = mp_to_radix(a, buf, (size_t)len, &written, radix)) != MP_OKAY) {
|
||||
goto LBL_ERR;
|
||||
}
|
||||
|
||||
for (x = 0; x < len; x++) {
|
||||
if (fputc((int)buf[x], stream) == EOF) {
|
||||
XFREE(buf, len);
|
||||
return MP_VAL;
|
||||
}
|
||||
if (fwrite(buf, written, 1uL, stream) != 1uL) {
|
||||
err = MP_ERR;
|
||||
goto LBL_ERR;
|
||||
}
|
||||
err = MP_OKAY;
|
||||
|
||||
XFREE(buf, len);
|
||||
return MP_OKAY;
|
||||
|
||||
LBL_ERR:
|
||||
MP_FREE_BUFFER(buf, (size_t)len);
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
|
||||
+21
-33
@@ -1,37 +1,29 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_GCD_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* Greatest Common Divisor using the binary method */
|
||||
int mp_gcd(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
mp_err mp_gcd(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
{
|
||||
mp_int u, v;
|
||||
int k, u_lsb, v_lsb, res;
|
||||
int k, u_lsb, v_lsb;
|
||||
mp_err err;
|
||||
|
||||
/* either zero than gcd is the largest */
|
||||
if (mp_iszero(a) == MP_YES) {
|
||||
if (MP_IS_ZERO(a)) {
|
||||
return mp_abs(b, c);
|
||||
}
|
||||
if (mp_iszero(b) == MP_YES) {
|
||||
if (MP_IS_ZERO(b)) {
|
||||
return mp_abs(a, c);
|
||||
}
|
||||
|
||||
/* get copies of a and b we can modify */
|
||||
if ((res = mp_init_copy(&u, a)) != MP_OKAY) {
|
||||
return res;
|
||||
if ((err = mp_init_copy(&u, a)) != MP_OKAY) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if ((res = mp_init_copy(&v, b)) != MP_OKAY) {
|
||||
if ((err = mp_init_copy(&v, b)) != MP_OKAY) {
|
||||
goto LBL_U;
|
||||
}
|
||||
|
||||
@@ -41,33 +33,33 @@ int mp_gcd(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
/* B1. Find the common power of two for u and v */
|
||||
u_lsb = mp_cnt_lsb(&u);
|
||||
v_lsb = mp_cnt_lsb(&v);
|
||||
k = MIN(u_lsb, v_lsb);
|
||||
k = MP_MIN(u_lsb, v_lsb);
|
||||
|
||||
if (k > 0) {
|
||||
/* divide the power of two out */
|
||||
if ((res = mp_div_2d(&u, k, &u, NULL)) != MP_OKAY) {
|
||||
if ((err = mp_div_2d(&u, k, &u, NULL)) != MP_OKAY) {
|
||||
goto LBL_V;
|
||||
}
|
||||
|
||||
if ((res = mp_div_2d(&v, k, &v, NULL)) != MP_OKAY) {
|
||||
if ((err = mp_div_2d(&v, k, &v, NULL)) != MP_OKAY) {
|
||||
goto LBL_V;
|
||||
}
|
||||
}
|
||||
|
||||
/* divide any remaining factors of two out */
|
||||
if (u_lsb != k) {
|
||||
if ((res = mp_div_2d(&u, u_lsb - k, &u, NULL)) != MP_OKAY) {
|
||||
if ((err = mp_div_2d(&u, u_lsb - k, &u, NULL)) != MP_OKAY) {
|
||||
goto LBL_V;
|
||||
}
|
||||
}
|
||||
|
||||
if (v_lsb != k) {
|
||||
if ((res = mp_div_2d(&v, v_lsb - k, &v, NULL)) != MP_OKAY) {
|
||||
if ((err = mp_div_2d(&v, v_lsb - k, &v, NULL)) != MP_OKAY) {
|
||||
goto LBL_V;
|
||||
}
|
||||
}
|
||||
|
||||
while (mp_iszero(&v) == MP_NO) {
|
||||
while (!MP_IS_ZERO(&v)) {
|
||||
/* make sure v is the largest */
|
||||
if (mp_cmp_mag(&u, &v) == MP_GT) {
|
||||
/* swap u and v to make sure v is >= u */
|
||||
@@ -75,30 +67,26 @@ int mp_gcd(const mp_int *a, const mp_int *b, mp_int *c)
|
||||
}
|
||||
|
||||
/* subtract smallest from largest */
|
||||
if ((res = s_mp_sub(&v, &u, &v)) != MP_OKAY) {
|
||||
if ((err = s_mp_sub(&v, &u, &v)) != MP_OKAY) {
|
||||
goto LBL_V;
|
||||
}
|
||||
|
||||
/* Divide out all factors of two */
|
||||
if ((res = mp_div_2d(&v, mp_cnt_lsb(&v), &v, NULL)) != MP_OKAY) {
|
||||
if ((err = mp_div_2d(&v, mp_cnt_lsb(&v), &v, NULL)) != MP_OKAY) {
|
||||
goto LBL_V;
|
||||
}
|
||||
}
|
||||
|
||||
/* multiply by 2**k which we divided out at the beginning */
|
||||
if ((res = mp_mul_2d(&u, k, c)) != MP_OKAY) {
|
||||
if ((err = mp_mul_2d(&u, k, c)) != MP_OKAY) {
|
||||
goto LBL_V;
|
||||
}
|
||||
c->sign = MP_ZPOS;
|
||||
res = MP_OKAY;
|
||||
err = MP_OKAY;
|
||||
LBL_V:
|
||||
mp_clear(&u);
|
||||
LBL_U:
|
||||
mp_clear(&v);
|
||||
return res;
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
|
||||
@@ -1,22 +1,13 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_GET_DOUBLE_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
double mp_get_double(const mp_int *a)
|
||||
{
|
||||
int i;
|
||||
double d = 0.0, fac = 1.0;
|
||||
for (i = 0; i < DIGIT_BIT; ++i) {
|
||||
for (i = 0; i < MP_DIGIT_BIT; ++i) {
|
||||
fac *= 2.0;
|
||||
}
|
||||
for (i = a->used; i --> 0;) {
|
||||
@@ -25,7 +16,3 @@ double mp_get_double(const mp_int *a)
|
||||
return (a->sign == MP_NEG) ? -d : d;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_GET_I32_C
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
MP_GET_SIGNED(mp_get_i32, mp_get_mag_u32, int32_t, uint32_t)
|
||||
#endif
|
||||
@@ -0,0 +1,7 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_GET_I64_C
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
MP_GET_SIGNED(mp_get_i64, mp_get_mag_u64, int64_t, uint64_t)
|
||||
#endif
|
||||
@@ -1,25 +0,0 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_GET_INT_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
|
||||
/* get the lower 32-bits of an mp_int */
|
||||
unsigned long mp_get_int(const mp_int *a)
|
||||
{
|
||||
/* force result to 32-bits always so it is consistent on non 32-bit platforms */
|
||||
return mp_get_long(a) & 0xFFFFFFFFUL;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
@@ -0,0 +1,7 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_GET_L_C
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
MP_GET_SIGNED(mp_get_l, mp_get_mag_ul, long, unsigned long)
|
||||
#endif
|
||||
@@ -0,0 +1,7 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_GET_LL_C
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
MP_GET_SIGNED(mp_get_ll, mp_get_mag_ull, long long, unsigned long long)
|
||||
#endif
|
||||
@@ -1,42 +0,0 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_GET_LONG_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
|
||||
/* get the lower unsigned long of an mp_int, platform dependent */
|
||||
unsigned long mp_get_long(const mp_int *a)
|
||||
{
|
||||
int i;
|
||||
unsigned long res;
|
||||
|
||||
if (IS_ZERO(a)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* get number of digits of the lsb we have to read */
|
||||
i = MIN(a->used, (((CHAR_BIT * (int)sizeof(unsigned long)) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1;
|
||||
|
||||
/* get most significant digit of result */
|
||||
res = (unsigned long)a->dp[i];
|
||||
|
||||
#if (ULONG_MAX != 0xFFFFFFFFUL) || (DIGIT_BIT < 32)
|
||||
while (--i >= 0) {
|
||||
res = (res << DIGIT_BIT) | (unsigned long)a->dp[i];
|
||||
}
|
||||
#endif
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
@@ -1,42 +0,0 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_GET_LONG_LONG_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
|
||||
/* get the lower unsigned long long of an mp_int, platform dependent */
|
||||
unsigned long long mp_get_long_long(const mp_int *a)
|
||||
{
|
||||
int i;
|
||||
unsigned long long res;
|
||||
|
||||
if (IS_ZERO(a)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* get number of digits of the lsb we have to read */
|
||||
i = MIN(a->used, (((CHAR_BIT * (int)sizeof(unsigned long long)) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1;
|
||||
|
||||
/* get most significant digit of result */
|
||||
res = (unsigned long long)a->dp[i];
|
||||
|
||||
#if DIGIT_BIT < 64
|
||||
while (--i >= 0) {
|
||||
res = (res << DIGIT_BIT) | (unsigned long long)a->dp[i];
|
||||
}
|
||||
#endif
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
@@ -0,0 +1,7 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_GET_MAG_U32_C
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
MP_GET_MAG(mp_get_mag_u32, uint32_t)
|
||||
#endif
|
||||
@@ -0,0 +1,7 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_GET_MAG_U64_C
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
MP_GET_MAG(mp_get_mag_u64, uint64_t)
|
||||
#endif
|
||||
@@ -0,0 +1,7 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_GET_MAG_UL_C
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
MP_GET_MAG(mp_get_mag_ul, unsigned long)
|
||||
#endif
|
||||
@@ -0,0 +1,7 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_GET_MAG_ULL_C
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
MP_GET_MAG(mp_get_mag_ull, unsigned long long)
|
||||
#endif
|
||||
+7
-25
@@ -1,37 +1,25 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_GROW_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* grow as required */
|
||||
int mp_grow(mp_int *a, int size)
|
||||
mp_err mp_grow(mp_int *a, int size)
|
||||
{
|
||||
int i;
|
||||
mp_digit *tmp;
|
||||
|
||||
/* if the alloc size is smaller alloc more ram */
|
||||
if (a->alloc < size) {
|
||||
/* ensure there are always at least MP_PREC digits extra on top */
|
||||
size += (MP_PREC * 2) - (size % MP_PREC);
|
||||
|
||||
/* reallocate the array a->dp
|
||||
*
|
||||
* We store the return in a temporary variable
|
||||
* in case the operation failed we don't want
|
||||
* to overwrite the dp member of a.
|
||||
*/
|
||||
tmp = (mp_digit *) XREALLOC(a->dp,
|
||||
(size_t)a->alloc * sizeof (mp_digit),
|
||||
(size_t)size * sizeof(mp_digit));
|
||||
tmp = (mp_digit *) MP_REALLOC(a->dp,
|
||||
(size_t)a->alloc * sizeof(mp_digit),
|
||||
(size_t)size * sizeof(mp_digit));
|
||||
if (tmp == NULL) {
|
||||
/* reallocation failed but "a" is still valid [can be freed] */
|
||||
return MP_MEM;
|
||||
@@ -43,14 +31,8 @@ int mp_grow(mp_int *a, int size)
|
||||
/* zero excess digits */
|
||||
i = a->alloc;
|
||||
a->alloc = size;
|
||||
for (; i < a->alloc; i++) {
|
||||
a->dp[i] = 0;
|
||||
}
|
||||
MP_ZERO_DIGITS(a->dp + i, a->alloc - i);
|
||||
}
|
||||
return MP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_IMPORT_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
|
||||
/* based on gmp's mpz_import.
|
||||
* see http://gmplib.org/manual/Integer-Import-and-Export.html
|
||||
*/
|
||||
int mp_import(mp_int *rop, size_t count, int order, size_t size,
|
||||
int endian, size_t nails, const void *op)
|
||||
{
|
||||
int result;
|
||||
size_t odd_nails, nail_bytes, i, j;
|
||||
unsigned char odd_nail_mask;
|
||||
|
||||
mp_zero(rop);
|
||||
|
||||
if (endian == 0) {
|
||||
union {
|
||||
unsigned int i;
|
||||
char c[4];
|
||||
} lint;
|
||||
lint.i = 0x01020304;
|
||||
|
||||
endian = (lint.c[0] == '\x04') ? -1 : 1;
|
||||
}
|
||||
|
||||
odd_nails = (nails % 8u);
|
||||
odd_nail_mask = 0xff;
|
||||
for (i = 0; i < odd_nails; ++i) {
|
||||
odd_nail_mask ^= (unsigned char)(1u << (7u - i));
|
||||
}
|
||||
nail_bytes = nails / 8u;
|
||||
|
||||
for (i = 0; i < count; ++i) {
|
||||
for (j = 0; j < (size - nail_bytes); ++j) {
|
||||
unsigned char byte = *((unsigned char *)op +
|
||||
(((order == 1) ? i : ((count - 1u) - i)) * size) +
|
||||
((endian == 1) ? (j + nail_bytes) : (((size - 1u) - j) - nail_bytes)));
|
||||
|
||||
if ((result = mp_mul_2d(rop, (j == 0u) ? (int)(8u - odd_nails) : 8, rop)) != MP_OKAY) {
|
||||
return result;
|
||||
}
|
||||
|
||||
rop->dp[0] |= (j == 0u) ? (mp_digit)(byte & odd_nail_mask) : (mp_digit)byte;
|
||||
rop->used += 1;
|
||||
}
|
||||
}
|
||||
|
||||
mp_clamp(rop);
|
||||
|
||||
return MP_OKAY;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
@@ -0,0 +1,30 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_INCR_C
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* Increment "a" by one like "a++". Changes input! */
|
||||
mp_err mp_incr(mp_int *a)
|
||||
{
|
||||
if (MP_IS_ZERO(a)) {
|
||||
mp_set(a,1uL);
|
||||
return MP_OKAY;
|
||||
} else if (a->sign == MP_NEG) {
|
||||
mp_err err;
|
||||
a->sign = MP_ZPOS;
|
||||
if ((err = mp_decr(a)) != MP_OKAY) {
|
||||
return err;
|
||||
}
|
||||
/* There is no -0 in LTM */
|
||||
if (!MP_IS_ZERO(a)) {
|
||||
a->sign = MP_NEG;
|
||||
}
|
||||
return MP_OKAY;
|
||||
} else if (a->dp[0] < MP_DIGIT_MAX) {
|
||||
a->dp[0]++;
|
||||
return MP_OKAY;
|
||||
} else {
|
||||
return mp_add_d(a, 1uL,a);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
+4
-24
@@ -1,33 +1,17 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_INIT_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* init a new mp_int */
|
||||
int mp_init(mp_int *a)
|
||||
mp_err mp_init(mp_int *a)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* allocate memory required and clear it */
|
||||
a->dp = (mp_digit *) XMALLOC(MP_PREC * sizeof(mp_digit));
|
||||
a->dp = (mp_digit *) MP_CALLOC((size_t)MP_PREC, sizeof(mp_digit));
|
||||
if (a->dp == NULL) {
|
||||
return MP_MEM;
|
||||
}
|
||||
|
||||
/* set the digits to zero */
|
||||
for (i = 0; i < MP_PREC; i++) {
|
||||
a->dp[i] = 0;
|
||||
}
|
||||
|
||||
/* set the used to zero, allocated digits to the default precision
|
||||
* and sign to positive */
|
||||
a->used = 0;
|
||||
@@ -37,7 +21,3 @@ int mp_init(mp_int *a)
|
||||
return MP_OKAY;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
|
||||
@@ -1,34 +1,21 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_INIT_COPY_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.
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense
|
||||
*/
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
/* creates "a" then copies b into it */
|
||||
int mp_init_copy(mp_int *a, const mp_int *b)
|
||||
mp_err mp_init_copy(mp_int *a, const mp_int *b)
|
||||
{
|
||||
int res;
|
||||
mp_err err;
|
||||
|
||||
if ((res = mp_init_size(a, b->used)) != MP_OKAY) {
|
||||
return res;
|
||||
if ((err = mp_init_size(a, b->used)) != MP_OKAY) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if ((res = mp_copy(b, a)) != MP_OKAY) {
|
||||
if ((err = mp_copy(b, a)) != MP_OKAY) {
|
||||
mp_clear(a);
|
||||
}
|
||||
|
||||
return res;
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ref: $Format:%D$ */
|
||||
/* git commit: $Format:%H$ */
|
||||
/* commit time: $Format:%ai$ */
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_INIT_I32_C
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
MP_INIT_INT(mp_init_i32, mp_set_i32, int32_t)
|
||||
#endif
|
||||
@@ -0,0 +1,7 @@
|
||||
#include "tommath_private.h"
|
||||
#ifdef BN_MP_INIT_I64_C
|
||||
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
|
||||
MP_INIT_INT(mp_init_i64, mp_set_i64, int64_t)
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user