Expand description
§Introduction
bc-crypto is a exposes a uniform API for the cryptographic primitives used in higher-level Blockchain Commons projects such as Gordian Envelope. The various providers listed below may change, but the API this package provides should be stable.
| Category | Algorithm | Provider |
|---|---|---|
| Cryptographic digest | SHA-256 | sha2 |
| Cryptographic digest | SHA-512 | sha2 |
| Hashed Message Authentication Codes | HMAC-SHA-256 | hmac |
| Hashed Message Authentication Codes | HMAC-SHA-512 | hmac |
| Password Expansion | PBKDF2-HMAC-SHA-256 | pbkdf2 |
| Key Derivation | HKDF-HMAC-SHA-256 | hkdf |
| Symmetric Encryption | IETF-ChaCha20-Poly1305 | chacha20poly1305 |
| Key Agreement | X25519 | x25519-dalek |
| Signing/Verification | ECDSA | secp256k1 |
| Signing/Verification | Schnorr | secp256k1 |
| Secure Random Number Generation | NA | getrandom, rand |
| Pseudorandom Number Generation | Xoshiro256** | rand_xoshiro |
§Getting Started
[dependencies]
bc-crypto = "0.14.0"Re-exports§
pub use error::Error;pub use error::Result;pub use hash::CRC32_SIZE;pub use hash::SHA256_SIZE;pub use hash::SHA512_SIZE;pub use hash::double_sha256;pub use hash::hkdf_hmac_sha256;pub use hash::hmac_sha256;pub use hash::hmac_sha512;pub use hash::pbkdf2_hmac_sha256;pub use hash::sha256;pub use hash::sha512;
Modules§
Constants§
- ECDSA_
MESSAGE_ HASH_ SIZE - ECDSA_
PRIVATE_ KEY_ SIZE - ECDSA_
PUBLIC_ KEY_ SIZE - ECDSA_
SIGNATURE_ SIZE - ECDSA_
UNCOMPRESSED_ PUBLIC_ KEY_ SIZE - ED25519_
PRIVATE_ KEY_ SIZE - ED25519_
PUBLIC_ KEY_ SIZE - ED25519_
SIGNATURE_ SIZE - SCHNORR_
PUBLIC_ KEY_ SIZE - SCHNORR_
SIGNATURE_ SIZE - SYMMETRIC_
AUTH_ SIZE - SYMMETRIC_
KEY_ SIZE - SYMMETRIC_
NONCE_ SIZE - X25519_
PRIVATE_ KEY_ SIZE - X25519_
PUBLIC_ KEY_ SIZE
Functions§
- aead_
chacha20_ poly1305_ decrypt - Symmetrically decrypts the given ciphertext using ChaCha20-Poly1305.
- aead_
chacha20_ poly1305_ decrypt_ with_ aad - Symmetrically decrypts the given ciphertext using ChaCha20-Poly1305 and the given additional authenticated data (AAD).
- aead_
chacha20_ poly1305_ encrypt - Symmetrically encrypts the given plaintext using ChaCha20-Poly1305.
- aead_
chacha20_ poly1305_ encrypt_ with_ aad - Symmetrically encrypts the given plaintext using ChaCha20-Poly1305 and the given additional authenticated data (AAD).
- argon2id
- derive_
agreement_ private_ key - Derive a 32-byte agreement private key from the given key material.
- derive_
signing_ private_ key - Derive a 32-byte signing private key from the given key material.
- ecdsa_
compress_ public_ key - Compresses the given ECDSA public key.
- ecdsa_
decompress_ public_ key - Decompresses the given ECDSA public key.
- ecdsa_
derive_ private_ key - Derives the ECDSA private key from the given key material.
- ecdsa_
new_ private_ key_ using - Generate a new ECDSA private key using the given random number generator.
- ecdsa_
public_ key_ from_ private_ key - Derives the ECDSA public key from the given private key.
- ecdsa_
sign - ECDSA signs the given message using the given private key.
- ecdsa_
verify - Verifies the given ECDSA signature using the given public key.
- ed25519_
new_ private_ key_ using - ed25519_
public_ key_ from_ private_ key - ed25519_
sign - ed25519_
verify - memzero
- Zero out a slice of bytes
- memzero_
vec_ vec_ u8 - Zero out a vector of vector of bytes
- schnorr_
public_ key_ from_ private_ key - Derives the Schnorr public key from the given private key.
- schnorr_
sign - schnorr_
sign_ using - schnorr_
sign_ with_ aux_ rand - schnorr_
verify - scrypt
- Computes the scrypt key derivation function using recommended parameters.
- scrypt_
opt - x25519_
new_ private_ key_ using - Create a new X25519 private key using the given random number generator.
- x25519_
public_ key_ from_ private_ key - Derive a X25519 public key from a private key.
- x25519_
shared_ key - Compute the shared symmetric key from the given X25519 private and public keys.