bc_crypto/
lib.rs

1#![doc(html_root_url = "https://docs.rs/bc-crypto/0.8.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.8.0"
28//! ```
29
30/// The `hash` module contains functions for hashing data.
31pub mod hash;
32pub use hash::{
33    sha256,
34    double_sha256,
35    sha512,
36    hmac_sha256,
37    hmac_sha512,
38    pbkdf2_hmac_sha256,
39    hkdf_hmac_sha256,
40    CRC32_SIZE,
41    SHA256_SIZE,
42    SHA512_SIZE,
43};
44
45mod memzero;
46pub use memzero::{ memzero, memzero_vec_vec_u8 };
47
48mod symmetric_encryption;
49pub use symmetric_encryption::{
50    aead_chacha20_poly1305_encrypt_with_aad,
51    aead_chacha20_poly1305_encrypt,
52    aead_chacha20_poly1305_decrypt_with_aad,
53    aead_chacha20_poly1305_decrypt,
54    SYMMETRIC_KEY_SIZE,
55    SYMMETRIC_NONCE_SIZE,
56    SYMMETRIC_AUTH_SIZE,
57};
58
59mod public_key_encryption;
60pub use public_key_encryption::{
61    x25519_new_private_key_using,
62    x25519_public_key_from_private_key,
63    x25519_derive_private_key,
64    x25519_derive_signing_private_key,
65    x25519_shared_key,
66    X25519_PRIVATE_KEY_SIZE,
67    X25519_PUBLIC_KEY_SIZE,
68};
69
70mod ecdsa_keys;
71pub use ecdsa_keys::{
72    ecdsa_new_private_key_using,
73    ecdsa_public_key_from_private_key,
74    ecdsa_decompress_public_key,
75    ecdsa_compress_public_key,
76    ecdsa_derive_private_key,
77    schnorr_public_key_from_private_key,
78    ECDSA_PRIVATE_KEY_SIZE,
79    ECDSA_PUBLIC_KEY_SIZE,
80    ECDSA_UNCOMPRESSED_PUBLIC_KEY_SIZE,
81    ECDSA_MESSAGE_HASH_SIZE,
82    ECDSA_SIGNATURE_SIZE,
83    SCHNORR_PUBLIC_KEY_SIZE,
84};
85
86mod ecdsa_signing;
87pub use ecdsa_signing::{ ecdsa_sign, ecdsa_verify };
88
89mod schnorr_signing;
90pub use schnorr_signing::{
91    schnorr_sign,
92    schnorr_sign_using,
93    schnorr_sign_with_aux_rand,
94    schnorr_verify,
95    SCHNORR_SIGNATURE_SIZE,
96};
97
98mod ed25519_signing;
99pub use ed25519_signing::{
100    ed25519_new_private_key_using,
101    ed25519_public_key_from_private_key,
102    ed25519_sign,
103    ed25519_verify,
104    ED25519_PRIVATE_KEY_SIZE,
105    ED25519_PUBLIC_KEY_SIZE,
106    ED25519_SIGNATURE_SIZE,
107};
108
109mod scrypt;
110pub use scrypt::{ scrypt, scrypt_opt };
111
112#[cfg(test)]
113mod tests {
114    #[test]
115    fn test_readme_deps() {
116        version_sync::assert_markdown_deps_updated!("README.md");
117    }
118
119    #[test]
120    fn test_html_root_url() {
121        version_sync::assert_html_root_url_updated!("src/lib.rs");
122    }
123}