bc_crypto/
lib.rs

1#![doc(html_root_url = "https://docs.rs/bc-crypto/0.14.0")]
2#![warn(rust_2018_idioms)]
3
4//! # Introduction
5//!
6//! `bc-crypto` is a exposes a uniform API for the cryptographic primitives used in higher-level [Blockchain Commons](https://blockchaincommons.com) projects such as [Gordian Envelope](https://crates.io/crates/bc-envelope). The various providers listed below may change, but the API this package provides should be stable.
7//!
8//! | Category | Algorithm | Provider
9//! |---|---|---
10//! | Cryptographic digest | SHA-256 | [sha2](https://crates.io/crates/sha2)
11//! | Cryptographic digest | SHA-512 | [sha2](https://crates.io/crates/sha2)
12//! | Hashed Message Authentication Codes | HMAC-SHA-256 | [hmac](https://crates.io/crates/hmac)
13//! | Hashed Message Authentication Codes | HMAC-SHA-512 | [hmac](https://crates.io/crates/hmac)
14//! | Password Expansion | PBKDF2-HMAC-SHA-256 | [pbkdf2](https://crates.io/crates/pbkdf2)
15//! | Key Derivation | HKDF-HMAC-SHA-256 |  [hkdf](https://crates.io/crates/hkdf)
16//! | Symmetric Encryption | IETF-ChaCha20-Poly1305 | [chacha20poly1305](https://crates.io/crates/chacha20poly1305)
17//! | Key Agreement | X25519 | [x25519-dalek](https://crates.io/crates/x25519-dalek)
18//! | Signing/Verification | ECDSA | [secp256k1](https://crates.io/crates/secp256k1)
19//! | Signing/Verification | Schnorr | [secp256k1](https://crates.io/crates/secp256k1)
20//! | Secure Random Number Generation | NA | [getrandom](https://crates.io/crates/getrandom), [rand](https://crates.io/crates/rand)
21//! | Pseudorandom Number Generation | Xoshiro256** | [rand_xoshiro](https://crates.io/crates/rand_xoshiro)
22//!
23//! # Getting Started
24//!
25//! ```toml
26//! [dependencies]
27//! bc-crypto = "0.14.0"
28//! ```
29
30pub mod error;
31pub use error::{Error, Result};
32
33/// The `hash` module contains functions for hashing data.
34pub mod hash;
35pub use hash::{
36    CRC32_SIZE, SHA256_SIZE, SHA512_SIZE, double_sha256, hkdf_hmac_sha256,
37    hmac_sha256, hmac_sha512, pbkdf2_hmac_sha256, sha256, sha512,
38};
39
40mod memzero;
41pub use memzero::{memzero, memzero_vec_vec_u8};
42
43mod symmetric_encryption;
44pub use symmetric_encryption::{
45    SYMMETRIC_AUTH_SIZE, SYMMETRIC_KEY_SIZE, SYMMETRIC_NONCE_SIZE,
46    aead_chacha20_poly1305_decrypt, aead_chacha20_poly1305_decrypt_with_aad,
47    aead_chacha20_poly1305_encrypt, aead_chacha20_poly1305_encrypt_with_aad,
48};
49
50mod public_key_encryption;
51pub use public_key_encryption::{
52    X25519_PRIVATE_KEY_SIZE, X25519_PUBLIC_KEY_SIZE,
53    derive_agreement_private_key, derive_signing_private_key,
54    x25519_new_private_key_using, x25519_public_key_from_private_key,
55    x25519_shared_key,
56};
57
58#[cfg(feature = "secp256k1")]
59mod ecdsa_keys;
60#[cfg(feature = "secp256k1")]
61pub use ecdsa_keys::{
62    ECDSA_MESSAGE_HASH_SIZE, ECDSA_PRIVATE_KEY_SIZE, ECDSA_PUBLIC_KEY_SIZE,
63    ECDSA_SIGNATURE_SIZE, ECDSA_UNCOMPRESSED_PUBLIC_KEY_SIZE,
64    SCHNORR_PUBLIC_KEY_SIZE, ecdsa_compress_public_key,
65    ecdsa_decompress_public_key, ecdsa_derive_private_key,
66    ecdsa_new_private_key_using, ecdsa_public_key_from_private_key,
67    schnorr_public_key_from_private_key,
68};
69
70#[cfg(feature = "secp256k1")]
71mod ecdsa_signing;
72#[cfg(feature = "secp256k1")]
73pub use ecdsa_signing::{ecdsa_sign, ecdsa_verify};
74
75#[cfg(feature = "secp256k1")]
76mod schnorr_signing;
77#[cfg(feature = "secp256k1")]
78pub use schnorr_signing::{
79    SCHNORR_SIGNATURE_SIZE, schnorr_sign, schnorr_sign_using,
80    schnorr_sign_with_aux_rand, schnorr_verify,
81};
82
83#[cfg(feature = "ed25519")]
84mod ed25519_signing;
85#[cfg(feature = "ed25519")]
86pub use ed25519_signing::{
87    ED25519_PRIVATE_KEY_SIZE, ED25519_PUBLIC_KEY_SIZE, ED25519_SIGNATURE_SIZE,
88    ed25519_new_private_key_using, ed25519_public_key_from_private_key,
89    ed25519_sign, ed25519_verify,
90};
91
92mod scrypt;
93pub use scrypt::{scrypt, scrypt_opt};
94
95mod argon;
96pub use argon::argon2id;
97
98#[cfg(test)]
99mod tests {
100    #[test]
101    fn test_readme_deps() {
102        version_sync::assert_markdown_deps_updated!("README.md");
103    }
104
105    #[test]
106    fn test_html_root_url() {
107        version_sync::assert_html_root_url_updated!("src/lib.rs");
108    }
109}