Skip to content

Commit

Permalink
Move AddStreamingAeadV0() to streamingaead/internal/.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 574997632
Change-Id: Id6d992c85f46732cb8e662425bc18848f74e3c49
  • Loading branch information
cindylindeed authored and copybara-github committed Oct 19, 2023
1 parent 4149827 commit 46aac36
Show file tree
Hide file tree
Showing 12 changed files with 427 additions and 43 deletions.
7 changes: 2 additions & 5 deletions tink/config/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,7 @@ cc_library(
"//tink/signature:rsa_ssa_pkcs1_verify_key_manager",
"//tink/signature:rsa_ssa_pss_sign_key_manager",
"//tink/signature:rsa_ssa_pss_verify_key_manager",
"//tink/streamingaead:aes_ctr_hmac_streaming_key_manager",
"//tink/streamingaead:aes_gcm_hkdf_streaming_key_manager",
"//tink/streamingaead:streaming_aead_wrapper",
"//tink/streamingaead/internal:config_v0",
"@com_google_absl//absl/log:check",
],
)
Expand Down Expand Up @@ -196,8 +194,7 @@ cc_library(
"//tink/signature:rsa_ssa_pkcs1_verify_key_manager",
"//tink/signature:rsa_ssa_pss_sign_key_manager",
"//tink/signature:rsa_ssa_pss_verify_key_manager",
"//tink/streamingaead:aes_ctr_hmac_streaming_key_manager",
"//tink/streamingaead:aes_gcm_hkdf_streaming_key_manager",
"//tink/streamingaead/internal:key_gen_config_v0",
"@com_google_absl//absl/log:check",
],
)
Expand Down
7 changes: 2 additions & 5 deletions tink/config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,7 @@ tink_cc_library(
tink::signature::rsa_ssa_pkcs1_verify_key_manager
tink::signature::rsa_ssa_pss_sign_key_manager
tink::signature::rsa_ssa_pss_verify_key_manager
tink::streamingaead::aes_ctr_hmac_streaming_key_manager
tink::streamingaead::aes_gcm_hkdf_streaming_key_manager
tink::streamingaead::streaming_aead_wrapper
tink::streamingaead::internal::config_v0
tink::signature::ecdsa_sign_key_manager
TAGS
exclude_if_openssl
Expand Down Expand Up @@ -180,8 +178,7 @@ tink_cc_library(
tink::signature::rsa_ssa_pkcs1_verify_key_manager
tink::signature::rsa_ssa_pss_sign_key_manager
tink::signature::rsa_ssa_pss_verify_key_manager
tink::streamingaead::aes_ctr_hmac_streaming_key_manager
tink::streamingaead::aes_gcm_hkdf_streaming_key_manager
tink::streamingaead::internal::key_gen_config_v0
tink::signature::ecdsa_sign_key_manager
TAGS
exclude_if_openssl
Expand Down
15 changes: 2 additions & 13 deletions tink/config/key_gen_v0.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
#include "tink/signature/rsa_ssa_pkcs1_verify_key_manager.h"
#include "tink/signature/rsa_ssa_pss_sign_key_manager.h"
#include "tink/signature/rsa_ssa_pss_verify_key_manager.h"
#include "tink/streamingaead/aes_ctr_hmac_streaming_key_manager.h"
#include "tink/streamingaead/aes_gcm_hkdf_streaming_key_manager.h"
#include "tink/streamingaead/internal/key_gen_config_v0.h"
#include "tink/signature/ecdsa_sign_key_manager.h"

namespace crypto {
Expand Down Expand Up @@ -89,16 +88,6 @@ util::Status AddDeterministicAead(KeyGenConfiguration& config) {
absl::make_unique<AesSivKeyManager>(), config);
}

util::Status AddStreamingAead(KeyGenConfiguration& config) {
util::Status status = internal::KeyGenConfigurationImpl::AddKeyTypeManager(
absl::make_unique<AesGcmHkdfStreamingKeyManager>(), config);
if (!status.ok()) {
return status;
}
return internal::KeyGenConfigurationImpl::AddKeyTypeManager(
absl::make_unique<AesCtrHmacStreamingKeyManager>(), config);
}

util::Status AddHybrid(KeyGenConfiguration& config) {
util::Status status =
internal::KeyGenConfigurationImpl::AddAsymmetricKeyManagers(
Expand Down Expand Up @@ -160,7 +149,7 @@ const KeyGenConfiguration& KeyGenConfigV0() {
CHECK_OK(AddMac(*config));
CHECK_OK(AddAead(*config));
CHECK_OK(AddDeterministicAead(*config));
CHECK_OK(AddStreamingAead(*config));
CHECK_OK(internal::AddStreamingAeadV0(*config));
CHECK_OK(AddHybrid(*config));
CHECK_OK(AddPrf(*config));
CHECK_OK(AddSignature(*config));
Expand Down
22 changes: 2 additions & 20 deletions tink/config/v0.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@
#include "tink/signature/rsa_ssa_pkcs1_verify_key_manager.h"
#include "tink/signature/rsa_ssa_pss_sign_key_manager.h"
#include "tink/signature/rsa_ssa_pss_verify_key_manager.h"
#include "tink/streamingaead/aes_ctr_hmac_streaming_key_manager.h"
#include "tink/streamingaead/aes_gcm_hkdf_streaming_key_manager.h"
#include "tink/streamingaead/streaming_aead_wrapper.h"
#include "tink/streamingaead/internal/config_v0.h"
#include "tink/signature/ecdsa_sign_key_manager.h"

namespace crypto {
Expand Down Expand Up @@ -86,22 +84,6 @@ util::Status AddDeterministicAead(Configuration& config) {
absl::make_unique<AesSivKeyManager>(), config);
}

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

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

util::Status AddHybrid(Configuration& config) {
util::Status status = internal::ConfigurationImpl::AddPrimitiveWrapper(
absl::make_unique<HybridEncryptWrapper>(), config);
Expand Down Expand Up @@ -189,7 +171,7 @@ const Configuration& ConfigV0() {
CHECK_OK(AddMac(*config));
CHECK_OK(internal::AddAeadV0(*config));
CHECK_OK(AddDeterministicAead(*config));
CHECK_OK(AddStreamingAead(*config));
CHECK_OK(internal::AddStreamingAeadV0(*config));
CHECK_OK(AddHybrid(*config));
CHECK_OK(AddPrf(*config));
CHECK_OK(AddSignature(*config));
Expand Down
2 changes: 2 additions & 0 deletions tink/streamingaead/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
tink_module(streamingaead)

add_subdirectory(internal)

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

licenses(["notice"])

cc_library(
name = "config_v0",
srcs = ["config_v0.cc"],
hdrs = ["config_v0.h"],
include_prefix = "tink/streamingaead/internal",
deps = [
"//tink:configuration",
"//tink/internal:configuration_impl",
"//tink/streamingaead:aes_ctr_hmac_streaming_key_manager",
"//tink/streamingaead:aes_gcm_hkdf_streaming_key_manager",
"//tink/streamingaead:streaming_aead_wrapper",
"//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:input_stream",
"//tink:key_gen_configuration",
"//tink:keyset_handle",
"//tink:output_stream",
"//tink:streaming_aead",
"//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/streamingaead:aes_ctr_hmac_streaming_key_manager",
"//tink/streamingaead:aes_gcm_hkdf_streaming_key_manager",
"//tink/streamingaead:streaming_aead_key_templates",
"//tink/subtle:test_util",
"//tink/util:istream_input_stream",
"//tink/util:ostream_output_stream",
"//tink/util:statusor",
"//tink/util:test_matchers",
"@com_google_absl//absl/memory",
"@com_google_googletest//:gtest_main",
],
)

cc_library(
name = "key_gen_config_v0",
srcs = ["key_gen_config_v0.cc"],
hdrs = ["key_gen_config_v0.h"],
include_prefix = "tink/streamingaead/internal",
deps = [
"//tink:key_gen_configuration",
"//tink/internal:key_gen_configuration_impl",
"//tink/streamingaead:aes_ctr_hmac_streaming_key_manager",
"//tink/streamingaead:aes_gcm_hkdf_streaming_key_manager",
"//tink/util:status",
"@com_google_absl//absl/memory",
],
)
60 changes: 60 additions & 0 deletions tink/streamingaead/internal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
tink_module(streamingaead::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::streamingaead::aes_ctr_hmac_streaming_key_manager
tink::streamingaead::aes_gcm_hkdf_streaming_key_manager
tink::streamingaead::streaming_aead_wrapper
tink::util::status
)

tink_cc_test(
NAME config_v0_test
SRCS
config_v0_test.cc
DEPS
tink::streamingaead::internal::config_v0
tink::streamingaead::internal::key_gen_config_v0
gmock
absl::memory
tink::core::configuration
tink::core::input_stream
tink::core::key_gen_configuration
tink::core::keyset_handle
tink::core::output_stream
tink::core::streaming_aead
tink::internal::configuration_impl
tink::internal::key_gen_configuration_impl
tink::internal::key_type_info_store
tink::internal::keyset_wrapper_store
tink::streamingaead::aes_ctr_hmac_streaming_key_manager
tink::streamingaead::aes_gcm_hkdf_streaming_key_manager
tink::streamingaead::streaming_aead_key_templates
tink::subtle::test_util
tink::util::istream_input_stream
tink::util::ostream_output_stream
tink::util::statusor
tink::util::test_matchers
tink::proto::tink_cc_proto
)

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::streamingaead::aes_ctr_hmac_streaming_key_manager
tink::streamingaead::aes_gcm_hkdf_streaming_key_manager
tink::util::status
)
49 changes: 49 additions & 0 deletions tink/streamingaead/internal/config_v0.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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/streamingaead/internal/config_v0.h"

#include "absl/memory/memory.h"
#include "tink/configuration.h"
#include "tink/internal/configuration_impl.h"
#include "tink/streamingaead/aes_ctr_hmac_streaming_key_manager.h"
#include "tink/streamingaead/aes_gcm_hkdf_streaming_key_manager.h"
#include "tink/streamingaead/streaming_aead_wrapper.h"
#include "tink/util/status.h"

namespace crypto {
namespace tink {
namespace internal {

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

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

} // namespace internal
} // namespace tink
} // namespace crypto
35 changes: 35 additions & 0 deletions tink/streamingaead/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_STREAMINGAEAD_INTERNAL_CONFIG_V0_H_
#define TINK_STREAMINGAEAD_INTERNAL_CONFIG_V0_H_

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

namespace crypto {
namespace tink {
namespace internal {

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

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

#endif // TINK_STREAMINGAEAD_INTERNAL_CONFIG_V0_H_
Loading

0 comments on commit 46aac36

Please sign in to comment.