mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-25 15:51:34 +00:00
Switch noise from the RingResolver to the DefaultResolver (#1439)
* hmm... * Switch snow resolver to default * Fix documentation * Use the sha2 crate for sha512 hashing * Use ring on native * Use different features on different targets Co-authored-by: Pierre Krieger <pierre.krieger1708@gmail.com>
This commit is contained in:
@ -198,12 +198,10 @@ impl<T: AsRef<[u8]>> AsRef<[u8]> for PublicKey<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Custom `snow::CryptoResolver` which delegates to the `RingResolver`
|
||||
/// Custom `snow::CryptoResolver` which delegates to either the
|
||||
/// `RingResolver` on native or the `DefaultResolver` on wasm
|
||||
/// for hash functions and symmetric ciphers, while using x25519-dalek
|
||||
/// for Curve25519 DH. We do not use the default resolver for any of
|
||||
/// the choices, because it comes with unwanted additional dependencies,
|
||||
/// notably rust-crypto, and to avoid being affected by changes to
|
||||
/// the defaults.
|
||||
/// for Curve25519 DH.
|
||||
struct Resolver;
|
||||
|
||||
impl snow::resolvers::CryptoResolver for Resolver {
|
||||
@ -220,11 +218,25 @@ impl snow::resolvers::CryptoResolver for Resolver {
|
||||
}
|
||||
|
||||
fn resolve_hash(&self, choice: &snow::params::HashChoice) -> Option<Box<dyn snow::types::Hash>> {
|
||||
snow::resolvers::RingResolver.resolve_hash(choice)
|
||||
#[cfg(target_os = "unknown")]
|
||||
{
|
||||
snow::resolvers::DefaultResolver.resolve_hash(choice)
|
||||
}
|
||||
#[cfg(not(target_os = "unknown"))]
|
||||
{
|
||||
snow::resolvers::RingResolver.resolve_hash(choice)
|
||||
}
|
||||
}
|
||||
|
||||
fn resolve_cipher(&self, choice: &snow::params::CipherChoice) -> Option<Box<dyn snow::types::Cipher>> {
|
||||
snow::resolvers::RingResolver.resolve_cipher(choice)
|
||||
#[cfg(target_os = "unknown")]
|
||||
{
|
||||
snow::resolvers::DefaultResolver.resolve_cipher(choice)
|
||||
}
|
||||
#[cfg(not(target_os = "unknown"))]
|
||||
{
|
||||
snow::resolvers::RingResolver.resolve_cipher(choice)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ use lazy_static::lazy_static;
|
||||
use libp2p_core::UpgradeInfo;
|
||||
use libp2p_core::{identity, identity::ed25519};
|
||||
use rand::Rng;
|
||||
use ring::digest::{SHA512, digest};
|
||||
use sha2::{Sha512, Digest};
|
||||
use x25519_dalek::{X25519_BASEPOINT_BYTES, x25519};
|
||||
use zeroize::Zeroize;
|
||||
|
||||
@ -212,7 +212,7 @@ impl SecretKey<X25519> {
|
||||
// the same to yield a Curve25519 keypair with the same public key.
|
||||
// let ed25519_sk = ed25519::SecretKey::from(ed);
|
||||
let mut curve25519_sk: [u8; 32] = [0; 32];
|
||||
let hash = digest(&SHA512, ed25519_sk.as_ref());
|
||||
let hash = Sha512::digest(ed25519_sk.as_ref());
|
||||
curve25519_sk.copy_from_slice(&hash.as_ref()[..32]);
|
||||
let sk = SecretKey(X25519(curve25519_sk)); // Copy
|
||||
curve25519_sk.zeroize();
|
||||
|
Reference in New Issue
Block a user