longfellow 0.1.0
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.
- checksums.yaml +7 -0
- data/CODE_OF_CONDUCT.md +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +152 -0
- data/ext/longfellow/CMakeLists.txt +76 -0
- data/ext/longfellow/extconf.rb +77 -0
- data/lib/longfellow/attribute.rb +65 -0
- data/lib/longfellow/c.rb +105 -0
- data/lib/longfellow/errors.rb +78 -0
- data/lib/longfellow/version.rb +5 -0
- data/lib/longfellow/zk_spec.rb +40 -0
- data/lib/longfellow.rb +162 -0
- data/sig/longfellow.rbs +74 -0
- data/vendor/longfellow-zk/LICENSE +203 -0
- data/vendor/longfellow-zk/lib/algebra/blas.h +121 -0
- data/vendor/longfellow-zk/lib/algebra/bogorng.h +68 -0
- data/vendor/longfellow-zk/lib/algebra/compare.h +40 -0
- data/vendor/longfellow-zk/lib/algebra/convolution.h +219 -0
- data/vendor/longfellow-zk/lib/algebra/crt.cc +42 -0
- data/vendor/longfellow-zk/lib/algebra/crt.h +299 -0
- data/vendor/longfellow-zk/lib/algebra/crt_convolution.h +114 -0
- data/vendor/longfellow-zk/lib/algebra/crt_test.cc +371 -0
- data/vendor/longfellow-zk/lib/algebra/fft.h +104 -0
- data/vendor/longfellow-zk/lib/algebra/fft_interpolation.h +304 -0
- data/vendor/longfellow-zk/lib/algebra/fft_interpolation_test.cc +168 -0
- data/vendor/longfellow-zk/lib/algebra/fft_test.cc +257 -0
- data/vendor/longfellow-zk/lib/algebra/fp.h +59 -0
- data/vendor/longfellow-zk/lib/algebra/fp2.h +240 -0
- data/vendor/longfellow-zk/lib/algebra/fp24.h +342 -0
- data/vendor/longfellow-zk/lib/algebra/fp24_6.h +305 -0
- data/vendor/longfellow-zk/lib/algebra/fp24_6_test.cc +197 -0
- data/vendor/longfellow-zk/lib/algebra/fp2_test.cc +280 -0
- data/vendor/longfellow-zk/lib/algebra/fp_generic.h +533 -0
- data/vendor/longfellow-zk/lib/algebra/fp_p128.h +91 -0
- data/vendor/longfellow-zk/lib/algebra/fp_p256.h +68 -0
- data/vendor/longfellow-zk/lib/algebra/fp_p256k1.h +123 -0
- data/vendor/longfellow-zk/lib/algebra/fp_p384.h +65 -0
- data/vendor/longfellow-zk/lib/algebra/fp_p521.h +62 -0
- data/vendor/longfellow-zk/lib/algebra/fp_test.cc +522 -0
- data/vendor/longfellow-zk/lib/algebra/hash.h +39 -0
- data/vendor/longfellow-zk/lib/algebra/interpolation.h +117 -0
- data/vendor/longfellow-zk/lib/algebra/interpolation_test.cc +74 -0
- data/vendor/longfellow-zk/lib/algebra/limb.h +153 -0
- data/vendor/longfellow-zk/lib/algebra/limb_test.cc +75 -0
- data/vendor/longfellow-zk/lib/algebra/nat.cc +32 -0
- data/vendor/longfellow-zk/lib/algebra/nat.h +212 -0
- data/vendor/longfellow-zk/lib/algebra/nat_test.cc +183 -0
- data/vendor/longfellow-zk/lib/algebra/nussbaumer.h +400 -0
- data/vendor/longfellow-zk/lib/algebra/nussbaumer_test.cc +138 -0
- data/vendor/longfellow-zk/lib/algebra/nussbaumerfp2_test.cc +139 -0
- data/vendor/longfellow-zk/lib/algebra/permutations.h +79 -0
- data/vendor/longfellow-zk/lib/algebra/poly.h +240 -0
- data/vendor/longfellow-zk/lib/algebra/poly_test.cc +123 -0
- data/vendor/longfellow-zk/lib/algebra/reed_solomon.h +150 -0
- data/vendor/longfellow-zk/lib/algebra/reed_solomon_extension.h +108 -0
- data/vendor/longfellow-zk/lib/algebra/reed_solomon_extension_test.cc +76 -0
- data/vendor/longfellow-zk/lib/algebra/reed_solomon_test.cc +473 -0
- data/vendor/longfellow-zk/lib/algebra/rfft.h +400 -0
- data/vendor/longfellow-zk/lib/algebra/rfft_test.cc +102 -0
- data/vendor/longfellow-zk/lib/algebra/static_string.h +29 -0
- data/vendor/longfellow-zk/lib/algebra/sysdep.h +495 -0
- data/vendor/longfellow-zk/lib/algebra/sysdep_test.cc +41 -0
- data/vendor/longfellow-zk/lib/algebra/twiddle.h +59 -0
- data/vendor/longfellow-zk/lib/algebra/utility.h +86 -0
- data/vendor/longfellow-zk/lib/algebra/utility_test.cc +86 -0
- data/vendor/longfellow-zk/lib/arrays/affine.h +56 -0
- data/vendor/longfellow-zk/lib/arrays/affine_test.cc +220 -0
- data/vendor/longfellow-zk/lib/arrays/dense.h +210 -0
- data/vendor/longfellow-zk/lib/arrays/eq.h +75 -0
- data/vendor/longfellow-zk/lib/arrays/eqs.h +137 -0
- data/vendor/longfellow-zk/lib/arrays/eqs_test.cc +151 -0
- data/vendor/longfellow-zk/lib/arrays/sparse.h +192 -0
- data/vendor/longfellow-zk/lib/cbor/host_decoder.h +323 -0
- data/vendor/longfellow-zk/lib/cbor/host_decoder_test.cc +541 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser/cbor.h +594 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser/cbor_byte_decoder.h +150 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser/cbor_byte_decoder_test.cc +147 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser/cbor_constants.h +27 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser/cbor_pluck.h +110 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser/cbor_pluck_test.cc +55 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser/cbor_test.cc +174 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser/cbor_testing.h +98 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser/cbor_witness.h +312 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser/mso2_test.cc +662 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser/mso_test.cc +485 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser/scan.h +104 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser/scan_test.cc +137 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser_v2/cbor.h +640 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser_v2/cbor_byte_decoder.h +150 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser_v2/cbor_byte_decoder_test.cc +147 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser_v2/cbor_constants.h +27 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser_v2/cbor_testing.h +99 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser_v2/cbor_witness.h +319 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser_v2/lexer_test.cc +120 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser_v2/mdoc_examples_test.cc +89 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser_v2/parser_circuit_test.cc +506 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser_v2/parser_size_test.cc +79 -0
- data/vendor/longfellow-zk/lib/circuits/cbor_parser_v2/parser_test.cc +473 -0
- data/vendor/longfellow-zk/lib/circuits/compiler/canonicalization_test.cc +185 -0
- data/vendor/longfellow-zk/lib/circuits/compiler/circuit_dump.h +65 -0
- data/vendor/longfellow-zk/lib/circuits/compiler/compiler.h +471 -0
- data/vendor/longfellow-zk/lib/circuits/compiler/compiler_test.cc +110 -0
- data/vendor/longfellow-zk/lib/circuits/compiler/node.h +176 -0
- data/vendor/longfellow-zk/lib/circuits/compiler/pdqhash.h +127 -0
- data/vendor/longfellow-zk/lib/circuits/compiler/schedule.h +435 -0
- data/vendor/longfellow-zk/lib/circuits/ecdsa/verify_circuit.h +371 -0
- data/vendor/longfellow-zk/lib/circuits/ecdsa/verify_external_test.cc +246 -0
- data/vendor/longfellow-zk/lib/circuits/ecdsa/verify_test.cc +587 -0
- data/vendor/longfellow-zk/lib/circuits/ecdsa/verify_witness.h +201 -0
- data/vendor/longfellow-zk/lib/circuits/logic/bit_adder.h +140 -0
- data/vendor/longfellow-zk/lib/circuits/logic/bit_adder_test.cc +64 -0
- data/vendor/longfellow-zk/lib/circuits/logic/bit_plucker.h +247 -0
- data/vendor/longfellow-zk/lib/circuits/logic/bit_plucker_constants.h +35 -0
- data/vendor/longfellow-zk/lib/circuits/logic/bit_plucker_encoder.h +72 -0
- data/vendor/longfellow-zk/lib/circuits/logic/bit_plucker_test.cc +183 -0
- data/vendor/longfellow-zk/lib/circuits/logic/compiler_backend.h +62 -0
- data/vendor/longfellow-zk/lib/circuits/logic/counter.h +171 -0
- data/vendor/longfellow-zk/lib/circuits/logic/counter_test.cc +102 -0
- data/vendor/longfellow-zk/lib/circuits/logic/evaluation_backend.h +94 -0
- data/vendor/longfellow-zk/lib/circuits/logic/logic.h +1232 -0
- data/vendor/longfellow-zk/lib/circuits/logic/logic_circuit_test.cc +310 -0
- data/vendor/longfellow-zk/lib/circuits/logic/logic_test.cc +521 -0
- data/vendor/longfellow-zk/lib/circuits/logic/memcmp.h +68 -0
- data/vendor/longfellow-zk/lib/circuits/logic/memcmp_test.cc +148 -0
- data/vendor/longfellow-zk/lib/circuits/logic/polynomial.h +94 -0
- data/vendor/longfellow-zk/lib/circuits/logic/polynomial_test.cc +62 -0
- data/vendor/longfellow-zk/lib/circuits/logic/routing.h +445 -0
- data/vendor/longfellow-zk/lib/circuits/logic/routing_test.cc +241 -0
- data/vendor/longfellow-zk/lib/circuits/logic/unary.h +55 -0
- data/vendor/longfellow-zk/lib/circuits/logic/unary_plucker.h +77 -0
- data/vendor/longfellow-zk/lib/circuits/logic/unary_plucker_constants.h +37 -0
- data/vendor/longfellow-zk/lib/circuits/logic/unary_plucker_test.cc +53 -0
- data/vendor/longfellow-zk/lib/circuits/logic/unary_size_test.cc +69 -0
- data/vendor/longfellow-zk/lib/circuits/logic/unary_test.cc +62 -0
- data/vendor/longfellow-zk/lib/circuits/mac/mac_circuit.h +193 -0
- data/vendor/longfellow-zk/lib/circuits/mac/mac_circuit_test.cc +223 -0
- data/vendor/longfellow-zk/lib/circuits/mac/mac_reference.h +72 -0
- data/vendor/longfellow-zk/lib/circuits/mac/mac_witness.h +94 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/circuit_maker.cc +242 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_attribute_ids.h +311 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_attribute_test.cc +64 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_circuit_id.cc +85 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_constants.h +85 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_decompress.cc +41 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_decompress.h +27 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_examples.h +5232 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_generate_circuit.cc +199 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_hash.h +554 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_signature.h +143 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_signature_test.cc +444 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_test_attributes.h +157 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_witness.h +863 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_zk.cc +693 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_zk.h +216 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/mdoc_zk_test.cc +724 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/zk_spec.cc +100 -0
- data/vendor/longfellow-zk/lib/circuits/mdoc/zk_spec_test.cc +155 -0
- data/vendor/longfellow-zk/lib/circuits/sha/flatsha256_circuit.h +330 -0
- data/vendor/longfellow-zk/lib/circuits/sha/flatsha256_circuit_test.cc +607 -0
- data/vendor/longfellow-zk/lib/circuits/sha/flatsha256_io.h +26 -0
- data/vendor/longfellow-zk/lib/circuits/sha/flatsha256_witness.cc +163 -0
- data/vendor/longfellow-zk/lib/circuits/sha/flatsha256_witness.h +47 -0
- data/vendor/longfellow-zk/lib/circuits/sha/sha256_constants.cc +34 -0
- data/vendor/longfellow-zk/lib/circuits/sha/sha256_constants.h +27 -0
- data/vendor/longfellow-zk/lib/circuits/sha/sha256_test_values.h +389 -0
- data/vendor/longfellow-zk/lib/circuits/tests/anoncred/ptrcred.h +171 -0
- data/vendor/longfellow-zk/lib/circuits/tests/anoncred/small.h +218 -0
- data/vendor/longfellow-zk/lib/circuits/tests/anoncred/small_examples.h +118 -0
- data/vendor/longfellow-zk/lib/circuits/tests/anoncred/small_io.h +25 -0
- data/vendor/longfellow-zk/lib/circuits/tests/anoncred/small_test.cc +208 -0
- data/vendor/longfellow-zk/lib/circuits/tests/anoncred/small_witness.h +130 -0
- data/vendor/longfellow-zk/lib/circuits/tests/base64/decode.h +508 -0
- data/vendor/longfellow-zk/lib/circuits/tests/base64/decode_circuit_test.cc +95 -0
- data/vendor/longfellow-zk/lib/circuits/tests/base64/decode_test.cc +119 -0
- data/vendor/longfellow-zk/lib/circuits/tests/base64/decode_util.cc +47 -0
- data/vendor/longfellow-zk/lib/circuits/tests/base64/decode_util.h +29 -0
- data/vendor/longfellow-zk/lib/circuits/tests/ec/pk_circuit.h +231 -0
- data/vendor/longfellow-zk/lib/circuits/tests/ec/pk_circuit_test.cc +428 -0
- data/vendor/longfellow-zk/lib/circuits/tests/ec/pk_witness.h +102 -0
- data/vendor/longfellow-zk/lib/circuits/tests/jwt/jwt.h +190 -0
- data/vendor/longfellow-zk/lib/circuits/tests/jwt/jwt_constants.h +26 -0
- data/vendor/longfellow-zk/lib/circuits/tests/jwt/jwt_test.cc +559 -0
- data/vendor/longfellow-zk/lib/circuits/tests/jwt/jwt_witness.h +315 -0
- data/vendor/longfellow-zk/lib/circuits/tests/mdoc/mdoc_1f.h +411 -0
- data/vendor/longfellow-zk/lib/circuits/tests/mdoc/mdoc_1f_io.h +32 -0
- data/vendor/longfellow-zk/lib/circuits/tests/mdoc/mdoc_1f_test.cc +364 -0
- data/vendor/longfellow-zk/lib/circuits/tests/mdoc/mdoc_1f_witness.h +278 -0
- data/vendor/longfellow-zk/lib/circuits/tests/mdoc/mdoc_revocation.h +146 -0
- data/vendor/longfellow-zk/lib/circuits/tests/mdoc/mdoc_revocation_constants.h +25 -0
- data/vendor/longfellow-zk/lib/circuits/tests/mdoc/mdoc_revocation_test.cc +315 -0
- data/vendor/longfellow-zk/lib/circuits/tests/mdoc/mdoc_revocation_witness.h +136 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/bitaddr/bitaddr.h +250 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/bitaddr/bitaddr_test.cc +333 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/bitaddr/bitaddr_witness.h +152 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_44.h +903 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_44_circuit_test.cc +274 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_44_eval_test.cc +440 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_44_examples.cc +8851 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_44_examples.h +93 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_44_types.cc +24 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_44_types.h +118 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_44_witness.h +453 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_44_witness_test.cc +49 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_ref.cc +458 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_ref.h +150 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_ref_test.cc +398 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_ref_test_vectors.inc +3618 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_ref_test_vectors_pkdecode.inc +689 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/ml_dsa_ref_test_vectors_sigdecode.inc +1501 -0
- data/vendor/longfellow-zk/lib/circuits/tests/pq/ml_dsa/sigdecode_test_vectors.inc +540 -0
- data/vendor/longfellow-zk/lib/circuits/tests/ripemd/ripemd_circuit.h +394 -0
- data/vendor/longfellow-zk/lib/circuits/tests/ripemd/ripemd_circuit_test.cc +577 -0
- data/vendor/longfellow-zk/lib/circuits/tests/ripemd/ripemd_constants.h +90 -0
- data/vendor/longfellow-zk/lib/circuits/tests/ripemd/ripemd_witness.cc +174 -0
- data/vendor/longfellow-zk/lib/circuits/tests/ripemd/ripemd_witness.h +140 -0
- data/vendor/longfellow-zk/lib/circuits/tests/sha3/sha3_circuit.h +351 -0
- data/vendor/longfellow-zk/lib/circuits/tests/sha3/sha3_circuit_test.cc +466 -0
- data/vendor/longfellow-zk/lib/circuits/tests/sha3/sha3_reference.cc +207 -0
- data/vendor/longfellow-zk/lib/circuits/tests/sha3/sha3_reference.h +59 -0
- data/vendor/longfellow-zk/lib/circuits/tests/sha3/sha3_reference_test.cc +153 -0
- data/vendor/longfellow-zk/lib/circuits/tests/sha3/sha3_round_constants.cc +39 -0
- data/vendor/longfellow-zk/lib/circuits/tests/sha3/sha3_round_constants.h +29 -0
- data/vendor/longfellow-zk/lib/circuits/tests/sha3/sha3_slicing.h +31 -0
- data/vendor/longfellow-zk/lib/circuits/tests/sha3/sha3_witness.cc +83 -0
- data/vendor/longfellow-zk/lib/circuits/tests/sha3/sha3_witness.h +72 -0
- data/vendor/longfellow-zk/lib/circuits/tests/sha3/shake_test_vectors.h +477 -0
- data/vendor/longfellow-zk/lib/ec/elliptic_curve.h +596 -0
- data/vendor/longfellow-zk/lib/ec/elliptic_curve_test.cc +548 -0
- data/vendor/longfellow-zk/lib/ec/p256.cc +36 -0
- data/vendor/longfellow-zk/lib/ec/p256.h +60 -0
- data/vendor/longfellow-zk/lib/ec/p256k1.cc +34 -0
- data/vendor/longfellow-zk/lib/ec/p256k1.h +60 -0
- data/vendor/longfellow-zk/lib/gf2k/gf2_128.h +503 -0
- data/vendor/longfellow-zk/lib/gf2k/gf2_128_bench.cc +48 -0
- data/vendor/longfellow-zk/lib/gf2k/gf2_128_test.cc +416 -0
- data/vendor/longfellow-zk/lib/gf2k/gf2poly.h +74 -0
- data/vendor/longfellow-zk/lib/gf2k/lch14.h +242 -0
- data/vendor/longfellow-zk/lib/gf2k/lch14_bench.cc +75 -0
- data/vendor/longfellow-zk/lib/gf2k/lch14_reed_solomon.h +127 -0
- data/vendor/longfellow-zk/lib/gf2k/lch14_reed_solomon_test.cc +110 -0
- data/vendor/longfellow-zk/lib/gf2k/lch14_test.cc +246 -0
- data/vendor/longfellow-zk/lib/gf2k/sysdep.h +329 -0
- data/vendor/longfellow-zk/lib/ligero/ligero_param.h +449 -0
- data/vendor/longfellow-zk/lib/ligero/ligero_prover.h +354 -0
- data/vendor/longfellow-zk/lib/ligero/ligero_test.cc +136 -0
- data/vendor/longfellow-zk/lib/ligero/ligero_transcript.h +67 -0
- data/vendor/longfellow-zk/lib/ligero/ligero_verifier.h +272 -0
- data/vendor/longfellow-zk/lib/merkle/merkle_commitment.h +104 -0
- data/vendor/longfellow-zk/lib/merkle/merkle_tree.h +216 -0
- data/vendor/longfellow-zk/lib/merkle/merkle_tree_test.cc +240 -0
- data/vendor/longfellow-zk/lib/proto/circuit.h +354 -0
- data/vendor/longfellow-zk/lib/proto/circuit_test.cc +202 -0
- data/vendor/longfellow-zk/lib/random/random.h +119 -0
- data/vendor/longfellow-zk/lib/random/random_test.cc +189 -0
- data/vendor/longfellow-zk/lib/random/secure_random_engine.h +37 -0
- data/vendor/longfellow-zk/lib/random/transcript.h +193 -0
- data/vendor/longfellow-zk/lib/random/transcript_test.cc +344 -0
- data/vendor/longfellow-zk/lib/sumcheck/circuit.h +148 -0
- data/vendor/longfellow-zk/lib/sumcheck/circuit_id.h +71 -0
- data/vendor/longfellow-zk/lib/sumcheck/equad.h +126 -0
- data/vendor/longfellow-zk/lib/sumcheck/hquad.h +115 -0
- data/vendor/longfellow-zk/lib/sumcheck/prover.h +59 -0
- data/vendor/longfellow-zk/lib/sumcheck/prover_layers.h +362 -0
- data/vendor/longfellow-zk/lib/sumcheck/quad.h +227 -0
- data/vendor/longfellow-zk/lib/sumcheck/quad_builder.h +211 -0
- data/vendor/longfellow-zk/lib/sumcheck/quad_test.cc +169 -0
- data/vendor/longfellow-zk/lib/sumcheck/sumcheck_test.cc +324 -0
- data/vendor/longfellow-zk/lib/sumcheck/testing.h +69 -0
- data/vendor/longfellow-zk/lib/sumcheck/transcript_sumcheck.h +85 -0
- data/vendor/longfellow-zk/lib/sumcheck/verifier.h +84 -0
- data/vendor/longfellow-zk/lib/sumcheck/verifier_layers.h +221 -0
- data/vendor/longfellow-zk/lib/testing/test_main.cc +50 -0
- data/vendor/longfellow-zk/lib/util/ceildiv.h +164 -0
- data/vendor/longfellow-zk/lib/util/ceildiv_test.cc +152 -0
- data/vendor/longfellow-zk/lib/util/crc64.h +45 -0
- data/vendor/longfellow-zk/lib/util/crypto.cc +39 -0
- data/vendor/longfellow-zk/lib/util/crypto.h +108 -0
- data/vendor/longfellow-zk/lib/util/log.cc +110 -0
- data/vendor/longfellow-zk/lib/util/log.h +33 -0
- data/vendor/longfellow-zk/lib/util/panic.h +40 -0
- data/vendor/longfellow-zk/lib/util/readbuffer.h +67 -0
- data/vendor/longfellow-zk/lib/util/serialization.h +54 -0
- data/vendor/longfellow-zk/lib/zk/zk_common.h +455 -0
- data/vendor/longfellow-zk/lib/zk/zk_proof.h +378 -0
- data/vendor/longfellow-zk/lib/zk/zk_prover.h +202 -0
- data/vendor/longfellow-zk/lib/zk/zk_test.cc +340 -0
- data/vendor/longfellow-zk/lib/zk/zk_testing.h +154 -0
- data/vendor/longfellow-zk/lib/zk/zk_verifier.h +109 -0
- metadata +347 -0
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
// Copyright 2026 Google LLC.
|
|
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
|
+
// http://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 <array>
|
|
16
|
+
#include <cstddef>
|
|
17
|
+
#include <cstdint>
|
|
18
|
+
#include <memory>
|
|
19
|
+
#include <vector>
|
|
20
|
+
|
|
21
|
+
#include "algebra/fp24.h"
|
|
22
|
+
#include "algebra/fp24_6.h"
|
|
23
|
+
#include "algebra/reed_solomon_extension.h"
|
|
24
|
+
#include "arrays/dense.h"
|
|
25
|
+
#include "circuits/compiler/circuit_dump.h"
|
|
26
|
+
#include "circuits/compiler/compiler.h"
|
|
27
|
+
#include "circuits/logic/compiler_backend.h"
|
|
28
|
+
#include "circuits/logic/logic.h"
|
|
29
|
+
#include "circuits/tests/pq/ml_dsa/ml_dsa_44.h"
|
|
30
|
+
#include "circuits/tests/pq/ml_dsa/ml_dsa_44_examples.h"
|
|
31
|
+
#include "circuits/tests/pq/ml_dsa/ml_dsa_44_types.h"
|
|
32
|
+
#include "circuits/tests/pq/ml_dsa/ml_dsa_44_witness.h"
|
|
33
|
+
#include "random/secure_random_engine.h"
|
|
34
|
+
#include "random/transcript.h"
|
|
35
|
+
#include "sumcheck/circuit.h"
|
|
36
|
+
#include "util/log.h"
|
|
37
|
+
#include "zk/zk_proof.h"
|
|
38
|
+
#include "zk/zk_prover.h"
|
|
39
|
+
#include "zk/zk_verifier.h"
|
|
40
|
+
#include "benchmark/benchmark.h"
|
|
41
|
+
#include "gtest/gtest.h"
|
|
42
|
+
|
|
43
|
+
namespace proofs {
|
|
44
|
+
namespace ml_dsa {
|
|
45
|
+
namespace {
|
|
46
|
+
|
|
47
|
+
using BaseField = Fp24;
|
|
48
|
+
using Field6 = Fp24_6;
|
|
49
|
+
using CBK = CompilerBackend<Field6>;
|
|
50
|
+
using LogicCircuit = Logic<Field6, CBK>;
|
|
51
|
+
using VerifyCircuit = MLDSA44Verify<LogicCircuit, Field6>;
|
|
52
|
+
|
|
53
|
+
constexpr uint32_t kBeta = 7;
|
|
54
|
+
|
|
55
|
+
template <typename F>
|
|
56
|
+
std::unique_ptr<Circuit<Field6>> build_ml_dsa_44_circuit(size_t nc,
|
|
57
|
+
const char* name,
|
|
58
|
+
F f) {
|
|
59
|
+
const Field6 f6 = Field6(ml_dsa::Fq, kBeta);
|
|
60
|
+
|
|
61
|
+
QuadCircuit<Field6> Q(f6);
|
|
62
|
+
const CBK cbk(&Q);
|
|
63
|
+
const LogicCircuit LC(&cbk, f6);
|
|
64
|
+
VerifyCircuit verify(LC);
|
|
65
|
+
|
|
66
|
+
f(Q, LC, verify);
|
|
67
|
+
|
|
68
|
+
auto CIRCUIT = Q.mkcircuit(nc);
|
|
69
|
+
dump_info(name, Q);
|
|
70
|
+
return CIRCUIT;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
std::unique_ptr<Circuit<Field6>> make_ml_dsa_44_circuit(size_t nc) {
|
|
74
|
+
return build_ml_dsa_44_circuit(
|
|
75
|
+
nc, "ml_dsa_44_valid_signature_on_mu",
|
|
76
|
+
[](QuadCircuit<Field6>& Q, const LogicCircuit& LC,
|
|
77
|
+
VerifyCircuit& verify) {
|
|
78
|
+
auto pk = std::make_unique<VerifyCircuit::Pk>();
|
|
79
|
+
pk->input(LC);
|
|
80
|
+
|
|
81
|
+
Q.private_input();
|
|
82
|
+
auto sig = std::make_unique<VerifyCircuit::SignatureW>();
|
|
83
|
+
sig->input(LC);
|
|
84
|
+
|
|
85
|
+
auto w = std::make_unique<VerifyCircuit::Witness>();
|
|
86
|
+
// c_tilde: H(mu || w1). mu=64, w1=768. Total 832 --> 7 blocks.
|
|
87
|
+
w->c_prime_tilde_bws_.resize(7);
|
|
88
|
+
|
|
89
|
+
w->input(LC);
|
|
90
|
+
|
|
91
|
+
// Dummy message
|
|
92
|
+
std::array<LogicCircuit::v8, 64> mu;
|
|
93
|
+
for (size_t i = 0; i < 64; ++i) {
|
|
94
|
+
mu[i] = LC.vinput<8>();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
verify.assert_valid_signature_on_mu(*pk, *sig, mu, *w);
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
std::unique_ptr<Circuit<Field6>> make_ml_dsa_44_sampleinball_circuit(
|
|
102
|
+
size_t nc) {
|
|
103
|
+
return build_ml_dsa_44_circuit(
|
|
104
|
+
nc, "ml_dsa_44_sample_in_ball",
|
|
105
|
+
[](QuadCircuit<Field6>& Q, const LogicCircuit& LC,
|
|
106
|
+
VerifyCircuit& verify) {
|
|
107
|
+
std::array<LogicCircuit::v8, 32> rho;
|
|
108
|
+
for (size_t i = 0; i < 32; ++i) {
|
|
109
|
+
rho[i] = LC.vinput<8>();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
Q.private_input();
|
|
113
|
+
|
|
114
|
+
VerifyCircuit::RqW cprime;
|
|
115
|
+
cprime.input(LC);
|
|
116
|
+
|
|
117
|
+
VerifyCircuit::SampleInBallWitness witness;
|
|
118
|
+
witness.input(LC);
|
|
119
|
+
|
|
120
|
+
verify.assert_sample_in_ball(rho, cprime, witness);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
std::unique_ptr<Circuit<Field6>> make_ml_dsa_44_w_prime_approx_circuit(
|
|
125
|
+
size_t nc) {
|
|
126
|
+
return build_ml_dsa_44_circuit(
|
|
127
|
+
nc, "ml_dsa_44_w_prime_approx",
|
|
128
|
+
[](QuadCircuit<Field6>& Q, const LogicCircuit& LC,
|
|
129
|
+
VerifyCircuit& verify) {
|
|
130
|
+
auto pk = std::make_unique<VerifyCircuit::Pk>();
|
|
131
|
+
pk->input(LC);
|
|
132
|
+
|
|
133
|
+
Q.private_input();
|
|
134
|
+
auto sig = std::make_unique<VerifyCircuit::SignatureW>();
|
|
135
|
+
sig->input(LC);
|
|
136
|
+
|
|
137
|
+
auto w = std::make_unique<VerifyCircuit::Witness>();
|
|
138
|
+
w->c_prime_tilde_bws_.resize(7);
|
|
139
|
+
|
|
140
|
+
w->input(LC);
|
|
141
|
+
|
|
142
|
+
verify.assert_w_prime_approx(*pk, *sig, *w);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
std::unique_ptr<Circuit<Field6>> make_ml_dsa_44_use_hint_circuit(size_t nc) {
|
|
147
|
+
return build_ml_dsa_44_circuit(
|
|
148
|
+
nc, "ml_dsa_44_use_hint",
|
|
149
|
+
[](QuadCircuit<Field6>& Q, const LogicCircuit& LC,
|
|
150
|
+
VerifyCircuit& verify) {
|
|
151
|
+
Q.private_input();
|
|
152
|
+
auto sig = std::make_unique<VerifyCircuit::SignatureW>();
|
|
153
|
+
sig->input(LC);
|
|
154
|
+
|
|
155
|
+
auto w = std::make_unique<VerifyCircuit::Witness>();
|
|
156
|
+
w->input(LC);
|
|
157
|
+
|
|
158
|
+
verify.assert_use_hint(sig->h, w->w_prime_approx_, w->w1_,
|
|
159
|
+
w->hint_aux_bits_, w->w_prime_1_,
|
|
160
|
+
w->w_prime_1_bits_);
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
std::unique_ptr<Circuit<Field6>> make_ml_dsa_44_ctilde_circuit(size_t nc) {
|
|
165
|
+
return build_ml_dsa_44_circuit(
|
|
166
|
+
nc, "ml_dsa_44_ctilde",
|
|
167
|
+
[](QuadCircuit<Field6>& Q, const LogicCircuit& LC,
|
|
168
|
+
VerifyCircuit& verify) {
|
|
169
|
+
Q.private_input();
|
|
170
|
+
auto sig = std::make_unique<VerifyCircuit::SignatureW>();
|
|
171
|
+
sig->input(LC);
|
|
172
|
+
|
|
173
|
+
auto w = std::make_unique<VerifyCircuit::Witness>();
|
|
174
|
+
w->c_prime_tilde_bws_.resize(7);
|
|
175
|
+
w->input(LC);
|
|
176
|
+
|
|
177
|
+
// Dummy message
|
|
178
|
+
std::array<LogicCircuit::v8, 64> mu;
|
|
179
|
+
for (size_t i = 0; i < 64; ++i) {
|
|
180
|
+
mu[i] = LC.vinput<8>();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
verify.assert_ctilde(mu, w->w1_tilde_, w->c_prime_tilde_bws_,
|
|
184
|
+
sig->c_tilde);
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
TEST(MlDsa44CircuitTest, SampleInBallCircuitSize) {
|
|
189
|
+
auto CIRCUIT = make_ml_dsa_44_sampleinball_circuit(1);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
TEST(MlDsa44CircuitTest, WPrimeApproxCircuitSize) {
|
|
193
|
+
auto CIRCUIT = make_ml_dsa_44_w_prime_approx_circuit(1);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
TEST(MlDsa44CircuitTest, UseHintCircuitSize) {
|
|
197
|
+
auto CIRCUIT = make_ml_dsa_44_use_hint_circuit(1);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
TEST(MlDsa44CircuitTest, CTildeCircuitSize) {
|
|
201
|
+
auto CIRCUIT = make_ml_dsa_44_ctilde_circuit(1);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
struct ProverEnv {
|
|
205
|
+
const Field6& f;
|
|
206
|
+
std::unique_ptr<Circuit<Field6>> circuit;
|
|
207
|
+
ReedSolomonExtensionFactory rsextf;
|
|
208
|
+
ml_dsa_44_witness witness_gen;
|
|
209
|
+
std::unique_ptr<ZkProof<Field6>> zkpr;
|
|
210
|
+
Dense<Field6> w;
|
|
211
|
+
ZkProver<Field6, ReedSolomonExtensionFactory> prover;
|
|
212
|
+
Transcript tp;
|
|
213
|
+
SecureRandomEngine rng;
|
|
214
|
+
|
|
215
|
+
explicit ProverEnv(const Field6& f6)
|
|
216
|
+
: f(f6),
|
|
217
|
+
circuit(make_ml_dsa_44_circuit(1)),
|
|
218
|
+
rsextf(ml_dsa::Fq),
|
|
219
|
+
w(1, circuit->ninputs),
|
|
220
|
+
prover(*circuit, f, rsextf),
|
|
221
|
+
tp((uint8_t*)"test", 4) {
|
|
222
|
+
auto tests = GetMlDsa44Examples();
|
|
223
|
+
const auto& test = tests[0];
|
|
224
|
+
witness_gen.compute_witness(test.pkey, test.sig, test.msg, test.ctx);
|
|
225
|
+
|
|
226
|
+
zkpr = std::make_unique<ZkProof<Field6>>(*circuit, 4, 128);
|
|
227
|
+
DenseFiller<Field6> filler(w);
|
|
228
|
+
filler.push_back(f.one());
|
|
229
|
+
witness_gen.fill_witness(filler, f);
|
|
230
|
+
|
|
231
|
+
for (size_t i = 0; i < 64; ++i) {
|
|
232
|
+
filler.push_back(witness_gen.mu_[i], 8, f);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
TEST(MlDsa44CircuitTest, AssertValidSignatureOnMu) {
|
|
238
|
+
const Field6 f = Field6(ml_dsa::Fq, kBeta);
|
|
239
|
+
ProverEnv env(f);
|
|
240
|
+
|
|
241
|
+
env.prover.commit(*env.zkpr, env.w, env.tp, env.rng);
|
|
242
|
+
bool ok = env.prover.prove(*env.zkpr, env.w, env.tp);
|
|
243
|
+
EXPECT_TRUE(ok) << "Failed to prove witness for test case ";
|
|
244
|
+
|
|
245
|
+
ZkVerifier<Field6, ReedSolomonExtensionFactory> verifier(
|
|
246
|
+
*env.circuit, env.rsextf, 4, 128, env.f);
|
|
247
|
+
Transcript tv((uint8_t*)"test", 4);
|
|
248
|
+
verifier.recv_commitment(*env.zkpr, tv);
|
|
249
|
+
Dense<Field6> pub(1, env.circuit->ninputs); // Empty public inputs
|
|
250
|
+
DenseFiller<Field6> vfiller(pub);
|
|
251
|
+
vfiller.push_back(env.f.one());
|
|
252
|
+
env.witness_gen.fill_pk(vfiller, env.f);
|
|
253
|
+
|
|
254
|
+
bool ok2 = verifier.verify(*env.zkpr, pub, tv);
|
|
255
|
+
EXPECT_TRUE(ok2) << "Failed to verify witness for test case ";
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
void BM_MLDSA44ZK_Prove(benchmark::State& state) {
|
|
259
|
+
set_log_level(ERROR);
|
|
260
|
+
const Field6& f = Field6(ml_dsa::Fq, kBeta);
|
|
261
|
+
|
|
262
|
+
ProverEnv env(f);
|
|
263
|
+
|
|
264
|
+
for (auto s : state) {
|
|
265
|
+
env.prover.commit(*env.zkpr, env.w, env.tp, env.rng);
|
|
266
|
+
env.prover.prove(*env.zkpr, env.w, env.tp);
|
|
267
|
+
benchmark::DoNotOptimize(env.zkpr);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
BENCHMARK(BM_MLDSA44ZK_Prove);
|
|
271
|
+
|
|
272
|
+
} // namespace
|
|
273
|
+
} // namespace ml_dsa
|
|
274
|
+
} // namespace proofs
|
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
// Copyright 2026 Google LLC.
|
|
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
|
+
// http://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 <array>
|
|
16
|
+
#include <cstddef>
|
|
17
|
+
#include <cstdint>
|
|
18
|
+
#include <vector>
|
|
19
|
+
|
|
20
|
+
#include "algebra/fp24.h"
|
|
21
|
+
#include "circuits/logic/evaluation_backend.h"
|
|
22
|
+
#include "circuits/logic/logic.h"
|
|
23
|
+
#include "circuits/tests/pq/ml_dsa/ml_dsa_44.h"
|
|
24
|
+
#include "circuits/tests/pq/ml_dsa/ml_dsa_44_examples.h"
|
|
25
|
+
#include "circuits/tests/pq/ml_dsa/ml_dsa_44_types.h"
|
|
26
|
+
#include "circuits/tests/pq/ml_dsa/ml_dsa_44_witness.h"
|
|
27
|
+
#include "circuits/tests/pq/ml_dsa/ml_dsa_ref.h"
|
|
28
|
+
#include "circuits/tests/sha3/sha3_circuit.h"
|
|
29
|
+
#include "circuits/tests/sha3/sha3_witness.h"
|
|
30
|
+
#include "gtest/gtest.h"
|
|
31
|
+
|
|
32
|
+
namespace proofs {
|
|
33
|
+
namespace {
|
|
34
|
+
|
|
35
|
+
using Field = Fp24;
|
|
36
|
+
using EvalBackend = EvaluationBackend<Field>;
|
|
37
|
+
using EvalLogic = Logic<Field, EvalBackend>;
|
|
38
|
+
using MLDSA44Verify = MLDSA44Verify<EvalLogic, Field>;
|
|
39
|
+
using v8 = typename EvalLogic::v8;
|
|
40
|
+
|
|
41
|
+
Sha3Circuit<EvalLogic>::BlockWitness convert_block_witness(
|
|
42
|
+
const EvalLogic& L, const Sha3Witness::BlockWitness& raw_bw) {
|
|
43
|
+
Sha3Circuit<EvalLogic>::BlockWitness bw;
|
|
44
|
+
for (size_t round = 0; round < 24; ++round) {
|
|
45
|
+
for (size_t x = 0; x < 5; ++x) {
|
|
46
|
+
for (size_t y = 0; y < 5; ++y) {
|
|
47
|
+
bw.a_intermediate[round][x][y] =
|
|
48
|
+
L.template vbit<64>(raw_bw.a_intermediate[round][x][y]);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return bw;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
template <typename Container>
|
|
56
|
+
void convert_rqw(MLDSA44Verify::RqW& dst, const Container& src,
|
|
57
|
+
const EvalLogic& L) {
|
|
58
|
+
for (size_t i = 0; i < ml_dsa::N; ++i) {
|
|
59
|
+
dst.coeffs[i] = L.konst(src[i]);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
void push_bytes(std::vector<v8>& dst, const uint8_t* src, size_t size,
|
|
64
|
+
const EvalLogic& L) {
|
|
65
|
+
for (size_t i = 0; i < size; ++i) {
|
|
66
|
+
dst.push_back(L.vbit8(src[i]));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
template <typename SrcContainer, typename DstContainer>
|
|
71
|
+
void convert_array(DstContainer& dst, const SrcContainer& src,
|
|
72
|
+
const EvalLogic& L) {
|
|
73
|
+
for (size_t i = 0; i < src.size(); ++i) {
|
|
74
|
+
dst[i] = L.vbit8(src[i]);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
template <size_t N, typename SrcContainer, typename DstContainer>
|
|
79
|
+
void convert_array_bits(DstContainer& dst, const SrcContainer& src,
|
|
80
|
+
const EvalLogic& L) {
|
|
81
|
+
for (size_t i = 0; i < src.size(); ++i) {
|
|
82
|
+
dst[i] = L.template vbit<N>(src[i]);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
MLDSA44Verify::Pk convert_pk(const ml_dsa::PublicKey& ref_pk,
|
|
87
|
+
const ml_dsa_44_witness& witness_gen,
|
|
88
|
+
const EvalLogic& L, const Field& F) {
|
|
89
|
+
MLDSA44Verify::Pk pk_w;
|
|
90
|
+
// a_hat
|
|
91
|
+
for (size_t r = 0; r < ml_dsa::K; ++r) {
|
|
92
|
+
for (size_t s = 0; s < ml_dsa::L; ++s) {
|
|
93
|
+
convert_rqw(pk_w.a_hat.mat[r][s], ref_pk.a_hat[r][s], L);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// t1 -> nttt1
|
|
97
|
+
for (size_t r = 0; r < ml_dsa::K; ++r) {
|
|
98
|
+
convert_rqw(pk_w.nttt1[r], witness_gen.nttt1_[r], L);
|
|
99
|
+
}
|
|
100
|
+
convert_array(pk_w.tr, witness_gen.tr_, L);
|
|
101
|
+
return pk_w;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
MLDSA44Verify::SignatureW convert_sig(const ml_dsa::Signature& ref_sig,
|
|
105
|
+
const ml_dsa_44_witness& witness_gen,
|
|
106
|
+
const EvalLogic& L, const Field& F) {
|
|
107
|
+
MLDSA44Verify::SignatureW sig_w;
|
|
108
|
+
// c_tilde
|
|
109
|
+
convert_array(sig_w.c_tilde, witness_gen.c_tilde_, L);
|
|
110
|
+
for (size_t r = 0; r < ml_dsa::L; ++r) {
|
|
111
|
+
convert_rqw(sig_w.z[r], ref_sig.z[r], L);
|
|
112
|
+
for (size_t i = 0; i < ml_dsa::N; ++i) {
|
|
113
|
+
sig_w.z_bits[r][i] = L.template vbit<19>(witness_gen.z_bits_[r][i]);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// h
|
|
117
|
+
for (size_t r = 0; r < ml_dsa::K; ++r) {
|
|
118
|
+
for (size_t i = 0; i < ml_dsa::N; ++i) {
|
|
119
|
+
sig_w.h[r].coeffs[i] = L.konst(ref_sig.h[r][i] ? F.one() : F.zero());
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return sig_w;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
MLDSA44Verify::SampleInBallWitness convert_sample_in_ball(
|
|
126
|
+
const ml_dsa_44_witness& witness_gen, const EvalLogic& L, const Field& F) {
|
|
127
|
+
MLDSA44Verify::SampleInBallWitness sib_w;
|
|
128
|
+
sib_w.shake_bws = convert_block_witness(L, witness_gen.shake_bws_);
|
|
129
|
+
for (size_t i = 0; i < ml_dsa::TAU; ++i) {
|
|
130
|
+
sib_w.j_vals[i] = L.vbit8(witness_gen.j_vals_[i]);
|
|
131
|
+
sib_w.j_k_indices[i] = L.template vbit<16>(witness_gen.j_k_indices_[i]);
|
|
132
|
+
}
|
|
133
|
+
// Copy position_trace
|
|
134
|
+
sib_w.position_trace.resize(witness_gen.position_trace_.size());
|
|
135
|
+
for (size_t s = 0; s < witness_gen.position_trace_.size(); ++s) {
|
|
136
|
+
sib_w.position_trace[s].resize(witness_gen.position_trace_[s].size());
|
|
137
|
+
convert_array(sib_w.position_trace[s], witness_gen.position_trace_[s], L);
|
|
138
|
+
}
|
|
139
|
+
return sib_w;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
MLDSA44Verify::Witness convert_witness(const ml_dsa_44_witness& witness_gen,
|
|
143
|
+
const EvalLogic& L, const Field& F) {
|
|
144
|
+
MLDSA44Verify::Witness witness;
|
|
145
|
+
convert_rqw(witness.c_, witness_gen.c_coeffs_, L);
|
|
146
|
+
|
|
147
|
+
witness.sample_in_ball_ = convert_sample_in_ball(witness_gen, L, F);
|
|
148
|
+
|
|
149
|
+
// Populate nttz, nttc, nttt1, w_prime_approx
|
|
150
|
+
for (size_t i = 0; i < ml_dsa::L; ++i) {
|
|
151
|
+
convert_rqw(witness.nttz_[i], witness_gen.nttz_[i], L);
|
|
152
|
+
}
|
|
153
|
+
convert_rqw(witness.nttc_, witness_gen.nttc_, L);
|
|
154
|
+
for (size_t i = 0; i < ml_dsa::K; ++i) {
|
|
155
|
+
convert_rqw(witness.w_prime_approx_[i], witness_gen.w_prime_approx_[i], L);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Populate w1 and hint_aux_bits
|
|
159
|
+
for (size_t i = 0; i < ml_dsa::K; ++i) {
|
|
160
|
+
for (size_t k = 0; k < ml_dsa::N; ++k) {
|
|
161
|
+
int32_t w1_val = witness_gen.w1_[i][k];
|
|
162
|
+
if (w1_val < 0) {
|
|
163
|
+
w1_val += ml_dsa::Q;
|
|
164
|
+
}
|
|
165
|
+
witness.w1_[i].coeffs[k] = L.konst(L.f_.of_scalar(w1_val));
|
|
166
|
+
witness.hint_aux_bits_[i][k] =
|
|
167
|
+
L.template vbit<19>(witness_gen.hint_aux_bits_[i][k]);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Populate w_prime_1 and w_prime_1_bits
|
|
172
|
+
for (size_t i = 0; i < ml_dsa::K; ++i) {
|
|
173
|
+
for (size_t k = 0; k < ml_dsa::N; ++k) {
|
|
174
|
+
int32_t w1_val = witness_gen.w_prime_1_[i][k];
|
|
175
|
+
EXPECT_TRUE(w1_val >= 0 && w1_val <= 43);
|
|
176
|
+
}
|
|
177
|
+
convert_rqw(witness.w_prime_1_[i], witness_gen.w_prime_1_[i], L);
|
|
178
|
+
convert_array_bits<6>(witness.w_prime_1_bits_[i],
|
|
179
|
+
witness_gen.w_prime_1_bits_[i], L);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// Populate w1_tilde_
|
|
183
|
+
convert_array(witness.w1_tilde_, witness_gen.w1_tilde_, L);
|
|
184
|
+
|
|
185
|
+
// Populate c_prime_tilde_bws
|
|
186
|
+
for (const auto& raw_bw : witness_gen.c_prime_tilde_bws_) {
|
|
187
|
+
witness.c_prime_tilde_bws_.push_back(convert_block_witness(L, raw_bw));
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return witness;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
TEST(MLDSA44EvalTest, SampleInBall) {
|
|
194
|
+
const Field& F = ml_dsa::Fq;
|
|
195
|
+
const EvalBackend ebk(F);
|
|
196
|
+
const EvalLogic L(&ebk, F);
|
|
197
|
+
MLDSA44Verify verify(L);
|
|
198
|
+
|
|
199
|
+
auto tests = ml_dsa::GetSampleInBallTests();
|
|
200
|
+
for (size_t t = 0; t < tests.size(); ++t) {
|
|
201
|
+
std::vector<uint8_t> rho(32);
|
|
202
|
+
std::array<EvalLogic::v8, 32> rho_w;
|
|
203
|
+
for (int i = 0; i < 32; ++i) {
|
|
204
|
+
rho[i] = tests[t].in[i];
|
|
205
|
+
rho_w[i] = L.vbit8(rho[i]);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Run reference SampleInBall to find j_vals, j_k_indices, and num blocks
|
|
209
|
+
// Emulate what SampleInBall does to get the witnesses.
|
|
210
|
+
std::array<uint8_t, 136> out;
|
|
211
|
+
ml_dsa::H(rho, out);
|
|
212
|
+
|
|
213
|
+
MLDSA44Verify::SampleInBallWitness witness;
|
|
214
|
+
|
|
215
|
+
size_t out_idx = 8;
|
|
216
|
+
witness.position_trace.resize(ml_dsa::TAU);
|
|
217
|
+
std::vector<uint8_t> current_pos;
|
|
218
|
+
current_pos.reserve(ml_dsa::TAU);
|
|
219
|
+
|
|
220
|
+
for (size_t s = 0; s < ml_dsa::TAU; ++s) {
|
|
221
|
+
size_t i = 256 - ml_dsa::TAU + s;
|
|
222
|
+
uint8_t j;
|
|
223
|
+
do {
|
|
224
|
+
j = out[out_idx++];
|
|
225
|
+
} while (j > i);
|
|
226
|
+
witness.j_vals[s] = L.vbit8(j);
|
|
227
|
+
witness.j_k_indices[s] = L.template vbit<16>(out_idx - 1);
|
|
228
|
+
|
|
229
|
+
for (size_t k = 0; k < current_pos.size(); ++k) {
|
|
230
|
+
if (current_pos[k] == j) {
|
|
231
|
+
current_pos[k] = i;
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
current_pos.push_back(j);
|
|
236
|
+
|
|
237
|
+
witness.position_trace[s].reserve(s + 1);
|
|
238
|
+
for (auto p : current_pos) {
|
|
239
|
+
witness.position_trace[s].push_back(L.vbit8(p));
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
std::vector<Sha3Witness::BlockWitness> bws;
|
|
244
|
+
Sha3Witness::compute_witness_shake256(rho, 136, bws);
|
|
245
|
+
witness.shake_bws = convert_block_witness(L, bws[0]);
|
|
246
|
+
|
|
247
|
+
MLDSA44Verify::RqW cprime;
|
|
248
|
+
for (size_t i = 0; i < ml_dsa::N; ++i) {
|
|
249
|
+
cprime.coeffs[i] = L.konst(F.of_scalar(tests[t].out[i]));
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
verify.assert_sample_in_ball(rho_w, cprime, witness);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
TEST(MLDSA44EvalTest, SHA3_Consistency) {
|
|
257
|
+
const Field& F = ml_dsa::Fq;
|
|
258
|
+
const EvalBackend ebk(F);
|
|
259
|
+
const EvalLogic L(&ebk, F);
|
|
260
|
+
Sha3Circuit<EvalLogic> sha3(L);
|
|
261
|
+
|
|
262
|
+
std::vector<uint8_t> rho(32);
|
|
263
|
+
for (int i = 0; i < 32; ++i) rho[i] = i;
|
|
264
|
+
|
|
265
|
+
std::array<uint8_t, 272> expected_out;
|
|
266
|
+
ml_dsa::H(rho, expected_out);
|
|
267
|
+
|
|
268
|
+
std::vector<Sha3Witness::BlockWitness> bws;
|
|
269
|
+
Sha3Witness::compute_witness_shake256(rho, 272, bws);
|
|
270
|
+
|
|
271
|
+
std::vector<Sha3Circuit<EvalLogic>::BlockWitness> circuit_bws(bws.size());
|
|
272
|
+
for (size_t k = 0; k < bws.size(); ++k) {
|
|
273
|
+
circuit_bws[k] = convert_block_witness(L, bws[k]);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
std::vector<EvalLogic::v8> rho_vec;
|
|
277
|
+
push_bytes(rho_vec, rho.data(), rho.size(), L);
|
|
278
|
+
|
|
279
|
+
std::vector<EvalLogic::v8> out;
|
|
280
|
+
sha3.assert_shake256(rho_vec, 272, out, circuit_bws);
|
|
281
|
+
|
|
282
|
+
ASSERT_EQ(out.size(), expected_out.size());
|
|
283
|
+
for (size_t i = 0; i < out.size(); ++i) {
|
|
284
|
+
uint8_t val = 0;
|
|
285
|
+
for (int b = 0; b < 8; ++b) {
|
|
286
|
+
if (L.eval(out[i][b]).elt() == F.one()) {
|
|
287
|
+
val |= (1 << b);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
EXPECT_EQ(val, expected_out[i]);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
TEST(MLDSA44EvalTest, NTTConsistency) {
|
|
295
|
+
const Field& F = ml_dsa::Fq;
|
|
296
|
+
const EvalBackend ebk(F);
|
|
297
|
+
const EvalLogic L(&ebk, F);
|
|
298
|
+
MLDSA44Verify verify(L);
|
|
299
|
+
|
|
300
|
+
auto tests = ml_dsa::GetNTTTests();
|
|
301
|
+
for (size_t t = 0; t < tests.size(); ++t) {
|
|
302
|
+
MLDSA44Verify::RqW w_in, w_out;
|
|
303
|
+
for (size_t i = 0; i < ml_dsa::N; ++i) {
|
|
304
|
+
w_in.coeffs[i] = L.konst(F.of_scalar(tests[t].in[i]));
|
|
305
|
+
w_out.coeffs[i] = L.konst(F.of_scalar(tests[t].out[i]));
|
|
306
|
+
}
|
|
307
|
+
verify.assert_ntt(w_in, w_out);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
for (size_t t = 0; t < tests.size(); ++t) {
|
|
311
|
+
MLDSA44Verify::RqW w_in, w_out;
|
|
312
|
+
for (size_t i = 0; i < ml_dsa::N; ++i) {
|
|
313
|
+
w_in.coeffs[i] = L.konst(F.of_scalar(tests[t].out[i]));
|
|
314
|
+
w_out.coeffs[i] = L.konst(F.of_scalar(tests[t].in[i]));
|
|
315
|
+
}
|
|
316
|
+
verify.assert_inverse_ntt(w_in, w_out);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
TEST(MLDSA44EvalTest, UseHintSingle) {
|
|
321
|
+
const Field& F = ml_dsa::Fq;
|
|
322
|
+
const EvalBackend ebk(F);
|
|
323
|
+
const EvalLogic L(&ebk, F);
|
|
324
|
+
MLDSA44Verify verify(L);
|
|
325
|
+
|
|
326
|
+
auto tests = ml_dsa::GetUseHintTestCases();
|
|
327
|
+
for (const auto& test_case : tests) {
|
|
328
|
+
bool h = test_case.h;
|
|
329
|
+
int32_t r = test_case.r;
|
|
330
|
+
int32_t expected = test_case.expected;
|
|
331
|
+
|
|
332
|
+
auto [r1, r0] = ml_dsa::Decompose(r);
|
|
333
|
+
|
|
334
|
+
int32_t w1_raw = r1;
|
|
335
|
+
if (h && r0 > 0)
|
|
336
|
+
w1_raw = r1 + 1;
|
|
337
|
+
else if (h && r0 <= 0)
|
|
338
|
+
w1_raw = r1 - 1;
|
|
339
|
+
|
|
340
|
+
int64_t gamma2 = static_cast<int64_t>(ml_dsa::GAMMA_2);
|
|
341
|
+
int64_t delta =
|
|
342
|
+
static_cast<int64_t>(r) - static_cast<int64_t>(r1) * (2 * gamma2);
|
|
343
|
+
|
|
344
|
+
// Symmetrically reduce modulo Q to get true remainder in Z_Q!
|
|
345
|
+
delta = delta % static_cast<int64_t>(ml_dsa::Q);
|
|
346
|
+
if (delta > static_cast<int64_t>(ml_dsa::Q) / 2) {
|
|
347
|
+
delta -= ml_dsa::Q;
|
|
348
|
+
} else if (delta < -static_cast<int64_t>(ml_dsa::Q) / 2) {
|
|
349
|
+
delta += ml_dsa::Q;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
uint64_t R = delta + gamma2 - 1;
|
|
353
|
+
uint64_t s = (delta > 0) ? 0 : 1;
|
|
354
|
+
uint64_t aux_bits = R | (s << 18);
|
|
355
|
+
|
|
356
|
+
auto normalize = [](int64_t x) {
|
|
357
|
+
int64_t v = x % static_cast<int64_t>(ml_dsa::Q);
|
|
358
|
+
if (v < 0) v += ml_dsa::Q;
|
|
359
|
+
return static_cast<uint64_t>(v);
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
auto h_elt = L.konst(F.of_scalar(normalize(h)));
|
|
363
|
+
auto w_prime_approx_elt = L.konst(F.of_scalar(normalize(r)));
|
|
364
|
+
auto w1_elt = L.konst(F.of_scalar(normalize(r1)));
|
|
365
|
+
auto w_prime_1_elt = L.konst(F.of_scalar(normalize(expected)));
|
|
366
|
+
|
|
367
|
+
// Bits
|
|
368
|
+
auto hint_aux_bits = L.template vbit<19>(normalize(aux_bits));
|
|
369
|
+
auto w_prime_1_bits = L.template vbit<6>(normalize(expected));
|
|
370
|
+
|
|
371
|
+
verify.assert_use_hint_single(h_elt, w_prime_approx_elt, w1_elt,
|
|
372
|
+
hint_aux_bits, w_prime_1_elt, w_prime_1_bits);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
TEST(MLDSA44EvalTest, W1Encode) {
|
|
377
|
+
const Field& F = ml_dsa::Fq;
|
|
378
|
+
const EvalBackend ebk(F);
|
|
379
|
+
const EvalLogic L(&ebk, F);
|
|
380
|
+
MLDSA44Verify verify(L);
|
|
381
|
+
|
|
382
|
+
auto tests = ml_dsa::GetW1EncodeTests();
|
|
383
|
+
for (size_t t = 0; t < tests.size(); ++t) {
|
|
384
|
+
std::array<std::array<EvalLogic::template bitvec<6>, ml_dsa::N>, ml_dsa::K>
|
|
385
|
+
w_prime_1_bits_arr;
|
|
386
|
+
for (size_t k = 0; k < ml_dsa::K; ++k) {
|
|
387
|
+
for (size_t i = 0; i < ml_dsa::N; ++i) {
|
|
388
|
+
w_prime_1_bits_arr[k][i] = L.template vbit<6>(tests[t].in[k][i]);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
std::array<EvalLogic::v8, ml_dsa::K * 192> putative_out;
|
|
393
|
+
for (size_t i = 0; i < tests[t].out.size(); ++i) {
|
|
394
|
+
putative_out[i] = L.vbit8(tests[t].out[i]);
|
|
395
|
+
}
|
|
396
|
+
verify.assert_w1_encode(w_prime_1_bits_arr, putative_out);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
TEST(MLDSA44EvalTest, AssertValidSignature) {
|
|
401
|
+
const Field& F = ml_dsa::Fq;
|
|
402
|
+
const EvalBackend ebk(F);
|
|
403
|
+
const EvalLogic L(&ebk, F);
|
|
404
|
+
using v8 = EvalLogic::v8;
|
|
405
|
+
MLDSA44Verify verify(L);
|
|
406
|
+
|
|
407
|
+
// Take the first example
|
|
408
|
+
auto tests = ml_dsa::GetMlDsa44Examples();
|
|
409
|
+
for (size_t t = 0; t < tests.size(); ++t) {
|
|
410
|
+
const auto& example = tests[t];
|
|
411
|
+
|
|
412
|
+
// 1. Decode Pk and Sig
|
|
413
|
+
ml_dsa::PublicKey ref_pk = ml_dsa::pkDecode(example.pkey);
|
|
414
|
+
auto maybe_ref_sig = ml_dsa::sigDecode(example.sig);
|
|
415
|
+
EXPECT_TRUE(maybe_ref_sig.has_value());
|
|
416
|
+
ml_dsa::Signature ref_sig = maybe_ref_sig.value();
|
|
417
|
+
|
|
418
|
+
// 1. Compute Witness
|
|
419
|
+
ml_dsa_44_witness witness_gen;
|
|
420
|
+
witness_gen.compute_witness(example.pkey, example.sig, example.msg,
|
|
421
|
+
example.ctx);
|
|
422
|
+
|
|
423
|
+
// 2. Setup inputs for the circuit
|
|
424
|
+
typename MLDSA44Verify::Pk pk_w = convert_pk(ref_pk, witness_gen, L, F);
|
|
425
|
+
|
|
426
|
+
typename MLDSA44Verify::SignatureW sig_w =
|
|
427
|
+
convert_sig(ref_sig, witness_gen, L, F);
|
|
428
|
+
|
|
429
|
+
// Generate SampleInBallWitness
|
|
430
|
+
typename MLDSA44Verify::Witness witness =
|
|
431
|
+
convert_witness(witness_gen, L, F);
|
|
432
|
+
|
|
433
|
+
std::array<v8, 64> mu;
|
|
434
|
+
convert_array(mu, witness_gen.mu_, L);
|
|
435
|
+
verify.assert_valid_signature_on_mu(pk_w, sig_w, mu, witness);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
} // namespace
|
|
440
|
+
} // namespace proofs
|