Browse Source

starting signatures

master
ennucore 5 years ago
parent
commit
a2615f22e4
  1. 29
      Cargo.lock
  2. 1
      Cargo.toml
  3. 28
      src/crypto.rs

29
Cargo.lock generated

@ -42,11 +42,24 @@ name = "byteorder"
version = "1.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cc"
version = "1.0.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "clear_on_drop"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "const-random"
version = "0.1.8"
@ -85,6 +98,18 @@ dependencies = [
"generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "ed25519-dalek"
version = "1.0.0-pre.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"curve25519-dalek 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
"sha2 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "fake-simd"
version = "0.1.2"
@ -122,6 +147,7 @@ dependencies = [
name = "ironforest"
version = "0.1.0"
dependencies = [
"ed25519-dalek 1.0.0-pre.3 (registry+https://github.com/rust-lang/crates.io-index)",
"pinecone 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_os 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -332,11 +358,14 @@ dependencies = [
"checksum block-padding 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5"
"checksum byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7"
"checksum byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
"checksum cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)" = "95e28fa049fda1c330bcf9d723be7663a899c4679724b34c81e9f5a326aab8cd"
"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
"checksum clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "97276801e127ffb46b66ce23f35cc96bd454fa311294bced4bbace7baa8b1d17"
"checksum const-random 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "2f1af9ac737b2dd2d577701e59fd09ba34822f6f2ebdb30a7647405d9e55e16a"
"checksum const-random-macro 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "25e4c606eb459dd29f7c57b2e0879f2b6f14ee130918c2b78ccb58a9624e6c7a"
"checksum curve25519-dalek 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "26778518a7f6cffa1d25a44b602b62b979bd88adb9e99ffec546998cf3404839"
"checksum digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5"
"checksum ed25519-dalek 1.0.0-pre.3 (registry+https://github.com/rust-lang/crates.io-index)" = "978710b352437433c97b2bff193f2fb1dfd58a093f863dd95e225a19baa599a2"
"checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
"checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec"
"checksum getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb"

1
Cargo.toml

@ -8,6 +8,7 @@ edition = "2018"
[dependencies]
rand_os = "0.2.2"
x25519-dalek = "0.6.0"
ed25519-dalek = { version = "1.0.0-pre.3", features = ["serde"] }
sha2 = "0.8.1"
rand = "*"
serde = { version = "1.0", features = ["derive", "alloc"], default-features = false }

28
src/crypto.rs

@ -1,14 +1,13 @@
extern crate rand;
extern crate rand_os;
extern crate x25519_dalek;
use rand_os::OsRng;
use x25519_dalek::EphemeralSecret;
use x25519_dalek::PublicKey as PK;
extern crate ed25519_dalek;
use ed25519_dalek::{PublicKey as PK, Keypair, Signature};
use sha2::Sha512;
use serde::{Serialize, Deserialize};
use rand::rngs::OsRng;
use self::ed25519_dalek::Digest;
#[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct PublicKey {
@ -17,23 +16,20 @@ pub struct PublicKey {
pub struct KeyPack {
pub public_key: PK,
pub secret_key: EphemeralSecret,
pub pair: Keypair,
csprng: OsRng,
}
impl KeyPack {
pub fn gen() -> KeyPack {
let mut osrng = OsRng;
let secret = EphemeralSecret::new(&mut osrng);
let public = PK::from(&secret);
KeyPack { public_key: public, secret_key: secret, csprng: osrng }
let mut osrng = OsRng {};
KeyPack { pair: Keypair::generate(&mut osrng), csprng: osrng }
}
}
impl PublicKey {
pub fn verify_sign(self, sign: u64) -> bool {
true
pub fn verify_sign(self, msg: crate::message::Message, sign: Signature) -> bool {
PK::from_bytes(&self.key).unwrap().verify(msg.get_hash().as_ref(), &sign).is_ok()
}
}
@ -43,6 +39,6 @@ impl KeyPack {
}
pub fn get_public(self) -> PublicKey {
PublicKey{key: *self.public_key.as_bytes()}
PublicKey { key: *self.pair.public.as_bytes() }
}
}

Loading…
Cancel
Save