[已弃用] 氨化钠: 适用于 Rust 的快速密码库(与 libsodium 进行绑定)
[DEPRECATED]
This project has reached the end of its development as a cryptographic library for rust. Feel free to browse the code, and feel free to use it, but it will not see any more updates (unless a security issue arises, those will be fixed).
The cryptographic landscape of rust has vastly changed since this library was introduced to the community, and we believe that if you need a featureset that goes beyond what this library delivers there are other libraries that would work well.
It's been fun, but the last couple of years I haven't been able to give this library the attention I feel that it deserves, so now it's time to formally deprecate it.
|Crate|Documentation|Gitter|
|:---:|:-----------:|:--------:|:-----:|:------:|:----:|
||
|
|
NaCl (pronounced "salt") is a new easy-to-use high-speed software library for network communication, encryption, decryption, signatures, etc. NaCl's goal is to provide all of the core operations needed to build higher-level cryptographic tools. Of course, other libraries already exist for these core operations. NaCl advances the state of the art by improving security, by improving usability, and by improving speed.
Sodium is a portable, cross-compilable, installable, packageable fork of NaCl (based on the latest released upstream version nacl-20110221), with a compatible API.
This package aims to provide a type-safe and efficient Rust binding that's just as easy to use. Rust >= 1.36.0 is required because of mem::MaybeUninit.
git clone https://github.com/sodiumoxide/sodiumoxide.git
cd sodiumoxide
git submodule update --init --recursivecargo buildcargo testcargo docDocumentation will be generated in target/doc/...
Most documentation is taken from NaCl, with minor modification where the API differs between the C and Rust versions.
The AES AEAD variant crypto_aead_aes256gcm requires hardware support for the
AES and CLMUL instruction set extensions to x86; you can read why that's the
case
here. These instruction set extensions were first made
available in Intel Westmere (early 2010) and at the time of writing x86 hardware
support for them is near universal.
Libsodium exposes an API for runtime feature detection and doesn't prevent
you from calling crypto_aead_aes256gcm on a machine lacking AES and
CMUL expressions; doing so will result in a runtime SIGILL (illegal
instruction). By contrast sodiumoxide exposes an API that precludes the use of
the crypto_aead_aes256gcm_* family of functions without performing the runtime
check. It's important to note that the use of sodiumoxide::init() is mandatory
when using AES; unless you call init calls aead::aes256gcm::Aes256Gcm::new()
will always return Err(_) even if your runtime hardware supports AES.
C compiler (cc, clang, ...) must be installed in order to build libsodium from source.
This project contains a snapshot of libsodium and builds it by default, favouring a statically-built, fixed version of the native library.
Although it is highly recommended to use the default way with the pinned version, there are several ways you may want to use this crate:
You can do this by setting environment variables.
| Name | Description | Example value | Notes |
|---|---|---|---|
SODIUM_LIB_DIR |
Where to find a precompiled library | /usr/lib/x86_64-linux-gnu/ |
The value should be set to the directory containing .so,.a,.la,.dll or .lib |
SODIUM_SHARED |
Tell rustc to link the library dynamically |
1 |
Works only with SODIUM_LIB_DIR. We check only the presence |
SODIUM_USE_PKG_CONFIG |
Tell build.rs to find system library using pkg-config | 1 |
We check only the presence |
SODIUM_DISABLE_PIE |
Build with --disable-pie |
1 |
Certain situations may require building libsodium configured with --disable-pie. Useful for !Windows only and when building libsodium from source. We check only the presence |
(Ubuntu: apt install pkg-config, OSX: brew install pkg-config, ...)
export SODIUM_USE_PKG_CONFIG=1
cargo buildSee https://download.libsodium.org/doc/installation.
export SODIUM_LIB_DIR=/home/user/libsodium-1.0.18/release/lib/
export SODIUM_SHARED=1
cargo buildSeveral optional features are available:
std (default: enabled). When this feature is disabled,
sodiumoxide builds using #![no_std]. Some functionality may be lost.
serde (default: enabled). Allows serialization and deserialization of
keys, authentication tags, etc. using the
serde library.
benchmarks (default: disabled). Compile benchmark tests. Requires a
nightly build of Rust.
sudo apt update
sudo apt install build-essential gcc-arm-linux-gnueabihf libc6-armhf-cross libc6-dev-armhf-cross -y
rustup target add armv7-unknown-linux-gnueabihf[target.armv7-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"cargo build --release --target armv7-unknown-linux-gnueabihf[target.armv7-unknown-linux-musleabihf]
linker = "arm-buildroot-linux-musleabihf-gcc"…sudo apt update
sudo apt install build-essential gcc-multilib -y
rustup target add i686-unknown-linux-gnucargo build --release --target i686-unknown-linux-gnuTBD
Sodiumoxide has been tested on:
File bugs in the issue tracker
Master git repository
git clone https://github.com/sodiumoxide/sodiumoxide.gitLicensed under either of
at your option.
Go through the CONTRIBUTING.md document to know more about how to contribute to this project.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
We believe in creating an enabling community for developers and have laid out a general code of conduct. Please read and adopt it to help us achieve and maintain the desired community standards.
暂无开放 Issues,或尚未同步最近议题。