/components/sodiumoxide/src/lib.rs
https://gitlab.com/admin-github-cloud/habitat · Rust · 94 lines · 36 code · 5 blank · 53 comment · 1 complexity · 718af5e6204bc1d432ef189a636f8432 MD5 · raw file
- //! Rust bindings to the [sodium library](https://github.com/jedisct1/libsodium).
- //!
- //! Sodium is a portable implementation of Dan Bernsteins [NaCl: Networking and
- //! Cryptography library](http://nacl.cr.yp.to)
- //!
- //! For most users, if you want public-key (asymmetric) cryptography you should use
- //! the functions in `crypto::box_` for encryption/decryption.
- //!
- //! If you want secret-key (symmetric) cryptography you should be using the
- //! functions in `crypto::secretbox` for encryption/decryption.
- //!
- //! For public-key signatures you should use the functions in `crypto::sign` for
- //! signature creation and verification.
- //!
- //! Unless you know what you're doing you most certainly don't want to use the
- //! functions in `crypto::scalarmult`, `crypto::stream`, `crypto::auth` and
- //! `crypto::onetimeauth`.
- //!
- //! ## Thread Safety
- //! All functions in this library are thread-safe provided that the `init()`
- //! function has been called during program execution.
- //!
- //! If `init()` hasn't been called then all functions except the random-number
- //! generation functions and the key-generation functions are thread-safe.
- //!
- //! # Public-key cryptography
- //! `crypto::box_`
- //!
- //! `crypto::sign`
- //!
- //! # Sealed boxes
- //! `crypto::sealedox`
- //!
- //! # Secret-key cryptography
- //! `crypto::secretbox`
- //!
- //! `crypto::stream`
- //!
- //! `crypto::auth`
- //!
- //! `crypto::onetimeauth`
- //!
- //! # Low-level functions
- //! `crypto::hash`
- //!
- //! `crypto::verify`
- //!
- //! `crypto::shorthash`
- #![crate_name = "sodiumoxide"]
- #![crate_type = "lib"]
- #![warn(missing_docs)]
- #![warn(non_upper_case_globals)]
- #![warn(non_camel_case_types)]
- #![warn(unused_qualifications)]
- extern crate libsodium_sys as ffi;
- extern crate libc;
- #[cfg(any(test, feature = "default"))]
- extern crate rustc_serialize;
- /// `init()` initializes the sodium library and chooses faster versions of
- /// the primitives if possible. `init()` also makes the random number generation
- /// functions (`gen_key`, `gen_keypair`, `gen_nonce`, `randombytes`, `randombytes_into`)
- /// thread-safe
- pub fn init() -> bool {
- unsafe {
- ffi::sodium_init() != -1
- }
- }
- mod marshal;
- #[macro_use]
- mod newtype_macros;
- pub mod randombytes;
- pub mod utils;
- #[cfg(test)]
- mod test_utils;
- /// Cryptographic functions
- pub mod crypto {
- pub mod box_;
- pub mod sealedbox;
- pub mod sign;
- pub mod scalarmult;
- pub mod auth;
- pub mod hash;
- pub mod secretbox;
- pub mod onetimeauth;
- pub mod pwhash;
- pub mod stream;
- pub mod shorthash;
- pub mod verify;
- }