rbnacl-libsodium 1.0.11 → 1.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (465) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +4 -0
  3. data/lib/rbnacl/libsodium/version.rb +1 -1
  4. data/vendor/libsodium/AUTHORS +45 -33
  5. data/vendor/libsodium/ChangeLog +63 -2
  6. data/vendor/libsodium/LICENSE +1 -1
  7. data/vendor/libsodium/Makefile.am +1 -0
  8. data/vendor/libsodium/Makefile.in +17 -14
  9. data/vendor/libsodium/README.markdown +1 -0
  10. data/vendor/libsodium/THANKS +38 -4
  11. data/vendor/libsodium/aclocal.m4 +25 -24
  12. data/vendor/libsodium/autogen.sh +12 -7
  13. data/vendor/libsodium/autom4te.cache/output.0 +5066 -2281
  14. data/vendor/libsodium/autom4te.cache/output.1 +1013 -600
  15. data/vendor/libsodium/autom4te.cache/output.2 +5066 -2281
  16. data/vendor/libsodium/autom4te.cache/requests +426 -1584
  17. data/vendor/libsodium/autom4te.cache/traces.0 +2044 -876
  18. data/vendor/libsodium/autom4te.cache/traces.1 +996 -523
  19. data/vendor/libsodium/autom4te.cache/traces.2 +1996 -828
  20. data/vendor/libsodium/build-aux/compile +5 -4
  21. data/vendor/libsodium/build-aux/config.guess +120 -68
  22. data/vendor/libsodium/build-aux/config.sub +51 -22
  23. data/vendor/libsodium/build-aux/depcomp +3 -3
  24. data/vendor/libsodium/build-aux/install-sh +2 -2
  25. data/vendor/libsodium/build-aux/missing +3 -3
  26. data/vendor/libsodium/build-aux/test-driver +3 -3
  27. data/vendor/libsodium/builds/msvc/properties/Win32.props +4 -1
  28. data/vendor/libsodium/builds/msvc/properties/x64.props +4 -1
  29. data/vendor/libsodium/builds/msvc/resource.h +14 -0
  30. data/vendor/libsodium/builds/msvc/resource.rc +63 -0
  31. data/vendor/libsodium/builds/msvc/version.h +7 -4
  32. data/vendor/libsodium/builds/msvc/vs2010/libsodium.import.props +1 -1
  33. data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.props +10 -5
  34. data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.vcxproj +182 -139
  35. data/vendor/libsodium/builds/msvc/vs2010/libsodium/libsodium.vcxproj.filters +632 -470
  36. data/vendor/libsodium/builds/msvc/vs2012/libsodium.import.props +1 -1
  37. data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.props +10 -5
  38. data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.vcxproj +182 -129
  39. data/vendor/libsodium/builds/msvc/vs2012/libsodium/libsodium.vcxproj.filters +632 -470
  40. data/vendor/libsodium/builds/msvc/vs2013/libsodium.import.props +1 -1
  41. data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.props +10 -5
  42. data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.vcxproj +182 -129
  43. data/vendor/libsodium/builds/msvc/vs2013/libsodium/libsodium.vcxproj.filters +632 -470
  44. data/vendor/libsodium/builds/msvc/vs2015/libsodium.import.props +1 -1
  45. data/vendor/libsodium/builds/msvc/vs2015/libsodium/libsodium.props +10 -5
  46. data/vendor/libsodium/builds/msvc/vs2015/libsodium/libsodium.vcxproj +181 -118
  47. data/vendor/libsodium/builds/msvc/vs2015/libsodium/libsodium.vcxproj.filters +632 -470
  48. data/vendor/libsodium/builds/msvc/vs2017/libsodium.import.props +52 -0
  49. data/vendor/libsodium/builds/msvc/vs2017/libsodium.import.xml +17 -0
  50. data/vendor/libsodium/builds/msvc/vs2017/libsodium.sln +52 -0
  51. data/vendor/libsodium/builds/msvc/vs2017/libsodium/libsodium.props +48 -0
  52. data/vendor/libsodium/builds/msvc/vs2017/libsodium/libsodium.vcxproj +320 -0
  53. data/vendor/libsodium/builds/msvc/vs2017/libsodium/libsodium.vcxproj.filters +962 -0
  54. data/vendor/libsodium/builds/msvc/vs2017/libsodium/libsodium.xml +15 -0
  55. data/vendor/libsodium/configure +1002 -589
  56. data/vendor/libsodium/configure.ac +48 -21
  57. data/vendor/libsodium/contrib/Findsodium.cmake +267 -0
  58. data/vendor/libsodium/contrib/Makefile.am +3 -0
  59. data/vendor/libsodium/contrib/Makefile.in +483 -0
  60. data/vendor/libsodium/dist-build/Makefile.in +11 -7
  61. data/vendor/libsodium/dist-build/android-armv8-a.sh +1 -1
  62. data/vendor/libsodium/dist-build/android-build.sh +25 -17
  63. data/vendor/libsodium/dist-build/android-mips32.sh +1 -1
  64. data/vendor/libsodium/dist-build/android-mips64.sh +1 -1
  65. data/vendor/libsodium/dist-build/android-x86_64.sh +1 -1
  66. data/vendor/libsodium/dist-build/emscripten-symbols.def +150 -2
  67. data/vendor/libsodium/dist-build/emscripten-wasm.sh +132 -0
  68. data/vendor/libsodium/dist-build/emscripten.sh +8 -6
  69. data/vendor/libsodium/dist-build/ios.sh +29 -5
  70. data/vendor/libsodium/libsodium.vcxproj +139 -77
  71. data/vendor/libsodium/libsodium.vcxproj.filters +315 -144
  72. data/vendor/libsodium/m4/ax_check_catchable_segv.m4 +42 -0
  73. data/vendor/libsodium/m4/ax_check_compile_flag.m4 +6 -4
  74. data/vendor/libsodium/m4/ax_check_define.m4 +3 -3
  75. data/vendor/libsodium/m4/ax_check_gnu_make.m4 +31 -25
  76. data/vendor/libsodium/m4/ax_check_link_flag.m4 +8 -6
  77. data/vendor/libsodium/m4/ax_pthread.m4 +275 -275
  78. data/vendor/libsodium/m4/ax_valgrind_check.m4 +92 -41
  79. data/vendor/libsodium/m4/pkg.m4 +1 -1
  80. data/vendor/libsodium/msvc-scripts/Makefile.in +11 -7
  81. data/vendor/libsodium/msvc-scripts/process.bat +4 -3
  82. data/vendor/libsodium/packaging/dotnet-core/README.md +59 -0
  83. data/vendor/libsodium/packaging/dotnet-core/desktop.targets +16 -0
  84. data/vendor/libsodium/packaging/dotnet-core/libsodium.props +33 -0
  85. data/vendor/libsodium/packaging/dotnet-core/prepare.py +262 -0
  86. data/vendor/libsodium/packaging/dotnet-core/recipes/alpine-x64 +3 -0
  87. data/vendor/libsodium/packaging/dotnet-core/recipes/build +9 -0
  88. data/vendor/libsodium/packaging/dotnet-core/recipes/centos-x64 +3 -0
  89. data/vendor/libsodium/packaging/dotnet-core/recipes/debian-x64 +4 -0
  90. data/vendor/libsodium/packaging/dotnet-core/recipes/fedora-x64 +3 -0
  91. data/vendor/libsodium/packaging/dotnet-core/recipes/opensuse-x64 +3 -0
  92. data/vendor/libsodium/packaging/dotnet-core/recipes/pack +5 -0
  93. data/vendor/libsodium/packaging/dotnet-core/recipes/test +27 -0
  94. data/vendor/libsodium/packaging/dotnet-core/recipes/ubuntu-x64 +4 -0
  95. data/vendor/libsodium/packaging/nuget/package.config +1 -1
  96. data/vendor/libsodium/packaging/nuget/package.gsl +3 -3
  97. data/vendor/libsodium/src/Makefile.in +11 -7
  98. data/vendor/libsodium/src/libsodium/Makefile.am +113 -98
  99. data/vendor/libsodium/src/libsodium/Makefile.in +1034 -1236
  100. data/vendor/libsodium/src/libsodium/crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c +31 -12
  101. data/vendor/libsodium/src/libsodium/crypto_aead/chacha20poly1305/sodium/aead_chacha20poly1305.c +31 -10
  102. data/vendor/libsodium/src/libsodium/crypto_aead/xchacha20poly1305/sodium/aead_xchacha20poly1305.c +153 -0
  103. data/vendor/libsodium/src/libsodium/crypto_auth/crypto_auth.c +7 -0
  104. data/vendor/libsodium/src/libsodium/crypto_auth/hmacsha256/{cp/hmac_hmacsha256.c → auth_hmacsha256.c} +43 -35
  105. data/vendor/libsodium/src/libsodium/crypto_auth/hmacsha512/{cp/hmac_hmacsha512.c → auth_hmacsha512.c} +43 -35
  106. data/vendor/libsodium/src/libsodium/crypto_auth/hmacsha512256/{cp/hmac_hmacsha512256.c → auth_hmacsha512256.c} +48 -9
  107. data/vendor/libsodium/src/libsodium/crypto_box/crypto_box_easy.c +4 -3
  108. data/vendor/libsodium/src/libsodium/crypto_box/crypto_box_seal.c +2 -1
  109. data/vendor/libsodium/src/libsodium/crypto_box/curve25519xchacha20poly1305/box_curve25519xchacha20poly1305.c +197 -0
  110. data/vendor/libsodium/src/libsodium/crypto_box/curve25519xchacha20poly1305/box_seal_curve25519xchacha20poly1305.c +79 -0
  111. data/vendor/libsodium/src/libsodium/crypto_box/curve25519xsalsa20poly1305/box_curve25519xsalsa20poly1305.c +150 -0
  112. data/vendor/libsodium/src/libsodium/crypto_core/curve25519/ref10/curve25519_ref10.c +1156 -662
  113. data/vendor/libsodium/src/libsodium/crypto_core/hchacha20/core_hchacha20.c +12 -5
  114. data/vendor/libsodium/src/libsodium/crypto_core/hsalsa20/{core_hsalsa20_api.c → core_hsalsa20.c} +0 -0
  115. data/vendor/libsodium/src/libsodium/crypto_core/hsalsa20/ref2/core_hsalsa20_ref2.c +95 -0
  116. data/vendor/libsodium/src/libsodium/crypto_core/salsa/ref/core_salsa_ref.c +195 -0
  117. data/vendor/libsodium/src/libsodium/crypto_generichash/{blake2/generichash_blake2_api.c → blake2b/generichash_blake2.c} +7 -0
  118. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2b/ref/blake2.h +109 -0
  119. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-avx2.c +49 -0
  120. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-avx2.h +140 -0
  121. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-ref.c +92 -0
  122. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-sse41.c +87 -0
  123. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-sse41.h +103 -0
  124. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-ssse3.c +90 -0
  125. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-ssse3.h +103 -0
  126. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2b/ref/blake2b-load-avx2.h +340 -0
  127. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2b/ref/blake2b-load-sse2.h +164 -0
  128. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2b/ref/blake2b-load-sse41.h +307 -0
  129. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2b/ref/blake2b-ref.c +494 -0
  130. data/vendor/libsodium/src/libsodium/crypto_generichash/{blake2 → blake2b}/ref/generichash_blake2b.c +22 -26
  131. data/vendor/libsodium/src/libsodium/crypto_generichash/crypto_generichash.c +7 -0
  132. data/vendor/libsodium/src/libsodium/crypto_hash/sha256/cp/hash_sha256_cp.c +254 -0
  133. data/vendor/libsodium/src/libsodium/crypto_hash/sha256/{hash_sha256_api.c → hash_sha256.c} +4 -2
  134. data/vendor/libsodium/src/libsodium/crypto_hash/sha512/cp/hash_sha512_cp.c +280 -0
  135. data/vendor/libsodium/src/libsodium/crypto_hash/sha512/{hash_sha512_api.c → hash_sha512.c} +4 -2
  136. data/vendor/libsodium/src/libsodium/crypto_kdf/blake2b/kdf_blake2b.c +52 -0
  137. data/vendor/libsodium/src/libsodium/crypto_kdf/crypto_kdf.c +49 -0
  138. data/vendor/libsodium/src/libsodium/crypto_kx/crypto_kx.c +136 -0
  139. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/crypto_onetimeauth.c +6 -0
  140. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna.c +34 -27
  141. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna.h +1 -1
  142. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna32.h +203 -156
  143. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna64.h +178 -134
  144. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305.c +22 -4
  145. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305.h +10 -12
  146. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/sse2/poly1305_sse2.c +564 -315
  147. data/vendor/libsodium/src/libsodium/crypto_onetimeauth/poly1305/sse2/poly1305_sse2.h +1 -1
  148. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-core.c +131 -84
  149. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-core.h +23 -18
  150. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-encoding.c +163 -145
  151. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-encoding.h +2 -1
  152. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-fill-block-avx2.c +247 -0
  153. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-fill-block-ref.c +42 -29
  154. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-fill-block-ssse3.c +71 -47
  155. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2.c +100 -65
  156. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2.h +77 -23
  157. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/blake2b-long.c +30 -31
  158. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/blamka-round-avx2.h +150 -0
  159. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/blamka-round-ref.h +28 -26
  160. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/blamka-round-ssse3.h +102 -99
  161. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/pwhash_argon2i.c +90 -41
  162. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/pwhash_argon2id.c +213 -0
  163. data/vendor/libsodium/src/libsodium/crypto_pwhash/crypto_pwhash.c +72 -4
  164. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/crypto_scrypt-common.c +34 -37
  165. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/crypto_scrypt.h +27 -32
  166. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/nosse/pwhash_scryptsalsa208sha256_nosse.c +120 -86
  167. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pbkdf2-sha256.c +16 -13
  168. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pbkdf2-sha256.h +4 -4
  169. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/pwhash_scryptsalsa208sha256.c +98 -50
  170. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/scrypt_platform.c +23 -18
  171. data/vendor/libsodium/src/libsodium/crypto_pwhash/scryptsalsa208sha256/sse/pwhash_scryptsalsa208sha256_sse.c +105 -105
  172. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/donna_c64/curve25519_donna_c64.c +395 -330
  173. data/vendor/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/x25519_ref10.c +225 -198
  174. data/vendor/libsodium/src/libsodium/crypto_secretbox/crypto_secretbox.c +7 -0
  175. data/vendor/libsodium/src/libsodium/crypto_secretbox/crypto_secretbox_easy.c +6 -5
  176. data/vendor/libsodium/src/libsodium/crypto_secretbox/xchacha20poly1305/secretbox_xchacha20poly1305.c +170 -0
  177. data/vendor/libsodium/src/libsodium/crypto_secretbox/xsalsa20poly1305/secretbox_xsalsa20poly1305.c +83 -0
  178. data/vendor/libsodium/src/libsodium/crypto_shorthash/crypto_shorthash.c +7 -0
  179. data/vendor/libsodium/src/libsodium/crypto_shorthash/siphash24/ref/shorthash_siphash24_ref.c +65 -0
  180. data/vendor/libsodium/src/libsodium/crypto_shorthash/siphash24/ref/shorthash_siphash_ref.h +24 -0
  181. data/vendor/libsodium/src/libsodium/crypto_shorthash/siphash24/ref/shorthash_siphashx24_ref.c +71 -0
  182. data/vendor/libsodium/src/libsodium/crypto_shorthash/siphash24/{shorthash_siphash24_api.c → shorthash_siphash24.c} +0 -0
  183. data/vendor/libsodium/src/libsodium/crypto_shorthash/siphash24/shorthash_siphashx24.c +11 -0
  184. data/vendor/libsodium/src/libsodium/crypto_sign/crypto_sign.c +33 -0
  185. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/ed25519_ref10.h +18 -0
  186. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/keypair.c +18 -13
  187. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/obsolete.c +29 -26
  188. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/open.c +75 -36
  189. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/ref10/sign.c +39 -15
  190. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/sign_ed25519.c +91 -0
  191. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/afternm_aes128ctr.c +174 -0
  192. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/beforenm_aes128ctr.c +66 -0
  193. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/common.h +766 -0
  194. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/consts.h +28 -0
  195. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/consts_aes128ctr.c +28 -0
  196. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/int128.h +50 -0
  197. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/int128_aes128ctr.c +149 -0
  198. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/stream_aes128ctr_nacl.c +31 -0
  199. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/nacl/xor_afternm_aes128ctr.c +195 -0
  200. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/{stream_aes128ctr_api.c → stream_aes128ctr.c} +6 -3
  201. data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-avx2.c +179 -0
  202. data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-avx2.h +8 -0
  203. data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-ssse3.c +173 -0
  204. data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/dolbeau/chacha20_dolbeau-ssse3.h +8 -0
  205. data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/dolbeau/u0.h +86 -0
  206. data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/dolbeau/u1.h +98 -0
  207. data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/dolbeau/u4.h +175 -0
  208. data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/dolbeau/u8.h +357 -0
  209. data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/ref/{stream_chacha20_ref.c → chacha20_ref.c} +93 -94
  210. data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/ref/chacha20_ref.h +8 -0
  211. data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/stream_chacha20.c +39 -7
  212. data/vendor/libsodium/src/libsodium/crypto_stream/crypto_stream.c +7 -0
  213. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/ref/salsa20_ref.c +120 -0
  214. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/ref/salsa20_ref.h +8 -0
  215. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/stream_salsa20.c +93 -0
  216. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/stream_salsa20.h +16 -0
  217. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/{amd64_xmm6/stream_salsa20_amd64_xmm6.S → xmm6/salsa20_xmm6-asm.S} +20 -12
  218. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/xmm6/salsa20_xmm6.c +31 -0
  219. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/xmm6/salsa20_xmm6.h +8 -0
  220. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/xmm6int/salsa20_xmm6int-avx2.c +131 -0
  221. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/xmm6int/salsa20_xmm6int-avx2.h +8 -0
  222. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/xmm6int/salsa20_xmm6int-sse2.c +122 -0
  223. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/xmm6int/salsa20_xmm6int-sse2.h +8 -0
  224. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/xmm6int/u0.h +195 -0
  225. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/xmm6int/u1.h +207 -0
  226. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/xmm6int/u4.h +547 -0
  227. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/xmm6int/u8.h +476 -0
  228. data/vendor/libsodium/src/libsodium/crypto_stream/salsa2012/ref/stream_salsa2012_ref.c +106 -0
  229. data/vendor/libsodium/src/libsodium/crypto_stream/salsa2012/stream_salsa2012.c +20 -0
  230. data/vendor/libsodium/src/libsodium/crypto_stream/salsa208/ref/stream_salsa208_ref.c +106 -0
  231. data/vendor/libsodium/src/libsodium/crypto_stream/salsa208/stream_salsa208.c +20 -0
  232. data/vendor/libsodium/src/libsodium/crypto_stream/xchacha20/stream_xchacha20.c +63 -0
  233. data/vendor/libsodium/src/libsodium/crypto_stream/xsalsa20/stream_xsalsa20.c +60 -0
  234. data/vendor/libsodium/src/libsodium/crypto_verify/sodium/verify.c +61 -0
  235. data/vendor/libsodium/src/libsodium/include/Makefile.am +8 -6
  236. data/vendor/libsodium/src/libsodium/include/Makefile.in +29 -21
  237. data/vendor/libsodium/src/libsodium/include/sodium.h +15 -4
  238. data/vendor/libsodium/src/libsodium/include/sodium/crypto_aead_aes256gcm.h +4 -0
  239. data/vendor/libsodium/src/libsodium/include/sodium/crypto_aead_chacha20poly1305.h +6 -0
  240. data/vendor/libsodium/src/libsodium/include/sodium/crypto_aead_xchacha20poly1305.h +91 -0
  241. data/vendor/libsodium/src/libsodium/include/sodium/crypto_auth.h +3 -0
  242. data/vendor/libsodium/src/libsodium/include/sodium/crypto_auth_hmacsha256.h +5 -0
  243. data/vendor/libsodium/src/libsodium/include/sodium/crypto_auth_hmacsha512.h +4 -0
  244. data/vendor/libsodium/src/libsodium/include/sodium/crypto_auth_hmacsha512256.h +4 -0
  245. data/vendor/libsodium/src/libsodium/include/sodium/crypto_box_curve25519xchacha20poly1305.h +153 -0
  246. data/vendor/libsodium/src/libsodium/include/sodium/crypto_generichash.h +4 -0
  247. data/vendor/libsodium/src/libsodium/include/sodium/crypto_generichash_blake2b.h +3 -4
  248. data/vendor/libsodium/src/libsodium/include/sodium/crypto_hash_sha256.h +4 -3
  249. data/vendor/libsodium/src/libsodium/include/sodium/crypto_hash_sha512.h +4 -3
  250. data/vendor/libsodium/src/libsodium/include/sodium/crypto_kdf.h +51 -0
  251. data/vendor/libsodium/src/libsodium/include/sodium/crypto_kdf_blake2b.h +42 -0
  252. data/vendor/libsodium/src/libsodium/include/sodium/crypto_kx.h +64 -0
  253. data/vendor/libsodium/src/libsodium/include/sodium/crypto_onetimeauth.h +4 -0
  254. data/vendor/libsodium/src/libsodium/include/sodium/crypto_onetimeauth_poly1305.h +11 -9
  255. data/vendor/libsodium/src/libsodium/include/sodium/crypto_pwhash.h +37 -1
  256. data/vendor/libsodium/src/libsodium/include/sodium/crypto_pwhash_argon2i.h +40 -10
  257. data/vendor/libsodium/src/libsodium/include/sodium/crypto_pwhash_argon2id.h +116 -0
  258. data/vendor/libsodium/src/libsodium/include/sodium/crypto_pwhash_scryptsalsa208sha256.h +37 -4
  259. data/vendor/libsodium/src/libsodium/include/sodium/crypto_scalarmult_curve25519.h +0 -4
  260. data/vendor/libsodium/src/libsodium/include/sodium/crypto_secretbox.h +3 -0
  261. data/vendor/libsodium/src/libsodium/include/sodium/crypto_secretbox_xchacha20poly1305.h +62 -0
  262. data/vendor/libsodium/src/libsodium/include/sodium/crypto_secretbox_xsalsa20poly1305.h +5 -1
  263. data/vendor/libsodium/src/libsodium/include/sodium/crypto_shorthash.h +3 -0
  264. data/vendor/libsodium/src/libsodium/include/sodium/crypto_shorthash_siphash24.h +18 -0
  265. data/vendor/libsodium/src/libsodium/include/sodium/crypto_sign.h +22 -0
  266. data/vendor/libsodium/src/libsodium/include/sodium/crypto_sign_ed25519.h +28 -0
  267. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream.h +3 -0
  268. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_aes128ctr.h +10 -5
  269. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_chacha20.h +14 -3
  270. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_salsa20.h +4 -0
  271. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_salsa2012.h +3 -0
  272. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_salsa208.h +3 -0
  273. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_xchacha20.h +53 -0
  274. data/vendor/libsodium/src/libsodium/include/sodium/crypto_stream_xsalsa20.h +4 -0
  275. data/vendor/libsodium/src/libsodium/include/sodium/private/common.h +84 -17
  276. data/vendor/libsodium/src/libsodium/include/sodium/private/implementations.h +11 -0
  277. data/vendor/libsodium/src/libsodium/include/sodium/private/sse2_64_32.h +50 -0
  278. data/vendor/libsodium/src/libsodium/include/sodium/randombytes.h +10 -2
  279. data/vendor/libsodium/src/libsodium/include/sodium/utils.h +4 -5
  280. data/vendor/libsodium/src/libsodium/include/sodium/version.h.in +4 -0
  281. data/vendor/libsodium/src/libsodium/randombytes/randombytes.c +47 -19
  282. data/vendor/libsodium/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c +30 -50
  283. data/vendor/libsodium/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c +25 -15
  284. data/vendor/libsodium/src/libsodium/sodium/core.c +25 -23
  285. data/vendor/libsodium/src/libsodium/sodium/runtime.c +66 -57
  286. data/vendor/libsodium/src/libsodium/sodium/utils.c +120 -106
  287. data/vendor/libsodium/src/libsodium/sodium/version.c +10 -0
  288. data/vendor/libsodium/test/Makefile.in +11 -7
  289. data/vendor/libsodium/test/default/Makefile.am +65 -5
  290. data/vendor/libsodium/test/default/Makefile.in +243 -78
  291. data/vendor/libsodium/test/default/aead_aes256gcm.c +2 -2
  292. data/vendor/libsodium/test/default/aead_xchacha20poly1305.c +188 -0
  293. data/vendor/libsodium/test/default/aead_xchacha20poly1305.exp +51 -0
  294. data/vendor/libsodium/test/default/auth.c +11 -7
  295. data/vendor/libsodium/test/default/auth2.c +15 -12
  296. data/vendor/libsodium/test/default/auth3.c +18 -15
  297. data/vendor/libsodium/test/default/auth5.c +3 -2
  298. data/vendor/libsodium/test/default/auth6.c +4 -3
  299. data/vendor/libsodium/test/default/auth7.c +3 -2
  300. data/vendor/libsodium/test/default/box.c +57 -52
  301. data/vendor/libsodium/test/default/box2.c +41 -36
  302. data/vendor/libsodium/test/default/box7.c +4 -3
  303. data/vendor/libsodium/test/default/box8.c +4 -3
  304. data/vendor/libsodium/test/default/box_easy.c +36 -32
  305. data/vendor/libsodium/test/default/box_easy2.c +41 -34
  306. data/vendor/libsodium/test/default/box_seal.c +7 -6
  307. data/vendor/libsodium/test/default/box_seed.c +10 -8
  308. data/vendor/libsodium/test/default/chacha20.c +18 -3
  309. data/vendor/libsodium/test/default/chacha20.exp +45 -0
  310. data/vendor/libsodium/test/default/cmptest.h +1 -0
  311. data/vendor/libsodium/test/default/core1.c +10 -9
  312. data/vendor/libsodium/test/default/core2.c +13 -12
  313. data/vendor/libsodium/test/default/core3.c +13 -12
  314. data/vendor/libsodium/test/default/core4.c +11 -12
  315. data/vendor/libsodium/test/default/core5.c +13 -12
  316. data/vendor/libsodium/test/default/core6.c +15 -13
  317. data/vendor/libsodium/test/default/ed25519_convert.c +12 -9
  318. data/vendor/libsodium/test/default/hash.c +10 -6
  319. data/vendor/libsodium/test/default/hash3.c +3 -2
  320. data/vendor/libsodium/test/default/index-wasm.html.tpl +118 -0
  321. data/vendor/libsodium/test/default/kdf.c +61 -0
  322. data/vendor/libsodium/test/default/kdf.exp +77 -0
  323. data/vendor/libsodium/test/default/keygen.c +64 -0
  324. data/vendor/libsodium/test/default/keygen.exp +1 -0
  325. data/vendor/libsodium/test/default/kx.c +119 -0
  326. data/vendor/libsodium/test/default/kx.exp +7 -0
  327. data/vendor/libsodium/test/default/nacl-test-wrapper.sh +9 -2
  328. data/vendor/libsodium/test/default/onetimeauth.c +26 -23
  329. data/vendor/libsodium/test/default/onetimeauth2.c +22 -20
  330. data/vendor/libsodium/test/default/onetimeauth7.c +3 -2
  331. data/vendor/libsodium/test/default/pwhash.c +209 -157
  332. data/vendor/libsodium/test/default/pwhash_argon2id.c +388 -0
  333. data/vendor/libsodium/test/default/pwhash_argon2id.exp +15 -0
  334. data/vendor/libsodium/test/default/pwhash_scrypt.c +232 -224
  335. data/vendor/libsodium/test/default/pwhash_scrypt.exp +2 -1
  336. data/vendor/libsodium/test/default/pwhash_scrypt_ll.c +39 -41
  337. data/vendor/libsodium/test/default/randombytes.c +34 -13
  338. data/vendor/libsodium/test/default/randombytes.exp +1 -0
  339. data/vendor/libsodium/test/default/scalarmult.c +21 -18
  340. data/vendor/libsodium/test/default/scalarmult2.c +8 -6
  341. data/vendor/libsodium/test/default/scalarmult5.c +13 -10
  342. data/vendor/libsodium/test/default/scalarmult6.c +17 -14
  343. data/vendor/libsodium/test/default/scalarmult7.c +9 -10
  344. data/vendor/libsodium/test/default/secretbox.c +39 -36
  345. data/vendor/libsodium/test/default/secretbox2.c +28 -25
  346. data/vendor/libsodium/test/default/secretbox7.c +3 -2
  347. data/vendor/libsodium/test/default/secretbox8.c +4 -3
  348. data/vendor/libsodium/test/default/secretbox_easy.c +40 -37
  349. data/vendor/libsodium/test/default/secretbox_easy2.c +19 -18
  350. data/vendor/libsodium/test/default/shorthash.c +4 -4
  351. data/vendor/libsodium/test/default/sign.c +70 -13
  352. data/vendor/libsodium/test/default/sign.exp +2 -0
  353. data/vendor/libsodium/test/default/siphashx24.c +33 -0
  354. data/vendor/libsodium/test/default/siphashx24.exp +64 -0
  355. data/vendor/libsodium/test/default/sodium_core.c +9 -8
  356. data/vendor/libsodium/test/default/sodium_utils.c +52 -46
  357. data/vendor/libsodium/test/default/sodium_utils2.c +17 -8
  358. data/vendor/libsodium/test/default/sodium_utils3.c +15 -6
  359. data/vendor/libsodium/test/default/sodium_version.c +7 -1
  360. data/vendor/libsodium/test/default/stream.c +31 -18
  361. data/vendor/libsodium/test/default/stream.exp +65 -0
  362. data/vendor/libsodium/test/default/stream2.c +13 -9
  363. data/vendor/libsodium/test/default/stream3.c +12 -10
  364. data/vendor/libsodium/test/default/stream4.c +30 -27
  365. data/vendor/libsodium/test/default/verify1.c +5 -4
  366. data/vendor/libsodium/test/default/xchacha20.c +376 -0
  367. data/vendor/libsodium/test/default/xchacha20.exp +5 -0
  368. data/vendor/libsodium/test/quirks/quirks.h +4 -3
  369. metadata +140 -111
  370. data/vendor/libsodium/autom4te.cache/output.3 +0 -17240
  371. data/vendor/libsodium/autom4te.cache/output.4 +0 -17517
  372. data/vendor/libsodium/autom4te.cache/output.5 +0 -18535
  373. data/vendor/libsodium/autom4te.cache/output.6 +0 -19077
  374. data/vendor/libsodium/autom4te.cache/output.7 +0 -19837
  375. data/vendor/libsodium/autom4te.cache/traces.3 +0 -2833
  376. data/vendor/libsodium/autom4te.cache/traces.4 +0 -2951
  377. data/vendor/libsodium/autom4te.cache/traces.5 +0 -3042
  378. data/vendor/libsodium/autom4te.cache/traces.6 +0 -3194
  379. data/vendor/libsodium/autom4te.cache/traces.7 +0 -3614
  380. data/vendor/libsodium/builds/msvc/properties/ARM.props +0 -20
  381. data/vendor/libsodium/compile +0 -347
  382. data/vendor/libsodium/config.guess +0 -1568
  383. data/vendor/libsodium/config.sub +0 -1793
  384. data/vendor/libsodium/depcomp +0 -791
  385. data/vendor/libsodium/install-sh +0 -527
  386. data/vendor/libsodium/ltmain.sh +0 -9655
  387. data/vendor/libsodium/missing +0 -215
  388. data/vendor/libsodium/src/libsodium/crypto_auth/hmacsha256/auth_hmacsha256_api.c +0 -16
  389. data/vendor/libsodium/src/libsodium/crypto_auth/hmacsha256/cp/verify_hmacsha256.c +0 -11
  390. data/vendor/libsodium/src/libsodium/crypto_auth/hmacsha512/auth_hmacsha512_api.c +0 -16
  391. data/vendor/libsodium/src/libsodium/crypto_auth/hmacsha512/cp/verify_hmacsha512.c +0 -12
  392. data/vendor/libsodium/src/libsodium/crypto_auth/hmacsha512256/auth_hmacsha512256_api.c +0 -16
  393. data/vendor/libsodium/src/libsodium/crypto_auth/hmacsha512256/cp/verify_hmacsha512256.c +0 -14
  394. data/vendor/libsodium/src/libsodium/crypto_box/curve25519xsalsa20poly1305/box_curve25519xsalsa20poly1305_api.c +0 -41
  395. data/vendor/libsodium/src/libsodium/crypto_box/curve25519xsalsa20poly1305/ref/after_curve25519xsalsa20poly1305.c +0 -22
  396. data/vendor/libsodium/src/libsodium/crypto_box/curve25519xsalsa20poly1305/ref/before_curve25519xsalsa20poly1305.c +0 -18
  397. data/vendor/libsodium/src/libsodium/crypto_box/curve25519xsalsa20poly1305/ref/box_curve25519xsalsa20poly1305.c +0 -42
  398. data/vendor/libsodium/src/libsodium/crypto_box/curve25519xsalsa20poly1305/ref/keypair_curve25519xsalsa20poly1305.c +0 -29
  399. data/vendor/libsodium/src/libsodium/crypto_core/hchacha20/core_hchacha20.h +0 -28
  400. data/vendor/libsodium/src/libsodium/crypto_core/hsalsa20/ref2/core_hsalsa20.c +0 -100
  401. data/vendor/libsodium/src/libsodium/crypto_core/salsa20/core_salsa20_api.c +0 -21
  402. data/vendor/libsodium/src/libsodium/crypto_core/salsa20/ref/core_salsa20.c +0 -126
  403. data/vendor/libsodium/src/libsodium/crypto_core/salsa2012/core_salsa2012_api.c +0 -21
  404. data/vendor/libsodium/src/libsodium/crypto_core/salsa2012/ref/core_salsa2012.c +0 -126
  405. data/vendor/libsodium/src/libsodium/crypto_core/salsa208/core_salsa208_api.c +0 -21
  406. data/vendor/libsodium/src/libsodium/crypto_core/salsa208/ref/core_salsa208.c +0 -126
  407. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2-impl.h +0 -48
  408. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2.h +0 -97
  409. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-compress-avx2.c +0 -45
  410. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-compress-avx2.h +0 -123
  411. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-compress-ref.c +0 -94
  412. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-compress-sse41.c +0 -80
  413. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-compress-sse41.h +0 -97
  414. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-compress-ssse3.c +0 -87
  415. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-compress-ssse3.h +0 -97
  416. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-load-avx2.h +0 -339
  417. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-load-sse2.h +0 -66
  418. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-load-sse41.h +0 -400
  419. data/vendor/libsodium/src/libsodium/crypto_generichash/blake2/ref/blake2b-ref.c +0 -456
  420. data/vendor/libsodium/src/libsodium/crypto_hash/sha256/cp/hash_sha256.c +0 -269
  421. data/vendor/libsodium/src/libsodium/crypto_hash/sha512/cp/hash_sha512.c +0 -298
  422. data/vendor/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-impl.h +0 -40
  423. data/vendor/libsodium/src/libsodium/crypto_secretbox/xsalsa20poly1305/ref/box_xsalsa20poly1305.c +0 -35
  424. data/vendor/libsodium/src/libsodium/crypto_secretbox/xsalsa20poly1305/secretbox_xsalsa20poly1305_api.c +0 -26
  425. data/vendor/libsodium/src/libsodium/crypto_shorthash/siphash24/ref/shorthash_siphash24.c +0 -72
  426. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/description +0 -1
  427. data/vendor/libsodium/src/libsodium/crypto_sign/ed25519/sign_ed25519_api.c +0 -39
  428. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/afternm_aes128ctr.c +0 -159
  429. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/beforenm_aes128ctr.c +0 -59
  430. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/common.h +0 -771
  431. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/consts.h +0 -28
  432. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/consts_aes128ctr.c +0 -14
  433. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/int128.h +0 -56
  434. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/int128_aes128ctr.c +0 -131
  435. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/stream_aes128ctr.c +0 -29
  436. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/types.h +0 -10
  437. data/vendor/libsodium/src/libsodium/crypto_stream/aes128ctr/portable/xor_afternm_aes128ctr.c +0 -180
  438. data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/ref/stream_chacha20_ref.h +0 -28
  439. data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/vec/stream_chacha20_vec.c +0 -336
  440. data/vendor/libsodium/src/libsodium/crypto_stream/chacha20/vec/stream_chacha20_vec.h +0 -28
  441. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/ref/stream_salsa20_ref.c +0 -55
  442. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/ref/xor_salsa20_ref.c +0 -63
  443. data/vendor/libsodium/src/libsodium/crypto_stream/salsa20/stream_salsa20_api.c +0 -19
  444. data/vendor/libsodium/src/libsodium/crypto_stream/salsa2012/ref/stream_salsa2012.c +0 -51
  445. data/vendor/libsodium/src/libsodium/crypto_stream/salsa2012/ref/xor_salsa2012.c +0 -54
  446. data/vendor/libsodium/src/libsodium/crypto_stream/salsa2012/stream_salsa2012_api.c +0 -11
  447. data/vendor/libsodium/src/libsodium/crypto_stream/salsa208/ref/stream_salsa208.c +0 -51
  448. data/vendor/libsodium/src/libsodium/crypto_stream/salsa208/ref/xor_salsa208.c +0 -54
  449. data/vendor/libsodium/src/libsodium/crypto_stream/salsa208/stream_salsa208_api.c +0 -11
  450. data/vendor/libsodium/src/libsodium/crypto_stream/xsalsa20/ref/stream_xsalsa20.c +0 -24
  451. data/vendor/libsodium/src/libsodium/crypto_stream/xsalsa20/ref/xor_xsalsa20.c +0 -35
  452. data/vendor/libsodium/src/libsodium/crypto_stream/xsalsa20/stream_xsalsa20_api.c +0 -11
  453. data/vendor/libsodium/src/libsodium/crypto_verify/16/ref/verify_16.c +0 -17
  454. data/vendor/libsodium/src/libsodium/crypto_verify/16/verify_16_api.c +0 -6
  455. data/vendor/libsodium/src/libsodium/crypto_verify/32/ref/verify_32.c +0 -17
  456. data/vendor/libsodium/src/libsodium/crypto_verify/32/verify_32_api.c +0 -6
  457. data/vendor/libsodium/src/libsodium/crypto_verify/64/ref/verify_64.c +0 -17
  458. data/vendor/libsodium/src/libsodium/crypto_verify/64/verify_64_api.c +0 -6
  459. data/vendor/libsodium/src/libsodium/include/sodium/crypto_int32.h +0 -8
  460. data/vendor/libsodium/src/libsodium/include/sodium/crypto_int64.h +0 -8
  461. data/vendor/libsodium/src/libsodium/include/sodium/crypto_uint16.h +0 -8
  462. data/vendor/libsodium/src/libsodium/include/sodium/crypto_uint32.h +0 -8
  463. data/vendor/libsodium/src/libsodium/include/sodium/crypto_uint64.h +0 -8
  464. data/vendor/libsodium/src/libsodium/include/sodium/crypto_uint8.h +0 -8
  465. data/vendor/libsodium/test-driver +0 -139
@@ -0,0 +1,150 @@
1
+ #include <string.h>
2
+
3
+ #include "crypto_box_curve25519xsalsa20poly1305.h"
4
+ #include "crypto_core_hsalsa20.h"
5
+ #include "crypto_hash_sha512.h"
6
+ #include "crypto_scalarmult_curve25519.h"
7
+ #include "crypto_secretbox_xsalsa20poly1305.h"
8
+ #include "randombytes.h"
9
+ #include "utils.h"
10
+
11
+ int
12
+ crypto_box_curve25519xsalsa20poly1305_seed_keypair(unsigned char *pk,
13
+ unsigned char *sk,
14
+ const unsigned char *seed)
15
+ {
16
+ unsigned char hash[64];
17
+
18
+ crypto_hash_sha512(hash, seed, 32);
19
+ memcpy(sk, hash, 32);
20
+ sodium_memzero(hash, sizeof hash);
21
+
22
+ return crypto_scalarmult_curve25519_base(pk, sk);
23
+ }
24
+
25
+ int
26
+ crypto_box_curve25519xsalsa20poly1305_keypair(unsigned char *pk,
27
+ unsigned char *sk)
28
+ {
29
+ randombytes_buf(sk, 32);
30
+
31
+ return crypto_scalarmult_curve25519_base(pk, sk);
32
+ }
33
+
34
+ int
35
+ crypto_box_curve25519xsalsa20poly1305_beforenm(unsigned char *k,
36
+ const unsigned char *pk,
37
+ const unsigned char *sk)
38
+ {
39
+ static const unsigned char zero[16] = { 0 };
40
+ unsigned char s[32];
41
+
42
+ if (crypto_scalarmult_curve25519(s, sk, pk) != 0) {
43
+ return -1;
44
+ }
45
+ return crypto_core_hsalsa20(k, zero, s, NULL);
46
+ }
47
+
48
+ int
49
+ crypto_box_curve25519xsalsa20poly1305_afternm(unsigned char *c,
50
+ const unsigned char *m,
51
+ unsigned long long mlen,
52
+ const unsigned char *n,
53
+ const unsigned char *k)
54
+ {
55
+ return crypto_secretbox_xsalsa20poly1305(c, m, mlen, n, k);
56
+ }
57
+
58
+ int
59
+ crypto_box_curve25519xsalsa20poly1305_open_afternm(unsigned char *m,
60
+ const unsigned char *c,
61
+ unsigned long long clen,
62
+ const unsigned char *n,
63
+ const unsigned char *k)
64
+ {
65
+ return crypto_secretbox_xsalsa20poly1305_open(m, c, clen, n, k);
66
+ }
67
+
68
+ int
69
+ crypto_box_curve25519xsalsa20poly1305(unsigned char *c, const unsigned char *m,
70
+ unsigned long long mlen,
71
+ const unsigned char *n,
72
+ const unsigned char *pk,
73
+ const unsigned char *sk)
74
+ {
75
+ unsigned char k[crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES];
76
+ int ret;
77
+
78
+ if (crypto_box_curve25519xsalsa20poly1305_beforenm(k, pk, sk) != 0) {
79
+ return -1;
80
+ }
81
+ ret = crypto_box_curve25519xsalsa20poly1305_afternm(c, m, mlen, n, k);
82
+ sodium_memzero(k, sizeof k);
83
+
84
+ return ret;
85
+ }
86
+
87
+ int
88
+ crypto_box_curve25519xsalsa20poly1305_open(
89
+ unsigned char *m, const unsigned char *c, unsigned long long clen,
90
+ const unsigned char *n, const unsigned char *pk, const unsigned char *sk)
91
+ {
92
+ unsigned char k[crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES];
93
+ int ret;
94
+
95
+ if (crypto_box_curve25519xsalsa20poly1305_beforenm(k, pk, sk) != 0) {
96
+ return -1;
97
+ }
98
+ ret = crypto_box_curve25519xsalsa20poly1305_open_afternm(m, c, clen, n, k);
99
+ sodium_memzero(k, sizeof k);
100
+
101
+ return ret;
102
+ }
103
+
104
+ size_t
105
+ crypto_box_curve25519xsalsa20poly1305_seedbytes(void)
106
+ {
107
+ return crypto_box_curve25519xsalsa20poly1305_SEEDBYTES;
108
+ }
109
+
110
+ size_t
111
+ crypto_box_curve25519xsalsa20poly1305_publickeybytes(void)
112
+ {
113
+ return crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES;
114
+ }
115
+
116
+ size_t
117
+ crypto_box_curve25519xsalsa20poly1305_secretkeybytes(void)
118
+ {
119
+ return crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES;
120
+ }
121
+
122
+ size_t
123
+ crypto_box_curve25519xsalsa20poly1305_beforenmbytes(void)
124
+ {
125
+ return crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES;
126
+ }
127
+
128
+ size_t
129
+ crypto_box_curve25519xsalsa20poly1305_noncebytes(void)
130
+ {
131
+ return crypto_box_curve25519xsalsa20poly1305_NONCEBYTES;
132
+ }
133
+
134
+ size_t
135
+ crypto_box_curve25519xsalsa20poly1305_zerobytes(void)
136
+ {
137
+ return crypto_box_curve25519xsalsa20poly1305_ZEROBYTES;
138
+ }
139
+
140
+ size_t
141
+ crypto_box_curve25519xsalsa20poly1305_boxzerobytes(void)
142
+ {
143
+ return crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES;
144
+ }
145
+
146
+ size_t
147
+ crypto_box_curve25519xsalsa20poly1305_macbytes(void)
148
+ {
149
+ return crypto_box_curve25519xsalsa20poly1305_MACBYTES;
150
+ }
@@ -1,12 +1,15 @@
1
1
  #include <stddef.h>
2
2
  #include <stdint.h>
3
3
  #include <string.h>
4
+
4
5
  #include "crypto_verify_32.h"
5
6
  #include "private/curve25519_ref10.h"
6
7
 
7
- static uint64_t load_3(const unsigned char *in)
8
+ static inline uint64_t
9
+ load_3(const unsigned char *in)
8
10
  {
9
11
  uint64_t result;
12
+
10
13
  result = (uint64_t) in[0];
11
14
  result |= ((uint64_t) in[1]) << 8;
12
15
  result |= ((uint64_t) in[2]) << 16;
@@ -14,9 +17,11 @@ static uint64_t load_3(const unsigned char *in)
14
17
  return result;
15
18
  }
16
19
 
17
- static uint64_t load_4(const unsigned char *in)
20
+ static inline uint64_t
21
+ load_4(const unsigned char *in)
18
22
  {
19
23
  uint64_t result;
24
+
20
25
  result = (uint64_t) in[0];
21
26
  result |= ((uint64_t) in[1]) << 8;
22
27
  result |= ((uint64_t) in[2]) << 16;
@@ -29,7 +34,8 @@ static uint64_t load_4(const unsigned char *in)
29
34
  h = 0
30
35
  */
31
36
 
32
- void fe_0(fe h)
37
+ void
38
+ fe_0(fe h)
33
39
  {
34
40
  memset(&h[0], 0, 10 * sizeof h[0]);
35
41
  }
@@ -38,7 +44,8 @@ void fe_0(fe h)
38
44
  h = 1
39
45
  */
40
46
 
41
- void fe_1(fe h)
47
+ void
48
+ fe_1(fe h)
42
49
  {
43
50
  h[0] = 1;
44
51
  h[1] = 0;
@@ -57,7 +64,8 @@ void fe_1(fe h)
57
64
  |h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
58
65
  */
59
66
 
60
- void fe_add(fe h,const fe f,const fe g)
67
+ void
68
+ fe_add(fe h, const fe f, const fe g)
61
69
  {
62
70
  int32_t f0 = f[0];
63
71
  int32_t f1 = f[1];
@@ -69,6 +77,7 @@ void fe_add(fe h,const fe f,const fe g)
69
77
  int32_t f7 = f[7];
70
78
  int32_t f8 = f[8];
71
79
  int32_t f9 = f[9];
80
+
72
81
  int32_t g0 = g[0];
73
82
  int32_t g1 = g[1];
74
83
  int32_t g2 = g[2];
@@ -79,6 +88,7 @@ void fe_add(fe h,const fe f,const fe g)
79
88
  int32_t g7 = g[7];
80
89
  int32_t g8 = g[8];
81
90
  int32_t g9 = g[9];
91
+
82
92
  int32_t h0 = f0 + g0;
83
93
  int32_t h1 = f1 + g1;
84
94
  int32_t h2 = f2 + g2;
@@ -89,6 +99,7 @@ void fe_add(fe h,const fe f,const fe g)
89
99
  int32_t h7 = f7 + g7;
90
100
  int32_t h8 = f8 + g8;
91
101
  int32_t h9 = f9 + g9;
102
+
92
103
  h[0] = h0;
93
104
  h[1] = h1;
94
105
  h[2] = h2;
@@ -108,7 +119,8 @@ void fe_add(fe h,const fe f,const fe g)
108
119
  Preconditions: b in {0,1}.
109
120
  */
110
121
 
111
- void fe_cmov(fe f,const fe g,unsigned int b)
122
+ void
123
+ fe_cmov(fe f, const fe g, unsigned int b)
112
124
  {
113
125
  int32_t f0 = f[0];
114
126
  int32_t f1 = f[1];
@@ -120,6 +132,7 @@ void fe_cmov(fe f,const fe g,unsigned int b)
120
132
  int32_t f7 = f[7];
121
133
  int32_t f8 = f[8];
122
134
  int32_t f9 = f[9];
135
+
123
136
  int32_t g0 = g[0];
124
137
  int32_t g1 = g[1];
125
138
  int32_t g2 = g[2];
@@ -130,6 +143,7 @@ void fe_cmov(fe f,const fe g,unsigned int b)
130
143
  int32_t g7 = g[7];
131
144
  int32_t g8 = g[8];
132
145
  int32_t g9 = g[9];
146
+
133
147
  int32_t x0 = f0 ^ g0;
134
148
  int32_t x1 = f1 ^ g1;
135
149
  int32_t x2 = f2 ^ g2;
@@ -140,7 +154,8 @@ void fe_cmov(fe f,const fe g,unsigned int b)
140
154
  int32_t x7 = f7 ^ g7;
141
155
  int32_t x8 = f8 ^ g8;
142
156
  int32_t x9 = f9 ^ g9;
143
- b = (unsigned int) (- (int) b);
157
+
158
+ b = (unsigned int) (-(int) b);
144
159
  x0 &= b;
145
160
  x1 &= b;
146
161
  x2 &= b;
@@ -167,7 +182,8 @@ void fe_cmov(fe f,const fe g,unsigned int b)
167
182
  h = f
168
183
  */
169
184
 
170
- void fe_copy(fe h,const fe f)
185
+ void
186
+ fe_copy(fe h, const fe f)
171
187
  {
172
188
  int32_t f0 = f[0];
173
189
  int32_t f1 = f[1];
@@ -179,6 +195,7 @@ void fe_copy(fe h,const fe f)
179
195
  int32_t f7 = f[7];
180
196
  int32_t f8 = f[8];
181
197
  int32_t f9 = f[9];
198
+
182
199
  h[0] = f0;
183
200
  h[1] = f1;
184
201
  h[2] = f2;
@@ -195,7 +212,8 @@ void fe_copy(fe h,const fe f)
195
212
  Ignores top bit of h.
196
213
  */
197
214
 
198
- void fe_frombytes(fe h,const unsigned char *s)
215
+ void
216
+ fe_frombytes(fe h, const unsigned char *s)
199
217
  {
200
218
  int64_t h0 = load_4(s);
201
219
  int64_t h1 = load_3(s + 4) << 6;
@@ -207,6 +225,7 @@ void fe_frombytes(fe h,const unsigned char *s)
207
225
  int64_t h7 = load_3(s + 23) << 5;
208
226
  int64_t h8 = load_3(s + 26) << 4;
209
227
  int64_t h9 = (load_3(s + 29) & 8388607) << 2;
228
+
210
229
  int64_t carry0;
211
230
  int64_t carry1;
212
231
  int64_t carry2;
@@ -218,17 +237,37 @@ void fe_frombytes(fe h,const unsigned char *s)
218
237
  int64_t carry8;
219
238
  int64_t carry9;
220
239
 
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);
240
+ carry9 = (h9 + (int64_t)(1L << 24)) >> 25;
241
+ h0 += carry9 * 19;
242
+ h9 -= carry9 * ((uint64_t) 1L << 25);
243
+ carry1 = (h1 + (int64_t)(1L << 24)) >> 25;
244
+ h2 += carry1;
245
+ h1 -= carry1 * ((uint64_t) 1L << 25);
246
+ carry3 = (h3 + (int64_t)(1L << 24)) >> 25;
247
+ h4 += carry3;
248
+ h3 -= carry3 * ((uint64_t) 1L << 25);
249
+ carry5 = (h5 + (int64_t)(1L << 24)) >> 25;
250
+ h6 += carry5;
251
+ h5 -= carry5 * ((uint64_t) 1L << 25);
252
+ carry7 = (h7 + (int64_t)(1L << 24)) >> 25;
253
+ h8 += carry7;
254
+ h7 -= carry7 * ((uint64_t) 1L << 25);
255
+
256
+ carry0 = (h0 + (int64_t)(1L << 25)) >> 26;
257
+ h1 += carry0;
258
+ h0 -= carry0 * ((uint64_t) 1L << 26);
259
+ carry2 = (h2 + (int64_t)(1L << 25)) >> 26;
260
+ h3 += carry2;
261
+ h2 -= carry2 * ((uint64_t) 1L << 26);
262
+ carry4 = (h4 + (int64_t)(1L << 25)) >> 26;
263
+ h5 += carry4;
264
+ h4 -= carry4 * ((uint64_t) 1L << 26);
265
+ carry6 = (h6 + (int64_t)(1L << 25)) >> 26;
266
+ h7 += carry6;
267
+ h6 -= carry6 * ((uint64_t) 1L << 26);
268
+ carry8 = (h8 + (int64_t)(1L << 25)) >> 26;
269
+ h9 += carry8;
270
+ h8 -= carry8 * ((uint64_t) 1L << 26);
232
271
 
233
272
  h[0] = (int32_t) h0;
234
273
  h[1] = (int32_t) h1;
@@ -267,7 +306,8 @@ void fe_frombytes(fe h,const unsigned char *s)
267
306
  so floor(2^(-255)(h + 19 2^(-25) h9 + 2^(-1))) = q.
268
307
  */
269
308
 
270
- void fe_tobytes(unsigned char *s,const fe h)
309
+ void
310
+ fe_tobytes(unsigned char *s, const fe h)
271
311
  {
272
312
  int32_t h0 = h[0];
273
313
  int32_t h1 = h[1];
@@ -279,6 +319,7 @@ void fe_tobytes(unsigned char *s,const fe h)
279
319
  int32_t h7 = h[7];
280
320
  int32_t h8 = h[8];
281
321
  int32_t h9 = h[9];
322
+
282
323
  int32_t q;
283
324
  int32_t carry0;
284
325
  int32_t carry1;
@@ -307,16 +348,35 @@ void fe_tobytes(unsigned char *s,const fe h)
307
348
  h0 += 19 * q;
308
349
  /* Goal: Output h-2^255 q, which is between 0 and 2^255-20. */
309
350
 
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);
351
+ carry0 = h0 >> 26;
352
+ h1 += carry0;
353
+ h0 -= carry0 * ((uint32_t) 1L << 26);
354
+ carry1 = h1 >> 25;
355
+ h2 += carry1;
356
+ h1 -= carry1 * ((uint32_t) 1L << 25);
357
+ carry2 = h2 >> 26;
358
+ h3 += carry2;
359
+ h2 -= carry2 * ((uint32_t) 1L << 26);
360
+ carry3 = h3 >> 25;
361
+ h4 += carry3;
362
+ h3 -= carry3 * ((uint32_t) 1L << 25);
363
+ carry4 = h4 >> 26;
364
+ h5 += carry4;
365
+ h4 -= carry4 * ((uint32_t) 1L << 26);
366
+ carry5 = h5 >> 25;
367
+ h6 += carry5;
368
+ h5 -= carry5 * ((uint32_t) 1L << 25);
369
+ carry6 = h6 >> 26;
370
+ h7 += carry6;
371
+ h6 -= carry6 * ((uint32_t) 1L << 26);
372
+ carry7 = h7 >> 25;
373
+ h8 += carry7;
374
+ h7 -= carry7 * ((uint32_t) 1L << 25);
375
+ carry8 = h8 >> 26;
376
+ h9 += carry8;
377
+ h8 -= carry8 * ((uint32_t) 1L << 26);
378
+ carry9 = h9 >> 25;
379
+ h9 -= carry9 * ((uint32_t) 1L << 25);
320
380
  /* h10 = carry9 */
321
381
 
322
382
  /*
@@ -326,16 +386,16 @@ void fe_tobytes(unsigned char *s,const fe h)
326
386
  Goal: Output h0+...+2^230 h9.
327
387
  */
328
388
 
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));
389
+ s[0] = h0 >> 0;
390
+ s[1] = h0 >> 8;
391
+ s[2] = h0 >> 16;
392
+ s[3] = (h0 >> 24) | (h1 * ((uint32_t) 1 << 2));
393
+ s[4] = h1 >> 6;
394
+ s[5] = h1 >> 14;
395
+ s[6] = (h1 >> 22) | (h2 * ((uint32_t) 1 << 3));
396
+ s[7] = h2 >> 5;
397
+ s[8] = h2 >> 13;
398
+ s[9] = (h2 >> 21) | (h3 * ((uint32_t) 1 << 5));
339
399
  s[10] = h3 >> 3;
340
400
  s[11] = h3 >> 11;
341
401
  s[12] = (h3 >> 19) | (h4 * ((uint32_t) 1 << 6));
@@ -368,10 +428,12 @@ void fe_tobytes(unsigned char *s,const fe h)
368
428
  |f| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
369
429
  */
370
430
 
371
- int fe_isnegative(const fe f)
431
+ int
432
+ fe_isnegative(const fe f)
372
433
  {
373
434
  unsigned char s[32];
374
- fe_tobytes(s,f);
435
+
436
+ fe_tobytes(s, f);
375
437
 
376
438
  return s[0] & 1;
377
439
  }
@@ -386,12 +448,14 @@ int fe_isnegative(const fe f)
386
448
 
387
449
  static unsigned char zero[32];
388
450
 
389
- int fe_isnonzero(const fe f)
451
+ int
452
+ fe_isnonzero(const fe f)
390
453
  {
391
454
  unsigned char s[32];
392
- fe_tobytes(s,f);
393
455
 
394
- return crypto_verify_32(s,zero);
456
+ fe_tobytes(s, f);
457
+
458
+ return crypto_verify_32(s, zero);
395
459
  }
396
460
 
397
461
  /*
@@ -426,7 +490,8 @@ int fe_isnonzero(const fe f)
426
490
  With tighter constraints on inputs can squeeze carries into int32.
427
491
  */
428
492
 
429
- void fe_mul(fe h,const fe f,const fe g)
493
+ void
494
+ fe_mul(fe h, const fe f, const fe g)
430
495
  {
431
496
  int32_t f0 = f[0];
432
497
  int32_t f1 = f[1];
@@ -438,6 +503,7 @@ void fe_mul(fe h,const fe f,const fe g)
438
503
  int32_t f7 = f[7];
439
504
  int32_t f8 = f[8];
440
505
  int32_t f9 = f[9];
506
+
441
507
  int32_t g0 = g[0];
442
508
  int32_t g1 = g[1];
443
509
  int32_t g2 = g[2];
@@ -448,6 +514,7 @@ void fe_mul(fe h,const fe f,const fe g)
448
514
  int32_t g7 = g[7];
449
515
  int32_t g8 = g[8];
450
516
  int32_t g9 = g[9];
517
+
451
518
  int32_t g1_19 = 19 * g1; /* 1.959375*2^29 */
452
519
  int32_t g2_19 = 19 * g2; /* 1.959375*2^30; still ok */
453
520
  int32_t g3_19 = 19 * g3;
@@ -457,121 +524,134 @@ void fe_mul(fe h,const fe f,const fe g)
457
524
  int32_t g7_19 = 19 * g7;
458
525
  int32_t g8_19 = 19 * g8;
459
526
  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;
527
+ int32_t f1_2 = 2 * f1;
528
+ int32_t f3_2 = 2 * f3;
529
+ int32_t f5_2 = 2 * f5;
530
+ int32_t f7_2 = 2 * f7;
531
+ int32_t f9_2 = 2 * f9;
532
+
533
+ int64_t f0g0 = f0 * (int64_t) g0;
534
+ int64_t f0g1 = f0 * (int64_t) g1;
535
+ int64_t f0g2 = f0 * (int64_t) g2;
536
+ int64_t f0g3 = f0 * (int64_t) g3;
537
+ int64_t f0g4 = f0 * (int64_t) g4;
538
+ int64_t f0g5 = f0 * (int64_t) g5;
539
+ int64_t f0g6 = f0 * (int64_t) g6;
540
+ int64_t f0g7 = f0 * (int64_t) g7;
541
+ int64_t f0g8 = f0 * (int64_t) g8;
542
+ int64_t f0g9 = f0 * (int64_t) g9;
543
+ int64_t f1g0 = f1 * (int64_t) g0;
476
544
  int64_t f1g1_2 = f1_2 * (int64_t) g1;
477
- int64_t f1g2 = f1 * (int64_t) g2;
545
+ int64_t f1g2 = f1 * (int64_t) g2;
478
546
  int64_t f1g3_2 = f1_2 * (int64_t) g3;
479
- int64_t f1g4 = f1 * (int64_t) g4;
547
+ int64_t f1g4 = f1 * (int64_t) g4;
480
548
  int64_t f1g5_2 = f1_2 * (int64_t) g5;
481
- int64_t f1g6 = f1 * (int64_t) g6;
549
+ int64_t f1g6 = f1 * (int64_t) g6;
482
550
  int64_t f1g7_2 = f1_2 * (int64_t) g7;
483
- int64_t f1g8 = f1 * (int64_t) g8;
551
+ int64_t f1g8 = f1 * (int64_t) g8;
484
552
  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;
553
+ int64_t f2g0 = f2 * (int64_t) g0;
554
+ int64_t f2g1 = f2 * (int64_t) g1;
555
+ int64_t f2g2 = f2 * (int64_t) g2;
556
+ int64_t f2g3 = f2 * (int64_t) g3;
557
+ int64_t f2g4 = f2 * (int64_t) g4;
558
+ int64_t f2g5 = f2 * (int64_t) g5;
559
+ int64_t f2g6 = f2 * (int64_t) g6;
560
+ int64_t f2g7 = f2 * (int64_t) g7;
561
+ int64_t f2g8_19 = f2 * (int64_t) g8_19;
562
+ int64_t f2g9_19 = f2 * (int64_t) g9_19;
563
+ int64_t f3g0 = f3 * (int64_t) g0;
496
564
  int64_t f3g1_2 = f3_2 * (int64_t) g1;
497
- int64_t f3g2 = f3 * (int64_t) g2;
565
+ int64_t f3g2 = f3 * (int64_t) g2;
498
566
  int64_t f3g3_2 = f3_2 * (int64_t) g3;
499
- int64_t f3g4 = f3 * (int64_t) g4;
567
+ int64_t f3g4 = f3 * (int64_t) g4;
500
568
  int64_t f3g5_2 = f3_2 * (int64_t) g5;
501
- int64_t f3g6 = f3 * (int64_t) g6;
569
+ int64_t f3g6 = f3 * (int64_t) g6;
502
570
  int64_t f3g7_38 = f3_2 * (int64_t) g7_19;
503
- int64_t f3g8_19 = f3 * (int64_t) g8_19;
571
+ int64_t f3g8_19 = f3 * (int64_t) g8_19;
504
572
  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;
573
+ int64_t f4g0 = f4 * (int64_t) g0;
574
+ int64_t f4g1 = f4 * (int64_t) g1;
575
+ int64_t f4g2 = f4 * (int64_t) g2;
576
+ int64_t f4g3 = f4 * (int64_t) g3;
577
+ int64_t f4g4 = f4 * (int64_t) g4;
578
+ int64_t f4g5 = f4 * (int64_t) g5;
579
+ int64_t f4g6_19 = f4 * (int64_t) g6_19;
580
+ int64_t f4g7_19 = f4 * (int64_t) g7_19;
581
+ int64_t f4g8_19 = f4 * (int64_t) g8_19;
582
+ int64_t f4g9_19 = f4 * (int64_t) g9_19;
583
+ int64_t f5g0 = f5 * (int64_t) g0;
516
584
  int64_t f5g1_2 = f5_2 * (int64_t) g1;
517
- int64_t f5g2 = f5 * (int64_t) g2;
585
+ int64_t f5g2 = f5 * (int64_t) g2;
518
586
  int64_t f5g3_2 = f5_2 * (int64_t) g3;
519
- int64_t f5g4 = f5 * (int64_t) g4;
587
+ int64_t f5g4 = f5 * (int64_t) g4;
520
588
  int64_t f5g5_38 = f5_2 * (int64_t) g5_19;
521
- int64_t f5g6_19 = f5 * (int64_t) g6_19;
589
+ int64_t f5g6_19 = f5 * (int64_t) g6_19;
522
590
  int64_t f5g7_38 = f5_2 * (int64_t) g7_19;
523
- int64_t f5g8_19 = f5 * (int64_t) g8_19;
591
+ int64_t f5g8_19 = f5 * (int64_t) g8_19;
524
592
  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;
593
+ int64_t f6g0 = f6 * (int64_t) g0;
594
+ int64_t f6g1 = f6 * (int64_t) g1;
595
+ int64_t f6g2 = f6 * (int64_t) g2;
596
+ int64_t f6g3 = f6 * (int64_t) g3;
597
+ int64_t f6g4_19 = f6 * (int64_t) g4_19;
598
+ int64_t f6g5_19 = f6 * (int64_t) g5_19;
599
+ int64_t f6g6_19 = f6 * (int64_t) g6_19;
600
+ int64_t f6g7_19 = f6 * (int64_t) g7_19;
601
+ int64_t f6g8_19 = f6 * (int64_t) g8_19;
602
+ int64_t f6g9_19 = f6 * (int64_t) g9_19;
603
+ int64_t f7g0 = f7 * (int64_t) g0;
536
604
  int64_t f7g1_2 = f7_2 * (int64_t) g1;
537
- int64_t f7g2 = f7 * (int64_t) g2;
605
+ int64_t f7g2 = f7 * (int64_t) g2;
538
606
  int64_t f7g3_38 = f7_2 * (int64_t) g3_19;
539
- int64_t f7g4_19 = f7 * (int64_t) g4_19;
607
+ int64_t f7g4_19 = f7 * (int64_t) g4_19;
540
608
  int64_t f7g5_38 = f7_2 * (int64_t) g5_19;
541
- int64_t f7g6_19 = f7 * (int64_t) g6_19;
609
+ int64_t f7g6_19 = f7 * (int64_t) g6_19;
542
610
  int64_t f7g7_38 = f7_2 * (int64_t) g7_19;
543
- int64_t f7g8_19 = f7 * (int64_t) g8_19;
611
+ int64_t f7g8_19 = f7 * (int64_t) g8_19;
544
612
  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;
613
+ int64_t f8g0 = f8 * (int64_t) g0;
614
+ int64_t f8g1 = f8 * (int64_t) g1;
615
+ int64_t f8g2_19 = f8 * (int64_t) g2_19;
616
+ int64_t f8g3_19 = f8 * (int64_t) g3_19;
617
+ int64_t f8g4_19 = f8 * (int64_t) g4_19;
618
+ int64_t f8g5_19 = f8 * (int64_t) g5_19;
619
+ int64_t f8g6_19 = f8 * (int64_t) g6_19;
620
+ int64_t f8g7_19 = f8 * (int64_t) g7_19;
621
+ int64_t f8g8_19 = f8 * (int64_t) g8_19;
622
+ int64_t f8g9_19 = f8 * (int64_t) g9_19;
623
+ int64_t f9g0 = f9 * (int64_t) g0;
556
624
  int64_t f9g1_38 = f9_2 * (int64_t) g1_19;
557
- int64_t f9g2_19 = f9 * (int64_t) g2_19;
625
+ int64_t f9g2_19 = f9 * (int64_t) g2_19;
558
626
  int64_t f9g3_38 = f9_2 * (int64_t) g3_19;
559
- int64_t f9g4_19 = f9 * (int64_t) g4_19;
627
+ int64_t f9g4_19 = f9 * (int64_t) g4_19;
560
628
  int64_t f9g5_38 = f9_2 * (int64_t) g5_19;
561
- int64_t f9g6_19 = f9 * (int64_t) g6_19;
629
+ int64_t f9g6_19 = f9 * (int64_t) g6_19;
562
630
  int64_t f9g7_38 = f9_2 * (int64_t) g7_19;
563
- int64_t f9g8_19 = f9 * (int64_t) g8_19;
631
+ int64_t f9g8_19 = f9 * (int64_t) g8_19;
564
632
  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 ;
633
+
634
+ int64_t h0 = f0g0 + f1g9_38 + f2g8_19 + f3g7_38 + f4g6_19 + f5g5_38 +
635
+ f6g4_19 + f7g3_38 + f8g2_19 + f9g1_38;
636
+ int64_t h1 = f0g1 + f1g0 + f2g9_19 + f3g8_19 + f4g7_19 + f5g6_19 + f6g5_19 +
637
+ f7g4_19 + f8g3_19 + f9g2_19;
638
+ int64_t h2 = f0g2 + f1g1_2 + f2g0 + f3g9_38 + f4g8_19 + f5g7_38 + f6g6_19 +
639
+ f7g5_38 + f8g4_19 + f9g3_38;
640
+ int64_t h3 = f0g3 + f1g2 + f2g1 + f3g0 + f4g9_19 + f5g8_19 + f6g7_19 +
641
+ f7g6_19 + f8g5_19 + f9g4_19;
642
+ int64_t h4 = f0g4 + f1g3_2 + f2g2 + f3g1_2 + f4g0 + f5g9_38 + f6g8_19 +
643
+ f7g7_38 + f8g6_19 + f9g5_38;
644
+ int64_t h5 = f0g5 + f1g4 + f2g3 + f3g2 + f4g1 + f5g0 + f6g9_19 + f7g8_19 +
645
+ f8g7_19 + f9g6_19;
646
+ int64_t h6 = f0g6 + f1g5_2 + f2g4 + f3g3_2 + f4g2 + f5g1_2 + f6g0 +
647
+ f7g9_38 + f8g8_19 + f9g7_38;
648
+ int64_t h7 = f0g7 + f1g6 + f2g5 + f3g4 + f4g3 + f5g2 + f6g1 + f7g0 +
649
+ f8g9_19 + f9g8_19;
650
+ int64_t h8 = f0g8 + f1g7_2 + f2g6 + f3g5_2 + f4g4 + f5g3_2 + f6g2 + f7g1_2 +
651
+ f8g0 + f9g9_38;
652
+ int64_t h9 =
653
+ f0g9 + f1g8 + f2g7 + f3g6 + f4g5 + f5g4 + f6g3 + f7g2 + f8g1 + f9g0;
654
+
575
655
  int64_t carry0;
576
656
  int64_t carry1;
577
657
  int64_t carry2;
@@ -590,46 +670,70 @@ void fe_mul(fe h,const fe f,const fe g)
590
670
  i.e. |h1| <= 1.7*2^59; narrower ranges for h3, h5, h7, h9
591
671
  */
592
672
 
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);
673
+ carry0 = (h0 + (int64_t)(1L << 25)) >> 26;
674
+ h1 += carry0;
675
+ h0 -= carry0 * ((uint64_t) 1L << 26);
676
+ carry4 = (h4 + (int64_t)(1L << 25)) >> 26;
677
+ h5 += carry4;
678
+ h4 -= carry4 * ((uint64_t) 1L << 26);
595
679
  /* |h0| <= 2^25 */
596
680
  /* |h4| <= 2^25 */
597
681
  /* |h1| <= 1.71*2^59 */
598
682
  /* |h5| <= 1.71*2^59 */
599
683
 
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);
684
+ carry1 = (h1 + (int64_t)(1L << 24)) >> 25;
685
+ h2 += carry1;
686
+ h1 -= carry1 * ((uint64_t) 1L << 25);
687
+ carry5 = (h5 + (int64_t)(1L << 24)) >> 25;
688
+ h6 += carry5;
689
+ h5 -= carry5 * ((uint64_t) 1L << 25);
602
690
  /* |h1| <= 2^24; from now on fits into int32 */
603
691
  /* |h5| <= 2^24; from now on fits into int32 */
604
692
  /* |h2| <= 1.41*2^60 */
605
693
  /* |h6| <= 1.41*2^60 */
606
694
 
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);
695
+ carry2 = (h2 + (int64_t)(1L << 25)) >> 26;
696
+ h3 += carry2;
697
+ h2 -= carry2 * ((uint64_t) 1L << 26);
698
+ carry6 = (h6 + (int64_t)(1L << 25)) >> 26;
699
+ h7 += carry6;
700
+ h6 -= carry6 * ((uint64_t) 1L << 26);
609
701
  /* |h2| <= 2^25; from now on fits into int32 unchanged */
610
702
  /* |h6| <= 2^25; from now on fits into int32 unchanged */
611
703
  /* |h3| <= 1.71*2^59 */
612
704
  /* |h7| <= 1.71*2^59 */
613
705
 
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);
706
+ carry3 = (h3 + (int64_t)(1L << 24)) >> 25;
707
+ h4 += carry3;
708
+ h3 -= carry3 * ((uint64_t) 1L << 25);
709
+ carry7 = (h7 + (int64_t)(1L << 24)) >> 25;
710
+ h8 += carry7;
711
+ h7 -= carry7 * ((uint64_t) 1L << 25);
616
712
  /* |h3| <= 2^24; from now on fits into int32 unchanged */
617
713
  /* |h7| <= 2^24; from now on fits into int32 unchanged */
618
714
  /* |h4| <= 1.72*2^34 */
619
715
  /* |h8| <= 1.41*2^60 */
620
716
 
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);
717
+ carry4 = (h4 + (int64_t)(1L << 25)) >> 26;
718
+ h5 += carry4;
719
+ h4 -= carry4 * ((uint64_t) 1L << 26);
720
+ carry8 = (h8 + (int64_t)(1L << 25)) >> 26;
721
+ h9 += carry8;
722
+ h8 -= carry8 * ((uint64_t) 1L << 26);
623
723
  /* |h4| <= 2^25; from now on fits into int32 unchanged */
624
724
  /* |h8| <= 2^25; from now on fits into int32 unchanged */
625
725
  /* |h5| <= 1.01*2^24 */
626
726
  /* |h9| <= 1.71*2^59 */
627
727
 
628
- carry9 = (h9 + (int64_t) (1L << 24)) >> 25; h0 += carry9 * 19; h9 -= carry9 * ((uint64_t) 1L << 25);
728
+ carry9 = (h9 + (int64_t)(1L << 24)) >> 25;
729
+ h0 += carry9 * 19;
730
+ h9 -= carry9 * ((uint64_t) 1L << 25);
629
731
  /* |h9| <= 2^24; from now on fits into int32 unchanged */
630
732
  /* |h0| <= 1.1*2^39 */
631
733
 
632
- carry0 = (h0 + (int64_t) (1L << 25)) >> 26; h1 += carry0; h0 -= carry0 * ((uint64_t) 1L << 26);
734
+ carry0 = (h0 + (int64_t)(1L << 25)) >> 26;
735
+ h1 += carry0;
736
+ h0 -= carry0 * ((uint64_t) 1L << 26);
633
737
  /* |h0| <= 2^25; from now on fits into int32 unchanged */
634
738
  /* |h1| <= 1.01*2^24 */
635
739
 
@@ -655,7 +759,8 @@ void fe_mul(fe h,const fe f,const fe g)
655
759
  |h| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
656
760
  */
657
761
 
658
- void fe_neg(fe h,const fe f)
762
+ void
763
+ fe_neg(fe h, const fe f)
659
764
  {
660
765
  int32_t f0 = f[0];
661
766
  int32_t f1 = f[1];
@@ -667,6 +772,7 @@ void fe_neg(fe h,const fe f)
667
772
  int32_t f7 = f[7];
668
773
  int32_t f8 = f[8];
669
774
  int32_t f9 = f[9];
775
+
670
776
  int32_t h0 = -f0;
671
777
  int32_t h1 = -f1;
672
778
  int32_t h2 = -f2;
@@ -677,6 +783,7 @@ void fe_neg(fe h,const fe f)
677
783
  int32_t h7 = -f7;
678
784
  int32_t h8 = -f8;
679
785
  int32_t h9 = -f9;
786
+
680
787
  h[0] = h0;
681
788
  h[1] = h1;
682
789
  h[2] = h2;
@@ -704,7 +811,8 @@ void fe_neg(fe h,const fe f)
704
811
  See fe_mul.c for discussion of implementation strategy.
705
812
  */
706
813
 
707
- void fe_sq(fe h,const fe f)
814
+ void
815
+ fe_sq(fe h, const fe f)
708
816
  {
709
817
  int32_t f0 = f[0];
710
818
  int32_t f1 = f[1];
@@ -716,20 +824,22 @@ void fe_sq(fe h,const fe f)
716
824
  int32_t f7 = f[7];
717
825
  int32_t f8 = f[8];
718
826
  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;
827
+
828
+ int32_t f0_2 = 2 * f0;
829
+ int32_t f1_2 = 2 * f1;
830
+ int32_t f2_2 = 2 * f2;
831
+ int32_t f3_2 = 2 * f3;
832
+ int32_t f4_2 = 2 * f4;
833
+ int32_t f5_2 = 2 * f5;
834
+ int32_t f6_2 = 2 * f6;
835
+ int32_t f7_2 = 2 * f7;
727
836
  int32_t f5_38 = 38 * f5; /* 1.959375*2^30 */
728
837
  int32_t f6_19 = 19 * f6; /* 1.959375*2^30 */
729
838
  int32_t f7_38 = 38 * f7; /* 1.959375*2^30 */
730
839
  int32_t f8_19 = 19 * f8; /* 1.959375*2^30 */
731
840
  int32_t f9_38 = 38 * f9; /* 1.959375*2^30 */
732
- int64_t f0f0 = f0 * (int64_t) f0;
841
+
842
+ int64_t f0f0 = f0 * (int64_t) f0;
733
843
  int64_t f0f1_2 = f0_2 * (int64_t) f1;
734
844
  int64_t f0f2_2 = f0_2 * (int64_t) f2;
735
845
  int64_t f0f3_2 = f0_2 * (int64_t) f3;
@@ -748,14 +858,14 @@ void fe_sq(fe h,const fe f)
748
858
  int64_t f1f7_4 = f1_2 * (int64_t) f7_2;
749
859
  int64_t f1f8_2 = f1_2 * (int64_t) f8;
750
860
  int64_t f1f9_76 = f1_2 * (int64_t) f9_38;
751
- int64_t f2f2 = f2 * (int64_t) f2;
861
+ int64_t f2f2 = f2 * (int64_t) f2;
752
862
  int64_t f2f3_2 = f2_2 * (int64_t) f3;
753
863
  int64_t f2f4_2 = f2_2 * (int64_t) f4;
754
864
  int64_t f2f5_2 = f2_2 * (int64_t) f5;
755
865
  int64_t f2f6_2 = f2_2 * (int64_t) f6;
756
866
  int64_t f2f7_2 = f2_2 * (int64_t) f7;
757
867
  int64_t f2f8_38 = f2_2 * (int64_t) f8_19;
758
- int64_t f2f9_38 = f2 * (int64_t) f9_38;
868
+ int64_t f2f9_38 = f2 * (int64_t) f9_38;
759
869
  int64_t f3f3_2 = f3_2 * (int64_t) f3;
760
870
  int64_t f3f4_2 = f3_2 * (int64_t) f4;
761
871
  int64_t f3f5_4 = f3_2 * (int64_t) f5_2;
@@ -763,37 +873,39 @@ void fe_sq(fe h,const fe f)
763
873
  int64_t f3f7_76 = f3_2 * (int64_t) f7_38;
764
874
  int64_t f3f8_38 = f3_2 * (int64_t) f8_19;
765
875
  int64_t f3f9_76 = f3_2 * (int64_t) f9_38;
766
- int64_t f4f4 = f4 * (int64_t) f4;
876
+ int64_t f4f4 = f4 * (int64_t) f4;
767
877
  int64_t f4f5_2 = f4_2 * (int64_t) f5;
768
878
  int64_t f4f6_38 = f4_2 * (int64_t) f6_19;
769
- int64_t f4f7_38 = f4 * (int64_t) f7_38;
879
+ int64_t f4f7_38 = f4 * (int64_t) f7_38;
770
880
  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;
881
+ int64_t f4f9_38 = f4 * (int64_t) f9_38;
882
+ int64_t f5f5_38 = f5 * (int64_t) f5_38;
773
883
  int64_t f5f6_38 = f5_2 * (int64_t) f6_19;
774
884
  int64_t f5f7_76 = f5_2 * (int64_t) f7_38;
775
885
  int64_t f5f8_38 = f5_2 * (int64_t) f8_19;
776
886
  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;
887
+ int64_t f6f6_19 = f6 * (int64_t) f6_19;
888
+ int64_t f6f7_38 = f6 * (int64_t) f7_38;
779
889
  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;
890
+ int64_t f6f9_38 = f6 * (int64_t) f9_38;
891
+ int64_t f7f7_38 = f7 * (int64_t) f7_38;
782
892
  int64_t f7f8_38 = f7_2 * (int64_t) f8_19;
783
893
  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;
894
+ int64_t f8f8_19 = f8 * (int64_t) f8_19;
895
+ int64_t f8f9_38 = f8 * (int64_t) f9_38;
896
+ int64_t f9f9_38 = f9 * (int64_t) f9_38;
897
+
898
+ int64_t h0 = f0f0 + f1f9_76 + f2f8_38 + f3f7_76 + f4f6_38 + f5f5_38;
899
+ int64_t h1 = f0f1_2 + f2f9_38 + f3f8_38 + f4f7_38 + f5f6_38;
900
+ int64_t h2 = f0f2_2 + f1f1_2 + f3f9_76 + f4f8_38 + f5f7_76 + f6f6_19;
901
+ int64_t h3 = f0f3_2 + f1f2_2 + f4f9_38 + f5f8_38 + f6f7_38;
902
+ int64_t h4 = f0f4_2 + f1f3_4 + f2f2 + f5f9_76 + f6f8_38 + f7f7_38;
903
+ int64_t h5 = f0f5_2 + f1f4_2 + f2f3_2 + f6f9_38 + f7f8_38;
904
+ int64_t h6 = f0f6_2 + f1f5_4 + f2f4_2 + f3f3_2 + f7f9_76 + f8f8_19;
905
+ int64_t h7 = f0f7_2 + f1f6_2 + f2f5_2 + f3f4_2 + f8f9_38;
906
+ int64_t h8 = f0f8_2 + f1f7_4 + f2f6_2 + f3f5_4 + f4f4 + f9f9_38;
907
+ int64_t h9 = f0f9_2 + f1f8_2 + f2f7_2 + f3f6_2 + f4f5_2;
908
+
797
909
  int64_t carry0;
798
910
  int64_t carry1;
799
911
  int64_t carry2;
@@ -805,24 +917,48 @@ void fe_sq(fe h,const fe f)
805
917
  int64_t carry8;
806
918
  int64_t carry9;
807
919
 
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);
920
+ carry0 = (h0 + (int64_t)(1L << 25)) >> 26;
921
+ h1 += carry0;
922
+ h0 -= carry0 * ((uint64_t) 1L << 26);
923
+ carry4 = (h4 + (int64_t)(1L << 25)) >> 26;
924
+ h5 += carry4;
925
+ h4 -= carry4 * ((uint64_t) 1L << 26);
926
+
927
+ carry1 = (h1 + (int64_t)(1L << 24)) >> 25;
928
+ h2 += carry1;
929
+ h1 -= carry1 * ((uint64_t) 1L << 25);
930
+ carry5 = (h5 + (int64_t)(1L << 24)) >> 25;
931
+ h6 += carry5;
932
+ h5 -= carry5 * ((uint64_t) 1L << 25);
933
+
934
+ carry2 = (h2 + (int64_t)(1L << 25)) >> 26;
935
+ h3 += carry2;
936
+ h2 -= carry2 * ((uint64_t) 1L << 26);
937
+ carry6 = (h6 + (int64_t)(1L << 25)) >> 26;
938
+ h7 += carry6;
939
+ h6 -= carry6 * ((uint64_t) 1L << 26);
940
+
941
+ carry3 = (h3 + (int64_t)(1L << 24)) >> 25;
942
+ h4 += carry3;
943
+ h3 -= carry3 * ((uint64_t) 1L << 25);
944
+ carry7 = (h7 + (int64_t)(1L << 24)) >> 25;
945
+ h8 += carry7;
946
+ h7 -= carry7 * ((uint64_t) 1L << 25);
947
+
948
+ carry4 = (h4 + (int64_t)(1L << 25)) >> 26;
949
+ h5 += carry4;
950
+ h4 -= carry4 * ((uint64_t) 1L << 26);
951
+ carry8 = (h8 + (int64_t)(1L << 25)) >> 26;
952
+ h9 += carry8;
953
+ h8 -= carry8 * ((uint64_t) 1L << 26);
954
+
955
+ carry9 = (h9 + (int64_t)(1L << 24)) >> 25;
956
+ h0 += carry9 * 19;
957
+ h9 -= carry9 * ((uint64_t) 1L << 25);
958
+
959
+ carry0 = (h0 + (int64_t)(1L << 25)) >> 26;
960
+ h1 += carry0;
961
+ h0 -= carry0 * ((uint64_t) 1L << 26);
826
962
 
827
963
  h[0] = (int32_t) h0;
828
964
  h[1] = (int32_t) h1;
@@ -851,7 +987,8 @@ void fe_sq(fe h,const fe f)
851
987
  See fe_mul.c for discussion of implementation strategy.
852
988
  */
853
989
 
854
- void fe_sq2(fe h,const fe f)
990
+ void
991
+ fe_sq2(fe h, const fe f)
855
992
  {
856
993
  int32_t f0 = f[0];
857
994
  int32_t f1 = f[1];
@@ -863,20 +1000,22 @@ void fe_sq2(fe h,const fe f)
863
1000
  int32_t f7 = f[7];
864
1001
  int32_t f8 = f[8];
865
1002
  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;
1003
+
1004
+ int32_t f0_2 = 2 * f0;
1005
+ int32_t f1_2 = 2 * f1;
1006
+ int32_t f2_2 = 2 * f2;
1007
+ int32_t f3_2 = 2 * f3;
1008
+ int32_t f4_2 = 2 * f4;
1009
+ int32_t f5_2 = 2 * f5;
1010
+ int32_t f6_2 = 2 * f6;
1011
+ int32_t f7_2 = 2 * f7;
874
1012
  int32_t f5_38 = 38 * f5; /* 1.959375*2^30 */
875
1013
  int32_t f6_19 = 19 * f6; /* 1.959375*2^30 */
876
1014
  int32_t f7_38 = 38 * f7; /* 1.959375*2^30 */
877
1015
  int32_t f8_19 = 19 * f8; /* 1.959375*2^30 */
878
1016
  int32_t f9_38 = 38 * f9; /* 1.959375*2^30 */
879
- int64_t f0f0 = f0 * (int64_t) f0;
1017
+
1018
+ int64_t f0f0 = f0 * (int64_t) f0;
880
1019
  int64_t f0f1_2 = f0_2 * (int64_t) f1;
881
1020
  int64_t f0f2_2 = f0_2 * (int64_t) f2;
882
1021
  int64_t f0f3_2 = f0_2 * (int64_t) f3;
@@ -895,14 +1034,14 @@ void fe_sq2(fe h,const fe f)
895
1034
  int64_t f1f7_4 = f1_2 * (int64_t) f7_2;
896
1035
  int64_t f1f8_2 = f1_2 * (int64_t) f8;
897
1036
  int64_t f1f9_76 = f1_2 * (int64_t) f9_38;
898
- int64_t f2f2 = f2 * (int64_t) f2;
1037
+ int64_t f2f2 = f2 * (int64_t) f2;
899
1038
  int64_t f2f3_2 = f2_2 * (int64_t) f3;
900
1039
  int64_t f2f4_2 = f2_2 * (int64_t) f4;
901
1040
  int64_t f2f5_2 = f2_2 * (int64_t) f5;
902
1041
  int64_t f2f6_2 = f2_2 * (int64_t) f6;
903
1042
  int64_t f2f7_2 = f2_2 * (int64_t) f7;
904
1043
  int64_t f2f8_38 = f2_2 * (int64_t) f8_19;
905
- int64_t f2f9_38 = f2 * (int64_t) f9_38;
1044
+ int64_t f2f9_38 = f2 * (int64_t) f9_38;
906
1045
  int64_t f3f3_2 = f3_2 * (int64_t) f3;
907
1046
  int64_t f3f4_2 = f3_2 * (int64_t) f4;
908
1047
  int64_t f3f5_4 = f3_2 * (int64_t) f5_2;
@@ -910,37 +1049,39 @@ void fe_sq2(fe h,const fe f)
910
1049
  int64_t f3f7_76 = f3_2 * (int64_t) f7_38;
911
1050
  int64_t f3f8_38 = f3_2 * (int64_t) f8_19;
912
1051
  int64_t f3f9_76 = f3_2 * (int64_t) f9_38;
913
- int64_t f4f4 = f4 * (int64_t) f4;
1052
+ int64_t f4f4 = f4 * (int64_t) f4;
914
1053
  int64_t f4f5_2 = f4_2 * (int64_t) f5;
915
1054
  int64_t f4f6_38 = f4_2 * (int64_t) f6_19;
916
- int64_t f4f7_38 = f4 * (int64_t) f7_38;
1055
+ int64_t f4f7_38 = f4 * (int64_t) f7_38;
917
1056
  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;
1057
+ int64_t f4f9_38 = f4 * (int64_t) f9_38;
1058
+ int64_t f5f5_38 = f5 * (int64_t) f5_38;
920
1059
  int64_t f5f6_38 = f5_2 * (int64_t) f6_19;
921
1060
  int64_t f5f7_76 = f5_2 * (int64_t) f7_38;
922
1061
  int64_t f5f8_38 = f5_2 * (int64_t) f8_19;
923
1062
  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;
1063
+ int64_t f6f6_19 = f6 * (int64_t) f6_19;
1064
+ int64_t f6f7_38 = f6 * (int64_t) f7_38;
926
1065
  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;
1066
+ int64_t f6f9_38 = f6 * (int64_t) f9_38;
1067
+ int64_t f7f7_38 = f7 * (int64_t) f7_38;
929
1068
  int64_t f7f8_38 = f7_2 * (int64_t) f8_19;
930
1069
  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;
1070
+ int64_t f8f8_19 = f8 * (int64_t) f8_19;
1071
+ int64_t f8f9_38 = f8 * (int64_t) f9_38;
1072
+ int64_t f9f9_38 = f9 * (int64_t) f9_38;
1073
+
1074
+ int64_t h0 = f0f0 + f1f9_76 + f2f8_38 + f3f7_76 + f4f6_38 + f5f5_38;
1075
+ int64_t h1 = f0f1_2 + f2f9_38 + f3f8_38 + f4f7_38 + f5f6_38;
1076
+ int64_t h2 = f0f2_2 + f1f1_2 + f3f9_76 + f4f8_38 + f5f7_76 + f6f6_19;
1077
+ int64_t h3 = f0f3_2 + f1f2_2 + f4f9_38 + f5f8_38 + f6f7_38;
1078
+ int64_t h4 = f0f4_2 + f1f3_4 + f2f2 + f5f9_76 + f6f8_38 + f7f7_38;
1079
+ int64_t h5 = f0f5_2 + f1f4_2 + f2f3_2 + f6f9_38 + f7f8_38;
1080
+ int64_t h6 = f0f6_2 + f1f5_4 + f2f4_2 + f3f3_2 + f7f9_76 + f8f8_19;
1081
+ int64_t h7 = f0f7_2 + f1f6_2 + f2f5_2 + f3f4_2 + f8f9_38;
1082
+ int64_t h8 = f0f8_2 + f1f7_4 + f2f6_2 + f3f5_4 + f4f4 + f9f9_38;
1083
+ int64_t h9 = f0f9_2 + f1f8_2 + f2f7_2 + f3f6_2 + f4f5_2;
1084
+
944
1085
  int64_t carry0;
945
1086
  int64_t carry1;
946
1087
  int64_t carry2;
@@ -963,24 +1104,48 @@ void fe_sq2(fe h,const fe f)
963
1104
  h8 += h8;
964
1105
  h9 += h9;
965
1106
 
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);
1107
+ carry0 = (h0 + (int64_t)(1L << 25)) >> 26;
1108
+ h1 += carry0;
1109
+ h0 -= carry0 * ((uint64_t) 1L << 26);
1110
+ carry4 = (h4 + (int64_t)(1L << 25)) >> 26;
1111
+ h5 += carry4;
1112
+ h4 -= carry4 * ((uint64_t) 1L << 26);
1113
+
1114
+ carry1 = (h1 + (int64_t)(1L << 24)) >> 25;
1115
+ h2 += carry1;
1116
+ h1 -= carry1 * ((uint64_t) 1L << 25);
1117
+ carry5 = (h5 + (int64_t)(1L << 24)) >> 25;
1118
+ h6 += carry5;
1119
+ h5 -= carry5 * ((uint64_t) 1L << 25);
1120
+
1121
+ carry2 = (h2 + (int64_t)(1L << 25)) >> 26;
1122
+ h3 += carry2;
1123
+ h2 -= carry2 * ((uint64_t) 1L << 26);
1124
+ carry6 = (h6 + (int64_t)(1L << 25)) >> 26;
1125
+ h7 += carry6;
1126
+ h6 -= carry6 * ((uint64_t) 1L << 26);
1127
+
1128
+ carry3 = (h3 + (int64_t)(1L << 24)) >> 25;
1129
+ h4 += carry3;
1130
+ h3 -= carry3 * ((uint64_t) 1L << 25);
1131
+ carry7 = (h7 + (int64_t)(1L << 24)) >> 25;
1132
+ h8 += carry7;
1133
+ h7 -= carry7 * ((uint64_t) 1L << 25);
1134
+
1135
+ carry4 = (h4 + (int64_t)(1L << 25)) >> 26;
1136
+ h5 += carry4;
1137
+ h4 -= carry4 * ((uint64_t) 1L << 26);
1138
+ carry8 = (h8 + (int64_t)(1L << 25)) >> 26;
1139
+ h9 += carry8;
1140
+ h8 -= carry8 * ((uint64_t) 1L << 26);
1141
+
1142
+ carry9 = (h9 + (int64_t)(1L << 24)) >> 25;
1143
+ h0 += carry9 * 19;
1144
+ h9 -= carry9 * ((uint64_t) 1L << 25);
1145
+
1146
+ carry0 = (h0 + (int64_t)(1L << 25)) >> 26;
1147
+ h1 += carry0;
1148
+ h0 -= carry0 * ((uint64_t) 1L << 26);
984
1149
 
985
1150
  h[0] = (int32_t) h0;
986
1151
  h[1] = (int32_t) h1;
@@ -994,12 +1159,13 @@ void fe_sq2(fe h,const fe f)
994
1159
  h[9] = (int32_t) h9;
995
1160
  }
996
1161
 
997
- void fe_invert(fe out,const fe z)
1162
+ void
1163
+ fe_invert(fe out, const fe z)
998
1164
  {
999
- fe t0;
1000
- fe t1;
1001
- fe t2;
1002
- fe t3;
1165
+ fe t0;
1166
+ fe t1;
1167
+ fe t2;
1168
+ fe t3;
1003
1169
  int i;
1004
1170
 
1005
1171
  fe_sq(t0, z);
@@ -1051,11 +1217,12 @@ void fe_invert(fe out,const fe z)
1051
1217
  fe_mul(out, t1, t0);
1052
1218
  }
1053
1219
 
1054
- void fe_pow22523(fe out,const fe z)
1220
+ void
1221
+ fe_pow22523(fe out, const fe z)
1055
1222
  {
1056
- fe t0;
1057
- fe t1;
1058
- fe t2;
1223
+ fe t0;
1224
+ fe t1;
1225
+ fe t2;
1059
1226
  int i;
1060
1227
 
1061
1228
  fe_sq(t0, z);
@@ -1117,7 +1284,8 @@ void fe_pow22523(fe out,const fe z)
1117
1284
  |h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
1118
1285
  */
1119
1286
 
1120
- void fe_sub(fe h,const fe f,const fe g)
1287
+ void
1288
+ fe_sub(fe h, const fe f, const fe g)
1121
1289
  {
1122
1290
  int32_t f0 = f[0];
1123
1291
  int32_t f1 = f[1];
@@ -1139,6 +1307,7 @@ void fe_sub(fe h,const fe f,const fe g)
1139
1307
  int32_t g7 = g[7];
1140
1308
  int32_t g8 = g[8];
1141
1309
  int32_t g9 = g[9];
1310
+
1142
1311
  int32_t h0 = f0 - g0;
1143
1312
  int32_t h1 = f1 - g1;
1144
1313
  int32_t h2 = f2 - g2;
@@ -1149,6 +1318,7 @@ void fe_sub(fe h,const fe f,const fe g)
1149
1318
  int32_t h7 = f7 - g7;
1150
1319
  int32_t h8 = f8 - g8;
1151
1320
  int32_t h9 = f9 - g9;
1321
+
1152
1322
  h[0] = h0;
1153
1323
  h[1] = h1;
1154
1324
  h[2] = h2;
@@ -1165,7 +1335,8 @@ void fe_sub(fe h,const fe f,const fe g)
1165
1335
  r = p + q
1166
1336
  */
1167
1337
 
1168
- void ge_add(ge_p1p1 *r,const ge_p3 *p,const ge_cached *q)
1338
+ void
1339
+ ge_add(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q)
1169
1340
  {
1170
1341
  fe t0;
1171
1342
 
@@ -1182,53 +1353,63 @@ void ge_add(ge_p1p1 *r,const ge_p3 *p,const ge_cached *q)
1182
1353
  fe_sub(r->T, t0, r->T);
1183
1354
  }
1184
1355
 
1185
- static void slide(signed char *r,const unsigned char *a)
1356
+ static void
1357
+ slide(signed char *r, const unsigned char *a)
1186
1358
  {
1187
1359
  int i;
1188
1360
  int b;
1189
1361
  int k;
1362
+ int ribs;
1363
+ int cmp;
1190
1364
 
1191
- for (i = 0;i < 256;++i)
1365
+ for (i = 0; i < 256; ++i) {
1192
1366
  r[i] = 1 & (a[i >> 3] >> (i & 7));
1193
-
1194
- for (i = 0;i < 256;++i)
1367
+ }
1368
+ for (i = 0; i < 256; ++i) {
1195
1369
  if (r[i]) {
1196
- for (b = 1;b <= 6 && i + b < 256;++b) {
1370
+ for (b = 1; b <= 6 && i + b < 256; ++b) {
1197
1371
  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;
1372
+ ribs = r[i + b] << b;
1373
+ cmp = r[i] + ribs;
1374
+ if (cmp <= 15) {
1375
+ r[i] = cmp;
1376
+ r[i + b] = 0;
1377
+ } else {
1378
+ cmp = r[i] - ribs;
1379
+ if (cmp >= -15) {
1380
+ r[i] = cmp;
1381
+ for (k = i + b; k < 256; ++k) {
1382
+ if (!r[k]) {
1383
+ r[k] = 1;
1384
+ break;
1385
+ }
1386
+ r[k] = 0;
1206
1387
  }
1207
- r[k] = 0;
1388
+ } else {
1389
+ break;
1208
1390
  }
1209
- } else
1210
- break;
1391
+ }
1211
1392
  }
1212
1393
  }
1213
1394
  }
1214
-
1395
+ }
1215
1396
  }
1216
1397
 
1217
1398
  static const ge_precomp Bi[8] = {
1218
1399
  #include "base2.h"
1219
1400
  };
1220
1401
 
1221
- /* 37095705934669439343138083508754565189542113879843219016388785533085940283555 */
1222
- static const fe d = {
1223
- -10913610,13857413,-15372611,6949391,114729,-8787816,-6275908,-3247719,-18696448,-12055116
1224
- };
1402
+ /* 37095705934669439343138083508754565189542113879843219016388785533085940283555
1403
+ */
1404
+ static const fe d = { -10913610, 13857413, -15372611, 6949391, 114729,
1405
+ -8787816, -6275908, -3247719, -18696448, -12055116 };
1225
1406
 
1226
1407
  /* sqrt(-1) */
1227
- static const fe sqrtm1 = {
1228
- -32595792,-7943725,9377950,3500415,12389472,-272473,-25146209,-2005654,326686,11406482
1229
- };
1408
+ static const fe sqrtm1 = { -32595792, -7943725, 9377950, 3500415, 12389472,
1409
+ -272473, -25146209, -2005654, 326686, 11406482 };
1230
1410
 
1231
- int ge_frombytes_negate_vartime(ge_p3 *h,const unsigned char *s)
1411
+ int
1412
+ ge_frombytes_negate_vartime(ge_p3 *h, const unsigned char *s)
1232
1413
  {
1233
1414
  fe u;
1234
1415
  fe v;
@@ -1236,38 +1417,38 @@ int ge_frombytes_negate_vartime(ge_p3 *h,const unsigned char *s)
1236
1417
  fe vxx;
1237
1418
  fe check;
1238
1419
 
1239
- fe_frombytes(h->Y,s);
1420
+ fe_frombytes(h->Y, s);
1240
1421
  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 */
1422
+ fe_sq(u, h->Y);
1423
+ fe_mul(v, u, d);
1424
+ fe_sub(u, u, h->Z); /* u = y^2-1 */
1425
+ fe_add(v, v, h->Z); /* v = dy^2+1 */
1426
+
1427
+ fe_sq(v3, v);
1428
+ fe_mul(v3, v3, v); /* v3 = v^3 */
1429
+ fe_sq(h->X, v3);
1430
+ fe_mul(h->X, h->X, v);
1431
+ fe_mul(h->X, h->X, u); /* x = uv^7 */
1432
+
1433
+ fe_pow22523(h->X, h->X); /* x = (uv^7)^((q-5)/8) */
1434
+ fe_mul(h->X, h->X, v3);
1435
+ fe_mul(h->X, h->X, u); /* x = uv^3(uv^7)^((q-5)/8) */
1436
+
1437
+ fe_sq(vxx, h->X);
1438
+ fe_mul(vxx, vxx, v);
1439
+ fe_sub(check, vxx, u); /* vx^2-u */
1259
1440
  if (fe_isnonzero(check)) {
1260
- fe_add(check,vxx,u); /* vx^2+u */
1441
+ fe_add(check, vxx, u); /* vx^2+u */
1261
1442
  if (fe_isnonzero(check)) {
1262
1443
  return -1;
1263
1444
  }
1264
- fe_mul(h->X,h->X,sqrtm1);
1445
+ fe_mul(h->X, h->X, sqrtm1);
1265
1446
  }
1266
1447
 
1267
1448
  if (fe_isnegative(h->X) == (s[31] >> 7)) {
1268
- fe_neg(h->X,h->X);
1449
+ fe_neg(h->X, h->X);
1269
1450
  }
1270
- fe_mul(h->T,h->X,h->Y);
1451
+ fe_mul(h->T, h->X, h->Y);
1271
1452
 
1272
1453
  return 0;
1273
1454
  }
@@ -1276,7 +1457,8 @@ int ge_frombytes_negate_vartime(ge_p3 *h,const unsigned char *s)
1276
1457
  r = p + q
1277
1458
  */
1278
1459
 
1279
- void ge_madd(ge_p1p1 *r,const ge_p3 *p,const ge_precomp *q)
1460
+ void
1461
+ ge_madd(ge_p1p1 *r, const ge_p3 *p, const ge_precomp *q)
1280
1462
  {
1281
1463
  fe t0;
1282
1464
 
@@ -1296,7 +1478,8 @@ void ge_madd(ge_p1p1 *r,const ge_p3 *p,const ge_precomp *q)
1296
1478
  r = p - q
1297
1479
  */
1298
1480
 
1299
- void ge_msub(ge_p1p1 *r,const ge_p3 *p,const ge_precomp *q)
1481
+ void
1482
+ ge_msub(ge_p1p1 *r, const ge_p3 *p, const ge_precomp *q)
1300
1483
  {
1301
1484
  fe t0;
1302
1485
 
@@ -1316,26 +1499,29 @@ void ge_msub(ge_p1p1 *r,const ge_p3 *p,const ge_precomp *q)
1316
1499
  r = p
1317
1500
  */
1318
1501
 
1319
- extern void ge_p1p1_to_p2(ge_p2 *r,const ge_p1p1 *p)
1502
+ extern void
1503
+ ge_p1p1_to_p2(ge_p2 *r, const ge_p1p1 *p)
1320
1504
  {
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);
1505
+ fe_mul(r->X, p->X, p->T);
1506
+ fe_mul(r->Y, p->Y, p->Z);
1507
+ fe_mul(r->Z, p->Z, p->T);
1324
1508
  }
1325
1509
 
1326
1510
  /*
1327
1511
  r = p
1328
1512
  */
1329
1513
 
1330
- extern void ge_p1p1_to_p3(ge_p3 *r,const ge_p1p1 *p)
1514
+ extern void
1515
+ ge_p1p1_to_p3(ge_p3 *r, const ge_p1p1 *p)
1331
1516
  {
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);
1517
+ fe_mul(r->X, p->X, p->T);
1518
+ fe_mul(r->Y, p->Y, p->Z);
1519
+ fe_mul(r->Z, p->Z, p->T);
1520
+ fe_mul(r->T, p->X, p->Y);
1336
1521
  }
1337
1522
 
1338
- void ge_p2_0(ge_p2 *h)
1523
+ void
1524
+ ge_p2_0(ge_p2 *h)
1339
1525
  {
1340
1526
  fe_0(h->X);
1341
1527
  fe_1(h->Y);
@@ -1346,7 +1532,8 @@ void ge_p2_0(ge_p2 *h)
1346
1532
  r = 2 * p
1347
1533
  */
1348
1534
 
1349
- void ge_p2_dbl(ge_p1p1 *r,const ge_p2 *p)
1535
+ void
1536
+ ge_p2_dbl(ge_p1p1 *r, const ge_p2 *p)
1350
1537
  {
1351
1538
  fe t0;
1352
1539
 
@@ -1361,7 +1548,8 @@ void ge_p2_dbl(ge_p1p1 *r,const ge_p2 *p)
1361
1548
  fe_sub(r->T, r->T, r->Z);
1362
1549
  }
1363
1550
 
1364
- void ge_p3_0(ge_p3 *h)
1551
+ void
1552
+ ge_p3_0(ge_p3 *h)
1365
1553
  {
1366
1554
  fe_0(h->X);
1367
1555
  fe_1(h->Y);
@@ -1373,40 +1561,44 @@ void ge_p3_0(ge_p3 *h)
1373
1561
  r = p
1374
1562
  */
1375
1563
 
1376
- /* 2 * d = 16295367250680780974490674513165176452449235426866156013048779062215315747161 */
1377
- static const fe d2 = {
1378
- -21827239,-5839606,-30745221,13898782,229458,15978800,-12551817,-6495438,29715968,9444199
1379
- };
1564
+ /* 2 * d =
1565
+ * 16295367250680780974490674513165176452449235426866156013048779062215315747161
1566
+ */
1567
+ static const fe d2 = { -21827239, -5839606, -30745221, 13898782, 229458,
1568
+ 15978800, -12551817, -6495438, 29715968, 9444199 };
1380
1569
 
1381
- extern void ge_p3_to_cached(ge_cached *r,const ge_p3 *p)
1570
+ extern void
1571
+ ge_p3_to_cached(ge_cached *r, const ge_p3 *p)
1382
1572
  {
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);
1573
+ fe_add(r->YplusX, p->Y, p->X);
1574
+ fe_sub(r->YminusX, p->Y, p->X);
1575
+ fe_copy(r->Z, p->Z);
1576
+ fe_mul(r->T2d, p->T, d2);
1387
1577
  }
1388
1578
 
1389
1579
  /*
1390
1580
  r = p
1391
1581
  */
1392
1582
 
1393
- extern void ge_p3_to_p2(ge_p2 *r,const ge_p3 *p)
1583
+ extern void
1584
+ ge_p3_to_p2(ge_p2 *r, const ge_p3 *p)
1394
1585
  {
1395
- fe_copy(r->X,p->X);
1396
- fe_copy(r->Y,p->Y);
1397
- fe_copy(r->Z,p->Z);
1586
+ fe_copy(r->X, p->X);
1587
+ fe_copy(r->Y, p->Y);
1588
+ fe_copy(r->Z, p->Z);
1398
1589
  }
1399
1590
 
1400
- void ge_p3_tobytes(unsigned char *s,const ge_p3 *h)
1591
+ void
1592
+ ge_p3_tobytes(unsigned char *s, const ge_p3 *h)
1401
1593
  {
1402
1594
  fe recip;
1403
1595
  fe x;
1404
1596
  fe y;
1405
1597
 
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);
1598
+ fe_invert(recip, h->Z);
1599
+ fe_mul(x, h->X, recip);
1600
+ fe_mul(y, h->Y, recip);
1601
+ fe_tobytes(s, y);
1410
1602
  s[31] ^= fe_isnegative(x) << 7;
1411
1603
  }
1412
1604
 
@@ -1414,45 +1606,53 @@ void ge_p3_tobytes(unsigned char *s,const ge_p3 *h)
1414
1606
  r = 2 * p
1415
1607
  */
1416
1608
 
1417
- void ge_p3_dbl(ge_p1p1 *r,const ge_p3 *p)
1609
+ void
1610
+ ge_p3_dbl(ge_p1p1 *r, const ge_p3 *p)
1418
1611
  {
1419
1612
  ge_p2 q;
1420
- ge_p3_to_p2(&q,p);
1421
- ge_p2_dbl(r,&q);
1613
+ ge_p3_to_p2(&q, p);
1614
+ ge_p2_dbl(r, &q);
1422
1615
  }
1423
1616
 
1424
- void ge_precomp_0(ge_precomp *h)
1617
+ void
1618
+ ge_precomp_0(ge_precomp *h)
1425
1619
  {
1426
1620
  fe_1(h->yplusx);
1427
1621
  fe_1(h->yminusx);
1428
1622
  fe_0(h->xy2d);
1429
1623
  }
1430
1624
 
1431
- static unsigned char equal(signed char b,signed char c)
1625
+ static unsigned char
1626
+ equal(signed char b, signed char c)
1432
1627
  {
1433
1628
  unsigned char ub = b;
1434
1629
  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 */
1630
+ unsigned char x = ub ^ uc; /* 0: yes; 1..255: no */
1631
+ uint32_t y = x; /* 0: yes; 1..255: no */
1632
+
1633
+ y -= 1; /* 4294967295: yes; 0..254: no */
1438
1634
  y >>= 31; /* 1: yes; 0: no */
1439
1635
 
1440
1636
  return y;
1441
1637
  }
1442
1638
 
1443
- static unsigned char negative(signed char b)
1639
+ static unsigned char
1640
+ negative(signed char b)
1444
1641
  {
1445
- uint64_t x = b; /* 18446744073709551361..18446744073709551615: yes; 0..255: no */
1642
+ uint64_t x =
1643
+ b; /* 18446744073709551361..18446744073709551615: yes; 0..255: no */
1644
+
1446
1645
  x >>= 63; /* 1: yes; 0: no */
1447
1646
 
1448
1647
  return x;
1449
1648
  }
1450
1649
 
1451
- static void cmov(ge_precomp *t,const ge_precomp *u,unsigned char b)
1650
+ static void
1651
+ cmov(ge_precomp *t, const ge_precomp *u, unsigned char b)
1452
1652
  {
1453
- fe_cmov(t->yplusx,u->yplusx,b);
1454
- fe_cmov(t->yminusx,u->yminusx,b);
1455
- fe_cmov(t->xy2d,u->xy2d,b);
1653
+ fe_cmov(t->yplusx, u->yplusx, b);
1654
+ fe_cmov(t->yminusx, u->yminusx, b);
1655
+ fe_cmov(t->xy2d, u->xy2d, b);
1456
1656
  }
1457
1657
 
1458
1658
  /* base[i][j] = (j+1)*256^i*B */
@@ -1460,32 +1660,34 @@ static const ge_precomp base[32][8] = {
1460
1660
  #include "base.h"
1461
1661
  };
1462
1662
 
1463
- static void ge_select(ge_precomp *t,int pos,signed char b)
1663
+ static void
1664
+ ge_select(ge_precomp *t, int pos, signed char b)
1464
1665
  {
1465
- ge_precomp minust;
1666
+ ge_precomp minust;
1466
1667
  unsigned char bnegative = negative(b);
1467
- unsigned char babs = b - (((-bnegative) & b) * ((signed char) 1 << 1));
1668
+ unsigned char babs = b - (((-bnegative) & b) * ((signed char) 1 << 1));
1468
1669
 
1469
1670
  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);
1671
+ cmov(t, &base[pos][0], equal(babs, 1));
1672
+ cmov(t, &base[pos][1], equal(babs, 2));
1673
+ cmov(t, &base[pos][2], equal(babs, 3));
1674
+ cmov(t, &base[pos][3], equal(babs, 4));
1675
+ cmov(t, &base[pos][4], equal(babs, 5));
1676
+ cmov(t, &base[pos][5], equal(babs, 6));
1677
+ cmov(t, &base[pos][6], equal(babs, 7));
1678
+ cmov(t, &base[pos][7], equal(babs, 8));
1679
+ fe_copy(minust.yplusx, t->yminusx);
1680
+ fe_copy(minust.yminusx, t->yplusx);
1681
+ fe_neg(minust.xy2d, t->xy2d);
1682
+ cmov(t, &minust, bnegative);
1482
1683
  }
1483
1684
 
1484
1685
  /*
1485
1686
  r = p - q
1486
1687
  */
1487
1688
 
1488
- void ge_sub(ge_p1p1 *r,const ge_p3 *p,const ge_cached *q)
1689
+ void
1690
+ ge_sub(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q)
1489
1691
  {
1490
1692
  fe t0;
1491
1693
 
@@ -1502,16 +1704,17 @@ void ge_sub(ge_p1p1 *r,const ge_p3 *p,const ge_cached *q)
1502
1704
  fe_add(r->T, t0, r->T);
1503
1705
  }
1504
1706
 
1505
- void ge_tobytes(unsigned char *s,const ge_p2 *h)
1707
+ void
1708
+ ge_tobytes(unsigned char *s, const ge_p2 *h)
1506
1709
  {
1507
1710
  fe recip;
1508
1711
  fe x;
1509
1712
  fe y;
1510
1713
 
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);
1714
+ fe_invert(recip, h->Z);
1715
+ fe_mul(x, h->X, recip);
1716
+ fe_mul(y, h->Y, recip);
1717
+ fe_tobytes(s, y);
1515
1718
  s[31] ^= fe_isnegative(x) << 7;
1516
1719
  }
1517
1720
 
@@ -1531,110 +1734,146 @@ void ge_tobytes(unsigned char *s,const ge_p2 *h)
1531
1734
  B is the Ed25519 base point (x,4/5) with x positive.
1532
1735
  */
1533
1736
 
1534
- void ge_double_scalarmult_vartime(ge_p2 *r,const unsigned char *a,const ge_p3 *A,const unsigned char *b)
1737
+ void
1738
+ ge_double_scalarmult_vartime(ge_p2 *r, const unsigned char *a, const ge_p3 *A,
1739
+ const unsigned char *b)
1535
1740
  {
1536
1741
  signed char aslide[256];
1537
1742
  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);
1743
+ ge_cached Ai[8]; /* A,3A,5A,7A,9A,11A,13A,15A */
1744
+ ge_p1p1 t;
1745
+ ge_p3 u;
1746
+ ge_p3 A2;
1747
+ int i;
1748
+
1749
+ slide(aslide, a);
1750
+ slide(bslide, b);
1751
+
1752
+ ge_p3_to_cached(&Ai[0], A);
1753
+ ge_p3_dbl(&t, A);
1754
+ ge_p1p1_to_p3(&A2, &t);
1755
+ ge_add(&t, &A2, &Ai[0]);
1756
+ ge_p1p1_to_p3(&u, &t);
1757
+ ge_p3_to_cached(&Ai[1], &u);
1758
+ ge_add(&t, &A2, &Ai[1]);
1759
+ ge_p1p1_to_p3(&u, &t);
1760
+ ge_p3_to_cached(&Ai[2], &u);
1761
+ ge_add(&t, &A2, &Ai[2]);
1762
+ ge_p1p1_to_p3(&u, &t);
1763
+ ge_p3_to_cached(&Ai[3], &u);
1764
+ ge_add(&t, &A2, &Ai[3]);
1765
+ ge_p1p1_to_p3(&u, &t);
1766
+ ge_p3_to_cached(&Ai[4], &u);
1767
+ ge_add(&t, &A2, &Ai[4]);
1768
+ ge_p1p1_to_p3(&u, &t);
1769
+ ge_p3_to_cached(&Ai[5], &u);
1770
+ ge_add(&t, &A2, &Ai[5]);
1771
+ ge_p1p1_to_p3(&u, &t);
1772
+ ge_p3_to_cached(&Ai[6], &u);
1773
+ ge_add(&t, &A2, &Ai[6]);
1774
+ ge_p1p1_to_p3(&u, &t);
1775
+ ge_p3_to_cached(&Ai[7], &u);
1556
1776
 
1557
1777
  ge_p2_0(r);
1558
1778
 
1559
- for (i = 255;i >= 0;--i) {
1560
- if (aslide[i] || bslide[i]) break;
1779
+ for (i = 255; i >= 0; --i) {
1780
+ if (aslide[i] || bslide[i])
1781
+ break;
1561
1782
  }
1562
1783
 
1563
- for (;i >= 0;--i) {
1564
- ge_p2_dbl(&t,r);
1784
+ for (; i >= 0; --i) {
1785
+ ge_p2_dbl(&t, r);
1565
1786
 
1566
1787
  if (aslide[i] > 0) {
1567
- ge_p1p1_to_p3(&u,&t);
1568
- ge_add(&t,&u,&Ai[aslide[i]/2]);
1788
+ ge_p1p1_to_p3(&u, &t);
1789
+ ge_add(&t, &u, &Ai[aslide[i] / 2]);
1569
1790
  } else if (aslide[i] < 0) {
1570
- ge_p1p1_to_p3(&u,&t);
1571
- ge_sub(&t,&u,&Ai[(-aslide[i])/2]);
1791
+ ge_p1p1_to_p3(&u, &t);
1792
+ ge_sub(&t, &u, &Ai[(-aslide[i]) / 2]);
1572
1793
  }
1573
1794
 
1574
1795
  if (bslide[i] > 0) {
1575
- ge_p1p1_to_p3(&u,&t);
1576
- ge_madd(&t,&u,&Bi[bslide[i]/2]);
1796
+ ge_p1p1_to_p3(&u, &t);
1797
+ ge_madd(&t, &u, &Bi[bslide[i] / 2]);
1577
1798
  } else if (bslide[i] < 0) {
1578
- ge_p1p1_to_p3(&u,&t);
1579
- ge_msub(&t,&u,&Bi[(-bslide[i])/2]);
1799
+ ge_p1p1_to_p3(&u, &t);
1800
+ ge_msub(&t, &u, &Bi[(-bslide[i]) / 2]);
1580
1801
  }
1581
1802
 
1582
- ge_p1p1_to_p2(r,&t);
1803
+ ge_p1p1_to_p2(r, &t);
1583
1804
  }
1584
1805
  }
1585
1806
 
1586
- void ge_scalarmult_vartime(ge_p3 *r,const unsigned char *a,const ge_p3 *A)
1807
+ void
1808
+ ge_scalarmult_vartime(ge_p3 *r, const unsigned char *a, const ge_p3 *A)
1587
1809
  {
1588
1810
  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);
1811
+ ge_cached Ai[8];
1812
+ ge_p1p1 t;
1813
+ ge_p3 u;
1814
+ ge_p3 A2;
1815
+ int i;
1816
+
1817
+ slide(aslide, a);
1818
+
1819
+ ge_p3_to_cached(&Ai[0], A);
1820
+ ge_p3_dbl(&t, A);
1821
+ ge_p1p1_to_p3(&A2, &t);
1822
+ ge_add(&t, &A2, &Ai[0]);
1823
+ ge_p1p1_to_p3(&u, &t);
1824
+ ge_p3_to_cached(&Ai[1], &u);
1825
+ ge_add(&t, &A2, &Ai[1]);
1826
+ ge_p1p1_to_p3(&u, &t);
1827
+ ge_p3_to_cached(&Ai[2], &u);
1828
+ ge_add(&t, &A2, &Ai[2]);
1829
+ ge_p1p1_to_p3(&u, &t);
1830
+ ge_p3_to_cached(&Ai[3], &u);
1831
+ ge_add(&t, &A2, &Ai[3]);
1832
+ ge_p1p1_to_p3(&u, &t);
1833
+ ge_p3_to_cached(&Ai[4], &u);
1834
+ ge_add(&t, &A2, &Ai[4]);
1835
+ ge_p1p1_to_p3(&u, &t);
1836
+ ge_p3_to_cached(&Ai[5], &u);
1837
+ ge_add(&t, &A2, &Ai[5]);
1838
+ ge_p1p1_to_p3(&u, &t);
1839
+ ge_p3_to_cached(&Ai[6], &u);
1840
+ ge_add(&t, &A2, &Ai[6]);
1841
+ ge_p1p1_to_p3(&u, &t);
1842
+ ge_p3_to_cached(&Ai[7], &u);
1606
1843
 
1607
1844
  ge_p3_0(r);
1608
1845
 
1609
- for (i = 255;i >= 0;--i) {
1610
- if (aslide[i]) break;
1846
+ for (i = 255; i >= 0; --i) {
1847
+ if (aslide[i])
1848
+ break;
1611
1849
  }
1612
1850
 
1613
- for (;i >= 0;--i) {
1614
- ge_p3_dbl(&t,r);
1851
+ for (; i >= 0; --i) {
1852
+ ge_p3_dbl(&t, r);
1615
1853
 
1616
1854
  if (aslide[i] > 0) {
1617
- ge_p1p1_to_p3(&u,&t);
1618
- ge_add(&t,&u,&Ai[aslide[i]/2]);
1855
+ ge_p1p1_to_p3(&u, &t);
1856
+ ge_add(&t, &u, &Ai[aslide[i] / 2]);
1619
1857
  } else if (aslide[i] < 0) {
1620
- ge_p1p1_to_p3(&u,&t);
1621
- ge_sub(&t,&u,&Ai[(-aslide[i])/2]);
1858
+ ge_p1p1_to_p3(&u, &t);
1859
+ ge_sub(&t, &u, &Ai[(-aslide[i]) / 2]);
1622
1860
  }
1623
1861
 
1624
- ge_p1p1_to_p3(r,&t);
1862
+ ge_p1p1_to_p3(r, &t);
1625
1863
  }
1626
1864
  }
1627
1865
 
1628
- void ge_scalarmult_base(ge_p3 *h,const unsigned char *a)
1866
+ void
1867
+ ge_scalarmult_base(ge_p3 *h, const unsigned char *a)
1629
1868
  {
1630
1869
  signed char e[64];
1631
1870
  signed char carry;
1632
- ge_p1p1 r;
1633
- ge_p2 s;
1634
- ge_precomp t;
1635
- int i;
1871
+ ge_p1p1 r;
1872
+ ge_p2 s;
1873
+ ge_precomp t;
1874
+ int i;
1636
1875
 
1637
- for (i = 0;i < 32;++i) {
1876
+ for (i = 0; i < 32; ++i) {
1638
1877
  e[2 * i + 0] = (a[i] >> 0) & 15;
1639
1878
  e[2 * i + 1] = (a[i] >> 4) & 15;
1640
1879
  }
@@ -1642,7 +1881,7 @@ void ge_scalarmult_base(ge_p3 *h,const unsigned char *a)
1642
1881
  /* e[63] is between 0 and 7 */
1643
1882
 
1644
1883
  carry = 0;
1645
- for (i = 0;i < 63;++i) {
1884
+ for (i = 0; i < 63; ++i) {
1646
1885
  e[i] += carry;
1647
1886
  carry = e[i] + 8;
1648
1887
  carry >>= 4;
@@ -1652,19 +1891,25 @@ void ge_scalarmult_base(ge_p3 *h,const unsigned char *a)
1652
1891
  /* each e[i] is between -8 and 8 */
1653
1892
 
1654
1893
  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);
1894
+ for (i = 1; i < 64; i += 2) {
1895
+ ge_select(&t, i / 2, e[i]);
1896
+ ge_madd(&r, h, &t);
1897
+ ge_p1p1_to_p3(h, &r);
1658
1898
  }
1659
1899
 
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);
1900
+ ge_p3_dbl(&r, h);
1901
+ ge_p1p1_to_p2(&s, &r);
1902
+ ge_p2_dbl(&r, &s);
1903
+ ge_p1p1_to_p2(&s, &r);
1904
+ ge_p2_dbl(&r, &s);
1905
+ ge_p1p1_to_p2(&s, &r);
1906
+ ge_p2_dbl(&r, &s);
1907
+ ge_p1p1_to_p3(h, &r);
1908
+
1909
+ for (i = 0; i < 64; i += 2) {
1910
+ ge_select(&t, i / 2, e[i]);
1911
+ ge_madd(&r, h, &t);
1912
+ ge_p1p1_to_p3(h, &r);
1668
1913
  }
1669
1914
  }
1670
1915
 
@@ -1679,44 +1924,49 @@ void ge_scalarmult_base(ge_p3 *h,const unsigned char *a)
1679
1924
  where l = 2^252 + 27742317777372353535851937790883648493.
1680
1925
  */
1681
1926
 
1682
- void sc_muladd(unsigned char *s,const unsigned char *a,const unsigned char *b,const unsigned char *c)
1927
+ void
1928
+ sc_muladd(unsigned char *s, const unsigned char *a, const unsigned char *b,
1929
+ const unsigned char *c)
1683
1930
  {
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);
1931
+ int64_t a0 = 2097151 & load_3(a);
1932
+ int64_t a1 = 2097151 & (load_4(a + 2) >> 5);
1933
+ int64_t a2 = 2097151 & (load_3(a + 5) >> 2);
1934
+ int64_t a3 = 2097151 & (load_4(a + 7) >> 7);
1935
+ int64_t a4 = 2097151 & (load_4(a + 10) >> 4);
1936
+ int64_t a5 = 2097151 & (load_3(a + 13) >> 1);
1937
+ int64_t a6 = 2097151 & (load_4(a + 15) >> 6);
1938
+ int64_t a7 = 2097151 & (load_3(a + 18) >> 3);
1939
+ int64_t a8 = 2097151 & load_3(a + 21);
1940
+ int64_t a9 = 2097151 & (load_4(a + 23) >> 5);
1694
1941
  int64_t a10 = 2097151 & (load_3(a + 26) >> 2);
1695
1942
  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);
1943
+
1944
+ int64_t b0 = 2097151 & load_3(b);
1945
+ int64_t b1 = 2097151 & (load_4(b + 2) >> 5);
1946
+ int64_t b2 = 2097151 & (load_3(b + 5) >> 2);
1947
+ int64_t b3 = 2097151 & (load_4(b + 7) >> 7);
1948
+ int64_t b4 = 2097151 & (load_4(b + 10) >> 4);
1949
+ int64_t b5 = 2097151 & (load_3(b + 13) >> 1);
1950
+ int64_t b6 = 2097151 & (load_4(b + 15) >> 6);
1951
+ int64_t b7 = 2097151 & (load_3(b + 18) >> 3);
1952
+ int64_t b8 = 2097151 & load_3(b + 21);
1953
+ int64_t b9 = 2097151 & (load_4(b + 23) >> 5);
1706
1954
  int64_t b10 = 2097151 & (load_3(b + 26) >> 2);
1707
1955
  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);
1956
+
1957
+ int64_t c0 = 2097151 & load_3(c);
1958
+ int64_t c1 = 2097151 & (load_4(c + 2) >> 5);
1959
+ int64_t c2 = 2097151 & (load_3(c + 5) >> 2);
1960
+ int64_t c3 = 2097151 & (load_4(c + 7) >> 7);
1961
+ int64_t c4 = 2097151 & (load_4(c + 10) >> 4);
1962
+ int64_t c5 = 2097151 & (load_3(c + 13) >> 1);
1963
+ int64_t c6 = 2097151 & (load_4(c + 15) >> 6);
1964
+ int64_t c7 = 2097151 & (load_3(c + 18) >> 3);
1965
+ int64_t c8 = 2097151 & load_3(c + 21);
1966
+ int64_t c9 = 2097151 & (load_4(c + 23) >> 5);
1718
1967
  int64_t c10 = 2097151 & (load_3(c + 26) >> 2);
1719
1968
  int64_t c11 = (load_4(c + 28) >> 7);
1969
+
1720
1970
  int64_t s0;
1721
1971
  int64_t s1;
1722
1972
  int64_t s2;
@@ -1741,6 +1991,7 @@ void sc_muladd(unsigned char *s,const unsigned char *a,const unsigned char *b,co
1741
1991
  int64_t s21;
1742
1992
  int64_t s22;
1743
1993
  int64_t s23;
1994
+
1744
1995
  int64_t carry0;
1745
1996
  int64_t carry1;
1746
1997
  int64_t carry2;
@@ -1765,55 +2016,112 @@ void sc_muladd(unsigned char *s,const unsigned char *a,const unsigned char *b,co
1765
2016
  int64_t carry21;
1766
2017
  int64_t carry22;
1767
2018
 
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;
2019
+ s0 = c0 + a0 * b0;
2020
+ s1 = c1 + a0 * b1 + a1 * b0;
2021
+ s2 = c2 + a0 * b2 + a1 * b1 + a2 * b0;
2022
+ s3 = c3 + a0 * b3 + a1 * b2 + a2 * b1 + a3 * b0;
2023
+ s4 = c4 + a0 * b4 + a1 * b3 + a2 * b2 + a3 * b1 + a4 * b0;
2024
+ s5 = c5 + a0 * b5 + a1 * b4 + a2 * b3 + a3 * b2 + a4 * b1 + a5 * b0;
2025
+ s6 = c6 + a0 * b6 + a1 * b5 + a2 * b4 + a3 * b3 + a4 * b2 + a5 * b1 +
2026
+ a6 * b0;
2027
+ s7 = c7 + a0 * b7 + a1 * b6 + a2 * b5 + a3 * b4 + a4 * b3 + a5 * b2 +
2028
+ a6 * b1 + a7 * b0;
2029
+ s8 = c8 + a0 * b8 + a1 * b7 + a2 * b6 + a3 * b5 + a4 * b4 + a5 * b3 +
2030
+ a6 * b2 + a7 * b1 + a8 * b0;
2031
+ s9 = c9 + a0 * b9 + a1 * b8 + a2 * b7 + a3 * b6 + a4 * b5 + a5 * b4 +
2032
+ a6 * b3 + a7 * b2 + a8 * b1 + a9 * b0;
2033
+ s10 = c10 + a0 * b10 + a1 * b9 + a2 * b8 + a3 * b7 + a4 * b6 + a5 * b5 +
2034
+ a6 * b4 + a7 * b3 + a8 * b2 + a9 * b1 + a10 * b0;
2035
+ s11 = c11 + a0 * b11 + a1 * b10 + a2 * b9 + a3 * b8 + a4 * b7 + a5 * b6 +
2036
+ a6 * b5 + a7 * b4 + a8 * b3 + a9 * b2 + a10 * b1 + a11 * b0;
2037
+ s12 = a1 * b11 + a2 * b10 + a3 * b9 + a4 * b8 + a5 * b7 + a6 * b6 +
2038
+ a7 * b5 + a8 * b4 + a9 * b3 + a10 * b2 + a11 * b1;
2039
+ s13 = a2 * b11 + a3 * b10 + a4 * b9 + a5 * b8 + a6 * b7 + a7 * b6 +
2040
+ a8 * b5 + a9 * b4 + a10 * b3 + a11 * b2;
2041
+ s14 = a3 * b11 + a4 * b10 + a5 * b9 + a6 * b8 + a7 * b7 + a8 * b6 +
2042
+ a9 * b5 + a10 * b4 + a11 * b3;
2043
+ s15 = a4 * b11 + a5 * b10 + a6 * b9 + a7 * b8 + a8 * b7 + a9 * b6 +
2044
+ a10 * b5 + a11 * b4;
2045
+ s16 =
2046
+ a5 * b11 + a6 * b10 + a7 * b9 + a8 * b8 + a9 * b7 + a10 * b6 + a11 * b5;
2047
+ s17 = a6 * b11 + a7 * b10 + a8 * b9 + a9 * b8 + a10 * b7 + a11 * b6;
2048
+ s18 = a7 * b11 + a8 * b10 + a9 * b9 + a10 * b8 + a11 * b7;
2049
+ s19 = a8 * b11 + a9 * b10 + a10 * b9 + a11 * b8;
2050
+ s20 = a9 * b11 + a10 * b10 + a11 * b9;
2051
+ s21 = a10 * b11 + a11 * b10;
2052
+ s22 = a11 * b11;
1791
2053
  s23 = 0;
1792
2054
 
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);
2055
+ carry0 = (s0 + (int64_t)(1L << 20)) >> 21;
2056
+ s1 += carry0;
2057
+ s0 -= carry0 * ((uint64_t) 1L << 21);
2058
+ carry2 = (s2 + (int64_t)(1L << 20)) >> 21;
2059
+ s3 += carry2;
2060
+ s2 -= carry2 * ((uint64_t) 1L << 21);
2061
+ carry4 = (s4 + (int64_t)(1L << 20)) >> 21;
2062
+ s5 += carry4;
2063
+ s4 -= carry4 * ((uint64_t) 1L << 21);
2064
+ carry6 = (s6 + (int64_t)(1L << 20)) >> 21;
2065
+ s7 += carry6;
2066
+ s6 -= carry6 * ((uint64_t) 1L << 21);
2067
+ carry8 = (s8 + (int64_t)(1L << 20)) >> 21;
2068
+ s9 += carry8;
2069
+ s8 -= carry8 * ((uint64_t) 1L << 21);
2070
+ carry10 = (s10 + (int64_t)(1L << 20)) >> 21;
2071
+ s11 += carry10;
2072
+ s10 -= carry10 * ((uint64_t) 1L << 21);
2073
+ carry12 = (s12 + (int64_t)(1L << 20)) >> 21;
2074
+ s13 += carry12;
2075
+ s12 -= carry12 * ((uint64_t) 1L << 21);
2076
+ carry14 = (s14 + (int64_t)(1L << 20)) >> 21;
2077
+ s15 += carry14;
2078
+ s14 -= carry14 * ((uint64_t) 1L << 21);
2079
+ carry16 = (s16 + (int64_t)(1L << 20)) >> 21;
2080
+ s17 += carry16;
2081
+ s16 -= carry16 * ((uint64_t) 1L << 21);
2082
+ carry18 = (s18 + (int64_t)(1L << 20)) >> 21;
2083
+ s19 += carry18;
2084
+ s18 -= carry18 * ((uint64_t) 1L << 21);
2085
+ carry20 = (s20 + (int64_t)(1L << 20)) >> 21;
2086
+ s21 += carry20;
2087
+ s20 -= carry20 * ((uint64_t) 1L << 21);
2088
+ carry22 = (s22 + (int64_t)(1L << 20)) >> 21;
2089
+ s23 += carry22;
2090
+ s22 -= carry22 * ((uint64_t) 1L << 21);
2091
+
2092
+ carry1 = (s1 + (int64_t)(1L << 20)) >> 21;
2093
+ s2 += carry1;
2094
+ s1 -= carry1 * ((uint64_t) 1L << 21);
2095
+ carry3 = (s3 + (int64_t)(1L << 20)) >> 21;
2096
+ s4 += carry3;
2097
+ s3 -= carry3 * ((uint64_t) 1L << 21);
2098
+ carry5 = (s5 + (int64_t)(1L << 20)) >> 21;
2099
+ s6 += carry5;
2100
+ s5 -= carry5 * ((uint64_t) 1L << 21);
2101
+ carry7 = (s7 + (int64_t)(1L << 20)) >> 21;
2102
+ s8 += carry7;
2103
+ s7 -= carry7 * ((uint64_t) 1L << 21);
2104
+ carry9 = (s9 + (int64_t)(1L << 20)) >> 21;
2105
+ s10 += carry9;
2106
+ s9 -= carry9 * ((uint64_t) 1L << 21);
2107
+ carry11 = (s11 + (int64_t)(1L << 20)) >> 21;
2108
+ s12 += carry11;
2109
+ s11 -= carry11 * ((uint64_t) 1L << 21);
2110
+ carry13 = (s13 + (int64_t)(1L << 20)) >> 21;
2111
+ s14 += carry13;
2112
+ s13 -= carry13 * ((uint64_t) 1L << 21);
2113
+ carry15 = (s15 + (int64_t)(1L << 20)) >> 21;
2114
+ s16 += carry15;
2115
+ s15 -= carry15 * ((uint64_t) 1L << 21);
2116
+ carry17 = (s17 + (int64_t)(1L << 20)) >> 21;
2117
+ s18 += carry17;
2118
+ s17 -= carry17 * ((uint64_t) 1L << 21);
2119
+ carry19 = (s19 + (int64_t)(1L << 20)) >> 21;
2120
+ s20 += carry19;
2121
+ s19 -= carry19 * ((uint64_t) 1L << 21);
2122
+ carry21 = (s21 + (int64_t)(1L << 20)) >> 21;
2123
+ s22 += carry21;
2124
+ s21 -= carry21 * ((uint64_t) 1L << 21);
1817
2125
 
1818
2126
  s11 += s23 * 666643;
1819
2127
  s12 += s23 * 470296;
@@ -1857,18 +2165,40 @@ void sc_muladd(unsigned char *s,const unsigned char *a,const unsigned char *b,co
1857
2165
  s10 += s18 * 136657;
1858
2166
  s11 -= s18 * 683901;
1859
2167
 
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);
2168
+ carry6 = (s6 + (int64_t)(1L << 20)) >> 21;
2169
+ s7 += carry6;
2170
+ s6 -= carry6 * ((uint64_t) 1L << 21);
2171
+ carry8 = (s8 + (int64_t)(1L << 20)) >> 21;
2172
+ s9 += carry8;
2173
+ s8 -= carry8 * ((uint64_t) 1L << 21);
2174
+ carry10 = (s10 + (int64_t)(1L << 20)) >> 21;
2175
+ s11 += carry10;
2176
+ s10 -= carry10 * ((uint64_t) 1L << 21);
2177
+ carry12 = (s12 + (int64_t)(1L << 20)) >> 21;
2178
+ s13 += carry12;
2179
+ s12 -= carry12 * ((uint64_t) 1L << 21);
2180
+ carry14 = (s14 + (int64_t)(1L << 20)) >> 21;
2181
+ s15 += carry14;
2182
+ s14 -= carry14 * ((uint64_t) 1L << 21);
2183
+ carry16 = (s16 + (int64_t)(1L << 20)) >> 21;
2184
+ s17 += carry16;
2185
+ s16 -= carry16 * ((uint64_t) 1L << 21);
2186
+
2187
+ carry7 = (s7 + (int64_t)(1L << 20)) >> 21;
2188
+ s8 += carry7;
2189
+ s7 -= carry7 * ((uint64_t) 1L << 21);
2190
+ carry9 = (s9 + (int64_t)(1L << 20)) >> 21;
2191
+ s10 += carry9;
2192
+ s9 -= carry9 * ((uint64_t) 1L << 21);
2193
+ carry11 = (s11 + (int64_t)(1L << 20)) >> 21;
2194
+ s12 += carry11;
2195
+ s11 -= carry11 * ((uint64_t) 1L << 21);
2196
+ carry13 = (s13 + (int64_t)(1L << 20)) >> 21;
2197
+ s14 += carry13;
2198
+ s13 -= carry13 * ((uint64_t) 1L << 21);
2199
+ carry15 = (s15 + (int64_t)(1L << 20)) >> 21;
2200
+ s16 += carry15;
2201
+ s15 -= carry15 * ((uint64_t) 1L << 21);
1872
2202
 
1873
2203
  s5 += s17 * 666643;
1874
2204
  s6 += s17 * 470296;
@@ -1913,19 +2243,43 @@ void sc_muladd(unsigned char *s,const unsigned char *a,const unsigned char *b,co
1913
2243
  s5 -= s12 * 683901;
1914
2244
  s12 = 0;
1915
2245
 
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);
2246
+ carry0 = (s0 + (int64_t)(1L << 20)) >> 21;
2247
+ s1 += carry0;
2248
+ s0 -= carry0 * ((uint64_t) 1L << 21);
2249
+ carry2 = (s2 + (int64_t)(1L << 20)) >> 21;
2250
+ s3 += carry2;
2251
+ s2 -= carry2 * ((uint64_t) 1L << 21);
2252
+ carry4 = (s4 + (int64_t)(1L << 20)) >> 21;
2253
+ s5 += carry4;
2254
+ s4 -= carry4 * ((uint64_t) 1L << 21);
2255
+ carry6 = (s6 + (int64_t)(1L << 20)) >> 21;
2256
+ s7 += carry6;
2257
+ s6 -= carry6 * ((uint64_t) 1L << 21);
2258
+ carry8 = (s8 + (int64_t)(1L << 20)) >> 21;
2259
+ s9 += carry8;
2260
+ s8 -= carry8 * ((uint64_t) 1L << 21);
2261
+ carry10 = (s10 + (int64_t)(1L << 20)) >> 21;
2262
+ s11 += carry10;
2263
+ s10 -= carry10 * ((uint64_t) 1L << 21);
2264
+
2265
+ carry1 = (s1 + (int64_t)(1L << 20)) >> 21;
2266
+ s2 += carry1;
2267
+ s1 -= carry1 * ((uint64_t) 1L << 21);
2268
+ carry3 = (s3 + (int64_t)(1L << 20)) >> 21;
2269
+ s4 += carry3;
2270
+ s3 -= carry3 * ((uint64_t) 1L << 21);
2271
+ carry5 = (s5 + (int64_t)(1L << 20)) >> 21;
2272
+ s6 += carry5;
2273
+ s5 -= carry5 * ((uint64_t) 1L << 21);
2274
+ carry7 = (s7 + (int64_t)(1L << 20)) >> 21;
2275
+ s8 += carry7;
2276
+ s7 -= carry7 * ((uint64_t) 1L << 21);
2277
+ carry9 = (s9 + (int64_t)(1L << 20)) >> 21;
2278
+ s10 += carry9;
2279
+ s9 -= carry9 * ((uint64_t) 1L << 21);
2280
+ carry11 = (s11 + (int64_t)(1L << 20)) >> 21;
2281
+ s12 += carry11;
2282
+ s11 -= carry11 * ((uint64_t) 1L << 21);
1929
2283
 
1930
2284
  s0 += s12 * 666643;
1931
2285
  s1 += s12 * 470296;
@@ -1935,18 +2289,42 @@ void sc_muladd(unsigned char *s,const unsigned char *a,const unsigned char *b,co
1935
2289
  s5 -= s12 * 683901;
1936
2290
  s12 = 0;
1937
2291
 
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);
2292
+ carry0 = s0 >> 21;
2293
+ s1 += carry0;
2294
+ s0 -= carry0 * ((uint64_t) 1L << 21);
2295
+ carry1 = s1 >> 21;
2296
+ s2 += carry1;
2297
+ s1 -= carry1 * ((uint64_t) 1L << 21);
2298
+ carry2 = s2 >> 21;
2299
+ s3 += carry2;
2300
+ s2 -= carry2 * ((uint64_t) 1L << 21);
2301
+ carry3 = s3 >> 21;
2302
+ s4 += carry3;
2303
+ s3 -= carry3 * ((uint64_t) 1L << 21);
2304
+ carry4 = s4 >> 21;
2305
+ s5 += carry4;
2306
+ s4 -= carry4 * ((uint64_t) 1L << 21);
2307
+ carry5 = s5 >> 21;
2308
+ s6 += carry5;
2309
+ s5 -= carry5 * ((uint64_t) 1L << 21);
2310
+ carry6 = s6 >> 21;
2311
+ s7 += carry6;
2312
+ s6 -= carry6 * ((uint64_t) 1L << 21);
2313
+ carry7 = s7 >> 21;
2314
+ s8 += carry7;
2315
+ s7 -= carry7 * ((uint64_t) 1L << 21);
2316
+ carry8 = s8 >> 21;
2317
+ s9 += carry8;
2318
+ s8 -= carry8 * ((uint64_t) 1L << 21);
2319
+ carry9 = s9 >> 21;
2320
+ s10 += carry9;
2321
+ s9 -= carry9 * ((uint64_t) 1L << 21);
2322
+ carry10 = s10 >> 21;
2323
+ s11 += carry10;
2324
+ s10 -= carry10 * ((uint64_t) 1L << 21);
2325
+ carry11 = s11 >> 21;
2326
+ s12 += carry11;
2327
+ s11 -= carry11 * ((uint64_t) 1L << 21);
1950
2328
 
1951
2329
  s0 += s12 * 666643;
1952
2330
  s1 += s12 * 470296;
@@ -1955,28 +2333,50 @@ void sc_muladd(unsigned char *s,const unsigned char *a,const unsigned char *b,co
1955
2333
  s4 += s12 * 136657;
1956
2334
  s5 -= s12 * 683901;
1957
2335
 
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;
2336
+ carry0 = s0 >> 21;
2337
+ s1 += carry0;
2338
+ s0 -= carry0 * ((uint64_t) 1L << 21);
2339
+ carry1 = s1 >> 21;
2340
+ s2 += carry1;
2341
+ s1 -= carry1 * ((uint64_t) 1L << 21);
2342
+ carry2 = s2 >> 21;
2343
+ s3 += carry2;
2344
+ s2 -= carry2 * ((uint64_t) 1L << 21);
2345
+ carry3 = s3 >> 21;
2346
+ s4 += carry3;
2347
+ s3 -= carry3 * ((uint64_t) 1L << 21);
2348
+ carry4 = s4 >> 21;
2349
+ s5 += carry4;
2350
+ s4 -= carry4 * ((uint64_t) 1L << 21);
2351
+ carry5 = s5 >> 21;
2352
+ s6 += carry5;
2353
+ s5 -= carry5 * ((uint64_t) 1L << 21);
2354
+ carry6 = s6 >> 21;
2355
+ s7 += carry6;
2356
+ s6 -= carry6 * ((uint64_t) 1L << 21);
2357
+ carry7 = s7 >> 21;
2358
+ s8 += carry7;
2359
+ s7 -= carry7 * ((uint64_t) 1L << 21);
2360
+ carry8 = s8 >> 21;
2361
+ s9 += carry8;
2362
+ s8 -= carry8 * ((uint64_t) 1L << 21);
2363
+ carry9 = s9 >> 21;
2364
+ s10 += carry9;
2365
+ s9 -= carry9 * ((uint64_t) 1L << 21);
2366
+ carry10 = s10 >> 21;
2367
+ s11 += carry10;
2368
+ s10 -= carry10 * ((uint64_t) 1L << 21);
2369
+
2370
+ s[0] = s0 >> 0;
2371
+ s[1] = s0 >> 8;
2372
+ s[2] = (s0 >> 16) | (s1 * ((uint64_t) 1 << 5));
2373
+ s[3] = s1 >> 3;
2374
+ s[4] = s1 >> 11;
2375
+ s[5] = (s1 >> 19) | (s2 * ((uint64_t) 1 << 2));
2376
+ s[6] = s2 >> 6;
2377
+ s[7] = (s2 >> 14) | (s3 * ((uint64_t) 1 << 7));
2378
+ s[8] = s3 >> 1;
2379
+ s[9] = s3 >> 9;
1980
2380
  s[10] = (s3 >> 17) | (s4 * ((uint64_t) 1 << 4));
1981
2381
  s[11] = s4 >> 4;
1982
2382
  s[12] = s4 >> 12;
@@ -2011,18 +2411,19 @@ void sc_muladd(unsigned char *s,const unsigned char *a,const unsigned char *b,co
2011
2411
  Overwrites s in place.
2012
2412
  */
2013
2413
 
2014
- void sc_reduce(unsigned char *s)
2414
+ void
2415
+ sc_reduce(unsigned char *s)
2015
2416
  {
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);
2417
+ int64_t s0 = 2097151 & load_3(s);
2418
+ int64_t s1 = 2097151 & (load_4(s + 2) >> 5);
2419
+ int64_t s2 = 2097151 & (load_3(s + 5) >> 2);
2420
+ int64_t s3 = 2097151 & (load_4(s + 7) >> 7);
2421
+ int64_t s4 = 2097151 & (load_4(s + 10) >> 4);
2422
+ int64_t s5 = 2097151 & (load_3(s + 13) >> 1);
2423
+ int64_t s6 = 2097151 & (load_4(s + 15) >> 6);
2424
+ int64_t s7 = 2097151 & (load_3(s + 18) >> 3);
2425
+ int64_t s8 = 2097151 & load_3(s + 21);
2426
+ int64_t s9 = 2097151 & (load_4(s + 23) >> 5);
2026
2427
  int64_t s10 = 2097151 & (load_3(s + 26) >> 2);
2027
2428
  int64_t s11 = 2097151 & (load_4(s + 28) >> 7);
2028
2429
  int64_t s12 = 2097151 & (load_4(s + 31) >> 4);
@@ -2037,6 +2438,7 @@ void sc_reduce(unsigned char *s)
2037
2438
  int64_t s21 = 2097151 & (load_3(s + 55) >> 1);
2038
2439
  int64_t s22 = 2097151 & (load_4(s + 57) >> 6);
2039
2440
  int64_t s23 = (load_4(s + 60) >> 3);
2441
+
2040
2442
  int64_t carry0;
2041
2443
  int64_t carry1;
2042
2444
  int64_t carry2;
@@ -2097,18 +2499,40 @@ void sc_reduce(unsigned char *s)
2097
2499
  s10 += s18 * 136657;
2098
2500
  s11 -= s18 * 683901;
2099
2501
 
2100
- carry6 = (s6 + (int64_t) (1L << 20)) >> 21; s7 += carry6; s6 -= carry6 * ((uint64_t) 1L << 21);
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);
2502
+ carry6 = (s6 + (int64_t)(1L << 20)) >> 21;
2503
+ s7 += carry6;
2504
+ s6 -= carry6 * ((uint64_t) 1L << 21);
2505
+ carry8 = (s8 + (int64_t)(1L << 20)) >> 21;
2506
+ s9 += carry8;
2507
+ s8 -= carry8 * ((uint64_t) 1L << 21);
2508
+ carry10 = (s10 + (int64_t)(1L << 20)) >> 21;
2509
+ s11 += carry10;
2510
+ s10 -= carry10 * ((uint64_t) 1L << 21);
2511
+ carry12 = (s12 + (int64_t)(1L << 20)) >> 21;
2512
+ s13 += carry12;
2513
+ s12 -= carry12 * ((uint64_t) 1L << 21);
2514
+ carry14 = (s14 + (int64_t)(1L << 20)) >> 21;
2515
+ s15 += carry14;
2516
+ s14 -= carry14 * ((uint64_t) 1L << 21);
2517
+ carry16 = (s16 + (int64_t)(1L << 20)) >> 21;
2518
+ s17 += carry16;
2519
+ s16 -= carry16 * ((uint64_t) 1L << 21);
2520
+
2521
+ carry7 = (s7 + (int64_t)(1L << 20)) >> 21;
2522
+ s8 += carry7;
2523
+ s7 -= carry7 * ((uint64_t) 1L << 21);
2524
+ carry9 = (s9 + (int64_t)(1L << 20)) >> 21;
2525
+ s10 += carry9;
2526
+ s9 -= carry9 * ((uint64_t) 1L << 21);
2527
+ carry11 = (s11 + (int64_t)(1L << 20)) >> 21;
2528
+ s12 += carry11;
2529
+ s11 -= carry11 * ((uint64_t) 1L << 21);
2530
+ carry13 = (s13 + (int64_t)(1L << 20)) >> 21;
2531
+ s14 += carry13;
2532
+ s13 -= carry13 * ((uint64_t) 1L << 21);
2533
+ carry15 = (s15 + (int64_t)(1L << 20)) >> 21;
2534
+ s16 += carry15;
2535
+ s15 -= carry15 * ((uint64_t) 1L << 21);
2112
2536
 
2113
2537
  s5 += s17 * 666643;
2114
2538
  s6 += s17 * 470296;
@@ -2153,19 +2577,43 @@ void sc_reduce(unsigned char *s)
2153
2577
  s5 -= s12 * 683901;
2154
2578
  s12 = 0;
2155
2579
 
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);
2580
+ carry0 = (s0 + (int64_t)(1L << 20)) >> 21;
2581
+ s1 += carry0;
2582
+ s0 -= carry0 * ((uint64_t) 1L << 21);
2583
+ carry2 = (s2 + (int64_t)(1L << 20)) >> 21;
2584
+ s3 += carry2;
2585
+ s2 -= carry2 * ((uint64_t) 1L << 21);
2586
+ carry4 = (s4 + (int64_t)(1L << 20)) >> 21;
2587
+ s5 += carry4;
2588
+ s4 -= carry4 * ((uint64_t) 1L << 21);
2589
+ carry6 = (s6 + (int64_t)(1L << 20)) >> 21;
2590
+ s7 += carry6;
2591
+ s6 -= carry6 * ((uint64_t) 1L << 21);
2592
+ carry8 = (s8 + (int64_t)(1L << 20)) >> 21;
2593
+ s9 += carry8;
2594
+ s8 -= carry8 * ((uint64_t) 1L << 21);
2595
+ carry10 = (s10 + (int64_t)(1L << 20)) >> 21;
2596
+ s11 += carry10;
2597
+ s10 -= carry10 * ((uint64_t) 1L << 21);
2598
+
2599
+ carry1 = (s1 + (int64_t)(1L << 20)) >> 21;
2600
+ s2 += carry1;
2601
+ s1 -= carry1 * ((uint64_t) 1L << 21);
2602
+ carry3 = (s3 + (int64_t)(1L << 20)) >> 21;
2603
+ s4 += carry3;
2604
+ s3 -= carry3 * ((uint64_t) 1L << 21);
2605
+ carry5 = (s5 + (int64_t)(1L << 20)) >> 21;
2606
+ s6 += carry5;
2607
+ s5 -= carry5 * ((uint64_t) 1L << 21);
2608
+ carry7 = (s7 + (int64_t)(1L << 20)) >> 21;
2609
+ s8 += carry7;
2610
+ s7 -= carry7 * ((uint64_t) 1L << 21);
2611
+ carry9 = (s9 + (int64_t)(1L << 20)) >> 21;
2612
+ s10 += carry9;
2613
+ s9 -= carry9 * ((uint64_t) 1L << 21);
2614
+ carry11 = (s11 + (int64_t)(1L << 20)) >> 21;
2615
+ s12 += carry11;
2616
+ s11 -= carry11 * ((uint64_t) 1L << 21);
2169
2617
 
2170
2618
  s0 += s12 * 666643;
2171
2619
  s1 += s12 * 470296;
@@ -2175,18 +2623,42 @@ void sc_reduce(unsigned char *s)
2175
2623
  s5 -= s12 * 683901;
2176
2624
  s12 = 0;
2177
2625
 
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);
2626
+ carry0 = s0 >> 21;
2627
+ s1 += carry0;
2628
+ s0 -= carry0 * ((uint64_t) 1L << 21);
2629
+ carry1 = s1 >> 21;
2630
+ s2 += carry1;
2631
+ s1 -= carry1 * ((uint64_t) 1L << 21);
2632
+ carry2 = s2 >> 21;
2633
+ s3 += carry2;
2634
+ s2 -= carry2 * ((uint64_t) 1L << 21);
2635
+ carry3 = s3 >> 21;
2636
+ s4 += carry3;
2637
+ s3 -= carry3 * ((uint64_t) 1L << 21);
2638
+ carry4 = s4 >> 21;
2639
+ s5 += carry4;
2640
+ s4 -= carry4 * ((uint64_t) 1L << 21);
2641
+ carry5 = s5 >> 21;
2642
+ s6 += carry5;
2643
+ s5 -= carry5 * ((uint64_t) 1L << 21);
2644
+ carry6 = s6 >> 21;
2645
+ s7 += carry6;
2646
+ s6 -= carry6 * ((uint64_t) 1L << 21);
2647
+ carry7 = s7 >> 21;
2648
+ s8 += carry7;
2649
+ s7 -= carry7 * ((uint64_t) 1L << 21);
2650
+ carry8 = s8 >> 21;
2651
+ s9 += carry8;
2652
+ s8 -= carry8 * ((uint64_t) 1L << 21);
2653
+ carry9 = s9 >> 21;
2654
+ s10 += carry9;
2655
+ s9 -= carry9 * ((uint64_t) 1L << 21);
2656
+ carry10 = s10 >> 21;
2657
+ s11 += carry10;
2658
+ s10 -= carry10 * ((uint64_t) 1L << 21);
2659
+ carry11 = s11 >> 21;
2660
+ s12 += carry11;
2661
+ s11 -= carry11 * ((uint64_t) 1L << 21);
2190
2662
 
2191
2663
  s0 += s12 * 666643;
2192
2664
  s1 += s12 * 470296;
@@ -2195,28 +2667,50 @@ void sc_reduce(unsigned char *s)
2195
2667
  s4 += s12 * 136657;
2196
2668
  s5 -= s12 * 683901;
2197
2669
 
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;
2670
+ carry0 = s0 >> 21;
2671
+ s1 += carry0;
2672
+ s0 -= carry0 * ((uint64_t) 1L << 21);
2673
+ carry1 = s1 >> 21;
2674
+ s2 += carry1;
2675
+ s1 -= carry1 * ((uint64_t) 1L << 21);
2676
+ carry2 = s2 >> 21;
2677
+ s3 += carry2;
2678
+ s2 -= carry2 * ((uint64_t) 1L << 21);
2679
+ carry3 = s3 >> 21;
2680
+ s4 += carry3;
2681
+ s3 -= carry3 * ((uint64_t) 1L << 21);
2682
+ carry4 = s4 >> 21;
2683
+ s5 += carry4;
2684
+ s4 -= carry4 * ((uint64_t) 1L << 21);
2685
+ carry5 = s5 >> 21;
2686
+ s6 += carry5;
2687
+ s5 -= carry5 * ((uint64_t) 1L << 21);
2688
+ carry6 = s6 >> 21;
2689
+ s7 += carry6;
2690
+ s6 -= carry6 * ((uint64_t) 1L << 21);
2691
+ carry7 = s7 >> 21;
2692
+ s8 += carry7;
2693
+ s7 -= carry7 * ((uint64_t) 1L << 21);
2694
+ carry8 = s8 >> 21;
2695
+ s9 += carry8;
2696
+ s8 -= carry8 * ((uint64_t) 1L << 21);
2697
+ carry9 = s9 >> 21;
2698
+ s10 += carry9;
2699
+ s9 -= carry9 * ((uint64_t) 1L << 21);
2700
+ carry10 = s10 >> 21;
2701
+ s11 += carry10;
2702
+ s10 -= carry10 * ((uint64_t) 1L << 21);
2703
+
2704
+ s[0] = s0 >> 0;
2705
+ s[1] = s0 >> 8;
2706
+ s[2] = (s0 >> 16) | (s1 * ((uint64_t) 1 << 5));
2707
+ s[3] = s1 >> 3;
2708
+ s[4] = s1 >> 11;
2709
+ s[5] = (s1 >> 19) | (s2 * ((uint64_t) 1 << 2));
2710
+ s[6] = s2 >> 6;
2711
+ s[7] = (s2 >> 14) | (s3 * ((uint64_t) 1 << 7));
2712
+ s[8] = s3 >> 1;
2713
+ s[9] = s3 >> 9;
2220
2714
  s[10] = (s3 >> 17) | (s4 * ((uint64_t) 1 << 4));
2221
2715
  s[11] = s4 >> 4;
2222
2716
  s[12] = s4 >> 12;