Moving functions that use protocol buffers to "testing/proto_utils" from testing/utils. This CL does not add any new code and only touches test and build files.
All the other files in this CL have changes related to adding "testing/proto_utils" as a dependency instead of / in addition to "testing/utils".
Tldr; Splits an existing file into two and adds the paths for the second file in all relevant BUILD, header and cc files.
PiperOrigin-RevId: 539760965
diff --git a/build/source_list.bzl b/build/source_list.bzl
index a37c510..e539204 100644
--- a/build/source_list.bzl
+++ b/build/source_list.bzl
@@ -1568,6 +1568,7 @@
"blind_sign_auth/anonymous_tokens/cpp/crypto/verifier.h",
"blind_sign_auth/anonymous_tokens/cpp/shared/proto_utils.h",
"blind_sign_auth/anonymous_tokens/cpp/shared/status_utils.h",
+ "blind_sign_auth/anonymous_tokens/cpp/testing/proto_utils.h",
"blind_sign_auth/anonymous_tokens/cpp/testing/utils.h",
"blind_sign_auth/blind_sign_auth.h",
"blind_sign_auth/blind_sign_auth_interface.h",
@@ -1584,6 +1585,7 @@
"blind_sign_auth/anonymous_tokens/cpp/crypto/rsa_blinder.cc",
"blind_sign_auth/anonymous_tokens/cpp/crypto/rsa_ssa_pss_verifier.cc",
"blind_sign_auth/anonymous_tokens/cpp/shared/proto_utils.cc",
+ "blind_sign_auth/anonymous_tokens/cpp/testing/proto_utils.cc",
"blind_sign_auth/anonymous_tokens/cpp/testing/utils.cc",
"blind_sign_auth/blind_sign_auth.cc",
"blind_sign_auth/cached_blind_sign_auth.cc",
diff --git a/build/source_list.gni b/build/source_list.gni
index 5f25812..2e5c6c2 100644
--- a/build/source_list.gni
+++ b/build/source_list.gni
@@ -1572,6 +1572,7 @@
"src/quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/verifier.h",
"src/quiche/blind_sign_auth/anonymous_tokens/cpp/shared/proto_utils.h",
"src/quiche/blind_sign_auth/anonymous_tokens/cpp/shared/status_utils.h",
+ "src/quiche/blind_sign_auth/anonymous_tokens/cpp/testing/proto_utils.h",
"src/quiche/blind_sign_auth/anonymous_tokens/cpp/testing/utils.h",
"src/quiche/blind_sign_auth/blind_sign_auth.h",
"src/quiche/blind_sign_auth/blind_sign_auth_interface.h",
@@ -1588,6 +1589,7 @@
"src/quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/rsa_blinder.cc",
"src/quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/rsa_ssa_pss_verifier.cc",
"src/quiche/blind_sign_auth/anonymous_tokens/cpp/shared/proto_utils.cc",
+ "src/quiche/blind_sign_auth/anonymous_tokens/cpp/testing/proto_utils.cc",
"src/quiche/blind_sign_auth/anonymous_tokens/cpp/testing/utils.cc",
"src/quiche/blind_sign_auth/blind_sign_auth.cc",
"src/quiche/blind_sign_auth/cached_blind_sign_auth.cc",
diff --git a/build/source_list.json b/build/source_list.json
index ae24505..f30cdfa 100644
--- a/build/source_list.json
+++ b/build/source_list.json
@@ -1571,6 +1571,7 @@
"quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/verifier.h",
"quiche/blind_sign_auth/anonymous_tokens/cpp/shared/proto_utils.h",
"quiche/blind_sign_auth/anonymous_tokens/cpp/shared/status_utils.h",
+ "quiche/blind_sign_auth/anonymous_tokens/cpp/testing/proto_utils.h",
"quiche/blind_sign_auth/anonymous_tokens/cpp/testing/utils.h",
"quiche/blind_sign_auth/blind_sign_auth.h",
"quiche/blind_sign_auth/blind_sign_auth_interface.h",
@@ -1587,6 +1588,7 @@
"quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/rsa_blinder.cc",
"quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/rsa_ssa_pss_verifier.cc",
"quiche/blind_sign_auth/anonymous_tokens/cpp/shared/proto_utils.cc",
+ "quiche/blind_sign_auth/anonymous_tokens/cpp/testing/proto_utils.cc",
"quiche/blind_sign_auth/anonymous_tokens/cpp/testing/utils.cc",
"quiche/blind_sign_auth/blind_sign_auth.cc",
"quiche/blind_sign_auth/cached_blind_sign_auth.cc"
diff --git a/quiche/blind_sign_auth/anonymous_tokens/cpp/client/anonymous_tokens_rsa_bssa_client_test.cc b/quiche/blind_sign_auth/anonymous_tokens/cpp/client/anonymous_tokens_rsa_bssa_client_test.cc
index 25cf416..b013b5a 100644
--- a/quiche/blind_sign_auth/anonymous_tokens/cpp/client/anonymous_tokens_rsa_bssa_client_test.cc
+++ b/quiche/blind_sign_auth/anonymous_tokens/cpp/client/anonymous_tokens_rsa_bssa_client_test.cc
@@ -26,6 +26,7 @@
#include "quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/rsa_blind_signer.h"
#include "quiche/blind_sign_auth/anonymous_tokens/cpp/shared/proto_utils.h"
#include "quiche/blind_sign_auth/anonymous_tokens/cpp/shared/status_utils.h"
+#include "quiche/blind_sign_auth/anonymous_tokens/cpp/testing/proto_utils.h"
#include "quiche/blind_sign_auth/anonymous_tokens/cpp/testing/utils.h"
#include "quiche/blind_sign_auth/anonymous_tokens/proto/anonymous_tokens.pb.h"
#include "openssl/base.h"
diff --git a/quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/at_crypto_utils_test.cc b/quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/at_crypto_utils_test.cc
index 24ff66f..940c112 100644
--- a/quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/at_crypto_utils_test.cc
+++ b/quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/at_crypto_utils_test.cc
@@ -23,6 +23,7 @@
#include "quiche/common/test_tools/quiche_test_utils.h"
#include "absl/strings/escaping.h"
#include "quiche/blind_sign_auth/anonymous_tokens/cpp/testing/utils.h"
+#include "quiche/blind_sign_auth/anonymous_tokens/cpp/testing/proto_utils.h"
#include "quiche/blind_sign_auth/anonymous_tokens/proto/anonymous_tokens.pb.h"
#include "openssl/base.h"
#include "openssl/rsa.h"
diff --git a/quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/rsa_blind_signer_test.cc b/quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/rsa_blind_signer_test.cc
index a332f19..47d2093 100644
--- a/quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/rsa_blind_signer_test.cc
+++ b/quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/rsa_blind_signer_test.cc
@@ -27,6 +27,7 @@
#include "quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/constants.h"
#include "quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/crypto_utils.h"
#include "quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/rsa_ssa_pss_verifier.h"
+#include "quiche/blind_sign_auth/anonymous_tokens/cpp/testing/proto_utils.h"
#include "quiche/blind_sign_auth/anonymous_tokens/cpp/testing/utils.h"
#include "quiche/blind_sign_auth/anonymous_tokens/proto/anonymous_tokens.pb.h"
#include "openssl/digest.h"
diff --git a/quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/rsa_blinder_test.cc b/quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/rsa_blinder_test.cc
index 509bfda..7c16753 100644
--- a/quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/rsa_blinder_test.cc
+++ b/quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/rsa_blinder_test.cc
@@ -26,6 +26,7 @@
#include "quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/constants.h"
#include "quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/crypto_utils.h"
#include "quiche/blind_sign_auth/anonymous_tokens/cpp/testing/utils.h"
+#include "quiche/blind_sign_auth/anonymous_tokens/cpp/testing/proto_utils.h"
#include "quiche/blind_sign_auth/anonymous_tokens/proto/anonymous_tokens.pb.h"
#include "openssl/base.h"
#include "openssl/rsa.h"
diff --git a/quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/rsa_ssa_pss_verifier_test.cc b/quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/rsa_ssa_pss_verifier_test.cc
index 2732c75..52dc988 100644
--- a/quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/rsa_ssa_pss_verifier_test.cc
+++ b/quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/rsa_ssa_pss_verifier_test.cc
@@ -25,6 +25,7 @@
#include "absl/strings/string_view.h"
#include "quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/constants.h"
#include "quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/crypto_utils.h"
+#include "quiche/blind_sign_auth/anonymous_tokens/cpp/testing/proto_utils.h"
#include "quiche/blind_sign_auth/anonymous_tokens/cpp/testing/utils.h"
#include "quiche/blind_sign_auth/anonymous_tokens/proto/anonymous_tokens.pb.h"
#include "openssl/rsa.h"
diff --git a/quiche/blind_sign_auth/anonymous_tokens/cpp/testing/proto_utils.cc b/quiche/blind_sign_auth/anonymous_tokens/cpp/testing/proto_utils.cc
new file mode 100644
index 0000000..51f8b8a
--- /dev/null
+++ b/quiche/blind_sign_auth/anonymous_tokens/cpp/testing/proto_utils.cc
@@ -0,0 +1,294 @@
+// Copyright 2023 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
+//
+// https://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 "quiche/blind_sign_auth/anonymous_tokens/cpp/testing/proto_utils.h"
+
+#include <cstdint>
+#include <fstream>
+#include <ios>
+#include <sstream>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "absl/status/status.h"
+#include "absl/status/statusor.h"
+#include "absl/strings/str_cat.h"
+#include "absl/strings/string_view.h"
+#include "quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/constants.h"
+#include "quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/crypto_utils.h"
+#include "quiche/blind_sign_auth/anonymous_tokens/cpp/shared/status_utils.h"
+#include "quiche/blind_sign_auth/anonymous_tokens/cpp/testing/utils.h"
+#include "quiche/blind_sign_auth/anonymous_tokens/proto/anonymous_tokens.pb.h"
+#include "quiche/common/platform/api/quiche_file_utils.h"
+#include "quiche/common/platform/api/quiche_test.h"
+#include "openssl/base.h"
+#include "openssl/bn.h"
+#include "openssl/rsa.h"
+
+namespace private_membership {
+namespace anonymous_tokens {
+
+namespace {
+
+absl::StatusOr<std::string> ReadFileToString(absl::string_view path) {
+ std::ifstream file(std::string(path), std::ios::binary);
+ if (!file.is_open()) {
+ return absl::InternalError("Reading file failed.");
+ }
+ std::ostringstream ss(std::ios::binary);
+ ss << file.rdbuf();
+ return ss.str();
+}
+
+absl::StatusOr<std::pair<RSAPublicKey, RSAPrivateKey>> ParseRsaKeysFromFile(
+ absl::string_view path) {
+ ANON_TOKENS_ASSIGN_OR_RETURN(std::string binary_proto,
+ ReadFileToString(path));
+ RSAPrivateKey private_key;
+ if (!private_key.ParseFromString(binary_proto)) {
+ return absl::InternalError("Parsing binary proto failed.");
+ }
+ RSAPublicKey public_key;
+ public_key.set_n(private_key.n());
+ public_key.set_e(private_key.e());
+ return std::make_pair(std::move(public_key), std::move(private_key));
+}
+
+absl::StatusOr<bssl::UniquePtr<RSA>> GenerateRSAKey(int modulus_bit_size,
+ const BIGNUM& e) {
+ bssl::UniquePtr<RSA> rsa(RSA_new());
+ if (!rsa.get()) {
+ return absl::InternalError(
+ absl::StrCat("RSA_new failed: ", GetSslErrors()));
+ }
+ if (RSA_generate_key_ex(rsa.get(), modulus_bit_size, &e,
+ /*cb=*/nullptr) != kBsslSuccess) {
+ return absl::InternalError(
+ absl::StrCat("Error generating private key: ", GetSslErrors()));
+ }
+ return rsa;
+}
+
+absl::StatusOr<std::pair<RSAPublicKey, RSAPrivateKey>> PopulateTestVectorKeys(
+ const std::string& n, const std::string& e, const std::string& d,
+ const std::string& p, const std::string& q) {
+ RSAPublicKey public_key;
+ RSAPrivateKey private_key;
+
+ public_key.set_n(n);
+ public_key.set_e(e);
+
+ private_key.set_n(n);
+ private_key.set_e(e);
+ private_key.set_d(d);
+ private_key.set_p(p);
+ private_key.set_q(q);
+
+ // Computing CRT parameters
+ ANON_TOKENS_ASSIGN_OR_RETURN(BnCtxPtr bn_ctx, GetAndStartBigNumCtx());
+ ANON_TOKENS_ASSIGN_OR_RETURN(bssl::UniquePtr<BIGNUM> dp_bn, NewBigNum());
+ ANON_TOKENS_ASSIGN_OR_RETURN(bssl::UniquePtr<BIGNUM> dq_bn, NewBigNum());
+ ANON_TOKENS_ASSIGN_OR_RETURN(bssl::UniquePtr<BIGNUM> crt_bn, NewBigNum());
+
+ // p - 1
+ ANON_TOKENS_ASSIGN_OR_RETURN(bssl::UniquePtr<BIGNUM> pm1, StringToBignum(p));
+ BN_sub_word(pm1.get(), 1);
+ // q - 1
+ ANON_TOKENS_ASSIGN_OR_RETURN(bssl::UniquePtr<BIGNUM> qm1, StringToBignum(q));
+ BN_sub_word(qm1.get(), 1);
+ // d mod p-1
+ ANON_TOKENS_ASSIGN_OR_RETURN(bssl::UniquePtr<BIGNUM> d_bn, StringToBignum(d));
+ BN_mod(dp_bn.get(), d_bn.get(), pm1.get(), bn_ctx.get());
+ // d mod q-1
+ BN_mod(dq_bn.get(), d_bn.get(), qm1.get(), bn_ctx.get());
+ // crt q^(-1) mod p
+ ANON_TOKENS_ASSIGN_OR_RETURN(bssl::UniquePtr<BIGNUM> q_bn, StringToBignum(q));
+ ANON_TOKENS_ASSIGN_OR_RETURN(bssl::UniquePtr<BIGNUM> p_bn, StringToBignum(p));
+ BN_mod_inverse(crt_bn.get(), q_bn.get(), p_bn.get(), bn_ctx.get());
+
+ // Populating crt params in private key
+ ANON_TOKENS_ASSIGN_OR_RETURN(
+ std::string dp_str, BignumToString(*dp_bn, BN_num_bytes(dp_bn.get())));
+ ANON_TOKENS_ASSIGN_OR_RETURN(
+ std::string dq_str, BignumToString(*dq_bn, BN_num_bytes(dq_bn.get())));
+ ANON_TOKENS_ASSIGN_OR_RETURN(
+ std::string crt_str, BignumToString(*crt_bn, BN_num_bytes(crt_bn.get())));
+ private_key.set_dp(dp_str);
+ private_key.set_dq(dq_str);
+ private_key.set_crt(crt_str);
+
+ return std::make_pair(std::move(public_key), std::move(private_key));
+}
+
+} // namespace
+
+absl::StatusOr<std::pair<bssl::UniquePtr<RSA>, RSABlindSignaturePublicKey>>
+CreateTestKey(int key_size, HashType sig_hash, MaskGenFunction mfg1_hash,
+ int salt_length, MessageMaskType message_mask_type,
+ int message_mask_size) {
+ ANON_TOKENS_ASSIGN_OR_RETURN(bssl::UniquePtr<BIGNUM> rsa_f4, NewBigNum());
+ BN_set_u64(rsa_f4.get(), RSA_F4);
+
+ ANON_TOKENS_ASSIGN_OR_RETURN(bssl::UniquePtr<RSA> rsa_key,
+ GenerateRSAKey(key_size * 8, *rsa_f4));
+
+ RSAPublicKey rsa_public_key;
+ ANON_TOKENS_ASSIGN_OR_RETURN(
+ *rsa_public_key.mutable_n(),
+ BignumToString(*RSA_get0_n(rsa_key.get()), key_size));
+ ANON_TOKENS_ASSIGN_OR_RETURN(
+ *rsa_public_key.mutable_e(),
+ BignumToString(*RSA_get0_e(rsa_key.get()), key_size));
+
+ RSABlindSignaturePublicKey public_key;
+ public_key.set_serialized_public_key(rsa_public_key.SerializeAsString());
+ public_key.set_sig_hash_type(sig_hash);
+ public_key.set_mask_gen_function(mfg1_hash);
+ public_key.set_salt_length(salt_length);
+ public_key.set_key_size(key_size);
+ public_key.set_message_mask_type(message_mask_type);
+ public_key.set_message_mask_size(message_mask_size);
+
+ return std::make_pair(std::move(rsa_key), std::move(public_key));
+}
+
+absl::StatusOr<std::string> EncodeMessageForTests(absl::string_view message,
+ RSAPublicKey public_key,
+ const EVP_MD* sig_hasher,
+ const EVP_MD* mgf1_hasher,
+ int32_t salt_length) {
+ ANON_TOKENS_ASSIGN_OR_RETURN(bssl::UniquePtr<BIGNUM> rsa_modulus,
+ StringToBignum(public_key.n()));
+ ANON_TOKENS_ASSIGN_OR_RETURN(bssl::UniquePtr<BIGNUM> e,
+ StringToBignum(public_key.e()));
+ // Convert to OpenSSL RSA.
+ bssl::UniquePtr<RSA> rsa_public_key(RSA_new());
+ if (!rsa_public_key.get()) {
+ return absl::InternalError(
+ absl::StrCat("RSA_new failed: ", GetSslErrors()));
+ } else if (RSA_set0_key(rsa_public_key.get(), rsa_modulus.release(),
+ e.release(), nullptr) != kBsslSuccess) {
+ return absl::InternalError(
+ absl::StrCat("RSA_set0_key failed: ", GetSslErrors()));
+ }
+
+ const int padded_len = RSA_size(rsa_public_key.get());
+ std::vector<uint8_t> padded(padded_len);
+ ANON_TOKENS_ASSIGN_OR_RETURN(std::string digest,
+ ComputeHash(message, *sig_hasher));
+ if (RSA_padding_add_PKCS1_PSS_mgf1(
+ /*rsa=*/rsa_public_key.get(), /*EM=*/padded.data(),
+ /*mHash=*/reinterpret_cast<uint8_t*>(&digest[0]), /*Hash=*/sig_hasher,
+ /*mgf1Hash=*/mgf1_hasher,
+ /*sLen=*/salt_length) != kBsslSuccess) {
+ return absl::InternalError(
+ "RSA_padding_add_PKCS1_PSS_mgf1 failed when called from "
+ "testing_utils");
+ }
+ std::string encoded_message(padded.begin(), padded.end());
+ return encoded_message;
+}
+
+absl::StatusOr<std::pair<RSAPublicKey, RSAPrivateKey>> GetStandardRsaKeyPair(
+ int modulus_size_in_bytes) {
+ ANON_TOKENS_ASSIGN_OR_RETURN(bssl::UniquePtr<BIGNUM> rsa_f4, NewBigNum());
+ BN_set_u64(rsa_f4.get(), RSA_F4);
+ ANON_TOKENS_ASSIGN_OR_RETURN(
+ bssl::UniquePtr<RSA> rsa_key,
+ GenerateRSAKey(modulus_size_in_bytes * 8, *rsa_f4));
+
+ RSAPublicKey rsa_public_key;
+ ANON_TOKENS_ASSIGN_OR_RETURN(
+ *rsa_public_key.mutable_n(),
+ BignumToString(*RSA_get0_n(rsa_key.get()), modulus_size_in_bytes));
+ ANON_TOKENS_ASSIGN_OR_RETURN(
+ *rsa_public_key.mutable_e(),
+ BignumToString(*RSA_get0_e(rsa_key.get()), modulus_size_in_bytes));
+
+ RSAPrivateKey rsa_private_key;
+ ANON_TOKENS_ASSIGN_OR_RETURN(
+ *rsa_private_key.mutable_n(),
+ BignumToString(*RSA_get0_n(rsa_key.get()), modulus_size_in_bytes));
+ ANON_TOKENS_ASSIGN_OR_RETURN(
+ *rsa_private_key.mutable_e(),
+ BignumToString(*RSA_get0_e(rsa_key.get()), modulus_size_in_bytes));
+ ANON_TOKENS_ASSIGN_OR_RETURN(
+ *rsa_private_key.mutable_d(),
+ BignumToString(*RSA_get0_d(rsa_key.get()), modulus_size_in_bytes));
+ ANON_TOKENS_ASSIGN_OR_RETURN(
+ *rsa_private_key.mutable_p(),
+ BignumToString(*RSA_get0_p(rsa_key.get()), modulus_size_in_bytes));
+ ANON_TOKENS_ASSIGN_OR_RETURN(
+ *rsa_private_key.mutable_q(),
+ BignumToString(*RSA_get0_q(rsa_key.get()), modulus_size_in_bytes));
+ ANON_TOKENS_ASSIGN_OR_RETURN(
+ *rsa_private_key.mutable_dp(),
+ BignumToString(*RSA_get0_dmp1(rsa_key.get()), modulus_size_in_bytes));
+ ANON_TOKENS_ASSIGN_OR_RETURN(
+ *rsa_private_key.mutable_dq(),
+ BignumToString(*RSA_get0_dmq1(rsa_key.get()), modulus_size_in_bytes));
+ ANON_TOKENS_ASSIGN_OR_RETURN(
+ *rsa_private_key.mutable_crt(),
+ BignumToString(*RSA_get0_iqmp(rsa_key.get()), modulus_size_in_bytes));
+
+ return std::make_pair(std::move(rsa_public_key), std::move(rsa_private_key));
+}
+
+absl::StatusOr<std::pair<RSAPublicKey, RSAPrivateKey>> GetStrongRsaKeys2048() {
+ std::string path = absl::StrCat(quiche::test::QuicheGetCommonSourcePath(),
+ "/anonymous_tokens/testdata/strong_rsa_modulus2048_example.binarypb");
+ ANON_TOKENS_ASSIGN_OR_RETURN(auto key_pair, ParseRsaKeysFromFile(path));
+ return std::make_pair(std::move(key_pair.first), std::move(key_pair.second));
+}
+
+absl::StatusOr<std::pair<RSAPublicKey, RSAPrivateKey>>
+GetAnotherStrongRsaKeys2048() {
+ std::string path = absl::StrCat(quiche::test::QuicheGetCommonSourcePath(),
+ "/anonymous_tokens/testdata/strong_rsa_modulus2048_example_2.binarypb");
+ ANON_TOKENS_ASSIGN_OR_RETURN(auto key_pair, ParseRsaKeysFromFile(path));
+ return std::make_pair(std::move(key_pair.first), std::move(key_pair.second));
+}
+
+absl::StatusOr<std::pair<RSAPublicKey, RSAPrivateKey>> GetStrongRsaKeys3072() {
+ std::string path = absl::StrCat(quiche::test::QuicheGetCommonSourcePath(),
+ "/anonymous_tokens/testdata/strong_rsa_modulus3072_example.binarypb");
+ ANON_TOKENS_ASSIGN_OR_RETURN(auto key_pair, ParseRsaKeysFromFile(path));
+ return std::make_pair(std::move(key_pair.first), std::move(key_pair.second));
+}
+
+absl::StatusOr<std::pair<RSAPublicKey, RSAPrivateKey>> GetStrongRsaKeys4096() {
+ std::string path = absl::StrCat(quiche::test::QuicheGetCommonSourcePath(),
+ "/anonymous_tokens/testdata/strong_rsa_modulus4096_example.binarypb");
+ ANON_TOKENS_ASSIGN_OR_RETURN(auto key_pair, ParseRsaKeysFromFile(path));
+ return std::make_pair(std::move(key_pair.first), std::move(key_pair.second));
+}
+
+absl::StatusOr<std::pair<RSAPublicKey, RSAPrivateKey>>
+GetIetfStandardRsaBlindSignatureTestKeys() {
+ IetfStandardRsaBlindSignatureTestVector test_vector =
+ GetIetfStandardRsaBlindSignatureTestVector();
+ return PopulateTestVectorKeys(test_vector.n, test_vector.e, test_vector.d,
+ test_vector.p, test_vector.q);
+}
+
+absl::StatusOr<std::pair<RSAPublicKey, RSAPrivateKey>>
+GetIetfRsaBlindSignatureWithPublicMetadataTestKeys() {
+ auto test_vectors = GetIetfRsaBlindSignatureWithPublicMetadataTestVectors();
+ return PopulateTestVectorKeys(test_vectors[0].n, test_vectors[0].e,
+ test_vectors[0].d, test_vectors[0].p,
+ test_vectors[0].q);
+}
+
+} // namespace anonymous_tokens
+} // namespace private_membership
diff --git a/quiche/blind_sign_auth/anonymous_tokens/cpp/testing/proto_utils.h b/quiche/blind_sign_auth/anonymous_tokens/cpp/testing/proto_utils.h
new file mode 100644
index 0000000..6b1359d
--- /dev/null
+++ b/quiche/blind_sign_auth/anonymous_tokens/cpp/testing/proto_utils.h
@@ -0,0 +1,84 @@
+// Copyright 2023 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
+//
+// https://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 THIRD_PARTY_ANONYMOUS_TOKENS_CPP_TESTING_PROTO_UTILS_H_
+#define THIRD_PARTY_ANONYMOUS_TOKENS_CPP_TESTING_PROTO_UTILS_H_
+
+#include <string>
+#include <utility>
+#include <cstdint>
+
+#include "absl/status/statusor.h"
+#include "absl/strings/string_view.h"
+#include "quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/constants.h"
+#include "quiche/blind_sign_auth/anonymous_tokens/proto/anonymous_tokens.pb.h"
+#include "openssl/base.h"
+
+namespace private_membership {
+namespace anonymous_tokens {
+
+// Creates a pair containing a standard RSA Private key and an Anonymous Tokens
+// RSABlindSignaturePublicKey using RSA_F4 (65537) as the public exponent and
+// other input parameters.
+absl::StatusOr<std::pair<bssl::UniquePtr<RSA>, RSABlindSignaturePublicKey>>
+CreateTestKey(int key_size = 512, HashType sig_hash = AT_HASH_TYPE_SHA384,
+ MaskGenFunction mfg1_hash = AT_MGF_SHA384, int salt_length = 48,
+ MessageMaskType message_mask_type = AT_MESSAGE_MASK_CONCAT,
+ int message_mask_size = kRsaMessageMaskSizeInBytes32);
+
+// Prepares message for signing by computing its hash and then applying the PSS
+// padding to the result by executing RSA_padding_add_PKCS1_PSS_mgf1 from the
+// openssl library, using the input parameters.
+//
+// This is a test function and it skips the message blinding part.
+absl::StatusOr<std::string> EncodeMessageForTests(absl::string_view message,
+ RSAPublicKey public_key,
+ const EVP_MD* sig_hasher,
+ const EVP_MD* mgf1_hasher,
+ int32_t salt_length);
+
+// This method returns a newly generated RSA key pair, setting the public
+// exponent to be the standard RSA_F4 (65537) and the default modulus size to
+// 512 bytes.
+absl::StatusOr<std::pair<RSAPublicKey, RSAPrivateKey>> GetStandardRsaKeyPair(
+ int modulus_size_in_bytes = kRsaModulusSizeInBytes512);
+
+// Method returns fixed 2048-bit strong RSA modulus for testing.
+absl::StatusOr<std::pair<RSAPublicKey, RSAPrivateKey>> GetStrongRsaKeys2048();
+
+// Method returns another fixed 2048-bit strong RSA modulus for testing.
+absl::StatusOr<std::pair<RSAPublicKey, RSAPrivateKey>>
+GetAnotherStrongRsaKeys2048();
+
+// Method returns fixed 3072-bit strong RSA modulus for testing.
+absl::StatusOr<std::pair<RSAPublicKey, RSAPrivateKey>> GetStrongRsaKeys3072();
+
+// Method returns fixed 4096-bit strong RSA modulus for testing.
+absl::StatusOr<std::pair<RSAPublicKey, RSAPrivateKey>> GetStrongRsaKeys4096();
+
+// This method returns a RSA key pair as described in the IETF test example
+// above.
+absl::StatusOr<std::pair<RSAPublicKey, RSAPrivateKey>>
+GetIetfStandardRsaBlindSignatureTestKeys();
+
+// This method returns a RSA key pair as described in the IETF test with Public
+// Metadata example. It can be used for all test vectors returned by
+// GetIetfRsaBlindSignatureWithPublicMetadataTestVectors.
+absl::StatusOr<std::pair<RSAPublicKey, RSAPrivateKey>>
+GetIetfRsaBlindSignatureWithPublicMetadataTestKeys();
+
+} // namespace anonymous_tokens
+} // namespace private_membership
+
+#endif // THIRD_PARTY_ANONYMOUS_TOKENS_CPP_TESTING_PROTO_UTILS_H_
diff --git a/quiche/blind_sign_auth/anonymous_tokens/cpp/testing/utils.cc b/quiche/blind_sign_auth/anonymous_tokens/cpp/testing/utils.cc
index 63fd304..3b48f9a 100644
--- a/quiche/blind_sign_auth/anonymous_tokens/cpp/testing/utils.cc
+++ b/quiche/blind_sign_auth/anonymous_tokens/cpp/testing/utils.cc
@@ -13,16 +13,10 @@
// limitations under the License.
#include "quiche/blind_sign_auth/anonymous_tokens/cpp/testing/utils.h"
-#include <stddef.h>
-#include <stdint.h>
-
-#include <fstream>
-#include <ios>
-#include <memory>
+#include <cstddef>
+#include <cstdint>
#include <random>
-#include <sstream>
#include <string>
-#include <utility>
#include <vector>
#include "absl/status/status.h"
@@ -33,138 +27,15 @@
#include "quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/constants.h"
#include "quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/crypto_utils.h"
#include "quiche/blind_sign_auth/anonymous_tokens/cpp/shared/status_utils.h"
-#include "quiche/blind_sign_auth/anonymous_tokens/proto/anonymous_tokens.pb.h"
#include "quiche/common/platform/api/quiche_file_utils.h"
#include "quiche/common/platform/api/quiche_test.h"
+#include "openssl/base.h"
+#include "openssl/bn.h"
#include "openssl/rsa.h"
namespace private_membership {
namespace anonymous_tokens {
-namespace {
-
-absl::StatusOr<std::string> ReadFileToString(absl::string_view path) {
- std::ifstream file(std::string(path), std::ios::binary);
- if (!file.is_open()) {
- return absl::InternalError("Reading file failed.");
- }
- std::ostringstream ss(std::ios::binary);
- ss << file.rdbuf();
- return ss.str();
-}
-
-absl::StatusOr<std::pair<RSAPublicKey, RSAPrivateKey>> ParseRsaKeysFromFile(
- absl::string_view path) {
- ANON_TOKENS_ASSIGN_OR_RETURN(std::string binary_proto,
- ReadFileToString(path));
- RSAPrivateKey private_key;
- if (!private_key.ParseFromString(binary_proto)) {
- return absl::InternalError("Parsing binary proto failed.");
- }
- RSAPublicKey public_key;
- public_key.set_n(private_key.n());
- public_key.set_e(private_key.e());
- return std::make_pair(std::move(public_key), std::move(private_key));
-}
-
-absl::StatusOr<bssl::UniquePtr<RSA>> GenerateRSAKey(int modulus_bit_size,
- const BIGNUM& e) {
- bssl::UniquePtr<RSA> rsa(RSA_new());
- if (!rsa.get()) {
- return absl::InternalError(
- absl::StrCat("RSA_new failed: ", GetSslErrors()));
- }
- if (RSA_generate_key_ex(rsa.get(), modulus_bit_size, &e,
- /*cb=*/nullptr) != kBsslSuccess) {
- return absl::InternalError(
- absl::StrCat("Error generating private key: ", GetSslErrors()));
- }
- return rsa;
-}
-
-absl::StatusOr<std::pair<RSAPublicKey, RSAPrivateKey>> PopulateTestVectorKeys(
- const std::string& n, const std::string& e, const std::string& d,
- const std::string& p, const std::string& q) {
- RSAPublicKey public_key;
- RSAPrivateKey private_key;
-
- public_key.set_n(n);
- public_key.set_e(e);
-
- private_key.set_n(n);
- private_key.set_e(e);
- private_key.set_d(d);
- private_key.set_p(p);
- private_key.set_q(q);
-
- // Computing CRT parameters
- ANON_TOKENS_ASSIGN_OR_RETURN(BnCtxPtr bn_ctx, GetAndStartBigNumCtx());
- ANON_TOKENS_ASSIGN_OR_RETURN(bssl::UniquePtr<BIGNUM> dp_bn, NewBigNum());
- ANON_TOKENS_ASSIGN_OR_RETURN(bssl::UniquePtr<BIGNUM> dq_bn, NewBigNum());
- ANON_TOKENS_ASSIGN_OR_RETURN(bssl::UniquePtr<BIGNUM> crt_bn, NewBigNum());
-
- // p - 1
- ANON_TOKENS_ASSIGN_OR_RETURN(bssl::UniquePtr<BIGNUM> pm1, StringToBignum(p));
- BN_sub_word(pm1.get(), 1);
- // q - 1
- ANON_TOKENS_ASSIGN_OR_RETURN(bssl::UniquePtr<BIGNUM> qm1, StringToBignum(q));
- BN_sub_word(qm1.get(), 1);
- // d mod p-1
- ANON_TOKENS_ASSIGN_OR_RETURN(bssl::UniquePtr<BIGNUM> d_bn, StringToBignum(d));
- BN_mod(dp_bn.get(), d_bn.get(), pm1.get(), bn_ctx.get());
- // d mod q-1
- BN_mod(dq_bn.get(), d_bn.get(), qm1.get(), bn_ctx.get());
- // crt q^(-1) mod p
- ANON_TOKENS_ASSIGN_OR_RETURN(bssl::UniquePtr<BIGNUM> q_bn, StringToBignum(q));
- ANON_TOKENS_ASSIGN_OR_RETURN(bssl::UniquePtr<BIGNUM> p_bn, StringToBignum(p));
- BN_mod_inverse(crt_bn.get(), q_bn.get(), p_bn.get(), bn_ctx.get());
-
- // Populating crt params in private key
- ANON_TOKENS_ASSIGN_OR_RETURN(
- std::string dp_str, BignumToString(*dp_bn, BN_num_bytes(dp_bn.get())));
- ANON_TOKENS_ASSIGN_OR_RETURN(
- std::string dq_str, BignumToString(*dq_bn, BN_num_bytes(dq_bn.get())));
- ANON_TOKENS_ASSIGN_OR_RETURN(
- std::string crt_str, BignumToString(*crt_bn, BN_num_bytes(crt_bn.get())));
- private_key.set_dp(dp_str);
- private_key.set_dq(dq_str);
- private_key.set_crt(crt_str);
-
- return std::make_pair(std::move(public_key), std::move(private_key));
-}
-
-} // namespace
-
-absl::StatusOr<std::pair<bssl::UniquePtr<RSA>, RSABlindSignaturePublicKey>>
-CreateTestKey(int key_size, HashType sig_hash, MaskGenFunction mfg1_hash,
- int salt_length, MessageMaskType message_mask_type,
- int message_mask_size) {
- ANON_TOKENS_ASSIGN_OR_RETURN(bssl::UniquePtr<BIGNUM> rsa_f4, NewBigNum());
- BN_set_u64(rsa_f4.get(), RSA_F4);
-
- ANON_TOKENS_ASSIGN_OR_RETURN(bssl::UniquePtr<RSA> rsa_key,
- GenerateRSAKey(key_size * 8, *rsa_f4));
-
- RSAPublicKey rsa_public_key;
- ANON_TOKENS_ASSIGN_OR_RETURN(
- *rsa_public_key.mutable_n(),
- BignumToString(*RSA_get0_n(rsa_key.get()), key_size));
- ANON_TOKENS_ASSIGN_OR_RETURN(
- *rsa_public_key.mutable_e(),
- BignumToString(*RSA_get0_e(rsa_key.get()), key_size));
-
- RSABlindSignaturePublicKey public_key;
- public_key.set_serialized_public_key(rsa_public_key.SerializeAsString());
- public_key.set_sig_hash_type(sig_hash);
- public_key.set_mask_gen_function(mfg1_hash);
- public_key.set_salt_length(salt_length);
- public_key.set_key_size(key_size);
- public_key.set_message_mask_type(message_mask_type);
- public_key.set_message_mask_size(message_mask_size);
-
- return std::make_pair(std::move(rsa_key), std::move(public_key));
-}
-
absl::StatusOr<std::string> TestSign(const absl::string_view blinded_data,
RSA* rsa_key) {
if (blinded_data.empty()) {
@@ -268,117 +139,6 @@
return BignumToString(*result, BN_num_bytes(RSA_get0_n(&rsa_key)));
}
-absl::StatusOr<std::string> EncodeMessageForTests(absl::string_view message,
- RSAPublicKey public_key,
- const EVP_MD* sig_hasher,
- const EVP_MD* mgf1_hasher,
- int32_t salt_length) {
- ANON_TOKENS_ASSIGN_OR_RETURN(bssl::UniquePtr<BIGNUM> rsa_modulus,
- StringToBignum(public_key.n()));
- ANON_TOKENS_ASSIGN_OR_RETURN(bssl::UniquePtr<BIGNUM> e,
- StringToBignum(public_key.e()));
- // Convert to OpenSSL RSA.
- bssl::UniquePtr<RSA> rsa_public_key(RSA_new());
- if (!rsa_public_key.get()) {
- return absl::InternalError(
- absl::StrCat("RSA_new failed: ", GetSslErrors()));
- } else if (RSA_set0_key(rsa_public_key.get(), rsa_modulus.release(),
- e.release(), nullptr) != kBsslSuccess) {
- return absl::InternalError(
- absl::StrCat("RSA_set0_key failed: ", GetSslErrors()));
- }
-
- const int padded_len = RSA_size(rsa_public_key.get());
- std::vector<uint8_t> padded(padded_len);
- ANON_TOKENS_ASSIGN_OR_RETURN(std::string digest,
- ComputeHash(message, *sig_hasher));
- if (RSA_padding_add_PKCS1_PSS_mgf1(
- /*rsa=*/rsa_public_key.get(), /*EM=*/padded.data(),
- /*mHash=*/reinterpret_cast<uint8_t*>(&digest[0]), /*Hash=*/sig_hasher,
- /*mgf1Hash=*/mgf1_hasher,
- /*sLen=*/salt_length) != kBsslSuccess) {
- return absl::InternalError(
- "RSA_padding_add_PKCS1_PSS_mgf1 failed when called from "
- "testing_utils");
- }
- std::string encoded_message(padded.begin(), padded.end());
- return encoded_message;
-}
-
-absl::StatusOr<std::pair<RSAPublicKey, RSAPrivateKey>> GetStandardRsaKeyPair(
- int modulus_size_in_bytes) {
- ANON_TOKENS_ASSIGN_OR_RETURN(bssl::UniquePtr<BIGNUM> rsa_f4, NewBigNum());
- BN_set_u64(rsa_f4.get(), RSA_F4);
- ANON_TOKENS_ASSIGN_OR_RETURN(
- bssl::UniquePtr<RSA> rsa_key,
- GenerateRSAKey(modulus_size_in_bytes * 8, *rsa_f4));
-
- RSAPublicKey rsa_public_key;
- ANON_TOKENS_ASSIGN_OR_RETURN(
- *rsa_public_key.mutable_n(),
- BignumToString(*RSA_get0_n(rsa_key.get()), modulus_size_in_bytes));
- ANON_TOKENS_ASSIGN_OR_RETURN(
- *rsa_public_key.mutable_e(),
- BignumToString(*RSA_get0_e(rsa_key.get()), modulus_size_in_bytes));
-
- RSAPrivateKey rsa_private_key;
- ANON_TOKENS_ASSIGN_OR_RETURN(
- *rsa_private_key.mutable_n(),
- BignumToString(*RSA_get0_n(rsa_key.get()), modulus_size_in_bytes));
- ANON_TOKENS_ASSIGN_OR_RETURN(
- *rsa_private_key.mutable_e(),
- BignumToString(*RSA_get0_e(rsa_key.get()), modulus_size_in_bytes));
- ANON_TOKENS_ASSIGN_OR_RETURN(
- *rsa_private_key.mutable_d(),
- BignumToString(*RSA_get0_d(rsa_key.get()), modulus_size_in_bytes));
- ANON_TOKENS_ASSIGN_OR_RETURN(
- *rsa_private_key.mutable_p(),
- BignumToString(*RSA_get0_p(rsa_key.get()), modulus_size_in_bytes));
- ANON_TOKENS_ASSIGN_OR_RETURN(
- *rsa_private_key.mutable_q(),
- BignumToString(*RSA_get0_q(rsa_key.get()), modulus_size_in_bytes));
- ANON_TOKENS_ASSIGN_OR_RETURN(
- *rsa_private_key.mutable_dp(),
- BignumToString(*RSA_get0_dmp1(rsa_key.get()), modulus_size_in_bytes));
- ANON_TOKENS_ASSIGN_OR_RETURN(
- *rsa_private_key.mutable_dq(),
- BignumToString(*RSA_get0_dmq1(rsa_key.get()), modulus_size_in_bytes));
- ANON_TOKENS_ASSIGN_OR_RETURN(
- *rsa_private_key.mutable_crt(),
- BignumToString(*RSA_get0_iqmp(rsa_key.get()), modulus_size_in_bytes));
-
- return std::make_pair(std::move(rsa_public_key), std::move(rsa_private_key));
-}
-
-absl::StatusOr<std::pair<RSAPublicKey, RSAPrivateKey>> GetStrongRsaKeys2048() {
- std::string path = absl::StrCat(quiche::test::QuicheGetCommonSourcePath(),
- "/anonymous_tokens/testdata/strong_rsa_modulus2048_example.binarypb");
- ANON_TOKENS_ASSIGN_OR_RETURN(auto key_pair, ParseRsaKeysFromFile(path));
- return std::make_pair(std::move(key_pair.first), std::move(key_pair.second));
-}
-
-absl::StatusOr<std::pair<RSAPublicKey, RSAPrivateKey>>
-GetAnotherStrongRsaKeys2048() {
- std::string path = absl::StrCat(quiche::test::QuicheGetCommonSourcePath(),
- "/anonymous_tokens/testdata/strong_rsa_modulus2048_example_2.binarypb");
- ANON_TOKENS_ASSIGN_OR_RETURN(auto key_pair, ParseRsaKeysFromFile(path));
- return std::make_pair(std::move(key_pair.first), std::move(key_pair.second));
-}
-
-absl::StatusOr<std::pair<RSAPublicKey, RSAPrivateKey>> GetStrongRsaKeys3072() {
- std::string path = absl::StrCat(quiche::test::QuicheGetCommonSourcePath(),
- "/anonymous_tokens/testdata/strong_rsa_modulus3072_example.binarypb");
- ANON_TOKENS_ASSIGN_OR_RETURN(auto key_pair, ParseRsaKeysFromFile(path));
- return std::make_pair(std::move(key_pair.first), std::move(key_pair.second));
-}
-
-absl::StatusOr<std::pair<RSAPublicKey, RSAPrivateKey>> GetStrongRsaKeys4096() {
- std::string path = absl::StrCat(quiche::test::QuicheGetCommonSourcePath(),
- "/anonymous_tokens/testdata/strong_rsa_modulus4096_example.binarypb");
- ANON_TOKENS_ASSIGN_OR_RETURN(auto key_pair, ParseRsaKeysFromFile(path));
- return std::make_pair(std::move(key_pair.first), std::move(key_pair.second));
-}
-
IetfStandardRsaBlindSignatureTestVector
GetIetfStandardRsaBlindSignatureTestVector() {
IetfStandardRsaBlindSignatureTestVector test_vector = {
@@ -761,22 +521,6 @@
return test_vectors;
}
-absl::StatusOr<std::pair<RSAPublicKey, RSAPrivateKey>>
-GetIetfStandardRsaBlindSignatureTestKeys() {
- IetfStandardRsaBlindSignatureTestVector test_vector =
- GetIetfStandardRsaBlindSignatureTestVector();
- return PopulateTestVectorKeys(test_vector.n, test_vector.e, test_vector.d,
- test_vector.p, test_vector.q);
-}
-
-absl::StatusOr<std::pair<RSAPublicKey, RSAPrivateKey>>
-GetIetfRsaBlindSignatureWithPublicMetadataTestKeys() {
- auto test_vectors = GetIetfRsaBlindSignatureWithPublicMetadataTestVectors();
- return PopulateTestVectorKeys(test_vectors[0].n, test_vectors[0].e,
- test_vectors[0].d, test_vectors[0].p,
- test_vectors[0].q);
-}
-
std::string RandomString(int n, std::uniform_int_distribution<int>* distr_u8,
std::mt19937_64* generator) {
std::string rand(n, 0);
diff --git a/quiche/blind_sign_auth/anonymous_tokens/cpp/testing/utils.h b/quiche/blind_sign_auth/anonymous_tokens/cpp/testing/utils.h
index 5c6aa1c..c2993cd 100644
--- a/quiche/blind_sign_auth/anonymous_tokens/cpp/testing/utils.h
+++ b/quiche/blind_sign_auth/anonymous_tokens/cpp/testing/utils.h
@@ -15,16 +15,11 @@
#ifndef THIRD_PARTY_ANONYMOUS_TOKENS_CPP_TESTING_UTILS_H_
#define THIRD_PARTY_ANONYMOUS_TOKENS_CPP_TESTING_UTILS_H_
-#include <stdint.h>
-
#include <random>
#include <string>
-#include <utility>
#include "absl/status/statusor.h"
#include "absl/strings/string_view.h"
-#include "quiche/blind_sign_auth/anonymous_tokens/cpp/crypto/constants.h"
-#include "quiche/blind_sign_auth/anonymous_tokens/proto/anonymous_tokens.pb.h"
#include "openssl/base.h"
namespace private_membership {
@@ -59,26 +54,6 @@
std::string signature;
};
-// Creates a pair containing a standard RSA Private key and an Anonymous Tokens
-// RSABlindSignaturePublicKey using RSA_F4 (65537) as the public exponent and
-// other input parameters.
-absl::StatusOr<std::pair<bssl::UniquePtr<RSA>, RSABlindSignaturePublicKey>>
-CreateTestKey(int key_size = 512, HashType sig_hash = AT_HASH_TYPE_SHA384,
- MaskGenFunction mfg1_hash = AT_MGF_SHA384, int salt_length = 48,
- MessageMaskType message_mask_type = AT_MESSAGE_MASK_CONCAT,
- int message_mask_size = kRsaMessageMaskSizeInBytes32);
-
-// Prepares message for signing by computing its hash and then applying the PSS
-// padding to the result by executing RSA_padding_add_PKCS1_PSS_mgf1 from the
-// openssl library, using the input parameters.
-//
-// This is a test function and it skips the message blinding part.
-absl::StatusOr<std::string> EncodeMessageForTests(absl::string_view message,
- RSAPublicKey public_key,
- const EVP_MD* sig_hasher,
- const EVP_MD* mgf1_hasher,
- int32_t salt_length);
-
// TestSign can be removed once rsa_blind_signer is moved to
// anonympous_tokens/public/cpp/crypto
absl::StatusOr<std::string> TestSign(absl::string_view blinded_data,
@@ -90,35 +65,11 @@
absl::string_view blinded_data, absl::string_view public_metadata,
const RSA& rsa_key);
-// This method returns a newly generated RSA key pair, setting the public
-// exponent to be the standard RSA_F4 (65537) and the default modulus size to
-// 512 bytes.
-absl::StatusOr<std::pair<RSAPublicKey, RSAPrivateKey>> GetStandardRsaKeyPair(
- int modulus_size_in_bytes = kRsaModulusSizeInBytes512);
-
-// Method returns fixed 2048-bit strong RSA modulus for testing.
-absl::StatusOr<std::pair<RSAPublicKey, RSAPrivateKey>> GetStrongRsaKeys2048();
-
-// Method returns another fixed 2048-bit strong RSA modulus for testing.
-absl::StatusOr<std::pair<RSAPublicKey, RSAPrivateKey>>
-GetAnotherStrongRsaKeys2048();
-
-// Method returns fixed 3072-bit strong RSA modulus for testing.
-absl::StatusOr<std::pair<RSAPublicKey, RSAPrivateKey>> GetStrongRsaKeys3072();
-
-// Method returns fixed 4096-bit strong RSA modulus for testing.
-absl::StatusOr<std::pair<RSAPublicKey, RSAPrivateKey>> GetStrongRsaKeys4096();
-
// Returns the IETF test example from
// https://datatracker.ietf.org/doc/draft-irtf-cfrg-rsa-blind-signatures/
IetfStandardRsaBlindSignatureTestVector
GetIetfStandardRsaBlindSignatureTestVector();
-// This method returns a RSA key pair as described in the IETF test example
-// above.
-absl::StatusOr<std::pair<RSAPublicKey, RSAPrivateKey>>
-GetIetfStandardRsaBlindSignatureTestKeys();
-
// Returns the IETF test with Public Metadata examples from
// https://datatracker.ietf.org/doc/draft-amjad-cfrg-partially-blind-rsa/
//
@@ -126,12 +77,6 @@
std::vector<IetfRsaBlindSignatureWithPublicMetadataTestVector>
GetIetfRsaBlindSignatureWithPublicMetadataTestVectors();
-// This method returns a RSA key pair as described in the IETF test with Public
-// Metadata example. It can be used for all test vectors returned by
-// GetIetfRsaBlindSignatureWithPublicMetadataTestVectors.
-absl::StatusOr<std::pair<RSAPublicKey, RSAPrivateKey>>
-GetIetfRsaBlindSignatureWithPublicMetadataTestKeys();
-
// Outputs a random string of n characters.
std::string RandomString(int n, std::uniform_int_distribution<int>* distr_u8,
std::mt19937_64* generator);
diff --git a/quiche/blind_sign_auth/blind_sign_auth_test.cc b/quiche/blind_sign_auth/blind_sign_auth_test.cc
index 3a5d842..ff1e969 100644
--- a/quiche/blind_sign_auth/blind_sign_auth_test.cc
+++ b/quiche/blind_sign_auth/blind_sign_auth_test.cc
@@ -19,6 +19,7 @@
#include "absl/status/statusor.h"
#include "absl/strings/escaping.h"
#include "absl/strings/string_view.h"
+#include "quiche/blind_sign_auth/anonymous_tokens/cpp/testing/proto_utils.h"
#include "quiche/blind_sign_auth/anonymous_tokens/cpp/testing/utils.h"
#include "quiche/blind_sign_auth/anonymous_tokens/proto/anonymous_tokens.pb.h"
#include "openssl/base.h"