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 AUTHORS DISCLAIM ALL WARRANTIES |
8 | // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
9 | // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS 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 | //! Safe, fast, small crypto using Rust with BoringSSL's cryptography |
16 | //! primitives. |
17 | //! |
18 | //! # Feature Flags |
19 | //! |
20 | //! <table> |
21 | //! <tr><th>Feature |
22 | //! <th>Description |
23 | //! <tr><td><code>alloc (default)</code> |
24 | //! <td>Enable features that require use of the heap, RSA in particular. |
25 | //! <tr><td><code>less-safe-getrandom-custom-or-rdrand</code> |
26 | //! <td>Treat user-provided ("custom") and RDRAND-based <code>getrandom</code> |
27 | //! implementations as secure random number generators (see |
28 | //! <code>SecureRandom</code>). This feature only works with |
29 | //! <code>os = "none"</code> targets. See |
30 | //! <a href="https://docs.rs/getrandom/0.2.10/getrandom/macro.register_custom_getrandom.html"> |
31 | //! <code>register_custom_getrandom</code> |
32 | //! </a> and <a href="https://docs.rs/getrandom/0.2.10/getrandom/#rdrand-on-x86"> |
33 | //! RDRAND on x86 |
34 | //! </a> for additional details. |
35 | //! <tr><td><code>less-safe-getrandom-espidf</code> |
36 | //! <td>Treat getrandom as a secure random number generator (see |
37 | //! <code>SecureRandom</code>) on the esp-idf target. While the esp-idf |
38 | //! target does have hardware RNG, it is beyond the scope of ring to |
39 | //! ensure its configuration. This feature allows ring to build |
40 | //! on esp-idf despite the likelihood that RNG is not secure. |
41 | //! This feature only works with <code>os = espidf</code> targets. |
42 | //! See <a href="https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/random.html"> |
43 | //! <tr><td><code>std</code> |
44 | //! <td>Enable features that use libstd, in particular |
45 | //! <code>std::error::Error</code> integration. Implies `alloc`. |
46 | //! <tr><td><code>wasm32_unknown_unknown_js</code> |
47 | //! <td>When this feature is enabled, for the wasm32-unknown-unknown target, |
48 | //! Web APIs will be used to implement features like `ring::rand` that |
49 | //! require an operating environment of some kind. This has no effect |
50 | //! for any other target. This enables the `getrandom` crate's `js` |
51 | //! feature. |
52 | //! </table> |
53 | |
54 | // When running mk/package.sh, don't actually build any code. |
55 | #![allow ( |
56 | clippy::collapsible_if, |
57 | clippy::identity_op, |
58 | clippy::len_without_is_empty, |
59 | clippy::let_unit_value, |
60 | clippy::new_without_default, |
61 | clippy::neg_cmp_op_on_partial_ord, |
62 | clippy::too_many_arguments, |
63 | clippy::type_complexity, |
64 | non_camel_case_types, |
65 | non_snake_case, |
66 | unsafe_code |
67 | )] |
68 | #![deny (variant_size_differences)] |
69 | #![forbid ( |
70 | unused_results, |
71 | unsafe_op_in_unsafe_fn, |
72 | clippy::char_lit_as_u8, |
73 | clippy::fn_to_numeric_cast, |
74 | clippy::fn_to_numeric_cast_with_truncation, |
75 | clippy::ptr_as_ptr |
76 | )] |
77 | #![warn ( |
78 | clippy::unnecessary_cast, |
79 | clippy::cast_lossless, |
80 | clippy::cast_possible_truncation, |
81 | clippy::cast_possible_wrap, |
82 | clippy::cast_precision_loss, |
83 | clippy::cast_sign_loss |
84 | )] |
85 | #![cfg_attr ( |
86 | not(any( |
87 | all(target_arch = "aarch64" , target_endian = "little" ), |
88 | all(target_arch = "arm" , target_endian = "little" ), |
89 | target_arch = "x86" , |
90 | target_arch = "x86_64" , |
91 | feature = "alloc" |
92 | )), |
93 | allow(dead_code, unused_imports, unused_macros) |
94 | )] |
95 | #![no_std ] |
96 | |
97 | #[cfg (feature = "alloc" )] |
98 | extern crate alloc; |
99 | |
100 | #[macro_use ] |
101 | mod debug; |
102 | |
103 | #[macro_use ] |
104 | mod prefixed; |
105 | |
106 | #[macro_use ] |
107 | pub mod test; |
108 | |
109 | #[macro_use ] |
110 | mod bssl; |
111 | |
112 | #[macro_use ] |
113 | mod polyfill; |
114 | |
115 | pub mod aead; |
116 | |
117 | pub mod agreement; |
118 | mod arithmetic; |
119 | mod bits; |
120 | |
121 | pub(crate) mod c; |
122 | pub mod constant_time; |
123 | |
124 | pub mod io; |
125 | |
126 | mod cpu; |
127 | pub mod digest; |
128 | mod ec; |
129 | pub mod error; |
130 | pub mod hkdf; |
131 | pub mod hmac; |
132 | mod limb; |
133 | pub mod pbkdf2; |
134 | pub mod pkcs8; |
135 | pub mod rand; |
136 | |
137 | #[cfg (feature = "alloc" )] |
138 | pub mod rsa; |
139 | |
140 | pub mod signature; |
141 | |
142 | #[cfg (test)] |
143 | mod tests; |
144 | |
145 | mod sealed { |
146 | /// Traits that are designed to only be implemented internally in *ring*. |
147 | // |
148 | // Usage: |
149 | // ``` |
150 | // use crate::sealed; |
151 | // |
152 | // pub trait MyType: sealed::Sealed { |
153 | // // [...] |
154 | // } |
155 | // |
156 | // impl sealed::Sealed for MyType {} |
157 | // ``` |
158 | pub trait Sealed {} |
159 | } |
160 | |