mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 12:33:44 +02:00
Make OpenSSL init get called automatically at process launch, and some more scatter gather work.
This commit is contained in:
parent
1afbc73ff8
commit
e64fab8b9d
7 changed files with 9 additions and 19 deletions
|
@ -19,6 +19,7 @@ foreign-types = "0.5.0"
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
lazy_static = "^1"
|
lazy_static = "^1"
|
||||||
rand_core = "0.6.4"
|
rand_core = "0.6.4"
|
||||||
|
ctor = "^0"
|
||||||
#ed25519-dalek still uses rand_core 0.5.1, and that version is incompatible with 0.6.4, so we need to import and implement both.
|
#ed25519-dalek still uses rand_core 0.5.1, and that version is incompatible with 0.6.4, so we need to import and implement both.
|
||||||
rand_core_051 = { package = "rand_core", version = "0.5.1" }
|
rand_core_051 = { package = "rand_core", version = "0.5.1" }
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use crate::aes::AesGcm;
|
use crate::aes::AesGcm;
|
||||||
use crate::init;
|
|
||||||
use crate::secret::Secret;
|
use crate::secret::Secret;
|
||||||
use hex_literal::hex;
|
use hex_literal::hex;
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn aes_256_gcm() {
|
fn aes_256_gcm() {
|
||||||
init();
|
|
||||||
let key = Secret::move_bytes([1u8; 32]);
|
let key = Secret::move_bytes([1u8; 32]);
|
||||||
let mut enc = AesGcm::<true>::new(&key);
|
let mut enc = AesGcm::<true>::new(&key);
|
||||||
let mut dec = AesGcm::<false>::new(&key);
|
let mut dec = AesGcm::<false>::new(&key);
|
||||||
|
|
|
@ -845,14 +845,10 @@ impl Neg for BigNum {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::{
|
use crate::bn::{BigNum, BigNumContext};
|
||||||
bn::{BigNum, BigNumContext},
|
|
||||||
init,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_to_from_slice() {
|
fn test_to_from_slice() {
|
||||||
init();
|
|
||||||
let v0 = BigNum::from_u32(10_203_004).unwrap();
|
let v0 = BigNum::from_u32(10_203_004).unwrap();
|
||||||
let vec = v0.to_vec();
|
let vec = v0.to_vec();
|
||||||
let v1 = BigNum::from_slice(&vec).unwrap();
|
let v1 = BigNum::from_slice(&vec).unwrap();
|
||||||
|
@ -862,7 +858,6 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_negation() {
|
fn test_negation() {
|
||||||
init();
|
|
||||||
let a = BigNum::from_u32(909_829_283).unwrap();
|
let a = BigNum::from_u32(909_829_283).unwrap();
|
||||||
|
|
||||||
assert!(!a.is_negative());
|
assert!(!a.is_negative());
|
||||||
|
@ -871,7 +866,6 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_shift() {
|
fn test_shift() {
|
||||||
init();
|
|
||||||
let a = BigNum::from_u32(909_829_283).unwrap();
|
let a = BigNum::from_u32(909_829_283).unwrap();
|
||||||
|
|
||||||
assert!(a == &(&a << 1) >> 1);
|
assert!(a == &(&a << 1) >> 1);
|
||||||
|
@ -880,7 +874,6 @@ mod tests {
|
||||||
#[cfg(not(osslconf = "OPENSSL_NO_DEPRECATED_3_0"))]
|
#[cfg(not(osslconf = "OPENSSL_NO_DEPRECATED_3_0"))]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_prime_numbers() {
|
fn test_prime_numbers() {
|
||||||
init();
|
|
||||||
let a = BigNum::from_u32(19_029_017).unwrap();
|
let a = BigNum::from_u32(19_029_017).unwrap();
|
||||||
let mut p = BigNum::new().unwrap();
|
let mut p = BigNum::new().unwrap();
|
||||||
p.generate_prime(128, true, None, Some(&a)).unwrap();
|
p.generate_prime(128, true, None, Some(&a)).unwrap();
|
||||||
|
@ -893,7 +886,6 @@ mod tests {
|
||||||
#[cfg(ossl110)]
|
#[cfg(ossl110)]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_secure_bn() {
|
fn test_secure_bn() {
|
||||||
init();
|
|
||||||
let a = BigNum::new().unwrap();
|
let a = BigNum::new().unwrap();
|
||||||
assert!(!a.is_secure());
|
assert!(!a.is_secure());
|
||||||
|
|
||||||
|
@ -904,7 +896,6 @@ mod tests {
|
||||||
#[cfg(ossl110)]
|
#[cfg(ossl110)]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_const_time_bn() {
|
fn test_const_time_bn() {
|
||||||
init();
|
|
||||||
let a = BigNum::new().unwrap();
|
let a = BigNum::new().unwrap();
|
||||||
assert!(!a.is_const_time());
|
assert!(!a.is_const_time());
|
||||||
|
|
||||||
|
|
|
@ -127,11 +127,9 @@ impl CipherCtxRef {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::init;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn aes_128_ecb() {
|
fn aes_128_ecb() {
|
||||||
init();
|
|
||||||
let key = [1u8; 16];
|
let key = [1u8; 16];
|
||||||
let ctx = CipherCtx::new().unwrap();
|
let ctx = CipherCtx::new().unwrap();
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
@ -33,8 +33,11 @@ pub use aes_gmac_siv_fruity as aes_gmac_siv;
|
||||||
#[cfg(not(target_os = "macos"))]
|
#[cfg(not(target_os = "macos"))]
|
||||||
pub use aes_gmac_siv_openssl as aes_gmac_siv;
|
pub use aes_gmac_siv_openssl as aes_gmac_siv;
|
||||||
|
|
||||||
/// This must be called before using any function from this library.
|
use ctor::ctor;
|
||||||
pub fn init() {
|
|
||||||
|
#[ctor]
|
||||||
|
fn openssl_init() {
|
||||||
|
println!("OpenSSL init()");
|
||||||
ffi::init();
|
ffi::init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,4 +55,5 @@ pub fn secure_eq<A: AsRef<[u8]> + ?Sized, B: AsRef<[u8]> + ?Sized>(a: &A, b: &B)
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const ZEROES: [u8; 64] = [0_u8; 64];
|
pub const ZEROES: [u8; 64] = [0_u8; 64];
|
||||||
|
|
|
@ -1322,11 +1322,10 @@ pub use openssl_based::*;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::{init, p384::P384KeyPair, secure_eq};
|
use crate::{p384::P384KeyPair, secure_eq};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn generate_sign_verify_agree() {
|
fn generate_sign_verify_agree() {
|
||||||
init();
|
|
||||||
let kp = P384KeyPair::generate();
|
let kp = P384KeyPair::generate();
|
||||||
let kp2 = P384KeyPair::generate();
|
let kp2 = P384KeyPair::generate();
|
||||||
|
|
||||||
|
|
|
@ -155,7 +155,6 @@ impl<Application: ApplicationLayer> Context<Application> {
|
||||||
///
|
///
|
||||||
/// * `max_incomplete_session_queue_size` - Maximum number of incomplete sessions in negotiation phase
|
/// * `max_incomplete_session_queue_size` - Maximum number of incomplete sessions in negotiation phase
|
||||||
pub fn new(max_incomplete_session_queue_size: usize, default_physical_mtu: usize) -> Self {
|
pub fn new(max_incomplete_session_queue_size: usize, default_physical_mtu: usize) -> Self {
|
||||||
zerotier_crypto::init();
|
|
||||||
Self {
|
Self {
|
||||||
max_incomplete_session_queue_size,
|
max_incomplete_session_queue_size,
|
||||||
default_physical_mtu: AtomicUsize::new(default_physical_mtu),
|
default_physical_mtu: AtomicUsize::new(default_physical_mtu),
|
||||||
|
|
Loading…
Add table
Reference in a new issue