combined bindings to one crate

This commit is contained in:
mamoniot 2023-02-27 13:30:02 -05:00
commit 970d075e25
No known key found for this signature in database
GPG key ID: ADCCDBBE0E3D3B3B
21 changed files with 43 additions and 94 deletions

View file

@ -7,7 +7,6 @@ members = [
"service", "service",
"vl1-service", "vl1-service",
"utils", "utils",
"openssl-zt",
"openssl-sys", "openssl-sys",
] ]

View file

@ -1,20 +1,32 @@
[package] [package]
authors = ["ZeroTier, Inc. <contact@zerotier.com>", "Adam Ierymenko <adam.ierymenko@zerotier.com>"]
edition = "2021"
license = "MPL-2.0"
name = "zerotier-crypto" name = "zerotier-crypto"
authors = ["Steven Fackler <sfackler@gmail.com>"]
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" version = "0.1.0"
[features]
vendored = ['ffi/vendored']
bindgen = ['ffi/bindgen']
default = []
[dependencies] [dependencies]
zerotier-utils = { path = "../utils" }
ed25519-dalek = { version = "1.0.1", features = ["std", "u64_backend"], default-features = false } ed25519-dalek = { version = "1.0.1", features = ["std", "u64_backend"], default-features = false }
poly1305 = { version = "0.8.0", features = [], 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 } 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] ffi = { package = "openssl-sys", version = "0.9.80", path = "../openssl-sys" }
winapi = { version = "^0", features = ["handleapi", "ws2ipdef", "ws2tcpip"] }
[target."cfg(not(windows))".dependencies] [dev-dependencies]
libc = "^0" hex = "0.4.3"
signal-hook = "^0" hex-literal = "0.3.4"

View file

@ -1 +0,0 @@
../rustfmt.toml

View file

@ -1,16 +1,28 @@
// (c) 2020-2022 ZeroTier, Inc. -- currently proprietary pending actual release and licensing. See LICENSE.md.
pub use openssl::aes; mod error;
pub use openssl::hash; mod cipher_ctx;
pub use openssl::p384; mod bn;
pub use openssl::random; mod ec;
pub use openssl::secret;
pub use openssl::aes_gmac_siv; 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 poly1305;
pub mod salsa; pub mod salsa;
pub mod typestate; pub mod typestate;
pub mod x25519; 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. /// Constant time byte slice equality.
#[inline] #[inline]
pub fn secure_eq<A: AsRef<[u8]> + ?Sized, B: AsRef<[u8]> + ?Sized>(a: &A, b: &B) -> bool { pub fn secure_eq<A: AsRef<[u8]> + ?Sized, B: AsRef<[u8]> + ?Sized>(a: &A, b: &B) -> bool {
@ -25,13 +37,3 @@ pub fn secure_eq<A: AsRef<[u8]> + ?Sized, B: AsRef<[u8]> + ?Sized>(a: &A, b: &B)
false 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()) };
}

View file

@ -5,8 +5,8 @@ use std::io::Write;
use ed25519_dalek::Digest; use ed25519_dalek::Digest;
use openssl::random::SecureRandom; use crate::random::SecureRandom;
use openssl::secret::Secret; use crate::secret::Secret;
pub const C25519_PUBLIC_KEY_SIZE: usize = 32; pub const C25519_PUBLIC_KEY_SIZE: usize = 32;
pub const C25519_SECRET_KEY_SIZE: usize = 32; pub const C25519_SECRET_KEY_SIZE: usize = 32;

View file

@ -1,29 +0,0 @@
[package]
name = "openssl-zt"
version = "0.0.1"
authors = ["Steven Fackler <sfackler@gmail.com>"]
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"

View file

@ -1 +0,0 @@
../README.md

View file

@ -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<A: AsRef<[u8]> + ?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
}
}