[−][src]Crate lib3h_crypto_api
lib3h abstract cryptography traits and data types
Examples
extern crate lib3h_crypto_api; // CryptoSystem is designed to be used as a Generic Trait like this: fn test<SecBuf: lib3h_crypto_api::Buffer, Crypto: lib3h_crypto_api::CryptoSystem>() { let mut seed = SecBuf::new(Crypto::SIGN_SEED_BYTES).unwrap(); Crypto::randombytes_buf(&mut seed).unwrap(); let mut pubkey = vec![0; Crypto::SIGN_PUBLIC_KEY_BYTES]; let mut seckey = SecBuf::new(Crypto::SIGN_SECRET_KEY_BYTES).unwrap(); Crypto::sign_seed_keypair(&seed, &mut pubkey, &mut seckey).unwrap(); let mut signature = vec![0; Crypto::SIGN_BYTES]; Crypto::sign(&mut signature, &vec![1, 2, 3, 4], &seckey).unwrap(); assert!(Crypto::sign_verify(&signature, &vec![1, 2, 3, 4], &pubkey).unwrap()); assert!(!Crypto::sign_verify(&signature, &vec![4, 3, 2, 1], &pubkey).unwrap()); } fn main() { test::<lib3h_crypto_api::InsecureBuffer, lib3h_crypto_api::FakeCryptoSystem>(); }
Structs
FakeCryptoSystem | WARNING THIS IS NOT SECURE!! This is a fake crypto system to give hints for implementing real systems. The functions here mimic a real crypto system, but are doing trivial things. Do not use this for any real systems. Even the random functions are fake, and produce poor results. |
InsecureBuffer | You probably just want to use Vec |
ReadLocker | Helper object that will automatically secure a Buffer when dropped |
WriteLocker | Helper object that will automatically secure a Buffer when dropped |
Enums
CryptoError | Represents an error generated by the cryptography system |
ProtectState | Track if a buffer has read/write access or is memory protected. |
Traits
Buffer | The Buffer trait is used by crypto_api functions to exchange data.
It is implemented for Vec |
BufferType | This is a thunk so we don't have to type these trait bounds over and over |
CryptoRandom | Provides functions dealing with cryptographic randomness |
CryptoSignature | Provides functions dealing with cryptographic / digital signatures |
CryptoSystem | CryptoSystem pulls our crypto sub-system traits together |
Type Definitions
CryptoResult | represents a Result object returned by an api in the cryptography system |