diff options
author | lizatretyakova <lizatretyakova@google.com> | 2021-11-08 03:28:22 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2021-11-08 03:28:56 -0800 |
commit | 80befd7d7404f98890e165aac72853dc8369bae9 (patch) | |
tree | b851fb60a5c884fed97f106734f21b8af87db261 /cc/experimental | |
parent | c454b48e3e52ab8e3191ffc9eb2d6b06d6ce09ab (diff) | |
download | tink-80befd7d7404f98890e165aac72853dc8369bae9.tar.gz |
Replace the deprecated crypto::tink::util::error::INVALID_ARGUMENT usages with its absl version absl::StatusCode::kInvalidArgument in tink/cc/experimental/pqcrypto.
This CL is a part of Tink migration to using absl::Status{,Or} and absl::StatusCode.
PiperOrigin-RevId: 408297585
Diffstat (limited to 'cc/experimental')
28 files changed, 115 insertions, 82 deletions
diff --git a/cc/experimental/pqcrypto/cecpq2/hybrid/BUILD.bazel b/cc/experimental/pqcrypto/cecpq2/hybrid/BUILD.bazel index 68e06e2f5..a27fd7266 100644 --- a/cc/experimental/pqcrypto/cecpq2/hybrid/BUILD.bazel +++ b/cc/experimental/pqcrypto/cecpq2/hybrid/BUILD.bazel @@ -61,6 +61,7 @@ cc_library( hdrs = ["cecpq2_aead_hkdf_private_key_manager.h"], deps = [ ":cecpq2_aead_hkdf_public_key_manager", + "@com_google_absl//absl/status", "@com_google_absl//absl/strings", "@tink_cc//:core/key_type_manager", "@tink_cc//:core/private_key_type_manager", @@ -83,6 +84,7 @@ cc_library( srcs = ["cecpq2_aead_hkdf_public_key_manager.cc"], hdrs = ["cecpq2_aead_hkdf_public_key_manager.h"], deps = [ + "@com_google_absl//absl/status", "@com_google_absl//absl/strings", "@tink_cc//:core/key_type_manager", "@tink_cc//:hybrid_encrypt", @@ -142,6 +144,7 @@ cc_test( copts = ["-Iexternal/gtest/include"], deps = [ ":cecpq2_aead_hkdf_dem_helper", + "@com_google_absl//absl/status", "@com_google_googletest//:gtest_main", "@tink_cc//aead:aes_gcm_key_manager", "@tink_cc//config:tink_config", @@ -158,6 +161,7 @@ cc_test( deps = [ ":cecpq2_aead_hkdf_private_key_manager", ":cecpq2_aead_hkdf_public_key_manager", + "@com_google_absl//absl/status", "@com_google_absl//absl/strings", "@com_google_googletest//:gtest_main", "@tink_cc//:core/key_type_manager", @@ -187,6 +191,7 @@ cc_test( deps = [ ":cecpq2_aead_hkdf_private_key_manager", ":cecpq2_aead_hkdf_public_key_manager", + "@com_google_absl//absl/status", "@com_google_absl//absl/strings", "@com_google_googletest//:gtest_main", "@tink_cc//:core/key_type_manager", diff --git a/cc/experimental/pqcrypto/cecpq2/hybrid/cecpq2_aead_hkdf_dem_helper.cc b/cc/experimental/pqcrypto/cecpq2/hybrid/cecpq2_aead_hkdf_dem_helper.cc index fdb574812..4ddc22097 100644 --- a/cc/experimental/pqcrypto/cecpq2/hybrid/cecpq2_aead_hkdf_dem_helper.cc +++ b/cc/experimental/pqcrypto/cecpq2/hybrid/cecpq2_aead_hkdf_dem_helper.cc @@ -78,7 +78,7 @@ class Cecpq2AeadHkdfDemHelperImpl : public Cecpq2AeadHkdfDemHelper { "type.googleapis.com/google.crypto.tink.XChaCha20Poly1305Key") { return 32; } else { - return ToStatusF(util::error::INVALID_ARGUMENT, + return ToStatusF(absl::StatusCode::kInvalidArgument, "Unsupported DEM key type '%s'.", dem_type_url); } } @@ -102,7 +102,7 @@ Cecpq2AeadHkdfDemHelper::New(const KeyTemplate& dem_key_template) { return {absl::make_unique<Cecpq2AeadHkdfDemHelperImpl<DeterministicAead>>( dem_key_template)}; } - return ToStatusF(util::error::INVALID_ARGUMENT, + return ToStatusF(absl::StatusCode::kInvalidArgument, "Unsupported DEM key type '%s'.", dem_type_url); } diff --git a/cc/experimental/pqcrypto/cecpq2/hybrid/cecpq2_aead_hkdf_dem_helper_test.cc b/cc/experimental/pqcrypto/cecpq2/hybrid/cecpq2_aead_hkdf_dem_helper_test.cc index fd35a6e28..f529ff1d1 100644 --- a/cc/experimental/pqcrypto/cecpq2/hybrid/cecpq2_aead_hkdf_dem_helper_test.cc +++ b/cc/experimental/pqcrypto/cecpq2/hybrid/cecpq2_aead_hkdf_dem_helper_test.cc @@ -18,6 +18,7 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "absl/status/status.h" #include "tink/aead/aes_gcm_key_manager.h" #include "tink/aead/xchacha20_poly1305_key_manager.h" #include "tink/config/tink_config.h" @@ -57,9 +58,9 @@ TEST(Cecpq2AeadHkdfDemHelperTest, InvalidKey) { google::crypto::tink::KeyTemplate dem_key_template; dem_key_template.set_type_url("some.type.url/that.is.not.supported"); auto result = Cecpq2AeadHkdfDemHelper::New(dem_key_template); - EXPECT_THAT( - Cecpq2AeadHkdfDemHelper::New(dem_key_template).status(), - StatusIs(util::error::INVALID_ARGUMENT, HasSubstr("Unsupported DEM"))); + EXPECT_THAT(Cecpq2AeadHkdfDemHelper::New(dem_key_template).status(), + StatusIs(absl::StatusCode::kInvalidArgument, + HasSubstr("Unsupported DEM"))); } TEST(Cecpq2AeadHkdfDemHelperTest, DemHelperWithAesGcmKeyType) { diff --git a/cc/experimental/pqcrypto/cecpq2/hybrid/cecpq2_aead_hkdf_private_key_manager.cc b/cc/experimental/pqcrypto/cecpq2/hybrid/cecpq2_aead_hkdf_private_key_manager.cc index 57b2b31b9..523c658ce 100644 --- a/cc/experimental/pqcrypto/cecpq2/hybrid/cecpq2_aead_hkdf_private_key_manager.cc +++ b/cc/experimental/pqcrypto/cecpq2/hybrid/cecpq2_aead_hkdf_private_key_manager.cc @@ -17,6 +17,7 @@ #include "experimental/pqcrypto/cecpq2/hybrid/cecpq2_aead_hkdf_private_key_manager.h" #include "absl/memory/memory.h" +#include "absl/status/status.h" #include "absl/strings/string_view.h" #include "openssl/hrss.h" #include "experimental/pqcrypto/cecpq2/hybrid/cecpq2_aead_hkdf_public_key_manager.h" @@ -45,7 +46,7 @@ using google::crypto::tink::Cecpq2AeadHkdfPublicKey; Status Cecpq2AeadHkdfPrivateKeyManager::ValidateKeyFormat( const Cecpq2AeadHkdfKeyFormat& key_format) const { if (!key_format.has_params()) { - return Status(util::error::INVALID_ARGUMENT, "Missing params."); + return Status(absl::StatusCode::kInvalidArgument, "Missing params."); } return Cecpq2AeadHkdfPublicKeyManager().ValidateParams(key_format.params()); } @@ -90,7 +91,7 @@ Status Cecpq2AeadHkdfPrivateKeyManager::ValidateKey( Status status = ValidateVersion(key.version(), get_version()); if (!status.ok()) return status; if (!key.has_public_key()) { - return Status(util::error::INVALID_ARGUMENT, "Missing public_key."); + return Status(absl::StatusCode::kInvalidArgument, "Missing public_key."); } return Cecpq2AeadHkdfPublicKeyManager().ValidateKey(key.public_key()); } diff --git a/cc/experimental/pqcrypto/cecpq2/hybrid/cecpq2_aead_hkdf_private_key_manager_test.cc b/cc/experimental/pqcrypto/cecpq2/hybrid/cecpq2_aead_hkdf_private_key_manager_test.cc index f96b71939..afcb5a6c8 100644 --- a/cc/experimental/pqcrypto/cecpq2/hybrid/cecpq2_aead_hkdf_private_key_manager_test.cc +++ b/cc/experimental/pqcrypto/cecpq2/hybrid/cecpq2_aead_hkdf_private_key_manager_test.cc @@ -17,6 +17,7 @@ #include "experimental/pqcrypto/cecpq2/hybrid/cecpq2_aead_hkdf_private_key_manager.h" #include "gtest/gtest.h" +#include "absl/status/status.h" #include "tink/aead/aead_key_templates.h" #include "tink/aead/aes_ctr_hmac_aead_key_manager.h" #include "tink/aead/aes_gcm_key_manager.h" @@ -62,7 +63,7 @@ TEST(Cecpq2AeadHkdfPrivateKeyManagerTest, Basics) { TEST(Cecpq2AeadHkdfPrivateKeyManagerTest, ValidateEmptyKey) { EXPECT_THAT( Cecpq2AeadHkdfPrivateKeyManager().ValidateKey(Cecpq2AeadHkdfPrivateKey()), - StatusIs(util::error::INVALID_ARGUMENT)); + StatusIs(absl::StatusCode::kInvalidArgument)); } Cecpq2AeadHkdfKeyFormat CreateValidKeyFormat() { @@ -88,14 +89,14 @@ TEST(Cecpq2AeadHkdfPrivateKeyManagerTest, ValidateKeyFormatNoPoint) { auto kem_params = key_format.mutable_params()->mutable_kem_params(); kem_params->set_ec_point_format(EcPointFormat::UNKNOWN_FORMAT); EXPECT_THAT(Cecpq2AeadHkdfPrivateKeyManager().ValidateKeyFormat(key_format), - StatusIs(util::error::INVALID_ARGUMENT)); + StatusIs(absl::StatusCode::kInvalidArgument)); } TEST(Cecpq2AeadHkdfPrivateKeyManagerTest, ValidateKeyFormatNoDem) { Cecpq2AeadHkdfKeyFormat key_format = CreateValidKeyFormat(); key_format.mutable_params()->mutable_dem_params()->clear_aead_dem(); EXPECT_THAT(Cecpq2AeadHkdfPrivateKeyManager().ValidateKeyFormat(key_format), - StatusIs(util::error::INVALID_ARGUMENT)); + StatusIs(absl::StatusCode::kInvalidArgument)); } TEST(Cecpq2AeadHkdfPrivateKeyManagerTest, ValidateKeyFormatNoKemCurve) { @@ -103,7 +104,7 @@ TEST(Cecpq2AeadHkdfPrivateKeyManagerTest, ValidateKeyFormatNoKemCurve) { key_format.mutable_params()->mutable_kem_params()->set_curve_type( EllipticCurveType::UNKNOWN_CURVE); EXPECT_THAT(Cecpq2AeadHkdfPrivateKeyManager().ValidateKeyFormat(key_format), - StatusIs(util::error::INVALID_ARGUMENT)); + StatusIs(absl::StatusCode::kInvalidArgument)); } TEST(Cecpq2AeadHkdfPrivateKeyManagerTest, ValidateKeyFormatNoKemHash) { @@ -111,7 +112,7 @@ TEST(Cecpq2AeadHkdfPrivateKeyManagerTest, ValidateKeyFormatNoKemHash) { key_format.mutable_params()->mutable_kem_params()->set_hkdf_hash_type( HashType::UNKNOWN_HASH); EXPECT_THAT(Cecpq2AeadHkdfPrivateKeyManager().ValidateKeyFormat(key_format), - StatusIs(util::error::INVALID_ARGUMENT)); + StatusIs(absl::StatusCode::kInvalidArgument)); } TEST(Cecpq2AeadHkdfPrivateKeyManagerTest, CreateKey) { @@ -148,7 +149,7 @@ Cecpq2AeadHkdfPrivateKey CreateValidKey() { TEST(Cecpq2AeadHkdfPrivateKeyManagerTest, ValidateKeyEmpty) { EXPECT_THAT( Cecpq2AeadHkdfPrivateKeyManager().ValidateKey(Cecpq2AeadHkdfPrivateKey()), - StatusIs(util::error::INVALID_ARGUMENT)); + StatusIs(absl::StatusCode::kInvalidArgument)); } TEST(Cecpq2AeadHkdfPrivateKeyManagerTest, ValidateKey) { @@ -160,7 +161,7 @@ TEST(Cecpq2AeadHkdfPrivateKeyManagerTest, ValidateKeyWrongVersion) { Cecpq2AeadHkdfPrivateKey key = CreateValidKey(); key.set_version(1); EXPECT_THAT(Cecpq2AeadHkdfPrivateKeyManager().ValidateKey(key), - StatusIs(util::error::INVALID_ARGUMENT)); + StatusIs(absl::StatusCode::kInvalidArgument)); } TEST(Cecpq2AeadHkdfPrivateKeyManagerTest, ValidateKeyNoPoint) { @@ -170,7 +171,7 @@ TEST(Cecpq2AeadHkdfPrivateKeyManagerTest, ValidateKeyNoPoint) { ->mutable_kem_params() ->set_ec_point_format(EcPointFormat::UNKNOWN_FORMAT); EXPECT_THAT(Cecpq2AeadHkdfPrivateKeyManager().ValidateKey(key), - StatusIs(util::error::INVALID_ARGUMENT)); + StatusIs(absl::StatusCode::kInvalidArgument)); } TEST(Cecpq2AeadHkdfPrivateKeyManagerTest, ValidateKeyNoDem) { @@ -180,7 +181,7 @@ TEST(Cecpq2AeadHkdfPrivateKeyManagerTest, ValidateKeyNoDem) { ->mutable_dem_params() ->clear_aead_dem(); EXPECT_THAT(Cecpq2AeadHkdfPrivateKeyManager().ValidateKey(key), - StatusIs(util::error::INVALID_ARGUMENT)); + StatusIs(absl::StatusCode::kInvalidArgument)); } TEST(Cecpq2AeadHkdfPrivateKeyManagerTest, ValidateKeyNoKemCurve) { @@ -190,7 +191,7 @@ TEST(Cecpq2AeadHkdfPrivateKeyManagerTest, ValidateKeyNoKemCurve) { ->mutable_kem_params() ->set_curve_type(EllipticCurveType::UNKNOWN_CURVE); EXPECT_THAT(Cecpq2AeadHkdfPrivateKeyManager().ValidateKey(key), - StatusIs(util::error::INVALID_ARGUMENT)); + StatusIs(absl::StatusCode::kInvalidArgument)); } TEST(Cecpq2AeadHkdfPrivateKeyManagerTest, ValidateKeyNoKemHash) { @@ -200,7 +201,7 @@ TEST(Cecpq2AeadHkdfPrivateKeyManagerTest, ValidateKeyNoKemHash) { ->mutable_kem_params() ->set_hkdf_hash_type(HashType::UNKNOWN_HASH); EXPECT_THAT(Cecpq2AeadHkdfPrivateKeyManager().ValidateKey(key), - StatusIs(util::error::INVALID_ARGUMENT)); + StatusIs(absl::StatusCode::kInvalidArgument)); } TEST(Cecpq2AeadHkdfPrivateKeyManagerTest, GetPublicKey) { diff --git a/cc/experimental/pqcrypto/cecpq2/hybrid/cecpq2_aead_hkdf_public_key_manager.cc b/cc/experimental/pqcrypto/cecpq2/hybrid/cecpq2_aead_hkdf_public_key_manager.cc index 33a669a63..36cd27dfb 100644 --- a/cc/experimental/pqcrypto/cecpq2/hybrid/cecpq2_aead_hkdf_public_key_manager.cc +++ b/cc/experimental/pqcrypto/cecpq2/hybrid/cecpq2_aead_hkdf_public_key_manager.cc @@ -16,6 +16,7 @@ #include "experimental/pqcrypto/cecpq2/hybrid/cecpq2_aead_hkdf_public_key_manager.h" +#include "absl/status/status.h" #include "absl/strings/string_view.h" #include "experimental/pqcrypto/cecpq2/hybrid/internal/cecpq2_aead_hkdf_hybrid_encrypt.h" #include "tink/hybrid_encrypt.h" @@ -42,25 +43,27 @@ Status Cecpq2AeadHkdfPublicKeyManager::ValidateParams( const Cecpq2AeadHkdfParams& params) const { // Validate KEM params if (!params.has_kem_params()) { - return Status(util::error::INVALID_ARGUMENT, "Missing kem_params."); + return Status(absl::StatusCode::kInvalidArgument, "Missing kem_params."); } if (params.kem_params().curve_type() == EllipticCurveType::UNKNOWN_CURVE || params.kem_params().curve_type() != EllipticCurveType::CURVE25519 || params.kem_params().hkdf_hash_type() == HashType::UNKNOWN_HASH) { - return Status(util::error::INVALID_ARGUMENT, "Invalid kem_params."); + return Status(absl::StatusCode::kInvalidArgument, "Invalid kem_params."); } // Validate DEM params if (!params.has_dem_params()) { - return Status(util::error::INVALID_ARGUMENT, "Missing dem_params."); + return Status(absl::StatusCode::kInvalidArgument, "Missing dem_params."); } if (!params.dem_params().has_aead_dem()) { - return Status(util::error::INVALID_ARGUMENT, "dem_params has no aead_dem."); + return Status(absl::StatusCode::kInvalidArgument, + "dem_params has no aead_dem."); } // Validate EC point format if (params.kem_params().ec_point_format() == EcPointFormat::UNKNOWN_FORMAT) { - return Status(util::error::INVALID_ARGUMENT, "Unknown EC point format."); + return Status(absl::StatusCode::kInvalidArgument, + "Unknown EC point format."); } return util::OkStatus(); } @@ -70,7 +73,7 @@ Status Cecpq2AeadHkdfPublicKeyManager::ValidateKey( Status status = ValidateVersion(key.version(), get_version()); if (!status.ok()) return status; if (!key.has_params()) { - return Status(util::error::INVALID_ARGUMENT, "Missing params."); + return Status(absl::StatusCode::kInvalidArgument, "Missing params."); } return ValidateParams(key.params()); } diff --git a/cc/experimental/pqcrypto/cecpq2/hybrid/cecpq2_aead_hkdf_public_key_manager_test.cc b/cc/experimental/pqcrypto/cecpq2/hybrid/cecpq2_aead_hkdf_public_key_manager_test.cc index 46d1820b7..95af1398c 100644 --- a/cc/experimental/pqcrypto/cecpq2/hybrid/cecpq2_aead_hkdf_public_key_manager_test.cc +++ b/cc/experimental/pqcrypto/cecpq2/hybrid/cecpq2_aead_hkdf_public_key_manager_test.cc @@ -17,6 +17,7 @@ #include "experimental/pqcrypto/cecpq2/hybrid/cecpq2_aead_hkdf_public_key_manager.h" #include "gtest/gtest.h" +#include "absl/status/status.h" #include "tink/aead/aead_key_templates.h" #include "tink/aead/aes_gcm_key_manager.h" #include "experimental/pqcrypto/cecpq2/hybrid/cecpq2_aead_hkdf_private_key_manager.h" @@ -59,7 +60,7 @@ TEST(Cecpq2AeadHkdfPublicKeyManagerTest, Basics) { TEST(Cecpq2AeadHkdfPublicKeyManagerTest, ValidateEmptyKey) { EXPECT_THAT( Cecpq2AeadHkdfPublicKeyManager().ValidateKey(Cecpq2AeadHkdfPublicKey()), - StatusIs(util::error::INVALID_ARGUMENT)); + StatusIs(absl::StatusCode::kInvalidArgument)); } Cecpq2AeadHkdfPublicKey CreatePublicKey() { @@ -89,28 +90,28 @@ TEST(Cecpq2AeadHkdfPublicKeyManagerTest, ValidateKeyNoPoint) { params.mutable_kem_params()->set_ec_point_format( EcPointFormat::UNKNOWN_FORMAT); EXPECT_THAT(Cecpq2AeadHkdfPublicKeyManager().ValidateParams(params), - StatusIs(util::error::INVALID_ARGUMENT)); + StatusIs(absl::StatusCode::kInvalidArgument)); } TEST(Cecpq2AeadHkdfPublicKeyManagerTest, ValidateKeyNoDem) { Cecpq2AeadHkdfParams params = CreatePublicKey().params(); params.mutable_dem_params()->clear_aead_dem(); EXPECT_THAT(Cecpq2AeadHkdfPublicKeyManager().ValidateParams(params), - StatusIs(util::error::INVALID_ARGUMENT)); + StatusIs(absl::StatusCode::kInvalidArgument)); } TEST(Cecpq2AeadHkdfPublicKeyManagerTest, ValidateKeyNoKemCurve) { Cecpq2AeadHkdfParams params = CreatePublicKey().params(); params.mutable_kem_params()->set_curve_type(EllipticCurveType::UNKNOWN_CURVE); EXPECT_THAT(Cecpq2AeadHkdfPublicKeyManager().ValidateParams(params), - StatusIs(util::error::INVALID_ARGUMENT)); + StatusIs(absl::StatusCode::kInvalidArgument)); } TEST(Cecpq2AeadHkdfPublicKeyManagerTest, ValidateKeyNoKemHash) { Cecpq2AeadHkdfParams params = CreatePublicKey().params(); params.mutable_kem_params()->set_hkdf_hash_type(HashType::UNKNOWN_HASH); EXPECT_THAT(Cecpq2AeadHkdfPublicKeyManager().ValidateParams(params), - StatusIs(util::error::INVALID_ARGUMENT)); + StatusIs(absl::StatusCode::kInvalidArgument)); } TEST(Cecpq2AeadHkdfPublicKeyManagerTest, ValidateGeneratedKey) { diff --git a/cc/experimental/pqcrypto/cecpq2/hybrid/internal/BUILD.bazel b/cc/experimental/pqcrypto/cecpq2/hybrid/internal/BUILD.bazel index 73e59fe65..2378e2b72 100644 --- a/cc/experimental/pqcrypto/cecpq2/hybrid/internal/BUILD.bazel +++ b/cc/experimental/pqcrypto/cecpq2/hybrid/internal/BUILD.bazel @@ -10,6 +10,7 @@ cc_library( hdrs = ["cecpq2_aead_hkdf_hybrid_decrypt.h"], deps = [ "@boringssl//:crypto", + "@com_google_absl//absl/status", "@com_google_absl//absl/strings", "@tink_cc//:hybrid_decrypt", "@tink_cc//experimental/pqcrypto/cecpq2/hybrid:cecpq2_aead_hkdf_dem_helper", @@ -29,6 +30,7 @@ cc_library( srcs = ["cecpq2_aead_hkdf_hybrid_encrypt.cc"], hdrs = ["cecpq2_aead_hkdf_hybrid_encrypt.h"], deps = [ + "@com_google_absl//absl/status", "@com_google_absl//absl/strings", "@tink_cc//:aead", "@tink_cc//:hybrid_encrypt", diff --git a/cc/experimental/pqcrypto/cecpq2/hybrid/internal/cecpq2_aead_hkdf_hybrid_decrypt.cc b/cc/experimental/pqcrypto/cecpq2/hybrid/internal/cecpq2_aead_hkdf_hybrid_decrypt.cc index 21d37141b..83d5b7ed7 100644 --- a/cc/experimental/pqcrypto/cecpq2/hybrid/internal/cecpq2_aead_hkdf_hybrid_decrypt.cc +++ b/cc/experimental/pqcrypto/cecpq2/hybrid/internal/cecpq2_aead_hkdf_hybrid_decrypt.cc @@ -19,6 +19,7 @@ #include <utility> #include "absl/memory/memory.h" +#include "absl/status/status.h" #include "openssl/hrss.h" #include "openssl/nid.h" #include "experimental/pqcrypto/cecpq2/hybrid/cecpq2_aead_hkdf_dem_helper.h" @@ -38,7 +39,7 @@ util::Status Validate( if (key.hrss_private_key_seed().empty() || key.x25519_private_key().empty() || key.public_key().hrss_public_key_marshalled().empty() || key.public_key().x25519_public_key_x().empty()) { - return util::Status(util::error::INVALID_ARGUMENT, + return util::Status(absl::StatusCode::kInvalidArgument, "Invalid Cecpq2AeadHkdfPrivateKeyInternal: missing KEM " "required fields."); } @@ -46,7 +47,7 @@ util::Status Validate( if (key.public_key().params().kem_params().curve_type() == google::crypto::tink::EllipticCurveType::CURVE25519) { if (!key.public_key().x25519_public_key_y().empty()) { - return util::Status(util::error::INVALID_ARGUMENT, + return util::Status(absl::StatusCode::kInvalidArgument, "Invalid Cecpq2AeadHkdfPrivateKeyInternal: has KEM " "unexpected field."); } @@ -54,7 +55,7 @@ util::Status Validate( if (key.public_key().params().kem_params().ec_point_format() != google::crypto::tink::EcPointFormat::COMPRESSED) { return util::Status( - util::error::INVALID_ARGUMENT, + absl::StatusCode::kInvalidArgument, "X25519 only supports compressed elliptic curve points."); } } @@ -100,7 +101,8 @@ util::StatusOr<std::string> Cecpq2AeadHkdfHybridDecrypt::Decrypt( uint32_t cecpq2_header_size = cecpq2_header_size_result.ValueOrDie() + HRSS_CIPHERTEXT_BYTES; if (ciphertext.size() < cecpq2_header_size) { - return util::Status(util::error::INVALID_ARGUMENT, "ciphertext too short"); + return util::Status(absl::StatusCode::kInvalidArgument, + "ciphertext too short"); } // Get the key material size based on the DEM type_url. diff --git a/cc/experimental/pqcrypto/cecpq2/hybrid/internal/cecpq2_aead_hkdf_hybrid_decrypt_test.cc b/cc/experimental/pqcrypto/cecpq2/hybrid/internal/cecpq2_aead_hkdf_hybrid_decrypt_test.cc index a6e25cdbc..f03a80cc4 100644 --- a/cc/experimental/pqcrypto/cecpq2/hybrid/internal/cecpq2_aead_hkdf_hybrid_decrypt_test.cc +++ b/cc/experimental/pqcrypto/cecpq2/hybrid/internal/cecpq2_aead_hkdf_hybrid_decrypt_test.cc @@ -231,7 +231,7 @@ TEST_F(Cecpq2AeadHkdfHybridDecryptTest, InvalidKeyNoFieldsSet) { EXPECT_THAT(Cecpq2AeadHkdfHybridDecrypt::New( google::crypto::tink::Cecpq2AeadHkdfPrivateKey()) .status(), - StatusIs(util::error::INVALID_ARGUMENT, + StatusIs(absl::StatusCode::kInvalidArgument, HasSubstr("missing KEM required fields"))); } @@ -240,7 +240,7 @@ TEST_F(Cecpq2AeadHkdfHybridDecryptTest, InvalidKeyX25519PrivKeyFieldMissing) { CreateValidKey(); recipient_key.set_x25519_private_key(""); EXPECT_THAT(Cecpq2AeadHkdfHybridDecrypt::New(recipient_key).status(), - StatusIs(util::error::INVALID_ARGUMENT, + StatusIs(absl::StatusCode::kInvalidArgument, HasSubstr("missing KEM required fields"))); } @@ -249,7 +249,7 @@ TEST_F(Cecpq2AeadHkdfHybridDecryptTest, InvalidKeyX25519PubKeyFieldMissing) { CreateValidKey(); recipient_key.mutable_public_key()->set_x25519_public_key_x(""); EXPECT_THAT(Cecpq2AeadHkdfHybridDecrypt::New(recipient_key).status(), - StatusIs(util::error::INVALID_ARGUMENT, + StatusIs(absl::StatusCode::kInvalidArgument, HasSubstr("missing KEM required fields"))); } @@ -258,7 +258,7 @@ TEST_F(Cecpq2AeadHkdfHybridDecryptTest, InvalidKeyHrssPrivKeyFieldMissing) { CreateValidKey(); recipient_key.set_hrss_private_key_seed(""); EXPECT_THAT(Cecpq2AeadHkdfHybridDecrypt::New(recipient_key).status(), - StatusIs(util::error::INVALID_ARGUMENT, + StatusIs(absl::StatusCode::kInvalidArgument, HasSubstr("missing KEM required fields"))); } @@ -267,7 +267,7 @@ TEST_F(Cecpq2AeadHkdfHybridDecryptTest, InvalidKeyHrssPubKeyFieldMissing) { CreateValidKey(); recipient_key.mutable_public_key()->set_hrss_public_key_marshalled(""); EXPECT_THAT(Cecpq2AeadHkdfHybridDecrypt::New(recipient_key).status(), - StatusIs(util::error::INVALID_ARGUMENT, + StatusIs(absl::StatusCode::kInvalidArgument, HasSubstr("missing KEM required fields"))); } @@ -301,7 +301,7 @@ TEST_F(Cecpq2AeadHkdfHybridDecryptTest, InvalidKeyUnsupportedDem) { ->mutable_aead_dem() ->set_type_url("some.type.url/that.is.not.supported"); auto result(Cecpq2AeadHkdfHybridDecrypt::New(recipient_key)); - EXPECT_THAT(result.status(), StatusIs(util::error::INVALID_ARGUMENT, + EXPECT_THAT(result.status(), StatusIs(absl::StatusCode::kInvalidArgument, HasSubstr("Unsupported DEM"))); } diff --git a/cc/experimental/pqcrypto/cecpq2/hybrid/internal/cecpq2_aead_hkdf_hybrid_encrypt.cc b/cc/experimental/pqcrypto/cecpq2/hybrid/internal/cecpq2_aead_hkdf_hybrid_encrypt.cc index 754700924..81d79ec98 100644 --- a/cc/experimental/pqcrypto/cecpq2/hybrid/internal/cecpq2_aead_hkdf_hybrid_encrypt.cc +++ b/cc/experimental/pqcrypto/cecpq2/hybrid/internal/cecpq2_aead_hkdf_hybrid_encrypt.cc @@ -17,6 +17,7 @@ #include "experimental/pqcrypto/cecpq2/hybrid/internal/cecpq2_aead_hkdf_hybrid_encrypt.h" #include "absl/memory/memory.h" +#include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "tink/aead.h" #include "tink/util/enums.h" @@ -31,7 +32,7 @@ util::Status Validate( const google::crypto::tink::Cecpq2AeadHkdfPublicKey& key) { if (key.x25519_public_key_x().empty() || key.hrss_public_key_marshalled().empty()) { - return util::Status(util::error::INVALID_ARGUMENT, + return util::Status(absl::StatusCode::kInvalidArgument, "Invalid Cecpq2AeadHkdfPublicKeyInternal: missing KEM " "required fields."); } @@ -40,7 +41,7 @@ util::Status Validate( google::crypto::tink::EllipticCurveType::CURVE25519 && !key.x25519_public_key_y().empty()) { return util::Status( - util::error::INVALID_ARGUMENT, + absl::StatusCode::kInvalidArgument, "Invalid Cecpq2AeadHkdfPublicKeyInternal: has KEM unexpected field."); } diff --git a/cc/experimental/pqcrypto/cecpq2/hybrid/internal/cecpq2_aead_hkdf_hybrid_encrypt_test.cc b/cc/experimental/pqcrypto/cecpq2/hybrid/internal/cecpq2_aead_hkdf_hybrid_encrypt_test.cc index 902ba083c..9005d87ac 100644 --- a/cc/experimental/pqcrypto/cecpq2/hybrid/internal/cecpq2_aead_hkdf_hybrid_encrypt_test.cc +++ b/cc/experimental/pqcrypto/cecpq2/hybrid/internal/cecpq2_aead_hkdf_hybrid_encrypt_test.cc @@ -70,7 +70,7 @@ TEST(Cecpq2AeadHkdfHybridEncryptTest, InvalidKeyNoFieldSet) { auto result = Cecpq2AeadHkdfHybridEncrypt::New( google::crypto::tink::Cecpq2AeadHkdfPublicKey()); EXPECT_THAT(result.status(), - StatusIs(util::error::INVALID_ARGUMENT, + StatusIs(absl::StatusCode::kInvalidArgument, HasSubstr("missing KEM required fields"))); } @@ -79,7 +79,7 @@ TEST(Cecpq2AeadHkdfHybridEncryptTest, InvalidKeySomeFieldsSet) { sender_key.set_x25519_public_key_x(""); auto result(Cecpq2AeadHkdfHybridEncrypt::New(sender_key)); EXPECT_THAT(result.status(), - StatusIs(util::error::INVALID_ARGUMENT, + StatusIs(absl::StatusCode::kInvalidArgument, HasSubstr("missing KEM required fields"))); } @@ -105,7 +105,7 @@ TEST(Cecpq2AeadHkdfHybridEncryptTest, InvalidKeyUnsupportedDemKeyType) { ->mutable_aead_dem() ->set_type_url("some.type.url/that.is.not.supported"); auto result(Cecpq2AeadHkdfHybridEncrypt::New(sender_key)); - EXPECT_THAT(result.status(), StatusIs(util::error::INVALID_ARGUMENT, + EXPECT_THAT(result.status(), StatusIs(absl::StatusCode::kInvalidArgument, HasSubstr("Unsupported DEM key type"))); } diff --git a/cc/experimental/pqcrypto/cecpq2/subtle/BUILD.bazel b/cc/experimental/pqcrypto/cecpq2/subtle/BUILD.bazel index c838e1e01..c2f25beac 100644 --- a/cc/experimental/pqcrypto/cecpq2/subtle/BUILD.bazel +++ b/cc/experimental/pqcrypto/cecpq2/subtle/BUILD.bazel @@ -61,6 +61,7 @@ cc_test( ":cecpq2_hkdf_sender_kem_boringssl", ":cecpq2_subtle_boringssl_util", "@boringssl//:crypto", + "@com_google_absl//absl/status", "@com_google_googletest//:gtest_main", "@tink_cc//config:tink_fips", "@tink_cc//subtle:random", @@ -78,6 +79,7 @@ cc_test( ":cecpq2_hkdf_recipient_kem_boringssl", ":cecpq2_subtle_boringssl_util", "@boringssl//:crypto", + "@com_google_absl//absl/status", "@com_google_googletest//:gtest_main", "@tink_cc//config:tink_fips", "@tink_cc//subtle:random", diff --git a/cc/experimental/pqcrypto/cecpq2/subtle/cecpq2_hkdf_recipient_kem_boringssl.cc b/cc/experimental/pqcrypto/cecpq2/subtle/cecpq2_hkdf_recipient_kem_boringssl.cc index d8d11aecc..6eaf613fd 100644 --- a/cc/experimental/pqcrypto/cecpq2/subtle/cecpq2_hkdf_recipient_kem_boringssl.cc +++ b/cc/experimental/pqcrypto/cecpq2/subtle/cecpq2_hkdf_recipient_kem_boringssl.cc @@ -62,11 +62,11 @@ Cecpq2HkdfX25519RecipientKemBoringSsl::New( // Basic input checking if (curve != CURVE25519) { - return util::Status(util::error::INVALID_ARGUMENT, + return util::Status(absl::StatusCode::kInvalidArgument, "curve is not CURVE25519"); } if (ec_private_key.size() != X25519_PRIVATE_KEY_LEN) { - return util::Status(util::error::INVALID_ARGUMENT, + return util::Status(absl::StatusCode::kInvalidArgument, "priv has unexpected length"); } // If all input parameters are ok, create a CECPQ2 Recipient KEM instance @@ -82,15 +82,15 @@ Cecpq2HkdfX25519RecipientKemBoringSsl::GenerateKey( // Basic input checking if (point_format != EcPointFormat::COMPRESSED) { return util::Status( - util::error::INVALID_ARGUMENT, + absl::StatusCode::kInvalidArgument, "X25519 only supports compressed elliptic curve points"); } if (kem_bytes.size() != X25519_PUBLIC_VALUE_LEN + HRSS_PUBLIC_KEY_BYTES) { - return util::Status(util::error::INVALID_ARGUMENT, + return util::Status(absl::StatusCode::kInvalidArgument, "kem_bytes has unexpected size"); } if (key_size_in_bytes < 32) { - return util::Status(util::error::INVALID_ARGUMENT, + return util::Status(absl::StatusCode::kInvalidArgument, "key size length is smaller than 32 bytes " "and thus not post-quantum secure."); } diff --git a/cc/experimental/pqcrypto/cecpq2/subtle/cecpq2_hkdf_recipient_kem_boringssl_test.cc b/cc/experimental/pqcrypto/cecpq2/subtle/cecpq2_hkdf_recipient_kem_boringssl_test.cc index a9037ce6e..9ef165966 100644 --- a/cc/experimental/pqcrypto/cecpq2/subtle/cecpq2_hkdf_recipient_kem_boringssl_test.cc +++ b/cc/experimental/pqcrypto/cecpq2/subtle/cecpq2_hkdf_recipient_kem_boringssl_test.cc @@ -18,6 +18,7 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "absl/status/status.h" #include "openssl/curve25519.h" #include "openssl/hrss.h" #include "tink/config/tink_fips.h" @@ -190,7 +191,7 @@ TEST(Cecpq2HkdfRecipientKemBoringSslTest, TestNotPostQuantumSecureKeyLength) { test::HexDecodeOrDie(kSaltHex), test::HexDecodeOrDie(kInfoHex), out_len, EcPointFormat::COMPRESSED); EXPECT_THAT(kem_key_or.status(), - StatusIs(util::error::INVALID_ARGUMENT, + StatusIs(absl::StatusCode::kInvalidArgument, HasSubstr("not post-quantum secure"))); } diff --git a/cc/experimental/pqcrypto/cecpq2/subtle/cecpq2_hkdf_sender_kem_boringssl.cc b/cc/experimental/pqcrypto/cecpq2/subtle/cecpq2_hkdf_sender_kem_boringssl.cc index aeef7f122..2fd87c374 100644 --- a/cc/experimental/pqcrypto/cecpq2/subtle/cecpq2_hkdf_sender_kem_boringssl.cc +++ b/cc/experimental/pqcrypto/cecpq2/subtle/cecpq2_hkdf_sender_kem_boringssl.cc @@ -69,18 +69,19 @@ Cecpq2HkdfX25519SenderKemBoringSsl::New( // Basic input checking if (curve != CURVE25519) { - return util::Status(util::error::INVALID_ARGUMENT, + return util::Status(absl::StatusCode::kInvalidArgument, "curve is not CURVE25519"); } if (pubx.size() != X25519_PUBLIC_VALUE_LEN) { - return util::Status(util::error::INVALID_ARGUMENT, + return util::Status(absl::StatusCode::kInvalidArgument, "pubx has unexpected length"); } if (!puby.empty()) { - return util::Status(util::error::INVALID_ARGUMENT, "puby is not empty"); + return util::Status(absl::StatusCode::kInvalidArgument, + "puby is not empty"); } if (marshalled_hrss_pub.size() != HRSS_PUBLIC_KEY_BYTES) { - return util::Status(util::error::INVALID_ARGUMENT, + return util::Status(absl::StatusCode::kInvalidArgument, "marshalled_hrss_pub has unexpected length"); } @@ -98,11 +99,11 @@ Cecpq2HkdfX25519SenderKemBoringSsl::GenerateKey( // Basic input validation: if (point_format != EcPointFormat::COMPRESSED) { return util::Status( - util::error::INVALID_ARGUMENT, + absl::StatusCode::kInvalidArgument, "X25519 only supports compressed elliptic curve points"); } if (key_size_in_bytes < 32) { - return util::Status(util::error::INVALID_ARGUMENT, + return util::Status(absl::StatusCode::kInvalidArgument, "key size length is smaller than 32 bytes " "and thus not post-quantum secure."); } diff --git a/cc/experimental/pqcrypto/cecpq2/subtle/cecpq2_hkdf_sender_kem_boringssl_test.cc b/cc/experimental/pqcrypto/cecpq2/subtle/cecpq2_hkdf_sender_kem_boringssl_test.cc index a593c0d4e..17111386e 100644 --- a/cc/experimental/pqcrypto/cecpq2/subtle/cecpq2_hkdf_sender_kem_boringssl_test.cc +++ b/cc/experimental/pqcrypto/cecpq2/subtle/cecpq2_hkdf_sender_kem_boringssl_test.cc @@ -18,6 +18,7 @@ #include "gtest/gtest.h" #include "absl/memory/memory.h" +#include "absl/status/status.h" #include "openssl/curve25519.h" #include "openssl/hrss.h" #include "openssl/sha.h" @@ -127,7 +128,7 @@ TEST(Cecpq2HkdfSenderKemBoringSslTest, TestNotPostQuantumSecureKeyLength) { test::HexDecodeOrDie(info_hex), out_len, EcPointFormat::COMPRESSED); EXPECT_THAT(status_or_kem_key.status(), - StatusIs(util::error::INVALID_ARGUMENT, + StatusIs(absl::StatusCode::kInvalidArgument, HasSubstr("not post-quantum secure"))); } diff --git a/cc/experimental/pqcrypto/signature/dilithium_sign_key_manager.cc b/cc/experimental/pqcrypto/signature/dilithium_sign_key_manager.cc index c0c3829ef..e79b286de 100644 --- a/cc/experimental/pqcrypto/signature/dilithium_sign_key_manager.cc +++ b/cc/experimental/pqcrypto/signature/dilithium_sign_key_manager.cc @@ -17,6 +17,7 @@ #include "tink/experimental/pqcrypto/signature/dilithium_sign_key_manager.h" #include "absl/memory/memory.h" +#include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" #include "tink/experimental/pqcrypto/signature/dilithium_verify_key_manager.h" @@ -101,7 +102,7 @@ Status DilithiumSignKeyManager::ValidateKey( PQCLEAN_DILITHIUM3_AVX2_CRYPTO_SECRETKEYBYTES && key.key_value().length() != PQCLEAN_DILITHIUM5_AVX2_CRYPTO_SECRETKEYBYTES) { - return Status(util::error::INVALID_ARGUMENT, + return Status(absl::StatusCode::kInvalidArgument, "Invalid dilithium private key size."); } @@ -111,7 +112,7 @@ Status DilithiumSignKeyManager::ValidateKey( Status DilithiumSignKeyManager::ValidateKeyFormat( const DilithiumKeyFormat& key_format) const { if (!key_format.has_params()) { - return Status(util::error::INVALID_ARGUMENT, "Missing params."); + return Status(absl::StatusCode::kInvalidArgument, "Missing params."); } return DilithiumVerifyKeyManager().ValidateParams(key_format.params()); diff --git a/cc/experimental/pqcrypto/signature/dilithium_verify_key_manager.cc b/cc/experimental/pqcrypto/signature/dilithium_verify_key_manager.cc index dbfcf2805..a0ae617ea 100644 --- a/cc/experimental/pqcrypto/signature/dilithium_verify_key_manager.cc +++ b/cc/experimental/pqcrypto/signature/dilithium_verify_key_manager.cc @@ -17,6 +17,7 @@ #include "tink/experimental/pqcrypto/signature/dilithium_verify_key_manager.h" #include "absl/memory/memory.h" +#include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" #include "tink/experimental/pqcrypto/signature/subtle/dilithium_avx2_verify.h" @@ -72,7 +73,7 @@ Status DilithiumVerifyKeyManager::ValidateKey( PQCLEAN_DILITHIUM3_AVX2_CRYPTO_PUBLICKEYBYTES && key.key_value().length() != PQCLEAN_DILITHIUM5_AVX2_CRYPTO_PUBLICKEYBYTES) { - return Status(util::error::INVALID_ARGUMENT, + return Status(absl::StatusCode::kInvalidArgument, "Invalid dilithium public key size."); } return util::OkStatus(); @@ -86,7 +87,8 @@ Status DilithiumVerifyKeyManager::ValidateParams( break; } default: { - return Status(util::error::INVALID_ARGUMENT, "Invalid seed expansion"); + return Status(absl::StatusCode::kInvalidArgument, + "Invalid seed expansion"); } } @@ -97,7 +99,7 @@ Status DilithiumVerifyKeyManager::ValidateParams( break; } default: { - return Status(util::error::INVALID_ARGUMENT, "Invalid key size."); + return Status(absl::StatusCode::kInvalidArgument, "Invalid key size."); } } diff --git a/cc/experimental/pqcrypto/signature/sphincs_sign_key_manager.cc b/cc/experimental/pqcrypto/signature/sphincs_sign_key_manager.cc index b20ef6a99..c481ae418 100644 --- a/cc/experimental/pqcrypto/signature/sphincs_sign_key_manager.cc +++ b/cc/experimental/pqcrypto/signature/sphincs_sign_key_manager.cc @@ -17,6 +17,7 @@ #include "tink/experimental/pqcrypto/signature/sphincs_sign_key_manager.h" #include "absl/memory/memory.h" +#include "absl/status/status.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" #include "tink/experimental/pqcrypto/signature/sphincs_verify_key_manager.h" @@ -113,7 +114,7 @@ Status SphincsSignKeyManager::ValidateKey(const SphincsPrivateKey& key) const { Status SphincsSignKeyManager::ValidateKeyFormat( const SphincsKeyFormat& key_format) const { if (!key_format.has_params()) { - return Status(util::error::INVALID_ARGUMENT, "Missing params."); + return Status(absl::StatusCode::kInvalidArgument, "Missing params."); } return SphincsVerifyKeyManager().ValidateParams(key_format.params()); diff --git a/cc/experimental/pqcrypto/signature/subtle/dilithium_avx2_sign.cc b/cc/experimental/pqcrypto/signature/subtle/dilithium_avx2_sign.cc index 80753c95a..ff0fca680 100644 --- a/cc/experimental/pqcrypto/signature/subtle/dilithium_avx2_sign.cc +++ b/cc/experimental/pqcrypto/signature/subtle/dilithium_avx2_sign.cc @@ -56,7 +56,7 @@ util::StatusOr<std::unique_ptr<PublicKeySign>> DilithiumAvx2Sign::New( key_size != PQCLEAN_DILITHIUM3_AVX2_CRYPTO_SECRETKEYBYTES && key_size != PQCLEAN_DILITHIUM5_AVX2_CRYPTO_SECRETKEYBYTES) { return util::Status( - util::error::INVALID_ARGUMENT, + absl::StatusCode::kInvalidArgument, absl::StrFormat("Invalid private key size (%d). " "The only valid sizes are %d, %d, %d.", private_key.GetKeyData().size(), diff --git a/cc/experimental/pqcrypto/signature/subtle/dilithium_avx2_verify.cc b/cc/experimental/pqcrypto/signature/subtle/dilithium_avx2_verify.cc index 23e4bf2a1..a427d45d0 100644 --- a/cc/experimental/pqcrypto/signature/subtle/dilithium_avx2_verify.cc +++ b/cc/experimental/pqcrypto/signature/subtle/dilithium_avx2_verify.cc @@ -55,7 +55,7 @@ util::StatusOr<std::unique_ptr<PublicKeyVerify>> DilithiumAvx2Verify::New( key_size != PQCLEAN_DILITHIUM3_AVX2_CRYPTO_PUBLICKEYBYTES && key_size != PQCLEAN_DILITHIUM5_AVX2_CRYPTO_PUBLICKEYBYTES) { return util::Status( - util::error::INVALID_ARGUMENT, + absl::StatusCode::kInvalidArgument, absl::StrFormat("Invalid public key size (%d). " "The only valid sizes are %d, %d, %d.", key_size, PQCLEAN_DILITHIUM2_AVX2_CRYPTO_PUBLICKEYBYTES, @@ -159,7 +159,7 @@ util::Status DilithiumAvx2Verify::Verify(absl::string_view signature, } if (result != 0) { - return util::Status(util::error::INVALID_ARGUMENT, + return util::Status(absl::StatusCode::kInvalidArgument, "Signature is not valid."); } diff --git a/cc/experimental/pqcrypto/signature/subtle/dilithium_key.cc b/cc/experimental/pqcrypto/signature/subtle/dilithium_key.cc index 39aec41ad..12f940ec7 100644 --- a/cc/experimental/pqcrypto/signature/subtle/dilithium_key.cc +++ b/cc/experimental/pqcrypto/signature/subtle/dilithium_key.cc @@ -20,6 +20,7 @@ #include <utility> #include "absl/memory/memory.h" +#include "absl/status/status.h" #include "absl/strings/str_format.h" #include "tink/util/secret_data.h" #include "tink/util/statusor.h" @@ -72,7 +73,7 @@ DilithiumPrivateKeyPqclean::GenerateKeyPair( break; } default: { - return util::Status(util::error::INVALID_ARGUMENT, + return util::Status(absl::StatusCode::kInvalidArgument, "Invalid seed expansion"); } } @@ -96,7 +97,7 @@ DilithiumPrivateKeyPqclean::GenerateKeyPair( break; } default: { - return util::Status(util::error::INVALID_ARGUMENT, + return util::Status(absl::StatusCode::kInvalidArgument, "Invalid seed expansion"); } } @@ -120,7 +121,7 @@ DilithiumPrivateKeyPqclean::GenerateKeyPair( break; } default: { - return util::Status(util::error::INVALID_ARGUMENT, + return util::Status(absl::StatusCode::kInvalidArgument, "Invalid seed expansion"); } } @@ -129,7 +130,7 @@ DilithiumPrivateKeyPqclean::GenerateKeyPair( // Invalid key size. default: { return util::Status( - util::error::INVALID_ARGUMENT, + absl::StatusCode::kInvalidArgument, absl::StrFormat("Invalid private key size (%d). " "The only valid sizes are %d, %d, %d.", private_key_size, diff --git a/cc/experimental/pqcrypto/signature/subtle/falcon_sign.cc b/cc/experimental/pqcrypto/signature/subtle/falcon_sign.cc index 87aa05379..ed0e8ce78 100644 --- a/cc/experimental/pqcrypto/signature/subtle/falcon_sign.cc +++ b/cc/experimental/pqcrypto/signature/subtle/falcon_sign.cc @@ -74,7 +74,8 @@ util::StatusOr<std::string> FalconSign::Sign(absl::string_view data) const { break; } default: - return util::Status(util::error::INVALID_ARGUMENT, "Invalid keysize."); + return util::Status(absl::StatusCode::kInvalidArgument, + "Invalid keysize."); } if (result != 0) { diff --git a/cc/experimental/pqcrypto/signature/subtle/falcon_subtle_utils.cc b/cc/experimental/pqcrypto/signature/subtle/falcon_subtle_utils.cc index 16fa60bb5..13e2a4df7 100644 --- a/cc/experimental/pqcrypto/signature/subtle/falcon_subtle_utils.cc +++ b/cc/experimental/pqcrypto/signature/subtle/falcon_subtle_utils.cc @@ -85,7 +85,7 @@ crypto::tink::util::StatusOr<FalconKeyPair> GenerateFalconKeyPair( // Invalid key size. default: { return util::Status( - util::error::INVALID_ARGUMENT, + absl::StatusCode::kInvalidArgument, absl::StrFormat("Invalid private key size (%d). " "The only valid sizes are %d, %d", private_key_size, kFalcon512PrivateKeySize, @@ -116,7 +116,7 @@ crypto::tink::util::Status ValidateFalconPrivateKeySize(int32_t key_size) { case kFalcon1024PrivateKeySize: return util::Status::OK; default: - return util::Status(util::error::INVALID_ARGUMENT, + return util::Status(absl::StatusCode::kInvalidArgument, absl::StrFormat("Invalid private key size (%d). " "The only valid sizes are %d, %d", key_size, kFalcon512PrivateKeySize, @@ -130,7 +130,7 @@ crypto::tink::util::Status ValidateFalconPublicKeySize(int32_t key_size) { case kFalcon1024PublicKeySize: return util::Status::OK; default: - return util::Status(util::error::INVALID_ARGUMENT, + return util::Status(absl::StatusCode::kInvalidArgument, absl::StrFormat("Invalid public key size (%d). " "The only valid sizes are %d, %d", key_size, kFalcon512PublicKeySize, diff --git a/cc/experimental/pqcrypto/signature/subtle/falcon_verify.cc b/cc/experimental/pqcrypto/signature/subtle/falcon_verify.cc index 41367b47f..4c45fec3f 100644 --- a/cc/experimental/pqcrypto/signature/subtle/falcon_verify.cc +++ b/cc/experimental/pqcrypto/signature/subtle/falcon_verify.cc @@ -66,7 +66,8 @@ util::Status FalconVerify::Verify(absl::string_view signature, break; } default: - return util::Status(util::error::INVALID_ARGUMENT, "Invalid keysize."); + return util::Status(absl::StatusCode::kInvalidArgument, + "Invalid keysize."); } if (result != 0) { diff --git a/cc/experimental/pqcrypto/signature/subtle/sphincs_subtle_utils.cc b/cc/experimental/pqcrypto/signature/subtle/sphincs_subtle_utils.cc index 2460a4d71..dff656593 100644 --- a/cc/experimental/pqcrypto/signature/subtle/sphincs_subtle_utils.cc +++ b/cc/experimental/pqcrypto/signature/subtle/sphincs_subtle_utils.cc @@ -77,7 +77,7 @@ crypto::tink::util::Status ValidatePrivateKeySize(int32 key_size) { return util::OkStatus(); default: return util::Status( - util::error::INVALID_ARGUMENT, + absl::StatusCode::kInvalidArgument, absl::StrFormat("Invalid private key size (%d). " "The only valid sizes are %d, %d, %d.", key_size, kSphincsPrivateKeySize64, @@ -93,7 +93,7 @@ crypto::tink::util::Status ValidatePublicKeySize(int32 key_size) { return util::OkStatus(); default: return util::Status( - util::error::INVALID_ARGUMENT, + absl::StatusCode::kInvalidArgument, absl::StrFormat("Invalid private key size (%d). " "The only valid sizes are %d, %d, %d.", key_size, kSphincsPublicKeySize32, @@ -110,7 +110,8 @@ crypto::tink::util::StatusOr<int32> SphincsKeySizeToIndex(int32 key_size) { case kSphincsPrivateKeySize128: return 2; default: - return util::Status(util::error::INVALID_ARGUMENT, "Invalid key size"); + return util::Status(absl::StatusCode::kInvalidArgument, + "Invalid key size"); } } @@ -122,7 +123,8 @@ crypto::tink::util::Status ValidateParams(SphincsParamsPqclean params) { break; } default: { - return util::Status(util::error::INVALID_ARGUMENT, "Invalid hash type"); + return util::Status(absl::StatusCode::kInvalidArgument, + "Invalid hash type"); } } @@ -132,7 +134,8 @@ crypto::tink::util::Status ValidateParams(SphincsParamsPqclean params) { break; } default: { - return util::Status(util::error::INVALID_ARGUMENT, "Invalid variant"); + return util::Status(absl::StatusCode::kInvalidArgument, + "Invalid variant"); } } @@ -142,7 +145,7 @@ crypto::tink::util::Status ValidateParams(SphincsParamsPqclean params) { break; } default: { - return util::Status(util::error::INVALID_ARGUMENT, + return util::Status(absl::StatusCode::kInvalidArgument, "Invalid signature type"); } } diff --git a/cc/experimental/pqcrypto/signature/subtle/sphincs_verify.cc b/cc/experimental/pqcrypto/signature/subtle/sphincs_verify.cc index 528c93728..88379fa1d 100644 --- a/cc/experimental/pqcrypto/signature/subtle/sphincs_verify.cc +++ b/cc/experimental/pqcrypto/signature/subtle/sphincs_verify.cc @@ -20,6 +20,7 @@ #include <utility> #include "absl/memory/memory.h" +#include "absl/status/status.h" #include "absl/strings/str_format.h" #include "tink/experimental/pqcrypto/signature/subtle/sphincs_helper_pqclean.h" #include "tink/experimental/pqcrypto/signature/subtle/sphincs_subtle_utils.h" @@ -67,7 +68,7 @@ util::Status SphincsVerify::Verify(absl::string_view signature, reinterpret_cast<const uint8_t *>(signature.data()), signature.size(), reinterpret_cast<const uint8_t *>(data.data()), data.size(), reinterpret_cast<const uint8_t *>(key_.GetKey().data()))) != 0) { - return util::Status(util::error::INVALID_ARGUMENT, + return util::Status(absl::StatusCode::kInvalidArgument, "Signature is not valid."); } |