fixed grumbles

This commit is contained in:
debris 2017-08-31 12:38:53 +02:00
parent 94f717a255
commit ba3b2712a1
3 changed files with 10 additions and 6 deletions

View File

@ -31,19 +31,23 @@ pub const KECCAK_NULL_RLP: H256 = H256( [0x56, 0xe8, 0x1f, 0x17, 0x1b, 0xcc, 0x5
pub const KECCAK_EMPTY_LIST_RLP: H256 = H256( [0x1d, 0xcc, 0x4d, 0xe8, 0xde, 0xc7, 0x5d, 0x7a, 0xab, 0x85, 0xb5, 0x67, 0xb6, 0xcc, 0xd4, 0x1a, 0xd3, 0x12, 0x45, 0x1b, 0x94, 0x8a, 0x74, 0x13, 0xf0, 0xa1, 0x42, 0xfd, 0x40, 0xd4, 0x93, 0x47] );
extern {
/// Hashes input. Returns -1 if either out or input does not exist. Otherwise returns 0.
pub fn keccak_256(out: *mut u8, outlen: usize, input: *const u8, inputlen: usize) -> i32;
/// Hashes input. Returns -1 if either out or input does not exist. Otherwise returns 0.
pub fn keccak_512(out: *mut u8, outlen: usize, input: *const u8, inputlen: usize) -> i32;
}
pub fn keccak<T: AsRef<[u8]>>(s: T) -> H256 {
let mut result = [0u8; 32];
keccak_into(s, &mut result);
write_keccak(s, &mut result);
H256(result)
}
pub fn keccak_into<T: AsRef<[u8]>>(s: T, dest: &mut [u8]) {
pub fn write_keccak<T: AsRef<[u8]>>(s: T, dest: &mut [u8]) {
let input = s.as_ref();
unsafe {
// we can safely ignore keccak_256 output, cause we know that both input
// and dest are properly allocated
keccak_256(dest.as_mut_ptr(), dest.len(), input.as_ptr(), input.len());
}
}

View File

@ -18,7 +18,7 @@ use std::sync::Arc;
use std::collections::VecDeque;
use std::net::SocketAddr;
use std::sync::atomic::{AtomicBool, Ordering as AtomicOrdering};
use hash::{keccak, keccak_into};
use hash::{keccak, write_keccak};
use mio::{Token, Ready, PollOpt};
use mio::deprecated::{Handler, EventLoop, TryRead, TryWrite};
use mio::tcp::*;
@ -312,7 +312,7 @@ impl EncryptedConnection {
}
let mut key_material = H512::new();
shared.copy_to(&mut key_material[0..32]);
keccak_into(&nonce_material, &mut key_material[32..64]);
write_keccak(&nonce_material, &mut key_material[32..64]);
keccak(&key_material).copy_to(&mut key_material[32..64]);
keccak(&key_material).copy_to(&mut key_material[32..64]);

View File

@ -16,7 +16,7 @@
use std::sync::Arc;
use rand::random;
use hash::keccak_into;
use hash::write_keccak;
use mio::tcp::*;
use util::hash::*;
use util::bytes::Bytes;
@ -273,7 +273,7 @@ impl Handshake {
// E(remote-pubk, S(ecdhe-random, ecdh-shared-secret^nonce) || H(ecdhe-random-pubk) || pubk || nonce || 0x0)
let shared = *ecdh::agree(secret, &self.id)?;
sig.copy_from_slice(&*sign(self.ecdhe.secret(), &(&shared ^ &self.nonce))?);
keccak_into(self.ecdhe.public(), hepubk);
write_keccak(self.ecdhe.public(), hepubk);
pubk.copy_from_slice(public);
nonce.copy_from_slice(&self.nonce);
}