Hashable::sha3 -> fn keccak for ethcore-network

This commit is contained in:
debris 2017-08-30 17:14:52 +02:00
parent 0e088d783d
commit e120c75d17
9 changed files with 27 additions and 25 deletions

1
Cargo.lock generated
View File

@ -693,6 +693,7 @@ dependencies = [
"ethcore-util 1.8.0",
"ethcrypto 0.1.0",
"ethkey 0.2.0",
"hash 0.1.0",
"igd 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ipnetwork 0.12.6 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -31,6 +31,7 @@ rlp = { path = "../rlp" }
path = { path = "../path" }
ethcore-logger = { path ="../../logger" }
ipnetwork = "0.12.6"
hash = { path = "../hash" }
[features]
default = []

View File

@ -18,11 +18,11 @@ 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 mio::{Token, Ready, PollOpt};
use mio::deprecated::{Handler, EventLoop, TryRead, TryWrite};
use mio::tcp::*;
use util::hash::*;
use util::sha3::*;
use util::bytes::*;
use rlp::*;
use std::io::{self, Cursor, Read, Write};
@ -312,16 +312,16 @@ impl EncryptedConnection {
}
let mut key_material = H512::new();
shared.copy_to(&mut key_material[0..32]);
nonce_material.sha3_into(&mut key_material[32..64]);
key_material.sha3().copy_to(&mut key_material[32..64]);
key_material.sha3().copy_to(&mut key_material[32..64]);
keccak_into(&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]);
let iv = vec![0u8; 16];
let encoder = CtrMode::new(AesSafe256Encryptor::new(&key_material[32..64]), iv);
let iv = vec![0u8; 16];
let decoder = CtrMode::new(AesSafe256Encryptor::new(&key_material[32..64]), iv);
key_material.sha3().copy_to(&mut key_material[32..64]);
keccak(&key_material).copy_to(&mut key_material[32..64]);
let mac_encoder = EcbEncryptor::new(AesSafe256Encryptor::new(&key_material[32..64]), NoPadding);
let mut egress_mac = Keccak::new_keccak256();

View File

@ -22,7 +22,7 @@ use std::default::Default;
use mio::*;
use mio::deprecated::{Handler, EventLoop};
use mio::udp::*;
use util::sha3::*;
use hash::keccak;
use time;
use util::hash::*;
use rlp::*;
@ -112,7 +112,7 @@ impl Discovery {
let socket = UdpSocket::bind(&listen).expect("Error binding UDP socket");
Discovery {
id: key.public().clone(),
id_hash: key.public().sha3(),
id_hash: keccak(key.public()),
secret: key.secret().clone(),
public_endpoint: public,
token: token,
@ -154,7 +154,7 @@ impl Discovery {
fn update_node(&mut self, e: NodeEntry) {
trace!(target: "discovery", "Inserting {:?}", &e);
let id_hash = e.id.sha3();
let id_hash = keccak(e.id);
let ping = {
let mut bucket = &mut self.node_buckets[Discovery::distance(&self.id_hash, &id_hash) as usize];
let updated = if let Some(node) = bucket.nodes.iter_mut().find(|n| n.address.id == e.id) {
@ -180,7 +180,7 @@ impl Discovery {
}
fn clear_ping(&mut self, id: &NodeId) {
let mut bucket = &mut self.node_buckets[Discovery::distance(&self.id_hash, &id.sha3()) as usize];
let mut bucket = &mut self.node_buckets[Discovery::distance(&self.id_hash, &keccak(id)) as usize];
if let Some(node) = bucket.nodes.iter_mut().find(|n| &n.address.id == id) {
node.timeout = None;
}
@ -264,7 +264,7 @@ impl Discovery {
rlp.append(&timestamp);
let bytes = rlp.drain();
let hash = bytes.as_ref().sha3();
let hash = keccak(bytes.as_ref());
let signature = match sign(&self.secret, &hash) {
Ok(s) => s,
Err(_) => {
@ -276,7 +276,7 @@ impl Discovery {
packet.extend(hash.iter());
packet.extend(signature.iter());
packet.extend(bytes.iter());
let signed_hash = (&packet[32..]).sha3();
let signed_hash = keccak(&packet[32..]);
packet[0..32].clone_from_slice(&signed_hash);
self.send_to(packet, address.clone());
}
@ -285,7 +285,7 @@ impl Discovery {
fn nearest_node_entries(target: &NodeId, buckets: &[NodeBucket]) -> Vec<NodeEntry> {
let mut found: BTreeMap<u32, Vec<&NodeEntry>> = BTreeMap::new();
let mut count = 0;
let target_hash = target.sha3();
let target_hash = keccak(target);
// Sort nodes by distance to target
for bucket in buckets {
@ -368,14 +368,14 @@ impl Discovery {
return Err(NetworkError::BadProtocol);
}
let hash_signed = (&packet[32..]).sha3();
let hash_signed = keccak(&packet[32..]);
if hash_signed[..] != packet[0..32] {
return Err(NetworkError::BadProtocol);
}
let signed = &packet[(32 + 65)..];
let signature = H520::from_slice(&packet[32..(32 + 65)]);
let node_id = recover(&signature.into(), &signed.sha3())?;
let node_id = recover(&signature.into(), &keccak(signed))?;
let packet_id = signed[0];
let rlp = UntrustedRlp::new(&signed[1..]);
@ -419,7 +419,7 @@ impl Discovery {
self.update_node(entry.clone());
added_map.insert(node.clone(), entry);
}
let hash = rlp.as_raw().sha3();
let hash = keccak(rlp.as_raw());
let mut response = RlpStream::new_list(2);
dest.to_rlp_list(&mut response);
response.append(&hash);
@ -636,7 +636,7 @@ mod tests {
buckets[0].nodes.push_back(BucketEntry {
address: NodeEntry { id: NodeId::new(), endpoint: ep.clone() },
timeout: None,
id_hash: NodeId::new().sha3(),
id_hash: keccak(NodeId::new()),
});
}
let nearest = Discovery::nearest_node_entries(&NodeId::new(), &buckets);

View File

@ -16,9 +16,9 @@
use std::sync::Arc;
use rand::random;
use hash::keccak_into;
use mio::tcp::*;
use util::hash::*;
use util::sha3::Hashable;
use util::bytes::Bytes;
use rlp::*;
use connection::{Connection};
@ -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))?);
self.ecdhe.public().sha3_into(hepubk);
keccak_into(self.ecdhe.public(), hepubk);
pubk.copy_from_slice(public);
nonce.copy_from_slice(&self.nonce);
}

View File

@ -25,11 +25,11 @@ use std::path::{Path, PathBuf};
use std::io::{Read, Write, ErrorKind};
use std::fs;
use ethkey::{KeyPair, Secret, Random, Generator};
use hash::keccak;
use mio::*;
use mio::deprecated::{EventLoop};
use mio::tcp::*;
use util::hash::*;
use util::Hashable;
use util::version;
use rlp::*;
use session::{Session, SessionInfo, SessionData};
@ -354,8 +354,8 @@ impl HostInfo {
/// Increments and returns connection nonce.
pub fn next_nonce(&mut self) -> H256 {
self.nonce = self.nonce.sha3();
self.nonce.clone()
self.nonce = keccak(&self.nonce);
self.nonce
}
}

View File

@ -78,6 +78,7 @@ extern crate bytes;
extern crate path;
extern crate ethcore_logger;
extern crate ipnetwork;
extern crate hash;
#[macro_use]
extern crate log;

View File

@ -118,7 +118,6 @@ pub mod error;
pub mod bytes;
pub mod misc;
pub mod vector;
//pub mod sha3;
pub mod hashdb;
pub mod memorydb;
pub mod migration;

View File

@ -130,7 +130,7 @@ impl<'db> TrieDB<'db> {
/// This could be a simple identity operation in the case that the node is sufficiently small, but
/// may require a database lookup.
fn get_raw_or_lookup(&'db self, node: &'db [u8]) -> super::Result<DBValue> {
// check if its sha3 + len
// check if its keccak + len
let r = Rlp::new(node);
match r.is_data() && r.size() == 32 {
true => {