crypto_bigint/lib.rs
1//! Pure Rust implementation of a big integer library designed for cryptography.
2//!
3//! # About
4//! This library has been designed from the ground-up for use in cryptographic
5//! applications. It provides constant-time, `no_std`-friendly implementations
6//! of modern formulas implemented using const generics.
7//!
8//! # Minimum Supported Rust Version
9//! **Rust 1.51** at a minimum.
10//!
11//! # Goals
12//! - No heap allocations i.e. `no_std`-friendly.
13//! - Constant-time by default using traits from the [`subtle`] crate.
14//! - Leverage what is possible today with const generics on `stable` rust.
15//! - Support `const fn` as much as possible, including decoding big integers from
16//! bytes/hex and performing arithmetic operations on them, with the goal of
17//! being able to compute values at compile-time.
18//!
19//! # Status
20//! This library presently provides only a baseline level of functionality.
21//! It's new, unaudited, and may contain bugs. We recommend that it only be
22//! used in an experimental capacity for now.
23//!
24//! Please see the [feature wishlist tracking ticket] for more information.
25//!
26//! # `generic-array` interop
27//! When the optional `generic-array` feature is enabled, this library provides
28//! an [`ArrayEncoding`] trait which can be used to serialize/deserialize big
29//! integer values as `GenericArray<u8, N>`.
30//!
31//! [feature wishlist tracking ticket]: https://github.com/RustCrypto/utils/issues/453
32
33#![no_std]
34#![cfg_attr(docsrs, feature(doc_cfg))]
35#![doc(
36 html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg",
37 html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg",
38 html_root_url = "https://docs.rs/crypto-bigint/0.2.5"
39)]
40#![forbid(unsafe_code, clippy::unwrap_used)]
41#![warn(missing_docs, rust_2018_idioms, unused_qualifications)]
42
43#[cfg(all(feature = "alloc", test))]
44extern crate alloc;
45
46#[macro_use]
47mod macros;
48
49#[cfg(feature = "generic-array")]
50mod array;
51mod checked;
52pub mod limb;
53mod traits;
54mod uint;
55mod wrapping;
56
57pub use crate::{checked::Checked, limb::Limb, traits::*, uint::*, wrapping::Wrapping};
58pub use subtle;
59
60#[cfg(feature = "generic-array")]
61pub use {
62 self::array::{ArrayEncoding, ByteArray},
63 generic_array::{self, typenum::consts},
64};
65
66/// Number of bytes in a [`Limb`].
67#[cfg(target_pointer_width = "32")]
68#[deprecated(since = "0.2.2", note = "use `Limb::BYTE_SIZE` instead")]
69pub const LIMB_BYTES: usize = 4;
70
71/// Number of bytes in a [`Limb`].
72#[cfg(target_pointer_width = "64")]
73#[deprecated(since = "0.2.2", note = "use `Limb::BYTE_SIZE` instead")]
74pub const LIMB_BYTES: usize = 8;