ring/
lib.rs

1// Copyright 2015-2016 Brian Smith.
2//
3// Permission to use, copy, modify, and/or distribute this software for any
4// purpose with or without fee is hereby granted, provided that the above
5// copyright notice and this permission notice appear in all copies.
6//
7// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
15//! # Feature Flags
16//!
17//! <table>
18//! <tr><th>Feature
19//!     <th>Description
20//! <tr><td><code>alloc (default)</code>
21//!     <td>Enable features that require use of the heap, RSA in particular.
22//! <tr><td><code>less-safe-getrandom-custom-or-rdrand</code>
23//!     <td>Treat user-provided ("custom") and RDRAND-based <code>getrandom</code>
24//!         implementations as secure random number generators (see
25//!         <code>SecureRandom</code>). This feature only works with
26//!         <code>os = "none"</code> targets. See
27//!         <a href="https://docs.rs/getrandom/0.2.10/getrandom/macro.register_custom_getrandom.html">
28//!             <code>register_custom_getrandom</code>
29//!         </a> and <a href="https://docs.rs/getrandom/0.2.10/getrandom/#rdrand-on-x86">
30//!             RDRAND on x86
31//!         </a> for additional details.
32//! <tr><td><code>less-safe-getrandom-espidf</code>
33//!     <td>Treat getrandom as a secure random number generator (see
34//!         <code>SecureRandom</code>) on the esp-idf target. While the esp-idf
35//!         target does have hardware RNG, it is beyond the scope of ring to
36//!         ensure its configuration. This feature allows ring to build
37//!         on esp-idf despite the likelihood that RNG is not secure.
38//!         This feature only works with <code>os = espidf</code> targets.
39//!         See <a href="https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/random.html">
40//! <tr><td><code>std</code>
41//!     <td>Enable features that use libstd, in particular
42//!         <code>std::error::Error</code> integration. Implies `alloc`.
43//! <tr><td><code>wasm32_unknown_unknown_js</code>
44//!     <td>When this feature is enabled, for the wasm32-unknown-unknown target,
45//!         Web APIs will be used to implement features like `ring::rand` that
46//!         require an operating environment of some kind. This has no effect
47//!         for any other target. This enables the `getrandom` crate's `js`
48//!         feature.
49//! </table>
50
51// When running mk/package.sh, don't actually build any code.
52#![allow(
53    clippy::collapsible_if,
54    clippy::identity_op,
55    clippy::len_without_is_empty,
56    clippy::let_unit_value,
57    clippy::new_without_default,
58    clippy::neg_cmp_op_on_partial_ord,
59    clippy::too_many_arguments,
60    clippy::type_complexity,
61    non_camel_case_types,
62    non_snake_case,
63    unsafe_code
64)]
65#![deny(variant_size_differences)]
66#![forbid(
67    unused_results,
68    unsafe_op_in_unsafe_fn,
69    clippy::char_lit_as_u8,
70    clippy::fn_to_numeric_cast,
71    clippy::fn_to_numeric_cast_with_truncation,
72    clippy::ptr_as_ptr
73)]
74#![warn(
75    clippy::unnecessary_cast,
76    clippy::cast_lossless,
77    clippy::cast_possible_truncation,
78    clippy::cast_possible_wrap,
79    clippy::cast_precision_loss,
80    clippy::cast_sign_loss
81)]
82#![cfg_attr(
83    not(any(
84        all(target_arch = "aarch64", target_endian = "little"),
85        all(target_arch = "arm", target_endian = "little"),
86        target_arch = "x86",
87        target_arch = "x86_64",
88        feature = "alloc"
89    )),
90    allow(dead_code, unused_imports, unused_macros)
91)]
92#![no_std]
93
94#[cfg(feature = "alloc")]
95extern crate alloc;
96
97#[macro_use]
98mod debug;
99
100#[macro_use]
101mod prefixed;
102
103#[macro_use]
104pub mod test;
105
106#[macro_use]
107mod bssl;
108
109#[macro_use]
110mod polyfill;
111
112pub mod aead;
113
114pub mod agreement;
115mod arithmetic;
116mod bits;
117
118pub(crate) mod bb;
119pub(crate) mod c;
120
121#[doc(hidden)]
122#[deprecated(
123    note = "Will be removed. Internal module not intended for external use, with no promises regarding side channels."
124)]
125pub mod deprecated_constant_time;
126
127#[doc(hidden)]
128#[allow(deprecated)]
129#[deprecated(
130    note = "Will be removed. Internal module not intended for external use, with no promises regarding side channels."
131)]
132pub use deprecated_constant_time as constant_time;
133
134pub mod io;
135
136mod cpu;
137pub mod digest;
138mod ec;
139pub mod error;
140pub mod hkdf;
141pub mod hmac;
142mod limb;
143pub mod pbkdf2;
144pub mod pkcs8;
145pub mod rand;
146
147#[cfg(feature = "alloc")]
148pub mod rsa;
149
150pub mod signature;
151
152#[cfg(test)]
153mod tests;
154
155mod sealed {
156    /// Traits that are designed to only be implemented internally in *ring*.
157    //
158    // Usage:
159    // ```
160    // use crate::sealed;
161    //
162    // pub trait MyType: sealed::Sealed {
163    //     // [...]
164    // }
165    //
166    // impl sealed::Sealed for MyType {}
167    // ```
168    pub trait Sealed {}
169}