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,3323 @@
|
|
|
1
|
+
// Copyright 2014 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
|
+
#include <openssl/base.h>
|
|
16
|
+
|
|
17
|
+
#include <memory>
|
|
18
|
+
|
|
19
|
+
#include <assert.h>
|
|
20
|
+
#include <stdlib.h>
|
|
21
|
+
|
|
22
|
+
#include <openssl/bytestring.h>
|
|
23
|
+
#include <openssl/mem.h>
|
|
24
|
+
#include <openssl/rand.h>
|
|
25
|
+
|
|
26
|
+
#include "../../internal.h"
|
|
27
|
+
#include "../../mem_internal.h"
|
|
28
|
+
#include "../bcm_interface.h"
|
|
29
|
+
#include "../keccak/internal.h"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
using namespace bssl;
|
|
33
|
+
|
|
34
|
+
#if defined(BORINGSSL_FIPS)
|
|
35
|
+
|
|
36
|
+
DEFINE_STATIC_ONCE(g_mldsa_keygen_self_test_once)
|
|
37
|
+
DEFINE_STATIC_ONCE(g_mldsa_sign_self_test_once)
|
|
38
|
+
DEFINE_STATIC_ONCE(g_mldsa_verify_self_test_once)
|
|
39
|
+
|
|
40
|
+
#endif
|
|
41
|
+
|
|
42
|
+
namespace mldsa {
|
|
43
|
+
namespace {
|
|
44
|
+
|
|
45
|
+
namespace fips {
|
|
46
|
+
void ensure_keygen_self_test();
|
|
47
|
+
void ensure_sign_self_test();
|
|
48
|
+
void ensure_verify_self_test();
|
|
49
|
+
} // namespace fips
|
|
50
|
+
|
|
51
|
+
constexpr int kDegree = 256;
|
|
52
|
+
constexpr int kRhoBytes = 32;
|
|
53
|
+
constexpr int kSigmaBytes = 64;
|
|
54
|
+
constexpr int kKBytes = 32;
|
|
55
|
+
constexpr int kTrBytes = 64;
|
|
56
|
+
constexpr int kMuBytes = 64;
|
|
57
|
+
constexpr int kRhoPrimeBytes = 64;
|
|
58
|
+
|
|
59
|
+
// 2^23 - 2^13 + 1
|
|
60
|
+
constexpr uint32_t kPrime = 8380417;
|
|
61
|
+
// Inverse of -kPrime modulo 2^32
|
|
62
|
+
constexpr uint32_t kPrimeNegInverse = 4236238847;
|
|
63
|
+
constexpr int kDroppedBits = 13;
|
|
64
|
+
constexpr uint32_t kHalfPrime = (kPrime - 1) / 2;
|
|
65
|
+
// 256^-1 ⋅ R² mod kPrime. This is not 256^-1 in Montgomery form, but 256^-1
|
|
66
|
+
// doubly-converted to Montgomery form.
|
|
67
|
+
constexpr uint32_t kInverseDegreeDoubleMontgomery = 41978;
|
|
68
|
+
|
|
69
|
+
// Constants that vary depending on ML-DSA size.
|
|
70
|
+
//
|
|
71
|
+
// These are implemented as templates which take the K parameter to distinguish
|
|
72
|
+
// the ML-DSA sizes.
|
|
73
|
+
|
|
74
|
+
template <int K>
|
|
75
|
+
constexpr size_t public_key_bytes() {
|
|
76
|
+
if constexpr (K == 6) {
|
|
77
|
+
return MLDSA65_PUBLIC_KEY_BYTES;
|
|
78
|
+
} else if constexpr (K == 8) {
|
|
79
|
+
return MLDSA87_PUBLIC_KEY_BYTES;
|
|
80
|
+
} else if constexpr (K == 4) {
|
|
81
|
+
return MLDSA44_PUBLIC_KEY_BYTES;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
template <int K>
|
|
86
|
+
constexpr size_t signature_bytes() {
|
|
87
|
+
if constexpr (K == 6) {
|
|
88
|
+
return MLDSA65_SIGNATURE_BYTES;
|
|
89
|
+
} else if constexpr (K == 8) {
|
|
90
|
+
return MLDSA87_SIGNATURE_BYTES;
|
|
91
|
+
} else if constexpr (K == 4) {
|
|
92
|
+
return MLDSA44_SIGNATURE_BYTES;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
template <int K>
|
|
97
|
+
constexpr int tau() {
|
|
98
|
+
if constexpr (K == 6) {
|
|
99
|
+
return 49;
|
|
100
|
+
} else if constexpr (K == 8) {
|
|
101
|
+
return 60;
|
|
102
|
+
} else if constexpr (K == 4) {
|
|
103
|
+
return 39;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
template <int K>
|
|
108
|
+
constexpr int lambda_bytes() {
|
|
109
|
+
if constexpr (K == 6) {
|
|
110
|
+
return 192 / 8;
|
|
111
|
+
} else if constexpr (K == 8) {
|
|
112
|
+
return 256 / 8;
|
|
113
|
+
} else if constexpr (K == 4) {
|
|
114
|
+
return 128 / 8;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
template <int K>
|
|
119
|
+
constexpr int gamma1_bits() {
|
|
120
|
+
if constexpr (K == 6 || K == 8) {
|
|
121
|
+
return 19;
|
|
122
|
+
} else if constexpr (K == 4) {
|
|
123
|
+
return 17;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
template <int K>
|
|
128
|
+
constexpr int gamma1() {
|
|
129
|
+
return 1 << gamma1_bits<K>();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
template <int K>
|
|
133
|
+
constexpr int scalar_le_gamma1_bytes() {
|
|
134
|
+
return ((gamma1_bits<K>() + 1) * kDegree) / 8;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
template <int K>
|
|
138
|
+
constexpr uint32_t w1_coeffs_bits() {
|
|
139
|
+
if constexpr (K == 6 || K == 8) {
|
|
140
|
+
return 4;
|
|
141
|
+
} else if constexpr (K == 4) {
|
|
142
|
+
return 6;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
template <int K>
|
|
147
|
+
constexpr uint32_t w1_scalar_bytes() {
|
|
148
|
+
return (w1_coeffs_bits<K>() * kDegree) / 8;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
template <int K>
|
|
152
|
+
constexpr uint32_t w1_bytes() {
|
|
153
|
+
return w1_scalar_bytes<K>() * K;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
template <int K>
|
|
157
|
+
constexpr uint32_t prime_minus_one_over_gamma2() {
|
|
158
|
+
if constexpr (K == 6 || K == 8) {
|
|
159
|
+
return 32;
|
|
160
|
+
} else if constexpr (K == 4) {
|
|
161
|
+
return 88;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
template <int K>
|
|
166
|
+
constexpr uint32_t gamma2() {
|
|
167
|
+
return (kPrime - 1) / prime_minus_one_over_gamma2<K>();
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
template <int K>
|
|
171
|
+
constexpr int beta() {
|
|
172
|
+
if constexpr (K == 6) {
|
|
173
|
+
return 196;
|
|
174
|
+
} else if constexpr (K == 8) {
|
|
175
|
+
return 120;
|
|
176
|
+
} else if constexpr (K == 4) {
|
|
177
|
+
return 78;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
template <int K>
|
|
182
|
+
constexpr int omega() {
|
|
183
|
+
if constexpr (K == 6) {
|
|
184
|
+
return 55;
|
|
185
|
+
} else if constexpr (K == 8) {
|
|
186
|
+
return 75;
|
|
187
|
+
} else if constexpr (K == 4) {
|
|
188
|
+
return 80;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
template <int K>
|
|
193
|
+
constexpr int eta() {
|
|
194
|
+
if constexpr (K == 6) {
|
|
195
|
+
return 4;
|
|
196
|
+
} else if constexpr (K == 8 || K == 4) {
|
|
197
|
+
return 2;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
template <int K>
|
|
202
|
+
constexpr int plus_minus_eta_bitlen() {
|
|
203
|
+
if constexpr (K == 6) {
|
|
204
|
+
return 4;
|
|
205
|
+
} else if constexpr (K == 8 || K == 4) {
|
|
206
|
+
return 3;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Fundamental types.
|
|
211
|
+
|
|
212
|
+
struct scalar {
|
|
213
|
+
uint32_t c[kDegree];
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
template <int K>
|
|
217
|
+
struct vector {
|
|
218
|
+
scalar v[K];
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
template <int K, int L>
|
|
222
|
+
struct matrix {
|
|
223
|
+
scalar v[K][L];
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
/* Arithmetic */
|
|
227
|
+
|
|
228
|
+
// This bit of Python will be referenced in some of the following comments:
|
|
229
|
+
//
|
|
230
|
+
// q = 8380417
|
|
231
|
+
// # Inverse of -q modulo 2^32
|
|
232
|
+
// q_neg_inverse = 4236238847
|
|
233
|
+
// # 2^64 modulo q
|
|
234
|
+
// montgomery_square = 2365951
|
|
235
|
+
//
|
|
236
|
+
// def bitreverse(i):
|
|
237
|
+
// ret = 0
|
|
238
|
+
// for n in range(8):
|
|
239
|
+
// bit = i & 1
|
|
240
|
+
// ret <<= 1
|
|
241
|
+
// ret |= bit
|
|
242
|
+
// i >>= 1
|
|
243
|
+
// return ret
|
|
244
|
+
//
|
|
245
|
+
// def montgomery_reduce(x):
|
|
246
|
+
// a = (x * q_neg_inverse) % 2**32
|
|
247
|
+
// b = x + a * q
|
|
248
|
+
// assert b & 0xFFFF_FFFF == 0
|
|
249
|
+
// c = b >> 32
|
|
250
|
+
// assert c < q
|
|
251
|
+
// return c
|
|
252
|
+
//
|
|
253
|
+
// def montgomery_transform(x):
|
|
254
|
+
// return montgomery_reduce(x * montgomery_square)
|
|
255
|
+
|
|
256
|
+
// kNTTRootsMontgomery = [
|
|
257
|
+
// montgomery_transform(pow(1753, bitreverse(i), q)) for i in range(256)
|
|
258
|
+
// ]
|
|
259
|
+
static const uint32_t kNTTRootsMontgomery[256] = {
|
|
260
|
+
4193792, 25847, 5771523, 7861508, 237124, 7602457, 7504169, 466468,
|
|
261
|
+
1826347, 2353451, 8021166, 6288512, 3119733, 5495562, 3111497, 2680103,
|
|
262
|
+
2725464, 1024112, 7300517, 3585928, 7830929, 7260833, 2619752, 6271868,
|
|
263
|
+
6262231, 4520680, 6980856, 5102745, 1757237, 8360995, 4010497, 280005,
|
|
264
|
+
2706023, 95776, 3077325, 3530437, 6718724, 4788269, 5842901, 3915439,
|
|
265
|
+
4519302, 5336701, 3574422, 5512770, 3539968, 8079950, 2348700, 7841118,
|
|
266
|
+
6681150, 6736599, 3505694, 4558682, 3507263, 6239768, 6779997, 3699596,
|
|
267
|
+
811944, 531354, 954230, 3881043, 3900724, 5823537, 2071892, 5582638,
|
|
268
|
+
4450022, 6851714, 4702672, 5339162, 6927966, 3475950, 2176455, 6795196,
|
|
269
|
+
7122806, 1939314, 4296819, 7380215, 5190273, 5223087, 4747489, 126922,
|
|
270
|
+
3412210, 7396998, 2147896, 2715295, 5412772, 4686924, 7969390, 5903370,
|
|
271
|
+
7709315, 7151892, 8357436, 7072248, 7998430, 1349076, 1852771, 6949987,
|
|
272
|
+
5037034, 264944, 508951, 3097992, 44288, 7280319, 904516, 3958618,
|
|
273
|
+
4656075, 8371839, 1653064, 5130689, 2389356, 8169440, 759969, 7063561,
|
|
274
|
+
189548, 4827145, 3159746, 6529015, 5971092, 8202977, 1315589, 1341330,
|
|
275
|
+
1285669, 6795489, 7567685, 6940675, 5361315, 4499357, 4751448, 3839961,
|
|
276
|
+
2091667, 3407706, 2316500, 3817976, 5037939, 2244091, 5933984, 4817955,
|
|
277
|
+
266997, 2434439, 7144689, 3513181, 4860065, 4621053, 7183191, 5187039,
|
|
278
|
+
900702, 1859098, 909542, 819034, 495491, 6767243, 8337157, 7857917,
|
|
279
|
+
7725090, 5257975, 2031748, 3207046, 4823422, 7855319, 7611795, 4784579,
|
|
280
|
+
342297, 286988, 5942594, 4108315, 3437287, 5038140, 1735879, 203044,
|
|
281
|
+
2842341, 2691481, 5790267, 1265009, 4055324, 1247620, 2486353, 1595974,
|
|
282
|
+
4613401, 1250494, 2635921, 4832145, 5386378, 1869119, 1903435, 7329447,
|
|
283
|
+
7047359, 1237275, 5062207, 6950192, 7929317, 1312455, 3306115, 6417775,
|
|
284
|
+
7100756, 1917081, 5834105, 7005614, 1500165, 777191, 2235880, 3406031,
|
|
285
|
+
7838005, 5548557, 6709241, 6533464, 5796124, 4656147, 594136, 4603424,
|
|
286
|
+
6366809, 2432395, 2454455, 8215696, 1957272, 3369112, 185531, 7173032,
|
|
287
|
+
5196991, 162844, 1616392, 3014001, 810149, 1652634, 4686184, 6581310,
|
|
288
|
+
5341501, 3523897, 3866901, 269760, 2213111, 7404533, 1717735, 472078,
|
|
289
|
+
7953734, 1723600, 6577327, 1910376, 6712985, 7276084, 8119771, 4546524,
|
|
290
|
+
5441381, 6144432, 7959518, 6094090, 183443, 7403526, 1612842, 4834730,
|
|
291
|
+
7826001, 3919660, 8332111, 7018208, 3937738, 1400424, 7534263, 1976782};
|
|
292
|
+
|
|
293
|
+
// Reduces x mod kPrime in constant time, where 0 <= x < 2*kPrime.
|
|
294
|
+
inline uint32_t reduce_once(uint32_t x) {
|
|
295
|
+
declassify_assert(x < 2 * kPrime);
|
|
296
|
+
// return x < kPrime ? x : x - kPrime;
|
|
297
|
+
const uint32_t subtracted = x - kPrime;
|
|
298
|
+
uint32_t mask = 0u - (subtracted >> 31);
|
|
299
|
+
// Although this is a constant-time select, we omit a value barrier here.
|
|
300
|
+
// Value barriers impede auto-vectorization (likely because it forces the
|
|
301
|
+
// value to transit through a general-purpose register). This is a difference
|
|
302
|
+
// of 1.4x to 1.5x in signing performance.
|
|
303
|
+
//
|
|
304
|
+
// We usually add value barriers to selects because Clang turns consecutive
|
|
305
|
+
// selects with the same condition into a branch instead of CMOV/CSEL. This
|
|
306
|
+
// condition does not occur in ML-DSA, so omitting it seems to be generally
|
|
307
|
+
// safe. However, see `coefficient_from_nibble`.
|
|
308
|
+
return (mask & x) | (~mask & subtracted);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// reduce_from_u32 returns `x mod kPrime`. `x` can be any `uint32_t`.
|
|
312
|
+
inline uint32_t reduce_from_u32(uint32_t x) {
|
|
313
|
+
// kPrime is 2^23 - 2^13 + 1. We first split `x` into the upper 9 bits and the
|
|
314
|
+
// lower 23 bits:
|
|
315
|
+
uint32_t hi = x >> 23, lo = x & ((uint32_t{1} << 23) - 1);
|
|
316
|
+
// 2^23 = 2^13 - 1 mod kPrime
|
|
317
|
+
// x = hi * 2^23 + lo
|
|
318
|
+
// = hi * 2^13 - hi + lo mod kPrime
|
|
319
|
+
//
|
|
320
|
+
// This value does not overflow and is below 2 * kPrime. We can `reduce_once`.
|
|
321
|
+
static constexpr uint32_t kMaxHi = UINT32_MAX >> 23;
|
|
322
|
+
static constexpr uint32_t kMaxLo = (uint32_t{1} << 23) - 1;
|
|
323
|
+
static_assert((kMaxHi << 13) - kMaxHi + kMaxLo < 2 * kPrime);
|
|
324
|
+
return reduce_once((hi << 13) - hi + lo);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// Returns the absolute value in constant time, interpreting the high bit as a
|
|
328
|
+
// sign bit.
|
|
329
|
+
inline uint32_t abs_signed(uint32_t x) {
|
|
330
|
+
// return is_negative(x) ? -x : x;
|
|
331
|
+
uint32_t mask = 0u - (x >> 31);
|
|
332
|
+
return constant_time_select_32(mask, 0u - x, x);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// Returns the absolute value modulo kPrime.
|
|
336
|
+
inline uint32_t abs_mod_prime(uint32_t x) {
|
|
337
|
+
declassify_assert(x < kPrime);
|
|
338
|
+
// return x <= kHalfPrime ? x : kPrime - x;
|
|
339
|
+
uint32_t mask = x - kHalfPrime - 1;
|
|
340
|
+
mask = 0u - (mask >> 31);
|
|
341
|
+
return constant_time_select_32(mask, x, kPrime - x);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// Returns the maximum of two values in constant time. Each value must be less
|
|
345
|
+
// than kPrime.
|
|
346
|
+
inline uint32_t maximum_reduced(uint32_t x, uint32_t y) {
|
|
347
|
+
declassify_assert(x < kPrime);
|
|
348
|
+
declassify_assert(y < kPrime);
|
|
349
|
+
// return x < y ? y : x;
|
|
350
|
+
uint32_t mask = x - y;
|
|
351
|
+
mask = 0u - (mask >> 31);
|
|
352
|
+
return constant_time_select_32(mask, y, x);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
inline uint32_t mod_sub(uint32_t a, uint32_t b) {
|
|
356
|
+
declassify_assert(a < kPrime);
|
|
357
|
+
declassify_assert(b < kPrime);
|
|
358
|
+
uint32_t r = a - b;
|
|
359
|
+
// return r < 0 ? r + kPrime : r;
|
|
360
|
+
uint32_t mask = 0u - (r >> 31);
|
|
361
|
+
// See `reduce_once` for why this does not have a value barrier.
|
|
362
|
+
return (mask & (r + kPrime)) | (~mask & r);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
inline void scalar_add(scalar *out, const scalar *lhs, const scalar *rhs) {
|
|
366
|
+
for (int i = 0; i < kDegree; i++) {
|
|
367
|
+
out->c[i] = reduce_once(lhs->c[i] + rhs->c[i]);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
inline void scalar_sub(scalar *out, const scalar *lhs, const scalar *rhs) {
|
|
372
|
+
for (int i = 0; i < kDegree; i++) {
|
|
373
|
+
out->c[i] = mod_sub(lhs->c[i], rhs->c[i]);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// reduce_montgomery_partial returns a number equivalent to x * R^-1 mod kPrime.
|
|
378
|
+
// The output is less than 2 * kPrime. `x` must be at most kPrime * 2^32.
|
|
379
|
+
inline uint32_t reduce_montgomery_partial(uint64_t x) {
|
|
380
|
+
declassify_assert(x <= ((uint64_t)kPrime << 32));
|
|
381
|
+
uint64_t a = (uint32_t)x * kPrimeNegInverse;
|
|
382
|
+
uint64_t b = x + a * kPrime;
|
|
383
|
+
declassify_assert((b & 0xffffffff) == 0);
|
|
384
|
+
return b >> 32;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// reduce_montgomery returns x * R^-1 mod kPrime, fully reduced. `x` must be at
|
|
388
|
+
// most kPrime * 2^32.
|
|
389
|
+
inline uint32_t reduce_montgomery(uint64_t x) {
|
|
390
|
+
return reduce_once(reduce_montgomery_partial(x));
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// Montgomery-multiply two scalars in the number theoretically transformed
|
|
394
|
+
// state. Each term gains an extra R^-1 term, which is expected to be canceled
|
|
395
|
+
// by `scalar_inverse_ntt_montgomery`.
|
|
396
|
+
inline void scalar_mult_montgomery(scalar *out, const scalar *lhs,
|
|
397
|
+
const scalar *rhs) {
|
|
398
|
+
for (int i = 0; i < kDegree; i++) {
|
|
399
|
+
out->c[i] = reduce_montgomery((uint64_t)lhs->c[i] * (uint64_t)rhs->c[i]);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// In place number theoretic transform of a given scalar.
|
|
404
|
+
//
|
|
405
|
+
// FIPS 204, Algorithm 41 (`NTT`).
|
|
406
|
+
inline void scalar_ntt(scalar *s) {
|
|
407
|
+
// Manually unrolled loop to maximize vectorization.
|
|
408
|
+
//
|
|
409
|
+
// Intermediate values of `s` are not fully reduced. `ITER` writes to every
|
|
410
|
+
// element of `s` exactly once. Each write adds less than 2*kPrime to some
|
|
411
|
+
// value from the previous iteration. After eight iterations, each element
|
|
412
|
+
// will be less than 17*kPrime. This fits in `uint32_t`, so we never overflow.
|
|
413
|
+
#define ITER(step, offset) \
|
|
414
|
+
{ \
|
|
415
|
+
int k = 0; \
|
|
416
|
+
for (int i = 0; i < step; i++) { \
|
|
417
|
+
const uint32_t step_root = kNTTRootsMontgomery[step + i]; \
|
|
418
|
+
for (int j = k; j < k + offset; j++) { \
|
|
419
|
+
uint32_t even = s->c[j]; \
|
|
420
|
+
/* `reduce_montgomery_partial` works on values up to kPrime*R. \
|
|
421
|
+
* `step_root < kPrime` because it's static data. `s->c[...] < R` \
|
|
422
|
+
* because it's 32-bit. */ \
|
|
423
|
+
uint32_t odd = reduce_montgomery_partial(uint64_t{step_root} * \
|
|
424
|
+
uint64_t{s->c[j + offset]}); \
|
|
425
|
+
s->c[j] = even + odd; \
|
|
426
|
+
s->c[j + offset] = even + 2 * kPrime - odd; \
|
|
427
|
+
} \
|
|
428
|
+
k += 2 * offset; \
|
|
429
|
+
} \
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
ITER(1, 128)
|
|
433
|
+
ITER(2, 64)
|
|
434
|
+
ITER(4, 32)
|
|
435
|
+
ITER(8, 16)
|
|
436
|
+
ITER(16, 8)
|
|
437
|
+
ITER(32, 4)
|
|
438
|
+
ITER(64, 2)
|
|
439
|
+
ITER(128, 1)
|
|
440
|
+
static_assert(kDegree == 256);
|
|
441
|
+
#undef ITER
|
|
442
|
+
|
|
443
|
+
// Now `s` is correct but the elements are not fully reduced. Reduce them.
|
|
444
|
+
for (int i = 0; i < kDegree; i++) {
|
|
445
|
+
s->c[i] = reduce_from_u32(s->c[i]);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
// In place inverse number theoretic transform of a given scalar, but with each
|
|
450
|
+
// term multiplied by an extra factor of R. This is function is intended to be
|
|
451
|
+
// used with products that have gone through `reduce_montgomery` one extra time,
|
|
452
|
+
// so the extra R^-1 term is canceled out.
|
|
453
|
+
//
|
|
454
|
+
// FIPS 204, Algorithm 42 (`NTT^-1`).
|
|
455
|
+
inline void scalar_inverse_ntt_montgomery(scalar *s) {
|
|
456
|
+
// Manually unrolled loop to maximize vectorization.
|
|
457
|
+
//
|
|
458
|
+
// Intermediate values of `s` are not fully reduced. `ITER` writes
|
|
459
|
+
// to every element of `s` exactly once. Each write either adds two values
|
|
460
|
+
// from the previous iteration, or is at most 2 * kPrime. After eight
|
|
461
|
+
// iterations, each element will be less than 2⁸ * kPrime = 256 * kPrime.
|
|
462
|
+
// This fits in `uint32_t`, so we never overflow.
|
|
463
|
+
#define ITER(step, offset) \
|
|
464
|
+
{ \
|
|
465
|
+
int k = 0; \
|
|
466
|
+
for (int i = 0; i < step; i++) { \
|
|
467
|
+
const uint32_t step_root = \
|
|
468
|
+
kPrime - kNTTRootsMontgomery[step + (step - 1 - i)]; \
|
|
469
|
+
for (int j = k; j < k + offset; j++) { \
|
|
470
|
+
uint32_t even = s->c[j]; \
|
|
471
|
+
uint32_t odd = s->c[j + offset]; \
|
|
472
|
+
s->c[j] = odd + even; \
|
|
473
|
+
/* `reduce_montgomery_partial` works on values up to kPrime*R. \
|
|
474
|
+
* `step_root < kPrime` because it's static data. The other term is \
|
|
475
|
+
* less than R because it's 32-bit, and does not overflow because \
|
|
476
|
+
* `odd` is at most 128 * kPrime per the above. */ \
|
|
477
|
+
s->c[j + offset] = reduce_montgomery_partial( \
|
|
478
|
+
uint64_t{step_root} * uint64_t{128 * kPrime + even - odd}); \
|
|
479
|
+
} \
|
|
480
|
+
k += 2 * offset; \
|
|
481
|
+
} \
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
ITER(128, 1)
|
|
485
|
+
ITER(64, 2)
|
|
486
|
+
ITER(32, 4)
|
|
487
|
+
ITER(16, 8)
|
|
488
|
+
ITER(8, 16)
|
|
489
|
+
ITER(4, 32)
|
|
490
|
+
ITER(2, 64)
|
|
491
|
+
ITER(1, 128)
|
|
492
|
+
static_assert(kDegree == 256);
|
|
493
|
+
#undef ITER
|
|
494
|
+
|
|
495
|
+
// `kInverseDegreeDoubleMontgomery` has been double-converted to Montgomery
|
|
496
|
+
// form, so the result is an extra R term in the final result. This also fully
|
|
497
|
+
// reduces the partially-reduced values above.
|
|
498
|
+
for (int i = 0; i < kDegree; i++) {
|
|
499
|
+
s->c[i] = reduce_montgomery(uint64_t{s->c[i]} *
|
|
500
|
+
uint64_t{kInverseDegreeDoubleMontgomery});
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
template <int X>
|
|
505
|
+
inline void vector_zero(vector<X> *out) {
|
|
506
|
+
OPENSSL_memset(out, 0, sizeof(*out));
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
template <int X>
|
|
510
|
+
inline void vector_add(vector<X> *out, const vector<X> *lhs,
|
|
511
|
+
const vector<X> *rhs) {
|
|
512
|
+
for (int i = 0; i < X; i++) {
|
|
513
|
+
scalar_add(&out->v[i], &lhs->v[i], &rhs->v[i]);
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
template <int X>
|
|
518
|
+
inline void vector_sub(vector<X> *out, const vector<X> *lhs,
|
|
519
|
+
const vector<X> *rhs) {
|
|
520
|
+
for (int i = 0; i < X; i++) {
|
|
521
|
+
scalar_sub(&out->v[i], &lhs->v[i], &rhs->v[i]);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
template <int X>
|
|
526
|
+
inline void vector_mult_scalar_montgomery(vector<X> *out, const vector<X> *lhs,
|
|
527
|
+
const scalar *rhs) {
|
|
528
|
+
for (int i = 0; i < X; i++) {
|
|
529
|
+
scalar_mult_montgomery(&out->v[i], &lhs->v[i], rhs);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
template <int X>
|
|
534
|
+
inline void vector_ntt(vector<X> *a) {
|
|
535
|
+
for (int i = 0; i < X; i++) {
|
|
536
|
+
scalar_ntt(&a->v[i]);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
template <int X>
|
|
541
|
+
inline void vector_inverse_ntt_montgomery(vector<X> *a) {
|
|
542
|
+
for (int i = 0; i < X; i++) {
|
|
543
|
+
scalar_inverse_ntt_montgomery(&a->v[i]);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
template <int K, int L>
|
|
548
|
+
inline void matrix_mult_montgomery(vector<K> *out, const matrix<K, L> *m,
|
|
549
|
+
const vector<L> *a) {
|
|
550
|
+
vector_zero(out);
|
|
551
|
+
for (int i = 0; i < K; i++) {
|
|
552
|
+
for (int j = 0; j < L; j++) {
|
|
553
|
+
scalar product;
|
|
554
|
+
scalar_mult_montgomery(&product, &m->v[i][j], &a->v[j]);
|
|
555
|
+
scalar_add(&out->v[i], &out->v[i], &product);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/* Rounding & hints */
|
|
561
|
+
|
|
562
|
+
// FIPS 204, Algorithm 35 (`Power2Round`).
|
|
563
|
+
inline void power2_round(uint32_t *r1, uint32_t *r0, uint32_t r) {
|
|
564
|
+
*r1 = r >> kDroppedBits;
|
|
565
|
+
*r0 = r - (*r1 << kDroppedBits);
|
|
566
|
+
|
|
567
|
+
uint32_t r0_adjusted = mod_sub(*r0, 1 << kDroppedBits);
|
|
568
|
+
uint32_t r1_adjusted = *r1 + 1;
|
|
569
|
+
|
|
570
|
+
// Mask is set iff r0 > 2^(dropped_bits - 1).
|
|
571
|
+
crypto_word_t mask =
|
|
572
|
+
constant_time_lt_w((uint32_t)(1 << (kDroppedBits - 1)), *r0);
|
|
573
|
+
// r0 = mask ? r0_adjusted : r0
|
|
574
|
+
*r0 = constant_time_select_32(mask, r0_adjusted, *r0);
|
|
575
|
+
// r1 = mask ? r1_adjusted : r1
|
|
576
|
+
*r1 = constant_time_select_32(mask, r1_adjusted, *r1);
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
// Scale back previously rounded value.
|
|
580
|
+
inline void scale_power2_round(uint32_t *out, uint32_t r1) {
|
|
581
|
+
// Pre-condition: 0 ≤ r1 ≤ 2^10 - 1
|
|
582
|
+
assert(r1 < (1u << 10));
|
|
583
|
+
|
|
584
|
+
*out = r1 << kDroppedBits;
|
|
585
|
+
|
|
586
|
+
// Post-condition: 0 ≤ out ≤ 2^23 - 2^13 = kPrime - 1
|
|
587
|
+
assert(*out < kPrime);
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
// FIPS 204, Algorithm 37 (`HighBits`).
|
|
591
|
+
template <int K>
|
|
592
|
+
inline uint32_t high_bits(uint32_t x) {
|
|
593
|
+
// Reference description (given 0 <= x < q):
|
|
594
|
+
//
|
|
595
|
+
// ```
|
|
596
|
+
// int32_t r0 = x mod+- (2 * gamma2);
|
|
597
|
+
// if (x - r0 == q - 1) {
|
|
598
|
+
// return 0;
|
|
599
|
+
// } else {
|
|
600
|
+
// return (x - r0) / (2 * gamma2);
|
|
601
|
+
// }
|
|
602
|
+
// ```
|
|
603
|
+
//
|
|
604
|
+
uint32_t r1 = (x + 127) >> 7;
|
|
605
|
+
if constexpr (prime_minus_one_over_gamma2<K>() == 32) {
|
|
606
|
+
// Below is the formula taken from the reference implementation.
|
|
607
|
+
//
|
|
608
|
+
// Here, Gamma2 == 2^18 - 2^8
|
|
609
|
+
// This returns ((ceil(x / 2^7) ⋅ (2^10 + 1) + 2^21) / 2^22) mod 2^4
|
|
610
|
+
r1 = (r1 * 1025 + (1 << 21)) >> 22;
|
|
611
|
+
r1 &= 15;
|
|
612
|
+
} else if constexpr (prime_minus_one_over_gamma2<K>() == 88) {
|
|
613
|
+
// 1488/2^24 is close enough to 1/1488 so that r1 becomes x/(2 gamma2)
|
|
614
|
+
// rounded down.
|
|
615
|
+
r1 = (r1 * 11275 + (1 << 23)) >> 24;
|
|
616
|
+
|
|
617
|
+
// For corner-case r1 = (Q-1)/(2 gamma2) = 44, we have to set r1=0.
|
|
618
|
+
r1 ^= ((uint32_t)(((int32_t)(43 - r1)) >> 31)) & r1;
|
|
619
|
+
}
|
|
620
|
+
return r1;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
// FIPS 204, Algorithm 36 (`Decompose`).
|
|
624
|
+
template <int K>
|
|
625
|
+
inline void decompose(uint32_t *r1, int32_t *r0, uint32_t r) {
|
|
626
|
+
*r1 = high_bits<K>(r);
|
|
627
|
+
|
|
628
|
+
*r0 = r;
|
|
629
|
+
*r0 -= *r1 * 2 * (int32_t)gamma2<K>();
|
|
630
|
+
*r0 -= (((int32_t)kHalfPrime - *r0) >> 31) & (int32_t)kPrime;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
// FIPS 204, Algorithm 38 (`LowBits`).
|
|
634
|
+
template <int K>
|
|
635
|
+
inline int32_t low_bits(uint32_t x) {
|
|
636
|
+
uint32_t r1;
|
|
637
|
+
int32_t r0;
|
|
638
|
+
decompose<K>(&r1, &r0, x);
|
|
639
|
+
return r0;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
// FIPS 204, Algorithm 39 (`MakeHint`).
|
|
643
|
+
//
|
|
644
|
+
// In the spec this takes two arguments, z and r, and is called with
|
|
645
|
+
// z = -ct0
|
|
646
|
+
// r = w - cs2 + ct0
|
|
647
|
+
//
|
|
648
|
+
// It then computes HighBits (algorithm 37) of z and z+r. But z+r is just w -
|
|
649
|
+
// cs2, so this takes three arguments and saves an addition.
|
|
650
|
+
template <int K>
|
|
651
|
+
inline int32_t make_hint(uint32_t ct0, uint32_t cs2, uint32_t w) {
|
|
652
|
+
uint32_t r_plus_z = mod_sub(w, cs2);
|
|
653
|
+
uint32_t r = reduce_once(r_plus_z + ct0);
|
|
654
|
+
return high_bits<K>(r) != high_bits<K>(r_plus_z);
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
// FIPS 204, Algorithm 40 (`UseHint`).
|
|
658
|
+
template <int K>
|
|
659
|
+
inline uint32_t use_hint_vartime(uint32_t h, uint32_t r) {
|
|
660
|
+
uint32_t r1;
|
|
661
|
+
int32_t r0;
|
|
662
|
+
decompose<K>(&r1, &r0, r);
|
|
663
|
+
|
|
664
|
+
if (h) {
|
|
665
|
+
if constexpr (prime_minus_one_over_gamma2<K>() == 32) {
|
|
666
|
+
if (r0 > 0) {
|
|
667
|
+
// (Q-1)/(2 gamma2) = m = 16, thus `mod m` in the spec turns into
|
|
668
|
+
// `& 15`.
|
|
669
|
+
return (r1 + 1) & 15;
|
|
670
|
+
} else {
|
|
671
|
+
return (r1 - 1) & 15;
|
|
672
|
+
}
|
|
673
|
+
} else {
|
|
674
|
+
// m = 44
|
|
675
|
+
static_assert(prime_minus_one_over_gamma2<K>() == 88);
|
|
676
|
+
if (r0 > 0) {
|
|
677
|
+
if (r1 == 43) {
|
|
678
|
+
return 0;
|
|
679
|
+
} else {
|
|
680
|
+
return r1 + 1;
|
|
681
|
+
}
|
|
682
|
+
} else {
|
|
683
|
+
if (r1 == 0) {
|
|
684
|
+
return 43;
|
|
685
|
+
} else {
|
|
686
|
+
return r1 - 1;
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
return r1;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
inline void scalar_power2_round(scalar *s1, scalar *s0, const scalar *s) {
|
|
695
|
+
for (int i = 0; i < kDegree; i++) {
|
|
696
|
+
power2_round(&s1->c[i], &s0->c[i], s->c[i]);
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
inline void scalar_scale_power2_round(scalar *out, const scalar *in) {
|
|
701
|
+
for (int i = 0; i < kDegree; i++) {
|
|
702
|
+
scale_power2_round(&out->c[i], in->c[i]);
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
template <int K>
|
|
707
|
+
inline void scalar_high_bits(scalar *out, const scalar *in) {
|
|
708
|
+
for (int i = 0; i < kDegree; i++) {
|
|
709
|
+
out->c[i] = high_bits<K>(in->c[i]);
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
template <int K>
|
|
714
|
+
inline void scalar_low_bits(scalar *out, const scalar *in) {
|
|
715
|
+
for (int i = 0; i < kDegree; i++) {
|
|
716
|
+
out->c[i] = low_bits<K>(in->c[i]);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
inline void scalar_max(uint32_t *max, const scalar *s) {
|
|
721
|
+
for (int i = 0; i < kDegree; i++) {
|
|
722
|
+
uint32_t abs = abs_mod_prime(s->c[i]);
|
|
723
|
+
*max = maximum_reduced(*max, abs);
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
inline void scalar_max_signed(uint32_t *max, const scalar *s) {
|
|
728
|
+
for (int i = 0; i < kDegree; i++) {
|
|
729
|
+
uint32_t abs = abs_signed(s->c[i]);
|
|
730
|
+
*max = maximum_reduced(*max, abs);
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
template <int K>
|
|
735
|
+
inline void scalar_make_hint(scalar *out, const scalar *ct0, const scalar *cs2,
|
|
736
|
+
const scalar *w) {
|
|
737
|
+
for (int i = 0; i < kDegree; i++) {
|
|
738
|
+
out->c[i] = make_hint<K>(ct0->c[i], cs2->c[i], w->c[i]);
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
template <int K>
|
|
743
|
+
inline void scalar_use_hint_vartime(scalar *out, const scalar *h,
|
|
744
|
+
const scalar *r) {
|
|
745
|
+
for (int i = 0; i < kDegree; i++) {
|
|
746
|
+
out->c[i] = use_hint_vartime<K>(h->c[i], r->c[i]);
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
template <int X>
|
|
751
|
+
inline void vector_power2_round(vector<X> *t1, vector<X> *t0,
|
|
752
|
+
const vector<X> *t) {
|
|
753
|
+
for (int i = 0; i < X; i++) {
|
|
754
|
+
scalar_power2_round(&t1->v[i], &t0->v[i], &t->v[i]);
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
template <int X>
|
|
759
|
+
inline void vector_scale_power2_round(vector<X> *out, const vector<X> *in) {
|
|
760
|
+
for (int i = 0; i < X; i++) {
|
|
761
|
+
scalar_scale_power2_round(&out->v[i], &in->v[i]);
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
template <int K>
|
|
766
|
+
inline void vector_high_bits(vector<K> *out, const vector<K> *in) {
|
|
767
|
+
for (int i = 0; i < K; i++) {
|
|
768
|
+
scalar_high_bits<K>(&out->v[i], &in->v[i]);
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
template <int K>
|
|
773
|
+
inline void vector_low_bits(vector<K> *out, const vector<K> *in) {
|
|
774
|
+
for (int i = 0; i < K; i++) {
|
|
775
|
+
scalar_low_bits<K>(&out->v[i], &in->v[i]);
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
template <int X>
|
|
780
|
+
inline uint32_t vector_max(const vector<X> *a) {
|
|
781
|
+
uint32_t max = 0;
|
|
782
|
+
for (int i = 0; i < X; i++) {
|
|
783
|
+
scalar_max(&max, &a->v[i]);
|
|
784
|
+
}
|
|
785
|
+
return max;
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
template <int X>
|
|
789
|
+
inline uint32_t vector_max_signed(const vector<X> *a) {
|
|
790
|
+
uint32_t max = 0;
|
|
791
|
+
for (int i = 0; i < X; i++) {
|
|
792
|
+
scalar_max_signed(&max, &a->v[i]);
|
|
793
|
+
}
|
|
794
|
+
return max;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
// The input vector contains only zeroes and ones.
|
|
798
|
+
template <int X>
|
|
799
|
+
inline size_t vector_count_ones(const vector<X> *a) {
|
|
800
|
+
size_t count = 0;
|
|
801
|
+
for (int i = 0; i < X; i++) {
|
|
802
|
+
for (int j = 0; j < kDegree; j++) {
|
|
803
|
+
count += a->v[i].c[j];
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
return count;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
template <int K>
|
|
810
|
+
inline void vector_make_hint(vector<K> *out, const vector<K> *ct0,
|
|
811
|
+
const vector<K> *cs2, const vector<K> *w) {
|
|
812
|
+
for (int i = 0; i < K; i++) {
|
|
813
|
+
scalar_make_hint<K>(&out->v[i], &ct0->v[i], &cs2->v[i], &w->v[i]);
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
template <int K>
|
|
818
|
+
inline void vector_use_hint_vartime(vector<K> *out, const vector<K> *h,
|
|
819
|
+
const vector<K> *r) {
|
|
820
|
+
for (int i = 0; i < K; i++) {
|
|
821
|
+
scalar_use_hint_vartime<K>(&out->v[i], &h->v[i], &r->v[i]);
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
/* Bit packing */
|
|
826
|
+
|
|
827
|
+
template <int bits>
|
|
828
|
+
inline void scalar_encode(uint8_t *out, const scalar *s);
|
|
829
|
+
|
|
830
|
+
// FIPS 204, Algorithm 16 (`SimpleBitPack`). Specialized to bitlen(b) = 4.
|
|
831
|
+
template <>
|
|
832
|
+
inline void scalar_encode<4>(uint8_t out[128], const scalar *s) {
|
|
833
|
+
// Every two elements lands on a byte boundary.
|
|
834
|
+
static_assert(kDegree % 2 == 0, "kDegree must be a multiple of 2");
|
|
835
|
+
for (int i = 0; i < kDegree / 2; i++) {
|
|
836
|
+
uint32_t a = s->c[2 * i];
|
|
837
|
+
uint32_t b = s->c[2 * i + 1];
|
|
838
|
+
declassify_assert(a < 16);
|
|
839
|
+
declassify_assert(b < 16);
|
|
840
|
+
out[i] = a | (b << 4);
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
// FIPS 204, Algorithm 16 (`SimpleBitPack`). Specialized to bitlen(b) = 6.
|
|
845
|
+
template <>
|
|
846
|
+
inline void scalar_encode<6>(uint8_t out[192], const scalar *s) {
|
|
847
|
+
// Every four elements lands on a byte boundary.
|
|
848
|
+
static_assert(kDegree % 4 == 0, "kDegree must be a multiple of 4");
|
|
849
|
+
for (int i = 0; i < kDegree / 4; i++) {
|
|
850
|
+
uint32_t a = s->c[4 * i];
|
|
851
|
+
uint32_t b = s->c[4 * i + 1];
|
|
852
|
+
uint32_t c = s->c[4 * i + 2];
|
|
853
|
+
uint32_t d = s->c[4 * i + 3];
|
|
854
|
+
declassify_assert(a < 64);
|
|
855
|
+
declassify_assert(b < 64);
|
|
856
|
+
declassify_assert(c < 64);
|
|
857
|
+
declassify_assert(d < 64);
|
|
858
|
+
out[3 * i] = a | (b << 6);
|
|
859
|
+
out[3 * i + 1] = (b >> 2) | (c << 4);
|
|
860
|
+
out[3 * i + 2] = (c >> 4) | (d << 2);
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
// FIPS 204, Algorithm 16 (`SimpleBitPack`). Specialized to bitlen(b) = 10.
|
|
865
|
+
template <>
|
|
866
|
+
inline void scalar_encode<10>(uint8_t out[320], const scalar *s) {
|
|
867
|
+
// Every four elements lands on a byte boundary.
|
|
868
|
+
static_assert(kDegree % 4 == 0, "kDegree must be a multiple of 4");
|
|
869
|
+
for (int i = 0; i < kDegree / 4; i++) {
|
|
870
|
+
uint32_t a = s->c[4 * i];
|
|
871
|
+
uint32_t b = s->c[4 * i + 1];
|
|
872
|
+
uint32_t c = s->c[4 * i + 2];
|
|
873
|
+
uint32_t d = s->c[4 * i + 3];
|
|
874
|
+
declassify_assert(a < 1024);
|
|
875
|
+
declassify_assert(b < 1024);
|
|
876
|
+
declassify_assert(c < 1024);
|
|
877
|
+
declassify_assert(d < 1024);
|
|
878
|
+
out[5 * i] = (uint8_t)a;
|
|
879
|
+
out[5 * i + 1] = (uint8_t)((a >> 8) | (b << 2));
|
|
880
|
+
out[5 * i + 2] = (uint8_t)((b >> 6) | (c << 4));
|
|
881
|
+
out[5 * i + 3] = (uint8_t)((c >> 4) | (d << 6));
|
|
882
|
+
out[5 * i + 4] = (uint8_t)(d >> 2);
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
template <int bits, uint32_t max>
|
|
887
|
+
inline void scalar_encode_signed(uint8_t *out, const scalar *s);
|
|
888
|
+
|
|
889
|
+
// FIPS 204, Algorithm 17 (`BitPack`). Specialized to bitlen(a+b) = 4 and b = 4.
|
|
890
|
+
template <>
|
|
891
|
+
inline void scalar_encode_signed<4, 4>(uint8_t out[128], const scalar *s) {
|
|
892
|
+
// Every two elements lands on a byte boundary.
|
|
893
|
+
static_assert(kDegree % 2 == 0, "kDegree must be a multiple of 2");
|
|
894
|
+
for (int i = 0; i < kDegree / 2; i++) {
|
|
895
|
+
uint32_t a = mod_sub(4, s->c[2 * i]);
|
|
896
|
+
uint32_t b = mod_sub(4, s->c[2 * i + 1]);
|
|
897
|
+
declassify_assert(a < 16);
|
|
898
|
+
declassify_assert(b < 16);
|
|
899
|
+
out[i] = a | (b << 4);
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
// FIPS 204, Algorithm 17 (`BitPack`). Specialized to bitlen(a+b) = 3 and b = 2.
|
|
904
|
+
template <>
|
|
905
|
+
inline void scalar_encode_signed<3, 2>(uint8_t out[96], const scalar *s) {
|
|
906
|
+
static_assert(kDegree % 8 == 0, "kDegree must be a multiple of 8");
|
|
907
|
+
for (int i = 0; i < kDegree / 8; i++) {
|
|
908
|
+
uint32_t a = mod_sub(2, s->c[8 * i]);
|
|
909
|
+
uint32_t b = mod_sub(2, s->c[8 * i + 1]);
|
|
910
|
+
uint32_t c = mod_sub(2, s->c[8 * i + 2]);
|
|
911
|
+
uint32_t d = mod_sub(2, s->c[8 * i + 3]);
|
|
912
|
+
uint32_t e = mod_sub(2, s->c[8 * i + 4]);
|
|
913
|
+
uint32_t f = mod_sub(2, s->c[8 * i + 5]);
|
|
914
|
+
uint32_t g = mod_sub(2, s->c[8 * i + 6]);
|
|
915
|
+
uint32_t h = mod_sub(2, s->c[8 * i + 7]);
|
|
916
|
+
uint32_t v = (h << 21) | (g << 18) | (f << 15) | (e << 12) | (d << 9) |
|
|
917
|
+
(c << 6) | (b << 3) | a;
|
|
918
|
+
uint8_t v_bytes[sizeof(v)];
|
|
919
|
+
CRYPTO_store_u32_le(v_bytes, v);
|
|
920
|
+
OPENSSL_memcpy(&out[i * 3], v_bytes, 3);
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
// FIPS 204, Algorithm 17 (`BitPack`). Specialized to bitlen(a+b) = 13 and b =
|
|
925
|
+
// 2^12.
|
|
926
|
+
template <>
|
|
927
|
+
inline void scalar_encode_signed<13, (1u << 12)>(uint8_t out[416],
|
|
928
|
+
const scalar *s) {
|
|
929
|
+
static const uint32_t kMax = 1u << 12;
|
|
930
|
+
// Every two elements lands on a byte boundary.
|
|
931
|
+
static_assert(kDegree % 8 == 0, "kDegree must be a multiple of 8");
|
|
932
|
+
for (int i = 0; i < kDegree / 8; i++) {
|
|
933
|
+
uint32_t a = mod_sub(kMax, s->c[8 * i]);
|
|
934
|
+
uint32_t b = mod_sub(kMax, s->c[8 * i + 1]);
|
|
935
|
+
uint32_t c = mod_sub(kMax, s->c[8 * i + 2]);
|
|
936
|
+
uint32_t d = mod_sub(kMax, s->c[8 * i + 3]);
|
|
937
|
+
uint32_t e = mod_sub(kMax, s->c[8 * i + 4]);
|
|
938
|
+
uint32_t f = mod_sub(kMax, s->c[8 * i + 5]);
|
|
939
|
+
uint32_t g = mod_sub(kMax, s->c[8 * i + 6]);
|
|
940
|
+
uint32_t h = mod_sub(kMax, s->c[8 * i + 7]);
|
|
941
|
+
declassify_assert(a < (1u << 13));
|
|
942
|
+
declassify_assert(b < (1u << 13));
|
|
943
|
+
declassify_assert(c < (1u << 13));
|
|
944
|
+
declassify_assert(d < (1u << 13));
|
|
945
|
+
declassify_assert(e < (1u << 13));
|
|
946
|
+
declassify_assert(f < (1u << 13));
|
|
947
|
+
declassify_assert(g < (1u << 13));
|
|
948
|
+
declassify_assert(h < (1u << 13));
|
|
949
|
+
a |= b << 13;
|
|
950
|
+
a |= c << 26;
|
|
951
|
+
c >>= 6;
|
|
952
|
+
c |= d << 7;
|
|
953
|
+
c |= e << 20;
|
|
954
|
+
e >>= 12;
|
|
955
|
+
e |= f << 1;
|
|
956
|
+
e |= g << 14;
|
|
957
|
+
e |= h << 27;
|
|
958
|
+
h >>= 5;
|
|
959
|
+
CRYPTO_store_u32_le(&out[13 * i], a);
|
|
960
|
+
CRYPTO_store_u32_le(&out[13 * i + 4], c);
|
|
961
|
+
CRYPTO_store_u32_le(&out[13 * i + 8], e);
|
|
962
|
+
out[13 * i + 12] = static_cast<uint8_t>(h);
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
// FIPS 204, Algorithm 17 (`BitPack`). Specialized to bitlen(a+b) = 20 and b =
|
|
967
|
+
// 2^19.
|
|
968
|
+
template <>
|
|
969
|
+
inline void scalar_encode_signed<20, (1u << 19)>(uint8_t out[640],
|
|
970
|
+
const scalar *s) {
|
|
971
|
+
static const uint32_t kMax = 1u << 19;
|
|
972
|
+
// Every two elements lands on a byte boundary.
|
|
973
|
+
static_assert(kDegree % 4 == 0, "kDegree must be a multiple of 4");
|
|
974
|
+
for (int i = 0; i < kDegree / 4; i++) {
|
|
975
|
+
uint32_t a = mod_sub(kMax, s->c[4 * i]);
|
|
976
|
+
uint32_t b = mod_sub(kMax, s->c[4 * i + 1]);
|
|
977
|
+
uint32_t c = mod_sub(kMax, s->c[4 * i + 2]);
|
|
978
|
+
uint32_t d = mod_sub(kMax, s->c[4 * i + 3]);
|
|
979
|
+
declassify_assert(a < (1u << 20));
|
|
980
|
+
declassify_assert(b < (1u << 20));
|
|
981
|
+
declassify_assert(c < (1u << 20));
|
|
982
|
+
declassify_assert(d < (1u << 20));
|
|
983
|
+
a |= b << 20;
|
|
984
|
+
b >>= 12;
|
|
985
|
+
b |= c << 8;
|
|
986
|
+
b |= d << 28;
|
|
987
|
+
d >>= 4;
|
|
988
|
+
CRYPTO_store_u32_le(&out[10 * i], a);
|
|
989
|
+
CRYPTO_store_u32_le(&out[10 * i + 4], b);
|
|
990
|
+
CRYPTO_store_u16_le(&out[10 * i + 8], static_cast<uint16_t>(d));
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
// FIPS 204, Algorithm 17 (`BitPack`). Specialized to bitlen(a+b) = 18 and b =
|
|
995
|
+
// 2^17.
|
|
996
|
+
template <>
|
|
997
|
+
inline void scalar_encode_signed<18, (1u << 17)>(uint8_t out[576],
|
|
998
|
+
const scalar *s) {
|
|
999
|
+
static const uint32_t kMax = 1u << 17;
|
|
1000
|
+
static_assert(kDegree % 4 == 0, "kDegree must be a multiple of 4");
|
|
1001
|
+
for (int i = 0; i < kDegree / 4; i++) {
|
|
1002
|
+
uint32_t a = mod_sub(kMax, s->c[4 * i]);
|
|
1003
|
+
uint32_t b = mod_sub(kMax, s->c[4 * i + 1]);
|
|
1004
|
+
uint32_t c = mod_sub(kMax, s->c[4 * i + 2]);
|
|
1005
|
+
uint32_t d = mod_sub(kMax, s->c[4 * i + 3]);
|
|
1006
|
+
declassify_assert(a < (1u << 18));
|
|
1007
|
+
declassify_assert(b < (1u << 18));
|
|
1008
|
+
declassify_assert(c < (1u << 18));
|
|
1009
|
+
declassify_assert(d < (1u << 18));
|
|
1010
|
+
out[9 * i] = (uint8_t)a;
|
|
1011
|
+
out[9 * i + 1] = (uint8_t)(a >> 8);
|
|
1012
|
+
out[9 * i + 2] = (uint8_t)(a >> 16) | (uint8_t)(b << 2);
|
|
1013
|
+
out[9 * i + 3] = (uint8_t)(b >> 6);
|
|
1014
|
+
out[9 * i + 4] = (uint8_t)(b >> 14) | (uint8_t)(c << 4);
|
|
1015
|
+
out[9 * i + 5] = (uint8_t)(c >> 4);
|
|
1016
|
+
out[9 * i + 6] = (uint8_t)(c >> 12) | (uint8_t)(d << 6);
|
|
1017
|
+
out[9 * i + 7] = (uint8_t)(d >> 2);
|
|
1018
|
+
out[9 * i + 8] = (uint8_t)(d >> 10);
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
template <int bits>
|
|
1023
|
+
inline void scalar_decode(scalar *out, const uint8_t *in);
|
|
1024
|
+
|
|
1025
|
+
// FIPS 204, Algorithm 18 (`SimpleBitUnpack`). Specialized for bitlen(b) == 10.
|
|
1026
|
+
template <>
|
|
1027
|
+
inline void scalar_decode<10>(scalar *out, const uint8_t in[320]) {
|
|
1028
|
+
static_assert(kDegree % 4 == 0, "kDegree must be a multiple of 4");
|
|
1029
|
+
for (int i = 0; i < kDegree / 4; i++) {
|
|
1030
|
+
uint32_t v = CRYPTO_load_u32_le(&in[5 * i]);
|
|
1031
|
+
out->c[4 * i] = v & 0x3ff;
|
|
1032
|
+
out->c[4 * i + 1] = (v >> 10) & 0x3ff;
|
|
1033
|
+
out->c[4 * i + 2] = (v >> 20) & 0x3ff;
|
|
1034
|
+
out->c[4 * i + 3] = (v >> 30) | (((uint32_t)in[5 * i + 4]) << 2);
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
template <int bits, uint32_t max>
|
|
1039
|
+
inline int scalar_decode_signed(scalar *out, const uint8_t *in);
|
|
1040
|
+
|
|
1041
|
+
// FIPS 204, Algorithm 19 (`BitUnpack`). Specialized to bitlen(a+b) = 4 and b =
|
|
1042
|
+
// 4.
|
|
1043
|
+
template <>
|
|
1044
|
+
inline int scalar_decode_signed<4, 4>(scalar *out, const uint8_t in[128]) {
|
|
1045
|
+
static_assert(kDegree % 8 == 0, "kDegree must be a multiple of 8");
|
|
1046
|
+
for (int i = 0; i < kDegree / 8; i++) {
|
|
1047
|
+
uint32_t v = CRYPTO_load_u32_le(&in[4 * i]);
|
|
1048
|
+
// None of the nibbles may be >= 9. So if the MSB of any nibble is set, none
|
|
1049
|
+
// of the other bits may be set. First, select all the MSBs.
|
|
1050
|
+
const uint32_t msbs = v & 0x88888888u;
|
|
1051
|
+
// For each nibble where the MSB is set, form a mask of all the other bits.
|
|
1052
|
+
const uint32_t mask = (msbs >> 1) | (msbs >> 2) | (msbs >> 3);
|
|
1053
|
+
// A nibble is only out of range in the case of invalid input, in which case
|
|
1054
|
+
// it is okay to leak the value.
|
|
1055
|
+
if (constant_time_declassify_int((mask & v) != 0)) {
|
|
1056
|
+
return 0;
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
out->c[i * 8] = mod_sub(4, v & 15);
|
|
1060
|
+
out->c[i * 8 + 1] = mod_sub(4, (v >> 4) & 15);
|
|
1061
|
+
out->c[i * 8 + 2] = mod_sub(4, (v >> 8) & 15);
|
|
1062
|
+
out->c[i * 8 + 3] = mod_sub(4, (v >> 12) & 15);
|
|
1063
|
+
out->c[i * 8 + 4] = mod_sub(4, (v >> 16) & 15);
|
|
1064
|
+
out->c[i * 8 + 5] = mod_sub(4, (v >> 20) & 15);
|
|
1065
|
+
out->c[i * 8 + 6] = mod_sub(4, (v >> 24) & 15);
|
|
1066
|
+
out->c[i * 8 + 7] = mod_sub(4, v >> 28);
|
|
1067
|
+
}
|
|
1068
|
+
return 1;
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
// FIPS 204, Algorithm 19 (`BitUnpack`). Specialized to bitlen(a+b) = 3 and b =
|
|
1072
|
+
// 2.
|
|
1073
|
+
template <>
|
|
1074
|
+
inline int scalar_decode_signed<3, 2>(scalar *out, const uint8_t in[96]) {
|
|
1075
|
+
uint32_t v;
|
|
1076
|
+
uint8_t v_bytes[sizeof(v)] = {0};
|
|
1077
|
+
static_assert(kDegree % 8 == 0, "kDegree must be a multiple of 8");
|
|
1078
|
+
for (int i = 0; i < kDegree / 8; i++) {
|
|
1079
|
+
OPENSSL_memcpy(v_bytes, &in[3 * i], 3);
|
|
1080
|
+
v = CRYPTO_load_u32_le(v_bytes);
|
|
1081
|
+
// v contains 8, 3-bit values in the lower 24 bits. None of the values may
|
|
1082
|
+
// be >= 5. So if the MSB of any triple is set, none of the other bits may
|
|
1083
|
+
// be set. First, select all the MSBs.
|
|
1084
|
+
const uint32_t msbs = v & 000044444444u;
|
|
1085
|
+
// For each triple where the MSB is set, form a mask of all the other bits.
|
|
1086
|
+
const uint32_t mask = (msbs >> 1) | (msbs >> 2);
|
|
1087
|
+
// A triple is only out of range in the case of invalid input, in which case
|
|
1088
|
+
// it is okay to leak the value.
|
|
1089
|
+
if (constant_time_declassify_int((mask & v) != 0)) {
|
|
1090
|
+
return 0;
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
out->c[i * 8 + 0] = mod_sub(2, (v >> 0) & 7);
|
|
1094
|
+
out->c[i * 8 + 1] = mod_sub(2, (v >> 3) & 7);
|
|
1095
|
+
out->c[i * 8 + 2] = mod_sub(2, (v >> 6) & 7);
|
|
1096
|
+
out->c[i * 8 + 3] = mod_sub(2, (v >> 9) & 7);
|
|
1097
|
+
out->c[i * 8 + 4] = mod_sub(2, (v >> 12) & 7);
|
|
1098
|
+
out->c[i * 8 + 5] = mod_sub(2, (v >> 15) & 7);
|
|
1099
|
+
out->c[i * 8 + 6] = mod_sub(2, (v >> 18) & 7);
|
|
1100
|
+
out->c[i * 8 + 7] = mod_sub(2, v >> 21);
|
|
1101
|
+
}
|
|
1102
|
+
return 1;
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
// FIPS 204, Algorithm 19 (`BitUnpack`). Specialized to bitlen(a+b) = 13 and b =
|
|
1106
|
+
// 2^12.
|
|
1107
|
+
template <>
|
|
1108
|
+
inline int scalar_decode_signed<13, (1u << 12)>(scalar *out,
|
|
1109
|
+
const uint8_t in[416]) {
|
|
1110
|
+
static const uint32_t kMax = 1u << 12;
|
|
1111
|
+
static const uint32_t k13Bits = (1u << 13) - 1;
|
|
1112
|
+
static const uint32_t k7Bits = (1u << 7) - 1;
|
|
1113
|
+
|
|
1114
|
+
static_assert(kDegree % 8 == 0, "kDegree must be a multiple of 8");
|
|
1115
|
+
for (int i = 0; i < kDegree / 8; i++) {
|
|
1116
|
+
uint32_t a = CRYPTO_load_u32_le(&in[13 * i]);
|
|
1117
|
+
uint32_t b = CRYPTO_load_u32_le(&in[13 * i + 4]);
|
|
1118
|
+
uint32_t c = CRYPTO_load_u32_le(&in[13 * i + 8]);
|
|
1119
|
+
uint8_t d = in[13 * i + 12];
|
|
1120
|
+
|
|
1121
|
+
// It's not possible for a 13-bit number to be out of range when the max is
|
|
1122
|
+
// 2^12.
|
|
1123
|
+
out->c[i * 8] = mod_sub(kMax, a & k13Bits);
|
|
1124
|
+
out->c[i * 8 + 1] = mod_sub(kMax, (a >> 13) & k13Bits);
|
|
1125
|
+
out->c[i * 8 + 2] = mod_sub(kMax, (a >> 26) | ((b & k7Bits) << 6));
|
|
1126
|
+
out->c[i * 8 + 3] = mod_sub(kMax, (b >> 7) & k13Bits);
|
|
1127
|
+
out->c[i * 8 + 4] = mod_sub(kMax, (b >> 20) | ((c & 1) << 12));
|
|
1128
|
+
out->c[i * 8 + 5] = mod_sub(kMax, (c >> 1) & k13Bits);
|
|
1129
|
+
out->c[i * 8 + 6] = mod_sub(kMax, (c >> 14) & k13Bits);
|
|
1130
|
+
out->c[i * 8 + 7] = mod_sub(kMax, (c >> 27) | ((uint32_t)d) << 5);
|
|
1131
|
+
}
|
|
1132
|
+
return 1;
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
// FIPS 204, Algorithm 19 (`BitUnpack`). Specialized to bitlen(a+b) = 18 and b =
|
|
1136
|
+
// 2^17.
|
|
1137
|
+
template <>
|
|
1138
|
+
inline int scalar_decode_signed<18, (1u << 17)>(scalar *out,
|
|
1139
|
+
const uint8_t in[576]) {
|
|
1140
|
+
static const uint32_t kMax = 1u << 17;
|
|
1141
|
+
|
|
1142
|
+
static_assert(kDegree % 4 == 0, "kDegree must be a multiple of 4");
|
|
1143
|
+
for (int i = 0; i < kDegree / 4; i++) {
|
|
1144
|
+
uint32_t a = uint32_t{in[9 * i]} | (uint32_t{in[9 * i + 1]} << 8) |
|
|
1145
|
+
((uint32_t{in[9 * i + 2]} & 0x3) << 16);
|
|
1146
|
+
uint32_t b = (uint32_t{in[9 * i + 2]} >> 2) |
|
|
1147
|
+
(uint32_t{in[9 * i + 3]} << 6) |
|
|
1148
|
+
((uint32_t{in[9 * i + 4]} & 0xf) << 14);
|
|
1149
|
+
uint32_t c = (uint32_t{in[9 * i + 4]} >> 4) |
|
|
1150
|
+
(uint32_t{in[9 * i + 5]} << 4) |
|
|
1151
|
+
((uint32_t{in[9 * i + 6]} & 0x3f) << 12);
|
|
1152
|
+
uint32_t d = (uint32_t{in[9 * i + 6]} >> 6) |
|
|
1153
|
+
(uint32_t{in[9 * i + 7]} << 2) |
|
|
1154
|
+
(uint32_t{in[9 * i + 8]} << 10);
|
|
1155
|
+
|
|
1156
|
+
out->c[i * 4] = mod_sub(kMax, a);
|
|
1157
|
+
out->c[i * 4 + 1] = mod_sub(kMax, b);
|
|
1158
|
+
out->c[i * 4 + 2] = mod_sub(kMax, c);
|
|
1159
|
+
out->c[i * 4 + 3] = mod_sub(kMax, d);
|
|
1160
|
+
}
|
|
1161
|
+
return 1;
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1164
|
+
// FIPS 204, Algorithm 19 (`BitUnpack`). Specialized to bitlen(a+b) = 20 and b =
|
|
1165
|
+
// 2^19.
|
|
1166
|
+
template <>
|
|
1167
|
+
inline int scalar_decode_signed<20, (1u << 19)>(scalar *out,
|
|
1168
|
+
const uint8_t in[640]) {
|
|
1169
|
+
static const uint32_t kMax = 1u << 19;
|
|
1170
|
+
static const uint32_t k20Bits = (1u << 20) - 1;
|
|
1171
|
+
|
|
1172
|
+
static_assert(kDegree % 4 == 0, "kDegree must be a multiple of 4");
|
|
1173
|
+
for (int i = 0; i < kDegree / 4; i++) {
|
|
1174
|
+
uint32_t a = CRYPTO_load_u32_le(&in[10 * i]);
|
|
1175
|
+
uint32_t b = CRYPTO_load_u32_le(&in[10 * i + 4]);
|
|
1176
|
+
uint16_t c = CRYPTO_load_u16_le(&in[10 * i + 8]);
|
|
1177
|
+
|
|
1178
|
+
// It's not possible for a 20-bit number to be out of range when the max is
|
|
1179
|
+
// 2^19.
|
|
1180
|
+
out->c[i * 4] = mod_sub(kMax, a & k20Bits);
|
|
1181
|
+
out->c[i * 4 + 1] = mod_sub(kMax, (a >> 20) | ((b & 0xff) << 12));
|
|
1182
|
+
out->c[i * 4 + 2] = mod_sub(kMax, (b >> 8) & k20Bits);
|
|
1183
|
+
out->c[i * 4 + 3] = mod_sub(kMax, (b >> 28) | ((uint32_t)c) << 4);
|
|
1184
|
+
}
|
|
1185
|
+
return 1;
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
|
|
1189
|
+
|
|
1190
|
+
/* Expansion functions */
|
|
1191
|
+
|
|
1192
|
+
// FIPS 204, Algorithm 30 (`RejNTTPoly`).
|
|
1193
|
+
//
|
|
1194
|
+
// Rejection samples a Keccak stream to get uniformly distributed elements. This
|
|
1195
|
+
// is used for matrix expansion and only operates on public inputs.
|
|
1196
|
+
inline void scalar_from_keccak_block_vartime(scalar *out, int *done,
|
|
1197
|
+
const uint8_t block[168]) {
|
|
1198
|
+
// kStep is the number of loop iterations to do at once. May need to become
|
|
1199
|
+
// platform dependent at some point. Must be a compile-time constant - if we
|
|
1200
|
+
// ever need to runtime dispatch on it, it has to be made a template argument.
|
|
1201
|
+
const size_t kStep = 2;
|
|
1202
|
+
|
|
1203
|
+
// Branchless sampling as long as there is enough space in the output buffer
|
|
1204
|
+
// even if all sampled numbers are < `kPrime`.
|
|
1205
|
+
size_t i = 0;
|
|
1206
|
+
for (; i <= size_t{168 - 3 * kStep} && *done <= int{kDegree - kStep};
|
|
1207
|
+
i += 3 * kStep) {
|
|
1208
|
+
uint32_t d[kStep];
|
|
1209
|
+
for (size_t k = 0; k < kStep; ++k) {
|
|
1210
|
+
size_t bi = i + 3 * k;
|
|
1211
|
+
d[k] = (uint32_t)block[bi] | ((uint32_t)block[bi + 1] << 8) |
|
|
1212
|
+
(((uint32_t)block[bi + 2] & 0x7f) << 16);
|
|
1213
|
+
}
|
|
1214
|
+
for (size_t k = 0; k < kStep; ++k) {
|
|
1215
|
+
out->c[*done] = d[k];
|
|
1216
|
+
*done += d[k] < kPrime;
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
// Branchful "tail".
|
|
1221
|
+
for (; i < 168 && *done < kDegree; i += 3) {
|
|
1222
|
+
// FIPS 204, Algorithm 14 (`CoeffFromThreeBytes`).
|
|
1223
|
+
uint32_t value = (uint32_t)block[i] | ((uint32_t)block[i + 1] << 8) |
|
|
1224
|
+
(((uint32_t)block[i + 2] & 0x7f) << 16);
|
|
1225
|
+
if (value < kPrime) {
|
|
1226
|
+
out->c[(*done)++] = value;
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
// FIPS 204, Algorithm 30 (`RejNTTPoly`).
|
|
1232
|
+
//
|
|
1233
|
+
// Rejection samples a Keccak stream to get uniformly distributed elements. This
|
|
1234
|
+
// is used for matrix expansion and only operates on public inputs.
|
|
1235
|
+
inline void scalar_from_keccak_vartime(scalar *out,
|
|
1236
|
+
BORINGSSL_keccak_st *keccak_ctx) {
|
|
1237
|
+
assert(keccak_ctx->squeeze_offset == 0);
|
|
1238
|
+
assert(keccak_ctx->rate_bytes == 168);
|
|
1239
|
+
static_assert(168 % 3 == 0, "block and coefficient boundaries do not align");
|
|
1240
|
+
|
|
1241
|
+
int done = 0;
|
|
1242
|
+
while (done < kDegree) {
|
|
1243
|
+
uint8_t block[168];
|
|
1244
|
+
BORINGSSL_keccak_squeeze(keccak_ctx, block, sizeof(block));
|
|
1245
|
+
scalar_from_keccak_block_vartime(out, &done, block);
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
#if defined(HAVE_KECCAK_X2)
|
|
1250
|
+
inline void scalar_from_keccak_vartime_x2(scalar *out[2],
|
|
1251
|
+
BORINGSSL_keccak_st keccak_ctx[2]) {
|
|
1252
|
+
assert(keccak_ctx[0].squeeze_offset == 0);
|
|
1253
|
+
assert(keccak_ctx[0].rate_bytes == 168);
|
|
1254
|
+
assert(keccak_ctx[1].squeeze_offset == 0);
|
|
1255
|
+
assert(keccak_ctx[1].rate_bytes == 168);
|
|
1256
|
+
static_assert(168 % 3 == 0, "block and coefficient boundaries do not align");
|
|
1257
|
+
|
|
1258
|
+
int done[2] = {0, 0};
|
|
1259
|
+
while (done[0] < kDegree || done[1] < kDegree) {
|
|
1260
|
+
uint8_t block[2][168];
|
|
1261
|
+
uint8_t *blocks[] = {block[0], block[1]};
|
|
1262
|
+
BORINGSSL_keccak_squeeze_x2(keccak_ctx, blocks, sizeof(block[0]));
|
|
1263
|
+
scalar_from_keccak_block_vartime(out[0], &done[0], block[0]);
|
|
1264
|
+
scalar_from_keccak_block_vartime(out[1], &done[1], block[1]);
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
#endif
|
|
1268
|
+
|
|
1269
|
+
#if defined(HAVE_KECCAK_X4)
|
|
1270
|
+
inline void scalar_from_keccak_vartime_x4(scalar *out[4],
|
|
1271
|
+
BORINGSSL_keccak_st keccak_ctx[]) {
|
|
1272
|
+
for (int i = 0; i < 4; i++) {
|
|
1273
|
+
assert(keccak_ctx[i].squeeze_offset == 0);
|
|
1274
|
+
assert(keccak_ctx[i].rate_bytes == 168);
|
|
1275
|
+
}
|
|
1276
|
+
static_assert(168 % 3 == 0, "block and coefficient boundaries do not align");
|
|
1277
|
+
|
|
1278
|
+
int done[4] = {0, 0, 0, 0};
|
|
1279
|
+
while (done[0] < kDegree || done[1] < kDegree || done[2] < kDegree ||
|
|
1280
|
+
done[3] < kDegree) {
|
|
1281
|
+
uint8_t block[4][168];
|
|
1282
|
+
uint8_t *blocks[] = {block[0], block[1], block[2], block[3]};
|
|
1283
|
+
BORINGSSL_keccak_squeeze_x4(keccak_ctx, blocks, sizeof(block[0]));
|
|
1284
|
+
scalar_from_keccak_block_vartime(out[0], &done[0], block[0]);
|
|
1285
|
+
scalar_from_keccak_block_vartime(out[1], &done[1], block[1]);
|
|
1286
|
+
scalar_from_keccak_block_vartime(out[2], &done[2], block[2]);
|
|
1287
|
+
scalar_from_keccak_block_vartime(out[3], &done[3], block[3]);
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
#endif
|
|
1291
|
+
|
|
1292
|
+
template <int ETA>
|
|
1293
|
+
inline bool coefficient_from_nibble(uint32_t nibble, uint32_t *result);
|
|
1294
|
+
|
|
1295
|
+
template <>
|
|
1296
|
+
inline bool coefficient_from_nibble<4>(uint32_t nibble, uint32_t *result) {
|
|
1297
|
+
// Knowing bounds on `nibble` seems to tempt some versions of Clang to emit
|
|
1298
|
+
// a branch, if we don't have a barrier in `mod_sub`.
|
|
1299
|
+
*result = mod_sub(4, value_barrier_u32(nibble));
|
|
1300
|
+
return constant_time_declassify_int(nibble < 9);
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
template <>
|
|
1304
|
+
inline bool coefficient_from_nibble<2>(uint32_t nibble, uint32_t *result) {
|
|
1305
|
+
// Knowing bounds on `nibble` seems to tempt some versions of Clang to emit
|
|
1306
|
+
// a branch, if we don't have a barrier in `mod_sub`.
|
|
1307
|
+
// Constant time "nibble % 5".
|
|
1308
|
+
uint32_t rem = nibble - 5 * ((205 * nibble) >> 10);
|
|
1309
|
+
*result = mod_sub(2, value_barrier_u32(rem));
|
|
1310
|
+
return constant_time_declassify_int(nibble < 15);
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
template <int ETA>
|
|
1314
|
+
inline void scalar_uniform_block(scalar *out, int *done,
|
|
1315
|
+
const uint8_t block[136]) {
|
|
1316
|
+
for (size_t i = 0; i < 136 && *done < kDegree; ++i) {
|
|
1317
|
+
uint32_t t0 = block[i] & 0x0F;
|
|
1318
|
+
uint32_t t1 = block[i] >> 4;
|
|
1319
|
+
// FIPS 204, Algorithm 15 (`CoefFromHalfByte`). Although both the input
|
|
1320
|
+
// and output here are secret, it is OK to leak when we rejected a byte.
|
|
1321
|
+
// Individual bytes of the SHAKE-256 stream are (indistinguishable from)
|
|
1322
|
+
// independent of each other and the original seed, so leaking information
|
|
1323
|
+
// about the rejected bytes does not reveal the input or output.
|
|
1324
|
+
*done += coefficient_from_nibble<ETA>(t0, &out->c[*done]);
|
|
1325
|
+
if (*done < kDegree) {
|
|
1326
|
+
*done += coefficient_from_nibble<ETA>(t1, &out->c[*done]);
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
// FIPS 204, Algorithm 31 (`RejBoundedPoly`).
|
|
1332
|
+
template <int ETA>
|
|
1333
|
+
inline void scalar_uniform(scalar *out, BORINGSSL_keccak_st *keccak_ctx) {
|
|
1334
|
+
assert(keccak_ctx->squeeze_offset == 0);
|
|
1335
|
+
assert(keccak_ctx->rate_bytes == 136);
|
|
1336
|
+
|
|
1337
|
+
int done = 0;
|
|
1338
|
+
while (done < kDegree) {
|
|
1339
|
+
uint8_t block[136];
|
|
1340
|
+
BORINGSSL_keccak_squeeze(keccak_ctx, block, sizeof(block));
|
|
1341
|
+
scalar_uniform_block<ETA>(out, &done, block);
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
#if defined(HAVE_KECCAK_X2)
|
|
1346
|
+
template <int ETA>
|
|
1347
|
+
inline void scalar_uniform_x2(scalar *out[2],
|
|
1348
|
+
BORINGSSL_keccak_st keccak_ctx[2]) {
|
|
1349
|
+
assert(keccak_ctx[0].squeeze_offset == 0);
|
|
1350
|
+
assert(keccak_ctx[0].rate_bytes == 136);
|
|
1351
|
+
assert(keccak_ctx[1].squeeze_offset == 0);
|
|
1352
|
+
assert(keccak_ctx[1].rate_bytes == 136);
|
|
1353
|
+
|
|
1354
|
+
int done[2] = {0, 0};
|
|
1355
|
+
while (done[0] < kDegree || done[1] < kDegree) {
|
|
1356
|
+
uint8_t block[2][136];
|
|
1357
|
+
uint8_t *blocks[] = {block[0], block[1]};
|
|
1358
|
+
BORINGSSL_keccak_squeeze_x2(keccak_ctx, blocks, sizeof(block[0]));
|
|
1359
|
+
scalar_uniform_block<ETA>(out[0], &done[0], block[0]);
|
|
1360
|
+
scalar_uniform_block<ETA>(out[1], &done[1], block[1]);
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
#endif
|
|
1364
|
+
|
|
1365
|
+
#if defined(HAVE_KECCAK_X4)
|
|
1366
|
+
template <int ETA>
|
|
1367
|
+
inline void scalar_uniform_x4(scalar *out[4],
|
|
1368
|
+
BORINGSSL_keccak_st keccak_ctx[]) {
|
|
1369
|
+
for (int i = 0; i < 4; i++) {
|
|
1370
|
+
assert(keccak_ctx[i].squeeze_offset == 0);
|
|
1371
|
+
assert(keccak_ctx[i].rate_bytes == 136);
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
int done[4] = {0, 0, 0, 0};
|
|
1375
|
+
while (done[0] < kDegree || done[1] < kDegree || done[2] < kDegree ||
|
|
1376
|
+
done[3] < kDegree) {
|
|
1377
|
+
uint8_t block[4][136];
|
|
1378
|
+
uint8_t *blocks[] = {block[0], block[1], block[2], block[3]};
|
|
1379
|
+
BORINGSSL_keccak_squeeze_x4(keccak_ctx, blocks, sizeof(block[0]));
|
|
1380
|
+
scalar_uniform_block<ETA>(out[0], &done[0], block[0]);
|
|
1381
|
+
scalar_uniform_block<ETA>(out[1], &done[1], block[1]);
|
|
1382
|
+
scalar_uniform_block<ETA>(out[2], &done[2], block[2]);
|
|
1383
|
+
scalar_uniform_block<ETA>(out[3], &done[3], block[3]);
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
#endif
|
|
1387
|
+
|
|
1388
|
+
// FIPS 204, Algorithm 34 (`ExpandMask`), but just a single step.
|
|
1389
|
+
template <int K>
|
|
1390
|
+
inline void scalar_sample_mask(scalar *out,
|
|
1391
|
+
const uint8_t rho_prime[kRhoPrimeBytes],
|
|
1392
|
+
size_t index) {
|
|
1393
|
+
uint8_t buf[scalar_le_gamma1_bytes<K>()];
|
|
1394
|
+
struct BORINGSSL_keccak_st ctx;
|
|
1395
|
+
BORINGSSL_keccak_init(&ctx, boringssl_shake256);
|
|
1396
|
+
BORINGSSL_keccak_absorb(&ctx, rho_prime, kRhoPrimeBytes);
|
|
1397
|
+
uint8_t index_buf[2];
|
|
1398
|
+
index_buf[0] = static_cast<uint8_t>(index);
|
|
1399
|
+
index_buf[1] = static_cast<uint8_t>(index >> 8);
|
|
1400
|
+
BORINGSSL_keccak_absorb(&ctx, index_buf, 2);
|
|
1401
|
+
BORINGSSL_keccak_squeeze(&ctx, buf, sizeof(buf));
|
|
1402
|
+
scalar_decode_signed<gamma1_bits<K>() + 1, gamma1<K>()>(out, buf);
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1405
|
+
// FIPS 204, Algorithm 29 (`SampleInBall`).
|
|
1406
|
+
inline void scalar_sample_in_ball_vartime(scalar *out, const uint8_t *seed,
|
|
1407
|
+
int len, int tau) {
|
|
1408
|
+
BORINGSSL_keccak_st keccak_ctx;
|
|
1409
|
+
BORINGSSL_keccak_init(&keccak_ctx, boringssl_shake256);
|
|
1410
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, seed, len);
|
|
1411
|
+
assert(keccak_ctx.squeeze_offset == 0);
|
|
1412
|
+
assert(keccak_ctx.rate_bytes == 136);
|
|
1413
|
+
|
|
1414
|
+
uint8_t block[136];
|
|
1415
|
+
BORINGSSL_keccak_squeeze(&keccak_ctx, block, sizeof(block));
|
|
1416
|
+
|
|
1417
|
+
uint64_t signs = CRYPTO_load_u64_le(block);
|
|
1418
|
+
int offset = 8;
|
|
1419
|
+
// SampleInBall implements a Fisher–Yates shuffle, which unavoidably leaks
|
|
1420
|
+
// where the zeros are by memory access pattern. Although this leak happens
|
|
1421
|
+
// before bad signatures are rejected, this is safe. See
|
|
1422
|
+
// https://boringssl-review.googlesource.com/c/boringssl/+/67747/comment/8d8f01ac_70af3f21/
|
|
1423
|
+
CONSTTIME_DECLASSIFY(block + offset, sizeof(block) - offset);
|
|
1424
|
+
|
|
1425
|
+
OPENSSL_memset(out, 0, sizeof(*out));
|
|
1426
|
+
for (size_t i = kDegree - tau; i < kDegree; i++) {
|
|
1427
|
+
size_t byte;
|
|
1428
|
+
for (;;) {
|
|
1429
|
+
if (offset == 136) {
|
|
1430
|
+
BORINGSSL_keccak_squeeze(&keccak_ctx, block, sizeof(block));
|
|
1431
|
+
// See above.
|
|
1432
|
+
CONSTTIME_DECLASSIFY(block, sizeof(block));
|
|
1433
|
+
offset = 0;
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
byte = block[offset++];
|
|
1437
|
+
if (byte <= i) {
|
|
1438
|
+
break;
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
out->c[i] = out->c[byte];
|
|
1443
|
+
out->c[byte] = mod_sub(1, 2 * (signs & 1));
|
|
1444
|
+
signs >>= 1;
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
template <int K, int L>
|
|
1449
|
+
inline void matrix_expand_step(scalar *out, const uint8_t rho[kRhoBytes],
|
|
1450
|
+
int index) {
|
|
1451
|
+
BORINGSSL_keccak_st keccak_ctx;
|
|
1452
|
+
BORINGSSL_keccak_init(&keccak_ctx, boringssl_shake128);
|
|
1453
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, rho, kRhoBytes);
|
|
1454
|
+
uint8_t index_buf[2];
|
|
1455
|
+
index_buf[0] = static_cast<uint8_t>(index % L);
|
|
1456
|
+
index_buf[1] = static_cast<uint8_t>(index / L);
|
|
1457
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, index_buf, 2);
|
|
1458
|
+
scalar_from_keccak_vartime(out, &keccak_ctx);
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
#if defined(HAVE_KECCAK_X2)
|
|
1462
|
+
template <int K, int L>
|
|
1463
|
+
inline void matrix_expand_step_x2(matrix<K, L> *out,
|
|
1464
|
+
const uint8_t rho[kRhoBytes], int index) {
|
|
1465
|
+
BORINGSSL_keccak_st keccak_ctx[2];
|
|
1466
|
+
BORINGSSL_keccak_init(&keccak_ctx[0], boringssl_shake128);
|
|
1467
|
+
BORINGSSL_keccak_init(&keccak_ctx[1], boringssl_shake128);
|
|
1468
|
+
BORINGSSL_keccak_absorb(&keccak_ctx[0], rho, kRhoBytes);
|
|
1469
|
+
BORINGSSL_keccak_absorb(&keccak_ctx[1], rho, kRhoBytes);
|
|
1470
|
+
uint8_t index_buf[2];
|
|
1471
|
+
index_buf[0] = static_cast<uint8_t>(index % L);
|
|
1472
|
+
index_buf[1] = static_cast<uint8_t>(index / L);
|
|
1473
|
+
BORINGSSL_keccak_absorb(&keccak_ctx[0], index_buf, 2);
|
|
1474
|
+
index_buf[0] = static_cast<uint8_t>((index + 1) % L);
|
|
1475
|
+
index_buf[1] = static_cast<uint8_t>((index + 1) / L);
|
|
1476
|
+
BORINGSSL_keccak_absorb(&keccak_ctx[1], index_buf, 2);
|
|
1477
|
+
|
|
1478
|
+
scalar *outs[] = {&out->v[index / L][index % L],
|
|
1479
|
+
&out->v[(index + 1) / L][(index + 1) % L]};
|
|
1480
|
+
scalar_from_keccak_vartime_x2(outs, keccak_ctx);
|
|
1481
|
+
}
|
|
1482
|
+
#endif
|
|
1483
|
+
|
|
1484
|
+
#if defined(HAVE_KECCAK_X4)
|
|
1485
|
+
template <int K, int L>
|
|
1486
|
+
inline void matrix_expand_step_x4(matrix<K, L> *out,
|
|
1487
|
+
const uint8_t rho[kRhoBytes], int index) {
|
|
1488
|
+
BORINGSSL_keccak_st keccak_ctx[4];
|
|
1489
|
+
for (int k = 0; k < 4; k++) {
|
|
1490
|
+
BORINGSSL_keccak_init(&keccak_ctx[k], boringssl_shake128);
|
|
1491
|
+
BORINGSSL_keccak_absorb(&keccak_ctx[k], rho, kRhoBytes);
|
|
1492
|
+
uint8_t index_buf[2];
|
|
1493
|
+
index_buf[0] = static_cast<uint8_t>((index + k) % L);
|
|
1494
|
+
index_buf[1] = static_cast<uint8_t>((index + k) / L);
|
|
1495
|
+
BORINGSSL_keccak_absorb(&keccak_ctx[k], index_buf, 2);
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
scalar *outs[] = {&out->v[index / L][index % L],
|
|
1499
|
+
&out->v[(index + 1) / L][(index + 1) % L],
|
|
1500
|
+
&out->v[(index + 2) / L][(index + 2) % L],
|
|
1501
|
+
&out->v[(index + 3) / L][(index + 3) % L]};
|
|
1502
|
+
scalar_from_keccak_vartime_x4(outs, keccak_ctx);
|
|
1503
|
+
}
|
|
1504
|
+
#endif
|
|
1505
|
+
|
|
1506
|
+
template <int K, int L>
|
|
1507
|
+
inline void matrix_expand(matrix<K, L> *out, const uint8_t rho[kRhoBytes]) {
|
|
1508
|
+
static_assert(K <= 0x100, "K must fit in 8 bits");
|
|
1509
|
+
static_assert(L <= 0x100, "L must fit in 8 bits");
|
|
1510
|
+
|
|
1511
|
+
int index = 0;
|
|
1512
|
+
#if defined(HAVE_KECCAK_X4)
|
|
1513
|
+
if (BORINGSSL_have_keccak_x4()) {
|
|
1514
|
+
for (; index + 4 <= K * L; index += 4) {
|
|
1515
|
+
matrix_expand_step_x4<K, L>(out, rho, index);
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
#endif
|
|
1519
|
+
#if defined(HAVE_KECCAK_X2)
|
|
1520
|
+
for (; index + 2 <= K * L; index += 2) {
|
|
1521
|
+
matrix_expand_step_x2(out, rho, index);
|
|
1522
|
+
}
|
|
1523
|
+
#endif
|
|
1524
|
+
|
|
1525
|
+
for (; index < K * L; index++) {
|
|
1526
|
+
matrix_expand_step<K, L>(&out->v[index / L][index % L], rho, index);
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
template <int K>
|
|
1531
|
+
inline void vector_expand_short_step(scalar *out,
|
|
1532
|
+
const uint8_t sigma[kSigmaBytes],
|
|
1533
|
+
int index) {
|
|
1534
|
+
BORINGSSL_keccak_st keccak_ctx;
|
|
1535
|
+
BORINGSSL_keccak_init(&keccak_ctx, boringssl_shake256);
|
|
1536
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, sigma, kSigmaBytes);
|
|
1537
|
+
uint8_t index_buf[2];
|
|
1538
|
+
index_buf[0] = static_cast<uint8_t>(index);
|
|
1539
|
+
index_buf[1] = 0;
|
|
1540
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, index_buf, 2);
|
|
1541
|
+
scalar_uniform<eta<K>()>(out, &keccak_ctx);
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
#if defined(HAVE_KECCAK_X2)
|
|
1545
|
+
template <int K>
|
|
1546
|
+
inline void vector_expand_short_step_x2(scalar *out0, scalar *out1,
|
|
1547
|
+
const uint8_t sigma[kSigmaBytes],
|
|
1548
|
+
int index) {
|
|
1549
|
+
BORINGSSL_keccak_st keccak_ctx[2];
|
|
1550
|
+
BORINGSSL_keccak_init(&keccak_ctx[0], boringssl_shake256);
|
|
1551
|
+
BORINGSSL_keccak_init(&keccak_ctx[1], boringssl_shake256);
|
|
1552
|
+
BORINGSSL_keccak_absorb(&keccak_ctx[0], sigma, kSigmaBytes);
|
|
1553
|
+
BORINGSSL_keccak_absorb(&keccak_ctx[1], sigma, kSigmaBytes);
|
|
1554
|
+
uint8_t index_buf[2];
|
|
1555
|
+
index_buf[0] = static_cast<uint8_t>(index);
|
|
1556
|
+
index_buf[1] = 0;
|
|
1557
|
+
BORINGSSL_keccak_absorb(&keccak_ctx[0], index_buf, 2);
|
|
1558
|
+
index_buf[0] = static_cast<uint8_t>(index + 1);
|
|
1559
|
+
index_buf[1] = 0;
|
|
1560
|
+
BORINGSSL_keccak_absorb(&keccak_ctx[1], index_buf, 2);
|
|
1561
|
+
|
|
1562
|
+
scalar *outs[] = {out0, out1};
|
|
1563
|
+
scalar_uniform_x2<eta<K>()>(outs, keccak_ctx);
|
|
1564
|
+
}
|
|
1565
|
+
#endif
|
|
1566
|
+
|
|
1567
|
+
#if defined(HAVE_KECCAK_X4)
|
|
1568
|
+
template <int K>
|
|
1569
|
+
inline void vector_expand_short_step_x4(scalar *out0, scalar *out1,
|
|
1570
|
+
scalar *out2, scalar *out3,
|
|
1571
|
+
const uint8_t sigma[kSigmaBytes],
|
|
1572
|
+
int index) {
|
|
1573
|
+
BORINGSSL_keccak_st keccak_ctx[4];
|
|
1574
|
+
for (int k = 0; k < 4; k++) {
|
|
1575
|
+
BORINGSSL_keccak_init(&keccak_ctx[k], boringssl_shake256);
|
|
1576
|
+
BORINGSSL_keccak_absorb(&keccak_ctx[k], sigma, kSigmaBytes);
|
|
1577
|
+
uint8_t index_buf[2];
|
|
1578
|
+
index_buf[0] = static_cast<uint8_t>(index + k);
|
|
1579
|
+
index_buf[1] = 0;
|
|
1580
|
+
BORINGSSL_keccak_absorb(&keccak_ctx[k], index_buf, 2);
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
scalar *outs[] = {out0, out1, out2, out3};
|
|
1584
|
+
scalar_uniform_x4<eta<K>()>(outs, keccak_ctx);
|
|
1585
|
+
}
|
|
1586
|
+
#endif
|
|
1587
|
+
|
|
1588
|
+
// FIPS 204, Algorithm 33 (`ExpandS`).
|
|
1589
|
+
template <int K, int L>
|
|
1590
|
+
inline void vector_expand_short(vector<L> *s1, vector<K> *s2,
|
|
1591
|
+
const uint8_t sigma[kSigmaBytes]) {
|
|
1592
|
+
static_assert(K <= 0x100, "K must fit in 8 bits");
|
|
1593
|
+
static_assert(L <= 0x100, "L must fit in 8 bits");
|
|
1594
|
+
static_assert(K + L <= 0x100, "K+L must fit in 8 bits");
|
|
1595
|
+
|
|
1596
|
+
scalar *all_scalars[K + L];
|
|
1597
|
+
for (int i = 0; i < L; i++) {
|
|
1598
|
+
all_scalars[i] = &s1->v[i];
|
|
1599
|
+
}
|
|
1600
|
+
for (int i = 0; i < K; i++) {
|
|
1601
|
+
all_scalars[L + i] = &s2->v[i];
|
|
1602
|
+
}
|
|
1603
|
+
|
|
1604
|
+
int index = 0;
|
|
1605
|
+
#if defined(HAVE_KECCAK_X4)
|
|
1606
|
+
if (BORINGSSL_have_keccak_x4()) {
|
|
1607
|
+
for (; index + 4 <= K + L; index += 4) {
|
|
1608
|
+
vector_expand_short_step_x4<K>(all_scalars[index], all_scalars[index + 1],
|
|
1609
|
+
all_scalars[index + 2],
|
|
1610
|
+
all_scalars[index + 3], sigma, index);
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
#endif
|
|
1614
|
+
#if defined(HAVE_KECCAK_X2)
|
|
1615
|
+
for (; index + 2 <= K + L; index += 2) {
|
|
1616
|
+
vector_expand_short_step_x2<K>(all_scalars[index], all_scalars[index + 1],
|
|
1617
|
+
sigma, index);
|
|
1618
|
+
}
|
|
1619
|
+
#endif
|
|
1620
|
+
|
|
1621
|
+
for (; index < K + L; index++) {
|
|
1622
|
+
vector_expand_short_step<K>(all_scalars[index], sigma, index);
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
|
|
1626
|
+
// FIPS 204, Algorithm 34 (`ExpandMask`).
|
|
1627
|
+
template <int K, int L>
|
|
1628
|
+
inline void vector_expand_mask(vector<L> *out,
|
|
1629
|
+
const uint8_t rho_prime[kRhoPrimeBytes],
|
|
1630
|
+
size_t kappa) {
|
|
1631
|
+
assert(kappa + L <= 0x10000);
|
|
1632
|
+
|
|
1633
|
+
for (int i = 0; i < L; i++) {
|
|
1634
|
+
size_t index = kappa + i;
|
|
1635
|
+
scalar_sample_mask<K>(&out->v[i], rho_prime, index);
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
/* Encoding */
|
|
1640
|
+
|
|
1641
|
+
// FIPS 204, Algorithm 16 (`SimpleBitPack`).
|
|
1642
|
+
//
|
|
1643
|
+
// Encodes an entire vector into 32*K*`bits` bytes. Note that since 256
|
|
1644
|
+
// (kDegree) is divisible by 8, the individual vector entries will always fill a
|
|
1645
|
+
// whole number of bytes, so we do not need to worry about bit packing here.
|
|
1646
|
+
template <int bits, int K>
|
|
1647
|
+
inline void vector_encode(uint8_t *out, const vector<K> *a) {
|
|
1648
|
+
for (int i = 0; i < K; i++) {
|
|
1649
|
+
scalar_encode<bits>(out + i * bits * kDegree / 8, &a->v[i]);
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
// FIPS 204, Algorithm 18 (`SimpleBitUnpack`).
|
|
1654
|
+
template <int bits, int K>
|
|
1655
|
+
inline void vector_decode(vector<K> *out, const uint8_t *in) {
|
|
1656
|
+
for (int i = 0; i < K; i++) {
|
|
1657
|
+
scalar_decode<bits>(&out->v[i], in + i * bits * kDegree / 8);
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
|
|
1661
|
+
// FIPS 204, Algorithm 17 (`BitPack`).
|
|
1662
|
+
//
|
|
1663
|
+
// Encodes an entire vector into 32*L*`bits` bytes. Note that since 256
|
|
1664
|
+
// (kDegree) is divisible by 8, the individual vector entries will always fill a
|
|
1665
|
+
// whole number of bytes, so we do not need to worry about bit packing here.
|
|
1666
|
+
template <int bits, uint32_t max, int X>
|
|
1667
|
+
inline void vector_encode_signed(uint8_t *out, const vector<X> *a) {
|
|
1668
|
+
for (int i = 0; i < X; i++) {
|
|
1669
|
+
scalar_encode_signed<bits, max>(out + i * bits * kDegree / 8, &a->v[i]);
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
|
|
1673
|
+
// `vector_encode_signed_ntt` behaves like `vector_encode_signed` but takes its
|
|
1674
|
+
// input in NTT form. This is only used by the testing-only `skEncode` and
|
|
1675
|
+
// `skDecode` functions and is not performance-sensitive.
|
|
1676
|
+
template <int bits, uint32_t max, int X>
|
|
1677
|
+
inline void vector_encode_signed_ntt(uint8_t *out, const vector<X> *a_ntt) {
|
|
1678
|
+
vector<X> a = *a_ntt;
|
|
1679
|
+
vector_inverse_ntt_montgomery(&a);
|
|
1680
|
+
// `vector_inverse_ntt_montgomery` adds an extra factor of R, which we must
|
|
1681
|
+
// cancel with a Montgomery reduction.
|
|
1682
|
+
for (int i = 0; i < X; i++) {
|
|
1683
|
+
for (int j = 0; j < kDegree; j++) {
|
|
1684
|
+
a.v[i].c[j] = reduce_montgomery(a.v[i].c[j]);
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1688
|
+
vector_encode_signed<bits, max>(out, &a);
|
|
1689
|
+
}
|
|
1690
|
+
|
|
1691
|
+
// FIPS 204, Algorithm 19 (`BitUnpack`).
|
|
1692
|
+
template <int bits, uint32_t max, int X>
|
|
1693
|
+
inline int vector_decode_signed(vector<X> *out, const uint8_t *in) {
|
|
1694
|
+
for (int i = 0; i < X; i++) {
|
|
1695
|
+
if (!scalar_decode_signed<bits, max>(&out->v[i],
|
|
1696
|
+
in + i * bits * kDegree / 8)) {
|
|
1697
|
+
return 0;
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
return 1;
|
|
1701
|
+
}
|
|
1702
|
+
|
|
1703
|
+
// FIPS 204, Algorithm 28 (`w1Encode`).
|
|
1704
|
+
template <int K>
|
|
1705
|
+
inline void w1_encode(uint8_t out[w1_bytes<K>()], const vector<K> *w1) {
|
|
1706
|
+
vector_encode<w1_coeffs_bits<K>()>(out, w1);
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
// FIPS 204, Algorithm 20 (`HintBitPack`).
|
|
1710
|
+
template <int K>
|
|
1711
|
+
inline void hint_bit_pack(uint8_t out[omega<K>() + K], const vector<K> *h) {
|
|
1712
|
+
OPENSSL_memset(out, 0, omega<K>() + K);
|
|
1713
|
+
int index = 0;
|
|
1714
|
+
for (int i = 0; i < K; i++) {
|
|
1715
|
+
for (int j = 0; j < kDegree; j++) {
|
|
1716
|
+
if (h->v[i].c[j]) {
|
|
1717
|
+
// h must have at most omega<K>() non-zero coefficients.
|
|
1718
|
+
BSSL_CHECK(index < omega<K>());
|
|
1719
|
+
out[index++] = j;
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
out[omega<K>() + i] = index;
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1726
|
+
// FIPS 204, Algorithm 21 (`HintBitUnpack`).
|
|
1727
|
+
template <int K>
|
|
1728
|
+
inline int hint_bit_unpack(vector<K> *h, const uint8_t in[omega<K>() + K]) {
|
|
1729
|
+
vector_zero(h);
|
|
1730
|
+
int index = 0;
|
|
1731
|
+
for (int i = 0; i < K; i++) {
|
|
1732
|
+
const int limit = in[omega<K>() + i];
|
|
1733
|
+
if (limit < index || limit > omega<K>()) {
|
|
1734
|
+
return 0;
|
|
1735
|
+
}
|
|
1736
|
+
|
|
1737
|
+
int last = -1;
|
|
1738
|
+
while (index < limit) {
|
|
1739
|
+
int byte = in[index++];
|
|
1740
|
+
if (last >= 0 && byte <= last) {
|
|
1741
|
+
return 0;
|
|
1742
|
+
}
|
|
1743
|
+
last = byte;
|
|
1744
|
+
static_assert(kDegree == 256,
|
|
1745
|
+
"kDegree must be 256 for this write to be in bounds");
|
|
1746
|
+
h->v[i].c[byte] = 1;
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
for (; index < omega<K>(); index++) {
|
|
1750
|
+
if (in[index] != 0) {
|
|
1751
|
+
return 0;
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1754
|
+
return 1;
|
|
1755
|
+
}
|
|
1756
|
+
|
|
1757
|
+
template <int K>
|
|
1758
|
+
struct public_key {
|
|
1759
|
+
uint8_t rho[kRhoBytes];
|
|
1760
|
+
vector<K> t1;
|
|
1761
|
+
// Pre-cached value(s).
|
|
1762
|
+
uint8_t public_key_hash[kTrBytes];
|
|
1763
|
+
};
|
|
1764
|
+
|
|
1765
|
+
template <int K, int L>
|
|
1766
|
+
struct private_key {
|
|
1767
|
+
public_key<K> pub;
|
|
1768
|
+
uint8_t k[kKBytes];
|
|
1769
|
+
vector<L> s1_ntt;
|
|
1770
|
+
vector<K> s2_ntt;
|
|
1771
|
+
vector<K> t0_ntt;
|
|
1772
|
+
};
|
|
1773
|
+
|
|
1774
|
+
template <int K, int L>
|
|
1775
|
+
struct signature {
|
|
1776
|
+
uint8_t c_tilde[2 * lambda_bytes<K>()];
|
|
1777
|
+
vector<L> z;
|
|
1778
|
+
vector<K> h;
|
|
1779
|
+
};
|
|
1780
|
+
|
|
1781
|
+
// FIPS 204, Algorithm 22 (`pkEncode`).
|
|
1782
|
+
template <int K>
|
|
1783
|
+
inline int mldsa_marshal_public_key(CBB *out, const public_key<K> *pub) {
|
|
1784
|
+
if (!CBB_add_bytes(out, pub->rho, sizeof(pub->rho))) {
|
|
1785
|
+
return 0;
|
|
1786
|
+
}
|
|
1787
|
+
|
|
1788
|
+
uint8_t *vectork_output;
|
|
1789
|
+
if (!CBB_add_space(out, &vectork_output, 320 * K)) {
|
|
1790
|
+
return 0;
|
|
1791
|
+
}
|
|
1792
|
+
vector_encode<10>(vectork_output, &pub->t1);
|
|
1793
|
+
|
|
1794
|
+
return 1;
|
|
1795
|
+
}
|
|
1796
|
+
|
|
1797
|
+
// FIPS 204, Algorithm 23 (`pkDecode`).
|
|
1798
|
+
template <int K>
|
|
1799
|
+
inline int mldsa_parse_public_key(public_key<K> *pub, CBS *in) {
|
|
1800
|
+
const CBS orig_in = *in;
|
|
1801
|
+
|
|
1802
|
+
if (!CBS_copy_bytes(in, pub->rho, sizeof(pub->rho))) {
|
|
1803
|
+
return 0;
|
|
1804
|
+
}
|
|
1805
|
+
|
|
1806
|
+
CBS t1_bytes;
|
|
1807
|
+
if (!CBS_get_bytes(in, &t1_bytes, 320 * K) || CBS_len(in) != 0) {
|
|
1808
|
+
return 0;
|
|
1809
|
+
}
|
|
1810
|
+
vector_decode<10>(&pub->t1, CBS_data(&t1_bytes));
|
|
1811
|
+
|
|
1812
|
+
// Compute pre-cached values.
|
|
1813
|
+
BORINGSSL_keccak(pub->public_key_hash, sizeof(pub->public_key_hash),
|
|
1814
|
+
CBS_data(&orig_in), CBS_len(&orig_in), boringssl_shake256);
|
|
1815
|
+
|
|
1816
|
+
return 1;
|
|
1817
|
+
}
|
|
1818
|
+
|
|
1819
|
+
// FIPS 204, Algorithm 24 (`skEncode`).
|
|
1820
|
+
template <int K, int L>
|
|
1821
|
+
inline int mldsa_marshal_private_key(CBB *out, const private_key<K, L> *priv) {
|
|
1822
|
+
if (!CBB_add_bytes(out, priv->pub.rho, sizeof(priv->pub.rho)) ||
|
|
1823
|
+
!CBB_add_bytes(out, priv->k, sizeof(priv->k)) ||
|
|
1824
|
+
!CBB_add_bytes(out, priv->pub.public_key_hash,
|
|
1825
|
+
sizeof(priv->pub.public_key_hash))) {
|
|
1826
|
+
return 0;
|
|
1827
|
+
}
|
|
1828
|
+
|
|
1829
|
+
constexpr size_t scalar_bytes =
|
|
1830
|
+
(kDegree * plus_minus_eta_bitlen<K>() + 7) / 8;
|
|
1831
|
+
uint8_t *vectorl_output;
|
|
1832
|
+
if (!CBB_add_space(out, &vectorl_output, scalar_bytes * L)) {
|
|
1833
|
+
return 0;
|
|
1834
|
+
}
|
|
1835
|
+
vector_encode_signed_ntt<plus_minus_eta_bitlen<K>(), eta<K>()>(vectorl_output,
|
|
1836
|
+
&priv->s1_ntt);
|
|
1837
|
+
|
|
1838
|
+
uint8_t *s2_output;
|
|
1839
|
+
if (!CBB_add_space(out, &s2_output, scalar_bytes * K)) {
|
|
1840
|
+
return 0;
|
|
1841
|
+
}
|
|
1842
|
+
vector_encode_signed_ntt<plus_minus_eta_bitlen<K>(), eta<K>()>(s2_output,
|
|
1843
|
+
&priv->s2_ntt);
|
|
1844
|
+
|
|
1845
|
+
uint8_t *t0_output;
|
|
1846
|
+
if (!CBB_add_space(out, &t0_output, 416 * K)) {
|
|
1847
|
+
return 0;
|
|
1848
|
+
}
|
|
1849
|
+
vector_encode_signed_ntt<13, (1 << 12)>(t0_output, &priv->t0_ntt);
|
|
1850
|
+
|
|
1851
|
+
return 1;
|
|
1852
|
+
}
|
|
1853
|
+
|
|
1854
|
+
// FIPS 204, Algorithm 25 (`skDecode`). This is only used for testing. The
|
|
1855
|
+
// supported external way to construct ML-DSA keys is to use the input seed.
|
|
1856
|
+
template <int K, int L>
|
|
1857
|
+
inline int mldsa_parse_private_key(private_key<K, L> *priv, CBS *in) {
|
|
1858
|
+
CBS public_key_hash, s1_bytes, s2_bytes, t0_bytes;
|
|
1859
|
+
constexpr size_t scalar_bytes =
|
|
1860
|
+
(kDegree * plus_minus_eta_bitlen<K>() + 7) / 8;
|
|
1861
|
+
if (!CBS_copy_bytes(in, priv->pub.rho, sizeof(priv->pub.rho)) ||
|
|
1862
|
+
!CBS_copy_bytes(in, priv->k, sizeof(priv->k)) ||
|
|
1863
|
+
!CBS_get_bytes(in, &public_key_hash, kTrBytes) ||
|
|
1864
|
+
!CBS_get_bytes(in, &s1_bytes, scalar_bytes * L) ||
|
|
1865
|
+
!vector_decode_signed<plus_minus_eta_bitlen<K>(), eta<K>()>(
|
|
1866
|
+
&priv->s1_ntt, CBS_data(&s1_bytes)) ||
|
|
1867
|
+
!CBS_get_bytes(in, &s2_bytes, scalar_bytes * K) ||
|
|
1868
|
+
!vector_decode_signed<plus_minus_eta_bitlen<K>(), eta<K>()>(
|
|
1869
|
+
&priv->s2_ntt, CBS_data(&s2_bytes)) ||
|
|
1870
|
+
!CBS_get_bytes(in, &t0_bytes, 416 * K)) {
|
|
1871
|
+
return 0;
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1874
|
+
// Compute `t1`, which is not in the `skDecode` input. This also computes
|
|
1875
|
+
// `t0_ntt` and converts `s1_ntt` and `s2_ntt` to NTT form.
|
|
1876
|
+
uint8_t unused[public_key_bytes<K>()];
|
|
1877
|
+
if (!mldsa_finish_keygen(unused, priv)) {
|
|
1878
|
+
return 0;
|
|
1879
|
+
}
|
|
1880
|
+
|
|
1881
|
+
// As a side effect of computing `t1`, we also compute `t0` and
|
|
1882
|
+
// `public_key_hash`. Check they match the received bytes.
|
|
1883
|
+
uint8_t t0_computed[416 * K];
|
|
1884
|
+
vector_encode_signed_ntt<13, (1 << 12)>(t0_computed, &priv->t0_ntt);
|
|
1885
|
+
if (!CBS_mem_equal(&public_key_hash, priv->pub.public_key_hash,
|
|
1886
|
+
sizeof(priv->pub.public_key_hash)) ||
|
|
1887
|
+
!CBS_mem_equal(&t0_bytes, t0_computed, sizeof(t0_computed))) {
|
|
1888
|
+
return 0;
|
|
1889
|
+
}
|
|
1890
|
+
|
|
1891
|
+
return 1;
|
|
1892
|
+
}
|
|
1893
|
+
|
|
1894
|
+
// FIPS 204, Algorithm 26 (`sigEncode`).
|
|
1895
|
+
template <int K, int L>
|
|
1896
|
+
inline int mldsa_marshal_signature(CBB *out, const signature<K, L> *sign) {
|
|
1897
|
+
if (!CBB_add_bytes(out, sign->c_tilde, sizeof(sign->c_tilde))) {
|
|
1898
|
+
return 0;
|
|
1899
|
+
}
|
|
1900
|
+
|
|
1901
|
+
uint8_t *vectorl_output;
|
|
1902
|
+
if (!CBB_add_space(out, &vectorl_output, scalar_le_gamma1_bytes<K>() * L)) {
|
|
1903
|
+
return 0;
|
|
1904
|
+
}
|
|
1905
|
+
vector_encode_signed<gamma1_bits<K>() + 1, gamma1<K>()>(vectorl_output,
|
|
1906
|
+
&sign->z);
|
|
1907
|
+
|
|
1908
|
+
uint8_t *hint_output;
|
|
1909
|
+
if (!CBB_add_space(out, &hint_output, omega<K>() + K)) {
|
|
1910
|
+
return 0;
|
|
1911
|
+
}
|
|
1912
|
+
hint_bit_pack(hint_output, &sign->h);
|
|
1913
|
+
|
|
1914
|
+
return 1;
|
|
1915
|
+
}
|
|
1916
|
+
|
|
1917
|
+
// FIPS 204, Algorithm 27 (`sigDecode`).
|
|
1918
|
+
template <int K, int L>
|
|
1919
|
+
inline int mldsa_parse_signature(signature<K, L> *sign, CBS *in) {
|
|
1920
|
+
CBS z_bytes;
|
|
1921
|
+
CBS hint_bytes;
|
|
1922
|
+
if (!CBS_copy_bytes(in, sign->c_tilde, sizeof(sign->c_tilde)) ||
|
|
1923
|
+
!CBS_get_bytes(in, &z_bytes, scalar_le_gamma1_bytes<K>() * L) ||
|
|
1924
|
+
// Note: Decoding b+1 bits into (-2^b, 2^b] cannot fail.
|
|
1925
|
+
!vector_decode_signed<gamma1_bits<K>() + 1, gamma1<K>()>(
|
|
1926
|
+
&sign->z, CBS_data(&z_bytes)) ||
|
|
1927
|
+
!CBS_get_bytes(in, &hint_bytes, omega<K>() + K) ||
|
|
1928
|
+
!hint_bit_unpack(&sign->h, CBS_data(&hint_bytes))) {
|
|
1929
|
+
return 0;
|
|
1930
|
+
};
|
|
1931
|
+
|
|
1932
|
+
return 1;
|
|
1933
|
+
}
|
|
1934
|
+
|
|
1935
|
+
// FIPS 204, Algorithm 6 (`ML-DSA.KeyGen_internal`), steps 3 and 5–11.
|
|
1936
|
+
// Returns 1 on success and 0 on failure.
|
|
1937
|
+
//
|
|
1938
|
+
// On input, `priv->s1_ntt` and `priv->s2_ntt` are not yet in NTT form. They are
|
|
1939
|
+
// converted to NTT form by this function.
|
|
1940
|
+
template <int K, int L>
|
|
1941
|
+
inline int mldsa_finish_keygen(
|
|
1942
|
+
uint8_t out_encoded_public_key[public_key_bytes<K>()],
|
|
1943
|
+
private_key<K, L> *priv) {
|
|
1944
|
+
// Intermediate values, allocated on the heap to allow use when there is a
|
|
1945
|
+
// limited amount of stack.
|
|
1946
|
+
struct Values {
|
|
1947
|
+
enum { kAllowUniquePtr = true };
|
|
1948
|
+
matrix<K, L> a_ntt;
|
|
1949
|
+
vector<K> t;
|
|
1950
|
+
};
|
|
1951
|
+
auto values = MakeUnique<Values>();
|
|
1952
|
+
if (values == nullptr) {
|
|
1953
|
+
return 0;
|
|
1954
|
+
}
|
|
1955
|
+
|
|
1956
|
+
// Step 3.
|
|
1957
|
+
matrix_expand(&values->a_ntt, priv->pub.rho);
|
|
1958
|
+
|
|
1959
|
+
// Step 5. Note that, on input, `s1_ntt` and `s2_ntt` are not yet in NTT form,
|
|
1960
|
+
// but this function is responsible for converting them to NTT.
|
|
1961
|
+
vector_ntt(&priv->s1_ntt);
|
|
1962
|
+
matrix_mult_montgomery(&values->t, &values->a_ntt, &priv->s1_ntt);
|
|
1963
|
+
vector_inverse_ntt_montgomery(&values->t);
|
|
1964
|
+
vector_add(&values->t, &values->t, &priv->s2_ntt);
|
|
1965
|
+
vector_ntt(&priv->s2_ntt);
|
|
1966
|
+
|
|
1967
|
+
// Step 6-7. We store t0 in NTT form.
|
|
1968
|
+
vector_power2_round(&priv->pub.t1, &priv->t0_ntt, &values->t);
|
|
1969
|
+
vector_ntt(&priv->t0_ntt);
|
|
1970
|
+
// t1 is public.
|
|
1971
|
+
CONSTTIME_DECLASSIFY(&priv->pub.t1, sizeof(priv->pub.t1));
|
|
1972
|
+
|
|
1973
|
+
// Step 8.
|
|
1974
|
+
CBB cbb;
|
|
1975
|
+
CBB_init_fixed(&cbb, out_encoded_public_key, public_key_bytes<K>());
|
|
1976
|
+
if (!mldsa_marshal_public_key(&cbb, &priv->pub)) {
|
|
1977
|
+
return 0;
|
|
1978
|
+
}
|
|
1979
|
+
assert(CBB_len(&cbb) == public_key_bytes<K>());
|
|
1980
|
+
|
|
1981
|
+
// Step 9-11.
|
|
1982
|
+
BORINGSSL_keccak(priv->pub.public_key_hash, sizeof(priv->pub.public_key_hash),
|
|
1983
|
+
out_encoded_public_key, public_key_bytes<K>(),
|
|
1984
|
+
boringssl_shake256);
|
|
1985
|
+
|
|
1986
|
+
return 1;
|
|
1987
|
+
}
|
|
1988
|
+
|
|
1989
|
+
// FIPS 204, Algorithm 6 (`ML-DSA.KeyGen_internal`). Returns 1 on success and 0
|
|
1990
|
+
// on failure.
|
|
1991
|
+
template <int K, int L>
|
|
1992
|
+
inline int mldsa_generate_key_external_entropy_no_self_test(
|
|
1993
|
+
uint8_t out_encoded_public_key[public_key_bytes<K>()],
|
|
1994
|
+
private_key<K, L> *priv, const uint8_t entropy[MLDSA_SEED_BYTES]) {
|
|
1995
|
+
// Step 1-2.
|
|
1996
|
+
uint8_t augmented_entropy[MLDSA_SEED_BYTES + 2];
|
|
1997
|
+
OPENSSL_memcpy(augmented_entropy, entropy, MLDSA_SEED_BYTES);
|
|
1998
|
+
// The k and l parameters are appended to the seed.
|
|
1999
|
+
augmented_entropy[MLDSA_SEED_BYTES] = K;
|
|
2000
|
+
augmented_entropy[MLDSA_SEED_BYTES + 1] = L;
|
|
2001
|
+
uint8_t expanded_seed[kRhoBytes + kSigmaBytes + kKBytes];
|
|
2002
|
+
BORINGSSL_keccak(expanded_seed, sizeof(expanded_seed), augmented_entropy,
|
|
2003
|
+
sizeof(augmented_entropy), boringssl_shake256);
|
|
2004
|
+
const uint8_t *const rho = expanded_seed;
|
|
2005
|
+
const uint8_t *const sigma = expanded_seed + kRhoBytes;
|
|
2006
|
+
const uint8_t *const k = expanded_seed + kRhoBytes + kSigmaBytes;
|
|
2007
|
+
// rho is public.
|
|
2008
|
+
CONSTTIME_DECLASSIFY(rho, kRhoBytes);
|
|
2009
|
+
OPENSSL_memcpy(priv->pub.rho, rho, sizeof(priv->pub.rho));
|
|
2010
|
+
OPENSSL_memcpy(priv->k, k, sizeof(priv->k));
|
|
2011
|
+
// Steps 4. This is independent of A (step 3) and can be done first.
|
|
2012
|
+
// `mldsa_finish_keygen` will convert `s1_ntt` and `s2_ntt` into NTT from.
|
|
2013
|
+
vector_expand_short(&priv->s1_ntt, &priv->s2_ntt, sigma);
|
|
2014
|
+
// Steps 3 and 5-11.
|
|
2015
|
+
return mldsa_finish_keygen(out_encoded_public_key, priv);
|
|
2016
|
+
}
|
|
2017
|
+
|
|
2018
|
+
template <int K, int L>
|
|
2019
|
+
inline int mldsa_generate_key_external_entropy(
|
|
2020
|
+
uint8_t out_encoded_public_key[public_key_bytes<K>()],
|
|
2021
|
+
private_key<K, L> *priv, const uint8_t entropy[MLDSA_SEED_BYTES]) {
|
|
2022
|
+
fips::ensure_keygen_self_test();
|
|
2023
|
+
return mldsa_generate_key_external_entropy_no_self_test(
|
|
2024
|
+
out_encoded_public_key, priv, entropy);
|
|
2025
|
+
}
|
|
2026
|
+
|
|
2027
|
+
// FIPS 204, Algorithm 7 (`ML-DSA.Sign_internal`), using a pre-computed mu.
|
|
2028
|
+
// Returns 1 on success and 0 on failure.
|
|
2029
|
+
template <int K, int L>
|
|
2030
|
+
inline int mldsa_sign_mu_no_self_test(
|
|
2031
|
+
uint8_t out_encoded_signature[signature_bytes<K>()],
|
|
2032
|
+
const private_key<K, L> *priv, const uint8_t mu[kMuBytes],
|
|
2033
|
+
const uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES]) {
|
|
2034
|
+
uint8_t rho_prime[kRhoPrimeBytes];
|
|
2035
|
+
BORINGSSL_keccak_st keccak_ctx;
|
|
2036
|
+
BORINGSSL_keccak_init(&keccak_ctx, boringssl_shake256);
|
|
2037
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, priv->k, sizeof(priv->k));
|
|
2038
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, randomizer,
|
|
2039
|
+
BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES);
|
|
2040
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, mu, kMuBytes);
|
|
2041
|
+
BORINGSSL_keccak_squeeze(&keccak_ctx, rho_prime, kRhoPrimeBytes);
|
|
2042
|
+
|
|
2043
|
+
// Intermediate values, allocated on the heap to allow use when there is a
|
|
2044
|
+
// limited amount of stack.
|
|
2045
|
+
struct Values {
|
|
2046
|
+
enum { kAllowUniquePtr = true };
|
|
2047
|
+
signature<K, L> sign;
|
|
2048
|
+
matrix<K, L> a_ntt;
|
|
2049
|
+
vector<L> y;
|
|
2050
|
+
vector<K> w;
|
|
2051
|
+
vector<K> w1;
|
|
2052
|
+
vector<L> cs1;
|
|
2053
|
+
vector<K> cs2;
|
|
2054
|
+
};
|
|
2055
|
+
auto values = MakeUnique<Values>();
|
|
2056
|
+
if (values == nullptr) {
|
|
2057
|
+
return 0;
|
|
2058
|
+
}
|
|
2059
|
+
matrix_expand(&values->a_ntt, priv->pub.rho);
|
|
2060
|
+
|
|
2061
|
+
// kappa must not exceed 2**16/L = 13107. But the probability of it
|
|
2062
|
+
// exceeding even 1000 iterations is vanishingly small.
|
|
2063
|
+
for (size_t kappa = 0;; kappa += L) {
|
|
2064
|
+
vector_expand_mask<K, L>(&values->y, rho_prime, kappa);
|
|
2065
|
+
|
|
2066
|
+
vector<L> *y_ntt = &values->cs1;
|
|
2067
|
+
OPENSSL_memcpy(y_ntt, &values->y, sizeof(*y_ntt));
|
|
2068
|
+
vector_ntt(y_ntt);
|
|
2069
|
+
|
|
2070
|
+
matrix_mult_montgomery(&values->w, &values->a_ntt, y_ntt);
|
|
2071
|
+
vector_inverse_ntt_montgomery(&values->w);
|
|
2072
|
+
|
|
2073
|
+
vector_high_bits(&values->w1, &values->w);
|
|
2074
|
+
uint8_t w1_encoded[w1_bytes<K>()];
|
|
2075
|
+
w1_encode(w1_encoded, &values->w1);
|
|
2076
|
+
|
|
2077
|
+
BORINGSSL_keccak_init(&keccak_ctx, boringssl_shake256);
|
|
2078
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, mu, kMuBytes);
|
|
2079
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, w1_encoded, w1_bytes<K>());
|
|
2080
|
+
BORINGSSL_keccak_squeeze(&keccak_ctx, values->sign.c_tilde,
|
|
2081
|
+
2 * lambda_bytes<K>());
|
|
2082
|
+
|
|
2083
|
+
scalar c_ntt;
|
|
2084
|
+
scalar_sample_in_ball_vartime(&c_ntt, values->sign.c_tilde,
|
|
2085
|
+
sizeof(values->sign.c_tilde), tau<K>());
|
|
2086
|
+
scalar_ntt(&c_ntt);
|
|
2087
|
+
|
|
2088
|
+
vector_mult_scalar_montgomery(&values->cs1, &priv->s1_ntt, &c_ntt);
|
|
2089
|
+
vector_inverse_ntt_montgomery(&values->cs1);
|
|
2090
|
+
vector_mult_scalar_montgomery(&values->cs2, &priv->s2_ntt, &c_ntt);
|
|
2091
|
+
vector_inverse_ntt_montgomery(&values->cs2);
|
|
2092
|
+
|
|
2093
|
+
vector_add(&values->sign.z, &values->y, &values->cs1);
|
|
2094
|
+
|
|
2095
|
+
vector<K> *r0 = &values->w1;
|
|
2096
|
+
vector_sub(r0, &values->w, &values->cs2);
|
|
2097
|
+
vector_low_bits(r0, r0);
|
|
2098
|
+
|
|
2099
|
+
// Leaking the fact that a signature was rejected is fine as the next
|
|
2100
|
+
// attempt at a signature will be (indistinguishable from) independent of
|
|
2101
|
+
// this one. Note, however, that we additionally leak which of the two
|
|
2102
|
+
// branches rejected the signature. Section 5.5 of
|
|
2103
|
+
// https://pq-crystals.org/dilithium/data/dilithium-specification-round3.pdf
|
|
2104
|
+
// describes this leak as OK. Note we leak less than what is described by
|
|
2105
|
+
// the paper; we do not reveal which coefficient violated the bound, and
|
|
2106
|
+
// we hide which of the `z_max` or `r0_max` bound failed. See also
|
|
2107
|
+
// https://boringssl-review.googlesource.com/c/boringssl/+/67747/comment/2bbab0fa_d241d35a/
|
|
2108
|
+
uint32_t z_max = vector_max(&values->sign.z);
|
|
2109
|
+
uint32_t r0_max = vector_max_signed(r0);
|
|
2110
|
+
if (constant_time_declassify_w(
|
|
2111
|
+
constant_time_ge_w(z_max, gamma1<K>() - beta<K>()) |
|
|
2112
|
+
constant_time_ge_w(r0_max, gamma2<K>() - beta<K>()))) {
|
|
2113
|
+
#if defined(BORINGSSL_FIPS_BREAK_TESTS)
|
|
2114
|
+
// In order to show that our self-tests trigger both restart cases in
|
|
2115
|
+
// this loop, printf-logging is added when built in break-test mode.
|
|
2116
|
+
printf("MLDSA signature restart case 1.\n");
|
|
2117
|
+
#endif
|
|
2118
|
+
continue;
|
|
2119
|
+
}
|
|
2120
|
+
|
|
2121
|
+
vector<K> *ct0 = &values->w1;
|
|
2122
|
+
vector_mult_scalar_montgomery(ct0, &priv->t0_ntt, &c_ntt);
|
|
2123
|
+
vector_inverse_ntt_montgomery(ct0);
|
|
2124
|
+
vector_make_hint(&values->sign.h, ct0, &values->cs2, &values->w);
|
|
2125
|
+
|
|
2126
|
+
// See above.
|
|
2127
|
+
uint32_t ct0_max = vector_max(ct0);
|
|
2128
|
+
size_t h_ones = vector_count_ones(&values->sign.h);
|
|
2129
|
+
if (constant_time_declassify_w(constant_time_ge_w(ct0_max, gamma2<K>()) |
|
|
2130
|
+
constant_time_lt_w(omega<K>(), h_ones))) {
|
|
2131
|
+
#if defined(BORINGSSL_FIPS_BREAK_TESTS)
|
|
2132
|
+
// In order to show that our self-tests trigger both restart cases in
|
|
2133
|
+
// this loop, printf-logging is added when built in break-test mode.
|
|
2134
|
+
printf("MLDSA signature restart case 2.\n");
|
|
2135
|
+
#endif
|
|
2136
|
+
continue;
|
|
2137
|
+
}
|
|
2138
|
+
|
|
2139
|
+
// Although computed with the private key, the signature is public.
|
|
2140
|
+
CONSTTIME_DECLASSIFY(values->sign.c_tilde, sizeof(values->sign.c_tilde));
|
|
2141
|
+
CONSTTIME_DECLASSIFY(&values->sign.z, sizeof(values->sign.z));
|
|
2142
|
+
CONSTTIME_DECLASSIFY(&values->sign.h, sizeof(values->sign.h));
|
|
2143
|
+
|
|
2144
|
+
CBB cbb;
|
|
2145
|
+
CBB_init_fixed(&cbb, out_encoded_signature, signature_bytes<K>());
|
|
2146
|
+
if (!mldsa_marshal_signature(&cbb, &values->sign)) {
|
|
2147
|
+
return 0;
|
|
2148
|
+
}
|
|
2149
|
+
|
|
2150
|
+
BSSL_CHECK(CBB_len(&cbb) == signature_bytes<K>());
|
|
2151
|
+
return 1;
|
|
2152
|
+
}
|
|
2153
|
+
}
|
|
2154
|
+
|
|
2155
|
+
// FIPS 204, Algorithm 7 (`ML-DSA.Sign_internal`), using a pre-computed mu.
|
|
2156
|
+
// Returns 1 on success and 0 on failure.
|
|
2157
|
+
template <int K, int L>
|
|
2158
|
+
inline int mldsa_sign_mu(
|
|
2159
|
+
uint8_t out_encoded_signature[signature_bytes<K>()],
|
|
2160
|
+
const private_key<K, L> *priv, const uint8_t mu[kMuBytes],
|
|
2161
|
+
const uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES]) {
|
|
2162
|
+
fips::ensure_sign_self_test();
|
|
2163
|
+
return mldsa_sign_mu_no_self_test(out_encoded_signature, priv, mu,
|
|
2164
|
+
randomizer);
|
|
2165
|
+
}
|
|
2166
|
+
|
|
2167
|
+
// FIPS 204, Algorithm 7 (`ML-DSA.Sign_internal`). Returns 1 on success and 0
|
|
2168
|
+
// on failure.
|
|
2169
|
+
template <int K, int L>
|
|
2170
|
+
inline int mldsa_sign_internal_no_self_test(
|
|
2171
|
+
uint8_t out_encoded_signature[signature_bytes<K>()],
|
|
2172
|
+
const private_key<K, L> *priv, const uint8_t *msg, size_t msg_len,
|
|
2173
|
+
const uint8_t *context_prefix, size_t context_prefix_len,
|
|
2174
|
+
const uint8_t *context, size_t context_len,
|
|
2175
|
+
const uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES]) {
|
|
2176
|
+
uint8_t mu[kMuBytes];
|
|
2177
|
+
BORINGSSL_keccak_st keccak_ctx;
|
|
2178
|
+
BORINGSSL_keccak_init(&keccak_ctx, boringssl_shake256);
|
|
2179
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, priv->pub.public_key_hash,
|
|
2180
|
+
sizeof(priv->pub.public_key_hash));
|
|
2181
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, context_prefix, context_prefix_len);
|
|
2182
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, context, context_len);
|
|
2183
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, msg, msg_len);
|
|
2184
|
+
BORINGSSL_keccak_squeeze(&keccak_ctx, mu, kMuBytes);
|
|
2185
|
+
|
|
2186
|
+
return mldsa_sign_mu_no_self_test(out_encoded_signature, priv, mu,
|
|
2187
|
+
randomizer);
|
|
2188
|
+
}
|
|
2189
|
+
|
|
2190
|
+
// FIPS 204, Algorithm 7 (`ML-DSA.Sign_internal`). Returns 1 on success and 0
|
|
2191
|
+
// on failure.
|
|
2192
|
+
template <int K, int L>
|
|
2193
|
+
inline int mldsa_sign_internal(
|
|
2194
|
+
uint8_t out_encoded_signature[signature_bytes<K>()],
|
|
2195
|
+
const private_key<K, L> *priv, const uint8_t *msg, size_t msg_len,
|
|
2196
|
+
const uint8_t *context_prefix, size_t context_prefix_len,
|
|
2197
|
+
const uint8_t *context, size_t context_len,
|
|
2198
|
+
const uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES]) {
|
|
2199
|
+
fips::ensure_sign_self_test();
|
|
2200
|
+
return mldsa_sign_internal_no_self_test(
|
|
2201
|
+
out_encoded_signature, priv, msg, msg_len, context_prefix,
|
|
2202
|
+
context_prefix_len, context, context_len, randomizer);
|
|
2203
|
+
}
|
|
2204
|
+
|
|
2205
|
+
struct prehash_context {
|
|
2206
|
+
BORINGSSL_keccak_st keccak_ctx;
|
|
2207
|
+
};
|
|
2208
|
+
|
|
2209
|
+
template <int K>
|
|
2210
|
+
inline void mldsa_prehash_init(prehash_context *out_prehash_ctx,
|
|
2211
|
+
const public_key<K> *pub,
|
|
2212
|
+
const uint8_t *context_prefix,
|
|
2213
|
+
size_t context_prefix_len,
|
|
2214
|
+
const uint8_t *context, size_t context_len) {
|
|
2215
|
+
BORINGSSL_keccak_init(&out_prehash_ctx->keccak_ctx, boringssl_shake256);
|
|
2216
|
+
BORINGSSL_keccak_absorb(&out_prehash_ctx->keccak_ctx, pub->public_key_hash,
|
|
2217
|
+
sizeof(pub->public_key_hash));
|
|
2218
|
+
BORINGSSL_keccak_absorb(&out_prehash_ctx->keccak_ctx, context_prefix,
|
|
2219
|
+
context_prefix_len);
|
|
2220
|
+
BORINGSSL_keccak_absorb(&out_prehash_ctx->keccak_ctx, context, context_len);
|
|
2221
|
+
}
|
|
2222
|
+
|
|
2223
|
+
inline void mldsa_prehash_update(prehash_context *inout_prehash_ctx,
|
|
2224
|
+
const uint8_t *msg, size_t msg_len) {
|
|
2225
|
+
BORINGSSL_keccak_absorb(&inout_prehash_ctx->keccak_ctx, msg, msg_len);
|
|
2226
|
+
}
|
|
2227
|
+
|
|
2228
|
+
inline void mldsa_prehash_finalize(uint8_t out_msg_rep[kMuBytes],
|
|
2229
|
+
prehash_context *inout_prehash_ctx) {
|
|
2230
|
+
BORINGSSL_keccak_squeeze(&inout_prehash_ctx->keccak_ctx, out_msg_rep,
|
|
2231
|
+
kMuBytes);
|
|
2232
|
+
}
|
|
2233
|
+
|
|
2234
|
+
// FIPS 204, Algorithm 8 (`ML-DSA.Verify_internal`), using a pre-computed mu.
|
|
2235
|
+
// Returns 1 on success and 0 on failure.
|
|
2236
|
+
template <int K, int L>
|
|
2237
|
+
inline int mldsa_verify_mu_no_self_test(
|
|
2238
|
+
const public_key<K> *pub,
|
|
2239
|
+
const uint8_t encoded_signature[signature_bytes<K>()],
|
|
2240
|
+
const uint8_t mu[kMuBytes]) {
|
|
2241
|
+
// Intermediate values, allocated on the heap to allow use when there is a
|
|
2242
|
+
// limited amount of stack.
|
|
2243
|
+
struct Values {
|
|
2244
|
+
enum { kAllowUniquePtr = true };
|
|
2245
|
+
signature<K, L> sign;
|
|
2246
|
+
matrix<K, L> a_ntt;
|
|
2247
|
+
vector<L> z_ntt;
|
|
2248
|
+
vector<K> az_ntt;
|
|
2249
|
+
vector<K> ct1_ntt;
|
|
2250
|
+
};
|
|
2251
|
+
auto values = MakeUnique<Values>();
|
|
2252
|
+
if (values == nullptr) {
|
|
2253
|
+
return 0;
|
|
2254
|
+
}
|
|
2255
|
+
|
|
2256
|
+
CBS cbs;
|
|
2257
|
+
CBS_init(&cbs, encoded_signature, signature_bytes<K>());
|
|
2258
|
+
if (!mldsa_parse_signature(&values->sign, &cbs)) {
|
|
2259
|
+
return 0;
|
|
2260
|
+
}
|
|
2261
|
+
|
|
2262
|
+
matrix_expand(&values->a_ntt, pub->rho);
|
|
2263
|
+
|
|
2264
|
+
scalar c_ntt;
|
|
2265
|
+
scalar_sample_in_ball_vartime(&c_ntt, values->sign.c_tilde,
|
|
2266
|
+
sizeof(values->sign.c_tilde), tau<K>());
|
|
2267
|
+
scalar_ntt(&c_ntt);
|
|
2268
|
+
|
|
2269
|
+
OPENSSL_memcpy(&values->z_ntt, &values->sign.z, sizeof(values->z_ntt));
|
|
2270
|
+
vector_ntt(&values->z_ntt);
|
|
2271
|
+
|
|
2272
|
+
matrix_mult_montgomery(&values->az_ntt, &values->a_ntt, &values->z_ntt);
|
|
2273
|
+
|
|
2274
|
+
vector_scale_power2_round(&values->ct1_ntt, &pub->t1);
|
|
2275
|
+
vector_ntt(&values->ct1_ntt);
|
|
2276
|
+
|
|
2277
|
+
vector_mult_scalar_montgomery(&values->ct1_ntt, &values->ct1_ntt, &c_ntt);
|
|
2278
|
+
|
|
2279
|
+
vector<K> *const w1 = &values->az_ntt;
|
|
2280
|
+
vector_sub(w1, &values->az_ntt, &values->ct1_ntt);
|
|
2281
|
+
vector_inverse_ntt_montgomery(w1);
|
|
2282
|
+
|
|
2283
|
+
vector_use_hint_vartime(w1, &values->sign.h, w1);
|
|
2284
|
+
uint8_t w1_encoded[w1_bytes<K>()];
|
|
2285
|
+
w1_encode(w1_encoded, w1);
|
|
2286
|
+
|
|
2287
|
+
uint8_t c_tilde[2 * lambda_bytes<K>()];
|
|
2288
|
+
BORINGSSL_keccak_st keccak_ctx;
|
|
2289
|
+
BORINGSSL_keccak_init(&keccak_ctx, boringssl_shake256);
|
|
2290
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, mu, kMuBytes);
|
|
2291
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, w1_encoded, w1_bytes<K>());
|
|
2292
|
+
BORINGSSL_keccak_squeeze(&keccak_ctx, c_tilde, 2 * lambda_bytes<K>());
|
|
2293
|
+
|
|
2294
|
+
uint32_t z_max = vector_max(&values->sign.z);
|
|
2295
|
+
return z_max < static_cast<uint32_t>(gamma1<K>() - beta<K>()) &&
|
|
2296
|
+
OPENSSL_memcmp(c_tilde, values->sign.c_tilde, 2 * lambda_bytes<K>()) ==
|
|
2297
|
+
0;
|
|
2298
|
+
}
|
|
2299
|
+
|
|
2300
|
+
// FIPS 204, Algorithm 8 (`ML-DSA.Verify_internal`), using a pre-computed mu.
|
|
2301
|
+
// Returns 1 on success and 0 on failure.
|
|
2302
|
+
template <int K, int L>
|
|
2303
|
+
inline int mldsa_verify_mu(
|
|
2304
|
+
const public_key<K> *pub,
|
|
2305
|
+
const uint8_t encoded_signature[signature_bytes<K>()],
|
|
2306
|
+
const uint8_t mu[kMuBytes]) {
|
|
2307
|
+
fips::ensure_verify_self_test();
|
|
2308
|
+
return mldsa_verify_mu_no_self_test<K, L>(pub, encoded_signature, mu);
|
|
2309
|
+
}
|
|
2310
|
+
|
|
2311
|
+
// FIPS 204, Algorithm 8 (`ML-DSA.Verify_internal`).
|
|
2312
|
+
template <int K, int L>
|
|
2313
|
+
inline int mldsa_verify_internal_no_self_test(
|
|
2314
|
+
const public_key<K> *pub,
|
|
2315
|
+
const uint8_t encoded_signature[signature_bytes<K>()], const uint8_t *msg,
|
|
2316
|
+
size_t msg_len, const uint8_t *context_prefix, size_t context_prefix_len,
|
|
2317
|
+
const uint8_t *context, size_t context_len) {
|
|
2318
|
+
uint8_t mu[kMuBytes];
|
|
2319
|
+
BORINGSSL_keccak_st keccak_ctx;
|
|
2320
|
+
BORINGSSL_keccak_init(&keccak_ctx, boringssl_shake256);
|
|
2321
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, pub->public_key_hash,
|
|
2322
|
+
sizeof(pub->public_key_hash));
|
|
2323
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, context_prefix, context_prefix_len);
|
|
2324
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, context, context_len);
|
|
2325
|
+
BORINGSSL_keccak_absorb(&keccak_ctx, msg, msg_len);
|
|
2326
|
+
BORINGSSL_keccak_squeeze(&keccak_ctx, mu, kMuBytes);
|
|
2327
|
+
|
|
2328
|
+
return mldsa_verify_mu_no_self_test<K, L>(pub, encoded_signature, mu);
|
|
2329
|
+
}
|
|
2330
|
+
|
|
2331
|
+
// FIPS 204, Algorithm 8 (`ML-DSA.Verify_internal`).
|
|
2332
|
+
template <int K, int L>
|
|
2333
|
+
inline int mldsa_verify_internal(
|
|
2334
|
+
const public_key<K> *pub,
|
|
2335
|
+
const uint8_t encoded_signature[signature_bytes<K>()], const uint8_t *msg,
|
|
2336
|
+
size_t msg_len, const uint8_t *context_prefix, size_t context_prefix_len,
|
|
2337
|
+
const uint8_t *context, size_t context_len) {
|
|
2338
|
+
fips::ensure_verify_self_test();
|
|
2339
|
+
return mldsa_verify_internal_no_self_test<K, L>(
|
|
2340
|
+
pub, encoded_signature, msg, msg_len, context_prefix, context_prefix_len,
|
|
2341
|
+
context, context_len);
|
|
2342
|
+
}
|
|
2343
|
+
|
|
2344
|
+
static_assert(sizeof(MLDSA65_private_key) == sizeof(private_key<6, 5>));
|
|
2345
|
+
static_assert(alignof(MLDSA65_private_key) == alignof(private_key<6, 5>));
|
|
2346
|
+
|
|
2347
|
+
inline const private_key<6, 5> *private_key_from_external_65(
|
|
2348
|
+
const MLDSA65_private_key *external) {
|
|
2349
|
+
return reinterpret_cast<const private_key<6, 5> *>(external);
|
|
2350
|
+
}
|
|
2351
|
+
inline private_key<6, 5> *private_key_from_external_65(
|
|
2352
|
+
MLDSA65_private_key *external) {
|
|
2353
|
+
return reinterpret_cast<private_key<6, 5> *>(external);
|
|
2354
|
+
}
|
|
2355
|
+
|
|
2356
|
+
static_assert(sizeof(MLDSA65_public_key) == sizeof(public_key<6>));
|
|
2357
|
+
static_assert(alignof(MLDSA65_public_key) == alignof(public_key<6>));
|
|
2358
|
+
|
|
2359
|
+
inline const public_key<6> *public_key_from_external_65(
|
|
2360
|
+
const MLDSA65_public_key *external) {
|
|
2361
|
+
return reinterpret_cast<const public_key<6> *>(external);
|
|
2362
|
+
}
|
|
2363
|
+
inline public_key<6> *public_key_from_external_65(
|
|
2364
|
+
MLDSA65_public_key *external) {
|
|
2365
|
+
return reinterpret_cast<public_key<6> *>(external);
|
|
2366
|
+
}
|
|
2367
|
+
|
|
2368
|
+
inline prehash_context *prehash_context_from_external_65(
|
|
2369
|
+
MLDSA65_prehash *external) {
|
|
2370
|
+
static_assert(sizeof(MLDSA65_prehash) == sizeof(prehash_context));
|
|
2371
|
+
static_assert(alignof(MLDSA65_prehash) == alignof(prehash_context));
|
|
2372
|
+
return reinterpret_cast<prehash_context *>(external);
|
|
2373
|
+
}
|
|
2374
|
+
|
|
2375
|
+
static_assert(sizeof(MLDSA87_private_key) == sizeof(private_key<8, 7>));
|
|
2376
|
+
static_assert(alignof(MLDSA87_private_key) == alignof(private_key<8, 7>));
|
|
2377
|
+
inline const private_key<8, 7> *private_key_from_external_87(
|
|
2378
|
+
const MLDSA87_private_key *external) {
|
|
2379
|
+
return reinterpret_cast<const private_key<8, 7> *>(external);
|
|
2380
|
+
}
|
|
2381
|
+
inline private_key<8, 7> *private_key_from_external_87(
|
|
2382
|
+
MLDSA87_private_key *external) {
|
|
2383
|
+
return reinterpret_cast<private_key<8, 7> *>(external);
|
|
2384
|
+
}
|
|
2385
|
+
|
|
2386
|
+
static_assert(sizeof(MLDSA87_public_key) == sizeof(public_key<8>));
|
|
2387
|
+
static_assert(alignof(MLDSA87_public_key) == alignof(public_key<8>));
|
|
2388
|
+
|
|
2389
|
+
inline const public_key<8> *public_key_from_external_87(
|
|
2390
|
+
const MLDSA87_public_key *external) {
|
|
2391
|
+
return reinterpret_cast<const public_key<8> *>(external);
|
|
2392
|
+
}
|
|
2393
|
+
inline public_key<8> *public_key_from_external_87(
|
|
2394
|
+
MLDSA87_public_key *external) {
|
|
2395
|
+
return reinterpret_cast<public_key<8> *>(external);
|
|
2396
|
+
}
|
|
2397
|
+
|
|
2398
|
+
inline prehash_context *prehash_context_from_external_87(
|
|
2399
|
+
MLDSA87_prehash *external) {
|
|
2400
|
+
static_assert(sizeof(MLDSA87_prehash) == sizeof(prehash_context));
|
|
2401
|
+
static_assert(alignof(MLDSA87_prehash) == alignof(prehash_context));
|
|
2402
|
+
return reinterpret_cast<prehash_context *>(external);
|
|
2403
|
+
}
|
|
2404
|
+
|
|
2405
|
+
static_assert(sizeof(MLDSA44_private_key) == sizeof(private_key<4, 4>));
|
|
2406
|
+
static_assert(alignof(MLDSA44_private_key) == alignof(private_key<4, 4>));
|
|
2407
|
+
|
|
2408
|
+
inline const private_key<4, 4> *private_key_from_external_44(
|
|
2409
|
+
const MLDSA44_private_key *external) {
|
|
2410
|
+
return reinterpret_cast<const private_key<4, 4> *>(external);
|
|
2411
|
+
}
|
|
2412
|
+
inline private_key<4, 4> *private_key_from_external_44(
|
|
2413
|
+
MLDSA44_private_key *external) {
|
|
2414
|
+
return reinterpret_cast<private_key<4, 4> *>(external);
|
|
2415
|
+
}
|
|
2416
|
+
|
|
2417
|
+
static_assert(sizeof(MLDSA44_public_key) == sizeof(public_key<4>));
|
|
2418
|
+
static_assert(alignof(MLDSA44_public_key) == alignof(public_key<4>));
|
|
2419
|
+
|
|
2420
|
+
inline const public_key<4> *public_key_from_external_44(
|
|
2421
|
+
const MLDSA44_public_key *external) {
|
|
2422
|
+
return reinterpret_cast<const public_key<4> *>(external);
|
|
2423
|
+
}
|
|
2424
|
+
inline public_key<4> *public_key_from_external_44(
|
|
2425
|
+
MLDSA44_public_key *external) {
|
|
2426
|
+
return reinterpret_cast<public_key<4> *>(external);
|
|
2427
|
+
}
|
|
2428
|
+
|
|
2429
|
+
inline prehash_context *prehash_context_from_external_44(
|
|
2430
|
+
MLDSA44_prehash *external) {
|
|
2431
|
+
static_assert(sizeof(MLDSA44_prehash) == sizeof(prehash_context));
|
|
2432
|
+
static_assert(alignof(MLDSA44_prehash) == alignof(prehash_context));
|
|
2433
|
+
return reinterpret_cast<prehash_context *>(external);
|
|
2434
|
+
}
|
|
2435
|
+
|
|
2436
|
+
namespace fips {
|
|
2437
|
+
|
|
2438
|
+
#include "fips_known_values.inc"
|
|
2439
|
+
|
|
2440
|
+
inline int keygen_self_test() {
|
|
2441
|
+
struct Values {
|
|
2442
|
+
enum { kAllowUniquePtr = true };
|
|
2443
|
+
private_key<6, 5> priv;
|
|
2444
|
+
uint8_t pub_bytes[MLDSA65_PUBLIC_KEY_BYTES];
|
|
2445
|
+
uint8_t priv_bytes[BCM_MLDSA65_PRIVATE_KEY_BYTES];
|
|
2446
|
+
};
|
|
2447
|
+
auto values = MakeUnique<Values>();
|
|
2448
|
+
if (values == nullptr ||
|
|
2449
|
+
!mldsa_generate_key_external_entropy_no_self_test(
|
|
2450
|
+
values->pub_bytes, &values->priv, kGenerateKeyEntropy)) {
|
|
2451
|
+
return 0;
|
|
2452
|
+
}
|
|
2453
|
+
|
|
2454
|
+
CBB cbb;
|
|
2455
|
+
CBB_init_fixed(&cbb, values->priv_bytes, sizeof(values->priv_bytes));
|
|
2456
|
+
if (!mldsa_marshal_private_key(&cbb, &values->priv)) {
|
|
2457
|
+
return 0;
|
|
2458
|
+
}
|
|
2459
|
+
|
|
2460
|
+
if (!BORINGSSL_check_test(kExpectedPublicKey, values->pub_bytes,
|
|
2461
|
+
"ML-DSA keygen public key") ||
|
|
2462
|
+
!BORINGSSL_check_test(kExpectedPrivateKey, values->priv_bytes,
|
|
2463
|
+
"ML-DSA keygen private key")) {
|
|
2464
|
+
return 0;
|
|
2465
|
+
}
|
|
2466
|
+
|
|
2467
|
+
return 1;
|
|
2468
|
+
}
|
|
2469
|
+
|
|
2470
|
+
inline int sign_self_test() {
|
|
2471
|
+
struct Values {
|
|
2472
|
+
enum { kAllowUniquePtr = true };
|
|
2473
|
+
private_key<6, 5> priv;
|
|
2474
|
+
uint8_t pub_bytes[MLDSA65_PUBLIC_KEY_BYTES];
|
|
2475
|
+
uint8_t sig[MLDSA65_SIGNATURE_BYTES];
|
|
2476
|
+
};
|
|
2477
|
+
auto values = MakeUnique<Values>();
|
|
2478
|
+
if (values == nullptr ||
|
|
2479
|
+
!mldsa_generate_key_external_entropy(values->pub_bytes, &values->priv,
|
|
2480
|
+
kSignEntropy)) {
|
|
2481
|
+
return 0;
|
|
2482
|
+
}
|
|
2483
|
+
|
|
2484
|
+
const uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES] = {};
|
|
2485
|
+
|
|
2486
|
+
// This message triggers the first restart case for signing.
|
|
2487
|
+
uint8_t message[4] = {0};
|
|
2488
|
+
if (!mldsa_sign_internal_no_self_test(values->sig, &values->priv, message,
|
|
2489
|
+
sizeof(message), nullptr, 0, nullptr, 0,
|
|
2490
|
+
randomizer)) {
|
|
2491
|
+
return 0;
|
|
2492
|
+
}
|
|
2493
|
+
if (!BORINGSSL_check_test(kExpectedCase1Signature, values->sig,
|
|
2494
|
+
"ML-DSA sign case 1")) {
|
|
2495
|
+
return 0;
|
|
2496
|
+
}
|
|
2497
|
+
|
|
2498
|
+
// This message triggers the second restart case for signing.
|
|
2499
|
+
message[0] = 123;
|
|
2500
|
+
if (!mldsa_sign_internal_no_self_test(values->sig, &values->priv, message,
|
|
2501
|
+
sizeof(message), nullptr, 0, nullptr, 0,
|
|
2502
|
+
randomizer)) {
|
|
2503
|
+
return 0;
|
|
2504
|
+
}
|
|
2505
|
+
if (!BORINGSSL_check_test(kExpectedCase2Signature, values->sig,
|
|
2506
|
+
"ML-DSA sign case 2")) {
|
|
2507
|
+
return 0;
|
|
2508
|
+
}
|
|
2509
|
+
|
|
2510
|
+
return 1;
|
|
2511
|
+
}
|
|
2512
|
+
|
|
2513
|
+
inline int verify_self_test() {
|
|
2514
|
+
struct Values {
|
|
2515
|
+
enum { kAllowUniquePtr = true };
|
|
2516
|
+
private_key<6, 5> priv;
|
|
2517
|
+
uint8_t pub_bytes[MLDSA65_PUBLIC_KEY_BYTES];
|
|
2518
|
+
};
|
|
2519
|
+
auto values = MakeUnique<Values>();
|
|
2520
|
+
if (values == nullptr) {
|
|
2521
|
+
return 0;
|
|
2522
|
+
}
|
|
2523
|
+
|
|
2524
|
+
if (!mldsa_generate_key_external_entropy(values->pub_bytes, &values->priv,
|
|
2525
|
+
kSignEntropy)) {
|
|
2526
|
+
return 0;
|
|
2527
|
+
}
|
|
2528
|
+
|
|
2529
|
+
const uint8_t message[4] = {1, 0};
|
|
2530
|
+
if (!mldsa_verify_internal_no_self_test<6, 5>(
|
|
2531
|
+
&values->priv.pub, kExpectedVerifySignature, message, sizeof(message),
|
|
2532
|
+
nullptr, 0, nullptr, 0)) {
|
|
2533
|
+
return 0;
|
|
2534
|
+
}
|
|
2535
|
+
|
|
2536
|
+
return 1;
|
|
2537
|
+
}
|
|
2538
|
+
|
|
2539
|
+
template <int K, int L>
|
|
2540
|
+
inline int check_key(const private_key<K, L> *priv) {
|
|
2541
|
+
uint8_t sig[signature_bytes<K>()];
|
|
2542
|
+
uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES] = {};
|
|
2543
|
+
if (!mldsa_sign_internal_no_self_test(sig, priv, nullptr, 0, nullptr, 0,
|
|
2544
|
+
nullptr, 0, randomizer)) {
|
|
2545
|
+
return 0;
|
|
2546
|
+
}
|
|
2547
|
+
|
|
2548
|
+
if (boringssl_fips_break_test("MLDSA_PWCT")) {
|
|
2549
|
+
sig[0] ^= 1;
|
|
2550
|
+
}
|
|
2551
|
+
|
|
2552
|
+
if (!mldsa_verify_internal_no_self_test<K, L>(&priv->pub, sig, nullptr, 0,
|
|
2553
|
+
nullptr, 0, nullptr, 0)) {
|
|
2554
|
+
return 0;
|
|
2555
|
+
}
|
|
2556
|
+
return 1;
|
|
2557
|
+
}
|
|
2558
|
+
|
|
2559
|
+
#if defined(BORINGSSL_FIPS)
|
|
2560
|
+
|
|
2561
|
+
void ensure_keygen_self_test() {
|
|
2562
|
+
CRYPTO_once(g_mldsa_keygen_self_test_once_bss_get(), []() {
|
|
2563
|
+
if (!keygen_self_test()) {
|
|
2564
|
+
BORINGSSL_FIPS_abort();
|
|
2565
|
+
}
|
|
2566
|
+
});
|
|
2567
|
+
}
|
|
2568
|
+
|
|
2569
|
+
void ensure_sign_self_test() {
|
|
2570
|
+
CRYPTO_once(g_mldsa_sign_self_test_once_bss_get(), []() {
|
|
2571
|
+
if (!sign_self_test()) {
|
|
2572
|
+
BORINGSSL_FIPS_abort();
|
|
2573
|
+
}
|
|
2574
|
+
});
|
|
2575
|
+
}
|
|
2576
|
+
|
|
2577
|
+
void ensure_verify_self_test() {
|
|
2578
|
+
CRYPTO_once(g_mldsa_verify_self_test_once_bss_get(), []() {
|
|
2579
|
+
if (!verify_self_test()) {
|
|
2580
|
+
BORINGSSL_FIPS_abort();
|
|
2581
|
+
}
|
|
2582
|
+
});
|
|
2583
|
+
}
|
|
2584
|
+
|
|
2585
|
+
#else
|
|
2586
|
+
|
|
2587
|
+
void ensure_keygen_self_test() {}
|
|
2588
|
+
void ensure_sign_self_test() {}
|
|
2589
|
+
void ensure_verify_self_test() {}
|
|
2590
|
+
|
|
2591
|
+
#endif
|
|
2592
|
+
|
|
2593
|
+
} // namespace fips
|
|
2594
|
+
|
|
2595
|
+
} // namespace
|
|
2596
|
+
} // namespace mldsa
|
|
2597
|
+
|
|
2598
|
+
|
|
2599
|
+
// ML-DSA-65 specific wrappers.
|
|
2600
|
+
|
|
2601
|
+
bcm_status bssl::BCM_mldsa65_parse_public_key(MLDSA65_public_key *public_key,
|
|
2602
|
+
CBS *in) {
|
|
2603
|
+
return bcm_as_approved_status(mldsa_parse_public_key(
|
|
2604
|
+
mldsa::public_key_from_external_65(public_key), in));
|
|
2605
|
+
}
|
|
2606
|
+
|
|
2607
|
+
bcm_status bssl::BCM_mldsa65_marshal_private_key(
|
|
2608
|
+
CBB *out, const MLDSA65_private_key *private_key) {
|
|
2609
|
+
return bcm_as_approved_status(mldsa_marshal_private_key(
|
|
2610
|
+
out, mldsa::private_key_from_external_65(private_key)));
|
|
2611
|
+
}
|
|
2612
|
+
|
|
2613
|
+
bcm_status bssl::BCM_mldsa65_parse_private_key(MLDSA65_private_key *private_key,
|
|
2614
|
+
CBS *in) {
|
|
2615
|
+
return bcm_as_approved_status(
|
|
2616
|
+
mldsa_parse_private_key(mldsa::private_key_from_external_65(private_key),
|
|
2617
|
+
in) &&
|
|
2618
|
+
CBS_len(in) == 0);
|
|
2619
|
+
}
|
|
2620
|
+
|
|
2621
|
+
bcm_status bssl::BCM_mldsa65_check_key_fips(MLDSA65_private_key *private_key) {
|
|
2622
|
+
return bcm_as_approved_status(
|
|
2623
|
+
mldsa::fips::check_key(mldsa::private_key_from_external_65(private_key)));
|
|
2624
|
+
}
|
|
2625
|
+
|
|
2626
|
+
// Calls `MLDSA_generate_key_external_entropy` with random bytes from
|
|
2627
|
+
// `BCM_rand_bytes`.
|
|
2628
|
+
bcm_status bssl::BCM_mldsa65_generate_key(
|
|
2629
|
+
uint8_t out_encoded_public_key[MLDSA65_PUBLIC_KEY_BYTES],
|
|
2630
|
+
uint8_t out_seed[MLDSA_SEED_BYTES], MLDSA65_private_key *out_private_key) {
|
|
2631
|
+
BCM_rand_bytes(out_seed, MLDSA_SEED_BYTES);
|
|
2632
|
+
CONSTTIME_SECRET(out_seed, MLDSA_SEED_BYTES);
|
|
2633
|
+
return BCM_mldsa65_generate_key_external_entropy(out_encoded_public_key,
|
|
2634
|
+
out_private_key, out_seed);
|
|
2635
|
+
}
|
|
2636
|
+
|
|
2637
|
+
bcm_status bssl::BCM_mldsa65_private_key_from_seed(
|
|
2638
|
+
MLDSA65_private_key *out_private_key,
|
|
2639
|
+
const uint8_t seed[MLDSA_SEED_BYTES]) {
|
|
2640
|
+
uint8_t public_key[MLDSA65_PUBLIC_KEY_BYTES];
|
|
2641
|
+
return BCM_mldsa65_generate_key_external_entropy(public_key, out_private_key,
|
|
2642
|
+
seed);
|
|
2643
|
+
}
|
|
2644
|
+
|
|
2645
|
+
bcm_status bssl::BCM_mldsa65_generate_key_external_entropy(
|
|
2646
|
+
uint8_t out_encoded_public_key[MLDSA65_PUBLIC_KEY_BYTES],
|
|
2647
|
+
MLDSA65_private_key *out_private_key,
|
|
2648
|
+
const uint8_t entropy[MLDSA_SEED_BYTES]) {
|
|
2649
|
+
return bcm_as_not_approved_status(mldsa_generate_key_external_entropy(
|
|
2650
|
+
out_encoded_public_key,
|
|
2651
|
+
mldsa::private_key_from_external_65(out_private_key), entropy));
|
|
2652
|
+
}
|
|
2653
|
+
|
|
2654
|
+
bcm_status bssl::BCM_mldsa65_generate_key_fips(
|
|
2655
|
+
uint8_t out_encoded_public_key[MLDSA65_PUBLIC_KEY_BYTES],
|
|
2656
|
+
uint8_t out_seed[MLDSA_SEED_BYTES], MLDSA65_private_key *out_private_key) {
|
|
2657
|
+
if (out_encoded_public_key == nullptr || out_private_key == nullptr) {
|
|
2658
|
+
return bcm_status::failure;
|
|
2659
|
+
}
|
|
2660
|
+
if (BCM_mldsa65_generate_key(out_encoded_public_key, out_seed,
|
|
2661
|
+
out_private_key) == bcm_status::failure) {
|
|
2662
|
+
return bcm_status::failure;
|
|
2663
|
+
}
|
|
2664
|
+
return BCM_mldsa65_check_key_fips(out_private_key);
|
|
2665
|
+
}
|
|
2666
|
+
|
|
2667
|
+
bcm_status bssl::BCM_mldsa65_generate_key_external_entropy_fips(
|
|
2668
|
+
uint8_t out_encoded_public_key[MLDSA65_PUBLIC_KEY_BYTES],
|
|
2669
|
+
MLDSA65_private_key *out_private_key,
|
|
2670
|
+
const uint8_t entropy[MLDSA_SEED_BYTES]) {
|
|
2671
|
+
if (out_encoded_public_key == nullptr || out_private_key == nullptr) {
|
|
2672
|
+
return bcm_status::failure;
|
|
2673
|
+
}
|
|
2674
|
+
if (BCM_mldsa65_generate_key_external_entropy(out_encoded_public_key,
|
|
2675
|
+
out_private_key, entropy) ==
|
|
2676
|
+
bcm_status::failure) {
|
|
2677
|
+
return bcm_status::failure;
|
|
2678
|
+
}
|
|
2679
|
+
return BCM_mldsa65_check_key_fips(out_private_key);
|
|
2680
|
+
}
|
|
2681
|
+
|
|
2682
|
+
bcm_status bssl::BCM_mldsa65_private_key_from_seed_fips(
|
|
2683
|
+
MLDSA65_private_key *out_private_key,
|
|
2684
|
+
const uint8_t seed[MLDSA_SEED_BYTES]) {
|
|
2685
|
+
uint8_t public_key[MLDSA65_PUBLIC_KEY_BYTES];
|
|
2686
|
+
if (BCM_mldsa65_generate_key_external_entropy(public_key, out_private_key,
|
|
2687
|
+
seed) == bcm_status::failure) {
|
|
2688
|
+
return bcm_status::failure;
|
|
2689
|
+
}
|
|
2690
|
+
return BCM_mldsa65_check_key_fips(out_private_key);
|
|
2691
|
+
}
|
|
2692
|
+
|
|
2693
|
+
bcm_status bssl::BCM_mldsa65_public_from_private(
|
|
2694
|
+
MLDSA65_public_key *out_public_key,
|
|
2695
|
+
const MLDSA65_private_key *private_key) {
|
|
2696
|
+
const auto *priv = mldsa::private_key_from_external_65(private_key);
|
|
2697
|
+
auto *out_pub = mldsa::public_key_from_external_65(out_public_key);
|
|
2698
|
+
*out_pub = priv->pub;
|
|
2699
|
+
return bcm_status::approved;
|
|
2700
|
+
}
|
|
2701
|
+
|
|
2702
|
+
const MLDSA65_public_key *bssl::BCM_mldsa65_public_of_private(
|
|
2703
|
+
const MLDSA65_private_key *private_key) {
|
|
2704
|
+
return reinterpret_cast<const MLDSA65_public_key *>(
|
|
2705
|
+
&mldsa::private_key_from_external_65(private_key)->pub);
|
|
2706
|
+
}
|
|
2707
|
+
|
|
2708
|
+
bcm_status bssl::BCM_mldsa65_sign_internal(
|
|
2709
|
+
uint8_t out_encoded_signature[MLDSA65_SIGNATURE_BYTES],
|
|
2710
|
+
const MLDSA65_private_key *private_key, const uint8_t *msg, size_t msg_len,
|
|
2711
|
+
const uint8_t *context_prefix, size_t context_prefix_len,
|
|
2712
|
+
const uint8_t *context, size_t context_len,
|
|
2713
|
+
const uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES]) {
|
|
2714
|
+
return bcm_as_approved_status(mldsa_sign_internal(
|
|
2715
|
+
out_encoded_signature, mldsa::private_key_from_external_65(private_key),
|
|
2716
|
+
msg, msg_len, context_prefix, context_prefix_len, context, context_len,
|
|
2717
|
+
randomizer));
|
|
2718
|
+
}
|
|
2719
|
+
|
|
2720
|
+
bcm_status bssl::BCM_mldsa65_sign_mu_internal(
|
|
2721
|
+
uint8_t out_encoded_signature[MLDSA65_SIGNATURE_BYTES],
|
|
2722
|
+
const MLDSA65_private_key *private_key,
|
|
2723
|
+
const uint8_t msg_rep[MLDSA_MU_BYTES],
|
|
2724
|
+
const uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES]) {
|
|
2725
|
+
return bcm_as_approved_status(mldsa_sign_mu(
|
|
2726
|
+
out_encoded_signature, mldsa::private_key_from_external_65(private_key),
|
|
2727
|
+
msg_rep, randomizer));
|
|
2728
|
+
}
|
|
2729
|
+
|
|
2730
|
+
// ML-DSA signature in randomized mode, filling the random bytes with
|
|
2731
|
+
// `BCM_rand_bytes`.
|
|
2732
|
+
bcm_status bssl::BCM_mldsa65_sign(
|
|
2733
|
+
uint8_t out_encoded_signature[MLDSA65_SIGNATURE_BYTES],
|
|
2734
|
+
const MLDSA65_private_key *private_key, const uint8_t *msg, size_t msg_len,
|
|
2735
|
+
const uint8_t *context, size_t context_len) {
|
|
2736
|
+
BSSL_CHECK(context_len <= 255);
|
|
2737
|
+
uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES];
|
|
2738
|
+
BCM_rand_bytes(randomizer, sizeof(randomizer));
|
|
2739
|
+
CONSTTIME_SECRET(randomizer, sizeof(randomizer));
|
|
2740
|
+
|
|
2741
|
+
const uint8_t context_prefix[2] = {0, static_cast<uint8_t>(context_len)};
|
|
2742
|
+
return BCM_mldsa65_sign_internal(
|
|
2743
|
+
out_encoded_signature, private_key, msg, msg_len, context_prefix,
|
|
2744
|
+
sizeof(context_prefix), context, context_len, randomizer);
|
|
2745
|
+
}
|
|
2746
|
+
|
|
2747
|
+
// ML-DSA pre-hashed API: initializing a pre-hashing context.
|
|
2748
|
+
void bssl::BCM_mldsa65_prehash_init(MLDSA65_prehash *out_prehash_ctx,
|
|
2749
|
+
const MLDSA65_public_key *public_key,
|
|
2750
|
+
const uint8_t *context,
|
|
2751
|
+
size_t context_len) {
|
|
2752
|
+
BSSL_CHECK(context_len <= 255);
|
|
2753
|
+
|
|
2754
|
+
const uint8_t context_prefix[2] = {0, static_cast<uint8_t>(context_len)};
|
|
2755
|
+
mldsa_prehash_init(mldsa::prehash_context_from_external_65(out_prehash_ctx),
|
|
2756
|
+
mldsa::public_key_from_external_65(public_key),
|
|
2757
|
+
context_prefix, sizeof(context_prefix), context,
|
|
2758
|
+
context_len);
|
|
2759
|
+
}
|
|
2760
|
+
|
|
2761
|
+
// ML-DSA pre-hashed API: updating a pre-hashing context with a message chunk.
|
|
2762
|
+
void bssl::BCM_mldsa65_prehash_update(MLDSA65_prehash *inout_prehash_ctx,
|
|
2763
|
+
const uint8_t *msg, size_t msg_len) {
|
|
2764
|
+
mldsa_prehash_update(
|
|
2765
|
+
mldsa::prehash_context_from_external_65(inout_prehash_ctx), msg, msg_len);
|
|
2766
|
+
}
|
|
2767
|
+
|
|
2768
|
+
// ML-DSA pre-hashed API: obtaining a message representative to sign.
|
|
2769
|
+
void bssl::BCM_mldsa65_prehash_finalize(uint8_t out_msg_rep[MLDSA_MU_BYTES],
|
|
2770
|
+
MLDSA65_prehash *inout_prehash_ctx) {
|
|
2771
|
+
mldsa_prehash_finalize(
|
|
2772
|
+
out_msg_rep, mldsa::prehash_context_from_external_65(inout_prehash_ctx));
|
|
2773
|
+
}
|
|
2774
|
+
|
|
2775
|
+
// ML-DSA pre-hashed API: signing a message representative.
|
|
2776
|
+
bcm_status bssl::BCM_mldsa65_sign_message_representative(
|
|
2777
|
+
uint8_t out_encoded_signature[MLDSA65_SIGNATURE_BYTES],
|
|
2778
|
+
const MLDSA65_private_key *private_key,
|
|
2779
|
+
const uint8_t msg_rep[MLDSA_MU_BYTES]) {
|
|
2780
|
+
uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES];
|
|
2781
|
+
BCM_rand_bytes(randomizer, sizeof(randomizer));
|
|
2782
|
+
CONSTTIME_SECRET(randomizer, sizeof(randomizer));
|
|
2783
|
+
|
|
2784
|
+
return bcm_as_approved_status(mldsa_sign_mu(
|
|
2785
|
+
out_encoded_signature, mldsa::private_key_from_external_65(private_key),
|
|
2786
|
+
msg_rep, randomizer));
|
|
2787
|
+
}
|
|
2788
|
+
|
|
2789
|
+
// ML-DSA pre-hashed API: verifying a message representative.
|
|
2790
|
+
bcm_status bssl::BCM_mldsa65_verify_message_representative(
|
|
2791
|
+
const MLDSA65_public_key *public_key,
|
|
2792
|
+
const uint8_t signature[MLDSA65_SIGNATURE_BYTES],
|
|
2793
|
+
const uint8_t msg_rep[MLDSA_MU_BYTES]) {
|
|
2794
|
+
return bcm_as_approved_status(mldsa::mldsa_verify_mu<6, 5>(
|
|
2795
|
+
mldsa::public_key_from_external_65(public_key), signature, msg_rep));
|
|
2796
|
+
}
|
|
2797
|
+
|
|
2798
|
+
// FIPS 204, Algorithm 3 (`ML-DSA.Verify`).
|
|
2799
|
+
bcm_status bssl::BCM_mldsa65_verify(
|
|
2800
|
+
const MLDSA65_public_key *public_key,
|
|
2801
|
+
const uint8_t signature[MLDSA65_SIGNATURE_BYTES], const uint8_t *msg,
|
|
2802
|
+
size_t msg_len, const uint8_t *context, size_t context_len) {
|
|
2803
|
+
BSSL_CHECK(context_len <= 255);
|
|
2804
|
+
const uint8_t context_prefix[2] = {0, static_cast<uint8_t>(context_len)};
|
|
2805
|
+
return BCM_mldsa65_verify_internal(public_key, signature, msg, msg_len,
|
|
2806
|
+
context_prefix, sizeof(context_prefix),
|
|
2807
|
+
context, context_len);
|
|
2808
|
+
}
|
|
2809
|
+
|
|
2810
|
+
bcm_status bssl::BCM_mldsa65_verify_internal(
|
|
2811
|
+
const MLDSA65_public_key *public_key,
|
|
2812
|
+
const uint8_t encoded_signature[MLDSA65_SIGNATURE_BYTES],
|
|
2813
|
+
const uint8_t *msg, size_t msg_len, const uint8_t *context_prefix,
|
|
2814
|
+
size_t context_prefix_len, const uint8_t *context, size_t context_len) {
|
|
2815
|
+
return bcm_as_approved_status(mldsa::mldsa_verify_internal<6, 5>(
|
|
2816
|
+
mldsa::public_key_from_external_65(public_key), encoded_signature, msg,
|
|
2817
|
+
msg_len, context_prefix, context_prefix_len, context, context_len));
|
|
2818
|
+
}
|
|
2819
|
+
|
|
2820
|
+
bcm_status bssl::BCM_mldsa65_marshal_public_key(
|
|
2821
|
+
CBB *out, const MLDSA65_public_key *public_key) {
|
|
2822
|
+
return bcm_as_approved_status(mldsa_marshal_public_key(
|
|
2823
|
+
out, mldsa::public_key_from_external_65(public_key)));
|
|
2824
|
+
}
|
|
2825
|
+
|
|
2826
|
+
int bssl::BCM_mldsa65_public_keys_equal(const MLDSA65_public_key *a,
|
|
2827
|
+
const MLDSA65_public_key *b) {
|
|
2828
|
+
auto *a_pub = mldsa::public_key_from_external_65(a);
|
|
2829
|
+
auto *b_pub = mldsa::public_key_from_external_65(b);
|
|
2830
|
+
// It is sufficient to compare `public_key_hash`. When importing a public key,
|
|
2831
|
+
// the hash must be computed. When importing a private key in expanded form
|
|
2832
|
+
// (an internal testing-only API), the hash is provided, but we recompute it
|
|
2833
|
+
// and check for correctness.
|
|
2834
|
+
return OPENSSL_memcmp(a_pub->public_key_hash, b_pub->public_key_hash,
|
|
2835
|
+
sizeof(a_pub->public_key_hash)) == 0;
|
|
2836
|
+
}
|
|
2837
|
+
|
|
2838
|
+
|
|
2839
|
+
// ML-DSA-87 specific wrappers.
|
|
2840
|
+
|
|
2841
|
+
bcm_status bssl::BCM_mldsa87_parse_public_key(MLDSA87_public_key *public_key,
|
|
2842
|
+
CBS *in) {
|
|
2843
|
+
return bcm_as_approved_status(mldsa_parse_public_key(
|
|
2844
|
+
mldsa::public_key_from_external_87(public_key), in));
|
|
2845
|
+
}
|
|
2846
|
+
|
|
2847
|
+
bcm_status bssl::BCM_mldsa87_marshal_private_key(
|
|
2848
|
+
CBB *out, const MLDSA87_private_key *private_key) {
|
|
2849
|
+
return bcm_as_approved_status(mldsa_marshal_private_key(
|
|
2850
|
+
out, mldsa::private_key_from_external_87(private_key)));
|
|
2851
|
+
}
|
|
2852
|
+
|
|
2853
|
+
bcm_status bssl::BCM_mldsa87_parse_private_key(MLDSA87_private_key *private_key,
|
|
2854
|
+
CBS *in) {
|
|
2855
|
+
return bcm_as_approved_status(
|
|
2856
|
+
mldsa_parse_private_key(mldsa::private_key_from_external_87(private_key),
|
|
2857
|
+
in) &&
|
|
2858
|
+
CBS_len(in) == 0);
|
|
2859
|
+
}
|
|
2860
|
+
|
|
2861
|
+
bcm_status bssl::BCM_mldsa87_check_key_fips(MLDSA87_private_key *private_key) {
|
|
2862
|
+
return bcm_as_approved_status(
|
|
2863
|
+
mldsa::fips::check_key(mldsa::private_key_from_external_87(private_key)));
|
|
2864
|
+
}
|
|
2865
|
+
|
|
2866
|
+
// Calls `MLDSA_generate_key_external_entropy` with random bytes from
|
|
2867
|
+
// `BCM_rand_bytes`.
|
|
2868
|
+
bcm_status bssl::BCM_mldsa87_generate_key(
|
|
2869
|
+
uint8_t out_encoded_public_key[MLDSA87_PUBLIC_KEY_BYTES],
|
|
2870
|
+
uint8_t out_seed[MLDSA_SEED_BYTES], MLDSA87_private_key *out_private_key) {
|
|
2871
|
+
BCM_rand_bytes(out_seed, MLDSA_SEED_BYTES);
|
|
2872
|
+
CONSTTIME_SECRET(out_seed, MLDSA_SEED_BYTES);
|
|
2873
|
+
return BCM_mldsa87_generate_key_external_entropy(out_encoded_public_key,
|
|
2874
|
+
out_private_key, out_seed);
|
|
2875
|
+
}
|
|
2876
|
+
|
|
2877
|
+
bcm_status bssl::BCM_mldsa87_private_key_from_seed(
|
|
2878
|
+
MLDSA87_private_key *out_private_key,
|
|
2879
|
+
const uint8_t seed[MLDSA_SEED_BYTES]) {
|
|
2880
|
+
uint8_t public_key[MLDSA87_PUBLIC_KEY_BYTES];
|
|
2881
|
+
return BCM_mldsa87_generate_key_external_entropy(public_key, out_private_key,
|
|
2882
|
+
seed);
|
|
2883
|
+
}
|
|
2884
|
+
|
|
2885
|
+
bcm_status bssl::BCM_mldsa87_generate_key_external_entropy(
|
|
2886
|
+
uint8_t out_encoded_public_key[MLDSA87_PUBLIC_KEY_BYTES],
|
|
2887
|
+
MLDSA87_private_key *out_private_key,
|
|
2888
|
+
const uint8_t entropy[MLDSA_SEED_BYTES]) {
|
|
2889
|
+
return bcm_as_not_approved_status(mldsa_generate_key_external_entropy(
|
|
2890
|
+
out_encoded_public_key,
|
|
2891
|
+
mldsa::private_key_from_external_87(out_private_key), entropy));
|
|
2892
|
+
}
|
|
2893
|
+
|
|
2894
|
+
bcm_status bssl::BCM_mldsa87_generate_key_fips(
|
|
2895
|
+
uint8_t out_encoded_public_key[MLDSA87_PUBLIC_KEY_BYTES],
|
|
2896
|
+
uint8_t out_seed[MLDSA_SEED_BYTES], MLDSA87_private_key *out_private_key) {
|
|
2897
|
+
if (out_encoded_public_key == nullptr || out_private_key == nullptr) {
|
|
2898
|
+
return bcm_status::failure;
|
|
2899
|
+
}
|
|
2900
|
+
if (BCM_mldsa87_generate_key(out_encoded_public_key, out_seed,
|
|
2901
|
+
out_private_key) == bcm_status::failure) {
|
|
2902
|
+
return bcm_status::failure;
|
|
2903
|
+
}
|
|
2904
|
+
return BCM_mldsa87_check_key_fips(out_private_key);
|
|
2905
|
+
}
|
|
2906
|
+
|
|
2907
|
+
bcm_status bssl::BCM_mldsa87_generate_key_external_entropy_fips(
|
|
2908
|
+
uint8_t out_encoded_public_key[MLDSA87_PUBLIC_KEY_BYTES],
|
|
2909
|
+
MLDSA87_private_key *out_private_key,
|
|
2910
|
+
const uint8_t entropy[MLDSA_SEED_BYTES]) {
|
|
2911
|
+
if (out_encoded_public_key == nullptr || out_private_key == nullptr) {
|
|
2912
|
+
return bcm_status::failure;
|
|
2913
|
+
}
|
|
2914
|
+
if (BCM_mldsa87_generate_key_external_entropy(out_encoded_public_key,
|
|
2915
|
+
out_private_key, entropy) ==
|
|
2916
|
+
bcm_status::failure) {
|
|
2917
|
+
return bcm_status::failure;
|
|
2918
|
+
}
|
|
2919
|
+
return BCM_mldsa87_check_key_fips(out_private_key);
|
|
2920
|
+
}
|
|
2921
|
+
|
|
2922
|
+
bcm_status bssl::BCM_mldsa87_private_key_from_seed_fips(
|
|
2923
|
+
MLDSA87_private_key *out_private_key,
|
|
2924
|
+
const uint8_t seed[MLDSA_SEED_BYTES]) {
|
|
2925
|
+
uint8_t public_key[MLDSA87_PUBLIC_KEY_BYTES];
|
|
2926
|
+
if (BCM_mldsa87_generate_key_external_entropy(public_key, out_private_key,
|
|
2927
|
+
seed) == bcm_status::failure) {
|
|
2928
|
+
return bcm_status::failure;
|
|
2929
|
+
}
|
|
2930
|
+
return BCM_mldsa87_check_key_fips(out_private_key);
|
|
2931
|
+
}
|
|
2932
|
+
|
|
2933
|
+
bcm_status bssl::BCM_mldsa87_public_from_private(
|
|
2934
|
+
MLDSA87_public_key *out_public_key,
|
|
2935
|
+
const MLDSA87_private_key *private_key) {
|
|
2936
|
+
const auto *priv = mldsa::private_key_from_external_87(private_key);
|
|
2937
|
+
auto *out_pub = mldsa::public_key_from_external_87(out_public_key);
|
|
2938
|
+
*out_pub = priv->pub;
|
|
2939
|
+
return bcm_status::approved;
|
|
2940
|
+
}
|
|
2941
|
+
|
|
2942
|
+
const MLDSA87_public_key *bssl::BCM_mldsa87_public_of_private(
|
|
2943
|
+
const MLDSA87_private_key *private_key) {
|
|
2944
|
+
return reinterpret_cast<const MLDSA87_public_key *>(
|
|
2945
|
+
&mldsa::private_key_from_external_87(private_key)->pub);
|
|
2946
|
+
}
|
|
2947
|
+
|
|
2948
|
+
bcm_status bssl::BCM_mldsa87_sign_internal(
|
|
2949
|
+
uint8_t out_encoded_signature[MLDSA87_SIGNATURE_BYTES],
|
|
2950
|
+
const MLDSA87_private_key *private_key, const uint8_t *msg, size_t msg_len,
|
|
2951
|
+
const uint8_t *context_prefix, size_t context_prefix_len,
|
|
2952
|
+
const uint8_t *context, size_t context_len,
|
|
2953
|
+
const uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES]) {
|
|
2954
|
+
return bcm_as_approved_status(mldsa_sign_internal(
|
|
2955
|
+
out_encoded_signature, mldsa::private_key_from_external_87(private_key),
|
|
2956
|
+
msg, msg_len, context_prefix, context_prefix_len, context, context_len,
|
|
2957
|
+
randomizer));
|
|
2958
|
+
}
|
|
2959
|
+
|
|
2960
|
+
bcm_status bssl::BCM_mldsa87_sign_mu_internal(
|
|
2961
|
+
uint8_t out_encoded_signature[MLDSA87_SIGNATURE_BYTES],
|
|
2962
|
+
const MLDSA87_private_key *private_key,
|
|
2963
|
+
const uint8_t msg_rep[MLDSA_MU_BYTES],
|
|
2964
|
+
const uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES]) {
|
|
2965
|
+
return bcm_as_approved_status(mldsa_sign_mu(
|
|
2966
|
+
out_encoded_signature, mldsa::private_key_from_external_87(private_key),
|
|
2967
|
+
msg_rep, randomizer));
|
|
2968
|
+
}
|
|
2969
|
+
|
|
2970
|
+
// ML-DSA signature in randomized mode, filling the random bytes with
|
|
2971
|
+
// `BCM_rand_bytes`.
|
|
2972
|
+
bcm_status bssl::BCM_mldsa87_sign(
|
|
2973
|
+
uint8_t out_encoded_signature[MLDSA87_SIGNATURE_BYTES],
|
|
2974
|
+
const MLDSA87_private_key *private_key, const uint8_t *msg, size_t msg_len,
|
|
2975
|
+
const uint8_t *context, size_t context_len) {
|
|
2976
|
+
BSSL_CHECK(context_len <= 255);
|
|
2977
|
+
uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES];
|
|
2978
|
+
BCM_rand_bytes(randomizer, sizeof(randomizer));
|
|
2979
|
+
CONSTTIME_SECRET(randomizer, sizeof(randomizer));
|
|
2980
|
+
|
|
2981
|
+
const uint8_t context_prefix[2] = {0, static_cast<uint8_t>(context_len)};
|
|
2982
|
+
return BCM_mldsa87_sign_internal(
|
|
2983
|
+
out_encoded_signature, private_key, msg, msg_len, context_prefix,
|
|
2984
|
+
sizeof(context_prefix), context, context_len, randomizer);
|
|
2985
|
+
}
|
|
2986
|
+
|
|
2987
|
+
// ML-DSA pre-hashed API: initializing a pre-hashing context.
|
|
2988
|
+
void bssl::BCM_mldsa87_prehash_init(MLDSA87_prehash *out_prehash_ctx,
|
|
2989
|
+
const MLDSA87_public_key *public_key,
|
|
2990
|
+
const uint8_t *context,
|
|
2991
|
+
size_t context_len) {
|
|
2992
|
+
BSSL_CHECK(context_len <= 255);
|
|
2993
|
+
|
|
2994
|
+
const uint8_t context_prefix[2] = {0, static_cast<uint8_t>(context_len)};
|
|
2995
|
+
mldsa_prehash_init(mldsa::prehash_context_from_external_87(out_prehash_ctx),
|
|
2996
|
+
mldsa::public_key_from_external_87(public_key),
|
|
2997
|
+
context_prefix, sizeof(context_prefix), context,
|
|
2998
|
+
context_len);
|
|
2999
|
+
}
|
|
3000
|
+
|
|
3001
|
+
// ML-DSA pre-hashed API: updating a pre-hashing context with a message chunk.
|
|
3002
|
+
void bssl::BCM_mldsa87_prehash_update(MLDSA87_prehash *inout_prehash_ctx,
|
|
3003
|
+
const uint8_t *msg, size_t msg_len) {
|
|
3004
|
+
mldsa_prehash_update(
|
|
3005
|
+
mldsa::prehash_context_from_external_87(inout_prehash_ctx), msg, msg_len);
|
|
3006
|
+
}
|
|
3007
|
+
|
|
3008
|
+
// ML-DSA pre-hashed API: obtaining a message representative to sign.
|
|
3009
|
+
void bssl::BCM_mldsa87_prehash_finalize(uint8_t out_msg_rep[MLDSA_MU_BYTES],
|
|
3010
|
+
MLDSA87_prehash *inout_prehash_ctx) {
|
|
3011
|
+
mldsa_prehash_finalize(
|
|
3012
|
+
out_msg_rep, mldsa::prehash_context_from_external_87(inout_prehash_ctx));
|
|
3013
|
+
}
|
|
3014
|
+
|
|
3015
|
+
// ML-DSA pre-hashed API: signing a message representative.
|
|
3016
|
+
bcm_status bssl::BCM_mldsa87_sign_message_representative(
|
|
3017
|
+
uint8_t out_encoded_signature[MLDSA87_SIGNATURE_BYTES],
|
|
3018
|
+
const MLDSA87_private_key *private_key,
|
|
3019
|
+
const uint8_t msg_rep[MLDSA_MU_BYTES]) {
|
|
3020
|
+
uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES];
|
|
3021
|
+
BCM_rand_bytes(randomizer, sizeof(randomizer));
|
|
3022
|
+
CONSTTIME_SECRET(randomizer, sizeof(randomizer));
|
|
3023
|
+
|
|
3024
|
+
return bcm_as_approved_status(mldsa_sign_mu(
|
|
3025
|
+
out_encoded_signature, mldsa::private_key_from_external_87(private_key),
|
|
3026
|
+
msg_rep, randomizer));
|
|
3027
|
+
}
|
|
3028
|
+
|
|
3029
|
+
// ML-DSA pre-hashed API: verifying a message representative.
|
|
3030
|
+
bcm_status bssl::BCM_mldsa87_verify_message_representative(
|
|
3031
|
+
const MLDSA87_public_key *public_key,
|
|
3032
|
+
const uint8_t signature[MLDSA87_SIGNATURE_BYTES],
|
|
3033
|
+
const uint8_t msg_rep[MLDSA_MU_BYTES]) {
|
|
3034
|
+
return bcm_as_approved_status(mldsa::mldsa_verify_mu<8, 7>(
|
|
3035
|
+
mldsa::public_key_from_external_87(public_key), signature, msg_rep));
|
|
3036
|
+
}
|
|
3037
|
+
|
|
3038
|
+
// FIPS 204, Algorithm 3 (`ML-DSA.Verify`).
|
|
3039
|
+
bcm_status bssl::BCM_mldsa87_verify(const MLDSA87_public_key *public_key,
|
|
3040
|
+
const uint8_t *signature,
|
|
3041
|
+
const uint8_t *msg, size_t msg_len,
|
|
3042
|
+
const uint8_t *context,
|
|
3043
|
+
size_t context_len) {
|
|
3044
|
+
BSSL_CHECK(context_len <= 255);
|
|
3045
|
+
const uint8_t context_prefix[2] = {0, static_cast<uint8_t>(context_len)};
|
|
3046
|
+
return BCM_mldsa87_verify_internal(public_key, signature, msg, msg_len,
|
|
3047
|
+
context_prefix, sizeof(context_prefix),
|
|
3048
|
+
context, context_len);
|
|
3049
|
+
}
|
|
3050
|
+
|
|
3051
|
+
bcm_status bssl::BCM_mldsa87_verify_internal(
|
|
3052
|
+
const MLDSA87_public_key *public_key,
|
|
3053
|
+
const uint8_t encoded_signature[MLDSA87_SIGNATURE_BYTES],
|
|
3054
|
+
const uint8_t *msg, size_t msg_len, const uint8_t *context_prefix,
|
|
3055
|
+
size_t context_prefix_len, const uint8_t *context, size_t context_len) {
|
|
3056
|
+
return bcm_as_approved_status(mldsa::mldsa_verify_internal<8, 7>(
|
|
3057
|
+
mldsa::public_key_from_external_87(public_key), encoded_signature, msg,
|
|
3058
|
+
msg_len, context_prefix, context_prefix_len, context, context_len));
|
|
3059
|
+
}
|
|
3060
|
+
|
|
3061
|
+
bcm_status bssl::BCM_mldsa87_marshal_public_key(
|
|
3062
|
+
CBB *out, const MLDSA87_public_key *public_key) {
|
|
3063
|
+
return bcm_as_approved_status(mldsa_marshal_public_key(
|
|
3064
|
+
out, mldsa::public_key_from_external_87(public_key)));
|
|
3065
|
+
}
|
|
3066
|
+
|
|
3067
|
+
int bssl::BCM_mldsa87_public_keys_equal(const MLDSA87_public_key *a,
|
|
3068
|
+
const MLDSA87_public_key *b) {
|
|
3069
|
+
auto *a_pub = mldsa::public_key_from_external_87(a);
|
|
3070
|
+
auto *b_pub = mldsa::public_key_from_external_87(b);
|
|
3071
|
+
// It is sufficient to compare `public_key_hash`. When importing a public key,
|
|
3072
|
+
// the hash must be computed. When importing a private key in expanded form
|
|
3073
|
+
// (an internal testing-only API), the hash is provided, but we recompute it
|
|
3074
|
+
// and check for correctness.
|
|
3075
|
+
return OPENSSL_memcmp(a_pub->public_key_hash, b_pub->public_key_hash,
|
|
3076
|
+
sizeof(a_pub->public_key_hash)) == 0;
|
|
3077
|
+
}
|
|
3078
|
+
|
|
3079
|
+
|
|
3080
|
+
// ML-DSA-44 specific wrappers.
|
|
3081
|
+
|
|
3082
|
+
bcm_status bssl::BCM_mldsa44_parse_public_key(MLDSA44_public_key *public_key,
|
|
3083
|
+
CBS *in) {
|
|
3084
|
+
return bcm_as_approved_status(mldsa_parse_public_key(
|
|
3085
|
+
mldsa::public_key_from_external_44(public_key), in));
|
|
3086
|
+
}
|
|
3087
|
+
|
|
3088
|
+
bcm_status bssl::BCM_mldsa44_marshal_private_key(
|
|
3089
|
+
CBB *out, const MLDSA44_private_key *private_key) {
|
|
3090
|
+
return bcm_as_approved_status(mldsa_marshal_private_key(
|
|
3091
|
+
out, mldsa::private_key_from_external_44(private_key)));
|
|
3092
|
+
}
|
|
3093
|
+
|
|
3094
|
+
bcm_status bssl::BCM_mldsa44_parse_private_key(MLDSA44_private_key *private_key,
|
|
3095
|
+
CBS *in) {
|
|
3096
|
+
return bcm_as_approved_status(
|
|
3097
|
+
mldsa_parse_private_key(mldsa::private_key_from_external_44(private_key),
|
|
3098
|
+
in) &&
|
|
3099
|
+
CBS_len(in) == 0);
|
|
3100
|
+
}
|
|
3101
|
+
|
|
3102
|
+
bcm_status bssl::BCM_mldsa44_check_key_fips(MLDSA44_private_key *private_key) {
|
|
3103
|
+
return bcm_as_approved_status(
|
|
3104
|
+
mldsa::fips::check_key(mldsa::private_key_from_external_44(private_key)));
|
|
3105
|
+
}
|
|
3106
|
+
|
|
3107
|
+
// Calls `MLDSA_generate_key_external_entropy` with random bytes from
|
|
3108
|
+
// `BCM_rand_bytes`.
|
|
3109
|
+
bcm_status bssl::BCM_mldsa44_generate_key(
|
|
3110
|
+
uint8_t out_encoded_public_key[MLDSA44_PUBLIC_KEY_BYTES],
|
|
3111
|
+
uint8_t out_seed[MLDSA_SEED_BYTES], MLDSA44_private_key *out_private_key) {
|
|
3112
|
+
BCM_rand_bytes(out_seed, MLDSA_SEED_BYTES);
|
|
3113
|
+
CONSTTIME_SECRET(out_seed, MLDSA_SEED_BYTES);
|
|
3114
|
+
return BCM_mldsa44_generate_key_external_entropy(out_encoded_public_key,
|
|
3115
|
+
out_private_key, out_seed);
|
|
3116
|
+
}
|
|
3117
|
+
|
|
3118
|
+
bcm_status bssl::BCM_mldsa44_private_key_from_seed(
|
|
3119
|
+
MLDSA44_private_key *out_private_key,
|
|
3120
|
+
const uint8_t seed[MLDSA_SEED_BYTES]) {
|
|
3121
|
+
uint8_t public_key[MLDSA44_PUBLIC_KEY_BYTES];
|
|
3122
|
+
return BCM_mldsa44_generate_key_external_entropy(public_key, out_private_key,
|
|
3123
|
+
seed);
|
|
3124
|
+
}
|
|
3125
|
+
|
|
3126
|
+
bcm_status bssl::BCM_mldsa44_generate_key_external_entropy(
|
|
3127
|
+
uint8_t out_encoded_public_key[MLDSA44_PUBLIC_KEY_BYTES],
|
|
3128
|
+
MLDSA44_private_key *out_private_key,
|
|
3129
|
+
const uint8_t entropy[MLDSA_SEED_BYTES]) {
|
|
3130
|
+
return bcm_as_not_approved_status(mldsa_generate_key_external_entropy(
|
|
3131
|
+
out_encoded_public_key,
|
|
3132
|
+
mldsa::private_key_from_external_44(out_private_key), entropy));
|
|
3133
|
+
}
|
|
3134
|
+
|
|
3135
|
+
bcm_status bssl::BCM_mldsa44_generate_key_fips(
|
|
3136
|
+
uint8_t out_encoded_public_key[MLDSA44_PUBLIC_KEY_BYTES],
|
|
3137
|
+
uint8_t out_seed[MLDSA_SEED_BYTES], MLDSA44_private_key *out_private_key) {
|
|
3138
|
+
if (out_encoded_public_key == nullptr || out_private_key == nullptr) {
|
|
3139
|
+
return bcm_status::failure;
|
|
3140
|
+
}
|
|
3141
|
+
if (BCM_mldsa44_generate_key(out_encoded_public_key, out_seed,
|
|
3142
|
+
out_private_key) == bcm_status::failure) {
|
|
3143
|
+
return bcm_status::failure;
|
|
3144
|
+
}
|
|
3145
|
+
return BCM_mldsa44_check_key_fips(out_private_key);
|
|
3146
|
+
}
|
|
3147
|
+
|
|
3148
|
+
bcm_status bssl::BCM_mldsa44_generate_key_external_entropy_fips(
|
|
3149
|
+
uint8_t out_encoded_public_key[MLDSA44_PUBLIC_KEY_BYTES],
|
|
3150
|
+
MLDSA44_private_key *out_private_key,
|
|
3151
|
+
const uint8_t entropy[MLDSA_SEED_BYTES]) {
|
|
3152
|
+
if (out_encoded_public_key == nullptr || out_private_key == nullptr) {
|
|
3153
|
+
return bcm_status::failure;
|
|
3154
|
+
}
|
|
3155
|
+
if (BCM_mldsa44_generate_key_external_entropy(out_encoded_public_key,
|
|
3156
|
+
out_private_key, entropy) ==
|
|
3157
|
+
bcm_status::failure) {
|
|
3158
|
+
return bcm_status::failure;
|
|
3159
|
+
}
|
|
3160
|
+
return BCM_mldsa44_check_key_fips(out_private_key);
|
|
3161
|
+
}
|
|
3162
|
+
|
|
3163
|
+
bcm_status bssl::BCM_mldsa44_private_key_from_seed_fips(
|
|
3164
|
+
MLDSA44_private_key *out_private_key,
|
|
3165
|
+
const uint8_t seed[MLDSA_SEED_BYTES]) {
|
|
3166
|
+
uint8_t public_key[MLDSA44_PUBLIC_KEY_BYTES];
|
|
3167
|
+
if (BCM_mldsa44_generate_key_external_entropy(public_key, out_private_key,
|
|
3168
|
+
seed) == bcm_status::failure) {
|
|
3169
|
+
return bcm_status::failure;
|
|
3170
|
+
}
|
|
3171
|
+
return BCM_mldsa44_check_key_fips(out_private_key);
|
|
3172
|
+
}
|
|
3173
|
+
|
|
3174
|
+
bcm_status bssl::BCM_mldsa44_public_from_private(
|
|
3175
|
+
MLDSA44_public_key *out_public_key,
|
|
3176
|
+
const MLDSA44_private_key *private_key) {
|
|
3177
|
+
const auto *priv = mldsa::private_key_from_external_44(private_key);
|
|
3178
|
+
auto *out_pub = mldsa::public_key_from_external_44(out_public_key);
|
|
3179
|
+
*out_pub = priv->pub;
|
|
3180
|
+
return bcm_status::approved;
|
|
3181
|
+
}
|
|
3182
|
+
|
|
3183
|
+
const MLDSA44_public_key *bssl::BCM_mldsa44_public_of_private(
|
|
3184
|
+
const MLDSA44_private_key *private_key) {
|
|
3185
|
+
return reinterpret_cast<const MLDSA44_public_key *>(
|
|
3186
|
+
&mldsa::private_key_from_external_44(private_key)->pub);
|
|
3187
|
+
}
|
|
3188
|
+
|
|
3189
|
+
bcm_status bssl::BCM_mldsa44_sign_internal(
|
|
3190
|
+
uint8_t out_encoded_signature[MLDSA44_SIGNATURE_BYTES],
|
|
3191
|
+
const MLDSA44_private_key *private_key, const uint8_t *msg, size_t msg_len,
|
|
3192
|
+
const uint8_t *context_prefix, size_t context_prefix_len,
|
|
3193
|
+
const uint8_t *context, size_t context_len,
|
|
3194
|
+
const uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES]) {
|
|
3195
|
+
return bcm_as_approved_status(mldsa_sign_internal(
|
|
3196
|
+
out_encoded_signature, mldsa::private_key_from_external_44(private_key),
|
|
3197
|
+
msg, msg_len, context_prefix, context_prefix_len, context, context_len,
|
|
3198
|
+
randomizer));
|
|
3199
|
+
}
|
|
3200
|
+
|
|
3201
|
+
bcm_status bssl::BCM_mldsa44_sign_mu_internal(
|
|
3202
|
+
uint8_t out_encoded_signature[MLDSA44_SIGNATURE_BYTES],
|
|
3203
|
+
const MLDSA44_private_key *private_key,
|
|
3204
|
+
const uint8_t msg_rep[MLDSA_MU_BYTES],
|
|
3205
|
+
const uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES]) {
|
|
3206
|
+
return bcm_as_approved_status(mldsa_sign_mu(
|
|
3207
|
+
out_encoded_signature, mldsa::private_key_from_external_44(private_key),
|
|
3208
|
+
msg_rep, randomizer));
|
|
3209
|
+
}
|
|
3210
|
+
|
|
3211
|
+
// ML-DSA signature in randomized mode, filling the random bytes with
|
|
3212
|
+
// `BCM_rand_bytes`.
|
|
3213
|
+
bcm_status bssl::BCM_mldsa44_sign(
|
|
3214
|
+
uint8_t out_encoded_signature[MLDSA44_SIGNATURE_BYTES],
|
|
3215
|
+
const MLDSA44_private_key *private_key, const uint8_t *msg, size_t msg_len,
|
|
3216
|
+
const uint8_t *context, size_t context_len) {
|
|
3217
|
+
BSSL_CHECK(context_len <= 255);
|
|
3218
|
+
uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES];
|
|
3219
|
+
BCM_rand_bytes(randomizer, sizeof(randomizer));
|
|
3220
|
+
CONSTTIME_SECRET(randomizer, sizeof(randomizer));
|
|
3221
|
+
|
|
3222
|
+
const uint8_t context_prefix[2] = {0, static_cast<uint8_t>(context_len)};
|
|
3223
|
+
return BCM_mldsa44_sign_internal(
|
|
3224
|
+
out_encoded_signature, private_key, msg, msg_len, context_prefix,
|
|
3225
|
+
sizeof(context_prefix), context, context_len, randomizer);
|
|
3226
|
+
}
|
|
3227
|
+
|
|
3228
|
+
// ML-DSA pre-hashed API: initializing a pre-hashing context.
|
|
3229
|
+
void bssl::BCM_mldsa44_prehash_init(MLDSA44_prehash *out_prehash_ctx,
|
|
3230
|
+
const MLDSA44_public_key *public_key,
|
|
3231
|
+
const uint8_t *context,
|
|
3232
|
+
size_t context_len) {
|
|
3233
|
+
BSSL_CHECK(context_len <= 255);
|
|
3234
|
+
|
|
3235
|
+
const uint8_t context_prefix[2] = {0, static_cast<uint8_t>(context_len)};
|
|
3236
|
+
mldsa_prehash_init(mldsa::prehash_context_from_external_44(out_prehash_ctx),
|
|
3237
|
+
mldsa::public_key_from_external_44(public_key),
|
|
3238
|
+
context_prefix, sizeof(context_prefix), context,
|
|
3239
|
+
context_len);
|
|
3240
|
+
}
|
|
3241
|
+
|
|
3242
|
+
// ML-DSA pre-hashed API: updating a pre-hashing context with a message chunk.
|
|
3243
|
+
void bssl::BCM_mldsa44_prehash_update(MLDSA44_prehash *inout_prehash_ctx,
|
|
3244
|
+
const uint8_t *msg, size_t msg_len) {
|
|
3245
|
+
mldsa_prehash_update(
|
|
3246
|
+
mldsa::prehash_context_from_external_44(inout_prehash_ctx), msg, msg_len);
|
|
3247
|
+
}
|
|
3248
|
+
|
|
3249
|
+
// ML-DSA pre-hashed API: obtaining a message representative to sign.
|
|
3250
|
+
void bssl::BCM_mldsa44_prehash_finalize(uint8_t out_msg_rep[MLDSA_MU_BYTES],
|
|
3251
|
+
MLDSA44_prehash *inout_prehash_ctx) {
|
|
3252
|
+
mldsa_prehash_finalize(
|
|
3253
|
+
out_msg_rep, mldsa::prehash_context_from_external_44(inout_prehash_ctx));
|
|
3254
|
+
}
|
|
3255
|
+
|
|
3256
|
+
// ML-DSA pre-hashed API: signing a message representative.
|
|
3257
|
+
bcm_status bssl::BCM_mldsa44_sign_message_representative(
|
|
3258
|
+
uint8_t out_encoded_signature[MLDSA44_SIGNATURE_BYTES],
|
|
3259
|
+
const MLDSA44_private_key *private_key,
|
|
3260
|
+
const uint8_t msg_rep[MLDSA_MU_BYTES]) {
|
|
3261
|
+
uint8_t randomizer[BCM_MLDSA_SIGNATURE_RANDOMIZER_BYTES];
|
|
3262
|
+
BCM_rand_bytes(randomizer, sizeof(randomizer));
|
|
3263
|
+
CONSTTIME_SECRET(randomizer, sizeof(randomizer));
|
|
3264
|
+
|
|
3265
|
+
return bcm_as_approved_status(mldsa_sign_mu(
|
|
3266
|
+
out_encoded_signature, mldsa::private_key_from_external_44(private_key),
|
|
3267
|
+
msg_rep, randomizer));
|
|
3268
|
+
}
|
|
3269
|
+
|
|
3270
|
+
// ML-DSA pre-hashed API: verifying a message representative.
|
|
3271
|
+
bcm_status bssl::BCM_mldsa44_verify_message_representative(
|
|
3272
|
+
const MLDSA44_public_key *public_key,
|
|
3273
|
+
const uint8_t signature[MLDSA44_SIGNATURE_BYTES],
|
|
3274
|
+
const uint8_t msg_rep[MLDSA_MU_BYTES]) {
|
|
3275
|
+
return bcm_as_approved_status(mldsa::mldsa_verify_mu<4, 4>(
|
|
3276
|
+
mldsa::public_key_from_external_44(public_key), signature, msg_rep));
|
|
3277
|
+
}
|
|
3278
|
+
|
|
3279
|
+
// FIPS 204, Algorithm 3 (`ML-DSA.Verify`).
|
|
3280
|
+
bcm_status bssl::BCM_mldsa44_verify(const MLDSA44_public_key *public_key,
|
|
3281
|
+
const uint8_t *signature,
|
|
3282
|
+
const uint8_t *msg, size_t msg_len,
|
|
3283
|
+
const uint8_t *context,
|
|
3284
|
+
size_t context_len) {
|
|
3285
|
+
BSSL_CHECK(context_len <= 255);
|
|
3286
|
+
const uint8_t context_prefix[2] = {0, static_cast<uint8_t>(context_len)};
|
|
3287
|
+
return BCM_mldsa44_verify_internal(public_key, signature, msg, msg_len,
|
|
3288
|
+
context_prefix, sizeof(context_prefix),
|
|
3289
|
+
context, context_len);
|
|
3290
|
+
}
|
|
3291
|
+
|
|
3292
|
+
bcm_status bssl::BCM_mldsa44_verify_internal(
|
|
3293
|
+
const MLDSA44_public_key *public_key,
|
|
3294
|
+
const uint8_t encoded_signature[MLDSA44_SIGNATURE_BYTES],
|
|
3295
|
+
const uint8_t *msg, size_t msg_len, const uint8_t *context_prefix,
|
|
3296
|
+
size_t context_prefix_len, const uint8_t *context, size_t context_len) {
|
|
3297
|
+
return bcm_as_approved_status(mldsa::mldsa_verify_internal<4, 4>(
|
|
3298
|
+
mldsa::public_key_from_external_44(public_key), encoded_signature, msg,
|
|
3299
|
+
msg_len, context_prefix, context_prefix_len, context, context_len));
|
|
3300
|
+
}
|
|
3301
|
+
|
|
3302
|
+
bcm_status bssl::BCM_mldsa44_marshal_public_key(
|
|
3303
|
+
CBB *out, const MLDSA44_public_key *public_key) {
|
|
3304
|
+
return bcm_as_approved_status(mldsa_marshal_public_key(
|
|
3305
|
+
out, mldsa::public_key_from_external_44(public_key)));
|
|
3306
|
+
}
|
|
3307
|
+
|
|
3308
|
+
int bssl::BCM_mldsa44_public_keys_equal(const MLDSA44_public_key *a,
|
|
3309
|
+
const MLDSA44_public_key *b) {
|
|
3310
|
+
auto *a_pub = mldsa::public_key_from_external_44(a);
|
|
3311
|
+
auto *b_pub = mldsa::public_key_from_external_44(b);
|
|
3312
|
+
// It is sufficient to compare `public_key_hash`. When importing a public key,
|
|
3313
|
+
// the hash must be computed. When importing a private key in expanded form
|
|
3314
|
+
// (an internal testing-only API), the hash is provided, but we recompute it
|
|
3315
|
+
// and check for correctness.
|
|
3316
|
+
return OPENSSL_memcmp(a_pub->public_key_hash, b_pub->public_key_hash,
|
|
3317
|
+
sizeof(a_pub->public_key_hash)) == 0;
|
|
3318
|
+
}
|
|
3319
|
+
|
|
3320
|
+
int bssl::boringssl_self_test_mldsa() {
|
|
3321
|
+
return mldsa::fips::keygen_self_test() && mldsa::fips::sign_self_test() &&
|
|
3322
|
+
mldsa::fips::verify_self_test();
|
|
3323
|
+
}
|