/components/sodiumoxide/src/lib.rs

https://gitlab.com/github-cloud-corporation/habitat · Rust · 94 lines · 36 code · 5 blank · 53 comment · 1 complexity · 718af5e6204bc1d432ef189a636f8432 MD5 · raw file

  1. //! Rust bindings to the [sodium library](https://github.com/jedisct1/libsodium).
  2. //!
  3. //! Sodium is a portable implementation of Dan Bernsteins [NaCl: Networking and
  4. //! Cryptography library](http://nacl.cr.yp.to)
  5. //!
  6. //! For most users, if you want public-key (asymmetric) cryptography you should use
  7. //! the functions in `crypto::box_` for encryption/decryption.
  8. //!
  9. //! If you want secret-key (symmetric) cryptography you should be using the
  10. //! functions in `crypto::secretbox` for encryption/decryption.
  11. //!
  12. //! For public-key signatures you should use the functions in `crypto::sign` for
  13. //! signature creation and verification.
  14. //!
  15. //! Unless you know what you're doing you most certainly don't want to use the
  16. //! functions in `crypto::scalarmult`, `crypto::stream`, `crypto::auth` and
  17. //! `crypto::onetimeauth`.
  18. //!
  19. //! ## Thread Safety
  20. //! All functions in this library are thread-safe provided that the `init()`
  21. //! function has been called during program execution.
  22. //!
  23. //! If `init()` hasn't been called then all functions except the random-number
  24. //! generation functions and the key-generation functions are thread-safe.
  25. //!
  26. //! # Public-key cryptography
  27. //! `crypto::box_`
  28. //!
  29. //! `crypto::sign`
  30. //!
  31. //! # Sealed boxes
  32. //! `crypto::sealedox`
  33. //!
  34. //! # Secret-key cryptography
  35. //! `crypto::secretbox`
  36. //!
  37. //! `crypto::stream`
  38. //!
  39. //! `crypto::auth`
  40. //!
  41. //! `crypto::onetimeauth`
  42. //!
  43. //! # Low-level functions
  44. //! `crypto::hash`
  45. //!
  46. //! `crypto::verify`
  47. //!
  48. //! `crypto::shorthash`
  49. #![crate_name = "sodiumoxide"]
  50. #![crate_type = "lib"]
  51. #![warn(missing_docs)]
  52. #![warn(non_upper_case_globals)]
  53. #![warn(non_camel_case_types)]
  54. #![warn(unused_qualifications)]
  55. extern crate libsodium_sys as ffi;
  56. extern crate libc;
  57. #[cfg(any(test, feature = "default"))]
  58. extern crate rustc_serialize;
  59. /// `init()` initializes the sodium library and chooses faster versions of
  60. /// the primitives if possible. `init()` also makes the random number generation
  61. /// functions (`gen_key`, `gen_keypair`, `gen_nonce`, `randombytes`, `randombytes_into`)
  62. /// thread-safe
  63. pub fn init() -> bool {
  64. unsafe {
  65. ffi::sodium_init() != -1
  66. }
  67. }
  68. mod marshal;
  69. #[macro_use]
  70. mod newtype_macros;
  71. pub mod randombytes;
  72. pub mod utils;
  73. #[cfg(test)]
  74. mod test_utils;
  75. /// Cryptographic functions
  76. pub mod crypto {
  77. pub mod box_;
  78. pub mod sealedbox;
  79. pub mod sign;
  80. pub mod scalarmult;
  81. pub mod auth;
  82. pub mod hash;
  83. pub mod secretbox;
  84. pub mod onetimeauth;
  85. pub mod pwhash;
  86. pub mod stream;
  87. pub mod shorthash;
  88. pub mod verify;
  89. }