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,174 @@
|
|
|
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 "circuits/tests/ripemd/ripemd_witness.h"
|
|
16
|
+
|
|
17
|
+
#include <cstdint>
|
|
18
|
+
#include <cstring>
|
|
19
|
+
#include <vector>
|
|
20
|
+
|
|
21
|
+
#include "circuits/tests/ripemd/ripemd_constants.h"
|
|
22
|
+
|
|
23
|
+
namespace proofs {
|
|
24
|
+
|
|
25
|
+
namespace ripemd {
|
|
26
|
+
inline uint32_t rol(uint32_t x, int n) { return (x << n) | (x >> (32 - n)); }
|
|
27
|
+
|
|
28
|
+
inline uint32_t f1(uint32_t x, uint32_t y, uint32_t z) { return x ^ y ^ z; }
|
|
29
|
+
inline uint32_t f2(uint32_t x, uint32_t y, uint32_t z) {
|
|
30
|
+
return (x & y) | (~x & z);
|
|
31
|
+
}
|
|
32
|
+
inline uint32_t f3(uint32_t x, uint32_t y, uint32_t z) { return (x | ~y) ^ z; }
|
|
33
|
+
inline uint32_t f4(uint32_t x, uint32_t y, uint32_t z) {
|
|
34
|
+
return (x & z) | (y & ~z);
|
|
35
|
+
}
|
|
36
|
+
inline uint32_t f5(uint32_t x, uint32_t y, uint32_t z) { return x ^ (y | ~z); }
|
|
37
|
+
|
|
38
|
+
#define ROTATE_STATE(a, b, c, d, e, t) \
|
|
39
|
+
do { \
|
|
40
|
+
(a) = (e); \
|
|
41
|
+
(e) = (d); \
|
|
42
|
+
(d) = rol((c), 10); \
|
|
43
|
+
(c) = (b); \
|
|
44
|
+
(b) = (t); \
|
|
45
|
+
} while (0)
|
|
46
|
+
|
|
47
|
+
inline uint32_t f_round_left(int r, uint32_t x, uint32_t y, uint32_t z) {
|
|
48
|
+
switch (r) {
|
|
49
|
+
case 0:
|
|
50
|
+
return f1(x, y, z);
|
|
51
|
+
case 1:
|
|
52
|
+
return f2(x, y, z);
|
|
53
|
+
case 2:
|
|
54
|
+
return f3(x, y, z);
|
|
55
|
+
case 3:
|
|
56
|
+
return f4(x, y, z);
|
|
57
|
+
case 4:
|
|
58
|
+
return f5(x, y, z);
|
|
59
|
+
}
|
|
60
|
+
return 0;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
inline uint32_t f_round_right(int r, uint32_t x, uint32_t y, uint32_t z) {
|
|
64
|
+
switch (r) {
|
|
65
|
+
case 0:
|
|
66
|
+
return f5(x, y, z);
|
|
67
|
+
case 1:
|
|
68
|
+
return f4(x, y, z);
|
|
69
|
+
case 2:
|
|
70
|
+
return f3(x, y, z);
|
|
71
|
+
case 3:
|
|
72
|
+
return f2(x, y, z);
|
|
73
|
+
case 4:
|
|
74
|
+
return f1(x, y, z);
|
|
75
|
+
}
|
|
76
|
+
return 0;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
} // namespace ripemd
|
|
80
|
+
|
|
81
|
+
using ripemd::f_round_left;
|
|
82
|
+
using ripemd::f_round_right;
|
|
83
|
+
using ripemd::KL;
|
|
84
|
+
using ripemd::KR;
|
|
85
|
+
using ripemd::RL;
|
|
86
|
+
using ripemd::rol;
|
|
87
|
+
using ripemd::RR;
|
|
88
|
+
using ripemd::SL;
|
|
89
|
+
using ripemd::SR;
|
|
90
|
+
|
|
91
|
+
void RipemdWitness::witness_block(const uint32_t in[16], const uint32_t H0[5],
|
|
92
|
+
uint32_t left_temp[80],
|
|
93
|
+
uint32_t left_calc[80],
|
|
94
|
+
uint32_t right_temp[80],
|
|
95
|
+
uint32_t right_calc[80], uint32_t H1[5]) {
|
|
96
|
+
uint32_t a = H0[0], b = H0[1], c = H0[2], d = H0[3], e = H0[4];
|
|
97
|
+
uint32_t aa = H0[0], bb = H0[1], cc = H0[2], dd = H0[3], ee = H0[4];
|
|
98
|
+
|
|
99
|
+
for (int round = 0; round < 5; ++round) {
|
|
100
|
+
for (int step = 0; step < 16; ++step) {
|
|
101
|
+
int idx = round * 16 + step;
|
|
102
|
+
|
|
103
|
+
// Left
|
|
104
|
+
{
|
|
105
|
+
uint32_t f_val = f_round_left(round, b, c, d);
|
|
106
|
+
uint32_t temp = a + f_val + in[RL[round][step]] + KL[round];
|
|
107
|
+
left_temp[idx] = temp;
|
|
108
|
+
uint32_t calc = rol(temp, SL[round][step]) + e;
|
|
109
|
+
left_calc[idx] = calc;
|
|
110
|
+
ROTATE_STATE(a, b, c, d, e, calc);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Right
|
|
114
|
+
{
|
|
115
|
+
uint32_t f_val = f_round_right(round, bb, cc, dd);
|
|
116
|
+
uint32_t temp = aa + f_val + in[RR[round][step]] + KR[round];
|
|
117
|
+
right_temp[idx] = temp;
|
|
118
|
+
uint32_t calc = rol(temp, SR[round][step]) + ee;
|
|
119
|
+
right_calc[idx] = calc;
|
|
120
|
+
ROTATE_STATE(aa, bb, cc, dd, ee, calc);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
H1[0] = H0[1] + c + dd;
|
|
126
|
+
H1[1] = H0[2] + d + ee;
|
|
127
|
+
H1[2] = H0[3] + e + aa;
|
|
128
|
+
H1[3] = H0[4] + a + bb;
|
|
129
|
+
H1[4] = H0[0] + b + cc;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
std::vector<uint8_t> RipemdWitness::PadMessage(
|
|
133
|
+
const std::vector<uint8_t>& msg) {
|
|
134
|
+
std::vector<uint8_t> padded = msg;
|
|
135
|
+
uint64_t L = padded.size() * 8;
|
|
136
|
+
padded.push_back(0x80);
|
|
137
|
+
while ((padded.size() % 64) != 56) {
|
|
138
|
+
padded.push_back(0x00);
|
|
139
|
+
}
|
|
140
|
+
// Append length (64-bit little endian)
|
|
141
|
+
for (int i = 0; i < 8; ++i) {
|
|
142
|
+
padded.push_back((L >> (i * 8)) & 0xff);
|
|
143
|
+
}
|
|
144
|
+
return padded;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
void RipemdWitness::witness_message(const std::vector<uint8_t>& msg,
|
|
148
|
+
std::vector<BlockWitness>& witnesses) {
|
|
149
|
+
// 1. Padding
|
|
150
|
+
std::vector<uint8_t> padded = PadMessage(msg);
|
|
151
|
+
|
|
152
|
+
// 2. Process blocks
|
|
153
|
+
size_t num_blocks = padded.size() / 64;
|
|
154
|
+
witnesses.resize(num_blocks);
|
|
155
|
+
uint32_t initial[5] = {0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476,
|
|
156
|
+
0xC3D2E1F0};
|
|
157
|
+
const uint32_t* H = initial;
|
|
158
|
+
|
|
159
|
+
for (size_t b = 0; b < num_blocks; ++b) {
|
|
160
|
+
uint32_t in[16];
|
|
161
|
+
for (int i = 0; i < 16; ++i) {
|
|
162
|
+
// Little endian load
|
|
163
|
+
in[i] = (uint32_t)padded[b * 64 + i * 4 + 0] |
|
|
164
|
+
((uint32_t)padded[b * 64 + i * 4 + 1] << 8) |
|
|
165
|
+
((uint32_t)padded[b * 64 + i * 4 + 2] << 16) |
|
|
166
|
+
((uint32_t)padded[b * 64 + i * 4 + 3] << 24);
|
|
167
|
+
}
|
|
168
|
+
witness_block(in, H, witnesses[b].left_temp, witnesses[b].left_calc,
|
|
169
|
+
witnesses[b].right_temp, witnesses[b].right_calc,
|
|
170
|
+
witnesses[b].h_out);
|
|
171
|
+
H = witnesses[b].h_out;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
} // namespace proofs
|
|
@@ -0,0 +1,140 @@
|
|
|
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
|
+
#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_TESTS_RIPEMD_RIPEMD_WITNESS_H_
|
|
16
|
+
#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_TESTS_RIPEMD_RIPEMD_WITNESS_H_
|
|
17
|
+
|
|
18
|
+
#include <cstddef>
|
|
19
|
+
#include <cstdint>
|
|
20
|
+
#include <vector>
|
|
21
|
+
|
|
22
|
+
#include "arrays/dense.h"
|
|
23
|
+
#include "circuits/logic/bit_plucker_encoder.h"
|
|
24
|
+
#include "util/panic.h"
|
|
25
|
+
|
|
26
|
+
namespace proofs {
|
|
27
|
+
|
|
28
|
+
struct RipemdWitness {
|
|
29
|
+
using v32 = uint32_t;
|
|
30
|
+
|
|
31
|
+
struct BlockWitness {
|
|
32
|
+
uint32_t left_temp[80];
|
|
33
|
+
uint32_t left_calc[80];
|
|
34
|
+
uint32_t right_temp[80];
|
|
35
|
+
uint32_t right_calc[80];
|
|
36
|
+
uint32_t h_out[5];
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
static void witness_block(const uint32_t in[16], const uint32_t H0[5],
|
|
40
|
+
uint32_t left_temp[80], uint32_t left_calc[80],
|
|
41
|
+
uint32_t right_temp[80], uint32_t right_calc[80],
|
|
42
|
+
uint32_t H1[5]);
|
|
43
|
+
|
|
44
|
+
static void witness_message(const std::vector<uint8_t>& msg,
|
|
45
|
+
std::vector<BlockWitness>& witnesses);
|
|
46
|
+
|
|
47
|
+
static std::vector<uint8_t> PadMessage(const std::vector<uint8_t>& msg);
|
|
48
|
+
|
|
49
|
+
template <class Field, int plucker_size = 1>
|
|
50
|
+
static void fill_input(DenseFiller<Field>& filler,
|
|
51
|
+
const std::vector<uint8_t>& message, size_t ninputs,
|
|
52
|
+
size_t maxBlocks, const Field& f);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
template <class Field, int plucker_size>
|
|
56
|
+
void RipemdWitness::fill_input(DenseFiller<Field>& filler,
|
|
57
|
+
const std::vector<uint8_t>& message,
|
|
58
|
+
size_t ninputs, size_t maxBlocks,
|
|
59
|
+
const Field& f) {
|
|
60
|
+
std::vector<RipemdWitness::BlockWitness> bwb;
|
|
61
|
+
RipemdWitness::witness_message(message, bwb);
|
|
62
|
+
size_t numBlocks = maxBlocks;
|
|
63
|
+
uint8_t numb = bwb.size();
|
|
64
|
+
|
|
65
|
+
// checking if message fits in maxBlocks
|
|
66
|
+
check(bwb.size() <= maxBlocks, "bwb.size() <= maxBlocks");
|
|
67
|
+
|
|
68
|
+
// fill input wires
|
|
69
|
+
filler.push_back(f.one());
|
|
70
|
+
filler.push_back(numb, 8, f);
|
|
71
|
+
|
|
72
|
+
// Let's replicate padding here to get full input bytes.
|
|
73
|
+
std::vector<uint8_t> padded = RipemdWitness::PadMessage(message);
|
|
74
|
+
|
|
75
|
+
for (size_t j = 0; j < padded.size(); j++) {
|
|
76
|
+
filler.push_back(padded[j], 8, f);
|
|
77
|
+
}
|
|
78
|
+
// If padded.size() < 64 * numBlocks, fill remaining.
|
|
79
|
+
for (size_t j = padded.size(); j < 64 * numBlocks; j++) {
|
|
80
|
+
filler.push_back((uint8_t)0, 8, f);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Target hash.
|
|
84
|
+
if (!bwb.empty()) {
|
|
85
|
+
const auto& final_h = bwb.back().h_out;
|
|
86
|
+
for (int j = 0; j < 5; ++j) {
|
|
87
|
+
uint32_t val = final_h[j];
|
|
88
|
+
for (int k = 0; k < 32; ++k) {
|
|
89
|
+
uint8_t bit = (val >> k) & 1;
|
|
90
|
+
filler.push_back(bit ? f.one() : f.zero());
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
} else {
|
|
94
|
+
for (int k = 0; k < 160; ++k) filler.push_back(f.zero());
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Block witnesses.
|
|
98
|
+
BitPluckerEncoder<Field, plucker_size> BPENC(f);
|
|
99
|
+
// Pad witnesses if needed
|
|
100
|
+
if (bwb.size() < numBlocks) {
|
|
101
|
+
auto last_h = bwb.empty() ? std::array<uint32_t, 5>{0x67452301, 0xEFCDAB89,
|
|
102
|
+
0x98BADCFE, 0x10325476,
|
|
103
|
+
0xC3D2E1F0}
|
|
104
|
+
: std::array<uint32_t, 5>{0};
|
|
105
|
+
if (!bwb.empty()) {
|
|
106
|
+
for (int k = 0; k < 5; ++k) last_h[k] = bwb.back().h_out[k];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// We need to generate witnesses for compressing blocks of 0s.
|
|
110
|
+
// The input for these blocks is 0.
|
|
111
|
+
uint32_t zero_block[16] = {0};
|
|
112
|
+
for (size_t j = bwb.size(); j < numBlocks; ++j) {
|
|
113
|
+
RipemdWitness::BlockWitness bw;
|
|
114
|
+
uint32_t h1[5];
|
|
115
|
+
RipemdWitness::witness_block(zero_block, last_h.data(), bw.left_temp,
|
|
116
|
+
bw.left_calc, bw.right_temp, bw.right_calc,
|
|
117
|
+
h1);
|
|
118
|
+
for (int k = 0; k < 5; ++k) bw.h_out[k] = h1[k]; // Store h1 as h_out
|
|
119
|
+
bwb.push_back(bw);
|
|
120
|
+
for (int k = 0; k < 5; ++k) last_h[k] = h1[k];
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
for (size_t j = 0; j < numBlocks; j++) {
|
|
125
|
+
const auto& w = bwb[j];
|
|
126
|
+
for (size_t k = 0; k < 80; ++k) {
|
|
127
|
+
filler.push_back(BPENC.mkpacked_v32(w.left_temp[k]));
|
|
128
|
+
filler.push_back(BPENC.mkpacked_v32(w.left_calc[k]));
|
|
129
|
+
filler.push_back(BPENC.mkpacked_v32(w.right_temp[k]));
|
|
130
|
+
filler.push_back(BPENC.mkpacked_v32(w.right_calc[k]));
|
|
131
|
+
}
|
|
132
|
+
for (size_t k = 0; k < 5; ++k) {
|
|
133
|
+
filler.push_back(BPENC.mkpacked_v32(w.h_out[k]));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
} // namespace proofs
|
|
139
|
+
|
|
140
|
+
#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_TESTS_RIPEMD_RIPEMD_WITNESS_H_
|
|
@@ -0,0 +1,351 @@
|
|
|
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
|
+
#ifndef PRIVACY_PROOFS_ZK_LIB_CIRCUITS_TESTS_SHA3_SHA3_CIRCUIT_H_
|
|
16
|
+
#define PRIVACY_PROOFS_ZK_LIB_CIRCUITS_TESTS_SHA3_SHA3_CIRCUIT_H_
|
|
17
|
+
|
|
18
|
+
// ----------------------------------------------------------------------------
|
|
19
|
+
//
|
|
20
|
+
// !!!!! DO NOT USE IN PRODUCTION !!!!!
|
|
21
|
+
//
|
|
22
|
+
// This SHA3 circuit is an experimental implementation for research purposes.
|
|
23
|
+
// It has not been fully vetted and is not recommended for production use cases
|
|
24
|
+
// at this time.
|
|
25
|
+
//
|
|
26
|
+
// Sha3 and SHAKE256 are specified in
|
|
27
|
+
//
|
|
28
|
+
// FIPS PUB 202
|
|
29
|
+
// SHA-3 Standard: Permutation-Based Hash and
|
|
30
|
+
// Extendable-Output Functions
|
|
31
|
+
//
|
|
32
|
+
// https://nvlpubs.nist.gov/nistPubs/fips/nist.fips.202.pdf
|
|
33
|
+
//
|
|
34
|
+
// ----------------------------------------------------------------------------
|
|
35
|
+
|
|
36
|
+
#include <stddef.h>
|
|
37
|
+
|
|
38
|
+
#include <algorithm>
|
|
39
|
+
#include <cstdint>
|
|
40
|
+
#include <vector>
|
|
41
|
+
|
|
42
|
+
#include "circuits/tests/sha3/sha3_round_constants.h"
|
|
43
|
+
#include "circuits/tests/sha3/sha3_slicing.h"
|
|
44
|
+
#include "util/panic.h"
|
|
45
|
+
|
|
46
|
+
namespace proofs {
|
|
47
|
+
template <class LogicCircuit>
|
|
48
|
+
class Sha3Circuit {
|
|
49
|
+
typedef typename LogicCircuit::template bitvec<64> v64;
|
|
50
|
+
typedef typename LogicCircuit::template bitvec<8> v8;
|
|
51
|
+
|
|
52
|
+
const LogicCircuit& lc_;
|
|
53
|
+
|
|
54
|
+
v64 of_scalar(uint64_t x) const { return lc_.template vbit<64>(x); }
|
|
55
|
+
|
|
56
|
+
// Implementation of Step 6 in Algorithm 8, page 18--19 of the spec.
|
|
57
|
+
void xorin_block(v64 A[5][5], const std::vector<v8>& block, size_t rate) {
|
|
58
|
+
size_t x = 0, y = 0;
|
|
59
|
+
for (size_t i = 0; i < rate; i += 8) {
|
|
60
|
+
v64 a;
|
|
61
|
+
for (size_t b = 0; b < 8; ++b) {
|
|
62
|
+
for (size_t j = 0; j < 8; ++j) {
|
|
63
|
+
a[b * 8 + j] = block[i + b][j];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
A[x][y] = lc_.vxor(A[x][y], a);
|
|
67
|
+
++x;
|
|
68
|
+
if (x == 5) {
|
|
69
|
+
++y;
|
|
70
|
+
x = 0;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// FIPS 202 3.2.1, theta
|
|
76
|
+
void theta(v64 A[5][5]) {
|
|
77
|
+
// The reference computes a five-way xor
|
|
78
|
+
//
|
|
79
|
+
// C[x] = A[x][0] ^ A[x][1] ^ A[x][2] ^ A[x][3] ^ A[x][4]
|
|
80
|
+
//
|
|
81
|
+
// However, computing C[x] requires three levels of xor.
|
|
82
|
+
// Instead, we write C[x] = C0[x] ^ C1[x] where
|
|
83
|
+
//
|
|
84
|
+
// C0[x] = A[x][0] ^ A[x][1] ^ A[x][2] ^ A[x][3]
|
|
85
|
+
// C1[x] = A[x][4]
|
|
86
|
+
//
|
|
87
|
+
// C0 requires two XOR levels, C1 is free.
|
|
88
|
+
//
|
|
89
|
+
// Later, the reference computes
|
|
90
|
+
//
|
|
91
|
+
// D_x = C[(x + 4) % 5] ^ rotl(C[(x + 1) % 5], 1)
|
|
92
|
+
//
|
|
93
|
+
// Similarly, we split D_x = D0_x ^ D1_x.
|
|
94
|
+
v64 C0[5], C1[5];
|
|
95
|
+
for (size_t x = 0; x < 5; ++x) {
|
|
96
|
+
auto a01 = lc_.vxor(A[x][0], A[x][1]);
|
|
97
|
+
auto a23 = lc_.vxor(A[x][2], A[x][3]);
|
|
98
|
+
C0[x] = lc_.vxor(a23, a01);
|
|
99
|
+
C1[x] = A[x][4];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
for (size_t x = 0; x < 5; ++x) {
|
|
103
|
+
v64 D0_x = lc_.vxor(C0[(x + 4) % 5], lc_.vrotl(C0[(x + 1) % 5], 1));
|
|
104
|
+
v64 D1_x = lc_.vxor(C1[(x + 4) % 5], lc_.vrotl(C1[(x + 1) % 5], 1));
|
|
105
|
+
for (size_t y = 0; y < 5; ++y) {
|
|
106
|
+
// D1_x is available two levels before D0_x, so we xor
|
|
107
|
+
// it in first.
|
|
108
|
+
A[x][y] = lc_.vxor(A[x][y], D1_x);
|
|
109
|
+
A[x][y] = lc_.vxor(A[x][y], D0_x);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// FIPS 202 3.2.2, rho
|
|
115
|
+
void rho(v64 A[5][5]) {
|
|
116
|
+
size_t x = 1, y = 0;
|
|
117
|
+
for (size_t t = 0; t < 24; ++t) {
|
|
118
|
+
A[x][y] = lc_.vrotl(A[x][y], sha3::sha3_rotc[t]);
|
|
119
|
+
size_t nx = y, ny = (2 * x + 3 * y) % 5;
|
|
120
|
+
x = nx;
|
|
121
|
+
y = ny;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// FIPS 202 3.2.3, pi
|
|
126
|
+
void pi(const v64 A[5][5], v64 A1[5][5]) {
|
|
127
|
+
for (size_t x = 0; x < 5; ++x) {
|
|
128
|
+
for (size_t y = 0; y < 5; ++y) {
|
|
129
|
+
A1[x][y] = A[(x + 3 * y) % 5][x];
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// FIPS 202 3.2.4, chi
|
|
135
|
+
void chi(const v64 A1[5][5], v64 A[5][5]) {
|
|
136
|
+
for (size_t x = 0; x < 5; ++x) {
|
|
137
|
+
for (size_t y = 0; y < 5; ++y) {
|
|
138
|
+
A[x][y] = lc_.vxor(A1[x][y], lc_.vand(A1[(x + 2) % 5][y],
|
|
139
|
+
lc_.vnot(A1[(x + 1) % 5][y])));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// FIPS 202 3.2.5, iota
|
|
145
|
+
void iota(v64 A[5][5], size_t round) {
|
|
146
|
+
A[0][0] = lc_.vxor(A[0][0], of_scalar(sha3::sha3_rc[round]));
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
public:
|
|
150
|
+
explicit Sha3Circuit(const LogicCircuit& lc) : lc_(lc) {}
|
|
151
|
+
|
|
152
|
+
struct BlockWitness {
|
|
153
|
+
// One set of wires per round. However the circuit only
|
|
154
|
+
// uses rounds satisfying SHA3_SLICE_AT()
|
|
155
|
+
v64 a_intermediate[24][5][5];
|
|
156
|
+
|
|
157
|
+
void input(const LogicCircuit& lc) {
|
|
158
|
+
for (size_t round = 0; round < 24; ++round) {
|
|
159
|
+
if (sha3_slice_at(round)) {
|
|
160
|
+
for (size_t x = 0; x < 5; ++x) {
|
|
161
|
+
for (size_t y = 0; y < 5; ++y) {
|
|
162
|
+
a_intermediate[round][x][y] = lc.template vinput<64>();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
// This version of the Keccak-f[1600] permutation does not use any witnesses.
|
|
171
|
+
// It provides a baseline to measure the depth and computation required.
|
|
172
|
+
void keccak_f_1600(v64 A[5][5]) {
|
|
173
|
+
for (size_t round = 0; round < 24; ++round) {
|
|
174
|
+
theta(A);
|
|
175
|
+
rho(A);
|
|
176
|
+
v64 A1[5][5];
|
|
177
|
+
pi(A, A1);
|
|
178
|
+
chi(A1, A);
|
|
179
|
+
iota(A, round);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
void keccak_f_1600(v64 A[5][5], const BlockWitness& bw) {
|
|
184
|
+
for (size_t round = 0; round < 24; ++round) {
|
|
185
|
+
theta(A);
|
|
186
|
+
rho(A);
|
|
187
|
+
v64 A1[5][5];
|
|
188
|
+
pi(A, A1);
|
|
189
|
+
chi(A1, A);
|
|
190
|
+
iota(A, round);
|
|
191
|
+
|
|
192
|
+
if (sha3_slice_at(round)) {
|
|
193
|
+
for (size_t x = 0; x < 5; ++x) {
|
|
194
|
+
for (size_t y = 0; y < 5; ++y) {
|
|
195
|
+
sha3_vassert_eq(A[x][y], bw.a_intermediate[round][x][y]);
|
|
196
|
+
A[x][y] = bw.a_intermediate[round][x][y];
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Computes SHAKE256 hash of seed with output length outlen bytes, and stores
|
|
204
|
+
// result in out.
|
|
205
|
+
//
|
|
206
|
+
// SHAKE256 is an extendable-output function (XOF) from Keccak family,
|
|
207
|
+
// standardized in FIPS 202.
|
|
208
|
+
//
|
|
209
|
+
// Arguments:
|
|
210
|
+
// - seed: Input message as a vector of v8.
|
|
211
|
+
// - outlen: Desired output length in bytes.
|
|
212
|
+
// - out: Output vector for hash result, resized to outlen v8.
|
|
213
|
+
// - bws: Block witnesses for Keccak rounds. One witness is required for each
|
|
214
|
+
// call to keccak_f_1600, which occurs once per 136-byte block of
|
|
215
|
+
// padded input, and once per 136-byte block of squeezed output
|
|
216
|
+
// (except for the last block).
|
|
217
|
+
//
|
|
218
|
+
// Constraints:
|
|
219
|
+
// The number of block witnesses bws.size() must be exactly equal to:
|
|
220
|
+
// (seed.size() + 136) / 136 + (outlen == 0 ? 0 : (outlen - 1) / 136).
|
|
221
|
+
void assert_shake256(const std::vector<v8>& seed, size_t outlen,
|
|
222
|
+
std::vector<v8>& out,
|
|
223
|
+
const std::vector<BlockWitness>& bws) {
|
|
224
|
+
size_t rate = 136; // shake256 rate
|
|
225
|
+
// Calculate expected number of blocks
|
|
226
|
+
size_t num_absorb_blocks = (seed.size() + rate) / rate;
|
|
227
|
+
size_t num_squeeze_blocks = (outlen == 0) ? 0 : (outlen - 1) / rate;
|
|
228
|
+
check(bws.size() == num_absorb_blocks + num_squeeze_blocks,
|
|
229
|
+
"Incorrect number of BlockWitnesses");
|
|
230
|
+
|
|
231
|
+
// Eagerly populate output
|
|
232
|
+
out.resize(outlen);
|
|
233
|
+
size_t out_ptr = 0;
|
|
234
|
+
size_t sqz_req = 0;
|
|
235
|
+
while (out_ptr < outlen) {
|
|
236
|
+
std::vector<v8> squeeze_block(200);
|
|
237
|
+
// It is possible to use a single index into A here,
|
|
238
|
+
// but this more verbose sx,sy makes it easier to map
|
|
239
|
+
// to the Fips spec.
|
|
240
|
+
size_t sx = 0, sy = 0;
|
|
241
|
+
for (size_t i = 0; i < rate; i += 8) {
|
|
242
|
+
// Handle the awkward copy of v64 into v8s.
|
|
243
|
+
for (size_t b = 0; b < 8; ++b) {
|
|
244
|
+
for (size_t j = 0; j < 8; ++j) {
|
|
245
|
+
squeeze_block[i + b][j] =
|
|
246
|
+
bws[num_absorb_blocks - 1 + sqz_req]
|
|
247
|
+
.a_intermediate[23][sx][sy][b * 8 + j];
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
++sx;
|
|
251
|
+
if (sx == 5) {
|
|
252
|
+
++sy;
|
|
253
|
+
sx = 0;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
size_t take = std::min(rate, outlen - out_ptr);
|
|
257
|
+
for (size_t i = 0; i < take; ++i) {
|
|
258
|
+
out[out_ptr++] = squeeze_block[i];
|
|
259
|
+
}
|
|
260
|
+
sqz_req++;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// Evaluate blocks in parallel
|
|
264
|
+
// Absorb phase
|
|
265
|
+
std::vector<v8> block(200); // invariant: block[] is zero-padded.
|
|
266
|
+
for (size_t i = 0; i < 200; ++i) block[i] = lc_.template vbit<8>(0);
|
|
267
|
+
size_t bw_idx = 0;
|
|
268
|
+
size_t ptr = 0;
|
|
269
|
+
|
|
270
|
+
for (size_t i = 0; i < seed.size(); ++i) {
|
|
271
|
+
block[ptr++] = seed[i];
|
|
272
|
+
if (ptr == rate) {
|
|
273
|
+
v64 A_in[5][5];
|
|
274
|
+
for (int x = 0; x < 5; ++x) {
|
|
275
|
+
for (int y = 0; y < 5; ++y) {
|
|
276
|
+
if (bw_idx == 0) {
|
|
277
|
+
A_in[x][y] = lc_.template vbit<64>(0);
|
|
278
|
+
} else {
|
|
279
|
+
A_in[x][y] = bws[bw_idx - 1].a_intermediate[23][x][y];
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
xorin_block(A_in, block, rate);
|
|
285
|
+
keccak_f_1600(A_in, bws[bw_idx++]);
|
|
286
|
+
ptr = 0;
|
|
287
|
+
for (size_t j = 0; j < 200; ++j) block[j] = lc_.template vbit<8>(0);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// Pad and process the last block
|
|
292
|
+
auto pad1 = lc_.template vbit<8>(0x1F);
|
|
293
|
+
auto pad2 = lc_.template vbit<8>(0x80);
|
|
294
|
+
block[ptr] = pad1;
|
|
295
|
+
block[rate - 1] = lc_.vxor(block[rate - 1], pad2);
|
|
296
|
+
|
|
297
|
+
v64 A_in[5][5];
|
|
298
|
+
for (int x = 0; x < 5; ++x) {
|
|
299
|
+
for (int y = 0; y < 5; ++y) {
|
|
300
|
+
if (bw_idx == 0) {
|
|
301
|
+
A_in[x][y] = lc_.template vbit<64>(0);
|
|
302
|
+
} else {
|
|
303
|
+
A_in[x][y] = bws[bw_idx - 1].a_intermediate[23][x][y];
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
xorin_block(A_in, block, rate);
|
|
309
|
+
keccak_f_1600(A_in, bws[bw_idx++]);
|
|
310
|
+
|
|
311
|
+
// Squeeze phase blocks
|
|
312
|
+
for (size_t i = 0; i < num_squeeze_blocks; ++i) {
|
|
313
|
+
v64 A_sqz[5][5];
|
|
314
|
+
for (int x = 0; x < 5; ++x) {
|
|
315
|
+
for (int y = 0; y < 5; ++y) {
|
|
316
|
+
A_sqz[x][y] = bws[num_absorb_blocks - 1 + i].a_intermediate[23][x][y];
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
keccak_f_1600(A_sqz, bws[bw_idx++]);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
check(bw_idx == bws.size(), "Did not consume all BlockWitnesses");
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
template <size_t I0, size_t I1>
|
|
326
|
+
void sha3_vassert_eq_range(const v64& x, const v64& y) const {
|
|
327
|
+
auto xx = lc_.as_scalar(lc_.template slice<I0, I1>(x));
|
|
328
|
+
auto yy = lc_.as_scalar(lc_.template slice<I0, I1>(y));
|
|
329
|
+
lc_.assert_eq(xx, yy);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
void sha3_vassert_eq(const v64& x, const v64& y) const {
|
|
333
|
+
if (LogicCircuit::Field::kSubFieldBits == 16) {
|
|
334
|
+
sha3_vassert_eq_range<0, 16>(x, y);
|
|
335
|
+
sha3_vassert_eq_range<16, 32>(x, y);
|
|
336
|
+
sha3_vassert_eq_range<32, 48>(x, y);
|
|
337
|
+
sha3_vassert_eq_range<48, 64>(x, y);
|
|
338
|
+
} else {
|
|
339
|
+
// Assume >= 22 bit subfield. If this assumption is
|
|
340
|
+
// wrong, as_scalar() will crash at circuit-compile time,
|
|
341
|
+
// but we won't produce an unsound circuit.
|
|
342
|
+
sha3_vassert_eq_range<0, 22>(x, y);
|
|
343
|
+
sha3_vassert_eq_range<22, 43>(x, y);
|
|
344
|
+
sha3_vassert_eq_range<43, 64>(x, y);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
} // namespace proofs
|
|
350
|
+
|
|
351
|
+
#endif // PRIVACY_PROOFS_ZK_LIB_CIRCUITS_TESTS_SHA3_SHA3_CIRCUIT_H_
|