Skip to content

Commit

Permalink
Move AddPrfV0() to prf/internal/.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 575029842
Change-Id: I87a4fe61c79acbf58e01d56a18b8ebb9429301b6
  • Loading branch information
cindylindeed authored and copybara-github committed Oct 19, 2023
1 parent 46aac36 commit 2f78301
Show file tree
Hide file tree
Showing 12 changed files with 413 additions and 59 deletions.
9 changes: 2 additions & 7 deletions tink/config/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,7 @@ cc_library(
"//tink/mac:hmac_key_manager",
"//tink/mac:mac_wrapper",
"//tink/mac/internal:chunked_mac_wrapper",
"//tink/prf:aes_cmac_prf_key_manager",
"//tink/prf:hkdf_prf_key_manager",
"//tink/prf:hmac_prf_key_manager",
"//tink/prf:prf_set_wrapper",
"//tink/prf/internal:config_v0",
"//tink/signature:ecdsa_sign_key_manager",
"//tink/signature:ecdsa_verify_key_manager",
"//tink/signature:ed25519_sign_key_manager",
Expand Down Expand Up @@ -183,9 +180,7 @@ cc_library(
"//tink/internal:key_gen_configuration_impl",
"//tink/mac:aes_cmac_key_manager",
"//tink/mac:hmac_key_manager",
"//tink/prf:aes_cmac_prf_key_manager",
"//tink/prf:hkdf_prf_key_manager",
"//tink/prf:hmac_prf_key_manager",
"//tink/prf/internal:key_gen_config_v0",
"//tink/signature:ecdsa_sign_key_manager",
"//tink/signature:ecdsa_verify_key_manager",
"//tink/signature:ed25519_sign_key_manager",
Expand Down
9 changes: 2 additions & 7 deletions tink/config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,7 @@ tink_cc_library(
tink::mac::hmac_key_manager
tink::mac::mac_wrapper
tink::mac::internal::chunked_mac_wrapper
tink::prf::aes_cmac_prf_key_manager
tink::prf::hkdf_prf_key_manager
tink::prf::hmac_prf_key_manager
tink::prf::prf_set_wrapper
tink::prf::internal::config_v0
tink::signature::ecdsa_verify_key_manager
tink::signature::ed25519_sign_key_manager
tink::signature::ed25519_verify_key_manager
Expand Down Expand Up @@ -168,9 +165,7 @@ tink_cc_library(
tink::internal::key_gen_configuration_impl
tink::mac::aes_cmac_key_manager
tink::mac::hmac_key_manager
tink::prf::aes_cmac_prf_key_manager
tink::prf::hkdf_prf_key_manager
tink::prf::hmac_prf_key_manager
tink::prf::internal::key_gen_config_v0
tink::signature::ecdsa_verify_key_manager
tink::signature::ed25519_sign_key_manager
tink::signature::ed25519_verify_key_manager
Expand Down
21 changes: 2 additions & 19 deletions tink/config/key_gen_v0.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
#include "tink/internal/key_gen_configuration_impl.h"
#include "tink/mac/aes_cmac_key_manager.h"
#include "tink/mac/hmac_key_manager.h"
#include "tink/prf/aes_cmac_prf_key_manager.h"
#include "tink/prf/hkdf_prf_key_manager.h"
#include "tink/prf/hmac_prf_key_manager.h"
#include "tink/prf/internal/key_gen_config_v0.h"
#include "tink/signature/ecdsa_verify_key_manager.h"
#include "tink/signature/ed25519_sign_key_manager.h"
#include "tink/signature/ed25519_verify_key_manager.h"
Expand Down Expand Up @@ -101,21 +99,6 @@ util::Status AddHybrid(KeyGenConfiguration& config) {
absl::make_unique<internal::HpkePublicKeyManager>(), config);
}

util::Status AddPrf(KeyGenConfiguration& config) {
util::Status status = internal::KeyGenConfigurationImpl::AddKeyTypeManager(
absl::make_unique<HmacPrfKeyManager>(), config);
if (!status.ok()) {
return status;
}
status = internal::KeyGenConfigurationImpl::AddKeyTypeManager(
absl::make_unique<HkdfPrfKeyManager>(), config);
if (!status.ok()) {
return status;
}
return internal::KeyGenConfigurationImpl::AddKeyTypeManager(
absl::make_unique<AesCmacPrfKeyManager>(), config);
}

util::Status AddSignature(KeyGenConfiguration& config) {
util::Status status =
internal::KeyGenConfigurationImpl::AddAsymmetricKeyManagers(
Expand Down Expand Up @@ -151,7 +134,7 @@ const KeyGenConfiguration& KeyGenConfigV0() {
CHECK_OK(AddDeterministicAead(*config));
CHECK_OK(internal::AddStreamingAeadV0(*config));
CHECK_OK(AddHybrid(*config));
CHECK_OK(AddPrf(*config));
CHECK_OK(internal::AddPrfKeyGenV0(*config));
CHECK_OK(AddSignature(*config));
return config;
}();
Expand Down
28 changes: 2 additions & 26 deletions tink/config/v0.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@
#include "tink/mac/hmac_key_manager.h"
#include "tink/mac/internal/chunked_mac_wrapper.h"
#include "tink/mac/mac_wrapper.h"
#include "tink/prf/aes_cmac_prf_key_manager.h"
#include "tink/prf/hkdf_prf_key_manager.h"
#include "tink/prf/hmac_prf_key_manager.h"
#include "tink/prf/prf_set_wrapper.h"
#include "tink/prf/internal/config_v0.h"
#include "tink/signature/ecdsa_verify_key_manager.h"
#include "tink/signature/ed25519_sign_key_manager.h"
#include "tink/signature/ed25519_verify_key_manager.h"
Expand Down Expand Up @@ -107,27 +104,6 @@ util::Status AddHybrid(Configuration& config) {
absl::make_unique<internal::HpkePublicKeyManager>(), config);
}

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

status = internal::ConfigurationImpl::AddKeyTypeManager(
absl::make_unique<HmacPrfKeyManager>(), config);
if (!status.ok()) {
return status;
}
status = internal::ConfigurationImpl::AddKeyTypeManager(
absl::make_unique<HkdfPrfKeyManager>(), config);
if (!status.ok()) {
return status;
}
return internal::ConfigurationImpl::AddKeyTypeManager(
absl::make_unique<AesCmacPrfKeyManager>(), config);
}

util::Status AddSignature(Configuration& config) {
util::Status status = internal::ConfigurationImpl::AddPrimitiveWrapper(
absl::make_unique<PublicKeySignWrapper>(), config);
Expand Down Expand Up @@ -173,7 +149,7 @@ const Configuration& ConfigV0() {
CHECK_OK(AddDeterministicAead(*config));
CHECK_OK(internal::AddStreamingAeadV0(*config));
CHECK_OK(AddHybrid(*config));
CHECK_OK(AddPrf(*config));
CHECK_OK(internal::AddPrfV0(*config));
CHECK_OK(AddSignature(*config));
return config;
}();
Expand Down
2 changes: 2 additions & 0 deletions tink/prf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
tink_module(prf)

add_subdirectory(internal)

tink_cc_library(
NAME hkdf_prf_key_manager
SRCS
Expand Down
60 changes: 60 additions & 0 deletions tink/prf/internal/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1 +1,61 @@
package(default_visibility = ["//:__subpackages__"])

licenses(["notice"])

cc_library(
name = "config_v0",
srcs = ["config_v0.cc"],
hdrs = ["config_v0.h"],
include_prefix = "tink/prf/internal",
deps = [
"//tink:configuration",
"//tink/internal:configuration_impl",
"//tink/prf:aes_cmac_prf_key_manager",
"//tink/prf:hkdf_prf_key_manager",
"//tink/prf:hmac_prf_key_manager",
"//tink/prf:prf_set_wrapper",
"//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/prf/internal",
deps = [
"//tink:key_gen_configuration",
"//tink/internal:key_gen_configuration_impl",
"//tink/prf:aes_cmac_prf_key_manager",
"//tink/prf:hkdf_prf_key_manager",
"//tink/prf:hmac_prf_key_manager",
"//tink/util:status",
"@com_google_absl//absl/memory",
],
)

cc_test(
name = "config_v0_test",
srcs = ["config_v0_test.cc"],
deps = [
":config_v0",
":key_gen_config_v0",
"//tink:configuration",
"//tink:key_gen_configuration",
"//tink:keyset_handle",
"//tink/internal:configuration_impl",
"//tink/internal:key_gen_configuration_impl",
"//tink/internal:key_type_info_store",
"//tink/internal:keyset_wrapper_store",
"//tink/prf:aes_cmac_prf_key_manager",
"//tink/prf:hkdf_prf_key_manager",
"//tink/prf:hmac_prf_key_manager",
"//tink/prf:prf_key_templates",
"//tink/prf:prf_set",
"//proto:tink_cc_proto",
"//tink/util:statusor",
"//tink/util:test_matchers",
"@com_google_googletest//:gtest_main",
],
)
57 changes: 57 additions & 0 deletions tink/prf/internal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
tink_module(prf::internal)

tink_cc_library(
NAME config_v0
SRCS
config_v0.cc
config_v0.h
DEPS
absl::memory
tink::core::configuration
tink::internal::configuration_impl
tink::prf::aes_cmac_prf_key_manager
tink::prf::hkdf_prf_key_manager
tink::prf::hmac_prf_key_manager
tink::prf::prf_set_wrapper
tink::util::status
)

tink_cc_library(
NAME key_gen_config_v0
SRCS
key_gen_config_v0.cc
key_gen_config_v0.h
DEPS
absl::memory
tink::core::key_gen_configuration
tink::internal::key_gen_configuration_impl
tink::prf::aes_cmac_prf_key_manager
tink::prf::hkdf_prf_key_manager
tink::prf::hmac_prf_key_manager
tink::util::status
)

tink_cc_test(
NAME config_v0_test
SRCS
config_v0_test.cc
DEPS
tink::prf::internal::config_v0
tink::prf::internal::key_gen_config_v0
gmock
tink::core::configuration
tink::core::key_gen_configuration
tink::core::keyset_handle
tink::internal::configuration_impl
tink::internal::key_gen_configuration_impl
tink::internal::key_type_info_store
tink::internal::keyset_wrapper_store
tink::prf::aes_cmac_prf_key_manager
tink::prf::hkdf_prf_key_manager
tink::prf::hmac_prf_key_manager
tink::prf::prf_key_templates
tink::prf::prf_set
tink::util::statusor
tink::util::test_matchers
tink::proto::tink_cc_proto
)
55 changes: 55 additions & 0 deletions tink/prf/internal/config_v0.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// 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/prf/internal/config_v0.h"

#include "absl/memory/memory.h"
#include "tink/configuration.h"
#include "tink/internal/configuration_impl.h"
#include "tink/prf/aes_cmac_prf_key_manager.h"
#include "tink/prf/hkdf_prf_key_manager.h"
#include "tink/prf/hmac_prf_key_manager.h"
#include "tink/prf/prf_set_wrapper.h"
#include "tink/util/status.h"

namespace crypto {
namespace tink {
namespace internal {

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

status = ConfigurationImpl::AddKeyTypeManager(
absl::make_unique<AesCmacPrfKeyManager>(), config);
if (!status.ok()) {
return status;
}
status = ConfigurationImpl::AddKeyTypeManager(
absl::make_unique<HkdfPrfKeyManager>(), config);
if (!status.ok()) {
return status;
}
return ConfigurationImpl::AddKeyTypeManager(
absl::make_unique<HmacPrfKeyManager>(), config);
}

} // namespace internal
} // namespace tink
} // namespace crypto
35 changes: 35 additions & 0 deletions tink/prf/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_PRF_INTERNAL_CONFIG_V0_H_
#define TINK_PRF_INTERNAL_CONFIG_V0_H_

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

namespace crypto {
namespace tink {
namespace internal {

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

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

#endif // TINK_PRF_INTERNAL_CONFIG_V0_H_
Loading

0 comments on commit 2f78301

Please sign in to comment.