diff --git a/Cargo.toml b/Cargo.toml index 2cb3708d2..4c8d77acc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,6 @@ members = [ "service", "vl1-service", "utils", - "openssl-zt", "openssl-sys", ] diff --git a/crypto/Cargo.toml b/crypto/Cargo.toml index d30fedcda..f3a0872fb 100644 --- a/crypto/Cargo.toml +++ b/crypto/Cargo.toml @@ -1,20 +1,32 @@ [package] -authors = ["ZeroTier, Inc. ", "Adam Ierymenko "] -edition = "2021" -license = "MPL-2.0" name = "zerotier-crypto" +authors = ["Steven Fackler "] +license = "Apache-2.0" +description = "OpenSSL bindings" +readme = "README.md" +keywords = ["crypto", "tls", "ssl", "dtls"] +categories = ["cryptography", "api-bindings"] +edition = "2021" version = "0.1.0" + +[features] +vendored = ['ffi/vendored'] +bindgen = ['ffi/bindgen'] +default = [] + [dependencies] -zerotier-utils = { path = "../utils" } ed25519-dalek = { version = "1.0.1", features = ["std", "u64_backend"], default-features = false } poly1305 = { version = "0.8.0", features = [], default-features = false } x25519-dalek = { version = "1.2.0", features = ["std", "u64_backend"], default-features = false } -openssl = { package = "openssl-zt", path = "../openssl-zt" } +cfg-if = "1.0" +foreign-types = "0.5.0" +libc = "0.2" +lazy_static = "^1" +rand_core = "0.5.1" -[target."cfg(windows)".dependencies] -winapi = { version = "^0", features = ["handleapi", "ws2ipdef", "ws2tcpip"] } +ffi = { package = "openssl-sys", version = "0.9.80", path = "../openssl-sys" } -[target."cfg(not(windows))".dependencies] -libc = "^0" -signal-hook = "^0" +[dev-dependencies] +hex = "0.4.3" +hex-literal = "0.3.4" diff --git a/openssl-zt/LICENSE b/crypto/LICENSE similarity index 100% rename from openssl-zt/LICENSE rename to crypto/LICENSE diff --git a/openssl-zt/build.rs b/crypto/build.rs similarity index 100% rename from openssl-zt/build.rs rename to crypto/build.rs diff --git a/crypto/rustfmt.toml b/crypto/rustfmt.toml deleted file mode 120000 index 39f97b043..000000000 --- a/crypto/rustfmt.toml +++ /dev/null @@ -1 +0,0 @@ -../rustfmt.toml \ No newline at end of file diff --git a/openssl-zt/src/aes.rs b/crypto/src/aes.rs similarity index 100% rename from openssl-zt/src/aes.rs rename to crypto/src/aes.rs diff --git a/openssl-zt/src/aes_gmac_siv.rs b/crypto/src/aes_gmac_siv.rs similarity index 100% rename from openssl-zt/src/aes_gmac_siv.rs rename to crypto/src/aes_gmac_siv.rs diff --git a/openssl-zt/src/bn.rs b/crypto/src/bn.rs similarity index 100% rename from openssl-zt/src/bn.rs rename to crypto/src/bn.rs diff --git a/openssl-zt/src/cipher.rs b/crypto/src/cipher.rs similarity index 100% rename from openssl-zt/src/cipher.rs rename to crypto/src/cipher.rs diff --git a/openssl-zt/src/cipher_ctx.rs b/crypto/src/cipher_ctx.rs similarity index 100% rename from openssl-zt/src/cipher_ctx.rs rename to crypto/src/cipher_ctx.rs diff --git a/openssl-zt/src/ec.rs b/crypto/src/ec.rs similarity index 100% rename from openssl-zt/src/ec.rs rename to crypto/src/ec.rs diff --git a/openssl-zt/src/error.rs b/crypto/src/error.rs similarity index 100% rename from openssl-zt/src/error.rs rename to crypto/src/error.rs diff --git a/openssl-zt/src/hash.rs b/crypto/src/hash.rs similarity index 100% rename from openssl-zt/src/hash.rs rename to crypto/src/hash.rs diff --git a/crypto/src/lib.rs b/crypto/src/lib.rs index 0136ef081..2c740a060 100644 --- a/crypto/src/lib.rs +++ b/crypto/src/lib.rs @@ -1,16 +1,28 @@ -// (c) 2020-2022 ZeroTier, Inc. -- currently proprietary pending actual release and licensing. See LICENSE.md. -pub use openssl::aes; -pub use openssl::hash; -pub use openssl::p384; -pub use openssl::random; -pub use openssl::secret; -pub use openssl::aes_gmac_siv; + +mod error; +mod cipher_ctx; +mod bn; +mod ec; + +pub mod aes_gmac_siv; +pub mod secret; +pub mod random; +pub mod aes; +pub mod hash; +pub mod p384; pub mod poly1305; pub mod salsa; pub mod typestate; pub mod x25519; + +/// This must be called before using any function from this library. +pub fn init() { + ffi::init(); + lazy_static::initialize(&p384::GROUP_P384); +} + /// Constant time byte slice equality. #[inline] pub fn secure_eq + ?Sized, B: AsRef<[u8]> + ?Sized>(a: &A, b: &B) -> bool { @@ -25,13 +37,3 @@ pub fn secure_eq + ?Sized, B: AsRef<[u8]> + ?Sized>(a: &A, b: &B) false } } - -extern "C" { - fn OPENSSL_cleanse(ptr: *mut std::ffi::c_void, len: usize); -} - -/// Destroy the contents of some memory -#[inline(always)] -pub fn burn(b: &mut [u8]) { - unsafe { OPENSSL_cleanse(b.as_mut_ptr().cast(), b.len()) }; -} diff --git a/openssl-zt/src/p384.rs b/crypto/src/p384.rs similarity index 100% rename from openssl-zt/src/p384.rs rename to crypto/src/p384.rs diff --git a/openssl-zt/src/random.rs b/crypto/src/random.rs similarity index 100% rename from openssl-zt/src/random.rs rename to crypto/src/random.rs diff --git a/openssl-zt/src/secret.rs b/crypto/src/secret.rs similarity index 100% rename from openssl-zt/src/secret.rs rename to crypto/src/secret.rs diff --git a/crypto/src/x25519.rs b/crypto/src/x25519.rs index afffdee16..e0a2d8b7d 100644 --- a/crypto/src/x25519.rs +++ b/crypto/src/x25519.rs @@ -5,8 +5,8 @@ use std::io::Write; use ed25519_dalek::Digest; -use openssl::random::SecureRandom; -use openssl::secret::Secret; +use crate::random::SecureRandom; +use crate::secret::Secret; pub const C25519_PUBLIC_KEY_SIZE: usize = 32; pub const C25519_SECRET_KEY_SIZE: usize = 32; diff --git a/openssl-zt/Cargo.toml b/openssl-zt/Cargo.toml deleted file mode 100644 index 26c151e08..000000000 --- a/openssl-zt/Cargo.toml +++ /dev/null @@ -1,29 +0,0 @@ -[package] -name = "openssl-zt" -version = "0.0.1" -authors = ["Steven Fackler "] -license = "Apache-2.0" -description = "OpenSSL bindings" -repository = "https://github.com/sfackler/rust-openssl" -readme = "README.md" -keywords = ["crypto", "tls", "ssl", "dtls"] -categories = ["cryptography", "api-bindings"] -edition = "2018" - -[features] -vendored = ['ffi/vendored'] -bindgen = ['ffi/bindgen'] -default = [] - -[dependencies] -cfg-if = "1.0" -foreign-types = "0.5.0" -libc = "0.2" -lazy_static = "^1" -rand_core = "0.5.1" - -ffi = { package = "openssl-sys", version = "0.9.80", path = "../openssl-sys" } - -[dev-dependencies] -hex = "0.4.3" -hex-literal = "0.3.4" diff --git a/openssl-zt/README.md b/openssl-zt/README.md deleted file mode 120000 index 32d46ee88..000000000 --- a/openssl-zt/README.md +++ /dev/null @@ -1 +0,0 @@ -../README.md \ No newline at end of file diff --git a/openssl-zt/src/lib.rs b/openssl-zt/src/lib.rs deleted file mode 100644 index 3ed2f2e92..000000000 --- a/openssl-zt/src/lib.rs +++ /dev/null @@ -1,33 +0,0 @@ - -mod error; -mod cipher_ctx; -mod bn; -mod ec; - -pub mod aes_gmac_siv; -pub mod secret; -pub mod random; -pub mod aes; -pub mod hash; -pub mod p384; - -/// This must be called before using any function from this library. -pub fn init() { - ffi::init(); - lazy_static::initialize(&p384::GROUP_P384); -} - -/// Constant time byte slice equality. -#[inline] -pub fn secure_eq + ?Sized, B: AsRef<[u8]> + ?Sized>(a: &A, b: &B) -> bool { - let (a, b) = (a.as_ref(), b.as_ref()); - if a.len() == b.len() { - let mut x = 0u8; - for (aa, bb) in a.iter().zip(b.iter()) { - x |= *aa ^ *bb; - } - x == 0 - } else { - false - } -}