diem_crypto/
lib.rs

1// Copyright (c) The Diem Core Contributors
2// SPDX-License-Identifier: Apache-2.0
3
4// Copyright 2021 Conflux Foundation. All rights reserved.
5// Conflux is free software and distributed under GNU General Public License.
6// See http://www.gnu.org/licenses/
7
8#![forbid(unsafe_code)]
9#![deny(missing_docs)]
10//! This feature gets turned on only if diem-crypto is compiled via MIRAI in a
11//! nightly build.
12#![cfg_attr(mirai, allow(incomplete_features), feature(const_generics))]
13
14//! A library supplying various cryptographic primitives
15
16/// A BLS signature wrapper
17pub mod bls;
18pub mod compat;
19/// A Elliptic Curve VRF wrapper
20pub mod ec_vrf;
21pub mod ed25519;
22pub mod error;
23pub mod hash;
24pub mod hkdf;
25/// A multi bls signature wrapper
26pub mod multi_bls;
27pub mod multi_ed25519;
28pub mod noise;
29pub mod test_utils;
30pub mod traits;
31/// VDF SHA256.
32pub mod vdf_sha3;
33pub mod x25519;
34
35#[cfg(test)]
36mod unit_tests;
37
38/// Utility to store encrypted private keys
39pub mod key_file;
40#[cfg(mirai)]
41mod tags;
42
43pub use self::traits::*;
44pub use hash::HashValue;
45
46// Reexport once_cell and serde_name for use in CryptoHasher Derive
47// implementation.
48#[doc(hidden)]
49pub use once_cell as _once_cell;
50#[doc(hidden)]
51pub use serde_name as _serde_name;
52
53// We use [formally verified arithmetic](https://crates.io/crates/fiat-crypto)
54// in maintained forks of the dalek suite of libraries ({curve, ed,
55// x}25519-dalek). This is controlled by a feature in the forked crates
56// ('fiat_u64_backend'), which we turn on by default.
57#[cfg(not(any(feature = "fiat", feature = "u64", feature = "u32")))]
58compile_error!(
59    "no dalek arithmetic backend cargo feature enabled! \
60     please enable one of: fiat, u64, u32"
61);
62
63#[cfg(all(feature = "fiat", feature = "u64"))]
64compile_error!(
65    "at most one dalek arithmetic backend cargo feature should be enabled! \
66     please enable exactly one of: fiat, u64, u32"
67);
68
69#[cfg(all(feature = "fiat", feature = "u32"))]
70compile_error!(
71    "at most one dalek arithmetic backend cargo feature should be enabled! \
72     please enable exactly one of: fiat, u64, u32"
73);
74
75#[cfg(all(feature = "u64", feature = "u32"))]
76compile_error!(
77    "at most one dalek arithmetic backend cargo feature should be enabled! \
78     please enable exactly one of: fiat, u64, u32"
79);
80
81// MIRAI's tag analysis makes use of the incomplete const_generics feature, so
82// the module containing the definitions of MIRAI tag types should not get
83// compiled in a release build. The code below fails a build of the crate if
84// mirai is on but debug_assertions is not.
85#[cfg(all(mirai, not(debug_assertions)))]
86compile_error!("MIRAI can only be used to compile the crate in a debug build!");