Skip to content

Commit

Permalink
Update of dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
iquerejeta committed Oct 12, 2021
1 parent fc14c8a commit 0c613a9
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 23 deletions.
6 changes: 3 additions & 3 deletions kes-mmm-sumed25519/Cargo.toml
Expand Up @@ -10,9 +10,9 @@ keywords = [ "Crypto", "KES", "Ed25519", "MMM", "Sum" ]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ed25519-dalek = "1.0.0-pre.3"
rand_core = "0.5"
sha2 = "0.8"
ed25519-dalek = "1"
rand = { version = "0.7" }
sha2 = "0.9"

[dev-dependencies]
quickcheck = "0.9"
Expand Down
2 changes: 1 addition & 1 deletion kes-mmm-sumed25519/examples/kesutil.rs
@@ -1,5 +1,5 @@
use kes_mmm_sumed25519::sumed25519 as kes;
use rand_core::OsRng;
use rand::rngs::OsRng;
use std::env::args;
use std::fs::{File, OpenOptions};
use std::io::{Read, Write};
Expand Down
12 changes: 6 additions & 6 deletions kes-mmm-sumed25519/src/common.rs
Expand Up @@ -62,14 +62,14 @@ pub fn split_seed(r: &Seed) -> (Seed, Seed) {
let mut hleft = sha2::Sha256::default();
let mut hright = sha2::Sha256::default();

hleft.input(&[1]);
hleft.input(&r.0);
hleft.update(&[1]);
hleft.update(&r.0);

hright.input(&[2]);
hright.input(&r.0);
hright.update(&[2]);
hright.update(&r.0);

let o1 = hleft.result();
let o2 = hright.result();
let o1 = hleft.finalize();
let o2 = hright.finalize();
let s1 = Seed::from_slice(&o1);
let s2 = Seed::from_slice(&o2);
(s1, s2)
Expand Down
24 changes: 14 additions & 10 deletions kes-mmm-sumed25519/src/sumed25519.rs
Expand Up @@ -3,13 +3,15 @@
use super::common;
pub use super::common::{Depth, Seed};
use ed25519_dalek as ed25519;
use ed25519_dalek::Verifier;
use ed25519_dalek::Signer;
use ed25519_dalek::Digest;
use rand_core::{CryptoRng, RngCore};
use rand::{CryptoRng, RngCore};
//use std::hash::Hash;

#[derive(Debug, Clone)]
pub enum Error {
Ed25519SignatureError(ed25519::SignatureError),
Ed25519SignatureError(String),
InvalidSecretKeySize(usize),
InvalidPublicKeySize(usize),
InvalidSignatureSize(usize),
Expand All @@ -20,7 +22,7 @@ pub enum Error {

impl From<ed25519::SignatureError> for Error {
fn from(sig: ed25519::SignatureError) -> Error {
Error::Ed25519SignatureError(sig)
Error::Ed25519SignatureError(format!("{:?}", sig))
}
}

Expand Down Expand Up @@ -506,8 +508,9 @@ impl Signature {
}

fn sigma(&self) -> ed25519::Signature {
let bytes = &self.0[Self::SIGMA_OFFSET..Self::PK_OFFSET];
ed25519::Signature::from_bytes(bytes).expect("internal error: signature invalid")
let mut bytes = [0u8; SIGMA_SIZE];
bytes.copy_from_slice(&self.0[Self::SIGMA_OFFSET..Self::PK_OFFSET]);
ed25519::Signature::new(bytes)
}

fn pk(&self) -> ed25519::PublicKey {
Expand Down Expand Up @@ -575,12 +578,13 @@ impl Signature {
return Err(Error::InvalidSignatureCount(t, depth));
}

let sigma_slice = &bytes[Self::SIGMA_OFFSET..Self::SIGMA_OFFSET + SIGMA_SIZE];
let mut sigma_slice = [0u8; SIGMA_SIZE];
sigma_slice.copy_from_slice(&bytes[Self::SIGMA_OFFSET..Self::SIGMA_OFFSET + SIGMA_SIZE]);
let pk_slice = &bytes[Self::PK_OFFSET..Self::PK_OFFSET + INDIVIDUAL_PUBLIC_SIZE];

// verify sigma and pk format, no need to verify pks
let _ = ed25519::PublicKey::from_bytes(pk_slice)?;
let _ = ed25519::Signature::from_bytes(sigma_slice)?;
let _ = ed25519::Signature::new(sigma_slice);

let mut out = Vec::with_capacity(bytes.len());
out.extend_from_slice(bytes);
Expand All @@ -592,10 +596,10 @@ impl Signature {
pub fn hash(pk1: &PublicKey, pk2: &PublicKey) -> PublicKey {
let mut out = [0u8; 32];
let mut h = sha2::Sha256::default();
h.input(&pk1.0);
h.input(&pk2.0);
h.update(&pk1.0);
h.update(&pk2.0);

let o = h.result();
let o = h.finalize();
out.copy_from_slice(&o);
PublicKey(out)
}
Expand Down
6 changes: 3 additions & 3 deletions kes-mmm-sumed25519/src/sumrec.rs
Expand Up @@ -34,10 +34,10 @@ pub enum Signature {
pub fn hash(pk1: &PublicKey, pk2: &PublicKey) -> [u8; 32] {
let mut out = [0u8; 32];
let mut h = sha2::Sha256::default();
h.input(pk1.as_bytes());
h.input(pk2.as_bytes());
h.update(pk1.as_bytes());
h.update(pk2.as_bytes());

let o = h.result();
let o = h.finalize();
out.copy_from_slice(&o);
out
}
Expand Down

0 comments on commit 0c613a9

Please sign in to comment.