Skip to content

Commit

Permalink
Remove dependency on rust-crypto (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Varlakov authored Jan 4, 2022
1 parent c480a8a commit c80c87d
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 54 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ optional = true

[dev-dependencies]
criterion = "0.3"
rust-crypto = "0.2"
aes-gcm = "0.9.4"
hex = "0.4"
tokio = { version = "1", default-features = false, features = ["macros"] }
futures = "0.3"
rocket = { version = "0.5.0-rc.1", default-features = false, features = ["json"] }
reqwest = { version = "0.9", default-features = false }
uuid = { version = "0.8", features = ["v4"] }
serde_json = "1.0"
rand = "0.7"
rand = "0.8"
surf = "2"
async-sse = "5"
anyhow = "1"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ The following steps are for setup, key generation with `n` parties and signing w
2. Install [Rust](https://rustup.rs/). Run `cargo build --release --examples` (it will build into `/target/release/examples/`)
3. Run the shared state machine: `./gg18_sm_manager`. Currently configured to be in `127.0.0.1:8001`, this can be changed in `Rocket.toml` file. The `Rocket.toml` file should be in the same folder you run `sm_manager` from.
3. Run the shared state machine: `./gg18_sm_manager`. By default, it's configured to be in `127.0.0.1:8000`, this can be changed in `Rocket.toml` file. The `Rocket.toml` file should be in the same folder you run `sm_manager` from.

### KeyGen

run `gg18_keygen_client` as follows: `./gg18_keygen_client http://127.0.0.1:8001 keys.store`. Replace IP and port with the ones configured in setup. Once `n` parties join the application will run till finish. At the end each party will get a local keys file `keys.store` (change filename in command line). This contains secret and public data of the party after keygen. The file therefore should remain private.
run `gg18_keygen_client` as follows: `./gg18_keygen_client http://127.0.0.1:8000 keys.store`. Replace IP and port with the ones configured in setup. Once `n` parties join the application will run till finish. At the end each party will get a local keys file `keys.store` (change filename in command line). This contains secret and public data of the party after keygen. The file therefore should remain private.

### Sign

Expand All @@ -121,7 +121,7 @@ Simply put, the safest way to use the signing binary is to just always hex your
To sign the message `hello world`, first calculate its hexadecimal representation. This yields the `68656c6c6f20776f726c64`.
Then, run:
```bash
./gg18_sign_client http://127.0.0.1:8001 keys.store "68656c6c6f20776f726c64"
./gg18_sign_client http://127.0.0.1:8000 keys.store "68656c6c6f20776f726c64"
```
### GG18 demo
Expand Down
26 changes: 0 additions & 26 deletions Rocket.toml

This file was deleted.

47 changes: 27 additions & 20 deletions examples/common.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
use std::{env, iter::repeat, thread, time, time::Duration};
#![allow(dead_code)]

use std::{env, thread, time, time::Duration};

use aes_gcm::aead::{Aead, NewAead};
use aes_gcm::{Aes256Gcm, Nonce};
use rand::{rngs::OsRng, RngCore};

use crypto::{
aead::{AeadDecryptor, AeadEncryptor},
aes::KeySize::KeySize256,
aes_gcm::AesGcm,
};
use curv::{
arithmetic::traits::Converter,
elliptic::curves::{secp256_k1::Secp256k1, Point, Scalar},
BigInt,
};

use reqwest::Client;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -49,26 +51,31 @@ pub struct Params {

#[allow(dead_code)]
pub fn aes_encrypt(key: &[u8], plaintext: &[u8]) -> AEAD {
let nonce: Vec<u8> = repeat(3).take(12).collect();
let aad: [u8; 0] = [];
let mut gcm = AesGcm::new(KeySize256, key, &nonce[..], &aad);
let mut out: Vec<u8> = repeat(0).take(plaintext.len()).collect();
let mut out_tag: Vec<u8> = repeat(0).take(16).collect();
gcm.encrypt(plaintext, &mut out[..], &mut out_tag[..]);
let aes_key = aes_gcm::Key::from_slice(key);
let cipher = Aes256Gcm::new(aes_key);

let mut nonce = [0u8; 12];
OsRng.fill_bytes(&mut nonce);
let nonce = Nonce::from_slice(&nonce);

let ciphertext = cipher
.encrypt(nonce, plaintext)
.expect("encryption failure!");

AEAD {
ciphertext: out.to_vec(),
tag: out_tag.to_vec(),
ciphertext: ciphertext,
tag: nonce.to_vec(),
}
}

#[allow(dead_code)]
pub fn aes_decrypt(key: &[u8], aead_pack: AEAD) -> Vec<u8> {
let mut out: Vec<u8> = repeat(0).take(aead_pack.ciphertext.len()).collect();
let nonce: Vec<u8> = repeat(3).take(12).collect();
let aad: [u8; 0] = [];
let mut gcm = AesGcm::new(KeySize256, key, &nonce[..], &aad);
gcm.decrypt(&aead_pack.ciphertext[..], &mut out, &aead_pack.tag[..]);
out
let aes_key = aes_gcm::Key::from_slice(key);
let nonce = Nonce::from_slice(&aead_pack.tag);
let gcm = Aes256Gcm::new(aes_key);

let out = gcm.decrypt(nonce, aead_pack.ciphertext.as_slice());
out.unwrap()
}

pub fn postb<T>(client: &Client, path: &str, body: T) -> Option<String>
Expand Down
2 changes: 1 addition & 1 deletion examples/gg20_keygen.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{anyhow, ensure, Context, Result};
use anyhow::{anyhow, Context, Result};
use futures::StreamExt;
use std::path::PathBuf;
use structopt::StructOpt;
Expand Down
2 changes: 0 additions & 2 deletions params

This file was deleted.

0 comments on commit c80c87d

Please sign in to comment.