tink_streaming_aead/
lib.rs

1// Copyright 2020 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//! This crate provides implementations of the streaming AEAD primitive.
18//!
19//! AEAD encryption assures the confidentiality and authenticity of the data.
20//! This primitive is CPA secure.
21
22#![deny(broken_intra_doc_links)]
23
24use std::sync::Once;
25use tink_core::registry::register_key_manager;
26
27mod aes_ctr_hmac_key_manager;
28pub use aes_ctr_hmac_key_manager::*;
29mod aes_gcm_hkdf_key_manager;
30pub use aes_gcm_hkdf_key_manager::*;
31mod decrypt_reader;
32use decrypt_reader::*;
33mod streamingaead_factory;
34pub use streamingaead_factory::*;
35mod streamingaead_key_templates;
36pub use streamingaead_key_templates::*;
37
38pub mod subtle;
39
40/// The [upstream Tink](https://github.com/google/tink) version that this Rust
41/// port is based on.
42pub const UPSTREAM_VERSION: &str = "1.6.0";
43
44static INIT: Once = Once::new();
45
46/// Initialize the `tink-streaming-aead` crate, registering its primitives so they are available via
47/// tink-core.
48pub fn init() {
49    INIT.call_once(|| {
50        register_key_manager(std::sync::Arc::new(AesCtrHmacKeyManager::default()))
51            .expect("tink_streaming_aead::init() failed"); // safe: init
52        register_key_manager(std::sync::Arc::new(AesGcmHkdfKeyManager::default()))
53            .expect("tink_streaming_aead::init() failed"); // safe: init
54
55        tink_core::registry::register_template_generator(
56            "AES128_CTR_HMAC_SHA256_4KB",
57            aes128_ctr_hmac_sha256_segment_4kb_key_template,
58        );
59        tink_core::registry::register_template_generator(
60            "AES128_CTR_HMAC_SHA256_1MB",
61            aes128_ctr_hmac_sha256_segment_1mb_key_template,
62        );
63        tink_core::registry::register_template_generator(
64            "AES256_CTR_HMAC_SHA256_4KB",
65            aes256_ctr_hmac_sha256_segment_4kb_key_template,
66        );
67        tink_core::registry::register_template_generator(
68            "AES256_CTR_HMAC_SHA256_1MB",
69            aes256_ctr_hmac_sha256_segment_1mb_key_template,
70        );
71        tink_core::registry::register_template_generator(
72            "AES128_GCM_HKDF_4KB",
73            aes128_gcm_hkdf_4kb_key_template,
74        );
75        tink_core::registry::register_template_generator(
76            "AES128_GCM_HKDF_1MB",
77            aes128_gcm_hkdf_1mb_key_template,
78        );
79        tink_core::registry::register_template_generator(
80            "AES256_GCM_HKDF_4KB",
81            aes256_gcm_hkdf_4kb_key_template,
82        );
83        tink_core::registry::register_template_generator(
84            "AES256_GCM_HKDF_1MB",
85            aes256_gcm_hkdf_1mb_key_template,
86        );
87    });
88}