added features to enable swapping libsodum for rust crates
Dependencies
- [2]
UHAEQPZUSupport ecdsa-sha2-nistp256 keys for authentication - [3]
2Q3SZY2CVersion bump - [4]
7FRJYUI6Reboot because of a bad change - [5]
TFYJ3P2AVersion 0.30.8/0.19.4, and solving conflicts - [6]
Y67GNDVBuse tokio::process::Command for proxy commands - [7]
FT67GGO4Version bump (Pijul and Thrussh) - [8]
ELRPPXSGFixing conflicts - [9]
2VTUKRLJVersion - [10]
ORSEEVB5Version bump - [11]
2WEO7OZLVersion updates: getting rid of anyhow + moving to Tokio 1.0 - [12]
634OYCNMTokio 0.3 - [13]
NHOSLQGGThrussh: making OpenSSL optional - [14]
MCS77Y4VMaking OpenSSL optional - [*]
4XWMB23A
Change contents
- file addition: thrussh-rust-crypto[16.1]
- file addition: src[0.31]
- file addition: lib.rs[0.48]
pub mod chacha20 {use chacha20::cipher::{KeyIvInit, StreamCipherCore, StreamCipherSeekCore};pub const NONCE_BYTES: usize = 8;pub const KEY_BYTES: usize = 32;pub struct Nonce(pub [u8; NONCE_BYTES]);pub struct Key(pub [u8; KEY_BYTES]);pub fn chacha20_xor(c: &mut [u8], n: &Nonce, k: &Key) {let res = chacha20::ChaCha20LegacyCore::new(&k.0.into(), &n.0.into());chacha20::ChaCha20LegacyCore::apply_keystream_partial(res, c.into());}pub fn chacha20_xor_ic(c: &mut [u8], n: &Nonce, ic: u64, k: &Key) {let mut res = chacha20::ChaCha20LegacyCore::new(&k.0.into(), &n.0.into());chacha20::ChaCha20LegacyCore::set_block_pos(&mut res, ic as u32);chacha20::ChaCha20LegacyCore::apply_keystream_partial(res, c.into());}}pub mod poly1305 {use chacha20::cipher::KeyInit;use poly1305 as poly;use subtle::ConstantTimeEq;pub const KEY_BYTES: usize = 32;pub const TAG_BYTES: usize = 16;pub struct Key(pub [u8; KEY_BYTES]);pub struct Tag(pub [u8; TAG_BYTES]);pub fn poly1305_auth(m: &[u8], key: &Key) -> Tag {Tag(poly::Poly1305::new(&key.0.into()).compute_unpadded(m).into())}pub fn poly1305_verify(tag: &[u8], m: &[u8], key: &Key) -> bool {let t: [u8; TAG_BYTES] = poly::Poly1305::new(&key.0.into()).compute_unpadded(m).into();From::from(t.ct_eq(tag))}}pub mod ed25519 {use ed25519_dalek::ed25519::signature::Signer;pub const PUBLICKEY_BYTES: usize = 32;pub const SECRETKEY_BYTES: usize = 64;pub const SIGNATURE_BYTES: usize = 64;/// Ed25519 public key.#[derive(Debug, PartialEq, Eq)]pub struct PublicKey {/// Actual keypub key: [u8; PUBLICKEY_BYTES],}impl PublicKey {pub fn new_zeroed() -> Self {PublicKey {key: [0; PUBLICKEY_BYTES],}}}/// Ed25519 secret key.#[derive(Clone)]pub struct SecretKey {/// Actual keypub key: [u8; SECRETKEY_BYTES],}impl SecretKey {pub fn new_zeroed() -> Self {SecretKey {key: [0; SECRETKEY_BYTES],}}}pub struct Signature(pub [u8; SIGNATURE_BYTES]);/// Generate a key pair.pub fn keypair() -> (PublicKey, SecretKey) {let mut pk = PublicKey {key: [0; PUBLICKEY_BYTES],};let mut sk = SecretKey {key: [0; SECRETKEY_BYTES],};let mut csprng = rand::rngs::OsRng;let signing = ed25519_dalek::SigningKey::generate(&mut csprng);sk.key.copy_from_slice(&signing.to_keypair_bytes());pk.key.copy_from_slice(signing.verifying_key().as_bytes());(pk, sk)}/// Verify a signature, `sig` could as well be a `Signature`.pub fn verify_detached(sig: &[u8], m: &[u8], pk: &PublicKey) -> bool {if let Ok(sig) = ed25519_dalek::Signature::from_slice(sig) {if let Ok(pk) = ed25519_dalek::VerifyingKey::from_bytes(&pk.key) {pk.verify_strict(m, &sig).is_ok()} else {false}} else {false}}/// Sign a message with a secret key.pub fn sign_detached(m: &[u8], sk: &SecretKey) -> Signature {if let Ok(sk) = ed25519_dalek::SigningKey::from_keypair_bytes(&sk.key) {Signature(sk.sign(m).to_bytes())} else {Signature([0; SIGNATURE_BYTES])}}}pub mod scalarmult {pub const BYTES: usize = 32;pub use x25519_dalek::PublicKey;pub use x25519_dalek::ReusableSecret;pub use x25519_dalek::SharedSecret;#[derive(Debug)]pub struct GroupElement(pub [u8; BYTES]);pub fn scalarmult_base(n: &ReusableSecret) -> PublicKey {x25519_dalek::PublicKey::from(n)}pub fn scalarmult(n: &ReusableSecret, p: &PublicKey) -> SharedSecret {n.diffie_hellman(p)}} - file addition: Cargo.toml[0.31]
[package]name = "thrussh-rust-crypto"version = "0.1.0"edition = "2021"# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html[dependencies]ed25519-dalek = { version = "2.1.1", features = ["rand_core"] }rand = "0.8.5"x25519-dalek = { version = "2.0.1", features = ["reusable_secrets"] }poly1305 = "0.8.0"chacha20 = "0.9.1"subtle = "2.5.0" - edit in thrussh-keys/src/key.rs at line 23
#[cfg(feature = "libsodium")] - edit in thrussh-keys/src/key.rs at line 25
#[cfg(feature = "rust-crypto")]use thrussh_rust_crypto as sodium; - edit in thrussh-keys/src/key.rs at line 30
#[cfg(feature = "libsodium")] - edit in thrussh-keys/src/key.rs at line 34
#[cfg(feature = "rust-crypto")]pub use thrussh_rust_crypto::ed25519::{keypair, sign_detached, verify_detached, PublicKey, SecretKey,}; - edit in thrussh-keys/src/key.rs at line 115
#[cfg(feature = "libsodium")] - edit in thrussh-keys/src/key.rs at line 118
#[cfg(feature = "rust-crypto")]Ed25519(thrussh_rust_crypto::ed25519::PublicKey),#[doc(hidden)] - edit in thrussh-keys/src/key.rs at line 563
#[cfg(feature = "libsodium")] - edit in thrussh-keys/src/key.rs at line 565
#[cfg(feature = "rust-crypto")]use thrussh_rust_crypto::ed25519; - edit in thrussh-keys/Cargo.toml at line 30
[features]rust-crypto = ["dep:thrussh-rust-crypto"]libsodium = ["dep:thrussh-libsodium"] - replacement in thrussh-keys/Cargo.toml at line 53
thrussh-libsodium = "0.2"thrussh-libsodium = { version = "0.2", optional = true }thrussh-rust-crypto = { path = "../thrussh-rust-crypto", optional = true } - edit in thrussh/src/lib.rs at line 276
#[cfg(feature = "libsodium")] - edit in thrussh/src/lib.rs at line 278
#[cfg(feature = "rust-crypto")]extern crate thrussh_rust_crypto as sodium; - edit in thrussh/src/kex.rs at line 27
#[cfg(feature = "libsodium")] - edit in thrussh/src/kex.rs at line 29
#[cfg(feature = "libsodium")] - edit in thrussh/src/kex.rs at line 31
#[cfg(feature = "rust-crypto")]local_secret: Option<sodium::scalarmult::ReusableSecret>,#[cfg(feature = "rust-crypto")]shared_secret: Option<sodium::scalarmult::SharedSecret>, - edit in thrussh/src/kex.rs at line 88
#[cfg(feature = "rust-crypto")]let client_pubkey = PublicKey::from(client_pubkey.0);#[cfg(feature = "libsodium")] - edit in thrussh/src/kex.rs at line 92
#[cfg(feature = "libsodium")] - edit in thrussh/src/kex.rs at line 94
#[cfg(feature = "rust-crypto")]let mut csprng = rand::thread_rng();#[cfg(feature = "rust-crypto")]let server_secret = sodium::scalarmult::ReusableSecret::random_from_rng(&mut csprng); - edit in thrussh/src/kex.rs at line 102
#[cfg(feature = "libsodium")] - edit in thrussh/src/kex.rs at line 104
#[cfg(feature = "rust-crypto")]exchange.server_ephemeral.extend(server_pubkey.as_bytes()); - edit in thrussh/src/kex.rs at line 121
#[cfg(feature = "libsodium")] - edit in thrussh/src/kex.rs at line 123
#[cfg(feature = "libsodium")] - edit in thrussh/src/kex.rs at line 125
#[cfg(feature = "rust-crypto")]let mut csprng = rand::thread_rng();#[cfg(feature = "rust-crypto")]let client_secret = sodium::scalarmult::ReusableSecret::random_from_rng(&mut csprng); - edit in thrussh/src/kex.rs at line 133
#[cfg(feature = "libsodium")] - edit in thrussh/src/kex.rs at line 135
#[cfg(feature = "rust-crypto")]client_ephemeral.extend(client_pubkey.as_bytes()); - edit in thrussh/src/kex.rs at line 139
#[cfg(feature = "libsodium")] - edit in thrussh/src/kex.rs at line 141
#[cfg(feature = "rust-crypto")]buf.extend_ssh_string(client_pubkey.as_bytes()); - edit in thrussh/src/kex.rs at line 156
#[cfg(feature = "rust-crypto")]let remote_pubkey = PublicKey::from(remote_pubkey.0); - edit in thrussh/src/kex.rs at line 182
#[cfg(feature = "libsodium")] - edit in thrussh/src/kex.rs at line 184
#[cfg(feature = "rust-crypto")]buffer.extend_ssh_string(shared.as_bytes()); - edit in thrussh/src/kex.rs at line 215
#[cfg(feature = "libsodium")] - edit in thrussh/src/kex.rs at line 217
#[cfg(feature = "rust-crypto")]buffer.extend_ssh_string(shared.as_bytes()); - edit in thrussh/src/kex.rs at line 236
#[cfg(feature = "libsodium")] - edit in thrussh/src/kex.rs at line 238
#[cfg(feature = "rust-crypto")]buffer.extend_ssh_string(shared.as_bytes()); - replacement in thrussh/Cargo.toml at line 42
default = [ "flate2" ]default = [ "flate2", "libsodium" ] - edit in thrussh/Cargo.toml at line 45
libsodium = ["thrussh-keys/libsodium", "dep:thrussh-libsodium"]rust-crypto = ["thrussh-keys/rust-crypto", "dep:thrussh-rust-crypto"] - replacement in thrussh/Cargo.toml at line 54
thrussh-libsodium = "0.2"thrussh-libsodium = { version = "0.2", optional = true }thrussh-rust-crypto = { path = "../thrussh-rust-crypto", optional = true } - replacement in Cargo.toml at line 3
members = [ "thrussh-keys", "thrussh", "thrussh-libsodium", "thrussh-config", "cryptovec" ]members = [ "thrussh-keys", "thrussh", "thrussh-libsodium", "thrussh-config", "cryptovec" , "thrussh-rust-crypto"] - edit in Cargo.toml at line 9
thrussh-rust-crypto = { path = "thrussh-rust-crypto" }