Skip to content

Commit

Permalink
Move AddHybridV0() to hybrid/internal/.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 575942022
Change-Id: I34055e26a8a4bd265e792d94f53daa0f8b7ee47d
  • Loading branch information
cindylindeed authored and copybara-github committed Oct 23, 2023
1 parent 7419feb commit 00e4b50
Show file tree
Hide file tree
Showing 11 changed files with 431 additions and 71 deletions.
12 changes: 2 additions & 10 deletions tink/config/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,7 @@ cc_library(
"//tink:configuration",
"//tink/aead/internal:config_v0",
"//tink/daead/internal:config_v0",
"//tink/hybrid:ecies_aead_hkdf_private_key_manager",
"//tink/hybrid:ecies_aead_hkdf_public_key_manager",
"//tink/hybrid:hybrid_decrypt_wrapper",
"//tink/hybrid:hybrid_encrypt_wrapper",
"//tink/hybrid/internal:hpke_private_key_manager",
"//tink/hybrid/internal:hpke_public_key_manager",
"//tink/hybrid/internal:config_v0",
"//tink/internal:configuration_impl",
"//tink/mac/internal:config_v0",
"//tink/prf/internal:config_v0",
Expand All @@ -159,10 +154,7 @@ cc_library(
"//tink/aead:aes_gcm_siv_key_manager",
"//tink/aead:xchacha20_poly1305_key_manager",
"//tink/daead/internal:key_gen_config_v0",
"//tink/hybrid:ecies_aead_hkdf_private_key_manager",
"//tink/hybrid:ecies_aead_hkdf_public_key_manager",
"//tink/hybrid/internal:hpke_private_key_manager",
"//tink/hybrid/internal:hpke_public_key_manager",
"//tink/hybrid/internal:key_gen_config_v0",
"//tink/internal:key_gen_configuration_impl",
"//tink/mac/internal:key_gen_config_v0",
"//tink/prf/internal:key_gen_config_v0",
Expand Down
12 changes: 2 additions & 10 deletions tink/config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,7 @@ tink_cc_library(
tink::core::configuration
tink::aead::internal::config_v0
tink::daead::internal::config_v0
tink::hybrid::ecies_aead_hkdf_private_key_manager
tink::hybrid::ecies_aead_hkdf_public_key_manager
tink::hybrid::hybrid_decrypt_wrapper
tink::hybrid::hybrid_encrypt_wrapper
tink::hybrid::internal::hpke_private_key_manager
tink::hybrid::internal::hpke_public_key_manager
tink::hybrid::internal::config_v0
tink::internal::configuration_impl
tink::mac::internal::config_v0
tink::prf::internal::config_v0
Expand All @@ -144,10 +139,7 @@ tink_cc_library(
tink::aead::aes_gcm_siv_key_manager
tink::aead::xchacha20_poly1305_key_manager
tink::daead::internal::key_gen_config_v0
tink::hybrid::ecies_aead_hkdf_private_key_manager
tink::hybrid::ecies_aead_hkdf_public_key_manager
tink::hybrid::internal::hpke_private_key_manager
tink::hybrid::internal::hpke_public_key_manager
tink::hybrid::internal::key_gen_config_v0
tink::internal::key_gen_configuration_impl
tink::mac::internal::key_gen_config_v0
tink::prf::internal::key_gen_config_v0
Expand Down
20 changes: 2 additions & 18 deletions tink/config/key_gen_v0.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
#include "tink/aead/aes_gcm_siv_key_manager.h"
#include "tink/aead/xchacha20_poly1305_key_manager.h"
#include "tink/daead/internal/key_gen_config_v0.h"
#include "tink/hybrid/ecies_aead_hkdf_private_key_manager.h"
#include "tink/hybrid/ecies_aead_hkdf_public_key_manager.h"
#include "tink/hybrid/internal/hpke_private_key_manager.h"
#include "tink/hybrid/internal/hpke_public_key_manager.h"
#include "tink/hybrid/internal/key_gen_config_v0.h"
#include "tink/internal/key_gen_configuration_impl.h"
#include "tink/mac/internal/key_gen_config_v0.h"
#include "tink/prf/internal/key_gen_config_v0.h"
Expand Down Expand Up @@ -62,19 +59,6 @@ util::Status AddAead(KeyGenConfiguration& config) {
absl::make_unique<XChaCha20Poly1305KeyManager>(), config);
}

util::Status AddHybrid(KeyGenConfiguration& config) {
util::Status status =
internal::KeyGenConfigurationImpl::AddAsymmetricKeyManagers(
absl::make_unique<EciesAeadHkdfPrivateKeyManager>(),
absl::make_unique<EciesAeadHkdfPublicKeyManager>(), config);
if (!status.ok()) {
return status;
}
return internal::KeyGenConfigurationImpl::AddAsymmetricKeyManagers(
absl::make_unique<internal::HpkePrivateKeyManager>(),
absl::make_unique<internal::HpkePublicKeyManager>(), config);
}

} // namespace

const KeyGenConfiguration& KeyGenConfigV0() {
Expand All @@ -84,7 +68,7 @@ const KeyGenConfiguration& KeyGenConfigV0() {
CHECK_OK(AddAead(*config));
CHECK_OK(internal::AddDeterministicAeadKeyGenV0(*config));
CHECK_OK(internal::AddStreamingAeadV0(*config));
CHECK_OK(AddHybrid(*config));
CHECK_OK(internal::AddHybridKeyGenConfigV0(*config));
CHECK_OK(internal::AddPrfKeyGenV0(*config));
CHECK_OK(internal::AddSignatureKeyGenV0(*config));
return config;
Expand Down
35 changes: 2 additions & 33 deletions tink/config/v0.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@
#include "tink/aead/internal/config_v0.h"
#include "tink/configuration.h"
#include "tink/daead/internal/config_v0.h"
#include "tink/hybrid/ecies_aead_hkdf_private_key_manager.h"
#include "tink/hybrid/ecies_aead_hkdf_public_key_manager.h"
#include "tink/hybrid/hybrid_decrypt_wrapper.h"
#include "tink/hybrid/hybrid_encrypt_wrapper.h"
#include "tink/hybrid/internal/hpke_private_key_manager.h"
#include "tink/hybrid/internal/hpke_public_key_manager.h"
#include "tink/hybrid/internal/config_v0.h"
#include "tink/internal/configuration_impl.h"
#include "tink/mac/internal/config_v0.h"
#include "tink/prf/internal/config_v0.h"
Expand All @@ -34,32 +29,6 @@

namespace crypto {
namespace tink {
namespace {

util::Status AddHybrid(Configuration& config) {
util::Status status = internal::ConfigurationImpl::AddPrimitiveWrapper(
absl::make_unique<HybridEncryptWrapper>(), config);
if (!status.ok()) {
return status;
}
status = internal::ConfigurationImpl::AddPrimitiveWrapper(
absl::make_unique<HybridDecryptWrapper>(), config);
if (!status.ok()) {
return status;
}

status = internal::ConfigurationImpl::AddAsymmetricKeyManagers(
absl::make_unique<EciesAeadHkdfPrivateKeyManager>(),
absl::make_unique<EciesAeadHkdfPublicKeyManager>(), config);
if (!status.ok()) {
return status;
}
return internal::ConfigurationImpl::AddAsymmetricKeyManagers(
absl::make_unique<internal::HpkePrivateKeyManager>(),
absl::make_unique<internal::HpkePublicKeyManager>(), config);
}

} // namespace

const Configuration& ConfigV0() {
static const Configuration* instance = [] {
Expand All @@ -68,7 +37,7 @@ const Configuration& ConfigV0() {
CHECK_OK(internal::AddAeadV0(*config));
CHECK_OK(internal::AddDeterministicAeadV0(*config));
CHECK_OK(internal::AddStreamingAeadV0(*config));
CHECK_OK(AddHybrid(*config));
CHECK_OK(internal::AddHybridConfigV0(*config));
CHECK_OK(internal::AddPrfV0(*config));
CHECK_OK(internal::AddSignatureV0(*config));
return config;
Expand Down
64 changes: 64 additions & 0 deletions tink/hybrid/internal/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,44 @@ cc_library(
],
)

cc_library(
name = "config_v0",
srcs = ["config_v0.cc"],
hdrs = ["config_v0.h"],
include_prefix = "tink/hybrid/internal",
tags = ["requires_boringcrypto_update"],
deps = [
":hpke_private_key_manager",
":hpke_public_key_manager",
"//tink:configuration",
"//tink/hybrid:ecies_aead_hkdf_private_key_manager",
"//tink/hybrid:ecies_aead_hkdf_public_key_manager",
"//tink/hybrid:hybrid_decrypt_wrapper",
"//tink/hybrid:hybrid_encrypt_wrapper",
"//tink/internal:configuration_impl",
"//tink/util:status",
"@com_google_absl//absl/memory",
],
)

cc_library(
name = "key_gen_config_v0",
srcs = ["key_gen_config_v0.cc"],
hdrs = ["key_gen_config_v0.h"],
include_prefix = "tink/hybrid/internal",
tags = ["requires_boringcrypto_update"],
deps = [
":hpke_private_key_manager",
":hpke_public_key_manager",
"//tink:key_gen_configuration",
"//tink/hybrid:ecies_aead_hkdf_private_key_manager",
"//tink/hybrid:ecies_aead_hkdf_public_key_manager",
"//tink/internal:key_gen_configuration_impl",
"//tink/util:status",
"@com_google_absl//absl/memory",
],
)

# tests

cc_test(
Expand Down Expand Up @@ -466,3 +504,29 @@ cc_test(
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "config_v0_test",
srcs = ["config_v0_test.cc"],
tags = ["requires_boringcrypto_update"],
deps = [
":config_v0",
":hpke_private_key_manager",
":key_gen_config_v0",
"//tink:configuration",
"//tink:hybrid_decrypt",
"//tink:hybrid_encrypt",
"//tink:key_gen_configuration",
"//tink:keyset_handle",
"//tink/hybrid:ecies_aead_hkdf_private_key_manager",
"//tink/hybrid:hybrid_key_templates",
"//tink/internal:configuration_impl",
"//tink/internal:key_gen_configuration_impl",
"//tink/internal:key_type_info_store",
"//tink/internal:keyset_wrapper_store",
"//proto:tink_cc_proto",
"//tink/util:statusor",
"//tink/util:test_matchers",
"@com_google_googletest//:gtest_main",
],
)
65 changes: 65 additions & 0 deletions tink/hybrid/internal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,44 @@ tink_cc_library(
exclude_if_openssl
)

tink_cc_library(
NAME config_v0
SRCS
config_v0.cc
config_v0.h
DEPS
tink::hybrid::internal::hpke_private_key_manager
tink::hybrid::internal::hpke_public_key_manager
absl::memory
tink::core::configuration
tink::hybrid::ecies_aead_hkdf_private_key_manager
tink::hybrid::ecies_aead_hkdf_public_key_manager
tink::hybrid::hybrid_decrypt_wrapper
tink::hybrid::hybrid_encrypt_wrapper
tink::internal::configuration_impl
tink::util::status
TAGS
exclude_if_openssl
)

tink_cc_library(
NAME key_gen_config_v0
SRCS
key_gen_config_v0.cc
key_gen_config_v0.h
DEPS
tink::hybrid::internal::hpke_private_key_manager
tink::hybrid::internal::hpke_public_key_manager
absl::memory
tink::core::key_gen_configuration
tink::hybrid::ecies_aead_hkdf_private_key_manager
tink::hybrid::ecies_aead_hkdf_public_key_manager
tink::internal::key_gen_configuration_impl
tink::util::status
TAGS
exclude_if_openssl
)

# tests

tink_cc_test(
Expand Down Expand Up @@ -468,3 +506,30 @@ tink_cc_test(
TAGS
exclude_if_openssl
)

tink_cc_test(
NAME config_v0_test
SRCS
config_v0_test.cc
DEPS
tink::hybrid::internal::config_v0
tink::hybrid::internal::hpke_private_key_manager
tink::hybrid::internal::key_gen_config_v0
gmock
tink::core::configuration
tink::core::hybrid_decrypt
tink::core::hybrid_encrypt
tink::core::key_gen_configuration
tink::core::keyset_handle
tink::hybrid::ecies_aead_hkdf_private_key_manager
tink::hybrid::hybrid_key_templates
tink::internal::configuration_impl
tink::internal::key_gen_configuration_impl
tink::internal::key_type_info_store
tink::internal::keyset_wrapper_store
tink::util::statusor
tink::util::test_matchers
tink::proto::tink_cc_proto
TAGS
exclude_if_openssl
)
59 changes: 59 additions & 0 deletions tink/hybrid/internal/config_v0.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// 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
//
// 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 "tink/hybrid/internal/config_v0.h"

#include "absl/memory/memory.h"
#include "tink/configuration.h"
#include "tink/hybrid/ecies_aead_hkdf_private_key_manager.h"
#include "tink/hybrid/ecies_aead_hkdf_public_key_manager.h"
#include "tink/hybrid/hybrid_decrypt_wrapper.h"
#include "tink/hybrid/hybrid_encrypt_wrapper.h"
#include "tink/hybrid/internal/hpke_private_key_manager.h"
#include "tink/hybrid/internal/hpke_public_key_manager.h"
#include "tink/internal/configuration_impl.h"
#include "tink/util/status.h"

namespace crypto {
namespace tink {
namespace internal {

util::Status AddHybridConfigV0(Configuration& config) {
util::Status status = ConfigurationImpl::AddPrimitiveWrapper(
absl::make_unique<HybridEncryptWrapper>(), config);
if (!status.ok()) {
return status;
}
status = ConfigurationImpl::AddPrimitiveWrapper(
absl::make_unique<HybridDecryptWrapper>(), config);
if (!status.ok()) {
return status;
}

status = ConfigurationImpl::AddAsymmetricKeyManagers(
absl::make_unique<EciesAeadHkdfPrivateKeyManager>(),
absl::make_unique<EciesAeadHkdfPublicKeyManager>(), config);
if (!status.ok()) {
return status;
}
return ConfigurationImpl::AddAsymmetricKeyManagers(
absl::make_unique<HpkePrivateKeyManager>(),
absl::make_unique<HpkePublicKeyManager>(), config);
}

} // namespace internal
} // namespace tink
} // namespace crypto
35 changes: 35 additions & 0 deletions tink/hybrid/internal/config_v0.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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
//
// 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 TINK_HYBRID_INTERNAL_CONFIG_V0_H_
#define TINK_HYBRID_INTERNAL_CONFIG_V0_H_

#include "tink/configuration.h"
#include "tink/util/status.h"

namespace crypto {
namespace tink {
namespace internal {

// Add recommended Hybrid Encryption primitive wrappers and key managers to
// `config`, used to generate primitives.
util::Status AddHybridConfigV0(Configuration& config);

} // namespace internal
} // namespace tink
} // namespace crypto

#endif // TINK_HYBRID_INTERNAL_CONFIG_V0_H_
Loading

0 comments on commit 00e4b50

Please sign in to comment.