tink_mac/
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 [`tink_core::Mac`] primitive.
18//!
19//! MAC computes a tag for a given message that can be used to authenticate a
20//! message.  MAC protects data integrity as well as provides for authenticity
21//! of the message.
22
23#![deny(broken_intra_doc_links)]
24
25use std::sync::Once;
26
27mod aes_cmac_key_manager;
28pub use aes_cmac_key_manager::*;
29mod factory;
30pub use factory::*;
31mod hmac_key_manager;
32pub use hmac_key_manager::*;
33mod key_templates;
34pub use key_templates::*;
35
36pub mod subtle;
37
38/// The [upstream Tink](https://github.com/google/tink) version that this Rust
39/// port is based on.
40pub const UPSTREAM_VERSION: &str = "1.6.0";
41
42static INIT: Once = Once::new();
43
44/// Initialize the `tink-daead` crate, registering its primitives so they are available via
45/// Tink.
46pub fn init() {
47    INIT.call_once(|| {
48        tink_core::registry::register_key_manager(std::sync::Arc::new(HmacKeyManager))
49            .expect("tink_mac::init() failed"); // safe: init
50        tink_core::registry::register_key_manager(std::sync::Arc::new(AesCmacKeyManager))
51            .expect("tink_mac::init() failed"); // safe: init
52
53        tink_core::registry::register_template_generator(
54            "HMAC_SHA256_128BITTAG",
55            hmac_sha256_tag128_key_template,
56        );
57        tink_core::registry::register_template_generator(
58            "HMAC_SHA256_256BITTAG",
59            hmac_sha256_tag256_key_template,
60        );
61        tink_core::registry::register_template_generator(
62            "HMAC_SHA512_256BITTAG",
63            hmac_sha512_tag256_key_template,
64        );
65        tink_core::registry::register_template_generator(
66            "HMAC_SHA512_512BITTAG",
67            hmac_sha512_tag512_key_template,
68        );
69        tink_core::registry::register_template_generator("AES_CMAC", aes_cmac_tag128_key_template);
70    });
71}