visaljs 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.js +393 -62
- package/node/include/js_node.h +28 -5
- package/node/include/js_uv.h +36 -0
- package/node/prelude/crypto.js +7 -10
- package/node/prelude/dns.js +99 -0
- package/node/prelude/dns_promises.js +10 -0
- package/node/prelude/http.js +1039 -195
- package/node/prelude/internal/crypto/asym.js +39 -12
- package/node/prelude/internal/crypto/dh_groups.js +12 -0
- package/node/prelude/internal/crypto/diffiehellman.js +354 -0
- package/node/prelude/internal/crypto/hash.js +1 -1
- package/node/prelude/internal/crypto/key_type.js +3 -0
- package/node/prelude/internal/crypto/keys.js +39 -9
- package/node/prelude/internal/http_agent.js +249 -0
- package/node/prelude/internal/net.js +33 -0
- package/node/prelude/internal/socketaddress.js +249 -0
- package/node/prelude/internal/tls/common.js +306 -0
- package/node/prelude/internal/tls/wrap.js +1217 -0
- package/node/prelude/internal/tls/x509.js +394 -0
- package/node/prelude/net.js +1083 -50
- package/node/prelude/stream.js +6 -0
- package/node/prelude/tls.js +141 -0
- package/node/prelude/util.js +5 -2
- package/node/prelude/util_types.js +85 -0
- package/node/src/host_http.c +268 -270
- package/node/src/host_loop.c +84 -0
- package/node/src/host_net.c +495 -0
- package/node/src/host_sys.c +16 -0
- package/package.json +1 -1
- package/runtime/include/js_builtins.h +16 -0
- package/runtime/include/js_console.h +2 -0
- package/runtime/include/js_core.def +23 -0
- package/runtime/include/js_crypto.h +23 -0
- package/runtime/include/js_generator.h +2 -3
- package/runtime/include/js_promise.h +0 -2
- package/runtime/src/async_iter.c +4 -1
- package/runtime/src/boringssl_support.cc +34 -0
- package/runtime/src/builtin_table.c +8 -0
- package/runtime/src/components.c +10 -0
- package/runtime/src/console.c +6 -18
- package/runtime/src/core_all.c +1 -0
- package/runtime/src/crypto_asym.c +450 -241
- package/runtime/src/crypto_bn.c +91 -0
- package/runtime/src/crypto_cipher.c +153 -75
- package/runtime/src/crypto_hash.c +68 -53
- package/runtime/src/crypto_internal.h +55 -26
- package/runtime/src/crypto_pkey.c +198 -61
- package/runtime/src/crypto_subtle.c +42 -16
- package/runtime/src/crypto_tls.c +678 -0
- package/runtime/src/generator.c +8 -1
- package/runtime/src/global.c +2 -4
- package/runtime/src/internal.h +0 -1
- package/runtime/src/jobs.c +2 -1
- package/runtime/src/promise.c +4 -1
- package/runtime/src/tls_roots.gen.h +3215 -0
- package/runtime/src/util_types.c +52 -0
- package/runtime/src/weak.c +2 -1
- package/runtime/third_party/boringssl/LICENSE +238 -0
- package/runtime/third_party/boringssl/README.md +46 -0
- package/runtime/third_party/boringssl/VERSION +1 -0
- package/runtime/third_party/boringssl/crypto/aes/aes.cc +44 -0
- package/runtime/third_party/boringssl/crypto/armv8_feature_parsing.h +67 -0
- package/runtime/third_party/boringssl/crypto/asn1/a_bitstr.cc +297 -0
- package/runtime/third_party/boringssl/crypto/asn1/a_bool.cc +50 -0
- package/runtime/third_party/boringssl/crypto/asn1/a_d2i_fp.cc +47 -0
- package/runtime/third_party/boringssl/crypto/asn1/a_dup.cc +42 -0
- package/runtime/third_party/boringssl/crypto/asn1/a_gentm.cc +130 -0
- package/runtime/third_party/boringssl/crypto/asn1/a_i2d_fp.cc +44 -0
- package/runtime/third_party/boringssl/crypto/asn1/a_int.cc +467 -0
- package/runtime/third_party/boringssl/crypto/asn1/a_mbstr.cc +242 -0
- package/runtime/third_party/boringssl/crypto/asn1/a_object.cc +191 -0
- package/runtime/third_party/boringssl/crypto/asn1/a_octet.cc +32 -0
- package/runtime/third_party/boringssl/crypto/asn1/a_strex.cc +411 -0
- package/runtime/third_party/boringssl/crypto/asn1/a_strnid.cc +208 -0
- package/runtime/third_party/boringssl/crypto/asn1/a_time.cc +248 -0
- package/runtime/third_party/boringssl/crypto/asn1/a_type.cc +467 -0
- package/runtime/third_party/boringssl/crypto/asn1/a_utctm.cc +128 -0
- package/runtime/third_party/boringssl/crypto/asn1/asn1_lib.cc +453 -0
- package/runtime/third_party/boringssl/crypto/asn1/asn1_par.cc +61 -0
- package/runtime/third_party/boringssl/crypto/asn1/asn_pack.cc +56 -0
- package/runtime/third_party/boringssl/crypto/asn1/f_int.cc +63 -0
- package/runtime/third_party/boringssl/crypto/asn1/f_string.cc +52 -0
- package/runtime/third_party/boringssl/crypto/asn1/internal.h +430 -0
- package/runtime/third_party/boringssl/crypto/asn1/posix_time.cc +244 -0
- package/runtime/third_party/boringssl/crypto/asn1/tasn_dec.cc +611 -0
- package/runtime/third_party/boringssl/crypto/asn1/tasn_enc.cc +348 -0
- package/runtime/third_party/boringssl/crypto/asn1/tasn_fre.cc +163 -0
- package/runtime/third_party/boringssl/crypto/asn1/tasn_new.cc +274 -0
- package/runtime/third_party/boringssl/crypto/asn1/tasn_typ.cc +92 -0
- package/runtime/third_party/boringssl/crypto/asn1/tasn_utl.cc +218 -0
- package/runtime/third_party/boringssl/crypto/base64/base64.cc +433 -0
- package/runtime/third_party/boringssl/crypto/bcm_support.h +62 -0
- package/runtime/third_party/boringssl/crypto/bio/bio.cc +715 -0
- package/runtime/third_party/boringssl/crypto/bio/bio_mem.cc +260 -0
- package/runtime/third_party/boringssl/crypto/bio/connect.cc +463 -0
- package/runtime/third_party/boringssl/crypto/bio/errno.cc +52 -0
- package/runtime/third_party/boringssl/crypto/bio/fd.cc +193 -0
- package/runtime/third_party/boringssl/crypto/bio/file.cc +283 -0
- package/runtime/third_party/boringssl/crypto/bio/hexdump.cc +154 -0
- package/runtime/third_party/boringssl/crypto/bio/internal.h +128 -0
- package/runtime/third_party/boringssl/crypto/bio/pair.cc +426 -0
- package/runtime/third_party/boringssl/crypto/bio/printf.cc +59 -0
- package/runtime/third_party/boringssl/crypto/bio/socket.cc +210 -0
- package/runtime/third_party/boringssl/crypto/bio/socket_helper.cc +179 -0
- package/runtime/third_party/boringssl/crypto/blake2/blake2.cc +173 -0
- package/runtime/third_party/boringssl/crypto/bn/bn_asn1.cc +57 -0
- package/runtime/third_party/boringssl/crypto/bn/convert.cc +409 -0
- package/runtime/third_party/boringssl/crypto/bn/div.cc +102 -0
- package/runtime/third_party/boringssl/crypto/bn/exponentiation.cc +168 -0
- package/runtime/third_party/boringssl/crypto/bn/sqrt.cc +93 -0
- package/runtime/third_party/boringssl/crypto/buf/buf.cc +119 -0
- package/runtime/third_party/boringssl/crypto/bytestring/asn1_compat.cc +54 -0
- package/runtime/third_party/boringssl/crypto/bytestring/ber.cc +268 -0
- package/runtime/third_party/boringssl/crypto/bytestring/cbb.cc +787 -0
- package/runtime/third_party/boringssl/crypto/bytestring/cbs.cc +977 -0
- package/runtime/third_party/boringssl/crypto/bytestring/internal.h +134 -0
- package/runtime/third_party/boringssl/crypto/bytestring/unicode.cc +156 -0
- package/runtime/third_party/boringssl/crypto/chacha/chacha.cc +226 -0
- package/runtime/third_party/boringssl/crypto/chacha/internal.h +103 -0
- package/runtime/third_party/boringssl/crypto/cipher/derive_key.cc +106 -0
- package/runtime/third_party/boringssl/crypto/cipher/e_aesctrhmac.cc +294 -0
- package/runtime/third_party/boringssl/crypto/cipher/e_aeseax.cc +351 -0
- package/runtime/third_party/boringssl/crypto/cipher/e_aesgcmsiv.cc +918 -0
- package/runtime/third_party/boringssl/crypto/cipher/e_chacha20poly1305.cc +404 -0
- package/runtime/third_party/boringssl/crypto/cipher/e_des.cc +214 -0
- package/runtime/third_party/boringssl/crypto/cipher/e_null.cc +55 -0
- package/runtime/third_party/boringssl/crypto/cipher/e_rc2.cc +432 -0
- package/runtime/third_party/boringssl/crypto/cipher/e_rc4.cc +56 -0
- package/runtime/third_party/boringssl/crypto/cipher/e_tls.cc +615 -0
- package/runtime/third_party/boringssl/crypto/cipher/get_cipher.cc +85 -0
- package/runtime/third_party/boringssl/crypto/cipher/internal.h +399 -0
- package/runtime/third_party/boringssl/crypto/cipher/tls_cbc.cc +476 -0
- package/runtime/third_party/boringssl/crypto/cms/cms.cc +178 -0
- package/runtime/third_party/boringssl/crypto/conf/conf.cc +637 -0
- package/runtime/third_party/boringssl/crypto/conf/internal.h +54 -0
- package/runtime/third_party/boringssl/crypto/cpu_aarch64_apple.cc +76 -0
- package/runtime/third_party/boringssl/crypto/cpu_aarch64_fuchsia.cc +58 -0
- package/runtime/third_party/boringssl/crypto/cpu_aarch64_linux.cc +66 -0
- package/runtime/third_party/boringssl/crypto/cpu_aarch64_openbsd.cc +45 -0
- package/runtime/third_party/boringssl/crypto/cpu_aarch64_sysreg.cc +66 -0
- package/runtime/third_party/boringssl/crypto/cpu_aarch64_win.cc +52 -0
- package/runtime/third_party/boringssl/crypto/cpu_arm_freebsd.cc +55 -0
- package/runtime/third_party/boringssl/crypto/cpu_arm_linux.cc +173 -0
- package/runtime/third_party/boringssl/crypto/cpu_arm_linux.h +141 -0
- package/runtime/third_party/boringssl/crypto/cpu_intel.cc +287 -0
- package/runtime/third_party/boringssl/crypto/crypto.cc +152 -0
- package/runtime/third_party/boringssl/crypto/curve25519/asm/x25519-asm-arm.S +2124 -0
- package/runtime/third_party/boringssl/crypto/curve25519/cpace.cc +227 -0
- package/runtime/third_party/boringssl/crypto/curve25519/curve25519.cc +2436 -0
- package/runtime/third_party/boringssl/crypto/curve25519/curve25519_64_adx.cc +18 -0
- package/runtime/third_party/boringssl/crypto/curve25519/curve25519_tables.h +3264 -0
- package/runtime/third_party/boringssl/crypto/curve25519/internal.h +202 -0
- package/runtime/third_party/boringssl/crypto/curve25519/spake25519.cc +532 -0
- package/runtime/third_party/boringssl/crypto/des/des.cc +837 -0
- package/runtime/third_party/boringssl/crypto/des/internal.h +144 -0
- package/runtime/third_party/boringssl/crypto/dh/dh_asn1.cc +109 -0
- package/runtime/third_party/boringssl/crypto/dh/params.cc +411 -0
- package/runtime/third_party/boringssl/crypto/digest/digest_extra.cc +361 -0
- package/runtime/third_party/boringssl/crypto/dsa/dsa.cc +922 -0
- package/runtime/third_party/boringssl/crypto/dsa/dsa_asn1.cc +306 -0
- package/runtime/third_party/boringssl/crypto/dsa/internal.h +56 -0
- package/runtime/third_party/boringssl/crypto/ec/ec_asn1.cc +542 -0
- package/runtime/third_party/boringssl/crypto/ec/ec_derive.cc +94 -0
- package/runtime/third_party/boringssl/crypto/ec/hash_to_curve.cc +773 -0
- package/runtime/third_party/boringssl/crypto/ec/internal.h +114 -0
- package/runtime/third_party/boringssl/crypto/ecdh/ecdh.cc +75 -0
- package/runtime/third_party/boringssl/crypto/ecdsa/ecdsa_asn1.cc +337 -0
- package/runtime/third_party/boringssl/crypto/ecdsa/ecdsa_p1363.cc +54 -0
- package/runtime/third_party/boringssl/crypto/engine/engine.cc +95 -0
- package/runtime/third_party/boringssl/crypto/err/err.cc +820 -0
- package/runtime/third_party/boringssl/crypto/err/internal.h +45 -0
- package/runtime/third_party/boringssl/crypto/evp/evp.cc +454 -0
- package/runtime/third_party/boringssl/crypto/evp/evp_asn1.cc +439 -0
- package/runtime/third_party/boringssl/crypto/evp/evp_ctx.cc +541 -0
- package/runtime/third_party/boringssl/crypto/evp/evp_kem.cc +101 -0
- package/runtime/third_party/boringssl/crypto/evp/internal.h +427 -0
- package/runtime/third_party/boringssl/crypto/evp/p_dh.cc +326 -0
- package/runtime/third_party/boringssl/crypto/evp/p_dsa.cc +333 -0
- package/runtime/third_party/boringssl/crypto/evp/p_ec.cc +736 -0
- package/runtime/third_party/boringssl/crypto/evp/p_ed25519.cc +359 -0
- package/runtime/third_party/boringssl/crypto/evp/p_hkdf.cc +204 -0
- package/runtime/third_party/boringssl/crypto/evp/p_mldsa.cc +549 -0
- package/runtime/third_party/boringssl/crypto/evp/p_mlkem.cc +510 -0
- package/runtime/third_party/boringssl/crypto/evp/p_rsa.cc +1185 -0
- package/runtime/third_party/boringssl/crypto/evp/p_x25519.cc +371 -0
- package/runtime/third_party/boringssl/crypto/evp/p_xwing.cc +300 -0
- package/runtime/third_party/boringssl/crypto/evp/pbkdf.cc +105 -0
- package/runtime/third_party/boringssl/crypto/evp/print.cc +287 -0
- package/runtime/third_party/boringssl/crypto/evp/scrypt.cc +218 -0
- package/runtime/third_party/boringssl/crypto/evp/sign.cc +95 -0
- package/runtime/third_party/boringssl/crypto/ex_data.cc +140 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/aes/aes.cc.inc +208 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/aes/aes_nohw.cc.inc +1279 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/aes/cbc.cc.inc +132 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/aes/cfb.cc.inc +168 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/aes/ctr.cc.inc +102 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/aes/gcm.cc.inc +614 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/aes/gcm_nohw.cc.inc +304 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/aes/internal.h +590 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/aes/key_wrap.cc.inc +211 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/aes/mode_wrappers.cc.inc +97 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/aes/ofb.cc.inc +55 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/bcm.cc +288 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/bcm_interface.h +953 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/bn/add.cc.inc +276 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/bn/asm/x86_64-gcc.cc.inc +573 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/bn/bn.cc.inc +377 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/bn/bytes.cc.inc +230 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/bn/cmp.cc.inc +161 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/bn/ctx.cc.inc +127 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/bn/div.cc.inc +738 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/bn/div_extra.cc.inc +90 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/bn/exponentiation.cc.inc +743 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/bn/gcd.cc.inc +281 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/bn/gcd_extra.cc.inc +327 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/bn/generic.cc.inc +579 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/bn/internal.h +810 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/bn/jacobi.cc.inc +101 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/bn/montgomery.cc.inc +408 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/bn/montgomery_inv.cc.inc +179 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/bn/mul.cc.inc +347 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/bn/prime.cc.inc +931 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/bn/random.cc.inc +261 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/bn/rsaz_exp.cc.inc +144 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/bn/rsaz_exp.h +109 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/bn/shift.cc.inc +317 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/bn/sqrt.cc.inc +370 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/cipher/aead.cc.inc +619 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/cipher/cipher.cc.inc +837 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/cipher/e_aes.cc.inc +1240 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/cipher/e_aesccm.cc.inc +440 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/cipher/internal.h +461 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/cmac/cmac.cc.inc +293 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/delocate.h +95 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/dh/check.cc.inc +198 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/dh/dh.cc.inc +401 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/dh/internal.h +63 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/digest/digest.cc.inc +221 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/digest/digests.cc.inc +184 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/digest/internal.h +72 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/digest/md32_common.h +166 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/digestsign/digestsign.cc.inc +230 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/ec/builtin_curves.h +277 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/ec/ec.cc.inc +1024 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/ec/ec_key.cc.inc +536 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/ec/ec_montgomery.cc.inc +379 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/ec/felem.cc.inc +250 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/ec/internal.h +752 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/ec/oct.cc.inc +174 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/ec/p256-nistz-table.h +9502 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/ec/p256-nistz.cc.inc +740 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/ec/p256-nistz.h +207 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/ec/p256.cc.inc +578 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/ec/p256_table.h +297 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/ec/scalar.cc.inc +184 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/ec/simple.cc.inc +246 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/ec/simple_mul.cc.inc +274 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/ec/util.cc.inc +258 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/ec/wnaf.cc.inc +224 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/ecdh/ecdh.cc.inc +91 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/ecdsa/ecdsa.cc.inc +288 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/ecdsa/internal.h +57 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/entropy/internal.h +38 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/entropy/jitter.cc.inc +487 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/entropy/sha512.cc.inc +329 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/fips_shared_support.cc +28 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/hkdf/hkdf.cc.inc +114 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/hmac/hmac.cc.inc +218 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/keccak/internal.h +165 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/keccak/keccak.cc.inc +647 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/mldsa/fips_known_values.inc +1345 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/mldsa/mldsa.cc.inc +3323 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/mlkem/fips_known_values.inc +411 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/mlkem/mlkem.cc.inc +1856 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/rand/android_entropy_client.cc.inc +82 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/rand/ctrdrbg.cc.inc +401 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/rand/internal.h +99 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/rand/rand.cc.inc +486 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/rsa/internal.h +167 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/rsa/padding.cc.inc +371 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/rsa/rsa.cc.inc +996 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/rsa/rsa_impl.cc.inc +1000 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/self_check/fips.cc.inc +129 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/self_check/self_check.cc.inc +1093 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/service_indicator/internal.h +112 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/service_indicator/service_indicator.cc.inc +330 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/sha/internal.h +205 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/sha/sha1.cc.inc +404 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/sha/sha256.cc.inc +315 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/sha/sha512.cc.inc +473 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/slhdsa/address.h +144 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/slhdsa/fips_known_values.inc +674 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/slhdsa/fors.cc.inc +179 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/slhdsa/fors.h +48 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/slhdsa/merkle.cc.inc +164 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/slhdsa/merkle.h +58 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/slhdsa/params.h +178 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/slhdsa/slhdsa.cc.inc +690 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/slhdsa/thash.cc.inc +326 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/slhdsa/thash.h +71 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/slhdsa/wots.cc.inc +172 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/slhdsa/wots.h +40 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/tls/internal.h +33 -0
- package/runtime/third_party/boringssl/crypto/fipsmodule/tls/kdf.cc.inc +180 -0
- package/runtime/third_party/boringssl/crypto/fuzzer_mode.cc +30 -0
- package/runtime/third_party/boringssl/crypto/hpke/hpke.cc +1514 -0
- package/runtime/third_party/boringssl/crypto/hrss/asm/poly_rq_mul.S +8489 -0
- package/runtime/third_party/boringssl/crypto/hrss/hrss.cc +2189 -0
- package/runtime/third_party/boringssl/crypto/hrss/internal.h +64 -0
- package/runtime/third_party/boringssl/crypto/internal.h +1767 -0
- package/runtime/third_party/boringssl/crypto/lhash/internal.h +222 -0
- package/runtime/third_party/boringssl/crypto/lhash/lhash.cc +312 -0
- package/runtime/third_party/boringssl/crypto/md4/md4.cc +207 -0
- package/runtime/third_party/boringssl/crypto/md5/internal.h +34 -0
- package/runtime/third_party/boringssl/crypto/md5/md5.cc +255 -0
- package/runtime/third_party/boringssl/crypto/mem.cc +577 -0
- package/runtime/third_party/boringssl/crypto/mem_internal.h +706 -0
- package/runtime/third_party/boringssl/crypto/mldsa/mldsa.cc +296 -0
- package/runtime/third_party/boringssl/crypto/mlkem/mlkem.cc +108 -0
- package/runtime/third_party/boringssl/crypto/obj/obj.cc +494 -0
- package/runtime/third_party/boringssl/crypto/obj/obj_dat.h +11722 -0
- package/runtime/third_party/boringssl/crypto/obj/obj_xref.cc +83 -0
- package/runtime/third_party/boringssl/crypto/params_internal.h +30 -0
- package/runtime/third_party/boringssl/crypto/pem/internal.h +135 -0
- package/runtime/third_party/boringssl/crypto/pem/pem_all.cc +153 -0
- package/runtime/third_party/boringssl/crypto/pem/pem_info.cc +250 -0
- package/runtime/third_party/boringssl/crypto/pem/pem_lib.cc +707 -0
- package/runtime/third_party/boringssl/crypto/pem/pem_oth.cc +45 -0
- package/runtime/third_party/boringssl/crypto/pem/pem_pk8.cc +211 -0
- package/runtime/third_party/boringssl/crypto/pem/pem_pkey.cc +147 -0
- package/runtime/third_party/boringssl/crypto/pem/pem_x509.cc +25 -0
- package/runtime/third_party/boringssl/crypto/pem/pem_xaux.cc +25 -0
- package/runtime/third_party/boringssl/crypto/pkcs7/internal.h +67 -0
- package/runtime/third_party/boringssl/crypto/pkcs7/pkcs7.cc +198 -0
- package/runtime/third_party/boringssl/crypto/pkcs7/pkcs7_x509.cc +527 -0
- package/runtime/third_party/boringssl/crypto/pkcs8/internal.h +98 -0
- package/runtime/third_party/boringssl/crypto/pkcs8/p5_pbev2.cc +286 -0
- package/runtime/third_party/boringssl/crypto/pkcs8/pkcs8.cc +473 -0
- package/runtime/third_party/boringssl/crypto/pkcs8/pkcs8_x509.cc +1328 -0
- package/runtime/third_party/boringssl/crypto/poly1305/internal.h +54 -0
- package/runtime/third_party/boringssl/crypto/poly1305/poly1305.cc +315 -0
- package/runtime/third_party/boringssl/crypto/poly1305/poly1305_arm.cc +294 -0
- package/runtime/third_party/boringssl/crypto/poly1305/poly1305_arm_asm.S +2017 -0
- package/runtime/third_party/boringssl/crypto/poly1305/poly1305_vec.cc +853 -0
- package/runtime/third_party/boringssl/crypto/pool/internal.h +95 -0
- package/runtime/third_party/boringssl/crypto/pool/pool.cc +282 -0
- package/runtime/third_party/boringssl/crypto/rand/deterministic.cc +58 -0
- package/runtime/third_party/boringssl/crypto/rand/fork_detect.cc +222 -0
- package/runtime/third_party/boringssl/crypto/rand/forkunsafe.cc +44 -0
- package/runtime/third_party/boringssl/crypto/rand/getentropy.cc +53 -0
- package/runtime/third_party/boringssl/crypto/rand/internal.h +67 -0
- package/runtime/third_party/boringssl/crypto/rand/ios.cc +35 -0
- package/runtime/third_party/boringssl/crypto/rand/rand.cc +79 -0
- package/runtime/third_party/boringssl/crypto/rand/trusty.cc +39 -0
- package/runtime/third_party/boringssl/crypto/rand/urandom.cc +149 -0
- package/runtime/third_party/boringssl/crypto/rand/windows.cc +91 -0
- package/runtime/third_party/boringssl/crypto/rc4/rc4.cc +56 -0
- package/runtime/third_party/boringssl/crypto/refcount.cc +49 -0
- package/runtime/third_party/boringssl/crypto/rsa/internal.h +51 -0
- package/runtime/third_party/boringssl/crypto/rsa/rsa_asn1.cc +404 -0
- package/runtime/third_party/boringssl/crypto/rsa/rsa_crypt.cc +530 -0
- package/runtime/third_party/boringssl/crypto/rsa/rsa_extra.cc +30 -0
- package/runtime/third_party/boringssl/crypto/rsa/rsa_print.cc +25 -0
- package/runtime/third_party/boringssl/crypto/sha/sha1.cc +55 -0
- package/runtime/third_party/boringssl/crypto/sha/sha256.cc +89 -0
- package/runtime/third_party/boringssl/crypto/sha/sha512.cc +106 -0
- package/runtime/third_party/boringssl/crypto/siphash/siphash.cc +81 -0
- package/runtime/third_party/boringssl/crypto/slhdsa/slhdsa.cc +167 -0
- package/runtime/third_party/boringssl/crypto/spake2plus/internal.h +204 -0
- package/runtime/third_party/boringssl/crypto/spake2plus/spake2plus.cc +501 -0
- package/runtime/third_party/boringssl/crypto/stack/stack.cc +462 -0
- package/runtime/third_party/boringssl/crypto/thread.cc +68 -0
- package/runtime/third_party/boringssl/crypto/thread_none.cc +48 -0
- package/runtime/third_party/boringssl/crypto/thread_pthread.cc +138 -0
- package/runtime/third_party/boringssl/crypto/thread_win.cc +227 -0
- package/runtime/third_party/boringssl/crypto/trust_token/internal.h +405 -0
- package/runtime/third_party/boringssl/crypto/trust_token/pmbtoken.cc +1672 -0
- package/runtime/third_party/boringssl/crypto/trust_token/trust_token.cc +701 -0
- package/runtime/third_party/boringssl/crypto/trust_token/voprf.cc +1266 -0
- package/runtime/third_party/boringssl/crypto/x509/a_digest.cc +52 -0
- package/runtime/third_party/boringssl/crypto/x509/a_sign.cc +100 -0
- package/runtime/third_party/boringssl/crypto/x509/a_verify.cc +77 -0
- package/runtime/third_party/boringssl/crypto/x509/algorithm.cc +167 -0
- package/runtime/third_party/boringssl/crypto/x509/asn1_gen.cc +540 -0
- package/runtime/third_party/boringssl/crypto/x509/by_dir.cc +301 -0
- package/runtime/third_party/boringssl/crypto/x509/by_file.cc +226 -0
- package/runtime/third_party/boringssl/crypto/x509/i2d_pr.cc +37 -0
- package/runtime/third_party/boringssl/crypto/x509/internal.h +697 -0
- package/runtime/third_party/boringssl/crypto/x509/name_print.cc +187 -0
- package/runtime/third_party/boringssl/crypto/x509/policy.cc +686 -0
- package/runtime/third_party/boringssl/crypto/x509/rsa_pss.cc +187 -0
- package/runtime/third_party/boringssl/crypto/x509/t_crl.cc +106 -0
- package/runtime/third_party/boringssl/crypto/x509/t_req.cc +206 -0
- package/runtime/third_party/boringssl/crypto/x509/t_x509.cc +292 -0
- package/runtime/third_party/boringssl/crypto/x509/t_x509a.cc +81 -0
- package/runtime/third_party/boringssl/crypto/x509/v3_akey.cc +174 -0
- package/runtime/third_party/boringssl/crypto/x509/v3_akeya.cc +31 -0
- package/runtime/third_party/boringssl/crypto/x509/v3_alt.cc +636 -0
- package/runtime/third_party/boringssl/crypto/x509/v3_bcons.cc +96 -0
- package/runtime/third_party/boringssl/crypto/x509/v3_bitst.cc +100 -0
- package/runtime/third_party/boringssl/crypto/x509/v3_conf.cc +369 -0
- package/runtime/third_party/boringssl/crypto/x509/v3_cpols.cc +417 -0
- package/runtime/third_party/boringssl/crypto/x509/v3_crld.cc +471 -0
- package/runtime/third_party/boringssl/crypto/x509/v3_enum.cc +74 -0
- package/runtime/third_party/boringssl/crypto/x509/v3_extku.cc +97 -0
- package/runtime/third_party/boringssl/crypto/x509/v3_genn.cc +238 -0
- package/runtime/third_party/boringssl/crypto/x509/v3_ia5.cc +83 -0
- package/runtime/third_party/boringssl/crypto/x509/v3_info.cc +162 -0
- package/runtime/third_party/boringssl/crypto/x509/v3_int.cc +83 -0
- package/runtime/third_party/boringssl/crypto/x509/v3_lib.cc +349 -0
- package/runtime/third_party/boringssl/crypto/x509/v3_ncons.cc +798 -0
- package/runtime/third_party/boringssl/crypto/x509/v3_ocsp.cc +92 -0
- package/runtime/third_party/boringssl/crypto/x509/v3_pcons.cc +102 -0
- package/runtime/third_party/boringssl/crypto/x509/v3_pmaps.cc +110 -0
- package/runtime/third_party/boringssl/crypto/x509/v3_prn.cc +183 -0
- package/runtime/third_party/boringssl/crypto/x509/v3_purp.cc +580 -0
- package/runtime/third_party/boringssl/crypto/x509/v3_skey.cc +128 -0
- package/runtime/third_party/boringssl/crypto/x509/v3_utl.cc +1311 -0
- package/runtime/third_party/boringssl/crypto/x509/x509.cc +47 -0
- package/runtime/third_party/boringssl/crypto/x509/x509_att.cc +188 -0
- package/runtime/third_party/boringssl/crypto/x509/x509_cmp.cc +243 -0
- package/runtime/third_party/boringssl/crypto/x509/x509_d2.cc +66 -0
- package/runtime/third_party/boringssl/crypto/x509/x509_def.cc +42 -0
- package/runtime/third_party/boringssl/crypto/x509/x509_ext.cc +161 -0
- package/runtime/third_party/boringssl/crypto/x509/x509_lu.cc +570 -0
- package/runtime/third_party/boringssl/crypto/x509/x509_mtc.cc +598 -0
- package/runtime/third_party/boringssl/crypto/x509/x509_obj.cc +169 -0
- package/runtime/third_party/boringssl/crypto/x509/x509_req.cc +248 -0
- package/runtime/third_party/boringssl/crypto/x509/x509_set.cc +166 -0
- package/runtime/third_party/boringssl/crypto/x509/x509_trs.cc +123 -0
- package/runtime/third_party/boringssl/crypto/x509/x509_txt.cc +147 -0
- package/runtime/third_party/boringssl/crypto/x509/x509_v3.cc +249 -0
- package/runtime/third_party/boringssl/crypto/x509/x509_vfy.cc +1531 -0
- package/runtime/third_party/boringssl/crypto/x509/x509_vpm.cc +449 -0
- package/runtime/third_party/boringssl/crypto/x509/x509cset.cc +222 -0
- package/runtime/third_party/boringssl/crypto/x509/x509name.cc +377 -0
- package/runtime/third_party/boringssl/crypto/x509/x509rset.cc +55 -0
- package/runtime/third_party/boringssl/crypto/x509/x509spki.cc +91 -0
- package/runtime/third_party/boringssl/crypto/x509/x_algor.cc +223 -0
- package/runtime/third_party/boringssl/crypto/x509/x_all.cc +352 -0
- package/runtime/third_party/boringssl/crypto/x509/x_attrib.cc +61 -0
- package/runtime/third_party/boringssl/crypto/x509/x_crl.cc +325 -0
- package/runtime/third_party/boringssl/crypto/x509/x_exten.cc +42 -0
- package/runtime/third_party/boringssl/crypto/x509/x_name.cc +407 -0
- package/runtime/third_party/boringssl/crypto/x509/x_pubkey.cc +199 -0
- package/runtime/third_party/boringssl/crypto/x509/x_req.cc +80 -0
- package/runtime/third_party/boringssl/crypto/x509/x_sig.cc +51 -0
- package/runtime/third_party/boringssl/crypto/x509/x_spki.cc +44 -0
- package/runtime/third_party/boringssl/crypto/x509/x_x509.cc +495 -0
- package/runtime/third_party/boringssl/crypto/x509/x_x509a.cc +169 -0
- package/runtime/third_party/boringssl/crypto/xwing/xwing.cc +257 -0
- package/runtime/third_party/boringssl/gen/bcm/aes-gcm-avx2-x86_64-apple.S +1326 -0
- package/runtime/third_party/boringssl/gen/bcm/aes-gcm-avx2-x86_64-linux.S +1327 -0
- package/runtime/third_party/boringssl/gen/bcm/aes-gcm-avx512-x86_64-apple.S +1252 -0
- package/runtime/third_party/boringssl/gen/bcm/aes-gcm-avx512-x86_64-linux.S +1253 -0
- package/runtime/third_party/boringssl/gen/bcm/aesni-gcm-x86_64-apple.S +873 -0
- package/runtime/third_party/boringssl/gen/bcm/aesni-gcm-x86_64-linux.S +885 -0
- package/runtime/third_party/boringssl/gen/bcm/aesni-x86-apple.S +2490 -0
- package/runtime/third_party/boringssl/gen/bcm/aesni-x86-linux.S +2530 -0
- package/runtime/third_party/boringssl/gen/bcm/aesni-x86_64-apple.S +2413 -0
- package/runtime/third_party/boringssl/gen/bcm/aesni-x86_64-linux.S +2397 -0
- package/runtime/third_party/boringssl/gen/bcm/aesv8-armv7-linux.S +784 -0
- package/runtime/third_party/boringssl/gen/bcm/aesv8-armv8-apple.S +792 -0
- package/runtime/third_party/boringssl/gen/bcm/aesv8-armv8-linux.S +786 -0
- package/runtime/third_party/boringssl/gen/bcm/aesv8-armv8-win.S +798 -0
- package/runtime/third_party/boringssl/gen/bcm/aesv8-gcm-armv8-apple.S +2912 -0
- package/runtime/third_party/boringssl/gen/bcm/aesv8-gcm-armv8-linux.S +2907 -0
- package/runtime/third_party/boringssl/gen/bcm/aesv8-gcm-armv8-win.S +2915 -0
- package/runtime/third_party/boringssl/gen/bcm/armv4-mont-linux.S +932 -0
- package/runtime/third_party/boringssl/gen/bcm/armv8-mont-apple.S +1440 -0
- package/runtime/third_party/boringssl/gen/bcm/armv8-mont-linux.S +1440 -0
- package/runtime/third_party/boringssl/gen/bcm/armv8-mont-win.S +1446 -0
- package/runtime/third_party/boringssl/gen/bcm/bn-586-apple.S +530 -0
- package/runtime/third_party/boringssl/gen/bcm/bn-586-linux.S +540 -0
- package/runtime/third_party/boringssl/gen/bcm/bn-armv8-apple.S +88 -0
- package/runtime/third_party/boringssl/gen/bcm/bn-armv8-linux.S +87 -0
- package/runtime/third_party/boringssl/gen/bcm/bn-armv8-win.S +87 -0
- package/runtime/third_party/boringssl/gen/bcm/bsaes-armv7-linux.S +1520 -0
- package/runtime/third_party/boringssl/gen/bcm/co-586-apple.S +1256 -0
- package/runtime/third_party/boringssl/gen/bcm/co-586-linux.S +1264 -0
- package/runtime/third_party/boringssl/gen/bcm/ghash-armv4-linux.S +242 -0
- package/runtime/third_party/boringssl/gen/bcm/ghash-neon-armv8-apple.S +337 -0
- package/runtime/third_party/boringssl/gen/bcm/ghash-neon-armv8-linux.S +335 -0
- package/runtime/third_party/boringssl/gen/bcm/ghash-neon-armv8-win.S +341 -0
- package/runtime/third_party/boringssl/gen/bcm/ghash-ssse3-x86-apple.S +288 -0
- package/runtime/third_party/boringssl/gen/bcm/ghash-ssse3-x86-linux.S +292 -0
- package/runtime/third_party/boringssl/gen/bcm/ghash-ssse3-x86_64-apple.S +426 -0
- package/runtime/third_party/boringssl/gen/bcm/ghash-ssse3-x86_64-linux.S +425 -0
- package/runtime/third_party/boringssl/gen/bcm/ghash-x86-apple.S +322 -0
- package/runtime/third_party/boringssl/gen/bcm/ghash-x86-linux.S +328 -0
- package/runtime/third_party/boringssl/gen/bcm/ghash-x86_64-apple.S +1134 -0
- package/runtime/third_party/boringssl/gen/bcm/ghash-x86_64-linux.S +1129 -0
- package/runtime/third_party/boringssl/gen/bcm/ghashv8-armv7-linux.S +244 -0
- package/runtime/third_party/boringssl/gen/bcm/ghashv8-armv8-apple.S +567 -0
- package/runtime/third_party/boringssl/gen/bcm/ghashv8-armv8-linux.S +563 -0
- package/runtime/third_party/boringssl/gen/bcm/ghashv8-armv8-win.S +571 -0
- package/runtime/third_party/boringssl/gen/bcm/p256-armv8-asm-apple.S +1744 -0
- package/runtime/third_party/boringssl/gen/bcm/p256-armv8-asm-linux.S +1725 -0
- package/runtime/third_party/boringssl/gen/bcm/p256-armv8-asm-win.S +1765 -0
- package/runtime/third_party/boringssl/gen/bcm/p256-x86_64-asm-apple.S +4544 -0
- package/runtime/third_party/boringssl/gen/bcm/p256-x86_64-asm-linux.S +4600 -0
- package/runtime/third_party/boringssl/gen/bcm/p256_beeu-armv8-asm-apple.S +310 -0
- package/runtime/third_party/boringssl/gen/bcm/p256_beeu-armv8-asm-linux.S +310 -0
- package/runtime/third_party/boringssl/gen/bcm/p256_beeu-armv8-asm-win.S +310 -0
- package/runtime/third_party/boringssl/gen/bcm/p256_beeu-x86_64-asm-apple.S +321 -0
- package/runtime/third_party/boringssl/gen/bcm/p256_beeu-x86_64-asm-linux.S +335 -0
- package/runtime/third_party/boringssl/gen/bcm/rdrand-x86_64-apple.S +58 -0
- package/runtime/third_party/boringssl/gen/bcm/rdrand-x86_64-linux.S +57 -0
- package/runtime/third_party/boringssl/gen/bcm/rsaz-avx2-apple.S +1756 -0
- package/runtime/third_party/boringssl/gen/bcm/rsaz-avx2-linux.S +1751 -0
- package/runtime/third_party/boringssl/gen/bcm/sha1-586-apple.S +3782 -0
- package/runtime/third_party/boringssl/gen/bcm/sha1-586-linux.S +3788 -0
- package/runtime/third_party/boringssl/gen/bcm/sha1-armv4-large-linux.S +1479 -0
- package/runtime/third_party/boringssl/gen/bcm/sha1-armv8-apple.S +1219 -0
- package/runtime/third_party/boringssl/gen/bcm/sha1-armv8-linux.S +1218 -0
- package/runtime/third_party/boringssl/gen/bcm/sha1-armv8-win.S +1222 -0
- package/runtime/third_party/boringssl/gen/bcm/sha1-x86_64-apple.S +5454 -0
- package/runtime/third_party/boringssl/gen/bcm/sha1-x86_64-linux.S +5450 -0
- package/runtime/third_party/boringssl/gen/bcm/sha256-586-apple.S +5593 -0
- package/runtime/third_party/boringssl/gen/bcm/sha256-586-linux.S +5599 -0
- package/runtime/third_party/boringssl/gen/bcm/sha256-armv4-linux.S +2840 -0
- package/runtime/third_party/boringssl/gen/bcm/sha256-armv8-apple.S +1195 -0
- package/runtime/third_party/boringssl/gen/bcm/sha256-armv8-linux.S +1194 -0
- package/runtime/third_party/boringssl/gen/bcm/sha256-armv8-win.S +1198 -0
- package/runtime/third_party/boringssl/gen/bcm/sha256-x86_64-apple.S +4173 -0
- package/runtime/third_party/boringssl/gen/bcm/sha256-x86_64-linux.S +4170 -0
- package/runtime/third_party/boringssl/gen/bcm/sha512-586-apple.S +2406 -0
- package/runtime/third_party/boringssl/gen/bcm/sha512-586-linux.S +2410 -0
- package/runtime/third_party/boringssl/gen/bcm/sha512-armv4-linux.S +1857 -0
- package/runtime/third_party/boringssl/gen/bcm/sha512-armv8-apple.S +1598 -0
- package/runtime/third_party/boringssl/gen/bcm/sha512-armv8-linux.S +1597 -0
- package/runtime/third_party/boringssl/gen/bcm/sha512-armv8-win.S +1601 -0
- package/runtime/third_party/boringssl/gen/bcm/sha512-x86_64-apple.S +2979 -0
- package/runtime/third_party/boringssl/gen/bcm/sha512-x86_64-linux.S +2978 -0
- package/runtime/third_party/boringssl/gen/bcm/vpaes-armv7-linux.S +1225 -0
- package/runtime/third_party/boringssl/gen/bcm/vpaes-armv8-apple.S +1238 -0
- package/runtime/third_party/boringssl/gen/bcm/vpaes-armv8-linux.S +1220 -0
- package/runtime/third_party/boringssl/gen/bcm/vpaes-armv8-win.S +1256 -0
- package/runtime/third_party/boringssl/gen/bcm/vpaes-x86-apple.S +680 -0
- package/runtime/third_party/boringssl/gen/bcm/vpaes-x86-linux.S +706 -0
- package/runtime/third_party/boringssl/gen/bcm/vpaes-x86_64-apple.S +1146 -0
- package/runtime/third_party/boringssl/gen/bcm/vpaes-x86_64-linux.S +1133 -0
- package/runtime/third_party/boringssl/gen/bcm/x86-mont-apple.S +216 -0
- package/runtime/third_party/boringssl/gen/bcm/x86-mont-linux.S +218 -0
- package/runtime/third_party/boringssl/gen/bcm/x86_64-mont-apple.S +1238 -0
- package/runtime/third_party/boringssl/gen/bcm/x86_64-mont-linux.S +1237 -0
- package/runtime/third_party/boringssl/gen/bcm/x86_64-mont5-apple.S +3644 -0
- package/runtime/third_party/boringssl/gen/bcm/x86_64-mont5-linux.S +3628 -0
- package/runtime/third_party/boringssl/gen/boringssl_prefix_symbols_internal_x86_64_win_asm.inc +325 -0
- package/runtime/third_party/boringssl/gen/boringssl_prefix_symbols_internal_x86_win_asm.inc +325 -0
- package/runtime/third_party/boringssl/gen/crypto/aes128gcmsiv-x86_64-apple.S +3113 -0
- package/runtime/third_party/boringssl/gen/crypto/aes128gcmsiv-x86_64-linux.S +3091 -0
- package/runtime/third_party/boringssl/gen/crypto/chacha-armv4-linux.S +1450 -0
- package/runtime/third_party/boringssl/gen/crypto/chacha-armv8-apple.S +1969 -0
- package/runtime/third_party/boringssl/gen/crypto/chacha-armv8-linux.S +1967 -0
- package/runtime/third_party/boringssl/gen/crypto/chacha-armv8-win.S +1973 -0
- package/runtime/third_party/boringssl/gen/crypto/chacha-x86-apple.S +957 -0
- package/runtime/third_party/boringssl/gen/crypto/chacha-x86-linux.S +961 -0
- package/runtime/third_party/boringssl/gen/crypto/chacha-x86_64-apple.S +1608 -0
- package/runtime/third_party/boringssl/gen/crypto/chacha-x86_64-linux.S +1611 -0
- package/runtime/third_party/boringssl/gen/crypto/chacha20_poly1305_armv8-apple.S +3010 -0
- package/runtime/third_party/boringssl/gen/crypto/chacha20_poly1305_armv8-linux.S +3008 -0
- package/runtime/third_party/boringssl/gen/crypto/chacha20_poly1305_armv8-win.S +3014 -0
- package/runtime/third_party/boringssl/gen/crypto/chacha20_poly1305_x86_64-apple.S +8903 -0
- package/runtime/third_party/boringssl/gen/crypto/chacha20_poly1305_x86_64-linux.S +8940 -0
- package/runtime/third_party/boringssl/gen/crypto/err_data.cc +1578 -0
- package/runtime/third_party/boringssl/gen/crypto/md5-586-apple.S +684 -0
- package/runtime/third_party/boringssl/gen/crypto/md5-586-linux.S +686 -0
- package/runtime/third_party/boringssl/gen/crypto/md5-x86_64-apple.S +690 -0
- package/runtime/third_party/boringssl/gen/crypto/md5-x86_64-linux.S +695 -0
- package/runtime/third_party/boringssl/include/openssl/aead.h +650 -0
- package/runtime/third_party/boringssl/include/openssl/aes.h +173 -0
- package/runtime/third_party/boringssl/include/openssl/arm_arch.h +24 -0
- package/runtime/third_party/boringssl/include/openssl/asm_base.h +219 -0
- package/runtime/third_party/boringssl/include/openssl/asn1.h +2002 -0
- package/runtime/third_party/boringssl/include/openssl/asn1_mac.h +18 -0
- package/runtime/third_party/boringssl/include/openssl/asn1t.h +584 -0
- package/runtime/third_party/boringssl/include/openssl/base.h +548 -0
- package/runtime/third_party/boringssl/include/openssl/base64.h +156 -0
- package/runtime/third_party/boringssl/include/openssl/bio.h +1061 -0
- package/runtime/third_party/boringssl/include/openssl/blake2.h +63 -0
- package/runtime/third_party/boringssl/include/openssl/blowfish.h +58 -0
- package/runtime/third_party/boringssl/include/openssl/bn.h +986 -0
- package/runtime/third_party/boringssl/include/openssl/buf.h +95 -0
- package/runtime/third_party/boringssl/include/openssl/buffer.h +18 -0
- package/runtime/third_party/boringssl/include/openssl/bytestring.h +798 -0
- package/runtime/third_party/boringssl/include/openssl/cast.h +91 -0
- package/runtime/third_party/boringssl/include/openssl/chacha.h +47 -0
- package/runtime/third_party/boringssl/include/openssl/cipher.h +819 -0
- package/runtime/third_party/boringssl/include/openssl/cmac.h +91 -0
- package/runtime/third_party/boringssl/include/openssl/cms.h +147 -0
- package/runtime/third_party/boringssl/include/openssl/conf.h +136 -0
- package/runtime/third_party/boringssl/include/openssl/configuration.h +18 -0
- package/runtime/third_party/boringssl/include/openssl/cpu.h +18 -0
- package/runtime/third_party/boringssl/include/openssl/crypto.h +235 -0
- package/runtime/third_party/boringssl/include/openssl/ctrdrbg.h +116 -0
- package/runtime/third_party/boringssl/include/openssl/curve25519.h +309 -0
- package/runtime/third_party/boringssl/include/openssl/des.h +134 -0
- package/runtime/third_party/boringssl/include/openssl/dh.h +336 -0
- package/runtime/third_party/boringssl/include/openssl/digest.h +399 -0
- package/runtime/third_party/boringssl/include/openssl/dsa.h +392 -0
- package/runtime/third_party/boringssl/include/openssl/dtls1.h +16 -0
- package/runtime/third_party/boringssl/include/openssl/e_os2.h +18 -0
- package/runtime/third_party/boringssl/include/openssl/ec.h +530 -0
- package/runtime/third_party/boringssl/include/openssl/ec_key.h +358 -0
- package/runtime/third_party/boringssl/include/openssl/ecdh.h +67 -0
- package/runtime/third_party/boringssl/include/openssl/ecdsa.h +242 -0
- package/runtime/third_party/boringssl/include/openssl/engine.h +109 -0
- package/runtime/third_party/boringssl/include/openssl/err.h +416 -0
- package/runtime/third_party/boringssl/include/openssl/evp.h +1645 -0
- package/runtime/third_party/boringssl/include/openssl/evp_errors.h +66 -0
- package/runtime/third_party/boringssl/include/openssl/ex_data.h +117 -0
- package/runtime/third_party/boringssl/include/openssl/hkdf.h +68 -0
- package/runtime/third_party/boringssl/include/openssl/hmac.h +151 -0
- package/runtime/third_party/boringssl/include/openssl/hpke.h +456 -0
- package/runtime/third_party/boringssl/include/openssl/hrss.h +108 -0
- package/runtime/third_party/boringssl/include/openssl/is_boringssl.h +16 -0
- package/runtime/third_party/boringssl/include/openssl/kdf.h +92 -0
- package/runtime/third_party/boringssl/include/openssl/lhash.h +18 -0
- package/runtime/third_party/boringssl/include/openssl/md4.h +73 -0
- package/runtime/third_party/boringssl/include/openssl/md5.h +67 -0
- package/runtime/third_party/boringssl/include/openssl/mem.h +215 -0
- package/runtime/third_party/boringssl/include/openssl/mldsa.h +486 -0
- package/runtime/third_party/boringssl/include/openssl/mlkem.h +222 -0
- package/runtime/third_party/boringssl/include/openssl/nid.h +5561 -0
- package/runtime/third_party/boringssl/include/openssl/obj.h +225 -0
- package/runtime/third_party/boringssl/include/openssl/obj_mac.h +18 -0
- package/runtime/third_party/boringssl/include/openssl/objects.h +18 -0
- package/runtime/third_party/boringssl/include/openssl/opensslconf.h +108 -0
- package/runtime/third_party/boringssl/include/openssl/opensslv.h +18 -0
- package/runtime/third_party/boringssl/include/openssl/ossl_typ.h +18 -0
- package/runtime/third_party/boringssl/include/openssl/params.h +42 -0
- package/runtime/third_party/boringssl/include/openssl/pem.h +769 -0
- package/runtime/third_party/boringssl/include/openssl/pkcs12.h +18 -0
- package/runtime/third_party/boringssl/include/openssl/pkcs7.h +239 -0
- package/runtime/third_party/boringssl/include/openssl/pkcs8.h +267 -0
- package/runtime/third_party/boringssl/include/openssl/poly1305.h +52 -0
- package/runtime/third_party/boringssl/include/openssl/pool.h +137 -0
- package/runtime/third_party/boringssl/include/openssl/posix_time.h +51 -0
- package/runtime/third_party/boringssl/include/openssl/prefix_symbols.h +8000 -0
- package/runtime/third_party/boringssl/include/openssl/prefix_symbols_internal_S.h +633 -0
- package/runtime/third_party/boringssl/include/openssl/prefix_symbols_internal_c.h +329 -0
- package/runtime/third_party/boringssl/include/openssl/rand.h +138 -0
- package/runtime/third_party/boringssl/include/openssl/rc4.h +54 -0
- package/runtime/third_party/boringssl/include/openssl/ripemd.h +71 -0
- package/runtime/third_party/boringssl/include/openssl/rsa.h +893 -0
- package/runtime/third_party/boringssl/include/openssl/safestack.h +16 -0
- package/runtime/third_party/boringssl/include/openssl/service_indicator.h +19 -0
- package/runtime/third_party/boringssl/include/openssl/sha.h +108 -0
- package/runtime/third_party/boringssl/include/openssl/sha2.h +201 -0
- package/runtime/third_party/boringssl/include/openssl/siphash.h +37 -0
- package/runtime/third_party/boringssl/include/openssl/slhdsa.h +250 -0
- package/runtime/third_party/boringssl/include/openssl/span.h +376 -0
- package/runtime/third_party/boringssl/include/openssl/srtp.h +18 -0
- package/runtime/third_party/boringssl/include/openssl/ssl.h +7211 -0
- package/runtime/third_party/boringssl/include/openssl/ssl3.h +171 -0
- package/runtime/third_party/boringssl/include/openssl/stack.h +688 -0
- package/runtime/third_party/boringssl/include/openssl/target.h +246 -0
- package/runtime/third_party/boringssl/include/openssl/thread.h +114 -0
- package/runtime/third_party/boringssl/include/openssl/time.h +22 -0
- package/runtime/third_party/boringssl/include/openssl/tls1.h +263 -0
- package/runtime/third_party/boringssl/include/openssl/tls_prf.h +47 -0
- package/runtime/third_party/boringssl/include/openssl/trust_token.h +349 -0
- package/runtime/third_party/boringssl/include/openssl/type_check.h +37 -0
- package/runtime/third_party/boringssl/include/openssl/types.h +18 -0
- package/runtime/third_party/boringssl/include/openssl/x509.h +5404 -0
- package/runtime/third_party/boringssl/include/openssl/x509_vfy.h +18 -0
- package/runtime/third_party/boringssl/include/openssl/x509v3.h +63 -0
- package/runtime/third_party/boringssl/include/openssl/x509v3_errors.h +84 -0
- package/runtime/third_party/boringssl/include/openssl/xwing.h +115 -0
- package/runtime/third_party/boringssl/sources.json +696 -0
- package/runtime/third_party/boringssl/ssl/bio_ssl.cc +196 -0
- package/runtime/third_party/boringssl/ssl/d1_both.cc +1137 -0
- package/runtime/third_party/boringssl/ssl/d1_lib.cc +245 -0
- package/runtime/third_party/boringssl/ssl/d1_pkt.cc +322 -0
- package/runtime/third_party/boringssl/ssl/d1_srtp.cc +128 -0
- package/runtime/third_party/boringssl/ssl/dtls_method.cc +216 -0
- package/runtime/third_party/boringssl/ssl/dtls_record.cc +586 -0
- package/runtime/third_party/boringssl/ssl/encrypted_client_hello.cc +1110 -0
- package/runtime/third_party/boringssl/ssl/extensions.cc +5368 -0
- package/runtime/third_party/boringssl/ssl/handoff.cc +625 -0
- package/runtime/third_party/boringssl/ssl/handshake.cc +694 -0
- package/runtime/third_party/boringssl/ssl/handshake_client.cc +1958 -0
- package/runtime/third_party/boringssl/ssl/handshake_server.cc +1875 -0
- package/runtime/third_party/boringssl/ssl/internal.h +4506 -0
- package/runtime/third_party/boringssl/ssl/s3_both.cc +555 -0
- package/runtime/third_party/boringssl/ssl/s3_lib.cc +88 -0
- package/runtime/third_party/boringssl/ssl/s3_pkt.cc +396 -0
- package/runtime/third_party/boringssl/ssl/ssl_aead_ctx.cc +416 -0
- package/runtime/third_party/boringssl/ssl/ssl_asn1.cc +851 -0
- package/runtime/third_party/boringssl/ssl/ssl_buffer.cc +304 -0
- package/runtime/third_party/boringssl/ssl/ssl_cert.cc +723 -0
- package/runtime/third_party/boringssl/ssl/ssl_cipher.cc +1762 -0
- package/runtime/third_party/boringssl/ssl/ssl_credential.cc +913 -0
- package/runtime/third_party/boringssl/ssl/ssl_file.cc +375 -0
- package/runtime/third_party/boringssl/ssl/ssl_key_share.cc +445 -0
- package/runtime/third_party/boringssl/ssl/ssl_lib.cc +4132 -0
- package/runtime/third_party/boringssl/ssl/ssl_privkey.cc +973 -0
- package/runtime/third_party/boringssl/ssl/ssl_session.cc +1273 -0
- package/runtime/third_party/boringssl/ssl/ssl_stat.cc +162 -0
- package/runtime/third_party/boringssl/ssl/ssl_transcript.cc +224 -0
- package/runtime/third_party/boringssl/ssl/ssl_versions.cc +436 -0
- package/runtime/third_party/boringssl/ssl/ssl_x509.cc +1229 -0
- package/runtime/third_party/boringssl/ssl/t1_enc.cc +266 -0
- package/runtime/third_party/boringssl/ssl/tls13_both.cc +764 -0
- package/runtime/third_party/boringssl/ssl/tls13_client.cc +1325 -0
- package/runtime/third_party/boringssl/ssl/tls13_enc.cc +746 -0
- package/runtime/third_party/boringssl/ssl/tls13_server.cc +1623 -0
- package/runtime/third_party/boringssl/ssl/tls_method.cc +266 -0
- package/runtime/third_party/boringssl/ssl/tls_record.cc +524 -0
- package/runtime/third_party/boringssl/third_party/fiat/asm/fiat_curve25519_adx_mul.S +178 -0
- package/runtime/third_party/boringssl/third_party/fiat/asm/fiat_curve25519_adx_square.S +146 -0
- package/runtime/third_party/boringssl/third_party/fiat/asm/fiat_p256_adx_mul.S +177 -0
- package/runtime/third_party/boringssl/third_party/fiat/asm/fiat_p256_adx_sqr.S +166 -0
- package/runtime/third_party/boringssl/third_party/fiat/bedrock_unverified_bareminimum.c.inc +47 -0
- package/runtime/third_party/boringssl/third_party/fiat/bedrock_unverified_platform.c.inc +137 -0
- package/runtime/third_party/boringssl/third_party/fiat/curve25519_32.h +1571 -0
- package/runtime/third_party/boringssl/third_party/fiat/curve25519_64.h +978 -0
- package/runtime/third_party/boringssl/third_party/fiat/curve25519_64_adx.h +700 -0
- package/runtime/third_party/boringssl/third_party/fiat/curve25519_64_msvc.h +1281 -0
- package/runtime/third_party/boringssl/third_party/fiat/p256_32.h +4760 -0
- package/runtime/third_party/boringssl/third_party/fiat/p256_64.h +1984 -0
- package/runtime/third_party/boringssl/third_party/fiat/p256_64_msvc.h +1939 -0
- package/runtime/third_party/boringssl/third_party/fiat/p256_field.c.inc +26 -0
- package/runtime/third_party/boringssl/third_party/fiat/p256_field_32.br.c.inc +71 -0
- package/runtime/third_party/boringssl/third_party/fiat/p256_field_64.br.c.inc +84 -0
- package/runtime/third_party/boringssl/third_party/fiat/p256_point.br.c.inc +112 -0
- package/runtime/third_party/v8-ieee754/README.md +2 -1
- package/runtime/third_party/v8-ieee754/convert.py +4 -0
- package/runtime/third_party/v8-ieee754/ieee754.c +1 -1
- package/runtime/third_party/bearssl/LICENSE.txt +0 -21
- package/runtime/third_party/bearssl/README.txt +0 -136
- package/runtime/third_party/bearssl/VERSION +0 -1
- package/runtime/third_party/bearssl/inc/bearssl.h +0 -183
- package/runtime/third_party/bearssl/inc/bearssl_aead.h +0 -1059
- package/runtime/third_party/bearssl/inc/bearssl_block.h +0 -2618
- package/runtime/third_party/bearssl/inc/bearssl_ec.h +0 -967
- package/runtime/third_party/bearssl/inc/bearssl_hash.h +0 -1346
- package/runtime/third_party/bearssl/inc/bearssl_hmac.h +0 -241
- package/runtime/third_party/bearssl/inc/bearssl_kdf.h +0 -284
- package/runtime/third_party/bearssl/inc/bearssl_pem.h +0 -294
- package/runtime/third_party/bearssl/inc/bearssl_prf.h +0 -150
- package/runtime/third_party/bearssl/inc/bearssl_rand.h +0 -397
- package/runtime/third_party/bearssl/inc/bearssl_rsa.h +0 -1655
- package/runtime/third_party/bearssl/inc/bearssl_ssl.h +0 -4296
- package/runtime/third_party/bearssl/inc/bearssl_x509.h +0 -1474
- package/runtime/third_party/bearssl/src/aead/ccm.c +0 -346
- package/runtime/third_party/bearssl/src/aead/eax.c +0 -525
- package/runtime/third_party/bearssl/src/aead/gcm.c +0 -318
- package/runtime/third_party/bearssl/src/codec/ccopy.c +0 -44
- package/runtime/third_party/bearssl/src/codec/dec16be.c +0 -38
- package/runtime/third_party/bearssl/src/codec/dec16le.c +0 -38
- package/runtime/third_party/bearssl/src/codec/dec32be.c +0 -38
- package/runtime/third_party/bearssl/src/codec/dec32le.c +0 -38
- package/runtime/third_party/bearssl/src/codec/dec64be.c +0 -38
- package/runtime/third_party/bearssl/src/codec/dec64le.c +0 -38
- package/runtime/third_party/bearssl/src/codec/enc16be.c +0 -38
- package/runtime/third_party/bearssl/src/codec/enc16le.c +0 -38
- package/runtime/third_party/bearssl/src/codec/enc32be.c +0 -38
- package/runtime/third_party/bearssl/src/codec/enc32le.c +0 -38
- package/runtime/third_party/bearssl/src/codec/enc64be.c +0 -38
- package/runtime/third_party/bearssl/src/codec/enc64le.c +0 -38
- package/runtime/third_party/bearssl/src/codec/pemdec.c +0 -526
- package/runtime/third_party/bearssl/src/codec/pemdec.t0 +0 -314
- package/runtime/third_party/bearssl/src/codec/pemenc.c +0 -173
- package/runtime/third_party/bearssl/src/config.h +0 -247
- package/runtime/third_party/bearssl/src/ec/ec_all_m15.c +0 -121
- package/runtime/third_party/bearssl/src/ec/ec_all_m31.c +0 -171
- package/runtime/third_party/bearssl/src/ec/ec_c25519_i15.c +0 -398
- package/runtime/third_party/bearssl/src/ec/ec_c25519_i31.c +0 -390
- package/runtime/third_party/bearssl/src/ec/ec_c25519_m15.c +0 -1478
- package/runtime/third_party/bearssl/src/ec/ec_c25519_m31.c +0 -800
- package/runtime/third_party/bearssl/src/ec/ec_c25519_m62.c +0 -605
- package/runtime/third_party/bearssl/src/ec/ec_c25519_m64.c +0 -831
- package/runtime/third_party/bearssl/src/ec/ec_curve25519.c +0 -46
- package/runtime/third_party/bearssl/src/ec/ec_default.c +0 -36
- package/runtime/third_party/bearssl/src/ec/ec_keygen.c +0 -86
- package/runtime/third_party/bearssl/src/ec/ec_p256_m15.c +0 -2124
- package/runtime/third_party/bearssl/src/ec/ec_p256_m31.c +0 -1469
- package/runtime/third_party/bearssl/src/ec/ec_p256_m62.c +0 -1765
- package/runtime/third_party/bearssl/src/ec/ec_p256_m64.c +0 -1781
- package/runtime/third_party/bearssl/src/ec/ec_prime_i15.c +0 -824
- package/runtime/third_party/bearssl/src/ec/ec_prime_i31.c +0 -826
- package/runtime/third_party/bearssl/src/ec/ec_pubkey.c +0 -85
- package/runtime/third_party/bearssl/src/ec/ec_secp256r1.c +0 -51
- package/runtime/third_party/bearssl/src/ec/ec_secp384r1.c +0 -57
- package/runtime/third_party/bearssl/src/ec/ec_secp521r1.c +0 -64
- package/runtime/third_party/bearssl/src/ec/ecdsa_atr.c +0 -134
- package/runtime/third_party/bearssl/src/ec/ecdsa_default_sign_asn1.c +0 -36
- package/runtime/third_party/bearssl/src/ec/ecdsa_default_sign_raw.c +0 -36
- package/runtime/third_party/bearssl/src/ec/ecdsa_default_vrfy_asn1.c +0 -36
- package/runtime/third_party/bearssl/src/ec/ecdsa_default_vrfy_raw.c +0 -36
- package/runtime/third_party/bearssl/src/ec/ecdsa_i15_bits.c +0 -47
- package/runtime/third_party/bearssl/src/ec/ecdsa_i15_sign_asn1.c +0 -45
- package/runtime/third_party/bearssl/src/ec/ecdsa_i15_sign_raw.c +0 -174
- package/runtime/third_party/bearssl/src/ec/ecdsa_i15_vrfy_asn1.c +0 -48
- package/runtime/third_party/bearssl/src/ec/ecdsa_i15_vrfy_raw.c +0 -166
- package/runtime/third_party/bearssl/src/ec/ecdsa_i31_bits.c +0 -47
- package/runtime/third_party/bearssl/src/ec/ecdsa_i31_sign_asn1.c +0 -45
- package/runtime/third_party/bearssl/src/ec/ecdsa_i31_sign_raw.c +0 -173
- package/runtime/third_party/bearssl/src/ec/ecdsa_i31_vrfy_asn1.c +0 -48
- package/runtime/third_party/bearssl/src/ec/ecdsa_i31_vrfy_raw.c +0 -165
- package/runtime/third_party/bearssl/src/ec/ecdsa_rta.c +0 -121
- package/runtime/third_party/bearssl/src/hash/dig_oid.c +0 -84
- package/runtime/third_party/bearssl/src/hash/dig_size.c +0 -50
- package/runtime/third_party/bearssl/src/hash/ghash_ctmul.c +0 -345
- package/runtime/third_party/bearssl/src/hash/ghash_ctmul32.c +0 -251
- package/runtime/third_party/bearssl/src/hash/ghash_ctmul64.c +0 -154
- package/runtime/third_party/bearssl/src/hash/ghash_pclmul.c +0 -389
- package/runtime/third_party/bearssl/src/hash/ghash_pwr8.c +0 -411
- package/runtime/third_party/bearssl/src/hash/md5.c +0 -208
- package/runtime/third_party/bearssl/src/hash/md5sha1.c +0 -141
- package/runtime/third_party/bearssl/src/hash/mgf1.c +0 -56
- package/runtime/third_party/bearssl/src/hash/multihash.c +0 -166
- package/runtime/third_party/bearssl/src/hash/sha1.c +0 -191
- package/runtime/third_party/bearssl/src/hash/sha2big.c +0 -285
- package/runtime/third_party/bearssl/src/hash/sha2small.c +0 -341
- package/runtime/third_party/bearssl/src/inner.h +0 -2577
- package/runtime/third_party/bearssl/src/int/i15_add.c +0 -46
- package/runtime/third_party/bearssl/src/int/i15_bitlen.c +0 -44
- package/runtime/third_party/bearssl/src/int/i15_decmod.c +0 -124
- package/runtime/third_party/bearssl/src/int/i15_decode.c +0 -56
- package/runtime/third_party/bearssl/src/int/i15_decred.c +0 -100
- package/runtime/third_party/bearssl/src/int/i15_encode.c +0 -56
- package/runtime/third_party/bearssl/src/int/i15_fmont.c +0 -59
- package/runtime/third_party/bearssl/src/int/i15_iszero.c +0 -39
- package/runtime/third_party/bearssl/src/int/i15_moddiv.c +0 -465
- package/runtime/third_party/bearssl/src/int/i15_modpow.c +0 -50
- package/runtime/third_party/bearssl/src/int/i15_modpow2.c +0 -160
- package/runtime/third_party/bearssl/src/int/i15_montmul.c +0 -184
- package/runtime/third_party/bearssl/src/int/i15_mulacc.c +0 -61
- package/runtime/third_party/bearssl/src/int/i15_muladd.c +0 -173
- package/runtime/third_party/bearssl/src/int/i15_ninv15.c +0 -38
- package/runtime/third_party/bearssl/src/int/i15_reduce.c +0 -66
- package/runtime/third_party/bearssl/src/int/i15_rshift.c +0 -47
- package/runtime/third_party/bearssl/src/int/i15_sub.c +0 -46
- package/runtime/third_party/bearssl/src/int/i15_tmont.c +0 -36
- package/runtime/third_party/bearssl/src/int/i31_add.c +0 -46
- package/runtime/third_party/bearssl/src/int/i31_bitlen.c +0 -44
- package/runtime/third_party/bearssl/src/int/i31_decmod.c +0 -124
- package/runtime/third_party/bearssl/src/int/i31_decode.c +0 -57
- package/runtime/third_party/bearssl/src/int/i31_decred.c +0 -103
- package/runtime/third_party/bearssl/src/int/i31_encode.c +0 -79
- package/runtime/third_party/bearssl/src/int/i31_fmont.c +0 -60
- package/runtime/third_party/bearssl/src/int/i31_iszero.c +0 -39
- package/runtime/third_party/bearssl/src/int/i31_moddiv.c +0 -488
- package/runtime/third_party/bearssl/src/int/i31_modpow.c +0 -65
- package/runtime/third_party/bearssl/src/int/i31_modpow2.c +0 -160
- package/runtime/third_party/bearssl/src/int/i31_montmul.c +0 -127
- package/runtime/third_party/bearssl/src/int/i31_mulacc.c +0 -74
- package/runtime/third_party/bearssl/src/int/i31_muladd.c +0 -157
- package/runtime/third_party/bearssl/src/int/i31_ninv31.c +0 -39
- package/runtime/third_party/bearssl/src/int/i31_reduce.c +0 -66
- package/runtime/third_party/bearssl/src/int/i31_rshift.c +0 -47
- package/runtime/third_party/bearssl/src/int/i31_sub.c +0 -46
- package/runtime/third_party/bearssl/src/int/i31_tmont.c +0 -36
- package/runtime/third_party/bearssl/src/int/i32_add.c +0 -51
- package/runtime/third_party/bearssl/src/int/i32_bitlen.c +0 -44
- package/runtime/third_party/bearssl/src/int/i32_decmod.c +0 -77
- package/runtime/third_party/bearssl/src/int/i32_decode.c +0 -63
- package/runtime/third_party/bearssl/src/int/i32_decred.c +0 -107
- package/runtime/third_party/bearssl/src/int/i32_div32.c +0 -56
- package/runtime/third_party/bearssl/src/int/i32_encode.c +0 -72
- package/runtime/third_party/bearssl/src/int/i32_fmont.c +0 -60
- package/runtime/third_party/bearssl/src/int/i32_iszero.c +0 -39
- package/runtime/third_party/bearssl/src/int/i32_modpow.c +0 -65
- package/runtime/third_party/bearssl/src/int/i32_montmul.c +0 -69
- package/runtime/third_party/bearssl/src/int/i32_mulacc.c +0 -56
- package/runtime/third_party/bearssl/src/int/i32_muladd.c +0 -138
- package/runtime/third_party/bearssl/src/int/i32_ninv32.c +0 -39
- package/runtime/third_party/bearssl/src/int/i32_reduce.c +0 -66
- package/runtime/third_party/bearssl/src/int/i32_sub.c +0 -51
- package/runtime/third_party/bearssl/src/int/i32_tmont.c +0 -36
- package/runtime/third_party/bearssl/src/int/i62_modpow2.c +0 -493
- package/runtime/third_party/bearssl/src/kdf/hkdf.c +0 -107
- package/runtime/third_party/bearssl/src/kdf/shake.c +0 -590
- package/runtime/third_party/bearssl/src/mac/hmac.c +0 -122
- package/runtime/third_party/bearssl/src/mac/hmac_ct.c +0 -193
- package/runtime/third_party/bearssl/src/rand/aesctr_drbg.c +0 -206
- package/runtime/third_party/bearssl/src/rand/hmac_drbg.c +0 -157
- package/runtime/third_party/bearssl/src/rand/sysrng.c +0 -252
- package/runtime/third_party/bearssl/src/rsa/rsa_default_keygen.c +0 -38
- package/runtime/third_party/bearssl/src/rsa/rsa_default_modulus.c +0 -36
- package/runtime/third_party/bearssl/src/rsa/rsa_default_oaep_decrypt.c +0 -38
- package/runtime/third_party/bearssl/src/rsa/rsa_default_oaep_encrypt.c +0 -38
- package/runtime/third_party/bearssl/src/rsa/rsa_default_pkcs1_sign.c +0 -38
- package/runtime/third_party/bearssl/src/rsa/rsa_default_pkcs1_vrfy.c +0 -38
- package/runtime/third_party/bearssl/src/rsa/rsa_default_priv.c +0 -38
- package/runtime/third_party/bearssl/src/rsa/rsa_default_privexp.c +0 -36
- package/runtime/third_party/bearssl/src/rsa/rsa_default_pss_sign.c +0 -38
- package/runtime/third_party/bearssl/src/rsa/rsa_default_pss_vrfy.c +0 -38
- package/runtime/third_party/bearssl/src/rsa/rsa_default_pub.c +0 -38
- package/runtime/third_party/bearssl/src/rsa/rsa_default_pubexp.c +0 -36
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_keygen.c +0 -583
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_modulus.c +0 -99
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_oaep_decrypt.c +0 -41
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_oaep_encrypt.c +0 -44
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_pkcs1_sign.c +0 -37
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_pkcs1_vrfy.c +0 -43
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_priv.c +0 -209
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_privexp.c +0 -320
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_pss_sign.c +0 -40
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_pss_vrfy.c +0 -44
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_pub.c +0 -113
- package/runtime/third_party/bearssl/src/rsa/rsa_i15_pubexp.c +0 -152
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_keygen.c +0 -37
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_keygen_inner.c +0 -608
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_modulus.c +0 -99
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_oaep_decrypt.c +0 -41
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_oaep_encrypt.c +0 -44
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_pkcs1_sign.c +0 -37
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_pkcs1_vrfy.c +0 -43
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_priv.c +0 -203
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_privexp.c +0 -318
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_pss_sign.c +0 -40
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_pss_vrfy.c +0 -44
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_pub.c +0 -106
- package/runtime/third_party/bearssl/src/rsa/rsa_i31_pubexp.c +0 -152
- package/runtime/third_party/bearssl/src/rsa/rsa_i32_oaep_decrypt.c +0 -41
- package/runtime/third_party/bearssl/src/rsa/rsa_i32_oaep_encrypt.c +0 -44
- package/runtime/third_party/bearssl/src/rsa/rsa_i32_pkcs1_sign.c +0 -37
- package/runtime/third_party/bearssl/src/rsa/rsa_i32_pkcs1_vrfy.c +0 -43
- package/runtime/third_party/bearssl/src/rsa/rsa_i32_priv.c +0 -160
- package/runtime/third_party/bearssl/src/rsa/rsa_i32_pss_sign.c +0 -40
- package/runtime/third_party/bearssl/src/rsa/rsa_i32_pss_vrfy.c +0 -44
- package/runtime/third_party/bearssl/src/rsa/rsa_i32_pub.c +0 -77
- package/runtime/third_party/bearssl/src/rsa/rsa_i62_keygen.c +0 -57
- package/runtime/third_party/bearssl/src/rsa/rsa_i62_oaep_decrypt.c +0 -61
- package/runtime/third_party/bearssl/src/rsa/rsa_i62_oaep_encrypt.c +0 -64
- package/runtime/third_party/bearssl/src/rsa/rsa_i62_pkcs1_sign.c +0 -57
- package/runtime/third_party/bearssl/src/rsa/rsa_i62_pkcs1_vrfy.c +0 -63
- package/runtime/third_party/bearssl/src/rsa/rsa_i62_priv.c +0 -223
- package/runtime/third_party/bearssl/src/rsa/rsa_i62_pss_sign.c +0 -60
- package/runtime/third_party/bearssl/src/rsa/rsa_i62_pss_vrfy.c +0 -64
- package/runtime/third_party/bearssl/src/rsa/rsa_i62_pub.c +0 -125
- package/runtime/third_party/bearssl/src/rsa/rsa_oaep_pad.c +0 -112
- package/runtime/third_party/bearssl/src/rsa/rsa_oaep_unpad.c +0 -145
- package/runtime/third_party/bearssl/src/rsa/rsa_pkcs1_sig_pad.c +0 -100
- package/runtime/third_party/bearssl/src/rsa/rsa_pkcs1_sig_unpad.c +0 -121
- package/runtime/third_party/bearssl/src/rsa/rsa_pss_sig_pad.c +0 -106
- package/runtime/third_party/bearssl/src/rsa/rsa_pss_sig_unpad.c +0 -121
- package/runtime/third_party/bearssl/src/rsa/rsa_ssl_decrypt.c +0 -52
- package/runtime/third_party/bearssl/src/settings.c +0 -306
- package/runtime/third_party/bearssl/src/symcipher/aes_big_cbcdec.c +0 -69
- package/runtime/third_party/bearssl/src/symcipher/aes_big_cbcenc.c +0 -67
- package/runtime/third_party/bearssl/src/symcipher/aes_big_ctr.c +0 -84
- package/runtime/third_party/bearssl/src/symcipher/aes_big_ctrcbc.c +0 -142
- package/runtime/third_party/bearssl/src/symcipher/aes_big_dec.c +0 -254
- package/runtime/third_party/bearssl/src/symcipher/aes_big_enc.c +0 -157
- package/runtime/third_party/bearssl/src/symcipher/aes_common.c +0 -112
- package/runtime/third_party/bearssl/src/symcipher/aes_ct.c +0 -328
- package/runtime/third_party/bearssl/src/symcipher/aes_ct64.c +0 -398
- package/runtime/third_party/bearssl/src/symcipher/aes_ct64_cbcdec.c +0 -104
- package/runtime/third_party/bearssl/src/symcipher/aes_ct64_cbcenc.c +0 -81
- package/runtime/third_party/bearssl/src/symcipher/aes_ct64_ctr.c +0 -114
- package/runtime/third_party/bearssl/src/symcipher/aes_ct64_ctrcbc.c +0 -433
- package/runtime/third_party/bearssl/src/symcipher/aes_ct64_dec.c +0 -159
- package/runtime/third_party/bearssl/src/symcipher/aes_ct64_enc.c +0 -115
- package/runtime/third_party/bearssl/src/symcipher/aes_ct_cbcdec.c +0 -111
- package/runtime/third_party/bearssl/src/symcipher/aes_ct_cbcenc.c +0 -91
- package/runtime/third_party/bearssl/src/symcipher/aes_ct_ctr.c +0 -116
- package/runtime/third_party/bearssl/src/symcipher/aes_ct_ctrcbc.c +0 -422
- package/runtime/third_party/bearssl/src/symcipher/aes_ct_dec.c +0 -170
- package/runtime/third_party/bearssl/src/symcipher/aes_ct_enc.c +0 -112
- package/runtime/third_party/bearssl/src/symcipher/aes_pwr8.c +0 -445
- package/runtime/third_party/bearssl/src/symcipher/aes_pwr8_cbcdec.c +0 -670
- package/runtime/third_party/bearssl/src/symcipher/aes_pwr8_cbcenc.c +0 -417
- package/runtime/third_party/bearssl/src/symcipher/aes_pwr8_ctr.c +0 -717
- package/runtime/third_party/bearssl/src/symcipher/aes_pwr8_ctrcbc.c +0 -946
- package/runtime/third_party/bearssl/src/symcipher/aes_small_cbcdec.c +0 -69
- package/runtime/third_party/bearssl/src/symcipher/aes_small_cbcenc.c +0 -67
- package/runtime/third_party/bearssl/src/symcipher/aes_small_ctr.c +0 -84
- package/runtime/third_party/bearssl/src/symcipher/aes_small_ctrcbc.c +0 -142
- package/runtime/third_party/bearssl/src/symcipher/aes_small_dec.c +0 -176
- package/runtime/third_party/bearssl/src/symcipher/aes_small_enc.c +0 -129
- package/runtime/third_party/bearssl/src/symcipher/aes_x86ni.c +0 -240
- package/runtime/third_party/bearssl/src/symcipher/aes_x86ni_cbcdec.c +0 -223
- package/runtime/third_party/bearssl/src/symcipher/aes_x86ni_cbcenc.c +0 -122
- package/runtime/third_party/bearssl/src/symcipher/aes_x86ni_ctr.c +0 -211
- package/runtime/third_party/bearssl/src/symcipher/aes_x86ni_ctrcbc.c +0 -596
- package/runtime/third_party/bearssl/src/symcipher/chacha20_ct.c +0 -106
- package/runtime/third_party/bearssl/src/symcipher/chacha20_sse2.c +0 -237
- package/runtime/third_party/bearssl/src/symcipher/des_ct.c +0 -411
- package/runtime/third_party/bearssl/src/symcipher/des_ct_cbcdec.c +0 -87
- package/runtime/third_party/bearssl/src/symcipher/des_ct_cbcenc.c +0 -69
- package/runtime/third_party/bearssl/src/symcipher/des_support.c +0 -166
- package/runtime/third_party/bearssl/src/symcipher/des_tab.c +0 -310
- package/runtime/third_party/bearssl/src/symcipher/des_tab_cbcdec.c +0 -85
- package/runtime/third_party/bearssl/src/symcipher/des_tab_cbcenc.c +0 -67
- package/runtime/third_party/bearssl/src/symcipher/poly1305_ctmul.c +0 -260
- package/runtime/third_party/bearssl/src/symcipher/poly1305_ctmul32.c +0 -297
- package/runtime/third_party/bearssl/src/symcipher/poly1305_ctmulq.c +0 -475
- package/runtime/third_party/bearssl/src/symcipher/poly1305_i15.c +0 -221
- package/runtime/third_party/bearssl/src/x509/asn1.t0 +0 -757
- package/runtime/third_party/bearssl/src/x509/asn1enc.c +0 -93
- package/runtime/third_party/bearssl/src/x509/encode_ec_pk8der.c +0 -110
- package/runtime/third_party/bearssl/src/x509/encode_ec_rawder.c +0 -161
- package/runtime/third_party/bearssl/src/x509/encode_rsa_pk8der.c +0 -97
- package/runtime/third_party/bearssl/src/x509/encode_rsa_rawder.c +0 -96
- package/runtime/third_party/bearssl/src/x509/skey_decoder.c +0 -653
- package/runtime/third_party/bearssl/src/x509/skey_decoder.t0 +0 -376
- package/runtime/third_party/bearssl/src/x509/x509_decoder.c +0 -776
- package/runtime/third_party/bearssl/src/x509/x509_decoder.t0 +0 -324
- package/runtime/third_party/bearssl/src/x509/x509_knownkey.c +0 -105
- package/runtime/third_party/bearssl/src/x509/x509_minimal.c +0 -1722
- package/runtime/third_party/bearssl/src/x509/x509_minimal.t0 +0 -1526
- package/runtime/third_party/bearssl/src/x509/x509_minimal_full.c +0 -59
|
@@ -0,0 +1,2436 @@
|
|
|
1
|
+
// Copyright 2020 The BoringSSL Authors
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
// Some of this code is taken from the ref10 version of Ed25519 in SUPERCOP
|
|
16
|
+
// 20141124 (http://bench.cr.yp.to/supercop.html). That code is released as
|
|
17
|
+
// public domain. Other parts have been replaced to call into code generated by
|
|
18
|
+
// Fiat (https://github.com/mit-plv/fiat-crypto) in //third_party/fiat.
|
|
19
|
+
//
|
|
20
|
+
// The field functions are shared by Ed25519 and X25519 where possible.
|
|
21
|
+
|
|
22
|
+
#include <assert.h>
|
|
23
|
+
#include <string.h>
|
|
24
|
+
|
|
25
|
+
#include <openssl/digest.h>
|
|
26
|
+
#include <openssl/mem.h>
|
|
27
|
+
#include <openssl/rand.h>
|
|
28
|
+
#include <openssl/sha2.h>
|
|
29
|
+
|
|
30
|
+
#include "../internal.h"
|
|
31
|
+
#include "internal.h"
|
|
32
|
+
|
|
33
|
+
// Various pre-computed constants.
|
|
34
|
+
#include "./curve25519_tables.h"
|
|
35
|
+
|
|
36
|
+
#if defined(BORINGSSL_HAS_UINT128)
|
|
37
|
+
#include "../../third_party/fiat/curve25519_64.h"
|
|
38
|
+
#elif defined(OPENSSL_64_BIT)
|
|
39
|
+
#include "../../third_party/fiat/curve25519_64_msvc.h"
|
|
40
|
+
#else
|
|
41
|
+
#include "../../third_party/fiat/curve25519_32.h"
|
|
42
|
+
#endif
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
using namespace bssl;
|
|
46
|
+
|
|
47
|
+
// Low-level intrinsic operations
|
|
48
|
+
|
|
49
|
+
static uint64_t load_3(const uint8_t *in) {
|
|
50
|
+
uint64_t result;
|
|
51
|
+
result = (uint64_t)in[0];
|
|
52
|
+
result |= ((uint64_t)in[1]) << 8;
|
|
53
|
+
result |= ((uint64_t)in[2]) << 16;
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static uint64_t load_4(const uint8_t *in) {
|
|
58
|
+
uint64_t result;
|
|
59
|
+
result = (uint64_t)in[0];
|
|
60
|
+
result |= ((uint64_t)in[1]) << 8;
|
|
61
|
+
result |= ((uint64_t)in[2]) << 16;
|
|
62
|
+
result |= ((uint64_t)in[3]) << 24;
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
// Field operations.
|
|
68
|
+
|
|
69
|
+
#if defined(OPENSSL_64_BIT)
|
|
70
|
+
|
|
71
|
+
typedef uint64_t fe_limb_t;
|
|
72
|
+
#define FE_NUM_LIMBS 5
|
|
73
|
+
|
|
74
|
+
// assert_fe asserts that `f` satisfies bounds:
|
|
75
|
+
//
|
|
76
|
+
// [[0x0 ~> 0x8cccccccccccc],
|
|
77
|
+
// [0x0 ~> 0x8cccccccccccc],
|
|
78
|
+
// [0x0 ~> 0x8cccccccccccc],
|
|
79
|
+
// [0x0 ~> 0x8cccccccccccc],
|
|
80
|
+
// [0x0 ~> 0x8cccccccccccc]]
|
|
81
|
+
//
|
|
82
|
+
// See comments in curve25519_64.h for which functions use these bounds for
|
|
83
|
+
// inputs or outputs.
|
|
84
|
+
#define assert_fe(f) \
|
|
85
|
+
do { \
|
|
86
|
+
for (unsigned _assert_fe_i = 0; _assert_fe_i < 5; _assert_fe_i++) { \
|
|
87
|
+
declassify_assert(f[_assert_fe_i] <= UINT64_C(0x8cccccccccccc)); \
|
|
88
|
+
} \
|
|
89
|
+
} while (0)
|
|
90
|
+
|
|
91
|
+
// assert_fe_loose asserts that `f` satisfies bounds:
|
|
92
|
+
//
|
|
93
|
+
// [[0x0 ~> 0x1a666666666664],
|
|
94
|
+
// [0x0 ~> 0x1a666666666664],
|
|
95
|
+
// [0x0 ~> 0x1a666666666664],
|
|
96
|
+
// [0x0 ~> 0x1a666666666664],
|
|
97
|
+
// [0x0 ~> 0x1a666666666664]]
|
|
98
|
+
//
|
|
99
|
+
// See comments in curve25519_64.h for which functions use these bounds for
|
|
100
|
+
// inputs or outputs.
|
|
101
|
+
#define assert_fe_loose(f) \
|
|
102
|
+
do { \
|
|
103
|
+
for (unsigned _assert_fe_i = 0; _assert_fe_i < 5; _assert_fe_i++) { \
|
|
104
|
+
declassify_assert(f[_assert_fe_i] <= UINT64_C(0x1a666666666664)); \
|
|
105
|
+
} \
|
|
106
|
+
} while (0)
|
|
107
|
+
|
|
108
|
+
#else
|
|
109
|
+
|
|
110
|
+
typedef uint32_t fe_limb_t;
|
|
111
|
+
#define FE_NUM_LIMBS 10
|
|
112
|
+
|
|
113
|
+
// assert_fe asserts that `f` satisfies bounds:
|
|
114
|
+
//
|
|
115
|
+
// [[0x0 ~> 0x4666666], [0x0 ~> 0x2333333],
|
|
116
|
+
// [0x0 ~> 0x4666666], [0x0 ~> 0x2333333],
|
|
117
|
+
// [0x0 ~> 0x4666666], [0x0 ~> 0x2333333],
|
|
118
|
+
// [0x0 ~> 0x4666666], [0x0 ~> 0x2333333],
|
|
119
|
+
// [0x0 ~> 0x4666666], [0x0 ~> 0x2333333]]
|
|
120
|
+
//
|
|
121
|
+
// See comments in curve25519_32.h for which functions use these bounds for
|
|
122
|
+
// inputs or outputs.
|
|
123
|
+
#define assert_fe(f) \
|
|
124
|
+
do { \
|
|
125
|
+
for (unsigned _assert_fe_i = 0; _assert_fe_i < 10; _assert_fe_i++) { \
|
|
126
|
+
declassify_assert(f[_assert_fe_i] <= \
|
|
127
|
+
((_assert_fe_i & 1) ? 0x2333333u : 0x4666666u)); \
|
|
128
|
+
} \
|
|
129
|
+
} while (0)
|
|
130
|
+
|
|
131
|
+
// assert_fe_loose asserts that `f` satisfies bounds:
|
|
132
|
+
//
|
|
133
|
+
// [[0x0 ~> 0xd333332], [0x0 ~> 0x6999999],
|
|
134
|
+
// [0x0 ~> 0xd333332], [0x0 ~> 0x6999999],
|
|
135
|
+
// [0x0 ~> 0xd333332], [0x0 ~> 0x6999999],
|
|
136
|
+
// [0x0 ~> 0xd333332], [0x0 ~> 0x6999999],
|
|
137
|
+
// [0x0 ~> 0xd333332], [0x0 ~> 0x6999999]]
|
|
138
|
+
//
|
|
139
|
+
// See comments in curve25519_32.h for which functions use these bounds for
|
|
140
|
+
// inputs or outputs.
|
|
141
|
+
#define assert_fe_loose(f) \
|
|
142
|
+
do { \
|
|
143
|
+
for (unsigned _assert_fe_i = 0; _assert_fe_i < 10; _assert_fe_i++) { \
|
|
144
|
+
declassify_assert(f[_assert_fe_i] <= \
|
|
145
|
+
((_assert_fe_i & 1) ? 0x6999999u : 0xd333332u)); \
|
|
146
|
+
} \
|
|
147
|
+
} while (0)
|
|
148
|
+
|
|
149
|
+
#endif // OPENSSL_64_BIT
|
|
150
|
+
|
|
151
|
+
static_assert(sizeof(fe) == sizeof(fe_limb_t) * FE_NUM_LIMBS,
|
|
152
|
+
"fe_limb_t[FE_NUM_LIMBS] is inconsistent with fe");
|
|
153
|
+
|
|
154
|
+
static void fe_frombytes_strict(fe *h, const uint8_t s[32]) {
|
|
155
|
+
// `fiat_25519_from_bytes` requires the top-most bit be clear.
|
|
156
|
+
declassify_assert((s[31] & 0x80) == 0);
|
|
157
|
+
fiat_25519_from_bytes(h->v, s);
|
|
158
|
+
assert_fe(h->v);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// fe_frombytes takes in a little-endian 255-bit number and decodes it into an
|
|
162
|
+
// `fe`.
|
|
163
|
+
static void fe_frombytes(fe *h, const uint8_t s[32]) {
|
|
164
|
+
uint8_t s_copy[32];
|
|
165
|
+
OPENSSL_memcpy(s_copy, s, 32);
|
|
166
|
+
s_copy[31] &= 0x7f;
|
|
167
|
+
fe_frombytes_strict(h, s_copy);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
static void fe_tobytes(uint8_t s[32], const fe *f) {
|
|
171
|
+
assert_fe(f->v);
|
|
172
|
+
fiat_25519_to_bytes(s, f->v);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// h = 0
|
|
176
|
+
static void fe_0(fe *h) { OPENSSL_memset(h, 0, sizeof(fe)); }
|
|
177
|
+
|
|
178
|
+
static void fe_loose_0(fe_loose *h) { OPENSSL_memset(h, 0, sizeof(fe_loose)); }
|
|
179
|
+
|
|
180
|
+
// h = 1
|
|
181
|
+
static void fe_1(fe *h) {
|
|
182
|
+
OPENSSL_memset(h, 0, sizeof(fe));
|
|
183
|
+
h->v[0] = 1;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
static void fe_loose_1(fe_loose *h) {
|
|
187
|
+
OPENSSL_memset(h, 0, sizeof(fe_loose));
|
|
188
|
+
h->v[0] = 1;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// h = f + g
|
|
192
|
+
// Can overlap h with f or g.
|
|
193
|
+
static void fe_add(fe_loose *h, const fe *f, const fe *g) {
|
|
194
|
+
assert_fe(f->v);
|
|
195
|
+
assert_fe(g->v);
|
|
196
|
+
fiat_25519_add(h->v, f->v, g->v);
|
|
197
|
+
assert_fe_loose(h->v);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// h = f - g
|
|
201
|
+
// Can overlap h with f or g.
|
|
202
|
+
static void fe_sub(fe_loose *h, const fe *f, const fe *g) {
|
|
203
|
+
assert_fe(f->v);
|
|
204
|
+
assert_fe(g->v);
|
|
205
|
+
fiat_25519_sub(h->v, f->v, g->v);
|
|
206
|
+
assert_fe_loose(h->v);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
static void fe_carry(fe *h, const fe_loose *f) {
|
|
210
|
+
assert_fe_loose(f->v);
|
|
211
|
+
fiat_25519_carry(h->v, f->v);
|
|
212
|
+
assert_fe(h->v);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
static void fe_mul_impl(fe_limb_t out[FE_NUM_LIMBS],
|
|
216
|
+
const fe_limb_t in1[FE_NUM_LIMBS],
|
|
217
|
+
const fe_limb_t in2[FE_NUM_LIMBS]) {
|
|
218
|
+
assert_fe_loose(in1);
|
|
219
|
+
assert_fe_loose(in2);
|
|
220
|
+
fiat_25519_carry_mul(out, in1, in2);
|
|
221
|
+
assert_fe(out);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
static void fe_mul_ltt(fe_loose *h, const fe *f, const fe *g) {
|
|
225
|
+
fe_mul_impl(h->v, f->v, g->v);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
static void fe_mul_llt(fe_loose *h, const fe_loose *f, const fe *g) {
|
|
229
|
+
fe_mul_impl(h->v, f->v, g->v);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
static void fe_mul_ttt(fe *h, const fe *f, const fe *g) {
|
|
233
|
+
fe_mul_impl(h->v, f->v, g->v);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
static void fe_mul_tlt(fe *h, const fe_loose *f, const fe *g) {
|
|
237
|
+
fe_mul_impl(h->v, f->v, g->v);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
static void fe_mul_ttl(fe *h, const fe *f, const fe_loose *g) {
|
|
241
|
+
fe_mul_impl(h->v, f->v, g->v);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
static void fe_mul_tll(fe *h, const fe_loose *f, const fe_loose *g) {
|
|
245
|
+
fe_mul_impl(h->v, f->v, g->v);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
static void fe_sq_tl(fe *h, const fe_loose *f) {
|
|
249
|
+
assert_fe_loose(f->v);
|
|
250
|
+
fiat_25519_carry_square(h->v, f->v);
|
|
251
|
+
assert_fe(h->v);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
static void fe_sq_tt(fe *h, const fe *f) {
|
|
255
|
+
assert_fe_loose(f->v);
|
|
256
|
+
fiat_25519_carry_square(h->v, f->v);
|
|
257
|
+
assert_fe(h->v);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// Replace (f,g) with (g,f) if b == 1;
|
|
261
|
+
// replace (f,g) with (f,g) if b == 0.
|
|
262
|
+
//
|
|
263
|
+
// Preconditions: b in {0,1}.
|
|
264
|
+
static void fe_cswap(fe *f, fe *g, fe_limb_t b) {
|
|
265
|
+
b = 0 - b;
|
|
266
|
+
for (unsigned i = 0; i < FE_NUM_LIMBS; i++) {
|
|
267
|
+
fe_limb_t x = f->v[i] ^ g->v[i];
|
|
268
|
+
x &= b;
|
|
269
|
+
f->v[i] ^= x;
|
|
270
|
+
g->v[i] ^= x;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
static void fe_mul121666(fe *h, const fe_loose *f) {
|
|
275
|
+
assert_fe_loose(f->v);
|
|
276
|
+
fiat_25519_carry_scmul_121666(h->v, f->v);
|
|
277
|
+
assert_fe(h->v);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// h = -f
|
|
281
|
+
static void fe_neg(fe_loose *h, const fe *f) {
|
|
282
|
+
assert_fe(f->v);
|
|
283
|
+
fiat_25519_opp(h->v, f->v);
|
|
284
|
+
assert_fe_loose(h->v);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// Replace (f,g) with (g,g) if b == 1;
|
|
288
|
+
// replace (f,g) with (f,g) if b == 0.
|
|
289
|
+
//
|
|
290
|
+
// Preconditions: b in {0,1}.
|
|
291
|
+
static void fe_cmov(fe_loose *f, const fe_loose *g, fe_limb_t b) {
|
|
292
|
+
// Silence an unused function warning. `fiat_25519_selectznz` isn't quite the
|
|
293
|
+
// calling convention the rest of this code wants, so implement it by hand.
|
|
294
|
+
//
|
|
295
|
+
// TODO(davidben): Switch to fiat's calling convention, or ask fiat to emit a
|
|
296
|
+
// different one.
|
|
297
|
+
|
|
298
|
+
b = 0 - b;
|
|
299
|
+
for (unsigned i = 0; i < FE_NUM_LIMBS; i++) {
|
|
300
|
+
fe_limb_t x = f->v[i] ^ g->v[i];
|
|
301
|
+
x &= b;
|
|
302
|
+
f->v[i] ^= x;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// Replace (f,g) with (g,g) if b == 1;
|
|
307
|
+
// replace (f,g) with (f,g) if b == 0.
|
|
308
|
+
//
|
|
309
|
+
// Preconditions: b in {0,1}.
|
|
310
|
+
static void fe_cmov(fe *f, const fe *g, fe_limb_t b) {
|
|
311
|
+
b = 0 - b;
|
|
312
|
+
for (unsigned i = 0; i < FE_NUM_LIMBS; i++) {
|
|
313
|
+
fe_limb_t x = f->v[i] ^ g->v[i];
|
|
314
|
+
x &= b;
|
|
315
|
+
f->v[i] ^= x;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// h = f
|
|
320
|
+
static void fe_copy(fe *h, const fe *f) { OPENSSL_memmove(h, f, sizeof(fe)); }
|
|
321
|
+
|
|
322
|
+
static void fe_copy_lt(fe_loose *h, const fe *f) {
|
|
323
|
+
static_assert(sizeof(fe_loose) == sizeof(fe), "fe and fe_loose mismatch");
|
|
324
|
+
OPENSSL_memmove(h, f, sizeof(fe));
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
static void fe_loose_invert(fe *out, const fe_loose *z) {
|
|
328
|
+
fe t0;
|
|
329
|
+
fe t1;
|
|
330
|
+
fe t2;
|
|
331
|
+
fe t3;
|
|
332
|
+
int i;
|
|
333
|
+
|
|
334
|
+
fe_sq_tl(&t0, z);
|
|
335
|
+
fe_sq_tt(&t1, &t0);
|
|
336
|
+
for (i = 1; i < 2; ++i) {
|
|
337
|
+
fe_sq_tt(&t1, &t1);
|
|
338
|
+
}
|
|
339
|
+
fe_mul_tlt(&t1, z, &t1);
|
|
340
|
+
fe_mul_ttt(&t0, &t0, &t1);
|
|
341
|
+
fe_sq_tt(&t2, &t0);
|
|
342
|
+
fe_mul_ttt(&t1, &t1, &t2);
|
|
343
|
+
fe_sq_tt(&t2, &t1);
|
|
344
|
+
for (i = 1; i < 5; ++i) {
|
|
345
|
+
fe_sq_tt(&t2, &t2);
|
|
346
|
+
}
|
|
347
|
+
fe_mul_ttt(&t1, &t2, &t1);
|
|
348
|
+
fe_sq_tt(&t2, &t1);
|
|
349
|
+
for (i = 1; i < 10; ++i) {
|
|
350
|
+
fe_sq_tt(&t2, &t2);
|
|
351
|
+
}
|
|
352
|
+
fe_mul_ttt(&t2, &t2, &t1);
|
|
353
|
+
fe_sq_tt(&t3, &t2);
|
|
354
|
+
for (i = 1; i < 20; ++i) {
|
|
355
|
+
fe_sq_tt(&t3, &t3);
|
|
356
|
+
}
|
|
357
|
+
fe_mul_ttt(&t2, &t3, &t2);
|
|
358
|
+
fe_sq_tt(&t2, &t2);
|
|
359
|
+
for (i = 1; i < 10; ++i) {
|
|
360
|
+
fe_sq_tt(&t2, &t2);
|
|
361
|
+
}
|
|
362
|
+
fe_mul_ttt(&t1, &t2, &t1);
|
|
363
|
+
fe_sq_tt(&t2, &t1);
|
|
364
|
+
for (i = 1; i < 50; ++i) {
|
|
365
|
+
fe_sq_tt(&t2, &t2);
|
|
366
|
+
}
|
|
367
|
+
fe_mul_ttt(&t2, &t2, &t1);
|
|
368
|
+
fe_sq_tt(&t3, &t2);
|
|
369
|
+
for (i = 1; i < 100; ++i) {
|
|
370
|
+
fe_sq_tt(&t3, &t3);
|
|
371
|
+
}
|
|
372
|
+
fe_mul_ttt(&t2, &t3, &t2);
|
|
373
|
+
fe_sq_tt(&t2, &t2);
|
|
374
|
+
for (i = 1; i < 50; ++i) {
|
|
375
|
+
fe_sq_tt(&t2, &t2);
|
|
376
|
+
}
|
|
377
|
+
fe_mul_ttt(&t1, &t2, &t1);
|
|
378
|
+
fe_sq_tt(&t1, &t1);
|
|
379
|
+
for (i = 1; i < 5; ++i) {
|
|
380
|
+
fe_sq_tt(&t1, &t1);
|
|
381
|
+
}
|
|
382
|
+
fe_mul_ttt(out, &t1, &t0);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
static void fe_invert(fe *out, const fe *z) {
|
|
386
|
+
fe_loose l;
|
|
387
|
+
fe_copy_lt(&l, z);
|
|
388
|
+
fe_loose_invert(out, &l);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// return 0 if f == 0
|
|
392
|
+
// return 1 if f != 0
|
|
393
|
+
static int fe_isnonzero(const fe *f) {
|
|
394
|
+
uint8_t s[32];
|
|
395
|
+
fe_tobytes(s, f);
|
|
396
|
+
|
|
397
|
+
static const uint8_t zero[32] = {0};
|
|
398
|
+
return CRYPTO_memcmp(s, zero, sizeof(zero)) != 0;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// return 0 if f == 0
|
|
402
|
+
// return 1 if f != 0
|
|
403
|
+
static int fe_isnonzero(const fe_loose *f) {
|
|
404
|
+
fe tight;
|
|
405
|
+
fe_carry(&tight, f);
|
|
406
|
+
return fe_isnonzero(&tight);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// return 1 if f is in {1,3,5,...,q-2}
|
|
410
|
+
// return 0 if f is in {0,2,4,...,q-1}
|
|
411
|
+
static int fe_isnegative(const fe *f) {
|
|
412
|
+
uint8_t s[32];
|
|
413
|
+
fe_tobytes(s, f);
|
|
414
|
+
return s[0] & 1;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
static void fe_sq2_tt(fe *h, const fe *f) {
|
|
418
|
+
// h = f²
|
|
419
|
+
fe_sq_tt(h, f);
|
|
420
|
+
|
|
421
|
+
// h = h + h
|
|
422
|
+
fe_loose tmp;
|
|
423
|
+
fe_add(&tmp, h, h);
|
|
424
|
+
fe_carry(h, &tmp);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
static void fe_pow22523(fe *out, const fe *z) {
|
|
428
|
+
fe t0;
|
|
429
|
+
fe t1;
|
|
430
|
+
fe t2;
|
|
431
|
+
int i;
|
|
432
|
+
|
|
433
|
+
fe_sq_tt(&t0, z);
|
|
434
|
+
fe_sq_tt(&t1, &t0);
|
|
435
|
+
for (i = 1; i < 2; ++i) {
|
|
436
|
+
fe_sq_tt(&t1, &t1);
|
|
437
|
+
}
|
|
438
|
+
fe_mul_ttt(&t1, z, &t1);
|
|
439
|
+
fe_mul_ttt(&t0, &t0, &t1);
|
|
440
|
+
fe_sq_tt(&t0, &t0);
|
|
441
|
+
fe_mul_ttt(&t0, &t1, &t0);
|
|
442
|
+
fe_sq_tt(&t1, &t0);
|
|
443
|
+
for (i = 1; i < 5; ++i) {
|
|
444
|
+
fe_sq_tt(&t1, &t1);
|
|
445
|
+
}
|
|
446
|
+
fe_mul_ttt(&t0, &t1, &t0);
|
|
447
|
+
fe_sq_tt(&t1, &t0);
|
|
448
|
+
for (i = 1; i < 10; ++i) {
|
|
449
|
+
fe_sq_tt(&t1, &t1);
|
|
450
|
+
}
|
|
451
|
+
fe_mul_ttt(&t1, &t1, &t0);
|
|
452
|
+
fe_sq_tt(&t2, &t1);
|
|
453
|
+
for (i = 1; i < 20; ++i) {
|
|
454
|
+
fe_sq_tt(&t2, &t2);
|
|
455
|
+
}
|
|
456
|
+
fe_mul_ttt(&t1, &t2, &t1);
|
|
457
|
+
fe_sq_tt(&t1, &t1);
|
|
458
|
+
for (i = 1; i < 10; ++i) {
|
|
459
|
+
fe_sq_tt(&t1, &t1);
|
|
460
|
+
}
|
|
461
|
+
fe_mul_ttt(&t0, &t1, &t0);
|
|
462
|
+
fe_sq_tt(&t1, &t0);
|
|
463
|
+
for (i = 1; i < 50; ++i) {
|
|
464
|
+
fe_sq_tt(&t1, &t1);
|
|
465
|
+
}
|
|
466
|
+
fe_mul_ttt(&t1, &t1, &t0);
|
|
467
|
+
fe_sq_tt(&t2, &t1);
|
|
468
|
+
for (i = 1; i < 100; ++i) {
|
|
469
|
+
fe_sq_tt(&t2, &t2);
|
|
470
|
+
}
|
|
471
|
+
fe_mul_ttt(&t1, &t2, &t1);
|
|
472
|
+
fe_sq_tt(&t1, &t1);
|
|
473
|
+
for (i = 1; i < 50; ++i) {
|
|
474
|
+
fe_sq_tt(&t1, &t1);
|
|
475
|
+
}
|
|
476
|
+
fe_mul_ttt(&t0, &t1, &t0);
|
|
477
|
+
fe_sq_tt(&t0, &t0);
|
|
478
|
+
for (i = 1; i < 2; ++i) {
|
|
479
|
+
fe_sq_tt(&t0, &t0);
|
|
480
|
+
}
|
|
481
|
+
fe_mul_ttt(out, &t0, z);
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
// Group operations.
|
|
486
|
+
|
|
487
|
+
void bssl::x25519_ge_tobytes(uint8_t s[32], const ge_p2 *h) {
|
|
488
|
+
fe recip;
|
|
489
|
+
fe x;
|
|
490
|
+
fe y;
|
|
491
|
+
|
|
492
|
+
fe_invert(&recip, &h->Z);
|
|
493
|
+
fe_mul_ttt(&x, &h->X, &recip);
|
|
494
|
+
fe_mul_ttt(&y, &h->Y, &recip);
|
|
495
|
+
fe_tobytes(s, &y);
|
|
496
|
+
s[31] ^= fe_isnegative(&x) << 7;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
static void ge_p3_tobytes(uint8_t s[32], const ge_p3 *h) {
|
|
500
|
+
fe recip;
|
|
501
|
+
fe x;
|
|
502
|
+
fe y;
|
|
503
|
+
|
|
504
|
+
fe_invert(&recip, &h->Z);
|
|
505
|
+
fe_mul_ttt(&x, &h->X, &recip);
|
|
506
|
+
fe_mul_ttt(&y, &h->Y, &recip);
|
|
507
|
+
fe_tobytes(s, &y);
|
|
508
|
+
s[31] ^= fe_isnegative(&x) << 7;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
int bssl::x25519_ge_frombytes_vartime(ge_p3 *h, const uint8_t s[32]) {
|
|
512
|
+
fe u;
|
|
513
|
+
fe_loose v;
|
|
514
|
+
fe w;
|
|
515
|
+
fe vxx;
|
|
516
|
+
fe_loose check;
|
|
517
|
+
|
|
518
|
+
fe_frombytes(&h->Y, s);
|
|
519
|
+
fe_1(&h->Z);
|
|
520
|
+
fe_sq_tt(&w, &h->Y);
|
|
521
|
+
fe_mul_ttt(&vxx, &w, &d);
|
|
522
|
+
fe_sub(&v, &w, &h->Z); // u = y² - 1
|
|
523
|
+
fe_carry(&u, &v);
|
|
524
|
+
fe_add(&v, &vxx, &h->Z); // v = dy² + 1
|
|
525
|
+
|
|
526
|
+
fe_mul_ttl(&w, &u, &v); // w = u*v
|
|
527
|
+
fe_pow22523(&h->X, &w); // x = w^((q-5)/8)
|
|
528
|
+
fe_mul_ttt(&h->X, &h->X, &u); // x = u*w^((q-5)/8)
|
|
529
|
+
|
|
530
|
+
fe_sq_tt(&vxx, &h->X);
|
|
531
|
+
fe_mul_ttl(&vxx, &vxx, &v);
|
|
532
|
+
fe_sub(&check, &vxx, &u);
|
|
533
|
+
if (fe_isnonzero(&check)) {
|
|
534
|
+
fe_add(&check, &vxx, &u);
|
|
535
|
+
if (fe_isnonzero(&check)) {
|
|
536
|
+
return 0;
|
|
537
|
+
}
|
|
538
|
+
fe_mul_ttt(&h->X, &h->X, &sqrtm1);
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
if (fe_isnegative(&h->X) != (s[31] >> 7)) {
|
|
542
|
+
fe_loose t;
|
|
543
|
+
fe_neg(&t, &h->X);
|
|
544
|
+
fe_carry(&h->X, &t);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
fe_mul_ttt(&h->T, &h->X, &h->Y);
|
|
548
|
+
return 1;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
static void ge_p2_0(ge_p2 *h) {
|
|
552
|
+
fe_0(&h->X);
|
|
553
|
+
fe_1(&h->Y);
|
|
554
|
+
fe_1(&h->Z);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
static void ge_p3_0(ge_p3 *h) {
|
|
558
|
+
fe_0(&h->X);
|
|
559
|
+
fe_1(&h->Y);
|
|
560
|
+
fe_1(&h->Z);
|
|
561
|
+
fe_0(&h->T);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
static void ge_cached_0(ge_cached *h) {
|
|
565
|
+
fe_loose_1(&h->YplusX);
|
|
566
|
+
fe_loose_1(&h->YminusX);
|
|
567
|
+
fe_loose_1(&h->Z);
|
|
568
|
+
fe_loose_0(&h->T2d);
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
static void ge_precomp_0(ge_precomp *h) {
|
|
572
|
+
fe_loose_1(&h->yplusx);
|
|
573
|
+
fe_loose_1(&h->yminusx);
|
|
574
|
+
fe_loose_0(&h->xy2d);
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
// r = p
|
|
578
|
+
static void ge_p3_to_p2(ge_p2 *r, const ge_p3 *p) {
|
|
579
|
+
fe_copy(&r->X, &p->X);
|
|
580
|
+
fe_copy(&r->Y, &p->Y);
|
|
581
|
+
fe_copy(&r->Z, &p->Z);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
// r = p
|
|
585
|
+
void bssl::x25519_ge_p3_to_cached(ge_cached *r, const ge_p3 *p) {
|
|
586
|
+
fe_add(&r->YplusX, &p->Y, &p->X);
|
|
587
|
+
fe_sub(&r->YminusX, &p->Y, &p->X);
|
|
588
|
+
fe_copy_lt(&r->Z, &p->Z);
|
|
589
|
+
fe_mul_ltt(&r->T2d, &p->T, &d2);
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
// r = p
|
|
593
|
+
void bssl::x25519_ge_p1p1_to_p2(ge_p2 *r, const ge_p1p1 *p) {
|
|
594
|
+
fe_mul_tll(&r->X, &p->X, &p->T);
|
|
595
|
+
fe_mul_tll(&r->Y, &p->Y, &p->Z);
|
|
596
|
+
fe_mul_tll(&r->Z, &p->Z, &p->T);
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
// r = p
|
|
600
|
+
void bssl::x25519_ge_p1p1_to_p3(ge_p3 *r, const ge_p1p1 *p) {
|
|
601
|
+
fe_mul_tll(&r->X, &p->X, &p->T);
|
|
602
|
+
fe_mul_tll(&r->Y, &p->Y, &p->Z);
|
|
603
|
+
fe_mul_tll(&r->Z, &p->Z, &p->T);
|
|
604
|
+
fe_mul_tll(&r->T, &p->X, &p->Y);
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
// r = p
|
|
608
|
+
static void ge_p1p1_to_cached(ge_cached *r, const ge_p1p1 *p) {
|
|
609
|
+
ge_p3 t;
|
|
610
|
+
x25519_ge_p1p1_to_p3(&t, p);
|
|
611
|
+
x25519_ge_p3_to_cached(r, &t);
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
// r = 2 * p
|
|
615
|
+
static void ge_p2_dbl(ge_p1p1 *r, const ge_p2 *p) {
|
|
616
|
+
fe trX, trZ, trT;
|
|
617
|
+
fe t0;
|
|
618
|
+
|
|
619
|
+
fe_sq_tt(&trX, &p->X);
|
|
620
|
+
fe_sq_tt(&trZ, &p->Y);
|
|
621
|
+
fe_sq2_tt(&trT, &p->Z);
|
|
622
|
+
fe_add(&r->Y, &p->X, &p->Y);
|
|
623
|
+
fe_sq_tl(&t0, &r->Y);
|
|
624
|
+
|
|
625
|
+
fe_add(&r->Y, &trZ, &trX);
|
|
626
|
+
fe_sub(&r->Z, &trZ, &trX);
|
|
627
|
+
fe_carry(&trZ, &r->Y);
|
|
628
|
+
fe_sub(&r->X, &t0, &trZ);
|
|
629
|
+
fe_carry(&trZ, &r->Z);
|
|
630
|
+
fe_sub(&r->T, &trT, &trZ);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
// r = 2 * p
|
|
634
|
+
static void ge_p3_dbl(ge_p1p1 *r, const ge_p3 *p) {
|
|
635
|
+
ge_p2 q;
|
|
636
|
+
ge_p3_to_p2(&q, p);
|
|
637
|
+
ge_p2_dbl(r, &q);
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
// r = p + q
|
|
641
|
+
static void ge_madd(ge_p1p1 *r, const ge_p3 *p, const ge_precomp *q) {
|
|
642
|
+
fe trY, trZ, trT;
|
|
643
|
+
|
|
644
|
+
fe_add(&r->X, &p->Y, &p->X);
|
|
645
|
+
fe_sub(&r->Y, &p->Y, &p->X);
|
|
646
|
+
fe_mul_tll(&trZ, &r->X, &q->yplusx);
|
|
647
|
+
fe_mul_tll(&trY, &r->Y, &q->yminusx);
|
|
648
|
+
fe_mul_tlt(&trT, &q->xy2d, &p->T);
|
|
649
|
+
fe_add(&r->T, &p->Z, &p->Z);
|
|
650
|
+
fe_sub(&r->X, &trZ, &trY);
|
|
651
|
+
fe_add(&r->Y, &trZ, &trY);
|
|
652
|
+
fe_carry(&trZ, &r->T);
|
|
653
|
+
fe_add(&r->Z, &trZ, &trT);
|
|
654
|
+
fe_sub(&r->T, &trZ, &trT);
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
// r = p - q
|
|
658
|
+
static void ge_msub(ge_p1p1 *r, const ge_p3 *p, const ge_precomp *q) {
|
|
659
|
+
fe trY, trZ, trT;
|
|
660
|
+
|
|
661
|
+
fe_add(&r->X, &p->Y, &p->X);
|
|
662
|
+
fe_sub(&r->Y, &p->Y, &p->X);
|
|
663
|
+
fe_mul_tll(&trZ, &r->X, &q->yminusx);
|
|
664
|
+
fe_mul_tll(&trY, &r->Y, &q->yplusx);
|
|
665
|
+
fe_mul_tlt(&trT, &q->xy2d, &p->T);
|
|
666
|
+
fe_add(&r->T, &p->Z, &p->Z);
|
|
667
|
+
fe_sub(&r->X, &trZ, &trY);
|
|
668
|
+
fe_add(&r->Y, &trZ, &trY);
|
|
669
|
+
fe_carry(&trZ, &r->T);
|
|
670
|
+
fe_sub(&r->Z, &trZ, &trT);
|
|
671
|
+
fe_add(&r->T, &trZ, &trT);
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
// r = p + q
|
|
675
|
+
void bssl::x25519_ge_add(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q) {
|
|
676
|
+
fe trX, trY, trZ, trT;
|
|
677
|
+
|
|
678
|
+
fe_add(&r->X, &p->Y, &p->X);
|
|
679
|
+
fe_sub(&r->Y, &p->Y, &p->X);
|
|
680
|
+
fe_mul_tll(&trZ, &r->X, &q->YplusX);
|
|
681
|
+
fe_mul_tll(&trY, &r->Y, &q->YminusX);
|
|
682
|
+
fe_mul_tlt(&trT, &q->T2d, &p->T);
|
|
683
|
+
fe_mul_ttl(&trX, &p->Z, &q->Z);
|
|
684
|
+
fe_add(&r->T, &trX, &trX);
|
|
685
|
+
fe_sub(&r->X, &trZ, &trY);
|
|
686
|
+
fe_add(&r->Y, &trZ, &trY);
|
|
687
|
+
fe_carry(&trZ, &r->T);
|
|
688
|
+
fe_add(&r->Z, &trZ, &trT);
|
|
689
|
+
fe_sub(&r->T, &trZ, &trT);
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
// r = p - q
|
|
693
|
+
void bssl::x25519_ge_sub(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q) {
|
|
694
|
+
fe trX, trY, trZ, trT;
|
|
695
|
+
|
|
696
|
+
fe_add(&r->X, &p->Y, &p->X);
|
|
697
|
+
fe_sub(&r->Y, &p->Y, &p->X);
|
|
698
|
+
fe_mul_tll(&trZ, &r->X, &q->YminusX);
|
|
699
|
+
fe_mul_tll(&trY, &r->Y, &q->YplusX);
|
|
700
|
+
fe_mul_tlt(&trT, &q->T2d, &p->T);
|
|
701
|
+
fe_mul_ttl(&trX, &p->Z, &q->Z);
|
|
702
|
+
fe_add(&r->T, &trX, &trX);
|
|
703
|
+
fe_sub(&r->X, &trZ, &trY);
|
|
704
|
+
fe_add(&r->Y, &trZ, &trY);
|
|
705
|
+
fe_carry(&trZ, &r->T);
|
|
706
|
+
fe_sub(&r->Z, &trZ, &trT);
|
|
707
|
+
fe_add(&r->T, &trZ, &trT);
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
static void cmov(ge_precomp *t, const ge_precomp *u, uint8_t b) {
|
|
711
|
+
fe_cmov(&t->yplusx, &u->yplusx, b);
|
|
712
|
+
fe_cmov(&t->yminusx, &u->yminusx, b);
|
|
713
|
+
fe_cmov(&t->xy2d, &u->xy2d, b);
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
void bssl::x25519_ge_scalarmult_small_precomp(
|
|
717
|
+
ge_p3 *h, const uint8_t a[32], const uint8_t precomp_table[15 * 2 * 32]) {
|
|
718
|
+
// precomp_table is first expanded into matching `ge_precomp`
|
|
719
|
+
// elements.
|
|
720
|
+
ge_precomp multiples[15];
|
|
721
|
+
|
|
722
|
+
unsigned i;
|
|
723
|
+
for (i = 0; i < 15; i++) {
|
|
724
|
+
// The precomputed table is assumed to already clear the top bit, so
|
|
725
|
+
// `fe_frombytes_strict` may be used directly.
|
|
726
|
+
const uint8_t *bytes = &precomp_table[i * (2 * 32)];
|
|
727
|
+
fe x, y;
|
|
728
|
+
fe_frombytes_strict(&x, bytes);
|
|
729
|
+
fe_frombytes_strict(&y, bytes + 32);
|
|
730
|
+
|
|
731
|
+
ge_precomp *out = &multiples[i];
|
|
732
|
+
fe_add(&out->yplusx, &y, &x);
|
|
733
|
+
fe_sub(&out->yminusx, &y, &x);
|
|
734
|
+
fe_mul_ltt(&out->xy2d, &x, &y);
|
|
735
|
+
fe_mul_llt(&out->xy2d, &out->xy2d, &d2);
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
// See the comment above `k25519SmallPrecomp` about the structure of the
|
|
739
|
+
// precomputed elements. This loop does 64 additions and 64 doublings to
|
|
740
|
+
// calculate the result.
|
|
741
|
+
ge_p3_0(h);
|
|
742
|
+
|
|
743
|
+
for (i = 63; i < 64; i--) {
|
|
744
|
+
unsigned j;
|
|
745
|
+
signed char index = 0;
|
|
746
|
+
|
|
747
|
+
for (j = 0; j < 4; j++) {
|
|
748
|
+
const uint8_t bit = 1 & (a[(8 * j) + (i / 8)] >> (i & 7));
|
|
749
|
+
index |= (bit << j);
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
ge_precomp e;
|
|
753
|
+
ge_precomp_0(&e);
|
|
754
|
+
|
|
755
|
+
for (j = 1; j < 16; j++) {
|
|
756
|
+
cmov(&e, &multiples[j - 1], 1 & constant_time_eq_w(index, j));
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
ge_cached cached;
|
|
760
|
+
ge_p1p1 r;
|
|
761
|
+
x25519_ge_p3_to_cached(&cached, h);
|
|
762
|
+
x25519_ge_add(&r, h, &cached);
|
|
763
|
+
x25519_ge_p1p1_to_p3(h, &r);
|
|
764
|
+
|
|
765
|
+
ge_madd(&r, h, &e);
|
|
766
|
+
x25519_ge_p1p1_to_p3(h, &r);
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
#if defined(OPENSSL_SMALL)
|
|
771
|
+
|
|
772
|
+
void bssl::x25519_ge_scalarmult_base(ge_p3 *h, const uint8_t a[32]) {
|
|
773
|
+
x25519_ge_scalarmult_small_precomp(h, a, k25519SmallPrecomp);
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
#else
|
|
777
|
+
|
|
778
|
+
static void table_select(ge_precomp *t, const int pos, const signed char b) {
|
|
779
|
+
uint8_t bnegative = constant_time_msb_w(b);
|
|
780
|
+
uint8_t babs = b - ((bnegative & b) << 1);
|
|
781
|
+
|
|
782
|
+
uint8_t t_bytes[3][32] = {
|
|
783
|
+
{static_cast<uint8_t>(constant_time_is_zero_w(b) & 1)},
|
|
784
|
+
{static_cast<uint8_t>(constant_time_is_zero_w(b) & 1)},
|
|
785
|
+
{0}};
|
|
786
|
+
#if defined(__clang__) // materialize for vectorization, 6% speedup
|
|
787
|
+
__asm__("" : "+m"(t_bytes) : /*no inputs*/);
|
|
788
|
+
#endif
|
|
789
|
+
static_assert(sizeof(t_bytes) == sizeof(k25519Precomp[pos][0]));
|
|
790
|
+
for (int i = 0; i < 8; i++) {
|
|
791
|
+
constant_time_conditional_memxor(t_bytes, k25519Precomp[pos][i],
|
|
792
|
+
sizeof(t_bytes),
|
|
793
|
+
constant_time_eq_w(babs, 1 + i));
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
fe yplusx, yminusx, xy2d;
|
|
797
|
+
fe_frombytes_strict(&yplusx, t_bytes[0]);
|
|
798
|
+
fe_frombytes_strict(&yminusx, t_bytes[1]);
|
|
799
|
+
fe_frombytes_strict(&xy2d, t_bytes[2]);
|
|
800
|
+
|
|
801
|
+
fe_copy_lt(&t->yplusx, &yplusx);
|
|
802
|
+
fe_copy_lt(&t->yminusx, &yminusx);
|
|
803
|
+
fe_copy_lt(&t->xy2d, &xy2d);
|
|
804
|
+
|
|
805
|
+
ge_precomp minust;
|
|
806
|
+
fe_copy_lt(&minust.yplusx, &yminusx);
|
|
807
|
+
fe_copy_lt(&minust.yminusx, &yplusx);
|
|
808
|
+
fe_neg(&minust.xy2d, &xy2d);
|
|
809
|
+
cmov(t, &minust, bnegative >> 7);
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
// h = a * B
|
|
813
|
+
// where a = a[0]+256*a[1]+...+256^31 a[31]
|
|
814
|
+
// B is the Ed25519 base point (x,4/5) with x positive.
|
|
815
|
+
//
|
|
816
|
+
// Preconditions:
|
|
817
|
+
// a[31] <= 127
|
|
818
|
+
void bssl::x25519_ge_scalarmult_base(ge_p3 *h, const uint8_t a[32]) {
|
|
819
|
+
#if defined(BORINGSSL_FE25519_ADX)
|
|
820
|
+
if (CRYPTO_is_BMI1_capable() && CRYPTO_is_BMI2_capable() &&
|
|
821
|
+
CRYPTO_is_ADX_capable()) {
|
|
822
|
+
uint8_t t[4][32];
|
|
823
|
+
x25519_ge_scalarmult_base_adx(t, a);
|
|
824
|
+
fiat_25519_from_bytes(h->X.v, t[0]);
|
|
825
|
+
fiat_25519_from_bytes(h->Y.v, t[1]);
|
|
826
|
+
fiat_25519_from_bytes(h->Z.v, t[2]);
|
|
827
|
+
fiat_25519_from_bytes(h->T.v, t[3]);
|
|
828
|
+
return;
|
|
829
|
+
}
|
|
830
|
+
#endif
|
|
831
|
+
signed char e[64];
|
|
832
|
+
signed char carry;
|
|
833
|
+
ge_p1p1 r;
|
|
834
|
+
ge_p2 s;
|
|
835
|
+
ge_precomp t;
|
|
836
|
+
int i;
|
|
837
|
+
|
|
838
|
+
for (i = 0; i < 32; ++i) {
|
|
839
|
+
e[2 * i + 0] = (a[i] >> 0) & 15;
|
|
840
|
+
e[2 * i + 1] = (a[i] >> 4) & 15;
|
|
841
|
+
}
|
|
842
|
+
// each e[i] is between 0 and 15
|
|
843
|
+
// e[63] is between 0 and 7
|
|
844
|
+
|
|
845
|
+
carry = 0;
|
|
846
|
+
for (i = 0; i < 63; ++i) {
|
|
847
|
+
e[i] += carry;
|
|
848
|
+
carry = e[i] + 8;
|
|
849
|
+
carry >>= 4;
|
|
850
|
+
e[i] -= carry << 4;
|
|
851
|
+
}
|
|
852
|
+
e[63] += carry;
|
|
853
|
+
// each e[i] is between -8 and 8
|
|
854
|
+
|
|
855
|
+
ge_p3_0(h);
|
|
856
|
+
for (i = 1; i < 64; i += 2) {
|
|
857
|
+
table_select(&t, i / 2, e[i]);
|
|
858
|
+
ge_madd(&r, h, &t);
|
|
859
|
+
x25519_ge_p1p1_to_p3(h, &r);
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
ge_p3_dbl(&r, h);
|
|
863
|
+
x25519_ge_p1p1_to_p2(&s, &r);
|
|
864
|
+
ge_p2_dbl(&r, &s);
|
|
865
|
+
x25519_ge_p1p1_to_p2(&s, &r);
|
|
866
|
+
ge_p2_dbl(&r, &s);
|
|
867
|
+
x25519_ge_p1p1_to_p2(&s, &r);
|
|
868
|
+
ge_p2_dbl(&r, &s);
|
|
869
|
+
x25519_ge_p1p1_to_p3(h, &r);
|
|
870
|
+
|
|
871
|
+
for (i = 0; i < 64; i += 2) {
|
|
872
|
+
table_select(&t, i / 2, e[i]);
|
|
873
|
+
ge_madd(&r, h, &t);
|
|
874
|
+
x25519_ge_p1p1_to_p3(h, &r);
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
#endif
|
|
879
|
+
|
|
880
|
+
static void cmov_cached(ge_cached *t, ge_cached *u, uint8_t b) {
|
|
881
|
+
fe_cmov(&t->YplusX, &u->YplusX, b);
|
|
882
|
+
fe_cmov(&t->YminusX, &u->YminusX, b);
|
|
883
|
+
fe_cmov(&t->Z, &u->Z, b);
|
|
884
|
+
fe_cmov(&t->T2d, &u->T2d, b);
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
// r = scalar * A.
|
|
888
|
+
// where a = a[0]+256*a[1]+...+256^31 a[31].
|
|
889
|
+
void bssl::x25519_ge_scalarmult(ge_p2 *r, const uint8_t *scalar,
|
|
890
|
+
const ge_p3 *A) {
|
|
891
|
+
ge_p2 Ai_p2[8];
|
|
892
|
+
ge_cached Ai[16];
|
|
893
|
+
ge_p1p1 t;
|
|
894
|
+
|
|
895
|
+
ge_cached_0(&Ai[0]);
|
|
896
|
+
x25519_ge_p3_to_cached(&Ai[1], A);
|
|
897
|
+
ge_p3_to_p2(&Ai_p2[1], A);
|
|
898
|
+
|
|
899
|
+
unsigned i;
|
|
900
|
+
for (i = 2; i < 16; i += 2) {
|
|
901
|
+
ge_p2_dbl(&t, &Ai_p2[i / 2]);
|
|
902
|
+
ge_p1p1_to_cached(&Ai[i], &t);
|
|
903
|
+
if (i < 8) {
|
|
904
|
+
x25519_ge_p1p1_to_p2(&Ai_p2[i], &t);
|
|
905
|
+
}
|
|
906
|
+
x25519_ge_add(&t, A, &Ai[i]);
|
|
907
|
+
ge_p1p1_to_cached(&Ai[i + 1], &t);
|
|
908
|
+
if (i < 7) {
|
|
909
|
+
x25519_ge_p1p1_to_p2(&Ai_p2[i + 1], &t);
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
ge_p2_0(r);
|
|
914
|
+
ge_p3 u;
|
|
915
|
+
|
|
916
|
+
for (i = 0; i < 256; i += 4) {
|
|
917
|
+
ge_p2_dbl(&t, r);
|
|
918
|
+
x25519_ge_p1p1_to_p2(r, &t);
|
|
919
|
+
ge_p2_dbl(&t, r);
|
|
920
|
+
x25519_ge_p1p1_to_p2(r, &t);
|
|
921
|
+
ge_p2_dbl(&t, r);
|
|
922
|
+
x25519_ge_p1p1_to_p2(r, &t);
|
|
923
|
+
ge_p2_dbl(&t, r);
|
|
924
|
+
x25519_ge_p1p1_to_p3(&u, &t);
|
|
925
|
+
|
|
926
|
+
uint8_t index = scalar[31 - i / 8];
|
|
927
|
+
index >>= 4 - (i & 4);
|
|
928
|
+
index &= 0xf;
|
|
929
|
+
|
|
930
|
+
unsigned j;
|
|
931
|
+
ge_cached selected;
|
|
932
|
+
ge_cached_0(&selected);
|
|
933
|
+
for (j = 0; j < 16; j++) {
|
|
934
|
+
cmov_cached(&selected, &Ai[j], 1 & constant_time_eq_w(index, j));
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
x25519_ge_add(&t, &u, &selected);
|
|
938
|
+
x25519_ge_p1p1_to_p2(r, &t);
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
static void slide(signed char *r, const uint8_t *a) {
|
|
943
|
+
int i;
|
|
944
|
+
int b;
|
|
945
|
+
int k;
|
|
946
|
+
|
|
947
|
+
for (i = 0; i < 256; ++i) {
|
|
948
|
+
r[i] = 1 & (a[i >> 3] >> (i & 7));
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
for (i = 0; i < 256; ++i) {
|
|
952
|
+
if (r[i]) {
|
|
953
|
+
for (b = 1; b <= 6 && i + b < 256; ++b) {
|
|
954
|
+
if (r[i + b]) {
|
|
955
|
+
if (r[i] + (r[i + b] << b) <= 15) {
|
|
956
|
+
r[i] += r[i + b] << b;
|
|
957
|
+
r[i + b] = 0;
|
|
958
|
+
} else if (r[i] - (r[i + b] << b) >= -15) {
|
|
959
|
+
r[i] -= r[i + b] << b;
|
|
960
|
+
for (k = i + b; k < 256; ++k) {
|
|
961
|
+
if (!r[k]) {
|
|
962
|
+
r[k] = 1;
|
|
963
|
+
break;
|
|
964
|
+
}
|
|
965
|
+
r[k] = 0;
|
|
966
|
+
}
|
|
967
|
+
} else {
|
|
968
|
+
break;
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
// r = a * A + b * B
|
|
977
|
+
// where a = a[0]+256*a[1]+...+256^31 a[31].
|
|
978
|
+
// and b = b[0]+256*b[1]+...+256^31 b[31].
|
|
979
|
+
// B is the Ed25519 base point (x,4/5) with x positive.
|
|
980
|
+
static void ge_double_scalarmult_vartime(ge_p2 *r, const uint8_t *a,
|
|
981
|
+
const ge_p3 *A, const uint8_t *b) {
|
|
982
|
+
signed char aslide[256];
|
|
983
|
+
signed char bslide[256];
|
|
984
|
+
ge_cached Ai[8]; // A,3A,5A,7A,9A,11A,13A,15A
|
|
985
|
+
ge_p1p1 t;
|
|
986
|
+
ge_p3 u;
|
|
987
|
+
ge_p3 A2;
|
|
988
|
+
int i;
|
|
989
|
+
|
|
990
|
+
slide(aslide, a);
|
|
991
|
+
slide(bslide, b);
|
|
992
|
+
|
|
993
|
+
x25519_ge_p3_to_cached(&Ai[0], A);
|
|
994
|
+
ge_p3_dbl(&t, A);
|
|
995
|
+
x25519_ge_p1p1_to_p3(&A2, &t);
|
|
996
|
+
x25519_ge_add(&t, &A2, &Ai[0]);
|
|
997
|
+
x25519_ge_p1p1_to_p3(&u, &t);
|
|
998
|
+
x25519_ge_p3_to_cached(&Ai[1], &u);
|
|
999
|
+
x25519_ge_add(&t, &A2, &Ai[1]);
|
|
1000
|
+
x25519_ge_p1p1_to_p3(&u, &t);
|
|
1001
|
+
x25519_ge_p3_to_cached(&Ai[2], &u);
|
|
1002
|
+
x25519_ge_add(&t, &A2, &Ai[2]);
|
|
1003
|
+
x25519_ge_p1p1_to_p3(&u, &t);
|
|
1004
|
+
x25519_ge_p3_to_cached(&Ai[3], &u);
|
|
1005
|
+
x25519_ge_add(&t, &A2, &Ai[3]);
|
|
1006
|
+
x25519_ge_p1p1_to_p3(&u, &t);
|
|
1007
|
+
x25519_ge_p3_to_cached(&Ai[4], &u);
|
|
1008
|
+
x25519_ge_add(&t, &A2, &Ai[4]);
|
|
1009
|
+
x25519_ge_p1p1_to_p3(&u, &t);
|
|
1010
|
+
x25519_ge_p3_to_cached(&Ai[5], &u);
|
|
1011
|
+
x25519_ge_add(&t, &A2, &Ai[5]);
|
|
1012
|
+
x25519_ge_p1p1_to_p3(&u, &t);
|
|
1013
|
+
x25519_ge_p3_to_cached(&Ai[6], &u);
|
|
1014
|
+
x25519_ge_add(&t, &A2, &Ai[6]);
|
|
1015
|
+
x25519_ge_p1p1_to_p3(&u, &t);
|
|
1016
|
+
x25519_ge_p3_to_cached(&Ai[7], &u);
|
|
1017
|
+
|
|
1018
|
+
ge_p2_0(r);
|
|
1019
|
+
|
|
1020
|
+
for (i = 255; i >= 0; --i) {
|
|
1021
|
+
if (aslide[i] || bslide[i]) {
|
|
1022
|
+
break;
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
for (; i >= 0; --i) {
|
|
1027
|
+
ge_p2_dbl(&t, r);
|
|
1028
|
+
|
|
1029
|
+
if (aslide[i] > 0) {
|
|
1030
|
+
x25519_ge_p1p1_to_p3(&u, &t);
|
|
1031
|
+
x25519_ge_add(&t, &u, &Ai[aslide[i] / 2]);
|
|
1032
|
+
} else if (aslide[i] < 0) {
|
|
1033
|
+
x25519_ge_p1p1_to_p3(&u, &t);
|
|
1034
|
+
x25519_ge_sub(&t, &u, &Ai[(-aslide[i]) / 2]);
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
if (bslide[i] > 0) {
|
|
1038
|
+
x25519_ge_p1p1_to_p3(&u, &t);
|
|
1039
|
+
ge_madd(&t, &u, &Bi[bslide[i] / 2]);
|
|
1040
|
+
} else if (bslide[i] < 0) {
|
|
1041
|
+
x25519_ge_p1p1_to_p3(&u, &t);
|
|
1042
|
+
ge_msub(&t, &u, &Bi[(-bslide[i]) / 2]);
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
x25519_ge_p1p1_to_p2(r, &t);
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
// int64_lshift21 returns `a << 21` but is defined when shifting bits into the
|
|
1050
|
+
// sign bit. This works around a language flaw in C.
|
|
1051
|
+
static int64_t int64_lshift21(int64_t a) {
|
|
1052
|
+
return (int64_t)((uint64_t)a << 21);
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
// The set of scalars is \Z/l
|
|
1056
|
+
// where l = 2^252 + 27742317777372353535851937790883648493.
|
|
1057
|
+
|
|
1058
|
+
// Input:
|
|
1059
|
+
// s[0]+256*s[1]+...+256^63*s[63] = s
|
|
1060
|
+
//
|
|
1061
|
+
// Output:
|
|
1062
|
+
// s[0]+256*s[1]+...+256^31*s[31] = s mod l
|
|
1063
|
+
// where l = 2^252 + 27742317777372353535851937790883648493.
|
|
1064
|
+
// Overwrites s in place.
|
|
1065
|
+
void bssl::x25519_sc_reduce(uint8_t s[64]) {
|
|
1066
|
+
int64_t s0 = 2097151 & load_3(s);
|
|
1067
|
+
int64_t s1 = 2097151 & (load_4(s + 2) >> 5);
|
|
1068
|
+
int64_t s2 = 2097151 & (load_3(s + 5) >> 2);
|
|
1069
|
+
int64_t s3 = 2097151 & (load_4(s + 7) >> 7);
|
|
1070
|
+
int64_t s4 = 2097151 & (load_4(s + 10) >> 4);
|
|
1071
|
+
int64_t s5 = 2097151 & (load_3(s + 13) >> 1);
|
|
1072
|
+
int64_t s6 = 2097151 & (load_4(s + 15) >> 6);
|
|
1073
|
+
int64_t s7 = 2097151 & (load_3(s + 18) >> 3);
|
|
1074
|
+
int64_t s8 = 2097151 & load_3(s + 21);
|
|
1075
|
+
int64_t s9 = 2097151 & (load_4(s + 23) >> 5);
|
|
1076
|
+
int64_t s10 = 2097151 & (load_3(s + 26) >> 2);
|
|
1077
|
+
int64_t s11 = 2097151 & (load_4(s + 28) >> 7);
|
|
1078
|
+
int64_t s12 = 2097151 & (load_4(s + 31) >> 4);
|
|
1079
|
+
int64_t s13 = 2097151 & (load_3(s + 34) >> 1);
|
|
1080
|
+
int64_t s14 = 2097151 & (load_4(s + 36) >> 6);
|
|
1081
|
+
int64_t s15 = 2097151 & (load_3(s + 39) >> 3);
|
|
1082
|
+
int64_t s16 = 2097151 & load_3(s + 42);
|
|
1083
|
+
int64_t s17 = 2097151 & (load_4(s + 44) >> 5);
|
|
1084
|
+
int64_t s18 = 2097151 & (load_3(s + 47) >> 2);
|
|
1085
|
+
int64_t s19 = 2097151 & (load_4(s + 49) >> 7);
|
|
1086
|
+
int64_t s20 = 2097151 & (load_4(s + 52) >> 4);
|
|
1087
|
+
int64_t s21 = 2097151 & (load_3(s + 55) >> 1);
|
|
1088
|
+
int64_t s22 = 2097151 & (load_4(s + 57) >> 6);
|
|
1089
|
+
int64_t s23 = (load_4(s + 60) >> 3);
|
|
1090
|
+
int64_t carry0;
|
|
1091
|
+
int64_t carry1;
|
|
1092
|
+
int64_t carry2;
|
|
1093
|
+
int64_t carry3;
|
|
1094
|
+
int64_t carry4;
|
|
1095
|
+
int64_t carry5;
|
|
1096
|
+
int64_t carry6;
|
|
1097
|
+
int64_t carry7;
|
|
1098
|
+
int64_t carry8;
|
|
1099
|
+
int64_t carry9;
|
|
1100
|
+
int64_t carry10;
|
|
1101
|
+
int64_t carry11;
|
|
1102
|
+
int64_t carry12;
|
|
1103
|
+
int64_t carry13;
|
|
1104
|
+
int64_t carry14;
|
|
1105
|
+
int64_t carry15;
|
|
1106
|
+
int64_t carry16;
|
|
1107
|
+
|
|
1108
|
+
s11 += s23 * 666643;
|
|
1109
|
+
s12 += s23 * 470296;
|
|
1110
|
+
s13 += s23 * 654183;
|
|
1111
|
+
s14 -= s23 * 997805;
|
|
1112
|
+
s15 += s23 * 136657;
|
|
1113
|
+
s16 -= s23 * 683901;
|
|
1114
|
+
s23 = 0;
|
|
1115
|
+
|
|
1116
|
+
s10 += s22 * 666643;
|
|
1117
|
+
s11 += s22 * 470296;
|
|
1118
|
+
s12 += s22 * 654183;
|
|
1119
|
+
s13 -= s22 * 997805;
|
|
1120
|
+
s14 += s22 * 136657;
|
|
1121
|
+
s15 -= s22 * 683901;
|
|
1122
|
+
s22 = 0;
|
|
1123
|
+
|
|
1124
|
+
s9 += s21 * 666643;
|
|
1125
|
+
s10 += s21 * 470296;
|
|
1126
|
+
s11 += s21 * 654183;
|
|
1127
|
+
s12 -= s21 * 997805;
|
|
1128
|
+
s13 += s21 * 136657;
|
|
1129
|
+
s14 -= s21 * 683901;
|
|
1130
|
+
s21 = 0;
|
|
1131
|
+
|
|
1132
|
+
s8 += s20 * 666643;
|
|
1133
|
+
s9 += s20 * 470296;
|
|
1134
|
+
s10 += s20 * 654183;
|
|
1135
|
+
s11 -= s20 * 997805;
|
|
1136
|
+
s12 += s20 * 136657;
|
|
1137
|
+
s13 -= s20 * 683901;
|
|
1138
|
+
s20 = 0;
|
|
1139
|
+
|
|
1140
|
+
s7 += s19 * 666643;
|
|
1141
|
+
s8 += s19 * 470296;
|
|
1142
|
+
s9 += s19 * 654183;
|
|
1143
|
+
s10 -= s19 * 997805;
|
|
1144
|
+
s11 += s19 * 136657;
|
|
1145
|
+
s12 -= s19 * 683901;
|
|
1146
|
+
s19 = 0;
|
|
1147
|
+
|
|
1148
|
+
s6 += s18 * 666643;
|
|
1149
|
+
s7 += s18 * 470296;
|
|
1150
|
+
s8 += s18 * 654183;
|
|
1151
|
+
s9 -= s18 * 997805;
|
|
1152
|
+
s10 += s18 * 136657;
|
|
1153
|
+
s11 -= s18 * 683901;
|
|
1154
|
+
s18 = 0;
|
|
1155
|
+
|
|
1156
|
+
carry6 = (s6 + (1 << 20)) >> 21;
|
|
1157
|
+
s7 += carry6;
|
|
1158
|
+
s6 -= int64_lshift21(carry6);
|
|
1159
|
+
carry8 = (s8 + (1 << 20)) >> 21;
|
|
1160
|
+
s9 += carry8;
|
|
1161
|
+
s8 -= int64_lshift21(carry8);
|
|
1162
|
+
carry10 = (s10 + (1 << 20)) >> 21;
|
|
1163
|
+
s11 += carry10;
|
|
1164
|
+
s10 -= int64_lshift21(carry10);
|
|
1165
|
+
carry12 = (s12 + (1 << 20)) >> 21;
|
|
1166
|
+
s13 += carry12;
|
|
1167
|
+
s12 -= int64_lshift21(carry12);
|
|
1168
|
+
carry14 = (s14 + (1 << 20)) >> 21;
|
|
1169
|
+
s15 += carry14;
|
|
1170
|
+
s14 -= int64_lshift21(carry14);
|
|
1171
|
+
carry16 = (s16 + (1 << 20)) >> 21;
|
|
1172
|
+
s17 += carry16;
|
|
1173
|
+
s16 -= int64_lshift21(carry16);
|
|
1174
|
+
|
|
1175
|
+
carry7 = (s7 + (1 << 20)) >> 21;
|
|
1176
|
+
s8 += carry7;
|
|
1177
|
+
s7 -= int64_lshift21(carry7);
|
|
1178
|
+
carry9 = (s9 + (1 << 20)) >> 21;
|
|
1179
|
+
s10 += carry9;
|
|
1180
|
+
s9 -= int64_lshift21(carry9);
|
|
1181
|
+
carry11 = (s11 + (1 << 20)) >> 21;
|
|
1182
|
+
s12 += carry11;
|
|
1183
|
+
s11 -= int64_lshift21(carry11);
|
|
1184
|
+
carry13 = (s13 + (1 << 20)) >> 21;
|
|
1185
|
+
s14 += carry13;
|
|
1186
|
+
s13 -= int64_lshift21(carry13);
|
|
1187
|
+
carry15 = (s15 + (1 << 20)) >> 21;
|
|
1188
|
+
s16 += carry15;
|
|
1189
|
+
s15 -= int64_lshift21(carry15);
|
|
1190
|
+
|
|
1191
|
+
s5 += s17 * 666643;
|
|
1192
|
+
s6 += s17 * 470296;
|
|
1193
|
+
s7 += s17 * 654183;
|
|
1194
|
+
s8 -= s17 * 997805;
|
|
1195
|
+
s9 += s17 * 136657;
|
|
1196
|
+
s10 -= s17 * 683901;
|
|
1197
|
+
s17 = 0;
|
|
1198
|
+
|
|
1199
|
+
s4 += s16 * 666643;
|
|
1200
|
+
s5 += s16 * 470296;
|
|
1201
|
+
s6 += s16 * 654183;
|
|
1202
|
+
s7 -= s16 * 997805;
|
|
1203
|
+
s8 += s16 * 136657;
|
|
1204
|
+
s9 -= s16 * 683901;
|
|
1205
|
+
s16 = 0;
|
|
1206
|
+
|
|
1207
|
+
s3 += s15 * 666643;
|
|
1208
|
+
s4 += s15 * 470296;
|
|
1209
|
+
s5 += s15 * 654183;
|
|
1210
|
+
s6 -= s15 * 997805;
|
|
1211
|
+
s7 += s15 * 136657;
|
|
1212
|
+
s8 -= s15 * 683901;
|
|
1213
|
+
s15 = 0;
|
|
1214
|
+
|
|
1215
|
+
s2 += s14 * 666643;
|
|
1216
|
+
s3 += s14 * 470296;
|
|
1217
|
+
s4 += s14 * 654183;
|
|
1218
|
+
s5 -= s14 * 997805;
|
|
1219
|
+
s6 += s14 * 136657;
|
|
1220
|
+
s7 -= s14 * 683901;
|
|
1221
|
+
s14 = 0;
|
|
1222
|
+
|
|
1223
|
+
s1 += s13 * 666643;
|
|
1224
|
+
s2 += s13 * 470296;
|
|
1225
|
+
s3 += s13 * 654183;
|
|
1226
|
+
s4 -= s13 * 997805;
|
|
1227
|
+
s5 += s13 * 136657;
|
|
1228
|
+
s6 -= s13 * 683901;
|
|
1229
|
+
s13 = 0;
|
|
1230
|
+
|
|
1231
|
+
s0 += s12 * 666643;
|
|
1232
|
+
s1 += s12 * 470296;
|
|
1233
|
+
s2 += s12 * 654183;
|
|
1234
|
+
s3 -= s12 * 997805;
|
|
1235
|
+
s4 += s12 * 136657;
|
|
1236
|
+
s5 -= s12 * 683901;
|
|
1237
|
+
s12 = 0;
|
|
1238
|
+
|
|
1239
|
+
carry0 = (s0 + (1 << 20)) >> 21;
|
|
1240
|
+
s1 += carry0;
|
|
1241
|
+
s0 -= int64_lshift21(carry0);
|
|
1242
|
+
carry2 = (s2 + (1 << 20)) >> 21;
|
|
1243
|
+
s3 += carry2;
|
|
1244
|
+
s2 -= int64_lshift21(carry2);
|
|
1245
|
+
carry4 = (s4 + (1 << 20)) >> 21;
|
|
1246
|
+
s5 += carry4;
|
|
1247
|
+
s4 -= int64_lshift21(carry4);
|
|
1248
|
+
carry6 = (s6 + (1 << 20)) >> 21;
|
|
1249
|
+
s7 += carry6;
|
|
1250
|
+
s6 -= int64_lshift21(carry6);
|
|
1251
|
+
carry8 = (s8 + (1 << 20)) >> 21;
|
|
1252
|
+
s9 += carry8;
|
|
1253
|
+
s8 -= int64_lshift21(carry8);
|
|
1254
|
+
carry10 = (s10 + (1 << 20)) >> 21;
|
|
1255
|
+
s11 += carry10;
|
|
1256
|
+
s10 -= int64_lshift21(carry10);
|
|
1257
|
+
|
|
1258
|
+
carry1 = (s1 + (1 << 20)) >> 21;
|
|
1259
|
+
s2 += carry1;
|
|
1260
|
+
s1 -= int64_lshift21(carry1);
|
|
1261
|
+
carry3 = (s3 + (1 << 20)) >> 21;
|
|
1262
|
+
s4 += carry3;
|
|
1263
|
+
s3 -= int64_lshift21(carry3);
|
|
1264
|
+
carry5 = (s5 + (1 << 20)) >> 21;
|
|
1265
|
+
s6 += carry5;
|
|
1266
|
+
s5 -= int64_lshift21(carry5);
|
|
1267
|
+
carry7 = (s7 + (1 << 20)) >> 21;
|
|
1268
|
+
s8 += carry7;
|
|
1269
|
+
s7 -= int64_lshift21(carry7);
|
|
1270
|
+
carry9 = (s9 + (1 << 20)) >> 21;
|
|
1271
|
+
s10 += carry9;
|
|
1272
|
+
s9 -= int64_lshift21(carry9);
|
|
1273
|
+
carry11 = (s11 + (1 << 20)) >> 21;
|
|
1274
|
+
s12 += carry11;
|
|
1275
|
+
s11 -= int64_lshift21(carry11);
|
|
1276
|
+
|
|
1277
|
+
s0 += s12 * 666643;
|
|
1278
|
+
s1 += s12 * 470296;
|
|
1279
|
+
s2 += s12 * 654183;
|
|
1280
|
+
s3 -= s12 * 997805;
|
|
1281
|
+
s4 += s12 * 136657;
|
|
1282
|
+
s5 -= s12 * 683901;
|
|
1283
|
+
s12 = 0;
|
|
1284
|
+
|
|
1285
|
+
carry0 = s0 >> 21;
|
|
1286
|
+
s1 += carry0;
|
|
1287
|
+
s0 -= int64_lshift21(carry0);
|
|
1288
|
+
carry1 = s1 >> 21;
|
|
1289
|
+
s2 += carry1;
|
|
1290
|
+
s1 -= int64_lshift21(carry1);
|
|
1291
|
+
carry2 = s2 >> 21;
|
|
1292
|
+
s3 += carry2;
|
|
1293
|
+
s2 -= int64_lshift21(carry2);
|
|
1294
|
+
carry3 = s3 >> 21;
|
|
1295
|
+
s4 += carry3;
|
|
1296
|
+
s3 -= int64_lshift21(carry3);
|
|
1297
|
+
carry4 = s4 >> 21;
|
|
1298
|
+
s5 += carry4;
|
|
1299
|
+
s4 -= int64_lshift21(carry4);
|
|
1300
|
+
carry5 = s5 >> 21;
|
|
1301
|
+
s6 += carry5;
|
|
1302
|
+
s5 -= int64_lshift21(carry5);
|
|
1303
|
+
carry6 = s6 >> 21;
|
|
1304
|
+
s7 += carry6;
|
|
1305
|
+
s6 -= int64_lshift21(carry6);
|
|
1306
|
+
carry7 = s7 >> 21;
|
|
1307
|
+
s8 += carry7;
|
|
1308
|
+
s7 -= int64_lshift21(carry7);
|
|
1309
|
+
carry8 = s8 >> 21;
|
|
1310
|
+
s9 += carry8;
|
|
1311
|
+
s8 -= int64_lshift21(carry8);
|
|
1312
|
+
carry9 = s9 >> 21;
|
|
1313
|
+
s10 += carry9;
|
|
1314
|
+
s9 -= int64_lshift21(carry9);
|
|
1315
|
+
carry10 = s10 >> 21;
|
|
1316
|
+
s11 += carry10;
|
|
1317
|
+
s10 -= int64_lshift21(carry10);
|
|
1318
|
+
carry11 = s11 >> 21;
|
|
1319
|
+
s12 += carry11;
|
|
1320
|
+
s11 -= int64_lshift21(carry11);
|
|
1321
|
+
|
|
1322
|
+
s0 += s12 * 666643;
|
|
1323
|
+
s1 += s12 * 470296;
|
|
1324
|
+
s2 += s12 * 654183;
|
|
1325
|
+
s3 -= s12 * 997805;
|
|
1326
|
+
s4 += s12 * 136657;
|
|
1327
|
+
s5 -= s12 * 683901;
|
|
1328
|
+
s12 = 0;
|
|
1329
|
+
|
|
1330
|
+
carry0 = s0 >> 21;
|
|
1331
|
+
s1 += carry0;
|
|
1332
|
+
s0 -= int64_lshift21(carry0);
|
|
1333
|
+
carry1 = s1 >> 21;
|
|
1334
|
+
s2 += carry1;
|
|
1335
|
+
s1 -= int64_lshift21(carry1);
|
|
1336
|
+
carry2 = s2 >> 21;
|
|
1337
|
+
s3 += carry2;
|
|
1338
|
+
s2 -= int64_lshift21(carry2);
|
|
1339
|
+
carry3 = s3 >> 21;
|
|
1340
|
+
s4 += carry3;
|
|
1341
|
+
s3 -= int64_lshift21(carry3);
|
|
1342
|
+
carry4 = s4 >> 21;
|
|
1343
|
+
s5 += carry4;
|
|
1344
|
+
s4 -= int64_lshift21(carry4);
|
|
1345
|
+
carry5 = s5 >> 21;
|
|
1346
|
+
s6 += carry5;
|
|
1347
|
+
s5 -= int64_lshift21(carry5);
|
|
1348
|
+
carry6 = s6 >> 21;
|
|
1349
|
+
s7 += carry6;
|
|
1350
|
+
s6 -= int64_lshift21(carry6);
|
|
1351
|
+
carry7 = s7 >> 21;
|
|
1352
|
+
s8 += carry7;
|
|
1353
|
+
s7 -= int64_lshift21(carry7);
|
|
1354
|
+
carry8 = s8 >> 21;
|
|
1355
|
+
s9 += carry8;
|
|
1356
|
+
s8 -= int64_lshift21(carry8);
|
|
1357
|
+
carry9 = s9 >> 21;
|
|
1358
|
+
s10 += carry9;
|
|
1359
|
+
s9 -= int64_lshift21(carry9);
|
|
1360
|
+
carry10 = s10 >> 21;
|
|
1361
|
+
s11 += carry10;
|
|
1362
|
+
s10 -= int64_lshift21(carry10);
|
|
1363
|
+
|
|
1364
|
+
s[0] = s0 >> 0;
|
|
1365
|
+
s[1] = s0 >> 8;
|
|
1366
|
+
s[2] = (s0 >> 16) | (s1 << 5);
|
|
1367
|
+
s[3] = s1 >> 3;
|
|
1368
|
+
s[4] = s1 >> 11;
|
|
1369
|
+
s[5] = (s1 >> 19) | (s2 << 2);
|
|
1370
|
+
s[6] = s2 >> 6;
|
|
1371
|
+
s[7] = (s2 >> 14) | (s3 << 7);
|
|
1372
|
+
s[8] = s3 >> 1;
|
|
1373
|
+
s[9] = s3 >> 9;
|
|
1374
|
+
s[10] = (s3 >> 17) | (s4 << 4);
|
|
1375
|
+
s[11] = s4 >> 4;
|
|
1376
|
+
s[12] = s4 >> 12;
|
|
1377
|
+
s[13] = (s4 >> 20) | (s5 << 1);
|
|
1378
|
+
s[14] = s5 >> 7;
|
|
1379
|
+
s[15] = (s5 >> 15) | (s6 << 6);
|
|
1380
|
+
s[16] = s6 >> 2;
|
|
1381
|
+
s[17] = s6 >> 10;
|
|
1382
|
+
s[18] = (s6 >> 18) | (s7 << 3);
|
|
1383
|
+
s[19] = s7 >> 5;
|
|
1384
|
+
s[20] = s7 >> 13;
|
|
1385
|
+
s[21] = s8 >> 0;
|
|
1386
|
+
s[22] = s8 >> 8;
|
|
1387
|
+
s[23] = (s8 >> 16) | (s9 << 5);
|
|
1388
|
+
s[24] = s9 >> 3;
|
|
1389
|
+
s[25] = s9 >> 11;
|
|
1390
|
+
s[26] = (s9 >> 19) | (s10 << 2);
|
|
1391
|
+
s[27] = s10 >> 6;
|
|
1392
|
+
s[28] = (s10 >> 14) | (s11 << 7);
|
|
1393
|
+
s[29] = s11 >> 1;
|
|
1394
|
+
s[30] = s11 >> 9;
|
|
1395
|
+
s[31] = s11 >> 17;
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1398
|
+
// Input:
|
|
1399
|
+
// a[0]+256*a[1]+...+256^31*a[31] = a
|
|
1400
|
+
// b[0]+256*b[1]+...+256^31*b[31] = b
|
|
1401
|
+
// c[0]+256*c[1]+...+256^31*c[31] = c
|
|
1402
|
+
//
|
|
1403
|
+
// Output:
|
|
1404
|
+
// s[0]+256*s[1]+...+256^31*s[31] = (ab+c) mod l
|
|
1405
|
+
// where l = 2^252 + 27742317777372353535851937790883648493.
|
|
1406
|
+
static void sc_muladd(uint8_t *s, const uint8_t *a, const uint8_t *b,
|
|
1407
|
+
const uint8_t *c) {
|
|
1408
|
+
int64_t a0 = 2097151 & load_3(a);
|
|
1409
|
+
int64_t a1 = 2097151 & (load_4(a + 2) >> 5);
|
|
1410
|
+
int64_t a2 = 2097151 & (load_3(a + 5) >> 2);
|
|
1411
|
+
int64_t a3 = 2097151 & (load_4(a + 7) >> 7);
|
|
1412
|
+
int64_t a4 = 2097151 & (load_4(a + 10) >> 4);
|
|
1413
|
+
int64_t a5 = 2097151 & (load_3(a + 13) >> 1);
|
|
1414
|
+
int64_t a6 = 2097151 & (load_4(a + 15) >> 6);
|
|
1415
|
+
int64_t a7 = 2097151 & (load_3(a + 18) >> 3);
|
|
1416
|
+
int64_t a8 = 2097151 & load_3(a + 21);
|
|
1417
|
+
int64_t a9 = 2097151 & (load_4(a + 23) >> 5);
|
|
1418
|
+
int64_t a10 = 2097151 & (load_3(a + 26) >> 2);
|
|
1419
|
+
int64_t a11 = (load_4(a + 28) >> 7);
|
|
1420
|
+
int64_t b0 = 2097151 & load_3(b);
|
|
1421
|
+
int64_t b1 = 2097151 & (load_4(b + 2) >> 5);
|
|
1422
|
+
int64_t b2 = 2097151 & (load_3(b + 5) >> 2);
|
|
1423
|
+
int64_t b3 = 2097151 & (load_4(b + 7) >> 7);
|
|
1424
|
+
int64_t b4 = 2097151 & (load_4(b + 10) >> 4);
|
|
1425
|
+
int64_t b5 = 2097151 & (load_3(b + 13) >> 1);
|
|
1426
|
+
int64_t b6 = 2097151 & (load_4(b + 15) >> 6);
|
|
1427
|
+
int64_t b7 = 2097151 & (load_3(b + 18) >> 3);
|
|
1428
|
+
int64_t b8 = 2097151 & load_3(b + 21);
|
|
1429
|
+
int64_t b9 = 2097151 & (load_4(b + 23) >> 5);
|
|
1430
|
+
int64_t b10 = 2097151 & (load_3(b + 26) >> 2);
|
|
1431
|
+
int64_t b11 = (load_4(b + 28) >> 7);
|
|
1432
|
+
int64_t c0 = 2097151 & load_3(c);
|
|
1433
|
+
int64_t c1 = 2097151 & (load_4(c + 2) >> 5);
|
|
1434
|
+
int64_t c2 = 2097151 & (load_3(c + 5) >> 2);
|
|
1435
|
+
int64_t c3 = 2097151 & (load_4(c + 7) >> 7);
|
|
1436
|
+
int64_t c4 = 2097151 & (load_4(c + 10) >> 4);
|
|
1437
|
+
int64_t c5 = 2097151 & (load_3(c + 13) >> 1);
|
|
1438
|
+
int64_t c6 = 2097151 & (load_4(c + 15) >> 6);
|
|
1439
|
+
int64_t c7 = 2097151 & (load_3(c + 18) >> 3);
|
|
1440
|
+
int64_t c8 = 2097151 & load_3(c + 21);
|
|
1441
|
+
int64_t c9 = 2097151 & (load_4(c + 23) >> 5);
|
|
1442
|
+
int64_t c10 = 2097151 & (load_3(c + 26) >> 2);
|
|
1443
|
+
int64_t c11 = (load_4(c + 28) >> 7);
|
|
1444
|
+
int64_t s0;
|
|
1445
|
+
int64_t s1;
|
|
1446
|
+
int64_t s2;
|
|
1447
|
+
int64_t s3;
|
|
1448
|
+
int64_t s4;
|
|
1449
|
+
int64_t s5;
|
|
1450
|
+
int64_t s6;
|
|
1451
|
+
int64_t s7;
|
|
1452
|
+
int64_t s8;
|
|
1453
|
+
int64_t s9;
|
|
1454
|
+
int64_t s10;
|
|
1455
|
+
int64_t s11;
|
|
1456
|
+
int64_t s12;
|
|
1457
|
+
int64_t s13;
|
|
1458
|
+
int64_t s14;
|
|
1459
|
+
int64_t s15;
|
|
1460
|
+
int64_t s16;
|
|
1461
|
+
int64_t s17;
|
|
1462
|
+
int64_t s18;
|
|
1463
|
+
int64_t s19;
|
|
1464
|
+
int64_t s20;
|
|
1465
|
+
int64_t s21;
|
|
1466
|
+
int64_t s22;
|
|
1467
|
+
int64_t s23;
|
|
1468
|
+
int64_t carry0;
|
|
1469
|
+
int64_t carry1;
|
|
1470
|
+
int64_t carry2;
|
|
1471
|
+
int64_t carry3;
|
|
1472
|
+
int64_t carry4;
|
|
1473
|
+
int64_t carry5;
|
|
1474
|
+
int64_t carry6;
|
|
1475
|
+
int64_t carry7;
|
|
1476
|
+
int64_t carry8;
|
|
1477
|
+
int64_t carry9;
|
|
1478
|
+
int64_t carry10;
|
|
1479
|
+
int64_t carry11;
|
|
1480
|
+
int64_t carry12;
|
|
1481
|
+
int64_t carry13;
|
|
1482
|
+
int64_t carry14;
|
|
1483
|
+
int64_t carry15;
|
|
1484
|
+
int64_t carry16;
|
|
1485
|
+
int64_t carry17;
|
|
1486
|
+
int64_t carry18;
|
|
1487
|
+
int64_t carry19;
|
|
1488
|
+
int64_t carry20;
|
|
1489
|
+
int64_t carry21;
|
|
1490
|
+
int64_t carry22;
|
|
1491
|
+
|
|
1492
|
+
s0 = c0 + a0 * b0;
|
|
1493
|
+
s1 = c1 + a0 * b1 + a1 * b0;
|
|
1494
|
+
s2 = c2 + a0 * b2 + a1 * b1 + a2 * b0;
|
|
1495
|
+
s3 = c3 + a0 * b3 + a1 * b2 + a2 * b1 + a3 * b0;
|
|
1496
|
+
s4 = c4 + a0 * b4 + a1 * b3 + a2 * b2 + a3 * b1 + a4 * b0;
|
|
1497
|
+
s5 = c5 + a0 * b5 + a1 * b4 + a2 * b3 + a3 * b2 + a4 * b1 + a5 * b0;
|
|
1498
|
+
s6 = c6 + a0 * b6 + a1 * b5 + a2 * b4 + a3 * b3 + a4 * b2 + a5 * b1 + a6 * b0;
|
|
1499
|
+
s7 = c7 + a0 * b7 + a1 * b6 + a2 * b5 + a3 * b4 + a4 * b3 + a5 * b2 +
|
|
1500
|
+
a6 * b1 + a7 * b0;
|
|
1501
|
+
s8 = c8 + a0 * b8 + a1 * b7 + a2 * b6 + a3 * b5 + a4 * b4 + a5 * b3 +
|
|
1502
|
+
a6 * b2 + a7 * b1 + a8 * b0;
|
|
1503
|
+
s9 = c9 + a0 * b9 + a1 * b8 + a2 * b7 + a3 * b6 + a4 * b5 + a5 * b4 +
|
|
1504
|
+
a6 * b3 + a7 * b2 + a8 * b1 + a9 * b0;
|
|
1505
|
+
s10 = c10 + a0 * b10 + a1 * b9 + a2 * b8 + a3 * b7 + a4 * b6 + a5 * b5 +
|
|
1506
|
+
a6 * b4 + a7 * b3 + a8 * b2 + a9 * b1 + a10 * b0;
|
|
1507
|
+
s11 = c11 + a0 * b11 + a1 * b10 + a2 * b9 + a3 * b8 + a4 * b7 + a5 * b6 +
|
|
1508
|
+
a6 * b5 + a7 * b4 + a8 * b3 + a9 * b2 + a10 * b1 + a11 * b0;
|
|
1509
|
+
s12 = a1 * b11 + a2 * b10 + a3 * b9 + a4 * b8 + a5 * b7 + a6 * b6 + a7 * b5 +
|
|
1510
|
+
a8 * b4 + a9 * b3 + a10 * b2 + a11 * b1;
|
|
1511
|
+
s13 = a2 * b11 + a3 * b10 + a4 * b9 + a5 * b8 + a6 * b7 + a7 * b6 + a8 * b5 +
|
|
1512
|
+
a9 * b4 + a10 * b3 + a11 * b2;
|
|
1513
|
+
s14 = a3 * b11 + a4 * b10 + a5 * b9 + a6 * b8 + a7 * b7 + a8 * b6 + a9 * b5 +
|
|
1514
|
+
a10 * b4 + a11 * b3;
|
|
1515
|
+
s15 = a4 * b11 + a5 * b10 + a6 * b9 + a7 * b8 + a8 * b7 + a9 * b6 + a10 * b5 +
|
|
1516
|
+
a11 * b4;
|
|
1517
|
+
s16 = a5 * b11 + a6 * b10 + a7 * b9 + a8 * b8 + a9 * b7 + a10 * b6 + a11 * b5;
|
|
1518
|
+
s17 = a6 * b11 + a7 * b10 + a8 * b9 + a9 * b8 + a10 * b7 + a11 * b6;
|
|
1519
|
+
s18 = a7 * b11 + a8 * b10 + a9 * b9 + a10 * b8 + a11 * b7;
|
|
1520
|
+
s19 = a8 * b11 + a9 * b10 + a10 * b9 + a11 * b8;
|
|
1521
|
+
s20 = a9 * b11 + a10 * b10 + a11 * b9;
|
|
1522
|
+
s21 = a10 * b11 + a11 * b10;
|
|
1523
|
+
s22 = a11 * b11;
|
|
1524
|
+
s23 = 0;
|
|
1525
|
+
|
|
1526
|
+
carry0 = (s0 + (1 << 20)) >> 21;
|
|
1527
|
+
s1 += carry0;
|
|
1528
|
+
s0 -= int64_lshift21(carry0);
|
|
1529
|
+
carry2 = (s2 + (1 << 20)) >> 21;
|
|
1530
|
+
s3 += carry2;
|
|
1531
|
+
s2 -= int64_lshift21(carry2);
|
|
1532
|
+
carry4 = (s4 + (1 << 20)) >> 21;
|
|
1533
|
+
s5 += carry4;
|
|
1534
|
+
s4 -= int64_lshift21(carry4);
|
|
1535
|
+
carry6 = (s6 + (1 << 20)) >> 21;
|
|
1536
|
+
s7 += carry6;
|
|
1537
|
+
s6 -= int64_lshift21(carry6);
|
|
1538
|
+
carry8 = (s8 + (1 << 20)) >> 21;
|
|
1539
|
+
s9 += carry8;
|
|
1540
|
+
s8 -= int64_lshift21(carry8);
|
|
1541
|
+
carry10 = (s10 + (1 << 20)) >> 21;
|
|
1542
|
+
s11 += carry10;
|
|
1543
|
+
s10 -= int64_lshift21(carry10);
|
|
1544
|
+
carry12 = (s12 + (1 << 20)) >> 21;
|
|
1545
|
+
s13 += carry12;
|
|
1546
|
+
s12 -= int64_lshift21(carry12);
|
|
1547
|
+
carry14 = (s14 + (1 << 20)) >> 21;
|
|
1548
|
+
s15 += carry14;
|
|
1549
|
+
s14 -= int64_lshift21(carry14);
|
|
1550
|
+
carry16 = (s16 + (1 << 20)) >> 21;
|
|
1551
|
+
s17 += carry16;
|
|
1552
|
+
s16 -= int64_lshift21(carry16);
|
|
1553
|
+
carry18 = (s18 + (1 << 20)) >> 21;
|
|
1554
|
+
s19 += carry18;
|
|
1555
|
+
s18 -= int64_lshift21(carry18);
|
|
1556
|
+
carry20 = (s20 + (1 << 20)) >> 21;
|
|
1557
|
+
s21 += carry20;
|
|
1558
|
+
s20 -= int64_lshift21(carry20);
|
|
1559
|
+
carry22 = (s22 + (1 << 20)) >> 21;
|
|
1560
|
+
s23 += carry22;
|
|
1561
|
+
s22 -= int64_lshift21(carry22);
|
|
1562
|
+
|
|
1563
|
+
carry1 = (s1 + (1 << 20)) >> 21;
|
|
1564
|
+
s2 += carry1;
|
|
1565
|
+
s1 -= int64_lshift21(carry1);
|
|
1566
|
+
carry3 = (s3 + (1 << 20)) >> 21;
|
|
1567
|
+
s4 += carry3;
|
|
1568
|
+
s3 -= int64_lshift21(carry3);
|
|
1569
|
+
carry5 = (s5 + (1 << 20)) >> 21;
|
|
1570
|
+
s6 += carry5;
|
|
1571
|
+
s5 -= int64_lshift21(carry5);
|
|
1572
|
+
carry7 = (s7 + (1 << 20)) >> 21;
|
|
1573
|
+
s8 += carry7;
|
|
1574
|
+
s7 -= int64_lshift21(carry7);
|
|
1575
|
+
carry9 = (s9 + (1 << 20)) >> 21;
|
|
1576
|
+
s10 += carry9;
|
|
1577
|
+
s9 -= int64_lshift21(carry9);
|
|
1578
|
+
carry11 = (s11 + (1 << 20)) >> 21;
|
|
1579
|
+
s12 += carry11;
|
|
1580
|
+
s11 -= int64_lshift21(carry11);
|
|
1581
|
+
carry13 = (s13 + (1 << 20)) >> 21;
|
|
1582
|
+
s14 += carry13;
|
|
1583
|
+
s13 -= int64_lshift21(carry13);
|
|
1584
|
+
carry15 = (s15 + (1 << 20)) >> 21;
|
|
1585
|
+
s16 += carry15;
|
|
1586
|
+
s15 -= int64_lshift21(carry15);
|
|
1587
|
+
carry17 = (s17 + (1 << 20)) >> 21;
|
|
1588
|
+
s18 += carry17;
|
|
1589
|
+
s17 -= int64_lshift21(carry17);
|
|
1590
|
+
carry19 = (s19 + (1 << 20)) >> 21;
|
|
1591
|
+
s20 += carry19;
|
|
1592
|
+
s19 -= int64_lshift21(carry19);
|
|
1593
|
+
carry21 = (s21 + (1 << 20)) >> 21;
|
|
1594
|
+
s22 += carry21;
|
|
1595
|
+
s21 -= int64_lshift21(carry21);
|
|
1596
|
+
|
|
1597
|
+
s11 += s23 * 666643;
|
|
1598
|
+
s12 += s23 * 470296;
|
|
1599
|
+
s13 += s23 * 654183;
|
|
1600
|
+
s14 -= s23 * 997805;
|
|
1601
|
+
s15 += s23 * 136657;
|
|
1602
|
+
s16 -= s23 * 683901;
|
|
1603
|
+
s23 = 0;
|
|
1604
|
+
|
|
1605
|
+
s10 += s22 * 666643;
|
|
1606
|
+
s11 += s22 * 470296;
|
|
1607
|
+
s12 += s22 * 654183;
|
|
1608
|
+
s13 -= s22 * 997805;
|
|
1609
|
+
s14 += s22 * 136657;
|
|
1610
|
+
s15 -= s22 * 683901;
|
|
1611
|
+
s22 = 0;
|
|
1612
|
+
|
|
1613
|
+
s9 += s21 * 666643;
|
|
1614
|
+
s10 += s21 * 470296;
|
|
1615
|
+
s11 += s21 * 654183;
|
|
1616
|
+
s12 -= s21 * 997805;
|
|
1617
|
+
s13 += s21 * 136657;
|
|
1618
|
+
s14 -= s21 * 683901;
|
|
1619
|
+
s21 = 0;
|
|
1620
|
+
|
|
1621
|
+
s8 += s20 * 666643;
|
|
1622
|
+
s9 += s20 * 470296;
|
|
1623
|
+
s10 += s20 * 654183;
|
|
1624
|
+
s11 -= s20 * 997805;
|
|
1625
|
+
s12 += s20 * 136657;
|
|
1626
|
+
s13 -= s20 * 683901;
|
|
1627
|
+
s20 = 0;
|
|
1628
|
+
|
|
1629
|
+
s7 += s19 * 666643;
|
|
1630
|
+
s8 += s19 * 470296;
|
|
1631
|
+
s9 += s19 * 654183;
|
|
1632
|
+
s10 -= s19 * 997805;
|
|
1633
|
+
s11 += s19 * 136657;
|
|
1634
|
+
s12 -= s19 * 683901;
|
|
1635
|
+
s19 = 0;
|
|
1636
|
+
|
|
1637
|
+
s6 += s18 * 666643;
|
|
1638
|
+
s7 += s18 * 470296;
|
|
1639
|
+
s8 += s18 * 654183;
|
|
1640
|
+
s9 -= s18 * 997805;
|
|
1641
|
+
s10 += s18 * 136657;
|
|
1642
|
+
s11 -= s18 * 683901;
|
|
1643
|
+
s18 = 0;
|
|
1644
|
+
|
|
1645
|
+
carry6 = (s6 + (1 << 20)) >> 21;
|
|
1646
|
+
s7 += carry6;
|
|
1647
|
+
s6 -= int64_lshift21(carry6);
|
|
1648
|
+
carry8 = (s8 + (1 << 20)) >> 21;
|
|
1649
|
+
s9 += carry8;
|
|
1650
|
+
s8 -= int64_lshift21(carry8);
|
|
1651
|
+
carry10 = (s10 + (1 << 20)) >> 21;
|
|
1652
|
+
s11 += carry10;
|
|
1653
|
+
s10 -= int64_lshift21(carry10);
|
|
1654
|
+
carry12 = (s12 + (1 << 20)) >> 21;
|
|
1655
|
+
s13 += carry12;
|
|
1656
|
+
s12 -= int64_lshift21(carry12);
|
|
1657
|
+
carry14 = (s14 + (1 << 20)) >> 21;
|
|
1658
|
+
s15 += carry14;
|
|
1659
|
+
s14 -= int64_lshift21(carry14);
|
|
1660
|
+
carry16 = (s16 + (1 << 20)) >> 21;
|
|
1661
|
+
s17 += carry16;
|
|
1662
|
+
s16 -= int64_lshift21(carry16);
|
|
1663
|
+
|
|
1664
|
+
carry7 = (s7 + (1 << 20)) >> 21;
|
|
1665
|
+
s8 += carry7;
|
|
1666
|
+
s7 -= int64_lshift21(carry7);
|
|
1667
|
+
carry9 = (s9 + (1 << 20)) >> 21;
|
|
1668
|
+
s10 += carry9;
|
|
1669
|
+
s9 -= int64_lshift21(carry9);
|
|
1670
|
+
carry11 = (s11 + (1 << 20)) >> 21;
|
|
1671
|
+
s12 += carry11;
|
|
1672
|
+
s11 -= int64_lshift21(carry11);
|
|
1673
|
+
carry13 = (s13 + (1 << 20)) >> 21;
|
|
1674
|
+
s14 += carry13;
|
|
1675
|
+
s13 -= int64_lshift21(carry13);
|
|
1676
|
+
carry15 = (s15 + (1 << 20)) >> 21;
|
|
1677
|
+
s16 += carry15;
|
|
1678
|
+
s15 -= int64_lshift21(carry15);
|
|
1679
|
+
|
|
1680
|
+
s5 += s17 * 666643;
|
|
1681
|
+
s6 += s17 * 470296;
|
|
1682
|
+
s7 += s17 * 654183;
|
|
1683
|
+
s8 -= s17 * 997805;
|
|
1684
|
+
s9 += s17 * 136657;
|
|
1685
|
+
s10 -= s17 * 683901;
|
|
1686
|
+
s17 = 0;
|
|
1687
|
+
|
|
1688
|
+
s4 += s16 * 666643;
|
|
1689
|
+
s5 += s16 * 470296;
|
|
1690
|
+
s6 += s16 * 654183;
|
|
1691
|
+
s7 -= s16 * 997805;
|
|
1692
|
+
s8 += s16 * 136657;
|
|
1693
|
+
s9 -= s16 * 683901;
|
|
1694
|
+
s16 = 0;
|
|
1695
|
+
|
|
1696
|
+
s3 += s15 * 666643;
|
|
1697
|
+
s4 += s15 * 470296;
|
|
1698
|
+
s5 += s15 * 654183;
|
|
1699
|
+
s6 -= s15 * 997805;
|
|
1700
|
+
s7 += s15 * 136657;
|
|
1701
|
+
s8 -= s15 * 683901;
|
|
1702
|
+
s15 = 0;
|
|
1703
|
+
|
|
1704
|
+
s2 += s14 * 666643;
|
|
1705
|
+
s3 += s14 * 470296;
|
|
1706
|
+
s4 += s14 * 654183;
|
|
1707
|
+
s5 -= s14 * 997805;
|
|
1708
|
+
s6 += s14 * 136657;
|
|
1709
|
+
s7 -= s14 * 683901;
|
|
1710
|
+
s14 = 0;
|
|
1711
|
+
|
|
1712
|
+
s1 += s13 * 666643;
|
|
1713
|
+
s2 += s13 * 470296;
|
|
1714
|
+
s3 += s13 * 654183;
|
|
1715
|
+
s4 -= s13 * 997805;
|
|
1716
|
+
s5 += s13 * 136657;
|
|
1717
|
+
s6 -= s13 * 683901;
|
|
1718
|
+
s13 = 0;
|
|
1719
|
+
|
|
1720
|
+
s0 += s12 * 666643;
|
|
1721
|
+
s1 += s12 * 470296;
|
|
1722
|
+
s2 += s12 * 654183;
|
|
1723
|
+
s3 -= s12 * 997805;
|
|
1724
|
+
s4 += s12 * 136657;
|
|
1725
|
+
s5 -= s12 * 683901;
|
|
1726
|
+
s12 = 0;
|
|
1727
|
+
|
|
1728
|
+
carry0 = (s0 + (1 << 20)) >> 21;
|
|
1729
|
+
s1 += carry0;
|
|
1730
|
+
s0 -= int64_lshift21(carry0);
|
|
1731
|
+
carry2 = (s2 + (1 << 20)) >> 21;
|
|
1732
|
+
s3 += carry2;
|
|
1733
|
+
s2 -= int64_lshift21(carry2);
|
|
1734
|
+
carry4 = (s4 + (1 << 20)) >> 21;
|
|
1735
|
+
s5 += carry4;
|
|
1736
|
+
s4 -= int64_lshift21(carry4);
|
|
1737
|
+
carry6 = (s6 + (1 << 20)) >> 21;
|
|
1738
|
+
s7 += carry6;
|
|
1739
|
+
s6 -= int64_lshift21(carry6);
|
|
1740
|
+
carry8 = (s8 + (1 << 20)) >> 21;
|
|
1741
|
+
s9 += carry8;
|
|
1742
|
+
s8 -= int64_lshift21(carry8);
|
|
1743
|
+
carry10 = (s10 + (1 << 20)) >> 21;
|
|
1744
|
+
s11 += carry10;
|
|
1745
|
+
s10 -= int64_lshift21(carry10);
|
|
1746
|
+
|
|
1747
|
+
carry1 = (s1 + (1 << 20)) >> 21;
|
|
1748
|
+
s2 += carry1;
|
|
1749
|
+
s1 -= int64_lshift21(carry1);
|
|
1750
|
+
carry3 = (s3 + (1 << 20)) >> 21;
|
|
1751
|
+
s4 += carry3;
|
|
1752
|
+
s3 -= int64_lshift21(carry3);
|
|
1753
|
+
carry5 = (s5 + (1 << 20)) >> 21;
|
|
1754
|
+
s6 += carry5;
|
|
1755
|
+
s5 -= int64_lshift21(carry5);
|
|
1756
|
+
carry7 = (s7 + (1 << 20)) >> 21;
|
|
1757
|
+
s8 += carry7;
|
|
1758
|
+
s7 -= int64_lshift21(carry7);
|
|
1759
|
+
carry9 = (s9 + (1 << 20)) >> 21;
|
|
1760
|
+
s10 += carry9;
|
|
1761
|
+
s9 -= int64_lshift21(carry9);
|
|
1762
|
+
carry11 = (s11 + (1 << 20)) >> 21;
|
|
1763
|
+
s12 += carry11;
|
|
1764
|
+
s11 -= int64_lshift21(carry11);
|
|
1765
|
+
|
|
1766
|
+
s0 += s12 * 666643;
|
|
1767
|
+
s1 += s12 * 470296;
|
|
1768
|
+
s2 += s12 * 654183;
|
|
1769
|
+
s3 -= s12 * 997805;
|
|
1770
|
+
s4 += s12 * 136657;
|
|
1771
|
+
s5 -= s12 * 683901;
|
|
1772
|
+
s12 = 0;
|
|
1773
|
+
|
|
1774
|
+
carry0 = s0 >> 21;
|
|
1775
|
+
s1 += carry0;
|
|
1776
|
+
s0 -= int64_lshift21(carry0);
|
|
1777
|
+
carry1 = s1 >> 21;
|
|
1778
|
+
s2 += carry1;
|
|
1779
|
+
s1 -= int64_lshift21(carry1);
|
|
1780
|
+
carry2 = s2 >> 21;
|
|
1781
|
+
s3 += carry2;
|
|
1782
|
+
s2 -= int64_lshift21(carry2);
|
|
1783
|
+
carry3 = s3 >> 21;
|
|
1784
|
+
s4 += carry3;
|
|
1785
|
+
s3 -= int64_lshift21(carry3);
|
|
1786
|
+
carry4 = s4 >> 21;
|
|
1787
|
+
s5 += carry4;
|
|
1788
|
+
s4 -= int64_lshift21(carry4);
|
|
1789
|
+
carry5 = s5 >> 21;
|
|
1790
|
+
s6 += carry5;
|
|
1791
|
+
s5 -= int64_lshift21(carry5);
|
|
1792
|
+
carry6 = s6 >> 21;
|
|
1793
|
+
s7 += carry6;
|
|
1794
|
+
s6 -= int64_lshift21(carry6);
|
|
1795
|
+
carry7 = s7 >> 21;
|
|
1796
|
+
s8 += carry7;
|
|
1797
|
+
s7 -= int64_lshift21(carry7);
|
|
1798
|
+
carry8 = s8 >> 21;
|
|
1799
|
+
s9 += carry8;
|
|
1800
|
+
s8 -= int64_lshift21(carry8);
|
|
1801
|
+
carry9 = s9 >> 21;
|
|
1802
|
+
s10 += carry9;
|
|
1803
|
+
s9 -= int64_lshift21(carry9);
|
|
1804
|
+
carry10 = s10 >> 21;
|
|
1805
|
+
s11 += carry10;
|
|
1806
|
+
s10 -= int64_lshift21(carry10);
|
|
1807
|
+
carry11 = s11 >> 21;
|
|
1808
|
+
s12 += carry11;
|
|
1809
|
+
s11 -= int64_lshift21(carry11);
|
|
1810
|
+
|
|
1811
|
+
s0 += s12 * 666643;
|
|
1812
|
+
s1 += s12 * 470296;
|
|
1813
|
+
s2 += s12 * 654183;
|
|
1814
|
+
s3 -= s12 * 997805;
|
|
1815
|
+
s4 += s12 * 136657;
|
|
1816
|
+
s5 -= s12 * 683901;
|
|
1817
|
+
s12 = 0;
|
|
1818
|
+
|
|
1819
|
+
carry0 = s0 >> 21;
|
|
1820
|
+
s1 += carry0;
|
|
1821
|
+
s0 -= int64_lshift21(carry0);
|
|
1822
|
+
carry1 = s1 >> 21;
|
|
1823
|
+
s2 += carry1;
|
|
1824
|
+
s1 -= int64_lshift21(carry1);
|
|
1825
|
+
carry2 = s2 >> 21;
|
|
1826
|
+
s3 += carry2;
|
|
1827
|
+
s2 -= int64_lshift21(carry2);
|
|
1828
|
+
carry3 = s3 >> 21;
|
|
1829
|
+
s4 += carry3;
|
|
1830
|
+
s3 -= int64_lshift21(carry3);
|
|
1831
|
+
carry4 = s4 >> 21;
|
|
1832
|
+
s5 += carry4;
|
|
1833
|
+
s4 -= int64_lshift21(carry4);
|
|
1834
|
+
carry5 = s5 >> 21;
|
|
1835
|
+
s6 += carry5;
|
|
1836
|
+
s5 -= int64_lshift21(carry5);
|
|
1837
|
+
carry6 = s6 >> 21;
|
|
1838
|
+
s7 += carry6;
|
|
1839
|
+
s6 -= int64_lshift21(carry6);
|
|
1840
|
+
carry7 = s7 >> 21;
|
|
1841
|
+
s8 += carry7;
|
|
1842
|
+
s7 -= int64_lshift21(carry7);
|
|
1843
|
+
carry8 = s8 >> 21;
|
|
1844
|
+
s9 += carry8;
|
|
1845
|
+
s8 -= int64_lshift21(carry8);
|
|
1846
|
+
carry9 = s9 >> 21;
|
|
1847
|
+
s10 += carry9;
|
|
1848
|
+
s9 -= int64_lshift21(carry9);
|
|
1849
|
+
carry10 = s10 >> 21;
|
|
1850
|
+
s11 += carry10;
|
|
1851
|
+
s10 -= int64_lshift21(carry10);
|
|
1852
|
+
|
|
1853
|
+
s[0] = s0 >> 0;
|
|
1854
|
+
s[1] = s0 >> 8;
|
|
1855
|
+
s[2] = (s0 >> 16) | (s1 << 5);
|
|
1856
|
+
s[3] = s1 >> 3;
|
|
1857
|
+
s[4] = s1 >> 11;
|
|
1858
|
+
s[5] = (s1 >> 19) | (s2 << 2);
|
|
1859
|
+
s[6] = s2 >> 6;
|
|
1860
|
+
s[7] = (s2 >> 14) | (s3 << 7);
|
|
1861
|
+
s[8] = s3 >> 1;
|
|
1862
|
+
s[9] = s3 >> 9;
|
|
1863
|
+
s[10] = (s3 >> 17) | (s4 << 4);
|
|
1864
|
+
s[11] = s4 >> 4;
|
|
1865
|
+
s[12] = s4 >> 12;
|
|
1866
|
+
s[13] = (s4 >> 20) | (s5 << 1);
|
|
1867
|
+
s[14] = s5 >> 7;
|
|
1868
|
+
s[15] = (s5 >> 15) | (s6 << 6);
|
|
1869
|
+
s[16] = s6 >> 2;
|
|
1870
|
+
s[17] = s6 >> 10;
|
|
1871
|
+
s[18] = (s6 >> 18) | (s7 << 3);
|
|
1872
|
+
s[19] = s7 >> 5;
|
|
1873
|
+
s[20] = s7 >> 13;
|
|
1874
|
+
s[21] = s8 >> 0;
|
|
1875
|
+
s[22] = s8 >> 8;
|
|
1876
|
+
s[23] = (s8 >> 16) | (s9 << 5);
|
|
1877
|
+
s[24] = s9 >> 3;
|
|
1878
|
+
s[25] = s9 >> 11;
|
|
1879
|
+
s[26] = (s9 >> 19) | (s10 << 2);
|
|
1880
|
+
s[27] = s10 >> 6;
|
|
1881
|
+
s[28] = (s10 >> 14) | (s11 << 7);
|
|
1882
|
+
s[29] = s11 >> 1;
|
|
1883
|
+
s[30] = s11 >> 9;
|
|
1884
|
+
s[31] = s11 >> 17;
|
|
1885
|
+
}
|
|
1886
|
+
|
|
1887
|
+
void ED25519_keypair(uint8_t out_public_key[32], uint8_t out_private_key[64]) {
|
|
1888
|
+
uint8_t seed[32];
|
|
1889
|
+
RAND_bytes(seed, 32);
|
|
1890
|
+
ED25519_keypair_from_seed(out_public_key, out_private_key, seed);
|
|
1891
|
+
}
|
|
1892
|
+
|
|
1893
|
+
static int ed25519_sign(uint8_t out_sig[64], const uint8_t *hash_prefix,
|
|
1894
|
+
size_t hash_prefix_len, const uint8_t *message,
|
|
1895
|
+
size_t message_len, const uint8_t private_key[64]) {
|
|
1896
|
+
uint8_t az[SHA512_DIGEST_LENGTH];
|
|
1897
|
+
SHA512(private_key, 32, az);
|
|
1898
|
+
|
|
1899
|
+
az[0] &= 248;
|
|
1900
|
+
az[31] &= 63;
|
|
1901
|
+
az[31] |= 64;
|
|
1902
|
+
|
|
1903
|
+
SHA512_CTX hash_ctx;
|
|
1904
|
+
SHA512_Init(&hash_ctx);
|
|
1905
|
+
SHA512_Update(&hash_ctx, hash_prefix, hash_prefix_len);
|
|
1906
|
+
SHA512_Update(&hash_ctx, az + 32, 32);
|
|
1907
|
+
SHA512_Update(&hash_ctx, message, message_len);
|
|
1908
|
+
uint8_t nonce[SHA512_DIGEST_LENGTH];
|
|
1909
|
+
SHA512_Final(nonce, &hash_ctx);
|
|
1910
|
+
|
|
1911
|
+
x25519_sc_reduce(nonce);
|
|
1912
|
+
ge_p3 R;
|
|
1913
|
+
x25519_ge_scalarmult_base(&R, nonce);
|
|
1914
|
+
ge_p3_tobytes(out_sig, &R);
|
|
1915
|
+
|
|
1916
|
+
SHA512_Init(&hash_ctx);
|
|
1917
|
+
SHA512_Update(&hash_ctx, hash_prefix, hash_prefix_len);
|
|
1918
|
+
SHA512_Update(&hash_ctx, out_sig, 32);
|
|
1919
|
+
SHA512_Update(&hash_ctx, private_key + 32, 32);
|
|
1920
|
+
SHA512_Update(&hash_ctx, message, message_len);
|
|
1921
|
+
uint8_t hram[SHA512_DIGEST_LENGTH];
|
|
1922
|
+
SHA512_Final(hram, &hash_ctx);
|
|
1923
|
+
|
|
1924
|
+
x25519_sc_reduce(hram);
|
|
1925
|
+
sc_muladd(out_sig + 32, hram, az, nonce);
|
|
1926
|
+
|
|
1927
|
+
// The signature is computed from the private key, but is public.
|
|
1928
|
+
CONSTTIME_DECLASSIFY(out_sig, 64);
|
|
1929
|
+
return 1;
|
|
1930
|
+
}
|
|
1931
|
+
|
|
1932
|
+
static int ed25519_verify(const uint8_t *hash_prefix, size_t hash_prefix_len,
|
|
1933
|
+
const uint8_t *message, size_t message_len,
|
|
1934
|
+
const uint8_t signature[64],
|
|
1935
|
+
const uint8_t public_key[32]) {
|
|
1936
|
+
ge_p3 A;
|
|
1937
|
+
if ((signature[63] & 224) != 0 ||
|
|
1938
|
+
!x25519_ge_frombytes_vartime(&A, public_key)) {
|
|
1939
|
+
return 0;
|
|
1940
|
+
}
|
|
1941
|
+
|
|
1942
|
+
fe_loose t;
|
|
1943
|
+
fe_neg(&t, &A.X);
|
|
1944
|
+
fe_carry(&A.X, &t);
|
|
1945
|
+
fe_neg(&t, &A.T);
|
|
1946
|
+
fe_carry(&A.T, &t);
|
|
1947
|
+
|
|
1948
|
+
uint8_t pkcopy[32];
|
|
1949
|
+
OPENSSL_memcpy(pkcopy, public_key, 32);
|
|
1950
|
+
uint8_t rcopy[32];
|
|
1951
|
+
OPENSSL_memcpy(rcopy, signature, 32);
|
|
1952
|
+
uint8_t scopy[32];
|
|
1953
|
+
OPENSSL_memcpy(scopy, signature + 32, 32);
|
|
1954
|
+
|
|
1955
|
+
// https://tools.ietf.org/html/rfc8032#section-5.1.7 requires that s be in
|
|
1956
|
+
// the range [0, order) in order to prevent signature malleability.
|
|
1957
|
+
|
|
1958
|
+
// kOrder is the order of Curve25519 in little-endian form.
|
|
1959
|
+
static const uint64_t kOrder[4] = {
|
|
1960
|
+
UINT64_C(0x5812631a5cf5d3ed),
|
|
1961
|
+
UINT64_C(0x14def9dea2f79cd6),
|
|
1962
|
+
0,
|
|
1963
|
+
UINT64_C(0x1000000000000000),
|
|
1964
|
+
};
|
|
1965
|
+
for (size_t i = 3;; i--) {
|
|
1966
|
+
uint64_t word = CRYPTO_load_u64_le(scopy + i * 8);
|
|
1967
|
+
if (word > kOrder[i]) {
|
|
1968
|
+
return 0;
|
|
1969
|
+
} else if (word < kOrder[i]) {
|
|
1970
|
+
break;
|
|
1971
|
+
} else if (i == 0) {
|
|
1972
|
+
return 0;
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
|
|
1976
|
+
SHA512_CTX hash_ctx;
|
|
1977
|
+
SHA512_Init(&hash_ctx);
|
|
1978
|
+
SHA512_Update(&hash_ctx, hash_prefix, hash_prefix_len);
|
|
1979
|
+
SHA512_Update(&hash_ctx, signature, 32);
|
|
1980
|
+
SHA512_Update(&hash_ctx, public_key, 32);
|
|
1981
|
+
SHA512_Update(&hash_ctx, message, message_len);
|
|
1982
|
+
uint8_t h[SHA512_DIGEST_LENGTH];
|
|
1983
|
+
SHA512_Final(h, &hash_ctx);
|
|
1984
|
+
|
|
1985
|
+
x25519_sc_reduce(h);
|
|
1986
|
+
|
|
1987
|
+
ge_p2 R;
|
|
1988
|
+
ge_double_scalarmult_vartime(&R, h, &A, scopy);
|
|
1989
|
+
|
|
1990
|
+
uint8_t rcheck[32];
|
|
1991
|
+
x25519_ge_tobytes(rcheck, &R);
|
|
1992
|
+
|
|
1993
|
+
return CRYPTO_memcmp(rcheck, rcopy, sizeof(rcheck)) == 0;
|
|
1994
|
+
}
|
|
1995
|
+
|
|
1996
|
+
int ED25519_sign(uint8_t out_sig[64], const uint8_t *message,
|
|
1997
|
+
size_t message_len, const uint8_t private_key[64]) {
|
|
1998
|
+
// NOTE: The documentation on this function says that it returns zero on
|
|
1999
|
+
// allocation failure. While that can't happen with the current
|
|
2000
|
+
// implementation, we want to reserve the ability to allocate in this
|
|
2001
|
+
// implementation in the future.
|
|
2002
|
+
|
|
2003
|
+
return ed25519_sign(out_sig, nullptr, 0, message, message_len, private_key);
|
|
2004
|
+
}
|
|
2005
|
+
|
|
2006
|
+
int ED25519_verify(const uint8_t *message, size_t message_len,
|
|
2007
|
+
const uint8_t signature[64], const uint8_t public_key[32]) {
|
|
2008
|
+
return ed25519_verify(nullptr, 0, message, message_len, signature,
|
|
2009
|
+
public_key);
|
|
2010
|
+
}
|
|
2011
|
+
|
|
2012
|
+
// ED25519_MAX_CONTEXT is the longest context permitted by RFC 8032.
|
|
2013
|
+
#define ED25519_MAX_CONTEXT 255
|
|
2014
|
+
#define ED25519_MAX_HASH_PREFIX (32 + 1 + 1 + ED25519_MAX_CONTEXT)
|
|
2015
|
+
|
|
2016
|
+
// ed25519_build_hash_prefix implements the `dom2` function from
|
|
2017
|
+
// https://datatracker.ietf.org/doc/html/rfc8032#section-2
|
|
2018
|
+
static int ed25519_build_hash_prefix(
|
|
2019
|
+
uint8_t out_hash_prefix[ED25519_MAX_HASH_PREFIX],
|
|
2020
|
+
size_t *out_hash_prefix_len, const uint8_t *context, size_t context_len) {
|
|
2021
|
+
if (context_len > ED25519_MAX_CONTEXT) {
|
|
2022
|
+
return 0;
|
|
2023
|
+
}
|
|
2024
|
+
|
|
2025
|
+
OPENSSL_memcpy(out_hash_prefix, "SigEd25519 no Ed25519 collisions", 32);
|
|
2026
|
+
out_hash_prefix[32] = 1;
|
|
2027
|
+
out_hash_prefix[33] = static_cast<uint8_t>(context_len);
|
|
2028
|
+
OPENSSL_memcpy(&out_hash_prefix[34], context, context_len);
|
|
2029
|
+
*out_hash_prefix_len = 32 + 1 + 1 + context_len;
|
|
2030
|
+
return 1;
|
|
2031
|
+
}
|
|
2032
|
+
|
|
2033
|
+
int ED25519_sign_prehashed(uint8_t out_sig[64], const uint8_t *context,
|
|
2034
|
+
size_t context_len,
|
|
2035
|
+
const uint8_t sha512_digest[SHA512_DIGEST_LENGTH],
|
|
2036
|
+
const uint8_t private_key[64]) {
|
|
2037
|
+
// NOTE: The documentation on this function says that it returns zero on
|
|
2038
|
+
// allocation failure. While that can't happen with the current
|
|
2039
|
+
// implementation, we want to reserve the ability to allocate in this
|
|
2040
|
+
// implementation in the future.
|
|
2041
|
+
|
|
2042
|
+
uint8_t hash_prefix[ED25519_MAX_HASH_PREFIX];
|
|
2043
|
+
size_t hash_prefix_len;
|
|
2044
|
+
if (!ed25519_build_hash_prefix(hash_prefix, &hash_prefix_len, context,
|
|
2045
|
+
context_len)) {
|
|
2046
|
+
return 0;
|
|
2047
|
+
}
|
|
2048
|
+
|
|
2049
|
+
return ed25519_sign(out_sig, hash_prefix, hash_prefix_len, sha512_digest,
|
|
2050
|
+
SHA512_DIGEST_LENGTH, private_key);
|
|
2051
|
+
}
|
|
2052
|
+
|
|
2053
|
+
int ED25519_verify_prehashed(const uint8_t *context, size_t context_len,
|
|
2054
|
+
const uint8_t sha512_digest[SHA512_DIGEST_LENGTH],
|
|
2055
|
+
const uint8_t signature[64],
|
|
2056
|
+
const uint8_t public_key[32]) {
|
|
2057
|
+
uint8_t hash_prefix[ED25519_MAX_HASH_PREFIX];
|
|
2058
|
+
size_t hash_prefix_len;
|
|
2059
|
+
if (!ed25519_build_hash_prefix(hash_prefix, &hash_prefix_len, context,
|
|
2060
|
+
context_len)) {
|
|
2061
|
+
return 0;
|
|
2062
|
+
}
|
|
2063
|
+
|
|
2064
|
+
return ed25519_verify(hash_prefix, hash_prefix_len, sha512_digest,
|
|
2065
|
+
SHA512_DIGEST_LENGTH, signature, public_key);
|
|
2066
|
+
}
|
|
2067
|
+
|
|
2068
|
+
void ED25519_keypair_from_seed(uint8_t out_public_key[32],
|
|
2069
|
+
uint8_t out_private_key[64],
|
|
2070
|
+
const uint8_t seed[32]) {
|
|
2071
|
+
uint8_t az[SHA512_DIGEST_LENGTH];
|
|
2072
|
+
SHA512(seed, 32, az);
|
|
2073
|
+
|
|
2074
|
+
az[0] &= 248;
|
|
2075
|
+
az[31] &= 127;
|
|
2076
|
+
az[31] |= 64;
|
|
2077
|
+
|
|
2078
|
+
ge_p3 A;
|
|
2079
|
+
x25519_ge_scalarmult_base(&A, az);
|
|
2080
|
+
ge_p3_tobytes(out_public_key, &A);
|
|
2081
|
+
// The public key is derived from the private key, but it is public.
|
|
2082
|
+
CONSTTIME_DECLASSIFY(out_public_key, 32);
|
|
2083
|
+
|
|
2084
|
+
OPENSSL_memcpy(out_private_key, seed, 32);
|
|
2085
|
+
OPENSSL_memcpy(out_private_key + 32, out_public_key, 32);
|
|
2086
|
+
}
|
|
2087
|
+
|
|
2088
|
+
|
|
2089
|
+
static void x25519_scalar_mult_generic(uint8_t out[32],
|
|
2090
|
+
const uint8_t scalar[32],
|
|
2091
|
+
const uint8_t point[32]) {
|
|
2092
|
+
fe x1, x2, z2, x3, z3, tmp0, tmp1;
|
|
2093
|
+
fe_loose x2l, z2l, x3l, tmp0l, tmp1l;
|
|
2094
|
+
|
|
2095
|
+
uint8_t e[32];
|
|
2096
|
+
OPENSSL_memcpy(e, scalar, 32);
|
|
2097
|
+
e[0] &= 248;
|
|
2098
|
+
e[31] &= 127;
|
|
2099
|
+
e[31] |= 64;
|
|
2100
|
+
|
|
2101
|
+
// The following implementation was transcribed to Coq and proven to
|
|
2102
|
+
// correspond to unary scalar multiplication in affine coordinates given that
|
|
2103
|
+
// x1 != 0 is the x coordinate of some point on the curve. It was also checked
|
|
2104
|
+
// in Coq that doing a ladderstep with x1 = x3 = 0 gives z2' = z3' = 0, and z2
|
|
2105
|
+
// = z3 = 0 gives z2' = z3' = 0. The statement was quantified over the
|
|
2106
|
+
// underlying field, so it applies to Curve25519 itself and the quadratic
|
|
2107
|
+
// twist of Curve25519. It was not proven in Coq that prime-field arithmetic
|
|
2108
|
+
// correctly simulates extension-field arithmetic on prime-field values.
|
|
2109
|
+
// The decoding of the byte array representation of e was not considered.
|
|
2110
|
+
// Specification of Montgomery curves in affine coordinates:
|
|
2111
|
+
// <https://github.com/mit-plv/fiat-crypto/blob/2456d821825521f7e03e65882cc3521795b0320f/src/Spec/MontgomeryCurve.v#L27>
|
|
2112
|
+
// Proof that these form a group that is isomorphic to a Weierstrass curve:
|
|
2113
|
+
// <https://github.com/mit-plv/fiat-crypto/blob/2456d821825521f7e03e65882cc3521795b0320f/src/Curves/Montgomery/AffineProofs.v#L35>
|
|
2114
|
+
// Coq transcription and correctness proof of the loop (where scalarbits=255):
|
|
2115
|
+
// <https://github.com/mit-plv/fiat-crypto/blob/2456d821825521f7e03e65882cc3521795b0320f/src/Curves/Montgomery/XZ.v#L118>
|
|
2116
|
+
// <https://github.com/mit-plv/fiat-crypto/blob/2456d821825521f7e03e65882cc3521795b0320f/src/Curves/Montgomery/XZProofs.v#L278>
|
|
2117
|
+
// preconditions: 0 <= e < 2^255 (not necessarily e < order), fe_invert(0) = 0
|
|
2118
|
+
fe_frombytes(&x1, point);
|
|
2119
|
+
fe_1(&x2);
|
|
2120
|
+
fe_0(&z2);
|
|
2121
|
+
fe_copy(&x3, &x1);
|
|
2122
|
+
fe_1(&z3);
|
|
2123
|
+
|
|
2124
|
+
unsigned swap = 0;
|
|
2125
|
+
int pos;
|
|
2126
|
+
for (pos = 254; pos >= 0; --pos) {
|
|
2127
|
+
// loop invariant as of right before the test, for the case where x1 != 0:
|
|
2128
|
+
// pos >= -1; if z2 = 0 then x2 is nonzero; if z3 = 0 then x3 is nonzero
|
|
2129
|
+
// let r := e >> (pos+1) in the following equalities of projective points:
|
|
2130
|
+
// to_xz (r*P) === if swap then (x3, z3) else (x2, z2)
|
|
2131
|
+
// to_xz ((r+1)*P) === if swap then (x2, z2) else (x3, z3)
|
|
2132
|
+
// x1 is the nonzero x coordinate of the nonzero point (r*P-(r+1)*P)
|
|
2133
|
+
unsigned b = 1 & (e[pos / 8] >> (pos & 7));
|
|
2134
|
+
swap ^= b;
|
|
2135
|
+
fe_cswap(&x2, &x3, swap);
|
|
2136
|
+
fe_cswap(&z2, &z3, swap);
|
|
2137
|
+
swap = b;
|
|
2138
|
+
// Coq transcription of ladderstep formula (called from transcribed loop):
|
|
2139
|
+
// <https://github.com/mit-plv/fiat-crypto/blob/2456d821825521f7e03e65882cc3521795b0320f/src/Curves/Montgomery/XZ.v#L89>
|
|
2140
|
+
// <https://github.com/mit-plv/fiat-crypto/blob/2456d821825521f7e03e65882cc3521795b0320f/src/Curves/Montgomery/XZProofs.v#L131>
|
|
2141
|
+
// x1 != 0
|
|
2142
|
+
// <https://github.com/mit-plv/fiat-crypto/blob/2456d821825521f7e03e65882cc3521795b0320f/src/Curves/Montgomery/XZProofs.v#L217>
|
|
2143
|
+
// x1 = 0
|
|
2144
|
+
// <https://github.com/mit-plv/fiat-crypto/blob/2456d821825521f7e03e65882cc3521795b0320f/src/Curves/Montgomery/XZProofs.v#L147>
|
|
2145
|
+
fe_sub(&tmp0l, &x3, &z3);
|
|
2146
|
+
fe_sub(&tmp1l, &x2, &z2);
|
|
2147
|
+
fe_add(&x2l, &x2, &z2);
|
|
2148
|
+
fe_add(&z2l, &x3, &z3);
|
|
2149
|
+
fe_mul_tll(&z3, &tmp0l, &x2l);
|
|
2150
|
+
fe_mul_tll(&z2, &z2l, &tmp1l);
|
|
2151
|
+
fe_sq_tl(&tmp0, &tmp1l);
|
|
2152
|
+
fe_sq_tl(&tmp1, &x2l);
|
|
2153
|
+
fe_add(&x3l, &z3, &z2);
|
|
2154
|
+
fe_sub(&z2l, &z3, &z2);
|
|
2155
|
+
fe_mul_ttt(&x2, &tmp1, &tmp0);
|
|
2156
|
+
fe_sub(&tmp1l, &tmp1, &tmp0);
|
|
2157
|
+
fe_sq_tl(&z2, &z2l);
|
|
2158
|
+
fe_mul121666(&z3, &tmp1l);
|
|
2159
|
+
fe_sq_tl(&x3, &x3l);
|
|
2160
|
+
fe_add(&tmp0l, &tmp0, &z3);
|
|
2161
|
+
fe_mul_ttt(&z3, &x1, &z2);
|
|
2162
|
+
fe_mul_tll(&z2, &tmp1l, &tmp0l);
|
|
2163
|
+
}
|
|
2164
|
+
// here pos=-1, so r=e, so to_xz (e*P) === if swap then (x3, z3) else (x2, z2)
|
|
2165
|
+
fe_cswap(&x2, &x3, swap);
|
|
2166
|
+
fe_cswap(&z2, &z3, swap);
|
|
2167
|
+
|
|
2168
|
+
fe_invert(&z2, &z2);
|
|
2169
|
+
fe_mul_ttt(&x2, &x2, &z2);
|
|
2170
|
+
fe_tobytes(out, &x2);
|
|
2171
|
+
}
|
|
2172
|
+
|
|
2173
|
+
static void x25519_scalar_mult(uint8_t out[32], const uint8_t scalar[32],
|
|
2174
|
+
const uint8_t point[32]) {
|
|
2175
|
+
#if defined(BORINGSSL_X25519_NEON)
|
|
2176
|
+
if (CRYPTO_is_NEON_capable()) {
|
|
2177
|
+
x25519_NEON(out, scalar, point);
|
|
2178
|
+
return;
|
|
2179
|
+
}
|
|
2180
|
+
#elif defined(BORINGSSL_FE25519_ADX)
|
|
2181
|
+
if (CRYPTO_is_BMI1_capable() && CRYPTO_is_BMI2_capable() &&
|
|
2182
|
+
CRYPTO_is_ADX_capable()) {
|
|
2183
|
+
x25519_scalar_mult_adx(out, scalar, point);
|
|
2184
|
+
return;
|
|
2185
|
+
}
|
|
2186
|
+
#endif
|
|
2187
|
+
|
|
2188
|
+
x25519_scalar_mult_generic(out, scalar, point);
|
|
2189
|
+
}
|
|
2190
|
+
|
|
2191
|
+
void X25519_keypair(uint8_t out_public_value[32], uint8_t out_private_key[32]) {
|
|
2192
|
+
RAND_bytes(out_private_key, 32);
|
|
2193
|
+
|
|
2194
|
+
// All X25519 implementations should decode scalars correctly (see
|
|
2195
|
+
// https://tools.ietf.org/html/rfc7748#section-5). However, if an
|
|
2196
|
+
// implementation doesn't then it might interoperate with random keys a
|
|
2197
|
+
// fraction of the time because they'll, randomly, happen to be correctly
|
|
2198
|
+
// formed.
|
|
2199
|
+
//
|
|
2200
|
+
// Thus we do the opposite of the masking here to make sure that our private
|
|
2201
|
+
// keys are never correctly masked and so, hopefully, any incorrect
|
|
2202
|
+
// implementations are deterministically broken.
|
|
2203
|
+
//
|
|
2204
|
+
// This does not affect security because, although we're throwing away
|
|
2205
|
+
// entropy, a valid implementation of scalarmult should throw away the exact
|
|
2206
|
+
// same bits anyway.
|
|
2207
|
+
out_private_key[0] |= ~248;
|
|
2208
|
+
out_private_key[31] &= ~64;
|
|
2209
|
+
out_private_key[31] |= ~127;
|
|
2210
|
+
|
|
2211
|
+
X25519_public_from_private(out_public_value, out_private_key);
|
|
2212
|
+
}
|
|
2213
|
+
|
|
2214
|
+
int X25519(uint8_t out_shared_key[32], const uint8_t private_key[32],
|
|
2215
|
+
const uint8_t peer_public_value[32]) {
|
|
2216
|
+
static const uint8_t kZeros[32] = {0};
|
|
2217
|
+
x25519_scalar_mult(out_shared_key, private_key, peer_public_value);
|
|
2218
|
+
// The all-zero output results when the input is a point of small order.
|
|
2219
|
+
return constant_time_declassify_int(
|
|
2220
|
+
CRYPTO_memcmp(kZeros, out_shared_key, 32)) != 0;
|
|
2221
|
+
}
|
|
2222
|
+
|
|
2223
|
+
void X25519_public_from_private(uint8_t out_public_value[32],
|
|
2224
|
+
const uint8_t private_key[32]) {
|
|
2225
|
+
#if defined(BORINGSSL_X25519_NEON)
|
|
2226
|
+
if (CRYPTO_is_NEON_capable()) {
|
|
2227
|
+
static const uint8_t kMongomeryBasePoint[32] = {9};
|
|
2228
|
+
x25519_NEON(out_public_value, private_key, kMongomeryBasePoint);
|
|
2229
|
+
return;
|
|
2230
|
+
}
|
|
2231
|
+
#endif
|
|
2232
|
+
|
|
2233
|
+
uint8_t e[32];
|
|
2234
|
+
OPENSSL_memcpy(e, private_key, 32);
|
|
2235
|
+
e[0] &= 248;
|
|
2236
|
+
e[31] &= 127;
|
|
2237
|
+
e[31] |= 64;
|
|
2238
|
+
|
|
2239
|
+
ge_p3 A;
|
|
2240
|
+
x25519_ge_scalarmult_base(&A, e);
|
|
2241
|
+
|
|
2242
|
+
// We only need the u-coordinate of the curve25519 point. The map is
|
|
2243
|
+
// u=(y+1)/(1-y). Since y=Y/Z, this gives u=(Z+Y)/(Z-Y).
|
|
2244
|
+
fe_loose zplusy, zminusy;
|
|
2245
|
+
fe zminusy_inv;
|
|
2246
|
+
fe_add(&zplusy, &A.Z, &A.Y);
|
|
2247
|
+
fe_sub(&zminusy, &A.Z, &A.Y);
|
|
2248
|
+
fe_loose_invert(&zminusy_inv, &zminusy);
|
|
2249
|
+
fe_mul_tlt(&zminusy_inv, &zplusy, &zminusy_inv);
|
|
2250
|
+
fe_tobytes(out_public_value, &zminusy_inv);
|
|
2251
|
+
CONSTTIME_DECLASSIFY(out_public_value, 32);
|
|
2252
|
+
}
|
|
2253
|
+
|
|
2254
|
+
static void fe_from_limb(fe *h, fe_limb_t val) {
|
|
2255
|
+
fe_0(h);
|
|
2256
|
+
h->v[0] = val;
|
|
2257
|
+
assert_fe(h->v);
|
|
2258
|
+
}
|
|
2259
|
+
|
|
2260
|
+
// map_to_curve_elligator2 implements the straight-line Elligator 2 mapping
|
|
2261
|
+
// for Curve25519 from RFC 9380, Appendix G.2.1.
|
|
2262
|
+
//
|
|
2263
|
+
// It maps a field element u to a Montgomery point (xn / xd, y / 1) on the curve
|
|
2264
|
+
// t^2 = s^3 + 486662*s^2 + s.
|
|
2265
|
+
static void map_to_curve_elligator2(fe *out_xMn, fe *out_xMd, fe *out_yMn,
|
|
2266
|
+
const fe *u) {
|
|
2267
|
+
fe one, J_fe, c2_fe;
|
|
2268
|
+
fe_1(&one);
|
|
2269
|
+
fe_from_limb(&J_fe, 486662);
|
|
2270
|
+
// c2 = 2^((p + 3) / 8) mod (2^255 - 19) in little-endian.
|
|
2271
|
+
constexpr static uint8_t kC2[32] = {
|
|
2272
|
+
0xb1, 0xa0, 0x0e, 0x4a, 0x27, 0x1b, 0xee, 0xc4, 0x78, 0xe4, 0x2f,
|
|
2273
|
+
0xad, 0x06, 0x18, 0x43, 0x2f, 0xa7, 0xd7, 0xfb, 0x3d, 0x99, 0x00,
|
|
2274
|
+
0x4d, 0x2b, 0x0b, 0xdf, 0xc1, 0x4f, 0x80, 0x24, 0x83, 0x2b};
|
|
2275
|
+
fe_frombytes(&c2_fe, kC2);
|
|
2276
|
+
|
|
2277
|
+
// 1-2. tv1 = 2 * u^2
|
|
2278
|
+
fe tv1;
|
|
2279
|
+
fe_sq2_tt(&tv1, u);
|
|
2280
|
+
|
|
2281
|
+
// 3. xd = tv1 + 1
|
|
2282
|
+
fe_loose xd_loose;
|
|
2283
|
+
fe_add(&xd_loose, &tv1, &one);
|
|
2284
|
+
|
|
2285
|
+
// 4. x1n = -J
|
|
2286
|
+
fe_loose x1n_loose;
|
|
2287
|
+
fe_neg(&x1n_loose, &J_fe);
|
|
2288
|
+
|
|
2289
|
+
// 5. tv2 = xd^2
|
|
2290
|
+
fe tv2;
|
|
2291
|
+
fe_sq_tl(&tv2, &xd_loose);
|
|
2292
|
+
|
|
2293
|
+
// 6. gxd = xd^3
|
|
2294
|
+
fe gxd;
|
|
2295
|
+
fe_mul_ttl(&gxd, &tv2, &xd_loose);
|
|
2296
|
+
|
|
2297
|
+
fe gx1;
|
|
2298
|
+
{
|
|
2299
|
+
fe_loose l_tmp;
|
|
2300
|
+
// 7. gx1 = J * tv1
|
|
2301
|
+
fe_mul_ltt(&l_tmp, &J_fe, &tv1);
|
|
2302
|
+
// 8. gx1 = gx1 * x1n
|
|
2303
|
+
fe_mul_tll(&gx1, &l_tmp, &x1n_loose);
|
|
2304
|
+
// 9. gx1 = gx1 + tv2
|
|
2305
|
+
fe_add(&l_tmp, &gx1, &tv2);
|
|
2306
|
+
// 10. gx1 = gx1 * x1n
|
|
2307
|
+
fe_mul_tll(&gx1, &l_tmp, &x1n_loose);
|
|
2308
|
+
}
|
|
2309
|
+
|
|
2310
|
+
fe tv3;
|
|
2311
|
+
// 11. tv3 = gxd^2
|
|
2312
|
+
fe_sq_tt(&tv3, &gxd);
|
|
2313
|
+
// 12. tv2 = tv3^2
|
|
2314
|
+
fe_sq_tt(&tv2, &tv3);
|
|
2315
|
+
// 13. tv3 = tv3 * gxd
|
|
2316
|
+
fe_mul_ttt(&tv3, &tv3, &gxd);
|
|
2317
|
+
// 14. tv3 = tv3 * gx1
|
|
2318
|
+
fe_mul_ttt(&tv3, &tv3, &gx1);
|
|
2319
|
+
// 15. tv2 = tv2 * tv3
|
|
2320
|
+
fe_mul_ttt(&tv2, &tv2, &tv3);
|
|
2321
|
+
|
|
2322
|
+
// 16. y11 = tv2^c4 = (gx1 * gxd^7)^((p - 5) / 8)
|
|
2323
|
+
fe y11;
|
|
2324
|
+
fe_pow22523(&y11, &tv2);
|
|
2325
|
+
// 17. y11 = y11 * tv3
|
|
2326
|
+
fe_mul_ttt(&y11, &y11, &tv3);
|
|
2327
|
+
|
|
2328
|
+
// 18. y12 = y11 * c3
|
|
2329
|
+
fe y12;
|
|
2330
|
+
fe_mul_ttt(&y12, &y11, &sqrtm1);
|
|
2331
|
+
|
|
2332
|
+
// 19. tv2 = y11 ^ 2
|
|
2333
|
+
fe_sq_tt(&tv2, &y11);
|
|
2334
|
+
// 20. tv2 = tv2 * gxd
|
|
2335
|
+
fe_mul_ttt(&tv2, &tv2, &gxd);
|
|
2336
|
+
// 21. e1 = tv2 == gx1
|
|
2337
|
+
fe_limb_t e1;
|
|
2338
|
+
{
|
|
2339
|
+
fe_loose l_tmp;
|
|
2340
|
+
fe_sub(&l_tmp, &tv2, &gx1);
|
|
2341
|
+
e1 = 1 - fe_isnonzero(&l_tmp);
|
|
2342
|
+
}
|
|
2343
|
+
|
|
2344
|
+
// 22. y1 = CMOV(y12, y11, e1) # If g(x1) is square, this is its sqrt
|
|
2345
|
+
fe y1;
|
|
2346
|
+
fe_copy(&y1, &y12);
|
|
2347
|
+
fe_cmov(&y1, &y11, e1);
|
|
2348
|
+
|
|
2349
|
+
// 23. x2n = x1n * tv1
|
|
2350
|
+
fe x2n;
|
|
2351
|
+
fe_mul_ttl(&x2n, &tv1, &x1n_loose);
|
|
2352
|
+
|
|
2353
|
+
// 24. y21 = y11 * u
|
|
2354
|
+
fe y21;
|
|
2355
|
+
fe_mul_ttt(&y21, &y11, u);
|
|
2356
|
+
// 25. y21 = y21 * c2
|
|
2357
|
+
fe_mul_ttt(&y21, &y21, &c2_fe);
|
|
2358
|
+
|
|
2359
|
+
// 26. y22 = y21 * c3
|
|
2360
|
+
fe y22;
|
|
2361
|
+
fe_mul_ttt(&y22, &y21, &sqrtm1);
|
|
2362
|
+
|
|
2363
|
+
// 27. gx2 = gx1 * tv1 # g(x2) = gx2 / gxd = 2 * u^2 * g(x1)
|
|
2364
|
+
fe gx2;
|
|
2365
|
+
fe_mul_ttt(&gx2, &gx1, &tv1);
|
|
2366
|
+
|
|
2367
|
+
// 28. tv2 = y21^2
|
|
2368
|
+
fe_sq_tt(&tv2, &y21);
|
|
2369
|
+
// 29. tv2 = tv2 * gxd
|
|
2370
|
+
fe_mul_ttt(&tv2, &tv2, &gxd);
|
|
2371
|
+
// 30. e2 = tv2 == gx2
|
|
2372
|
+
fe_limb_t e2;
|
|
2373
|
+
{
|
|
2374
|
+
fe_loose l_tmp;
|
|
2375
|
+
fe_sub(&l_tmp, &tv2, &gx2);
|
|
2376
|
+
e2 = 1 - fe_isnonzero(&l_tmp);
|
|
2377
|
+
}
|
|
2378
|
+
|
|
2379
|
+
// 31. y2 = CMOV(y22, y21, e2) # If g(x2) is square, this is its sqrt
|
|
2380
|
+
fe y2;
|
|
2381
|
+
fe_copy(&y2, &y22);
|
|
2382
|
+
fe_cmov(&y2, &y21, e2);
|
|
2383
|
+
|
|
2384
|
+
// 32. tv2 = y1^2
|
|
2385
|
+
fe_sq_tt(&tv2, &y1);
|
|
2386
|
+
// 33. tv2 = tv2 * gxd
|
|
2387
|
+
fe_mul_ttt(&tv2, &tv2, &gxd);
|
|
2388
|
+
// 34. e3 = tv2 == gx1
|
|
2389
|
+
fe_limb_t e3;
|
|
2390
|
+
{
|
|
2391
|
+
fe_loose l_tmp;
|
|
2392
|
+
fe_sub(&l_tmp, &tv2, &gx1);
|
|
2393
|
+
e3 = 1 - fe_isnonzero(&l_tmp);
|
|
2394
|
+
}
|
|
2395
|
+
|
|
2396
|
+
fe xn, y;
|
|
2397
|
+
// 35. xn = CMOV(x2n, x1n, e3) # If e3, x = x1, else x = x2
|
|
2398
|
+
// or xn = CMOV(x1n, x2n, 1 - e3)
|
|
2399
|
+
fe_carry(&xn, &x1n_loose);
|
|
2400
|
+
fe_cmov(&xn, &x2n, 1 - e3);
|
|
2401
|
+
// 36. y = CMOV(y2, y1, e3) # If e3, y = y1, else y = y2
|
|
2402
|
+
fe_copy(&y, &y2);
|
|
2403
|
+
fe_cmov(&y, &y1, e3);
|
|
2404
|
+
|
|
2405
|
+
// 37. e4 = sgn0(y) == 1 # Fix sign of y
|
|
2406
|
+
fe_limb_t e4 = fe_isnegative(&y);
|
|
2407
|
+
fe negy;
|
|
2408
|
+
{
|
|
2409
|
+
fe_loose l_tmp;
|
|
2410
|
+
fe_neg(&l_tmp, &y);
|
|
2411
|
+
fe_carry(&negy, &l_tmp);
|
|
2412
|
+
}
|
|
2413
|
+
// 38. y = CMOV(y, -y, e3 XOR e4)
|
|
2414
|
+
fe_cmov(&y, &negy, e3 ^ e4);
|
|
2415
|
+
|
|
2416
|
+
// 39. return (xn, xd, y, /* 1 */)
|
|
2417
|
+
fe_copy(out_xMn, &xn);
|
|
2418
|
+
fe_carry(out_xMd, &xd_loose);
|
|
2419
|
+
fe_copy(out_yMn, &y);
|
|
2420
|
+
}
|
|
2421
|
+
|
|
2422
|
+
void bssl::map_to_curve_curve25519_elligator2(uint8_t out_qx[32],
|
|
2423
|
+
uint8_t out_qy[32],
|
|
2424
|
+
const uint8_t u[32]) {
|
|
2425
|
+
fe u_fe;
|
|
2426
|
+
fe_frombytes(&u_fe, u);
|
|
2427
|
+
|
|
2428
|
+
fe xMn, xMd, yMn;
|
|
2429
|
+
map_to_curve_elligator2(&xMn, &xMd, &yMn, &u_fe);
|
|
2430
|
+
|
|
2431
|
+
fe xMd_inv, qx;
|
|
2432
|
+
fe_invert(&xMd_inv, &xMd);
|
|
2433
|
+
fe_mul_ttt(&qx, &xMn, &xMd_inv);
|
|
2434
|
+
fe_tobytes(out_qx, &qx);
|
|
2435
|
+
fe_tobytes(out_qy, &yMn);
|
|
2436
|
+
}
|