mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-05-14 11:51:19 +00:00
transports/noise: Migrate away from deprecated sodiumoxide
for tests (#2817)
This commit is contained in:
parent
6855ab943b
commit
e01f77bc49
@ -33,7 +33,8 @@ async-io = "1.2.0"
|
||||
env_logger = "0.9.0"
|
||||
libp2p-tcp = { path = "../../transports/tcp" }
|
||||
quickcheck = "0.9.0"
|
||||
sodiumoxide = "0.2.5"
|
||||
libsodium-sys-stable = { version = "1.19.22", features = ["fetch-latest"] }
|
||||
ed25519-compact = "1.0.11"
|
||||
|
||||
[build-dependencies]
|
||||
prost-build = "0.11"
|
||||
|
@ -278,10 +278,13 @@ impl snow::types::Dh for Keypair<X25519> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
// Use the ed25519_compact for testing
|
||||
use ed25519_compact;
|
||||
use libp2p_core::identity::ed25519;
|
||||
// Use the libsodium-sys-stable crypto_sign imports for testing
|
||||
use libsodium_sys::crypto_sign_ed25519_pk_to_curve25519;
|
||||
use libsodium_sys::crypto_sign_ed25519_sk_to_curve25519;
|
||||
use quickcheck::*;
|
||||
use sodiumoxide::crypto::sign;
|
||||
use std::os::raw::c_int;
|
||||
use x25519_dalek::StaticSecret;
|
||||
|
||||
// ed25519 to x25519 keypair conversion must yield the same results as
|
||||
@ -292,9 +295,11 @@ mod tests {
|
||||
let ed25519 = ed25519::Keypair::generate();
|
||||
let x25519 = Keypair::from(SecretKey::from_ed25519(&ed25519.secret()));
|
||||
|
||||
let sodium_sec = ed25519_sk_to_curve25519(&sign::SecretKey(ed25519.encode()));
|
||||
let sodium_pub =
|
||||
ed25519_pk_to_curve25519(&sign::PublicKey(ed25519.public().encode().clone()));
|
||||
let sodium_sec =
|
||||
ed25519_sk_to_curve25519(&ed25519_compact::SecretKey::new(ed25519.encode()));
|
||||
let sodium_pub = ed25519_pk_to_curve25519(&ed25519_compact::PublicKey::new(
|
||||
ed25519.public().encode().clone(),
|
||||
));
|
||||
|
||||
let our_pub = x25519.public.0;
|
||||
// libsodium does the [clamping] of the scalar upon key construction,
|
||||
@ -327,18 +332,10 @@ mod tests {
|
||||
quickcheck(prop as fn() -> _);
|
||||
}
|
||||
|
||||
// Bindings to libsodium's ed25519 to curve25519 key conversions, to check that
|
||||
// they agree with the conversions performed in this module.
|
||||
|
||||
extern "C" {
|
||||
pub fn crypto_sign_ed25519_pk_to_curve25519(c: *mut u8, e: *const u8) -> c_int;
|
||||
pub fn crypto_sign_ed25519_sk_to_curve25519(c: *mut u8, e: *const u8) -> c_int;
|
||||
}
|
||||
|
||||
pub fn ed25519_pk_to_curve25519(k: &sign::PublicKey) -> Option<[u8; 32]> {
|
||||
pub fn ed25519_pk_to_curve25519(k: &ed25519_compact::PublicKey) -> Option<[u8; 32]> {
|
||||
let mut out = [0u8; 32];
|
||||
unsafe {
|
||||
if crypto_sign_ed25519_pk_to_curve25519(out.as_mut_ptr(), (&k.0).as_ptr()) == 0 {
|
||||
if crypto_sign_ed25519_pk_to_curve25519(out.as_mut_ptr(), k.as_ptr()) == 0 {
|
||||
Some(out)
|
||||
} else {
|
||||
None
|
||||
@ -346,10 +343,10 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ed25519_sk_to_curve25519(k: &sign::SecretKey) -> Option<[u8; 32]> {
|
||||
pub fn ed25519_sk_to_curve25519(k: &ed25519_compact::SecretKey) -> Option<[u8; 32]> {
|
||||
let mut out = [0u8; 32];
|
||||
unsafe {
|
||||
if crypto_sign_ed25519_sk_to_curve25519(out.as_mut_ptr(), (&k.0).as_ptr()) == 0 {
|
||||
if crypto_sign_ed25519_sk_to_curve25519(out.as_mut_ptr(), k.as_ptr()) == 0 {
|
||||
Some(out)
|
||||
} else {
|
||||
None
|
||||
|
Loading…
x
Reference in New Issue
Block a user