forked from premiere/premiere-libtorrent
run undefined sanitier on travis/linux (#1134)
run undefined sanitizer on travis/linux. back-port ed25519 unit test from master
This commit is contained in:
parent
15bf443bfd
commit
5f7e2eb928
59
.travis.yml
59
.travis.yml
|
@ -1,14 +1,21 @@
|
|||
language: cpp
|
||||
|
||||
os:
|
||||
- linux
|
||||
- osx
|
||||
matrix:
|
||||
include:
|
||||
- env: variant=test_release lang=cpp11 sim=0 coverage=1 docs=1
|
||||
- env: variant=test_debug lang=ubsan sim=1 coverage=0
|
||||
- env: variant=test_debug lang=cpp98 sim=0 coverage=0
|
||||
- env: variant=test_barebones lang=cpp11 sim=0 coverage=0
|
||||
|
||||
env:
|
||||
- variant=test_release lang=cpp11 sim=0 coverage=1 docs=1
|
||||
- variant=test_debug lang=cpp11 sim=1 coverage=0
|
||||
- variant=test_debug lang=cpp98 sim=0 coverage=0
|
||||
- variant=test_barebones lang=cpp11 sim=0 coverage=0
|
||||
- env: variant=test_debug lang=cpp11 sim=0 coverage=0 target=osx-tests
|
||||
os: osx
|
||||
osx_image: xcode6.4
|
||||
- env: variant=test_release lang=cpp11 sim=0 coverage=0 docs=1 target=osx-tests
|
||||
os: osx
|
||||
osx_image: xcode6.4
|
||||
- env: variant=test_debug lang=cpp98 sim=0 coverage=0 target=osx-tests
|
||||
os: osx
|
||||
osx_image: xcode6.4
|
||||
|
||||
git:
|
||||
submodules: false
|
||||
|
@ -36,7 +43,7 @@ addons:
|
|||
- libboost1.55-all-dev
|
||||
- libboost1.55-tools-dev
|
||||
- python2.7-dev
|
||||
- g++-4.8
|
||||
- g++-5
|
||||
|
||||
before_install:
|
||||
- git submodule update --init --recursive
|
||||
|
@ -52,8 +59,7 @@ before_install:
|
|||
fi'
|
||||
|
||||
# disable simulations on OSX for now. It hangs on travis
|
||||
- if [ $TRAVIS_OS_NAME == "osx" ]; then export toolset="darwin-${lang}"; export sim="0"; fi
|
||||
- if [ $TRAVIS_OS_NAME == "osx" ]; then export target="osx-tests"; fi
|
||||
- if [ $TRAVIS_OS_NAME == "osx" ]; then export toolset="darwin-${lang}"; fi
|
||||
- if [ $TRAVIS_OS_NAME == "linux" ]; then export toolset="gcc-${lang}"; fi
|
||||
- if [[ $TRAVIS_OS_NAME == "linux" && $coverage == "1" ]]; then
|
||||
export coverage_toolset=gcc-coverage;
|
||||
|
@ -61,13 +67,19 @@ before_install:
|
|||
else
|
||||
export coverage_toolset=$toolset;
|
||||
fi
|
||||
- 'echo "using toolset: " ${toolset}'
|
||||
- 'if [[ $lang == "ubsan" ]]; then export test_args=testing.arg="--no-stderr-redirect"; fi'
|
||||
- 'echo "toolset: " ${toolset}'
|
||||
- 'echo "target: " ${target}'
|
||||
- 'echo "coverage_toolset: " ${coverage_toolset}'
|
||||
- 'echo "test_args: " ${test_args}'
|
||||
- 'echo "variant: " ${variant}'
|
||||
|
||||
install:
|
||||
- g++-4.8 --version
|
||||
- 'echo "using gcc : cpp11 : ccache g++-4.8 : <cflags>-std=c11 <cxxflags>-std=c++11 ;" > ~/user-config.jam'
|
||||
- 'echo "using gcc : coverage : ccache g++-4.8 : <cflags>-std=c11 <cxxflags>-std=c++11 <compileflags>--coverage <linkflags>--coverage ;" >> ~/user-config.jam'
|
||||
- 'echo "using gcc : cpp98 : ccache g++-4.8 : <cflags>-std=c99 <cxxflags>-std=c++98 ;" >> ~/user-config.jam'
|
||||
- 'if [[ $toolset == "gcc" ]]; then g++-5 --version; fi'
|
||||
- 'echo "using gcc : cpp11 : ccache g++-5 : <cflags>-std=c11 <cxxflags>-std=c++11 ;" > ~/user-config.jam'
|
||||
- 'echo "using gcc : ubsan : ccache g++-5 : <cflags>-std=c11 <cxxflags>-std=c++11 <compileflags>-fsanitize=undefined <compileflags>-fno-sanitize-recover=undefined <linkflags>-fsanitize=undefined <linkflags>-fno-sanitize-recover=undefined ;" >> ~/user-config.jam'
|
||||
- 'echo "using gcc : coverage : ccache g++-5 : <cflags>-std=c11 <cxxflags>-std=c++11 <compileflags>--coverage <linkflags>--coverage ;" >> ~/user-config.jam'
|
||||
- 'echo "using gcc : cpp98 : ccache g++-5 : <cflags>-std=c99 <cxxflags>-std=c++98 ;" >> ~/user-config.jam'
|
||||
|
||||
# osx builds need to disable the deprecated warning because of the openssl
|
||||
# shipping with the system having marked all functions as deprecated. Since
|
||||
|
@ -85,7 +97,7 @@ script:
|
|||
- cd ..
|
||||
|
||||
- cd test
|
||||
- bjam --hash -j3 warnings-as-errors=on invariant-checks=full variant=$variant -l900 $coverage_toolset $target
|
||||
- bjam --hash -j3 warnings-as-errors=on invariant-checks=full variant=$variant -l900 $coverage_toolset $target $test_args
|
||||
# if we're building with code coverage, report it as soon as possible
|
||||
- if [[ $TRAVIS_OS_NAME == "linux" && $coverage == "1" ]]; then
|
||||
codecov --root .. --gcov-exec gcov-4.8;
|
||||
|
@ -103,15 +115,18 @@ script:
|
|||
# as the main library, so we can't stage them to the same directory
|
||||
- bjam --hash -j3 warnings-as-errors=on link=shared debug-iterators=on picker-debugging=on invariant-checks=full variant=$variant $coverage_toolset install location=./lib
|
||||
|
||||
- cd bindings/python
|
||||
# here we specify the temporary lib dir as a path to look for the main library
|
||||
- bjam --hash -j3 warnings-as-errors=on debug-iterators=on picker-debugging=on invariant-checks=full variant=$variant $coverage_toolset stage_module libtorrent-link=shared install-type=LIB dll-path=../../lib
|
||||
- LD_LIBRARY_PATH=../../lib DYLD_LIBRARY_PATH=../../lib python test.py
|
||||
- cd ../..
|
||||
# a binary built with ubsan does not interact well with python
|
||||
- 'if [[ $lang != "ubsan" ]]; then
|
||||
cd bindings/python;
|
||||
bjam --hash -j3 warnings-as-errors=on debug-iterators=on picker-debugging=on invariant-checks=full variant=$variant $coverage_toolset stage_module libtorrent-link=shared install-type=LIB dll-path=../../lib;
|
||||
LD_LIBRARY_PATH=../../lib DYLD_LIBRARY_PATH=../../lib python test.py;
|
||||
cd ../..;
|
||||
fi'
|
||||
|
||||
- cd simulation
|
||||
- if [ $sim = "1" ]; then
|
||||
bjam --hash -j2 crypto=built-in warnings-as-errors=on $coverage_toolset;
|
||||
bjam --hash -j2 crypto=built-in warnings-as-errors=on $coverage_toolset $test_args;
|
||||
fi
|
||||
- cd ..
|
||||
- ccache --show-stats
|
||||
|
|
2
Jamfile
2
Jamfile
|
@ -504,7 +504,7 @@ feature export-extra : off on : composite propagated ;
|
|||
variant test_release : release
|
||||
: <asserts>production <debug-symbols>on
|
||||
<invariant-checks>full <boost-link>shared <optimization>off
|
||||
<export-extra>on <debug-iterators>on <threading>multi
|
||||
<export-extra>on <debug-iterators>on <threading>multi <inlining>on
|
||||
;
|
||||
variant test_debug : debug
|
||||
: <crypto>openssl <logging>on <disk-stats>on
|
||||
|
|
|
@ -34,6 +34,9 @@ static u64 load_4(const unsigned char *in) {
|
|||
return result;
|
||||
}
|
||||
|
||||
static inline i64 shift_left(i64 v, int s) {
|
||||
return i64(u64(v) << s);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
@ -326,34 +329,34 @@ void fe_frombytes(fe h, const unsigned char *s) {
|
|||
|
||||
carry9 = (h9 + (i64) (1 << 24)) >> 25;
|
||||
h0 += carry9 * 19;
|
||||
h9 -= carry9 << 25;
|
||||
h9 -= shift_left(carry9, 25);
|
||||
carry1 = (h1 + (i64) (1 << 24)) >> 25;
|
||||
h2 += carry1;
|
||||
h1 -= carry1 << 25;
|
||||
h1 -= shift_left(carry1, 25);
|
||||
carry3 = (h3 + (i64) (1 << 24)) >> 25;
|
||||
h4 += carry3;
|
||||
h3 -= carry3 << 25;
|
||||
h3 -= shift_left(carry3, 25);
|
||||
carry5 = (h5 + (i64) (1 << 24)) >> 25;
|
||||
h6 += carry5;
|
||||
h5 -= carry5 << 25;
|
||||
h5 -= shift_left(carry5, 25);
|
||||
carry7 = (h7 + (i64) (1 << 24)) >> 25;
|
||||
h8 += carry7;
|
||||
h7 -= carry7 << 25;
|
||||
h7 -= shift_left(carry7, 25);
|
||||
carry0 = (h0 + (i64) (1 << 25)) >> 26;
|
||||
h1 += carry0;
|
||||
h0 -= carry0 << 26;
|
||||
h0 -= shift_left(carry0, 26);
|
||||
carry2 = (h2 + (i64) (1 << 25)) >> 26;
|
||||
h3 += carry2;
|
||||
h2 -= carry2 << 26;
|
||||
h2 -= shift_left(carry2, 26);
|
||||
carry4 = (h4 + (i64) (1 << 25)) >> 26;
|
||||
h5 += carry4;
|
||||
h4 -= carry4 << 26;
|
||||
h4 -= shift_left(carry4, 26);
|
||||
carry6 = (h6 + (i64) (1 << 25)) >> 26;
|
||||
h7 += carry6;
|
||||
h6 -= carry6 << 26;
|
||||
h6 -= shift_left(carry6, 26);
|
||||
carry8 = (h8 + (i64) (1 << 25)) >> 26;
|
||||
h9 += carry8;
|
||||
h8 -= carry8 << 26;
|
||||
h8 -= shift_left(carry8, 26);
|
||||
|
||||
h[0] = (i32) h0;
|
||||
h[1] = (i32) h1;
|
||||
|
@ -528,7 +531,6 @@ int fe_isnonzero(const fe f) {
|
|||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
h = f * g
|
||||
Can overlap h with f or g.
|
||||
|
@ -719,46 +721,46 @@ void fe_mul(fe h, const fe f, const fe g) {
|
|||
|
||||
carry0 = (h0 + (i64) (1 << 25)) >> 26;
|
||||
h1 += carry0;
|
||||
h0 -= carry0 << 26;
|
||||
h0 -= shift_left(carry0, 26);
|
||||
carry4 = (h4 + (i64) (1 << 25)) >> 26;
|
||||
h5 += carry4;
|
||||
h4 -= carry4 << 26;
|
||||
h4 -= shift_left(carry4, 26);
|
||||
|
||||
carry1 = (h1 + (i64) (1 << 24)) >> 25;
|
||||
h2 += carry1;
|
||||
h1 -= carry1 << 25;
|
||||
h1 -= shift_left(carry1, 25);
|
||||
carry5 = (h5 + (i64) (1 << 24)) >> 25;
|
||||
h6 += carry5;
|
||||
h5 -= carry5 << 25;
|
||||
h5 -= shift_left(carry5, 25);
|
||||
|
||||
carry2 = (h2 + (i64) (1 << 25)) >> 26;
|
||||
h3 += carry2;
|
||||
h2 -= carry2 << 26;
|
||||
h2 -= shift_left(carry2, 26);
|
||||
carry6 = (h6 + (i64) (1 << 25)) >> 26;
|
||||
h7 += carry6;
|
||||
h6 -= carry6 << 26;
|
||||
h6 -= shift_left(carry6, 26);
|
||||
|
||||
carry3 = (h3 + (i64) (1 << 24)) >> 25;
|
||||
h4 += carry3;
|
||||
h3 -= carry3 << 25;
|
||||
h3 -= shift_left(carry3, 25);
|
||||
carry7 = (h7 + (i64) (1 << 24)) >> 25;
|
||||
h8 += carry7;
|
||||
h7 -= carry7 << 25;
|
||||
h7 -= shift_left(carry7, 25);
|
||||
|
||||
carry4 = (h4 + (i64) (1 << 25)) >> 26;
|
||||
h5 += carry4;
|
||||
h4 -= carry4 << 26;
|
||||
h4 -= shift_left(carry4, 26);
|
||||
carry8 = (h8 + (i64) (1 << 25)) >> 26;
|
||||
h9 += carry8;
|
||||
h8 -= carry8 << 26;
|
||||
h8 -= shift_left(carry8, 26);
|
||||
|
||||
carry9 = (h9 + (i64) (1 << 24)) >> 25;
|
||||
h0 += carry9 * 19;
|
||||
h9 -= carry9 << 25;
|
||||
h9 -= shift_left(carry9, 25);
|
||||
|
||||
carry0 = (h0 + (i64) (1 << 25)) >> 26;
|
||||
h1 += carry0;
|
||||
h0 -= carry0 << 26;
|
||||
h0 -= shift_left(carry0, 26);
|
||||
|
||||
h[0] = (i32) h0;
|
||||
h[1] = (i32) h1;
|
||||
|
@ -816,17 +818,17 @@ void fe_mul121666(fe h, fe f) {
|
|||
i64 carry8;
|
||||
i64 carry9;
|
||||
|
||||
carry9 = (h9 + (i64) (1<<24)) >> 25; h0 += carry9 * 19; h9 -= carry9 << 25;
|
||||
carry1 = (h1 + (i64) (1<<24)) >> 25; h2 += carry1; h1 -= carry1 << 25;
|
||||
carry3 = (h3 + (i64) (1<<24)) >> 25; h4 += carry3; h3 -= carry3 << 25;
|
||||
carry5 = (h5 + (i64) (1<<24)) >> 25; h6 += carry5; h5 -= carry5 << 25;
|
||||
carry7 = (h7 + (i64) (1<<24)) >> 25; h8 += carry7; h7 -= carry7 << 25;
|
||||
carry9 = (h9 + (i64) (1<<24)) >> 25; h0 += carry9 * 19; h9 -= shift_left(carry9, 25);
|
||||
carry1 = (h1 + (i64) (1<<24)) >> 25; h2 += carry1; h1 -= shift_left(carry1, 25);
|
||||
carry3 = (h3 + (i64) (1<<24)) >> 25; h4 += carry3; h3 -= shift_left(carry3, 25);
|
||||
carry5 = (h5 + (i64) (1<<24)) >> 25; h6 += carry5; h5 -= shift_left(carry5, 25);
|
||||
carry7 = (h7 + (i64) (1<<24)) >> 25; h8 += carry7; h7 -= shift_left(carry7, 25);
|
||||
|
||||
carry0 = (h0 + (i64) (1<<25)) >> 26; h1 += carry0; h0 -= carry0 << 26;
|
||||
carry2 = (h2 + (i64) (1<<25)) >> 26; h3 += carry2; h2 -= carry2 << 26;
|
||||
carry4 = (h4 + (i64) (1<<25)) >> 26; h5 += carry4; h4 -= carry4 << 26;
|
||||
carry6 = (h6 + (i64) (1<<25)) >> 26; h7 += carry6; h6 -= carry6 << 26;
|
||||
carry8 = (h8 + (i64) (1<<25)) >> 26; h9 += carry8; h8 -= carry8 << 26;
|
||||
carry0 = (h0 + (i64) (1<<25)) >> 26; h1 += carry0; h0 -= shift_left(carry0, 26);
|
||||
carry2 = (h2 + (i64) (1<<25)) >> 26; h3 += carry2; h2 -= shift_left(carry2, 26);
|
||||
carry4 = (h4 + (i64) (1<<25)) >> 26; h5 += carry4; h4 -= shift_left(carry4, 26);
|
||||
carry6 = (h6 + (i64) (1<<25)) >> 26; h7 += carry6; h6 -= shift_left(carry6, 26);
|
||||
carry8 = (h8 + (i64) (1<<25)) >> 26; h9 += carry8; h8 -= shift_left(carry8, 26);
|
||||
|
||||
h[0] = h0;
|
||||
h[1] = h1;
|
||||
|
@ -1088,40 +1090,40 @@ void fe_sq(fe h, const fe f) {
|
|||
i64 carry9;
|
||||
carry0 = (h0 + (i64) (1 << 25)) >> 26;
|
||||
h1 += carry0;
|
||||
h0 -= carry0 << 26;
|
||||
h0 -= shift_left(carry0, 26);
|
||||
carry4 = (h4 + (i64) (1 << 25)) >> 26;
|
||||
h5 += carry4;
|
||||
h4 -= carry4 << 26;
|
||||
h4 -= shift_left(carry4, 26);
|
||||
carry1 = (h1 + (i64) (1 << 24)) >> 25;
|
||||
h2 += carry1;
|
||||
h1 -= carry1 << 25;
|
||||
h1 -= shift_left(carry1, 25);
|
||||
carry5 = (h5 + (i64) (1 << 24)) >> 25;
|
||||
h6 += carry5;
|
||||
h5 -= carry5 << 25;
|
||||
h5 -= shift_left(carry5, 25);
|
||||
carry2 = (h2 + (i64) (1 << 25)) >> 26;
|
||||
h3 += carry2;
|
||||
h2 -= carry2 << 26;
|
||||
h2 -= shift_left(carry2, 26);
|
||||
carry6 = (h6 + (i64) (1 << 25)) >> 26;
|
||||
h7 += carry6;
|
||||
h6 -= carry6 << 26;
|
||||
h6 -= shift_left(carry6, 26);
|
||||
carry3 = (h3 + (i64) (1 << 24)) >> 25;
|
||||
h4 += carry3;
|
||||
h3 -= carry3 << 25;
|
||||
h3 -= shift_left(carry3, 25);
|
||||
carry7 = (h7 + (i64) (1 << 24)) >> 25;
|
||||
h8 += carry7;
|
||||
h7 -= carry7 << 25;
|
||||
h7 -= shift_left(carry7, 25);
|
||||
carry4 = (h4 + (i64) (1 << 25)) >> 26;
|
||||
h5 += carry4;
|
||||
h4 -= carry4 << 26;
|
||||
h4 -= shift_left(carry4, 26);
|
||||
carry8 = (h8 + (i64) (1 << 25)) >> 26;
|
||||
h9 += carry8;
|
||||
h8 -= carry8 << 26;
|
||||
h8 -= shift_left(carry8, 26);
|
||||
carry9 = (h9 + (i64) (1 << 24)) >> 25;
|
||||
h0 += carry9 * 19;
|
||||
h9 -= carry9 << 25;
|
||||
h9 -= shift_left(carry9, 25);
|
||||
carry0 = (h0 + (i64) (1 << 25)) >> 26;
|
||||
h1 += carry0;
|
||||
h0 -= carry0 << 26;
|
||||
h0 -= shift_left(carry0, 26);
|
||||
h[0] = (i32) h0;
|
||||
h[1] = (i32) h1;
|
||||
h[2] = (i32) h2;
|
||||
|
@ -1261,40 +1263,40 @@ void fe_sq2(fe h, const fe f) {
|
|||
h9 += h9;
|
||||
carry0 = (h0 + (i64) (1 << 25)) >> 26;
|
||||
h1 += carry0;
|
||||
h0 -= carry0 << 26;
|
||||
h0 -= shift_left(carry0, 26);
|
||||
carry4 = (h4 + (i64) (1 << 25)) >> 26;
|
||||
h5 += carry4;
|
||||
h4 -= carry4 << 26;
|
||||
h4 -= shift_left(carry4, 26);
|
||||
carry1 = (h1 + (i64) (1 << 24)) >> 25;
|
||||
h2 += carry1;
|
||||
h1 -= carry1 << 25;
|
||||
h1 -= shift_left(carry1, 25);
|
||||
carry5 = (h5 + (i64) (1 << 24)) >> 25;
|
||||
h6 += carry5;
|
||||
h5 -= carry5 << 25;
|
||||
h5 -= shift_left(carry5, 25);
|
||||
carry2 = (h2 + (i64) (1 << 25)) >> 26;
|
||||
h3 += carry2;
|
||||
h2 -= carry2 << 26;
|
||||
h2 -= shift_left(carry2, 26);
|
||||
carry6 = (h6 + (i64) (1 << 25)) >> 26;
|
||||
h7 += carry6;
|
||||
h6 -= carry6 << 26;
|
||||
h6 -= shift_left(carry6, 26);
|
||||
carry3 = (h3 + (i64) (1 << 24)) >> 25;
|
||||
h4 += carry3;
|
||||
h3 -= carry3 << 25;
|
||||
h3 -= shift_left(carry3, 25);
|
||||
carry7 = (h7 + (i64) (1 << 24)) >> 25;
|
||||
h8 += carry7;
|
||||
h7 -= carry7 << 25;
|
||||
h7 -= shift_left(carry7, 25);
|
||||
carry4 = (h4 + (i64) (1 << 25)) >> 26;
|
||||
h5 += carry4;
|
||||
h4 -= carry4 << 26;
|
||||
h4 -= shift_left(carry4, 26);
|
||||
carry8 = (h8 + (i64) (1 << 25)) >> 26;
|
||||
h9 += carry8;
|
||||
h8 -= carry8 << 26;
|
||||
h8 -= shift_left(carry8, 26);
|
||||
carry9 = (h9 + (i64) (1 << 24)) >> 25;
|
||||
h0 += carry9 * 19;
|
||||
h9 -= carry9 << 25;
|
||||
h9 -= shift_left(carry9, 25);
|
||||
carry0 = (h0 + (i64) (1 << 25)) >> 26;
|
||||
h1 += carry0;
|
||||
h0 -= carry0 << 26;
|
||||
h0 -= shift_left(carry0, 26);
|
||||
h[0] = (i32) h0;
|
||||
h[1] = (i32) h1;
|
||||
h[2] = (i32) h2;
|
||||
|
@ -1429,33 +1431,33 @@ void fe_tobytes(unsigned char *s, const fe h) {
|
|||
/* Goal: Output h-2^255 q, which is between 0 and 2^255-20. */
|
||||
carry0 = h0 >> 26;
|
||||
h1 += carry0;
|
||||
h0 -= carry0 << 26;
|
||||
h0 -= shift_left(carry0, 26);
|
||||
carry1 = h1 >> 25;
|
||||
h2 += carry1;
|
||||
h1 -= carry1 << 25;
|
||||
h1 -= shift_left(carry1, 25);
|
||||
carry2 = h2 >> 26;
|
||||
h3 += carry2;
|
||||
h2 -= carry2 << 26;
|
||||
h2 -= shift_left(carry2, 26);
|
||||
carry3 = h3 >> 25;
|
||||
h4 += carry3;
|
||||
h3 -= carry3 << 25;
|
||||
h3 -= shift_left(carry3, 25);
|
||||
carry4 = h4 >> 26;
|
||||
h5 += carry4;
|
||||
h4 -= carry4 << 26;
|
||||
h4 -= shift_left(carry4, 26);
|
||||
carry5 = h5 >> 25;
|
||||
h6 += carry5;
|
||||
h5 -= carry5 << 25;
|
||||
h5 -= shift_left(carry5, 25);
|
||||
carry6 = h6 >> 26;
|
||||
h7 += carry6;
|
||||
h6 -= carry6 << 26;
|
||||
h6 -= shift_left(carry6, 26);
|
||||
carry7 = h7 >> 25;
|
||||
h8 += carry7;
|
||||
h7 -= carry7 << 25;
|
||||
h7 -= shift_left(carry7, 25);
|
||||
carry8 = h8 >> 26;
|
||||
h9 += carry8;
|
||||
h8 -= carry8 << 26;
|
||||
h8 -= shift_left(carry8, 26);
|
||||
carry9 = h9 >> 25;
|
||||
h9 -= carry9 << 25;
|
||||
h9 -= shift_left(carry9, 25);
|
||||
|
||||
/* h10 = carry9 */
|
||||
/*
|
||||
|
|
|
@ -357,9 +357,11 @@ static void cmov(ge_precomp *t, ge_precomp *u, unsigned char b) {
|
|||
|
||||
|
||||
static void select(ge_precomp *t, int pos, signed char b) {
|
||||
typedef signed char schar;
|
||||
typedef unsigned char uchar;
|
||||
ge_precomp minust;
|
||||
unsigned char bnegative = negative(b);
|
||||
unsigned char babs = b - (((-bnegative) & b) << 1);
|
||||
unsigned char const bnegative = negative(b);
|
||||
unsigned char const babs = b - schar(uchar((-bnegative) & b) << 1);
|
||||
fe_1(t->yplusx);
|
||||
fe_1(t->yminusx);
|
||||
fe_0(t->xy2d);
|
||||
|
|
|
@ -25,6 +25,10 @@ static u64 load_4(const unsigned char *in) {
|
|||
return result;
|
||||
}
|
||||
|
||||
static inline i64 shift_left(i64 v, int s) {
|
||||
return i64(u64(v) << s);
|
||||
}
|
||||
|
||||
/*
|
||||
Input:
|
||||
s[0]+256*s[1]+...+256^63*s[63] = s
|
||||
|
@ -122,37 +126,37 @@ void sc_reduce(unsigned char *s) {
|
|||
s18 = 0;
|
||||
carry6 = (s6 + (1 << 20)) >> 21;
|
||||
s7 += carry6;
|
||||
s6 -= carry6 << 21;
|
||||
s6 -= shift_left(carry6, 21);
|
||||
carry8 = (s8 + (1 << 20)) >> 21;
|
||||
s9 += carry8;
|
||||
s8 -= carry8 << 21;
|
||||
s8 -= shift_left(carry8, 21);
|
||||
carry10 = (s10 + (1 << 20)) >> 21;
|
||||
s11 += carry10;
|
||||
s10 -= carry10 << 21;
|
||||
s10 -= shift_left(carry10, 21);
|
||||
carry12 = (s12 + (1 << 20)) >> 21;
|
||||
s13 += carry12;
|
||||
s12 -= carry12 << 21;
|
||||
s12 -= shift_left(carry12, 21);
|
||||
carry14 = (s14 + (1 << 20)) >> 21;
|
||||
s15 += carry14;
|
||||
s14 -= carry14 << 21;
|
||||
s14 -= shift_left(carry14, 21);
|
||||
carry16 = (s16 + (1 << 20)) >> 21;
|
||||
s17 += carry16;
|
||||
s16 -= carry16 << 21;
|
||||
s16 -= shift_left(carry16, 21);
|
||||
carry7 = (s7 + (1 << 20)) >> 21;
|
||||
s8 += carry7;
|
||||
s7 -= carry7 << 21;
|
||||
s7 -= shift_left(carry7, 21);
|
||||
carry9 = (s9 + (1 << 20)) >> 21;
|
||||
s10 += carry9;
|
||||
s9 -= carry9 << 21;
|
||||
s9 -= shift_left(carry9, 21);
|
||||
carry11 = (s11 + (1 << 20)) >> 21;
|
||||
s12 += carry11;
|
||||
s11 -= carry11 << 21;
|
||||
s11 -= shift_left(carry11, 21);
|
||||
carry13 = (s13 + (1 << 20)) >> 21;
|
||||
s14 += carry13;
|
||||
s13 -= carry13 << 21;
|
||||
s13 -= shift_left(carry13, 21);
|
||||
carry15 = (s15 + (1 << 20)) >> 21;
|
||||
s16 += carry15;
|
||||
s15 -= carry15 << 21;
|
||||
s15 -= shift_left(carry15, 21);
|
||||
s5 += s17 * 666643;
|
||||
s6 += s17 * 470296;
|
||||
s7 += s17 * 654183;
|
||||
|
@ -197,40 +201,40 @@ void sc_reduce(unsigned char *s) {
|
|||
s12 = 0;
|
||||
carry0 = (s0 + (1 << 20)) >> 21;
|
||||
s1 += carry0;
|
||||
s0 -= carry0 << 21;
|
||||
s0 -= shift_left(carry0, 21);
|
||||
carry2 = (s2 + (1 << 20)) >> 21;
|
||||
s3 += carry2;
|
||||
s2 -= carry2 << 21;
|
||||
s2 -= shift_left(carry2, 21);
|
||||
carry4 = (s4 + (1 << 20)) >> 21;
|
||||
s5 += carry4;
|
||||
s4 -= carry4 << 21;
|
||||
s4 -= shift_left(carry4, 21);
|
||||
carry6 = (s6 + (1 << 20)) >> 21;
|
||||
s7 += carry6;
|
||||
s6 -= carry6 << 21;
|
||||
s6 -= shift_left(carry6, 21);
|
||||
carry8 = (s8 + (1 << 20)) >> 21;
|
||||
s9 += carry8;
|
||||
s8 -= carry8 << 21;
|
||||
s8 -= shift_left(carry8, 21);
|
||||
carry10 = (s10 + (1 << 20)) >> 21;
|
||||
s11 += carry10;
|
||||
s10 -= carry10 << 21;
|
||||
s10 -= shift_left(carry10, 21);
|
||||
carry1 = (s1 + (1 << 20)) >> 21;
|
||||
s2 += carry1;
|
||||
s1 -= carry1 << 21;
|
||||
s1 -= shift_left(carry1, 21);
|
||||
carry3 = (s3 + (1 << 20)) >> 21;
|
||||
s4 += carry3;
|
||||
s3 -= carry3 << 21;
|
||||
s3 -= shift_left(carry3, 21);
|
||||
carry5 = (s5 + (1 << 20)) >> 21;
|
||||
s6 += carry5;
|
||||
s5 -= carry5 << 21;
|
||||
s5 -= shift_left(carry5, 21);
|
||||
carry7 = (s7 + (1 << 20)) >> 21;
|
||||
s8 += carry7;
|
||||
s7 -= carry7 << 21;
|
||||
s7 -= shift_left(carry7, 21);
|
||||
carry9 = (s9 + (1 << 20)) >> 21;
|
||||
s10 += carry9;
|
||||
s9 -= carry9 << 21;
|
||||
s9 -= shift_left(carry9, 21);
|
||||
carry11 = (s11 + (1 << 20)) >> 21;
|
||||
s12 += carry11;
|
||||
s11 -= carry11 << 21;
|
||||
s11 -= shift_left(carry11, 21);
|
||||
s0 += s12 * 666643;
|
||||
s1 += s12 * 470296;
|
||||
s2 += s12 * 654183;
|
||||
|
@ -240,40 +244,40 @@ void sc_reduce(unsigned char *s) {
|
|||
s12 = 0;
|
||||
carry0 = s0 >> 21;
|
||||
s1 += carry0;
|
||||
s0 -= carry0 << 21;
|
||||
s0 -= shift_left(carry0, 21);
|
||||
carry1 = s1 >> 21;
|
||||
s2 += carry1;
|
||||
s1 -= carry1 << 21;
|
||||
s1 -= shift_left(carry1, 21);
|
||||
carry2 = s2 >> 21;
|
||||
s3 += carry2;
|
||||
s2 -= carry2 << 21;
|
||||
s2 -= shift_left(carry2, 21);
|
||||
carry3 = s3 >> 21;
|
||||
s4 += carry3;
|
||||
s3 -= carry3 << 21;
|
||||
s3 -= shift_left(carry3, 21);
|
||||
carry4 = s4 >> 21;
|
||||
s5 += carry4;
|
||||
s4 -= carry4 << 21;
|
||||
s4 -= shift_left(carry4, 21);
|
||||
carry5 = s5 >> 21;
|
||||
s6 += carry5;
|
||||
s5 -= carry5 << 21;
|
||||
s5 -= shift_left(carry5, 21);
|
||||
carry6 = s6 >> 21;
|
||||
s7 += carry6;
|
||||
s6 -= carry6 << 21;
|
||||
s6 -= shift_left(carry6, 21);
|
||||
carry7 = s7 >> 21;
|
||||
s8 += carry7;
|
||||
s7 -= carry7 << 21;
|
||||
s7 -= shift_left(carry7, 21);
|
||||
carry8 = s8 >> 21;
|
||||
s9 += carry8;
|
||||
s8 -= carry8 << 21;
|
||||
s8 -= shift_left(carry8, 21);
|
||||
carry9 = s9 >> 21;
|
||||
s10 += carry9;
|
||||
s9 -= carry9 << 21;
|
||||
s9 -= shift_left(carry9, 21);
|
||||
carry10 = s10 >> 21;
|
||||
s11 += carry10;
|
||||
s10 -= carry10 << 21;
|
||||
s10 -= shift_left(carry10, 21);
|
||||
carry11 = s11 >> 21;
|
||||
s12 += carry11;
|
||||
s11 -= carry11 << 21;
|
||||
s11 -= shift_left(carry11, 21);
|
||||
s0 += s12 * 666643;
|
||||
s1 += s12 * 470296;
|
||||
s2 += s12 * 654183;
|
||||
|
@ -283,37 +287,37 @@ void sc_reduce(unsigned char *s) {
|
|||
s12 = 0;
|
||||
carry0 = s0 >> 21;
|
||||
s1 += carry0;
|
||||
s0 -= carry0 << 21;
|
||||
s0 -= shift_left(carry0, 21);
|
||||
carry1 = s1 >> 21;
|
||||
s2 += carry1;
|
||||
s1 -= carry1 << 21;
|
||||
s1 -= shift_left(carry1, 21);
|
||||
carry2 = s2 >> 21;
|
||||
s3 += carry2;
|
||||
s2 -= carry2 << 21;
|
||||
s2 -= shift_left(carry2, 21);
|
||||
carry3 = s3 >> 21;
|
||||
s4 += carry3;
|
||||
s3 -= carry3 << 21;
|
||||
s3 -= shift_left(carry3, 21);
|
||||
carry4 = s4 >> 21;
|
||||
s5 += carry4;
|
||||
s4 -= carry4 << 21;
|
||||
s4 -= shift_left(carry4, 21);
|
||||
carry5 = s5 >> 21;
|
||||
s6 += carry5;
|
||||
s5 -= carry5 << 21;
|
||||
s5 -= shift_left(carry5, 21);
|
||||
carry6 = s6 >> 21;
|
||||
s7 += carry6;
|
||||
s6 -= carry6 << 21;
|
||||
s6 -= shift_left(carry6, 21);
|
||||
carry7 = s7 >> 21;
|
||||
s8 += carry7;
|
||||
s7 -= carry7 << 21;
|
||||
s7 -= shift_left(carry7, 21);
|
||||
carry8 = s8 >> 21;
|
||||
s9 += carry8;
|
||||
s8 -= carry8 << 21;
|
||||
s8 -= shift_left(carry8, 21);
|
||||
carry9 = s9 >> 21;
|
||||
s10 += carry9;
|
||||
s9 -= carry9 << 21;
|
||||
s9 -= shift_left(carry9, 21);
|
||||
carry10 = s10 >> 21;
|
||||
s11 += carry10;
|
||||
s10 -= carry10 << 21;
|
||||
s10 -= shift_left(carry10, 21);
|
||||
|
||||
s[0] = (unsigned char) ((s0 >> 0) & 0xff);
|
||||
s[1] = (unsigned char) ((s0 >> 8) & 0xff);
|
||||
|
@ -473,73 +477,73 @@ void sc_muladd(unsigned char *s, const unsigned char *a, const unsigned char *b,
|
|||
s23 = 0;
|
||||
carry0 = (s0 + (1 << 20)) >> 21;
|
||||
s1 += carry0;
|
||||
s0 -= carry0 << 21;
|
||||
s0 -= shift_left(carry0, 21);
|
||||
carry2 = (s2 + (1 << 20)) >> 21;
|
||||
s3 += carry2;
|
||||
s2 -= carry2 << 21;
|
||||
s2 -= shift_left(carry2, 21);
|
||||
carry4 = (s4 + (1 << 20)) >> 21;
|
||||
s5 += carry4;
|
||||
s4 -= carry4 << 21;
|
||||
s4 -= shift_left(carry4, 21);
|
||||
carry6 = (s6 + (1 << 20)) >> 21;
|
||||
s7 += carry6;
|
||||
s6 -= carry6 << 21;
|
||||
s6 -= shift_left(carry6, 21);
|
||||
carry8 = (s8 + (1 << 20)) >> 21;
|
||||
s9 += carry8;
|
||||
s8 -= carry8 << 21;
|
||||
s8 -= shift_left(carry8, 21);
|
||||
carry10 = (s10 + (1 << 20)) >> 21;
|
||||
s11 += carry10;
|
||||
s10 -= carry10 << 21;
|
||||
s10 -= shift_left(carry10, 21);
|
||||
carry12 = (s12 + (1 << 20)) >> 21;
|
||||
s13 += carry12;
|
||||
s12 -= carry12 << 21;
|
||||
s12 -= shift_left(carry12, 21);
|
||||
carry14 = (s14 + (1 << 20)) >> 21;
|
||||
s15 += carry14;
|
||||
s14 -= carry14 << 21;
|
||||
s14 -= shift_left(carry14, 21);
|
||||
carry16 = (s16 + (1 << 20)) >> 21;
|
||||
s17 += carry16;
|
||||
s16 -= carry16 << 21;
|
||||
s16 -= shift_left(carry16, 21);
|
||||
carry18 = (s18 + (1 << 20)) >> 21;
|
||||
s19 += carry18;
|
||||
s18 -= carry18 << 21;
|
||||
s18 -= shift_left(carry18, 21);
|
||||
carry20 = (s20 + (1 << 20)) >> 21;
|
||||
s21 += carry20;
|
||||
s20 -= carry20 << 21;
|
||||
s20 -= shift_left(carry20, 21);
|
||||
carry22 = (s22 + (1 << 20)) >> 21;
|
||||
s23 += carry22;
|
||||
s22 -= carry22 << 21;
|
||||
s22 -= shift_left(carry22, 21);
|
||||
carry1 = (s1 + (1 << 20)) >> 21;
|
||||
s2 += carry1;
|
||||
s1 -= carry1 << 21;
|
||||
s1 -= shift_left(carry1, 21);
|
||||
carry3 = (s3 + (1 << 20)) >> 21;
|
||||
s4 += carry3;
|
||||
s3 -= carry3 << 21;
|
||||
s3 -= shift_left(carry3, 21);
|
||||
carry5 = (s5 + (1 << 20)) >> 21;
|
||||
s6 += carry5;
|
||||
s5 -= carry5 << 21;
|
||||
s5 -= shift_left(carry5, 21);
|
||||
carry7 = (s7 + (1 << 20)) >> 21;
|
||||
s8 += carry7;
|
||||
s7 -= carry7 << 21;
|
||||
s7 -= shift_left(carry7, 21);
|
||||
carry9 = (s9 + (1 << 20)) >> 21;
|
||||
s10 += carry9;
|
||||
s9 -= carry9 << 21;
|
||||
s9 -= shift_left(carry9, 21);
|
||||
carry11 = (s11 + (1 << 20)) >> 21;
|
||||
s12 += carry11;
|
||||
s11 -= carry11 << 21;
|
||||
s11 -= shift_left(carry11, 21);
|
||||
carry13 = (s13 + (1 << 20)) >> 21;
|
||||
s14 += carry13;
|
||||
s13 -= carry13 << 21;
|
||||
s13 -= shift_left(carry13, 21);
|
||||
carry15 = (s15 + (1 << 20)) >> 21;
|
||||
s16 += carry15;
|
||||
s15 -= carry15 << 21;
|
||||
s15 -= shift_left(carry15, 21);
|
||||
carry17 = (s17 + (1 << 20)) >> 21;
|
||||
s18 += carry17;
|
||||
s17 -= carry17 << 21;
|
||||
s17 -= shift_left(carry17, 21);
|
||||
carry19 = (s19 + (1 << 20)) >> 21;
|
||||
s20 += carry19;
|
||||
s19 -= carry19 << 21;
|
||||
s19 -= shift_left(carry19, 21);
|
||||
carry21 = (s21 + (1 << 20)) >> 21;
|
||||
s22 += carry21;
|
||||
s21 -= carry21 << 21;
|
||||
s21 -= shift_left(carry21, 21);
|
||||
s11 += s23 * 666643;
|
||||
s12 += s23 * 470296;
|
||||
s13 += s23 * 654183;
|
||||
|
@ -584,37 +588,37 @@ void sc_muladd(unsigned char *s, const unsigned char *a, const unsigned char *b,
|
|||
s18 = 0;
|
||||
carry6 = (s6 + (1 << 20)) >> 21;
|
||||
s7 += carry6;
|
||||
s6 -= carry6 << 21;
|
||||
s6 -= shift_left(carry6, 21);
|
||||
carry8 = (s8 + (1 << 20)) >> 21;
|
||||
s9 += carry8;
|
||||
s8 -= carry8 << 21;
|
||||
s8 -= shift_left(carry8, 21);
|
||||
carry10 = (s10 + (1 << 20)) >> 21;
|
||||
s11 += carry10;
|
||||
s10 -= carry10 << 21;
|
||||
s10 -= shift_left(carry10, 21);
|
||||
carry12 = (s12 + (1 << 20)) >> 21;
|
||||
s13 += carry12;
|
||||
s12 -= carry12 << 21;
|
||||
s12 -= shift_left(carry12, 21);
|
||||
carry14 = (s14 + (1 << 20)) >> 21;
|
||||
s15 += carry14;
|
||||
s14 -= carry14 << 21;
|
||||
s14 -= shift_left(carry14, 21);
|
||||
carry16 = (s16 + (1 << 20)) >> 21;
|
||||
s17 += carry16;
|
||||
s16 -= carry16 << 21;
|
||||
s16 -= shift_left(carry16, 21);
|
||||
carry7 = (s7 + (1 << 20)) >> 21;
|
||||
s8 += carry7;
|
||||
s7 -= carry7 << 21;
|
||||
s7 -= shift_left(carry7, 21);
|
||||
carry9 = (s9 + (1 << 20)) >> 21;
|
||||
s10 += carry9;
|
||||
s9 -= carry9 << 21;
|
||||
s9 -= shift_left(carry9, 21);
|
||||
carry11 = (s11 + (1 << 20)) >> 21;
|
||||
s12 += carry11;
|
||||
s11 -= carry11 << 21;
|
||||
s11 -= shift_left(carry11, 21);
|
||||
carry13 = (s13 + (1 << 20)) >> 21;
|
||||
s14 += carry13;
|
||||
s13 -= carry13 << 21;
|
||||
s13 -= shift_left(carry13, 21);
|
||||
carry15 = (s15 + (1 << 20)) >> 21;
|
||||
s16 += carry15;
|
||||
s15 -= carry15 << 21;
|
||||
s15 -= shift_left(carry15, 21);
|
||||
s5 += s17 * 666643;
|
||||
s6 += s17 * 470296;
|
||||
s7 += s17 * 654183;
|
||||
|
@ -659,40 +663,40 @@ void sc_muladd(unsigned char *s, const unsigned char *a, const unsigned char *b,
|
|||
s12 = 0;
|
||||
carry0 = (s0 + (1 << 20)) >> 21;
|
||||
s1 += carry0;
|
||||
s0 -= carry0 << 21;
|
||||
s0 -= shift_left(carry0, 21);
|
||||
carry2 = (s2 + (1 << 20)) >> 21;
|
||||
s3 += carry2;
|
||||
s2 -= carry2 << 21;
|
||||
s2 -= shift_left(carry2, 21);
|
||||
carry4 = (s4 + (1 << 20)) >> 21;
|
||||
s5 += carry4;
|
||||
s4 -= carry4 << 21;
|
||||
s4 -= shift_left(carry4, 21);
|
||||
carry6 = (s6 + (1 << 20)) >> 21;
|
||||
s7 += carry6;
|
||||
s6 -= carry6 << 21;
|
||||
s6 -= shift_left(carry6, 21);
|
||||
carry8 = (s8 + (1 << 20)) >> 21;
|
||||
s9 += carry8;
|
||||
s8 -= carry8 << 21;
|
||||
s8 -= shift_left(carry8, 21);
|
||||
carry10 = (s10 + (1 << 20)) >> 21;
|
||||
s11 += carry10;
|
||||
s10 -= carry10 << 21;
|
||||
s10 -= shift_left(carry10, 21);
|
||||
carry1 = (s1 + (1 << 20)) >> 21;
|
||||
s2 += carry1;
|
||||
s1 -= carry1 << 21;
|
||||
s1 -= shift_left(carry1, 21);
|
||||
carry3 = (s3 + (1 << 20)) >> 21;
|
||||
s4 += carry3;
|
||||
s3 -= carry3 << 21;
|
||||
s3 -= shift_left(carry3, 21);
|
||||
carry5 = (s5 + (1 << 20)) >> 21;
|
||||
s6 += carry5;
|
||||
s5 -= carry5 << 21;
|
||||
s5 -= shift_left(carry5, 21);
|
||||
carry7 = (s7 + (1 << 20)) >> 21;
|
||||
s8 += carry7;
|
||||
s7 -= carry7 << 21;
|
||||
s7 -= shift_left(carry7, 21);
|
||||
carry9 = (s9 + (1 << 20)) >> 21;
|
||||
s10 += carry9;
|
||||
s9 -= carry9 << 21;
|
||||
s9 -= shift_left(carry9, 21);
|
||||
carry11 = (s11 + (1 << 20)) >> 21;
|
||||
s12 += carry11;
|
||||
s11 -= carry11 << 21;
|
||||
s11 -= shift_left(carry11, 21);
|
||||
s0 += s12 * 666643;
|
||||
s1 += s12 * 470296;
|
||||
s2 += s12 * 654183;
|
||||
|
@ -702,40 +706,40 @@ void sc_muladd(unsigned char *s, const unsigned char *a, const unsigned char *b,
|
|||
s12 = 0;
|
||||
carry0 = s0 >> 21;
|
||||
s1 += carry0;
|
||||
s0 -= carry0 << 21;
|
||||
s0 -= shift_left(carry0, 21);
|
||||
carry1 = s1 >> 21;
|
||||
s2 += carry1;
|
||||
s1 -= carry1 << 21;
|
||||
s1 -= shift_left(carry1, 21);
|
||||
carry2 = s2 >> 21;
|
||||
s3 += carry2;
|
||||
s2 -= carry2 << 21;
|
||||
s2 -= shift_left(carry2, 21);
|
||||
carry3 = s3 >> 21;
|
||||
s4 += carry3;
|
||||
s3 -= carry3 << 21;
|
||||
s3 -= shift_left(carry3, 21);
|
||||
carry4 = s4 >> 21;
|
||||
s5 += carry4;
|
||||
s4 -= carry4 << 21;
|
||||
s4 -= shift_left(carry4, 21);
|
||||
carry5 = s5 >> 21;
|
||||
s6 += carry5;
|
||||
s5 -= carry5 << 21;
|
||||
s5 -= shift_left(carry5, 21);
|
||||
carry6 = s6 >> 21;
|
||||
s7 += carry6;
|
||||
s6 -= carry6 << 21;
|
||||
s6 -= shift_left(carry6, 21);
|
||||
carry7 = s7 >> 21;
|
||||
s8 += carry7;
|
||||
s7 -= carry7 << 21;
|
||||
s7 -= shift_left(carry7, 21);
|
||||
carry8 = s8 >> 21;
|
||||
s9 += carry8;
|
||||
s8 -= carry8 << 21;
|
||||
s8 -= shift_left(carry8, 21);
|
||||
carry9 = s9 >> 21;
|
||||
s10 += carry9;
|
||||
s9 -= carry9 << 21;
|
||||
s9 -= shift_left(carry9, 21);
|
||||
carry10 = s10 >> 21;
|
||||
s11 += carry10;
|
||||
s10 -= carry10 << 21;
|
||||
s10 -= shift_left(carry10, 21);
|
||||
carry11 = s11 >> 21;
|
||||
s12 += carry11;
|
||||
s11 -= carry11 << 21;
|
||||
s11 -= shift_left(carry11, 21);
|
||||
s0 += s12 * 666643;
|
||||
s1 += s12 * 470296;
|
||||
s2 += s12 * 654183;
|
||||
|
@ -745,37 +749,37 @@ void sc_muladd(unsigned char *s, const unsigned char *a, const unsigned char *b,
|
|||
s12 = 0;
|
||||
carry0 = s0 >> 21;
|
||||
s1 += carry0;
|
||||
s0 -= carry0 << 21;
|
||||
s0 -= shift_left(carry0, 21);
|
||||
carry1 = s1 >> 21;
|
||||
s2 += carry1;
|
||||
s1 -= carry1 << 21;
|
||||
s1 -= shift_left(carry1, 21);
|
||||
carry2 = s2 >> 21;
|
||||
s3 += carry2;
|
||||
s2 -= carry2 << 21;
|
||||
s2 -= shift_left(carry2, 21);
|
||||
carry3 = s3 >> 21;
|
||||
s4 += carry3;
|
||||
s3 -= carry3 << 21;
|
||||
s3 -= shift_left(carry3, 21);
|
||||
carry4 = s4 >> 21;
|
||||
s5 += carry4;
|
||||
s4 -= carry4 << 21;
|
||||
s4 -= shift_left(carry4, 21);
|
||||
carry5 = s5 >> 21;
|
||||
s6 += carry5;
|
||||
s5 -= carry5 << 21;
|
||||
s5 -= shift_left(carry5, 21);
|
||||
carry6 = s6 >> 21;
|
||||
s7 += carry6;
|
||||
s6 -= carry6 << 21;
|
||||
s6 -= shift_left(carry6, 21);
|
||||
carry7 = s7 >> 21;
|
||||
s8 += carry7;
|
||||
s7 -= carry7 << 21;
|
||||
s7 -= shift_left(carry7, 21);
|
||||
carry8 = s8 >> 21;
|
||||
s9 += carry8;
|
||||
s8 -= carry8 << 21;
|
||||
s8 -= shift_left(carry8, 21);
|
||||
carry9 = s9 >> 21;
|
||||
s10 += carry9;
|
||||
s9 -= carry9 << 21;
|
||||
s9 -= shift_left(carry9, 21);
|
||||
carry10 = s10 >> 21;
|
||||
s11 += carry10;
|
||||
s10 -= carry10 << 21;
|
||||
s10 -= shift_left(carry10, 21);
|
||||
|
||||
s[0] = (unsigned char) ((s0 >> 0) & 0xff);
|
||||
s[1] = (unsigned char) ((s0 >> 8) & 0xff);
|
||||
|
|
|
@ -74,7 +74,8 @@ namespace libtorrent {
|
|||
, boost::uint32_t alert_mask = alert::error_notification);
|
||||
~alert_manager();
|
||||
|
||||
#ifndef BOOST_NO_CXX11_VARIADIC_TEMPLATES
|
||||
#if !defined BOOST_NO_CXX11_VARIADIC_TEMPLATES \
|
||||
&& !defined BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
|
||||
template <class T, typename... Args>
|
||||
void emplace_alert(Args&&... args)
|
||||
|
|
|
@ -226,11 +226,13 @@ namespace libtorrent
|
|||
// set all bits in the bitfield to 1 (set_all) or 0 (clear_all).
|
||||
void set_all()
|
||||
{
|
||||
if (m_buf == NULL) return;
|
||||
std::memset(m_buf, 0xff, size_t(num_words() * 4));
|
||||
clear_trailing_bits();
|
||||
}
|
||||
void clear_all()
|
||||
{
|
||||
if (m_buf == NULL) return;
|
||||
std::memset(m_buf, 0x00, size_t(num_words() * 4));
|
||||
}
|
||||
|
||||
|
|
|
@ -76,7 +76,8 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#if DEBUG_DISK_THREAD
|
||||
#define DLOG debug_log
|
||||
#else
|
||||
#define DLOG TORRENT_WHILE_0 debug_log
|
||||
inline void dummy(char const*, ...) {}
|
||||
#define DLOG TORRENT_WHILE_0 dummy
|
||||
#endif
|
||||
|
||||
#endif // cplusplus
|
||||
|
@ -95,14 +96,10 @@ namespace libtorrent
|
|||
|
||||
namespace {
|
||||
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wunused-function"
|
||||
#endif
|
||||
#if DEBUG_DISK_THREAD
|
||||
|
||||
void debug_log(char const* fmt, ...)
|
||||
{
|
||||
#if DEBUG_DISK_THREAD
|
||||
static mutex log_mutex;
|
||||
static const time_point start = clock_type::now();
|
||||
va_list v;
|
||||
|
@ -126,11 +123,10 @@ namespace libtorrent
|
|||
prepend_time = (usr[len-1] == '\n');
|
||||
mutex::scoped_lock l(log_mutex);
|
||||
fputs(buf, stderr);
|
||||
#else
|
||||
TORRENT_UNUSED(fmt);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // DEBUG_DISK_THREAD
|
||||
|
||||
int file_flags_for_job(disk_io_job* j
|
||||
, bool const coalesce_buffers)
|
||||
{
|
||||
|
@ -140,10 +136,6 @@ namespace libtorrent
|
|||
return ret;
|
||||
}
|
||||
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
// ------- disk_io_thread ------
|
||||
|
|
|
@ -102,6 +102,7 @@ const unsigned long siocgifmtu = SIOCGIFMTU;
|
|||
namespace libtorrent { namespace
|
||||
{
|
||||
|
||||
#if !defined TORRENT_BUILD_SIMULATOR
|
||||
address inaddr_to_address(in_addr const* ina, int len = 4)
|
||||
{
|
||||
typedef boost::asio::ip::address_v4::bytes_type bytes_t;
|
||||
|
@ -157,7 +158,7 @@ namespace libtorrent { namespace
|
|||
int read_len = recv(sock, buf, bufsize - msg_len, 0);
|
||||
if (read_len < 0) return -1;
|
||||
|
||||
nl_hdr = (nlmsghdr*)buf;
|
||||
nl_hdr = reinterpret_cast<nlmsghdr*>(buf);
|
||||
|
||||
if ((NLMSG_OK(nl_hdr, read_len) == 0) || (nl_hdr->nlmsg_type == NLMSG_ERROR))
|
||||
return -1;
|
||||
|
@ -175,7 +176,7 @@ namespace libtorrent { namespace
|
|||
|
||||
bool parse_route(int s, nlmsghdr* nl_hdr, ip_route* rt_info)
|
||||
{
|
||||
rtmsg* rt_msg = (rtmsg*)NLMSG_DATA(nl_hdr);
|
||||
rtmsg* rt_msg = reinterpret_cast<rtmsg*>(NLMSG_DATA(nl_hdr));
|
||||
|
||||
if((rt_msg->rtm_family != AF_INET && rt_msg->rtm_family != AF_INET6) || (rt_msg->rtm_table != RT_TABLE_MAIN
|
||||
&& rt_msg->rtm_table != RT_TABLE_LOCAL))
|
||||
|
@ -183,40 +184,47 @@ namespace libtorrent { namespace
|
|||
|
||||
int if_index = 0;
|
||||
int rt_len = RTM_PAYLOAD(nl_hdr);
|
||||
for (rtattr* rt_attr = (rtattr*)RTM_RTA(rt_msg);
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wcast-align"
|
||||
#endif
|
||||
for (rtattr* rt_attr = reinterpret_cast<rtattr*>(RTM_RTA(rt_msg));
|
||||
RTA_OK(rt_attr,rt_len); rt_attr = RTA_NEXT(rt_attr,rt_len))
|
||||
{
|
||||
switch(rt_attr->rta_type)
|
||||
{
|
||||
case RTA_OIF:
|
||||
if_index = *(int*)RTA_DATA(rt_attr);
|
||||
if_index = *reinterpret_cast<int*>(RTA_DATA(rt_attr));
|
||||
break;
|
||||
case RTA_GATEWAY:
|
||||
#if TORRENT_USE_IPV6
|
||||
if (rt_msg->rtm_family == AF_INET6)
|
||||
{
|
||||
rt_info->gateway = inaddr6_to_address((in6_addr*)RTA_DATA(rt_attr));
|
||||
rt_info->gateway = inaddr6_to_address(reinterpret_cast<in6_addr*>(RTA_DATA(rt_attr)));
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
rt_info->gateway = inaddr_to_address((in_addr*)RTA_DATA(rt_attr));
|
||||
rt_info->gateway = inaddr_to_address(reinterpret_cast<in_addr*>(RTA_DATA(rt_attr)));
|
||||
}
|
||||
break;
|
||||
case RTA_DST:
|
||||
#if TORRENT_USE_IPV6
|
||||
if (rt_msg->rtm_family == AF_INET6)
|
||||
{
|
||||
rt_info->destination = inaddr6_to_address((in6_addr*)RTA_DATA(rt_attr));
|
||||
rt_info->destination = inaddr6_to_address(reinterpret_cast<in6_addr*>(RTA_DATA(rt_attr)));
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
rt_info->destination = inaddr_to_address((in_addr*)RTA_DATA(rt_attr));
|
||||
rt_info->destination = inaddr_to_address(reinterpret_cast<in_addr*>(RTA_DATA(rt_attr)));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
if_indextoname(if_index, rt_info->name);
|
||||
ifreq req;
|
||||
|
@ -230,7 +238,8 @@ namespace libtorrent { namespace
|
|||
// }
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
#endif // TORRENT_USE_NETLINK
|
||||
#endif // !BUILD_SIMULATOR
|
||||
|
||||
#if TORRENT_USE_SYSCTL && !defined TORRENT_BUILD_SIMULATOR
|
||||
#ifdef TORRENT_OS2
|
||||
|
@ -375,7 +384,7 @@ namespace libtorrent
|
|||
typedef boost::asio::ip::address_v4::bytes_type bytes_t;
|
||||
bytes_t b;
|
||||
std::memset(&b[0], 0xff, b.size());
|
||||
for (int i = sizeof(bytes_t)/8-1; i > 0; --i)
|
||||
for (int i = int(sizeof(bytes_t)) / 8 - 1; i > 0; --i)
|
||||
{
|
||||
if (bits < 8)
|
||||
{
|
||||
|
@ -393,7 +402,7 @@ namespace libtorrent
|
|||
typedef boost::asio::ip::address_v6::bytes_type bytes_t;
|
||||
bytes_t b;
|
||||
std::memset(&b[0], 0xff, b.size());
|
||||
for (int i = sizeof(bytes_t)/8-1; i > 0; --i)
|
||||
for (int i = int(sizeof(bytes_t)) / 8 - 1; i > 0; --i)
|
||||
{
|
||||
if (bits < 8)
|
||||
{
|
||||
|
@ -465,9 +474,9 @@ namespace libtorrent
|
|||
if (iface_from_ifaddrs(ifa, iface))
|
||||
{
|
||||
ifreq req;
|
||||
memset(&req, 0, sizeof(req));
|
||||
// -1 to leave a null terminator
|
||||
strncpy(req.ifr_name, iface.name, IF_NAMESIZE - 1);
|
||||
std::memset(&req, 0, sizeof(req));
|
||||
// -1 to leave a 0-terminator
|
||||
std::strncpy(req.ifr_name, iface.name, IF_NAMESIZE - 1);
|
||||
|
||||
// ignore errors here. This is best-effort
|
||||
ioctl(s, siocgifmtu, &req);
|
||||
|
@ -490,7 +499,7 @@ namespace libtorrent
|
|||
// make sure the buffer is aligned to hold ifreq structs
|
||||
ifreq buf[40];
|
||||
ifc.ifc_len = sizeof(buf);
|
||||
ifc.ifc_buf = (char*)buf;
|
||||
ifc.ifc_buf = reinterpret_cast<char*>(buf);
|
||||
if (ioctl(s, SIOCGIFCONF, &ifc) < 0)
|
||||
{
|
||||
ec = error_code(errno, system_category());
|
||||
|
@ -498,7 +507,7 @@ namespace libtorrent
|
|||
return ret;
|
||||
}
|
||||
|
||||
char *ifr = (char*)ifc.ifc_req;
|
||||
char *ifr = reinterpret_cast<char*>(ifc.ifc_req);
|
||||
int remaining = ifc.ifc_len;
|
||||
|
||||
while (remaining > 0)
|
||||
|
@ -527,7 +536,7 @@ namespace libtorrent
|
|||
|
||||
ifreq req;
|
||||
memset(&req, 0, sizeof(req));
|
||||
// -1 to leave a null terminator
|
||||
// -1 to leave a 0-terminator
|
||||
strncpy(req.ifr_name, item.ifr_name, IF_NAMESIZE - 1);
|
||||
if (ioctl(s, siocgifmtu, &req) < 0)
|
||||
{
|
||||
|
@ -1081,7 +1090,7 @@ namespace libtorrent
|
|||
|
||||
char msg[BUFSIZE];
|
||||
memset(msg, 0, BUFSIZE);
|
||||
nlmsghdr* nl_msg = (nlmsghdr*)msg;
|
||||
nlmsghdr* nl_msg = reinterpret_cast<nlmsghdr*>(msg);
|
||||
|
||||
nl_msg->nlmsg_len = NLMSG_LENGTH(sizeof(rtmsg));
|
||||
nl_msg->nlmsg_type = RTM_GETROUTE;
|
||||
|
@ -1110,11 +1119,18 @@ namespace libtorrent
|
|||
ec = error_code(errno, system_category());
|
||||
return std::vector<ip_route>();
|
||||
}
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wcast-align"
|
||||
#endif
|
||||
for (; NLMSG_OK(nl_msg, len); nl_msg = NLMSG_NEXT(nl_msg, len))
|
||||
{
|
||||
ip_route r;
|
||||
if (parse_route(s, nl_msg, &r)) ret.push_back(r);
|
||||
}
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
close(s);
|
||||
close(sock);
|
||||
|
||||
|
|
|
@ -1681,6 +1681,7 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
|
|||
|
||||
namespace {
|
||||
|
||||
#if !TORRENT_USE_PREADV
|
||||
void gather_copy(file::iovec_t const* bufs, int num_bufs, char* dst)
|
||||
{
|
||||
std::size_t offset = 0;
|
||||
|
@ -1701,7 +1702,6 @@ typedef struct _FILE_ALLOCATED_RANGE_BUFFER {
|
|||
}
|
||||
}
|
||||
|
||||
#if !TORRENT_USE_PREADV
|
||||
bool coalesce_read_buffers(file::iovec_t const*& bufs, int& num_bufs
|
||||
, file::iovec_t* tmp)
|
||||
{
|
||||
|
|
|
@ -1062,14 +1062,15 @@ namespace libtorrent
|
|||
// since the call to disconnect_if_redundant() may
|
||||
// delete the entry from this container, make sure
|
||||
// to increment the iterator early
|
||||
bt_peer_connection* p = static_cast<bt_peer_connection*>(*i);
|
||||
peer_connection* p = *i;
|
||||
if (p->type() == peer_connection::bittorrent_connection)
|
||||
{
|
||||
boost::shared_ptr<peer_connection> me(p->self());
|
||||
if (!p->is_disconnecting())
|
||||
bt_peer_connection* btp = static_cast<bt_peer_connection*>(*i);
|
||||
boost::shared_ptr<peer_connection> me(btp->self());
|
||||
if (!btp->is_disconnecting())
|
||||
{
|
||||
p->send_not_interested();
|
||||
p->write_upload_only();
|
||||
btp->send_not_interested();
|
||||
btp->write_upload_only();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -807,7 +807,7 @@ void utp_socket_impl::update_mtu_limits()
|
|||
|
||||
m_mtu = (m_mtu_floor + m_mtu_ceiling) / 2;
|
||||
|
||||
if ((m_cwnd >> 16) < m_mtu) m_cwnd = boost::int64_t(m_mtu) << 16;
|
||||
if ((m_cwnd >> 16) < m_mtu) m_cwnd = boost::int64_t(m_mtu) * (1 << 16);
|
||||
|
||||
UTP_LOGV("%8p: updating MTU to: %d [%d, %d]\n"
|
||||
, static_cast<void*>(this), m_mtu, m_mtu_floor, m_mtu_ceiling);
|
||||
|
@ -2338,7 +2338,8 @@ void utp_socket_impl::experienced_loss(int const seq_nr)
|
|||
if (compare_less_wrap(seq_nr, m_loss_seq_nr + 1, ACK_MASK)) return;
|
||||
|
||||
// cut window size in 2
|
||||
m_cwnd = (std::max)(m_cwnd * m_sm->loss_multiplier() / 100, boost::int64_t(m_mtu << 16));
|
||||
m_cwnd = std::max(m_cwnd * m_sm->loss_multiplier() / 100
|
||||
, boost::int64_t(m_mtu) * (1 << 16));
|
||||
m_loss_seq_nr = m_seq_nr;
|
||||
UTP_LOGV("%8p: Lost packet %d caused cwnd cut\n", static_cast<void*>(this), seq_nr);
|
||||
|
||||
|
@ -2699,7 +2700,7 @@ void utp_socket_impl::init_mtu(int link_mtu, int utp_mtu)
|
|||
|
||||
// if the window size is smaller than one packet size
|
||||
// set it to one
|
||||
if ((m_cwnd >> 16) < m_mtu) m_cwnd = boost::int64_t(m_mtu) << 16;
|
||||
if ((m_cwnd >> 16) < m_mtu) m_cwnd = boost::int64_t(m_mtu) * (1 << 16);
|
||||
|
||||
UTP_LOGV("%8p: initializing MTU to: %d [%d, %d]\n"
|
||||
, static_cast<void*>(this), m_mtu, m_mtu_floor, m_mtu_ceiling);
|
||||
|
@ -3424,8 +3425,8 @@ void utp_socket_impl::do_ledbat(const int acked_bytes, const int delay
|
|||
const bool cwnd_saturated = (m_bytes_in_flight + acked_bytes + m_mtu > (m_cwnd >> 16));
|
||||
|
||||
// all of these are fixed points with 16 bits fraction portion
|
||||
const boost::int64_t window_factor = (boost::int64_t(acked_bytes) << 16) / in_flight;
|
||||
const boost::int64_t delay_factor = (boost::int64_t(target_delay - delay) << 16) / target_delay;
|
||||
const boost::int64_t window_factor = (boost::int64_t(acked_bytes) * (1 << 16)) / in_flight;
|
||||
const boost::int64_t delay_factor = (boost::int64_t(target_delay - delay) * (1 << 16)) / target_delay;
|
||||
boost::int64_t scaled_gain;
|
||||
|
||||
if (delay >= target_delay)
|
||||
|
@ -3452,7 +3453,7 @@ void utp_socket_impl::do_ledbat(const int acked_bytes, const int delay
|
|||
// congestion window), don't adjust it at all.
|
||||
if (cwnd_saturated)
|
||||
{
|
||||
boost::int64_t exponential_gain = boost::int64_t(acked_bytes) << 16;
|
||||
boost::int64_t exponential_gain = boost::int64_t(acked_bytes) * (1 << 16);
|
||||
if (m_slow_start)
|
||||
{
|
||||
// mimic TCP slow-start by adding the number of acked
|
||||
|
@ -3623,13 +3624,13 @@ void utp_socket_impl::tick(time_point now)
|
|||
{
|
||||
// this is just a timeout because this direction of
|
||||
// the stream is idle. Don't reset the cwnd, just decay it
|
||||
m_cwnd = (std::max)(m_cwnd * 2 / 3, boost::int64_t(m_mtu) << 16);
|
||||
m_cwnd = std::max(m_cwnd * 2 / 3, boost::int64_t(m_mtu) * (1 << 16));
|
||||
}
|
||||
else
|
||||
{
|
||||
// we timed out because a packet was not ACKed or because
|
||||
// the cwnd was made smaller than one packet
|
||||
m_cwnd = boost::int64_t(m_mtu) << 16;
|
||||
m_cwnd = boost::int64_t(m_mtu) * (1 << 16);
|
||||
}
|
||||
|
||||
TORRENT_ASSERT(m_cwnd >= 0);
|
||||
|
|
|
@ -151,6 +151,7 @@ test-suite libtorrent :
|
|||
[ run test_web_seed_chunked.cpp ]
|
||||
[ run test_web_seed_ban.cpp ]
|
||||
[ run test_pe_crypto.cpp ]
|
||||
[ run test_ed25519.cpp ]
|
||||
|
||||
[ run test_remap_files.cpp ]
|
||||
[ run test_utp.cpp ]
|
||||
|
|
|
@ -45,7 +45,8 @@ test_programs = \
|
|||
test_enum_net \
|
||||
test_file_progress \
|
||||
test_linked_list \
|
||||
test_direct_dht
|
||||
test_direct_dht \
|
||||
test_ed25519.cpp
|
||||
|
||||
if ENABLE_TESTS
|
||||
check_PROGRAMS = $(test_programs) $(benchmark_programs)
|
||||
|
|
|
@ -68,7 +68,8 @@ using namespace libtorrent;
|
|||
// out, such as the log
|
||||
int old_stdout = -1;
|
||||
int old_stderr = -1;
|
||||
bool redirect_output = true;
|
||||
bool redirect_stdout = true;
|
||||
bool redirect_stderr = true;
|
||||
bool keep_files = false;
|
||||
|
||||
extern int _g_test_idx;
|
||||
|
@ -79,7 +80,7 @@ unit_test_t* current_test = NULL;
|
|||
void output_test_log_to_terminal()
|
||||
{
|
||||
if (current_test == NULL || old_stdout == -1 || old_stderr == -1
|
||||
|| !redirect_output || current_test->output == NULL)
|
||||
|| !redirect_stdout || current_test->output == NULL)
|
||||
return;
|
||||
|
||||
fflush(stdout);
|
||||
|
@ -88,12 +89,12 @@ void output_test_log_to_terminal()
|
|||
dup2(old_stderr, fileno(stderr));
|
||||
|
||||
fseek(current_test->output, 0, SEEK_SET);
|
||||
fprintf(stderr, "\x1b[1m[%s]\x1b[0m\n\n", current_test->name);
|
||||
fprintf(stdout, "\x1b[1m[%s]\x1b[0m\n\n", current_test->name);
|
||||
char buf[4096];
|
||||
int size = 0;
|
||||
do {
|
||||
size = fread(buf, 1, sizeof(buf), current_test->output);
|
||||
if (size > 0) fwrite(buf, 1, size, stderr);
|
||||
if (size > 0) fwrite(buf, 1, size, stdout);
|
||||
} while (size > 0);
|
||||
}
|
||||
|
||||
|
@ -205,13 +206,17 @@ void print_usage(char const* executable)
|
|||
printf("%s [options] [tests...]\n"
|
||||
"\n"
|
||||
"OPTIONS:\n"
|
||||
"-h,--help show this help\n"
|
||||
"-l,--list list the tests available to run\n"
|
||||
"-k,--keep keep files created by the test\n"
|
||||
" regardless of whether it passed or not\n"
|
||||
"-n,--no-redirect don't redirect test output to\n"
|
||||
" temporary file, but let it go straight\n"
|
||||
" to stdout\n"
|
||||
"-h,--help show this help\n"
|
||||
"-l,--list list the tests available to run\n"
|
||||
"-k,--keep keep files created by the test\n"
|
||||
" regardless of whether it passed or not\n"
|
||||
"-n,--no-redirect don't redirect test output to\n"
|
||||
" temporary file, but let it go straight\n"
|
||||
" to stdout\n"
|
||||
"--no-stderr-redirect don't redirect stderr, but still redirect\n"
|
||||
" stdout. This is useful when building with\n"
|
||||
" sanitizers, which rely on being able to print\n"
|
||||
" to stderr and exit\n"
|
||||
"\n"
|
||||
"for tests, specify one or more test names as printed\n"
|
||||
"by -l. If no test is specified, all tests are run\n", executable);
|
||||
|
@ -245,7 +250,13 @@ EXPORT int main(int argc, char const* argv[])
|
|||
|
||||
if (strcmp(argv[0], "-n") == 0 || strcmp(argv[0], "--no-redirect") == 0)
|
||||
{
|
||||
redirect_output = false;
|
||||
redirect_stdout = false;
|
||||
redirect_stderr = false;
|
||||
}
|
||||
|
||||
if (strcmp(argv[0], "--no-stderr-redirect") == 0)
|
||||
{
|
||||
redirect_stderr = false;
|
||||
}
|
||||
|
||||
if (strcmp(argv[0], "-k") == 0 || strcmp(argv[0], "--keep") == 0)
|
||||
|
@ -335,11 +346,8 @@ EXPORT int main(int argc, char const* argv[])
|
|||
return 1;
|
||||
}
|
||||
|
||||
if (redirect_output)
|
||||
{
|
||||
old_stdout = dup(fileno(stdout));
|
||||
old_stderr = dup(fileno(stderr));
|
||||
}
|
||||
if (redirect_stdout) old_stdout = dup(fileno(stdout));
|
||||
if (redirect_stderr) old_stderr = dup(fileno(stderr));
|
||||
|
||||
int num_run = 0;
|
||||
for (int i = 0; i < _g_num_unit_tests; ++i)
|
||||
|
@ -349,7 +357,7 @@ EXPORT int main(int argc, char const* argv[])
|
|||
|
||||
unit_test_t& t = _g_unit_tests[i];
|
||||
|
||||
if (redirect_output)
|
||||
if (redirect_stdout)
|
||||
{
|
||||
// redirect test output to a temporary file
|
||||
fflush(stdout);
|
||||
|
@ -359,7 +367,7 @@ EXPORT int main(int argc, char const* argv[])
|
|||
if (f != NULL)
|
||||
{
|
||||
int ret1 = dup2(fileno(f), fileno(stdout));
|
||||
dup2(fileno(f), fileno(stderr));
|
||||
if (redirect_stderr) dup2(fileno(f), fileno(stderr));
|
||||
if (ret1 >= 0)
|
||||
{
|
||||
t.output = f;
|
||||
|
@ -417,17 +425,12 @@ EXPORT int main(int argc, char const* argv[])
|
|||
total_failures += _g_test_failures;
|
||||
++num_run;
|
||||
|
||||
if (redirect_output && t.output)
|
||||
{
|
||||
if (redirect_stdout && t.output)
|
||||
fclose(t.output);
|
||||
}
|
||||
}
|
||||
|
||||
if (redirect_output)
|
||||
{
|
||||
dup2(old_stdout, fileno(stdout));
|
||||
dup2(old_stderr, fileno(stderr));
|
||||
}
|
||||
if (redirect_stdout) dup2(old_stdout, fileno(stdout));
|
||||
if (redirect_stderr) dup2(old_stderr, fileno(stderr));
|
||||
|
||||
if (!tests_to_run.empty())
|
||||
{
|
||||
|
@ -453,11 +456,8 @@ EXPORT int main(int argc, char const* argv[])
|
|||
stop_peer();
|
||||
stop_dht();
|
||||
|
||||
if (redirect_output)
|
||||
{
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
}
|
||||
if (redirect_stdout) fflush(stdout);
|
||||
if (redirect_stderr) fflush(stderr);
|
||||
|
||||
int ret = print_failures();
|
||||
#if !defined TORRENT_LOGGING
|
||||
|
|
|
@ -0,0 +1,228 @@
|
|||
/*
|
||||
|
||||
Copyright (c) 2016, Alden Torres
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the author nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "test.hpp"
|
||||
|
||||
#ifndef TORRENT_DISABLE_DHT
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <ed25519.hpp>
|
||||
#include "libtorrent/hex.hpp"
|
||||
|
||||
using namespace libtorrent;
|
||||
|
||||
namespace
|
||||
{
|
||||
void test_vector(std::string seed, std::string pub, std::string sig_hex, std::string message)
|
||||
{
|
||||
typedef unsigned char uchar;
|
||||
uchar s[32];
|
||||
uchar sk[64];
|
||||
uchar pk[32];
|
||||
uchar sig[64];
|
||||
std::vector<uchar> msg(int(message.size()) / 2);
|
||||
|
||||
from_hex(seed.c_str(), seed.size(), reinterpret_cast<char*>(s));
|
||||
ed25519_create_keypair(pk, sk, s);
|
||||
|
||||
TEST_EQUAL(to_hex(std::string(reinterpret_cast<char*>(pk), sizeof(pk))), pub);
|
||||
|
||||
from_hex(message.c_str(), message.size(), reinterpret_cast<char*>(&msg[0]));
|
||||
ed25519_sign(sig, &msg[0], msg.size(), pk, sk);
|
||||
|
||||
TEST_EQUAL(to_hex(std::string(reinterpret_cast<char*>(sig), sizeof(sig))), sig_hex);
|
||||
|
||||
bool r = ed25519_verify(sig, &msg[0], msg.size(), pk);
|
||||
|
||||
TEST_CHECK(r);
|
||||
}
|
||||
}
|
||||
|
||||
// https://git.gnupg.org/cgi-bin/gitweb.cgi?p=libgcrypt.git;a=blob;f=tests/t-ed25519.inp;hb=HEAD
|
||||
TORRENT_TEST(ed25519_test_vec1)
|
||||
{
|
||||
// TST: 2
|
||||
test_vector(
|
||||
"4ccd089b28ff96da9db6c346ec114e0f5b8a319f35aba624da8cf6ed4fb8a6fb"
|
||||
, "3d4017c3e843895a92b70aa74d1b7ebc9c982ccf2ec4968cc0cd55f12af4660c"
|
||||
, "92a009a9f0d4cab8720e820b5f642540a2b27b5416503f8fb3762223ebdb69da"
|
||||
"085ac1e43e15996e458f3613d0f11d8c387b2eaeb4302aeeb00d291612bb0c00"
|
||||
, "72"
|
||||
);
|
||||
|
||||
// TST: 3
|
||||
test_vector(
|
||||
"c5aa8df43f9f837bedb7442f31dcb7b166d38535076f094b85ce3a2e0b4458f7"
|
||||
, "fc51cd8e6218a1a38da47ed00230f0580816ed13ba3303ac5deb911548908025"
|
||||
, "6291d657deec24024827e69c3abe01a30ce548a284743a445e3680d7db5ac3ac"
|
||||
"18ff9b538d16f290ae67f760984dc6594a7c15e9716ed28dc027beceea1ec40a"
|
||||
, "af82"
|
||||
);
|
||||
|
||||
// TST: 4
|
||||
test_vector(
|
||||
"0d4a05b07352a5436e180356da0ae6efa0345ff7fb1572575772e8005ed978e9"
|
||||
, "e61a185bcef2613a6c7cb79763ce945d3b245d76114dd440bcf5f2dc1aa57057"
|
||||
, "d9868d52c2bebce5f3fa5a79891970f309cb6591e3e1702a70276fa97c24b3a8"
|
||||
"e58606c38c9758529da50ee31b8219cba45271c689afa60b0ea26c99db19b00c"
|
||||
, "cbc77b"
|
||||
);
|
||||
|
||||
// TST: 47
|
||||
test_vector(
|
||||
"89f0d68299ba0a5a83f248ae0c169f8e3849a9b47bd4549884305c9912b46603"
|
||||
, "aba3e795aab2012acceadd7b3bd9daeeed6ff5258bdcd7c93699c2a3836e3832"
|
||||
, "2c691fa8d487ce20d5d2fa41559116e0bbf4397cf5240e152556183541d66cf7"
|
||||
"53582401a4388d390339dbef4d384743caa346f55f8daba68ba7b9131a8a6e0b"
|
||||
, "4f1846dd7ad50e545d4cfbffbb1dc2ff145dc123754d08af4e44ecc0bc8c9141"
|
||||
"1388bc7653e2d893d1eac2107d05"
|
||||
);
|
||||
|
||||
// TST: 48
|
||||
test_vector(
|
||||
"0a3c1844e2db070fb24e3c95cb1cc6714ef84e2ccd2b9dd2f1460ebf7ecf13b1"
|
||||
, "72e409937e0610eb5c20b326dc6ea1bbbc0406701c5cd67d1fbde09192b07c01"
|
||||
, "87f7fdf46095201e877a588fe3e5aaf476bd63138d8a878b89d6ac60631b3458"
|
||||
"b9d41a3c61a588e1db8d29a5968981b018776c588780922f5aa732ba6379dd05"
|
||||
, "4c8274d0ed1f74e2c86c08d955bde55b2d54327e82062a1f71f70d536fdc8722"
|
||||
"cdead7d22aaead2bfaa1ad00b82957"
|
||||
);
|
||||
|
||||
// TST: 49
|
||||
test_vector(
|
||||
"c8d7a8818b98dfdb20839c871cb5c48e9e9470ca3ad35ba2613a5d3199c8ab23"
|
||||
, "90d2efbba4d43e6b2b992ca16083dbcfa2b322383907b0ee75f3e95845d3c47f"
|
||||
, "fa2e994421aef1d5856674813d05cbd2cf84ef5eb424af6ecd0dc6fdbdc2fe60"
|
||||
"5fe985883312ecf34f59bfb2f1c9149e5b9cc9ecda05b2731130f3ed28ddae0b"
|
||||
, "783e33c3acbdbb36e819f544a7781d83fc283d3309f5d3d12c8dcd6b0b3d0e89"
|
||||
"e38cfd3b4d0885661ca547fb9764abff"
|
||||
);
|
||||
|
||||
// TST: 50
|
||||
test_vector(
|
||||
"b482703612d0c586f76cfcb21cfd2103c957251504a8c0ac4c86c9c6f3e429ff"
|
||||
, "fd711dc7dd3b1dfb9df9704be3e6b26f587fe7dd7ba456a91ba43fe51aec09ad"
|
||||
, "58832bdeb26feafc31b46277cf3fb5d7a17dfb7ccd9b1f58ecbe6feb97966682"
|
||||
"8f239ba4d75219260ecac0acf40f0e5e2590f4caa16bbbcd8a155d347967a607"
|
||||
, "29d77acfd99c7a0070a88feb6247a2bce9984fe3e6fbf19d4045042a21ab26cb"
|
||||
"d771e184a9a75f316b648c6920db92b87b"
|
||||
);
|
||||
|
||||
// TST: 51
|
||||
test_vector(
|
||||
"84e50dd9a0f197e3893c38dbd91fafc344c1776d3a400e2f0f0ee7aa829eb8a2"
|
||||
, "2c50f870ee48b36b0ac2f8a5f336fb090b113050dbcc25e078200a6e16153eea"
|
||||
, "69e6a4491a63837316e86a5f4ba7cd0d731ecc58f1d0a264c67c89befdd8d382"
|
||||
"9d8de13b33cc0bf513931715c7809657e2bfb960e5c764c971d733746093e500"
|
||||
, "f3992cde6493e671f1e129ddca8038b0abdb77bb9035f9f8be54bd5d68c1aeff"
|
||||
"724ff47d29344391dc536166b8671cbbf123"
|
||||
);
|
||||
|
||||
// TST: 52
|
||||
test_vector(
|
||||
"b322d46577a2a991a4d1698287832a39c487ef776b4bff037a05c7f1812bdeec"
|
||||
, "eb2bcadfd3eec2986baff32b98e7c4dbf03ff95d8ad5ff9aa9506e5472ff845f"
|
||||
, "c7b55137317ca21e33489ff6a9bfab97c855dc6f85684a70a9125a261b56d5e6"
|
||||
"f149c5774d734f2d8debfc77b721896a8267c23768e9badb910eef83ec258802"
|
||||
, "19f1bf5dcf1750c611f1c4a2865200504d82298edd72671f62a7b1471ac3d4a3"
|
||||
"0f7de9e5da4108c52a4ce70a3e114a52a3b3c5"
|
||||
);
|
||||
|
||||
// TST: 53
|
||||
test_vector(
|
||||
"960cab5034b9838d098d2dcbf4364bec16d388f6376d73a6273b70f82bbc98c0"
|
||||
, "5e3c19f2415acf729f829a4ebd5c40e1a6bc9fbca95703a9376087ed0937e51a"
|
||||
, "27d4c3a1811ef9d4360b3bdd133c2ccc30d02c2f248215776cb07ee4177f9b13"
|
||||
"fc42dd70a6c2fed8f225c7663c7f182e7ee8eccff20dc7b0e1d5834ec5b1ea01"
|
||||
, "f8b21962447b0a8f2e4279de411bea128e0be44b6915e6cda88341a68a0d8183"
|
||||
"57db938eac73e0af6d31206b3948f8c48a447308"
|
||||
);
|
||||
|
||||
// TST: 224
|
||||
test_vector(
|
||||
"ae1d2c6b171be24c2e413d364dcda97fa476aaf9123d3366b0be03a142fe6e7d"
|
||||
, "d437f57542c681dd543487408ec7a44bd42a5fd545ce2f4c8297d67bb0b3aa7b"
|
||||
, "909008f3fcfff43988aee1314b15b1822caaa8dab120bd452af494e08335b44a"
|
||||
"94c313c4b145eadd5166eaac034e29b7e6ac7941d5961fc49d260e1c4820b00e"
|
||||
, "9e6c2fc76e30f17cd8b498845da44f22d55bec150c6130b411c6339d14b39969"
|
||||
"ab1033be687569a991a06f70b2a8a6931a777b0e4be6723cd75e5aa7532813ef"
|
||||
"50b3d37271640fa2fb287c0355257641ea935c851c0b6ac68be72c88dfc5856f"
|
||||
"b53543fb377b0dbf64808afcc4274aa456855ad28f61267a419bc72166b9ca73"
|
||||
"cd3bb79bf7dd259baa75911440974b68e8ba95a78cbbe1cb6ad807a33a1cce2f"
|
||||
"406ff7bcbd058b44a311b38ab4d4e61416c4a74d883d6a6a794abd9cf1c03902"
|
||||
"8bf1b20e3d4990aae86f32bf06cd8349a7a884cce0165e36a0640e987b9d51"
|
||||
);
|
||||
|
||||
// TST: 225
|
||||
test_vector(
|
||||
"0265a7944baccfebf417b87ae1e6df2ff2a544ffb58225a08e092be03f026097"
|
||||
, "63d327615ea0139be0740b618aff1acfa818d4b0c2cfeaf0da93cdd5245fb5a9"
|
||||
, "b6c445b7eddca5935c61708d44ea5906bd19cc54224eae3c8e46ce99f5cbbd34"
|
||||
"1f26623938f5fe04070b1b02e71fbb7c78a90c0dda66cb143fab02e6a0bae306"
|
||||
, "874ed712a2c41c26a2d9527c55233fde0a4ffb86af8e8a1dd0a820502c5a2693"
|
||||
"2bf87ee0de72a8874ef2eebf83384d443f7a5f46a1233b4fb514a24699818248"
|
||||
"94f325bf86aa0fe1217153d40f3556c43a8ea9269444e149fb70e9415ae0766c"
|
||||
"565d93d1d6368f9a23a0ad76f9a09dbf79634aa97178677734d04ef1a5b3f87c"
|
||||
"e1ee9fc5a9ac4e7a72c9d7d31ec89e28a845d2e1103c15d6410ce3c723b0cc22"
|
||||
"09f698aa9fa288bbbecfd9e5f89cdcb09d3c215feb47a58b71ea70e2abead67f"
|
||||
"1b08ea6f561fb93ef05232eedabfc1c7702ab039bc465cf57e207f1093fc8208"
|
||||
);
|
||||
}
|
||||
|
||||
TORRENT_TEST(create_seed)
|
||||
{
|
||||
typedef unsigned char uchar;
|
||||
uchar s1[32];
|
||||
ed25519_create_seed(s1);
|
||||
uchar s2[32];
|
||||
ed25519_create_seed(s2);
|
||||
|
||||
TEST_CHECK(memcpy(s1, s2, sizeof(s1)) != 0); // what are the odds
|
||||
|
||||
int n1 = 0;
|
||||
int n2 = 0;
|
||||
for (int i = 0; i < 32; i++)
|
||||
{
|
||||
if (s1[i] != 0) n1++;
|
||||
if (s2[i] != 0) n2++;
|
||||
}
|
||||
TEST_CHECK(n1 > 0);
|
||||
TEST_CHECK(n2 > 0);
|
||||
}
|
||||
|
||||
#else
|
||||
TORRENT_TEST(empty)
|
||||
{
|
||||
TEST_CHECK(true);
|
||||
}
|
||||
#endif // TORRENT_DISABLE_DHT
|
Loading…
Reference in New Issue