tink_hybrid/lib.rs
1// Copyright 2019-2021 The Tink-Rust Authors
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//! Implementations of the `HybridEncrypt` and `HybridDecrypt` primitives.
18//!
19//! The functionality of Hybrid Encryption is represented as a pair of primitives (interfaces):
20//!
21//! - HybridEncrypt for encryption of data
22//! - HybridDecrypt for decryption of data
23//!
24//! Implementations of these interfaces are secure against adaptive chosen ciphertext attacks. In
25//! addition to plaintext the encryption takes an extra parameter contextInfo, which usually is
26//! public data implicit from the context, but should be bound to the resulting ciphertext, i.e. the
27//! ciphertext allows for checking the integrity of `context_info` (but there are no guarantees wrt.
28//! the secrecy or authenticity of `context_info`).
29
30#![cfg_attr(docsrs, feature(doc_cfg))]
31#![deny(broken_intra_doc_links)]
32
33use std::sync::Once;
34use tink_core::registry::{register_key_manager, register_template_generator};
35
36mod ecies_aead_hkdf_dem_helper;
37pub use ecies_aead_hkdf_dem_helper::*;
38mod ecies_aead_hkdf_private_key_manager;
39pub use ecies_aead_hkdf_private_key_manager::*;
40mod ecies_aead_hkdf_public_key_manager;
41pub use ecies_aead_hkdf_public_key_manager::*;
42mod hybrid_decrypt_factory;
43pub use hybrid_decrypt_factory::*;
44mod hybrid_encrypt_factory;
45pub use hybrid_encrypt_factory::*;
46mod hybrid_key_templates;
47pub use hybrid_key_templates::*;
48
49pub mod subtle;
50
51/// The [upstream Tink](https://github.com/google/tink) version that this Rust
52/// port is based on.
53pub const UPSTREAM_VERSION: &str = "1.6.0";
54
55static INIT: Once = Once::new();
56
57/// Initialize the `tink-hybrid` crate, registering its primitives so they are available via
58/// Tink.
59pub fn init() {
60 #[cfg(feature = "aead")]
61 tink_aead::init();
62 #[cfg(feature = "daead")]
63 tink_daead::init();
64 INIT.call_once(|| {
65 register_key_manager(std::sync::Arc::new(
66 EciesAeadHkdfPrivateKeyKeyManager::default(),
67 ))
68 .expect("tink_hybrid::init() failed"); // safe: init
69 register_key_manager(std::sync::Arc::new(
70 EciesAeadHkdfPublicKeyKeyManager::default(),
71 ))
72 .expect("tink_hybrid::init() failed"); // safe: init
73
74 register_template_generator(
75 "ECIES_P256_HKDF_HMAC_SHA256_AES128_GCM",
76 ecies_hkdf_aes128_gcm_key_template,
77 );
78 register_template_generator(
79 "ECIES_P256_HKDF_HMAC_SHA256_AES128_CTR_HMAC_SHA256",
80 ecies_hkdf_aes128_ctr_hmac_sha256_key_template,
81 );
82 });
83}