xref: /aosp_15_r20/external/tink/cc/config/key_gen_v0_test.cc (revision e7b1675dde1b92d52ec075b0a92829627f2c52a5)
1 // Copyright 2023 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 ////////////////////////////////////////////////////////////////////////////////
16 
17 #include "tink/config/key_gen_v0.h"
18 
19 #include "gmock/gmock.h"
20 #include "gtest/gtest.h"
21 #include "tink/aead/aead_key_templates.h"
22 #include "tink/aead/aes_ctr_hmac_aead_key_manager.h"
23 #include "tink/aead/aes_eax_key_manager.h"
24 #include "tink/aead/aes_gcm_key_manager.h"
25 #include "tink/aead/aes_gcm_siv_key_manager.h"
26 #include "tink/aead/xchacha20_poly1305_key_manager.h"
27 #include "tink/daead/aes_siv_key_manager.h"
28 #include "tink/hybrid/ecies_aead_hkdf_public_key_manager.h"
29 #include "tink/hybrid/internal/hpke_public_key_manager.h"
30 #include "tink/internal/key_gen_configuration_impl.h"
31 #include "tink/key_gen_configuration.h"
32 #include "tink/keyset_handle.h"
33 #include "tink/mac/aes_cmac_key_manager.h"
34 #include "tink/mac/hmac_key_manager.h"
35 #include "tink/prf/aes_cmac_prf_key_manager.h"
36 #include "tink/prf/hkdf_prf_key_manager.h"
37 #include "tink/prf/hmac_prf_key_manager.h"
38 #include "tink/signature/ecdsa_verify_key_manager.h"
39 #include "tink/signature/ed25519_verify_key_manager.h"
40 #include "tink/signature/rsa_ssa_pkcs1_verify_key_manager.h"
41 #include "tink/signature/rsa_ssa_pss_verify_key_manager.h"
42 #include "tink/streamingaead/aes_ctr_hmac_streaming_key_manager.h"
43 #include "tink/streamingaead/aes_gcm_hkdf_streaming_key_manager.h"
44 #include "tink/util/test_matchers.h"
45 
46 namespace crypto {
47 namespace tink {
48 namespace {
49 
50 using ::crypto::tink::test::IsOk;
51 
TEST(KeyGenV0Test,KeyManagers)52 TEST(KeyGenV0Test, KeyManagers) {
53   util::StatusOr<const internal::KeyTypeInfoStore*> store =
54       internal::KeyGenConfigurationImpl::GetKeyTypeInfoStore(KeyGenConfigV0());
55   ASSERT_THAT(store, IsOk());
56 
57   EXPECT_THAT((*store)->Get(HmacKeyManager().get_key_type()), IsOk());
58   EXPECT_THAT((*store)->Get(AesCmacKeyManager().get_key_type()), IsOk());
59   EXPECT_THAT((*store)->Get(AesCtrHmacAeadKeyManager().get_key_type()), IsOk());
60   EXPECT_THAT((*store)->Get(AesGcmKeyManager().get_key_type()), IsOk());
61   EXPECT_THAT((*store)->Get(AesGcmSivKeyManager().get_key_type()), IsOk());
62   EXPECT_THAT((*store)->Get(AesEaxKeyManager().get_key_type()), IsOk());
63   EXPECT_THAT((*store)->Get(XChaCha20Poly1305KeyManager().get_key_type()),
64               IsOk());
65   EXPECT_THAT((*store)->Get(AesSivKeyManager().get_key_type()), IsOk());
66   EXPECT_THAT((*store)->Get(AesGcmHkdfStreamingKeyManager().get_key_type()),
67               IsOk());
68   EXPECT_THAT((*store)->Get(AesCtrHmacStreamingKeyManager().get_key_type()),
69               IsOk());
70   EXPECT_THAT((*store)->Get(EciesAeadHkdfPublicKeyManager().get_key_type()),
71               IsOk());
72   EXPECT_THAT((*store)->Get(internal::HpkePublicKeyManager().get_key_type()),
73               IsOk());
74   EXPECT_THAT((*store)->Get(HmacPrfKeyManager().get_key_type()), IsOk());
75   EXPECT_THAT((*store)->Get(HkdfPrfKeyManager().get_key_type()), IsOk());
76   EXPECT_THAT((*store)->Get(AesCmacPrfKeyManager().get_key_type()), IsOk());
77   EXPECT_THAT((*store)->Get(EcdsaVerifyKeyManager().get_key_type()), IsOk());
78   EXPECT_THAT((*store)->Get(RsaSsaPssVerifyKeyManager().get_key_type()),
79               IsOk());
80   EXPECT_THAT((*store)->Get(RsaSsaPkcs1VerifyKeyManager().get_key_type()),
81               IsOk());
82   EXPECT_THAT((*store)->Get(Ed25519VerifyKeyManager().get_key_type()), IsOk());
83 }
84 
TEST(KeyGenV0Test,GenerateNewKeysetHandle)85 TEST(KeyGenV0Test, GenerateNewKeysetHandle) {
86   EXPECT_THAT(KeysetHandle::GenerateNew(AeadKeyTemplates::Aes128Gcm(),
87                                         KeyGenConfigV0()),
88               IsOk());
89 }
90 
91 }  // namespace
92 }  // namespace tink
93 }  // namespace crypto
94