Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr. Capybara committed Oct 17, 2023
1 parent 929b2bc commit bce157a
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 84 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "capycrypt"
version = "0.3.1"
version = "0.4.0"
edition = "2021"

license = "MIT"
Expand Down
57 changes: 30 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ A complete Rust cryptosystem implementing FIPS 202 paired with a variety of Edwa
## Installation
Add the following line to your `Cargo.toml` file:
```toml
capycrypt = "0.3.1"
capycrypt = "0.4.0"
```

### Note: Building the `rug` Crate
Expand All @@ -32,24 +32,6 @@ apt-get install m4
```

## Quick Start

### Schnorr Signatures:
```rust
use capycrypt::{KeyPair, Message, Signable};
// Get random 5mb
let mut msg = Message::new(&mut get_random_bytes(5242880));
// Get a random password
let pw = get_random_bytes(64);
// Generate a public/private keypair
let mut key_pair = KeyPair::new(&pw, "test key".to_string(), E448, 512);

// Sign the message with the private key
msg.sign(&mut key_pair, 512);
// Verify the message with the public key
msg.verify(key_pair.pub_key, 512);
assert!(msg.op_result.unwrap());
```

### Compute Digest:
```rust
use capycrypt::{Hashable, Message};
Expand All @@ -65,19 +47,24 @@ assert!(hex::encode(data.digest.unwrap().to_vec()) == expected);
### Symmetric Encrypt/Decrypt:
```rust
use capycrypt::{Message, PwEncryptable};

let pw = get_random_bytes(64); // Get a random password
let mut msg = Message::new(&mut get_random_bytes(5242880)); // Get 5mb random data

msg.pw_encrypt(&mut pw.clone(), 512); // Encrypt the data with 512 bits of security
msg.pw_decrypt(&mut pw.clone(), 512); // Decrypt the data

assert!(msg.op_result.unwrap()); // Verify operation success
use capycrypt::sha3::{aux_functions::{byte_utils::{get_random_bytes}}};
// Get a random password
let pw = get_random_bytes(64);
// Get 5mb random data
let mut msg = Message::new(&mut get_random_bytes(5242880));

// Encrypt the data with 512 bits of security
msg.pw_encrypt(&mut pw.clone(), 512);
// Decrypt the data
msg.pw_decrypt(&mut pw.clone(), 512);
// Verify operation success
assert!(msg.op_result.unwrap());
```

### Asymmetric Encrypt/Decrypt:
```rust
use capycrypt::{Message, KeyEncryptable};
use capycrypt::sha3::{aux_functions::{byte_utils::{get_random_bytes}}};
// 5mb random data
let mut msg = Message::new(&mut get_random_bytes(5242880));
// Generate a private/public keypair
Expand All @@ -91,7 +78,23 @@ msg.key_decrypt(&key_pair.priv_key, 256);
assert!(msg.op_result.unwrap());
```

### Schnorr Signatures:
```rust
use capycrypt::{KeyPair, Message, Signable};
use capycrypt::sha3::{aux_functions::{byte_utils::{get_random_bytes}}};
// Get random 5mb
let mut msg = Message::new(&mut get_random_bytes(5242880));
// Get a random password
let pw = get_random_bytes(64);
// Generate a public/private keypair
let mut key_pair = KeyPair::new(&pw, "Key Tester".to_string(), E448, 512);

// Sign the message with the private key
msg.sign(&key_pair, 512);
// Verify the message with the public key
msg.verify(&key_pair.pub_key, 512);
assert!(msg.op_result.unwrap());
```

## Benches
This library uses the criterion crate for benches. Running:
Expand Down
2 changes: 1 addition & 1 deletion benches/benchmark_e222_256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn key_gen_enc_dec(pw: &mut Vec<u8>, mut msg: Message) {
/// Signature generation + verification roundtrip
pub fn sign_verify(mut key_pair: KeyPair, mut msg: Message) {
msg.sign(&mut key_pair, 512);
msg.verify(key_pair.pub_key, 512);
msg.verify(&key_pair.pub_key, 512);
}

fn bench_sign_verify(c: &mut Criterion) {
Expand Down
2 changes: 1 addition & 1 deletion benches/benchmark_e521_512.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn key_gen_enc_dec(pw: &mut Vec<u8>, mut msg: Message) {
/// Signature generation + verification roundtrip
pub fn sign_verify(mut key_pair: KeyPair, mut msg: Message) {
msg.sign(&mut key_pair, 512);
msg.verify(key_pair.pub_key, 512);
msg.verify(&key_pair.pub_key, 512);
}

fn bench_sign_verify(c: &mut Criterion) {
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ pub trait KeyEncryptable {
}

pub trait Signable {
fn sign(&mut self, key: &mut KeyPair, d: u64);
fn verify(&mut self, pub_key: EdCurvePoint, d: u64);
fn sign(&mut self, key: &KeyPair, d: u64);
fn verify(&mut self, pub_key: &EdCurvePoint, d: u64);
}
Loading

0 comments on commit bce157a

Please sign in to comment.