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#[doc(hidden)]
104#[macro_use]
105mod testutil;
106
107#[macro_use]
108mod bssl;
109
110#[macro_use]
111mod polyfill;
112
113pub mod aead;
114
115pub mod agreement;
116mod arithmetic;
117mod bits;
118
119pub(crate) mod bb;
120pub(crate) mod c;
121
122#[doc(hidden)]
123#[deprecated(
124    note = "Will be removed. Internal module not intended for external use, with no promises regarding side channels."
125)]
126pub mod deprecated_constant_time;
127
128#[doc(hidden)]
129#[allow(deprecated)]
130#[deprecated(
131    note = "Will be removed. Internal module not intended for external use, with no promises regarding side channels."
132)]
133pub use deprecated_constant_time as constant_time;
134
135pub mod io;
136
137mod cpu;
138pub mod digest;
139mod ec;
140pub mod error;
141pub mod hkdf;
142pub mod hmac;
143mod limb;
144pub mod pbkdf2;
145pub mod pkcs8;
146pub mod rand;
147
148#[cfg(feature = "alloc")]
149pub mod rsa;
150
151pub mod signature;
152
153#[cfg(test)]
154mod tests;
155
156mod sealed {
157    /// Traits that are designed to only be implemented internally in *ring*.
158    //
159    // Usage:
160    // ```
161    // use crate::sealed;
162    //
163    // pub trait MyType: sealed::Sealed {
164    //     // [...]
165    // }
166    //
167    // impl sealed::Sealed for MyType {}
168    // ```
169    pub trait Sealed {}
170}
171
172#[deprecated(note = "internal API that will be removed")]
173pub mod deprecated_test;
174
175#[allow(deprecated)]
176#[deprecated(note = "internal API that will be removed")]
177pub use deprecated_test as test;