rbnacl-libsodium 1.0.8 → 1.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +23 -0
- data/CHANGES.md +5 -0
- data/Gemfile +5 -2
- data/Rakefile +5 -0
- data/ext/rbnacl/extconf.rb +2 -1
- data/lib/rbnacl/libsodium.rb +8 -2
- data/lib/rbnacl/libsodium/version.rb +1 -1
- data/vendor/libsodium/AUTHORS +14 -0
- data/vendor/libsodium/ChangeLog +26 -0
- data/vendor/libsodium/LICENSE +1 -1
- data/vendor/libsodium/Makefile.am +1 -0
- data/vendor/libsodium/Makefile.in +9 -0
- data/vendor/libsodium/README.markdown +7 -0
- data/vendor/libsodium/aclocal.m4 +1 -0
- data/vendor/libsodium/appveyor.yml +25 -0
- data/vendor/libsodium/autom4te.cache/output.1 +640 -126
- data/vendor/libsodium/autom4te.cache/output.6 +19049 -0
- data/vendor/libsodium/autom4te.cache/requests +1151 -914
- data/vendor/libsodium/autom4te.cache/traces.1 +472 -426
- data/vendor/libsodium/autom4te.cache/traces.6 +3193 -0
- data/vendor/libsodium/builds/msvc/version.h +2 -2
- data/vendor/libsodium/builds/msvc/vs2010/libsodium.sln +50 -79
- data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.vcxproj +20 -8
- data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.vcxproj.filters +208 -166
- data/vendor/libsodium/builds/msvc/vs2012/libsodium.sln +50 -79
- data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.vcxproj +20 -8
- data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.vcxproj.filters +206 -164
- data/vendor/libsodium/builds/msvc/vs2013/libsodium.sln +52 -81
- data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.vcxproj +20 -8
- data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.vcxproj.filters +206 -164
- data/vendor/libsodium/builds/msvc/vs2015/libsodium.sln +52 -81
- data/vendor/libsodium/builds/msvc/vs2015/libsodium/libsodium.vcxproj +20 -8
- data/vendor/libsodium/builds/msvc/vs2015/libsodium/libsodium.vcxproj.filters +206 -164
- data/vendor/libsodium/configure +639 -125
- data/vendor/libsodium/configure.ac +94 -16
- data/vendor/libsodium/dist-build/Makefile.in +9 -0
- data/vendor/libsodium/dist-build/emscripten-symbols.def +370 -0
- data/vendor/libsodium/dist-build/emscripten.sh +9 -3
- data/vendor/libsodium/dist-build/generate-emscripten-symbols.sh +43 -0
- data/vendor/libsodium/libsodium-uninstalled.pc.in +1 -1
- data/vendor/libsodium/libsodium.pc.in +1 -1
- data/vendor/libsodium/libsodium.vcxproj +70 -66
- data/vendor/libsodium/libsodium.vcxproj.filters +204 -192
- data/vendor/libsodium/m4/ax_valgrind_check.m4 +190 -0
- data/vendor/libsodium/msvc-scripts/Makefile.in +9 -0
- data/vendor/libsodium/msvc-scripts/process.bat +2 -2
- data/vendor/libsodium/src/Makefile.in +9 -0
- data/vendor/libsodium/src/libsodium/Makefile.am +31 -6
- data/vendor/libsodium/src/libsodium/Makefile.in +238 -42
- data/vendor/libsodium/src/libsodium/crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c +234 -38
- data/vendor/libsodium/src/libsodium/crypto_aead/chacha20poly1305/sodium/aead_chacha20poly1305.c +208 -118
- data/vendor/libsodium/src/libsodium/crypto_box/crypto_box_seal.c +2 -2
- data/vendor/libsodium/src/libsodium/crypto_box/curve25519xsalsa20poly1305/ref/before_curve25519xsalsa20poly1305.c +1 -4
- data/vendor/libsodium/src/libsodium/crypto_core/curve25519/ref10/curve25519_ref10.c +1799 -1790
- data/vendor/libsodium/src/libsodium/crypto_core/curve25519/ref10/curve25519_ref10.h +39 -39
- data/vendor/libsodium/src/libsodium/crypto_core/hchacha20/core_hchacha20.c +86 -0
- data/vendor/libsodium/src/libsodium/crypto_core/hchacha20/core_hchacha20.h +28 -0
- data/vendor/libsodium/src/libsodium/crypto_core/hsalsa20/ref2/core_hsalsa20.c +38 -46
- data/vendor/libsodium/src/libsodium/crypto_core/salsa20/ref/core_salsa20.c +47 -55
- data/vendor/libsodium/src/libsodium/crypto_core/salsa2012/ref/core_salsa2012.c +47 -55
- data/vendor/libsodium/src/libsodium/crypto_core/salsa208/ref/core_salsa208.c +47 -55
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/generichash_blake2_api.c +7 -0
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2-impl.h +0 -89
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2.h +50 -141
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-compress-avx2.c +45 -0
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-compress-avx2.h +123 -0
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-compress-ref.c +3 -2
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-compress-sse41.c +2 -2
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/{blake2b-round.h → blake2b-compress-sse41.h} +2 -28
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-compress-ssse3.c +2 -4
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-compress-ssse3.h +97 -0
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-load-avx2.h +339 -0
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-load-sse2.h +0 -2
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-load-sse41.h +0 -2
- data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-ref.c +29 -18
- data/vendor/libsodium/src/libsodium/crypto_hash/sha256/cp/hash_sha256.c +4 -43
- data/vendor/libsodium/src/libsodium/crypto_hash/sha512/cp/hash_sha512.c +3 -32
- data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna.h +1 -20
- data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna32.h +22 -41
- data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna64.h +12 -39
- data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/sse2/poly1305_sse2.c +2 -4
- data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/sse2/poly1305_sse2.h +1 -20
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-core.c +570 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-core.h +198 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-encoding.c +444 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-encoding.h +32 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-fill-block-ref.c +229 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-fill-block-ssse3.c +222 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-impl.h +40 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2.c +238 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2.h +251 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/blake2b-long.c +80 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/blake2b-long.h +8 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/blamka-round-ref.h +38 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/blamka-round-ssse3.h +117 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/pwhash_argon2i.c +164 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/crypto_pwhash.c +106 -0
- data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/crypto_scrypt-common.c +1 -1
- data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/crypto_scrypt.h +4 -4
- data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/nosse/pwhash_scryptsalsa208sha256_nosse.c +186 -186
- data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pbkdf2-sha256.c +2 -2
- data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c +3 -2
- data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/scrypt_platform.c +33 -33
- data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c +253 -254
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/donna_c64/curve25519_donna_c64.c +16 -17
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/donna_c64/curve25519_donna_c64.h +1 -0
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/x25519_ref10.c +11 -11
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/x25519_ref10.h +1 -0
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/consts_namespace.h +1 -1
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe.h +3 -2
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51.h +5 -3
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51_invert.c +41 -41
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51_mul.S +10 -2
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51_namespace.h +1 -1
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51_nsquare.S +4 -0
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe51_pack.S +4 -0
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/fe_frombytes_sandy2x.c +31 -32
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/ladder.S +4 -0
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/ladder.h +1 -1
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/ladder_base.S +4 -0
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/ladder_base.h +1 -1
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/ladder_base_namespace.h +1 -1
- data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/sandy2x/ladder_namespace.h +1 -1
- data/vendor/libsodium/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c +2 -6
- data/vendor/libsodium/src/libsodium/crypto_shorthash/siphash24/ref/shorthash_siphash24.c +8 -28
- data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/open.c +75 -0
- data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/afternm_aes128ctr.c +6 -6
- data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/common.h +1 -18
- data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/int128_aes128ctr.c +20 -20
- data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/types.h +4 -4
- data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/xor_afternm_aes128ctr.c +6 -6
- data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/ref/stream_chacha20_ref.c +56 -77
- data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/ref/stream_chacha20_ref.h +1 -0
- data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/vec/stream_chacha20_vec.h +1 -0
- data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/ref/stream_salsa20_ref.c +2 -8
- data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/ref/xor_salsa20_ref.c +2 -8
- data/vendor/libsodium/src/libsodium/crypto_stream/salsa2012/ref/stream_salsa2012.c +2 -8
- data/vendor/libsodium/src/libsodium/crypto_stream/salsa2012/ref/xor_salsa2012.c +2 -8
- data/vendor/libsodium/src/libsodium/crypto_stream/salsa208/ref/stream_salsa208.c +2 -8
- data/vendor/libsodium/src/libsodium/crypto_stream/salsa208/ref/xor_salsa208.c +2 -8
- data/vendor/libsodium/src/libsodium/crypto_stream/xsalsa20/ref/stream_xsalsa20.c +1 -5
- data/vendor/libsodium/src/libsodium/crypto_stream/xsalsa20/ref/xor_xsalsa20.c +1 -5
- data/vendor/libsodium/src/libsodium/include/Makefile.am +3 -0
- data/vendor/libsodium/src/libsodium/include/Makefile.in +19 -8
- data/vendor/libsodium/src/libsodium/include/sodium.h +3 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_aead_aes256gcm.h +50 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_aead_chacha20poly1305.h +94 -22
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_box_curve25519xsalsa20poly1305.h +6 -6
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_core_hchacha20.h +35 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_generichash_blake2b.h +3 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_pwhash.h +89 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_pwhash_argon2i.h +86 -0
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_secretbox_xsalsa20poly1305.h +6 -6
- data/vendor/libsodium/src/libsodium/include/sodium/crypto_sign_edwards25519sha512batch.h +0 -11
- data/vendor/libsodium/src/libsodium/include/sodium/runtime.h +3 -0
- data/vendor/libsodium/src/libsodium/randombytes/randombytes.c +3 -0
- data/vendor/libsodium/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c +5 -1
- data/vendor/libsodium/src/libsodium/sodium/common.h +150 -0
- data/vendor/libsodium/src/libsodium/sodium/core.c +3 -1
- data/vendor/libsodium/src/libsodium/sodium/runtime.c +37 -19
- data/vendor/libsodium/src/libsodium/sodium/utils.c +18 -9
- data/vendor/libsodium/test/Makefile.in +9 -0
- data/vendor/libsodium/test/default/Makefile.am +10 -0
- data/vendor/libsodium/test/default/Makefile.in +53 -20
- data/vendor/libsodium/test/default/aead_aes256gcm.c +43 -17
- data/vendor/libsodium/test/default/aead_chacha20poly1305.c +179 -86
- data/vendor/libsodium/test/default/auth7.c +5 -5
- data/vendor/libsodium/test/default/box.c +4 -4
- data/vendor/libsodium/test/default/box2.c +1 -1
- data/vendor/libsodium/test/default/core6.c +1 -1
- data/vendor/libsodium/test/default/generichash.c +12 -1
- data/vendor/libsodium/test/default/generichash2.c +2 -2
- data/vendor/libsodium/test/default/generichash3.c +21 -0
- data/vendor/libsodium/test/default/pwhash.c +186 -168
- data/vendor/libsodium/test/default/pwhash.exp +11 -30
- data/vendor/libsodium/test/default/pwhash_scrypt.c +349 -0
- data/vendor/libsodium/test/default/pwhash_scrypt.exp +31 -0
- data/vendor/libsodium/test/default/secretbox.c +1 -1
- data/vendor/libsodium/test/default/secretbox2.c +1 -1
- data/vendor/libsodium/test/default/sign.c +15 -0
- data/vendor/libsodium/test/default/sodium_utils2.c +8 -3
- data/vendor/libsodium/test/default/sodium_utils3.c +4 -2
- data/vendor/libsodium/test/default/verify1.c +0 -4
- data/vendor/libsodium/test/quirks/quirks.h +3 -0
- metadata +37 -22
- data/vendor/libsodium/builds/msvc/vs2010/test/test.props +0 -43
- data/vendor/libsodium/builds/msvc/vs2010/test/test.runner.bat +0 -78
- data/vendor/libsodium/builds/msvc/vs2010/test/test.vcxproj +0 -244
- data/vendor/libsodium/builds/msvc/vs2010/test/test.vcxproj.filters +0 -192
- data/vendor/libsodium/builds/msvc/vs2012/test/test.props +0 -43
- data/vendor/libsodium/builds/msvc/vs2012/test/test.runner.bat +0 -78
- data/vendor/libsodium/builds/msvc/vs2012/test/test.vcxproj +0 -244
- data/vendor/libsodium/builds/msvc/vs2012/test/test.vcxproj.filters +0 -192
- data/vendor/libsodium/builds/msvc/vs2013/test/test.props +0 -43
- data/vendor/libsodium/builds/msvc/vs2013/test/test.runner.bat +0 -78
- data/vendor/libsodium/builds/msvc/vs2013/test/test.vcxproj +0 -244
- data/vendor/libsodium/builds/msvc/vs2013/test/test.vcxproj.filters +0 -192
- data/vendor/libsodium/builds/msvc/vs2015/test/test.props +0 -43
- data/vendor/libsodium/builds/msvc/vs2015/test/test.runner.bat +0 -78
- data/vendor/libsodium/builds/msvc/vs2015/test/test.vcxproj +0 -244
- data/vendor/libsodium/builds/msvc/vs2015/test/test.vcxproj.filters +0 -192
- data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/sysendian.h +0 -146
- data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/common_aes128ctr.c +0 -64
@@ -35,9 +35,9 @@ crypto_box_seal(unsigned char *c, const unsigned char *m,
|
|
35
35
|
_crypto_box_seal_nonce(nonce, epk, pk);
|
36
36
|
ret = crypto_box_easy(c + crypto_box_PUBLICKEYBYTES, m, mlen,
|
37
37
|
nonce, pk, esk);
|
38
|
-
sodium_memzero(nonce, sizeof nonce);
|
39
|
-
sodium_memzero(epk, sizeof epk);
|
40
38
|
sodium_memzero(esk, sizeof esk);
|
39
|
+
sodium_memzero(epk, sizeof epk);
|
40
|
+
sodium_memzero(nonce, sizeof nonce);
|
41
41
|
|
42
42
|
return ret;
|
43
43
|
}
|
@@ -2,9 +2,6 @@
|
|
2
2
|
#include "crypto_core_hsalsa20.h"
|
3
3
|
#include "crypto_scalarmult_curve25519.h"
|
4
4
|
|
5
|
-
static const unsigned char sigma[16] = {
|
6
|
-
'e', 'x', 'p', 'a', 'n', 'd', ' ', '3', '2', '-', 'b', 'y', 't', 'e', ' ', 'k'
|
7
|
-
};
|
8
5
|
static const unsigned char n[16] = {0};
|
9
6
|
|
10
7
|
int crypto_box_curve25519xsalsa20poly1305_beforenm(
|
@@ -17,5 +14,5 @@ int crypto_box_curve25519xsalsa20poly1305_beforenm(
|
|
17
14
|
if (crypto_scalarmult_curve25519(s,sk,pk) != 0) {
|
18
15
|
return -1;
|
19
16
|
}
|
20
|
-
return crypto_core_hsalsa20(k,n,s,
|
17
|
+
return crypto_core_hsalsa20(k,n,s,NULL);
|
21
18
|
}
|
@@ -6,988 +6,992 @@
|
|
6
6
|
|
7
7
|
static uint64_t load_3(const unsigned char *in)
|
8
8
|
{
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
uint64_t result;
|
10
|
+
result = (uint64_t) in[0];
|
11
|
+
result |= ((uint64_t) in[1]) << 8;
|
12
|
+
result |= ((uint64_t) in[2]) << 16;
|
13
|
+
|
14
|
+
return result;
|
14
15
|
}
|
15
16
|
|
16
17
|
static uint64_t load_4(const unsigned char *in)
|
17
18
|
{
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
uint64_t result;
|
20
|
+
result = (uint64_t) in[0];
|
21
|
+
result |= ((uint64_t) in[1]) << 8;
|
22
|
+
result |= ((uint64_t) in[2]) << 16;
|
23
|
+
result |= ((uint64_t) in[3]) << 24;
|
24
|
+
|
25
|
+
return result;
|
24
26
|
}
|
25
27
|
|
26
28
|
/*
|
27
|
-
h = 0
|
28
|
-
*/
|
29
|
+
h = 0
|
30
|
+
*/
|
29
31
|
|
30
32
|
void fe_0(fe h)
|
31
33
|
{
|
32
|
-
|
34
|
+
memset(&h[0], 0, 10 * sizeof h[0]);
|
33
35
|
}
|
34
36
|
|
35
37
|
/*
|
36
|
-
h = 1
|
37
|
-
*/
|
38
|
+
h = 1
|
39
|
+
*/
|
38
40
|
|
39
41
|
void fe_1(fe h)
|
40
42
|
{
|
41
|
-
|
42
|
-
|
43
|
-
|
43
|
+
h[0] = 1;
|
44
|
+
h[1] = 0;
|
45
|
+
memset(&h[2], 0, 8 * sizeof h[0]);
|
44
46
|
}
|
45
47
|
|
46
48
|
/*
|
47
|
-
h = f + g
|
48
|
-
Can overlap h with f or g.
|
49
|
-
|
50
|
-
Preconditions:
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
Postconditions:
|
55
|
-
|
56
|
-
*/
|
49
|
+
h = f + g
|
50
|
+
Can overlap h with f or g.
|
51
|
+
*
|
52
|
+
Preconditions:
|
53
|
+
|f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
|
54
|
+
|g| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
|
55
|
+
*
|
56
|
+
Postconditions:
|
57
|
+
|h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
|
58
|
+
*/
|
57
59
|
|
58
60
|
void fe_add(fe h,const fe f,const fe g)
|
59
61
|
{
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
62
|
+
int32_t f0 = f[0];
|
63
|
+
int32_t f1 = f[1];
|
64
|
+
int32_t f2 = f[2];
|
65
|
+
int32_t f3 = f[3];
|
66
|
+
int32_t f4 = f[4];
|
67
|
+
int32_t f5 = f[5];
|
68
|
+
int32_t f6 = f[6];
|
69
|
+
int32_t f7 = f[7];
|
70
|
+
int32_t f8 = f[8];
|
71
|
+
int32_t f9 = f[9];
|
72
|
+
int32_t g0 = g[0];
|
73
|
+
int32_t g1 = g[1];
|
74
|
+
int32_t g2 = g[2];
|
75
|
+
int32_t g3 = g[3];
|
76
|
+
int32_t g4 = g[4];
|
77
|
+
int32_t g5 = g[5];
|
78
|
+
int32_t g6 = g[6];
|
79
|
+
int32_t g7 = g[7];
|
80
|
+
int32_t g8 = g[8];
|
81
|
+
int32_t g9 = g[9];
|
82
|
+
int32_t h0 = f0 + g0;
|
83
|
+
int32_t h1 = f1 + g1;
|
84
|
+
int32_t h2 = f2 + g2;
|
85
|
+
int32_t h3 = f3 + g3;
|
86
|
+
int32_t h4 = f4 + g4;
|
87
|
+
int32_t h5 = f5 + g5;
|
88
|
+
int32_t h6 = f6 + g6;
|
89
|
+
int32_t h7 = f7 + g7;
|
90
|
+
int32_t h8 = f8 + g8;
|
91
|
+
int32_t h9 = f9 + g9;
|
92
|
+
h[0] = h0;
|
93
|
+
h[1] = h1;
|
94
|
+
h[2] = h2;
|
95
|
+
h[3] = h3;
|
96
|
+
h[4] = h4;
|
97
|
+
h[5] = h5;
|
98
|
+
h[6] = h6;
|
99
|
+
h[7] = h7;
|
100
|
+
h[8] = h8;
|
101
|
+
h[9] = h9;
|
100
102
|
}
|
101
103
|
|
102
104
|
/*
|
103
|
-
Replace (f,g) with (g,g) if b == 1;
|
104
|
-
replace (f,g) with (f,g) if b == 0.
|
105
|
-
|
106
|
-
Preconditions: b in {0,1}.
|
107
|
-
*/
|
105
|
+
Replace (f,g) with (g,g) if b == 1;
|
106
|
+
replace (f,g) with (f,g) if b == 0.
|
107
|
+
*
|
108
|
+
Preconditions: b in {0,1}.
|
109
|
+
*/
|
108
110
|
|
109
111
|
void fe_cmov(fe f,const fe g,unsigned int b)
|
110
112
|
{
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
113
|
+
int32_t f0 = f[0];
|
114
|
+
int32_t f1 = f[1];
|
115
|
+
int32_t f2 = f[2];
|
116
|
+
int32_t f3 = f[3];
|
117
|
+
int32_t f4 = f[4];
|
118
|
+
int32_t f5 = f[5];
|
119
|
+
int32_t f6 = f[6];
|
120
|
+
int32_t f7 = f[7];
|
121
|
+
int32_t f8 = f[8];
|
122
|
+
int32_t f9 = f[9];
|
123
|
+
int32_t g0 = g[0];
|
124
|
+
int32_t g1 = g[1];
|
125
|
+
int32_t g2 = g[2];
|
126
|
+
int32_t g3 = g[3];
|
127
|
+
int32_t g4 = g[4];
|
128
|
+
int32_t g5 = g[5];
|
129
|
+
int32_t g6 = g[6];
|
130
|
+
int32_t g7 = g[7];
|
131
|
+
int32_t g8 = g[8];
|
132
|
+
int32_t g9 = g[9];
|
133
|
+
int32_t x0 = f0 ^ g0;
|
134
|
+
int32_t x1 = f1 ^ g1;
|
135
|
+
int32_t x2 = f2 ^ g2;
|
136
|
+
int32_t x3 = f3 ^ g3;
|
137
|
+
int32_t x4 = f4 ^ g4;
|
138
|
+
int32_t x5 = f5 ^ g5;
|
139
|
+
int32_t x6 = f6 ^ g6;
|
140
|
+
int32_t x7 = f7 ^ g7;
|
141
|
+
int32_t x8 = f8 ^ g8;
|
142
|
+
int32_t x9 = f9 ^ g9;
|
143
|
+
b = (unsigned int) (- (int) b);
|
144
|
+
x0 &= b;
|
145
|
+
x1 &= b;
|
146
|
+
x2 &= b;
|
147
|
+
x3 &= b;
|
148
|
+
x4 &= b;
|
149
|
+
x5 &= b;
|
150
|
+
x6 &= b;
|
151
|
+
x7 &= b;
|
152
|
+
x8 &= b;
|
153
|
+
x9 &= b;
|
154
|
+
f[0] = f0 ^ x0;
|
155
|
+
f[1] = f1 ^ x1;
|
156
|
+
f[2] = f2 ^ x2;
|
157
|
+
f[3] = f3 ^ x3;
|
158
|
+
f[4] = f4 ^ x4;
|
159
|
+
f[5] = f5 ^ x5;
|
160
|
+
f[6] = f6 ^ x6;
|
161
|
+
f[7] = f7 ^ x7;
|
162
|
+
f[8] = f8 ^ x8;
|
163
|
+
f[9] = f9 ^ x9;
|
162
164
|
}
|
163
165
|
|
164
166
|
/*
|
165
|
-
h = f
|
166
|
-
*/
|
167
|
+
h = f
|
168
|
+
*/
|
167
169
|
|
168
170
|
void fe_copy(fe h,const fe f)
|
169
171
|
{
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
172
|
+
int32_t f0 = f[0];
|
173
|
+
int32_t f1 = f[1];
|
174
|
+
int32_t f2 = f[2];
|
175
|
+
int32_t f3 = f[3];
|
176
|
+
int32_t f4 = f[4];
|
177
|
+
int32_t f5 = f[5];
|
178
|
+
int32_t f6 = f[6];
|
179
|
+
int32_t f7 = f[7];
|
180
|
+
int32_t f8 = f[8];
|
181
|
+
int32_t f9 = f[9];
|
182
|
+
h[0] = f0;
|
183
|
+
h[1] = f1;
|
184
|
+
h[2] = f2;
|
185
|
+
h[3] = f3;
|
186
|
+
h[4] = f4;
|
187
|
+
h[5] = f5;
|
188
|
+
h[6] = f6;
|
189
|
+
h[7] = f7;
|
190
|
+
h[8] = f8;
|
191
|
+
h[9] = f9;
|
190
192
|
}
|
191
193
|
|
192
194
|
/*
|
193
|
-
Ignores top bit of h.
|
194
|
-
*/
|
195
|
+
Ignores top bit of h.
|
196
|
+
*/
|
195
197
|
|
196
198
|
void fe_frombytes(fe h,const unsigned char *s)
|
197
199
|
{
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
200
|
+
int64_t h0 = load_4(s);
|
201
|
+
int64_t h1 = load_3(s + 4) << 6;
|
202
|
+
int64_t h2 = load_3(s + 7) << 5;
|
203
|
+
int64_t h3 = load_3(s + 10) << 3;
|
204
|
+
int64_t h4 = load_3(s + 13) << 2;
|
205
|
+
int64_t h5 = load_4(s + 16);
|
206
|
+
int64_t h6 = load_3(s + 20) << 7;
|
207
|
+
int64_t h7 = load_3(s + 23) << 5;
|
208
|
+
int64_t h8 = load_3(s + 26) << 4;
|
209
|
+
int64_t h9 = (load_3(s + 29) & 8388607) << 2;
|
210
|
+
int64_t carry0;
|
211
|
+
int64_t carry1;
|
212
|
+
int64_t carry2;
|
213
|
+
int64_t carry3;
|
214
|
+
int64_t carry4;
|
215
|
+
int64_t carry5;
|
216
|
+
int64_t carry6;
|
217
|
+
int64_t carry7;
|
218
|
+
int64_t carry8;
|
219
|
+
int64_t carry9;
|
220
|
+
|
221
|
+
carry9 = (h9 + (int64_t) (1L << 24)) >> 25; h0 += carry9 * 19; h9 -= carry9 * ((uint64_t) 1L << 25);
|
222
|
+
carry1 = (h1 + (int64_t) (1L << 24)) >> 25; h2 += carry1; h1 -= carry1 * ((uint64_t) 1L << 25);
|
223
|
+
carry3 = (h3 + (int64_t) (1L << 24)) >> 25; h4 += carry3; h3 -= carry3 * ((uint64_t) 1L << 25);
|
224
|
+
carry5 = (h5 + (int64_t) (1L << 24)) >> 25; h6 += carry5; h5 -= carry5 * ((uint64_t) 1L << 25);
|
225
|
+
carry7 = (h7 + (int64_t) (1L << 24)) >> 25; h8 += carry7; h7 -= carry7 * ((uint64_t) 1L << 25);
|
226
|
+
|
227
|
+
carry0 = (h0 + (int64_t) (1L << 25)) >> 26; h1 += carry0; h0 -= carry0 * ((uint64_t) 1L << 26);
|
228
|
+
carry2 = (h2 + (int64_t) (1L << 25)) >> 26; h3 += carry2; h2 -= carry2 * ((uint64_t) 1L << 26);
|
229
|
+
carry4 = (h4 + (int64_t) (1L << 25)) >> 26; h5 += carry4; h4 -= carry4 * ((uint64_t) 1L << 26);
|
230
|
+
carry6 = (h6 + (int64_t) (1L << 25)) >> 26; h7 += carry6; h6 -= carry6 * ((uint64_t) 1L << 26);
|
231
|
+
carry8 = (h8 + (int64_t) (1L << 25)) >> 26; h9 += carry8; h8 -= carry8 * ((uint64_t) 1L << 26);
|
232
|
+
|
233
|
+
h[0] = (int32_t) h0;
|
234
|
+
h[1] = (int32_t) h1;
|
235
|
+
h[2] = (int32_t) h2;
|
236
|
+
h[3] = (int32_t) h3;
|
237
|
+
h[4] = (int32_t) h4;
|
238
|
+
h[5] = (int32_t) h5;
|
239
|
+
h[6] = (int32_t) h6;
|
240
|
+
h[7] = (int32_t) h7;
|
241
|
+
h[8] = (int32_t) h8;
|
242
|
+
h[9] = (int32_t) h9;
|
241
243
|
}
|
242
244
|
|
243
245
|
/*
|
244
|
-
Preconditions:
|
245
|
-
|
246
|
-
|
247
|
-
Write p=2^255-19; q=floor(h/p).
|
248
|
-
Basic claim: q = floor(2^(-255)(h + 19 2^(-25)h9 + 2^(-1))).
|
249
|
-
|
250
|
-
Proof:
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
*/
|
246
|
+
Preconditions:
|
247
|
+
|h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
|
248
|
+
*
|
249
|
+
Write p=2^255-19; q=floor(h/p).
|
250
|
+
Basic claim: q = floor(2^(-255)(h + 19 2^(-25)h9 + 2^(-1))).
|
251
|
+
*
|
252
|
+
Proof:
|
253
|
+
Have |h|<=p so |q|<=1 so |19^2 2^(-255) q|<1/4.
|
254
|
+
Also have |h-2^230 h9|<2^231 so |19 2^(-255)(h-2^230 h9)|<1/4.
|
255
|
+
*
|
256
|
+
Write y=2^(-1)-19^2 2^(-255)q-19 2^(-255)(h-2^230 h9).
|
257
|
+
Then 0<y<1.
|
258
|
+
*
|
259
|
+
Write r=h-pq.
|
260
|
+
Have 0<=r<=p-1=2^255-20.
|
261
|
+
Thus 0<=r+19(2^-255)r<r+19(2^-255)2^255<=2^255-1.
|
262
|
+
*
|
263
|
+
Write x=r+19(2^-255)r+y.
|
264
|
+
Then 0<x<2^255 so floor(2^(-255)x) = 0 so floor(q+2^(-255)x) = q.
|
265
|
+
*
|
266
|
+
Have q+2^(-255)x = 2^(-255)(h + 19 2^(-25) h9 + 2^(-1))
|
267
|
+
so floor(2^(-255)(h + 19 2^(-25) h9 + 2^(-1))) = q.
|
268
|
+
*/
|
267
269
|
|
268
270
|
void fe_tobytes(unsigned char *s,const fe h)
|
269
271
|
{
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
272
|
+
int32_t h0 = h[0];
|
273
|
+
int32_t h1 = h[1];
|
274
|
+
int32_t h2 = h[2];
|
275
|
+
int32_t h3 = h[3];
|
276
|
+
int32_t h4 = h[4];
|
277
|
+
int32_t h5 = h[5];
|
278
|
+
int32_t h6 = h[6];
|
279
|
+
int32_t h7 = h[7];
|
280
|
+
int32_t h8 = h[8];
|
281
|
+
int32_t h9 = h[9];
|
282
|
+
int32_t q;
|
283
|
+
int32_t carry0;
|
284
|
+
int32_t carry1;
|
285
|
+
int32_t carry2;
|
286
|
+
int32_t carry3;
|
287
|
+
int32_t carry4;
|
288
|
+
int32_t carry5;
|
289
|
+
int32_t carry6;
|
290
|
+
int32_t carry7;
|
291
|
+
int32_t carry8;
|
292
|
+
int32_t carry9;
|
293
|
+
|
294
|
+
q = (19 * h9 + ((uint32_t) 1L << 24)) >> 25;
|
295
|
+
q = (h0 + q) >> 26;
|
296
|
+
q = (h1 + q) >> 25;
|
297
|
+
q = (h2 + q) >> 26;
|
298
|
+
q = (h3 + q) >> 25;
|
299
|
+
q = (h4 + q) >> 26;
|
300
|
+
q = (h5 + q) >> 25;
|
301
|
+
q = (h6 + q) >> 26;
|
302
|
+
q = (h7 + q) >> 25;
|
303
|
+
q = (h8 + q) >> 26;
|
304
|
+
q = (h9 + q) >> 25;
|
305
|
+
|
306
|
+
/* Goal: Output h-(2^255-19)q, which is between 0 and 2^255-20. */
|
307
|
+
h0 += 19 * q;
|
308
|
+
/* Goal: Output h-2^255 q, which is between 0 and 2^255-20. */
|
309
|
+
|
310
|
+
carry0 = h0 >> 26; h1 += carry0; h0 -= carry0 * ((uint32_t) 1L << 26);
|
311
|
+
carry1 = h1 >> 25; h2 += carry1; h1 -= carry1 * ((uint32_t) 1L << 25);
|
312
|
+
carry2 = h2 >> 26; h3 += carry2; h2 -= carry2 * ((uint32_t) 1L << 26);
|
313
|
+
carry3 = h3 >> 25; h4 += carry3; h3 -= carry3 * ((uint32_t) 1L << 25);
|
314
|
+
carry4 = h4 >> 26; h5 += carry4; h4 -= carry4 * ((uint32_t) 1L << 26);
|
315
|
+
carry5 = h5 >> 25; h6 += carry5; h5 -= carry5 * ((uint32_t) 1L << 25);
|
316
|
+
carry6 = h6 >> 26; h7 += carry6; h6 -= carry6 * ((uint32_t) 1L << 26);
|
317
|
+
carry7 = h7 >> 25; h8 += carry7; h7 -= carry7 * ((uint32_t) 1L << 25);
|
318
|
+
carry8 = h8 >> 26; h9 += carry8; h8 -= carry8 * ((uint32_t) 1L << 26);
|
319
|
+
carry9 = h9 >> 25; h9 -= carry9 * ((uint32_t) 1L << 25);
|
320
|
+
/* h10 = carry9 */
|
321
|
+
|
322
|
+
/*
|
323
|
+
Goal: Output h0+...+2^255 h10-2^255 q, which is between 0 and 2^255-20.
|
324
|
+
Have h0+...+2^230 h9 between 0 and 2^255-1;
|
325
|
+
evidently 2^255 h10-2^255 q = 0.
|
326
|
+
Goal: Output h0+...+2^230 h9.
|
327
|
+
*/
|
328
|
+
|
329
|
+
s[0] = h0 >> 0;
|
330
|
+
s[1] = h0 >> 8;
|
331
|
+
s[2] = h0 >> 16;
|
332
|
+
s[3] = (h0 >> 24) | (h1 * ((uint32_t) 1 << 2));
|
333
|
+
s[4] = h1 >> 6;
|
334
|
+
s[5] = h1 >> 14;
|
335
|
+
s[6] = (h1 >> 22) | (h2 * ((uint32_t) 1 << 3));
|
336
|
+
s[7] = h2 >> 5;
|
337
|
+
s[8] = h2 >> 13;
|
338
|
+
s[9] = (h2 >> 21) | (h3 * ((uint32_t) 1 << 5));
|
339
|
+
s[10] = h3 >> 3;
|
340
|
+
s[11] = h3 >> 11;
|
341
|
+
s[12] = (h3 >> 19) | (h4 * ((uint32_t) 1 << 6));
|
342
|
+
s[13] = h4 >> 2;
|
343
|
+
s[14] = h4 >> 10;
|
344
|
+
s[15] = h4 >> 18;
|
345
|
+
s[16] = h5 >> 0;
|
346
|
+
s[17] = h5 >> 8;
|
347
|
+
s[18] = h5 >> 16;
|
348
|
+
s[19] = (h5 >> 24) | (h6 * ((uint32_t) 1 << 1));
|
349
|
+
s[20] = h6 >> 7;
|
350
|
+
s[21] = h6 >> 15;
|
351
|
+
s[22] = (h6 >> 23) | (h7 * ((uint32_t) 1 << 3));
|
352
|
+
s[23] = h7 >> 5;
|
353
|
+
s[24] = h7 >> 13;
|
354
|
+
s[25] = (h7 >> 21) | (h8 * ((uint32_t) 1 << 4));
|
355
|
+
s[26] = h8 >> 4;
|
356
|
+
s[27] = h8 >> 12;
|
357
|
+
s[28] = (h8 >> 20) | (h9 * ((uint32_t) 1 << 6));
|
358
|
+
s[29] = h9 >> 2;
|
359
|
+
s[30] = h9 >> 10;
|
360
|
+
s[31] = h9 >> 18;
|
359
361
|
}
|
360
362
|
|
361
363
|
/*
|
362
|
-
return 1 if f is in {1,3,5,...,q-2}
|
363
|
-
return 0 if f is in {0,2,4,...,q-1}
|
364
|
-
|
365
|
-
Preconditions:
|
366
|
-
|
367
|
-
*/
|
364
|
+
return 1 if f is in {1,3,5,...,q-2}
|
365
|
+
return 0 if f is in {0,2,4,...,q-1}
|
366
|
+
*
|
367
|
+
Preconditions:
|
368
|
+
|f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
|
369
|
+
*/
|
368
370
|
|
369
371
|
int fe_isnegative(const fe f)
|
370
372
|
{
|
371
|
-
|
372
|
-
|
373
|
-
|
373
|
+
unsigned char s[32];
|
374
|
+
fe_tobytes(s,f);
|
375
|
+
|
376
|
+
return s[0] & 1;
|
374
377
|
}
|
375
378
|
|
376
379
|
/*
|
377
|
-
return 1 if f == 0
|
378
|
-
return 0 if f != 0
|
379
|
-
|
380
|
-
Preconditions:
|
381
|
-
|
382
|
-
*/
|
380
|
+
return 1 if f == 0
|
381
|
+
return 0 if f != 0
|
382
|
+
*
|
383
|
+
Preconditions:
|
384
|
+
|f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
|
385
|
+
*/
|
383
386
|
|
384
387
|
static unsigned char zero[32];
|
385
388
|
|
386
389
|
int fe_isnonzero(const fe f)
|
387
390
|
{
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
+
unsigned char s[32];
|
392
|
+
fe_tobytes(s,f);
|
393
|
+
|
394
|
+
return crypto_verify_32(s,zero);
|
391
395
|
}
|
392
396
|
|
393
397
|
/*
|
394
|
-
h = f * g
|
395
|
-
Can overlap h with f or g.
|
396
|
-
|
397
|
-
Preconditions:
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
Postconditions:
|
402
|
-
|
403
|
-
*/
|
398
|
+
h = f * g
|
399
|
+
Can overlap h with f or g.
|
400
|
+
*
|
401
|
+
Preconditions:
|
402
|
+
|f| bounded by 1.65*2^26,1.65*2^25,1.65*2^26,1.65*2^25,etc.
|
403
|
+
|g| bounded by 1.65*2^26,1.65*2^25,1.65*2^26,1.65*2^25,etc.
|
404
|
+
*
|
405
|
+
Postconditions:
|
406
|
+
|h| bounded by 1.01*2^25,1.01*2^24,1.01*2^25,1.01*2^24,etc.
|
407
|
+
*/
|
404
408
|
|
405
409
|
/*
|
406
|
-
Notes on implementation strategy:
|
407
|
-
|
408
|
-
Using schoolbook multiplication.
|
409
|
-
Karatsuba would save a little in some cost models.
|
410
|
-
|
411
|
-
Most multiplications by 2 and 19 are 32-bit precomputations;
|
412
|
-
cheaper than 64-bit postcomputations.
|
413
|
-
|
414
|
-
There is one remaining multiplication by 19 in the carry chain;
|
415
|
-
one *19 precomputation can be merged into this,
|
416
|
-
but the resulting data flow is considerably less clean.
|
417
|
-
|
418
|
-
There are 12 carries below.
|
419
|
-
10 of them are 2-way parallelizable and vectorizable.
|
420
|
-
Can get away with 11 carries, but then data flow is much deeper.
|
421
|
-
|
422
|
-
With tighter constraints on inputs can squeeze carries into int32.
|
423
|
-
*/
|
410
|
+
Notes on implementation strategy:
|
411
|
+
*
|
412
|
+
Using schoolbook multiplication.
|
413
|
+
Karatsuba would save a little in some cost models.
|
414
|
+
*
|
415
|
+
Most multiplications by 2 and 19 are 32-bit precomputations;
|
416
|
+
cheaper than 64-bit postcomputations.
|
417
|
+
*
|
418
|
+
There is one remaining multiplication by 19 in the carry chain;
|
419
|
+
one *19 precomputation can be merged into this,
|
420
|
+
but the resulting data flow is considerably less clean.
|
421
|
+
*
|
422
|
+
There are 12 carries below.
|
423
|
+
10 of them are 2-way parallelizable and vectorizable.
|
424
|
+
Can get away with 11 carries, but then data flow is much deeper.
|
425
|
+
*
|
426
|
+
With tighter constraints on inputs can squeeze carries into int32.
|
427
|
+
*/
|
424
428
|
|
425
429
|
void fe_mul(fe h,const fe f,const fe g)
|
426
430
|
{
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
431
|
+
int32_t f0 = f[0];
|
432
|
+
int32_t f1 = f[1];
|
433
|
+
int32_t f2 = f[2];
|
434
|
+
int32_t f3 = f[3];
|
435
|
+
int32_t f4 = f[4];
|
436
|
+
int32_t f5 = f[5];
|
437
|
+
int32_t f6 = f[6];
|
438
|
+
int32_t f7 = f[7];
|
439
|
+
int32_t f8 = f[8];
|
440
|
+
int32_t f9 = f[9];
|
441
|
+
int32_t g0 = g[0];
|
442
|
+
int32_t g1 = g[1];
|
443
|
+
int32_t g2 = g[2];
|
444
|
+
int32_t g3 = g[3];
|
445
|
+
int32_t g4 = g[4];
|
446
|
+
int32_t g5 = g[5];
|
447
|
+
int32_t g6 = g[6];
|
448
|
+
int32_t g7 = g[7];
|
449
|
+
int32_t g8 = g[8];
|
450
|
+
int32_t g9 = g[9];
|
451
|
+
int32_t g1_19 = 19 * g1; /* 1.959375*2^29 */
|
452
|
+
int32_t g2_19 = 19 * g2; /* 1.959375*2^30; still ok */
|
453
|
+
int32_t g3_19 = 19 * g3;
|
454
|
+
int32_t g4_19 = 19 * g4;
|
455
|
+
int32_t g5_19 = 19 * g5;
|
456
|
+
int32_t g6_19 = 19 * g6;
|
457
|
+
int32_t g7_19 = 19 * g7;
|
458
|
+
int32_t g8_19 = 19 * g8;
|
459
|
+
int32_t g9_19 = 19 * g9;
|
460
|
+
int32_t f1_2 = 2 * f1;
|
461
|
+
int32_t f3_2 = 2 * f3;
|
462
|
+
int32_t f5_2 = 2 * f5;
|
463
|
+
int32_t f7_2 = 2 * f7;
|
464
|
+
int32_t f9_2 = 2 * f9;
|
465
|
+
int64_t f0g0 = f0 * (int64_t) g0;
|
466
|
+
int64_t f0g1 = f0 * (int64_t) g1;
|
467
|
+
int64_t f0g2 = f0 * (int64_t) g2;
|
468
|
+
int64_t f0g3 = f0 * (int64_t) g3;
|
469
|
+
int64_t f0g4 = f0 * (int64_t) g4;
|
470
|
+
int64_t f0g5 = f0 * (int64_t) g5;
|
471
|
+
int64_t f0g6 = f0 * (int64_t) g6;
|
472
|
+
int64_t f0g7 = f0 * (int64_t) g7;
|
473
|
+
int64_t f0g8 = f0 * (int64_t) g8;
|
474
|
+
int64_t f0g9 = f0 * (int64_t) g9;
|
475
|
+
int64_t f1g0 = f1 * (int64_t) g0;
|
476
|
+
int64_t f1g1_2 = f1_2 * (int64_t) g1;
|
477
|
+
int64_t f1g2 = f1 * (int64_t) g2;
|
478
|
+
int64_t f1g3_2 = f1_2 * (int64_t) g3;
|
479
|
+
int64_t f1g4 = f1 * (int64_t) g4;
|
480
|
+
int64_t f1g5_2 = f1_2 * (int64_t) g5;
|
481
|
+
int64_t f1g6 = f1 * (int64_t) g6;
|
482
|
+
int64_t f1g7_2 = f1_2 * (int64_t) g7;
|
483
|
+
int64_t f1g8 = f1 * (int64_t) g8;
|
484
|
+
int64_t f1g9_38 = f1_2 * (int64_t) g9_19;
|
485
|
+
int64_t f2g0 = f2 * (int64_t) g0;
|
486
|
+
int64_t f2g1 = f2 * (int64_t) g1;
|
487
|
+
int64_t f2g2 = f2 * (int64_t) g2;
|
488
|
+
int64_t f2g3 = f2 * (int64_t) g3;
|
489
|
+
int64_t f2g4 = f2 * (int64_t) g4;
|
490
|
+
int64_t f2g5 = f2 * (int64_t) g5;
|
491
|
+
int64_t f2g6 = f2 * (int64_t) g6;
|
492
|
+
int64_t f2g7 = f2 * (int64_t) g7;
|
493
|
+
int64_t f2g8_19 = f2 * (int64_t) g8_19;
|
494
|
+
int64_t f2g9_19 = f2 * (int64_t) g9_19;
|
495
|
+
int64_t f3g0 = f3 * (int64_t) g0;
|
496
|
+
int64_t f3g1_2 = f3_2 * (int64_t) g1;
|
497
|
+
int64_t f3g2 = f3 * (int64_t) g2;
|
498
|
+
int64_t f3g3_2 = f3_2 * (int64_t) g3;
|
499
|
+
int64_t f3g4 = f3 * (int64_t) g4;
|
500
|
+
int64_t f3g5_2 = f3_2 * (int64_t) g5;
|
501
|
+
int64_t f3g6 = f3 * (int64_t) g6;
|
502
|
+
int64_t f3g7_38 = f3_2 * (int64_t) g7_19;
|
503
|
+
int64_t f3g8_19 = f3 * (int64_t) g8_19;
|
504
|
+
int64_t f3g9_38 = f3_2 * (int64_t) g9_19;
|
505
|
+
int64_t f4g0 = f4 * (int64_t) g0;
|
506
|
+
int64_t f4g1 = f4 * (int64_t) g1;
|
507
|
+
int64_t f4g2 = f4 * (int64_t) g2;
|
508
|
+
int64_t f4g3 = f4 * (int64_t) g3;
|
509
|
+
int64_t f4g4 = f4 * (int64_t) g4;
|
510
|
+
int64_t f4g5 = f4 * (int64_t) g5;
|
511
|
+
int64_t f4g6_19 = f4 * (int64_t) g6_19;
|
512
|
+
int64_t f4g7_19 = f4 * (int64_t) g7_19;
|
513
|
+
int64_t f4g8_19 = f4 * (int64_t) g8_19;
|
514
|
+
int64_t f4g9_19 = f4 * (int64_t) g9_19;
|
515
|
+
int64_t f5g0 = f5 * (int64_t) g0;
|
516
|
+
int64_t f5g1_2 = f5_2 * (int64_t) g1;
|
517
|
+
int64_t f5g2 = f5 * (int64_t) g2;
|
518
|
+
int64_t f5g3_2 = f5_2 * (int64_t) g3;
|
519
|
+
int64_t f5g4 = f5 * (int64_t) g4;
|
520
|
+
int64_t f5g5_38 = f5_2 * (int64_t) g5_19;
|
521
|
+
int64_t f5g6_19 = f5 * (int64_t) g6_19;
|
522
|
+
int64_t f5g7_38 = f5_2 * (int64_t) g7_19;
|
523
|
+
int64_t f5g8_19 = f5 * (int64_t) g8_19;
|
524
|
+
int64_t f5g9_38 = f5_2 * (int64_t) g9_19;
|
525
|
+
int64_t f6g0 = f6 * (int64_t) g0;
|
526
|
+
int64_t f6g1 = f6 * (int64_t) g1;
|
527
|
+
int64_t f6g2 = f6 * (int64_t) g2;
|
528
|
+
int64_t f6g3 = f6 * (int64_t) g3;
|
529
|
+
int64_t f6g4_19 = f6 * (int64_t) g4_19;
|
530
|
+
int64_t f6g5_19 = f6 * (int64_t) g5_19;
|
531
|
+
int64_t f6g6_19 = f6 * (int64_t) g6_19;
|
532
|
+
int64_t f6g7_19 = f6 * (int64_t) g7_19;
|
533
|
+
int64_t f6g8_19 = f6 * (int64_t) g8_19;
|
534
|
+
int64_t f6g9_19 = f6 * (int64_t) g9_19;
|
535
|
+
int64_t f7g0 = f7 * (int64_t) g0;
|
536
|
+
int64_t f7g1_2 = f7_2 * (int64_t) g1;
|
537
|
+
int64_t f7g2 = f7 * (int64_t) g2;
|
538
|
+
int64_t f7g3_38 = f7_2 * (int64_t) g3_19;
|
539
|
+
int64_t f7g4_19 = f7 * (int64_t) g4_19;
|
540
|
+
int64_t f7g5_38 = f7_2 * (int64_t) g5_19;
|
541
|
+
int64_t f7g6_19 = f7 * (int64_t) g6_19;
|
542
|
+
int64_t f7g7_38 = f7_2 * (int64_t) g7_19;
|
543
|
+
int64_t f7g8_19 = f7 * (int64_t) g8_19;
|
544
|
+
int64_t f7g9_38 = f7_2 * (int64_t) g9_19;
|
545
|
+
int64_t f8g0 = f8 * (int64_t) g0;
|
546
|
+
int64_t f8g1 = f8 * (int64_t) g1;
|
547
|
+
int64_t f8g2_19 = f8 * (int64_t) g2_19;
|
548
|
+
int64_t f8g3_19 = f8 * (int64_t) g3_19;
|
549
|
+
int64_t f8g4_19 = f8 * (int64_t) g4_19;
|
550
|
+
int64_t f8g5_19 = f8 * (int64_t) g5_19;
|
551
|
+
int64_t f8g6_19 = f8 * (int64_t) g6_19;
|
552
|
+
int64_t f8g7_19 = f8 * (int64_t) g7_19;
|
553
|
+
int64_t f8g8_19 = f8 * (int64_t) g8_19;
|
554
|
+
int64_t f8g9_19 = f8 * (int64_t) g9_19;
|
555
|
+
int64_t f9g0 = f9 * (int64_t) g0;
|
556
|
+
int64_t f9g1_38 = f9_2 * (int64_t) g1_19;
|
557
|
+
int64_t f9g2_19 = f9 * (int64_t) g2_19;
|
558
|
+
int64_t f9g3_38 = f9_2 * (int64_t) g3_19;
|
559
|
+
int64_t f9g4_19 = f9 * (int64_t) g4_19;
|
560
|
+
int64_t f9g5_38 = f9_2 * (int64_t) g5_19;
|
561
|
+
int64_t f9g6_19 = f9 * (int64_t) g6_19;
|
562
|
+
int64_t f9g7_38 = f9_2 * (int64_t) g7_19;
|
563
|
+
int64_t f9g8_19 = f9 * (int64_t) g8_19;
|
564
|
+
int64_t f9g9_38 = f9_2 * (int64_t) g9_19;
|
565
|
+
int64_t h0 = f0g0+f1g9_38+f2g8_19+f3g7_38+f4g6_19+f5g5_38+f6g4_19+f7g3_38+f8g2_19+f9g1_38;
|
566
|
+
int64_t h1 = f0g1+f1g0 +f2g9_19+f3g8_19+f4g7_19+f5g6_19+f6g5_19+f7g4_19+f8g3_19+f9g2_19;
|
567
|
+
int64_t h2 = f0g2+f1g1_2 +f2g0 +f3g9_38+f4g8_19+f5g7_38+f6g6_19+f7g5_38+f8g4_19+f9g3_38;
|
568
|
+
int64_t h3 = f0g3+f1g2 +f2g1 +f3g0 +f4g9_19+f5g8_19+f6g7_19+f7g6_19+f8g5_19+f9g4_19;
|
569
|
+
int64_t h4 = f0g4+f1g3_2 +f2g2 +f3g1_2 +f4g0 +f5g9_38+f6g8_19+f7g7_38+f8g6_19+f9g5_38;
|
570
|
+
int64_t h5 = f0g5+f1g4 +f2g3 +f3g2 +f4g1 +f5g0 +f6g9_19+f7g8_19+f8g7_19+f9g6_19;
|
571
|
+
int64_t h6 = f0g6+f1g5_2 +f2g4 +f3g3_2 +f4g2 +f5g1_2 +f6g0 +f7g9_38+f8g8_19+f9g7_38;
|
572
|
+
int64_t h7 = f0g7+f1g6 +f2g5 +f3g4 +f4g3 +f5g2 +f6g1 +f7g0 +f8g9_19+f9g8_19;
|
573
|
+
int64_t h8 = f0g8+f1g7_2 +f2g6 +f3g5_2 +f4g4 +f5g3_2 +f6g2 +f7g1_2 +f8g0 +f9g9_38;
|
574
|
+
int64_t h9 = f0g9+f1g8 +f2g7 +f3g6 +f4g5 +f5g4 +f6g3 +f7g2 +f8g1 +f9g0 ;
|
575
|
+
int64_t carry0;
|
576
|
+
int64_t carry1;
|
577
|
+
int64_t carry2;
|
578
|
+
int64_t carry3;
|
579
|
+
int64_t carry4;
|
580
|
+
int64_t carry5;
|
581
|
+
int64_t carry6;
|
582
|
+
int64_t carry7;
|
583
|
+
int64_t carry8;
|
584
|
+
int64_t carry9;
|
585
|
+
|
586
|
+
/*
|
587
|
+
|h0| <= (1.65*1.65*2^52*(1+19+19+19+19)+1.65*1.65*2^50*(38+38+38+38+38))
|
588
|
+
i.e. |h0| <= 1.4*2^60; narrower ranges for h2, h4, h6, h8
|
589
|
+
|h1| <= (1.65*1.65*2^51*(1+1+19+19+19+19+19+19+19+19))
|
590
|
+
i.e. |h1| <= 1.7*2^59; narrower ranges for h3, h5, h7, h9
|
591
|
+
*/
|
592
|
+
|
593
|
+
carry0 = (h0 + (int64_t) (1L << 25)) >> 26; h1 += carry0; h0 -= carry0 * ((uint64_t) 1L << 26);
|
594
|
+
carry4 = (h4 + (int64_t) (1L << 25)) >> 26; h5 += carry4; h4 -= carry4 * ((uint64_t) 1L << 26);
|
595
|
+
/* |h0| <= 2^25 */
|
596
|
+
/* |h4| <= 2^25 */
|
597
|
+
/* |h1| <= 1.71*2^59 */
|
598
|
+
/* |h5| <= 1.71*2^59 */
|
599
|
+
|
600
|
+
carry1 = (h1 + (int64_t) (1L << 24)) >> 25; h2 += carry1; h1 -= carry1 * ((uint64_t) 1L << 25);
|
601
|
+
carry5 = (h5 + (int64_t) (1L << 24)) >> 25; h6 += carry5; h5 -= carry5 * ((uint64_t) 1L << 25);
|
602
|
+
/* |h1| <= 2^24; from now on fits into int32 */
|
603
|
+
/* |h5| <= 2^24; from now on fits into int32 */
|
604
|
+
/* |h2| <= 1.41*2^60 */
|
605
|
+
/* |h6| <= 1.41*2^60 */
|
606
|
+
|
607
|
+
carry2 = (h2 + (int64_t) (1L << 25)) >> 26; h3 += carry2; h2 -= carry2 * ((uint64_t) 1L << 26);
|
608
|
+
carry6 = (h6 + (int64_t) (1L << 25)) >> 26; h7 += carry6; h6 -= carry6 * ((uint64_t) 1L << 26);
|
609
|
+
/* |h2| <= 2^25; from now on fits into int32 unchanged */
|
610
|
+
/* |h6| <= 2^25; from now on fits into int32 unchanged */
|
611
|
+
/* |h3| <= 1.71*2^59 */
|
612
|
+
/* |h7| <= 1.71*2^59 */
|
613
|
+
|
614
|
+
carry3 = (h3 + (int64_t) (1L << 24)) >> 25; h4 += carry3; h3 -= carry3 * ((uint64_t) 1L << 25);
|
615
|
+
carry7 = (h7 + (int64_t) (1L << 24)) >> 25; h8 += carry7; h7 -= carry7 * ((uint64_t) 1L << 25);
|
616
|
+
/* |h3| <= 2^24; from now on fits into int32 unchanged */
|
617
|
+
/* |h7| <= 2^24; from now on fits into int32 unchanged */
|
618
|
+
/* |h4| <= 1.72*2^34 */
|
619
|
+
/* |h8| <= 1.41*2^60 */
|
620
|
+
|
621
|
+
carry4 = (h4 + (int64_t) (1L << 25)) >> 26; h5 += carry4; h4 -= carry4 * ((uint64_t) 1L << 26);
|
622
|
+
carry8 = (h8 + (int64_t) (1L << 25)) >> 26; h9 += carry8; h8 -= carry8 * ((uint64_t) 1L << 26);
|
623
|
+
/* |h4| <= 2^25; from now on fits into int32 unchanged */
|
624
|
+
/* |h8| <= 2^25; from now on fits into int32 unchanged */
|
625
|
+
/* |h5| <= 1.01*2^24 */
|
626
|
+
/* |h9| <= 1.71*2^59 */
|
627
|
+
|
628
|
+
carry9 = (h9 + (int64_t) (1L << 24)) >> 25; h0 += carry9 * 19; h9 -= carry9 * ((uint64_t) 1L << 25);
|
629
|
+
/* |h9| <= 2^24; from now on fits into int32 unchanged */
|
630
|
+
/* |h0| <= 1.1*2^39 */
|
631
|
+
|
632
|
+
carry0 = (h0 + (int64_t) (1L << 25)) >> 26; h1 += carry0; h0 -= carry0 * ((uint64_t) 1L << 26);
|
633
|
+
/* |h0| <= 2^25; from now on fits into int32 unchanged */
|
634
|
+
/* |h1| <= 1.01*2^24 */
|
635
|
+
|
636
|
+
h[0] = (int32_t) h0;
|
637
|
+
h[1] = (int32_t) h1;
|
638
|
+
h[2] = (int32_t) h2;
|
639
|
+
h[3] = (int32_t) h3;
|
640
|
+
h[4] = (int32_t) h4;
|
641
|
+
h[5] = (int32_t) h5;
|
642
|
+
h[6] = (int32_t) h6;
|
643
|
+
h[7] = (int32_t) h7;
|
644
|
+
h[8] = (int32_t) h8;
|
645
|
+
h[9] = (int32_t) h9;
|
642
646
|
}
|
643
647
|
|
644
648
|
/*
|
645
|
-
h = -f
|
646
|
-
|
647
|
-
Preconditions:
|
648
|
-
|
649
|
-
|
650
|
-
Postconditions:
|
651
|
-
|
652
|
-
*/
|
649
|
+
h = -f
|
650
|
+
*
|
651
|
+
Preconditions:
|
652
|
+
|f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
|
653
|
+
*
|
654
|
+
Postconditions:
|
655
|
+
|h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
|
656
|
+
*/
|
653
657
|
|
654
658
|
void fe_neg(fe h,const fe f)
|
655
659
|
{
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
660
|
+
int32_t f0 = f[0];
|
661
|
+
int32_t f1 = f[1];
|
662
|
+
int32_t f2 = f[2];
|
663
|
+
int32_t f3 = f[3];
|
664
|
+
int32_t f4 = f[4];
|
665
|
+
int32_t f5 = f[5];
|
666
|
+
int32_t f6 = f[6];
|
667
|
+
int32_t f7 = f[7];
|
668
|
+
int32_t f8 = f[8];
|
669
|
+
int32_t f9 = f[9];
|
670
|
+
int32_t h0 = -f0;
|
671
|
+
int32_t h1 = -f1;
|
672
|
+
int32_t h2 = -f2;
|
673
|
+
int32_t h3 = -f3;
|
674
|
+
int32_t h4 = -f4;
|
675
|
+
int32_t h5 = -f5;
|
676
|
+
int32_t h6 = -f6;
|
677
|
+
int32_t h7 = -f7;
|
678
|
+
int32_t h8 = -f8;
|
679
|
+
int32_t h9 = -f9;
|
680
|
+
h[0] = h0;
|
681
|
+
h[1] = h1;
|
682
|
+
h[2] = h2;
|
683
|
+
h[3] = h3;
|
684
|
+
h[4] = h4;
|
685
|
+
h[5] = h5;
|
686
|
+
h[6] = h6;
|
687
|
+
h[7] = h7;
|
688
|
+
h[8] = h8;
|
689
|
+
h[9] = h9;
|
686
690
|
}
|
687
691
|
|
688
692
|
/*
|
689
|
-
h = f * f
|
690
|
-
Can overlap h with f.
|
691
|
-
|
692
|
-
Preconditions:
|
693
|
-
|
694
|
-
|
695
|
-
Postconditions:
|
696
|
-
|
697
|
-
*/
|
693
|
+
h = f * f
|
694
|
+
Can overlap h with f.
|
695
|
+
*
|
696
|
+
Preconditions:
|
697
|
+
|f| bounded by 1.65*2^26,1.65*2^25,1.65*2^26,1.65*2^25,etc.
|
698
|
+
*
|
699
|
+
Postconditions:
|
700
|
+
|h| bounded by 1.01*2^25,1.01*2^24,1.01*2^25,1.01*2^24,etc.
|
701
|
+
*/
|
698
702
|
|
699
703
|
/*
|
700
|
-
See fe_mul.c for discussion of implementation strategy.
|
701
|
-
*/
|
704
|
+
See fe_mul.c for discussion of implementation strategy.
|
705
|
+
*/
|
702
706
|
|
703
707
|
void fe_sq(fe h,const fe f)
|
704
708
|
{
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
709
|
+
int32_t f0 = f[0];
|
710
|
+
int32_t f1 = f[1];
|
711
|
+
int32_t f2 = f[2];
|
712
|
+
int32_t f3 = f[3];
|
713
|
+
int32_t f4 = f[4];
|
714
|
+
int32_t f5 = f[5];
|
715
|
+
int32_t f6 = f[6];
|
716
|
+
int32_t f7 = f[7];
|
717
|
+
int32_t f8 = f[8];
|
718
|
+
int32_t f9 = f[9];
|
719
|
+
int32_t f0_2 = 2 * f0;
|
720
|
+
int32_t f1_2 = 2 * f1;
|
721
|
+
int32_t f2_2 = 2 * f2;
|
722
|
+
int32_t f3_2 = 2 * f3;
|
723
|
+
int32_t f4_2 = 2 * f4;
|
724
|
+
int32_t f5_2 = 2 * f5;
|
725
|
+
int32_t f6_2 = 2 * f6;
|
726
|
+
int32_t f7_2 = 2 * f7;
|
727
|
+
int32_t f5_38 = 38 * f5; /* 1.959375*2^30 */
|
728
|
+
int32_t f6_19 = 19 * f6; /* 1.959375*2^30 */
|
729
|
+
int32_t f7_38 = 38 * f7; /* 1.959375*2^30 */
|
730
|
+
int32_t f8_19 = 19 * f8; /* 1.959375*2^30 */
|
731
|
+
int32_t f9_38 = 38 * f9; /* 1.959375*2^30 */
|
732
|
+
int64_t f0f0 = f0 * (int64_t) f0;
|
733
|
+
int64_t f0f1_2 = f0_2 * (int64_t) f1;
|
734
|
+
int64_t f0f2_2 = f0_2 * (int64_t) f2;
|
735
|
+
int64_t f0f3_2 = f0_2 * (int64_t) f3;
|
736
|
+
int64_t f0f4_2 = f0_2 * (int64_t) f4;
|
737
|
+
int64_t f0f5_2 = f0_2 * (int64_t) f5;
|
738
|
+
int64_t f0f6_2 = f0_2 * (int64_t) f6;
|
739
|
+
int64_t f0f7_2 = f0_2 * (int64_t) f7;
|
740
|
+
int64_t f0f8_2 = f0_2 * (int64_t) f8;
|
741
|
+
int64_t f0f9_2 = f0_2 * (int64_t) f9;
|
742
|
+
int64_t f1f1_2 = f1_2 * (int64_t) f1;
|
743
|
+
int64_t f1f2_2 = f1_2 * (int64_t) f2;
|
744
|
+
int64_t f1f3_4 = f1_2 * (int64_t) f3_2;
|
745
|
+
int64_t f1f4_2 = f1_2 * (int64_t) f4;
|
746
|
+
int64_t f1f5_4 = f1_2 * (int64_t) f5_2;
|
747
|
+
int64_t f1f6_2 = f1_2 * (int64_t) f6;
|
748
|
+
int64_t f1f7_4 = f1_2 * (int64_t) f7_2;
|
749
|
+
int64_t f1f8_2 = f1_2 * (int64_t) f8;
|
750
|
+
int64_t f1f9_76 = f1_2 * (int64_t) f9_38;
|
751
|
+
int64_t f2f2 = f2 * (int64_t) f2;
|
752
|
+
int64_t f2f3_2 = f2_2 * (int64_t) f3;
|
753
|
+
int64_t f2f4_2 = f2_2 * (int64_t) f4;
|
754
|
+
int64_t f2f5_2 = f2_2 * (int64_t) f5;
|
755
|
+
int64_t f2f6_2 = f2_2 * (int64_t) f6;
|
756
|
+
int64_t f2f7_2 = f2_2 * (int64_t) f7;
|
757
|
+
int64_t f2f8_38 = f2_2 * (int64_t) f8_19;
|
758
|
+
int64_t f2f9_38 = f2 * (int64_t) f9_38;
|
759
|
+
int64_t f3f3_2 = f3_2 * (int64_t) f3;
|
760
|
+
int64_t f3f4_2 = f3_2 * (int64_t) f4;
|
761
|
+
int64_t f3f5_4 = f3_2 * (int64_t) f5_2;
|
762
|
+
int64_t f3f6_2 = f3_2 * (int64_t) f6;
|
763
|
+
int64_t f3f7_76 = f3_2 * (int64_t) f7_38;
|
764
|
+
int64_t f3f8_38 = f3_2 * (int64_t) f8_19;
|
765
|
+
int64_t f3f9_76 = f3_2 * (int64_t) f9_38;
|
766
|
+
int64_t f4f4 = f4 * (int64_t) f4;
|
767
|
+
int64_t f4f5_2 = f4_2 * (int64_t) f5;
|
768
|
+
int64_t f4f6_38 = f4_2 * (int64_t) f6_19;
|
769
|
+
int64_t f4f7_38 = f4 * (int64_t) f7_38;
|
770
|
+
int64_t f4f8_38 = f4_2 * (int64_t) f8_19;
|
771
|
+
int64_t f4f9_38 = f4 * (int64_t) f9_38;
|
772
|
+
int64_t f5f5_38 = f5 * (int64_t) f5_38;
|
773
|
+
int64_t f5f6_38 = f5_2 * (int64_t) f6_19;
|
774
|
+
int64_t f5f7_76 = f5_2 * (int64_t) f7_38;
|
775
|
+
int64_t f5f8_38 = f5_2 * (int64_t) f8_19;
|
776
|
+
int64_t f5f9_76 = f5_2 * (int64_t) f9_38;
|
777
|
+
int64_t f6f6_19 = f6 * (int64_t) f6_19;
|
778
|
+
int64_t f6f7_38 = f6 * (int64_t) f7_38;
|
779
|
+
int64_t f6f8_38 = f6_2 * (int64_t) f8_19;
|
780
|
+
int64_t f6f9_38 = f6 * (int64_t) f9_38;
|
781
|
+
int64_t f7f7_38 = f7 * (int64_t) f7_38;
|
782
|
+
int64_t f7f8_38 = f7_2 * (int64_t) f8_19;
|
783
|
+
int64_t f7f9_76 = f7_2 * (int64_t) f9_38;
|
784
|
+
int64_t f8f8_19 = f8 * (int64_t) f8_19;
|
785
|
+
int64_t f8f9_38 = f8 * (int64_t) f9_38;
|
786
|
+
int64_t f9f9_38 = f9 * (int64_t) f9_38;
|
787
|
+
int64_t h0 = f0f0 +f1f9_76+f2f8_38+f3f7_76+f4f6_38+f5f5_38;
|
788
|
+
int64_t h1 = f0f1_2+f2f9_38+f3f8_38+f4f7_38+f5f6_38;
|
789
|
+
int64_t h2 = f0f2_2+f1f1_2 +f3f9_76+f4f8_38+f5f7_76+f6f6_19;
|
790
|
+
int64_t h3 = f0f3_2+f1f2_2 +f4f9_38+f5f8_38+f6f7_38;
|
791
|
+
int64_t h4 = f0f4_2+f1f3_4 +f2f2 +f5f9_76+f6f8_38+f7f7_38;
|
792
|
+
int64_t h5 = f0f5_2+f1f4_2 +f2f3_2 +f6f9_38+f7f8_38;
|
793
|
+
int64_t h6 = f0f6_2+f1f5_4 +f2f4_2 +f3f3_2 +f7f9_76+f8f8_19;
|
794
|
+
int64_t h7 = f0f7_2+f1f6_2 +f2f5_2 +f3f4_2 +f8f9_38;
|
795
|
+
int64_t h8 = f0f8_2+f1f7_4 +f2f6_2 +f3f5_4 +f4f4 +f9f9_38;
|
796
|
+
int64_t h9 = f0f9_2+f1f8_2 +f2f7_2 +f3f6_2 +f4f5_2;
|
797
|
+
int64_t carry0;
|
798
|
+
int64_t carry1;
|
799
|
+
int64_t carry2;
|
800
|
+
int64_t carry3;
|
801
|
+
int64_t carry4;
|
802
|
+
int64_t carry5;
|
803
|
+
int64_t carry6;
|
804
|
+
int64_t carry7;
|
805
|
+
int64_t carry8;
|
806
|
+
int64_t carry9;
|
807
|
+
|
808
|
+
carry0 = (h0 + (int64_t) (1L << 25)) >> 26; h1 += carry0; h0 -= carry0 * ((uint64_t) 1L << 26);
|
809
|
+
carry4 = (h4 + (int64_t) (1L << 25)) >> 26; h5 += carry4; h4 -= carry4 * ((uint64_t) 1L << 26);
|
810
|
+
|
811
|
+
carry1 = (h1 + (int64_t) (1L << 24)) >> 25; h2 += carry1; h1 -= carry1 * ((uint64_t) 1L << 25);
|
812
|
+
carry5 = (h5 + (int64_t) (1L << 24)) >> 25; h6 += carry5; h5 -= carry5 * ((uint64_t) 1L << 25);
|
813
|
+
|
814
|
+
carry2 = (h2 + (int64_t) (1L << 25)) >> 26; h3 += carry2; h2 -= carry2 * ((uint64_t) 1L << 26);
|
815
|
+
carry6 = (h6 + (int64_t) (1L << 25)) >> 26; h7 += carry6; h6 -= carry6 * ((uint64_t) 1L << 26);
|
816
|
+
|
817
|
+
carry3 = (h3 + (int64_t) (1L << 24)) >> 25; h4 += carry3; h3 -= carry3 * ((uint64_t) 1L << 25);
|
818
|
+
carry7 = (h7 + (int64_t) (1L << 24)) >> 25; h8 += carry7; h7 -= carry7 * ((uint64_t) 1L << 25);
|
819
|
+
|
820
|
+
carry4 = (h4 + (int64_t) (1L << 25)) >> 26; h5 += carry4; h4 -= carry4 * ((uint64_t) 1L << 26);
|
821
|
+
carry8 = (h8 + (int64_t) (1L << 25)) >> 26; h9 += carry8; h8 -= carry8 * ((uint64_t) 1L << 26);
|
822
|
+
|
823
|
+
carry9 = (h9 + (int64_t) (1L << 24)) >> 25; h0 += carry9 * 19; h9 -= carry9 * ((uint64_t) 1L << 25);
|
824
|
+
|
825
|
+
carry0 = (h0 + (int64_t) (1L << 25)) >> 26; h1 += carry0; h0 -= carry0 * ((uint64_t) 1L << 26);
|
826
|
+
|
827
|
+
h[0] = (int32_t) h0;
|
828
|
+
h[1] = (int32_t) h1;
|
829
|
+
h[2] = (int32_t) h2;
|
830
|
+
h[3] = (int32_t) h3;
|
831
|
+
h[4] = (int32_t) h4;
|
832
|
+
h[5] = (int32_t) h5;
|
833
|
+
h[6] = (int32_t) h6;
|
834
|
+
h[7] = (int32_t) h7;
|
835
|
+
h[8] = (int32_t) h8;
|
836
|
+
h[9] = (int32_t) h9;
|
833
837
|
}
|
834
838
|
|
835
839
|
/*
|
836
|
-
h = 2 * f * f
|
837
|
-
Can overlap h with f.
|
838
|
-
|
839
|
-
Preconditions:
|
840
|
-
|
841
|
-
|
842
|
-
Postconditions:
|
843
|
-
|
844
|
-
*/
|
840
|
+
h = 2 * f * f
|
841
|
+
Can overlap h with f.
|
842
|
+
*
|
843
|
+
Preconditions:
|
844
|
+
|f| bounded by 1.65*2^26,1.65*2^25,1.65*2^26,1.65*2^25,etc.
|
845
|
+
*
|
846
|
+
Postconditions:
|
847
|
+
|h| bounded by 1.01*2^25,1.01*2^24,1.01*2^25,1.01*2^24,etc.
|
848
|
+
*/
|
845
849
|
|
846
850
|
/*
|
847
|
-
See fe_mul.c for discussion of implementation strategy.
|
848
|
-
*/
|
851
|
+
See fe_mul.c for discussion of implementation strategy.
|
852
|
+
*/
|
849
853
|
|
850
854
|
void fe_sq2(fe h,const fe f)
|
851
855
|
{
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
856
|
+
int32_t f0 = f[0];
|
857
|
+
int32_t f1 = f[1];
|
858
|
+
int32_t f2 = f[2];
|
859
|
+
int32_t f3 = f[3];
|
860
|
+
int32_t f4 = f[4];
|
861
|
+
int32_t f5 = f[5];
|
862
|
+
int32_t f6 = f[6];
|
863
|
+
int32_t f7 = f[7];
|
864
|
+
int32_t f8 = f[8];
|
865
|
+
int32_t f9 = f[9];
|
866
|
+
int32_t f0_2 = 2 * f0;
|
867
|
+
int32_t f1_2 = 2 * f1;
|
868
|
+
int32_t f2_2 = 2 * f2;
|
869
|
+
int32_t f3_2 = 2 * f3;
|
870
|
+
int32_t f4_2 = 2 * f4;
|
871
|
+
int32_t f5_2 = 2 * f5;
|
872
|
+
int32_t f6_2 = 2 * f6;
|
873
|
+
int32_t f7_2 = 2 * f7;
|
874
|
+
int32_t f5_38 = 38 * f5; /* 1.959375*2^30 */
|
875
|
+
int32_t f6_19 = 19 * f6; /* 1.959375*2^30 */
|
876
|
+
int32_t f7_38 = 38 * f7; /* 1.959375*2^30 */
|
877
|
+
int32_t f8_19 = 19 * f8; /* 1.959375*2^30 */
|
878
|
+
int32_t f9_38 = 38 * f9; /* 1.959375*2^30 */
|
879
|
+
int64_t f0f0 = f0 * (int64_t) f0;
|
880
|
+
int64_t f0f1_2 = f0_2 * (int64_t) f1;
|
881
|
+
int64_t f0f2_2 = f0_2 * (int64_t) f2;
|
882
|
+
int64_t f0f3_2 = f0_2 * (int64_t) f3;
|
883
|
+
int64_t f0f4_2 = f0_2 * (int64_t) f4;
|
884
|
+
int64_t f0f5_2 = f0_2 * (int64_t) f5;
|
885
|
+
int64_t f0f6_2 = f0_2 * (int64_t) f6;
|
886
|
+
int64_t f0f7_2 = f0_2 * (int64_t) f7;
|
887
|
+
int64_t f0f8_2 = f0_2 * (int64_t) f8;
|
888
|
+
int64_t f0f9_2 = f0_2 * (int64_t) f9;
|
889
|
+
int64_t f1f1_2 = f1_2 * (int64_t) f1;
|
890
|
+
int64_t f1f2_2 = f1_2 * (int64_t) f2;
|
891
|
+
int64_t f1f3_4 = f1_2 * (int64_t) f3_2;
|
892
|
+
int64_t f1f4_2 = f1_2 * (int64_t) f4;
|
893
|
+
int64_t f1f5_4 = f1_2 * (int64_t) f5_2;
|
894
|
+
int64_t f1f6_2 = f1_2 * (int64_t) f6;
|
895
|
+
int64_t f1f7_4 = f1_2 * (int64_t) f7_2;
|
896
|
+
int64_t f1f8_2 = f1_2 * (int64_t) f8;
|
897
|
+
int64_t f1f9_76 = f1_2 * (int64_t) f9_38;
|
898
|
+
int64_t f2f2 = f2 * (int64_t) f2;
|
899
|
+
int64_t f2f3_2 = f2_2 * (int64_t) f3;
|
900
|
+
int64_t f2f4_2 = f2_2 * (int64_t) f4;
|
901
|
+
int64_t f2f5_2 = f2_2 * (int64_t) f5;
|
902
|
+
int64_t f2f6_2 = f2_2 * (int64_t) f6;
|
903
|
+
int64_t f2f7_2 = f2_2 * (int64_t) f7;
|
904
|
+
int64_t f2f8_38 = f2_2 * (int64_t) f8_19;
|
905
|
+
int64_t f2f9_38 = f2 * (int64_t) f9_38;
|
906
|
+
int64_t f3f3_2 = f3_2 * (int64_t) f3;
|
907
|
+
int64_t f3f4_2 = f3_2 * (int64_t) f4;
|
908
|
+
int64_t f3f5_4 = f3_2 * (int64_t) f5_2;
|
909
|
+
int64_t f3f6_2 = f3_2 * (int64_t) f6;
|
910
|
+
int64_t f3f7_76 = f3_2 * (int64_t) f7_38;
|
911
|
+
int64_t f3f8_38 = f3_2 * (int64_t) f8_19;
|
912
|
+
int64_t f3f9_76 = f3_2 * (int64_t) f9_38;
|
913
|
+
int64_t f4f4 = f4 * (int64_t) f4;
|
914
|
+
int64_t f4f5_2 = f4_2 * (int64_t) f5;
|
915
|
+
int64_t f4f6_38 = f4_2 * (int64_t) f6_19;
|
916
|
+
int64_t f4f7_38 = f4 * (int64_t) f7_38;
|
917
|
+
int64_t f4f8_38 = f4_2 * (int64_t) f8_19;
|
918
|
+
int64_t f4f9_38 = f4 * (int64_t) f9_38;
|
919
|
+
int64_t f5f5_38 = f5 * (int64_t) f5_38;
|
920
|
+
int64_t f5f6_38 = f5_2 * (int64_t) f6_19;
|
921
|
+
int64_t f5f7_76 = f5_2 * (int64_t) f7_38;
|
922
|
+
int64_t f5f8_38 = f5_2 * (int64_t) f8_19;
|
923
|
+
int64_t f5f9_76 = f5_2 * (int64_t) f9_38;
|
924
|
+
int64_t f6f6_19 = f6 * (int64_t) f6_19;
|
925
|
+
int64_t f6f7_38 = f6 * (int64_t) f7_38;
|
926
|
+
int64_t f6f8_38 = f6_2 * (int64_t) f8_19;
|
927
|
+
int64_t f6f9_38 = f6 * (int64_t) f9_38;
|
928
|
+
int64_t f7f7_38 = f7 * (int64_t) f7_38;
|
929
|
+
int64_t f7f8_38 = f7_2 * (int64_t) f8_19;
|
930
|
+
int64_t f7f9_76 = f7_2 * (int64_t) f9_38;
|
931
|
+
int64_t f8f8_19 = f8 * (int64_t) f8_19;
|
932
|
+
int64_t f8f9_38 = f8 * (int64_t) f9_38;
|
933
|
+
int64_t f9f9_38 = f9 * (int64_t) f9_38;
|
934
|
+
int64_t h0 = f0f0 +f1f9_76+f2f8_38+f3f7_76+f4f6_38+f5f5_38;
|
935
|
+
int64_t h1 = f0f1_2+f2f9_38+f3f8_38+f4f7_38+f5f6_38;
|
936
|
+
int64_t h2 = f0f2_2+f1f1_2 +f3f9_76+f4f8_38+f5f7_76+f6f6_19;
|
937
|
+
int64_t h3 = f0f3_2+f1f2_2 +f4f9_38+f5f8_38+f6f7_38;
|
938
|
+
int64_t h4 = f0f4_2+f1f3_4 +f2f2 +f5f9_76+f6f8_38+f7f7_38;
|
939
|
+
int64_t h5 = f0f5_2+f1f4_2 +f2f3_2 +f6f9_38+f7f8_38;
|
940
|
+
int64_t h6 = f0f6_2+f1f5_4 +f2f4_2 +f3f3_2 +f7f9_76+f8f8_19;
|
941
|
+
int64_t h7 = f0f7_2+f1f6_2 +f2f5_2 +f3f4_2 +f8f9_38;
|
942
|
+
int64_t h8 = f0f8_2+f1f7_4 +f2f6_2 +f3f5_4 +f4f4 +f9f9_38;
|
943
|
+
int64_t h9 = f0f9_2+f1f8_2 +f2f7_2 +f3f6_2 +f4f5_2;
|
944
|
+
int64_t carry0;
|
945
|
+
int64_t carry1;
|
946
|
+
int64_t carry2;
|
947
|
+
int64_t carry3;
|
948
|
+
int64_t carry4;
|
949
|
+
int64_t carry5;
|
950
|
+
int64_t carry6;
|
951
|
+
int64_t carry7;
|
952
|
+
int64_t carry8;
|
953
|
+
int64_t carry9;
|
954
|
+
|
955
|
+
h0 += h0;
|
956
|
+
h1 += h1;
|
957
|
+
h2 += h2;
|
958
|
+
h3 += h3;
|
959
|
+
h4 += h4;
|
960
|
+
h5 += h5;
|
961
|
+
h6 += h6;
|
962
|
+
h7 += h7;
|
963
|
+
h8 += h8;
|
964
|
+
h9 += h9;
|
965
|
+
|
966
|
+
carry0 = (h0 + (int64_t) (1L << 25)) >> 26; h1 += carry0; h0 -= carry0 * ((uint64_t) 1L << 26);
|
967
|
+
carry4 = (h4 + (int64_t) (1L << 25)) >> 26; h5 += carry4; h4 -= carry4 * ((uint64_t) 1L << 26);
|
968
|
+
|
969
|
+
carry1 = (h1 + (int64_t) (1L << 24)) >> 25; h2 += carry1; h1 -= carry1 * ((uint64_t) 1L << 25);
|
970
|
+
carry5 = (h5 + (int64_t) (1L << 24)) >> 25; h6 += carry5; h5 -= carry5 * ((uint64_t) 1L << 25);
|
971
|
+
|
972
|
+
carry2 = (h2 + (int64_t) (1L << 25)) >> 26; h3 += carry2; h2 -= carry2 * ((uint64_t) 1L << 26);
|
973
|
+
carry6 = (h6 + (int64_t) (1L << 25)) >> 26; h7 += carry6; h6 -= carry6 * ((uint64_t) 1L << 26);
|
974
|
+
|
975
|
+
carry3 = (h3 + (int64_t) (1L << 24)) >> 25; h4 += carry3; h3 -= carry3 * ((uint64_t) 1L << 25);
|
976
|
+
carry7 = (h7 + (int64_t) (1L << 24)) >> 25; h8 += carry7; h7 -= carry7 * ((uint64_t) 1L << 25);
|
977
|
+
|
978
|
+
carry4 = (h4 + (int64_t) (1L << 25)) >> 26; h5 += carry4; h4 -= carry4 * ((uint64_t) 1L << 26);
|
979
|
+
carry8 = (h8 + (int64_t) (1L << 25)) >> 26; h9 += carry8; h8 -= carry8 * ((uint64_t) 1L << 26);
|
980
|
+
|
981
|
+
carry9 = (h9 + (int64_t) (1L << 24)) >> 25; h0 += carry9 * 19; h9 -= carry9 * ((uint64_t) 1L << 25);
|
982
|
+
|
983
|
+
carry0 = (h0 + (int64_t) (1L << 25)) >> 26; h1 += carry0; h0 -= carry0 * ((uint64_t) 1L << 26);
|
984
|
+
|
985
|
+
h[0] = (int32_t) h0;
|
986
|
+
h[1] = (int32_t) h1;
|
987
|
+
h[2] = (int32_t) h2;
|
988
|
+
h[3] = (int32_t) h3;
|
989
|
+
h[4] = (int32_t) h4;
|
990
|
+
h[5] = (int32_t) h5;
|
991
|
+
h[6] = (int32_t) h6;
|
992
|
+
h[7] = (int32_t) h7;
|
993
|
+
h[8] = (int32_t) h8;
|
994
|
+
h[9] = (int32_t) h9;
|
991
995
|
}
|
992
996
|
|
993
997
|
void fe_invert(fe out,const fe z)
|
@@ -1102,64 +1106,64 @@ void fe_pow22523(fe out,const fe z)
|
|
1102
1106
|
}
|
1103
1107
|
|
1104
1108
|
/*
|
1105
|
-
h = f - g
|
1106
|
-
Can overlap h with f or g.
|
1107
|
-
|
1108
|
-
Preconditions:
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1112
|
-
Postconditions:
|
1113
|
-
|
1114
|
-
*/
|
1109
|
+
h = f - g
|
1110
|
+
Can overlap h with f or g.
|
1111
|
+
*
|
1112
|
+
Preconditions:
|
1113
|
+
|f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
|
1114
|
+
|g| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
|
1115
|
+
*
|
1116
|
+
Postconditions:
|
1117
|
+
|h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
|
1118
|
+
*/
|
1115
1119
|
|
1116
1120
|
void fe_sub(fe h,const fe f,const fe g)
|
1117
1121
|
{
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
1136
|
-
|
1137
|
-
|
1138
|
-
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1122
|
+
int32_t f0 = f[0];
|
1123
|
+
int32_t f1 = f[1];
|
1124
|
+
int32_t f2 = f[2];
|
1125
|
+
int32_t f3 = f[3];
|
1126
|
+
int32_t f4 = f[4];
|
1127
|
+
int32_t f5 = f[5];
|
1128
|
+
int32_t f6 = f[6];
|
1129
|
+
int32_t f7 = f[7];
|
1130
|
+
int32_t f8 = f[8];
|
1131
|
+
int32_t f9 = f[9];
|
1132
|
+
int32_t g0 = g[0];
|
1133
|
+
int32_t g1 = g[1];
|
1134
|
+
int32_t g2 = g[2];
|
1135
|
+
int32_t g3 = g[3];
|
1136
|
+
int32_t g4 = g[4];
|
1137
|
+
int32_t g5 = g[5];
|
1138
|
+
int32_t g6 = g[6];
|
1139
|
+
int32_t g7 = g[7];
|
1140
|
+
int32_t g8 = g[8];
|
1141
|
+
int32_t g9 = g[9];
|
1142
|
+
int32_t h0 = f0 - g0;
|
1143
|
+
int32_t h1 = f1 - g1;
|
1144
|
+
int32_t h2 = f2 - g2;
|
1145
|
+
int32_t h3 = f3 - g3;
|
1146
|
+
int32_t h4 = f4 - g4;
|
1147
|
+
int32_t h5 = f5 - g5;
|
1148
|
+
int32_t h6 = f6 - g6;
|
1149
|
+
int32_t h7 = f7 - g7;
|
1150
|
+
int32_t h8 = f8 - g8;
|
1151
|
+
int32_t h9 = f9 - g9;
|
1152
|
+
h[0] = h0;
|
1153
|
+
h[1] = h1;
|
1154
|
+
h[2] = h2;
|
1155
|
+
h[3] = h3;
|
1156
|
+
h[4] = h4;
|
1157
|
+
h[5] = h5;
|
1158
|
+
h[6] = h6;
|
1159
|
+
h[7] = h7;
|
1160
|
+
h[8] = h8;
|
1161
|
+
h[9] = h9;
|
1158
1162
|
}
|
1159
1163
|
|
1160
1164
|
/*
|
1161
|
-
r = p + q
|
1162
|
-
*/
|
1165
|
+
r = p + q
|
1166
|
+
*/
|
1163
1167
|
|
1164
1168
|
void ge_add(ge_p1p1 *r,const ge_p3 *p,const ge_cached *q)
|
1165
1169
|
{
|
@@ -1180,33 +1184,33 @@ void ge_add(ge_p1p1 *r,const ge_p3 *p,const ge_cached *q)
|
|
1180
1184
|
|
1181
1185
|
static void slide(signed char *r,const unsigned char *a)
|
1182
1186
|
{
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1192
|
-
|
1193
|
-
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1187
|
+
int i;
|
1188
|
+
int b;
|
1189
|
+
int k;
|
1190
|
+
|
1191
|
+
for (i = 0;i < 256;++i)
|
1192
|
+
r[i] = 1 & (a[i >> 3] >> (i & 7));
|
1193
|
+
|
1194
|
+
for (i = 0;i < 256;++i)
|
1195
|
+
if (r[i]) {
|
1196
|
+
for (b = 1;b <= 6 && i + b < 256;++b) {
|
1197
|
+
if (r[i + b]) {
|
1198
|
+
if (r[i] + (r[i + b] << b) <= 15) {
|
1199
|
+
r[i] += r[i + b] << b; r[i + b] = 0;
|
1200
|
+
} else if (r[i] - (r[i + b] << b) >= -15) {
|
1201
|
+
r[i] -= r[i + b] << b;
|
1202
|
+
for (k = i + b;k < 256;++k) {
|
1203
|
+
if (!r[k]) {
|
1204
|
+
r[k] = 1;
|
1205
|
+
break;
|
1206
|
+
}
|
1207
|
+
r[k] = 0;
|
1208
|
+
}
|
1209
|
+
} else
|
1210
|
+
break;
|
1211
|
+
}
|
1204
1212
|
}
|
1205
|
-
} else
|
1206
|
-
break;
|
1207
1213
|
}
|
1208
|
-
}
|
1209
|
-
}
|
1210
1214
|
|
1211
1215
|
}
|
1212
1216
|
|
@@ -1226,48 +1230,51 @@ static const fe sqrtm1 = {
|
|
1226
1230
|
|
1227
1231
|
int ge_frombytes_negate_vartime(ge_p3 *h,const unsigned char *s)
|
1228
1232
|
{
|
1229
|
-
|
1230
|
-
|
1231
|
-
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
1252
|
-
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1264
|
-
|
1265
|
-
|
1233
|
+
fe u;
|
1234
|
+
fe v;
|
1235
|
+
fe v3;
|
1236
|
+
fe vxx;
|
1237
|
+
fe check;
|
1238
|
+
|
1239
|
+
fe_frombytes(h->Y,s);
|
1240
|
+
fe_1(h->Z);
|
1241
|
+
fe_sq(u,h->Y);
|
1242
|
+
fe_mul(v,u,d);
|
1243
|
+
fe_sub(u,u,h->Z); /* u = y^2-1 */
|
1244
|
+
fe_add(v,v,h->Z); /* v = dy^2+1 */
|
1245
|
+
|
1246
|
+
fe_sq(v3,v);
|
1247
|
+
fe_mul(v3,v3,v); /* v3 = v^3 */
|
1248
|
+
fe_sq(h->X,v3);
|
1249
|
+
fe_mul(h->X,h->X,v);
|
1250
|
+
fe_mul(h->X,h->X,u); /* x = uv^7 */
|
1251
|
+
|
1252
|
+
fe_pow22523(h->X,h->X); /* x = (uv^7)^((q-5)/8) */
|
1253
|
+
fe_mul(h->X,h->X,v3);
|
1254
|
+
fe_mul(h->X,h->X,u); /* x = uv^3(uv^7)^((q-5)/8) */
|
1255
|
+
|
1256
|
+
fe_sq(vxx,h->X);
|
1257
|
+
fe_mul(vxx,vxx,v);
|
1258
|
+
fe_sub(check,vxx,u); /* vx^2-u */
|
1259
|
+
if (fe_isnonzero(check)) {
|
1260
|
+
fe_add(check,vxx,u); /* vx^2+u */
|
1261
|
+
if (fe_isnonzero(check)) {
|
1262
|
+
return -1;
|
1263
|
+
}
|
1264
|
+
fe_mul(h->X,h->X,sqrtm1);
|
1265
|
+
}
|
1266
|
+
|
1267
|
+
if (fe_isnegative(h->X) == (s[31] >> 7)) {
|
1268
|
+
fe_neg(h->X,h->X);
|
1269
|
+
}
|
1270
|
+
fe_mul(h->T,h->X,h->Y);
|
1271
|
+
|
1272
|
+
return 0;
|
1266
1273
|
}
|
1267
1274
|
|
1268
1275
|
/*
|
1269
|
-
r = p + q
|
1270
|
-
*/
|
1276
|
+
r = p + q
|
1277
|
+
*/
|
1271
1278
|
|
1272
1279
|
void ge_madd(ge_p1p1 *r,const ge_p3 *p,const ge_precomp *q)
|
1273
1280
|
{
|
@@ -1286,8 +1293,8 @@ void ge_madd(ge_p1p1 *r,const ge_p3 *p,const ge_precomp *q)
|
|
1286
1293
|
}
|
1287
1294
|
|
1288
1295
|
/*
|
1289
|
-
r = p - q
|
1290
|
-
*/
|
1296
|
+
r = p - q
|
1297
|
+
*/
|
1291
1298
|
|
1292
1299
|
void ge_msub(ge_p1p1 *r,const ge_p3 *p,const ge_precomp *q)
|
1293
1300
|
{
|
@@ -1306,38 +1313,38 @@ void ge_msub(ge_p1p1 *r,const ge_p3 *p,const ge_precomp *q)
|
|
1306
1313
|
}
|
1307
1314
|
|
1308
1315
|
/*
|
1309
|
-
r = p
|
1310
|
-
*/
|
1316
|
+
r = p
|
1317
|
+
*/
|
1311
1318
|
|
1312
1319
|
extern void ge_p1p1_to_p2(ge_p2 *r,const ge_p1p1 *p)
|
1313
1320
|
{
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1321
|
+
fe_mul(r->X,p->X,p->T);
|
1322
|
+
fe_mul(r->Y,p->Y,p->Z);
|
1323
|
+
fe_mul(r->Z,p->Z,p->T);
|
1317
1324
|
}
|
1318
1325
|
|
1319
1326
|
/*
|
1320
|
-
r = p
|
1321
|
-
*/
|
1327
|
+
r = p
|
1328
|
+
*/
|
1322
1329
|
|
1323
1330
|
extern void ge_p1p1_to_p3(ge_p3 *r,const ge_p1p1 *p)
|
1324
1331
|
{
|
1325
|
-
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1332
|
+
fe_mul(r->X,p->X,p->T);
|
1333
|
+
fe_mul(r->Y,p->Y,p->Z);
|
1334
|
+
fe_mul(r->Z,p->Z,p->T);
|
1335
|
+
fe_mul(r->T,p->X,p->Y);
|
1329
1336
|
}
|
1330
1337
|
|
1331
1338
|
void ge_p2_0(ge_p2 *h)
|
1332
1339
|
{
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1340
|
+
fe_0(h->X);
|
1341
|
+
fe_1(h->Y);
|
1342
|
+
fe_1(h->Z);
|
1336
1343
|
}
|
1337
1344
|
|
1338
1345
|
/*
|
1339
|
-
r = 2 * p
|
1340
|
-
*/
|
1346
|
+
r = 2 * p
|
1347
|
+
*/
|
1341
1348
|
|
1342
1349
|
void ge_p2_dbl(ge_p1p1 *r,const ge_p2 *p)
|
1343
1350
|
{
|
@@ -1356,15 +1363,15 @@ void ge_p2_dbl(ge_p1p1 *r,const ge_p2 *p)
|
|
1356
1363
|
|
1357
1364
|
void ge_p3_0(ge_p3 *h)
|
1358
1365
|
{
|
1359
|
-
|
1360
|
-
|
1361
|
-
|
1362
|
-
|
1366
|
+
fe_0(h->X);
|
1367
|
+
fe_1(h->Y);
|
1368
|
+
fe_1(h->Z);
|
1369
|
+
fe_0(h->T);
|
1363
1370
|
}
|
1364
1371
|
|
1365
1372
|
/*
|
1366
|
-
r = p
|
1367
|
-
*/
|
1373
|
+
r = p
|
1374
|
+
*/
|
1368
1375
|
|
1369
1376
|
/* 2 * d = 16295367250680780974490674513165176452449235426866156013048779062215315747161 */
|
1370
1377
|
static const fe d2 = {
|
@@ -1373,77 +1380,79 @@ static const fe d2 = {
|
|
1373
1380
|
|
1374
1381
|
extern void ge_p3_to_cached(ge_cached *r,const ge_p3 *p)
|
1375
1382
|
{
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1383
|
+
fe_add(r->YplusX,p->Y,p->X);
|
1384
|
+
fe_sub(r->YminusX,p->Y,p->X);
|
1385
|
+
fe_copy(r->Z,p->Z);
|
1386
|
+
fe_mul(r->T2d,p->T,d2);
|
1380
1387
|
}
|
1381
1388
|
|
1382
1389
|
/*
|
1383
|
-
r = p
|
1384
|
-
*/
|
1390
|
+
r = p
|
1391
|
+
*/
|
1385
1392
|
|
1386
1393
|
extern void ge_p3_to_p2(ge_p2 *r,const ge_p3 *p)
|
1387
1394
|
{
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1395
|
+
fe_copy(r->X,p->X);
|
1396
|
+
fe_copy(r->Y,p->Y);
|
1397
|
+
fe_copy(r->Z,p->Z);
|
1391
1398
|
}
|
1392
1399
|
|
1393
1400
|
void ge_p3_tobytes(unsigned char *s,const ge_p3 *h)
|
1394
1401
|
{
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1402
|
-
|
1403
|
-
|
1402
|
+
fe recip;
|
1403
|
+
fe x;
|
1404
|
+
fe y;
|
1405
|
+
|
1406
|
+
fe_invert(recip,h->Z);
|
1407
|
+
fe_mul(x,h->X,recip);
|
1408
|
+
fe_mul(y,h->Y,recip);
|
1409
|
+
fe_tobytes(s,y);
|
1410
|
+
s[31] ^= fe_isnegative(x) << 7;
|
1404
1411
|
}
|
1405
1412
|
|
1406
1413
|
/*
|
1407
|
-
r = 2 * p
|
1408
|
-
*/
|
1414
|
+
r = 2 * p
|
1415
|
+
*/
|
1409
1416
|
|
1410
1417
|
void ge_p3_dbl(ge_p1p1 *r,const ge_p3 *p)
|
1411
1418
|
{
|
1412
|
-
|
1413
|
-
|
1414
|
-
|
1419
|
+
ge_p2 q;
|
1420
|
+
ge_p3_to_p2(&q,p);
|
1421
|
+
ge_p2_dbl(r,&q);
|
1415
1422
|
}
|
1416
1423
|
|
1417
1424
|
void ge_precomp_0(ge_precomp *h)
|
1418
1425
|
{
|
1419
|
-
|
1420
|
-
|
1421
|
-
|
1426
|
+
fe_1(h->yplusx);
|
1427
|
+
fe_1(h->yminusx);
|
1428
|
+
fe_0(h->xy2d);
|
1422
1429
|
}
|
1423
1430
|
|
1424
1431
|
static unsigned char equal(signed char b,signed char c)
|
1425
1432
|
{
|
1426
|
-
|
1427
|
-
|
1428
|
-
|
1429
|
-
|
1430
|
-
|
1431
|
-
|
1432
|
-
|
1433
|
+
unsigned char ub = b;
|
1434
|
+
unsigned char uc = c;
|
1435
|
+
unsigned char x = ub ^ uc; /* 0: yes; 1..255: no */
|
1436
|
+
uint32_t y = x; /* 0: yes; 1..255: no */
|
1437
|
+
y -= 1; /* 4294967295: yes; 0..254: no */
|
1438
|
+
y >>= 31; /* 1: yes; 0: no */
|
1439
|
+
|
1440
|
+
return y;
|
1433
1441
|
}
|
1434
1442
|
|
1435
1443
|
static unsigned char negative(signed char b)
|
1436
1444
|
{
|
1437
|
-
|
1438
|
-
|
1439
|
-
|
1445
|
+
uint64_t x = b; /* 18446744073709551361..18446744073709551615: yes; 0..255: no */
|
1446
|
+
x >>= 63; /* 1: yes; 0: no */
|
1447
|
+
|
1448
|
+
return x;
|
1440
1449
|
}
|
1441
1450
|
|
1442
1451
|
static void cmov(ge_precomp *t,const ge_precomp *u,unsigned char b)
|
1443
1452
|
{
|
1444
|
-
|
1445
|
-
|
1446
|
-
|
1453
|
+
fe_cmov(t->yplusx,u->yplusx,b);
|
1454
|
+
fe_cmov(t->yminusx,u->yminusx,b);
|
1455
|
+
fe_cmov(t->xy2d,u->xy2d,b);
|
1447
1456
|
}
|
1448
1457
|
|
1449
1458
|
/* base[i][j] = (j+1)*256^i*B */
|
@@ -1453,28 +1462,28 @@ static const ge_precomp base[32][8] = {
|
|
1453
1462
|
|
1454
1463
|
static void ge_select(ge_precomp *t,int pos,signed char b)
|
1455
1464
|
{
|
1456
|
-
|
1457
|
-
|
1458
|
-
|
1459
|
-
|
1460
|
-
|
1461
|
-
|
1462
|
-
|
1463
|
-
|
1464
|
-
|
1465
|
-
|
1466
|
-
|
1467
|
-
|
1468
|
-
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1465
|
+
ge_precomp minust;
|
1466
|
+
unsigned char bnegative = negative(b);
|
1467
|
+
unsigned char babs = b - (((-bnegative) & b) * ((signed char) 1 << 1));
|
1468
|
+
|
1469
|
+
ge_precomp_0(t);
|
1470
|
+
cmov(t,&base[pos][0],equal(babs,1));
|
1471
|
+
cmov(t,&base[pos][1],equal(babs,2));
|
1472
|
+
cmov(t,&base[pos][2],equal(babs,3));
|
1473
|
+
cmov(t,&base[pos][3],equal(babs,4));
|
1474
|
+
cmov(t,&base[pos][4],equal(babs,5));
|
1475
|
+
cmov(t,&base[pos][5],equal(babs,6));
|
1476
|
+
cmov(t,&base[pos][6],equal(babs,7));
|
1477
|
+
cmov(t,&base[pos][7],equal(babs,8));
|
1478
|
+
fe_copy(minust.yplusx,t->yminusx);
|
1479
|
+
fe_copy(minust.yminusx,t->yplusx);
|
1480
|
+
fe_neg(minust.xy2d,t->xy2d);
|
1481
|
+
cmov(t,&minust,bnegative);
|
1473
1482
|
}
|
1474
1483
|
|
1475
1484
|
/*
|
1476
|
-
r = p - q
|
1477
|
-
*/
|
1485
|
+
r = p - q
|
1486
|
+
*/
|
1478
1487
|
|
1479
1488
|
void ge_sub(ge_p1p1 *r,const ge_p3 *p,const ge_cached *q)
|
1480
1489
|
{
|
@@ -1495,739 +1504,739 @@ void ge_sub(ge_p1p1 *r,const ge_p3 *p,const ge_cached *q)
|
|
1495
1504
|
|
1496
1505
|
void ge_tobytes(unsigned char *s,const ge_p2 *h)
|
1497
1506
|
{
|
1498
|
-
|
1499
|
-
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1505
|
-
|
1506
|
-
|
1507
|
+
fe recip;
|
1508
|
+
fe x;
|
1509
|
+
fe y;
|
1510
|
+
|
1511
|
+
fe_invert(recip,h->Z);
|
1512
|
+
fe_mul(x,h->X,recip);
|
1513
|
+
fe_mul(y,h->Y,recip);
|
1514
|
+
fe_tobytes(s,y);
|
1515
|
+
s[31] ^= fe_isnegative(x) << 7;
|
1507
1516
|
}
|
1508
1517
|
|
1509
1518
|
/*
|
1510
|
-
h = a * B
|
1511
|
-
where a = a[0]+256*a[1]+...+256^31 a[31]
|
1512
|
-
B is the Ed25519 base point (x,4/5) with x positive.
|
1513
|
-
|
1514
|
-
Preconditions:
|
1515
|
-
|
1516
|
-
*/
|
1519
|
+
h = a * B
|
1520
|
+
where a = a[0]+256*a[1]+...+256^31 a[31]
|
1521
|
+
B is the Ed25519 base point (x,4/5) with x positive.
|
1522
|
+
*
|
1523
|
+
Preconditions:
|
1524
|
+
a[31] <= 127
|
1525
|
+
*/
|
1517
1526
|
|
1518
1527
|
/*
|
1519
|
-
r = a * A + b * B
|
1520
|
-
where a = a[0]+256*a[1]+...+256^31 a[31].
|
1521
|
-
and b = b[0]+256*b[1]+...+256^31 b[31].
|
1522
|
-
B is the Ed25519 base point (x,4/5) with x positive.
|
1523
|
-
*/
|
1528
|
+
r = a * A + b * B
|
1529
|
+
where a = a[0]+256*a[1]+...+256^31 a[31].
|
1530
|
+
and b = b[0]+256*b[1]+...+256^31 b[31].
|
1531
|
+
B is the Ed25519 base point (x,4/5) with x positive.
|
1532
|
+
*/
|
1524
1533
|
|
1525
1534
|
void ge_double_scalarmult_vartime(ge_p2 *r,const unsigned char *a,const ge_p3 *A,const unsigned char *b)
|
1526
1535
|
{
|
1527
|
-
|
1528
|
-
|
1529
|
-
|
1530
|
-
|
1531
|
-
|
1532
|
-
|
1533
|
-
|
1534
|
-
|
1535
|
-
|
1536
|
-
|
1537
|
-
|
1538
|
-
|
1539
|
-
|
1540
|
-
|
1541
|
-
|
1542
|
-
|
1543
|
-
|
1544
|
-
|
1545
|
-
|
1546
|
-
|
1547
|
-
|
1548
|
-
ge_p2_0(r);
|
1549
|
-
|
1550
|
-
for (i = 255;i >= 0;--i) {
|
1551
|
-
if (aslide[i] || bslide[i]) break;
|
1552
|
-
}
|
1553
|
-
|
1554
|
-
for (;i >= 0;--i) {
|
1555
|
-
ge_p2_dbl(&t,r);
|
1556
|
-
|
1557
|
-
if (aslide[i] > 0) {
|
1558
|
-
ge_p1p1_to_p3(&u,&t);
|
1559
|
-
ge_add(&t,&u,&Ai[aslide[i]/2]);
|
1560
|
-
} else if (aslide[i] < 0) {
|
1561
|
-
ge_p1p1_to_p3(&u,&t);
|
1562
|
-
ge_sub(&t,&u,&Ai[(-aslide[i])/2]);
|
1563
|
-
}
|
1536
|
+
signed char aslide[256];
|
1537
|
+
signed char bslide[256];
|
1538
|
+
ge_cached Ai[8]; /* A,3A,5A,7A,9A,11A,13A,15A */
|
1539
|
+
ge_p1p1 t;
|
1540
|
+
ge_p3 u;
|
1541
|
+
ge_p3 A2;
|
1542
|
+
int i;
|
1543
|
+
|
1544
|
+
slide(aslide,a);
|
1545
|
+
slide(bslide,b);
|
1546
|
+
|
1547
|
+
ge_p3_to_cached(&Ai[0],A);
|
1548
|
+
ge_p3_dbl(&t,A); ge_p1p1_to_p3(&A2,&t);
|
1549
|
+
ge_add(&t,&A2,&Ai[0]); ge_p1p1_to_p3(&u,&t); ge_p3_to_cached(&Ai[1],&u);
|
1550
|
+
ge_add(&t,&A2,&Ai[1]); ge_p1p1_to_p3(&u,&t); ge_p3_to_cached(&Ai[2],&u);
|
1551
|
+
ge_add(&t,&A2,&Ai[2]); ge_p1p1_to_p3(&u,&t); ge_p3_to_cached(&Ai[3],&u);
|
1552
|
+
ge_add(&t,&A2,&Ai[3]); ge_p1p1_to_p3(&u,&t); ge_p3_to_cached(&Ai[4],&u);
|
1553
|
+
ge_add(&t,&A2,&Ai[4]); ge_p1p1_to_p3(&u,&t); ge_p3_to_cached(&Ai[5],&u);
|
1554
|
+
ge_add(&t,&A2,&Ai[5]); ge_p1p1_to_p3(&u,&t); ge_p3_to_cached(&Ai[6],&u);
|
1555
|
+
ge_add(&t,&A2,&Ai[6]); ge_p1p1_to_p3(&u,&t); ge_p3_to_cached(&Ai[7],&u);
|
1564
1556
|
|
1565
|
-
|
1566
|
-
|
1567
|
-
|
1568
|
-
|
1569
|
-
ge_p1p1_to_p3(&u,&t);
|
1570
|
-
ge_msub(&t,&u,&Bi[(-bslide[i])/2]);
|
1557
|
+
ge_p2_0(r);
|
1558
|
+
|
1559
|
+
for (i = 255;i >= 0;--i) {
|
1560
|
+
if (aslide[i] || bslide[i]) break;
|
1571
1561
|
}
|
1572
1562
|
|
1573
|
-
|
1574
|
-
|
1563
|
+
for (;i >= 0;--i) {
|
1564
|
+
ge_p2_dbl(&t,r);
|
1565
|
+
|
1566
|
+
if (aslide[i] > 0) {
|
1567
|
+
ge_p1p1_to_p3(&u,&t);
|
1568
|
+
ge_add(&t,&u,&Ai[aslide[i]/2]);
|
1569
|
+
} else if (aslide[i] < 0) {
|
1570
|
+
ge_p1p1_to_p3(&u,&t);
|
1571
|
+
ge_sub(&t,&u,&Ai[(-aslide[i])/2]);
|
1572
|
+
}
|
1573
|
+
|
1574
|
+
if (bslide[i] > 0) {
|
1575
|
+
ge_p1p1_to_p3(&u,&t);
|
1576
|
+
ge_madd(&t,&u,&Bi[bslide[i]/2]);
|
1577
|
+
} else if (bslide[i] < 0) {
|
1578
|
+
ge_p1p1_to_p3(&u,&t);
|
1579
|
+
ge_msub(&t,&u,&Bi[(-bslide[i])/2]);
|
1580
|
+
}
|
1581
|
+
|
1582
|
+
ge_p1p1_to_p2(r,&t);
|
1583
|
+
}
|
1575
1584
|
}
|
1576
1585
|
|
1577
1586
|
void ge_scalarmult_vartime(ge_p3 *r,const unsigned char *a,const ge_p3 *A)
|
1578
1587
|
{
|
1579
|
-
|
1580
|
-
|
1581
|
-
|
1582
|
-
|
1583
|
-
|
1584
|
-
|
1585
|
-
|
1586
|
-
|
1587
|
-
|
1588
|
-
|
1589
|
-
|
1590
|
-
|
1591
|
-
|
1592
|
-
|
1593
|
-
|
1594
|
-
|
1595
|
-
|
1596
|
-
|
1597
|
-
|
1598
|
-
|
1599
|
-
|
1600
|
-
|
1601
|
-
|
1602
|
-
}
|
1603
|
-
|
1604
|
-
for (;i >= 0;--i) {
|
1605
|
-
ge_p3_dbl(&t,r);
|
1606
|
-
|
1607
|
-
if (aslide[i] > 0) {
|
1608
|
-
ge_p1p1_to_p3(&u,&t);
|
1609
|
-
ge_add(&t,&u,&Ai[aslide[i]/2]);
|
1610
|
-
} else if (aslide[i] < 0) {
|
1611
|
-
ge_p1p1_to_p3(&u,&t);
|
1612
|
-
ge_sub(&t,&u,&Ai[(-aslide[i])/2]);
|
1588
|
+
signed char aslide[256];
|
1589
|
+
ge_cached Ai[8];
|
1590
|
+
ge_p1p1 t;
|
1591
|
+
ge_p3 u;
|
1592
|
+
ge_p3 A2;
|
1593
|
+
int i;
|
1594
|
+
|
1595
|
+
slide(aslide,a);
|
1596
|
+
|
1597
|
+
ge_p3_to_cached(&Ai[0],A);
|
1598
|
+
ge_p3_dbl(&t,A); ge_p1p1_to_p3(&A2,&t);
|
1599
|
+
ge_add(&t,&A2,&Ai[0]); ge_p1p1_to_p3(&u,&t); ge_p3_to_cached(&Ai[1],&u);
|
1600
|
+
ge_add(&t,&A2,&Ai[1]); ge_p1p1_to_p3(&u,&t); ge_p3_to_cached(&Ai[2],&u);
|
1601
|
+
ge_add(&t,&A2,&Ai[2]); ge_p1p1_to_p3(&u,&t); ge_p3_to_cached(&Ai[3],&u);
|
1602
|
+
ge_add(&t,&A2,&Ai[3]); ge_p1p1_to_p3(&u,&t); ge_p3_to_cached(&Ai[4],&u);
|
1603
|
+
ge_add(&t,&A2,&Ai[4]); ge_p1p1_to_p3(&u,&t); ge_p3_to_cached(&Ai[5],&u);
|
1604
|
+
ge_add(&t,&A2,&Ai[5]); ge_p1p1_to_p3(&u,&t); ge_p3_to_cached(&Ai[6],&u);
|
1605
|
+
ge_add(&t,&A2,&Ai[6]); ge_p1p1_to_p3(&u,&t); ge_p3_to_cached(&Ai[7],&u);
|
1606
|
+
|
1607
|
+
ge_p3_0(r);
|
1608
|
+
|
1609
|
+
for (i = 255;i >= 0;--i) {
|
1610
|
+
if (aslide[i]) break;
|
1613
1611
|
}
|
1614
1612
|
|
1615
|
-
|
1616
|
-
|
1613
|
+
for (;i >= 0;--i) {
|
1614
|
+
ge_p3_dbl(&t,r);
|
1615
|
+
|
1616
|
+
if (aslide[i] > 0) {
|
1617
|
+
ge_p1p1_to_p3(&u,&t);
|
1618
|
+
ge_add(&t,&u,&Ai[aslide[i]/2]);
|
1619
|
+
} else if (aslide[i] < 0) {
|
1620
|
+
ge_p1p1_to_p3(&u,&t);
|
1621
|
+
ge_sub(&t,&u,&Ai[(-aslide[i])/2]);
|
1622
|
+
}
|
1623
|
+
|
1624
|
+
ge_p1p1_to_p3(r,&t);
|
1625
|
+
}
|
1617
1626
|
}
|
1618
1627
|
|
1619
1628
|
void ge_scalarmult_base(ge_p3 *h,const unsigned char *a)
|
1620
1629
|
{
|
1621
|
-
|
1622
|
-
|
1623
|
-
|
1624
|
-
|
1625
|
-
|
1626
|
-
|
1627
|
-
|
1628
|
-
|
1629
|
-
|
1630
|
-
|
1631
|
-
|
1632
|
-
|
1633
|
-
|
1634
|
-
|
1635
|
-
|
1636
|
-
|
1637
|
-
|
1638
|
-
|
1639
|
-
|
1640
|
-
|
1641
|
-
|
1642
|
-
|
1643
|
-
|
1644
|
-
|
1645
|
-
|
1646
|
-
|
1647
|
-
|
1648
|
-
|
1649
|
-
|
1650
|
-
|
1651
|
-
|
1652
|
-
|
1653
|
-
|
1654
|
-
|
1655
|
-
|
1656
|
-
|
1657
|
-
|
1658
|
-
|
1659
|
-
|
1630
|
+
signed char e[64];
|
1631
|
+
signed char carry;
|
1632
|
+
ge_p1p1 r;
|
1633
|
+
ge_p2 s;
|
1634
|
+
ge_precomp t;
|
1635
|
+
int i;
|
1636
|
+
|
1637
|
+
for (i = 0;i < 32;++i) {
|
1638
|
+
e[2 * i + 0] = (a[i] >> 0) & 15;
|
1639
|
+
e[2 * i + 1] = (a[i] >> 4) & 15;
|
1640
|
+
}
|
1641
|
+
/* each e[i] is between 0 and 15 */
|
1642
|
+
/* e[63] is between 0 and 7 */
|
1643
|
+
|
1644
|
+
carry = 0;
|
1645
|
+
for (i = 0;i < 63;++i) {
|
1646
|
+
e[i] += carry;
|
1647
|
+
carry = e[i] + 8;
|
1648
|
+
carry >>= 4;
|
1649
|
+
e[i] -= carry * ((signed char) 1 << 4);
|
1650
|
+
}
|
1651
|
+
e[63] += carry;
|
1652
|
+
/* each e[i] is between -8 and 8 */
|
1653
|
+
|
1654
|
+
ge_p3_0(h);
|
1655
|
+
for (i = 1;i < 64;i += 2) {
|
1656
|
+
ge_select(&t,i / 2,e[i]);
|
1657
|
+
ge_madd(&r,h,&t); ge_p1p1_to_p3(h,&r);
|
1658
|
+
}
|
1659
|
+
|
1660
|
+
ge_p3_dbl(&r,h); ge_p1p1_to_p2(&s,&r);
|
1661
|
+
ge_p2_dbl(&r,&s); ge_p1p1_to_p2(&s,&r);
|
1662
|
+
ge_p2_dbl(&r,&s); ge_p1p1_to_p2(&s,&r);
|
1663
|
+
ge_p2_dbl(&r,&s); ge_p1p1_to_p3(h,&r);
|
1664
|
+
|
1665
|
+
for (i = 0;i < 64;i += 2) {
|
1666
|
+
ge_select(&t,i / 2,e[i]);
|
1667
|
+
ge_madd(&r,h,&t); ge_p1p1_to_p3(h,&r);
|
1668
|
+
}
|
1660
1669
|
}
|
1661
1670
|
|
1662
1671
|
/*
|
1663
|
-
Input:
|
1664
|
-
|
1665
|
-
|
1666
|
-
|
1667
|
-
|
1668
|
-
Output:
|
1669
|
-
|
1670
|
-
|
1671
|
-
*/
|
1672
|
+
Input:
|
1673
|
+
a[0]+256*a[1]+...+256^31*a[31] = a
|
1674
|
+
b[0]+256*b[1]+...+256^31*b[31] = b
|
1675
|
+
c[0]+256*c[1]+...+256^31*c[31] = c
|
1676
|
+
*
|
1677
|
+
Output:
|
1678
|
+
s[0]+256*s[1]+...+256^31*s[31] = (ab+c) mod l
|
1679
|
+
where l = 2^252 + 27742317777372353535851937790883648493.
|
1680
|
+
*/
|
1672
1681
|
|
1673
1682
|
void sc_muladd(unsigned char *s,const unsigned char *a,const unsigned char *b,const unsigned char *c)
|
1674
1683
|
{
|
1675
|
-
|
1676
|
-
|
1677
|
-
|
1678
|
-
|
1679
|
-
|
1680
|
-
|
1681
|
-
|
1682
|
-
|
1683
|
-
|
1684
|
-
|
1685
|
-
|
1686
|
-
|
1687
|
-
|
1688
|
-
|
1689
|
-
|
1690
|
-
|
1691
|
-
|
1692
|
-
|
1693
|
-
|
1694
|
-
|
1695
|
-
|
1696
|
-
|
1697
|
-
|
1698
|
-
|
1699
|
-
|
1700
|
-
|
1701
|
-
|
1702
|
-
|
1703
|
-
|
1704
|
-
|
1705
|
-
|
1706
|
-
|
1707
|
-
|
1708
|
-
|
1709
|
-
|
1710
|
-
|
1711
|
-
|
1712
|
-
|
1713
|
-
|
1714
|
-
|
1715
|
-
|
1716
|
-
|
1717
|
-
|
1718
|
-
|
1719
|
-
|
1720
|
-
|
1721
|
-
|
1722
|
-
|
1723
|
-
|
1724
|
-
|
1725
|
-
|
1726
|
-
|
1727
|
-
|
1728
|
-
|
1729
|
-
|
1730
|
-
|
1731
|
-
|
1732
|
-
|
1733
|
-
|
1734
|
-
|
1735
|
-
|
1736
|
-
|
1737
|
-
|
1738
|
-
|
1739
|
-
|
1740
|
-
|
1741
|
-
|
1742
|
-
|
1743
|
-
|
1744
|
-
|
1745
|
-
|
1746
|
-
|
1747
|
-
|
1748
|
-
|
1749
|
-
|
1750
|
-
|
1751
|
-
|
1752
|
-
|
1753
|
-
|
1754
|
-
|
1755
|
-
|
1756
|
-
|
1757
|
-
|
1758
|
-
|
1759
|
-
|
1760
|
-
|
1761
|
-
|
1762
|
-
|
1763
|
-
|
1764
|
-
|
1765
|
-
|
1766
|
-
|
1767
|
-
|
1768
|
-
|
1769
|
-
|
1770
|
-
|
1771
|
-
|
1772
|
-
|
1773
|
-
|
1774
|
-
|
1775
|
-
|
1776
|
-
|
1777
|
-
|
1778
|
-
|
1779
|
-
|
1780
|
-
|
1781
|
-
|
1782
|
-
|
1783
|
-
|
1784
|
-
|
1785
|
-
|
1786
|
-
|
1787
|
-
|
1788
|
-
|
1789
|
-
|
1790
|
-
|
1791
|
-
|
1792
|
-
|
1793
|
-
|
1794
|
-
|
1795
|
-
|
1796
|
-
|
1797
|
-
|
1798
|
-
|
1799
|
-
|
1800
|
-
|
1801
|
-
|
1802
|
-
|
1803
|
-
|
1804
|
-
|
1805
|
-
|
1806
|
-
|
1807
|
-
|
1808
|
-
|
1809
|
-
|
1810
|
-
|
1811
|
-
|
1812
|
-
|
1813
|
-
|
1814
|
-
|
1815
|
-
|
1816
|
-
|
1817
|
-
|
1818
|
-
|
1819
|
-
|
1820
|
-
|
1821
|
-
|
1822
|
-
|
1823
|
-
|
1824
|
-
|
1825
|
-
|
1826
|
-
|
1827
|
-
|
1828
|
-
|
1829
|
-
|
1830
|
-
|
1831
|
-
|
1832
|
-
|
1833
|
-
|
1834
|
-
|
1835
|
-
|
1836
|
-
|
1837
|
-
|
1838
|
-
|
1839
|
-
|
1840
|
-
|
1841
|
-
|
1842
|
-
|
1843
|
-
|
1844
|
-
|
1845
|
-
|
1846
|
-
|
1847
|
-
|
1848
|
-
|
1849
|
-
|
1850
|
-
|
1851
|
-
|
1852
|
-
|
1853
|
-
|
1854
|
-
|
1855
|
-
|
1856
|
-
|
1857
|
-
|
1858
|
-
|
1859
|
-
|
1860
|
-
|
1861
|
-
|
1862
|
-
|
1863
|
-
|
1864
|
-
|
1865
|
-
|
1866
|
-
|
1867
|
-
|
1868
|
-
|
1869
|
-
|
1870
|
-
|
1871
|
-
|
1872
|
-
|
1873
|
-
|
1874
|
-
|
1875
|
-
|
1876
|
-
|
1877
|
-
|
1878
|
-
|
1879
|
-
|
1880
|
-
|
1881
|
-
|
1882
|
-
|
1883
|
-
|
1884
|
-
|
1885
|
-
|
1886
|
-
|
1887
|
-
|
1888
|
-
|
1889
|
-
|
1890
|
-
|
1891
|
-
|
1892
|
-
|
1893
|
-
|
1894
|
-
|
1895
|
-
|
1896
|
-
|
1897
|
-
|
1898
|
-
|
1899
|
-
|
1900
|
-
|
1901
|
-
|
1902
|
-
|
1903
|
-
|
1904
|
-
|
1905
|
-
|
1906
|
-
|
1907
|
-
|
1908
|
-
|
1909
|
-
|
1910
|
-
|
1911
|
-
|
1912
|
-
|
1913
|
-
|
1914
|
-
|
1915
|
-
|
1916
|
-
|
1917
|
-
|
1918
|
-
|
1919
|
-
|
1920
|
-
|
1921
|
-
|
1922
|
-
|
1923
|
-
|
1924
|
-
|
1925
|
-
|
1926
|
-
|
1927
|
-
|
1928
|
-
|
1929
|
-
|
1930
|
-
|
1931
|
-
|
1932
|
-
|
1933
|
-
|
1934
|
-
|
1935
|
-
|
1936
|
-
|
1937
|
-
|
1938
|
-
|
1939
|
-
|
1940
|
-
|
1941
|
-
|
1942
|
-
|
1943
|
-
|
1944
|
-
|
1945
|
-
|
1946
|
-
|
1947
|
-
|
1948
|
-
|
1949
|
-
|
1950
|
-
|
1951
|
-
|
1952
|
-
|
1953
|
-
|
1954
|
-
|
1955
|
-
|
1956
|
-
|
1957
|
-
|
1958
|
-
|
1959
|
-
|
1960
|
-
|
1961
|
-
|
1962
|
-
|
1963
|
-
|
1964
|
-
|
1965
|
-
|
1966
|
-
|
1967
|
-
|
1968
|
-
|
1969
|
-
|
1970
|
-
|
1971
|
-
|
1972
|
-
|
1973
|
-
|
1974
|
-
|
1975
|
-
|
1976
|
-
|
1977
|
-
|
1978
|
-
|
1979
|
-
|
1980
|
-
|
1981
|
-
|
1982
|
-
|
1983
|
-
|
1984
|
-
|
1985
|
-
|
1986
|
-
|
1987
|
-
|
1988
|
-
|
1989
|
-
|
1990
|
-
|
1991
|
-
|
1992
|
-
|
1684
|
+
int64_t a0 = 2097151 & load_3(a);
|
1685
|
+
int64_t a1 = 2097151 & (load_4(a + 2) >> 5);
|
1686
|
+
int64_t a2 = 2097151 & (load_3(a + 5) >> 2);
|
1687
|
+
int64_t a3 = 2097151 & (load_4(a + 7) >> 7);
|
1688
|
+
int64_t a4 = 2097151 & (load_4(a + 10) >> 4);
|
1689
|
+
int64_t a5 = 2097151 & (load_3(a + 13) >> 1);
|
1690
|
+
int64_t a6 = 2097151 & (load_4(a + 15) >> 6);
|
1691
|
+
int64_t a7 = 2097151 & (load_3(a + 18) >> 3);
|
1692
|
+
int64_t a8 = 2097151 & load_3(a + 21);
|
1693
|
+
int64_t a9 = 2097151 & (load_4(a + 23) >> 5);
|
1694
|
+
int64_t a10 = 2097151 & (load_3(a + 26) >> 2);
|
1695
|
+
int64_t a11 = (load_4(a + 28) >> 7);
|
1696
|
+
int64_t b0 = 2097151 & load_3(b);
|
1697
|
+
int64_t b1 = 2097151 & (load_4(b + 2) >> 5);
|
1698
|
+
int64_t b2 = 2097151 & (load_3(b + 5) >> 2);
|
1699
|
+
int64_t b3 = 2097151 & (load_4(b + 7) >> 7);
|
1700
|
+
int64_t b4 = 2097151 & (load_4(b + 10) >> 4);
|
1701
|
+
int64_t b5 = 2097151 & (load_3(b + 13) >> 1);
|
1702
|
+
int64_t b6 = 2097151 & (load_4(b + 15) >> 6);
|
1703
|
+
int64_t b7 = 2097151 & (load_3(b + 18) >> 3);
|
1704
|
+
int64_t b8 = 2097151 & load_3(b + 21);
|
1705
|
+
int64_t b9 = 2097151 & (load_4(b + 23) >> 5);
|
1706
|
+
int64_t b10 = 2097151 & (load_3(b + 26) >> 2);
|
1707
|
+
int64_t b11 = (load_4(b + 28) >> 7);
|
1708
|
+
int64_t c0 = 2097151 & load_3(c);
|
1709
|
+
int64_t c1 = 2097151 & (load_4(c + 2) >> 5);
|
1710
|
+
int64_t c2 = 2097151 & (load_3(c + 5) >> 2);
|
1711
|
+
int64_t c3 = 2097151 & (load_4(c + 7) >> 7);
|
1712
|
+
int64_t c4 = 2097151 & (load_4(c + 10) >> 4);
|
1713
|
+
int64_t c5 = 2097151 & (load_3(c + 13) >> 1);
|
1714
|
+
int64_t c6 = 2097151 & (load_4(c + 15) >> 6);
|
1715
|
+
int64_t c7 = 2097151 & (load_3(c + 18) >> 3);
|
1716
|
+
int64_t c8 = 2097151 & load_3(c + 21);
|
1717
|
+
int64_t c9 = 2097151 & (load_4(c + 23) >> 5);
|
1718
|
+
int64_t c10 = 2097151 & (load_3(c + 26) >> 2);
|
1719
|
+
int64_t c11 = (load_4(c + 28) >> 7);
|
1720
|
+
int64_t s0;
|
1721
|
+
int64_t s1;
|
1722
|
+
int64_t s2;
|
1723
|
+
int64_t s3;
|
1724
|
+
int64_t s4;
|
1725
|
+
int64_t s5;
|
1726
|
+
int64_t s6;
|
1727
|
+
int64_t s7;
|
1728
|
+
int64_t s8;
|
1729
|
+
int64_t s9;
|
1730
|
+
int64_t s10;
|
1731
|
+
int64_t s11;
|
1732
|
+
int64_t s12;
|
1733
|
+
int64_t s13;
|
1734
|
+
int64_t s14;
|
1735
|
+
int64_t s15;
|
1736
|
+
int64_t s16;
|
1737
|
+
int64_t s17;
|
1738
|
+
int64_t s18;
|
1739
|
+
int64_t s19;
|
1740
|
+
int64_t s20;
|
1741
|
+
int64_t s21;
|
1742
|
+
int64_t s22;
|
1743
|
+
int64_t s23;
|
1744
|
+
int64_t carry0;
|
1745
|
+
int64_t carry1;
|
1746
|
+
int64_t carry2;
|
1747
|
+
int64_t carry3;
|
1748
|
+
int64_t carry4;
|
1749
|
+
int64_t carry5;
|
1750
|
+
int64_t carry6;
|
1751
|
+
int64_t carry7;
|
1752
|
+
int64_t carry8;
|
1753
|
+
int64_t carry9;
|
1754
|
+
int64_t carry10;
|
1755
|
+
int64_t carry11;
|
1756
|
+
int64_t carry12;
|
1757
|
+
int64_t carry13;
|
1758
|
+
int64_t carry14;
|
1759
|
+
int64_t carry15;
|
1760
|
+
int64_t carry16;
|
1761
|
+
int64_t carry17;
|
1762
|
+
int64_t carry18;
|
1763
|
+
int64_t carry19;
|
1764
|
+
int64_t carry20;
|
1765
|
+
int64_t carry21;
|
1766
|
+
int64_t carry22;
|
1767
|
+
|
1768
|
+
s0 = c0 + a0*b0;
|
1769
|
+
s1 = c1 + a0*b1 + a1*b0;
|
1770
|
+
s2 = c2 + a0*b2 + a1*b1 + a2*b0;
|
1771
|
+
s3 = c3 + a0*b3 + a1*b2 + a2*b1 + a3*b0;
|
1772
|
+
s4 = c4 + a0*b4 + a1*b3 + a2*b2 + a3*b1 + a4*b0;
|
1773
|
+
s5 = c5 + a0*b5 + a1*b4 + a2*b3 + a3*b2 + a4*b1 + a5*b0;
|
1774
|
+
s6 = c6 + a0*b6 + a1*b5 + a2*b4 + a3*b3 + a4*b2 + a5*b1 + a6*b0;
|
1775
|
+
s7 = c7 + a0*b7 + a1*b6 + a2*b5 + a3*b4 + a4*b3 + a5*b2 + a6*b1 + a7*b0;
|
1776
|
+
s8 = c8 + a0*b8 + a1*b7 + a2*b6 + a3*b5 + a4*b4 + a5*b3 + a6*b2 + a7*b1 + a8*b0;
|
1777
|
+
s9 = c9 + a0*b9 + a1*b8 + a2*b7 + a3*b6 + a4*b5 + a5*b4 + a6*b3 + a7*b2 + a8*b1 + a9*b0;
|
1778
|
+
s10 = c10 + a0*b10 + a1*b9 + a2*b8 + a3*b7 + a4*b6 + a5*b5 + a6*b4 + a7*b3 + a8*b2 + a9*b1 + a10*b0;
|
1779
|
+
s11 = c11 + a0*b11 + a1*b10 + a2*b9 + a3*b8 + a4*b7 + a5*b6 + a6*b5 + a7*b4 + a8*b3 + a9*b2 + a10*b1 + a11*b0;
|
1780
|
+
s12 = a1*b11 + a2*b10 + a3*b9 + a4*b8 + a5*b7 + a6*b6 + a7*b5 + a8*b4 + a9*b3 + a10*b2 + a11*b1;
|
1781
|
+
s13 = a2*b11 + a3*b10 + a4*b9 + a5*b8 + a6*b7 + a7*b6 + a8*b5 + a9*b4 + a10*b3 + a11*b2;
|
1782
|
+
s14 = a3*b11 + a4*b10 + a5*b9 + a6*b8 + a7*b7 + a8*b6 + a9*b5 + a10*b4 + a11*b3;
|
1783
|
+
s15 = a4*b11 + a5*b10 + a6*b9 + a7*b8 + a8*b7 + a9*b6 + a10*b5 + a11*b4;
|
1784
|
+
s16 = a5*b11 + a6*b10 + a7*b9 + a8*b8 + a9*b7 + a10*b6 + a11*b5;
|
1785
|
+
s17 = a6*b11 + a7*b10 + a8*b9 + a9*b8 + a10*b7 + a11*b6;
|
1786
|
+
s18 = a7*b11 + a8*b10 + a9*b9 + a10*b8 + a11*b7;
|
1787
|
+
s19 = a8*b11 + a9*b10 + a10*b9 + a11*b8;
|
1788
|
+
s20 = a9*b11 + a10*b10 + a11*b9;
|
1789
|
+
s21 = a10*b11 + a11*b10;
|
1790
|
+
s22 = a11*b11;
|
1791
|
+
s23 = 0;
|
1792
|
+
|
1793
|
+
carry0 = (s0 + (int64_t) (1L << 20)) >> 21; s1 += carry0; s0 -= carry0 * ((uint64_t) 1L << 21);
|
1794
|
+
carry2 = (s2 + (int64_t) (1L << 20)) >> 21; s3 += carry2; s2 -= carry2 * ((uint64_t) 1L << 21);
|
1795
|
+
carry4 = (s4 + (int64_t) (1L << 20)) >> 21; s5 += carry4; s4 -= carry4 * ((uint64_t) 1L << 21);
|
1796
|
+
carry6 = (s6 + (int64_t) (1L << 20)) >> 21; s7 += carry6; s6 -= carry6 * ((uint64_t) 1L << 21);
|
1797
|
+
carry8 = (s8 + (int64_t) (1L << 20)) >> 21; s9 += carry8; s8 -= carry8 * ((uint64_t) 1L << 21);
|
1798
|
+
carry10 = (s10 + (int64_t) (1L << 20)) >> 21; s11 += carry10; s10 -= carry10 * ((uint64_t) 1L << 21);
|
1799
|
+
carry12 = (s12 + (int64_t) (1L << 20)) >> 21; s13 += carry12; s12 -= carry12 * ((uint64_t) 1L << 21);
|
1800
|
+
carry14 = (s14 + (int64_t) (1L << 20)) >> 21; s15 += carry14; s14 -= carry14 * ((uint64_t) 1L << 21);
|
1801
|
+
carry16 = (s16 + (int64_t) (1L << 20)) >> 21; s17 += carry16; s16 -= carry16 * ((uint64_t) 1L << 21);
|
1802
|
+
carry18 = (s18 + (int64_t) (1L << 20)) >> 21; s19 += carry18; s18 -= carry18 * ((uint64_t) 1L << 21);
|
1803
|
+
carry20 = (s20 + (int64_t) (1L << 20)) >> 21; s21 += carry20; s20 -= carry20 * ((uint64_t) 1L << 21);
|
1804
|
+
carry22 = (s22 + (int64_t) (1L << 20)) >> 21; s23 += carry22; s22 -= carry22 * ((uint64_t) 1L << 21);
|
1805
|
+
|
1806
|
+
carry1 = (s1 + (int64_t) (1L << 20)) >> 21; s2 += carry1; s1 -= carry1 * ((uint64_t) 1L << 21);
|
1807
|
+
carry3 = (s3 + (int64_t) (1L << 20)) >> 21; s4 += carry3; s3 -= carry3 * ((uint64_t) 1L << 21);
|
1808
|
+
carry5 = (s5 + (int64_t) (1L << 20)) >> 21; s6 += carry5; s5 -= carry5 * ((uint64_t) 1L << 21);
|
1809
|
+
carry7 = (s7 + (int64_t) (1L << 20)) >> 21; s8 += carry7; s7 -= carry7 * ((uint64_t) 1L << 21);
|
1810
|
+
carry9 = (s9 + (int64_t) (1L << 20)) >> 21; s10 += carry9; s9 -= carry9 * ((uint64_t) 1L << 21);
|
1811
|
+
carry11 = (s11 + (int64_t) (1L << 20)) >> 21; s12 += carry11; s11 -= carry11 * ((uint64_t) 1L << 21);
|
1812
|
+
carry13 = (s13 + (int64_t) (1L << 20)) >> 21; s14 += carry13; s13 -= carry13 * ((uint64_t) 1L << 21);
|
1813
|
+
carry15 = (s15 + (int64_t) (1L << 20)) >> 21; s16 += carry15; s15 -= carry15 * ((uint64_t) 1L << 21);
|
1814
|
+
carry17 = (s17 + (int64_t) (1L << 20)) >> 21; s18 += carry17; s17 -= carry17 * ((uint64_t) 1L << 21);
|
1815
|
+
carry19 = (s19 + (int64_t) (1L << 20)) >> 21; s20 += carry19; s19 -= carry19 * ((uint64_t) 1L << 21);
|
1816
|
+
carry21 = (s21 + (int64_t) (1L << 20)) >> 21; s22 += carry21; s21 -= carry21 * ((uint64_t) 1L << 21);
|
1817
|
+
|
1818
|
+
s11 += s23 * 666643;
|
1819
|
+
s12 += s23 * 470296;
|
1820
|
+
s13 += s23 * 654183;
|
1821
|
+
s14 -= s23 * 997805;
|
1822
|
+
s15 += s23 * 136657;
|
1823
|
+
s16 -= s23 * 683901;
|
1824
|
+
|
1825
|
+
s10 += s22 * 666643;
|
1826
|
+
s11 += s22 * 470296;
|
1827
|
+
s12 += s22 * 654183;
|
1828
|
+
s13 -= s22 * 997805;
|
1829
|
+
s14 += s22 * 136657;
|
1830
|
+
s15 -= s22 * 683901;
|
1831
|
+
|
1832
|
+
s9 += s21 * 666643;
|
1833
|
+
s10 += s21 * 470296;
|
1834
|
+
s11 += s21 * 654183;
|
1835
|
+
s12 -= s21 * 997805;
|
1836
|
+
s13 += s21 * 136657;
|
1837
|
+
s14 -= s21 * 683901;
|
1838
|
+
|
1839
|
+
s8 += s20 * 666643;
|
1840
|
+
s9 += s20 * 470296;
|
1841
|
+
s10 += s20 * 654183;
|
1842
|
+
s11 -= s20 * 997805;
|
1843
|
+
s12 += s20 * 136657;
|
1844
|
+
s13 -= s20 * 683901;
|
1845
|
+
|
1846
|
+
s7 += s19 * 666643;
|
1847
|
+
s8 += s19 * 470296;
|
1848
|
+
s9 += s19 * 654183;
|
1849
|
+
s10 -= s19 * 997805;
|
1850
|
+
s11 += s19 * 136657;
|
1851
|
+
s12 -= s19 * 683901;
|
1852
|
+
|
1853
|
+
s6 += s18 * 666643;
|
1854
|
+
s7 += s18 * 470296;
|
1855
|
+
s8 += s18 * 654183;
|
1856
|
+
s9 -= s18 * 997805;
|
1857
|
+
s10 += s18 * 136657;
|
1858
|
+
s11 -= s18 * 683901;
|
1859
|
+
|
1860
|
+
carry6 = (s6 + (int64_t) (1L << 20)) >> 21; s7 += carry6; s6 -= carry6 * ((uint64_t) 1L << 21);
|
1861
|
+
carry8 = (s8 + (int64_t) (1L << 20)) >> 21; s9 += carry8; s8 -= carry8 * ((uint64_t) 1L << 21);
|
1862
|
+
carry10 = (s10 + (int64_t) (1L << 20)) >> 21; s11 += carry10; s10 -= carry10 * ((uint64_t) 1L << 21);
|
1863
|
+
carry12 = (s12 + (int64_t) (1L << 20)) >> 21; s13 += carry12; s12 -= carry12 * ((uint64_t) 1L << 21);
|
1864
|
+
carry14 = (s14 + (int64_t) (1L << 20)) >> 21; s15 += carry14; s14 -= carry14 * ((uint64_t) 1L << 21);
|
1865
|
+
carry16 = (s16 + (int64_t) (1L << 20)) >> 21; s17 += carry16; s16 -= carry16 * ((uint64_t) 1L << 21);
|
1866
|
+
|
1867
|
+
carry7 = (s7 + (int64_t) (1L << 20)) >> 21; s8 += carry7; s7 -= carry7 * ((uint64_t) 1L << 21);
|
1868
|
+
carry9 = (s9 + (int64_t) (1L << 20)) >> 21; s10 += carry9; s9 -= carry9 * ((uint64_t) 1L << 21);
|
1869
|
+
carry11 = (s11 + (int64_t) (1L << 20)) >> 21; s12 += carry11; s11 -= carry11 * ((uint64_t) 1L << 21);
|
1870
|
+
carry13 = (s13 + (int64_t) (1L << 20)) >> 21; s14 += carry13; s13 -= carry13 * ((uint64_t) 1L << 21);
|
1871
|
+
carry15 = (s15 + (int64_t) (1L << 20)) >> 21; s16 += carry15; s15 -= carry15 * ((uint64_t) 1L << 21);
|
1872
|
+
|
1873
|
+
s5 += s17 * 666643;
|
1874
|
+
s6 += s17 * 470296;
|
1875
|
+
s7 += s17 * 654183;
|
1876
|
+
s8 -= s17 * 997805;
|
1877
|
+
s9 += s17 * 136657;
|
1878
|
+
s10 -= s17 * 683901;
|
1879
|
+
|
1880
|
+
s4 += s16 * 666643;
|
1881
|
+
s5 += s16 * 470296;
|
1882
|
+
s6 += s16 * 654183;
|
1883
|
+
s7 -= s16 * 997805;
|
1884
|
+
s8 += s16 * 136657;
|
1885
|
+
s9 -= s16 * 683901;
|
1886
|
+
|
1887
|
+
s3 += s15 * 666643;
|
1888
|
+
s4 += s15 * 470296;
|
1889
|
+
s5 += s15 * 654183;
|
1890
|
+
s6 -= s15 * 997805;
|
1891
|
+
s7 += s15 * 136657;
|
1892
|
+
s8 -= s15 * 683901;
|
1893
|
+
|
1894
|
+
s2 += s14 * 666643;
|
1895
|
+
s3 += s14 * 470296;
|
1896
|
+
s4 += s14 * 654183;
|
1897
|
+
s5 -= s14 * 997805;
|
1898
|
+
s6 += s14 * 136657;
|
1899
|
+
s7 -= s14 * 683901;
|
1900
|
+
|
1901
|
+
s1 += s13 * 666643;
|
1902
|
+
s2 += s13 * 470296;
|
1903
|
+
s3 += s13 * 654183;
|
1904
|
+
s4 -= s13 * 997805;
|
1905
|
+
s5 += s13 * 136657;
|
1906
|
+
s6 -= s13 * 683901;
|
1907
|
+
|
1908
|
+
s0 += s12 * 666643;
|
1909
|
+
s1 += s12 * 470296;
|
1910
|
+
s2 += s12 * 654183;
|
1911
|
+
s3 -= s12 * 997805;
|
1912
|
+
s4 += s12 * 136657;
|
1913
|
+
s5 -= s12 * 683901;
|
1914
|
+
s12 = 0;
|
1915
|
+
|
1916
|
+
carry0 = (s0 + (int64_t) (1L << 20)) >> 21; s1 += carry0; s0 -= carry0 * ((uint64_t) 1L << 21);
|
1917
|
+
carry2 = (s2 + (int64_t) (1L << 20)) >> 21; s3 += carry2; s2 -= carry2 * ((uint64_t) 1L << 21);
|
1918
|
+
carry4 = (s4 + (int64_t) (1L << 20)) >> 21; s5 += carry4; s4 -= carry4 * ((uint64_t) 1L << 21);
|
1919
|
+
carry6 = (s6 + (int64_t) (1L << 20)) >> 21; s7 += carry6; s6 -= carry6 * ((uint64_t) 1L << 21);
|
1920
|
+
carry8 = (s8 + (int64_t) (1L << 20)) >> 21; s9 += carry8; s8 -= carry8 * ((uint64_t) 1L << 21);
|
1921
|
+
carry10 = (s10 + (int64_t) (1L << 20)) >> 21; s11 += carry10; s10 -= carry10 * ((uint64_t) 1L << 21);
|
1922
|
+
|
1923
|
+
carry1 = (s1 + (int64_t) (1L << 20)) >> 21; s2 += carry1; s1 -= carry1 * ((uint64_t) 1L << 21);
|
1924
|
+
carry3 = (s3 + (int64_t) (1L << 20)) >> 21; s4 += carry3; s3 -= carry3 * ((uint64_t) 1L << 21);
|
1925
|
+
carry5 = (s5 + (int64_t) (1L << 20)) >> 21; s6 += carry5; s5 -= carry5 * ((uint64_t) 1L << 21);
|
1926
|
+
carry7 = (s7 + (int64_t) (1L << 20)) >> 21; s8 += carry7; s7 -= carry7 * ((uint64_t) 1L << 21);
|
1927
|
+
carry9 = (s9 + (int64_t) (1L << 20)) >> 21; s10 += carry9; s9 -= carry9 * ((uint64_t) 1L << 21);
|
1928
|
+
carry11 = (s11 + (int64_t) (1L << 20)) >> 21; s12 += carry11; s11 -= carry11 * ((uint64_t) 1L << 21);
|
1929
|
+
|
1930
|
+
s0 += s12 * 666643;
|
1931
|
+
s1 += s12 * 470296;
|
1932
|
+
s2 += s12 * 654183;
|
1933
|
+
s3 -= s12 * 997805;
|
1934
|
+
s4 += s12 * 136657;
|
1935
|
+
s5 -= s12 * 683901;
|
1936
|
+
s12 = 0;
|
1937
|
+
|
1938
|
+
carry0 = s0 >> 21; s1 += carry0; s0 -= carry0 * ((uint64_t) 1L << 21);
|
1939
|
+
carry1 = s1 >> 21; s2 += carry1; s1 -= carry1 * ((uint64_t) 1L << 21);
|
1940
|
+
carry2 = s2 >> 21; s3 += carry2; s2 -= carry2 * ((uint64_t) 1L << 21);
|
1941
|
+
carry3 = s3 >> 21; s4 += carry3; s3 -= carry3 * ((uint64_t) 1L << 21);
|
1942
|
+
carry4 = s4 >> 21; s5 += carry4; s4 -= carry4 * ((uint64_t) 1L << 21);
|
1943
|
+
carry5 = s5 >> 21; s6 += carry5; s5 -= carry5 * ((uint64_t) 1L << 21);
|
1944
|
+
carry6 = s6 >> 21; s7 += carry6; s6 -= carry6 * ((uint64_t) 1L << 21);
|
1945
|
+
carry7 = s7 >> 21; s8 += carry7; s7 -= carry7 * ((uint64_t) 1L << 21);
|
1946
|
+
carry8 = s8 >> 21; s9 += carry8; s8 -= carry8 * ((uint64_t) 1L << 21);
|
1947
|
+
carry9 = s9 >> 21; s10 += carry9; s9 -= carry9 * ((uint64_t) 1L << 21);
|
1948
|
+
carry10 = s10 >> 21; s11 += carry10; s10 -= carry10 * ((uint64_t) 1L << 21);
|
1949
|
+
carry11 = s11 >> 21; s12 += carry11; s11 -= carry11 * ((uint64_t) 1L << 21);
|
1950
|
+
|
1951
|
+
s0 += s12 * 666643;
|
1952
|
+
s1 += s12 * 470296;
|
1953
|
+
s2 += s12 * 654183;
|
1954
|
+
s3 -= s12 * 997805;
|
1955
|
+
s4 += s12 * 136657;
|
1956
|
+
s5 -= s12 * 683901;
|
1957
|
+
|
1958
|
+
carry0 = s0 >> 21; s1 += carry0; s0 -= carry0 * ((uint64_t) 1L << 21);
|
1959
|
+
carry1 = s1 >> 21; s2 += carry1; s1 -= carry1 * ((uint64_t) 1L << 21);
|
1960
|
+
carry2 = s2 >> 21; s3 += carry2; s2 -= carry2 * ((uint64_t) 1L << 21);
|
1961
|
+
carry3 = s3 >> 21; s4 += carry3; s3 -= carry3 * ((uint64_t) 1L << 21);
|
1962
|
+
carry4 = s4 >> 21; s5 += carry4; s4 -= carry4 * ((uint64_t) 1L << 21);
|
1963
|
+
carry5 = s5 >> 21; s6 += carry5; s5 -= carry5 * ((uint64_t) 1L << 21);
|
1964
|
+
carry6 = s6 >> 21; s7 += carry6; s6 -= carry6 * ((uint64_t) 1L << 21);
|
1965
|
+
carry7 = s7 >> 21; s8 += carry7; s7 -= carry7 * ((uint64_t) 1L << 21);
|
1966
|
+
carry8 = s8 >> 21; s9 += carry8; s8 -= carry8 * ((uint64_t) 1L << 21);
|
1967
|
+
carry9 = s9 >> 21; s10 += carry9; s9 -= carry9 * ((uint64_t) 1L << 21);
|
1968
|
+
carry10 = s10 >> 21; s11 += carry10; s10 -= carry10 * ((uint64_t) 1L << 21);
|
1969
|
+
|
1970
|
+
s[0] = s0 >> 0;
|
1971
|
+
s[1] = s0 >> 8;
|
1972
|
+
s[2] = (s0 >> 16) | (s1 * ((uint64_t) 1 << 5));
|
1973
|
+
s[3] = s1 >> 3;
|
1974
|
+
s[4] = s1 >> 11;
|
1975
|
+
s[5] = (s1 >> 19) | (s2 * ((uint64_t) 1 << 2));
|
1976
|
+
s[6] = s2 >> 6;
|
1977
|
+
s[7] = (s2 >> 14) | (s3 * ((uint64_t) 1 << 7));
|
1978
|
+
s[8] = s3 >> 1;
|
1979
|
+
s[9] = s3 >> 9;
|
1980
|
+
s[10] = (s3 >> 17) | (s4 * ((uint64_t) 1 << 4));
|
1981
|
+
s[11] = s4 >> 4;
|
1982
|
+
s[12] = s4 >> 12;
|
1983
|
+
s[13] = (s4 >> 20) | (s5 * ((uint64_t) 1 << 1));
|
1984
|
+
s[14] = s5 >> 7;
|
1985
|
+
s[15] = (s5 >> 15) | (s6 * ((uint64_t) 1 << 6));
|
1986
|
+
s[16] = s6 >> 2;
|
1987
|
+
s[17] = s6 >> 10;
|
1988
|
+
s[18] = (s6 >> 18) | (s7 * ((uint64_t) 1 << 3));
|
1989
|
+
s[19] = s7 >> 5;
|
1990
|
+
s[20] = s7 >> 13;
|
1991
|
+
s[21] = s8 >> 0;
|
1992
|
+
s[22] = s8 >> 8;
|
1993
|
+
s[23] = (s8 >> 16) | (s9 * ((uint64_t) 1 << 5));
|
1994
|
+
s[24] = s9 >> 3;
|
1995
|
+
s[25] = s9 >> 11;
|
1996
|
+
s[26] = (s9 >> 19) | (s10 * ((uint64_t) 1 << 2));
|
1997
|
+
s[27] = s10 >> 6;
|
1998
|
+
s[28] = (s10 >> 14) | (s11 * ((uint64_t) 1 << 7));
|
1999
|
+
s[29] = s11 >> 1;
|
2000
|
+
s[30] = s11 >> 9;
|
2001
|
+
s[31] = s11 >> 17;
|
1993
2002
|
}
|
1994
2003
|
|
1995
2004
|
/*
|
1996
|
-
Input:
|
1997
|
-
|
1998
|
-
|
1999
|
-
Output:
|
2000
|
-
|
2001
|
-
|
2002
|
-
|
2003
|
-
*/
|
2005
|
+
Input:
|
2006
|
+
s[0]+256*s[1]+...+256^63*s[63] = s
|
2007
|
+
*
|
2008
|
+
Output:
|
2009
|
+
s[0]+256*s[1]+...+256^31*s[31] = s mod l
|
2010
|
+
where l = 2^252 + 27742317777372353535851937790883648493.
|
2011
|
+
Overwrites s in place.
|
2012
|
+
*/
|
2004
2013
|
|
2005
2014
|
void sc_reduce(unsigned char *s)
|
2006
2015
|
{
|
2007
|
-
|
2008
|
-
|
2009
|
-
|
2010
|
-
|
2011
|
-
|
2012
|
-
|
2013
|
-
|
2014
|
-
|
2015
|
-
|
2016
|
-
|
2017
|
-
|
2018
|
-
|
2019
|
-
|
2020
|
-
|
2021
|
-
|
2022
|
-
|
2023
|
-
|
2024
|
-
|
2025
|
-
|
2026
|
-
|
2027
|
-
|
2028
|
-
|
2029
|
-
|
2030
|
-
|
2031
|
-
|
2032
|
-
|
2033
|
-
|
2034
|
-
|
2035
|
-
|
2036
|
-
|
2037
|
-
|
2038
|
-
|
2039
|
-
|
2040
|
-
|
2041
|
-
|
2042
|
-
|
2043
|
-
|
2044
|
-
|
2045
|
-
|
2046
|
-
|
2047
|
-
|
2048
|
-
|
2049
|
-
|
2050
|
-
|
2051
|
-
|
2052
|
-
|
2053
|
-
|
2054
|
-
|
2055
|
-
|
2056
|
-
|
2057
|
-
|
2058
|
-
|
2059
|
-
|
2060
|
-
|
2061
|
-
|
2062
|
-
|
2063
|
-
|
2064
|
-
|
2065
|
-
|
2066
|
-
|
2067
|
-
|
2068
|
-
|
2069
|
-
|
2070
|
-
|
2071
|
-
|
2072
|
-
|
2073
|
-
|
2074
|
-
|
2075
|
-
|
2076
|
-
|
2077
|
-
|
2078
|
-
|
2079
|
-
|
2080
|
-
|
2081
|
-
|
2082
|
-
|
2083
|
-
|
2084
|
-
|
2085
|
-
|
2086
|
-
|
2087
|
-
|
2088
|
-
|
2089
|
-
|
2016
|
+
int64_t s0 = 2097151 & load_3(s);
|
2017
|
+
int64_t s1 = 2097151 & (load_4(s + 2) >> 5);
|
2018
|
+
int64_t s2 = 2097151 & (load_3(s + 5) >> 2);
|
2019
|
+
int64_t s3 = 2097151 & (load_4(s + 7) >> 7);
|
2020
|
+
int64_t s4 = 2097151 & (load_4(s + 10) >> 4);
|
2021
|
+
int64_t s5 = 2097151 & (load_3(s + 13) >> 1);
|
2022
|
+
int64_t s6 = 2097151 & (load_4(s + 15) >> 6);
|
2023
|
+
int64_t s7 = 2097151 & (load_3(s + 18) >> 3);
|
2024
|
+
int64_t s8 = 2097151 & load_3(s + 21);
|
2025
|
+
int64_t s9 = 2097151 & (load_4(s + 23) >> 5);
|
2026
|
+
int64_t s10 = 2097151 & (load_3(s + 26) >> 2);
|
2027
|
+
int64_t s11 = 2097151 & (load_4(s + 28) >> 7);
|
2028
|
+
int64_t s12 = 2097151 & (load_4(s + 31) >> 4);
|
2029
|
+
int64_t s13 = 2097151 & (load_3(s + 34) >> 1);
|
2030
|
+
int64_t s14 = 2097151 & (load_4(s + 36) >> 6);
|
2031
|
+
int64_t s15 = 2097151 & (load_3(s + 39) >> 3);
|
2032
|
+
int64_t s16 = 2097151 & load_3(s + 42);
|
2033
|
+
int64_t s17 = 2097151 & (load_4(s + 44) >> 5);
|
2034
|
+
int64_t s18 = 2097151 & (load_3(s + 47) >> 2);
|
2035
|
+
int64_t s19 = 2097151 & (load_4(s + 49) >> 7);
|
2036
|
+
int64_t s20 = 2097151 & (load_4(s + 52) >> 4);
|
2037
|
+
int64_t s21 = 2097151 & (load_3(s + 55) >> 1);
|
2038
|
+
int64_t s22 = 2097151 & (load_4(s + 57) >> 6);
|
2039
|
+
int64_t s23 = (load_4(s + 60) >> 3);
|
2040
|
+
int64_t carry0;
|
2041
|
+
int64_t carry1;
|
2042
|
+
int64_t carry2;
|
2043
|
+
int64_t carry3;
|
2044
|
+
int64_t carry4;
|
2045
|
+
int64_t carry5;
|
2046
|
+
int64_t carry6;
|
2047
|
+
int64_t carry7;
|
2048
|
+
int64_t carry8;
|
2049
|
+
int64_t carry9;
|
2050
|
+
int64_t carry10;
|
2051
|
+
int64_t carry11;
|
2052
|
+
int64_t carry12;
|
2053
|
+
int64_t carry13;
|
2054
|
+
int64_t carry14;
|
2055
|
+
int64_t carry15;
|
2056
|
+
int64_t carry16;
|
2057
|
+
|
2058
|
+
s11 += s23 * 666643;
|
2059
|
+
s12 += s23 * 470296;
|
2060
|
+
s13 += s23 * 654183;
|
2061
|
+
s14 -= s23 * 997805;
|
2062
|
+
s15 += s23 * 136657;
|
2063
|
+
s16 -= s23 * 683901;
|
2064
|
+
|
2065
|
+
s10 += s22 * 666643;
|
2066
|
+
s11 += s22 * 470296;
|
2067
|
+
s12 += s22 * 654183;
|
2068
|
+
s13 -= s22 * 997805;
|
2069
|
+
s14 += s22 * 136657;
|
2070
|
+
s15 -= s22 * 683901;
|
2071
|
+
|
2072
|
+
s9 += s21 * 666643;
|
2073
|
+
s10 += s21 * 470296;
|
2074
|
+
s11 += s21 * 654183;
|
2075
|
+
s12 -= s21 * 997805;
|
2076
|
+
s13 += s21 * 136657;
|
2077
|
+
s14 -= s21 * 683901;
|
2078
|
+
|
2079
|
+
s8 += s20 * 666643;
|
2080
|
+
s9 += s20 * 470296;
|
2081
|
+
s10 += s20 * 654183;
|
2082
|
+
s11 -= s20 * 997805;
|
2083
|
+
s12 += s20 * 136657;
|
2084
|
+
s13 -= s20 * 683901;
|
2085
|
+
|
2086
|
+
s7 += s19 * 666643;
|
2087
|
+
s8 += s19 * 470296;
|
2088
|
+
s9 += s19 * 654183;
|
2089
|
+
s10 -= s19 * 997805;
|
2090
|
+
s11 += s19 * 136657;
|
2091
|
+
s12 -= s19 * 683901;
|
2092
|
+
|
2093
|
+
s6 += s18 * 666643;
|
2094
|
+
s7 += s18 * 470296;
|
2095
|
+
s8 += s18 * 654183;
|
2096
|
+
s9 -= s18 * 997805;
|
2097
|
+
s10 += s18 * 136657;
|
2098
|
+
s11 -= s18 * 683901;
|
2090
2099
|
|
2091
2100
|
carry6 = (s6 + (int64_t) (1L << 20)) >> 21; s7 += carry6; s6 -= carry6 * ((uint64_t) 1L << 21);
|
2092
|
-
|
2093
|
-
|
2094
|
-
|
2095
|
-
|
2096
|
-
|
2097
|
-
|
2098
|
-
|
2099
|
-
|
2100
|
-
|
2101
|
-
|
2102
|
-
|
2103
|
-
|
2104
|
-
|
2105
|
-
|
2106
|
-
|
2107
|
-
|
2108
|
-
|
2109
|
-
|
2110
|
-
|
2111
|
-
|
2112
|
-
|
2113
|
-
|
2114
|
-
|
2115
|
-
|
2116
|
-
|
2117
|
-
|
2118
|
-
|
2119
|
-
|
2120
|
-
|
2121
|
-
|
2122
|
-
|
2123
|
-
|
2124
|
-
|
2125
|
-
|
2126
|
-
|
2127
|
-
|
2128
|
-
|
2129
|
-
|
2130
|
-
|
2131
|
-
|
2132
|
-
|
2133
|
-
|
2134
|
-
|
2135
|
-
|
2136
|
-
|
2137
|
-
|
2138
|
-
|
2139
|
-
|
2140
|
-
|
2141
|
-
|
2142
|
-
|
2143
|
-
|
2144
|
-
|
2145
|
-
|
2146
|
-
|
2147
|
-
|
2148
|
-
|
2149
|
-
|
2150
|
-
|
2151
|
-
|
2152
|
-
|
2153
|
-
|
2154
|
-
|
2155
|
-
|
2156
|
-
|
2157
|
-
|
2158
|
-
|
2159
|
-
|
2160
|
-
|
2161
|
-
|
2162
|
-
|
2163
|
-
|
2164
|
-
|
2165
|
-
|
2166
|
-
|
2167
|
-
|
2168
|
-
|
2169
|
-
|
2170
|
-
|
2171
|
-
|
2172
|
-
|
2173
|
-
|
2174
|
-
|
2175
|
-
|
2176
|
-
|
2177
|
-
|
2178
|
-
|
2179
|
-
|
2180
|
-
|
2181
|
-
|
2182
|
-
|
2183
|
-
|
2184
|
-
|
2185
|
-
|
2186
|
-
|
2187
|
-
|
2188
|
-
|
2189
|
-
|
2190
|
-
|
2191
|
-
|
2192
|
-
|
2193
|
-
|
2194
|
-
|
2195
|
-
|
2196
|
-
|
2197
|
-
|
2198
|
-
|
2199
|
-
|
2200
|
-
|
2201
|
-
|
2202
|
-
|
2203
|
-
|
2204
|
-
|
2205
|
-
|
2206
|
-
|
2207
|
-
|
2208
|
-
|
2209
|
-
|
2210
|
-
|
2211
|
-
|
2212
|
-
|
2213
|
-
|
2214
|
-
|
2215
|
-
|
2216
|
-
|
2217
|
-
|
2218
|
-
|
2219
|
-
|
2220
|
-
|
2221
|
-
|
2222
|
-
|
2223
|
-
|
2224
|
-
|
2225
|
-
|
2226
|
-
|
2227
|
-
|
2228
|
-
|
2229
|
-
|
2230
|
-
|
2231
|
-
|
2232
|
-
|
2101
|
+
carry8 = (s8 + (int64_t) (1L << 20)) >> 21; s9 += carry8; s8 -= carry8 * ((uint64_t) 1L << 21);
|
2102
|
+
carry10 = (s10 + (int64_t) (1L << 20)) >> 21; s11 += carry10; s10 -= carry10 * ((uint64_t) 1L << 21);
|
2103
|
+
carry12 = (s12 + (int64_t) (1L << 20)) >> 21; s13 += carry12; s12 -= carry12 * ((uint64_t) 1L << 21);
|
2104
|
+
carry14 = (s14 + (int64_t) (1L << 20)) >> 21; s15 += carry14; s14 -= carry14 * ((uint64_t) 1L << 21);
|
2105
|
+
carry16 = (s16 + (int64_t) (1L << 20)) >> 21; s17 += carry16; s16 -= carry16 * ((uint64_t) 1L << 21);
|
2106
|
+
|
2107
|
+
carry7 = (s7 + (int64_t) (1L << 20)) >> 21; s8 += carry7; s7 -= carry7 * ((uint64_t) 1L << 21);
|
2108
|
+
carry9 = (s9 + (int64_t) (1L << 20)) >> 21; s10 += carry9; s9 -= carry9 * ((uint64_t) 1L << 21);
|
2109
|
+
carry11 = (s11 + (int64_t) (1L << 20)) >> 21; s12 += carry11; s11 -= carry11 * ((uint64_t) 1L << 21);
|
2110
|
+
carry13 = (s13 + (int64_t) (1L << 20)) >> 21; s14 += carry13; s13 -= carry13 * ((uint64_t) 1L << 21);
|
2111
|
+
carry15 = (s15 + (int64_t) (1L << 20)) >> 21; s16 += carry15; s15 -= carry15 * ((uint64_t) 1L << 21);
|
2112
|
+
|
2113
|
+
s5 += s17 * 666643;
|
2114
|
+
s6 += s17 * 470296;
|
2115
|
+
s7 += s17 * 654183;
|
2116
|
+
s8 -= s17 * 997805;
|
2117
|
+
s9 += s17 * 136657;
|
2118
|
+
s10 -= s17 * 683901;
|
2119
|
+
|
2120
|
+
s4 += s16 * 666643;
|
2121
|
+
s5 += s16 * 470296;
|
2122
|
+
s6 += s16 * 654183;
|
2123
|
+
s7 -= s16 * 997805;
|
2124
|
+
s8 += s16 * 136657;
|
2125
|
+
s9 -= s16 * 683901;
|
2126
|
+
|
2127
|
+
s3 += s15 * 666643;
|
2128
|
+
s4 += s15 * 470296;
|
2129
|
+
s5 += s15 * 654183;
|
2130
|
+
s6 -= s15 * 997805;
|
2131
|
+
s7 += s15 * 136657;
|
2132
|
+
s8 -= s15 * 683901;
|
2133
|
+
|
2134
|
+
s2 += s14 * 666643;
|
2135
|
+
s3 += s14 * 470296;
|
2136
|
+
s4 += s14 * 654183;
|
2137
|
+
s5 -= s14 * 997805;
|
2138
|
+
s6 += s14 * 136657;
|
2139
|
+
s7 -= s14 * 683901;
|
2140
|
+
|
2141
|
+
s1 += s13 * 666643;
|
2142
|
+
s2 += s13 * 470296;
|
2143
|
+
s3 += s13 * 654183;
|
2144
|
+
s4 -= s13 * 997805;
|
2145
|
+
s5 += s13 * 136657;
|
2146
|
+
s6 -= s13 * 683901;
|
2147
|
+
|
2148
|
+
s0 += s12 * 666643;
|
2149
|
+
s1 += s12 * 470296;
|
2150
|
+
s2 += s12 * 654183;
|
2151
|
+
s3 -= s12 * 997805;
|
2152
|
+
s4 += s12 * 136657;
|
2153
|
+
s5 -= s12 * 683901;
|
2154
|
+
s12 = 0;
|
2155
|
+
|
2156
|
+
carry0 = (s0 + (int64_t) (1L << 20)) >> 21; s1 += carry0; s0 -= carry0 * ((uint64_t) 1L << 21);
|
2157
|
+
carry2 = (s2 + (int64_t) (1L << 20)) >> 21; s3 += carry2; s2 -= carry2 * ((uint64_t) 1L << 21);
|
2158
|
+
carry4 = (s4 + (int64_t) (1L << 20)) >> 21; s5 += carry4; s4 -= carry4 * ((uint64_t) 1L << 21);
|
2159
|
+
carry6 = (s6 + (int64_t) (1L << 20)) >> 21; s7 += carry6; s6 -= carry6 * ((uint64_t) 1L << 21);
|
2160
|
+
carry8 = (s8 + (int64_t) (1L << 20)) >> 21; s9 += carry8; s8 -= carry8 * ((uint64_t) 1L << 21);
|
2161
|
+
carry10 = (s10 + (int64_t) (1L << 20)) >> 21; s11 += carry10; s10 -= carry10 * ((uint64_t) 1L << 21);
|
2162
|
+
|
2163
|
+
carry1 = (s1 + (int64_t) (1L << 20)) >> 21; s2 += carry1; s1 -= carry1 * ((uint64_t) 1L << 21);
|
2164
|
+
carry3 = (s3 + (int64_t) (1L << 20)) >> 21; s4 += carry3; s3 -= carry3 * ((uint64_t) 1L << 21);
|
2165
|
+
carry5 = (s5 + (int64_t) (1L << 20)) >> 21; s6 += carry5; s5 -= carry5 * ((uint64_t) 1L << 21);
|
2166
|
+
carry7 = (s7 + (int64_t) (1L << 20)) >> 21; s8 += carry7; s7 -= carry7 * ((uint64_t) 1L << 21);
|
2167
|
+
carry9 = (s9 + (int64_t) (1L << 20)) >> 21; s10 += carry9; s9 -= carry9 * ((uint64_t) 1L << 21);
|
2168
|
+
carry11 = (s11 + (int64_t) (1L << 20)) >> 21; s12 += carry11; s11 -= carry11 * ((uint64_t) 1L << 21);
|
2169
|
+
|
2170
|
+
s0 += s12 * 666643;
|
2171
|
+
s1 += s12 * 470296;
|
2172
|
+
s2 += s12 * 654183;
|
2173
|
+
s3 -= s12 * 997805;
|
2174
|
+
s4 += s12 * 136657;
|
2175
|
+
s5 -= s12 * 683901;
|
2176
|
+
s12 = 0;
|
2177
|
+
|
2178
|
+
carry0 = s0 >> 21; s1 += carry0; s0 -= carry0 * ((uint64_t) 1L << 21);
|
2179
|
+
carry1 = s1 >> 21; s2 += carry1; s1 -= carry1 * ((uint64_t) 1L << 21);
|
2180
|
+
carry2 = s2 >> 21; s3 += carry2; s2 -= carry2 * ((uint64_t) 1L << 21);
|
2181
|
+
carry3 = s3 >> 21; s4 += carry3; s3 -= carry3 * ((uint64_t) 1L << 21);
|
2182
|
+
carry4 = s4 >> 21; s5 += carry4; s4 -= carry4 * ((uint64_t) 1L << 21);
|
2183
|
+
carry5 = s5 >> 21; s6 += carry5; s5 -= carry5 * ((uint64_t) 1L << 21);
|
2184
|
+
carry6 = s6 >> 21; s7 += carry6; s6 -= carry6 * ((uint64_t) 1L << 21);
|
2185
|
+
carry7 = s7 >> 21; s8 += carry7; s7 -= carry7 * ((uint64_t) 1L << 21);
|
2186
|
+
carry8 = s8 >> 21; s9 += carry8; s8 -= carry8 * ((uint64_t) 1L << 21);
|
2187
|
+
carry9 = s9 >> 21; s10 += carry9; s9 -= carry9 * ((uint64_t) 1L << 21);
|
2188
|
+
carry10 = s10 >> 21; s11 += carry10; s10 -= carry10 * ((uint64_t) 1L << 21);
|
2189
|
+
carry11 = s11 >> 21; s12 += carry11; s11 -= carry11 * ((uint64_t) 1L << 21);
|
2190
|
+
|
2191
|
+
s0 += s12 * 666643;
|
2192
|
+
s1 += s12 * 470296;
|
2193
|
+
s2 += s12 * 654183;
|
2194
|
+
s3 -= s12 * 997805;
|
2195
|
+
s4 += s12 * 136657;
|
2196
|
+
s5 -= s12 * 683901;
|
2197
|
+
|
2198
|
+
carry0 = s0 >> 21; s1 += carry0; s0 -= carry0 * ((uint64_t) 1L << 21);
|
2199
|
+
carry1 = s1 >> 21; s2 += carry1; s1 -= carry1 * ((uint64_t) 1L << 21);
|
2200
|
+
carry2 = s2 >> 21; s3 += carry2; s2 -= carry2 * ((uint64_t) 1L << 21);
|
2201
|
+
carry3 = s3 >> 21; s4 += carry3; s3 -= carry3 * ((uint64_t) 1L << 21);
|
2202
|
+
carry4 = s4 >> 21; s5 += carry4; s4 -= carry4 * ((uint64_t) 1L << 21);
|
2203
|
+
carry5 = s5 >> 21; s6 += carry5; s5 -= carry5 * ((uint64_t) 1L << 21);
|
2204
|
+
carry6 = s6 >> 21; s7 += carry6; s6 -= carry6 * ((uint64_t) 1L << 21);
|
2205
|
+
carry7 = s7 >> 21; s8 += carry7; s7 -= carry7 * ((uint64_t) 1L << 21);
|
2206
|
+
carry8 = s8 >> 21; s9 += carry8; s8 -= carry8 * ((uint64_t) 1L << 21);
|
2207
|
+
carry9 = s9 >> 21; s10 += carry9; s9 -= carry9 * ((uint64_t) 1L << 21);
|
2208
|
+
carry10 = s10 >> 21; s11 += carry10; s10 -= carry10 * ((uint64_t) 1L << 21);
|
2209
|
+
|
2210
|
+
s[0] = s0 >> 0;
|
2211
|
+
s[1] = s0 >> 8;
|
2212
|
+
s[2] = (s0 >> 16) | (s1 * ((uint64_t) 1 << 5));
|
2213
|
+
s[3] = s1 >> 3;
|
2214
|
+
s[4] = s1 >> 11;
|
2215
|
+
s[5] = (s1 >> 19) | (s2 * ((uint64_t) 1 << 2));
|
2216
|
+
s[6] = s2 >> 6;
|
2217
|
+
s[7] = (s2 >> 14) | (s3 * ((uint64_t) 1 << 7));
|
2218
|
+
s[8] = s3 >> 1;
|
2219
|
+
s[9] = s3 >> 9;
|
2220
|
+
s[10] = (s3 >> 17) | (s4 * ((uint64_t) 1 << 4));
|
2221
|
+
s[11] = s4 >> 4;
|
2222
|
+
s[12] = s4 >> 12;
|
2223
|
+
s[13] = (s4 >> 20) | (s5 * ((uint64_t) 1 << 1));
|
2224
|
+
s[14] = s5 >> 7;
|
2225
|
+
s[15] = (s5 >> 15) | (s6 * ((uint64_t) 1 << 6));
|
2226
|
+
s[16] = s6 >> 2;
|
2227
|
+
s[17] = s6 >> 10;
|
2228
|
+
s[18] = (s6 >> 18) | (s7 * ((uint64_t) 1 << 3));
|
2229
|
+
s[19] = s7 >> 5;
|
2230
|
+
s[20] = s7 >> 13;
|
2231
|
+
s[21] = s8 >> 0;
|
2232
|
+
s[22] = s8 >> 8;
|
2233
|
+
s[23] = (s8 >> 16) | (s9 * ((uint64_t) 1 << 5));
|
2234
|
+
s[24] = s9 >> 3;
|
2235
|
+
s[25] = s9 >> 11;
|
2236
|
+
s[26] = (s9 >> 19) | (s10 * ((uint64_t) 1 << 2));
|
2237
|
+
s[27] = s10 >> 6;
|
2238
|
+
s[28] = (s10 >> 14) | (s11 * ((uint64_t) 1 << 7));
|
2239
|
+
s[29] = s11 >> 1;
|
2240
|
+
s[30] = s11 >> 9;
|
2241
|
+
s[31] = s11 >> 17;
|
2233
2242
|
}
|