From 8d909ce67ad9f3463f4bcdff636a91a35c9c3a97 Mon Sep 17 00:00:00 2001 From: Phi Hung Le Date: Tue, 19 Mar 2024 03:27:06 +0000 Subject: [PATCH 1/5] Add jni call to generate secret shares. --- src/main/cc/any_sketch/crypto/BUILD.bazel | 29 ------ src/main/cc/crypto/BUILD.bazel | 20 ++++ .../cc/{any_sketch => }/crypto/shuffle.cc | 4 +- src/main/cc/{any_sketch => }/crypto/shuffle.h | 10 +- src/main/cc/frequency_count/BUILD.bazel | 27 ++++++ .../secret_share_generator.cc | 6 +- .../secret_share_generator.h | 16 ++-- .../secret_share_generator_adapter.cc | 47 ++++++++++ .../secret_share_generator_adapter.h | 35 +++++++ src/main/cc/math/BUILD.bazel | 2 +- .../math/open_ssl_uniform_random_generator.h | 4 +- src/main/proto/wfa/any_sketch/BUILD.bazel | 22 ----- .../proto/wfa/frequency_count/BUILD.bazel | 42 +++++++++ .../secret_share.proto | 4 +- .../share_shuffle_methods.proto | 29 ++++++ .../share_shuffle_sketch.proto | 4 +- src/test/cc/any_sketch/crypto/BUILD.bazel | 30 ------ src/test/cc/crypto/BUILD.bazel | 13 +++ .../{any_sketch => }/crypto/shuffle_test.cc | 8 +- src/test/cc/frequency_count/BUILD.bazel | 30 ++++++ .../secret_share_generator_adapter_test.cc | 94 +++++++++++++++++++ .../secret_share_generator_test.cc | 6 +- 22 files changed, 369 insertions(+), 113 deletions(-) create mode 100644 src/main/cc/crypto/BUILD.bazel rename src/main/cc/{any_sketch => }/crypto/shuffle.cc (95%) rename src/main/cc/{any_sketch => }/crypto/shuffle.h (80%) create mode 100644 src/main/cc/frequency_count/BUILD.bazel rename src/main/cc/{any_sketch/crypto => frequency_count}/secret_share_generator.cc (96%) rename src/main/cc/{any_sketch/crypto => frequency_count}/secret_share_generator.h (67%) create mode 100644 src/main/cc/frequency_count/secret_share_generator_adapter.cc create mode 100644 src/main/cc/frequency_count/secret_share_generator_adapter.h create mode 100644 src/main/proto/wfa/frequency_count/BUILD.bazel rename src/main/proto/wfa/{any_sketch => frequency_count}/secret_share.proto (93%) create mode 100644 src/main/proto/wfa/frequency_count/share_shuffle_methods.proto rename src/main/proto/wfa/{any_sketch => frequency_count}/share_shuffle_sketch.proto (93%) create mode 100644 src/test/cc/crypto/BUILD.bazel rename src/test/cc/{any_sketch => }/crypto/shuffle_test.cc (96%) create mode 100644 src/test/cc/frequency_count/BUILD.bazel create mode 100644 src/test/cc/frequency_count/secret_share_generator_adapter_test.cc rename src/test/cc/{any_sketch/crypto => frequency_count}/secret_share_generator_test.cc (97%) diff --git a/src/main/cc/any_sketch/crypto/BUILD.bazel b/src/main/cc/any_sketch/crypto/BUILD.bazel index 90813e4..99476b8 100644 --- a/src/main/cc/any_sketch/crypto/BUILD.bazel +++ b/src/main/cc/any_sketch/crypto/BUILD.bazel @@ -21,18 +21,6 @@ cc_library( ], ) -cc_library( - name = "secret_share_generator", - srcs = [":secret_share_generator.cc"], - hdrs = [":secret_share_generator.h"], - strip_include_prefix = _INCLUDE_PREFIX, - deps = [ - "//src/main/cc/math:open_ssl_uniform_random_generator", - "//src/main/proto/wfa/any_sketch:secret_share_cc_proto", - "@wfa_common_cpp//src/main/cc/common_cpp/macros", - ], -) - cc_library( name = "sketch_encrypter_adapter", srcs = [":sketch_encrypter_adapter.cc"], @@ -55,20 +43,3 @@ cc_binary( "@com_google_absl//absl/strings", ], ) - -cc_library( - name = "shuffle", - srcs = [ - "shuffle.cc", - ], - hdrs = [ - "shuffle.h", - ], - strip_include_prefix = _INCLUDE_PREFIX, - deps = [ - "//src/main/cc/math:open_ssl_uniform_random_generator", - "//src/main/proto/wfa/any_sketch:secret_share_cc_proto", - "@com_google_absl//absl/status", - "@wfa_common_cpp//src/main/cc/common_cpp/macros", - ], -) diff --git a/src/main/cc/crypto/BUILD.bazel b/src/main/cc/crypto/BUILD.bazel new file mode 100644 index 0000000..3a9648a --- /dev/null +++ b/src/main/cc/crypto/BUILD.bazel @@ -0,0 +1,20 @@ +package(default_visibility = ["//visibility:public"]) + +_INCLUDE_PREFIX = "/src/main/cc/" + +cc_library( + name = "shuffle", + srcs = [ + "shuffle.cc", + ], + hdrs = [ + "shuffle.h", + ], + strip_include_prefix = _INCLUDE_PREFIX, + deps = [ + "//src/main/cc/math:open_ssl_uniform_random_generator", + "//src/main/proto/wfa/frequency_count:secret_share_cc_proto", + "@com_google_absl//absl/status", + "@wfa_common_cpp//src/main/cc/common_cpp/macros", + ], +) diff --git a/src/main/cc/any_sketch/crypto/shuffle.cc b/src/main/cc/crypto/shuffle.cc similarity index 95% rename from src/main/cc/any_sketch/crypto/shuffle.cc rename to src/main/cc/crypto/shuffle.cc index 986081c..3e7f9cd 100644 --- a/src/main/cc/any_sketch/crypto/shuffle.cc +++ b/src/main/cc/crypto/shuffle.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "any_sketch/crypto/shuffle.h" +#include "crypto/shuffle.h" #include @@ -23,7 +23,7 @@ namespace wfa::measurement::common::crypto { absl::Status SecureShuffleWithSeed(std::vector& data, - const any_sketch::PrngSeed& seed) { + const frequency_count::PrngSeed& seed) { // Does nothing if the input is empty or has size 1. if (data.size() <= 1) { return absl::OkStatus(); diff --git a/src/main/cc/any_sketch/crypto/shuffle.h b/src/main/cc/crypto/shuffle.h similarity index 80% rename from src/main/cc/any_sketch/crypto/shuffle.h rename to src/main/cc/crypto/shuffle.h index d447831..4d77d9c 100644 --- a/src/main/cc/any_sketch/crypto/shuffle.h +++ b/src/main/cc/crypto/shuffle.h @@ -12,15 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef SRC_MAIN_CC_ANY_SKETCH_CRYPTO_SHUFFLE_H_ -#define SRC_MAIN_CC_ANY_SKETCH_CRYPTO_SHUFFLE_H_ +#ifndef SRC_MAIN_CC_CRYPTO_SHUFFLE_H_ +#define SRC_MAIN_CC_CRYPTO_SHUFFLE_H_ #include #include #include #include "absl/status/status.h" -#include "wfa/any_sketch/secret_share.pb.h" +#include "wfa/frequency_count/secret_share.pb.h" namespace wfa::measurement::common::crypto { @@ -30,8 +30,8 @@ namespace wfa::measurement::common::crypto { // Draws a random value j in the range [i; n-1] // Swaps data[i] and data[j] absl::Status SecureShuffleWithSeed(std::vector& data, - const any_sketch::PrngSeed& seed); + const frequency_count::PrngSeed& seed); } // namespace wfa::measurement::common::crypto -#endif // SRC_MAIN_CC_ANY_SKETCH_CRYPTO_SHUFFLE_H_ +#endif // SRC_MAIN_CC_CRYPTO_SHUFFLE_H_ diff --git a/src/main/cc/frequency_count/BUILD.bazel b/src/main/cc/frequency_count/BUILD.bazel new file mode 100644 index 0000000..a9735d6 --- /dev/null +++ b/src/main/cc/frequency_count/BUILD.bazel @@ -0,0 +1,27 @@ +package(default_visibility = ["//visibility:public"]) + +_INCLUDE_PREFIX = "/src/main/cc/" + +cc_library( + name = "secret_share_generator", + srcs = [":secret_share_generator.cc"], + hdrs = [":secret_share_generator.h"], + strip_include_prefix = _INCLUDE_PREFIX, + deps = [ + "//src/main/cc/math:open_ssl_uniform_random_generator", + "//src/main/proto/wfa/frequency_count:secret_share_cc_proto", + "@wfa_common_cpp//src/main/cc/common_cpp/macros", + ], +) + +cc_library( + name = "secret_share_generator_adapter", + srcs = [":secret_share_generator_adapter.cc"], + hdrs = [":secret_share_generator_adapter.h"], + strip_include_prefix = _INCLUDE_PREFIX, + deps = [ + ":secret_share_generator", + "//src/main/proto/wfa/frequency_count:secret_share_cc_proto", + "//src/main/proto/wfa/frequency_count:share_shuffle_methods_cc_proto", + ], +) diff --git a/src/main/cc/any_sketch/crypto/secret_share_generator.cc b/src/main/cc/frequency_count/secret_share_generator.cc similarity index 96% rename from src/main/cc/any_sketch/crypto/secret_share_generator.cc rename to src/main/cc/frequency_count/secret_share_generator.cc index 2a39082..d3f84b5 100644 --- a/src/main/cc/any_sketch/crypto/secret_share_generator.cc +++ b/src/main/cc/frequency_count/secret_share_generator.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "any_sketch/crypto/secret_share_generator.h" +#include "frequency_count/secret_share_generator.h" #include #include @@ -22,7 +22,7 @@ #include "common_cpp/macros/macros.h" #include "math/open_ssl_uniform_random_generator.h" -namespace wfa::any_sketch::crypto { +namespace wfa::frequency_count { using wfa::math::kBytesPerAes256Iv; using wfa::math::kBytesPerAes256Key; @@ -101,4 +101,4 @@ absl::StatusOr GenerateSecretShares( return secret_share; } -} // namespace wfa::any_sketch::crypto +} // namespace wfa::frequency_count diff --git a/src/main/cc/any_sketch/crypto/secret_share_generator.h b/src/main/cc/frequency_count/secret_share_generator.h similarity index 67% rename from src/main/cc/any_sketch/crypto/secret_share_generator.h rename to src/main/cc/frequency_count/secret_share_generator.h index d0a4377..4708b0f 100644 --- a/src/main/cc/any_sketch/crypto/secret_share_generator.h +++ b/src/main/cc/frequency_count/secret_share_generator.h @@ -12,23 +12,23 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef SRC_MAIN_CC_ANY_SKETCH_CRYPTO_SECRET_SHARE_GENERATOR_H_ -#define SRC_MAIN_CC_ANY_SKETCH_CRYPTO_SECRET_SHARE_GENERATOR_H_ +#ifndef SRC_MAIN_CC_FREQUENCY_COUNT_SECRET_SHARE_GENERATOR_H_ +#define SRC_MAIN_CC_FREQUENCY_COUNT_SECRET_SHARE_GENERATOR_H_ #include #include "absl/status/statusor.h" -#include "wfa/any_sketch/secret_share.pb.h" +#include "wfa/frequency_count/secret_share.pb.h" -using wfa::any_sketch::SecretShare; -using wfa::any_sketch::SecretShareParameter; +using wfa::frequency_count::SecretShare; +using wfa::frequency_count::SecretShareParameter; -namespace wfa::any_sketch::crypto { +namespace wfa::frequency_count { absl::StatusOr GenerateSecretShares( const SecretShareParameter& secret_share_parameter, const absl::Span input); -} // namespace wfa::any_sketch::crypto +} // namespace wfa::frequency_count -#endif // SRC_MAIN_CC_ANY_SKETCH_CRYPTO_SECRET_SHARE_GENERATOR_H_ +#endif // SRC_MAIN_CC_FREQUENCY_COUNT_SECRET_SHARE_GENERATOR_H_ diff --git a/src/main/cc/frequency_count/secret_share_generator_adapter.cc b/src/main/cc/frequency_count/secret_share_generator_adapter.cc new file mode 100644 index 0000000..260013a --- /dev/null +++ b/src/main/cc/frequency_count/secret_share_generator_adapter.cc @@ -0,0 +1,47 @@ +// Copyright 2024 The Cross-Media Measurement Authors +// +// 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. + +#include "frequency_count/secret_share_generator_adapter.h" + +#include +#include + +#include "absl/memory/memory.h" +#include "absl/status/status.h" +#include "absl/status/statusor.h" +#include "common_cpp/macros/macros.h" +#include "frequency_count/secret_share_generator.h" +#include "wfa/frequency_count/secret_share.pb.h" +#include "wfa/frequency_count/share_shuffle_methods.pb.h" + +namespace wfa::frequency_count { + +absl::StatusOr SecretShareFrequencyVector( + const std::string& serialized_request) { + ShareShuffleGeneratorRequest request_proto; + if (!request_proto.ParseFromString(serialized_request)) { + return absl::InvalidArgumentError( + "failed to parse the ShareShuffleGeneratorRequest proto."); + } + std::vector frequency_vector = std::vector( + request_proto.data().begin(), request_proto.data().end()); + SecretShareParameter secret_share_param; + secret_share_param.set_modulus(request_proto.ring_modulus()); + + ASSIGN_OR_RETURN(auto secret_share, + GenerateSecretShares(secret_share_param, frequency_vector)); + return secret_share.SerializeAsString(); +} + +} // namespace wfa::frequency_count diff --git a/src/main/cc/frequency_count/secret_share_generator_adapter.h b/src/main/cc/frequency_count/secret_share_generator_adapter.h new file mode 100644 index 0000000..8b1a973 --- /dev/null +++ b/src/main/cc/frequency_count/secret_share_generator_adapter.h @@ -0,0 +1,35 @@ +// Copyright 2024 The Cross-Media Measurement Authors +// +// 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. + +#ifndef SRC_MAIN_CC_FREQUENCY_COUNT_SECRET_SHARE_GENERATOR_ADAPTER_H_ +#define SRC_MAIN_CC_FREQUENCY_COUNT_SECRET_SHARE_GENERATOR_ADAPTER_H_ + +#include + +#include "absl/status/statusor.h" + +// Wrapper methods used to generate the swig/JNI Java classes. +// The only functionality of these methods are converting between proto messages +// and their corresponding serialized strings, and then calling the function +// GenerateSecretShares to secret share a frequency vector. +// Note: this method shouldn't be used in any c++ binary, use +// GenerateSecretShares directly. +namespace wfa::frequency_count { + +absl::StatusOr SecretShareFrequencyVector( + const std::string& serialized_request); + +} // namespace wfa::frequency_count + +#endif // SRC_MAIN_CC_FREQUENCY_COUNT_SECRET_SHARE_GENERATOR_ADAPTER_H_ \ No newline at end of file diff --git a/src/main/cc/math/BUILD.bazel b/src/main/cc/math/BUILD.bazel index 2baf6e3..81d7eb5 100644 --- a/src/main/cc/math/BUILD.bazel +++ b/src/main/cc/math/BUILD.bazel @@ -35,7 +35,7 @@ cc_library( strip_include_prefix = _INCLUDE_PREFIX, deps = [ ":uniform_pseudorandom_generator", - "//src/main/proto/wfa/any_sketch:secret_share_cc_proto", + "//src/main/proto/wfa/frequency_count:secret_share_cc_proto", "@boringssl//:ssl", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", diff --git a/src/main/cc/math/open_ssl_uniform_random_generator.h b/src/main/cc/math/open_ssl_uniform_random_generator.h index 84a914d..8d453f7 100644 --- a/src/main/cc/math/open_ssl_uniform_random_generator.h +++ b/src/main/cc/math/open_ssl_uniform_random_generator.h @@ -28,11 +28,11 @@ #include "absl/status/statusor.h" #include "absl/strings/substitute.h" #include "math/uniform_pseudorandom_generator.h" -#include "wfa/any_sketch/secret_share.pb.h" +#include "wfa/frequency_count/secret_share.pb.h" namespace wfa::math { -using any_sketch::PrngSeed; +using frequency_count::PrngSeed; // Key length for EVP_aes_256_ctr. // See https://www.openssl.org/docs/man1.1.1/man3/EVP_aes_256_ctr.html diff --git a/src/main/proto/wfa/any_sketch/BUILD.bazel b/src/main/proto/wfa/any_sketch/BUILD.bazel index 4591a27..25aa93f 100644 --- a/src/main/proto/wfa/any_sketch/BUILD.bazel +++ b/src/main/proto/wfa/any_sketch/BUILD.bazel @@ -26,25 +26,3 @@ cc_proto_library( name = "differential_privacy_cc_proto", deps = [":differential_privacy_proto"], ) - -proto_library( - name = "secret_share_proto", - srcs = ["secret_share.proto"], - strip_import_prefix = IMPORT_PREFIX, -) - -cc_proto_library( - name = "secret_share_cc_proto", - deps = [":secret_share_proto"], -) - -proto_library( - name = "share_shuffle_sketch_proto", - srcs = ["share_shuffle_sketch.proto"], - strip_import_prefix = IMPORT_PREFIX, -) - -cc_proto_library( - name = "share_shuffle_sketch_cc_proto", - deps = [":share_shuffle_sketch_proto"], -) diff --git a/src/main/proto/wfa/frequency_count/BUILD.bazel b/src/main/proto/wfa/frequency_count/BUILD.bazel new file mode 100644 index 0000000..bdab576 --- /dev/null +++ b/src/main/proto/wfa/frequency_count/BUILD.bazel @@ -0,0 +1,42 @@ +load("@rules_cc//cc:defs.bzl", "cc_proto_library") +load("@rules_proto//proto:defs.bzl", "proto_library") + +package(default_visibility = ["//visibility:public"]) + +IMPORT_PREFIX = "/src/main/proto" + +proto_library( + name = "secret_share_proto", + srcs = ["secret_share.proto"], + strip_import_prefix = IMPORT_PREFIX, +) + +cc_proto_library( + name = "secret_share_cc_proto", + deps = [":secret_share_proto"], +) + +proto_library( + name = "share_shuffle_sketch_proto", + srcs = ["share_shuffle_sketch.proto"], + strip_import_prefix = IMPORT_PREFIX, +) + +cc_proto_library( + name = "share_shuffle_sketch_cc_proto", + deps = [":share_shuffle_sketch_proto"], +) + +proto_library( + name = "share_shuffle_methods_proto", + srcs = ["share_shuffle_methods.proto"], + strip_import_prefix = IMPORT_PREFIX, + deps = [ + ":secret_share_proto", + ], +) + +cc_proto_library( + name = "share_shuffle_methods_cc_proto", + deps = [":share_shuffle_methods_proto"], +) diff --git a/src/main/proto/wfa/any_sketch/secret_share.proto b/src/main/proto/wfa/frequency_count/secret_share.proto similarity index 93% rename from src/main/proto/wfa/any_sketch/secret_share.proto rename to src/main/proto/wfa/frequency_count/secret_share.proto index 609792a..38d6799 100644 --- a/src/main/proto/wfa/any_sketch/secret_share.proto +++ b/src/main/proto/wfa/frequency_count/secret_share.proto @@ -18,9 +18,9 @@ syntax = "proto3"; -package wfa.any_sketch; +package wfa.frequency_count; -option java_package = "org.wfanet.anysketch"; +option java_package = "org.wfanet.frequencycount"; option java_multiple_files = true; option java_outer_classname = "SecretShareProto"; diff --git a/src/main/proto/wfa/frequency_count/share_shuffle_methods.proto b/src/main/proto/wfa/frequency_count/share_shuffle_methods.proto new file mode 100644 index 0000000..c272d91 --- /dev/null +++ b/src/main/proto/wfa/frequency_count/share_shuffle_methods.proto @@ -0,0 +1,29 @@ +// Copyright 2024 The Cross-Media Measurement Authors +// +// 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. + +syntax = "proto3"; + +package wfa.frequency_count; + +import "wfa/frequency_count/secret_share.proto"; + +option java_package = "org.wfanet.frequencycount"; +option java_multiple_files = true; + +// The request to encrypt a sketch. +message ShareShuffleGeneratorRequest { + uint32 ring_modulus = 1; + // The input frequency vector + repeated uint32 data = 2; +} diff --git a/src/main/proto/wfa/any_sketch/share_shuffle_sketch.proto b/src/main/proto/wfa/frequency_count/share_shuffle_sketch.proto similarity index 93% rename from src/main/proto/wfa/any_sketch/share_shuffle_sketch.proto rename to src/main/proto/wfa/frequency_count/share_shuffle_sketch.proto index 503647e..31c70a9 100644 --- a/src/main/proto/wfa/any_sketch/share_shuffle_sketch.proto +++ b/src/main/proto/wfa/frequency_count/share_shuffle_sketch.proto @@ -18,9 +18,9 @@ syntax = "proto3"; -package wfa.any_sketch; +package wfa.frequency_count; -option java_package = "org.wfanet.anysketch"; +option java_package = "org.wfanet.frequencycount"; option java_multiple_files = true; option java_outer_classname = "ShareShuffleSketchProto"; diff --git a/src/test/cc/any_sketch/crypto/BUILD.bazel b/src/test/cc/any_sketch/crypto/BUILD.bazel index 15838bf..5544abc 100644 --- a/src/test/cc/any_sketch/crypto/BUILD.bazel +++ b/src/test/cc/any_sketch/crypto/BUILD.bazel @@ -28,33 +28,3 @@ cc_test( "@wfa_common_cpp//src/main/cc/common_cpp/testing:status", ], ) - -cc_test( - name = "secret_share_generator_test", - size = "small", - srcs = [ - ":secret_share_generator_test.cc", - ], - deps = [ - "//src/main/cc/any_sketch/crypto:secret_share_generator", - "//src/main/cc/math:open_ssl_uniform_random_generator", - "//src/main/proto/wfa/any_sketch:secret_share_cc_proto", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - "@wfa_common_cpp//src/main/cc/common_cpp/testing:status", - ], -) - -cc_test( - name = "shuffle_test", - size = "small", - srcs = [ - "shuffle_test.cc", - ], - deps = [ - "//src/main/cc/any_sketch/crypto:shuffle", - "@com_google_googletest//:gtest", - "@com_google_googletest//:gtest_main", - "@wfa_common_cpp//src/main/cc/common_cpp/testing:status", - ], -) diff --git a/src/test/cc/crypto/BUILD.bazel b/src/test/cc/crypto/BUILD.bazel new file mode 100644 index 0000000..3d2cd9c --- /dev/null +++ b/src/test/cc/crypto/BUILD.bazel @@ -0,0 +1,13 @@ +cc_test( + name = "shuffle_test", + size = "small", + srcs = [ + "shuffle_test.cc", + ], + deps = [ + "//src/main/cc/crypto:shuffle", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", + "@wfa_common_cpp//src/main/cc/common_cpp/testing:status", + ], +) diff --git a/src/test/cc/any_sketch/crypto/shuffle_test.cc b/src/test/cc/crypto/shuffle_test.cc similarity index 96% rename from src/test/cc/any_sketch/crypto/shuffle_test.cc rename to src/test/cc/crypto/shuffle_test.cc index d2a4d1e..4c7501d 100644 --- a/src/test/cc/any_sketch/crypto/shuffle_test.cc +++ b/src/test/cc/crypto/shuffle_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "any_sketch/crypto/shuffle.h" +#include "crypto/shuffle.h" #include "absl/status/status.h" #include "absl/status/statusor.h" @@ -21,10 +21,10 @@ #include "gtest/gtest.h" #include "math/open_ssl_uniform_random_generator.h" -namespace wfa::any_sketch::crypto { +namespace wfa::crypto { namespace { -using any_sketch::PrngSeed; +using frequency_count::PrngSeed; using measurement::common::crypto::SecureShuffleWithSeed; using ::wfa::StatusIs; using ::wfa::math::kBytesPerAes256Iv; @@ -117,4 +117,4 @@ TEST(SecureShuffleWithSeed, ShufflingWithSameSeedSucceeds) { } } // namespace -} // namespace wfa::any_sketch::crypto +} // namespace wfa::crypto diff --git a/src/test/cc/frequency_count/BUILD.bazel b/src/test/cc/frequency_count/BUILD.bazel new file mode 100644 index 0000000..f64c1f6 --- /dev/null +++ b/src/test/cc/frequency_count/BUILD.bazel @@ -0,0 +1,30 @@ +cc_test( + name = "secret_share_generator_test", + size = "small", + srcs = [ + ":secret_share_generator_test.cc", + ], + deps = [ + "//src/main/cc/frequency_count:secret_share_generator", + "//src/main/cc/math:open_ssl_uniform_random_generator", + "//src/main/proto/wfa/frequency_count:secret_share_cc_proto", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", + "@wfa_common_cpp//src/main/cc/common_cpp/testing:status", + ], +) + +cc_test( + name = "secret_share_generator_adapter_test", + size = "small", + srcs = [":secret_share_generator_adapter_test.cc"], + deps = [ + "//src/main/cc/frequency_count:secret_share_generator_adapter", + "//src/main/cc/math:open_ssl_uniform_random_generator", + "//src/main/proto/wfa/frequency_count:secret_share_cc_proto", + "//src/main/proto/wfa/frequency_count:share_shuffle_methods_cc_proto", + "@com_google_googletest//:gtest", + "@com_google_googletest//:gtest_main", + "@wfa_common_cpp//src/main/cc/common_cpp/testing:status", + ], +) diff --git a/src/test/cc/frequency_count/secret_share_generator_adapter_test.cc b/src/test/cc/frequency_count/secret_share_generator_adapter_test.cc new file mode 100644 index 0000000..e1776e4 --- /dev/null +++ b/src/test/cc/frequency_count/secret_share_generator_adapter_test.cc @@ -0,0 +1,94 @@ +// Copyright 2024 The Cross-Media Measurement Authors +// +// 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. + +#include "frequency_count/secret_share_generator_adapter.h" + +#include "absl/status/status.h" +#include "absl/status/statusor.h" +#include "common_cpp/testing/status_macros.h" +#include "common_cpp/testing/status_matchers.h" +#include "frequency_count/secret_share_generator.h" +#include "gtest/gtest.h" +#include "math/open_ssl_uniform_random_generator.h" +#include "wfa/frequency_count/share_shuffle_methods.pb.h" + +namespace wfa::frequency_count { +namespace { + +using math::OpenSslUniformPseudorandomGenerator; +using math::UniformPseudorandomGenerator; + +constexpr int kRingModulus = 128; + +TEST(SecretShareJavaAdapterTest, EmptyFrequencyVectorFails) { + // Build the request + ShareShuffleGeneratorRequest request; + request.set_ring_modulus(kRingModulus); + std::vector frequency_vector(0); + + EXPECT_THAT(SecretShareFrequencyVector(request.SerializeAsString()).status(), + StatusIs(absl::StatusCode::kInvalidArgument, "Input")); +} + +TEST(SecretShareJavaAdapterTest, InvalidRingModulusFails) { + // Build the request + ShareShuffleGeneratorRequest request; + request.set_ring_modulus(1); + std::vector frequency_vector = {1, 2, 3, 4, 5}; + request.mutable_data()->Add(frequency_vector.begin(), frequency_vector.end()); + + EXPECT_THAT(SecretShareFrequencyVector(request.SerializeAsString()).status(), + StatusIs(absl::StatusCode::kInvalidArgument, "modulus")); +} + +TEST(SecretShareJavaAdapterTest, SecretShareGenerationSucceeds) { + // Build the request + ShareShuffleGeneratorRequest request; + request.set_ring_modulus(kRingModulus); + std::vector frequency_vector = {1, 2, 3, 4, 5}; + request.mutable_data()->Add(frequency_vector.begin(), frequency_vector.end()); + + ASSERT_OK_AND_ASSIGN(std::string response, + SecretShareFrequencyVector(request.SerializeAsString())); + + SecretShare secret_share; + secret_share.ParseFromString(response); + + std::string key = secret_share.share_seed().key(); + std::string iv = secret_share.share_seed().iv(); + + std::vector key_vec, iv_vec; + key_vec.insert(key_vec.end(), key.begin(), key.end()); + iv_vec.insert(iv_vec.end(), iv.begin(), iv.end()); + + ASSERT_OK_AND_ASSIGN( + std::unique_ptr prng, + OpenSslUniformPseudorandomGenerator::Create(key_vec, iv_vec)); + + ASSERT_OK_AND_ASSIGN( + std::vector share_vector_from_seed, + prng->GenerateUniformRandomRange(frequency_vector.size(), kRingModulus)); + + ASSERT_EQ(secret_share.share_vector().size(), frequency_vector.size()); + ASSERT_EQ(share_vector_from_seed.size(), frequency_vector.size()); + + for (int i = 0; i < frequency_vector.size(); i++) { + ASSERT_EQ(frequency_vector[i], + (share_vector_from_seed[i] + secret_share.share_vector(i)) % + kRingModulus); + } +} + +} // namespace +} // namespace wfa::frequency_count diff --git a/src/test/cc/any_sketch/crypto/secret_share_generator_test.cc b/src/test/cc/frequency_count/secret_share_generator_test.cc similarity index 97% rename from src/test/cc/any_sketch/crypto/secret_share_generator_test.cc rename to src/test/cc/frequency_count/secret_share_generator_test.cc index d7983f1..c988e0b 100644 --- a/src/test/cc/any_sketch/crypto/secret_share_generator_test.cc +++ b/src/test/cc/frequency_count/secret_share_generator_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "any_sketch/crypto/secret_share_generator.h" +#include "frequency_count/secret_share_generator.h" #include "absl/status/status.h" #include "absl/status/statusor.h" @@ -21,7 +21,7 @@ #include "gtest/gtest.h" #include "math/open_ssl_uniform_random_generator.h" -namespace wfa::any_sketch::crypto { +namespace wfa::frequency_count { namespace { using math::OpenSslUniformPseudorandomGenerator; @@ -122,4 +122,4 @@ TEST(AdditiveSecretSharing, InputOutOfBoundFails) { } } // namespace -} // namespace wfa::any_sketch::crypto +} // namespace wfa::frequency_count From 8709469959041ca73e4eef7e85b800d73ee5c442 Mon Sep 17 00:00:00 2001 From: Phi Hung Le Date: Tue, 19 Mar 2024 03:33:20 +0000 Subject: [PATCH 2/5] Update message name. --- .../cc/frequency_count/secret_share_generator_adapter.cc | 4 ++-- .../proto/wfa/frequency_count/share_shuffle_methods.proto | 2 +- .../frequency_count/secret_share_generator_adapter_test.cc | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/cc/frequency_count/secret_share_generator_adapter.cc b/src/main/cc/frequency_count/secret_share_generator_adapter.cc index 260013a..94626c9 100644 --- a/src/main/cc/frequency_count/secret_share_generator_adapter.cc +++ b/src/main/cc/frequency_count/secret_share_generator_adapter.cc @@ -29,10 +29,10 @@ namespace wfa::frequency_count { absl::StatusOr SecretShareFrequencyVector( const std::string& serialized_request) { - ShareShuffleGeneratorRequest request_proto; + SecretShareGeneratorRequest request_proto; if (!request_proto.ParseFromString(serialized_request)) { return absl::InvalidArgumentError( - "failed to parse the ShareShuffleGeneratorRequest proto."); + "failed to parse the SecretShareGeneratorRequest proto."); } std::vector frequency_vector = std::vector( request_proto.data().begin(), request_proto.data().end()); diff --git a/src/main/proto/wfa/frequency_count/share_shuffle_methods.proto b/src/main/proto/wfa/frequency_count/share_shuffle_methods.proto index c272d91..dc53aa3 100644 --- a/src/main/proto/wfa/frequency_count/share_shuffle_methods.proto +++ b/src/main/proto/wfa/frequency_count/share_shuffle_methods.proto @@ -22,7 +22,7 @@ option java_package = "org.wfanet.frequencycount"; option java_multiple_files = true; // The request to encrypt a sketch. -message ShareShuffleGeneratorRequest { +message SecretShareGeneratorRequest { uint32 ring_modulus = 1; // The input frequency vector repeated uint32 data = 2; diff --git a/src/test/cc/frequency_count/secret_share_generator_adapter_test.cc b/src/test/cc/frequency_count/secret_share_generator_adapter_test.cc index e1776e4..43a9e23 100644 --- a/src/test/cc/frequency_count/secret_share_generator_adapter_test.cc +++ b/src/test/cc/frequency_count/secret_share_generator_adapter_test.cc @@ -33,7 +33,7 @@ constexpr int kRingModulus = 128; TEST(SecretShareJavaAdapterTest, EmptyFrequencyVectorFails) { // Build the request - ShareShuffleGeneratorRequest request; + SecretShareGeneratorRequest request; request.set_ring_modulus(kRingModulus); std::vector frequency_vector(0); @@ -43,7 +43,7 @@ TEST(SecretShareJavaAdapterTest, EmptyFrequencyVectorFails) { TEST(SecretShareJavaAdapterTest, InvalidRingModulusFails) { // Build the request - ShareShuffleGeneratorRequest request; + SecretShareGeneratorRequest request; request.set_ring_modulus(1); std::vector frequency_vector = {1, 2, 3, 4, 5}; request.mutable_data()->Add(frequency_vector.begin(), frequency_vector.end()); @@ -54,7 +54,7 @@ TEST(SecretShareJavaAdapterTest, InvalidRingModulusFails) { TEST(SecretShareJavaAdapterTest, SecretShareGenerationSucceeds) { // Build the request - ShareShuffleGeneratorRequest request; + SecretShareGeneratorRequest request; request.set_ring_modulus(kRingModulus); std::vector frequency_vector = {1, 2, 3, 4, 5}; request.mutable_data()->Add(frequency_vector.begin(), frequency_vector.end()); From 09b5a135a31abb831c079da4b8576674579d0b52 Mon Sep 17 00:00:00 2001 From: Phi Hung Le Date: Tue, 19 Mar 2024 03:34:59 +0000 Subject: [PATCH 3/5] Fix Lint. --- src/main/cc/frequency_count/secret_share_generator_adapter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/cc/frequency_count/secret_share_generator_adapter.h b/src/main/cc/frequency_count/secret_share_generator_adapter.h index 8b1a973..2838689 100644 --- a/src/main/cc/frequency_count/secret_share_generator_adapter.h +++ b/src/main/cc/frequency_count/secret_share_generator_adapter.h @@ -32,4 +32,4 @@ absl::StatusOr SecretShareFrequencyVector( } // namespace wfa::frequency_count -#endif // SRC_MAIN_CC_FREQUENCY_COUNT_SECRET_SHARE_GENERATOR_ADAPTER_H_ \ No newline at end of file +#endif // SRC_MAIN_CC_FREQUENCY_COUNT_SECRET_SHARE_GENERATOR_ADAPTER_H_ From ac5b003a92aa2f1fdcf7cf017e2cbe76a63324a9 Mon Sep 17 00:00:00 2001 From: Phi Hung Le Date: Wed, 20 Mar 2024 18:20:47 +0000 Subject: [PATCH 4/5] Address comments. --- src/main/cc/crypto/shuffle.cc | 4 ++-- src/main/cc/crypto/shuffle.h | 4 ++-- src/main/cc/frequency_count/BUILD.bazel | 2 +- .../secret_share_generator_adapter.cc | 2 +- src/main/proto/wfa/frequency_count/BUILD.bazel | 16 ++++++++-------- ...uffle_sketch.proto => frequency_vector.proto} | 5 ++--- ..._methods.proto => secret_share_methods.proto} | 2 +- src/test/cc/crypto/shuffle_test.cc | 2 +- src/test/cc/frequency_count/BUILD.bazel | 2 +- .../secret_share_generator_adapter_test.cc | 2 +- 10 files changed, 20 insertions(+), 21 deletions(-) rename src/main/proto/wfa/frequency_count/{share_shuffle_sketch.proto => frequency_vector.proto} (87%) rename src/main/proto/wfa/frequency_count/{share_shuffle_methods.proto => secret_share_methods.proto} (94%) diff --git a/src/main/cc/crypto/shuffle.cc b/src/main/cc/crypto/shuffle.cc index 3e7f9cd..852f113 100644 --- a/src/main/cc/crypto/shuffle.cc +++ b/src/main/cc/crypto/shuffle.cc @@ -20,7 +20,7 @@ #include "common_cpp/macros/macros.h" #include "math/open_ssl_uniform_random_generator.h" -namespace wfa::measurement::common::crypto { +namespace wfa::crypto { absl::Status SecureShuffleWithSeed(std::vector& data, const frequency_count::PrngSeed& seed) { @@ -61,4 +61,4 @@ absl::Status SecureShuffleWithSeed(std::vector& data, return absl::OkStatus(); } -} // namespace wfa::measurement::common::crypto +} // namespace wfa::crypto diff --git a/src/main/cc/crypto/shuffle.h b/src/main/cc/crypto/shuffle.h index 4d77d9c..f7c40ea 100644 --- a/src/main/cc/crypto/shuffle.h +++ b/src/main/cc/crypto/shuffle.h @@ -22,7 +22,7 @@ #include "absl/status/status.h" #include "wfa/frequency_count/secret_share.pb.h" -namespace wfa::measurement::common::crypto { +namespace wfa::crypto { // Shuffles the vector data using Fisher-Yates approach. Let n be the size of // data, the Fisher-Yates shuffle is as below. @@ -32,6 +32,6 @@ namespace wfa::measurement::common::crypto { absl::Status SecureShuffleWithSeed(std::vector& data, const frequency_count::PrngSeed& seed); -} // namespace wfa::measurement::common::crypto +} // namespace wfa::crypto #endif // SRC_MAIN_CC_CRYPTO_SHUFFLE_H_ diff --git a/src/main/cc/frequency_count/BUILD.bazel b/src/main/cc/frequency_count/BUILD.bazel index a9735d6..fc4840e 100644 --- a/src/main/cc/frequency_count/BUILD.bazel +++ b/src/main/cc/frequency_count/BUILD.bazel @@ -22,6 +22,6 @@ cc_library( deps = [ ":secret_share_generator", "//src/main/proto/wfa/frequency_count:secret_share_cc_proto", - "//src/main/proto/wfa/frequency_count:share_shuffle_methods_cc_proto", + "//src/main/proto/wfa/frequency_count:secret_share_methods_cc_proto", ], ) diff --git a/src/main/cc/frequency_count/secret_share_generator_adapter.cc b/src/main/cc/frequency_count/secret_share_generator_adapter.cc index 94626c9..9dea06b 100644 --- a/src/main/cc/frequency_count/secret_share_generator_adapter.cc +++ b/src/main/cc/frequency_count/secret_share_generator_adapter.cc @@ -23,7 +23,7 @@ #include "common_cpp/macros/macros.h" #include "frequency_count/secret_share_generator.h" #include "wfa/frequency_count/secret_share.pb.h" -#include "wfa/frequency_count/share_shuffle_methods.pb.h" +#include "wfa/frequency_count/secret_share_methods.pb.h" namespace wfa::frequency_count { diff --git a/src/main/proto/wfa/frequency_count/BUILD.bazel b/src/main/proto/wfa/frequency_count/BUILD.bazel index bdab576..acb74c9 100644 --- a/src/main/proto/wfa/frequency_count/BUILD.bazel +++ b/src/main/proto/wfa/frequency_count/BUILD.bazel @@ -17,19 +17,19 @@ cc_proto_library( ) proto_library( - name = "share_shuffle_sketch_proto", - srcs = ["share_shuffle_sketch.proto"], + name = "frequency_vector_proto", + srcs = ["frequency_vector.proto"], strip_import_prefix = IMPORT_PREFIX, ) cc_proto_library( - name = "share_shuffle_sketch_cc_proto", - deps = [":share_shuffle_sketch_proto"], + name = "frequency_vector_cc_proto", + deps = [":frequency_vector_proto"], ) proto_library( - name = "share_shuffle_methods_proto", - srcs = ["share_shuffle_methods.proto"], + name = "secret_share_methods_proto", + srcs = ["secret_share_methods.proto"], strip_import_prefix = IMPORT_PREFIX, deps = [ ":secret_share_proto", @@ -37,6 +37,6 @@ proto_library( ) cc_proto_library( - name = "share_shuffle_methods_cc_proto", - deps = [":share_shuffle_methods_proto"], + name = "secret_share_methods_cc_proto", + deps = [":secret_share_methods_proto"], ) diff --git a/src/main/proto/wfa/frequency_count/share_shuffle_sketch.proto b/src/main/proto/wfa/frequency_count/frequency_vector.proto similarity index 87% rename from src/main/proto/wfa/frequency_count/share_shuffle_sketch.proto rename to src/main/proto/wfa/frequency_count/frequency_vector.proto index 31c70a9..07c6c23 100644 --- a/src/main/proto/wfa/frequency_count/share_shuffle_sketch.proto +++ b/src/main/proto/wfa/frequency_count/frequency_vector.proto @@ -22,10 +22,9 @@ package wfa.frequency_count; option java_package = "org.wfanet.frequencycount"; option java_multiple_files = true; -option java_outer_classname = "ShareShuffleSketchProto"; +option java_outer_classname = "FrequencyVectorProto"; -// The data share of HonestMajorityShareShuffle protocol. -message ShareShuffleSketch { +message FrequencyVector { // A vector of count where each count corresponds to the frequency of a single // VID. repeated uint32 data = 1; diff --git a/src/main/proto/wfa/frequency_count/share_shuffle_methods.proto b/src/main/proto/wfa/frequency_count/secret_share_methods.proto similarity index 94% rename from src/main/proto/wfa/frequency_count/share_shuffle_methods.proto rename to src/main/proto/wfa/frequency_count/secret_share_methods.proto index dc53aa3..1f27433 100644 --- a/src/main/proto/wfa/frequency_count/share_shuffle_methods.proto +++ b/src/main/proto/wfa/frequency_count/secret_share_methods.proto @@ -21,7 +21,7 @@ import "wfa/frequency_count/secret_share.proto"; option java_package = "org.wfanet.frequencycount"; option java_multiple_files = true; -// The request to encrypt a sketch. +// The request to secret share a frequency vector. message SecretShareGeneratorRequest { uint32 ring_modulus = 1; // The input frequency vector diff --git a/src/test/cc/crypto/shuffle_test.cc b/src/test/cc/crypto/shuffle_test.cc index 4c7501d..8790f9c 100644 --- a/src/test/cc/crypto/shuffle_test.cc +++ b/src/test/cc/crypto/shuffle_test.cc @@ -25,8 +25,8 @@ namespace wfa::crypto { namespace { using frequency_count::PrngSeed; -using measurement::common::crypto::SecureShuffleWithSeed; using ::wfa::StatusIs; +using ::wfa::crypto::SecureShuffleWithSeed; using ::wfa::math::kBytesPerAes256Iv; using ::wfa::math::kBytesPerAes256Key; diff --git a/src/test/cc/frequency_count/BUILD.bazel b/src/test/cc/frequency_count/BUILD.bazel index f64c1f6..e5080f2 100644 --- a/src/test/cc/frequency_count/BUILD.bazel +++ b/src/test/cc/frequency_count/BUILD.bazel @@ -22,7 +22,7 @@ cc_test( "//src/main/cc/frequency_count:secret_share_generator_adapter", "//src/main/cc/math:open_ssl_uniform_random_generator", "//src/main/proto/wfa/frequency_count:secret_share_cc_proto", - "//src/main/proto/wfa/frequency_count:share_shuffle_methods_cc_proto", + "//src/main/proto/wfa/frequency_count:secret_share_methods_cc_proto", "@com_google_googletest//:gtest", "@com_google_googletest//:gtest_main", "@wfa_common_cpp//src/main/cc/common_cpp/testing:status", diff --git a/src/test/cc/frequency_count/secret_share_generator_adapter_test.cc b/src/test/cc/frequency_count/secret_share_generator_adapter_test.cc index 43a9e23..32ebfc2 100644 --- a/src/test/cc/frequency_count/secret_share_generator_adapter_test.cc +++ b/src/test/cc/frequency_count/secret_share_generator_adapter_test.cc @@ -21,7 +21,7 @@ #include "frequency_count/secret_share_generator.h" #include "gtest/gtest.h" #include "math/open_ssl_uniform_random_generator.h" -#include "wfa/frequency_count/share_shuffle_methods.pb.h" +#include "wfa/frequency_count/secret_share_methods.pb.h" namespace wfa::frequency_count { namespace { From 80c5c7bb51302b87d3a603b418c0cde477ddb24b Mon Sep 17 00:00:00 2001 From: Phi Hung Le Date: Thu, 21 Mar 2024 17:45:54 +0000 Subject: [PATCH 5/5] Address comments. --- src/main/cc/frequency_count/BUILD.bazel | 8 ++++---- ...ecret_share_generator.cc => generate_secret_shares.cc} | 2 +- ...{secret_share_generator.h => generate_secret_shares.h} | 6 +++--- .../cc/frequency_count/secret_share_generator_adapter.cc | 2 +- src/test/cc/frequency_count/BUILD.bazel | 6 +++--- ...e_generator_test.cc => generate_secret_shares_test.cc} | 2 +- .../secret_share_generator_adapter_test.cc | 8 ++++---- 7 files changed, 17 insertions(+), 17 deletions(-) rename src/main/cc/frequency_count/{secret_share_generator.cc => generate_secret_shares.cc} (98%) rename src/main/cc/frequency_count/{secret_share_generator.h => generate_secret_shares.h} (84%) rename src/test/cc/frequency_count/{secret_share_generator_test.cc => generate_secret_shares_test.cc} (98%) diff --git a/src/main/cc/frequency_count/BUILD.bazel b/src/main/cc/frequency_count/BUILD.bazel index fc4840e..5a2347c 100644 --- a/src/main/cc/frequency_count/BUILD.bazel +++ b/src/main/cc/frequency_count/BUILD.bazel @@ -3,9 +3,9 @@ package(default_visibility = ["//visibility:public"]) _INCLUDE_PREFIX = "/src/main/cc/" cc_library( - name = "secret_share_generator", - srcs = [":secret_share_generator.cc"], - hdrs = [":secret_share_generator.h"], + name = "generate_secret_shares", + srcs = [":generate_secret_shares.cc"], + hdrs = [":generate_secret_shares.h"], strip_include_prefix = _INCLUDE_PREFIX, deps = [ "//src/main/cc/math:open_ssl_uniform_random_generator", @@ -20,7 +20,7 @@ cc_library( hdrs = [":secret_share_generator_adapter.h"], strip_include_prefix = _INCLUDE_PREFIX, deps = [ - ":secret_share_generator", + ":generate_secret_shares", "//src/main/proto/wfa/frequency_count:secret_share_cc_proto", "//src/main/proto/wfa/frequency_count:secret_share_methods_cc_proto", ], diff --git a/src/main/cc/frequency_count/secret_share_generator.cc b/src/main/cc/frequency_count/generate_secret_shares.cc similarity index 98% rename from src/main/cc/frequency_count/secret_share_generator.cc rename to src/main/cc/frequency_count/generate_secret_shares.cc index d3f84b5..a2c2c4f 100644 --- a/src/main/cc/frequency_count/secret_share_generator.cc +++ b/src/main/cc/frequency_count/generate_secret_shares.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "frequency_count/secret_share_generator.h" +#include "frequency_count/generate_secret_shares.h" #include #include diff --git a/src/main/cc/frequency_count/secret_share_generator.h b/src/main/cc/frequency_count/generate_secret_shares.h similarity index 84% rename from src/main/cc/frequency_count/secret_share_generator.h rename to src/main/cc/frequency_count/generate_secret_shares.h index 4708b0f..3448603 100644 --- a/src/main/cc/frequency_count/secret_share_generator.h +++ b/src/main/cc/frequency_count/generate_secret_shares.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef SRC_MAIN_CC_FREQUENCY_COUNT_SECRET_SHARE_GENERATOR_H_ -#define SRC_MAIN_CC_FREQUENCY_COUNT_SECRET_SHARE_GENERATOR_H_ +#ifndef SRC_MAIN_CC_FREQUENCY_COUNT_GENERATE_SECRET_SHARES_H_ +#define SRC_MAIN_CC_FREQUENCY_COUNT_GENERATE_SECRET_SHARES_H_ #include @@ -31,4 +31,4 @@ absl::StatusOr GenerateSecretShares( } // namespace wfa::frequency_count -#endif // SRC_MAIN_CC_FREQUENCY_COUNT_SECRET_SHARE_GENERATOR_H_ +#endif // SRC_MAIN_CC_FREQUENCY_COUNT_GENERATE_SECRET_SHARES_H_ diff --git a/src/main/cc/frequency_count/secret_share_generator_adapter.cc b/src/main/cc/frequency_count/secret_share_generator_adapter.cc index 9dea06b..146fe7d 100644 --- a/src/main/cc/frequency_count/secret_share_generator_adapter.cc +++ b/src/main/cc/frequency_count/secret_share_generator_adapter.cc @@ -21,7 +21,7 @@ #include "absl/status/status.h" #include "absl/status/statusor.h" #include "common_cpp/macros/macros.h" -#include "frequency_count/secret_share_generator.h" +#include "frequency_count/generate_secret_shares.h" #include "wfa/frequency_count/secret_share.pb.h" #include "wfa/frequency_count/secret_share_methods.pb.h" diff --git a/src/test/cc/frequency_count/BUILD.bazel b/src/test/cc/frequency_count/BUILD.bazel index e5080f2..63fe9ab 100644 --- a/src/test/cc/frequency_count/BUILD.bazel +++ b/src/test/cc/frequency_count/BUILD.bazel @@ -1,11 +1,11 @@ cc_test( - name = "secret_share_generator_test", + name = "generate_secret_shares_test", size = "small", srcs = [ - ":secret_share_generator_test.cc", + ":generate_secret_shares_test.cc", ], deps = [ - "//src/main/cc/frequency_count:secret_share_generator", + "//src/main/cc/frequency_count:generate_secret_shares", "//src/main/cc/math:open_ssl_uniform_random_generator", "//src/main/proto/wfa/frequency_count:secret_share_cc_proto", "@com_google_googletest//:gtest", diff --git a/src/test/cc/frequency_count/secret_share_generator_test.cc b/src/test/cc/frequency_count/generate_secret_shares_test.cc similarity index 98% rename from src/test/cc/frequency_count/secret_share_generator_test.cc rename to src/test/cc/frequency_count/generate_secret_shares_test.cc index c988e0b..a879a32 100644 --- a/src/test/cc/frequency_count/secret_share_generator_test.cc +++ b/src/test/cc/frequency_count/generate_secret_shares_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "frequency_count/secret_share_generator.h" +#include "frequency_count/generate_secret_shares.h" #include "absl/status/status.h" #include "absl/status/statusor.h" diff --git a/src/test/cc/frequency_count/secret_share_generator_adapter_test.cc b/src/test/cc/frequency_count/secret_share_generator_adapter_test.cc index 32ebfc2..5fb85f5 100644 --- a/src/test/cc/frequency_count/secret_share_generator_adapter_test.cc +++ b/src/test/cc/frequency_count/secret_share_generator_adapter_test.cc @@ -18,7 +18,7 @@ #include "absl/status/statusor.h" #include "common_cpp/testing/status_macros.h" #include "common_cpp/testing/status_matchers.h" -#include "frequency_count/secret_share_generator.h" +#include "frequency_count/generate_secret_shares.h" #include "gtest/gtest.h" #include "math/open_ssl_uniform_random_generator.h" #include "wfa/frequency_count/secret_share_methods.pb.h" @@ -31,7 +31,7 @@ using math::UniformPseudorandomGenerator; constexpr int kRingModulus = 128; -TEST(SecretShareJavaAdapterTest, EmptyFrequencyVectorFails) { +TEST(SecretShareAdapterTest, EmptyFrequencyVectorFails) { // Build the request SecretShareGeneratorRequest request; request.set_ring_modulus(kRingModulus); @@ -41,7 +41,7 @@ TEST(SecretShareJavaAdapterTest, EmptyFrequencyVectorFails) { StatusIs(absl::StatusCode::kInvalidArgument, "Input")); } -TEST(SecretShareJavaAdapterTest, InvalidRingModulusFails) { +TEST(SecretShareAdapterTest, InvalidRingModulusFails) { // Build the request SecretShareGeneratorRequest request; request.set_ring_modulus(1); @@ -52,7 +52,7 @@ TEST(SecretShareJavaAdapterTest, InvalidRingModulusFails) { StatusIs(absl::StatusCode::kInvalidArgument, "modulus")); } -TEST(SecretShareJavaAdapterTest, SecretShareGenerationSucceeds) { +TEST(SecretShareAdapterTest, SecretShareGenerationSucceeds) { // Build the request SecretShareGeneratorRequest request; request.set_ring_modulus(kRingModulus);