Initial crypto crate

This commit is contained in:
Jedrzej Stuczynski
2020-01-10 11:49:49 +00:00
parent 4f23d7e58b
commit 2a05d77d94
7 changed files with 24 additions and 35 deletions
Generated
+9
View File
@@ -400,6 +400,15 @@ dependencies = [
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "crypto"
version = "0.1.0"
dependencies = [
"curve25519-dalek 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "crypto-mac"
version = "0.7.0"
+1
View File
@@ -7,6 +7,7 @@ members = [
"clients/provider-client",
"clients/validator-client",
"common/addressing",
"common/crypto",
"common/topology",
"mixnode",
"sfw-provider",
-33
View File
@@ -1,33 +0,0 @@
use curve25519_dalek::montgomery::MontgomeryPoint;
use curve25519_dalek::scalar::Scalar;
// This keypair serves as the user's identity within the Mixnet
pub struct KeyPair {
pub private: Scalar,
pub public: MontgomeryPoint,
}
impl KeyPair {
pub fn new() -> KeyPair {
let (private, public) = sphinx::crypto::keygen();
KeyPair { private, public }
}
pub fn from_bytes(private_bytes: Vec<u8>, public_bytes: Vec<u8>) -> KeyPair {
let mut bytes = [0; 32];
bytes.copy_from_slice(&private_bytes[..]);
let private = Scalar::from_canonical_bytes(bytes).unwrap();
let mut bytes = [0; 32];
bytes.copy_from_slice(&public_bytes[..]);
let public = MontgomeryPoint(bytes);
KeyPair { private, public }
}
pub fn private_bytes(&self) -> [u8; 32] {
self.private.to_bytes()
}
pub fn public_bytes(&self) -> [u8; 32] {
self.public.to_bytes()
}
}
-1
View File
@@ -1 +0,0 @@
pub mod mixnet;
@@ -1 +0,0 @@
// TODO types for Validator keys will go in here once we hook this up.
+12
View File
@@ -0,0 +1,12 @@
[package]
name = "crypto"
version = "0.1.0"
authors = ["Jedrzej Stuczynski <andrew@nymtech.net"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
curve25519-dalek = "1.2.3"
rand = "0.7.2"
rand_os = "0.1"
+2
View File
@@ -0,0 +1,2 @@
pub mod encryption;
pub mod identity;