Skip to content

Commit

Permalink
Update deps (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
AgeManning authored Feb 3, 2021
1 parent 66f213a commit f47dac2
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 36 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "discv5"
authors = ["Age Manning <[email protected]>"]
edition = "2018"
version = "0.1.0-beta.2"
version = "0.1.0-beta.3"
description = "Implementation of the p2p discv5 discovery protocol"
license = "MIT"
repository = "https://github.com/sigp/discv5"
Expand All @@ -15,15 +15,15 @@ exclude = [
]

[dependencies]
enr = { version = "0.4.0", features = ["k256", "ed25519"] }
enr = { version = "0.5.0", features = ["k256", "ed25519"] }
tokio = { version = "1.1", features = ["net", "sync", "macros"] }
tokio-stream = "0.1.2"
tokio-util = { version = "0.6.2", features = ["time"] }
libp2p-core = { version = "0.27.0", optional = true }
zeroize = { version = "1.1.1", features = ["zeroize_derive"] }
futures = "0.3.8"
uint = { version = "0.8.5", default-features = false }
rlp = "0.4.6"
rlp = "0.5"
sha2 = "0.9.2"
hkdf = "0.10.0"
hex = "0.4.2"
Expand All @@ -37,7 +37,7 @@ lru_time_cache = "0.11.2"
lazy_static = "1.4.0"
aes-gcm = "0.8.0"
aes-ctr = "0.6.0"
k256 = { version = "0.5.10", features = ["zeroize", "ecdh", "sha2"] }
k256 = { version = "0.7", features = ["zeroize", "ecdh", "sha2"] }
tracing = { version = "0.1.21", features = ["log"] }
tracing-subscriber = "0.2.15"

Expand Down
2 changes: 1 addition & 1 deletion examples/find_nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async fn main() {
// A fixed key for testing
let raw_key =
hex::decode("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291").unwrap();
let secret_key = k256::ecdsa::SigningKey::new(&raw_key).unwrap();
let secret_key = k256::ecdsa::SigningKey::from_bytes(&raw_key).unwrap();
let mut enr_key = CombinedKey::from(secret_key);

// use a random key if specified
Expand Down
1 change: 1 addition & 0 deletions src/discv5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ impl Discv5 {
self.local_enr
.write()
.insert(key, value, &self.enr_key.read())
.map(|v| v.map(|v| v.to_vec()))
}

/// Returns an iterator over all ENR node IDs of nodes currently contained in the routing table.
Expand Down
2 changes: 1 addition & 1 deletion src/discv5/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fn generate_deterministic_keypair(n: usize, seed: u64) -> Vec<CombinedKey> {
loop {
// until a value is given within the curve order
rng.fill_bytes(&mut b);
if let Ok(k) = k256::ecdsa::SigningKey::new(&b) {
if let Ok(k) = k256::ecdsa::SigningKey::from_bytes(&b) {
break k;
}
}
Expand Down
23 changes: 11 additions & 12 deletions src/handler/crypto/ecdh.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
//! Implements the static ecdh algorithm required by discv5 in terms of the `k256` library.
use k256::{
ecdsa::{SigningKey, VerifyKey},
elliptic_curve::sec1::FromEncodedPoint,
ecdsa::{SigningKey, VerifyingKey},
elliptic_curve::sec1::ToEncodedPoint,
};

pub fn ecdh(public_key: &VerifyKey, secret_key: &SigningKey) -> Vec<u8> {
k256::elliptic_curve::ecdh::PublicKey::from(
(k256::ProjectivePoint::from(
k256::elliptic_curve::AffinePoint::<k256::Secp256k1>::from_encoded_point(
&k256::elliptic_curve::ecdh::PublicKey::from_bytes(public_key.to_bytes().as_ref())
.unwrap(),
)
.unwrap(),
) * k256::SecretKey::from_bytes(secret_key.to_bytes())
pub fn ecdh(public_key: &VerifyingKey, secret_key: &SigningKey) -> Vec<u8> {
k256::PublicKey::from_affine(
(&k256::PublicKey::from_sec1_bytes(public_key.to_bytes().as_ref())
.unwrap()
.secret_scalar())
.to_projective()
* k256::SecretKey::from_bytes(secret_key.to_bytes())
.unwrap()
.secret_scalar())
.to_affine(),
)
.unwrap()
.to_encoded_point(true)
.as_bytes()
.to_vec()
}
12 changes: 6 additions & 6 deletions src/handler/crypto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub(crate) fn derive_keys_from_pubkey(
CombinedKey::Secp256k1(key) => {
// convert remote pubkey into secp256k1 public key
// the key type should match our own node record
let remote_pubkey = k256::ecdsa::VerifyKey::new(ephem_pubkey)
let remote_pubkey = k256::ecdsa::VerifyingKey::from_sec1_bytes(ephem_pubkey)
.map_err(|_| Discv5Error::InvalidRemotePublicKey)?;
ecdh(&remote_pubkey, &key)
}
Expand Down Expand Up @@ -258,8 +258,8 @@ mod tests {
hex::decode("033b11a2a1f214567e1537ce5e509ffd9b21373247f2a3ff6841f4976f53165e7e")
.unwrap();

let remote_pk = k256::ecdsa::VerifyKey::new(&remote_pubkey).unwrap();
let local_sk = k256::ecdsa::SigningKey::new(&local_secret_key).unwrap();
let remote_pk = k256::ecdsa::VerifyingKey::from_sec1_bytes(&remote_pubkey).unwrap();
let local_sk = k256::ecdsa::SigningKey::from_bytes(&local_secret_key).unwrap();

let secret = ecdh(&remote_pk, &local_sk);
assert_eq!(secret, expected_secret);
Expand All @@ -274,8 +274,8 @@ mod tests {
hex::decode("0317931e6e0840220642f230037d285d122bc59063221ef3226b1f403ddc69ca91")
.unwrap();

let remote_pk = k256::ecdsa::VerifyKey::new(&dest_pubkey).unwrap();
let local_sk = k256::ecdsa::SigningKey::new(&ephem_key).unwrap();
let remote_pk = k256::ecdsa::VerifyingKey::from_sec1_bytes(&dest_pubkey).unwrap();
let local_sk = k256::ecdsa::SigningKey::from_bytes(&ephem_key).unwrap();

let secret = ecdh(&remote_pk, &local_sk);

Expand Down Expand Up @@ -309,7 +309,7 @@ mod tests {
let expected_sig = hex::decode("94852a1e2318c4e5e9d422c98eaf19d1d90d876b29cd06ca7cb7546d0fff7b484fe86c09a064fe72bdbef73ba8e9c34df0cd2b53e9d65528c2c7f336d5dfc6e6").unwrap();

let challenge_data = ChallengeData::try_from(hex::decode("000000000000000000000000000000006469736376350001010102030405060708090a0b0c00180102030405060708090a0b0c0d0e0f100000000000000000").unwrap().as_slice()).unwrap();
let key = k256::ecdsa::SigningKey::new(&local_secret_key).unwrap();
let key = k256::ecdsa::SigningKey::from_bytes(&local_secret_key).unwrap();
let sig = sign_nonce(&key.into(), &challenge_data, &ephemeral_pubkey, &dst_id).unwrap();

assert_eq!(sig, expected_sig);
Expand Down
2 changes: 1 addition & 1 deletion src/node_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl std::convert::TryFrom<Multiaddr> for NodeContact {
{
PublicKey::Secp256k1(pk) => {
// TODO: Remove libp2p dep to avoid conversion here
enr::k256::ecdsa::VerifyKey::new(&pk.encode_uncompressed())
enr::k256::ecdsa::VerifyingKey::from_sec1_bytes(&pk.encode_uncompressed())
.expect("Libp2p key conversion, always valid")
.into()
}
Expand Down
20 changes: 10 additions & 10 deletions src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl Request {
s.begin_list(2);
s.append(&id.as_bytes());
s.append(&enr_seq);
buf.extend_from_slice(&s.drain());
buf.extend_from_slice(&s.out());
buf
}
RequestBody::FindNode { distances } => {
Expand All @@ -156,7 +156,7 @@ impl Request {
for distance in distances {
s.append(&distance);
}
buf.extend_from_slice(&s.drain());
buf.extend_from_slice(&s.out());
buf
}
RequestBody::Talk { protocol, request } => {
Expand All @@ -165,7 +165,7 @@ impl Request {
s.append(&id.as_bytes());
s.append(&protocol);
s.append(&request);
buf.extend_from_slice(&s.drain());
buf.extend_from_slice(&s.out());
buf
}
RequestBody::RegisterTopic { topic, enr, ticket } => {
Expand All @@ -175,15 +175,15 @@ impl Request {
s.append(&topic);
s.append(&enr);
s.append(&ticket);
buf.extend_from_slice(&s.drain());
buf.extend_from_slice(&s.out());
buf
}
RequestBody::TopicQuery { topic } => {
let mut s = RlpStream::new();
s.begin_list(2);
s.append(&id.as_bytes());
s.append(&(&topic as &[u8]));
buf.extend_from_slice(&s.drain());
buf.extend_from_slice(&s.out());
buf
}
}
Expand Down Expand Up @@ -233,7 +233,7 @@ impl Response {
IpAddr::V6(addr) => s.append(&(&addr.octets() as &[u8])),
};
s.append(&port);
buf.extend_from_slice(&s.drain());
buf.extend_from_slice(&s.out());
buf
}
ResponseBody::Nodes { total, nodes } => {
Expand All @@ -250,15 +250,15 @@ impl Response {
s.append(&node);
}
}
buf.extend_from_slice(&s.drain());
buf.extend_from_slice(&s.out());
buf
}
ResponseBody::Talk { response } => {
let mut s = RlpStream::new();
s.begin_list(2);
s.append(&id.as_bytes());
s.append(&response);
buf.extend_from_slice(&s.drain());
buf.extend_from_slice(&s.out());
buf
}
ResponseBody::Ticket { ticket, wait_time } => {
Expand All @@ -267,15 +267,15 @@ impl Response {
s.append(&id.as_bytes());
s.append(&ticket);
s.append(&wait_time);
buf.extend_from_slice(&s.drain());
buf.extend_from_slice(&s.out());
buf
}
ResponseBody::RegisterConfirmation { topic } => {
let mut s = RlpStream::new();
s.begin_list(2);
s.append(&id.as_bytes());
s.append(&topic);
buf.extend_from_slice(&s.drain());
buf.extend_from_slice(&s.out());
buf
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ impl Service {
let mut rpc_index = 0;
to_send_nodes.push(Vec::new());
for enr in nodes_to_send.into_iter() {
let entry_size = enr.encode().len();
let entry_size = rlp::encode(&enr).len();
// Responses assume that a session is established. Thus, on top of the encoded
// ENR's the packet should be a regular message. A regular message has an IV (16
// bytes), and a header of 55 bytes. The find-nodes RPC requires 16 bytes for the ID and the
Expand Down

0 comments on commit f47dac2

Please sign in to comment.