diff --git a/willow/benches/BUILD b/willow/benches/BUILD index 11651ca..a975b7e 100644 --- a/willow/benches/BUILD +++ b/willow/benches/BUILD @@ -28,24 +28,24 @@ rust_library( deps = [ "@crate_index//:clap", "//willow/src/api:aggregation_config", - "//willow/src/shell:kahe_shell", - "//willow/src/shell:parameters_shell", - "//willow/src/shell:single_thread_hkdf", - "//willow/src/shell:vahe_shell", + "//willow/src/crypto:ahe_traits", + "//willow/src/crypto:kahe_traits", + "//willow/src/crypto:prng_traits", + "//willow/src/crypto:shell_kahe", + "//willow/src/crypto:shell_parameters", + "//willow/src/crypto:shell_vahe", + "//willow/src/crypto:single_thread_hkdf", + "//willow/src/crypto:vahe_traits", + "//willow/src/protocol:client_traits", + "//willow/src/protocol:decryptor_traits", + "//willow/src/protocol:messages", + "//willow/src/protocol:server_traits", + "//willow/src/protocol:verifier_traits", + "//willow/src/protocol:willow_v1_client", + "//willow/src/protocol:willow_v1_decryptor", + "//willow/src/protocol:willow_v1_server", + "//willow/src/protocol:willow_v1_verifier", "//willow/src/testing_utils", - "//willow/src/traits:ahe_traits", - "//willow/src/traits:client_traits", - "//willow/src/traits:decryptor_traits", - "//willow/src/traits:kahe_traits", - "//willow/src/traits:messages", - "//willow/src/traits:prng_traits", - "//willow/src/traits:server_traits", - "//willow/src/traits:vahe_traits", - "//willow/src/traits:verifier_traits", - "//willow/src/willow_v1:willow_v1_client", - "//willow/src/willow_v1:willow_v1_decryptor", - "//willow/src/willow_v1:willow_v1_server", - "//willow/src/willow_v1:willow_v1_verifier", ], ) diff --git a/willow/benches/shell_benchmarks.rs b/willow/benches/shell_benchmarks.rs index 1933297..c3b4587 100644 --- a/willow/benches/shell_benchmarks.rs +++ b/willow/benches/shell_benchmarks.rs @@ -21,18 +21,18 @@ use aggregation_config::AggregationConfig; use ahe_traits::AheBase; use client_traits::SecureAggregationClient; use decryptor_traits::SecureAggregationDecryptor; -use kahe_shell::ShellKahe; use kahe_traits::KaheBase; use messages::{ CiphertextContribution, DecryptionRequestContribution, DecryptorPublicKey, PartialDecryptionRequest, }; -use parameters_shell::{create_shell_ahe_config, create_shell_kahe_config}; use prng_traits::SecurePrng; use server_traits::SecureAggregationServer; +use shell_kahe::ShellKahe; +use shell_parameters::{create_shell_ahe_config, create_shell_kahe_config}; +use shell_vahe::ShellVahe; use single_thread_hkdf::SingleThreadHkdfPrng; use testing_utils::{generate_random_nonce, generate_random_unsigned_vector}; -use vahe_shell::ShellVahe; use verifier_traits::SecureAggregationVerifier; use willow_v1_client::WillowV1Client; use willow_v1_decryptor::{DecryptorState, WillowV1Decryptor}; diff --git a/willow/src/api/BUILD b/willow/src/api/BUILD index 076cdf5..3484577 100644 --- a/willow/src/api/BUILD +++ b/willow/src/api/BUILD @@ -24,16 +24,27 @@ package( default_visibility = ["//visibility:public"], ) +rust_library( + name = "proto_serialization_traits", + srcs = [ + "proto_serialization.rs", + ], + deps = [ + "@protobuf//rust:protobuf", + "//shell_wrapper:status", + ], +) + rust_library( name = "aggregation_config", srcs = [ "aggregation_config.rs", ], deps = [ + ":proto_serialization_traits", "@protobuf//rust:protobuf", "//shell_wrapper:status", "//willow/proto/willow:aggregation_config_rust_proto", - "//willow/src/traits:proto_serialization_traits", ], ) @@ -97,17 +108,17 @@ rust_library( "//shell_wrapper:status", "//willow/proto/willow:aggregation_config_rust_proto", "//willow/proto/willow:server_accumulator_rust_proto", - "//willow/src/shell:kahe_shell", - "//willow/src/shell:parameters_shell", - "//willow/src/shell:vahe_shell", - "//willow/src/traits:ahe_traits", - "//willow/src/traits:kahe_traits", - "//willow/src/traits:messages", - "//willow/src/traits:proto_serialization_traits", - "//willow/src/traits:server_traits", - "//willow/src/traits:vahe_traits", - "//willow/src/traits:verifier_traits", - "//willow/src/willow_v1:willow_v1_server", - "//willow/src/willow_v1:willow_v1_verifier", + "//willow/src/crypto:ahe_traits", + "//willow/src/crypto:kahe_traits", + "//willow/src/crypto:shell_kahe", + "//willow/src/crypto:shell_parameters", + "//willow/src/crypto:shell_vahe", + "//willow/src/crypto:vahe_traits", + "//willow/src/protocol:messages", + "//willow/src/protocol:server_traits", + "//willow/src/protocol:verifier_traits", + "//willow/src/protocol:willow_v1_server", + "//willow/src/protocol:willow_v1_verifier", + ":proto_serialization_traits", ], ) diff --git a/willow/src/traits/proto_serialization.rs b/willow/src/api/proto_serialization.rs similarity index 100% rename from willow/src/traits/proto_serialization.rs rename to willow/src/api/proto_serialization.rs diff --git a/willow/src/api/server_accumulator.rs b/willow/src/api/server_accumulator.rs index aa3e3ae..f3568d7 100644 --- a/willow/src/api/server_accumulator.rs +++ b/willow/src/api/server_accumulator.rs @@ -15,17 +15,17 @@ use aggregation_config::AggregationConfig; use aggregation_config_rust_proto::AggregationConfigProto; use ahe_traits::AheBase; -use kahe_shell::ShellKahe; use kahe_traits::KaheBase; use messages::ClientMessage; -use parameters_shell::{create_shell_ahe_config, create_shell_kahe_config}; use proto_serialization_traits::{FromProto, ToProto}; use protobuf::prelude::*; use protobuf::AsView; use server_accumulator_rust_proto::{ClientMessageList, ServerAccumulatorState}; use server_traits::SecureAggregationServer; +use shell_kahe::ShellKahe; +use shell_parameters::{create_shell_ahe_config, create_shell_kahe_config}; +use shell_vahe::ShellVahe; use status::StatusError; -use vahe_shell::ShellVahe; use verifier_traits::SecureAggregationVerifier; use willow_v1_server::{ServerState, WillowV1Server}; use willow_v1_verifier::{VerifierState, WillowV1Verifier}; diff --git a/willow/src/crypto/BUILD b/willow/src/crypto/BUILD new file mode 100644 index 0000000..9b1e5d4 --- /dev/null +++ b/willow/src/crypto/BUILD @@ -0,0 +1,429 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") + +package( + default_applicable_licenses = [ + ], + default_visibility = ["//visibility:public"], +) + +# Cryptographic primitives traits + +rust_library( + name = "prng_traits", + srcs = [ + "prng_traits.rs", + ], + deps = [ + "//shell_wrapper:status", + ], +) + +rust_library( + name = "kahe_traits", + srcs = [ + "kahe_traits.rs", + ], + deps = [ + ":prng_traits", + "//shell_wrapper:status", + ], +) + +rust_library( + name = "ahe_traits", + srcs = [ + "ahe_traits.rs", + ], + deps = [ + ":prng_traits", + "//shell_wrapper:status", + ], +) + +rust_library( + name = "vahe_traits", + srcs = [ + "vahe_traits.rs", + ], + deps = [ + ":ahe_traits", + "//shell_wrapper:status", + ], +) + +# KAHE, AHE and VAHE implementations using Shell + +rust_library( + name = "shell_kahe", + srcs = ["shell_kahe.rs"], + deps = [ + ":kahe_traits", + ":prng_traits", + ":single_thread_hkdf", + "@protobuf//rust:protobuf", + "//shell_wrapper:kahe", + "//shell_wrapper:shell_serialization", + "//shell_wrapper:shell_serialization_cxx", # fixdeps: keep + "//shell_wrapper:shell_types", + "//shell_wrapper:status", + "//willow/proto/shell:shell_ciphertexts_rust_proto", + "//willow/src/api:proto_serialization_traits", + ], +) + +rust_test( + name = "shell_kahe_test", + crate = ":shell_kahe", + deps = [ + ":shell_kahe", + "@crate_index//:googletest", + "//shell_wrapper:kahe", + "//shell_wrapper:status", + "//willow/src/testing_utils", + "//willow/src/testing_utils:shell_testing_parameters", + ], +) + +rust_library( + name = "shell_ahe", + srcs = [ + "shell_ahe.rs", + ], + deps = [ + ":ahe_traits", + ":prng_traits", + ":single_thread_hkdf", + "@protobuf//rust:protobuf", + "//shell_wrapper:ahe", + "//shell_wrapper:ahe_cxx", # fixdeps: keep + "//shell_wrapper:shell_serialization", + "//shell_wrapper:shell_serialization_cxx", # fixdeps: keep + "//shell_wrapper:shell_types", + "//shell_wrapper:status", + "//willow/proto/shell:shell_ciphertexts_rust_proto", + "//willow/src/api:proto_serialization_traits", + ], +) + +rust_test( + name = "shell_ahe_test", + crate = ":shell_ahe", + deps = [ + ":ahe_traits", + ":prng_traits", + ":shell_ahe", + ":single_thread_hkdf", + "@crate_index//:googletest", + "//shell_wrapper:status", + "//shell_wrapper:status_matchers_rs", + "//willow/src/api:proto_serialization_traits", + "//willow/src/testing_utils", + "//willow/src/testing_utils:shell_testing_parameters", + ], +) + +rust_library( + name = "shell_vahe", + srcs = ["shell_vahe.rs"], + deps = [ + ":ahe_traits", + ":rlwe_relation_serialization", + ":shell_ahe", + ":single_thread_hkdf", + ":vahe_traits", + ":zk_rlwe_relation", + ":zk_traits", + "@protobuf//rust:protobuf", + "@crate_index//:merlin", + "//shell_wrapper:ahe", + "//shell_wrapper:ahe_cxx", # fixdeps: keep + "//shell_wrapper:shell_types", + "//shell_wrapper:status", + "//willow/proto/zk:proofs_rust_proto", + "//willow/src/api:proto_serialization_traits", + ], +) + +rust_test( + name = "shell_vahe_test", + crate = ":shell_vahe", + deps = [ + ":ahe_traits", + ":prng_traits", + ":shell_vahe", + ":vahe_traits", + ":zk_rlwe_relation", + ":zk_traits", + "@crate_index//:googletest", + "@crate_index//:merlin", + "//shell_wrapper:status", + "//willow/src/api:proto_serialization_traits", + "//willow/src/testing_utils", + "//willow/src/testing_utils:shell_testing_parameters", + ], +) + +# Parameters of the underlying RLWE systems +rust_library( + name = "shell_parameters", + srcs = ["shell_parameters.rs"], + deps = [ + ":shell_ahe", + ":shell_kahe", + ":shell_parameters_generation", + "//shell_wrapper:kahe", + "//shell_wrapper:status", + "//willow/src/api:aggregation_config", + ], +) + +# Utilities for parameters proto (e.g. conversion between rust structs and protos) +rust_library( + name = "shell_parameters_utils", + srcs = ["shell_parameters_utils.rs"], + deps = [ + ":shell_kahe", + "@protobuf//rust:protobuf", + "//shell_wrapper:kahe", + "//shell_wrapper:status", + "//willow/proto/shell:shell_parameters_rust_proto", + ], +) + +rust_test( + name = "shell_parameters_utils_test", + crate = ":shell_parameters_utils", + deps = [ + ":shell_parameters_utils", + "@crate_index//:googletest", + "@protobuf//rust:protobuf_gtest_matchers", + "//shell_wrapper:status", + ], +) + +# Parameter generation +rust_library( + name = "shell_parameters_generation", + srcs = ["shell_parameters_generation.rs"], + deps = [ + ":shell_kahe", + "//shell_wrapper:kahe", + "//shell_wrapper:status", + "//willow/src/api:aggregation_config", + ], +) + +rust_test( + name = "shell_parameters_generation_test", + crate = ":shell_parameters_generation", + deps = [ + ":shell_parameters_generation", + "@crate_index//:googletest", + "@protobuf//rust:protobuf_gtest_matchers", + "//shell_wrapper:status", + ], +) + +# PRNG +rust_library( + name = "single_thread_hkdf", + srcs = [ + "single_thread_hkdf.rs", + ], + deps = [ + ":prng_traits", + "//shell_wrapper:single_thread_hkdf", + "//shell_wrapper:single_thread_hkdf_cxx", # fixdeps: keep + "//shell_wrapper:status", + ], +) + +rust_test( + name = "single_thread_hkdf_test", + crate = ":single_thread_hkdf", + deps = [ + "@crate_index//:googletest", + ], +) + +# Zero knowledge + +rust_library( + name = "zk_traits", + srcs = [ + "zk_traits.rs", + ], + visibility = ["//visibility:private"], + deps = [ + ":ahe_traits", + ":shell_ahe", + ":single_thread_hkdf", + "@protobuf//rust:protobuf", + "@crate_index//:curve25519-dalek", + "@crate_index//:merlin", + "//shell_wrapper:shell_types", + "//shell_wrapper:status", + ], +) + +rust_library( + name = "zk_linear_innerproduct", + srcs = ["zk_linear_ip.rs"], + deps = [ + ":prng_traits", + ":zk_traits", + "@crate_index//:curve25519-dalek", + "@crate_index//:merlin", + "@crate_index//:rand", + "@crate_index//:sha3", + "@crate_index//:thiserror", + "//shell_wrapper:status", + "//willow/proto/zk:proofs_rust_proto", + ], +) + +rust_test( + name = "zk_linear_innerproduct_test", + crate = ":zk_linear_innerproduct", + deps = [ + "@crate_index//:googletest", + "//shell_wrapper:status_matchers_rs", + ], +) + +rust_library( + name = "linear_ip_serialization", + srcs = ["linear_ip_serialization.rs"], + deps = [ + ":zk_linear_innerproduct", + ":zk_traits", + "@protobuf//rust:protobuf", + "@crate_index//:curve25519-dalek", + "//shell_wrapper:status", + "//willow/proto/zk:proofs_rust_proto", + ], +) + +rust_test( + name = "linear_ip_serialization_test", + crate = ":linear_ip_serialization", + deps = [ + ":zk_linear_innerproduct", + ":zk_traits", + "@crate_index//:googletest", + "@crate_index//:curve25519-dalek", + "@crate_index//:merlin", + "@crate_index//:rand", + ], +) + +rust_library( + name = "zk_quadratic_innerproduct", + testonly = 1, + srcs = ["zk_quadratic_ip.rs"], + deps = [ + ":prng_traits", + ":zk_traits", + "@crate_index//:curve25519-dalek", + "@crate_index//:merlin", + "@crate_index//:rand", + "@crate_index//:sha3", + "@crate_index//:thiserror", + "//shell_wrapper:status", + ], +) + +rust_test( + name = "zk_quadratic_innerproduct_test", + crate = ":zk_quadratic_innerproduct", + deps = [ + "@crate_index//:googletest", + "//shell_wrapper:status_matchers_rs", + ], +) + +# RLWE relation zero-knowledge proof. +rust_library( + name = "zk_rlwe_relation", + srcs = ["zk_rlwe_relation.rs"], + visibility = ["//visibility:private"], + deps = [ + ":zk_linear_innerproduct", + ":zk_traits", + "@protobuf//rust:protobuf", + "@crate_index//:curve25519-dalek", + "@crate_index//:merlin", + "@crate_index//:rand", + "//shell_wrapper:shell_types", + "//shell_wrapper:status", + "//willow/proto/zk:proofs_rust_proto", + ], +) + +rust_test( + name = "zk_rlwe_relation_test", + crate = ":zk_rlwe_relation", + deps = [ + ":shell_ahe", + "@crate_index//:googletest", + "@crate_index//:sha3", + "//shell_wrapper:ahe", + "//shell_wrapper:ahe_cxx", # fixdeps: keep + "//shell_wrapper:single_thread_hkdf", + "//shell_wrapper:single_thread_hkdf_cxx", + "//shell_wrapper:status_matchers_rs", + "//willow/src/testing_utils:shell_testing_parameters", + ], +) + +rust_library( + name = "rlwe_relation_serialization", + srcs = ["rlwe_relation_serialization.rs"], + deps = [ + ":linear_ip_serialization", + ":zk_linear_innerproduct", + ":zk_rlwe_relation", + "@protobuf//rust:protobuf", + "@crate_index//:curve25519-dalek", + "//shell_wrapper:status", + "//willow/proto/zk:proofs_rust_proto", + ], +) + +rust_test( + name = "rlwe_relation_serialization_test", + crate = ":rlwe_relation_serialization", + deps = [ + ":prng_traits", + ":rlwe_relation_serialization", + ":shell_ahe", + ":single_thread_hkdf", + ":zk_traits", + "@crate_index//:googletest", + "@protobuf//rust:protobuf", + "@crate_index//:curve25519-dalek", + "@crate_index//:merlin", + "@crate_index//:sha3", + "//shell_wrapper:ahe", + "//shell_wrapper:ahe_cxx", + "//shell_wrapper:shell_types", + "//shell_wrapper:single_thread_hkdf_cxx", + "//shell_wrapper:status_matchers_rs", + "//willow/proto/zk:proofs_rust_proto", + "//willow/src/testing_utils:shell_testing_parameters", + ], +) diff --git a/willow/src/traits/ahe.rs b/willow/src/crypto/ahe_traits.rs similarity index 100% rename from willow/src/traits/ahe.rs rename to willow/src/crypto/ahe_traits.rs diff --git a/willow/src/traits/kahe.rs b/willow/src/crypto/kahe_traits.rs similarity index 100% rename from willow/src/traits/kahe.rs rename to willow/src/crypto/kahe_traits.rs diff --git a/willow/src/zk/linear_ip_serialization.rs b/willow/src/crypto/linear_ip_serialization.rs similarity index 96% rename from willow/src/zk/linear_ip_serialization.rs rename to willow/src/crypto/linear_ip_serialization.rs index 8ba6e43..95e3f0e 100644 --- a/willow/src/zk/linear_ip_serialization.rs +++ b/willow/src/crypto/linear_ip_serialization.rs @@ -14,9 +14,9 @@ use curve25519_dalek::ristretto::CompressedRistretto; use curve25519_dalek::Scalar; -use linear_innerproduct::LinearInnerProductProof; use proofs_rust_proto::LinearInnerProductProofProto; use protobuf::{proto, AsView}; +use zk_linear_innerproduct::LinearInnerProductProof; pub fn linear_inner_product_proof_to_proto( proof: &LinearInnerProductProof, @@ -67,9 +67,9 @@ mod tests { use super::*; use curve25519_dalek::scalar::Scalar; use googletest::gtest; - use linear_innerproduct::{LinearInnerProductProver, LinearInnerProductVerifier}; use merlin::Transcript as MerlinTranscript; use rand; + use zk_linear_innerproduct::{LinearInnerProductProver, LinearInnerProductVerifier}; use zk_traits::{ LinearInnerProductProofStatement, LinearInnerProductProofWitness, ZeroKnowledgeProver, ZeroKnowledgeVerifier, diff --git a/willow/src/traits/prng.rs b/willow/src/crypto/prng_traits.rs similarity index 100% rename from willow/src/traits/prng.rs rename to willow/src/crypto/prng_traits.rs diff --git a/willow/src/zk/rlwe_relation_serialization.rs b/willow/src/crypto/rlwe_relation_serialization.rs similarity index 96% rename from willow/src/zk/rlwe_relation_serialization.rs rename to willow/src/crypto/rlwe_relation_serialization.rs index 49a97cb..83d3ece 100644 --- a/willow/src/zk/rlwe_relation_serialization.rs +++ b/willow/src/crypto/rlwe_relation_serialization.rs @@ -19,7 +19,7 @@ use linear_ip_serialization::{ }; use proofs_rust_proto::RlweRelationProofProto; use protobuf::{proto, AsView}; -use rlwe_relation::RlweRelationProof; +use zk_rlwe_relation::RlweRelationProof; pub fn rlwe_relation_proof_to_proto(proof: &RlweRelationProof) -> RlweRelationProofProto { proto!(RlweRelationProofProto { @@ -124,9 +124,10 @@ mod tests { use ahe::{create_public_parameters, get_moduli, get_rns_context_ref}; use googletest::gtest; use merlin::Transcript as MerlinTranscript; - use rlwe_relation::{RlweRelationProver, RlweRelationVerifier}; + use prng_traits::SecurePrng; use shell_types::read_small_rns_polynomial_from_buffer; - use single_thread_hkdf::generate_seed; + use single_thread_hkdf::SingleThreadHkdfPrng; + use zk_rlwe_relation::{RlweRelationProver, RlweRelationVerifier}; use zk_traits::{ RlweRelationProofStatement, RlweRelationProofWitness, ZeroKnowledgeProver, ZeroKnowledgeVerifier, @@ -136,7 +137,7 @@ mod tests { fn test_proof_proto_roundtrip() -> googletest::Result<()> { // We create an ahe_parameters instance to get the context reference and moduli objects. let qvec = vec![1000_000_009]; - let seed_wrapper = generate_seed()?; + let seed_wrapper = SingleThreadHkdfPrng::generate_seed()?; let ahe_parameters = create_public_parameters(2, 54001, &qvec, 1, 1.0, 1.0, &seed_wrapper)?; let context = get_rns_context_ref(&ahe_parameters); let n = 4; diff --git a/willow/src/shell/ahe.rs b/willow/src/crypto/shell_ahe.rs similarity index 99% rename from willow/src/shell/ahe.rs rename to willow/src/crypto/shell_ahe.rs index d8e3b27..f67c0b0 100644 --- a/willow/src/shell/ahe.rs +++ b/willow/src/crypto/shell_ahe.rs @@ -765,7 +765,7 @@ impl ExportEncryptionMetadata<(Vec>, Vec>)> for ShellAhe { #[cfg(test)] mod test { // Instead of `super::*` because we consume types from other testing crates. - use ahe_shell::*; + use shell_ahe::*; use ahe_traits::{ AheBase, AheEncrypt, AheKeygen, ExportCiphertext, ExportEncryptionMetadata, diff --git a/willow/src/shell/kahe.rs b/willow/src/crypto/shell_kahe.rs similarity index 99% rename from willow/src/shell/kahe.rs rename to willow/src/crypto/shell_kahe.rs index 8ff84a3..7d75bda 100644 --- a/willow/src/shell/kahe.rs +++ b/willow/src/crypto/shell_kahe.rs @@ -368,12 +368,12 @@ mod test { // Instead of `super::*` because we consume types from other testing crates. use googletest::{gtest, verify_eq, verify_le}; use kahe::PackedVectorConfig; - use kahe_shell::*; use kahe_traits::{ KaheBase, KaheDecrypt, KaheEncrypt, KaheKeygen, TrySecretKeyFrom, TrySecretKeyInto, }; use prng_traits::SecurePrng; use proto_serialization_traits::{FromProto, ToProto}; + use shell_kahe::*; use shell_testing_parameters::{make_kahe_config_for, set_kahe_num_public_polynomials}; use single_thread_hkdf::SingleThreadHkdfPrng; use std::collections::HashMap; @@ -381,7 +381,7 @@ mod test { /// Standard deviation of the discrete Gaussian distribution used for /// secret key generation. Hardcoded in shell_wrapper/kahe.h for now (if we ever - /// need to change it then we can pass it from Rust like we do in shell/ahe.rs). + /// need to change it then we can pass it from Rust like we do in shell_ahe.rs). const SECRET_KEY_STD: f64 = 4.5; /// The tail bound cut-off multiplier such that the probability of a sample diff --git a/willow/src/shell/parameters.rs b/willow/src/crypto/shell_parameters.rs similarity index 99% rename from willow/src/shell/parameters.rs rename to willow/src/crypto/shell_parameters.rs index 69ea365..29b414a 100644 --- a/willow/src/shell/parameters.rs +++ b/willow/src/crypto/shell_parameters.rs @@ -13,8 +13,9 @@ // limitations under the License. use aggregation_config::AggregationConfig; -use ahe_shell::ShellAheConfig; -use kahe_shell::ShellKaheConfig; +use shell_ahe::ShellAheConfig; +use shell_kahe::ShellKaheConfig; + use shell_parameters_generation::{divide_and_roundup, generate_packing_config}; /// This file contains parameters for the KAHE and AHE schemes in Willow, which diff --git a/willow/src/shell/parameters_generation.rs b/willow/src/crypto/shell_parameters_generation.rs similarity index 100% rename from willow/src/shell/parameters_generation.rs rename to willow/src/crypto/shell_parameters_generation.rs diff --git a/willow/src/shell/parameters_utils.rs b/willow/src/crypto/shell_parameters_utils.rs similarity index 99% rename from willow/src/shell/parameters_utils.rs rename to willow/src/crypto/shell_parameters_utils.rs index c309d11..b0805fd 100644 --- a/willow/src/shell/parameters_utils.rs +++ b/willow/src/crypto/shell_parameters_utils.rs @@ -13,8 +13,8 @@ // limitations under the License. use kahe::PackedVectorConfig; -use kahe_shell::ShellKaheConfig; use protobuf::{proto, ProtoStr}; +use shell_kahe::ShellKaheConfig; use shell_parameters_rust_proto::{ PackedVectorConfigProto, PackedVectorConfigProtoView, ShellKaheConfigProto, ShellKaheConfigProtoView, diff --git a/willow/src/shell/vahe.rs b/willow/src/crypto/shell_vahe.rs similarity index 99% rename from willow/src/shell/vahe.rs rename to willow/src/crypto/shell_vahe.rs index 55c1544..26c3cfe 100644 --- a/willow/src/shell/vahe.rs +++ b/willow/src/crypto/shell_vahe.rs @@ -12,15 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. -use ahe_shell::{ShellAhe, ShellAheConfig}; use ahe_traits::Recover as AheRecover; use ahe_traits::{AheBase, AheKeygen, PartialDec}; use merlin::Transcript as MerlinTranscript; use proofs_rust_proto::{RlweRelationProofListProto, RlweRelationProofProto}; use proto_serialization_traits::{FromProto, ToProto}; use protobuf::{proto, AsView}; -use rlwe_relation::{RlweRelationProof, RlweRelationProver, RlweRelationVerifier}; use rlwe_relation_serialization::{rlwe_relation_proof_from_proto, rlwe_relation_proof_to_proto}; +use shell_ahe::{ShellAhe, ShellAheConfig}; use single_thread_hkdf::{compute_hkdf, Seed}; use status::Status; use status::StatusError; @@ -28,6 +27,7 @@ use vahe_traits::{ EncryptVerify, KeyGenVerify, PartialDecVerify, Recover, VaheBase, VerifiableEncrypt, VerifiableKeyGen, VerifiablePartialDec, }; +use zk_rlwe_relation::{RlweRelationProof, RlweRelationProver, RlweRelationVerifier}; use zk_traits::{ RlweRelationProofStatement, RlweRelationProofWitness, ZeroKnowledgeProver, ZeroKnowledgeVerifier, diff --git a/willow/src/shell/single_thread_hkdf.rs b/willow/src/crypto/single_thread_hkdf.rs similarity index 100% rename from willow/src/shell/single_thread_hkdf.rs rename to willow/src/crypto/single_thread_hkdf.rs diff --git a/willow/src/traits/vahe.rs b/willow/src/crypto/vahe_traits.rs similarity index 100% rename from willow/src/traits/vahe.rs rename to willow/src/crypto/vahe_traits.rs diff --git a/willow/src/zk/linear_ip.rs b/willow/src/crypto/zk_linear_ip.rs similarity index 99% rename from willow/src/zk/linear_ip.rs rename to willow/src/crypto/zk_linear_ip.rs index d96f4da..d969ecc 100644 --- a/willow/src/zk/linear_ip.rs +++ b/willow/src/crypto/zk_linear_ip.rs @@ -15,6 +15,7 @@ use curve25519_dalek::ristretto::{CompressedRistretto, RistrettoPoint}; use curve25519_dalek::scalar::Scalar; use curve25519_dalek::traits::VartimeMultiscalarMul; +use proofs_rust_proto::LinearInnerProductProofProto; use rand; use std::iter; use zk_traits::{ diff --git a/willow/src/zk/quadratic_ip.rs b/willow/src/crypto/zk_quadratic_ip.rs similarity index 100% rename from willow/src/zk/quadratic_ip.rs rename to willow/src/crypto/zk_quadratic_ip.rs diff --git a/willow/src/zk/rlwe_relation.rs b/willow/src/crypto/zk_rlwe_relation.rs similarity index 99% rename from willow/src/zk/rlwe_relation.rs rename to willow/src/crypto/zk_rlwe_relation.rs index c8dbc45..b11d268 100644 --- a/willow/src/zk/rlwe_relation.rs +++ b/willow/src/crypto/zk_rlwe_relation.rs @@ -14,11 +14,12 @@ use curve25519_dalek::ristretto::{CompressedRistretto, RistrettoPoint}; use curve25519_dalek::scalar::Scalar; -use linear_innerproduct::{ - LinearInnerProductProof, LinearInnerProductProver, LinearInnerProductVerifier, -}; +use proofs_rust_proto::RlweRelationProofProto; use rand::Rng; use shell_types::{write_rns_polynomial_to_buffer_128, RnsContextRef, RnsPolynomial}; +use zk_linear_innerproduct::{ + LinearInnerProductProof, LinearInnerProductProver, LinearInnerProductVerifier, +}; use zk_traits::{ LinearInnerProductProofStatement, LinearInnerProductProofWitness, RlweRelationProofStatement, RlweRelationProofWitness, Transcript, ZeroKnowledgeProver, ZeroKnowledgeVerifier, diff --git a/willow/src/traits/zk.rs b/willow/src/crypto/zk_traits.rs similarity index 100% rename from willow/src/traits/zk.rs rename to willow/src/crypto/zk_traits.rs diff --git a/willow/src/protocol/BUILD b/willow/src/protocol/BUILD new file mode 100644 index 0000000..f2016ef --- /dev/null +++ b/willow/src/protocol/BUILD @@ -0,0 +1,244 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") + +package( + default_applicable_licenses = [ + ], + default_visibility = ["//visibility:public"], +) + +# Protocol level message types: Client, Server, Decryptor. +rust_library( + name = "messages", + srcs = [ + "messages.rs", + ], + deps = [ + "@protobuf//rust:protobuf", + "//shell_wrapper:status", + "//willow/proto/shell:shell_ciphertexts_rust_proto", + "//willow/proto/willow:messages_rust_proto", + "//willow/proto/zk:proofs_rust_proto", + "//willow/src/api:proto_serialization_traits", + "//willow/src/crypto:ahe_traits", + "//willow/src/crypto:kahe_traits", + "//willow/src/crypto:vahe_traits", + ], +) + +# Protocol level traits +rust_library( + name = "client_traits", + srcs = [ + "client_traits.rs", + ], + deps = [ + ":messages", + "//shell_wrapper:status", + "//willow/src/crypto:kahe_traits", + "//willow/src/crypto:vahe_traits", + ], +) + +rust_library( + name = "server_traits", + srcs = [ + "server_traits.rs", + ], + deps = [ + ":messages", + "//shell_wrapper:status", + "//willow/src/crypto:kahe_traits", + "//willow/src/crypto:vahe_traits", + ], +) + +rust_library( + name = "decryptor_traits", + srcs = [ + "decryptor_traits.rs", + ], + deps = [ + ":messages", + "//shell_wrapper:status", + "//willow/src/crypto:vahe_traits", + ], +) + +rust_library( + name = "verifier_traits", + srcs = [ + "verifier_traits.rs", + ], + deps = [ + ":messages", + "//shell_wrapper:status", + "//willow/src/crypto:vahe_traits", + ], +) + +# Protocol level implementations using Shell +rust_library( + name = "willow_v1_client", + srcs = [ + "willow_v1_client.rs", + ], + deps = [ + ":client_traits", + ":messages", + "//shell_wrapper:status", + "//willow/src/crypto:ahe_traits", + "//willow/src/crypto:kahe_traits", + "//willow/src/crypto:prng_traits", + "//willow/src/crypto:vahe_traits", + ], +) + +rust_test( + name = "willow_v1_client_test", + crate = ":willow_v1_client", + deps = [ + "@crate_index//:googletest", + "//willow/src/api:aggregation_config", + "//willow/src/crypto:prng_traits", + "//willow/src/crypto:shell_kahe", + "//willow/src/crypto:shell_vahe", + "//willow/src/crypto:single_thread_hkdf", + "//willow/src/testing_utils", + "//willow/src/testing_utils:shell_testing_parameters", + ], +) + +rust_test( + name = "willow_v1_decryptor_test", + crate = ":willow_v1_decryptor", + deps = [ + ":decryptor_traits", + "@crate_index//:googletest", + "//willow/src/api:proto_serialization_traits", + "//willow/src/crypto:ahe_traits", + "//willow/src/crypto:prng_traits", + "//willow/src/crypto:shell_parameters", + "//willow/src/crypto:shell_vahe", + "//willow/src/crypto:single_thread_hkdf", + ], +) + +rust_library( + name = "willow_v1_decryptor", + srcs = [ + "willow_v1_decryptor.rs", + ], + deps = [ + ":decryptor_traits", + ":messages", + "@protobuf//rust:protobuf", + "//shell_wrapper:status", + "//willow/proto/shell:shell_ciphertexts_rust_proto", + "//willow/proto/willow:messages_rust_proto", + "//willow/src/api:proto_serialization_traits", + "//willow/src/crypto:ahe_traits", + "//willow/src/crypto:vahe_traits", + ], +) + +rust_test( + name = "willow_v1_server_test", + crate = ":willow_v1_server", + deps = [ + ":client_traits", + ":decryptor_traits", + ":server_traits", + ":verifier_traits", + ":willow_v1_client", + ":willow_v1_decryptor", + ":willow_v1_verifier", + "@crate_index//:googletest", + "//willow/src/api:proto_serialization_traits", + "//willow/src/crypto:ahe_traits", + "//willow/src/crypto:prng_traits", + "//willow/src/crypto:shell_kahe", + "//willow/src/crypto:shell_parameters", + "//willow/src/crypto:shell_vahe", + "//willow/src/crypto:single_thread_hkdf", + "//willow/src/testing_utils", + "//willow/src/testing_utils:shell_testing_parameters", + ], +) + +rust_library( + name = "willow_v1_server", + srcs = [ + "willow_v1_server.rs", + ], + deps = [ + ":messages", + ":server_traits", + "@protobuf//rust:protobuf", + "//shell_wrapper:status", + "//willow/proto/shell:shell_ciphertexts_rust_proto", + "//willow/proto/willow:messages_rust_proto", + "//willow/src/api:proto_serialization_traits", + "//willow/src/crypto:ahe_traits", + "//willow/src/crypto:kahe_traits", + "//willow/src/crypto:vahe_traits", + ], +) + +rust_library( + name = "willow_v1_verifier", + srcs = [ + "willow_v1_verifier.rs", + ], + deps = [ + ":messages", + ":verifier_traits", + "@protobuf//rust:protobuf", + "//shell_wrapper:status", + "//willow/proto/shell:shell_ciphertexts_rust_proto", + "//willow/proto/willow:messages_rust_proto", + "//willow/src/api:proto_serialization_traits", + "//willow/src/crypto:ahe_traits", + "//willow/src/crypto:kahe_traits", + "//willow/src/crypto:vahe_traits", + ], +) + +rust_test( + name = "willow_v1_verifier_test", + crate = ":willow_v1_verifier", + deps = [ + ":client_traits", + ":decryptor_traits", + ":server_traits", + ":willow_v1_client", + ":willow_v1_decryptor", + ":willow_v1_server", + "@crate_index//:googletest", + "//shell_wrapper:status_matchers_rs", + "//willow/src/api:proto_serialization_traits", + "//willow/src/crypto:ahe_traits", + "//willow/src/crypto:kahe_traits", + "//willow/src/crypto:prng_traits", + "//willow/src/crypto:shell_kahe", + "//willow/src/crypto:shell_parameters", + "//willow/src/crypto:shell_vahe", + "//willow/src/crypto:single_thread_hkdf", + "//willow/src/crypto:vahe_traits", + "//willow/src/testing_utils", + "//willow/src/testing_utils:shell_testing_parameters", + ], +) diff --git a/willow/src/traits/client.rs b/willow/src/protocol/client_traits.rs similarity index 100% rename from willow/src/traits/client.rs rename to willow/src/protocol/client_traits.rs diff --git a/willow/src/traits/decryptor.rs b/willow/src/protocol/decryptor_traits.rs similarity index 100% rename from willow/src/traits/decryptor.rs rename to willow/src/protocol/decryptor_traits.rs diff --git a/willow/src/traits/messages.rs b/willow/src/protocol/messages.rs similarity index 100% rename from willow/src/traits/messages.rs rename to willow/src/protocol/messages.rs diff --git a/willow/src/traits/server.rs b/willow/src/protocol/server_traits.rs similarity index 100% rename from willow/src/traits/server.rs rename to willow/src/protocol/server_traits.rs diff --git a/willow/src/traits/verifier.rs b/willow/src/protocol/verifier_traits.rs similarity index 100% rename from willow/src/traits/verifier.rs rename to willow/src/protocol/verifier_traits.rs diff --git a/willow/src/willow_v1/client.rs b/willow/src/protocol/willow_v1_client.rs similarity index 99% rename from willow/src/willow_v1/client.rs rename to willow/src/protocol/willow_v1_client.rs index 6b4c9ba..1be282f 100644 --- a/willow/src/willow_v1/client.rs +++ b/willow/src/protocol/willow_v1_client.rs @@ -15,7 +15,6 @@ use client_traits::SecureAggregationClient; use kahe_traits::{HasKahe, KaheBase, KaheEncrypt, KaheKeygen, TrySecretKeyInto}; use messages::{ClientMessage, DecryptorPublicKey}; -use prng_traits::SecurePrng; use vahe_traits::{HasVahe, VaheBase, VerifiableEncrypt}; /// Lightweight client directly exposing KAHE/VAHE types. @@ -87,14 +86,14 @@ mod test { use ahe_traits::{AheBase, AheKeygen, PartialDec}; use googletest::prelude::container_eq; use googletest::{gtest, verify_eq, verify_that}; - use kahe_shell::ShellKahe; use kahe_traits::{KaheDecrypt, TrySecretKeyFrom}; use prng_traits::SecurePrng; + use shell_kahe::ShellKahe; use shell_testing_parameters::{make_ahe_config, make_kahe_config}; + use shell_vahe::ShellVahe; use single_thread_hkdf::SingleThreadHkdfPrng; use std::collections::HashMap; use testing_utils::generate_random_nonce; - use vahe_shell::ShellVahe; use vahe_traits::Recover; const CONTEXT_STRING: &[u8] = b"test_context_string"; diff --git a/willow/src/willow_v1/decryptor.rs b/willow/src/protocol/willow_v1_decryptor.rs similarity index 98% rename from willow/src/willow_v1/decryptor.rs rename to willow/src/protocol/willow_v1_decryptor.rs index 9301df0..9491909 100644 --- a/willow/src/willow_v1/decryptor.rs +++ b/willow/src/protocol/willow_v1_decryptor.rs @@ -134,11 +134,11 @@ mod tests { use ahe_traits::AheBase; use decryptor_traits::SecureAggregationDecryptor; use googletest::{gtest, verify_true}; - use parameters_shell::create_shell_ahe_config; use prng_traits::SecurePrng; use proto_serialization_traits::{FromProto, ToProto}; + use shell_parameters::create_shell_ahe_config; + use shell_vahe::ShellVahe; use single_thread_hkdf::SingleThreadHkdfPrng; - use vahe_shell::ShellVahe; const CONTEXT_STRING: &[u8] = b"testing_context_string"; diff --git a/willow/src/willow_v1/server.rs b/willow/src/protocol/willow_v1_server.rs similarity index 99% rename from willow/src/willow_v1/server.rs rename to willow/src/protocol/willow_v1_server.rs index 5ca4f61..e35a7ba 100644 --- a/willow/src/willow_v1/server.rs +++ b/willow/src/protocol/willow_v1_server.rs @@ -360,15 +360,15 @@ mod tests { use client_traits::SecureAggregationClient; use decryptor_traits::SecureAggregationDecryptor; use googletest::{gtest, verify_true}; - use kahe_shell::ShellKahe; - use parameters_shell::{create_shell_ahe_config, create_shell_kahe_config}; + use shell_kahe::ShellKahe; + use shell_parameters::{create_shell_ahe_config, create_shell_kahe_config}; use prng_traits::SecurePrng; use proto_serialization_traits::{FromProto, ToProto}; use server_traits::SecureAggregationServer; use single_thread_hkdf::SingleThreadHkdfPrng; use std::collections::HashMap; use testing_utils::{generate_aggregation_config, generate_random_nonce}; - use vahe_shell::ShellVahe; + use shell_vahe::ShellVahe; use verifier_traits::SecureAggregationVerifier; use willow_v1_client::WillowV1Client; use willow_v1_decryptor::{DecryptorState, WillowV1Decryptor}; diff --git a/willow/src/willow_v1/verifier.rs b/willow/src/protocol/willow_v1_verifier.rs similarity index 99% rename from willow/src/willow_v1/verifier.rs rename to willow/src/protocol/willow_v1_verifier.rs index f9006fa..aca7ff0 100644 --- a/willow/src/willow_v1/verifier.rs +++ b/willow/src/protocol/willow_v1_verifier.rs @@ -268,9 +268,9 @@ mod tests { use googletest::prelude::{ contains_substring, eq, err, gtest, verify_eq, verify_that, verify_true, }; - use kahe_shell::ShellKahe; use kahe_traits::KaheBase; - use parameters_shell::{create_shell_ahe_config, create_shell_kahe_config}; + use shell_kahe::ShellKahe; + use shell_parameters::{create_shell_ahe_config, create_shell_kahe_config}; use prng_traits::SecurePrng; use proto_serialization_traits::{FromProto, ToProto}; use server_traits::SecureAggregationServer; @@ -278,7 +278,7 @@ mod tests { use status_matchers_rs::status_is; use std::collections::HashMap; use testing_utils::{generate_aggregation_config, generate_random_nonce}; - use vahe_shell::ShellVahe; + use shell_vahe::ShellVahe; use willow_v1_client::WillowV1Client; use willow_v1_decryptor::{DecryptorState, WillowV1Decryptor}; use willow_v1_server::{ServerState, WillowV1Server}; diff --git a/willow/src/shell/BUILD b/willow/src/shell/BUILD deleted file mode 100644 index 8efd481..0000000 --- a/willow/src/shell/BUILD +++ /dev/null @@ -1,219 +0,0 @@ -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") - -package( - default_applicable_licenses = [ - ], - default_visibility = ["//visibility:public"], -) - -# AHE -rust_library( - name = "ahe_shell", - srcs = [ - "ahe.rs", - ], - crate_root = "ahe.rs", - deps = [ - ":single_thread_hkdf", - "@protobuf//rust:protobuf", - "//shell_wrapper:ahe", - "//shell_wrapper:ahe_cxx", # fixdeps: keep - "//shell_wrapper:shell_serialization", - "//shell_wrapper:shell_serialization_cxx", # fixdeps: keep - "//shell_wrapper:shell_types", - "//shell_wrapper:status", - "//willow/proto/shell:shell_ciphertexts_rust_proto", - "//willow/src/traits:ahe_traits", - "//willow/src/traits:prng_traits", - "//willow/src/traits:proto_serialization_traits", - ], -) - -rust_test( - name = "ahe_shell_test", - crate = ":ahe_shell", - deps = [ - ":ahe_shell", - ":single_thread_hkdf", - "@crate_index//:googletest", - "//shell_wrapper:status", - "//shell_wrapper:status_matchers_rs", - "//willow/src/testing_utils", - "//willow/src/testing_utils:shell_testing_parameters", - "//willow/src/traits:ahe_traits", - "//willow/src/traits:prng_traits", - ], -) - -# KAHE -rust_library( - name = "kahe_shell", - srcs = ["kahe.rs"], - deps = [ - ":single_thread_hkdf", - "@protobuf//rust:protobuf", - "//shell_wrapper:kahe", - "//shell_wrapper:shell_serialization", - "//shell_wrapper:shell_serialization_cxx", # fixdeps: keep - "//shell_wrapper:shell_types", - "//shell_wrapper:status", - "//willow/proto/shell:shell_ciphertexts_rust_proto", - "//willow/src/traits:kahe_traits", - "//willow/src/traits:prng_traits", - "//willow/src/traits:proto_serialization_traits", - ], -) - -rust_test( - name = "kahe_shell_test", - crate = ":kahe_shell", - deps = [ - ":kahe_shell", - "@crate_index//:googletest", - "//shell_wrapper:kahe", - "//shell_wrapper:status", - "//willow/src/testing_utils", - "//willow/src/testing_utils:shell_testing_parameters", - ], -) - -# Parameters of the underlying RLWE systems -rust_library( - name = "parameters_shell", - srcs = ["parameters.rs"], - crate_root = "parameters.rs", - deps = [ - ":ahe_shell", - ":kahe_shell", - ":shell_parameters_generation", - "//shell_wrapper:kahe", - "//shell_wrapper:status", - "//willow/src/api:aggregation_config", - ], -) - -# Utilities for parameters proto (e.g. conversion between rust structs and protos) -rust_library( - name = "shell_parameters_utils", - srcs = ["parameters_utils.rs"], - crate_root = "parameters_utils.rs", - deps = [ - ":kahe_shell", - "@protobuf//rust:protobuf", - "//shell_wrapper:kahe", - "//shell_wrapper:status", - "//willow/proto/shell:shell_parameters_rust_proto", - ], -) - -rust_test( - name = "shell_parameters_utils_test", - crate = ":shell_parameters_utils", - deps = [ - ":shell_parameters_utils", - "@crate_index//:googletest", - "@protobuf//rust:protobuf_gtest_matchers", - "//shell_wrapper:status", - ], -) - -# Parameter generation -rust_library( - name = "shell_parameters_generation", - srcs = ["parameters_generation.rs"], - crate_root = "parameters_generation.rs", - deps = [ - ":kahe_shell", - "//shell_wrapper:kahe", - "//shell_wrapper:status", - "//willow/src/api:aggregation_config", - ], -) - -rust_test( - name = "shell_parameters_generation_test", - crate = ":shell_parameters_generation", - deps = [ - ":shell_parameters_generation", - "@crate_index//:googletest", - "@protobuf//rust:protobuf_gtest_matchers", - "//shell_wrapper:status", - ], -) - -# PRNG -rust_library( - name = "single_thread_hkdf", - srcs = [ - "single_thread_hkdf.rs", - ], - deps = [ - "//shell_wrapper:single_thread_hkdf", - "//shell_wrapper:single_thread_hkdf_cxx", # fixdeps: keep - "//shell_wrapper:status", - "//willow/src/traits:prng_traits", - ], -) - -rust_test( - name = "single_thread_hkdf_test", - crate = ":single_thread_hkdf", - deps = [ - "@crate_index//:googletest", - ], -) - -rust_library( - name = "vahe_shell", - srcs = ["vahe.rs"], - deps = [ - ":ahe_shell", - ":single_thread_hkdf", - "@protobuf//rust:protobuf", - "@crate_index//:merlin", - "//shell_wrapper:ahe", - "//shell_wrapper:ahe_cxx", # fixdeps: keep - "//shell_wrapper:shell_types", - "//shell_wrapper:status", - "//willow/proto/zk:proofs_rust_proto", - "//willow/src/traits:ahe_traits", - "//willow/src/traits:proto_serialization_traits", - "//willow/src/traits:vahe_traits", - "//willow/src/traits:zk_traits", - "//willow/src/zk:rlwe_relation", - "//willow/src/zk:rlwe_relation_serialization", - ], -) - -rust_test( - name = "vahe_shell_test", - crate = ":vahe_shell", - deps = [ - ":vahe_shell", - "@crate_index//:googletest", - "@crate_index//:merlin", - "//shell_wrapper:status", - "//willow/src/testing_utils", - "//willow/src/testing_utils:shell_testing_parameters", - "//willow/src/traits:ahe_traits", - "//willow/src/traits:prng_traits", - "//willow/src/traits:proto_serialization_traits", - "//willow/src/traits:vahe_traits", - "//willow/src/traits:zk_traits", - "//willow/src/zk:rlwe_relation", - ], -) diff --git a/willow/src/testing_utils/BUILD b/willow/src/testing_utils/BUILD index 51d364c..4a19807 100644 --- a/willow/src/testing_utils/BUILD +++ b/willow/src/testing_utils/BUILD @@ -29,7 +29,7 @@ rust_library( ], deps = [ "//shell_wrapper:status", - "//willow/src/traits:prng_traits", + "//willow/src/crypto:prng_traits", ], ) @@ -50,11 +50,11 @@ rust_library( "//shell_wrapper:kahe", "//shell_wrapper:status", "//willow/src/api:aggregation_config", - "//willow/src/shell:ahe_shell", - "//willow/src/shell:kahe_shell", - "//willow/src/shell:shell_parameters_generation", - "//willow/src/traits:ahe_traits", - "//willow/src/traits:kahe_traits", + "//willow/src/crypto:ahe_traits", + "//willow/src/crypto:kahe_traits", + "//willow/src/crypto:shell_ahe", + "//willow/src/crypto:shell_kahe", + "//willow/src/crypto:shell_parameters_generation", ], ) @@ -70,15 +70,15 @@ rust_library( "@crate_index//:rand", "//shell_wrapper:status", "//willow/src/api:aggregation_config", - "//willow/src/shell:kahe_shell", - "//willow/src/shell:single_thread_hkdf", - "//willow/src/shell:vahe_shell", - "//willow/src/traits:ahe_traits", - "//willow/src/traits:kahe_traits", - "//willow/src/traits:messages", - "//willow/src/traits:prng_traits", - "//willow/src/traits:vahe_traits", - "//willow/src/willow_v1:willow_v1_client", + "//willow/src/crypto:ahe_traits", + "//willow/src/crypto:kahe_traits", + "//willow/src/crypto:prng_traits", + "//willow/src/crypto:shell_kahe", + "//willow/src/crypto:shell_vahe", + "//willow/src/crypto:single_thread_hkdf", + "//willow/src/crypto:vahe_traits", + "//willow/src/protocol:messages", + "//willow/src/protocol:willow_v1_client", ], ) diff --git a/willow/src/testing_utils/shell_testing_parameters.rs b/willow/src/testing_utils/shell_testing_parameters.rs index 2feb9f6..30728bb 100644 --- a/willow/src/testing_utils/shell_testing_parameters.rs +++ b/willow/src/testing_utils/shell_testing_parameters.rs @@ -13,9 +13,9 @@ // limitations under the License. use aggregation_config::AggregationConfig; -use ahe_shell::ShellAheConfig; use kahe::PackedVectorConfig; -use kahe_shell::ShellKaheConfig; +use shell_ahe::ShellAheConfig; +use shell_kahe::ShellKaheConfig; use shell_parameters_generation::{divide_and_roundup, generate_packing_config}; use std::collections::HashMap; diff --git a/willow/src/testing_utils/testing_utils.rs b/willow/src/testing_utils/testing_utils.rs index 40b8edb..eb22fde 100644 --- a/willow/src/testing_utils/testing_utils.rs +++ b/willow/src/testing_utils/testing_utils.rs @@ -14,11 +14,11 @@ use aggregation_config::AggregationConfig; use ahe_traits::{AheBase, PartialDec}; -use kahe_shell::ShellKahe; use kahe_traits::KaheBase; use rand::Rng; +use shell_kahe::ShellKahe; +use shell_vahe::ShellVahe; use std::collections::HashMap; -use vahe_shell::ShellVahe; use vahe_traits::Recover; pub fn generate_random_nonce() -> Vec { diff --git a/willow/src/traits/BUILD b/willow/src/traits/BUILD deleted file mode 100644 index 6b1503a..0000000 --- a/willow/src/traits/BUILD +++ /dev/null @@ -1,160 +0,0 @@ -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -load("@rules_rust//rust:defs.bzl", "rust_library") - -package( - default_applicable_licenses = [ - ], - default_visibility = ["//visibility:public"], -) - -# Cryptographic primitives traits: PRNG, AHE, KAHE. - -rust_library( - name = "proto_serialization_traits", - srcs = [ - "proto_serialization.rs", - ], - deps = [ - "@protobuf//rust:protobuf", - "//shell_wrapper:status", - ], -) - -rust_library( - name = "prng_traits", - srcs = [ - "prng.rs", - ], - deps = [ - "//shell_wrapper:status", - ], -) - -rust_library( - name = "kahe_traits", - srcs = [ - "kahe.rs", - ], - deps = [ - ":prng_traits", - "//shell_wrapper:status", - ], -) - -rust_library( - name = "ahe_traits", - srcs = [ - "ahe.rs", - ], - deps = [ - ":prng_traits", - "//shell_wrapper:status", - ], -) - -rust_library( - name = "vahe_traits", - srcs = [ - "vahe.rs", - ], - deps = [ - ":ahe_traits", - "//shell_wrapper:status", - ], -) - -# Protocol level message types: Client, Server, Decryptor. -rust_library( - name = "messages", - srcs = [ - "messages.rs", - ], - deps = [ - ":ahe_traits", - ":kahe_traits", - ":proto_serialization_traits", - ":vahe_traits", - "@protobuf//rust:protobuf", - "//shell_wrapper:status", - "//willow/proto/shell:shell_ciphertexts_rust_proto", - "//willow/proto/willow:messages_rust_proto", - "//willow/proto/zk:proofs_rust_proto", - ], -) - -rust_library( - name = "client_traits", - srcs = [ - "client.rs", - ], - deps = [ - ":kahe_traits", - ":messages", - ":vahe_traits", - "//shell_wrapper:status", - ], -) - -rust_library( - name = "server_traits", - srcs = [ - "server.rs", - ], - deps = [ - ":kahe_traits", - ":messages", - ":vahe_traits", - "//shell_wrapper:status", - ], -) - -rust_library( - name = "decryptor_traits", - srcs = [ - "decryptor.rs", - ], - deps = [ - ":messages", - ":vahe_traits", - "//shell_wrapper:status", - ], -) - -rust_library( - name = "verifier_traits", - srcs = [ - "verifier.rs", - ], - deps = [ - ":messages", - ":vahe_traits", - "//shell_wrapper:status", - ], -) - -rust_library( - name = "zk_traits", - srcs = [ - "zk.rs", - ], - deps = [ - ":ahe_traits", - "@crate_index//:curve25519-dalek", - "@crate_index//:merlin", - "//shell_wrapper:shell_types", - "//shell_wrapper:status", - ], -) diff --git a/willow/src/willow_v1/BUILD b/willow/src/willow_v1/BUILD deleted file mode 100644 index c7b015e..0000000 --- a/willow/src/willow_v1/BUILD +++ /dev/null @@ -1,172 +0,0 @@ -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") - -package( - default_applicable_licenses = [ - ], - default_visibility = ["//visibility:public"], -) - -rust_library( - name = "willow_v1_client", - srcs = [ - "client.rs", - ], - deps = [ - "//shell_wrapper:status", - "//willow/src/traits:ahe_traits", - "//willow/src/traits:client_traits", - "//willow/src/traits:kahe_traits", - "//willow/src/traits:messages", - "//willow/src/traits:prng_traits", - "//willow/src/traits:vahe_traits", - ], -) - -rust_test( - name = "willow_v1_client_test", - crate = ":willow_v1_client", - deps = [ - "@crate_index//:googletest", - "//willow/src/api:aggregation_config", - "//willow/src/shell:kahe_shell", - "//willow/src/shell:single_thread_hkdf", - "//willow/src/shell:vahe_shell", - "//willow/src/testing_utils", - "//willow/src/testing_utils:shell_testing_parameters", - "//willow/src/traits:prng_traits", - ], -) - -rust_test( - name = "willow_v1_decryptor_test", - crate = ":willow_v1_decryptor", - deps = [ - "@crate_index//:googletest", - "//willow/src/shell:parameters_shell", - "//willow/src/shell:single_thread_hkdf", - "//willow/src/shell:vahe_shell", - "//willow/src/traits:ahe_traits", - "//willow/src/traits:decryptor_traits", - "//willow/src/traits:prng_traits", - "//willow/src/traits:proto_serialization_traits", - ], -) - -rust_library( - name = "willow_v1_decryptor", - srcs = [ - "decryptor.rs", - ], - deps = [ - "@protobuf//rust:protobuf", - "//shell_wrapper:status", - "//willow/proto/shell:shell_ciphertexts_rust_proto", - "//willow/proto/willow:messages_rust_proto", - "//willow/src/traits:ahe_traits", - "//willow/src/traits:decryptor_traits", - "//willow/src/traits:messages", - "//willow/src/traits:proto_serialization_traits", - "//willow/src/traits:vahe_traits", - ], -) - -rust_test( - name = "willow_v1_server_test", - crate = ":willow_v1_server", - deps = [ - ":willow_v1_client", - ":willow_v1_decryptor", - ":willow_v1_verifier", - "@crate_index//:googletest", - "//willow/src/shell:kahe_shell", - "//willow/src/shell:parameters_shell", - "//willow/src/shell:single_thread_hkdf", - "//willow/src/shell:vahe_shell", - "//willow/src/testing_utils", - "//willow/src/traits:ahe_traits", - "//willow/src/traits:client_traits", - "//willow/src/traits:decryptor_traits", - "//willow/src/traits:prng_traits", - "//willow/src/traits:proto_serialization_traits", - "//willow/src/traits:server_traits", - "//willow/src/traits:verifier_traits", - ], -) - -rust_library( - name = "willow_v1_server", - srcs = [ - "server.rs", - ], - deps = [ - "@protobuf//rust:protobuf", - "//shell_wrapper:status", - "//willow/proto/shell:shell_ciphertexts_rust_proto", - "//willow/proto/willow:messages_rust_proto", - "//willow/src/traits:ahe_traits", - "//willow/src/traits:kahe_traits", - "//willow/src/traits:messages", - "//willow/src/traits:proto_serialization_traits", - "//willow/src/traits:server_traits", - "//willow/src/traits:vahe_traits", - ], -) - -rust_library( - name = "willow_v1_verifier", - srcs = [ - "verifier.rs", - ], - deps = [ - "@protobuf//rust:protobuf", - "//shell_wrapper:status", - "//willow/proto/shell:shell_ciphertexts_rust_proto", - "//willow/proto/willow:messages_rust_proto", - "//willow/src/traits:ahe_traits", - "//willow/src/traits:kahe_traits", - "//willow/src/traits:messages", - "//willow/src/traits:proto_serialization_traits", - "//willow/src/traits:vahe_traits", - "//willow/src/traits:verifier_traits", - ], -) - -rust_test( - name = "willow_v1_verifier_test", - crate = ":willow_v1_verifier", - deps = [ - ":willow_v1_client", - ":willow_v1_decryptor", - ":willow_v1_server", - "@crate_index//:googletest", - "//shell_wrapper:status_matchers_rs", - "//willow/src/shell:kahe_shell", - "//willow/src/shell:parameters_shell", - "//willow/src/shell:single_thread_hkdf", - "//willow/src/shell:vahe_shell", - "//willow/src/testing_utils", - "//willow/src/testing_utils:shell_testing_parameters", - "//willow/src/traits:ahe_traits", - "//willow/src/traits:client_traits", - "//willow/src/traits:decryptor_traits", - "//willow/src/traits:kahe_traits", - "//willow/src/traits:prng_traits", - "//willow/src/traits:proto_serialization_traits", - "//willow/src/traits:server_traits", - "//willow/src/traits:vahe_traits", - ], -) diff --git a/willow/src/zk/BUILD b/willow/src/zk/BUILD deleted file mode 100644 index 4eb76ab..0000000 --- a/willow/src/zk/BUILD +++ /dev/null @@ -1,164 +0,0 @@ -# Copyright 2025 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") - -package( - default_applicable_licenses = [ - ], - default_visibility = ["//:internal"], -) - -rust_library( - name = "linear_innerproduct", - srcs = ["linear_ip.rs"], - deps = [ - "@crate_index//:curve25519-dalek", - "@crate_index//:merlin", - "@crate_index//:rand", - "@crate_index//:sha3", - "@crate_index//:thiserror", - "//shell_wrapper:status", - "//willow/src/traits:prng_traits", - "//willow/src/traits:zk_traits", - ], -) - -rust_test( - name = "linear_innerproduct_test", - crate = ":linear_innerproduct", - deps = [ - "@crate_index//:googletest", - "//shell_wrapper:status_matchers_rs", - ], -) - -rust_library( - name = "linear_ip_serialization", - srcs = ["linear_ip_serialization.rs"], - deps = [ - ":linear_innerproduct", - "@protobuf//rust:protobuf", - "@crate_index//:curve25519-dalek", - "//shell_wrapper:status", - "//willow/proto/zk:proofs_rust_proto", - ], -) - -rust_test( - name = "linear_ip_serialization_test", - crate = ":linear_ip_serialization", - deps = [ - ":linear_innerproduct", - "@crate_index//:googletest", - "@crate_index//:curve25519-dalek", - "@crate_index//:merlin", - "@crate_index//:rand", - "//willow/src/traits:zk_traits", - ], -) - -# quadratic inner product zero-knowledge proof. -rust_library( - name = "quadratic_innerproduct", - testonly = 1, - srcs = ["quadratic_ip.rs"], - deps = [ - "@crate_index//:curve25519-dalek", - "@crate_index//:merlin", - "@crate_index//:rand", - "@crate_index//:sha3", - "@crate_index//:thiserror", - "//shell_wrapper:status", - "//willow/src/traits:prng_traits", - "//willow/src/traits:zk_traits", - ], -) - -rust_test( - name = "quadratic_innerproduct_test", - crate = ":quadratic_innerproduct", - deps = [ - "@crate_index//:googletest", - "//shell_wrapper:status_matchers_rs", - ], -) - -# RLWE relation zero-knowledge proof. -rust_library( - name = "rlwe_relation", - srcs = ["rlwe_relation.rs"], - deps = [ - ":linear_innerproduct", - "@crate_index//:curve25519-dalek", - "@crate_index//:merlin", - "@crate_index//:rand", - "//shell_wrapper:shell_types", - "//shell_wrapper:status", - "//willow/src/traits:zk_traits", - ], -) - -rust_test( - name = "rlwe_relation_test", - crate = ":rlwe_relation", - deps = [ - "@crate_index//:googletest", - "@crate_index//:sha3", - "//shell_wrapper:ahe", - "//shell_wrapper:ahe_cxx", # fixdeps: keep - "//shell_wrapper:single_thread_hkdf", - "//shell_wrapper:single_thread_hkdf_cxx", - "//shell_wrapper:status_matchers_rs", - "//willow/src/shell:ahe_shell", - "//willow/src/testing_utils:shell_testing_parameters", - ], -) - -rust_library( - name = "rlwe_relation_serialization", - srcs = ["rlwe_relation_serialization.rs"], - deps = [ - ":linear_innerproduct", - ":linear_ip_serialization", - ":rlwe_relation", - "@protobuf//rust:protobuf", - "@crate_index//:curve25519-dalek", - "//shell_wrapper:status", - "//willow/proto/zk:proofs_rust_proto", - ], -) - -rust_test( - name = "rlwe_relation_serialization_test", - crate = ":rlwe_relation_serialization", - deps = [ - ":rlwe_relation_serialization", - "@crate_index//:googletest", - "@protobuf//rust:protobuf", - "@crate_index//:curve25519-dalek", - "@crate_index//:merlin", - "@crate_index//:sha3", - "//shell_wrapper:ahe", - "//shell_wrapper:ahe_cxx", # fixdeps: keep - "//shell_wrapper:shell_types", - "//shell_wrapper:single_thread_hkdf", - "//shell_wrapper:single_thread_hkdf_cxx", - "//shell_wrapper:status_matchers_rs", - "//willow/proto/zk:proofs_rust_proto", - "//willow/src/shell:ahe_shell", - "//willow/src/testing_utils:shell_testing_parameters", - "//willow/src/traits:zk_traits", - ], -) diff --git a/willow/tests/BUILD b/willow/tests/BUILD index 7e0ad48..97765e6 100644 --- a/willow/tests/BUILD +++ b/willow/tests/BUILD @@ -27,25 +27,26 @@ rust_test( "@crate_index//:googletest", "//shell_wrapper:status", "//shell_wrapper:status_matchers_rs", - "//willow/src/shell:ahe_shell", - "//willow/src/shell:kahe_shell", - "//willow/src/shell:parameters_shell", - "//willow/src/shell:single_thread_hkdf", - "//willow/src/shell:vahe_shell", + "//willow/src/api:proto_serialization_traits", + "//willow/src/crypto:ahe_traits", + "//willow/src/crypto:kahe_traits", + "//willow/src/crypto:prng_traits", + "//willow/src/crypto:shell_ahe", + "//willow/src/crypto:shell_kahe", + "//willow/src/crypto:shell_parameters", + "//willow/src/crypto:shell_vahe", + "//willow/src/crypto:single_thread_hkdf", + "//willow/src/crypto:vahe_traits", + "//willow/src/protocol:client_traits", + "//willow/src/protocol:decryptor_traits", + "//willow/src/protocol:messages", + "//willow/src/protocol:server_traits", + "//willow/src/protocol:verifier_traits", + "//willow/src/protocol:willow_v1_client", + "//willow/src/protocol:willow_v1_decryptor", + "//willow/src/protocol:willow_v1_server", + "//willow/src/protocol:willow_v1_verifier", "//willow/src/testing_utils", - "//willow/src/traits:ahe_traits", - "//willow/src/traits:client_traits", - "//willow/src/traits:decryptor_traits", - "//willow/src/traits:kahe_traits", - "//willow/src/traits:messages", - "//willow/src/traits:prng_traits", - "//willow/src/traits:proto_serialization_traits", - "//willow/src/traits:server_traits", - "//willow/src/traits:vahe_traits", - "//willow/src/traits:verifier_traits", - "//willow/src/willow_v1:willow_v1_client", - "//willow/src/willow_v1:willow_v1_decryptor", - "//willow/src/willow_v1:willow_v1_server", - "//willow/src/willow_v1:willow_v1_verifier", + "//willow/src/testing_utils:shell_testing_parameters", ], ) diff --git a/willow/tests/willow_v1_shell.rs b/willow/tests/willow_v1_shell.rs index 9e497fd..4a9c88f 100644 --- a/willow/tests/willow_v1_shell.rs +++ b/willow/tests/willow_v1_shell.rs @@ -17,16 +17,18 @@ use client_traits::SecureAggregationClient; use decryptor_traits::SecureAggregationDecryptor; use googletest::prelude::container_eq; use googletest::{gtest, verify_eq, verify_that}; -use kahe_shell::ShellKahe; use kahe_traits::KaheBase; use messages::{ CiphertextContribution, ClientMessage, DecryptionRequestContribution, DecryptorPublicKeyShare, PartialDecryptionRequest, PartialDecryptionResponse, }; -use parameters_shell::{create_shell_ahe_config, create_shell_kahe_config}; use prng_traits::SecurePrng; use proto_serialization_traits::{FromProto, ToProto}; use server_traits::SecureAggregationServer; +use shell_kahe::ShellKahe; +use shell_parameters::{create_shell_ahe_config, create_shell_kahe_config}; +use shell_testing_parameters::{make_ahe_config, make_kahe_config}; +use shell_vahe::ShellVahe; use single_thread_hkdf::SingleThreadHkdfPrng; use status::StatusErrorCode; use status_matchers_rs::status_is; @@ -34,7 +36,6 @@ use std::collections::HashMap; use testing_utils::{ generate_aggregation_config, generate_random_nonce, generate_random_unsigned_vector, }; -use vahe_shell::ShellVahe; use verifier_traits::SecureAggregationVerifier; use willow_v1_client::WillowV1Client; use willow_v1_decryptor::{DecryptorState, WillowV1Decryptor};