work in progress

This commit is contained in:
J. Ayo Akinyele 2018-02-25 02:46:52 -05:00
parent d680c4761f
commit 9406262435
6 changed files with 213 additions and 23 deletions

View File

@ -0,0 +1,29 @@
<component name="libraryTable">
<library name="Cargo &lt;libbolt&gt;">
<CLASSES>
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/winapi-i686-pc-windows-gnu-0.4.0" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/bn-0.4.3" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/byteorder-1.2.1" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/bitflags-1.0.1" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/rand-0.3.22" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/winapi-x86_64-pc-windows-gnu-0.4.0" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/num-traits-0.1.43" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/bincode-0.5.9" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/byteorder-0.5.3" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/serde-1.0.27" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/pkg-config-0.3.9" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/fuchsia-zircon-0.3.3" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/num-traits-0.2.0" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/fuchsia-zircon-sys-0.3.3" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-serialize-0.3.24" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/libsodium-sys-0.0.16" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/rand-0.4.2" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/winapi-0.3.4" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/serde-0.7.15" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/sodiumoxide-0.0.16" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.36" />
<root url="file://$USER_HOME$/.cargo/registry/src/github.com-1ecc6299db9ec823/bincode-0.6.1" />
</CLASSES>
<SOURCES />
</library>
</component>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -12,6 +12,13 @@ license = "MIT License"
[dependencies]
bn = "0.4.3"
rand = "~0.3.14"
bincode = "0.5.9"
sodiumoxide = "0.0.16"
[dev-dependencies.bincode]
version = "~0.6.0"
default-features = false
features = ["rustc-serialize"]
[[bin]]
name = "bolt"

View File

@ -1,8 +1,16 @@
.PHONY: all
.PHONY: all test doc clean
all:
cargo build
cargo run
test:
# runs the unit test suite
cargo test
doc:
# generates the documentation
cargo doc
clean:
cargo clean

View File

@ -25,5 +25,8 @@ fn main() {
assert!(alice_ss == bob_ss && bob_ss == carol_ss);
println!("All bn tests succeeded!");
libbolt::setup();
let pk = libbolt::setup();
// let msg = String::from("Hello, World!");
// let cm = libbolt::commit(pk, msg);
}

View File

@ -1,34 +1,171 @@
extern crate bn;
extern crate rand;
extern crate bincode;
extern crate sodiumoxide;
use std::fmt;
use bn::{Group, Fr, G1, G2, pairing};
use bincode::SizeLimit::Infinite;
use bincode::rustc_serialize::{encode, decode};
use sodiumoxide::crypto::hash::sha256;
// define some structures here
pub fn test_libbolt() {
println!("Hello, Libbolt here!");
pub struct PublicKey {
g: G1,
h: G1
}
pub fn setup() {
pub struct Commitment {
c: G1,
d: Fr
}
// Begin CL Signature scheme data structures
pub struct PublicKeySigs {
X: G1,
Y: G1
}
pub struct SecretKeySigs {
x: Fr,
y: Fr
}
// End CL Signature scheme data structures
// To hash this message structure, encode each element in the tuple
// as a byte stream, then apply a hash on it. Then, convert the output value into
// a Fr element.
pub struct Message {
sk_sigs: SecretKeySigs, // the secret key for the signature scheme
k1: Fr, // seed 1 for PRF
k2: Fr, // seed 2 for PRF
balance: i32 // the balance for the user
}
// TODO: add a function that operates over the Message structure
// TODO: to perform the encodng an hash
impl Message {
fn hash(&self) -> Fr {
let rng = &mut rand::thread_rng();
let a = Fr::random(rng);
return a;
}
}
impl fmt::Display for PublicKey {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let g_vec: Vec<u8> = encode(&self.g, Infinite).unwrap();
let h_vec: Vec<u8> = encode(&self.h, Infinite).unwrap();
let mut g_s = String::new();
for x in g_vec.iter() {
g_s = format!("{}{:x}", g_s, x);
}
let mut h_s = String::new();
for y in h_vec.iter() {
h_s = format!("{}{:x}", h_s, y);
}
write!(f, "PK : (g=0x{}, h=0x{})", g_s, h_s)
}
}
impl fmt::Display for Commitment {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let c_vec: Vec<u8> = encode(&self.c, Infinite).unwrap();
let mut c_s = String::new();
for x in c_vec.iter() {
c_s = format!("{}{:x}", c_s, x);
}
let d_vec: Vec<u8> = encode(&self.d, Infinite).unwrap();
let mut d_s = String::new();
for x in d_vec.iter() {
d_s = format!("{}{:x}", d_s, x);
}
write!(f, "Commitment : (c=0x{}, d=0x{})", c_s, d_s)
}
}
pub fn misc_tests() {
let rng = &mut rand::thread_rng();
let a = Fr::random(rng);
// println!("crs = {}", stringify!(a));
// let limit = bincode::SizeLimit::Bounded(256);
let encoded: Vec<u8> = encode(&a, Infinite).unwrap();
println!("a length = {}", encoded.len());
println!("a = {:?}", encoded);
print!("a (hex) = 0x");
for x in encoded.iter() {
print!("{:x}", x);
}
print!("\n");
}
/*
Implements the setup algorithm for the Pedersen92 commitment scheme
*/
pub fn setup() -> PublicKey {
println!("Run Setup...");
let rng = &mut rand::thread_rng();
let g = G1::random(rng);
let h = G1::random(rng);
let pk = PublicKey { g: g, h: h };
println!("{}", pk);
return pk;
}
pub fn keygen() {
println!("Run Keygen...");
// TODO: need to be able to handle a message structure
pub fn commit(pk : PublicKey, msg : Message) -> Commitment {
let rng = &mut rand::thread_rng();
let r = Fr::random(rng);
// TODO: replace with hash of message into m (of type Fr)
let m = msg.hash();
let c = (pk.g * m) + (pk.h * r);
// return (c, r) <- d=r
let commitment = Commitment { c: c, d: r };
// debugging
println!("{}", commitment);
return commitment;
}
pub fn init() {
println!("Run Init...");
/*
pub fn decommit(pk: PublicKey, cm: Commitment, msg: Message) -> bool {
// TODO: replace with hash of message into m (of type Fr)
let m = Fr::random(rng);
let dm = (pk.g * m) + (pk.h * cm.d);
return dm == cm.c;
}
*/
pub fn refund() {
println!("Run Refund...");
}
pub fn refute() {
println!("Run Refute...");
}
pub fn resolve() {
println!("Run Resolve...");
}
//pub fn keygen() {
// println!("Run Keygen...");
//}
//
//pub fn init() {
// println!("Run Init...");
//
//}
//
//pub fn refund() {
// println!("Run Refund...");
//
//}
//
//pub fn refute() {
// println!("Run Refute...");
//
//}
//
//pub fn resolve() {
// println!("Run Resolve...");
//
//}