From bd55e032e2d513a9f9728bad2860d8c92a60ed04 Mon Sep 17 00:00:00 2001 From: Monica Moniot Date: Tue, 15 Aug 2023 12:57:24 -0400 Subject: [PATCH] integrated changes to deps --- Cargo.toml | 36 +- crypto-glue/LICENSE => LICENSE | 0 README.md | 9 +- crypto-glue/Cargo.toml | 30 - crypto-glue/README.md | 7 - crypto-glue/build.rs | 110 -- crypto-glue/src/aes_fruity.rs | 335 ----- crypto-glue/src/aes_gmac_siv_fruity.rs | 482 ------- crypto-glue/src/aes_openssl.rs | 183 --- crypto-glue/src/cipher_ctx.rs | 210 --- crypto-glue/src/error.rs | 364 ----- crypto-glue/src/p384_builtin.rs | 1257 ----------------- crypto-glue/src/random.rs | 156 -- crypto-glue/src/secret.rs | 137 -- crypto-glue/src/x25519.rs | 181 --- openssl-sys/CHANGELOG.md | 411 ------ openssl-sys/Cargo.toml | 36 - openssl-sys/LICENSE-MIT | 25 - openssl-sys/README.md | 1 - openssl-sys/build/cfgs.rs | 94 -- openssl-sys/build/expando.c | 124 -- openssl-sys/build/find_normal.rs | 266 ---- openssl-sys/build/find_vendored.rs | 10 - openssl-sys/build/main.rs | 404 ------ openssl-sys/build/run_bindgen.rs | 123 -- openssl-sys/src/aes.rs | 7 - openssl-sys/src/asn1.rs | 39 - openssl-sys/src/bio.rs | 54 - openssl-sys/src/bn.rs | 15 - openssl-sys/src/cms.rs | 46 - openssl-sys/src/crypto.rs | 114 -- openssl-sys/src/dtls1.rs | 9 - openssl-sys/src/ec.rs | 11 - openssl-sys/src/err.rs | 70 - openssl-sys/src/evp.rs | 227 --- openssl-sys/src/handwritten/aes.rs | 21 - openssl-sys/src/handwritten/asn1.rs | 55 - openssl-sys/src/handwritten/bio.rs | 94 -- openssl-sys/src/handwritten/bn.rs | 105 -- openssl-sys/src/handwritten/cms.rs | 43 - openssl-sys/src/handwritten/conf.rs | 7 - openssl-sys/src/handwritten/crypto.rs | 77 - openssl-sys/src/handwritten/dh.rs | 40 - openssl-sys/src/handwritten/dsa.rs | 61 - openssl-sys/src/handwritten/ec.rs | 164 --- openssl-sys/src/handwritten/err.rs | 50 - openssl-sys/src/handwritten/evp.rs | 500 ------- openssl-sys/src/handwritten/hmac.rs | 24 - openssl-sys/src/handwritten/kdf.rs | 26 - openssl-sys/src/handwritten/mod.rs | 65 - openssl-sys/src/handwritten/object.rs | 20 - openssl-sys/src/handwritten/ocsp.rs | 71 - openssl-sys/src/handwritten/pem.rs | 101 -- openssl-sys/src/handwritten/pkcs12.rs | 47 - openssl-sys/src/handwritten/pkcs7.rs | 38 - openssl-sys/src/handwritten/provider.rs | 13 - openssl-sys/src/handwritten/rand.rs | 12 - openssl-sys/src/handwritten/rsa.rs | 55 - openssl-sys/src/handwritten/safestack.rs | 1 - openssl-sys/src/handwritten/sha.rs | 101 -- openssl-sys/src/handwritten/srtp.rs | 10 - openssl-sys/src/handwritten/ssl.rs | 781 ---------- openssl-sys/src/handwritten/stack.rs | 45 - openssl-sys/src/handwritten/tls1.rs | 28 - openssl-sys/src/handwritten/types.rs | 1078 -------------- openssl-sys/src/handwritten/x509.rs | 588 -------- openssl-sys/src/handwritten/x509_vfy.rs | 110 -- openssl-sys/src/handwritten/x509v3.rs | 86 -- openssl-sys/src/lib.rs | 182 --- openssl-sys/src/macros.rs | 298 ---- openssl-sys/src/obj_mac.rs | 978 ------------- openssl-sys/src/ocsp.rs | 35 - openssl-sys/src/pem.rs | 3 - openssl-sys/src/pkcs7.rs | 20 - openssl-sys/src/rsa.rs | 90 -- openssl-sys/src/sha.rs | 103 -- openssl-sys/src/srtp.rs | 14 - openssl-sys/src/ssl.rs | 591 -------- openssl-sys/src/ssl3.rs | 5 - openssl-sys/src/tls1.rs | 67 - openssl-sys/src/types.rs | 21 - openssl-sys/src/x509.rs | 15 - openssl-sys/src/x509_vfy.rs | 139 -- openssl-sys/src/x509v3.rs | 93 -- .../src => src}/aes_gmac_siv_openssl.rs | 62 +- src/aes_openssl.rs | 86 ++ {crypto-glue/src => src}/aes_tests.rs | 45 +- {crypto-glue/src => src}/hash.rs | 73 +- {crypto-glue/src => src}/lib.rs | 28 +- {crypto-glue/src => src}/p384.rs | 153 +- {crypto-glue/src => src}/poly1305.rs | 0 src/random.rs | 105 ++ {crypto-glue/src => src}/salsa.rs | 0 {crypto-glue/src => src}/typestate.rs | 0 src/x25519.rs | 150 ++ 95 files changed, 550 insertions(+), 12906 deletions(-) rename crypto-glue/LICENSE => LICENSE (100%) delete mode 100644 crypto-glue/Cargo.toml delete mode 100644 crypto-glue/README.md delete mode 100644 crypto-glue/build.rs delete mode 100644 crypto-glue/src/aes_fruity.rs delete mode 100644 crypto-glue/src/aes_gmac_siv_fruity.rs delete mode 100644 crypto-glue/src/aes_openssl.rs delete mode 100644 crypto-glue/src/cipher_ctx.rs delete mode 100644 crypto-glue/src/error.rs delete mode 100644 crypto-glue/src/p384_builtin.rs delete mode 100644 crypto-glue/src/random.rs delete mode 100644 crypto-glue/src/secret.rs delete mode 100644 crypto-glue/src/x25519.rs delete mode 100644 openssl-sys/CHANGELOG.md delete mode 100644 openssl-sys/Cargo.toml delete mode 100644 openssl-sys/LICENSE-MIT delete mode 120000 openssl-sys/README.md delete mode 100644 openssl-sys/build/cfgs.rs delete mode 100644 openssl-sys/build/expando.c delete mode 100644 openssl-sys/build/find_normal.rs delete mode 100644 openssl-sys/build/find_vendored.rs delete mode 100644 openssl-sys/build/main.rs delete mode 100644 openssl-sys/build/run_bindgen.rs delete mode 100644 openssl-sys/src/aes.rs delete mode 100644 openssl-sys/src/asn1.rs delete mode 100644 openssl-sys/src/bio.rs delete mode 100644 openssl-sys/src/bn.rs delete mode 100644 openssl-sys/src/cms.rs delete mode 100644 openssl-sys/src/crypto.rs delete mode 100644 openssl-sys/src/dtls1.rs delete mode 100644 openssl-sys/src/ec.rs delete mode 100644 openssl-sys/src/err.rs delete mode 100644 openssl-sys/src/evp.rs delete mode 100644 openssl-sys/src/handwritten/aes.rs delete mode 100644 openssl-sys/src/handwritten/asn1.rs delete mode 100644 openssl-sys/src/handwritten/bio.rs delete mode 100644 openssl-sys/src/handwritten/bn.rs delete mode 100644 openssl-sys/src/handwritten/cms.rs delete mode 100644 openssl-sys/src/handwritten/conf.rs delete mode 100644 openssl-sys/src/handwritten/crypto.rs delete mode 100644 openssl-sys/src/handwritten/dh.rs delete mode 100644 openssl-sys/src/handwritten/dsa.rs delete mode 100644 openssl-sys/src/handwritten/ec.rs delete mode 100644 openssl-sys/src/handwritten/err.rs delete mode 100644 openssl-sys/src/handwritten/evp.rs delete mode 100644 openssl-sys/src/handwritten/hmac.rs delete mode 100644 openssl-sys/src/handwritten/kdf.rs delete mode 100644 openssl-sys/src/handwritten/mod.rs delete mode 100644 openssl-sys/src/handwritten/object.rs delete mode 100644 openssl-sys/src/handwritten/ocsp.rs delete mode 100644 openssl-sys/src/handwritten/pem.rs delete mode 100644 openssl-sys/src/handwritten/pkcs12.rs delete mode 100644 openssl-sys/src/handwritten/pkcs7.rs delete mode 100644 openssl-sys/src/handwritten/provider.rs delete mode 100644 openssl-sys/src/handwritten/rand.rs delete mode 100644 openssl-sys/src/handwritten/rsa.rs delete mode 100644 openssl-sys/src/handwritten/safestack.rs delete mode 100644 openssl-sys/src/handwritten/sha.rs delete mode 100644 openssl-sys/src/handwritten/srtp.rs delete mode 100644 openssl-sys/src/handwritten/ssl.rs delete mode 100644 openssl-sys/src/handwritten/stack.rs delete mode 100644 openssl-sys/src/handwritten/tls1.rs delete mode 100644 openssl-sys/src/handwritten/types.rs delete mode 100644 openssl-sys/src/handwritten/x509.rs delete mode 100644 openssl-sys/src/handwritten/x509_vfy.rs delete mode 100644 openssl-sys/src/handwritten/x509v3.rs delete mode 100644 openssl-sys/src/lib.rs delete mode 100644 openssl-sys/src/macros.rs delete mode 100644 openssl-sys/src/obj_mac.rs delete mode 100644 openssl-sys/src/ocsp.rs delete mode 100644 openssl-sys/src/pem.rs delete mode 100644 openssl-sys/src/pkcs7.rs delete mode 100644 openssl-sys/src/rsa.rs delete mode 100644 openssl-sys/src/sha.rs delete mode 100644 openssl-sys/src/srtp.rs delete mode 100644 openssl-sys/src/ssl.rs delete mode 100644 openssl-sys/src/ssl3.rs delete mode 100644 openssl-sys/src/tls1.rs delete mode 100644 openssl-sys/src/types.rs delete mode 100644 openssl-sys/src/x509.rs delete mode 100644 openssl-sys/src/x509_vfy.rs delete mode 100644 openssl-sys/src/x509v3.rs rename {crypto-glue/src => src}/aes_gmac_siv_openssl.rs (81%) create mode 100644 src/aes_openssl.rs rename {crypto-glue/src => src}/aes_tests.rs (99%) rename {crypto-glue/src => src}/hash.rs (93%) rename {crypto-glue/src => src}/lib.rs (69%) rename {crypto-glue/src => src}/p384.rs (79%) rename {crypto-glue/src => src}/poly1305.rs (100%) create mode 100644 src/random.rs rename {crypto-glue/src => src}/salsa.rs (100%) rename {crypto-glue/src => src}/typestate.rs (100%) create mode 100644 src/x25519.rs diff --git a/Cargo.toml b/Cargo.toml index 02d4844..0737669 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,12 +1,26 @@ -[workspace] -members = [ - "crypto-glue", - "openssl-sys", -] +[package] +name = "zerotier-crypto-glue" +authors = ["ZeroTier, Inc. "] +license = "MPL-2.0" +description = "ZeroTier common security functions and glue code to wrap cryptography APIs." +readme = "README.md" +categories = ["cryptography", "api-bindings"] +edition = "2021" +version = "0.1.0" -#[profile.release] -#opt-level = 3 -#strip = true -#debug = false -#codegen-units = 1 -#lto = true +[features] + +[dependencies] +x25519-dalek = { version = "2.0.0", features = ["static_secrets"], default-features = false } +ed25519-dalek = { version = "2.0.0", features = ["digest", "rand_core"], default-features = false } +poly1305 = { version = "0.8.0", features = [], default-features = false } +cfg-if = "1.0" +libc = "0.2" +once_cell = "1.18.0" +ctor = "^0" +zssp = { git = "ssh://git@github.com/zerotier/zssp.git", branch = "proto", features = ["openssl-sys"], default-features = false } +rand_xoshiro = { version = "0.6.0"} + +[dev-dependencies] +hex = "0.4.3" +hex-literal = "0.4.1" diff --git a/crypto-glue/LICENSE b/LICENSE similarity index 100% rename from crypto-glue/LICENSE rename to LICENSE diff --git a/README.md b/README.md index 2859b59..3006f04 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ -ZeroTier Cryptographic Glue -====== +# ZeroTier Cryptography Library -This repository contains a few utility classes and mostly glue code to provide a common layer for other ZeroTier Rust projects to use various cryptographic APIs. +------ + +Most of this library is just glue to provide a simple safe API around things like OpenSSL or OS-specific crypto APIs. + +It is very important that this library is only linked to OpenSSL versions greater than 1.1.0. 1.1.0 introduced no-hassle threadsafety which we take advantage of. If we want a version prior to 1.1.0 we will have to add conditional threadsafety code. diff --git a/crypto-glue/Cargo.toml b/crypto-glue/Cargo.toml deleted file mode 100644 index f3f2a31..0000000 --- a/crypto-glue/Cargo.toml +++ /dev/null @@ -1,30 +0,0 @@ -[package] -name = "zerotier-crypto-glue" -authors = ["ZeroTier, Inc. "] -license = "MPL-2.0" -description = "ZeroTier common security functions and glue code to wrap cryptography APIs." -readme = "README.md" -categories = ["cryptography", "api-bindings"] -edition = "2021" -version = "0.1.0" - -[features] - -[dependencies] -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 } -cfg-if = "1.0" -foreign-types = "0.5.0" -libc = "0.2" -once_cell = "1.18.0" -ctor = "^0" -#ed25519-dalek still uses rand_core 0.5.1, and that version is incompatible with 0.6.4, so we need to implement both. -rand_core_051 = { package = "rand_core", version = "0.5.1" } -ffi = { package = "openssl-sys", version = "0.9.80", path = "../openssl-sys" } -zssp = { git = "ssh://git@github.com/zerotier/zssp.git", branch = "dev" } -rand_xoshiro = { version = "0.6.0"} - -[dev-dependencies] -hex = "0.4.3" -hex-literal = "0.3.4" diff --git a/crypto-glue/README.md b/crypto-glue/README.md deleted file mode 100644 index 3006f04..0000000 --- a/crypto-glue/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# ZeroTier Cryptography Library - ------- - -Most of this library is just glue to provide a simple safe API around things like OpenSSL or OS-specific crypto APIs. - -It is very important that this library is only linked to OpenSSL versions greater than 1.1.0. 1.1.0 introduced no-hassle threadsafety which we take advantage of. If we want a version prior to 1.1.0 we will have to add conditional threadsafety code. diff --git a/crypto-glue/build.rs b/crypto-glue/build.rs deleted file mode 100644 index 7651429..0000000 --- a/crypto-glue/build.rs +++ /dev/null @@ -1,110 +0,0 @@ -#![allow( - clippy::inconsistent_digit_grouping, - clippy::uninlined_format_args, - clippy::unusual_byte_groupings -)] - -use std::env; - -fn main() { - if env::var("DEP_OPENSSL_LIBRESSL").is_ok() { - println!("cargo:rustc-cfg=libressl"); - } - - if env::var("CARGO_FEATURE_UNSTABLE_BORINGSSL").is_ok() { - println!("cargo:rustc-cfg=boringssl"); - return; - } - - if let Ok(v) = env::var("DEP_OPENSSL_LIBRESSL_VERSION") { - println!("cargo:rustc-cfg=libressl{}", v); - } - - if let Ok(vars) = env::var("DEP_OPENSSL_CONF") { - for var in vars.split(',') { - println!("cargo:rustc-cfg=osslconf=\"{}\"", var); - } - } - - if let Ok(version) = env::var("DEP_OPENSSL_VERSION_NUMBER") { - let version = u64::from_str_radix(&version, 16).unwrap(); - - if version >= 0x1_00_01_00_0 { - println!("cargo:rustc-cfg=ossl101"); - } - if version >= 0x1_00_02_00_0 { - println!("cargo:rustc-cfg=ossl102"); - } - if version >= 0x1_01_00_00_0 { - println!("cargo:rustc-cfg=ossl110"); - } - if version >= 0x1_01_00_07_0 { - println!("cargo:rustc-cfg=ossl110g"); - } - if version >= 0x1_01_00_08_0 { - println!("cargo:rustc-cfg=ossl110h"); - } - if version >= 0x1_01_01_00_0 { - println!("cargo:rustc-cfg=ossl111"); - } - if version >= 0x3_00_00_00_0 { - println!("cargo:rustc-cfg=ossl300"); - } - } - - if let Ok(version) = env::var("DEP_OPENSSL_LIBRESSL_VERSION_NUMBER") { - let version = u64::from_str_radix(&version, 16).unwrap(); - - if version >= 0x2_05_01_00_0 { - println!("cargo:rustc-cfg=libressl251"); - } - - if version >= 0x2_06_01_00_0 { - println!("cargo:rustc-cfg=libressl261"); - } - - if version >= 0x2_07_00_00_0 { - println!("cargo:rustc-cfg=libressl270"); - } - - if version >= 0x2_07_01_00_0 { - println!("cargo:rustc-cfg=libressl271"); - } - - if version >= 0x2_07_03_00_0 { - println!("cargo:rustc-cfg=libressl273"); - } - - if version >= 0x2_08_00_00_0 { - println!("cargo:rustc-cfg=libressl280"); - } - - if version >= 0x2_09_01_00_0 { - println!("cargo:rustc-cfg=libressl291"); - } - - if version >= 0x3_02_01_00_0 { - println!("cargo:rustc-cfg=libressl321"); - } - - if version >= 0x3_03_02_00_0 { - println!("cargo:rustc-cfg=libressl332"); - } - - if version >= 0x3_04_00_00_0 { - println!("cargo:rustc-cfg=libressl340"); - } - - if version >= 0x3_05_00_00_0 { - println!("cargo:rustc-cfg=libressl350"); - } - - if version >= 0x3_06_00_00_0 { - println!("cargo:rustc-cfg=libressl360"); - } - - if version >= 0x3_06_01_00_0 { - println!("cargo:rustc-cfg=libressl361"); - } - } -} diff --git a/crypto-glue/src/aes_fruity.rs b/crypto-glue/src/aes_fruity.rs deleted file mode 100644 index f0da0ce..0000000 --- a/crypto-glue/src/aes_fruity.rs +++ /dev/null @@ -1,335 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * (c) ZeroTier, Inc. - * https://www.zerotier.com/ - */ - -// MacOS implementation of AES primitives since CommonCrypto seems to be faster than OpenSSL, especially on ARM64. -use std::os::raw::{c_int, c_void}; -use std::ptr::{null, null_mut}; -use std::sync::Mutex; - -use zssp::crypto::aes::{self, AES_256_BLOCK_SIZE, AES_256_KEY_SIZE}; -use zssp::crypto::aes_gcm::{self, AES_GCM_IV_SIZE, AES_GCM_TAG_SIZE}; - -#[allow(unused_imports)] -use crate::secure_eq; - -#[allow(non_upper_case_globals, unused)] -const kCCModeECB: i32 = 1; -#[allow(non_upper_case_globals, unused)] -const kCCModeCTR: i32 = 4; -#[allow(non_upper_case_globals, unused)] -const kCCModeGCM: i32 = 11; -#[allow(non_upper_case_globals, unused)] -const kCCEncrypt: i32 = 0; -#[allow(non_upper_case_globals, unused)] -const kCCDecrypt: i32 = 1; -#[allow(non_upper_case_globals, unused)] -const kCCAlgorithmAES: i32 = 0; -#[allow(non_upper_case_globals, unused)] -const kCCOptionECBMode: i32 = 2; - -extern "C" { - fn CCCryptorCreateWithMode( - op: i32, - mode: i32, - alg: i32, - padding: i32, - iv: *const c_void, - key: *const c_void, - key_len: usize, - tweak: *const c_void, - tweak_len: usize, - num_rounds: c_int, - options: i32, - cryyptor_ref: *mut *mut c_void, - ) -> i32; - fn CCCryptorUpdate( - cryptor_ref: *mut c_void, - data_in: *const c_void, - data_in_len: usize, - data_out: *mut c_void, - data_out_len: usize, - data_out_written: *mut usize, - ) -> i32; - //fn CCCryptorReset(cryptor_ref: *mut c_void, iv: *const c_void) -> i32; - fn CCCryptorRelease(cryptor_ref: *mut c_void) -> i32; - fn CCCryptorGCMSetIV(cryptor_ref: *mut c_void, iv: *const c_void, iv_len: usize) -> i32; - fn CCCryptorGCMAddAAD(cryptor_ref: *mut c_void, aad: *const c_void, len: usize) -> i32; - fn CCCryptorGCMEncrypt( - cryptor_ref: *mut c_void, - data_in: *const c_void, - data_in_len: usize, - data_out: *mut c_void, - ) -> i32; - fn CCCryptorGCMDecrypt( - cryptor_ref: *mut c_void, - data_in: *const c_void, - data_in_len: usize, - data_out: *mut c_void, - ) -> i32; - fn CCCryptorGCMFinal(cryptor_ref: *mut c_void, tag: *mut c_void, tag_len: *mut usize) -> i32; - fn CCCryptorGCMReset(cryptor_ref: *mut c_void) -> i32; -} - -pub struct AesGcm(*mut c_void); - -impl Drop for AesGcm { - #[inline(always)] - fn drop(&mut self) { - unsafe { CCCryptorRelease(self.0) }; - } -} - -impl AesGcm { - pub fn new(k: &[u8; AES_256_KEY_SIZE]) -> Self { - unsafe { - let mut ptr: *mut c_void = null_mut(); - assert_eq!( - CCCryptorCreateWithMode( - if ENCRYPT { - kCCEncrypt - } else { - kCCDecrypt - }, - kCCModeGCM, - kCCAlgorithmAES, - 0, - null(), - k.as_ptr().cast(), - AES_256_KEY_SIZE, - null(), - 0, - 0, - 0, - &mut ptr, - ), - 0 - ); - AesGcm(ptr) - } - } - - #[inline(always)] - pub fn reset_init_gcm(&mut self, iv: &[u8]) { - assert_eq!(iv.len(), AES_GCM_IV_SIZE); - unsafe { - assert_eq!(CCCryptorGCMReset(self.0), 0); - assert_eq!(CCCryptorGCMSetIV(self.0, iv.as_ptr().cast(), AES_GCM_IV_SIZE), 0); - } - } - - #[inline(always)] - pub fn aad(&mut self, aad: &[u8]) { - unsafe { - assert_eq!(CCCryptorGCMAddAAD(self.0, aad.as_ptr().cast(), aad.len()), 0); - } - } - - #[inline(always)] - pub fn crypt(&mut self, input: &[u8], output: &mut [u8]) { - unsafe { - assert_eq!(input.len(), output.len()); - if ENCRYPT { - assert_eq!( - CCCryptorGCMEncrypt(self.0, input.as_ptr().cast(), input.len(), output.as_mut_ptr().cast()), - 0 - ); - } else { - assert_eq!( - CCCryptorGCMDecrypt(self.0, input.as_ptr().cast(), input.len(), output.as_mut_ptr().cast()), - 0 - ); - } - } - } - - #[inline(always)] - pub fn crypt_in_place(&mut self, data: &mut [u8]) { - unsafe { - if ENCRYPT { - assert_eq!( - CCCryptorGCMEncrypt(self.0, data.as_ptr().cast(), data.len(), data.as_mut_ptr().cast()), - 0 - ); - } else { - assert_eq!( - CCCryptorGCMDecrypt(self.0, data.as_ptr().cast(), data.len(), data.as_mut_ptr().cast()), - 0 - ); - } - } - } - - #[inline(always)] - fn finish(&mut self, tag: &mut [u8; AES_GCM_TAG_SIZE]) { - unsafe { - let mut tag_len = AES_GCM_TAG_SIZE; - if CCCryptorGCMFinal(self.0, tag.as_mut_ptr().cast(), &mut tag_len) != 0 { - debug_assert!(false); - tag.fill(0); - } - } - } -} - -pub struct Aes(Mutex<*mut c_void>); -unsafe impl Send for Aes {} -unsafe impl Sync for Aes {} - -impl Drop for Aes { - #[inline(always)] - fn drop(&mut self) { - let p = self.0.lock().unwrap(); - unsafe { - CCCryptorRelease(*p); - } - } -} - -impl Aes { - pub fn new(key: &[u8; AES_256_KEY_SIZE]) -> Self { - unsafe { - let mut p = null_mut(); - assert_eq!( - CCCryptorCreateWithMode( - if ENCRYPT { - kCCEncrypt - } else { - kCCDecrypt - }, - kCCModeECB, - kCCAlgorithmAES, - 0, - null(), - key.as_ptr().cast(), - AES_256_KEY_SIZE, - null(), - 0, - 0, - kCCOptionECBMode, - &mut p, - ), - 0 - ); - Self(Mutex::new(p)) - } - } - pub fn reset(&self, key: &[u8; AES_256_KEY_SIZE]) { - let mut p = self.0.lock().unwrap(); - unsafe { - CCCryptorRelease(*p); - assert_eq!( - CCCryptorCreateWithMode( - if ENCRYPT { - kCCEncrypt - } else { - kCCDecrypt - }, - kCCModeECB, - kCCAlgorithmAES, - 0, - null(), - key.as_ptr().cast(), - AES_256_KEY_SIZE, - null(), - 0, - 0, - kCCOptionECBMode, - &mut *p, - ), - 0 - ); - } - } - - #[inline(always)] - pub fn crypt_block_in_place(&self, data: &mut [u8]) { - assert_eq!(data.len(), AES_256_BLOCK_SIZE); - unsafe { - let mut data_out_written = 0; - let p = self.0.lock().unwrap(); - CCCryptorUpdate( - *p, - data.as_ptr().cast(), - AES_256_BLOCK_SIZE, - data.as_mut_ptr().cast(), - AES_256_BLOCK_SIZE, - &mut data_out_written, - ); - } - } -} - -impl aes_gcm::AesGcmEnc for AesGcm { - fn new(key: &[u8; aes_gcm::AES_GCM_KEY_SIZE]) -> Self { - Self::new(key) - } - fn set_iv(&mut self, iv: &[u8; aes_gcm::AES_GCM_IV_SIZE]) { - self.reset_init_gcm(iv) - } - fn set_aad(&mut self, aad: &[u8]) { - self.aad(aad) - } - fn encrypt(&mut self, input: &[u8], output: &mut [u8]) { - self.crypt(input, output) - } - fn encrypt_in_place(&mut self, data: &mut [u8]) { - self.crypt_in_place(data) - } - fn finish_encrypt(&mut self, output: &mut [u8; aes_gcm::AES_GCM_TAG_SIZE]) { - self.finish(output); - } -} - -impl aes_gcm::AesGcmDec for AesGcm { - fn new(key: &[u8; aes_gcm::AES_GCM_KEY_SIZE]) -> Self { - Self::new(key) - } - fn set_iv(&mut self, iv: &[u8; aes_gcm::AES_GCM_IV_SIZE]) { - self.reset_init_gcm(iv) - } - fn set_aad(&mut self, aad: &[u8]) { - self.aad(aad) - } - fn decrypt(&mut self, input: &[u8], output: &mut [u8]) { - self.crypt(input, output) - } - fn decrypt_in_place(&mut self, data: &mut [u8]) { - self.crypt_in_place(data) - } - fn finish_decrypt(&mut self, expected_tag: &[u8; aes_gcm::AES_GCM_TAG_SIZE]) -> bool { - let mut output = [0u8; aes_gcm::AES_GCM_TAG_SIZE]; - self.finish(&mut output); - secure_eq(expected_tag, &output) - } -} - -impl aes::AesEnc for Aes { - fn new(key: &[u8; AES_256_KEY_SIZE]) -> Self { - Self::new(key) - } - fn reset(&self, key: &[u8; AES_256_KEY_SIZE]) { - self.reset(key) - } - - fn encrypt_in_place(&self, block: &mut [u8; AES_256_BLOCK_SIZE]) { - self.crypt_block_in_place(block) - } -} - -impl aes::AesDec for Aes { - fn new(key: &[u8; AES_256_KEY_SIZE]) -> Self { - Self::new(key) - } - fn reset(&self, key: &[u8; AES_256_KEY_SIZE]) { - self.reset(key) - } - - fn decrypt_in_place(&self, block: &mut [u8; AES_256_BLOCK_SIZE]) { - self.crypt_block_in_place(block) - } -} diff --git a/crypto-glue/src/aes_gmac_siv_fruity.rs b/crypto-glue/src/aes_gmac_siv_fruity.rs deleted file mode 100644 index 40d446b..0000000 --- a/crypto-glue/src/aes_gmac_siv_fruity.rs +++ /dev/null @@ -1,482 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * (c) ZeroTier, Inc. - * https://www.zerotier.com/ - */ - -// AES-GMAC-SIV implemented using MacOS/iOS CommonCrypto (MacOS 10.13 or newer required). - -use std::os::raw::{c_int, c_void}; -use std::ptr::{null, null_mut}; - -#[allow(non_upper_case_globals)] -const kCCModeECB: i32 = 1; -#[allow(non_upper_case_globals)] -const kCCModeCTR: i32 = 4; -#[allow(non_upper_case_globals)] -const kCCModeGCM: i32 = 11; -#[allow(non_upper_case_globals)] -const kCCEncrypt: i32 = 0; -#[allow(non_upper_case_globals)] -const kCCDecrypt: i32 = 1; -#[allow(non_upper_case_globals)] -const kCCAlgorithmAES: i32 = 0; -#[allow(non_upper_case_globals)] -const kCCOptionECBMode: i32 = 2; - -extern "C" { - fn CCCryptorCreateWithMode( - op: i32, - mode: i32, - alg: i32, - padding: i32, - iv: *const c_void, - key: *const c_void, - key_len: usize, - tweak: *const c_void, - tweak_len: usize, - num_rounds: c_int, - options: i32, - cryyptor_ref: *mut *mut c_void, - ) -> i32; - fn CCCryptorUpdate( - cryptor_ref: *mut c_void, - data_in: *const c_void, - data_in_len: usize, - data_out: *mut c_void, - data_out_len: usize, - data_out_written: *mut usize, - ) -> i32; - fn CCCryptorReset(cryptor_ref: *mut c_void, iv: *const c_void) -> i32; - fn CCCryptorRelease(cryptor_ref: *mut c_void) -> i32; - fn CCCryptorGCMSetIV(cryptor_ref: *mut c_void, iv: *const c_void, iv_len: usize) -> i32; - fn CCCryptorGCMAddAAD(cryptor_ref: *mut c_void, aad: *const c_void, len: usize) -> i32; - fn CCCryptorGCMFinalize(cryptor_ref: *mut c_void, tag: *mut c_void, tag_len: usize) -> i32; - fn CCCryptorGCMReset(cryptor_ref: *mut c_void) -> i32; -} - -pub struct AesCtr(*mut c_void); - -impl Drop for AesCtr { - fn drop(&mut self) { - if !self.0.is_null() { - unsafe { - CCCryptorRelease(self.0); - } - } - } -} - -impl AesCtr { - /// Construct a new AES-CTR cipher. - /// Key must be 16, 24, or 32 bytes in length or a panic will occur. - pub fn new(k: &[u8]) -> Self { - if k.len() != 32 && k.len() != 24 && k.len() != 16 { - panic!("AES supports 128, 192, or 256 bits keys"); - } - unsafe { - let mut ptr: *mut c_void = null_mut(); - let result = CCCryptorCreateWithMode( - kCCEncrypt, - kCCModeCTR, - kCCAlgorithmAES, - 0, - crate::ZEROES.as_ptr().cast(), - k.as_ptr().cast(), - k.len(), - null(), - 0, - 0, - 0, - &mut ptr, - ); - if result != 0 { - panic!("CCCryptorCreateWithMode for CTR mode returned {}", result); - } - AesCtr(ptr) - } - } - - /// Initialize AES-CTR for encryption or decryption with the given IV. - /// If it's already been used, this also resets the cipher. There is no separate reset. - pub fn init(&mut self, iv: &[u8]) { - unsafe { - if iv.len() == 16 { - if CCCryptorReset(self.0, iv.as_ptr().cast()) != 0 { - panic!("CCCryptorReset for CTR mode failed (old MacOS bug)"); - } - } else if iv.len() < 16 { - let mut iv2 = [0_u8; 16]; - iv2[0..iv.len()].copy_from_slice(iv); - if CCCryptorReset(self.0, iv2.as_ptr().cast()) != 0 { - panic!("CCCryptorReset for CTR mode failed (old MacOS bug)"); - } - } else { - panic!("CTR IV must be less than or equal to 16 bytes in length"); - } - } - } - - /// Encrypt or decrypt (same operation with CTR mode) - #[inline(always)] - pub fn crypt(&mut self, input: &[u8], output: &mut [u8]) { - unsafe { - assert!(output.len() >= input.len()); - let mut data_out_written: usize = 0; - CCCryptorUpdate( - self.0, - input.as_ptr().cast(), - input.len(), - output.as_mut_ptr().cast(), - output.len(), - &mut data_out_written, - ); - } - } - - /// Encrypt or decrypt in place (same operation with CTR mode) - #[inline(always)] - pub fn crypt_in_place(&mut self, data: &mut [u8]) { - unsafe { - let mut data_out_written: usize = 0; - CCCryptorUpdate( - self.0, - data.as_ptr().cast(), - data.len(), - data.as_mut_ptr().cast(), - data.len(), - &mut data_out_written, - ); - } - } -} - -unsafe impl Send for AesCtr {} - -#[repr(align(8))] -pub struct AesGmacSiv { - tag: [u8; 16], - tmp: [u8; 16], - ctr: *mut c_void, - ecb_enc: *mut c_void, - ecb_dec: *mut c_void, - gmac: *mut c_void, -} - -impl Drop for AesGmacSiv { - fn drop(&mut self) { - unsafe { - if !self.ctr.is_null() { - CCCryptorRelease(self.ctr); - } - if !self.ecb_enc.is_null() { - CCCryptorRelease(self.ecb_enc); - } - if !self.ecb_dec.is_null() { - CCCryptorRelease(self.ecb_dec); - } - if !self.gmac.is_null() { - CCCryptorRelease(self.gmac); - } - } - } -} - -impl AesGmacSiv { - /// Create a new keyed instance of AES-GMAC-SIV - /// The key may be of size 16, 24, or 32 bytes (128, 192, or 256 bits). Any other size will panic. - /// Two keys are required: one for GMAC and one for AES-CTR. - pub fn new(k0: &[u8], k1: &[u8]) -> Self { - if k0.len() != 32 && k0.len() != 24 && k0.len() != 16 { - panic!("AES supports 128, 192, or 256 bits keys"); - } - if k1.len() != k0.len() { - panic!("k0 and k1 must be of the same size"); - } - let mut c: AesGmacSiv = AesGmacSiv { - tag: [0_u8; 16], - tmp: [0_u8; 16], - ctr: null_mut(), - ecb_enc: null_mut(), - ecb_dec: null_mut(), - gmac: null_mut(), - }; - unsafe { - let result = CCCryptorCreateWithMode( - kCCEncrypt, - kCCModeCTR, - kCCAlgorithmAES, - 0, - crate::ZEROES.as_ptr().cast(), - k1.as_ptr().cast(), - k1.len(), - null(), - 0, - 0, - 0, - &mut c.ctr, - ); - if result != 0 { - panic!("CCCryptorCreateWithMode for CTR mode returned {}", result); - } - let result = CCCryptorCreateWithMode( - kCCEncrypt, - kCCModeECB, - kCCAlgorithmAES, - 0, - crate::ZEROES.as_ptr().cast(), - k1.as_ptr().cast(), - k1.len(), - null(), - 0, - 0, - kCCOptionECBMode, - &mut c.ecb_enc, - ); - if result != 0 { - panic!("CCCryptorCreateWithMode for ECB encrypt mode returned {}", result); - } - let result = CCCryptorCreateWithMode( - kCCDecrypt, - kCCModeECB, - kCCAlgorithmAES, - 0, - crate::ZEROES.as_ptr().cast(), - k1.as_ptr().cast(), - k1.len(), - null(), - 0, - 0, - kCCOptionECBMode, - &mut c.ecb_dec, - ); - if result != 0 { - panic!("CCCryptorCreateWithMode for ECB decrypt mode returned {}", result); - } - let result = CCCryptorCreateWithMode( - kCCEncrypt, - kCCModeGCM, - kCCAlgorithmAES, - 0, - crate::ZEROES.as_ptr().cast(), - k0.as_ptr().cast(), - k0.len(), - null(), - 0, - 0, - 0, - &mut c.gmac, - ); - if result != 0 { - panic!("CCCryptorCreateWithMode for GCM (GMAC) mode returned {}", result); - } - } - c - } - - /// Reset to prepare for another encrypt or decrypt operation. - #[inline(always)] - pub fn reset(&mut self) { - unsafe { - CCCryptorGCMReset(self.gmac); - } - } - - /// Initialize for encryption. - #[inline(always)] - pub fn encrypt_init(&mut self, iv: &[u8]) { - self.tag[0..8].copy_from_slice(iv); - self.tag[8..12].fill(0); - unsafe { - CCCryptorGCMSetIV(self.gmac, self.tag.as_ptr().cast(), 12); - } - } - - /// Set additional authenticated data (data to be authenticated but not encrypted). - /// This can currently only be called once. Multiple calls will result in corrupt data. - #[inline(always)] - pub fn encrypt_set_aad(&mut self, data: &[u8]) { - unsafe { - CCCryptorGCMAddAAD(self.gmac, data.as_ptr().cast(), data.len()); - } - let pad = data.len() & 0xf; - if pad != 0 { - unsafe { - CCCryptorGCMAddAAD(self.gmac, crate::ZEROES.as_ptr().cast(), 16 - pad); - } - } - } - - /// Feed plaintext in for the first encryption pass. - /// This may be called more than once. - #[inline(always)] - pub fn encrypt_first_pass(&mut self, plaintext: &[u8]) { - unsafe { - CCCryptorGCMAddAAD(self.gmac, plaintext.as_ptr().cast(), plaintext.len()); - } - } - - /// Finish first pass and begin second pass. - #[inline(always)] - pub fn encrypt_first_pass_finish(&mut self) { - unsafe { - CCCryptorGCMFinalize(self.gmac, self.tmp.as_mut_ptr().cast(), 16); - let tmp = self.tmp.as_mut_ptr().cast::(); - *self.tag.as_mut_ptr().cast::().offset(1) = *tmp ^ *tmp.offset(1); - let mut data_out_written: usize = 0; - CCCryptorUpdate( - self.ecb_enc, - self.tag.as_ptr().cast(), - 16, - self.tag.as_mut_ptr().cast(), - 16, - &mut data_out_written, - ); - } - self.tmp.copy_from_slice(&self.tag); - self.tmp[12] &= 0x7f; - unsafe { - if CCCryptorReset(self.ctr, self.tmp.as_ptr().cast()) != 0 { - panic!("CCCryptorReset for CTR mode failed (old MacOS bug)"); - } - } - } - - /// Feed plaintext for second pass and write ciphertext to supplied buffer. - /// This may be called more than once. - #[inline(always)] - pub fn encrypt_second_pass(&mut self, plaintext: &[u8], ciphertext: &mut [u8]) { - unsafe { - assert!(ciphertext.len() >= plaintext.len()); - let mut data_out_written: usize = 0; - CCCryptorUpdate( - self.ctr, - plaintext.as_ptr().cast(), - plaintext.len(), - ciphertext.as_mut_ptr().cast(), - ciphertext.len(), - &mut data_out_written, - ); - } - } - - /// Encrypt plaintext in place. - /// This may be called more than once. - #[inline(always)] - pub fn encrypt_second_pass_in_place(&mut self, plaintext_to_ciphertext: &mut [u8]) { - unsafe { - let mut data_out_written: usize = 0; - CCCryptorUpdate( - self.ctr, - plaintext_to_ciphertext.as_ptr().cast(), - plaintext_to_ciphertext.len(), - plaintext_to_ciphertext.as_mut_ptr().cast(), - plaintext_to_ciphertext.len(), - &mut data_out_written, - ); - } - } - - /// Finish second pass and return a reference to the tag for this message. - /// The tag returned remains valid until reset() is called. - #[inline(always)] - pub fn encrypt_second_pass_finish(&mut self) -> &[u8; 16] { - return &self.tag; - } - - #[inline(always)] - fn decrypt_init_internal(&mut self) { - self.tmp[12] &= 0x7f; - unsafe { - if CCCryptorReset(self.ctr, self.tmp.as_ptr().cast()) != 0 { - panic!("CCCryptorReset for CTR mode failed (old MacOS bug)"); - } - let mut data_out_written = 0; - CCCryptorUpdate( - self.ecb_dec, - self.tag.as_ptr().cast(), - 16, - self.tag.as_mut_ptr().cast(), - 16, - &mut data_out_written, - ); - let tmp = self.tmp.as_mut_ptr().cast::(); - *tmp = *self.tag.as_mut_ptr().cast::(); - *tmp.add(1) = 0; - CCCryptorGCMSetIV(self.gmac, self.tmp.as_ptr().cast(), 12); - } - } - - /// Initialize this cipher for decryption. - /// The supplied tag must be 16 bytes in length. Any other length will panic. - #[inline(always)] - pub fn decrypt_init(&mut self, tag: &[u8]) { - self.tmp.copy_from_slice(tag); - self.tag.copy_from_slice(tag); - self.decrypt_init_internal(); - } - - /// Set additional authenticated data to be checked. - #[inline(always)] - pub fn decrypt_set_aad(&mut self, data: &[u8]) { - self.encrypt_set_aad(data); - } - - /// Decrypt ciphertext and write to plaintext. - /// This may be called more than once. - #[inline(always)] - pub fn decrypt(&mut self, ciphertext: &[u8], plaintext: &mut [u8]) { - unsafe { - let mut data_out_written = 0; - CCCryptorUpdate( - self.ctr, - ciphertext.as_ptr().cast(), - ciphertext.len(), - plaintext.as_mut_ptr().cast(), - plaintext.len(), - &mut data_out_written, - ); - CCCryptorGCMAddAAD(self.gmac, plaintext.as_ptr().cast(), plaintext.len()); - } - } - - /// Decrypt ciphertext in place. - /// This may be called more than once. - #[inline(always)] - pub fn decrypt_in_place(&mut self, ciphertext_to_plaintext: &mut [u8]) { - unsafe { - let mut data_out_written = 0; - CCCryptorUpdate( - self.ctr, - ciphertext_to_plaintext.as_ptr().cast(), - ciphertext_to_plaintext.len(), - ciphertext_to_plaintext.as_mut_ptr().cast(), - ciphertext_to_plaintext.len(), - &mut data_out_written, - ); - CCCryptorGCMAddAAD( - self.gmac, - ciphertext_to_plaintext.as_ptr().cast(), - ciphertext_to_plaintext.len(), - ); - } - } - - /// Finish decryption and returns the decrypted tag if the message appears valid. - #[inline(always)] - pub fn decrypt_finish(&mut self) -> Option<&[u8; 16]> { - unsafe { - CCCryptorGCMFinalize(self.gmac, self.tmp.as_mut_ptr().cast(), 16); - let tmp = self.tmp.as_mut_ptr().cast::(); - if *self.tag.as_mut_ptr().cast::().offset(1) == *tmp ^ *tmp.offset(1) { - Some(&self.tag) - } else { - None - } - } - } -} - -unsafe impl Send for AesGmacSiv {} diff --git a/crypto-glue/src/aes_openssl.rs b/crypto-glue/src/aes_openssl.rs deleted file mode 100644 index 8efd864..0000000 --- a/crypto-glue/src/aes_openssl.rs +++ /dev/null @@ -1,183 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * (c) ZeroTier, Inc. - * https://www.zerotier.com/ - */ - -use std::{ptr, sync::Mutex}; - -use zssp::crypto::{aes, aes_gcm}; - -use crate::cipher_ctx::CipherCtx; - -/// An OpenSSL AES_GCM context. Automatically frees itself on drop. -/// The current interface is custom made for ZeroTier, but could easily be adapted for other uses. -/// Whether `ENCRYPT` is true or false decides respectively whether this context encrypts or decrypts. -/// Even though OpenSSL lets you set this dynamically almost no operations work when you do this -/// without resetting the context. -/// -/// This object cannot be mutated by multiple threads at the same time so wrap it in a Mutex if -/// you need to do this. As far as I have read a Mutex can safely implement Send and Sync. -pub struct AesGcm(CipherCtx); - -impl AesGcm { - /// Create an AesGcm context with the given key. - /// OpenSSL internally processes and caches this key, so it is recommended to reuse this context whenever encrypting under the same key. Call `reset_init_gcm` to change the IV for each reuse. - fn new(key: &[u8; aes_gcm::AES_GCM_KEY_SIZE]) -> Self { - let ctx = CipherCtx::new().unwrap(); - unsafe { - let t = ffi::EVP_aes_256_gcm(); - ctx.cipher_init::(t, key.as_ptr(), ptr::null()).unwrap(); - ffi::EVP_CIPHER_CTX_set_padding(ctx.as_ptr(), 0); - } - - AesGcm(ctx) - } - - /// Set the IV of this AesGcm context. This call resets the IV but leaves the key and encryption algorithm alone. - /// This method must be called before any other method on AesGcm. - /// `iv` must be exactly 12 bytes in length, because that is what Aes supports. - fn reset_init_gcm(&mut self, iv: &[u8]) { - unsafe { - self.0 - .cipher_init::(ptr::null(), ptr::null(), iv.as_ptr()) - .unwrap(); - } - } - - /// Add additional authentication data to AesGcm (same operation with CTR mode). - #[inline(always)] - fn aad(&mut self, aad: &[u8]) { - unsafe { self.0.update::(aad, ptr::null_mut()).unwrap() }; - } - - /// Encrypt or decrypt (same operation with CTR mode) - #[inline(always)] - fn crypt(&mut self, input: &[u8], output: &mut [u8]) { - unsafe { self.0.update::(input, output.as_mut_ptr()).unwrap() }; - } - - /// Encrypt or decrypt in place (same operation with CTR mode). - #[inline(always)] - fn crypt_in_place(&mut self, data: &mut [u8]) { - let ptr = data.as_mut_ptr(); - unsafe { self.0.update::(data, ptr).unwrap() } - } -} -impl AesGcm { - /// Produce the gcm authentication tag. - #[inline(always)] - fn finish_encrypt(&mut self, output: &mut [u8; aes_gcm::AES_GCM_TAG_SIZE]) { - unsafe { - self.0.finalize::().unwrap(); - self.0.tag(output).unwrap(); - } - } -} -impl AesGcm { - /// Check the gcm authentication tag. Outputs true if it matches the just decrypted message, outputs false otherwise. - #[inline(always)] - fn finish_decrypt(&mut self, expected_tag: &[u8; aes_gcm::AES_GCM_TAG_SIZE]) -> bool { - unsafe { self.0.set_tag(expected_tag).is_ok() && self.0.finalize::().is_ok() } - } -} - -impl aes_gcm::AesGcmEnc for AesGcm { - fn new(key: &[u8; aes_gcm::AES_GCM_KEY_SIZE]) -> Self { - Self::new(key) - } - fn set_iv(&mut self, iv: &[u8; aes_gcm::AES_GCM_IV_SIZE]) { - self.reset_init_gcm(iv) - } - fn set_aad(&mut self, aad: &[u8]) { - self.aad(aad) - } - fn encrypt(&mut self, input: &[u8], output: &mut [u8]) { - self.crypt(input, output) - } - fn encrypt_in_place(&mut self, data: &mut [u8]) { - self.crypt_in_place(data) - } - fn finish_encrypt(&mut self, output: &mut [u8; aes_gcm::AES_GCM_TAG_SIZE]) { - self.finish_encrypt(output) - } -} -impl aes_gcm::AesGcmDec for AesGcm { - fn new(key: &[u8; aes_gcm::AES_GCM_KEY_SIZE]) -> Self { - Self::new(key) - } - fn set_iv(&mut self, iv: &[u8; aes_gcm::AES_GCM_IV_SIZE]) { - self.reset_init_gcm(iv) - } - fn set_aad(&mut self, aad: &[u8]) { - self.aad(aad) - } - fn decrypt(&mut self, input: &[u8], output: &mut [u8]) { - self.crypt(input, output) - } - fn decrypt_in_place(&mut self, data: &mut [u8]) { - self.crypt_in_place(data) - } - fn finish_decrypt(&mut self, expected_tag: &[u8; aes_gcm::AES_GCM_TAG_SIZE]) -> bool { - self.finish_decrypt(expected_tag) - } -} - -/// An OpenSSL AES_ECB context. Automatically frees itself on drop. -/// AES_ECB is very insecure if used incorrectly so its public interface supports only exactly what -/// ZeroTier uses it for. -pub struct Aes(Mutex); -unsafe impl Send for Aes {} -unsafe impl Sync for Aes {} - -impl Aes { - fn new(key: &[u8; aes::AES_256_KEY_SIZE]) -> Self { - let ctx = CipherCtx::new().unwrap(); - unsafe { - let t = ffi::EVP_aes_256_ecb(); - ctx.cipher_init::(t, key.as_ptr(), ptr::null()).unwrap(); - ffi::EVP_CIPHER_CTX_set_padding(ctx.as_ptr(), 0); - } - - Aes(Mutex::new(ctx)) - } - - fn reset(&self, key: &[u8; aes::AES_256_KEY_SIZE]) { - let ctx = self.0.lock().unwrap(); - unsafe { - ctx.cipher_init::(ptr::null(), key.as_ptr(), ptr::null()) - .unwrap(); - } - } -} - -impl aes::AesEnc for Aes { - fn new(key: &[u8; aes::AES_256_KEY_SIZE]) -> Self { - Self::new(key) - } - fn reset(&self, key: &[u8; aes::AES_256_KEY_SIZE]) { - self.reset(key) - } - - fn encrypt_in_place(&self, block: &mut [u8; aes::AES_256_BLOCK_SIZE]) { - let ptr = block.as_mut_ptr(); - let ctx = self.0.lock().unwrap(); - unsafe { ctx.update::(block, ptr).unwrap() } - } -} -impl aes::AesDec for Aes { - fn new(key: &[u8; aes::AES_256_KEY_SIZE]) -> Self { - Self::new(key) - } - fn reset(&self, key: &[u8; aes::AES_256_KEY_SIZE]) { - self.reset(key) - } - - fn decrypt_in_place(&self, block: &mut [u8; aes::AES_256_BLOCK_SIZE]) { - let ptr = block.as_mut_ptr(); - let ctx = self.0.lock().unwrap(); - unsafe { ctx.update::(block, ptr).unwrap() } - } -} diff --git a/crypto-glue/src/cipher_ctx.rs b/crypto-glue/src/cipher_ctx.rs deleted file mode 100644 index 3f6586f..0000000 --- a/crypto-glue/src/cipher_ctx.rs +++ /dev/null @@ -1,210 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * (c) ZeroTier, Inc. - * https://www.zerotier.com/ - */ - -use std::ptr::{self, NonNull}; - -use crate::error::{cvt, cvt_p, ErrorStack}; -use libc::{c_int, c_void}; - -extern "C" { - fn EVP_CIPHER_CTX_free(ctx: *mut ffi::EVP_CIPHER_CTX); - fn EVP_CIPHER_CTX_new() -> *mut ffi::EVP_CIPHER_CTX; - - fn EVP_EncryptInit_ex( - ctx: *mut ffi::EVP_CIPHER_CTX, - cipher: *const ffi::EVP_CIPHER, - engine: *mut c_void, - key: *const u8, - iv: *const u8, - ) -> c_int; - fn EVP_DecryptInit_ex( - ctx: *mut ffi::EVP_CIPHER_CTX, - cipher: *const ffi::EVP_CIPHER, - engine: *mut c_void, - key: *const u8, - iv: *const u8, - ) -> c_int; - fn EVP_EncryptUpdate( - ctx: *mut ffi::EVP_CIPHER_CTX, - out: *mut u8, - outl: *mut c_int, - in_: *const u8, - inl: c_int, - ) -> c_int; - fn EVP_DecryptUpdate( - ctx: *mut ffi::EVP_CIPHER_CTX, - out: *mut u8, - outl: *mut c_int, - in_: *const u8, - inl: c_int, - ) -> c_int; - fn EVP_EncryptFinal_ex(ctx: *mut ffi::EVP_CIPHER_CTX, out: *mut u8, outl: *mut c_int) -> c_int; - fn EVP_DecryptFinal_ex(ctx: *mut ffi::EVP_CIPHER_CTX, out: *mut u8, outl: *mut c_int) -> c_int; - fn EVP_CIPHER_CTX_ctrl(ctx: *mut ffi::EVP_CIPHER_CTX, type_: c_int, arg: c_int, ptr: *mut c_void) -> c_int; - -} - -pub struct CipherCtx(NonNull); -impl Drop for CipherCtx { - fn drop(&mut self) { - unsafe { - EVP_CIPHER_CTX_free(self.0.as_ptr()); - } - } -} - -impl CipherCtx { - /// Creates a new context. - pub fn new() -> Result { - unsafe { - let ptr = cvt_p(EVP_CIPHER_CTX_new())?; - Ok(CipherCtx(NonNull::new_unchecked(ptr))) - } - } -} -impl CipherCtx { - /// Initializes the context for encryption or decryption. - /// All pointer fields can be null, in which case the corresponding field in the context is not updated. - pub unsafe fn cipher_init( - &self, - t: *const ffi::EVP_CIPHER, - key: *const u8, - iv: *const u8, - ) -> Result<(), ErrorStack> { - let evp_f = if ENCRYPT { - EVP_EncryptInit_ex - } else { - EVP_DecryptInit_ex - }; - - // OpenSSL will usually leak a static amount of memory per cipher given here. - cvt(evp_f(self.0.as_ptr(), t, ptr::null_mut(), key, iv))?; - Ok(()) - } - - /// Writes data into the context. - /// - /// Providing no output buffer will cause the input to be considered additional authenticated data (AAD). - /// - /// Returns the number of bytes written to `output`. - /// - /// This function is the same as [`Self::cipher_update`] but with the - /// output size check removed. It can be used when the exact - /// buffer size control is maintained by the caller. - /// - /// SAFETY: The caller is expected to provide `output` buffer - /// large enough to contain correct number of bytes. For streaming - /// ciphers the output buffer size should be at least as big as - /// the input buffer. For block ciphers the size of the output - /// buffer depends on the state of partially updated blocks. - pub unsafe fn update(&self, input: &[u8], output: *mut u8) -> Result<(), ErrorStack> { - let evp_f = if ENCRYPT { - EVP_EncryptUpdate - } else { - EVP_DecryptUpdate - }; - - let mut outlen = 0; - - cvt(evp_f( - self.0.as_ptr(), - output, - &mut outlen, - input.as_ptr(), - input.len() as c_int, - ))?; - - Ok(()) - } - - /// Finalizes the encryption or decryption process. - /// - /// Any remaining data will be written to the output buffer. - /// - /// Returns the number of bytes written to `output`. - /// - /// This function is the same as [`Self::cipher_final`] but with - /// the output buffer size check removed. - pub unsafe fn finalize(&self) -> Result<(), ErrorStack> { - let evp_f = if ENCRYPT { - EVP_EncryptFinal_ex - } else { - EVP_DecryptFinal_ex - }; - let mut outl = 0; - - cvt(evp_f(self.0.as_ptr(), ptr::null_mut(), &mut outl))?; - - Ok(()) - } - - /// Retrieves the calculated authentication tag from the context. - /// - /// This should be called after [`Self::cipher_final`], and is only supported by authenticated ciphers. - /// - /// The size of the buffer indicates the size of the tag. While some ciphers support a range of tag sizes, it is - /// recommended to pick the maximum size. - pub fn tag(&self, tag: &mut [u8]) -> Result<(), ErrorStack> { - unsafe { - cvt(EVP_CIPHER_CTX_ctrl( - self.0.as_ptr(), - ffi::EVP_CTRL_GCM_GET_TAG, - tag.len() as c_int, - tag.as_mut_ptr() as *mut _, - ))?; - } - - Ok(()) - } - - /// Sets the authentication tag for verification during decryption. - #[allow(unused)] - pub fn set_tag(&self, tag: &[u8]) -> Result<(), ErrorStack> { - unsafe { - cvt(EVP_CIPHER_CTX_ctrl( - self.0.as_ptr(), - ffi::EVP_CTRL_GCM_SET_TAG, - tag.len() as c_int, - tag.as_ptr() as *mut _, - ))?; - } - - Ok(()) - } - pub fn as_ptr(&self) -> *mut ffi::EVP_CIPHER_CTX { - self.0.as_ptr() - } -} - -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn aes_128_ecb() { - let key = [1u8; 16]; - let ctx = CipherCtx::new().unwrap(); - unsafe { - ctx.cipher_init::(ffi::EVP_aes_128_ecb(), key.as_ptr(), ptr::null()) - .unwrap(); - ffi::EVP_CIPHER_CTX_set_padding(ctx.as_ptr(), 0); - assert_eq!(ffi::EVP_CIPHER_CTX_get_block_size(ctx.as_ptr()) as usize, 16); - - let origin = [2u8; 16]; - let mut val = origin; - let p = val.as_mut_ptr(); - - ctx.update::(&val, p).unwrap(); - ctx.cipher_init::(ptr::null(), key.as_ptr(), ptr::null()) - .unwrap(); - ctx.update::(&val, p).unwrap(); - - assert_eq!(val, origin); - } - } -} diff --git a/crypto-glue/src/error.rs b/crypto-glue/src/error.rs deleted file mode 100644 index e97b09a..0000000 --- a/crypto-glue/src/error.rs +++ /dev/null @@ -1,364 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * (c) ZeroTier, Inc. - * https://www.zerotier.com/ - */ - -use cfg_if::cfg_if; -use libc::{c_char, c_int}; -use std::borrow::Cow; -use std::error; -use std::ffi::CStr; -use std::fmt; -use std::io; -use std::ptr; -use std::str; - -type ErrType = libc::c_ulong; - -/// Collection of [`Error`]s from OpenSSL. -/// -/// [`Error`]: struct.Error.html -#[derive(Debug, Clone)] -pub struct ErrorStack(Vec); - -impl ErrorStack { - /// Returns the contents of the OpenSSL error stack. - #[cold] - #[inline(never)] - pub fn get() -> ErrorStack { - let mut vec = vec![]; - while let Some(err) = Error::get() { - vec.push(err); - } - ErrorStack(vec) - } - - /// Pushes the errors back onto the OpenSSL error stack. - pub fn put(&self) { - for error in self.errors() { - error.put(); - } - } -} - -impl ErrorStack { - /// Returns the errors in the stack. - pub fn errors(&self) -> &[Error] { - &self.0 - } -} - -impl fmt::Display for ErrorStack { - fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - if self.0.is_empty() { - return fmt.write_str("OpenSSL error"); - } - - let mut first = true; - for err in &self.0 { - if !first { - fmt.write_str(", ")?; - } - write!(fmt, "{}", err)?; - first = false; - } - Ok(()) - } -} - -impl error::Error for ErrorStack {} - -impl From for io::Error { - fn from(e: ErrorStack) -> io::Error { - io::Error::new(io::ErrorKind::Other, e) - } -} - -impl From for fmt::Error { - fn from(_: ErrorStack) -> fmt::Error { - fmt::Error - } -} - -/// An error reported from OpenSSL. -#[derive(Clone)] -pub struct Error { - code: ErrType, - file: ShimStr, - line: c_int, - func: Option, - data: Option>, -} - -unsafe impl Sync for Error {} -unsafe impl Send for Error {} - -impl Error { - /// Returns the first error on the OpenSSL error stack. - pub fn get() -> Option { - unsafe { - let mut file = ptr::null(); - let mut line = 0; - let mut func = ptr::null(); - let mut data = ptr::null(); - let mut flags = 0; - match ERR_get_error_all(&mut file, &mut line, &mut func, &mut data, &mut flags) { - 0 => None, - code => { - // The memory referenced by data is only valid until that slot is overwritten - // in the error stack, so we'll need to copy it off if it's dynamic - let data = if flags & ffi::ERR_TXT_STRING != 0 { - let bytes = CStr::from_ptr(data as *const _).to_bytes(); - let data = str::from_utf8(bytes).unwrap(); - #[cfg(not(boringssl))] - let data = if flags & ffi::ERR_TXT_MALLOCED != 0 { - Cow::Owned(data.to_string()) - } else { - Cow::Borrowed(data) - }; - #[cfg(boringssl)] - let data = Cow::Borrowed(data); - Some(data) - } else { - None - }; - - let file = ShimStr::new(file); - - let func = if func.is_null() { - None - } else { - Some(ShimStr::new(func)) - }; - - Some(Error { code, file, line, func, data }) - } - } - } - } - - /// Pushes the error back onto the OpenSSL error stack. - pub fn put(&self) { - self.put_error(); - - unsafe { - let data = match self.data { - Some(Cow::Borrowed(data)) => Some((data.as_ptr() as *mut c_char, 0)), - Some(Cow::Owned(ref data)) => { - let ptr = ffi::CRYPTO_malloc( - (data.len() + 1) as _, - concat!(file!(), "\0").as_ptr() as _, - line!() as _, - ) as *mut c_char; - if ptr.is_null() { - None - } else { - ptr::copy_nonoverlapping(data.as_ptr(), ptr as *mut u8, data.len()); - *ptr.add(data.len()) = 0; - Some((ptr, ffi::ERR_TXT_MALLOCED)) - } - } - None => None, - }; - if let Some((ptr, flags)) = data { - ffi::ERR_set_error_data(ptr, flags | ffi::ERR_TXT_STRING); - } - } - } - - #[cfg(ossl300)] - fn put_error(&self) { - unsafe { - ffi::ERR_new(); - ffi::ERR_set_debug( - self.file.as_ptr(), - self.line, - self.func.as_ref().map_or(ptr::null(), |s| s.as_ptr()), - ); - ffi::ERR_set_error(ffi::ERR_GET_LIB(self.code), ffi::ERR_GET_REASON(self.code), ptr::null()); - } - } - - /// Returns the raw OpenSSL error code for this error. - pub fn code(&self) -> ErrType { - self.code - } - - /// Returns the name of the library reporting the error, if available. - pub fn library(&self) -> Option<&'static str> { - unsafe { - let cstr = ffi::ERR_lib_error_string(self.code); - if cstr.is_null() { - return None; - } - let bytes = CStr::from_ptr(cstr as *const _).to_bytes(); - Some(str::from_utf8(bytes).unwrap()) - } - } - - /// Returns the name of the function reporting the error. - pub fn function(&self) -> Option> { - self.func.as_ref().map(|s| s.as_str()) - } - - /// Returns the reason for the error. - pub fn reason(&self) -> Option<&'static str> { - unsafe { - let cstr = ffi::ERR_reason_error_string(self.code); - if cstr.is_null() { - return None; - } - let bytes = CStr::from_ptr(cstr as *const _).to_bytes(); - Some(str::from_utf8(bytes).unwrap()) - } - } - - /// Returns the name of the source file which encountered the error. - pub fn file(&self) -> RetStr<'_> { - self.file.as_str() - } - - /// Returns the line in the source file which encountered the error. - pub fn line(&self) -> u32 { - self.line as u32 - } - - /// Returns additional data describing the error. - #[allow(clippy::option_as_ref_deref)] - pub fn data(&self) -> Option<&str> { - self.data.as_ref().map(|s| &**s) - } -} - -impl fmt::Debug for Error { - fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - let mut builder = fmt.debug_struct("Error"); - builder.field("code", &self.code()); - if let Some(library) = self.library() { - builder.field("library", &library); - } - if let Some(function) = self.function() { - builder.field("function", &function); - } - if let Some(reason) = self.reason() { - builder.field("reason", &reason); - } - builder.field("file", &self.file()); - builder.field("line", &self.line()); - if let Some(data) = self.data() { - builder.field("data", &data); - } - builder.finish() - } -} - -impl fmt::Display for Error { - fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(fmt, "error:{:08X}", self.code())?; - match self.library() { - Some(l) => write!(fmt, ":{}", l)?, - None => write!(fmt, ":lib({})", ffi::ERR_GET_LIB(self.code()))?, - } - match self.function() { - Some(f) => write!(fmt, ":{}", f)?, - None => write!(fmt, ":func({})", ffi::ERR_GET_FUNC(self.code()))?, - } - match self.reason() { - Some(r) => write!(fmt, ":{}", r)?, - None => write!(fmt, ":reason({})", ffi::ERR_GET_REASON(self.code()))?, - } - write!(fmt, ":{}:{}:{}", self.file(), self.line(), self.data().unwrap_or("")) - } -} - -impl error::Error for Error {} - -cfg_if! { - if #[cfg(ossl300)] { - use std::ffi::{CString}; - use ffi::ERR_get_error_all; - - type RetStr<'a> = &'a str; - - #[derive(Clone)] - struct ShimStr(CString); - - impl ShimStr { - unsafe fn new(s: *const c_char) -> Self { - ShimStr(CStr::from_ptr(s).to_owned()) - } - - fn as_ptr(&self) -> *const c_char { - self.0.as_ptr() - } - - fn as_str(&self) -> &str { - self.0.to_str().unwrap() - } - } - } else { - #[allow(bad_style)] - unsafe extern "C" fn ERR_get_error_all( - file: *mut *const c_char, - line: *mut c_int, - func: *mut *const c_char, - data: *mut *const c_char, - flags: *mut c_int, - ) -> ErrType { - let code = ffi::ERR_get_error_line_data(file, line, data, flags); - *func = ffi::ERR_func_error_string(code); - code - } - - type RetStr<'a> = &'static str; - - #[derive(Clone)] - struct ShimStr(*const c_char); - - impl ShimStr { - unsafe fn new(s: *const c_char) -> Self { - ShimStr(s) - } - - fn as_ptr(&self) -> *const c_char { - self.0 - } - - fn as_str(&self) -> &'static str { - unsafe { - CStr::from_ptr(self.0).to_str().unwrap() - } - } - } - } -} - -#[inline] -pub fn cvt_p(r: *mut T) -> Result<*mut T, ErrorStack> { - if r.is_null() { - Err(ErrorStack::get()) - } else { - Ok(r) - } -} - -#[inline] -pub fn cvt(r: c_int) -> Result { - if r <= 0 { - Err(ErrorStack::get()) - } else { - Ok(r) - } -} - -#[inline] -pub fn cvt_n(r: c_int) -> Result { - if r < 0 { - Err(ErrorStack::get()) - } else { - Ok(r) - } -} diff --git a/crypto-glue/src/p384_builtin.rs b/crypto-glue/src/p384_builtin.rs deleted file mode 100644 index 0c40773..0000000 --- a/crypto-glue/src/p384_builtin.rs +++ /dev/null @@ -1,1257 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * (c) ZeroTier, Inc. - * https://www.zerotier.com/ - */ - -// This is small and relatively fast but may not be constant time and hasn't been well audited, so we don't -// use it by default. It's left here though in case it proves useful in the future on embedded systems. -#[cfg(target_feature = "builtin_nist_ecc")] -mod builtin { - use crate::hash::SHA384; - use crate::secret::Secret; - - // EASY-ECC by Kenneth MacKay - // https://github.com/esxgx/easy-ecc (no longer there, but search GitHub for forks) - // - // Translated directly from C to Rust using https://c2rust.com and then hacked a bit - // to eliminate some dependencies. The translated code still has a lot of gratuitous - // "as"es but they're not consequential. - // - // It inherits its original BSD 2-Clause license, not ZeroTier's license. - - pub mod libc { - pub type c_uchar = u8; - pub type c_ulong = u64; - pub type c_long = i64; - pub type c_uint = u32; - pub type c_int = i32; - pub type c_ulonglong = u64; - pub type c_longlong = i64; - } - - pub type uint8_t = libc::c_uchar; - pub type uint64_t = libc::c_ulong; - pub type uint = libc::c_uint; - pub type uint128_t = u128; - pub struct EccPoint { - pub x: [u64; 6], - pub y: [u64; 6], - } - static mut curve_p: [uint64_t; 6] = [ - 0xffffffff as libc::c_uint as uint64_t, - 0xffffffff00000000 as libc::c_ulong, - 0xfffffffffffffffe as libc::c_ulong, - 0xffffffffffffffff as libc::c_ulong, - 0xffffffffffffffff as libc::c_ulong, - 0xffffffffffffffff as libc::c_ulong, - ]; - static mut curve_b: [uint64_t; 6] = [ - 0x2a85c8edd3ec2aef as libc::c_long as uint64_t, - 0xc656398d8a2ed19d as libc::c_ulong, - 0x314088f5013875a as libc::c_long as uint64_t, - 0x181d9c6efe814112 as libc::c_long as uint64_t, - 0x988e056be3f82d19 as libc::c_ulong, - 0xb3312fa7e23ee7e4 as libc::c_ulong, - ]; - static mut curve_G: EccPoint = { - let mut init = EccPoint { - x: [ - 0x3a545e3872760ab7 as libc::c_long as uint64_t, - 0x5502f25dbf55296c as libc::c_long as uint64_t, - 0x59f741e082542a38 as libc::c_long as uint64_t, - 0x6e1d3b628ba79b98 as libc::c_long as uint64_t, - 0x8eb1c71ef320ad74 as libc::c_ulong, - 0xaa87ca22be8b0537 as libc::c_ulong, - ], - y: [ - 0x7a431d7c90ea0e5f as libc::c_long as uint64_t, - 0xa60b1ce1d7e819d as libc::c_long as uint64_t, - 0xe9da3113b5f0b8c0 as libc::c_ulong, - 0xf8f41dbd289a147c as libc::c_ulong, - 0x5d9e98bf9292dc29 as libc::c_long as uint64_t, - 0x3617de4a96262c6f as libc::c_long as uint64_t, - ], - }; - init - }; - static mut curve_n: [uint64_t; 6] = [ - 0xecec196accc52973 as libc::c_ulong, - 0x581a0db248b0a77a as libc::c_long as uint64_t, - 0xc7634d81f4372ddf as libc::c_ulong, - 0xffffffffffffffff as libc::c_ulong, - 0xffffffffffffffff as libc::c_ulong, - 0xffffffffffffffff as libc::c_ulong, - ]; - - unsafe fn getRandomNumber(mut p_vli: *mut uint64_t) -> libc::c_int { - crate::random::fill_bytes_secure(&mut *std::ptr::slice_from_raw_parts_mut(p_vli.cast(), 48)); - return 1 as libc::c_int; - } - - unsafe fn vli_clear(mut p_vli: *mut uint64_t) { - let mut i: uint = 0; - i = 0 as libc::c_int as uint; - while i < (48 as libc::c_int / 8 as libc::c_int) as libc::c_uint { - *p_vli.offset(i as isize) = 0 as libc::c_int as uint64_t; - i = i.wrapping_add(1) - } - } - /* Returns 1 if p_vli == 0, 0 otherwise. */ - - unsafe fn vli_isZero(mut p_vli: *mut uint64_t) -> libc::c_int { - let mut i: uint = 0; - i = 0 as libc::c_int as uint; - while i < (48 as libc::c_int / 8 as libc::c_int) as libc::c_uint { - if *p_vli.offset(i as isize) != 0 { - return 0 as libc::c_int; - } - i = i.wrapping_add(1) - } - return 1 as libc::c_int; - } - /* Returns nonzero if bit p_bit of p_vli is set. */ - - unsafe fn vli_testBit(mut p_vli: *mut uint64_t, mut p_bit: uint) -> uint64_t { - return *p_vli.offset(p_bit.wrapping_div(64 as libc::c_int as libc::c_uint) as isize) - & (1 as libc::c_int as uint64_t) << p_bit.wrapping_rem(64 as libc::c_int as libc::c_uint); - } - /* Counts the number of 64-bit "digits" in p_vli. */ - - unsafe fn vli_numDigits(mut p_vli: *mut uint64_t) -> uint { - let mut i: libc::c_int = 0; - /* Search from the end until we find a non-zero digit. - We do it in reverse because we expect that most digits will be nonzero. */ - i = 48 as libc::c_int / 8 as libc::c_int - 1 as libc::c_int; - while i >= 0 as libc::c_int && *p_vli.offset(i as isize) == 0 as libc::c_int as libc::c_ulong { - i -= 1 - } - return (i + 1 as libc::c_int) as uint; - } - /* Counts the number of bits required for p_vli. */ - - unsafe fn vli_numBits(mut p_vli: *mut uint64_t) -> uint { - let mut i: uint = 0; - let mut l_digit: uint64_t = 0; - let mut l_numDigits: uint = vli_numDigits(p_vli); - if l_numDigits == 0 as libc::c_int as libc::c_uint { - return 0 as libc::c_int as uint; - } - l_digit = *p_vli.offset(l_numDigits.wrapping_sub(1 as libc::c_int as libc::c_uint) as isize); - i = 0 as libc::c_int as uint; - while l_digit != 0 { - l_digit >>= 1 as libc::c_int; - i = i.wrapping_add(1) - } - return l_numDigits - .wrapping_sub(1 as libc::c_int as libc::c_uint) - .wrapping_mul(64 as libc::c_int as libc::c_uint) - .wrapping_add(i); - } - /* Sets p_dest = p_src. */ - - unsafe fn vli_set(mut p_dest: *mut uint64_t, mut p_src: *mut uint64_t) { - let mut i: uint = 0; - i = 0 as libc::c_int as uint; - while i < (48 as libc::c_int / 8 as libc::c_int) as libc::c_uint { - *p_dest.offset(i as isize) = *p_src.offset(i as isize); - i = i.wrapping_add(1) - } - } - /* Returns sign of p_left - p_right. */ - - unsafe fn vli_cmp(mut p_left: *mut uint64_t, mut p_right: *mut uint64_t) -> libc::c_int { - let mut i: libc::c_int = 0; - i = 48 as libc::c_int / 8 as libc::c_int - 1 as libc::c_int; - while i >= 0 as libc::c_int { - if *p_left.offset(i as isize) > *p_right.offset(i as isize) { - return 1 as libc::c_int; - } else { - if *p_left.offset(i as isize) < *p_right.offset(i as isize) { - return -(1 as libc::c_int); - } - } - i -= 1 - } - return 0 as libc::c_int; - } - /* Computes p_result = p_in << c, returning carry. Can modify in place (if p_result == p_in). 0 < p_shift < 64. */ - - unsafe fn vli_lshift(mut p_result: *mut uint64_t, mut p_in: *mut uint64_t, mut p_shift: uint) -> uint64_t { - let mut l_carry: uint64_t = 0 as libc::c_int as uint64_t; - let mut i: uint = 0; - i = 0 as libc::c_int as uint; - while i < (48 as libc::c_int / 8 as libc::c_int) as libc::c_uint { - let mut l_temp: uint64_t = *p_in.offset(i as isize); - *p_result.offset(i as isize) = l_temp << p_shift | l_carry; - l_carry = l_temp >> (64 as libc::c_int as libc::c_uint).wrapping_sub(p_shift); - i = i.wrapping_add(1) - } - return l_carry; - } - /* Computes p_vli = p_vli >> 1. */ - - unsafe fn vli_rshift1(mut p_vli: *mut uint64_t) { - let mut l_end: *mut uint64_t = p_vli; - let mut l_carry: uint64_t = 0 as libc::c_int as uint64_t; - p_vli = p_vli.offset((48 as libc::c_int / 8 as libc::c_int) as isize); - loop { - let fresh0 = p_vli; - p_vli = p_vli.offset(-1); - if !(fresh0 > l_end) { - break; - } - let mut l_temp: uint64_t = *p_vli; - *p_vli = l_temp >> 1 as libc::c_int | l_carry; - l_carry = l_temp << 63 as libc::c_int - } - } - /* Computes p_result = p_left + p_right, returning carry. Can modify in place. */ - - unsafe fn vli_add(mut p_result: *mut uint64_t, mut p_left: *mut uint64_t, mut p_right: *mut uint64_t) -> uint64_t { - let mut l_carry: uint64_t = 0 as libc::c_int as uint64_t; - let mut i: uint = 0; - i = 0 as libc::c_int as uint; - while i < (48 as libc::c_int / 8 as libc::c_int) as libc::c_uint { - let mut l_sum: uint64_t = (*p_left.offset(i as isize)) - .wrapping_add(*p_right.offset(i as isize)) - .wrapping_add(l_carry); - if l_sum != *p_left.offset(i as isize) { - l_carry = (l_sum < *p_left.offset(i as isize)) as libc::c_int as uint64_t - } - *p_result.offset(i as isize) = l_sum; - i = i.wrapping_add(1) - } - return l_carry; - } - /* Computes p_result = p_left - p_right, returning borrow. Can modify in place. */ - - unsafe fn vli_sub(mut p_result: *mut uint64_t, mut p_left: *mut uint64_t, mut p_right: *mut uint64_t) -> uint64_t { - let mut l_borrow: uint64_t = 0 as libc::c_int as uint64_t; - let mut i: uint = 0; - i = 0 as libc::c_int as uint; - while i < (48 as libc::c_int / 8 as libc::c_int) as libc::c_uint { - let mut l_diff: uint64_t = (*p_left.offset(i as isize)) - .wrapping_sub(*p_right.offset(i as isize)) - .wrapping_sub(l_borrow); - if l_diff != *p_left.offset(i as isize) { - l_borrow = (l_diff > *p_left.offset(i as isize)) as libc::c_int as uint64_t - } - *p_result.offset(i as isize) = l_diff; - i = i.wrapping_add(1) - } - return l_borrow; - } - /* Computes p_result = p_left * p_right. */ - - unsafe fn vli_mult(mut p_result: *mut uint64_t, mut p_left: *mut uint64_t, mut p_right: *mut uint64_t) { - let mut r01: uint128_t = 0 as libc::c_int as uint128_t; - let mut r2: uint64_t = 0 as libc::c_int as uint64_t; - let mut i: uint = 0; - let mut k: uint = 0; - /* Compute each digit of p_result in sequence, maintaining the carries. */ - k = 0 as libc::c_int as uint; - while k < (48 as libc::c_int / 8 as libc::c_int * 2 as libc::c_int - 1 as libc::c_int) as libc::c_uint { - let mut l_min: uint = if k < (48 as libc::c_int / 8 as libc::c_int) as libc::c_uint { - 0 as libc::c_int as libc::c_uint - } else { - k.wrapping_add(1 as libc::c_int as libc::c_uint) - .wrapping_sub((48 as libc::c_int / 8 as libc::c_int) as libc::c_uint) - }; - i = l_min; - while i <= k && i < (48 as libc::c_int / 8 as libc::c_int) as libc::c_uint { - let mut l_product: uint128_t = (*p_left.offset(i as isize) as uint128_t) - .wrapping_mul(*p_right.offset(k.wrapping_sub(i) as isize) as u128); - r01 = (r01 as u128).wrapping_add(l_product) as uint128_t as uint128_t; - r2 = (r2 as libc::c_ulong).wrapping_add((r01 < l_product) as libc::c_int as libc::c_ulong) as uint64_t - as uint64_t; - i = i.wrapping_add(1) - } - *p_result.offset(k as isize) = r01 as uint64_t; - r01 = r01 >> 64 as libc::c_int | (r2 as uint128_t) << 64 as libc::c_int; - r2 = 0 as libc::c_int as uint64_t; - k = k.wrapping_add(1) - } - *p_result.offset((48 as libc::c_int / 8 as libc::c_int * 2 as libc::c_int - 1 as libc::c_int) as isize) = - r01 as uint64_t; - } - /* Computes p_result = p_left^2. */ - - unsafe fn vli_square(mut p_result: *mut uint64_t, mut p_left: *mut uint64_t) { - let mut r01: uint128_t = 0 as libc::c_int as uint128_t; - let mut r2: uint64_t = 0 as libc::c_int as uint64_t; - let mut i: uint = 0; - let mut k: uint = 0; - k = 0 as libc::c_int as uint; - while k < (48 as libc::c_int / 8 as libc::c_int * 2 as libc::c_int - 1 as libc::c_int) as libc::c_uint { - let mut l_min: uint = if k < (48 as libc::c_int / 8 as libc::c_int) as libc::c_uint { - 0 as libc::c_int as libc::c_uint - } else { - k.wrapping_add(1 as libc::c_int as libc::c_uint) - .wrapping_sub((48 as libc::c_int / 8 as libc::c_int) as libc::c_uint) - }; - i = l_min; - while i <= k && i <= k.wrapping_sub(i) { - let mut l_product: uint128_t = (*p_left.offset(i as isize) as uint128_t) - .wrapping_mul(*p_left.offset(k.wrapping_sub(i) as isize) as u128); - if i < k.wrapping_sub(i) { - r2 = (r2 as u128).wrapping_add(l_product >> 127 as libc::c_int) as uint64_t as uint64_t; - l_product = (l_product as u128).wrapping_mul(2 as libc::c_int as u128) as uint128_t as uint128_t - } - r01 = (r01 as u128).wrapping_add(l_product) as uint128_t as uint128_t; - r2 = (r2 as libc::c_ulong).wrapping_add((r01 < l_product) as libc::c_int as libc::c_ulong) as uint64_t - as uint64_t; - i = i.wrapping_add(1) - } - *p_result.offset(k as isize) = r01 as uint64_t; - r01 = r01 >> 64 as libc::c_int | (r2 as uint128_t) << 64 as libc::c_int; - r2 = 0 as libc::c_int as uint64_t; - k = k.wrapping_add(1) - } - *p_result.offset((48 as libc::c_int / 8 as libc::c_int * 2 as libc::c_int - 1 as libc::c_int) as isize) = - r01 as uint64_t; - } - /* #if SUPPORTS_INT128 */ - /* SUPPORTS_INT128 */ - /* Computes p_result = (p_left + p_right) % p_mod. - Assumes that p_left < p_mod and p_right < p_mod, p_result != p_mod. */ - - unsafe fn vli_modAdd( - mut p_result: *mut uint64_t, - mut p_left: *mut uint64_t, - mut p_right: *mut uint64_t, - mut p_mod: *mut uint64_t, - ) { - let mut l_carry: uint64_t = vli_add(p_result, p_left, p_right); - if l_carry != 0 || vli_cmp(p_result, p_mod) >= 0 as libc::c_int { - /* p_result > p_mod (p_result = p_mod + remainder), so subtract p_mod to get remainder. */ - vli_sub(p_result, p_result, p_mod); - }; - } - /* Computes p_result = (p_left - p_right) % p_mod. - Assumes that p_left < p_mod and p_right < p_mod, p_result != p_mod. */ - - unsafe fn vli_modSub( - mut p_result: *mut uint64_t, - mut p_left: *mut uint64_t, - mut p_right: *mut uint64_t, - mut p_mod: *mut uint64_t, - ) { - let mut l_borrow: uint64_t = vli_sub(p_result, p_left, p_right); - if l_borrow != 0 { - /* In this case, p_result == -diff == (max int) - diff. - Since -x % d == d - x, we can get the correct result from p_result + p_mod (with overflow). */ - vli_add(p_result, p_result, p_mod); - }; - } - //#elif ECC_CURVE == secp384r1 - - unsafe fn omega_mult(mut p_result: *mut uint64_t, mut p_right: *mut uint64_t) { - let mut l_tmp: [uint64_t; 6] = std::mem::MaybeUninit::uninit().assume_init(); - let mut l_carry: uint64_t = 0; - let mut l_diff: uint64_t = 0; - /* Multiply by (2^128 + 2^96 - 2^32 + 1). */ - vli_set(p_result, p_right); /* 1 */ - l_carry = vli_lshift(l_tmp.as_mut_ptr(), p_right, 32 as libc::c_int as uint); /* 2^96 + 1 */ - *p_result.offset((1 as libc::c_int + 48 as libc::c_int / 8 as libc::c_int) as isize) = - l_carry.wrapping_add(vli_add( - p_result.offset(1 as libc::c_int as isize), - p_result.offset(1 as libc::c_int as isize), - l_tmp.as_mut_ptr(), - )); /* 2^128 + 2^96 + 1 */ - *p_result.offset((2 as libc::c_int + 48 as libc::c_int / 8 as libc::c_int) as isize) = vli_add( - p_result.offset(2 as libc::c_int as isize), - p_result.offset(2 as libc::c_int as isize), - p_right, - ); /* 2^128 + 2^96 - 2^32 + 1 */ - l_carry = (l_carry as libc::c_ulong).wrapping_add(vli_sub(p_result, p_result, l_tmp.as_mut_ptr())) as uint64_t - as uint64_t; - l_diff = (*p_result.offset((48 as libc::c_int / 8 as libc::c_int) as isize)).wrapping_sub(l_carry); - if l_diff > *p_result.offset((48 as libc::c_int / 8 as libc::c_int) as isize) { - /* Propagate borrow if necessary. */ - let mut i: uint = 0; - i = (1 as libc::c_int + 48 as libc::c_int / 8 as libc::c_int) as uint; - loop { - let ref mut fresh1 = *p_result.offset(i as isize); - *fresh1 = (*fresh1).wrapping_sub(1); - if *p_result.offset(i as isize) != -(1 as libc::c_int) as uint64_t { - break; - } - i = i.wrapping_add(1) - } - } - *p_result.offset((48 as libc::c_int / 8 as libc::c_int) as isize) = l_diff; - } - /* Computes p_result = p_product % curve_p - see PDF "Comparing Elliptic Curve Cryptography and RSA on 8-bit CPUs" - section "Curve-Specific Optimizations" */ - - unsafe fn vli_mmod_fast(mut p_result: *mut uint64_t, mut p_product: *mut uint64_t) { - let mut l_tmp: [uint64_t; 12] = std::mem::MaybeUninit::uninit().assume_init(); - while vli_isZero(p_product.offset((48 as libc::c_int / 8 as libc::c_int) as isize)) == 0 { - /* While c1 != 0 */ - let mut l_carry: uint64_t = 0 as libc::c_int as uint64_t; /* tmp = w * c1 */ - let mut i: uint = 0; /* p = c0 */ - vli_clear(l_tmp.as_mut_ptr()); - vli_clear( - l_tmp - .as_mut_ptr() - .offset((48 as libc::c_int / 8 as libc::c_int) as isize), - ); - omega_mult( - l_tmp.as_mut_ptr(), - p_product.offset((48 as libc::c_int / 8 as libc::c_int) as isize), - ); - vli_clear(p_product.offset((48 as libc::c_int / 8 as libc::c_int) as isize)); - /* (c1, c0) = c0 + w * c1 */ - i = 0 as libc::c_int as uint; - while i < (48 as libc::c_int / 8 as libc::c_int + 3 as libc::c_int) as libc::c_uint { - let mut l_sum: uint64_t = (*p_product.offset(i as isize)) - .wrapping_add(l_tmp[i as usize]) - .wrapping_add(l_carry); - if l_sum != *p_product.offset(i as isize) { - l_carry = (l_sum < *p_product.offset(i as isize)) as libc::c_int as uint64_t - } - *p_product.offset(i as isize) = l_sum; - i = i.wrapping_add(1) - } - } - while vli_cmp(p_product, curve_p.as_mut_ptr()) > 0 as libc::c_int { - vli_sub(p_product, p_product, curve_p.as_mut_ptr()); - } - vli_set(p_result, p_product); - } - //#endif - /* Computes p_result = (p_left * p_right) % curve_p. */ - - unsafe fn vli_modMult_fast(mut p_result: *mut uint64_t, mut p_left: *mut uint64_t, mut p_right: *mut uint64_t) { - let mut l_product: [uint64_t; 12] = std::mem::MaybeUninit::uninit().assume_init(); - vli_mult(l_product.as_mut_ptr(), p_left, p_right); - vli_mmod_fast(p_result, l_product.as_mut_ptr()); - } - /* Computes p_result = p_left^2 % curve_p. */ - - unsafe fn vli_modSquare_fast(mut p_result: *mut uint64_t, mut p_left: *mut uint64_t) { - let mut l_product: [uint64_t; 12] = std::mem::MaybeUninit::uninit().assume_init(); - vli_square(l_product.as_mut_ptr(), p_left); - vli_mmod_fast(p_result, l_product.as_mut_ptr()); - } - /* Computes p_result = (1 / p_input) % p_mod. All VLIs are the same size. - See "From Euclid's GCD to Montgomery Multiplication to the Great Divide" - https://labs.oracle.com/techrep/2001/smli_tr-2001-95.pdf */ - - unsafe fn vli_modInv(mut p_result: *mut uint64_t, mut p_input: *mut uint64_t, mut p_mod: *mut uint64_t) { - let mut a: [uint64_t; 6] = std::mem::MaybeUninit::uninit().assume_init(); - let mut b: [uint64_t; 6] = std::mem::MaybeUninit::uninit().assume_init(); - let mut u: [uint64_t; 6] = std::mem::MaybeUninit::uninit().assume_init(); - let mut v: [uint64_t; 6] = std::mem::MaybeUninit::uninit().assume_init(); - let mut l_carry: uint64_t = 0; - let mut l_cmpResult: libc::c_int = 0; - if vli_isZero(p_input) != 0 { - vli_clear(p_result); - return; - } - vli_set(a.as_mut_ptr(), p_input); - vli_set(b.as_mut_ptr(), p_mod); - vli_clear(u.as_mut_ptr()); - u[0 as libc::c_int as usize] = 1 as libc::c_int as uint64_t; - vli_clear(v.as_mut_ptr()); - loop { - l_cmpResult = vli_cmp(a.as_mut_ptr(), b.as_mut_ptr()); - if !(l_cmpResult != 0 as libc::c_int) { - break; - } - l_carry = 0 as libc::c_int as uint64_t; - if a[0 as libc::c_int as usize] & 1 as libc::c_int as libc::c_ulong == 0 { - vli_rshift1(a.as_mut_ptr()); - if u[0 as libc::c_int as usize] & 1 as libc::c_int as libc::c_ulong != 0 { - l_carry = vli_add(u.as_mut_ptr(), u.as_mut_ptr(), p_mod) - } - vli_rshift1(u.as_mut_ptr()); - if l_carry != 0 { - u[(48 as libc::c_int / 8 as libc::c_int - 1 as libc::c_int) as usize] = - (u[(48 as libc::c_int / 8 as libc::c_int - 1 as libc::c_int) as usize] as libc::c_ulonglong - | 0x8000000000000000 as libc::c_ulonglong) as uint64_t - } - } else if b[0 as libc::c_int as usize] & 1 as libc::c_int as libc::c_ulong == 0 { - vli_rshift1(b.as_mut_ptr()); - if v[0 as libc::c_int as usize] & 1 as libc::c_int as libc::c_ulong != 0 { - l_carry = vli_add(v.as_mut_ptr(), v.as_mut_ptr(), p_mod) - } - vli_rshift1(v.as_mut_ptr()); - if l_carry != 0 { - v[(48 as libc::c_int / 8 as libc::c_int - 1 as libc::c_int) as usize] = - (v[(48 as libc::c_int / 8 as libc::c_int - 1 as libc::c_int) as usize] as libc::c_ulonglong - | 0x8000000000000000 as libc::c_ulonglong) as uint64_t - } - } else if l_cmpResult > 0 as libc::c_int { - vli_sub(a.as_mut_ptr(), a.as_mut_ptr(), b.as_mut_ptr()); - vli_rshift1(a.as_mut_ptr()); - if vli_cmp(u.as_mut_ptr(), v.as_mut_ptr()) < 0 as libc::c_int { - vli_add(u.as_mut_ptr(), u.as_mut_ptr(), p_mod); - } - vli_sub(u.as_mut_ptr(), u.as_mut_ptr(), v.as_mut_ptr()); - if u[0 as libc::c_int as usize] & 1 as libc::c_int as libc::c_ulong != 0 { - l_carry = vli_add(u.as_mut_ptr(), u.as_mut_ptr(), p_mod) - } - vli_rshift1(u.as_mut_ptr()); - if l_carry != 0 { - u[(48 as libc::c_int / 8 as libc::c_int - 1 as libc::c_int) as usize] = - (u[(48 as libc::c_int / 8 as libc::c_int - 1 as libc::c_int) as usize] as libc::c_ulonglong - | 0x8000000000000000 as libc::c_ulonglong) as uint64_t - } - } else { - vli_sub(b.as_mut_ptr(), b.as_mut_ptr(), a.as_mut_ptr()); - vli_rshift1(b.as_mut_ptr()); - if vli_cmp(v.as_mut_ptr(), u.as_mut_ptr()) < 0 as libc::c_int { - vli_add(v.as_mut_ptr(), v.as_mut_ptr(), p_mod); - } - vli_sub(v.as_mut_ptr(), v.as_mut_ptr(), u.as_mut_ptr()); - if v[0 as libc::c_int as usize] & 1 as libc::c_int as libc::c_ulong != 0 { - l_carry = vli_add(v.as_mut_ptr(), v.as_mut_ptr(), p_mod) - } - vli_rshift1(v.as_mut_ptr()); - if l_carry != 0 { - v[(48 as libc::c_int / 8 as libc::c_int - 1 as libc::c_int) as usize] = - (v[(48 as libc::c_int / 8 as libc::c_int - 1 as libc::c_int) as usize] as libc::c_ulonglong - | 0x8000000000000000 as libc::c_ulonglong) as uint64_t - } - } - } - vli_set(p_result, u.as_mut_ptr()); - } - /* ------ Point operations ------ */ - /* Returns 1 if p_point is the point at infinity, 0 otherwise. */ - - unsafe fn EccPoint_isZero(mut p_point: *mut EccPoint) -> libc::c_int { - return (vli_isZero((*p_point).x.as_mut_ptr()) != 0 && vli_isZero((*p_point).y.as_mut_ptr()) != 0) - as libc::c_int; - } - /* Point multiplication algorithm using Montgomery's ladder with co-Z coordinates. - From http://eprint.iacr.org/2011/338.pdf - */ - /* Double in place */ - - unsafe fn EccPoint_double_jacobian(mut X1: *mut uint64_t, mut Y1: *mut uint64_t, mut Z1: *mut uint64_t) { - /* t1 = X, t2 = Y, t3 = Z */ - let mut t4: [uint64_t; 6] = std::mem::MaybeUninit::uninit().assume_init(); /* t4 = y1^2 */ - let mut t5: [uint64_t; 6] = std::mem::MaybeUninit::uninit().assume_init(); /* t5 = x1*y1^2 = A */ - if vli_isZero(Z1) != 0 { - return; - } /* t4 = y1^4 */ - vli_modSquare_fast(t4.as_mut_ptr(), Y1); /* t2 = y1*z1 = z3 */ - vli_modMult_fast(t5.as_mut_ptr(), X1, t4.as_mut_ptr()); /* t3 = z1^2 */ - vli_modSquare_fast(t4.as_mut_ptr(), t4.as_mut_ptr()); /* t1 = x1 + z1^2 */ - vli_modMult_fast(Y1, Y1, Z1); /* t3 = 2*z1^2 */ - vli_modSquare_fast(Z1, Z1); /* t3 = x1 - z1^2 */ - vli_modAdd(X1, X1, Z1, curve_p.as_mut_ptr()); /* t1 = x1^2 - z1^4 */ - vli_modAdd(Z1, Z1, Z1, curve_p.as_mut_ptr()); /* t3 = 2*(x1^2 - z1^4) */ - vli_modSub(Z1, X1, Z1, curve_p.as_mut_ptr()); /* t1 = 3*(x1^2 - z1^4) */ - vli_modMult_fast(X1, X1, Z1); - vli_modAdd(Z1, X1, X1, curve_p.as_mut_ptr()); - vli_modAdd(X1, X1, Z1, curve_p.as_mut_ptr()); - if vli_testBit(X1, 0 as libc::c_int as uint) != 0 { - let mut l_carry: uint64_t = vli_add(X1, X1, curve_p.as_mut_ptr()); - vli_rshift1(X1); - let ref mut fresh2 = *X1.offset((48 as libc::c_int / 8 as libc::c_int - 1 as libc::c_int) as isize); - *fresh2 |= l_carry << 63 as libc::c_int - } else { - vli_rshift1(X1); - } - /* t1 = 3/2*(x1^2 - z1^4) = B */ - vli_modSquare_fast(Z1, X1); /* t3 = B^2 */ - vli_modSub(Z1, Z1, t5.as_mut_ptr(), curve_p.as_mut_ptr()); /* t3 = B^2 - A */ - vli_modSub(Z1, Z1, t5.as_mut_ptr(), curve_p.as_mut_ptr()); /* t3 = B^2 - 2A = x3 */ - vli_modSub(t5.as_mut_ptr(), t5.as_mut_ptr(), Z1, curve_p.as_mut_ptr()); /* t5 = A - x3 */ - vli_modMult_fast(X1, X1, t5.as_mut_ptr()); /* t1 = B * (A - x3) */ - vli_modSub(t4.as_mut_ptr(), X1, t4.as_mut_ptr(), curve_p.as_mut_ptr()); /* t4 = B * (A - x3) - y1^4 = y3 */ - vli_set(X1, Z1); - vli_set(Z1, Y1); - vli_set(Y1, t4.as_mut_ptr()); - } - /* Modify (x1, y1) => (x1 * z^2, y1 * z^3) */ - - unsafe fn apply_z(mut X1: *mut uint64_t, mut Y1: *mut uint64_t, mut Z: *mut uint64_t) { - let mut t1: [uint64_t; 6] = std::mem::MaybeUninit::uninit().assume_init(); /* z^2 */ - vli_modSquare_fast(t1.as_mut_ptr(), Z); /* x1 * z^2 */ - vli_modMult_fast(X1, X1, t1.as_mut_ptr()); /* z^3 */ - vli_modMult_fast(t1.as_mut_ptr(), t1.as_mut_ptr(), Z); - vli_modMult_fast(Y1, Y1, t1.as_mut_ptr()); - /* y1 * z^3 */ - } - /* P = (x1, y1) => 2P, (x2, y2) => P' */ - - unsafe fn XYcZ_initial_double( - mut X1: *mut uint64_t, - mut Y1: *mut uint64_t, - mut X2: *mut uint64_t, - mut Y2: *mut uint64_t, - mut p_initialZ: *mut uint64_t, - ) { - let mut z: [uint64_t; 6] = std::mem::MaybeUninit::uninit().assume_init(); - vli_set(X2, X1); - vli_set(Y2, Y1); - vli_clear(z.as_mut_ptr()); - z[0 as libc::c_int as usize] = 1 as libc::c_int as uint64_t; - if !p_initialZ.is_null() { - vli_set(z.as_mut_ptr(), p_initialZ); - } - apply_z(X1, Y1, z.as_mut_ptr()); - EccPoint_double_jacobian(X1, Y1, z.as_mut_ptr()); - apply_z(X2, Y2, z.as_mut_ptr()); - } - /* Input P = (x1, y1, Z), Q = (x2, y2, Z) - Output P' = (x1', y1', Z3), P + Q = (x3, y3, Z3) - or P => P', Q => P + Q - */ - - unsafe fn XYcZ_add(mut X1: *mut uint64_t, mut Y1: *mut uint64_t, mut X2: *mut uint64_t, mut Y2: *mut uint64_t) { - /* t1 = X1, t2 = Y1, t3 = X2, t4 = Y2 */ - let mut t5: [uint64_t; 6] = std::mem::MaybeUninit::uninit().assume_init(); /* t5 = x2 - x1 */ - vli_modSub(t5.as_mut_ptr(), X2, X1, curve_p.as_mut_ptr()); /* t5 = (x2 - x1)^2 = A */ - vli_modSquare_fast(t5.as_mut_ptr(), t5.as_mut_ptr()); /* t1 = x1*A = B */ - vli_modMult_fast(X1, X1, t5.as_mut_ptr()); /* t3 = x2*A = C */ - vli_modMult_fast(X2, X2, t5.as_mut_ptr()); /* t4 = y2 - y1 */ - vli_modSub(Y2, Y2, Y1, curve_p.as_mut_ptr()); /* t5 = (y2 - y1)^2 = D */ - vli_modSquare_fast(t5.as_mut_ptr(), Y2); /* t5 = D - B */ - vli_modSub(t5.as_mut_ptr(), t5.as_mut_ptr(), X1, curve_p.as_mut_ptr()); /* t5 = D - B - C = x3 */ - vli_modSub(t5.as_mut_ptr(), t5.as_mut_ptr(), X2, curve_p.as_mut_ptr()); /* t3 = C - B */ - vli_modSub(X2, X2, X1, curve_p.as_mut_ptr()); /* t2 = y1*(C - B) */ - vli_modMult_fast(Y1, Y1, X2); /* t3 = B - x3 */ - vli_modSub(X2, X1, t5.as_mut_ptr(), curve_p.as_mut_ptr()); /* t4 = (y2 - y1)*(B - x3) */ - vli_modMult_fast(Y2, Y2, X2); /* t4 = y3 */ - vli_modSub(Y2, Y2, Y1, curve_p.as_mut_ptr()); - vli_set(X2, t5.as_mut_ptr()); - } - /* Input P = (x1, y1, Z), Q = (x2, y2, Z) - Output P + Q = (x3, y3, Z3), P - Q = (x3', y3', Z3) - or P => P - Q, Q => P + Q - */ - - unsafe fn XYcZ_addC(mut X1: *mut uint64_t, mut Y1: *mut uint64_t, mut X2: *mut uint64_t, mut Y2: *mut uint64_t) { - /* t1 = X1, t2 = Y1, t3 = X2, t4 = Y2 */ - let mut t5: [uint64_t; 6] = std::mem::MaybeUninit::uninit().assume_init(); /* t5 = x2 - x1 */ - let mut t6: [uint64_t; 6] = std::mem::MaybeUninit::uninit().assume_init(); /* t5 = (x2 - x1)^2 = A */ - let mut t7: [uint64_t; 6] = std::mem::MaybeUninit::uninit().assume_init(); /* t1 = x1*A = B */ - vli_modSub(t5.as_mut_ptr(), X2, X1, curve_p.as_mut_ptr()); /* t3 = x2*A = C */ - vli_modSquare_fast(t5.as_mut_ptr(), t5.as_mut_ptr()); /* t4 = y2 + y1 */ - vli_modMult_fast(X1, X1, t5.as_mut_ptr()); /* t4 = y2 - y1 */ - vli_modMult_fast(X2, X2, t5.as_mut_ptr()); /* t6 = C - B */ - vli_modAdd(t5.as_mut_ptr(), Y2, Y1, curve_p.as_mut_ptr()); /* t2 = y1 * (C - B) */ - vli_modSub(Y2, Y2, Y1, curve_p.as_mut_ptr()); /* t6 = B + C */ - vli_modSub(t6.as_mut_ptr(), X2, X1, curve_p.as_mut_ptr()); /* t3 = (y2 - y1)^2 */ - vli_modMult_fast(Y1, Y1, t6.as_mut_ptr()); /* t3 = x3 */ - vli_modAdd(t6.as_mut_ptr(), X1, X2, curve_p.as_mut_ptr()); /* t7 = B - x3 */ - vli_modSquare_fast(X2, Y2); /* t4 = (y2 - y1)*(B - x3) */ - vli_modSub(X2, X2, t6.as_mut_ptr(), curve_p.as_mut_ptr()); /* t4 = y3 */ - vli_modSub(t7.as_mut_ptr(), X1, X2, curve_p.as_mut_ptr()); /* t7 = (y2 + y1)^2 = F */ - vli_modMult_fast(Y2, Y2, t7.as_mut_ptr()); /* t7 = x3' */ - vli_modSub(Y2, Y2, Y1, curve_p.as_mut_ptr()); /* t6 = x3' - B */ - vli_modSquare_fast(t7.as_mut_ptr(), t5.as_mut_ptr()); /* t6 = (y2 + y1)*(x3' - B) */ - vli_modSub(t7.as_mut_ptr(), t7.as_mut_ptr(), t6.as_mut_ptr(), curve_p.as_mut_ptr()); /* t2 = y3' */ - vli_modSub(t6.as_mut_ptr(), t7.as_mut_ptr(), X1, curve_p.as_mut_ptr()); - vli_modMult_fast(t6.as_mut_ptr(), t6.as_mut_ptr(), t5.as_mut_ptr()); - vli_modSub(Y1, t6.as_mut_ptr(), Y1, curve_p.as_mut_ptr()); - vli_set(X1, t7.as_mut_ptr()); - } - - unsafe fn EccPoint_mult( - mut p_result: *mut EccPoint, - mut p_point: *mut EccPoint, - mut p_scalar: *mut uint64_t, - mut p_initialZ: *mut uint64_t, - ) { - /* R0 and R1 */ - let mut Rx: [[uint64_t; 6]; 2] = std::mem::MaybeUninit::uninit().assume_init(); - let mut Ry: [[uint64_t; 6]; 2] = std::mem::MaybeUninit::uninit().assume_init(); - let mut z: [uint64_t; 6] = std::mem::MaybeUninit::uninit().assume_init(); - let mut i: libc::c_int = 0; - let mut nb: libc::c_int = 0; - vli_set(Rx[1 as libc::c_int as usize].as_mut_ptr(), (*p_point).x.as_mut_ptr()); - vli_set(Ry[1 as libc::c_int as usize].as_mut_ptr(), (*p_point).y.as_mut_ptr()); - XYcZ_initial_double( - Rx[1 as libc::c_int as usize].as_mut_ptr(), - Ry[1 as libc::c_int as usize].as_mut_ptr(), - Rx[0 as libc::c_int as usize].as_mut_ptr(), - Ry[0 as libc::c_int as usize].as_mut_ptr(), - p_initialZ, - ); - i = vli_numBits(p_scalar).wrapping_sub(2 as libc::c_int as libc::c_uint) as libc::c_int; - while i > 0 as libc::c_int { - nb = (vli_testBit(p_scalar, i as uint) == 0) as libc::c_int; - XYcZ_addC( - Rx[(1 as libc::c_int - nb) as usize].as_mut_ptr(), - Ry[(1 as libc::c_int - nb) as usize].as_mut_ptr(), - Rx[nb as usize].as_mut_ptr(), - Ry[nb as usize].as_mut_ptr(), - ); - XYcZ_add( - Rx[nb as usize].as_mut_ptr(), - Ry[nb as usize].as_mut_ptr(), - Rx[(1 as libc::c_int - nb) as usize].as_mut_ptr(), - Ry[(1 as libc::c_int - nb) as usize].as_mut_ptr(), - ); - i -= 1 - } - nb = (vli_testBit(p_scalar, 0 as libc::c_int as uint) == 0) as libc::c_int; - XYcZ_addC( - Rx[(1 as libc::c_int - nb) as usize].as_mut_ptr(), - Ry[(1 as libc::c_int - nb) as usize].as_mut_ptr(), - Rx[nb as usize].as_mut_ptr(), - Ry[nb as usize].as_mut_ptr(), - ); - /* Find final 1/Z value. */ - vli_modSub( - z.as_mut_ptr(), - Rx[1 as libc::c_int as usize].as_mut_ptr(), - Rx[0 as libc::c_int as usize].as_mut_ptr(), - curve_p.as_mut_ptr(), - ); /* X1 - X0 */ - vli_modMult_fast( - z.as_mut_ptr(), - z.as_mut_ptr(), - Ry[(1 as libc::c_int - nb) as usize].as_mut_ptr(), - ); /* Yb * (X1 - X0) */ - vli_modMult_fast(z.as_mut_ptr(), z.as_mut_ptr(), (*p_point).x.as_mut_ptr()); /* xP * Yb * (X1 - X0) */ - vli_modInv(z.as_mut_ptr(), z.as_mut_ptr(), curve_p.as_mut_ptr()); /* 1 / (xP * Yb * (X1 - X0)) */ - vli_modMult_fast(z.as_mut_ptr(), z.as_mut_ptr(), (*p_point).y.as_mut_ptr()); /* yP / (xP * Yb * (X1 - X0)) */ - vli_modMult_fast( - z.as_mut_ptr(), - z.as_mut_ptr(), - Rx[(1 as libc::c_int - nb) as usize].as_mut_ptr(), - ); /* Xb * yP / (xP * Yb * (X1 - X0)) */ - /* End 1/Z calculation */ - XYcZ_add( - Rx[nb as usize].as_mut_ptr(), - Ry[nb as usize].as_mut_ptr(), - Rx[(1 as libc::c_int - nb) as usize].as_mut_ptr(), - Ry[(1 as libc::c_int - nb) as usize].as_mut_ptr(), - ); - apply_z( - Rx[0 as libc::c_int as usize].as_mut_ptr(), - Ry[0 as libc::c_int as usize].as_mut_ptr(), - z.as_mut_ptr(), - ); - vli_set((*p_result).x.as_mut_ptr(), Rx[0 as libc::c_int as usize].as_mut_ptr()); - vli_set((*p_result).y.as_mut_ptr(), Ry[0 as libc::c_int as usize].as_mut_ptr()); - } - - unsafe fn ecc_bytes2native(mut p_native: *mut uint64_t, mut p_bytes: *const uint8_t) { - let mut i: libc::c_uint = 0; - i = 0 as libc::c_int as libc::c_uint; - while i < (48 as libc::c_int / 8 as libc::c_int) as libc::c_uint { - let mut p_digit: *const uint8_t = p_bytes.offset((8 as libc::c_int as libc::c_uint).wrapping_mul( - ((48 as libc::c_int / 8 as libc::c_int - 1 as libc::c_int) as libc::c_uint).wrapping_sub(i), - ) as isize); - *p_native.offset(i as isize) = (*p_digit.offset(0 as libc::c_int as isize) as uint64_t) - << 56 as libc::c_int - | (*p_digit.offset(1 as libc::c_int as isize) as uint64_t) << 48 as libc::c_int - | (*p_digit.offset(2 as libc::c_int as isize) as uint64_t) << 40 as libc::c_int - | (*p_digit.offset(3 as libc::c_int as isize) as uint64_t) << 32 as libc::c_int - | (*p_digit.offset(4 as libc::c_int as isize) as uint64_t) << 24 as libc::c_int - | (*p_digit.offset(5 as libc::c_int as isize) as uint64_t) << 16 as libc::c_int - | (*p_digit.offset(6 as libc::c_int as isize) as uint64_t) << 8 as libc::c_int - | *p_digit.offset(7 as libc::c_int as isize) as uint64_t; - i = i.wrapping_add(1) - } - } - - unsafe fn ecc_native2bytes(mut p_bytes: *mut uint8_t, mut p_native: *const uint64_t) { - let mut i: libc::c_uint = 0; - i = 0 as libc::c_int as libc::c_uint; - while i < (48 as libc::c_int / 8 as libc::c_int) as libc::c_uint { - let mut p_digit: *mut uint8_t = p_bytes.offset((8 as libc::c_int as libc::c_uint).wrapping_mul( - ((48 as libc::c_int / 8 as libc::c_int - 1 as libc::c_int) as libc::c_uint).wrapping_sub(i), - ) as isize); - *p_digit.offset(0 as libc::c_int as isize) = (*p_native.offset(i as isize) >> 56 as libc::c_int) as uint8_t; - *p_digit.offset(1 as libc::c_int as isize) = (*p_native.offset(i as isize) >> 48 as libc::c_int) as uint8_t; - *p_digit.offset(2 as libc::c_int as isize) = (*p_native.offset(i as isize) >> 40 as libc::c_int) as uint8_t; - *p_digit.offset(3 as libc::c_int as isize) = (*p_native.offset(i as isize) >> 32 as libc::c_int) as uint8_t; - *p_digit.offset(4 as libc::c_int as isize) = (*p_native.offset(i as isize) >> 24 as libc::c_int) as uint8_t; - *p_digit.offset(5 as libc::c_int as isize) = (*p_native.offset(i as isize) >> 16 as libc::c_int) as uint8_t; - *p_digit.offset(6 as libc::c_int as isize) = (*p_native.offset(i as isize) >> 8 as libc::c_int) as uint8_t; - *p_digit.offset(7 as libc::c_int as isize) = *p_native.offset(i as isize) as uint8_t; - i = i.wrapping_add(1) - } - } - /* Compute a = sqrt(a) (mod curve_p). */ - - unsafe fn mod_sqrt(mut a: *mut uint64_t) { - let mut i: libc::c_uint = 0; - let mut p1: [uint64_t; 6] = [1 as libc::c_int as uint64_t, 0, 0, 0, 0, 0]; - let mut l_result: [uint64_t; 6] = [1 as libc::c_int as uint64_t, 0, 0, 0, 0, 0]; - /* Since curve_p == 3 (mod 4) for all supported curves, we can - compute sqrt(a) = a^((curve_p + 1) / 4) (mod curve_p). */ - vli_add(p1.as_mut_ptr(), curve_p.as_mut_ptr(), p1.as_mut_ptr()); /* p1 = curve_p + 1 */ - i = vli_numBits(p1.as_mut_ptr()).wrapping_sub(1 as libc::c_int as libc::c_uint); /* -a = 3 */ - while i > 1 as libc::c_int as libc::c_uint { - vli_modSquare_fast(l_result.as_mut_ptr(), l_result.as_mut_ptr()); /* y = x^2 */ - if vli_testBit(p1.as_mut_ptr(), i) != 0 { - vli_modMult_fast(l_result.as_mut_ptr(), l_result.as_mut_ptr(), a); - /* y = x^2 - 3 */ - } /* y = x^3 - 3x */ - i = i.wrapping_sub(1) - } /* y = x^3 - 3x + b */ - vli_set(a, l_result.as_mut_ptr()); - } - - unsafe fn ecc_point_decompress(mut p_point: *mut EccPoint, mut p_compressed: *const uint8_t) { - let mut _3: [uint64_t; 6] = [3 as libc::c_int as uint64_t, 0, 0, 0, 0, 0]; - ecc_bytes2native( - (*p_point).x.as_mut_ptr(), - p_compressed.offset(1 as libc::c_int as isize), - ); - vli_modSquare_fast((*p_point).y.as_mut_ptr(), (*p_point).x.as_mut_ptr()); - vli_modSub( - (*p_point).y.as_mut_ptr(), - (*p_point).y.as_mut_ptr(), - _3.as_mut_ptr(), - curve_p.as_mut_ptr(), - ); - vli_modMult_fast( - (*p_point).y.as_mut_ptr(), - (*p_point).y.as_mut_ptr(), - (*p_point).x.as_mut_ptr(), - ); - vli_modAdd( - (*p_point).y.as_mut_ptr(), - (*p_point).y.as_mut_ptr(), - curve_b.as_mut_ptr(), - curve_p.as_mut_ptr(), - ); - mod_sqrt((*p_point).y.as_mut_ptr()); - if (*p_point).y[0 as libc::c_int as usize] & 0x1 as libc::c_int as libc::c_ulong - != (*p_compressed.offset(0 as libc::c_int as isize) as libc::c_int & 0x1 as libc::c_int) as libc::c_ulong - { - vli_sub( - (*p_point).y.as_mut_ptr(), - curve_p.as_mut_ptr(), - (*p_point).y.as_mut_ptr(), - ); - }; - } - pub unsafe fn ecc_make_key(mut p_publicKey: *mut uint8_t, mut p_privateKey: *mut uint8_t) -> libc::c_int { - let mut l_private: [uint64_t; 6] = std::mem::MaybeUninit::uninit().assume_init(); - let mut l_public: EccPoint = std::mem::MaybeUninit::uninit().assume_init(); - let mut l_tries: libc::c_uint = 0 as libc::c_int as libc::c_uint; - loop { - if getRandomNumber(l_private.as_mut_ptr()) == 0 || { - let fresh3 = l_tries; - l_tries = l_tries.wrapping_add(1); - (fresh3) >= 1024 as libc::c_int as libc::c_uint - } { - return 0 as libc::c_int; - } - if !(vli_isZero(l_private.as_mut_ptr()) != 0) { - /* Make sure the private key is in the range [1, n-1]. - For the supported curves, n is always large enough that we only need to subtract once at most. */ - if vli_cmp(curve_n.as_mut_ptr(), l_private.as_mut_ptr()) != 1 as libc::c_int { - vli_sub(l_private.as_mut_ptr(), l_private.as_mut_ptr(), curve_n.as_mut_ptr()); - } - EccPoint_mult(&mut l_public, &mut curve_G, l_private.as_mut_ptr(), 0 as *mut uint64_t); - } - if !(EccPoint_isZero(&mut l_public) != 0) { - break; - } - } - ecc_native2bytes(p_privateKey, l_private.as_mut_ptr() as *const uint64_t); - ecc_native2bytes( - p_publicKey.offset(1 as libc::c_int as isize), - l_public.x.as_mut_ptr() as *const uint64_t, - ); - *p_publicKey.offset(0 as libc::c_int as isize) = (2 as libc::c_int as libc::c_ulong) - .wrapping_add(l_public.y[0 as libc::c_int as usize] & 0x1 as libc::c_int as libc::c_ulong) - as uint8_t; - return 1 as libc::c_int; - } - pub unsafe fn ecdh_shared_secret( - mut p_publicKey: *const uint8_t, - mut p_privateKey: *const uint8_t, - mut p_secret: *mut uint8_t, - ) -> libc::c_int { - let mut l_public: EccPoint = std::mem::MaybeUninit::uninit().assume_init(); - let mut l_private: [uint64_t; 6] = std::mem::MaybeUninit::uninit().assume_init(); - let mut l_random: [uint64_t; 6] = std::mem::MaybeUninit::uninit().assume_init(); - if getRandomNumber(l_random.as_mut_ptr()) == 0 { - return 0 as libc::c_int; - } - ecc_point_decompress(&mut l_public, p_publicKey); - ecc_bytes2native(l_private.as_mut_ptr(), p_privateKey); - let mut l_product: EccPoint = EccPoint { x: [0; 6], y: [0; 6] }; - EccPoint_mult( - &mut l_product, - &mut l_public, - l_private.as_mut_ptr(), - l_random.as_mut_ptr(), - ); - ecc_native2bytes(p_secret, l_product.x.as_mut_ptr() as *const uint64_t); - return (EccPoint_isZero(&mut l_product) == 0) as libc::c_int; - } - /* -------- ECDSA code -------- */ - /* Computes p_result = (p_left * p_right) % p_mod. */ - - unsafe fn vli_modMult( - mut p_result: *mut uint64_t, - mut p_left: *mut uint64_t, - mut p_right: *mut uint64_t, - mut p_mod: *mut uint64_t, - ) { - let mut l_product: [uint64_t; 12] = std::mem::MaybeUninit::uninit().assume_init(); - let mut l_modMultiple: [uint64_t; 12] = std::mem::MaybeUninit::uninit().assume_init(); - let mut l_digitShift: uint = 0; - let mut l_bitShift: uint = 0; - let mut l_productBits: uint = 0; - let mut l_modBits: uint = vli_numBits(p_mod); - vli_mult(l_product.as_mut_ptr(), p_left, p_right); - l_productBits = vli_numBits( - l_product - .as_mut_ptr() - .offset((48 as libc::c_int / 8 as libc::c_int) as isize), - ); - if l_productBits != 0 { - l_productBits = (l_productBits as libc::c_uint) - .wrapping_add((48 as libc::c_int / 8 as libc::c_int * 64 as libc::c_int) as libc::c_uint) - as uint as uint - } else { - l_productBits = vli_numBits(l_product.as_mut_ptr()) - } - if l_productBits < l_modBits { - /* l_product < p_mod. */ - vli_set(p_result, l_product.as_mut_ptr()); - return; - } - /* Shift p_mod by (l_leftBits - l_modBits). This multiplies p_mod by the largest - power of two possible while still resulting in a number less than p_left. */ - vli_clear(l_modMultiple.as_mut_ptr()); - vli_clear( - l_modMultiple - .as_mut_ptr() - .offset((48 as libc::c_int / 8 as libc::c_int) as isize), - ); - l_digitShift = l_productBits - .wrapping_sub(l_modBits) - .wrapping_div(64 as libc::c_int as libc::c_uint); - l_bitShift = l_productBits - .wrapping_sub(l_modBits) - .wrapping_rem(64 as libc::c_int as libc::c_uint); - if l_bitShift != 0 { - l_modMultiple[l_digitShift.wrapping_add((48 as libc::c_int / 8 as libc::c_int) as libc::c_uint) as usize] = - vli_lshift( - l_modMultiple.as_mut_ptr().offset(l_digitShift as isize), - p_mod, - l_bitShift, - ) - } else { - vli_set(l_modMultiple.as_mut_ptr().offset(l_digitShift as isize), p_mod); - } - /* Subtract all multiples of p_mod to get the remainder. */ - vli_clear(p_result); /* Use p_result as a temp var to store 1 (for subtraction) */ - *p_result.offset(0 as libc::c_int as isize) = 1 as libc::c_int as uint64_t; - while l_productBits > (48 as libc::c_int / 8 as libc::c_int * 64 as libc::c_int) as libc::c_uint - || vli_cmp(l_modMultiple.as_mut_ptr(), p_mod) >= 0 as libc::c_int - { - let mut l_cmp: libc::c_int = vli_cmp( - l_modMultiple - .as_mut_ptr() - .offset((48 as libc::c_int / 8 as libc::c_int) as isize), - l_product - .as_mut_ptr() - .offset((48 as libc::c_int / 8 as libc::c_int) as isize), - ); - if l_cmp < 0 as libc::c_int - || l_cmp == 0 as libc::c_int - && vli_cmp(l_modMultiple.as_mut_ptr(), l_product.as_mut_ptr()) <= 0 as libc::c_int - { - if vli_sub( - l_product.as_mut_ptr(), - l_product.as_mut_ptr(), - l_modMultiple.as_mut_ptr(), - ) != 0 - { - /* borrow */ - vli_sub( - l_product - .as_mut_ptr() - .offset((48 as libc::c_int / 8 as libc::c_int) as isize), - l_product - .as_mut_ptr() - .offset((48 as libc::c_int / 8 as libc::c_int) as isize), - p_result, - ); - } - vli_sub( - l_product - .as_mut_ptr() - .offset((48 as libc::c_int / 8 as libc::c_int) as isize), - l_product - .as_mut_ptr() - .offset((48 as libc::c_int / 8 as libc::c_int) as isize), - l_modMultiple - .as_mut_ptr() - .offset((48 as libc::c_int / 8 as libc::c_int) as isize), - ); - } - let mut l_carry: uint64_t = (l_modMultiple[(48 as libc::c_int / 8 as libc::c_int) as usize] - & 0x1 as libc::c_int as libc::c_ulong) - << 63 as libc::c_int; - vli_rshift1( - l_modMultiple - .as_mut_ptr() - .offset((48 as libc::c_int / 8 as libc::c_int) as isize), - ); - vli_rshift1(l_modMultiple.as_mut_ptr()); - l_modMultiple[(48 as libc::c_int / 8 as libc::c_int - 1 as libc::c_int) as usize] |= l_carry; - l_productBits = l_productBits.wrapping_sub(1) - } - vli_set(p_result, l_product.as_mut_ptr()); - } - - unsafe fn umax(mut a: uint, mut b: uint) -> uint { - a.max(b) - } - pub unsafe fn ecdsa_sign( - mut p_privateKey: *const uint8_t, - mut p_hash: *const uint8_t, - mut p_signature: *mut uint8_t, - ) -> libc::c_int { - let mut k: [uint64_t; 6] = std::mem::MaybeUninit::uninit().assume_init(); - let mut l_tmp: [uint64_t; 6] = std::mem::MaybeUninit::uninit().assume_init(); - let mut l_s: [uint64_t; 6] = std::mem::MaybeUninit::uninit().assume_init(); - let mut p: EccPoint = std::mem::MaybeUninit::uninit().assume_init(); - let mut l_tries: libc::c_uint = 0 as libc::c_int as libc::c_uint; - loop { - if getRandomNumber(k.as_mut_ptr()) == 0 || { - let fresh4 = l_tries; - l_tries = l_tries.wrapping_add(1); - (fresh4) >= 1024 as libc::c_int as libc::c_uint - } { - return 0 as libc::c_int; - } - if !(vli_isZero(k.as_mut_ptr()) != 0) { - if vli_cmp(curve_n.as_mut_ptr(), k.as_mut_ptr()) != 1 as libc::c_int { - vli_sub(k.as_mut_ptr(), k.as_mut_ptr(), curve_n.as_mut_ptr()); - } - /* tmp = k * G */ - EccPoint_mult(&mut p, &mut curve_G, k.as_mut_ptr(), 0 as *mut uint64_t); - /* r = x1 (mod n) */ - if vli_cmp(curve_n.as_mut_ptr(), p.x.as_mut_ptr()) != 1 as libc::c_int { - vli_sub(p.x.as_mut_ptr(), p.x.as_mut_ptr(), curve_n.as_mut_ptr()); - /* s = r*d */ - } - } /* s = e + r*d */ - if !(vli_isZero(p.x.as_mut_ptr()) != 0) { - break; /* k = 1 / k */ - } - } /* s = (e + r*d) / k */ - ecc_native2bytes(p_signature, p.x.as_mut_ptr() as *const uint64_t); - ecc_bytes2native(l_tmp.as_mut_ptr(), p_privateKey); - vli_modMult( - l_s.as_mut_ptr(), - p.x.as_mut_ptr(), - l_tmp.as_mut_ptr(), - curve_n.as_mut_ptr(), - ); - ecc_bytes2native(l_tmp.as_mut_ptr(), p_hash); - vli_modAdd( - l_s.as_mut_ptr(), - l_tmp.as_mut_ptr(), - l_s.as_mut_ptr(), - curve_n.as_mut_ptr(), - ); - vli_modInv(k.as_mut_ptr(), k.as_mut_ptr(), curve_n.as_mut_ptr()); - vli_modMult(l_s.as_mut_ptr(), l_s.as_mut_ptr(), k.as_mut_ptr(), curve_n.as_mut_ptr()); - ecc_native2bytes( - p_signature.offset(48 as libc::c_int as isize), - l_s.as_mut_ptr() as *const uint64_t, - ); - return 1 as libc::c_int; - } - pub unsafe fn ecdsa_verify( - mut p_publicKey: *const uint8_t, - mut p_hash: *const uint8_t, - mut p_signature: *const uint8_t, - ) -> libc::c_int { - let mut u1: [uint64_t; 6] = std::mem::MaybeUninit::uninit().assume_init(); - let mut u2: [uint64_t; 6] = std::mem::MaybeUninit::uninit().assume_init(); - let mut z: [uint64_t; 6] = std::mem::MaybeUninit::uninit().assume_init(); - let mut l_public: EccPoint = std::mem::MaybeUninit::uninit().assume_init(); - let mut l_sum: EccPoint = std::mem::MaybeUninit::uninit().assume_init(); - let mut rx: [uint64_t; 6] = std::mem::MaybeUninit::uninit().assume_init(); - let mut ry: [uint64_t; 6] = std::mem::MaybeUninit::uninit().assume_init(); - let mut tx: [uint64_t; 6] = std::mem::MaybeUninit::uninit().assume_init(); - let mut ty: [uint64_t; 6] = std::mem::MaybeUninit::uninit().assume_init(); - let mut tz: [uint64_t; 6] = std::mem::MaybeUninit::uninit().assume_init(); - let mut l_r: [uint64_t; 6] = std::mem::MaybeUninit::uninit().assume_init(); - let mut l_s: [uint64_t; 6] = std::mem::MaybeUninit::uninit().assume_init(); - ecc_point_decompress(&mut l_public, p_publicKey); - ecc_bytes2native(l_r.as_mut_ptr(), p_signature); - ecc_bytes2native(l_s.as_mut_ptr(), p_signature.offset(48 as libc::c_int as isize)); - if vli_isZero(l_r.as_mut_ptr()) != 0 || vli_isZero(l_s.as_mut_ptr()) != 0 { - /* r, s must not be 0. */ - return 0 as libc::c_int; - } - if vli_cmp(curve_n.as_mut_ptr(), l_r.as_mut_ptr()) != 1 as libc::c_int - || vli_cmp(curve_n.as_mut_ptr(), l_s.as_mut_ptr()) != 1 as libc::c_int - { - /* r, s must be < n. */ - return 0 as libc::c_int; - } - /* Calculate u1 and u2. */ - vli_modInv(z.as_mut_ptr(), l_s.as_mut_ptr(), curve_n.as_mut_ptr()); /* Z = s^-1 */ - ecc_bytes2native(u1.as_mut_ptr(), p_hash); /* u1 = e/s */ - vli_modMult(u1.as_mut_ptr(), u1.as_mut_ptr(), z.as_mut_ptr(), curve_n.as_mut_ptr()); /* u2 = r/s */ - vli_modMult(u2.as_mut_ptr(), l_r.as_mut_ptr(), z.as_mut_ptr(), curve_n.as_mut_ptr()); - /* Calculate l_sum = G + Q. */ - vli_set(l_sum.x.as_mut_ptr(), l_public.x.as_mut_ptr()); /* Z = x2 - x1 */ - vli_set(l_sum.y.as_mut_ptr(), l_public.y.as_mut_ptr()); /* Z = 1/Z */ - vli_set(tx.as_mut_ptr(), curve_G.x.as_mut_ptr()); - vli_set(ty.as_mut_ptr(), curve_G.y.as_mut_ptr()); - vli_modSub( - z.as_mut_ptr(), - l_sum.x.as_mut_ptr(), - tx.as_mut_ptr(), - curve_p.as_mut_ptr(), - ); - XYcZ_add( - tx.as_mut_ptr(), - ty.as_mut_ptr(), - l_sum.x.as_mut_ptr(), - l_sum.y.as_mut_ptr(), - ); - vli_modInv(z.as_mut_ptr(), z.as_mut_ptr(), curve_p.as_mut_ptr()); - apply_z(l_sum.x.as_mut_ptr(), l_sum.y.as_mut_ptr(), z.as_mut_ptr()); - /* Use Shamir's trick to calculate u1*G + u2*Q */ - let mut l_points: [*mut EccPoint; 4] = [0 as *mut EccPoint, &mut curve_G, &mut l_public, &mut l_sum]; /* Z = x2 - x1 */ - let mut l_numBits: uint = umax(vli_numBits(u1.as_mut_ptr()), vli_numBits(u2.as_mut_ptr())); /* Z = 1/Z */ - let mut l_point: *mut EccPoint = l_points[((vli_testBit( - u1.as_mut_ptr(), - l_numBits.wrapping_sub(1 as libc::c_int as libc::c_uint), - ) != 0) as libc::c_int - | ((vli_testBit( - u2.as_mut_ptr(), - l_numBits.wrapping_sub(1 as libc::c_int as libc::c_uint), - ) != 0) as libc::c_int) - << 1 as libc::c_int) as usize]; - vli_set(rx.as_mut_ptr(), (*l_point).x.as_mut_ptr()); - vli_set(ry.as_mut_ptr(), (*l_point).y.as_mut_ptr()); - vli_clear(z.as_mut_ptr()); - z[0 as libc::c_int as usize] = 1 as libc::c_int as uint64_t; - let mut i: libc::c_int = 0; - i = l_numBits.wrapping_sub(2 as libc::c_int as libc::c_uint) as libc::c_int; - while i >= 0 as libc::c_int { - EccPoint_double_jacobian(rx.as_mut_ptr(), ry.as_mut_ptr(), z.as_mut_ptr()); - let mut l_index: libc::c_int = (vli_testBit(u1.as_mut_ptr(), i as uint) != 0) as libc::c_int - | ((vli_testBit(u2.as_mut_ptr(), i as uint) != 0) as libc::c_int) << 1 as libc::c_int; - let mut l_point_0: *mut EccPoint = l_points[l_index as usize]; - if !l_point_0.is_null() { - vli_set(tx.as_mut_ptr(), (*l_point_0).x.as_mut_ptr()); - vli_set(ty.as_mut_ptr(), (*l_point_0).y.as_mut_ptr()); - apply_z(tx.as_mut_ptr(), ty.as_mut_ptr(), z.as_mut_ptr()); - vli_modSub(tz.as_mut_ptr(), rx.as_mut_ptr(), tx.as_mut_ptr(), curve_p.as_mut_ptr()); - XYcZ_add(tx.as_mut_ptr(), ty.as_mut_ptr(), rx.as_mut_ptr(), ry.as_mut_ptr()); - vli_modMult_fast(z.as_mut_ptr(), z.as_mut_ptr(), tz.as_mut_ptr()); - } - i -= 1 - } - vli_modInv(z.as_mut_ptr(), z.as_mut_ptr(), curve_p.as_mut_ptr()); - apply_z(rx.as_mut_ptr(), ry.as_mut_ptr(), z.as_mut_ptr()); - /* v = x1 (mod n) */ - if vli_cmp(curve_n.as_mut_ptr(), rx.as_mut_ptr()) != 1 as libc::c_int { - vli_sub(rx.as_mut_ptr(), rx.as_mut_ptr(), curve_n.as_mut_ptr()); - } - /* Accept only if v == r. */ - return (vli_cmp(rx.as_mut_ptr(), l_r.as_mut_ptr()) == 0 as libc::c_int) as libc::c_int; - } - - #[derive(Clone, PartialEq, Eq)] - pub struct P384PublicKey([u8; 49]); - - impl P384PublicKey { - pub fn from_bytes(b: &[u8]) -> Option { - if b.len() == 49 { - Some(Self(b.try_into().unwrap())) - } else { - None - } - } - - pub fn verify(&self, msg: &[u8], signature: &[u8]) -> bool { - if signature.len() == 96 { - unsafe { - return ecdsa_verify( - self.0.as_ptr().cast(), - SHA384::hash(msg).as_ptr().cast(), - signature.as_ptr().cast(), - ) != 0; - } - } - return false; - } - - pub fn as_bytes(&self) -> &[u8; 49] { - &self.0 - } - } - - #[derive(Clone, PartialEq, Eq)] - pub struct P384KeyPair(P384PublicKey, Secret<48>); - - impl P384KeyPair { - pub fn generate() -> P384KeyPair { - let mut kp = Self(P384PublicKey([0_u8; 49]), Secret::new()); - unsafe { ecc_make_key(kp.0 .0.as_mut_ptr().cast(), kp.1 .0.as_mut_ptr().cast()) }; - kp - } - - pub fn from_bytes(public_bytes: &[u8], secret_bytes: &[u8]) -> Option { - if public_bytes.len() == 49 && secret_bytes.len() == 48 { - Some(Self( - P384PublicKey(public_bytes.try_into().unwrap()), - Secret(secret_bytes.try_into().unwrap()), - )) - } else { - None - } - } - - pub fn public_key(&self) -> &P384PublicKey { - &self.0 - } - - pub fn public_key_bytes(&self) -> &[u8; 49] { - &self.0 .0 - } - - pub fn secret_key_bytes(&self) -> Secret<48> { - self.1.clone() - } - - pub fn sign(&self, msg: &[u8]) -> [u8; 96] { - let msg = SHA384::hash(msg); - let mut sig = [0_u8; 96]; - unsafe { - ecdsa_sign(self.1 .0.as_ptr().cast(), msg.as_ptr().cast(), sig.as_mut_ptr().cast()); - } - sig - } - - pub fn agree(&self, other_public: &P384PublicKey) -> Option> { - let mut k = Secret::new(); - unsafe { - ecdh_shared_secret( - other_public.0.as_ptr().cast(), - self.1 .0.as_ptr().cast(), - k.0.as_mut_ptr().cast(), - ); - } - Some(k) - } - } - - impl P384KeyPair {} -} - -#[cfg(target_feature = "builtin_nist_ecc")] -pub use builtin::*; diff --git a/crypto-glue/src/random.rs b/crypto-glue/src/random.rs deleted file mode 100644 index aa3fd57..0000000 --- a/crypto-glue/src/random.rs +++ /dev/null @@ -1,156 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * (c) ZeroTier, Inc. - * https://www.zerotier.com/ - */ - -use std::sync::Mutex; - -use libc::c_int; -use once_cell::unsync::Lazy; -use rand_xoshiro::rand_core::{CryptoRng, Error, RngCore, SeedableRng}; - -use crate::error::cvt; - -/// Fill buffer with cryptographically strong pseudo-random bytes. -#[inline] -pub fn fill_bytes_secure(dest: &mut [u8]) { - unsafe { - debug_assert!(dest.len() <= c_int::max_value() as usize); - cvt(ffi::RAND_bytes(dest.as_mut_ptr(), dest.len() as c_int)).unwrap(); - } -} - -pub fn next_u32_secure() -> u32 { - let mut tmp = [0u8; 4]; - fill_bytes_secure(&mut tmp); - u32::from_ne_bytes(tmp) -} - -pub fn next_u64_secure() -> u64 { - let mut tmp = [0u8; 8]; - fill_bytes_secure(&mut tmp); - u64::from_ne_bytes(tmp) -} - -pub fn next_u128_secure() -> u128 { - let mut tmp = [0u8; 16]; - fill_bytes_secure(&mut tmp); - u128::from_ne_bytes(tmp) -} - -#[inline(always)] -pub fn get_bytes_secure() -> [u8; COUNT] { - let mut tmp = [0u8; COUNT]; - fill_bytes_secure(&mut tmp); - tmp -} - -pub struct SecureRandom; - -impl Default for SecureRandom { - #[inline(always)] - fn default() -> Self { - Self - } -} - -impl SecureRandom { - #[inline(always)] - pub fn get() -> Self { - Self - } -} - -impl RngCore for SecureRandom { - #[inline(always)] - fn next_u32(&mut self) -> u32 { - next_u32_secure() - } - - #[inline(always)] - fn next_u64(&mut self) -> u64 { - next_u64_secure() - } - - #[inline(always)] - fn fill_bytes(&mut self, dest: &mut [u8]) { - fill_bytes_secure(dest); - } - - #[inline(always)] - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { - fill_bytes_secure(dest); - Ok(()) - } -} - -/// 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. -impl rand_core_051::RngCore for SecureRandom { - #[inline(always)] - fn next_u32(&mut self) -> u32 { - next_u32_secure() - } - - #[inline(always)] - fn next_u64(&mut self) -> u64 { - next_u64_secure() - } - - #[inline(always)] - fn fill_bytes(&mut self, dest: &mut [u8]) { - fill_bytes_secure(dest); - } - - #[inline(always)] - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand_core_051::Error> { - fill_bytes_secure(dest); - Ok(()) - } -} - -impl CryptoRng for SecureRandom {} -impl rand_core_051::CryptoRng for SecureRandom {} -unsafe impl Sync for SecureRandom {} -unsafe impl Send for SecureRandom {} - -/// This crate contains the most modern, feature rich and high-quality variants of the Xorshift family of random -/// number generators. -/// While they are not cryptographically secure, they are also faster and several times harder to -/// reverse than Xorshift64, so I think we should prefer them. -/// I read the source of this crate and it is low level and efficient. -pub use rand_xoshiro; -/// Xoshiro256** according to my benchmarking is surprisingly twice as fast as vanilla -/// Xorshift64 because there are fewer dependency chains in Xoshiro256** compared to Xorshift64. -pub use rand_xoshiro::Xoshiro256StarStar; - -/// A global Xoshiro256** wrapped in a mutex and a OnceCell. -/// Unsync OnceCell is just a wrapped `Option<>` and is very fast. -/// Also OnceCell is about to be stabilized into Rust std. -pub static GLOBAL_XORSHIFT: Mutex> = - Mutex::new(Lazy::new(|| Xoshiro256StarStar::from_rng(SecureRandom).unwrap())); - -/// Quickly creates a new Xoshiro256StarStar state that is randomly seeded and fully owned by the -/// caller (does not require dereferencing and locking a global variable). -#[inline] -pub fn new_xorshift_rng() -> Xoshiro256StarStar { - let mut state = GLOBAL_XORSHIFT.lock().unwrap(); - let ret = state.clone(); - state.jump(); - ret -} -/// Generate a random 64-bit number (not cryptographically secure). -#[inline] -pub fn next_u64_xorshift() -> u64 { - GLOBAL_XORSHIFT.lock().unwrap().next_u64() -} - -/// Generate a random 32-bit number (not cryptographically secure). -/// Internally this generates a 64-bit number and uses the top-most bits, -/// since they are slightlyhigher quality randomness. -#[inline] -pub fn next_u32_xorshift() -> u32 { - GLOBAL_XORSHIFT.lock().unwrap().next_u32() -} diff --git a/crypto-glue/src/secret.rs b/crypto-glue/src/secret.rs deleted file mode 100644 index 1c43649..0000000 --- a/crypto-glue/src/secret.rs +++ /dev/null @@ -1,137 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * (c) ZeroTier, Inc. - * https://www.zerotier.com/ - */ - -use std::{convert::TryInto, ffi::c_void}; - -extern "C" { - fn OPENSSL_cleanse(ptr: *mut c_void, len: usize); -} - -/// Container for secrets that clears them on drop. -/// -/// We can't be totally sure that things like libraries are doing this and it's -/// hard to get every use of a secret anywhere, but using this in our code at -/// least reduces the number of secrets that are left lying around in memory. -/// -/// This is generally a low-risk thing since it's process memory that's protected, -/// but it's still not a bad idea due to things like swap or obscure side channel -/// attacks that allow memory to be read. -#[derive(Clone, PartialEq, Eq)] -#[repr(transparent)] -pub struct Secret(pub [u8; L]); - -impl Secret { - /// Create a new all-zero secret. - #[inline(always)] - pub fn new() -> Self { - Self([0_u8; L]) - } - - /// Moves bytes into secret, will panic if the slice does not match the size of this secret. - #[inline(always)] - pub fn move_bytes(b: [u8; L]) -> Self { - Self(b) - } - - /// Copy bytes into secret, then nuke the previous value, will panic if the slice does not match the size of this secret. - #[inline(always)] - pub fn from_bytes_then_nuke(b: &mut [u8]) -> Self { - let ret = Self(b.try_into().unwrap()); - unsafe { OPENSSL_cleanse(b.as_mut_ptr().cast(), L) }; - ret - } - #[inline(always)] - pub unsafe fn from_bytes(b: &[u8]) -> Self { - Self(b.try_into().unwrap()) - } - - #[inline(always)] - pub fn as_bytes(&self) -> &[u8; L] { - &self.0 - } - #[inline(always)] - pub fn as_ptr(&self) -> *const u8 { - self.0.as_ptr() - } - - #[inline(always)] - pub fn as_bytes_mut(&mut self) -> &mut [u8; L] { - &mut self.0 - } - - /// Get the first N bytes of this secret as a fixed length array. - #[inline(always)] - pub fn first_n(&self) -> &[u8; N] { - assert!(N <= L); - unsafe { &*self.0.as_ptr().cast() } - } - - /// Clone the first N bytes of this secret as another secret. - #[inline(always)] - pub fn first_n_clone(&self) -> Secret { - Secret::(*self.first_n()) - } - - pub fn overwrite(&mut self, src: &Self) { - self.0.copy_from_slice(&src.0); - } - pub fn overwrite_first_n(&mut self, src: &Secret) { - let amount = N.min(L); - self.0[..amount].copy_from_slice(&src.0[..amount]); - } - - /// Destroy the contents of this secret, ignoring normal Rust mutability constraints. - /// - /// This can be used to force a secret to be forgotten under e.g. key lifetime exceeded or error conditions. - #[inline(always)] - pub fn nuke(&self) { - unsafe { OPENSSL_cleanse(self.0.as_ptr().cast_mut().cast(), L) }; - } -} - -impl Drop for Secret { - #[inline(always)] - fn drop(&mut self) { - unsafe { OPENSSL_cleanse(self.0.as_mut_ptr().cast(), L) }; - } -} - -impl Default for Secret { - #[inline(always)] - fn default() -> Self { - Self([0_u8; L]) - } -} - -impl AsRef<[u8]> for Secret { - #[inline(always)] - fn as_ref(&self) -> &[u8] { - &self.0 - } -} - -impl AsRef<[u8; L]> for Secret { - #[inline(always)] - fn as_ref(&self) -> &[u8; L] { - &self.0 - } -} - -impl AsMut<[u8]> for Secret { - #[inline(always)] - fn as_mut(&mut self) -> &mut [u8] { - &mut self.0 - } -} - -impl AsMut<[u8; L]> for Secret { - #[inline(always)] - fn as_mut(&mut self) -> &mut [u8; L] { - &mut self.0 - } -} diff --git a/crypto-glue/src/x25519.rs b/crypto-glue/src/x25519.rs deleted file mode 100644 index f982fb0..0000000 --- a/crypto-glue/src/x25519.rs +++ /dev/null @@ -1,181 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * (c) ZeroTier, Inc. - * https://www.zerotier.com/ - */ - -use std::convert::TryInto; -use std::io::Write; - -use ed25519_dalek::Digest; - -use crate::random::SecureRandom; -use crate::secret::Secret; - -pub const C25519_PUBLIC_KEY_SIZE: usize = 32; -pub const C25519_SECRET_KEY_SIZE: usize = 32; -pub const C25519_SHARED_SECRET_SIZE: usize = 32; -pub const ED25519_PUBLIC_KEY_SIZE: usize = 32; -pub const ED25519_SECRET_KEY_SIZE: usize = 32; -pub const ED25519_SIGNATURE_SIZE: usize = 64; - -/// Curve25519 key pair for ECDH key agreement. -pub struct X25519KeyPair(x25519_dalek::StaticSecret, Secret<32>, x25519_dalek::PublicKey); - -impl X25519KeyPair { - pub fn generate() -> X25519KeyPair { - let sk = x25519_dalek::StaticSecret::new(SecureRandom::get()); - let sk2 = Secret(sk.to_bytes()); - let pk = x25519_dalek::PublicKey::from(&sk); - X25519KeyPair(sk, sk2, pk) - } - - pub fn from_bytes(public_key: &[u8], secret_key: &[u8]) -> Option { - if public_key.len() == 32 && secret_key.len() == 32 { - /* NOTE: we keep the original secret separately from x25519_dalek's StaticSecret - * due to how "clamping" is done in the old C++ code vs x25519_dalek. Clamping - * is explained here: - * - * https://www.jcraige.com/an-explainer-on-ed25519-clamping - * - * The old code does clamping at the time of use. In other words the code that - * performs things like key agreement or signing clamps the secret before doing - * the operation. The x25519_dalek code does clamping at generation or when - * from() is used to get a key from a raw byte array. - * - * Unfortunately this introduces issues when interoperating with old code. The - * old system generates secrets that are not clamped (since they're clamped at - * use!) and assumes that these exact binary keys will be preserved in e.g. - * identities. So to preserve this behavior we store the secret separately - * so secret_bytes() will return it as-is. - * - * The new code will still clamp at generation resulting in secrets that are - * pre-clamped, but the old code won't care about this. It's only a problem when - * going the other way. - * - * This has no cryptographic implication since regardless of where, the clamping - * is done. It's just an API thing. - */ - let pk: [u8; 32] = public_key.try_into().unwrap(); - let sk_orig: Secret<32> = Secret(secret_key.try_into().unwrap()); - let pk = x25519_dalek::PublicKey::from(pk); - let sk = x25519_dalek::StaticSecret::from(sk_orig.0); - Some(X25519KeyPair(sk, sk_orig, pk)) - } else { - None - } - } - - #[inline(always)] - pub fn public_bytes(&self) -> [u8; C25519_PUBLIC_KEY_SIZE] { - self.2.to_bytes() - } - - #[inline(always)] - pub fn secret_bytes(&self) -> &Secret<32> { - &self.1 - } - - /// Execute ECDH agreement and return a raw (un-hashed) shared secret key. - pub fn agree(&self, their_public: &[u8]) -> Secret<{ C25519_SHARED_SECRET_SIZE }> { - let pk: [u8; 32] = their_public.try_into().unwrap(); - let pk = x25519_dalek::PublicKey::from(pk); - let sec = self.0.diffie_hellman(&pk); - Secret(sec.to_bytes()) - } -} - -impl Clone for X25519KeyPair { - fn clone(&self) -> Self { - Self( - x25519_dalek::StaticSecret::from(self.0.to_bytes()), - self.1.clone(), - x25519_dalek::PublicKey::from(self.1 .0), - ) - } -} - -/// Ed25519 key pair for EDDSA signatures. -pub struct Ed25519KeyPair(ed25519_dalek::Keypair, Secret<32>); - -impl Ed25519KeyPair { - pub fn generate() -> Ed25519KeyPair { - let mut rng = SecureRandom::get(); - let kp = ed25519_dalek::Keypair::generate(&mut rng); - let sk2 = Secret(kp.secret.to_bytes()); - Ed25519KeyPair(kp, sk2) - } - - pub fn from_bytes(public_bytes: &[u8], secret_bytes: &[u8]) -> Option { - if public_bytes.len() == ED25519_PUBLIC_KEY_SIZE && secret_bytes.len() == ED25519_SECRET_KEY_SIZE { - let pk = ed25519_dalek::PublicKey::from_bytes(public_bytes); - let sk = ed25519_dalek::SecretKey::from_bytes(secret_bytes); - if pk.is_ok() && sk.is_ok() { - // See comment in from_bytes() in C25519KeyPair for an explanation of the copy of the secret here. - let pk = pk.unwrap(); - let sk = sk.unwrap(); - let sk2 = Secret(sk.to_bytes()); - Some(Ed25519KeyPair(ed25519_dalek::Keypair { public: pk, secret: sk }, sk2)) - } else { - None - } - } else { - None - } - } - - #[inline(always)] - pub fn public_bytes(&self) -> [u8; ED25519_PUBLIC_KEY_SIZE] { - self.0.public.to_bytes() - } - - #[inline(always)] - pub fn secret_bytes(&self) -> &Secret<32> { - &self.1 - } - - pub fn sign(&self, msg: &[u8]) -> [u8; ED25519_SIGNATURE_SIZE] { - let mut h = ed25519_dalek::Sha512::new(); - let _ = h.write_all(msg); - self.0.sign_prehashed(h.clone(), None).unwrap().to_bytes() - } - - /// Create a signature with the first 32 bytes of the SHA512 hash appended. - /// ZeroTier does this for legacy reasons, but it's ignored in newer versions. - pub fn sign_zt(&self, msg: &[u8]) -> [u8; 96] { - let mut h = ed25519_dalek::Sha512::new(); - let _ = h.write_all(msg); - let sig = self.0.sign_prehashed(h.clone(), None).unwrap(); - let s = sig.as_ref(); - let mut s2 = [0_u8; 96]; - s2[0..64].copy_from_slice(s); - let h = h.finalize(); - s2[64..96].copy_from_slice(&h.as_slice()[0..32]); - s2 - } -} - -impl Clone for Ed25519KeyPair { - fn clone(&self) -> Self { - Self( - ed25519_dalek::Keypair::from_bytes(&self.0.to_bytes()).unwrap(), - self.1.clone(), - ) - } -} - -pub fn ed25519_verify(public_key: &[u8], signature: &[u8], msg: &[u8]) -> bool { - if public_key.len() == 32 && signature.len() >= 64 { - ed25519_dalek::PublicKey::from_bytes(public_key).map_or(false, |pk| { - let mut h = ed25519_dalek::Sha512::new(); - let _ = h.write_all(msg); - let sig: [u8; 64] = signature[0..64].try_into().unwrap(); - pk.verify_prehashed(h, None, &ed25519_dalek::Signature::from(sig)) - .is_ok() - }) - } else { - false - } -} diff --git a/openssl-sys/CHANGELOG.md b/openssl-sys/CHANGELOG.md deleted file mode 100644 index 1bf8690..0000000 --- a/openssl-sys/CHANGELOG.md +++ /dev/null @@ -1,411 +0,0 @@ -# Change Log - -## [Unreleased] - -## [v0.9.80] - 2022-12-20 - -### Fixed - -* Added `NO_DEPRECATED_3_0` cfg checks for more APIs. - -### Added - -* Added support for LibreSSL 3.7.0. -* Added `SSL_CTRL_CHAIN_CERT` and `SSL_add0_chain_cert`. -* Added `EVP_PKEY_get_security_bits` and `EVP_PKEY_security_bits`. -* Added `OSSL_PROVIDER_set_default_search_path`. - -## [v0.9.79] - 2022-12-06 - -### Added - -* Added `EVP_CIPHER_CTX_num`. -* Added `X509_LOOKUP_file` and `X509_load_cert_file`. - -## [v0.9.78] - 2022-11-23 - -### Added - -* Added support for LibreSSL 3.6.x. -* Added `NID_brainpoolP256r1`, `NID_brainpoolP384r1`, and `NID_brainpool512r1`. -* Added `EVP_camellia_128_cfb128`, `EVP_camellia_128_ecb`, `EVP_camellia_192_cfb128`, `EVP_camellia_192_ecb`, - `EVP_camellia_256_cfb128`, and `EVP_camellia_256_ecb`. -* Added `EVP_cast5_cfb64` and `EVP_cast5_ecb`. -* Added `EVP_idea_cfb64` and `EVP_idea_ecb`. -* Added `DSA_SIG`, `d2i_DSA_SIG`, `i2d_DSA_SIG`, `DSA_SIG_new`, `DSA_SIG_free`, `DSA_SIG_get0`, and `DSA_SIG_set0`. -* Added `X509_STORE_set1_param`, `X509_VERIFY_PARAM_new`, `X509_VERIFY_PARAM_set_time`, and - `X509_VERIFY_PARAM_set_depth`. - -## [v0.9.77] - 2022-10-22 - -### Added - -* Added support for LibreSSL 3.6.0 -* Added `assume_init`. - -## [v0.9.76] - 2022-09-26 - -### Added - -* Added `SSL_get_psk_identity_hint` and `SSL_get_psk_identity`. -* Added SHA-3 NID constants. -* Added `SSL_OP_PRIORITIZE_CHACHA`. -* Added `X509_REQ_print`. -* Added `EVP_MD_CTX_size` and `EVP_MD_CTX_get_size` -* Added `EVP_MD_CTX_reset`. -* Added experimental, unstable support for BoringSSL. - -### Fixed - -* Fixed the deprecation note on `SSL_CTX_set_alpn_select_cb`. - -## [v0.9.75] - 2022-07-09 - -### Added - -* Added SM4 bindings. -* Added `EC_GROUP_set_generator` and `EC_POINT_set_affine_coordinates_GFp`. - -## [v0.9.74] - 2022-06-01 - -### Added - -* Added `EVP_MD_block_size`. -* Added `X509V3_EXT_add_alias`. -* Added `X509_V_ERR_INVALID_CA` back when building against OpenSSL 3.0. - -## [v0.9.73] - 2022-05-02 - -### Added - -* Added support for installations that place libraries in `$OPENSSL_DIR/lib64` in addition to `$OPENSSL_DIR/lib`. -* Added `X509_issuer_name_hash`. -* Added `ASN1_string_set`. -* Added `X509_CRL_dup`, `X509_REQ_dup`, `X509_NAME_dup`, and `X509_dup`. -* Added `X509_print`. -* Added support for LibreSSL 3.5.x. - -## [v0.9.72] - 2021-12-11 - -### Changed - -* Temporarily downgraded the vendored OpenSSL back to 1.1.1 due to significant performance regressions. We will move - back to 3.0.0 when a future release resolves those issues. - -### Added - -* Added `PKCS12_set_mac`. -* Added `EVP_PKEY_sign_init`, `EVP_PKEY_sign`, `EVP_PKEY_verify_init`, and `EVP_PKEY_verify`. -* Added support for LibreSSL 3.4.x. - -## [v0.9.71] - -### Fixed - -* Fixed linkage to static OpenSSL 3.0.0 libraries on some 32 bit Android targets. - -### Added - -* Added support for LibreSSL 3.4.1. -* Added `SSL_get_extms_support` and `SSL_CTRL_GET_EXTMS_SUPPORT`. -* Added `OBJ_create`. -* Added `EVP_CIPHER_CTX_get0_cipher`, `EVP_CIPHER_CTX_get_block_size`, `EVP_CIPHER_CTX_get_key_length`, - `EVP_CIPHER_CTX_get_iv_length`, and `EVP_CIPHER_CTX_get_tag_length`. -* Added `EVP_CIPHER_free`. -* Added `EVP_CIPHER_CTX_rand_key`. -* Added `OSSL_LIB_CTX_new` and `OSSL_LIB_CTX_free`. -* Added `EVP_CIPHER_fetch`. -* Added `EVP_MD_fetch` and `EVP_MD_free`. -* Added `OPENSSL_malloc` and `OPENSSL_free`. -* Added `EVP_DigestSignUpdate` and `EVP_DigestVerifyUpdate`. - -## [v0.9.70] - 2021-10-31 - -### Fixed - -* Fixed linkage to static 3.0.0 OpenSSL libraries on some 32 bit architectures. - -## [v0.9.69] - 2021-10-31 - -### Changed - -* Upgraded the vendored OpenSSL to 3.0.0. - -### Added - -* Added support for automatic detection of Homebrew `openssl@3` installs. -* Added `EVP_PKEY_Q_keygen` and `EVP_EC_gen`. - -## [v0.9.68] - 2021-10-27 - -### Added - -* Added `BN_bn2binpad`. -* Added `i2d_X509_NAME` and `d2i_X509_NAME`. -* Added `BN_FLG_MALLOCED`, `BN_FLG_STATIC_DATA`, `BN_FLG_CONSTTIME`, and `BN_FLG_SECURE`. -* Added `BN_CTX_secure_new`, `BN_secure_new`, `BN_set_flags`, and `BN_get_flags`. - -## [v0.9.67] - 2021-09-21 - -### Added - -* Added support for LibreSSL 3.4.0 - -## [v0.9.66] - 2021-08-17 - -### Added - -* Added `EVP_seed_cbc`, `EVP_seed_cfb128`, `EVP_seed_ecb`, and `EVP_seed_ofb`. -* Added `OBJ_length` and `OBJ_get0_data`. -* Added `i2d_PKCS8PrivateKey_bio`. - -## [v0.9.65] - 2021-06-21 - -### Fixed - -* Restored the accidentally deleted `PEM_read_bio_X509_CRL` function. - -## [v0.9.64] - 2021-06-18 - -### Added - -* Added support for OpenSSL 3.x.x. -* Added `SSL_peek`. -* Added `ERR_LIB_ASN1` and `ASN1_R_HEADER_TOO_LONG`. -* Added `d2i_X509_bio`. -* Added `OBJ_nid2obj`. -* Added `RAND_add`. -* Added `SSL_CTX_set_post_handshake_auth`. -* Added `COMP_get_type`. -* Added `X509_get_default_cert_file_env`, `X509_get_default_cert_file`, `X509_get_default_cert_dir_env`, and - `X509_get_default_cirt_dir`. - -## [v0.9.63] - 2021-05-06 - -### Added - -* Added support for LibreSSL 3.3.x. - -## [v0.9.62] - 2021-04-28 - -### Added - -* Added support for LibreSSL 3.3.2. -* Added `DH_set0_key`. -* Added `EC_POINT_get_affine_coordinates`. - -## [v0.9.61] - 2021-03-13 - -### Added - -* Added support for automatic detection of OpenSSL installations via pkgsrc and MacPorts on macOS. -* Added various `V_ASN1_*` constants. -* Added `DH_generate_parameters_ex`. -* Added `EC_POINT_is_at_infinity` and `EC_POINT_is_on_curve`. -* Added `EVP_CIPHER_nid`. -* Added `EVP_sm3`. -* Added `NID_*` constants related to SM3. -* Added `PKCS7_get0_signers`. -* Added `EVP_PKEY_CTX_set0_rsa_oaep_label`. -* Added `ACCESS_DESCRIPTION` and `ACCESS_DESCRIPTION_free`. - -## [v0.9.60] - 2020-12-24 - -### Added - -* Added support for the default Homebrew install directory on ARM. -* Added `EVP_PKEY_CTX_set_rsa_oaep_md` and `EVP_PKEY_CTRL_RSA_OAEP_MD`. - -## [v0.9.59] - 2020-12-09 - -### Added - -* Added support for LibreSSL 3.2.x, 3.3.0, and 3.3.1. -* Added `DH_generate_parameters`, `DH_generate_key`, `DH_compute_key`, and `DH_size`. -* Added `NID_X25519`, `NID_X448`, `EVP_PKEY_x25519` and `EVP_PKEY_x448`. -* Added `OBJ_txt2obj`. -* Added `d2i_PKCS7` and `i2d_PKCS7`. -* Added `SRTP_AEAD_AES_128_GCM` and `SRTP_AEAD_AES_256_GCM`. - -## [v0.9.58] - 2020-06-05 - -### Added - -* Added `SSL_set_mtu`. -* Added support for LibreSSL 3.2.0. -* Added `PEM_read_bio_EC_PUBKEY`, `PEM_write_bio_EC_PUBKEY`, `d2i_EC_PUBKEY`, and `i2d_EC_PUBKEY`. -* Added `EVP_PKEY_encrypt_init`, `EVP_PKEY_encrypt`, `EVP_PKEY_decrypt_init`, `EVP_PKEY_decrypt`, - `EVP_PKEY_get_raw_public_key`, `EVP_PKEY_new_raw_public_key`, `EVP_PKEY_get_raw_private_key`, - and `EVP_PKEY_new_raw_private_key`. -* Added `OBJ_sn2nid`. - -## [v0.9.57] - 2020-05-24 - -### Added - -* Added support for LibreSSL 3.1.x. - -## [v0.9.56] - 2020-05-07 - -### Fixed - -* Fixed vendored builds on windows-gnu targets. - -### Added - -* Added support for LibreSSL 3.0.0. - -## [v0.9.55] - 2020-04-07 - -### Fixed - -* Fixed windows-msvc library names when using OpenSSL from vcpkg. - -### Added - -* If the `OPENSSL_NO_VENDOR` environment variable is set, vendoring will not be used even if enabled. -* Added `SSL_CTX_get_verify_mode` and `SSL_get_verify_mode`. -* Added `SSL_is_init_finished`. -* Added `SSL_CTX_set_cert_store`. -* Added `TLS_server_method` and `TLS_client_method`. -* Added `X509_STORE_get0_objects`. -* Added `X509_OBJECT_free`, `X509_OBJECT_get_type`, and `X509_OBJECT_get0_X509`. - -## [v0.9.54] - 2020-01-29 - -### Added - -* Added `BIO_CTRL_DGRAM_QUERY_MTU`. -* Added `EVP_EncryptInit_ex`, `EVP_EncryptFinal_ex`, `EVP_DecryptInit_ex`, and `EVP_DecryptFinal_ex`. -* Added `EVP_md_null`. -* Added `EVP_PKCS82PKEY`. -* Added `PKCS8_PRIV_KEY_INFO`, `d2i_PKCS8_PRIV_KEY_INFO`, and `PKCS8_PRIV_KEY_INFO_free`. -* Added `SSL_OP_NO_RENEGOTIATION`. - -## [v0.9.53] - 2019-11-22 - -### Added - -* Added `ASN1_TIME_diff`. -* Added `EC_GROUP_order_bits`. -* Added `EVP_EncodeBlock` and `EVP_DecodeBlock`. -* Added `SSL_CTRL_SET_GROUPS_LIST`, `SSL_CTRL_SET_SIGALGS_LIST`, `SSL_CTX_set1_groups_list`, and - `SSL_CTX_set1_sigalgs_list`. -* Added `Clone` implementations to `SHA_CTX`, `SHA256_CTX`, and `SHA512_CTX`. - -## [v0.9.52] - 2019-10-19 - -### Added - -* Added support for LibreSSL 3.0.x. - -## [v0.9.51] - 2019-10-02 - -### Added - -* Added support for LibreSSL 3.0.1. - -## [v0.9.50] - 2019-10-02 - -### Added - -* Added `CRYPTO_LOCK_EVP_PKEY`. -* Added `EVP_PKEY_ED25519` and `EVP_PKEY_ED448`. -* Added `EVP_DigestSign` and `EVP_DigestVerify`. -* Added `EVP_PKEY_up_ref`. -* Added `NID_ED25519` and `NID_ED448`. - -## [v0.9.49] - 2019-08-15 - -### Added - -* Added support for LibreSSL 3.0.0. - -## [v0.9.48] - 2019-07-19 - -### Added - -* Added `AES_wrap_key` and `AES_unwrap_key`. -* Added `EC_GROUP_get_cofactor`, `EC_GROUP_get0_generator`, and `EC_POINT_dup`. -* Added `EVP_aes_128_ofb`, `EVP_aes_192_ecb`, `EVP_aes_192_cbc`, `EVP_aes_192_cfb1`, `EVP_aes_192_cfb8`, - `EVP_aes_192_cfb_128`, `EVP_aes_192_ctr`, `EVP_aes_192_ccm`, `EVP_aes_192_gcm`, `EVP_aes_192_ofb`, and - `EVP_aes_256_ofb`. -* Added `PEM_read_bio_CMS` and `PEM_write_bio_CMS`. - -## [v0.9.47] - 2019-05-18 - -### Added - -* Added `SSL_CTX_add_client_CA`. - -## [v0.9.46] - 2019-05-08 - -### Added - -* Added support for the LibreSSL 2.9.x series. - -## [v0.9.45] - 2019-05-03 - -### Fixed - -* Reverted a change to windows-gnu library names that caused regressions. - -## [v0.9.44] - 2019-04-30 - -### Added - -* The `DEP_OPENSSL_VENDORED` environment variable tells downstream build scripts if the vendored feature was enabled. -* Added `EVP_SealInit`, `EVP_SealFinal`, `EVP_EncryptUpdate`, `EVP_OpenInit`, `EVP_OpenFinal`, and `EVP_DecryptUpdate`. -* Added `EVP_PKEY_size`. - -### Fixed - -* Fixed library names when targeting windows-gnu and pkg-config fails. - -## [v0.9.43] - 2019-03-20 - -### Added - -* Added `d2i_CMS_ContentInfo` and `CMS_encrypt`. -* Added `X509_verify` and `X509_REQ_verify`. -* Added `EVP_MD_type` and `EVP_GROUP_get_curve_name`. - -[Unreleased]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.80..master -[v0.9.80]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.79...openssl-sys-v0.9.80 -[v0.9.79]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.78...openssl-sys-v0.9.79 -[v0.9.78]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.77...openssl-sys-v0.9.78 -[v0.9.77]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.76...openssl-sys-v0.9.77 -[v0.9.76]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.75...openssl-sys-v0.9.76 -[v0.9.75]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.74...openssl-sys-v0.9.75 -[v0.9.74]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.73...openssl-sys-v0.9.74 -[v0.9.73]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.72...openssl-sys-v0.9.73 -[v0.9.72]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.71...openssl-sys-v0.9.72 -[v0.9.71]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.70...openssl-sys-v0.9.71 -[v0.9.70]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.69...openssl-sys-v0.9.70 -[v0.9.69]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.68...openssl-sys-v0.9.69 -[v0.9.68]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.67...openssl-sys-v0.9.68 -[v0.9.67]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.66...openssl-sys-v0.9.67 -[v0.9.66]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.65...openssl-sys-v0.9.66 -[v0.9.65]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.64...openssl-sys-v0.9.65 -[v0.9.64]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.63...openssl-sys-v0.9.64 -[v0.9.63]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.62...openssl-sys-v0.9.63 -[v0.9.62]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.61...openssl-sys-v0.9.62 -[v0.9.61]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.60...openssl-sys-v0.9.61 -[v0.9.60]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.59...openssl-sys-v0.9.60 -[v0.9.59]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.58...openssl-sys-v0.9.59 -[v0.9.58]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.57...openssl-sys-v0.9.58 -[v0.9.57]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.56...openssl-sys-v0.9.57 -[v0.9.56]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.55...openssl-sys-v0.9.56 -[v0.9.55]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.54...openssl-sys-v0.9.55 -[v0.9.54]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.53...openssl-sys-v0.9.54 -[v0.9.53]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.52...openssl-sys-v0.9.53 -[v0.9.52]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.51...openssl-sys-v0.9.52 -[v0.9.51]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.50...openssl-sys-v0.9.51 -[v0.9.50]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.49...openssl-sys-v0.9.50 -[v0.9.49]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.48...openssl-sys-v0.9.49 -[v0.9.48]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.47...openssl-sys-v0.9.48 -[v0.9.47]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.46...openssl-sys-v0.9.47 -[v0.9.46]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.45...openssl-sys-v0.9.46 -[v0.9.45]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.44...openssl-sys-v0.9.45 -[v0.9.44]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.43...openssl-sys-v0.9.44 -[v0.9.43]: https://github.com/sfackler/rust-openssl/compare/openssl-sys-v0.9.42...openssl-sys-v0.9.43 diff --git a/openssl-sys/Cargo.toml b/openssl-sys/Cargo.toml deleted file mode 100644 index 56810ec..0000000 --- a/openssl-sys/Cargo.toml +++ /dev/null @@ -1,36 +0,0 @@ -[package] -name = "openssl-sys" -version = "0.9.80" -authors = [ - "Alex Crichton ", - "Steven Fackler ", -] -license = "MIT" -description = "FFI bindings to OpenSSL" -repository = "https://github.com/sfackler/rust-openssl" -readme = "README.md" -categories = ["cryptography", "external-ffi-bindings"] -links = "openssl" -build = "build/main.rs" -edition = "2018" - -[features] -vendored = ['openssl-src'] - -[dependencies] -libc = "0.2" -#bssl-sys = { version = "0.1.0", optional = true }#package does not seem needed for ZT - -[build-dependencies] -bindgen = { version = "0.64.0", optional = true } -cc = "1.0" -openssl-src = { version = "300.0.12", optional = true } -pkg-config = "0.3.9" -autocfg = "1.0" - -[target.'cfg(target_env = "msvc")'.build-dependencies] -vcpkg = "0.2.8" - -# We don't actually use metadeps for annoying reasons but this is still here for tooling -[package.metadata.pkg-config] -openssl = "1.1.0" diff --git a/openssl-sys/LICENSE-MIT b/openssl-sys/LICENSE-MIT deleted file mode 100644 index 39e0ed6..0000000 --- a/openssl-sys/LICENSE-MIT +++ /dev/null @@ -1,25 +0,0 @@ -Copyright (c) 2014 Alex Crichton - -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/openssl-sys/README.md b/openssl-sys/README.md deleted file mode 120000 index 32d46ee..0000000 --- a/openssl-sys/README.md +++ /dev/null @@ -1 +0,0 @@ -../README.md \ No newline at end of file diff --git a/openssl-sys/build/cfgs.rs b/openssl-sys/build/cfgs.rs deleted file mode 100644 index d925d90..0000000 --- a/openssl-sys/build/cfgs.rs +++ /dev/null @@ -1,94 +0,0 @@ -pub fn get(openssl_version: Option, libressl_version: Option) -> Vec<&'static str> { - let mut cfgs = vec![]; - - if let Some(libressl_version) = libressl_version { - cfgs.push("libressl"); - - if libressl_version >= 0x2_05_01_00_0 { - cfgs.push("libressl251"); - } - if libressl_version >= 0x2_05_02_00_0 { - cfgs.push("libressl252"); - } - if libressl_version >= 0x2_06_01_00_0 { - cfgs.push("libressl261"); - } - if libressl_version >= 0x2_07_00_00_0 { - cfgs.push("libressl270"); - } - if libressl_version >= 0x2_07_01_00_0 { - cfgs.push("libressl271"); - } - if libressl_version >= 0x2_07_03_00_0 { - cfgs.push("libressl273"); - } - if libressl_version >= 0x2_08_00_00_0 { - cfgs.push("libressl280"); - } - if libressl_version >= 0x2_08_01_00_0 { - cfgs.push("libressl281"); - } - if libressl_version >= 0x2_09_01_00_0 { - cfgs.push("libressl291"); - } - if libressl_version >= 0x3_02_01_00_0 { - cfgs.push("libressl321"); - } - if libressl_version >= 0x3_03_02_00_0 { - cfgs.push("libressl332"); - } - if libressl_version >= 0x3_04_00_00_0 { - cfgs.push("libressl340"); - } - if libressl_version >= 0x3_05_00_00_0 { - cfgs.push("libressl350"); - } - if libressl_version >= 0x3_06_00_00_0 { - cfgs.push("libressl360"); - } - if libressl_version >= 0x3_07_00_00_0 { - cfgs.push("libressl370"); - } - } else { - let openssl_version = openssl_version.unwrap(); - - if openssl_version >= 0x3_00_00_00_0 { - cfgs.push("ossl300"); - } - if openssl_version >= 0x1_00_01_00_0 { - cfgs.push("ossl101"); - } - if openssl_version >= 0x1_00_02_00_0 { - cfgs.push("ossl102"); - } - if openssl_version >= 0x1_00_02_06_0 { - cfgs.push("ossl102f"); - } - if openssl_version >= 0x1_00_02_08_0 { - cfgs.push("ossl102h"); - } - if openssl_version >= 0x1_01_00_00_0 { - cfgs.push("ossl110"); - } - if openssl_version >= 0x1_01_00_06_0 { - cfgs.push("ossl110f"); - } - if openssl_version >= 0x1_01_00_07_0 { - cfgs.push("ossl110g"); - } - if openssl_version >= 0x1_01_00_08_0 { - cfgs.push("ossl110h"); - } - if openssl_version >= 0x1_01_01_00_0 { - cfgs.push("ossl111"); - } - if openssl_version >= 0x1_01_01_02_0 { - cfgs.push("ossl111b"); - } - if openssl_version >= 0x1_01_01_03_0 { - cfgs.push("ossl111c"); - } - } - - cfgs -} diff --git a/openssl-sys/build/expando.c b/openssl-sys/build/expando.c deleted file mode 100644 index 11fb04d..0000000 --- a/openssl-sys/build/expando.c +++ /dev/null @@ -1,124 +0,0 @@ -#include -#include - -#define VERSION2(n, v) RUST_VERSION_##n##_##v -#define VERSION(n, v) VERSION2(n, v) - -#define NEW_VERSION2(a, b, c) RUST_VERSION_NEW_OPENSSL_##a##_##b##_##c -#define NEW_VERSION(a, b, c) NEW_VERSION2(a, b, c) - -#ifdef LIBRESSL_VERSION_NUMBER -VERSION(LIBRESSL, LIBRESSL_VERSION_NUMBER) -#elif defined OPENSSL_VERSION_MAJOR -NEW_VERSION(OPENSSL_VERSION_MAJOR, OPENSSL_VERSION_MINOR, OPENSSL_VERSION_PATCH) -#else -VERSION(OPENSSL, OPENSSL_VERSION_NUMBER) -#endif - -#ifdef OPENSSL_IS_BORINGSSL -RUST_OPENSSL_IS_BORINGSSL -#endif - -#ifdef OPENSSL_NO_BF -RUST_CONF_OPENSSL_NO_BF -#endif - -#ifdef OPENSSL_NO_BUF_FREELISTS -RUST_CONF_OPENSSL_NO_BUF_FREELISTS -#endif - -#ifdef OPENSSL_NO_CHACHA -RUST_CONF_OPENSSL_NO_CHACHA -#endif - -#ifdef OPENSSL_NO_IDEA -RUST_CONF_OPENSSL_NO_IDEA -#endif - -#ifdef OPENSSL_NO_CAMELLIA -RUST_CONF_OPENSSL_NO_CAMELLIA -#endif - -#ifdef OPENSSL_NO_CAST -RUST_CONF_OPENSSL_NO_CAST -#endif - -#ifdef OPENSSL_NO_CMS -RUST_CONF_OPENSSL_NO_CMS -#endif - -#ifdef OPENSSL_NO_COMP -RUST_CONF_OPENSSL_NO_COMP -#endif - -#ifdef OPENSSL_NO_EC -RUST_CONF_OPENSSL_NO_EC -#endif - -#ifdef OPENSSL_NO_EC2M -RUST_CONF_OPENSSL_NO_EC2M -#endif - -#ifdef OPENSSL_NO_ENGINE -RUST_CONF_OPENSSL_NO_ENGINE -#endif - -#ifdef OPENSSL_NO_KRB5 -RUST_CONF_OPENSSL_NO_KRB5 -#endif - -#ifdef OPENSSL_NO_NEXTPROTONEG -RUST_CONF_OPENSSL_NO_NEXTPROTONEG -#endif - -#ifdef OPENSSL_NO_OCSP -RUST_CONF_OPENSSL_NO_OCSP -#endif - -#ifdef OPENSSL_NO_PSK -RUST_CONF_OPENSSL_NO_PSK -#endif - -#ifdef OPENSSL_NO_RFC3779 -RUST_CONF_OPENSSL_NO_RFC3779 -#endif - -#ifdef OPENSSL_NO_RMD160 -RUST_CONF_OPENSSL_NO_RMD160 -#endif - -#ifdef OPENSSL_NO_SHA -RUST_CONF_OPENSSL_NO_SHA -#endif - -#ifdef OPENSSL_NO_SRP -RUST_CONF_OPENSSL_NO_SRP -#endif - -#ifdef OPENSSL_NO_SSL3_METHOD -RUST_CONF_OPENSSL_NO_SSL3_METHOD -#endif - -#ifdef OPENSSL_NO_TLSEXT -RUST_CONF_OPENSSL_NO_TLSEXT -#endif - -#ifdef OPENSSL_NO_STDIO -RUST_CONF_OPENSSL_NO_STDIO -#endif - -#ifdef OPENSSL_NO_SM3 -RUST_CONF_OPENSSL_NO_SM3 -#endif - -#ifdef OPENSSL_NO_SM4 -RUST_CONF_OPENSSL_NO_SM4 -#endif - -#ifdef OPENSSL_NO_DEPRECATED_3_0 -RUST_CONF_OPENSSL_NO_DEPRECATED_3_0 -#endif - -#ifdef OPENSSL_NO_SEED -RUST_CONF_OPENSSL_NO_SEED -#endif diff --git a/openssl-sys/build/find_normal.rs b/openssl-sys/build/find_normal.rs deleted file mode 100644 index 742d143..0000000 --- a/openssl-sys/build/find_normal.rs +++ /dev/null @@ -1,266 +0,0 @@ -use std::ffi::OsString; -use std::path::{Path, PathBuf}; -use std::process::{self, Command}; - -use super::env; - -pub fn get_openssl(target: &str) -> (Vec, PathBuf) { - let lib_dir = env("OPENSSL_LIB_DIR").map(PathBuf::from); - let include_dir = env("OPENSSL_INCLUDE_DIR").map(PathBuf::from); - - match (lib_dir, include_dir) { - (Some(lib_dir), Some(include_dir)) => (vec![lib_dir], include_dir), - (lib_dir, include_dir) => { - let openssl_dir = env("OPENSSL_DIR").unwrap_or_else(|| find_openssl_dir(target)); - let openssl_dir = Path::new(&openssl_dir); - let lib_dir = lib_dir.map(|d| vec![d]).unwrap_or_else(|| { - let mut lib_dirs = vec![]; - // OpenSSL 3.0 now puts it's libraries in lib64/ by default, - // check for both it and lib/. - if openssl_dir.join("lib64").exists() { - lib_dirs.push(openssl_dir.join("lib64")); - } - if openssl_dir.join("lib").exists() { - lib_dirs.push(openssl_dir.join("lib")); - } - lib_dirs - }); - let include_dir = include_dir.unwrap_or_else(|| openssl_dir.join("include")); - (lib_dir, include_dir) - } - } -} - -fn resolve_with_wellknown_homebrew_location(dir: &str) -> Option { - let versions = ["openssl@3", "openssl@1.1"]; - - // Check up default aarch 64 Homebrew installation location first - // for quick resolution if possible. - // `pkg-config` on brew doesn't necessarily contain settings for openssl apparently. - for version in &versions { - let homebrew = Path::new(dir).join(format!("opt/{}", version)); - if homebrew.exists() { - return Some(homebrew); - } - } - - for version in &versions { - // Calling `brew --prefix ` command usually slow and - // takes seconds, and will be used only as a last resort. - let output = execute_command_and_get_output("brew", &["--prefix", version]); - if let Some(ref output) = output { - let homebrew = Path::new(&output); - if homebrew.exists() { - return Some(homebrew.to_path_buf()); - } - } - } - - None -} - -fn resolve_with_wellknown_location(dir: &str) -> Option { - let root_dir = Path::new(dir); - let include_openssl = root_dir.join("include/openssl"); - if include_openssl.exists() { - Some(root_dir.to_path_buf()) - } else { - None - } -} - -fn find_openssl_dir(target: &str) -> OsString { - let host = env::var("HOST").unwrap(); - - if host == target && target.ends_with("-apple-darwin") { - let homebrew_dir = match target { - "aarch64-apple-darwin" => "/opt/homebrew", - _ => "/usr/local", - }; - - if let Some(dir) = resolve_with_wellknown_homebrew_location(homebrew_dir) { - return dir.into(); - } else if let Some(dir) = resolve_with_wellknown_location("/opt/pkg") { - // pkgsrc - return dir.into(); - } else if let Some(dir) = resolve_with_wellknown_location("/opt/local") { - // MacPorts - return dir.into(); - } - } - - try_pkg_config(); - try_vcpkg(); - - // FreeBSD ships with OpenSSL but doesn't include a pkg-config file :( - if host == target && target.contains("freebsd") { - return OsString::from("/usr"); - } - - // DragonFly has libressl (or openssl) in ports, but this doesn't include a pkg-config file - if host == target && target.contains("dragonfly") { - return OsString::from("/usr/local"); - } - - let mut msg = format!( - " - -Could not find directory of OpenSSL installation, and this `-sys` crate cannot -proceed without this knowledge. If OpenSSL is installed and this crate had -trouble finding it, you can set the `OPENSSL_DIR` environment variable for the -compilation process. - -Make sure you also have the development packages of openssl installed. -For example, `libssl-dev` on Ubuntu or `openssl-devel` on Fedora. - -If you're in a situation where you think the directory *should* be found -automatically, please open a bug at https://github.com/sfackler/rust-openssl -and include information about your system as well as this message. - -$HOST = {} -$TARGET = {} -openssl-sys = {} - -", - host, - target, - env!("CARGO_PKG_VERSION") - ); - - if host.contains("apple-darwin") && target.contains("apple-darwin") { - let system = Path::new("/usr/lib/libssl.0.9.8.dylib"); - if system.exists() { - msg.push_str( - " - -openssl-sys crate build failed: no supported version of OpenSSL found. - -Ways to fix it: -- Use the `vendored` feature of openssl-sys crate to build OpenSSL from source. -- Use Homebrew to install the `openssl` package. - -", - ); - } - } - - if host.contains("unknown-linux") && target.contains("unknown-linux-gnu") && Command::new("pkg-config").output().is_err() { - msg.push_str( - " -It looks like you're compiling on Linux and also targeting Linux. Currently this -requires the `pkg-config` utility to find OpenSSL but unfortunately `pkg-config` -could not be found. If you have OpenSSL installed you can likely fix this by -installing `pkg-config`. - -", - ); - } - - if host.contains("windows") && target.contains("windows-gnu") { - msg.push_str( - " -It looks like you're compiling for MinGW but you may not have either OpenSSL or -pkg-config installed. You can install these two dependencies with: - -pacman -S openssl-devel pkg-config - -and try building this crate again. - -", - ); - } - - if host.contains("windows") && target.contains("windows-msvc") { - msg.push_str( - " -It looks like you're compiling for MSVC but we couldn't detect an OpenSSL -installation. If there isn't one installed then you can try the rust-openssl -README for more information about how to download precompiled binaries of -OpenSSL: - -https://github.com/sfackler/rust-openssl#windows - -", - ); - } - - panic!("{}", msg); -} - -/// Attempt to find OpenSSL through pkg-config. -/// -/// Note that if this succeeds then the function does not return as pkg-config -/// typically tells us all the information that we need. -fn try_pkg_config() { - let target = env::var("TARGET").unwrap(); - let host = env::var("HOST").unwrap(); - - // If we're going to windows-gnu we can use pkg-config, but only so long as - // we're coming from a windows host. - // - // Otherwise if we're going to windows we probably can't use pkg-config. - if target.contains("windows-gnu") && host.contains("windows") { - env::set_var("PKG_CONFIG_ALLOW_CROSS", "1"); - } else if target.contains("windows") { - return; - } - - let lib = match pkg_config::Config::new().print_system_libs(false).probe("openssl") { - Ok(lib) => lib, - Err(e) => { - println!("run pkg_config fail: {:?}", e); - return; - } - }; - - super::postprocess(&lib.include_paths); - - for include in lib.include_paths.iter() { - println!("cargo:include={}", include.display()); - } - - process::exit(0); -} - -/// Attempt to find OpenSSL through vcpkg. -/// -/// Note that if this succeeds then the function does not return as vcpkg -/// should emit all of the cargo metadata that we need. -#[cfg(target_env = "msvc")] -fn try_vcpkg() { - // vcpkg will not emit any metadata if it can not find libraries - // appropriate for the target triple with the desired linkage. - - let lib = match vcpkg::Config::new().emit_includes(true).find_package("openssl") { - Ok(lib) => lib, - Err(e) => { - println!("note: vcpkg did not find openssl: {}", e); - return; - } - }; - - super::postprocess(&lib.include_paths); - - println!("cargo:rustc-link-lib=user32"); - println!("cargo:rustc-link-lib=gdi32"); - println!("cargo:rustc-link-lib=crypt32"); - - process::exit(0); -} - -#[cfg(not(target_env = "msvc"))] -fn try_vcpkg() {} - -fn execute_command_and_get_output(cmd: &str, args: &[&str]) -> Option { - let out = Command::new(cmd).args(args).output(); - if let Ok(ref r1) = out { - if r1.status.success() { - let r2 = String::from_utf8(r1.stdout.clone()); - if let Ok(r3) = r2 { - return Some(r3.trim().to_string()); - } - } - } - - None -} diff --git a/openssl-sys/build/find_vendored.rs b/openssl-sys/build/find_vendored.rs deleted file mode 100644 index 1c654c6..0000000 --- a/openssl-sys/build/find_vendored.rs +++ /dev/null @@ -1,10 +0,0 @@ -use openssl_src; -use std::path::PathBuf; - -pub fn get_openssl(_target: &str) -> (Vec, PathBuf) { - let artifacts = openssl_src::Build::new().build(); - println!("cargo:vendored=1"); - println!("cargo:root={}", artifacts.lib_dir().parent().unwrap().display()); - - (vec![artifacts.lib_dir().to_path_buf()], artifacts.include_dir().to_path_buf()) -} diff --git a/openssl-sys/build/main.rs b/openssl-sys/build/main.rs deleted file mode 100644 index 03e7c1d..0000000 --- a/openssl-sys/build/main.rs +++ /dev/null @@ -1,404 +0,0 @@ -#![allow(clippy::inconsistent_digit_grouping, clippy::uninlined_format_args, clippy::unusual_byte_groupings)] - -extern crate autocfg; -#[cfg(feature = "bindgen")] -extern crate bindgen; -extern crate cc; -#[cfg(feature = "vendored")] -extern crate openssl_src; -extern crate pkg_config; -#[cfg(target_env = "msvc")] -extern crate vcpkg; - -use std::collections::HashSet; -use std::env; -use std::ffi::OsString; -use std::path::{Path, PathBuf}; -mod cfgs; - -mod find_normal; -#[cfg(feature = "vendored")] -mod find_vendored; -#[cfg(feature = "bindgen")] -mod run_bindgen; - -#[derive(PartialEq)] -enum Version { - Openssl3xx, - Openssl11x, - Openssl10x, - Libressl, -} - -fn env_inner(name: &str) -> Option { - let var = env::var_os(name); - println!("cargo:rerun-if-env-changed={}", name); - - match var { - Some(ref v) => println!("{} = {}", name, v.to_string_lossy()), - None => println!("{} unset", name), - } - - var -} - -fn env(name: &str) -> Option { - let prefix = env::var("TARGET").unwrap().to_uppercase().replace('-', "_"); - let prefixed = format!("{}_{}", prefix, name); - env_inner(&prefixed).or_else(|| env_inner(name)) -} - -fn find_openssl(target: &str) -> (Vec, PathBuf) { - #[cfg(feature = "vendored")] - { - // vendor if the feature is present, unless - // OPENSSL_NO_VENDOR exists and isn't `0` - if env("OPENSSL_NO_VENDOR").map_or(true, |s| s == "0") { - return find_vendored::get_openssl(target); - } - } - find_normal::get_openssl(target) -} - -fn check_ssl_kind() { - if cfg!(feature = "unstable_boringssl") { - println!("cargo:rustc-cfg=boringssl"); - // BoringSSL does not have any build logic, exit early - std::process::exit(0); - } else { - println!("cargo:rustc-cfg=openssl"); - } -} - -fn main() { - check_rustc_versions(); - - check_ssl_kind(); - - let target = env::var("TARGET").unwrap(); - - let (lib_dirs, include_dir) = find_openssl(&target); - - if !lib_dirs.iter().all(|p| Path::new(p).exists()) { - panic!("OpenSSL library directory does not exist: {:?}", lib_dirs); - } - if !Path::new(&include_dir).exists() { - panic!("OpenSSL include directory does not exist: {}", include_dir.to_string_lossy()); - } - - for lib_dir in lib_dirs.iter() { - println!("cargo:rustc-link-search=native={}", lib_dir.to_string_lossy()); - } - println!("cargo:include={}", include_dir.to_string_lossy()); - - let version = postprocess(&[include_dir]); - - let libs_env = env("OPENSSL_LIBS"); - let libs = match libs_env.as_ref().and_then(|s| s.to_str()) { - Some(v) => { - if v.is_empty() { - vec![] - } else { - v.split(':').collect() - } - } - None => match version { - Version::Openssl10x if target.contains("windows") => vec!["ssleay32", "libeay32"], - Version::Openssl3xx | Version::Openssl11x if target.contains("windows-msvc") => { - vec!["libssl", "libcrypto"] - } - _ => vec!["ssl", "crypto"], - }, - }; - - let kind = determine_mode(&lib_dirs, &libs); - for lib in libs.into_iter() { - println!("cargo:rustc-link-lib={}={}", kind, lib); - } - - if kind == "static" && target.contains("windows") { - println!("cargo:rustc-link-lib=dylib=gdi32"); - println!("cargo:rustc-link-lib=dylib=user32"); - println!("cargo:rustc-link-lib=dylib=crypt32"); - println!("cargo:rustc-link-lib=dylib=ws2_32"); - println!("cargo:rustc-link-lib=dylib=advapi32"); - } -} - -fn check_rustc_versions() { - let cfg = autocfg::new(); - - if cfg.probe_rustc_version(1, 31) { - println!("cargo:rustc-cfg=const_fn"); - } -} - -#[allow(clippy::let_and_return)] -fn postprocess(include_dirs: &[PathBuf]) -> Version { - let version = validate_headers(include_dirs); - #[cfg(feature = "bindgen")] - run_bindgen::run(&include_dirs); - - version -} - -/// Validates the header files found in `include_dir` and then returns the -/// version string of OpenSSL. -#[allow(clippy::manual_strip)] // we need to support pre-1.45.0 -fn validate_headers(include_dirs: &[PathBuf]) -> Version { - // This `*-sys` crate only works with OpenSSL 1.0.1, 1.0.2, 1.1.0, 1.1.1 and 3.0.0. - // To correctly expose the right API from this crate, take a look at - // `opensslv.h` to see what version OpenSSL claims to be. - // - // OpenSSL has a number of build-time configuration options which affect - // various structs and such. Since OpenSSL 1.1.0 this isn't really a problem - // as the library is much more FFI-friendly, but 1.0.{1,2} suffer this problem. - // - // To handle all this conditional compilation we slurp up the configuration - // file of OpenSSL, `opensslconf.h`, and then dump out everything it defines - // as our own #[cfg] directives. That way the `ossl10x.rs` bindings can - // account for compile differences and such. - println!("cargo:rerun-if-changed=build/expando.c"); - let mut gcc = cc::Build::new(); - for include_dir in include_dirs { - gcc.include(include_dir); - } - let expanded = match gcc.file("build/expando.c").try_expand() { - Ok(expanded) => expanded, - Err(e) => { - panic!( - " -Header expansion error: -{:?} - -Failed to find OpenSSL development headers. - -You can try fixing this setting the `OPENSSL_DIR` environment variable -pointing to your OpenSSL installation or installing OpenSSL headers package -specific to your distribution: - - # On Ubuntu - sudo apt-get install libssl-dev - # On Arch Linux - sudo pacman -S openssl - # On Fedora - sudo dnf install openssl-devel - # On Alpine Linux - apk add openssl-dev - -See rust-openssl documentation for more information: - - https://docs.rs/openssl -", - e - ); - } - }; - let expanded = String::from_utf8(expanded).unwrap(); - - let mut enabled = vec![]; - let mut openssl_version = None; - let mut libressl_version = None; - let mut is_boringssl = false; - for line in expanded.lines() { - let line = line.trim(); - - let openssl_prefix = "RUST_VERSION_OPENSSL_"; - let new_openssl_prefix = "RUST_VERSION_NEW_OPENSSL_"; - let libressl_prefix = "RUST_VERSION_LIBRESSL_"; - let boringsl_prefix = "RUST_OPENSSL_IS_BORINGSSL"; - let conf_prefix = "RUST_CONF_"; - if line.starts_with(openssl_prefix) { - let version = &line[openssl_prefix.len()..]; - openssl_version = Some(parse_version(version)); - } else if line.starts_with(new_openssl_prefix) { - let version = &line[new_openssl_prefix.len()..]; - openssl_version = Some(parse_new_version(version)); - } else if line.starts_with(libressl_prefix) { - let version = &line[libressl_prefix.len()..]; - libressl_version = Some(parse_version(version)); - } else if line.starts_with(conf_prefix) { - enabled.push(&line[conf_prefix.len()..]); - } else if line.starts_with(boringsl_prefix) { - is_boringssl = true; - } - } - - if is_boringssl { - panic!("BoringSSL detected, but `unstable_boringssl` feature wasn't specified.") - } - - for enabled in &enabled { - println!("cargo:rustc-cfg=osslconf=\"{}\"", enabled); - } - println!("cargo:conf={}", enabled.join(",")); - - for cfg in cfgs::get(openssl_version, libressl_version) { - println!("cargo:rustc-cfg={}", cfg); - } - - if let Some(libressl_version) = libressl_version { - println!("cargo:libressl_version_number={:x}", libressl_version); - - let major = (libressl_version >> 28) as u8; - let minor = (libressl_version >> 20) as u8; - let fix = (libressl_version >> 12) as u8; - let (major, minor, fix) = match (major, minor, fix) { - (2, 5, 0) => ('2', '5', '0'), - (2, 5, 1) => ('2', '5', '1'), - (2, 5, 2) => ('2', '5', '2'), - (2, 5, _) => ('2', '5', 'x'), - (2, 6, 0) => ('2', '6', '0'), - (2, 6, 1) => ('2', '6', '1'), - (2, 6, 2) => ('2', '6', '2'), - (2, 6, _) => ('2', '6', 'x'), - (2, 7, _) => ('2', '7', 'x'), - (2, 8, 0) => ('2', '8', '0'), - (2, 8, 1) => ('2', '8', '1'), - (2, 8, _) => ('2', '8', 'x'), - (2, 9, 0) => ('2', '9', '0'), - (2, 9, _) => ('2', '9', 'x'), - (3, 0, 0) => ('3', '0', '0'), - (3, 0, 1) => ('3', '0', '1'), - (3, 0, _) => ('3', '0', 'x'), - (3, 1, 0) => ('3', '1', '0'), - (3, 1, _) => ('3', '1', 'x'), - (3, 2, 0) => ('3', '2', '0'), - (3, 2, 1) => ('3', '2', '1'), - (3, 2, _) => ('3', '2', 'x'), - (3, 3, 0) => ('3', '3', '0'), - (3, 3, 1) => ('3', '3', '1'), - (3, 3, _) => ('3', '3', 'x'), - (3, 4, 0) => ('3', '4', '0'), - (3, 4, _) => ('3', '4', 'x'), - (3, 5, _) => ('3', '5', 'x'), - (3, 6, 0) => ('3', '6', '0'), - (3, 6, _) => ('3', '6', 'x'), - (3, 7, 0) => ('3', '7', '0'), - _ => version_error(), - }; - - println!("cargo:libressl=true"); - println!("cargo:libressl_version={}{}{}", major, minor, fix); - println!("cargo:version=101"); - Version::Libressl - } else { - let openssl_version = openssl_version.unwrap(); - println!("cargo:version_number={:x}", openssl_version); - - if openssl_version >= 0x4_00_00_00_0 { - version_error() - } else if openssl_version >= 0x3_00_00_00_0 { - Version::Openssl3xx - } else if openssl_version >= 0x1_01_01_00_0 { - println!("cargo:version=111"); - Version::Openssl11x - } else if openssl_version >= 0x1_01_00_06_0 { - println!("cargo:version=110"); - println!("cargo:patch=f"); - Version::Openssl11x - } else if openssl_version >= 0x1_01_00_00_0 { - println!("cargo:version=110"); - Version::Openssl11x - } else if openssl_version >= 0x1_00_02_00_0 { - println!("cargo:version=102"); - Version::Openssl10x - } else if openssl_version >= 0x1_00_01_00_0 { - println!("cargo:version=101"); - Version::Openssl10x - } else { - version_error() - } - } -} - -fn version_error() -> ! { - panic!( - " - -This crate is only compatible with OpenSSL (version 1.0.1 through 1.1.1, or 3.0.0), or LibreSSL 2.5 -through 3.7.0, but a different version of OpenSSL was found. The build is now aborting -due to this version mismatch. - -" - ); -} - -// parses a string that looks like "0x100020cfL" -#[allow(deprecated)] // trim_right_matches is now trim_end_matches -#[allow(clippy::match_like_matches_macro)] // matches macro requires rust 1.42.0 -fn parse_version(version: &str) -> u64 { - // cut off the 0x prefix - assert!(version.starts_with("0x")); - let version = &version[2..]; - - // and the type specifier suffix - let version = version.trim_right_matches(|c: char| match c { - '0'..='9' | 'a'..='f' | 'A'..='F' => false, - _ => true, - }); - - u64::from_str_radix(version, 16).unwrap() -} - -// parses a string that looks like 3_0_0 -fn parse_new_version(version: &str) -> u64 { - println!("version: {}", version); - let mut it = version.split('_'); - let major = it.next().unwrap().parse::().unwrap(); - let minor = it.next().unwrap().parse::().unwrap(); - let patch = it.next().unwrap().parse::().unwrap(); - - (major << 28) | (minor << 20) | (patch << 4) -} - -/// Given a libdir for OpenSSL (where artifacts are located) as well as the name -/// of the libraries we're linking to, figure out whether we should link them -/// statically or dynamically. -fn determine_mode(libdirs: &[PathBuf], libs: &[&str]) -> &'static str { - // First see if a mode was explicitly requested - let kind = env("OPENSSL_STATIC"); - match kind.as_ref().and_then(|s| s.to_str()) { - Some("0") => return "dylib", - Some(_) => return "static", - None => {} - } - - // Next, see what files we actually have to link against, and see what our - // possibilities even are. - let mut files = HashSet::new(); - for dir in libdirs { - for path in dir - .read_dir() - .unwrap() - .map(|e| e.unwrap()) - .map(|e| e.file_name()) - .filter_map(|e| e.into_string().ok()) - { - files.insert(path); - } - } - let can_static = libs - .iter() - .all(|l| files.contains(&format!("lib{}.a", l)) || files.contains(&format!("{}.lib", l))); - let can_dylib = libs - .iter() - .all(|l| files.contains(&format!("lib{}.so", l)) || files.contains(&format!("{}.dll", l)) || files.contains(&format!("lib{}.dylib", l))); - match (can_static, can_dylib) { - (true, false) => return "static", - (false, true) => return "dylib", - (false, false) => { - panic!( - "OpenSSL libdir at `{:?}` does not contain the required files \ - to either statically or dynamically link OpenSSL", - libdirs - ); - } - (true, true) => {} - } - - // Ok, we've got not explicit preference and can *either* link statically or - // link dynamically. In the interest of "security upgrades" and/or "best - // practices with security libs", let's link dynamically. - "dylib" -} diff --git a/openssl-sys/build/run_bindgen.rs b/openssl-sys/build/run_bindgen.rs deleted file mode 100644 index 9555192..0000000 --- a/openssl-sys/build/run_bindgen.rs +++ /dev/null @@ -1,123 +0,0 @@ -use bindgen::callbacks::{MacroParsingBehavior, ParseCallbacks}; -use bindgen::RustTarget; -use std::env; -use std::path::PathBuf; - -const INCLUDES: &str = " -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// this must be included after ssl.h for libressl! -#include - -#if !defined(LIBRESSL_VERSION_NUMBER) -#include -#endif - -#if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= 0x10100000 -#include -#endif - -#if OPENSSL_VERSION_NUMBER >= 0x30000000 -#include -#endif -"; - -pub fn run(include_dirs: &[PathBuf]) { - let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap()); - - let mut builder = bindgen::builder() - .parse_callbacks(Box::new(OpensslCallbacks)) - .rust_target(RustTarget::Stable_1_47) - .ctypes_prefix("::libc") - .raw_line("use libc::*;") - .raw_line("type evp_pkey_st = EVP_PKEY;") - .allowlist_file(".*/openssl/[^/]+\\.h") - .allowlist_recursively(false) - // libc is missing pthread_once_t on macOS - .blocklist_type("CRYPTO_ONCE") - .blocklist_function("CRYPTO_THREAD_run_once") - // we don't want to mess with va_list - .blocklist_function("BIO_vprintf") - .blocklist_function("BIO_vsnprintf") - .blocklist_function("ERR_vset_error") - .blocklist_function("ERR_add_error_vdata") - .blocklist_function("EVP_KDF_vctrl") - .blocklist_type("OSSL_FUNC_core_vset_error_fn") - .blocklist_type("OSSL_FUNC_BIO_vprintf_fn") - .blocklist_type("OSSL_FUNC_BIO_vsnprintf_fn") - // Maintain compatibility for existing enum definitions - .rustified_enum("point_conversion_form_t") - // Maintain compatibility for pre-union definitions - .blocklist_type("GENERAL_NAME") - .blocklist_type("GENERAL_NAME_st") - .blocklist_type("EVP_PKEY") - .blocklist_type("evp_pkey_st") - .layout_tests(false) - .header_contents("includes.h", INCLUDES); - - for include_dir in include_dirs { - builder = builder.clang_arg("-I").clang_arg(include_dir.display().to_string()); - } - - builder.generate().unwrap().write_to_file(out_dir.join("bindgen.rs")).unwrap(); -} - -#[derive(Debug)] -struct OpensslCallbacks; - -impl ParseCallbacks for OpensslCallbacks { - // for now we'll continue hand-writing constants - fn will_parse_macro(&self, _name: &str) -> MacroParsingBehavior { - MacroParsingBehavior::Ignore - } - - fn item_name(&self, original_item_name: &str) -> Option { - match original_item_name { - // Our original definitions of these are wrong, so rename to avoid breakage - "CRYPTO_EX_new" - | "CRYPTO_EX_dup" - | "CRYPTO_EX_free" - | "BIO_meth_set_write" - | "BIO_meth_set_read" - | "BIO_meth_set_puts" - | "BIO_meth_set_ctrl" - | "BIO_meth_set_create" - | "BIO_meth_set_destroy" - | "CRYPTO_set_locking_callback" - | "CRYPTO_set_id_callback" - | "SSL_CTX_set_tmp_dh_callback" - | "SSL_set_tmp_dh_callback" - | "SSL_CTX_set_tmp_ecdh_callback" - | "SSL_set_tmp_ecdh_callback" - | "SSL_CTX_callback_ctrl" - | "SSL_CTX_set_alpn_select_cb" => Some(format!("{}__fixed_rust", original_item_name)), - _ => None, - } - } -} diff --git a/openssl-sys/src/aes.rs b/openssl-sys/src/aes.rs deleted file mode 100644 index ade6e84..0000000 --- a/openssl-sys/src/aes.rs +++ /dev/null @@ -1,7 +0,0 @@ -use libc::*; - -pub const AES_ENCRYPT: c_int = 1; -pub const AES_DECRYPT: c_int = 0; - -pub const AES_MAXNR: c_int = 14; -pub const AES_BLOCK_SIZE: c_int = 16; diff --git a/openssl-sys/src/asn1.rs b/openssl-sys/src/asn1.rs deleted file mode 100644 index caf14f7..0000000 --- a/openssl-sys/src/asn1.rs +++ /dev/null @@ -1,39 +0,0 @@ -use libc::*; - -use super::*; - -// ASN.1 tag values -pub const V_ASN1_EOC: c_int = 0; -pub const V_ASN1_BOOLEAN: c_int = 1; -pub const V_ASN1_INTEGER: c_int = 2; -pub const V_ASN1_BIT_STRING: c_int = 3; -pub const V_ASN1_OCTET_STRING: c_int = 4; -pub const V_ASN1_NULL: c_int = 5; -pub const V_ASN1_OBJECT: c_int = 6; -pub const V_ASN1_OBJECT_DESCRIPTOR: c_int = 7; -pub const V_ASN1_EXTERNAL: c_int = 8; -pub const V_ASN1_REAL: c_int = 9; -pub const V_ASN1_ENUMERATED: c_int = 10; -pub const V_ASN1_UTF8STRING: c_int = 12; -pub const V_ASN1_SEQUENCE: c_int = 16; -pub const V_ASN1_SET: c_int = 17; -pub const V_ASN1_NUMERICSTRING: c_int = 18; -pub const V_ASN1_PRINTABLESTRING: c_int = 19; -pub const V_ASN1_T61STRING: c_int = 20; -pub const V_ASN1_TELETEXSTRING: c_int = 20; // alias -pub const V_ASN1_VIDEOTEXSTRING: c_int = 21; -pub const V_ASN1_IA5STRING: c_int = 22; -pub const V_ASN1_UTCTIME: c_int = 23; -pub const V_ASN1_GENERALIZEDTIME: c_int = 24; -pub const V_ASN1_GRAPHICSTRING: c_int = 25; -pub const V_ASN1_ISO64STRING: c_int = 26; -pub const V_ASN1_VISIBLESTRING: c_int = 26; // alias -pub const V_ASN1_GENERALSTRING: c_int = 27; -pub const V_ASN1_UNIVERSALSTRING: c_int = 28; -pub const V_ASN1_BMPSTRING: c_int = 30; - -pub const MBSTRING_FLAG: c_int = 0x1000; -pub const MBSTRING_UTF8: c_int = MBSTRING_FLAG; -pub const MBSTRING_ASC: c_int = MBSTRING_FLAG | 1; -pub const MBSTRING_BMP: c_int = MBSTRING_FLAG | 2; -pub const MBSTRING_UNIV: c_int = MBSTRING_FLAG | 4; diff --git a/openssl-sys/src/bio.rs b/openssl-sys/src/bio.rs deleted file mode 100644 index 4be2d66..0000000 --- a/openssl-sys/src/bio.rs +++ /dev/null @@ -1,54 +0,0 @@ -use libc::*; - -use super::*; - -pub const BIO_TYPE_NONE: c_int = 0; - -pub const BIO_CTRL_EOF: c_int = 2; -pub const BIO_CTRL_INFO: c_int = 3; -pub const BIO_CTRL_FLUSH: c_int = 11; -pub const BIO_CTRL_DGRAM_QUERY_MTU: c_int = 40; -pub const BIO_C_SET_BUF_MEM_EOF_RETURN: c_int = 130; - -pub unsafe fn BIO_set_retry_read(b: *mut BIO) { - BIO_set_flags(b, BIO_FLAGS_READ | BIO_FLAGS_SHOULD_RETRY) -} - -pub unsafe fn BIO_set_retry_write(b: *mut BIO) { - BIO_set_flags(b, BIO_FLAGS_WRITE | BIO_FLAGS_SHOULD_RETRY) -} - -pub unsafe fn BIO_clear_retry_flags(b: *mut BIO) { - BIO_clear_flags(b, BIO_FLAGS_RWS | BIO_FLAGS_SHOULD_RETRY) -} - -pub const BIO_FLAGS_READ: c_int = 0x01; -pub const BIO_FLAGS_WRITE: c_int = 0x02; -pub const BIO_FLAGS_IO_SPECIAL: c_int = 0x04; -pub const BIO_FLAGS_RWS: c_int = BIO_FLAGS_READ | BIO_FLAGS_WRITE | BIO_FLAGS_IO_SPECIAL; -pub const BIO_FLAGS_SHOULD_RETRY: c_int = 0x08; - -pub unsafe fn BIO_get_mem_data(b: *mut BIO, pp: *mut *mut c_char) -> c_long { - BIO_ctrl(b, BIO_CTRL_INFO, 0, pp as *mut c_void) -} - -extern "C" { - #[deprecated(note = "use BIO_meth_set_write__fixed_rust instead")] - #[cfg(any(ossl110, libressl273))] - pub fn BIO_meth_set_write(biom: *mut BIO_METHOD, write: unsafe extern "C" fn(*mut BIO, *const c_char, c_int) -> c_int) -> c_int; - #[deprecated(note = "use BIO_meth_set_read__fixed_rust instead")] - #[cfg(any(ossl110, libressl273))] - pub fn BIO_meth_set_read(biom: *mut BIO_METHOD, read: unsafe extern "C" fn(*mut BIO, *mut c_char, c_int) -> c_int) -> c_int; - #[deprecated(note = "use BIO_meth_set_puts__fixed_rust instead")] - #[cfg(any(ossl110, libressl273))] - pub fn BIO_meth_set_puts(biom: *mut BIO_METHOD, read: unsafe extern "C" fn(*mut BIO, *const c_char) -> c_int) -> c_int; - #[deprecated(note = "use BIO_meth_set_ctrl__fixed_rust instead")] - #[cfg(any(ossl110, libressl273))] - pub fn BIO_meth_set_ctrl(biom: *mut BIO_METHOD, read: unsafe extern "C" fn(*mut BIO, c_int, c_long, *mut c_void) -> c_long) -> c_int; - #[deprecated(note = "use BIO_meth_set_create__fixed_rust instead")] - #[cfg(any(ossl110, libressl273))] - pub fn BIO_meth_set_create(biom: *mut BIO_METHOD, create: unsafe extern "C" fn(*mut BIO) -> c_int) -> c_int; - #[deprecated(note = "use BIO_meth_set_destroy__fixed_rust instead")] - #[cfg(any(ossl110, libressl273))] - pub fn BIO_meth_set_destroy(biom: *mut BIO_METHOD, destroy: unsafe extern "C" fn(*mut BIO) -> c_int) -> c_int; -} diff --git a/openssl-sys/src/bn.rs b/openssl-sys/src/bn.rs deleted file mode 100644 index a6bbcce..0000000 --- a/openssl-sys/src/bn.rs +++ /dev/null @@ -1,15 +0,0 @@ -use libc::*; - -#[cfg(target_pointer_width = "64")] -pub type BN_ULONG = c_ulonglong; -#[cfg(target_pointer_width = "32")] -pub type BN_ULONG = c_uint; - -#[cfg(ossl110)] -pub const BN_FLG_MALLOCED: c_int = 0x01; -#[cfg(ossl110)] -pub const BN_FLG_STATIC_DATA: c_int = 0x02; -#[cfg(ossl110)] -pub const BN_FLG_CONSTTIME: c_int = 0x04; -#[cfg(ossl110)] -pub const BN_FLG_SECURE: c_int = 0x08; diff --git a/openssl-sys/src/cms.rs b/openssl-sys/src/cms.rs deleted file mode 100644 index f008adb..0000000 --- a/openssl-sys/src/cms.rs +++ /dev/null @@ -1,46 +0,0 @@ -use libc::*; - -#[cfg(ossl101)] -pub const CMS_TEXT: c_uint = 0x1; -#[cfg(ossl101)] -pub const CMS_NOCERTS: c_uint = 0x2; -#[cfg(ossl101)] -pub const CMS_NO_CONTENT_VERIFY: c_uint = 0x4; -#[cfg(ossl101)] -pub const CMS_NO_ATTR_VERIFY: c_uint = 0x8; -#[cfg(ossl101)] -pub const CMS_NOSIGS: c_uint = 0x4 | 0x8; -#[cfg(ossl101)] -pub const CMS_NOINTERN: c_uint = 0x10; -#[cfg(ossl101)] -pub const CMS_NO_SIGNER_CERT_VERIFY: c_uint = 0x20; -#[cfg(ossl101)] -pub const CMS_NOVERIFY: c_uint = 0x20; -#[cfg(ossl101)] -pub const CMS_DETACHED: c_uint = 0x40; -#[cfg(ossl101)] -pub const CMS_BINARY: c_uint = 0x80; -#[cfg(ossl101)] -pub const CMS_NOATTR: c_uint = 0x100; -#[cfg(ossl101)] -pub const CMS_NOSMIMECAP: c_uint = 0x200; -#[cfg(ossl101)] -pub const CMS_NOOLDMIMETYPE: c_uint = 0x400; -#[cfg(ossl101)] -pub const CMS_CRLFEOL: c_uint = 0x800; -#[cfg(ossl101)] -pub const CMS_STREAM: c_uint = 0x1000; -#[cfg(ossl101)] -pub const CMS_NOCRL: c_uint = 0x2000; -#[cfg(ossl101)] -pub const CMS_PARTIAL: c_uint = 0x4000; -#[cfg(ossl101)] -pub const CMS_REUSE_DIGEST: c_uint = 0x8000; -#[cfg(ossl101)] -pub const CMS_USE_KEYID: c_uint = 0x10000; -#[cfg(ossl101)] -pub const CMS_DEBUG_DECRYPT: c_uint = 0x20000; -#[cfg(ossl102)] -pub const CMS_KEY_PARAM: c_uint = 0x40000; -#[cfg(ossl110)] -pub const CMS_ASCIICRLF: c_uint = 0x80000; diff --git a/openssl-sys/src/crypto.rs b/openssl-sys/src/crypto.rs deleted file mode 100644 index df17caa..0000000 --- a/openssl-sys/src/crypto.rs +++ /dev/null @@ -1,114 +0,0 @@ -use super::*; -use libc::*; - -extern "C" { - #[deprecated(note = "use CRYPTO_set_locking_callback__fixed_rust instead")] - #[cfg(not(ossl110))] - pub fn CRYPTO_set_locking_callback(func: unsafe extern "C" fn(mode: c_int, n: c_int, file: *const c_char, line: c_int)); - - #[deprecated(note = "use CRYPTO_set_id_callback__fixed_rust instead")] - #[cfg(not(ossl110))] - pub fn CRYPTO_set_id_callback(func: unsafe extern "C" fn() -> c_ulong); -} - -cfg_if! { - if #[cfg(ossl110)] { - type CRYPTO_EX_new_ret = (); - type CRYPTO_EX_dup_from = *const CRYPTO_EX_DATA; - } else { - type CRYPTO_EX_new_ret = c_int; - type CRYPTO_EX_dup_from = *mut CRYPTO_EX_DATA; - } -} - -cfg_if! { - if #[cfg(ossl300)] { - type CRYPTO_EX_dup_from_d = *mut *mut c_void; - } else { - type CRYPTO_EX_dup_from_d = *mut c_void; - } -} - -// FIXME should be options -pub type CRYPTO_EX_new = unsafe extern "C" fn( - parent: *mut c_void, - ptr: *mut c_void, - ad: *mut CRYPTO_EX_DATA, - idx: c_int, - argl: c_long, - argp: *mut c_void, -) -> CRYPTO_EX_new_ret; -pub type CRYPTO_EX_dup = unsafe extern "C" fn( - to: *mut CRYPTO_EX_DATA, - from: CRYPTO_EX_dup_from, - from_d: CRYPTO_EX_dup_from_d, - idx: c_int, - argl: c_long, - argp: *mut c_void, -) -> c_int; -pub type CRYPTO_EX_free = - unsafe extern "C" fn(parent: *mut c_void, ptr: *mut c_void, ad: *mut CRYPTO_EX_DATA, idx: c_int, argl: c_long, argp: *mut c_void); - -#[cfg(ossl110)] -#[inline] -#[track_caller] -pub unsafe fn OPENSSL_malloc(num: usize) -> *mut c_void { - CRYPTO_malloc(num, concat!(file!(), "\0").as_ptr() as *const _, line!() as _) -} - -#[cfg(not(ossl110))] -#[inline] -#[track_caller] -pub unsafe fn OPENSSL_malloc(num: c_int) -> *mut c_void { - CRYPTO_malloc(num, concat!(file!(), "\0").as_ptr() as *const _, line!() as _) -} - -#[cfg(ossl110)] -#[inline] -#[track_caller] -pub unsafe fn OPENSSL_free(addr: *mut c_void) { - CRYPTO_free(addr, concat!(file!(), "\0").as_ptr() as *const _, line!() as _) -} - -#[cfg(not(ossl110))] -#[inline] -pub unsafe fn OPENSSL_free(addr: *mut c_void) { - CRYPTO_free(addr) -} - -#[cfg(not(ossl110))] -pub const CRYPTO_LOCK_X509: c_int = 3; -#[cfg(not(ossl110))] -pub const CRYPTO_LOCK_EVP_PKEY: c_int = 10; -#[cfg(not(ossl110))] -pub const CRYPTO_LOCK_SSL_CTX: c_int = 12; -#[cfg(not(ossl110))] -pub const CRYPTO_LOCK_SSL_SESSION: c_int = 14; - -cfg_if! { - if #[cfg(ossl110)] { - pub const CRYPTO_EX_INDEX_SSL: c_int = 0; - pub const CRYPTO_EX_INDEX_SSL_CTX: c_int = 1; - } else if #[cfg(libressl)] { - pub const CRYPTO_EX_INDEX_SSL: c_int = 1; - pub const CRYPTO_EX_INDEX_SSL_CTX: c_int = 2; - } -} - -cfg_if! { - if #[cfg(any(ossl110, libressl271))] { - pub const OPENSSL_VERSION: c_int = 0; - pub const OPENSSL_CFLAGS: c_int = 1; - pub const OPENSSL_BUILT_ON: c_int = 2; - pub const OPENSSL_PLATFORM: c_int = 3; - pub const OPENSSL_DIR: c_int = 4; - } else { - pub const SSLEAY_VERSION: c_int = 0; - pub const SSLEAY_CFLAGS: c_int = 2; - pub const SSLEAY_BUILT_ON: c_int = 3; - pub const SSLEAY_PLATFORM: c_int = 4; - pub const SSLEAY_DIR: c_int = 5; - } -} - -pub const CRYPTO_LOCK: c_int = 1; diff --git a/openssl-sys/src/dtls1.rs b/openssl-sys/src/dtls1.rs deleted file mode 100644 index 9ef5e77..0000000 --- a/openssl-sys/src/dtls1.rs +++ /dev/null @@ -1,9 +0,0 @@ -use libc::*; - -cfg_if! { - if #[cfg(ossl300)] { - pub const DTLS1_COOKIE_LENGTH: c_uint = 255; - } else { - pub const DTLS1_COOKIE_LENGTH: c_uint = 256; - } -} diff --git a/openssl-sys/src/ec.rs b/openssl-sys/src/ec.rs deleted file mode 100644 index 80a229a..0000000 --- a/openssl-sys/src/ec.rs +++ /dev/null @@ -1,11 +0,0 @@ -use libc::*; -use std::ptr; - -use super::*; - -pub const OPENSSL_EC_NAMED_CURVE: c_int = 1; - -#[cfg(ossl300)] -pub unsafe fn EVP_EC_gen(curve: *const c_char) -> *mut EVP_PKEY { - EVP_PKEY_Q_keygen(ptr::null_mut(), ptr::null_mut(), "EC\0".as_ptr().cast(), curve) -} diff --git a/openssl-sys/src/err.rs b/openssl-sys/src/err.rs deleted file mode 100644 index 5e84e62..0000000 --- a/openssl-sys/src/err.rs +++ /dev/null @@ -1,70 +0,0 @@ -use libc::*; - -pub const ERR_TXT_MALLOCED: c_int = 0x01; -pub const ERR_TXT_STRING: c_int = 0x02; - -pub const ERR_LIB_SYS: c_int = 2; -pub const ERR_LIB_PEM: c_int = 9; -pub const ERR_LIB_ASN1: c_int = 13; - -cfg_if! { - if #[cfg(ossl300)] { - pub const ERR_SYSTEM_FLAG: c_ulong = c_int::max_value() as c_ulong + 1; - pub const ERR_SYSTEM_MASK: c_ulong = c_int::max_value() as c_ulong; - - pub const ERR_LIB_OFFSET: c_ulong = 23; - pub const ERR_LIB_MASK: c_ulong = 0xff; - pub const ERR_RFLAGS_OFFSET: c_ulong = 18; - pub const ERR_RFLAGS_MASK: c_ulong = 0x1f; - pub const ERR_REASON_MASK: c_ulong = 0x7FFFFF; - - pub const ERR_RFLAG_FATAL: c_ulong = 0x1 << ERR_RFLAGS_OFFSET; - - const_fn! { - pub const fn ERR_SYSTEM_ERROR(errcode: c_ulong) -> bool { - errcode & ERR_SYSTEM_FLAG != 0 - } - - pub const fn ERR_GET_LIB(errcode: c_ulong) -> c_int { - // hacks since `if` isn't yet stable in const functions :( - ((ERR_LIB_SYS as c_ulong * (ERR_SYSTEM_ERROR(errcode) as c_ulong)) | - (((errcode >> ERR_LIB_OFFSET) & ERR_LIB_MASK) * (!ERR_SYSTEM_ERROR(errcode) as c_ulong))) as c_int - } - - pub const fn ERR_GET_FUNC(_errcode: c_ulong) -> c_int { - 0 - } - - pub const fn ERR_GET_REASON(errcode: c_ulong) -> c_int { - // hacks since `if` isn't yet stable in const functions :( - ((ERR_LIB_SYS as c_ulong * (ERR_SYSTEM_ERROR(errcode) as c_ulong)) | - ((errcode & ERR_REASON_MASK) * (!ERR_SYSTEM_ERROR(errcode) as c_ulong))) as c_int - } - - pub const fn ERR_PACK(lib: c_int, _func: c_int, reason: c_int) -> c_ulong { - ((lib as c_ulong & ERR_LIB_MASK) << ERR_LIB_OFFSET) | - (reason as c_ulong & ERR_REASON_MASK) - } - } - } else { - const_fn! { - pub const fn ERR_PACK(l: c_int, f: c_int, r: c_int) -> c_ulong { - ((l as c_ulong & 0x0FF) << 24) | - ((f as c_ulong & 0xFFF) << 12) | - (r as c_ulong & 0xFFF) - } - - pub const fn ERR_GET_LIB(l: c_ulong) -> c_int { - ((l >> 24) & 0x0FF) as c_int - } - - pub const fn ERR_GET_FUNC(l: c_ulong) -> c_int { - ((l >> 12) & 0xFFF) as c_int - } - - pub const fn ERR_GET_REASON(l: c_ulong) -> c_int { - (l & 0xFFF) as c_int - } - } - } -} diff --git a/openssl-sys/src/evp.rs b/openssl-sys/src/evp.rs deleted file mode 100644 index 4449336..0000000 --- a/openssl-sys/src/evp.rs +++ /dev/null @@ -1,227 +0,0 @@ -use super::*; -use libc::*; - -pub const EVP_MAX_MD_SIZE: c_uint = 64; - -pub const PKCS5_SALT_LEN: c_int = 8; -pub const PKCS12_DEFAULT_ITER: c_int = 2048; - -pub const EVP_PKEY_RSA: c_int = NID_rsaEncryption; -pub const EVP_PKEY_DSA: c_int = NID_dsa; -pub const EVP_PKEY_DH: c_int = NID_dhKeyAgreement; -pub const EVP_PKEY_EC: c_int = NID_X9_62_id_ecPublicKey; -#[cfg(ossl111)] -pub const EVP_PKEY_X25519: c_int = NID_X25519; -#[cfg(ossl111)] -pub const EVP_PKEY_ED25519: c_int = NID_ED25519; -#[cfg(ossl111)] -pub const EVP_PKEY_X448: c_int = NID_X448; -#[cfg(ossl111)] -pub const EVP_PKEY_ED448: c_int = NID_ED448; -pub const EVP_PKEY_HMAC: c_int = NID_hmac; -pub const EVP_PKEY_CMAC: c_int = NID_cmac; -#[cfg(ossl110)] -pub const EVP_PKEY_HKDF: c_int = NID_hkdf; - -pub const EVP_CTRL_GCM_SET_IVLEN: c_int = 0x9; -pub const EVP_CTRL_GCM_GET_TAG: c_int = 0x10; -pub const EVP_CTRL_GCM_SET_TAG: c_int = 0x11; - -pub unsafe fn EVP_get_digestbynid(type_: c_int) -> *const EVP_MD { - EVP_get_digestbyname(OBJ_nid2sn(type_)) -} - -cfg_if! { - if #[cfg(ossl300)] { - #[inline] - pub unsafe fn EVP_MD_CTX_md(ctx: *const EVP_MD_CTX) -> *const EVP_MD { - EVP_MD_CTX_get0_md(ctx) - } - - #[inline] - pub unsafe fn EVP_MD_CTX_get_size(ctx: *const EVP_MD_CTX) -> c_int { - EVP_MD_get_size(EVP_MD_CTX_get0_md(ctx)) - } - - #[inline] - pub unsafe fn EVP_MD_CTX_size(ctx: *const EVP_MD_CTX) -> c_int { - EVP_MD_CTX_get_size(ctx) - } - - #[inline] - pub unsafe fn EVP_MD_block_size(md: *const EVP_MD) -> c_int { - EVP_MD_get_block_size(md) - } - - #[inline] - pub unsafe fn EVP_MD_size(md: *const EVP_MD) -> c_int { - EVP_MD_get_size(md) - } - - #[inline] - pub unsafe fn EVP_MD_type(md: *const EVP_MD) -> c_int { - EVP_MD_get_type(md) - } - - #[inline] - pub unsafe fn EVP_CIPHER_key_length(cipher: *const EVP_CIPHER) -> c_int { - EVP_CIPHER_get_key_length(cipher) - } - - #[inline] - pub unsafe fn EVP_CIPHER_block_size(cipher: *const EVP_CIPHER) -> c_int { - EVP_CIPHER_get_block_size(cipher) - } - - #[inline] - pub unsafe fn EVP_CIPHER_iv_length(cipher: *const EVP_CIPHER) -> c_int { - EVP_CIPHER_get_iv_length(cipher) - } - - #[inline] - pub unsafe fn EVP_CIPHER_nid(cipher: *const EVP_CIPHER) -> c_int { - EVP_CIPHER_get_nid(cipher) - } - - #[inline] - pub unsafe fn EVP_CIPHER_CTX_block_size(ctx: *const EVP_CIPHER_CTX) -> c_int { - EVP_CIPHER_CTX_get_block_size(ctx) - } - - #[inline] - pub unsafe fn EVP_CIPHER_CTX_key_length(ctx: *const EVP_CIPHER_CTX) -> c_int { - EVP_CIPHER_CTX_get_key_length(ctx) - } - - #[inline] - pub unsafe fn EVP_CIPHER_CTX_iv_length(ctx: *const EVP_CIPHER_CTX) -> c_int { - EVP_CIPHER_CTX_get_iv_length(ctx) - } - - #[inline] - pub unsafe fn EVP_CIPHER_CTX_num(ctx: *const EVP_CIPHER_CTX) -> c_int { - EVP_CIPHER_CTX_get_num(ctx) - } - } else { - pub unsafe fn EVP_MD_CTX_size(ctx: *const EVP_MD_CTX) -> c_int { - EVP_MD_size(EVP_MD_CTX_md(ctx)) - } - } -} -#[cfg(not(ossl300))] -#[inline] -pub unsafe fn EVP_DigestSignUpdate(ctx: *mut EVP_MD_CTX, data: *const c_void, dsize: size_t) -> c_int { - EVP_DigestUpdate(ctx, data, dsize) -} -#[cfg(not(ossl300))] -#[inline] -pub unsafe fn EVP_DigestVerifyUpdate(ctx: *mut EVP_MD_CTX, data: *const c_void, dsize: size_t) -> c_int { - EVP_DigestUpdate(ctx, data, dsize) -} -#[cfg(ossl300)] -#[inline] -pub unsafe fn EVP_PKEY_size(pkey: *const EVP_PKEY) -> c_int { - EVP_PKEY_get_size(pkey) -} - -cfg_if! { - if #[cfg(ossl300)] { - #[inline] - pub unsafe fn EVP_PKEY_id(pkey: *const EVP_PKEY) -> c_int { - EVP_PKEY_get_id(pkey) - } - - #[inline] - pub unsafe fn EVP_PKEY_bits(pkey: *const EVP_PKEY) -> c_int { - EVP_PKEY_get_bits(pkey) - } - - #[inline] - pub unsafe fn EVP_PKEY_security_bits(pkey: *const EVP_PKEY) -> c_int { - EVP_PKEY_get_security_bits(pkey) - } - } -} - -pub const EVP_PKEY_OP_KEYGEN: c_int = 1 << 2; -cfg_if! { - if #[cfg(ossl300)] { - pub const EVP_PKEY_OP_SIGN: c_int = 1 << 4; - pub const EVP_PKEY_OP_VERIFY: c_int = 1 << 5; - pub const EVP_PKEY_OP_VERIFYRECOVER: c_int = 1 << 6; - pub const EVP_PKEY_OP_SIGNCTX: c_int = 1 << 7; - pub const EVP_PKEY_OP_VERIFYCTX: c_int = 1 << 8; - pub const EVP_PKEY_OP_ENCRYPT: c_int = 1 << 9; - pub const EVP_PKEY_OP_DECRYPT: c_int = 1 << 10; - pub const EVP_PKEY_OP_DERIVE: c_int = 1 << 11; - } else { - pub const EVP_PKEY_OP_SIGN: c_int = 1 << 3; - pub const EVP_PKEY_OP_VERIFY: c_int = 1 << 4; - pub const EVP_PKEY_OP_VERIFYRECOVER: c_int = 1 << 5; - pub const EVP_PKEY_OP_SIGNCTX: c_int = 1 << 6; - pub const EVP_PKEY_OP_VERIFYCTX: c_int = 1 << 7; - pub const EVP_PKEY_OP_ENCRYPT: c_int = 1 << 8; - pub const EVP_PKEY_OP_DECRYPT: c_int = 1 << 9; - pub const EVP_PKEY_OP_DERIVE: c_int = 1 << 10; - } -} - -pub const EVP_PKEY_OP_TYPE_SIG: c_int = - EVP_PKEY_OP_SIGN | EVP_PKEY_OP_VERIFY | EVP_PKEY_OP_VERIFYRECOVER | EVP_PKEY_OP_SIGNCTX | EVP_PKEY_OP_VERIFYCTX; - -pub const EVP_PKEY_OP_TYPE_CRYPT: c_int = EVP_PKEY_OP_ENCRYPT | EVP_PKEY_OP_DECRYPT; - -pub const EVP_PKEY_CTRL_SET_MAC_KEY: c_int = 6; - -pub const EVP_PKEY_CTRL_CIPHER: c_int = 12; - -pub const EVP_PKEY_ALG_CTRL: c_int = 0x1000; - -#[cfg(ossl111)] -pub const EVP_PKEY_HKDEF_MODE_EXTRACT_AND_EXPAND: c_int = 0; - -#[cfg(ossl111)] -pub const EVP_PKEY_HKDEF_MODE_EXTRACT_ONLY: c_int = 1; - -#[cfg(ossl111)] -pub const EVP_PKEY_HKDEF_MODE_EXPAND_ONLY: c_int = 2; - -#[cfg(ossl110)] -pub const EVP_PKEY_CTRL_HKDF_MD: c_int = EVP_PKEY_ALG_CTRL + 3; - -#[cfg(ossl110)] -pub const EVP_PKEY_CTRL_HKDF_SALT: c_int = EVP_PKEY_ALG_CTRL + 4; - -#[cfg(ossl110)] -pub const EVP_PKEY_CTRL_HKDF_KEY: c_int = EVP_PKEY_ALG_CTRL + 5; - -#[cfg(ossl110)] -pub const EVP_PKEY_CTRL_HKDF_INFO: c_int = EVP_PKEY_ALG_CTRL + 6; - -#[cfg(ossl111)] -pub const EVP_PKEY_CTRL_HKDF_MODE: c_int = EVP_PKEY_ALG_CTRL + 7; - -#[cfg(all(ossl111, not(ossl300)))] -pub unsafe fn EVP_PKEY_CTX_set_hkdf_mode(ctx: *mut EVP_PKEY_CTX, mode: c_int) -> c_int { - EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_HKDF_MODE, mode, std::ptr::null_mut()) -} - -#[cfg(all(ossl110, not(ossl300)))] -pub unsafe fn EVP_PKEY_CTX_set_hkdf_md(ctx: *mut EVP_PKEY_CTX, md: *const EVP_MD) -> c_int { - EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_HKDF_MD, 0, md as *mut c_void) -} - -#[cfg(all(ossl110, not(ossl300)))] -pub unsafe fn EVP_PKEY_CTX_set1_hkdf_salt(ctx: *mut EVP_PKEY_CTX, salt: *const u8, saltlen: c_int) -> c_int { - EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_HKDF_SALT, saltlen, salt as *mut c_void) -} - -#[cfg(all(ossl110, not(ossl300)))] -pub unsafe fn EVP_PKEY_CTX_set1_hkdf_key(ctx: *mut EVP_PKEY_CTX, key: *const u8, keylen: c_int) -> c_int { - EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_HKDF_KEY, keylen, key as *mut c_void) -} - -#[cfg(all(ossl110, not(ossl300)))] -pub unsafe fn EVP_PKEY_CTX_add1_hkdf_info(ctx: *mut EVP_PKEY_CTX, info: *const u8, infolen: c_int) -> c_int { - EVP_PKEY_CTX_ctrl(ctx, -1, EVP_PKEY_OP_DERIVE, EVP_PKEY_CTRL_HKDF_INFO, infolen, info as *mut c_void) -} diff --git a/openssl-sys/src/handwritten/aes.rs b/openssl-sys/src/handwritten/aes.rs deleted file mode 100644 index bb22b37..0000000 --- a/openssl-sys/src/handwritten/aes.rs +++ /dev/null @@ -1,21 +0,0 @@ -use super::super::*; -use libc::*; - -#[repr(C)] -pub struct AES_KEY { - // There is some business with AES_LONG which is there to ensure the values here are 32 bits - rd_key: [u32; 4 * (AES_MAXNR as usize + 1)], - rounds: c_int, -} - -extern "C" { - pub fn AES_set_encrypt_key(userKey: *const c_uchar, bits: c_int, key: *mut AES_KEY) -> c_int; - pub fn AES_set_decrypt_key(userKey: *const c_uchar, bits: c_int, key: *mut AES_KEY) -> c_int; - - #[cfg(not(osslconf = "OPENSSL_NO_DEPRECATED_3_0"))] - pub fn AES_ige_encrypt(in_: *const c_uchar, out: *mut c_uchar, length: size_t, key: *const AES_KEY, ivec: *mut c_uchar, enc: c_int); - - pub fn AES_wrap_key(key: *mut AES_KEY, iv: *const c_uchar, out: *mut c_uchar, in_: *const c_uchar, inlen: c_uint) -> c_int; - - pub fn AES_unwrap_key(key: *mut AES_KEY, iv: *const c_uchar, out: *mut c_uchar, in_: *const c_uchar, inlen: c_uint) -> c_int; -} diff --git a/openssl-sys/src/handwritten/asn1.rs b/openssl-sys/src/handwritten/asn1.rs deleted file mode 100644 index fbd201f..0000000 --- a/openssl-sys/src/handwritten/asn1.rs +++ /dev/null @@ -1,55 +0,0 @@ -use super::super::*; -use libc::*; - -#[repr(C)] -pub struct ASN1_ENCODING { - pub enc: *mut c_uchar, - pub len: c_long, - pub modified: c_int, -} - -extern "C" { - pub fn ASN1_OBJECT_free(x: *mut ASN1_OBJECT); -} - -stack!(stack_st_ASN1_OBJECT); - -extern "C" { - pub fn ASN1_STRING_type_new(ty: c_int) -> *mut ASN1_STRING; - #[cfg(any(ossl110, libressl273))] - pub fn ASN1_STRING_get0_data(x: *const ASN1_STRING) -> *const c_uchar; - #[cfg(any(all(ossl101, not(ossl110)), libressl))] - pub fn ASN1_STRING_data(x: *mut ASN1_STRING) -> *mut c_uchar; - - pub fn ASN1_BIT_STRING_free(x: *mut ASN1_BIT_STRING); - - pub fn ASN1_STRING_free(x: *mut ASN1_STRING); - pub fn ASN1_STRING_length(x: *const ASN1_STRING) -> c_int; - - pub fn ASN1_STRING_set(x: *mut ASN1_STRING, data: *const c_void, len: c_int) -> c_int; - - pub fn ASN1_GENERALIZEDTIME_free(tm: *mut ASN1_GENERALIZEDTIME); - pub fn ASN1_GENERALIZEDTIME_print(b: *mut BIO, tm: *const ASN1_GENERALIZEDTIME) -> c_int; - pub fn ASN1_TIME_new() -> *mut ASN1_TIME; - #[cfg(ossl102)] - pub fn ASN1_TIME_diff(pday: *mut c_int, psec: *mut c_int, from: *const ASN1_TIME, to: *const ASN1_TIME) -> c_int; - pub fn ASN1_TIME_free(tm: *mut ASN1_TIME); - pub fn ASN1_TIME_print(b: *mut BIO, tm: *const ASN1_TIME) -> c_int; - pub fn ASN1_TIME_set(from: *mut ASN1_TIME, to: time_t) -> *mut ASN1_TIME; - - pub fn ASN1_INTEGER_free(x: *mut ASN1_INTEGER); - pub fn ASN1_INTEGER_get(dest: *const ASN1_INTEGER) -> c_long; - pub fn ASN1_INTEGER_set(dest: *mut ASN1_INTEGER, value: c_long) -> c_int; - pub fn BN_to_ASN1_INTEGER(bn: *const BIGNUM, ai: *mut ASN1_INTEGER) -> *mut ASN1_INTEGER; - pub fn ASN1_INTEGER_to_BN(ai: *const ASN1_INTEGER, bn: *mut BIGNUM) -> *mut BIGNUM; - - pub fn ASN1_TIME_set_string(s: *mut ASN1_TIME, str: *const c_char) -> c_int; - #[cfg(ossl111)] - pub fn ASN1_TIME_set_string_X509(s: *mut ASN1_TIME, str: *const c_char) -> c_int; -} - -const_ptr_api! { - extern "C" { - pub fn ASN1_STRING_to_UTF8(out: *mut *mut c_uchar, s: #[const_ptr_if(any(ossl110, libressl280))] ASN1_STRING) -> c_int; - } -} diff --git a/openssl-sys/src/handwritten/bio.rs b/openssl-sys/src/handwritten/bio.rs deleted file mode 100644 index 48ce99a..0000000 --- a/openssl-sys/src/handwritten/bio.rs +++ /dev/null @@ -1,94 +0,0 @@ -use super::super::*; -use libc::*; - -extern "C" { - pub fn BIO_set_flags(b: *mut BIO, flags: c_int); - pub fn BIO_clear_flags(b: *mut BIO, flags: c_int); -} - -pub type bio_info_cb = Option; - -cfg_if! { - if #[cfg(any(ossl110, libressl280))] { - pub enum BIO_METHOD {} - } else { - #[repr(C)] - pub struct BIO_METHOD { - pub type_: c_int, - pub name: *const c_char, - pub bwrite: Option c_int>, - pub bread: Option c_int>, - pub bputs: Option c_int>, - pub bgets: Option c_int>, - pub ctrl: Option c_long>, - pub create: Option c_int>, - pub destroy: Option c_int>, - pub callback_ctrl: Option c_long>, - } - } -} - -const_ptr_api! { - extern "C" { - pub fn BIO_s_file() -> #[const_ptr_if(any(ossl110, libressl280))] BIO_METHOD; - pub fn BIO_new(type_: #[const_ptr_if(any(ossl110, libressl280))] BIO_METHOD) -> *mut BIO; - } -} -extern "C" { - #[cfg(not(osslconf = "OPENSSL_NO_STDIO"))] - pub fn BIO_new_fp(stream: *mut FILE, close_flag: c_int) -> *mut BIO; - #[cfg(any(ossl110, libressl273))] - pub fn BIO_set_data(a: *mut BIO, data: *mut c_void); - #[cfg(any(ossl110, libressl273))] - pub fn BIO_get_data(a: *mut BIO) -> *mut c_void; - #[cfg(any(ossl110, libressl273))] - pub fn BIO_set_init(a: *mut BIO, init: c_int); - pub fn BIO_write(b: *mut BIO, buf: *const c_void, len: c_int) -> c_int; - pub fn BIO_read(b: *mut BIO, buf: *mut c_void, len: c_int) -> c_int; - pub fn BIO_ctrl(b: *mut BIO, cmd: c_int, larg: c_long, parg: *mut c_void) -> c_long; - pub fn BIO_free_all(b: *mut BIO); -} - -const_ptr_api! { - extern "C" { - pub fn BIO_s_mem() -> #[const_ptr_if(any(ossl110, libressl280))] BIO_METHOD; - pub fn BIO_new_mem_buf(buf: #[const_ptr_if(any(ossl102, libressl280))] c_void, len: c_int) -> *mut BIO; - } -} - -extern "C" { - pub fn BIO_new_socket(sock: c_int, close_flag: c_int) -> *mut BIO; - - #[cfg(any(ossl110, libressl273))] - pub fn BIO_meth_new(type_: c_int, name: *const c_char) -> *mut BIO_METHOD; - #[cfg(any(ossl110, libressl273))] - pub fn BIO_meth_free(biom: *mut BIO_METHOD); -} - -#[allow(clashing_extern_declarations)] -extern "C" { - #[cfg(any(ossl110, libressl273))] - #[link_name = "BIO_meth_set_write"] - pub fn BIO_meth_set_write__fixed_rust( - biom: *mut BIO_METHOD, - write: Option c_int>, - ) -> c_int; - #[cfg(any(ossl110, libressl273))] - #[link_name = "BIO_meth_set_read"] - pub fn BIO_meth_set_read__fixed_rust(biom: *mut BIO_METHOD, read: Option c_int>) -> c_int; - #[cfg(any(ossl110, libressl273))] - #[link_name = "BIO_meth_set_puts"] - pub fn BIO_meth_set_puts__fixed_rust(biom: *mut BIO_METHOD, read: Option c_int>) -> c_int; - #[cfg(any(ossl110, libressl273))] - #[link_name = "BIO_meth_set_ctrl"] - pub fn BIO_meth_set_ctrl__fixed_rust( - biom: *mut BIO_METHOD, - read: Option c_long>, - ) -> c_int; - #[cfg(any(ossl110, libressl273))] - #[link_name = "BIO_meth_set_create"] - pub fn BIO_meth_set_create__fixed_rust(biom: *mut BIO_METHOD, create: Option c_int>) -> c_int; - #[cfg(any(ossl110, libressl273))] - #[link_name = "BIO_meth_set_destroy"] - pub fn BIO_meth_set_destroy__fixed_rust(biom: *mut BIO_METHOD, destroy: Option c_int>) -> c_int; -} diff --git a/openssl-sys/src/handwritten/bn.rs b/openssl-sys/src/handwritten/bn.rs deleted file mode 100644 index e93de19..0000000 --- a/openssl-sys/src/handwritten/bn.rs +++ /dev/null @@ -1,105 +0,0 @@ -use super::super::*; -use libc::*; - -extern "C" { - pub fn BN_CTX_new() -> *mut BN_CTX; - #[cfg(ossl110)] - pub fn BN_CTX_secure_new() -> *mut BN_CTX; - pub fn BN_CTX_free(ctx: *mut BN_CTX); - pub fn BN_rand(r: *mut BIGNUM, bits: c_int, top: c_int, bottom: c_int) -> c_int; - #[cfg(not(osslconf = "OPENSSL_NO_DEPRECATED_3_0"))] - pub fn BN_pseudo_rand(r: *mut BIGNUM, bits: c_int, top: c_int, bottom: c_int) -> c_int; - pub fn BN_rand_range(r: *mut BIGNUM, range: *const BIGNUM) -> c_int; - #[cfg(not(osslconf = "OPENSSL_NO_DEPRECATED_3_0"))] - pub fn BN_pseudo_rand_range(r: *mut BIGNUM, range: *const BIGNUM) -> c_int; - pub fn BN_new() -> *mut BIGNUM; - #[cfg(ossl110)] - pub fn BN_secure_new() -> *mut BIGNUM; - #[cfg(ossl110)] - pub fn BN_set_flags(b: *mut BIGNUM, n: c_int); - #[cfg(ossl110)] - pub fn BN_get_flags(b: *const BIGNUM, n: c_int) -> c_int; - pub fn BN_num_bits(bn: *const BIGNUM) -> c_int; - pub fn BN_clear_free(bn: *mut BIGNUM); - pub fn BN_bin2bn(s: *const u8, size: c_int, ret: *mut BIGNUM) -> *mut BIGNUM; - pub fn BN_bn2bin(a: *const BIGNUM, to: *mut u8) -> c_int; - #[cfg(ossl110)] - pub fn BN_bn2binpad(a: *const BIGNUM, to: *mut u8, tolen: c_int) -> c_int; - pub fn BN_sub(r: *mut BIGNUM, a: *const BIGNUM, b: *const BIGNUM) -> c_int; - pub fn BN_add(r: *mut BIGNUM, a: *const BIGNUM, b: *const BIGNUM) -> c_int; - pub fn BN_mul(r: *mut BIGNUM, a: *const BIGNUM, b: *const BIGNUM, ctx: *mut BN_CTX) -> c_int; - pub fn BN_sqr(r: *mut BIGNUM, a: *const BIGNUM, ctx: *mut BN_CTX) -> c_int; - pub fn BN_set_negative(bn: *mut BIGNUM, n: c_int); - #[cfg(any(ossl110, libressl350))] - pub fn BN_is_negative(b: *const BIGNUM) -> c_int; - - pub fn BN_div(dv: *mut BIGNUM, rem: *mut BIGNUM, a: *const BIGNUM, b: *const BIGNUM, ctx: *mut BN_CTX) -> c_int; - pub fn BN_nnmod(rem: *mut BIGNUM, a: *const BIGNUM, m: *const BIGNUM, ctx: *mut BN_CTX) -> c_int; - pub fn BN_mod_add(r: *mut BIGNUM, a: *const BIGNUM, b: *const BIGNUM, m: *const BIGNUM, ctx: *mut BN_CTX) -> c_int; - pub fn BN_mod_sub(r: *mut BIGNUM, a: *const BIGNUM, b: *const BIGNUM, m: *const BIGNUM, ctx: *mut BN_CTX) -> c_int; - pub fn BN_mod_mul(r: *mut BIGNUM, a: *const BIGNUM, b: *const BIGNUM, m: *const BIGNUM, ctx: *mut BN_CTX) -> c_int; - pub fn BN_mod_sqr(r: *mut BIGNUM, a: *const BIGNUM, m: *const BIGNUM, ctx: *mut BN_CTX) -> c_int; - - pub fn BN_mod_word(r: *const BIGNUM, w: BN_ULONG) -> BN_ULONG; - pub fn BN_div_word(r: *mut BIGNUM, w: BN_ULONG) -> BN_ULONG; - pub fn BN_mul_word(r: *mut BIGNUM, w: BN_ULONG) -> c_int; - pub fn BN_add_word(r: *mut BIGNUM, w: BN_ULONG) -> c_int; - pub fn BN_sub_word(r: *mut BIGNUM, w: BN_ULONG) -> c_int; - pub fn BN_set_word(bn: *mut BIGNUM, n: BN_ULONG) -> c_int; - - pub fn BN_cmp(a: *const BIGNUM, b: *const BIGNUM) -> c_int; - pub fn BN_free(bn: *mut BIGNUM); - pub fn BN_is_bit_set(a: *const BIGNUM, n: c_int) -> c_int; - pub fn BN_lshift(r: *mut BIGNUM, a: *const BIGNUM, n: c_int) -> c_int; - pub fn BN_lshift1(r: *mut BIGNUM, a: *const BIGNUM) -> c_int; - pub fn BN_exp(r: *mut BIGNUM, a: *const BIGNUM, p: *const BIGNUM, ctx: *mut BN_CTX) -> c_int; - - pub fn BN_mod_exp(r: *mut BIGNUM, a: *const BIGNUM, p: *const BIGNUM, m: *const BIGNUM, ctx: *mut BN_CTX) -> c_int; - - pub fn BN_mask_bits(a: *mut BIGNUM, n: c_int) -> c_int; - pub fn BN_rshift(r: *mut BIGNUM, a: *const BIGNUM, n: c_int) -> c_int; - pub fn BN_rshift1(r: *mut BIGNUM, a: *const BIGNUM) -> c_int; - pub fn BN_bn2hex(a: *const BIGNUM) -> *mut c_char; - pub fn BN_bn2dec(a: *const BIGNUM) -> *mut c_char; - pub fn BN_hex2bn(a: *mut *mut BIGNUM, s: *const c_char) -> c_int; - pub fn BN_dec2bn(a: *mut *mut BIGNUM, s: *const c_char) -> c_int; - pub fn BN_gcd(r: *mut BIGNUM, a: *const BIGNUM, b: *const BIGNUM, ctx: *mut BN_CTX) -> c_int; - pub fn BN_mod_inverse(r: *mut BIGNUM, a: *const BIGNUM, n: *const BIGNUM, ctx: *mut BN_CTX) -> *mut BIGNUM; - pub fn BN_clear(bn: *mut BIGNUM); - pub fn BN_dup(n: *const BIGNUM) -> *mut BIGNUM; - pub fn BN_ucmp(a: *const BIGNUM, b: *const BIGNUM) -> c_int; - pub fn BN_set_bit(a: *mut BIGNUM, n: c_int) -> c_int; - pub fn BN_clear_bit(a: *mut BIGNUM, n: c_int) -> c_int; - - pub fn BN_generate_prime_ex(r: *mut BIGNUM, bits: c_int, safe: c_int, add: *const BIGNUM, rem: *const BIGNUM, cb: *mut BN_GENCB) -> c_int; - #[cfg(not(osslconf = "OPENSSL_NO_DEPRECATED_3_0"))] - pub fn BN_is_prime_ex(p: *const BIGNUM, checks: c_int, ctx: *mut BN_CTX, cb: *mut BN_GENCB) -> c_int; - #[cfg(not(osslconf = "OPENSSL_NO_DEPRECATED_3_0"))] - pub fn BN_is_prime_fasttest_ex(p: *const BIGNUM, checks: c_int, ctx: *mut BN_CTX, do_trial_division: c_int, cb: *mut BN_GENCB) -> c_int; -} - -cfg_if! { - if #[cfg(any(ossl110, libressl350))] { - extern "C" { - pub fn BN_get_rfc2409_prime_768(bn: *mut BIGNUM) -> *mut BIGNUM; - pub fn BN_get_rfc2409_prime_1024(bn: *mut BIGNUM) -> *mut BIGNUM; - pub fn BN_get_rfc3526_prime_1536(bn: *mut BIGNUM) -> *mut BIGNUM; - pub fn BN_get_rfc3526_prime_2048(bn: *mut BIGNUM) -> *mut BIGNUM; - pub fn BN_get_rfc3526_prime_3072(bn: *mut BIGNUM) -> *mut BIGNUM; - pub fn BN_get_rfc3526_prime_4096(bn: *mut BIGNUM) -> *mut BIGNUM; - pub fn BN_get_rfc3526_prime_6144(bn: *mut BIGNUM) -> *mut BIGNUM; - pub fn BN_get_rfc3526_prime_8192(bn: *mut BIGNUM) -> *mut BIGNUM; - } - } else { - extern "C" { - pub fn get_rfc2409_prime_768(bn: *mut BIGNUM) -> *mut BIGNUM; - pub fn get_rfc2409_prime_1024(bn: *mut BIGNUM) -> *mut BIGNUM; - pub fn get_rfc3526_prime_1536(bn: *mut BIGNUM) -> *mut BIGNUM; - pub fn get_rfc3526_prime_2048(bn: *mut BIGNUM) -> *mut BIGNUM; - pub fn get_rfc3526_prime_3072(bn: *mut BIGNUM) -> *mut BIGNUM; - pub fn get_rfc3526_prime_4096(bn: *mut BIGNUM) -> *mut BIGNUM; - pub fn get_rfc3526_prime_6144(bn: *mut BIGNUM) -> *mut BIGNUM; - pub fn get_rfc3526_prime_8192(bn: *mut BIGNUM) -> *mut BIGNUM; - } - } -} diff --git a/openssl-sys/src/handwritten/cms.rs b/openssl-sys/src/handwritten/cms.rs deleted file mode 100644 index fd92c75..0000000 --- a/openssl-sys/src/handwritten/cms.rs +++ /dev/null @@ -1,43 +0,0 @@ -use super::super::*; -use libc::*; - -pub enum CMS_ContentInfo {} - -extern "C" { - #[cfg(ossl101)] - pub fn CMS_ContentInfo_free(cms: *mut CMS_ContentInfo); -} - -const_ptr_api! { - extern "C" { - #[cfg(ossl101)] - pub fn i2d_CMS_ContentInfo(a: #[const_ptr_if(ossl300)] CMS_ContentInfo, pp: *mut *mut c_uchar) -> c_int; - } -} - -extern "C" { - #[cfg(ossl101)] - pub fn d2i_CMS_ContentInfo(a: *mut *mut CMS_ContentInfo, pp: *mut *const c_uchar, length: c_long) -> *mut CMS_ContentInfo; - - #[cfg(ossl101)] - pub fn SMIME_read_CMS(bio: *mut BIO, bcont: *mut *mut BIO) -> *mut CMS_ContentInfo; - - #[cfg(ossl101)] - pub fn CMS_sign(signcert: *mut X509, pkey: *mut EVP_PKEY, certs: *mut stack_st_X509, data: *mut BIO, flags: c_uint) -> *mut CMS_ContentInfo; - - #[cfg(ossl101)] - pub fn CMS_verify( - cms: *mut CMS_ContentInfo, - certs: *mut stack_st_X509, - store: *mut X509_STORE, - detached_data: *mut BIO, - out: *mut BIO, - flags: c_uint, - ) -> c_int; - - #[cfg(ossl101)] - pub fn CMS_encrypt(certs: *mut stack_st_X509, data: *mut BIO, cipher: *const EVP_CIPHER, flags: c_uint) -> *mut CMS_ContentInfo; - - #[cfg(ossl101)] - pub fn CMS_decrypt(cms: *mut CMS_ContentInfo, pkey: *mut EVP_PKEY, cert: *mut X509, dcont: *mut BIO, out: *mut BIO, flags: c_uint) -> c_int; -} diff --git a/openssl-sys/src/handwritten/conf.rs b/openssl-sys/src/handwritten/conf.rs deleted file mode 100644 index 2348d7d..0000000 --- a/openssl-sys/src/handwritten/conf.rs +++ /dev/null @@ -1,7 +0,0 @@ -use super::super::*; - -extern "C" { - pub fn NCONF_new(meth: *mut CONF_METHOD) -> *mut CONF; - pub fn NCONF_default() -> *mut CONF_METHOD; - pub fn NCONF_free(conf: *mut CONF); -} diff --git a/openssl-sys/src/handwritten/crypto.rs b/openssl-sys/src/handwritten/crypto.rs deleted file mode 100644 index 0c24188..0000000 --- a/openssl-sys/src/handwritten/crypto.rs +++ /dev/null @@ -1,77 +0,0 @@ -use super::super::*; -use libc::*; - -stack!(stack_st_void); - -cfg_if! { - if #[cfg(any(ossl110, libressl271))] { - extern "C" { - pub fn OpenSSL_version_num() -> c_ulong; - pub fn OpenSSL_version(key: c_int) -> *const c_char; - } - } else { - extern "C" { - pub fn SSLeay() -> c_ulong; - pub fn SSLeay_version(key: c_int) -> *const c_char; - } - } -} - -extern "C" { - #[cfg(any(ossl110, libressl))] - pub fn CRYPTO_get_ex_new_index( - class_index: c_int, - argl: c_long, - argp: *mut c_void, - new_func: Option, - dup_func: Option, - free_func: Option, - ) -> c_int; - - #[cfg(not(ossl110))] - pub fn CRYPTO_num_locks() -> c_int; -} - -#[allow(clashing_extern_declarations)] -extern "C" { - #[cfg(not(ossl110))] - #[link_name = "CRYPTO_set_locking_callback"] - pub fn CRYPTO_set_locking_callback__fixed_rust(func: Option); - - #[cfg(not(ossl110))] - #[link_name = "CRYPTO_set_id_callback"] - pub fn CRYPTO_set_id_callback__fixed_rust(func: Option c_ulong>); -} - -extern "C" { - #[cfg(not(ossl110))] - pub fn CRYPTO_add_lock(pointer: *mut c_int, amount: c_int, type_: c_int, file: *const c_char, line: c_int) -> c_int; -} - -cfg_if! { - if #[cfg(ossl110)] { - extern "C" { - pub fn CRYPTO_malloc(num: size_t, file: *const c_char, line: c_int) -> *mut c_void; - pub fn CRYPTO_free(buf: *mut c_void, file: *const c_char, line: c_int); - } - } else { - extern "C" { - pub fn CRYPTO_malloc(num: c_int, file: *const c_char, line: c_int) -> *mut c_void; - pub fn CRYPTO_free(buf: *mut c_void); - } - } -} - -extern "C" { - #[cfg(all(ossl101, not(ossl300)))] - pub fn FIPS_mode() -> c_int; - #[cfg(all(ossl101, not(ossl300)))] - pub fn FIPS_mode_set(onoff: c_int) -> c_int; - - pub fn CRYPTO_memcmp(a: *const c_void, b: *const c_void, len: size_t) -> c_int; - - #[cfg(ossl300)] - pub fn OSSL_LIB_CTX_new() -> *mut OSSL_LIB_CTX; - #[cfg(ossl300)] - pub fn OSSL_LIB_CTX_free(libcts: *mut OSSL_LIB_CTX); -} diff --git a/openssl-sys/src/handwritten/dh.rs b/openssl-sys/src/handwritten/dh.rs deleted file mode 100644 index 200e16e..0000000 --- a/openssl-sys/src/handwritten/dh.rs +++ /dev/null @@ -1,40 +0,0 @@ -use super::super::*; - -extern "C" { - pub fn DH_new() -> *mut DH; - pub fn DH_free(dh: *mut DH); - - pub fn DH_generate_parameters( - prime_len: c_int, - generator: c_int, - callback: Option, - cb_arg: *mut c_void, - ) -> *mut DH; - - pub fn DH_generate_parameters_ex(dh: *mut DH, prime_len: c_int, generator: c_int, cb: *mut BN_GENCB) -> c_int; - - pub fn DH_generate_key(dh: *mut DH) -> c_int; - pub fn DH_compute_key(key: *mut c_uchar, pub_key: *const BIGNUM, dh: *mut DH) -> c_int; - pub fn DH_size(dh: *const DH) -> c_int; - - pub fn d2i_DHparams(k: *mut *mut DH, pp: *mut *const c_uchar, length: c_long) -> *mut DH; - pub fn i2d_DHparams(dh: *const DH, pp: *mut *mut c_uchar) -> c_int; - - #[cfg(ossl102)] - pub fn DH_get_1024_160() -> *mut DH; - #[cfg(ossl102)] - pub fn DH_get_2048_224() -> *mut DH; - #[cfg(ossl102)] - pub fn DH_get_2048_256() -> *mut DH; - - #[cfg(any(ossl110, libressl270))] - pub fn DH_set0_pqg(dh: *mut DH, p: *mut BIGNUM, q: *mut BIGNUM, g: *mut BIGNUM) -> c_int; - #[cfg(any(ossl110, libressl270))] - pub fn DH_get0_pqg(dh: *const DH, p: *mut *const BIGNUM, q: *mut *const BIGNUM, g: *mut *const BIGNUM); - - #[cfg(any(ossl110, libressl270))] - pub fn DH_set0_key(dh: *mut DH, pub_key: *mut BIGNUM, priv_key: *mut BIGNUM) -> c_int; - - #[cfg(any(ossl110, libressl270))] - pub fn DH_get0_key(dh: *const DH, pub_key: *mut *const BIGNUM, priv_key: *mut *const BIGNUM); -} diff --git a/openssl-sys/src/handwritten/dsa.rs b/openssl-sys/src/handwritten/dsa.rs deleted file mode 100644 index 651b842..0000000 --- a/openssl-sys/src/handwritten/dsa.rs +++ /dev/null @@ -1,61 +0,0 @@ -use libc::*; - -use super::super::*; - -cfg_if! { - if #[cfg(any(ossl110, libressl280))] { - pub enum DSA_SIG {} - } else { - #[repr(C)] - pub struct DSA_SIG { - pub r: *mut BIGNUM, - pub s: *mut BIGNUM, - } - } -} - -extern "C" { - pub fn DSA_new() -> *mut DSA; - pub fn DSA_free(dsa: *mut DSA); - pub fn DSA_up_ref(dsa: *mut DSA) -> c_int; - pub fn DSA_size(dsa: *const DSA) -> c_int; - pub fn DSA_sign(dummy: c_int, dgst: *const c_uchar, len: c_int, sigret: *mut c_uchar, siglen: *mut c_uint, dsa: *mut DSA) -> c_int; - pub fn DSA_verify(dummy: c_int, dgst: *const c_uchar, len: c_int, sigbuf: *const c_uchar, siglen: c_int, dsa: *mut DSA) -> c_int; - - pub fn d2i_DSAPublicKey(a: *mut *mut DSA, pp: *mut *const c_uchar, length: c_long) -> *mut DSA; - pub fn d2i_DSAPrivateKey(a: *mut *mut DSA, pp: *mut *const c_uchar, length: c_long) -> *mut DSA; - - pub fn DSA_generate_parameters_ex( - dsa: *mut DSA, - bits: c_int, - seed: *const c_uchar, - seed_len: c_int, - counter_ref: *mut c_int, - h_ret: *mut c_ulong, - cb: *mut BN_GENCB, - ) -> c_int; - - pub fn DSA_generate_key(dsa: *mut DSA) -> c_int; - pub fn i2d_DSAPublicKey(a: *const DSA, pp: *mut *mut c_uchar) -> c_int; - pub fn i2d_DSAPrivateKey(a: *const DSA, pp: *mut *mut c_uchar) -> c_int; - - #[cfg(any(ossl110, libressl273))] - pub fn DSA_get0_pqg(d: *const DSA, p: *mut *const BIGNUM, q: *mut *const BIGNUM, q: *mut *const BIGNUM); - #[cfg(any(ossl110, libressl273))] - pub fn DSA_set0_pqg(d: *mut DSA, p: *mut BIGNUM, q: *mut BIGNUM, q: *mut BIGNUM) -> c_int; - #[cfg(any(ossl110, libressl273))] - pub fn DSA_get0_key(d: *const DSA, pub_key: *mut *const BIGNUM, priv_key: *mut *const BIGNUM); - #[cfg(any(ossl110, libressl273))] - pub fn DSA_set0_key(d: *mut DSA, pub_key: *mut BIGNUM, priv_key: *mut BIGNUM) -> c_int; - pub fn d2i_DSA_SIG(sig: *mut *mut DSA_SIG, pp: *mut *const c_uchar, length: c_long) -> *mut DSA_SIG; - pub fn i2d_DSA_SIG(a: *const DSA_SIG, pp: *mut *mut c_uchar) -> c_int; - - pub fn DSA_SIG_new() -> *mut DSA_SIG; - pub fn DSA_SIG_free(sig: *mut DSA_SIG); - - #[cfg(any(ossl110, libressl273))] - pub fn DSA_SIG_get0(sig: *const DSA_SIG, pr: *mut *const BIGNUM, ps: *mut *const BIGNUM); - - #[cfg(any(ossl110, libressl273))] - pub fn DSA_SIG_set0(sig: *mut DSA_SIG, pr: *mut BIGNUM, ps: *mut BIGNUM) -> c_int; -} diff --git a/openssl-sys/src/handwritten/ec.rs b/openssl-sys/src/handwritten/ec.rs deleted file mode 100644 index bafac6b..0000000 --- a/openssl-sys/src/handwritten/ec.rs +++ /dev/null @@ -1,164 +0,0 @@ -use super::super::*; -use libc::*; - -#[repr(C)] -#[derive(Copy, Clone)] -pub enum point_conversion_form_t { - POINT_CONVERSION_COMPRESSED = 2, - POINT_CONVERSION_UNCOMPRESSED = 4, - POINT_CONVERSION_HYBRID = 6, -} - -pub enum EC_METHOD {} -pub enum EC_GROUP {} -pub enum EC_POINT {} - -extern "C" { - #[cfg(not(osslconf = "OPENSSL_NO_EC2M"))] - pub fn EC_GF2m_simple_method() -> *const EC_METHOD; - - pub fn EC_GROUP_new(meth: *const EC_METHOD) -> *mut EC_GROUP; - - pub fn EC_GROUP_free(group: *mut EC_GROUP); - - pub fn EC_GROUP_get_order(group: *const EC_GROUP, order: *mut BIGNUM, ctx: *mut BN_CTX) -> c_int; - - pub fn EC_GROUP_get_cofactor(group: *const EC_GROUP, cofactor: *mut BIGNUM, ctx: *mut BN_CTX) -> c_int; - - pub fn EC_GROUP_get0_generator(group: *const EC_GROUP) -> *const EC_POINT; - - pub fn EC_GROUP_set_generator(group: *mut EC_GROUP, generator: *const EC_POINT, order: *const BIGNUM, cofactor: *const BIGNUM) -> c_int; - - pub fn EC_GROUP_get_curve_name(group: *const EC_GROUP) -> c_int; - - pub fn EC_GROUP_set_asn1_flag(key: *mut EC_GROUP, flag: c_int); - - pub fn EC_GROUP_get_curve_GFp(group: *const EC_GROUP, p: *mut BIGNUM, a: *mut BIGNUM, b: *mut BIGNUM, ctx: *mut BN_CTX) -> c_int; - - #[cfg(not(osslconf = "OPENSSL_NO_EC2M"))] - pub fn EC_GROUP_get_curve_GF2m(group: *const EC_GROUP, p: *mut BIGNUM, a: *mut BIGNUM, b: *mut BIGNUM, ctx: *mut BN_CTX) -> c_int; - - pub fn EC_GROUP_get_degree(group: *const EC_GROUP) -> c_int; - - #[cfg(ossl110)] - pub fn EC_GROUP_order_bits(group: *const EC_GROUP) -> c_int; - - pub fn EC_GROUP_new_curve_GFp(p: *const BIGNUM, a: *const BIGNUM, b: *const BIGNUM, ctx: *mut BN_CTX) -> *mut EC_GROUP; - - #[cfg(not(osslconf = "OPENSSL_NO_EC2M"))] - pub fn EC_GROUP_new_curve_GF2m(p: *const BIGNUM, a: *const BIGNUM, b: *const BIGNUM, ctx: *mut BN_CTX) -> *mut EC_GROUP; - - pub fn EC_GROUP_new_by_curve_name(nid: c_int) -> *mut EC_GROUP; - - pub fn EC_POINT_is_at_infinity(group: *const EC_GROUP, point: *const EC_POINT) -> c_int; - - pub fn EC_POINT_is_on_curve(group: *const EC_GROUP, point: *const EC_POINT, ctx: *mut BN_CTX) -> c_int; - - pub fn EC_POINT_new(group: *const EC_GROUP) -> *mut EC_POINT; - - pub fn EC_POINT_free(point: *mut EC_POINT); - - pub fn EC_POINT_dup(p: *const EC_POINT, group: *const EC_GROUP) -> *mut EC_POINT; - - #[cfg(ossl111)] - pub fn EC_POINT_get_affine_coordinates(group: *const EC_GROUP, p: *const EC_POINT, x: *mut BIGNUM, y: *mut BIGNUM, ctx: *mut BN_CTX) -> c_int; - - pub fn EC_POINT_get_affine_coordinates_GFp(group: *const EC_GROUP, p: *const EC_POINT, x: *mut BIGNUM, y: *mut BIGNUM, ctx: *mut BN_CTX) - -> c_int; - - pub fn EC_POINT_set_affine_coordinates_GFp( - group: *const EC_GROUP, - p: *mut EC_POINT, - x: *const BIGNUM, - y: *const BIGNUM, - ctx: *mut BN_CTX, - ) -> c_int; - - #[cfg(not(osslconf = "OPENSSL_NO_EC2M"))] - pub fn EC_POINT_get_affine_coordinates_GF2m( - group: *const EC_GROUP, - p: *const EC_POINT, - x: *mut BIGNUM, - y: *mut BIGNUM, - ctx: *mut BN_CTX, - ) -> c_int; - - pub fn EC_POINT_point2oct( - group: *const EC_GROUP, - p: *const EC_POINT, - form: point_conversion_form_t, - buf: *mut c_uchar, - len: size_t, - ctx: *mut BN_CTX, - ) -> size_t; - - pub fn EC_POINT_oct2point(group: *const EC_GROUP, p: *mut EC_POINT, buf: *const c_uchar, len: size_t, ctx: *mut BN_CTX) -> c_int; - - pub fn EC_POINT_add(group: *const EC_GROUP, r: *mut EC_POINT, a: *const EC_POINT, b: *const EC_POINT, ctx: *mut BN_CTX) -> c_int; - - pub fn EC_POINT_invert(group: *const EC_GROUP, r: *mut EC_POINT, ctx: *mut BN_CTX) -> c_int; - - pub fn EC_POINT_cmp(group: *const EC_GROUP, a: *const EC_POINT, b: *const EC_POINT, ctx: *mut BN_CTX) -> c_int; - - pub fn EC_POINT_mul(group: *const EC_GROUP, r: *mut EC_POINT, n: *const BIGNUM, q: *const EC_POINT, m: *const BIGNUM, ctx: *mut BN_CTX) -> c_int; - - pub fn EC_KEY_new() -> *mut EC_KEY; - - pub fn EC_KEY_new_by_curve_name(nid: c_int) -> *mut EC_KEY; - - pub fn EC_KEY_free(key: *mut EC_KEY); - - pub fn EC_KEY_dup(key: *const EC_KEY) -> *mut EC_KEY; - - pub fn EC_KEY_up_ref(key: *mut EC_KEY) -> c_int; - - pub fn EC_KEY_get0_group(key: *const EC_KEY) -> *const EC_GROUP; - - pub fn EC_KEY_set_group(key: *mut EC_KEY, group: *const EC_GROUP) -> c_int; - - pub fn EC_KEY_get0_private_key(key: *const EC_KEY) -> *const BIGNUM; - - pub fn EC_KEY_set_private_key(key: *mut EC_KEY, key: *const BIGNUM) -> c_int; - - pub fn EC_KEY_get0_public_key(key: *const EC_KEY) -> *const EC_POINT; - - pub fn EC_KEY_set_public_key(key: *mut EC_KEY, key: *const EC_POINT) -> c_int; - - pub fn EC_KEY_generate_key(key: *mut EC_KEY) -> c_int; - - pub fn EC_KEY_check_key(key: *const EC_KEY) -> c_int; - - pub fn EC_KEY_set_public_key_affine_coordinates(key: *mut EC_KEY, x: *mut BIGNUM, y: *mut BIGNUM) -> c_int; -} - -cfg_if! { - if #[cfg(any(ossl110, libressl280))] { - pub enum ECDSA_SIG {} - } else { - #[repr(C)] - pub struct ECDSA_SIG { - pub r: *mut BIGNUM, - pub s: *mut BIGNUM, - } - } -} - -extern "C" { - pub fn ECDSA_SIG_new() -> *mut ECDSA_SIG; - - pub fn ECDSA_SIG_free(sig: *mut ECDSA_SIG); - - #[cfg(any(ossl110, libressl273))] - pub fn ECDSA_SIG_get0(sig: *const ECDSA_SIG, pr: *mut *const BIGNUM, ps: *mut *const BIGNUM); - - #[cfg(any(ossl110, libressl273))] - pub fn ECDSA_SIG_set0(sig: *mut ECDSA_SIG, pr: *mut BIGNUM, ps: *mut BIGNUM) -> c_int; - - pub fn ECDSA_do_sign(dgst: *const c_uchar, dgst_len: c_int, eckey: *mut EC_KEY) -> *mut ECDSA_SIG; - - pub fn ECDSA_do_verify(dgst: *const c_uchar, dgst_len: c_int, sig: *const ECDSA_SIG, eckey: *mut EC_KEY) -> c_int; - - pub fn d2i_ECDSA_SIG(sig: *mut *mut ECDSA_SIG, inp: *mut *const c_uchar, length: c_long) -> *mut ECDSA_SIG; - - pub fn i2d_ECDSA_SIG(sig: *const ECDSA_SIG, out: *mut *mut c_uchar) -> c_int; -} diff --git a/openssl-sys/src/handwritten/err.rs b/openssl-sys/src/handwritten/err.rs deleted file mode 100644 index 58f9686..0000000 --- a/openssl-sys/src/handwritten/err.rs +++ /dev/null @@ -1,50 +0,0 @@ -use super::super::*; -use libc::*; - -#[repr(C)] -pub struct ERR_STRING_DATA { - pub error: c_ulong, - pub string: *const c_char, -} - -cfg_if! { - if #[cfg(ossl300)] { - extern "C" { - pub fn ERR_new(); - pub fn ERR_set_debug(file: *const c_char, line: c_int, func: *const c_char); - pub fn ERR_set_error(lib: c_int, reason: c_int, fmt: *const c_char, ...); - } - } else { - extern "C" { - pub fn ERR_put_error(lib: c_int, func: c_int, reason: c_int, file: *const c_char, line: c_int); - } - } -} - -extern "C" { - pub fn ERR_set_error_data(data: *mut c_char, flags: c_int); - - pub fn ERR_get_error() -> c_ulong; - #[cfg(ossl300)] - pub fn ERR_get_error_all( - file: *mut *const c_char, - line: *mut c_int, - func: *mut *const c_char, - data: *mut *const c_char, - flags: *mut c_int, - ) -> c_ulong; - pub fn ERR_get_error_line_data(file: *mut *const c_char, line: *mut c_int, data: *mut *const c_char, flags: *mut c_int) -> c_ulong; - pub fn ERR_peek_last_error() -> c_ulong; - pub fn ERR_clear_error(); - pub fn ERR_lib_error_string(err: c_ulong) -> *const c_char; - pub fn ERR_func_error_string(err: c_ulong) -> *const c_char; - pub fn ERR_reason_error_string(err: c_ulong) -> *const c_char; - #[cfg(ossl110)] - pub fn ERR_load_strings(lib: c_int, str: *mut ERR_STRING_DATA) -> c_int; - #[cfg(not(ossl110))] - pub fn ERR_load_strings(lib: c_int, str: *mut ERR_STRING_DATA); - #[cfg(not(ossl110))] - pub fn ERR_load_crypto_strings(); - - pub fn ERR_get_next_error_library() -> c_int; -} diff --git a/openssl-sys/src/handwritten/evp.rs b/openssl-sys/src/handwritten/evp.rs deleted file mode 100644 index 7d7b5dd..0000000 --- a/openssl-sys/src/handwritten/evp.rs +++ /dev/null @@ -1,500 +0,0 @@ -use super::super::*; -use libc::*; - -cfg_if! { - if #[cfg(ossl300)] { - extern "C" { - pub fn EVP_MD_get_block_size(md: *const EVP_MD) -> c_int; - pub fn EVP_MD_get_size(md: *const EVP_MD) -> c_int; - pub fn EVP_MD_get_type(md: *const EVP_MD) -> c_int; - - pub fn EVP_MD_CTX_get0_md(ctx: *const EVP_MD_CTX) -> *const EVP_MD; - - pub fn EVP_CIPHER_get_key_length(cipher: *const EVP_CIPHER) -> c_int; - pub fn EVP_CIPHER_get_block_size(cipher: *const EVP_CIPHER) -> c_int; - pub fn EVP_CIPHER_get_iv_length(cipher: *const EVP_CIPHER) -> c_int; - pub fn EVP_CIPHER_get_nid(cipher: *const EVP_CIPHER) -> c_int; - pub fn EVP_CIPHER_fetch( - ctx: *mut OSSL_LIB_CTX, - algorithm: *const c_char, - properties: *const c_char, - ) -> *mut EVP_CIPHER; - pub fn EVP_CIPHER_free(cipher: *mut EVP_CIPHER); - - pub fn EVP_CIPHER_CTX_get0_cipher(ctx: *const EVP_CIPHER_CTX) -> *const EVP_CIPHER; - pub fn EVP_CIPHER_CTX_get_block_size(ctx: *const EVP_CIPHER_CTX) -> c_int; - pub fn EVP_CIPHER_CTX_get_key_length(ctx: *const EVP_CIPHER_CTX) -> c_int; - pub fn EVP_CIPHER_CTX_get_iv_length(ctx: *const EVP_CIPHER_CTX) -> c_int; - pub fn EVP_CIPHER_CTX_get_tag_length(ctx: *const EVP_CIPHER_CTX) -> c_int; - pub fn EVP_CIPHER_CTX_get_num(ctx: *const EVP_CIPHER_CTX) -> c_int; - } - } else { - extern "C" { - pub fn EVP_MD_block_size(md: *const EVP_MD) -> c_int; - pub fn EVP_MD_size(md: *const EVP_MD) -> c_int; - pub fn EVP_MD_type(md: *const EVP_MD) -> c_int; - - pub fn EVP_MD_CTX_md(ctx: *const EVP_MD_CTX) -> *const EVP_MD; - - pub fn EVP_CIPHER_key_length(cipher: *const EVP_CIPHER) -> c_int; - pub fn EVP_CIPHER_block_size(cipher: *const EVP_CIPHER) -> c_int; - pub fn EVP_CIPHER_iv_length(cipher: *const EVP_CIPHER) -> c_int; - pub fn EVP_CIPHER_nid(cipher: *const EVP_CIPHER) -> c_int; - - pub fn EVP_CIPHER_CTX_cipher(ctx: *const EVP_CIPHER_CTX) -> *const EVP_CIPHER; - pub fn EVP_CIPHER_CTX_block_size(ctx: *const EVP_CIPHER_CTX) -> c_int; - pub fn EVP_CIPHER_CTX_key_length(ctx: *const EVP_CIPHER_CTX) -> c_int; - pub fn EVP_CIPHER_CTX_iv_length(ctx: *const EVP_CIPHER_CTX) -> c_int; - #[cfg(ossl110)] - pub fn EVP_CIPHER_CTX_num(ctx: *const EVP_CIPHER_CTX) -> c_int; - } - } -} - -cfg_if! { - if #[cfg(ossl110)] { - extern "C" { - pub fn EVP_MD_CTX_new() -> *mut EVP_MD_CTX; - pub fn EVP_MD_CTX_free(ctx: *mut EVP_MD_CTX); - } - } else { - extern "C" { - pub fn EVP_MD_CTX_create() -> *mut EVP_MD_CTX; - pub fn EVP_MD_CTX_destroy(ctx: *mut EVP_MD_CTX); - } - } -} - -extern "C" { - pub fn EVP_DigestInit_ex(ctx: *mut EVP_MD_CTX, typ: *const EVP_MD, imple: *mut ENGINE) -> c_int; - pub fn EVP_DigestUpdate(ctx: *mut EVP_MD_CTX, data: *const c_void, n: size_t) -> c_int; - pub fn EVP_DigestFinal_ex(ctx: *mut EVP_MD_CTX, res: *mut u8, n: *mut u32) -> c_int; - #[cfg(ossl300)] - pub fn EVP_Q_digest( - libctx: *mut OSSL_LIB_CTX, - name: *const c_char, - propq: *const c_char, - data: *const c_void, - count: size_t, - md: *mut c_uchar, - size: *mut size_t, - ) -> c_int; - pub fn EVP_DigestInit(ctx: *mut EVP_MD_CTX, typ: *const EVP_MD) -> c_int; - pub fn EVP_DigestFinal(ctx: *mut EVP_MD_CTX, res: *mut u8, n: *mut u32) -> c_int; - #[cfg(ossl111)] - pub fn EVP_DigestFinalXOF(ctx: *mut EVP_MD_CTX, res: *mut u8, len: usize) -> c_int; - - #[cfg(ossl300)] - pub fn EVP_MD_fetch(ctx: *mut OSSL_LIB_CTX, algorithm: *const c_char, properties: *const c_char) -> *mut EVP_MD; - - #[cfg(ossl300)] - pub fn EVP_MD_free(md: *mut EVP_MD); - - pub fn EVP_BytesToKey( - typ: *const EVP_CIPHER, - md: *const EVP_MD, - salt: *const u8, - data: *const u8, - datalen: c_int, - count: c_int, - key: *mut u8, - iv: *mut u8, - ) -> c_int; - - pub fn EVP_CipherInit(ctx: *mut EVP_CIPHER_CTX, evp: *const EVP_CIPHER, key: *const u8, iv: *const u8, mode: c_int) -> c_int; - pub fn EVP_CipherInit_ex( - ctx: *mut EVP_CIPHER_CTX, - type_: *const EVP_CIPHER, - impl_: *mut ENGINE, - key: *const c_uchar, - iv: *const c_uchar, - enc: c_int, - ) -> c_int; - pub fn EVP_CipherUpdate(ctx: *mut EVP_CIPHER_CTX, outbuf: *mut u8, outlen: *mut c_int, inbuf: *const u8, inlen: c_int) -> c_int; - pub fn EVP_CipherFinal(ctx: *mut EVP_CIPHER_CTX, res: *mut u8, len: *mut c_int) -> c_int; - - pub fn EVP_DigestSignInit(ctx: *mut EVP_MD_CTX, pctx: *mut *mut EVP_PKEY_CTX, type_: *const EVP_MD, e: *mut ENGINE, pkey: *mut EVP_PKEY) - -> c_int; - - #[cfg(ossl300)] - pub fn EVP_DigestSignUpdate(ctx: *mut EVP_MD_CTX, data: *const c_void, dsize: size_t) -> c_int; - pub fn EVP_DigestSignFinal(ctx: *mut EVP_MD_CTX, sig: *mut c_uchar, siglen: *mut size_t) -> c_int; - pub fn EVP_DigestVerifyInit( - ctx: *mut EVP_MD_CTX, - pctx: *mut *mut EVP_PKEY_CTX, - type_: *const EVP_MD, - e: *mut ENGINE, - pkey: *mut EVP_PKEY, - ) -> c_int; - #[cfg(ossl300)] - pub fn EVP_DigestVerifyUpdate(ctx: *mut EVP_MD_CTX, data: *const c_void, dsize: size_t) -> c_int; - pub fn EVP_SealInit( - ctx: *mut EVP_CIPHER_CTX, - type_: *const EVP_CIPHER, - ek: *mut *mut c_uchar, - ekl: *mut c_int, - iv: *mut c_uchar, - pubk: *mut *mut EVP_PKEY, - npubk: c_int, - ) -> c_int; - pub fn EVP_SealFinal(ctx: *mut EVP_CIPHER_CTX, out: *mut c_uchar, outl: *mut c_int) -> c_int; - pub fn EVP_EncryptInit_ex( - ctx: *mut EVP_CIPHER_CTX, - cipher: *const EVP_CIPHER, - impl_: *mut ENGINE, - key: *const c_uchar, - iv: *const c_uchar, - ) -> c_int; - pub fn EVP_EncryptUpdate(ctx: *mut EVP_CIPHER_CTX, out: *mut c_uchar, outl: *mut c_int, in_: *const u8, inl: c_int) -> c_int; - pub fn EVP_EncryptFinal_ex(ctx: *mut EVP_CIPHER_CTX, out: *mut c_uchar, outl: *mut c_int) -> c_int; - pub fn EVP_OpenInit( - ctx: *mut EVP_CIPHER_CTX, - type_: *const EVP_CIPHER, - ek: *const c_uchar, - ekl: c_int, - iv: *const c_uchar, - priv_: *mut EVP_PKEY, - ) -> c_int; - pub fn EVP_OpenFinal(ctx: *mut EVP_CIPHER_CTX, out: *mut c_uchar, outl: *mut c_int) -> c_int; - pub fn EVP_DecryptInit_ex( - ctx: *mut EVP_CIPHER_CTX, - cipher: *const EVP_CIPHER, - impl_: *mut ENGINE, - key: *const c_uchar, - iv: *const c_uchar, - ) -> c_int; - pub fn EVP_DecryptUpdate(ctx: *mut EVP_CIPHER_CTX, out: *mut c_uchar, outl: *mut c_int, in_: *const u8, inl: c_int) -> c_int; - pub fn EVP_DecryptFinal_ex(ctx: *mut EVP_CIPHER_CTX, outm: *mut c_uchar, outl: *mut c_int) -> c_int; -} -cfg_if! { - if #[cfg(ossl300)] { - extern "C" { - pub fn EVP_PKEY_get_size(pkey: *const EVP_PKEY) -> c_int; - } - } else { - const_ptr_api! { - extern "C" { - pub fn EVP_PKEY_size(pkey: #[const_ptr_if(any(ossl111b, libressl280))] EVP_PKEY) -> c_int; - } - } - } -} -cfg_if! { - if #[cfg(ossl111)] { - extern "C" { - pub fn EVP_DigestSign( - ctx: *mut EVP_MD_CTX, - sigret: *mut c_uchar, - siglen: *mut size_t, - tbs: *const c_uchar, - tbslen: size_t - ) -> c_int; - - pub fn EVP_DigestVerify( - ctx: *mut EVP_MD_CTX, - sigret: *const c_uchar, - siglen: size_t, - tbs: *const c_uchar, - tbslen: size_t - ) -> c_int; - } - } -} -const_ptr_api! { - extern "C" { - pub fn EVP_DigestVerifyFinal( - ctx: *mut EVP_MD_CTX, - sigret: #[const_ptr_if(any(ossl102, libressl280))] c_uchar, - siglen: size_t, - ) -> c_int; - } -} - -extern "C" { - pub fn EVP_CIPHER_CTX_new() -> *mut EVP_CIPHER_CTX; - pub fn EVP_CIPHER_CTX_free(ctx: *mut EVP_CIPHER_CTX); - pub fn EVP_MD_CTX_copy_ex(dst: *mut EVP_MD_CTX, src: *const EVP_MD_CTX) -> c_int; - #[cfg(ossl111)] - pub fn EVP_MD_CTX_reset(ctx: *mut EVP_MD_CTX) -> c_int; - pub fn EVP_CIPHER_CTX_set_key_length(ctx: *mut EVP_CIPHER_CTX, keylen: c_int) -> c_int; - pub fn EVP_CIPHER_CTX_set_padding(ctx: *mut EVP_CIPHER_CTX, padding: c_int) -> c_int; - pub fn EVP_CIPHER_CTX_ctrl(ctx: *mut EVP_CIPHER_CTX, type_: c_int, arg: c_int, ptr: *mut c_void) -> c_int; - pub fn EVP_CIPHER_CTX_rand_key(ctx: *mut EVP_CIPHER_CTX, key: *mut c_uchar) -> c_int; - - pub fn EVP_md_null() -> *const EVP_MD; - pub fn EVP_md5() -> *const EVP_MD; - pub fn EVP_sha1() -> *const EVP_MD; - pub fn EVP_sha224() -> *const EVP_MD; - pub fn EVP_sha256() -> *const EVP_MD; - pub fn EVP_sha384() -> *const EVP_MD; - pub fn EVP_sha512() -> *const EVP_MD; - #[cfg(ossl111)] - pub fn EVP_sha3_224() -> *const EVP_MD; - #[cfg(ossl111)] - pub fn EVP_sha3_256() -> *const EVP_MD; - #[cfg(ossl111)] - pub fn EVP_sha3_384() -> *const EVP_MD; - #[cfg(ossl111)] - pub fn EVP_sha3_512() -> *const EVP_MD; - #[cfg(ossl111)] - pub fn EVP_shake128() -> *const EVP_MD; - #[cfg(ossl111)] - pub fn EVP_shake256() -> *const EVP_MD; - pub fn EVP_ripemd160() -> *const EVP_MD; - #[cfg(all(any(ossl111, libressl291), not(osslconf = "OPENSSL_NO_SM3")))] - pub fn EVP_sm3() -> *const EVP_MD; - pub fn EVP_des_ecb() -> *const EVP_CIPHER; - pub fn EVP_des_ede3() -> *const EVP_CIPHER; - pub fn EVP_des_ede3_cbc() -> *const EVP_CIPHER; - pub fn EVP_des_ede3_cfb64() -> *const EVP_CIPHER; - pub fn EVP_des_cbc() -> *const EVP_CIPHER; - pub fn EVP_rc4() -> *const EVP_CIPHER; - pub fn EVP_bf_ecb() -> *const EVP_CIPHER; - pub fn EVP_bf_cbc() -> *const EVP_CIPHER; - pub fn EVP_bf_cfb64() -> *const EVP_CIPHER; - pub fn EVP_bf_ofb() -> *const EVP_CIPHER; - pub fn EVP_aes_128_ecb() -> *const EVP_CIPHER; - pub fn EVP_aes_128_cbc() -> *const EVP_CIPHER; - pub fn EVP_aes_128_cfb1() -> *const EVP_CIPHER; - pub fn EVP_aes_128_cfb8() -> *const EVP_CIPHER; - pub fn EVP_aes_128_cfb128() -> *const EVP_CIPHER; - pub fn EVP_aes_128_ctr() -> *const EVP_CIPHER; - pub fn EVP_aes_128_ccm() -> *const EVP_CIPHER; - pub fn EVP_aes_128_gcm() -> *const EVP_CIPHER; - pub fn EVP_aes_128_xts() -> *const EVP_CIPHER; - pub fn EVP_aes_128_ofb() -> *const EVP_CIPHER; - #[cfg(ossl110)] - pub fn EVP_aes_128_ocb() -> *const EVP_CIPHER; - pub fn EVP_aes_192_ecb() -> *const EVP_CIPHER; - pub fn EVP_aes_192_cbc() -> *const EVP_CIPHER; - pub fn EVP_aes_192_cfb1() -> *const EVP_CIPHER; - pub fn EVP_aes_192_cfb8() -> *const EVP_CIPHER; - pub fn EVP_aes_192_cfb128() -> *const EVP_CIPHER; - pub fn EVP_aes_192_ctr() -> *const EVP_CIPHER; - pub fn EVP_aes_192_ccm() -> *const EVP_CIPHER; - pub fn EVP_aes_192_gcm() -> *const EVP_CIPHER; - pub fn EVP_aes_192_ofb() -> *const EVP_CIPHER; - #[cfg(ossl110)] - pub fn EVP_aes_192_ocb() -> *const EVP_CIPHER; - pub fn EVP_aes_256_ecb() -> *const EVP_CIPHER; - pub fn EVP_aes_256_cbc() -> *const EVP_CIPHER; - pub fn EVP_aes_256_cfb1() -> *const EVP_CIPHER; - pub fn EVP_aes_256_cfb8() -> *const EVP_CIPHER; - pub fn EVP_aes_256_cfb128() -> *const EVP_CIPHER; - pub fn EVP_aes_256_ctr() -> *const EVP_CIPHER; - pub fn EVP_aes_256_ccm() -> *const EVP_CIPHER; - pub fn EVP_aes_256_gcm() -> *const EVP_CIPHER; - pub fn EVP_aes_256_xts() -> *const EVP_CIPHER; - pub fn EVP_aes_256_ofb() -> *const EVP_CIPHER; - #[cfg(ossl110)] - pub fn EVP_aes_256_ocb() -> *const EVP_CIPHER; - #[cfg(all(ossl110, not(osslconf = "OPENSSL_NO_CHACHA")))] - pub fn EVP_chacha20() -> *const EVP_CIPHER; - #[cfg(all(ossl110, not(osslconf = "OPENSSL_NO_CHACHA")))] - pub fn EVP_chacha20_poly1305() -> *const EVP_CIPHER; - #[cfg(not(osslconf = "OPENSSL_NO_SEED"))] - pub fn EVP_seed_cbc() -> *const EVP_CIPHER; - #[cfg(not(osslconf = "OPENSSL_NO_SEED"))] - pub fn EVP_seed_cfb128() -> *const EVP_CIPHER; - #[cfg(not(osslconf = "OPENSSL_NO_SEED"))] - pub fn EVP_seed_ecb() -> *const EVP_CIPHER; - #[cfg(not(osslconf = "OPENSSL_NO_SEED"))] - pub fn EVP_seed_ofb() -> *const EVP_CIPHER; - - #[cfg(all(any(ossl111, libressl291), not(osslconf = "OPENSSL_NO_SM4")))] - pub fn EVP_sm4_ecb() -> *const EVP_CIPHER; - #[cfg(all(any(ossl111, libressl291), not(osslconf = "OPENSSL_NO_SM4")))] - pub fn EVP_sm4_cbc() -> *const EVP_CIPHER; - #[cfg(all(any(ossl111, libressl291), not(osslconf = "OPENSSL_NO_SM4")))] - pub fn EVP_sm4_cfb128() -> *const EVP_CIPHER; - #[cfg(all(any(ossl111, libressl291), not(osslconf = "OPENSSL_NO_SM4")))] - pub fn EVP_sm4_ofb() -> *const EVP_CIPHER; - #[cfg(all(any(ossl111, libressl291), not(osslconf = "OPENSSL_NO_SM4")))] - pub fn EVP_sm4_ctr() -> *const EVP_CIPHER; - - #[cfg(not(any(boringssl, osslconf = "OPENSSL_NO_CAMELLIA")))] - pub fn EVP_camellia_128_cfb128() -> *const EVP_CIPHER; - #[cfg(not(any(boringssl, osslconf = "OPENSSL_NO_CAMELLIA")))] - pub fn EVP_camellia_128_ecb() -> *const EVP_CIPHER; - #[cfg(not(any(boringssl, osslconf = "OPENSSL_NO_CAMELLIA")))] - pub fn EVP_camellia_192_cfb128() -> *const EVP_CIPHER; - #[cfg(not(any(boringssl, osslconf = "OPENSSL_NO_CAMELLIA")))] - pub fn EVP_camellia_192_ecb() -> *const EVP_CIPHER; - #[cfg(not(any(boringssl, osslconf = "OPENSSL_NO_CAMELLIA")))] - pub fn EVP_camellia_256_cfb128() -> *const EVP_CIPHER; - #[cfg(not(any(boringssl, osslconf = "OPENSSL_NO_CAMELLIA")))] - pub fn EVP_camellia_256_ecb() -> *const EVP_CIPHER; - - #[cfg(not(any(boringssl, osslconf = "OPENSSL_NO_CAST")))] - pub fn EVP_cast5_cfb64() -> *const EVP_CIPHER; - #[cfg(not(any(boringssl, osslconf = "OPENSSL_NO_CAST")))] - pub fn EVP_cast5_ecb() -> *const EVP_CIPHER; - - #[cfg(not(any(boringssl, osslconf = "OPENSSL_NO_IDEA")))] - pub fn EVP_idea_cfb64() -> *const EVP_CIPHER; - #[cfg(not(any(boringssl, osslconf = "OPENSSL_NO_IDEA")))] - pub fn EVP_idea_ecb() -> *const EVP_CIPHER; - - #[cfg(not(ossl110))] - pub fn OPENSSL_add_all_algorithms_noconf(); - - pub fn EVP_get_digestbyname(name: *const c_char) -> *const EVP_MD; - pub fn EVP_get_cipherbyname(name: *const c_char) -> *const EVP_CIPHER; -} - -cfg_if! { - if #[cfg(ossl300)] { - extern "C" { - pub fn EVP_PKEY_get_id(pkey: *const EVP_PKEY) -> c_int; - pub fn EVP_PKEY_get_bits(key: *const EVP_PKEY) -> c_int; - pub fn EVP_PKEY_get_security_bits(key: *const EVP_PKEY) -> c_int; - } - - #[inline] - pub unsafe fn EVP_PKEY_id(pkey: *const EVP_PKEY) -> c_int { - EVP_PKEY_get_id(pkey) - } - - #[inline] - pub unsafe fn EVP_PKEY_bits(pkey: *const EVP_PKEY) -> c_int { - EVP_PKEY_get_bits(pkey) - } - - #[inline] - pub unsafe fn EVP_PKEY_security_bits(pkey: *const EVP_PKEY) -> c_int { - EVP_PKEY_get_security_bits(pkey) - } - - } else { - extern "C" { - pub fn EVP_PKEY_id(pkey: *const EVP_PKEY) -> c_int; - } - const_ptr_api! { - extern "C" { - pub fn EVP_PKEY_bits(key: #[const_ptr_if(any(ossl110, libressl280))] EVP_PKEY) -> c_int; - #[cfg(any(ossl110, libressl360))] - pub fn EVP_PKEY_security_bits(pkey: #[const_ptr_if(any(ossl110, libressl280))] EVP_PKEY) -> c_int; - } - } - } -} -extern "C" { - pub fn EVP_PKEY_assign(pkey: *mut EVP_PKEY, typ: c_int, key: *mut c_void) -> c_int; - - pub fn EVP_PKEY_set1_RSA(k: *mut EVP_PKEY, r: *mut RSA) -> c_int; - pub fn EVP_PKEY_get1_RSA(k: *mut EVP_PKEY) -> *mut RSA; - pub fn EVP_PKEY_get1_DSA(k: *mut EVP_PKEY) -> *mut DSA; - pub fn EVP_PKEY_get1_DH(k: *mut EVP_PKEY) -> *mut DH; - pub fn EVP_PKEY_get1_EC_KEY(k: *mut EVP_PKEY) -> *mut EC_KEY; - - pub fn EVP_PKEY_new() -> *mut EVP_PKEY; - pub fn EVP_PKEY_free(k: *mut EVP_PKEY); - #[cfg(any(ossl110, libressl270))] - pub fn EVP_PKEY_up_ref(pkey: *mut EVP_PKEY) -> c_int; - - pub fn d2i_AutoPrivateKey(a: *mut *mut EVP_PKEY, pp: *mut *const c_uchar, length: c_long) -> *mut EVP_PKEY; - - pub fn EVP_PKEY_cmp(a: *const EVP_PKEY, b: *const EVP_PKEY) -> c_int; - - pub fn EVP_PKEY_copy_parameters(to: *mut EVP_PKEY, from: *const EVP_PKEY) -> c_int; - - pub fn PKCS5_PBKDF2_HMAC_SHA1( - pass: *const c_char, - passlen: c_int, - salt: *const u8, - saltlen: c_int, - iter: c_int, - keylen: c_int, - out: *mut u8, - ) -> c_int; - pub fn PKCS5_PBKDF2_HMAC( - pass: *const c_char, - passlen: c_int, - salt: *const c_uchar, - saltlen: c_int, - iter: c_int, - digest: *const EVP_MD, - keylen: c_int, - out: *mut u8, - ) -> c_int; - - #[cfg(ossl110)] - pub fn EVP_PBE_scrypt( - pass: *const c_char, - passlen: size_t, - salt: *const c_uchar, - saltlen: size_t, - N: u64, - r: u64, - p: u64, - maxmem: u64, - key: *mut c_uchar, - keylen: size_t, - ) -> c_int; - - pub fn EVP_PKEY_CTX_new(k: *mut EVP_PKEY, e: *mut ENGINE) -> *mut EVP_PKEY_CTX; - pub fn EVP_PKEY_CTX_new_id(id: c_int, e: *mut ENGINE) -> *mut EVP_PKEY_CTX; - pub fn EVP_PKEY_CTX_free(ctx: *mut EVP_PKEY_CTX); - - pub fn EVP_PKEY_CTX_ctrl(ctx: *mut EVP_PKEY_CTX, keytype: c_int, optype: c_int, cmd: c_int, p1: c_int, p2: *mut c_void) -> c_int; - - pub fn EVP_PKEY_new_mac_key(type_: c_int, e: *mut ENGINE, key: *const c_uchar, keylen: c_int) -> *mut EVP_PKEY; - - pub fn EVP_PKEY_derive_init(ctx: *mut EVP_PKEY_CTX) -> c_int; - pub fn EVP_PKEY_derive_set_peer(ctx: *mut EVP_PKEY_CTX, peer: *mut EVP_PKEY) -> c_int; - pub fn EVP_PKEY_derive(ctx: *mut EVP_PKEY_CTX, key: *mut c_uchar, size: *mut size_t) -> c_int; - - #[cfg(ossl300)] - pub fn EVP_PKEY_Q_keygen(libctx: *mut OSSL_LIB_CTX, propq: *const c_char, type_: *const c_char, ...) -> *mut EVP_PKEY; - pub fn EVP_PKEY_keygen_init(ctx: *mut EVP_PKEY_CTX) -> c_int; - pub fn EVP_PKEY_keygen(ctx: *mut EVP_PKEY_CTX, key: *mut *mut EVP_PKEY) -> c_int; - - pub fn EVP_PKEY_sign_init(ctx: *mut EVP_PKEY_CTX) -> c_int; - pub fn EVP_PKEY_sign(ctx: *mut EVP_PKEY_CTX, sig: *mut c_uchar, siglen: *mut size_t, tbs: *const c_uchar, tbslen: size_t) -> c_int; - pub fn EVP_PKEY_verify_init(ctx: *mut EVP_PKEY_CTX) -> c_int; - pub fn EVP_PKEY_verify(ctx: *mut EVP_PKEY_CTX, sig: *const c_uchar, siglen: size_t, tbs: *const c_uchar, tbslen: size_t) -> c_int; - pub fn EVP_PKEY_encrypt_init(ctx: *mut EVP_PKEY_CTX) -> c_int; - pub fn EVP_PKEY_encrypt(ctx: *mut EVP_PKEY_CTX, pout: *mut c_uchar, poutlen: *mut size_t, pin: *const c_uchar, pinlen: size_t) -> c_int; - pub fn EVP_PKEY_decrypt_init(ctx: *mut EVP_PKEY_CTX) -> c_int; - pub fn EVP_PKEY_decrypt(ctx: *mut EVP_PKEY_CTX, pout: *mut c_uchar, poutlen: *mut size_t, pin: *const c_uchar, pinlen: size_t) -> c_int; -} - -const_ptr_api! { - extern "C" { - pub fn EVP_PKCS82PKEY(p8: #[const_ptr_if(any(ossl110, libressl280))] PKCS8_PRIV_KEY_INFO) -> *mut EVP_PKEY; - } -} - -cfg_if! { - if #[cfg(any(ossl111))] { - extern "C" { - pub fn EVP_PKEY_get_raw_public_key( - pkey: *const EVP_PKEY, - ppub: *mut c_uchar, - len: *mut size_t, - ) -> c_int; - pub fn EVP_PKEY_new_raw_public_key( - ttype: c_int, - e: *mut ENGINE, - key: *const c_uchar, - keylen: size_t, - ) -> *mut EVP_PKEY; - pub fn EVP_PKEY_get_raw_private_key( - pkey: *const EVP_PKEY, - ppriv: *mut c_uchar, - len: *mut size_t, - ) -> c_int; - pub fn EVP_PKEY_new_raw_private_key( - ttype: c_int, - e: *mut ENGINE, - key: *const c_uchar, - keylen: size_t, - ) -> *mut EVP_PKEY; - } - } -} - -extern "C" { - pub fn EVP_EncodeBlock(dst: *mut c_uchar, src: *const c_uchar, src_len: c_int) -> c_int; - pub fn EVP_DecodeBlock(dst: *mut c_uchar, src: *const c_uchar, src_len: c_int) -> c_int; -} diff --git a/openssl-sys/src/handwritten/hmac.rs b/openssl-sys/src/handwritten/hmac.rs deleted file mode 100644 index a7b13a1..0000000 --- a/openssl-sys/src/handwritten/hmac.rs +++ /dev/null @@ -1,24 +0,0 @@ -use libc::*; - -use super::super::*; - -cfg_if! { - if #[cfg(any(ossl110, libressl350))] { - extern "C" { - pub fn HMAC_CTX_new() -> *mut HMAC_CTX; - pub fn HMAC_CTX_free(ctx: *mut HMAC_CTX); - } - } else { - extern "C" { - pub fn HMAC_CTX_init(ctx: *mut HMAC_CTX); - pub fn HMAC_CTX_cleanup(ctx: *mut HMAC_CTX); - } - } -} - -extern "C" { - pub fn HMAC_Init_ex(ctx: *mut HMAC_CTX, key: *const c_void, len: c_int, md: *const EVP_MD, impl_: *mut ENGINE) -> c_int; - pub fn HMAC_Update(ctx: *mut HMAC_CTX, data: *const c_uchar, len: size_t) -> c_int; - pub fn HMAC_Final(ctx: *mut HMAC_CTX, md: *mut c_uchar, len: *mut c_uint) -> c_int; - pub fn HMAC_CTX_copy(dst: *mut HMAC_CTX, src: *mut HMAC_CTX) -> c_int; -} diff --git a/openssl-sys/src/handwritten/kdf.rs b/openssl-sys/src/handwritten/kdf.rs deleted file mode 100644 index 0f14b63..0000000 --- a/openssl-sys/src/handwritten/kdf.rs +++ /dev/null @@ -1,26 +0,0 @@ -use super::super::*; -use libc::*; - -cfg_if! { - if #[cfg(ossl300)] { - extern "C" { - pub fn EVP_PKEY_CTX_set_hkdf_mode(ctx: *mut EVP_PKEY_CTX, mode: c_int) -> c_int; - pub fn EVP_PKEY_CTX_set_hkdf_md(ctx: *mut EVP_PKEY_CTX, md: *const EVP_MD) -> c_int; - pub fn EVP_PKEY_CTX_set1_hkdf_salt( - ctx: *mut EVP_PKEY_CTX, - salt: *const u8, - saltlen: c_int, - ) -> c_int; - pub fn EVP_PKEY_CTX_set1_hkdf_key( - ctx: *mut EVP_PKEY_CTX, - key: *const u8, - keylen: c_int, - ) -> c_int; - pub fn EVP_PKEY_CTX_add1_hkdf_info( - ctx: *mut EVP_PKEY_CTX, - info: *const u8, - infolen: c_int, - ) -> c_int; - } - } -} diff --git a/openssl-sys/src/handwritten/mod.rs b/openssl-sys/src/handwritten/mod.rs deleted file mode 100644 index 28aa4ae..0000000 --- a/openssl-sys/src/handwritten/mod.rs +++ /dev/null @@ -1,65 +0,0 @@ -pub use self::aes::*; -pub use self::asn1::*; -pub use self::bio::*; -pub use self::bn::*; -pub use self::cms::*; -pub use self::conf::*; -pub use self::crypto::*; -pub use self::dh::*; -pub use self::dsa::*; -pub use self::ec::*; -pub use self::err::*; -pub use self::evp::*; -pub use self::hmac::*; -pub use self::kdf::*; -pub use self::object::*; -pub use self::ocsp::*; -pub use self::pem::*; -pub use self::pkcs12::*; -pub use self::pkcs7::*; -pub use self::provider::*; -pub use self::rand::*; -pub use self::rsa::*; -pub use self::safestack::*; -pub use self::sha::*; -pub use self::srtp::*; -pub use self::ssl::*; -pub use self::stack::*; -pub use self::tls1::*; -pub use self::types::*; -pub use self::x509::*; -pub use self::x509_vfy::*; -pub use self::x509v3::*; - -mod aes; -mod asn1; -mod bio; -mod bn; -mod cms; -mod conf; -mod crypto; -mod dh; -mod dsa; -mod ec; -mod err; -mod evp; -mod hmac; -mod kdf; -mod object; -mod ocsp; -mod pem; -mod pkcs12; -mod pkcs7; -mod provider; -mod rand; -mod rsa; -mod safestack; -mod sha; -mod srtp; -mod ssl; -mod stack; -mod tls1; -mod types; -mod x509; -mod x509_vfy; -mod x509v3; diff --git a/openssl-sys/src/handwritten/object.rs b/openssl-sys/src/handwritten/object.rs deleted file mode 100644 index 665324d..0000000 --- a/openssl-sys/src/handwritten/object.rs +++ /dev/null @@ -1,20 +0,0 @@ -use libc::*; - -use super::super::*; - -extern "C" { - pub fn OBJ_nid2ln(nid: c_int) -> *const c_char; - pub fn OBJ_nid2sn(nid: c_int) -> *const c_char; - pub fn OBJ_nid2obj(n: c_int) -> *mut ASN1_OBJECT; - pub fn OBJ_obj2nid(o: *const ASN1_OBJECT) -> c_int; - pub fn OBJ_obj2txt(buf: *mut c_char, buf_len: c_int, a: *const ASN1_OBJECT, no_name: c_int) -> c_int; - - pub fn OBJ_find_sigid_algs(signid: c_int, pdig_nid: *mut c_int, ppkey_nid: *mut c_int) -> c_int; - pub fn OBJ_sn2nid(sn: *const libc::c_char) -> libc::c_int; - pub fn OBJ_txt2obj(s: *const libc::c_char, no_name: libc::c_int) -> *mut ASN1_OBJECT; - pub fn OBJ_create(oid: *const libc::c_char, sn: *const libc::c_char, ln: *const libc::c_char) -> c_int; - #[cfg(ossl111)] - pub fn OBJ_length(obj: *const ASN1_OBJECT) -> libc::size_t; - #[cfg(ossl111)] - pub fn OBJ_get0_data(obj: *const ASN1_OBJECT) -> *const c_uchar; -} diff --git a/openssl-sys/src/handwritten/ocsp.rs b/openssl-sys/src/handwritten/ocsp.rs deleted file mode 100644 index 5591164..0000000 --- a/openssl-sys/src/handwritten/ocsp.rs +++ /dev/null @@ -1,71 +0,0 @@ -use super::super::*; -use libc::*; - -pub enum OCSP_CERTID {} - -pub enum OCSP_ONEREQ {} - -pub enum OCSP_REQUEST {} - -pub enum OCSP_BASICRESP {} - -const_ptr_api! { - extern "C" { - pub fn OCSP_cert_to_id( - dgst: *const EVP_MD, - subject: #[const_ptr_if(any(ossl110, libressl281))] X509, - issuer: #[const_ptr_if(any(ossl110, libressl281))] X509, - ) -> *mut OCSP_CERTID; - } -} - -extern "C" { - pub fn OCSP_request_add0_id(r: *mut OCSP_REQUEST, id: *mut OCSP_CERTID) -> *mut OCSP_ONEREQ; - - pub fn OCSP_resp_find_status( - bs: *mut OCSP_BASICRESP, - id: *mut OCSP_CERTID, - status: *mut c_int, - reason: *mut c_int, - revtime: *mut *mut ASN1_GENERALIZEDTIME, - thisupd: *mut *mut ASN1_GENERALIZEDTIME, - nextupd: *mut *mut ASN1_GENERALIZEDTIME, - ) -> c_int; - pub fn OCSP_check_validity(thisupd: *mut ASN1_GENERALIZEDTIME, nextupd: *mut ASN1_GENERALIZEDTIME, sec: c_long, maxsec: c_long) -> c_int; - - pub fn OCSP_response_status(resp: *mut OCSP_RESPONSE) -> c_int; - pub fn OCSP_response_get1_basic(resp: *mut OCSP_RESPONSE) -> *mut OCSP_BASICRESP; - - pub fn OCSP_response_create(status: c_int, bs: *mut OCSP_BASICRESP) -> *mut OCSP_RESPONSE; - - pub fn OCSP_BASICRESP_new() -> *mut OCSP_BASICRESP; - pub fn OCSP_BASICRESP_free(r: *mut OCSP_BASICRESP); - pub fn OCSP_RESPONSE_new() -> *mut OCSP_RESPONSE; - pub fn OCSP_RESPONSE_free(r: *mut OCSP_RESPONSE); -} - -const_ptr_api! { - extern "C" { - pub fn i2d_OCSP_RESPONSE(a: #[const_ptr_if(ossl300)] OCSP_RESPONSE, pp: *mut *mut c_uchar) -> c_int; - } -} - -extern "C" { - pub fn d2i_OCSP_RESPONSE(a: *mut *mut OCSP_RESPONSE, pp: *mut *const c_uchar, length: c_long) -> *mut OCSP_RESPONSE; - pub fn OCSP_ONEREQ_free(r: *mut OCSP_ONEREQ); - pub fn OCSP_CERTID_free(id: *mut OCSP_CERTID); - pub fn OCSP_REQUEST_new() -> *mut OCSP_REQUEST; - pub fn OCSP_REQUEST_free(r: *mut OCSP_REQUEST); -} - -const_ptr_api! { - extern "C" { - pub fn i2d_OCSP_REQUEST(a: #[const_ptr_if(ossl300)] OCSP_REQUEST, pp: *mut *mut c_uchar) -> c_int; - } -} - -extern "C" { - pub fn d2i_OCSP_REQUEST(a: *mut *mut OCSP_REQUEST, pp: *mut *const c_uchar, length: c_long) -> *mut OCSP_REQUEST; - - pub fn OCSP_basic_verify(bs: *mut OCSP_BASICRESP, certs: *mut stack_st_X509, st: *mut X509_STORE, flags: c_ulong) -> c_int; -} diff --git a/openssl-sys/src/handwritten/pem.rs b/openssl-sys/src/handwritten/pem.rs deleted file mode 100644 index da05f3c..0000000 --- a/openssl-sys/src/handwritten/pem.rs +++ /dev/null @@ -1,101 +0,0 @@ -use super::super::*; -use libc::*; - -pub type pem_password_cb = Option c_int>; - -const_ptr_api! { - extern "C" { - pub fn PEM_write_bio_X509(bio: *mut BIO, x509: #[const_ptr_if(ossl300)] X509) -> c_int; - pub fn PEM_write_bio_X509_REQ(bio: *mut BIO, x509: #[const_ptr_if(ossl300)] X509_REQ) -> c_int; - pub fn PEM_write_bio_X509_CRL(bio: *mut BIO, x509: #[const_ptr_if(ossl300)] X509_CRL) -> c_int; - pub fn PEM_write_bio_RSAPrivateKey( - bp: *mut BIO, - rsa: #[const_ptr_if(ossl300)] RSA, - cipher: *const EVP_CIPHER, - kstr: #[const_ptr_if(ossl300)] c_uchar, - klen: c_int, - callback: pem_password_cb, - user_data: *mut c_void, - ) -> c_int; - pub fn PEM_write_bio_RSA_PUBKEY(bp: *mut BIO, rsa: #[const_ptr_if(ossl300)] RSA) -> c_int; - pub fn PEM_write_bio_DSAPrivateKey( - bp: *mut BIO, - dsa: #[const_ptr_if(ossl300)] DSA, - cipher: *const EVP_CIPHER, - kstr: #[const_ptr_if(ossl300)] c_uchar, - klen: c_int, - callback: pem_password_cb, - user_data: *mut c_void, - ) -> c_int; - pub fn PEM_write_bio_ECPrivateKey( - bio: *mut BIO, - key: #[const_ptr_if(ossl300)] EC_KEY, - cipher: *const EVP_CIPHER, - kstr: #[const_ptr_if(ossl300)] c_uchar, - klen: c_int, - callback: pem_password_cb, - user_data: *mut c_void, - ) -> c_int; - pub fn PEM_write_bio_DSA_PUBKEY(bp: *mut BIO, dsa: #[const_ptr_if(ossl300)] DSA) -> c_int; - pub fn PEM_write_bio_PrivateKey( - bio: *mut BIO, - pkey: #[const_ptr_if(ossl300)] EVP_PKEY, - cipher: *const EVP_CIPHER, - kstr: #[const_ptr_if(ossl300)] c_uchar, - klen: c_int, - callback: pem_password_cb, - user_data: *mut c_void, - ) -> c_int; - pub fn PEM_write_bio_PUBKEY(bp: *mut BIO, x: #[const_ptr_if(ossl300)] EVP_PKEY) -> c_int; - pub fn PEM_write_bio_PKCS8PrivateKey( - bio: *mut BIO, - pkey: #[const_ptr_if(ossl300)] EVP_PKEY, - cipher: *const EVP_CIPHER, - kstr: #[const_ptr_if(ossl300)] c_char, - klen: c_int, - callback: pem_password_cb, - user_data: *mut c_void, - ) -> c_int; - pub fn PEM_write_bio_PKCS7(bp: *mut BIO, x: #[const_ptr_if(ossl300)] PKCS7) -> c_int; - pub fn PEM_write_bio_EC_PUBKEY(bp: *mut BIO, ec: #[const_ptr_if(ossl300)] EC_KEY) -> c_int; - pub fn i2d_PKCS8PrivateKey_bio( - bp: *mut BIO, - x: #[const_ptr_if(ossl300)] EVP_PKEY, - enc: *const EVP_CIPHER, - kstr: #[const_ptr_if(ossl300)] c_char, - klen: c_int, - cb: pem_password_cb, - u: *mut c_void, - ) -> c_int; - } -} - -extern "C" { - pub fn PEM_read_bio_X509(bio: *mut BIO, out: *mut *mut X509, callback: pem_password_cb, user_data: *mut c_void) -> *mut X509; - pub fn PEM_read_bio_X509_REQ(bio: *mut BIO, out: *mut *mut X509_REQ, callback: pem_password_cb, user_data: *mut c_void) -> *mut X509_REQ; - pub fn PEM_read_bio_X509_CRL(bio: *mut BIO, out: *mut *mut X509_CRL, callback: pem_password_cb, user_data: *mut c_void) -> *mut X509_CRL; - pub fn PEM_read_bio_RSAPrivateKey(bio: *mut BIO, rsa: *mut *mut RSA, callback: pem_password_cb, user_data: *mut c_void) -> *mut RSA; - pub fn PEM_read_bio_RSAPublicKey(bio: *mut BIO, rsa: *mut *mut RSA, callback: pem_password_cb, user_data: *mut c_void) -> *mut RSA; - pub fn PEM_write_bio_RSAPublicKey(bp: *mut BIO, rsa: *const RSA) -> c_int; - pub fn PEM_read_bio_RSA_PUBKEY(bio: *mut BIO, rsa: *mut *mut RSA, callback: pem_password_cb, user_data: *mut c_void) -> *mut RSA; - pub fn PEM_read_bio_DSAPrivateKey(bp: *mut BIO, dsa: *mut *mut DSA, callback: pem_password_cb, user_data: *mut c_void) -> *mut DSA; - pub fn PEM_read_bio_DSA_PUBKEY(bp: *mut BIO, dsa: *mut *mut DSA, callback: pem_password_cb, user_data: *mut c_void) -> *mut DSA; - pub fn PEM_read_bio_ECPrivateKey(bio: *mut BIO, key: *mut *mut EC_KEY, callback: pem_password_cb, user_data: *mut c_void) -> *mut EC_KEY; - pub fn PEM_read_bio_EC_PUBKEY(bp: *mut BIO, ec: *mut *mut EC_KEY, callback: pem_password_cb, user_data: *mut c_void) -> *mut EC_KEY; - pub fn PEM_read_bio_DHparams(bio: *mut BIO, out: *mut *mut DH, callback: pem_password_cb, user_data: *mut c_void) -> *mut DH; - pub fn PEM_write_bio_DHparams(bio: *mut BIO, x: *const DH) -> c_int; - pub fn PEM_read_bio_PrivateKey(bio: *mut BIO, out: *mut *mut EVP_PKEY, callback: pem_password_cb, user_data: *mut c_void) -> *mut EVP_PKEY; - pub fn PEM_read_bio_PUBKEY(bio: *mut BIO, out: *mut *mut EVP_PKEY, callback: pem_password_cb, user_data: *mut c_void) -> *mut EVP_PKEY; - - pub fn d2i_PKCS8PrivateKey_bio(bp: *mut BIO, x: *mut *mut EVP_PKEY, cb: pem_password_cb, u: *mut c_void) -> *mut EVP_PKEY; - pub fn d2i_PKCS8_PRIV_KEY_INFO(k: *mut *mut PKCS8_PRIV_KEY_INFO, buf: *mut *const u8, length: c_long) -> *mut PKCS8_PRIV_KEY_INFO; - pub fn PKCS8_PRIV_KEY_INFO_free(p8inf: *mut PKCS8_PRIV_KEY_INFO); - - pub fn PEM_read_bio_PKCS7(bio: *mut BIO, out: *mut *mut PKCS7, cb: pem_password_cb, u: *mut c_void) -> *mut PKCS7; - - #[cfg(ossl101)] - pub fn PEM_read_bio_CMS(bio: *mut BIO, out: *mut *mut CMS_ContentInfo, callback: pem_password_cb, user_data: *mut c_void) - -> *mut CMS_ContentInfo; - #[cfg(ossl101)] - pub fn PEM_write_bio_CMS(bio: *mut BIO, cms: *const CMS_ContentInfo) -> c_int; -} diff --git a/openssl-sys/src/handwritten/pkcs12.rs b/openssl-sys/src/handwritten/pkcs12.rs deleted file mode 100644 index a1cc3de..0000000 --- a/openssl-sys/src/handwritten/pkcs12.rs +++ /dev/null @@ -1,47 +0,0 @@ -use libc::*; - -use super::super::*; - -pub enum PKCS12 {} - -extern "C" { - pub fn PKCS12_free(p12: *mut PKCS12); -} -const_ptr_api! { - extern "C" { - pub fn i2d_PKCS12(a: #[const_ptr_if(ossl300)] PKCS12, buf: *mut *mut u8) -> c_int; - } -} -extern "C" { - pub fn d2i_PKCS12(a: *mut *mut PKCS12, pp: *mut *const u8, length: c_long) -> *mut PKCS12; - - pub fn PKCS12_parse(p12: *mut PKCS12, pass: *const c_char, pkey: *mut *mut EVP_PKEY, cert: *mut *mut X509, ca: *mut *mut stack_st_X509) -> c_int; - - pub fn PKCS12_set_mac( - p12: *mut PKCS12, - pass: *const c_char, - passlen: c_int, - salt: *mut c_uchar, - saltlen: c_int, - iter: c_int, - md_type: *const EVP_MD, - ) -> c_int; -} -const_ptr_api! { - extern "C" { - pub fn PKCS12_create( - pass: #[const_ptr_if(any(ossl110, libressl280))] c_char, - friendly_name: #[const_ptr_if(any(ossl110, libressl280))] c_char, - pkey: *mut EVP_PKEY, - cert: *mut X509, - ca: *mut stack_st_X509, - nid_key: c_int, - nid_cert: c_int, - iter: c_int, - mac_iter: c_int, - keytype: c_int, - ) -> *mut PKCS12; - - pub fn i2d_PKCS12_bio(b: *mut BIO, a: #[const_ptr_if(ossl300)] PKCS12) -> c_int; - } -} diff --git a/openssl-sys/src/handwritten/pkcs7.rs b/openssl-sys/src/handwritten/pkcs7.rs deleted file mode 100644 index 0b6d30b..0000000 --- a/openssl-sys/src/handwritten/pkcs7.rs +++ /dev/null @@ -1,38 +0,0 @@ -use super::super::*; -use libc::*; - -pub enum PKCS7_SIGNED {} -pub enum PKCS7_ENVELOPE {} -pub enum PKCS7_SIGN_ENVELOPE {} -pub enum PKCS7_DIGEST {} -pub enum PKCS7_ENCRYPT {} -pub enum PKCS7 {} - -extern "C" { - pub fn d2i_PKCS7(a: *mut *mut PKCS7, pp: *mut *const c_uchar, length: c_long) -> *mut PKCS7; -} - -const_ptr_api! { - extern "C" { - pub fn i2d_PKCS7(a: #[const_ptr_if(ossl300)] PKCS7, buf: *mut *mut u8) -> c_int; - } -} - -extern "C" { - pub fn PKCS7_encrypt(certs: *mut stack_st_X509, b: *mut BIO, cipher: *const EVP_CIPHER, flags: c_int) -> *mut PKCS7; - - pub fn PKCS7_verify(pkcs7: *mut PKCS7, certs: *mut stack_st_X509, store: *mut X509_STORE, indata: *mut BIO, out: *mut BIO, flags: c_int) - -> c_int; - - pub fn PKCS7_get0_signers(pkcs7: *mut PKCS7, certs: *mut stack_st_X509, flags: c_int) -> *mut stack_st_X509; - - pub fn PKCS7_sign(signcert: *mut X509, pkey: *mut EVP_PKEY, certs: *mut stack_st_X509, data: *mut BIO, flags: c_int) -> *mut PKCS7; - - pub fn PKCS7_decrypt(pkcs7: *mut PKCS7, pkey: *mut EVP_PKEY, cert: *mut X509, data: *mut BIO, flags: c_int) -> c_int; - - pub fn PKCS7_free(pkcs7: *mut PKCS7); - - pub fn SMIME_write_PKCS7(out: *mut BIO, pkcs7: *mut PKCS7, data: *mut BIO, flags: c_int) -> c_int; - - pub fn SMIME_read_PKCS7(bio: *mut BIO, bcont: *mut *mut BIO) -> *mut PKCS7; -} diff --git a/openssl-sys/src/handwritten/provider.rs b/openssl-sys/src/handwritten/provider.rs deleted file mode 100644 index ce8bf4f..0000000 --- a/openssl-sys/src/handwritten/provider.rs +++ /dev/null @@ -1,13 +0,0 @@ -use super::super::*; -use libc::*; - -extern "C" { - #[cfg(ossl300)] - pub fn OSSL_PROVIDER_load(ctx: *mut OSSL_LIB_CTX, name: *const c_char) -> *mut OSSL_PROVIDER; - #[cfg(ossl300)] - pub fn OSSL_PROVIDER_try_load(ctx: *mut OSSL_LIB_CTX, name: *const c_char, retain_fallbacks: c_int) -> *mut OSSL_PROVIDER; - #[cfg(ossl300)] - pub fn OSSL_PROVIDER_unload(prov: *mut OSSL_PROVIDER) -> c_int; - #[cfg(ossl300)] - pub fn OSSL_PROVIDER_set_default_search_path(ctx: *mut OSSL_LIB_CTX, path: *const c_char) -> c_int; -} diff --git a/openssl-sys/src/handwritten/rand.rs b/openssl-sys/src/handwritten/rand.rs deleted file mode 100644 index 3bf9da5..0000000 --- a/openssl-sys/src/handwritten/rand.rs +++ /dev/null @@ -1,12 +0,0 @@ -use libc::*; - -extern "C" { - pub fn RAND_bytes(buf: *mut u8, num: c_int) -> c_int; - - #[cfg(ossl111)] - pub fn RAND_keep_random_devices_open(keep: c_int); - - pub fn RAND_status() -> c_int; - - pub fn RAND_add(buf: *const c_void, num: c_int, randomness: c_double); -} diff --git a/openssl-sys/src/handwritten/rsa.rs b/openssl-sys/src/handwritten/rsa.rs deleted file mode 100644 index ccda18a..0000000 --- a/openssl-sys/src/handwritten/rsa.rs +++ /dev/null @@ -1,55 +0,0 @@ -use super::super::*; -use libc::*; - -cfg_if! { - if #[cfg(ossl300)] { - extern "C" { - pub fn EVP_PKEY_CTX_set_rsa_padding(ctx: *mut EVP_PKEY_CTX, pad_mode: c_int) -> c_int; - pub fn EVP_PKEY_CTX_get_rsa_padding(ctx: *mut EVP_PKEY_CTX, pad_mode: *mut c_int) -> c_int; - - pub fn EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx: *mut EVP_PKEY_CTX, len: c_int) -> c_int; - pub fn EVP_PKEY_CTX_set_rsa_mgf1_md(ctx: *mut EVP_PKEY_CTX, md: *const EVP_MD) -> c_int; - } - } -} - -extern "C" { - pub fn RSA_new() -> *mut RSA; - pub fn RSA_size(k: *const RSA) -> c_int; - - #[cfg(any(ossl110, libressl273))] - pub fn RSA_set0_key(r: *mut RSA, n: *mut BIGNUM, e: *mut BIGNUM, d: *mut BIGNUM) -> c_int; - #[cfg(any(ossl110, libressl273))] - pub fn RSA_set0_factors(r: *mut RSA, p: *mut BIGNUM, q: *mut BIGNUM) -> c_int; - #[cfg(any(ossl110, libressl273))] - pub fn RSA_set0_crt_params(r: *mut RSA, dmp1: *mut BIGNUM, dmq1: *mut BIGNUM, iqmp: *mut BIGNUM) -> c_int; - #[cfg(any(ossl110, libressl273))] - pub fn RSA_get0_key(r: *const RSA, n: *mut *const BIGNUM, e: *mut *const BIGNUM, d: *mut *const BIGNUM); - #[cfg(any(ossl110, libressl273))] - pub fn RSA_get0_factors(r: *const RSA, p: *mut *const BIGNUM, q: *mut *const BIGNUM); - #[cfg(any(ossl110, libressl273))] - pub fn RSA_get0_crt_params(r: *const RSA, dmp1: *mut *const BIGNUM, dmq1: *mut *const BIGNUM, iqmp: *mut *const BIGNUM); - - #[cfg(not(ossl110))] - pub fn RSA_generate_key(modsz: c_int, e: c_ulong, cb: Option, cbarg: *mut c_void) -> *mut RSA; - - pub fn RSA_generate_key_ex(rsa: *mut RSA, bits: c_int, e: *mut BIGNUM, cb: *mut BN_GENCB) -> c_int; - - pub fn RSA_public_encrypt(flen: c_int, from: *const u8, to: *mut u8, k: *mut RSA, pad: c_int) -> c_int; - pub fn RSA_private_encrypt(flen: c_int, from: *const u8, to: *mut u8, k: *mut RSA, pad: c_int) -> c_int; - pub fn RSA_public_decrypt(flen: c_int, from: *const u8, to: *mut u8, k: *mut RSA, pad: c_int) -> c_int; - pub fn RSA_private_decrypt(flen: c_int, from: *const u8, to: *mut u8, k: *mut RSA, pad: c_int) -> c_int; - pub fn RSA_check_key(r: *const RSA) -> c_int; - pub fn RSA_free(rsa: *mut RSA); - pub fn RSA_up_ref(rsa: *mut RSA) -> c_int; - - pub fn i2d_RSAPublicKey(k: *const RSA, buf: *mut *mut u8) -> c_int; - pub fn d2i_RSAPublicKey(k: *mut *mut RSA, buf: *mut *const u8, len: c_long) -> *mut RSA; - pub fn i2d_RSAPrivateKey(k: *const RSA, buf: *mut *mut u8) -> c_int; - pub fn d2i_RSAPrivateKey(k: *mut *mut RSA, buf: *mut *const u8, len: c_long) -> *mut RSA; - - pub fn RSA_sign(t: c_int, m: *const u8, mlen: c_uint, sig: *mut u8, siglen: *mut c_uint, k: *mut RSA) -> c_int; - pub fn RSA_verify(t: c_int, m: *const u8, mlen: c_uint, sig: *const u8, siglen: c_uint, k: *mut RSA) -> c_int; - - pub fn RSA_padding_check_PKCS1_type_2(to: *mut c_uchar, tlen: c_int, f: *const c_uchar, fl: c_int, rsa_len: c_int) -> c_int; -} diff --git a/openssl-sys/src/handwritten/safestack.rs b/openssl-sys/src/handwritten/safestack.rs deleted file mode 100644 index 0bee90d..0000000 --- a/openssl-sys/src/handwritten/safestack.rs +++ /dev/null @@ -1 +0,0 @@ -stack!(stack_st_OPENSSL_STRING); diff --git a/openssl-sys/src/handwritten/sha.rs b/openssl-sys/src/handwritten/sha.rs deleted file mode 100644 index 7d00b59..0000000 --- a/openssl-sys/src/handwritten/sha.rs +++ /dev/null @@ -1,101 +0,0 @@ -use super::super::*; -use libc::*; - -cfg_if! { - if #[cfg(not(osslconf = "OPENSSL_NO_DEPRECATED_3_0"))] { - #[repr(C)] - #[derive(Clone)] - pub struct SHA_CTX { - pub h0: SHA_LONG, - pub h1: SHA_LONG, - pub h2: SHA_LONG, - pub h3: SHA_LONG, - pub h4: SHA_LONG, - pub Nl: SHA_LONG, - pub Nh: SHA_LONG, - pub data: [SHA_LONG; SHA_LBLOCK as usize], - pub num: c_uint, - } - - extern "C" { - pub fn SHA1_Init(c: *mut SHA_CTX) -> c_int; - pub fn SHA1_Update(c: *mut SHA_CTX, data: *const c_void, len: size_t) -> c_int; - pub fn SHA1_Final(md: *mut c_uchar, c: *mut SHA_CTX) -> c_int; - } - } -} - -cfg_if! { - if #[cfg(not(ossl300))] { - extern "C" { - pub fn SHA1(d: *const c_uchar, n: size_t, md: *mut c_uchar) -> *mut c_uchar; - } - } -} - -cfg_if! { - if #[cfg(not(osslconf = "OPENSSL_NO_DEPRECATED_3_0"))] { - #[repr(C)] - #[derive(Clone)] - pub struct SHA256_CTX { - pub h: [SHA_LONG; 8], - pub Nl: SHA_LONG, - pub Nh: SHA_LONG, - pub data: [SHA_LONG; SHA_LBLOCK as usize], - pub num: c_uint, - pub md_len: c_uint, - } - - extern "C" { - pub fn SHA224_Init(c: *mut SHA256_CTX) -> c_int; - pub fn SHA224_Update(c: *mut SHA256_CTX, data: *const c_void, len: size_t) -> c_int; - pub fn SHA224_Final(md: *mut c_uchar, c: *mut SHA256_CTX) -> c_int; - pub fn SHA256_Init(c: *mut SHA256_CTX) -> c_int; - pub fn SHA256_Update(c: *mut SHA256_CTX, data: *const c_void, len: size_t) -> c_int; - pub fn SHA256_Final(md: *mut c_uchar, c: *mut SHA256_CTX) -> c_int; - } - } -} - -cfg_if! { - if #[cfg(not(ossl300))] { - extern "C" { - pub fn SHA224(d: *const c_uchar, n: size_t, md: *mut c_uchar) -> *mut c_uchar; - pub fn SHA256(d: *const c_uchar, n: size_t, md: *mut c_uchar) -> *mut c_uchar; - } - } -} - -cfg_if! { - if #[cfg(not(osslconf = "OPENSSL_NO_DEPRECATED_3_0"))] { - #[repr(C)] - #[derive(Clone)] - pub struct SHA512_CTX { - pub h: [SHA_LONG64; 8], - pub Nl: SHA_LONG64, - pub Nh: SHA_LONG64, - // this is a union but we don't want to require 1.19 - u: [SHA_LONG64; SHA_LBLOCK as usize], - pub num: c_uint, - pub md_len: c_uint, - } - - extern "C" { - pub fn SHA384_Init(c: *mut SHA512_CTX) -> c_int; - pub fn SHA384_Update(c: *mut SHA512_CTX, data: *const c_void, len: size_t) -> c_int; - pub fn SHA384_Final(md: *mut c_uchar, c: *mut SHA512_CTX) -> c_int; - pub fn SHA512_Init(c: *mut SHA512_CTX) -> c_int; - pub fn SHA512_Update(c: *mut SHA512_CTX, data: *const c_void, len: size_t) -> c_int; - pub fn SHA512_Final(md: *mut c_uchar, c: *mut SHA512_CTX) -> c_int; - } - } -} - -cfg_if! { - if #[cfg(not(ossl300))] { - extern "C" { - pub fn SHA384(d: *const c_uchar, n: size_t, md: *mut c_uchar) -> *mut c_uchar; - pub fn SHA512(d: *const c_uchar, n: size_t, md: *mut c_uchar) -> *mut c_uchar; - } - } -} diff --git a/openssl-sys/src/handwritten/srtp.rs b/openssl-sys/src/handwritten/srtp.rs deleted file mode 100644 index d4c7af8..0000000 --- a/openssl-sys/src/handwritten/srtp.rs +++ /dev/null @@ -1,10 +0,0 @@ -use super::super::*; -use libc::*; - -extern "C" { - pub fn SSL_CTX_set_tlsext_use_srtp(ctx: *mut SSL_CTX, profiles: *const c_char) -> c_int; - pub fn SSL_set_tlsext_use_srtp(ssl: *mut SSL, profiles: *const c_char) -> c_int; - - pub fn SSL_get_srtp_profiles(ssl: *mut SSL) -> *mut stack_st_SRTP_PROTECTION_PROFILE; - pub fn SSL_get_selected_srtp_profile(ssl: *mut SSL) -> *mut SRTP_PROTECTION_PROFILE; -} diff --git a/openssl-sys/src/handwritten/ssl.rs b/openssl-sys/src/handwritten/ssl.rs deleted file mode 100644 index 247a4ae..0000000 --- a/openssl-sys/src/handwritten/ssl.rs +++ /dev/null @@ -1,781 +0,0 @@ -use super::super::*; -use libc::*; - -pub enum SSL_METHOD {} -pub enum SSL_CIPHER {} -cfg_if! { - if #[cfg(any(ossl110, libressl280))] { - pub enum SSL_SESSION {} - } else if #[cfg(libressl251)] { - #[repr(C)] - pub struct SSL_SESSION { - ssl_version: c_int, - pub master_key_length: c_int, - pub master_key: [c_uchar; 48], - session_id_length: c_uint, - session_id: [c_uchar; SSL_MAX_SSL_SESSION_ID_LENGTH as usize], - sid_ctx_length: c_uint, - sid_ctx: [c_uchar; SSL_MAX_SID_CTX_LENGTH as usize], - peer: *mut X509, - verify_result: c_long, - timeout: c_long, - time: time_t, - pub references: c_int, - cipher: *const SSL_CIPHER, - cipher_id: c_long, - ciphers: *mut stack_st_SSL_CIPHER, - tlsext_hostname: *mut c_char, - tlsext_tick: *mut c_uchar, - tlsext_ticklen: size_t, - tlsext_tick_lifetime_int: c_long, - internal: *mut c_void, - } - } else if #[cfg(libressl)] { - #[repr(C)] - pub struct SSL_SESSION { - ssl_version: c_int, - pub master_key_length: c_int, - pub master_key: [c_uchar; 48], - session_id_length: c_uint, - session_id: [c_uchar; SSL_MAX_SSL_SESSION_ID_LENGTH as usize], - sid_ctx_length: c_uint, - sid_ctx: [c_uchar; SSL_MAX_SID_CTX_LENGTH as usize], - not_resumable: c_int, - sess_cert: *mut c_void, - peer: *mut X509, - verify_result: c_long, - timeout: c_long, - time: time_t, - pub references: c_int, - cipher: *const c_void, - cipher_id: c_ulong, - ciphers: *mut c_void, - ex_data: CRYPTO_EX_DATA, - prev: *mut c_void, - next: *mut c_void, - tlsext_hostname: *mut c_char, - tlsext_ecpointformatlist_length: size_t, - tlsext_ecpointformatlist: *mut u8, - tlsext_ellipticcurvelist_length: size_t, - tlsext_ellipticcurvelist: *mut u16, - tlsext_tick: *mut c_uchar, - tlsext_ticklen: size_t, - tlsext_tick_lifetime_hint: c_long, - } - } else { - #[repr(C)] - pub struct SSL_SESSION { - ssl_version: c_int, - key_arg_length: c_uint, - key_arg: [c_uchar; SSL_MAX_KEY_ARG_LENGTH as usize], - pub master_key_length: c_int, - pub master_key: [c_uchar; 48], - session_id_length: c_uint, - session_id: [c_uchar; SSL_MAX_SSL_SESSION_ID_LENGTH as usize], - sid_ctx_length: c_uint, - sid_ctx: [c_uchar; SSL_MAX_SID_CTX_LENGTH as usize], - #[cfg(not(osslconf = "OPENSSL_NO_KRB5"))] - krb5_client_princ_len: c_uint, - #[cfg(not(osslconf = "OPENSSL_NO_KRB5"))] - krb5_client_princ: [c_uchar; SSL_MAX_KRB5_PRINCIPAL_LENGTH as usize], - #[cfg(not(osslconf = "OPENSSL_NO_PSK"))] - psk_identity_hint: *mut c_char, - #[cfg(not(osslconf = "OPENSSL_NO_PSK"))] - psk_identity: *mut c_char, - not_resumable: c_int, - sess_cert: *mut c_void, - peer: *mut X509, - verify_result: c_long, - pub references: c_int, - timeout: c_long, - time: c_long, - compress_meth: c_uint, - cipher: *const c_void, - cipher_id: c_ulong, - ciphers: *mut c_void, - ex_data: CRYPTO_EX_DATA, - prev: *mut c_void, - next: *mut c_void, - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - tlsext_hostname: *mut c_char, - #[cfg(all( - not(osslconf = "OPENSSL_NO_TLSEXT"), - not(osslconf = "OPENSSL_NO_EC") - ))] - tlsext_ecpointformatlist_length: size_t, - #[cfg(all( - not(osslconf = "OPENSSL_NO_TLSEXT"), - not(osslconf = "OPENSSL_NO_EC") - ))] - tlsext_ecpointformatlist: *mut c_uchar, - #[cfg(all( - not(osslconf = "OPENSSL_NO_TLSEXT"), - not(osslconf = "OPENSSL_NO_EC") - ))] - tlsext_ellipticcurvelist_length: size_t, - #[cfg(all( - not(osslconf = "OPENSSL_NO_TLSEXT"), - not(osslconf = "OPENSSL_NO_EC") - ))] - tlsext_ellipticcurvelist: *mut c_uchar, - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - tlsext_tick: *mut c_uchar, - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - tlsext_ticklen: size_t, - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - tlsext_tick_lifetime_hint: c_long, - #[cfg(not(osslconf = "OPENSSL_NO_SRP"))] - srp_username: *mut c_char, - } - } -} - -stack!(stack_st_SSL_CIPHER); - -#[repr(C)] -pub struct SRTP_PROTECTION_PROFILE { - pub name: *const c_char, - pub id: c_ulong, -} - -stack!(stack_st_SRTP_PROTECTION_PROFILE); - -pub type tls_session_ticket_ext_cb_fn = Option c_int>; -pub type tls_session_secret_cb_fn = - Option c_int>; - -#[cfg(ossl111)] -pub type SSL_custom_ext_add_cb_ex = Option< - unsafe extern "C" fn( - ssl: *mut SSL, - ext_type: c_uint, - context: c_uint, - out: *mut *const c_uchar, - outlen: *mut size_t, - x: *mut X509, - chainidx: size_t, - al: *mut c_int, - add_arg: *mut c_void, - ) -> c_int, ->; - -#[cfg(ossl111)] -pub type SSL_custom_ext_free_cb_ex = - Option; - -#[cfg(ossl111)] -pub type SSL_custom_ext_parse_cb_ex = Option< - unsafe extern "C" fn( - ssl: *mut SSL, - ext_type: c_uint, - context: c_uint, - input: *const c_uchar, - inlen: size_t, - x: *mut X509, - chainidx: size_t, - al: *mut c_int, - parse_arg: *mut c_void, - ) -> c_int, ->; - -cfg_if! { - if #[cfg(ossl300)] { - extern "C" { - pub fn SSL_CTX_get_options(ctx: *const SSL_CTX) -> u64; - pub fn SSL_CTX_set_options(ctx: *mut SSL_CTX, op: u64) -> u64; - pub fn SSL_CTX_clear_options(ctx: *mut SSL_CTX, op: u64) -> u64; - } - } else if #[cfg(ossl110)] { - extern "C" { - pub fn SSL_CTX_get_options(ctx: *const SSL_CTX) -> c_ulong; - pub fn SSL_CTX_set_options(ctx: *mut SSL_CTX, op: c_ulong) -> c_ulong; - pub fn SSL_CTX_clear_options(ctx: *mut SSL_CTX, op: c_ulong) -> c_ulong; - } - } -} - -pub type GEN_SESSION_CB = Option c_int>; - -extern "C" { - pub fn SSL_CTX_sess_set_new_cb(ctx: *mut SSL_CTX, new_session_cb: Option c_int>); - pub fn SSL_CTX_sess_set_remove_cb(ctx: *mut SSL_CTX, remove_session_cb: Option); -} -cfg_if! { - // const change in passed function pointer signature - if #[cfg(any(ossl110, libressl280))] { - extern "C" { - pub fn SSL_CTX_sess_set_get_cb( - ctx: *mut SSL_CTX, - get_session_cb: Option< - unsafe extern "C" fn(*mut SSL, *const c_uchar, c_int, *mut c_int) -> *mut SSL_SESSION, - >, - ); - } - } else { - extern "C" { - pub fn SSL_CTX_sess_set_get_cb( - ctx: *mut SSL_CTX, - get_session_cb: Option< - unsafe extern "C" fn(*mut SSL, *mut c_uchar, c_int, *mut c_int) -> *mut SSL_SESSION, - >, - ); - } - } -} -extern "C" { - // FIXME change to unsafe extern "C" fn - pub fn SSL_CTX_set_cookie_generate_cb( - s: *mut SSL_CTX, - cb: Option c_int>, - ); -} - -cfg_if! { - // const change in passed function pointer signature - if #[cfg(any(ossl110, libressl280))] { - extern "C" { - pub fn SSL_CTX_set_cookie_verify_cb( - s: *mut SSL_CTX, - cb: Option< - extern "C" fn(ssl: *mut SSL, cookie: *const c_uchar, cookie_len: c_uint) -> c_int, - >, - ); - } - } else { - extern "C" { - pub fn SSL_CTX_set_cookie_verify_cb( - s: *mut SSL_CTX, - cb: Option c_int>, - ); - } - } -} - -extern "C" { - #[cfg(ossl111)] - pub fn SSL_CTX_set_stateless_cookie_generate_cb( - s: *mut SSL_CTX, - cb: Option c_int>, - ); - #[cfg(ossl111)] - pub fn SSL_CTX_set_stateless_cookie_verify_cb( - s: *mut SSL_CTX, - cb: Option c_int>, - ); - - pub fn SSL_CTX_set_next_protos_advertised_cb( - ssl: *mut SSL_CTX, - cb: extern "C" fn(ssl: *mut SSL, out: *mut *const c_uchar, outlen: *mut c_uint, arg: *mut c_void) -> c_int, - arg: *mut c_void, - ); - pub fn SSL_CTX_set_next_proto_select_cb( - ssl: *mut SSL_CTX, - cb: extern "C" fn( - ssl: *mut SSL, - out: *mut *mut c_uchar, - outlen: *mut c_uchar, - inbuf: *const c_uchar, - inlen: c_uint, - arg: *mut c_void, - ) -> c_int, - arg: *mut c_void, - ); - pub fn SSL_get0_next_proto_negotiated(s: *const SSL, data: *mut *const c_uchar, len: *mut c_uint); - - pub fn SSL_select_next_proto( - out: *mut *mut c_uchar, - outlen: *mut c_uchar, - inbuf: *const c_uchar, - inlen: c_uint, - client: *const c_uchar, - client_len: c_uint, - ) -> c_int; -} - -extern "C" { - #[cfg(any(ossl102, libressl261))] - pub fn SSL_CTX_set_alpn_protos(s: *mut SSL_CTX, data: *const c_uchar, len: c_uint) -> c_int; - #[cfg(any(ossl102, libressl261))] - pub fn SSL_set_alpn_protos(s: *mut SSL, data: *const c_uchar, len: c_uint) -> c_int; - #[cfg(any(ossl102, libressl261))] - #[link_name = "SSL_CTX_set_alpn_select_cb"] - pub fn SSL_CTX_set_alpn_select_cb__fixed_rust( - ssl: *mut SSL_CTX, - cb: Option< - unsafe extern "C" fn( - ssl: *mut SSL, - out: *mut *const c_uchar, - outlen: *mut c_uchar, - inbuf: *const c_uchar, - inlen: c_uint, - arg: *mut c_void, - ) -> c_int, - >, - arg: *mut c_void, - ); - #[cfg(any(ossl102, libressl261))] - pub fn SSL_get0_alpn_selected(s: *const SSL, data: *mut *const c_uchar, len: *mut c_uint); -} - -#[cfg(not(osslconf = "OPENSSL_NO_PSK"))] -extern "C" { - pub fn SSL_CTX_set_psk_client_callback( - ssl: *mut SSL_CTX, - psk_client_cb: Option c_uint>, - ); - pub fn SSL_CTX_set_psk_server_callback( - ssl: *mut SSL_CTX, - psk_server_cb: Option c_uint>, - ); - pub fn SSL_get_psk_identity_hint(ssl: *const SSL) -> *const c_char; - pub fn SSL_get_psk_identity(ssl: *const SSL) -> *const c_char; -} - -extern "C" { - #[cfg(ossl111)] - pub fn SSL_CTX_add_custom_ext( - ctx: *mut SSL_CTX, - ext_type: c_uint, - context: c_uint, - add_cb: SSL_custom_ext_add_cb_ex, - free_cb: SSL_custom_ext_free_cb_ex, - add_arg: *mut c_void, - parse_cb: SSL_custom_ext_parse_cb_ex, - parse_arg: *mut c_void, - ) -> c_int; - - #[cfg(ossl102)] - pub fn SSL_extension_supported(ext_type: c_uint) -> c_int; -} - -#[cfg(ossl111)] -pub type SSL_CTX_keylog_cb_func = Option; - -extern "C" { - #[cfg(ossl111)] - pub fn SSL_CTX_set_keylog_callback(ctx: *mut SSL_CTX, cb: SSL_CTX_keylog_cb_func); - - #[cfg(any(ossl111, libressl340))] - pub fn SSL_CTX_set_max_early_data(ctx: *mut SSL_CTX, max_early_data: u32) -> c_int; - #[cfg(any(ossl111, libressl340))] - pub fn SSL_CTX_get_max_early_data(ctx: *const SSL_CTX) -> u32; - #[cfg(any(ossl111, libressl340))] - pub fn SSL_set_max_early_data(ctx: *mut SSL, max_early_data: u32) -> c_int; - #[cfg(any(ossl111, libressl340))] - pub fn SSL_get_max_early_data(ctx: *const SSL) -> u32; - - pub fn SSL_get_finished(s: *const SSL, buf: *mut c_void, count: size_t) -> size_t; - pub fn SSL_get_peer_finished(s: *const SSL, buf: *mut c_void, count: size_t) -> size_t; - - pub fn SSL_CTX_get_verify_mode(ctx: *const SSL_CTX) -> c_int; - pub fn SSL_get_verify_mode(s: *const SSL) -> c_int; -} - -const_ptr_api! { - extern "C" { - #[cfg(ossl110)] - pub fn SSL_is_init_finished(s: #[const_ptr_if(ossl111)] SSL) -> c_int; - } -} - -cfg_if! { - if #[cfg(libressl261)] { - extern "C" { - pub fn SSL_CTX_set_min_proto_version(ctx: *mut SSL_CTX, version: u16) -> c_int; - pub fn SSL_CTX_set_max_proto_version(ctx: *mut SSL_CTX, version: u16) -> c_int; - pub fn SSL_set_min_proto_version(s: *mut SSL, version: u16) -> c_int; - pub fn SSL_set_max_proto_version(s: *mut SSL, version: u16) -> c_int; - } - } -} - -cfg_if! { - if #[cfg(libressl270)] { - extern "C" { - pub fn SSL_CTX_get_min_proto_version(ctx: *mut SSL_CTX) -> c_int; - pub fn SSL_CTX_get_max_proto_version(ctx: *mut SSL_CTX) -> c_int; - pub fn SSL_get_min_proto_version(s: *mut SSL) -> c_int; - pub fn SSL_get_max_proto_version(s: *mut SSL) -> c_int; - } - } -} - -extern "C" { - pub fn SSL_CTX_set_cipher_list(ssl: *mut SSL_CTX, s: *const c_char) -> c_int; - pub fn SSL_CTX_new(method: *const SSL_METHOD) -> *mut SSL_CTX; - pub fn SSL_CTX_free(ctx: *mut SSL_CTX); - #[cfg(any(ossl110, libressl273))] - pub fn SSL_CTX_up_ref(x: *mut SSL_CTX) -> c_int; - pub fn SSL_CTX_get_cert_store(ctx: *const SSL_CTX) -> *mut X509_STORE; - pub fn SSL_CTX_set_cert_store(ctx: *mut SSL_CTX, store: *mut X509_STORE); - - pub fn SSL_get_current_cipher(ssl: *const SSL) -> *const SSL_CIPHER; - pub fn SSL_CIPHER_get_bits(cipher: *const SSL_CIPHER, alg_bits: *mut c_int) -> c_int; -} -const_ptr_api! { - extern "C" { - pub fn SSL_CIPHER_get_version(cipher: *const SSL_CIPHER) -> #[const_ptr_if(any(ossl110, libressl280))] c_char; - } -} -extern "C" { - #[cfg(ossl111)] - pub fn SSL_CIPHER_get_handshake_digest(cipher: *const SSL_CIPHER) -> *const EVP_MD; - pub fn SSL_CIPHER_get_name(cipher: *const SSL_CIPHER) -> *const c_char; - #[cfg(ossl111)] - pub fn SSL_CIPHER_standard_name(cipher: *const SSL_CIPHER) -> *const c_char; - #[cfg(ossl111)] - pub fn OPENSSL_cipher_name(rfc_name: *const c_char) -> *const c_char; - - pub fn SSL_pending(ssl: *const SSL) -> c_int; - pub fn SSL_set_bio(ssl: *mut SSL, rbio: *mut BIO, wbio: *mut BIO); - pub fn SSL_get_rbio(ssl: *const SSL) -> *mut BIO; - pub fn SSL_get_wbio(ssl: *const SSL) -> *mut BIO; - #[cfg(any(ossl111, libressl340))] - pub fn SSL_CTX_set_ciphersuites(ctx: *mut SSL_CTX, str: *const c_char) -> c_int; - #[cfg(any(ossl111, libressl340))] - pub fn SSL_set_ciphersuites(ssl: *mut SSL, str: *const c_char) -> c_int; - pub fn SSL_set_cipher_list(ssl: *mut SSL, s: *const c_char) -> c_int; - pub fn SSL_set_ssl_method(s: *mut SSL, method: *const SSL_METHOD) -> c_int; - pub fn SSL_set_verify( - ssl: *mut SSL, - mode: c_int, - // FIXME should be unsafe - verify_callback: Option c_int>, - ); - pub fn SSL_CTX_use_PrivateKey(ctx: *mut SSL_CTX, key: *mut EVP_PKEY) -> c_int; - pub fn SSL_CTX_use_certificate(ctx: *mut SSL_CTX, cert: *mut X509) -> c_int; - - pub fn SSL_CTX_use_PrivateKey_file(ctx: *mut SSL_CTX, key_file: *const c_char, file_type: c_int) -> c_int; - pub fn SSL_CTX_use_certificate_file(ctx: *mut SSL_CTX, cert_file: *const c_char, file_type: c_int) -> c_int; - pub fn SSL_CTX_use_certificate_chain_file(ctx: *mut SSL_CTX, cert_chain_file: *const c_char) -> c_int; - pub fn SSL_use_PrivateKey_file(ssl: *mut SSL, file: *const c_char, type_: c_int) -> c_int; - pub fn SSL_use_PrivateKey(ssl: *mut SSL, pkey: *mut EVP_PKEY) -> c_int; - pub fn SSL_use_certificate(ssl: *mut SSL, x: *mut X509) -> c_int; - #[cfg(any(ossl110, libressl332))] - pub fn SSL_use_certificate_chain_file(ssl: *mut SSL, file: *const c_char) -> c_int; - pub fn SSL_set_client_CA_list(s: *mut SSL, name_list: *mut stack_st_X509_NAME); - pub fn SSL_add_client_CA(ssl: *mut SSL, x: *mut X509) -> c_int; - pub fn SSL_load_client_CA_file(file: *const c_char) -> *mut stack_st_X509_NAME; - - #[cfg(not(ossl110))] - pub fn SSL_load_error_strings(); - pub fn SSL_state_string(ssl: *const SSL) -> *const c_char; - pub fn SSL_state_string_long(ssl: *const SSL) -> *const c_char; - - pub fn SSL_SESSION_get_time(s: *const SSL_SESSION) -> c_long; - pub fn SSL_SESSION_get_timeout(s: *const SSL_SESSION) -> c_long; - #[cfg(any(ossl110, libressl270))] - pub fn SSL_SESSION_get_protocol_version(s: *const SSL_SESSION) -> c_int; - - #[cfg(any(ossl111, libressl340))] - pub fn SSL_SESSION_set_max_early_data(ctx: *mut SSL_SESSION, max_early_data: u32) -> c_int; - #[cfg(any(ossl111, libressl340))] - pub fn SSL_SESSION_get_max_early_data(ctx: *const SSL_SESSION) -> u32; - - pub fn SSL_SESSION_get_id(s: *const SSL_SESSION, len: *mut c_uint) -> *const c_uchar; - #[cfg(any(ossl110, libressl273))] - pub fn SSL_SESSION_up_ref(ses: *mut SSL_SESSION) -> c_int; - pub fn SSL_SESSION_free(s: *mut SSL_SESSION); -} -const_ptr_api! { - extern "C" { - pub fn i2d_SSL_SESSION(s: #[const_ptr_if(ossl300)] SSL_SESSION, pp: *mut *mut c_uchar) -> c_int; - } -} -extern "C" { - pub fn SSL_set_session(ssl: *mut SSL, session: *mut SSL_SESSION) -> c_int; - pub fn SSL_CTX_add_session(ctx: *mut SSL_CTX, session: *mut SSL_SESSION) -> c_int; - pub fn SSL_CTX_remove_session(ctx: *mut SSL_CTX, session: *mut SSL_SESSION) -> c_int; - pub fn d2i_SSL_SESSION(a: *mut *mut SSL_SESSION, pp: *mut *const c_uchar, len: c_long) -> *mut SSL_SESSION; - - #[cfg(not(ossl300))] - pub fn SSL_get_peer_certificate(ssl: *const SSL) -> *mut X509; - #[cfg(ossl300)] - pub fn SSL_get1_peer_certificate(ssl: *const SSL) -> *mut X509; - - pub fn SSL_get_peer_cert_chain(ssl: *const SSL) -> *mut stack_st_X509; - - pub fn SSL_CTX_set_verify(ctx: *mut SSL_CTX, mode: c_int, verify_callback: Option c_int>); - pub fn SSL_CTX_set_verify_depth(ctx: *mut SSL_CTX, depth: c_int); - - #[cfg(any(ossl111, libressl340))] - pub fn SSL_CTX_set_post_handshake_auth(ctx: *mut SSL_CTX, val: c_int); - - pub fn SSL_CTX_check_private_key(ctx: *const SSL_CTX) -> c_int; - - pub fn SSL_CTX_set_session_id_context(ssl: *mut SSL_CTX, sid_ctx: *const c_uchar, sid_ctx_len: c_uint) -> c_int; - - pub fn SSL_new(ctx: *mut SSL_CTX) -> *mut SSL; - - #[cfg(any(ossl102, libressl261))] - pub fn SSL_CTX_get0_param(ctx: *mut SSL_CTX) -> *mut X509_VERIFY_PARAM; - - #[cfg(any(ossl102, libressl261))] - pub fn SSL_get0_param(ssl: *mut SSL) -> *mut X509_VERIFY_PARAM; -} - -#[cfg(ossl111)] -pub type SSL_client_hello_cb_fn = Option c_int>; -extern "C" { - #[cfg(ossl111)] - pub fn SSL_CTX_set_client_hello_cb(c: *mut SSL_CTX, cb: SSL_client_hello_cb_fn, arg: *mut c_void); - #[cfg(ossl111)] - pub fn SSL_client_hello_isv2(s: *mut SSL) -> c_int; - #[cfg(ossl111)] - pub fn SSL_client_hello_get0_legacy_version(s: *mut SSL) -> c_uint; - #[cfg(ossl111)] - pub fn SSL_client_hello_get0_random(s: *mut SSL, out: *mut *const c_uchar) -> size_t; - #[cfg(ossl111)] - pub fn SSL_client_hello_get0_session_id(s: *mut SSL, out: *mut *const c_uchar) -> size_t; - #[cfg(ossl111)] - pub fn SSL_client_hello_get0_ciphers(s: *mut SSL, out: *mut *const c_uchar) -> size_t; - #[cfg(ossl111)] - pub fn SSL_client_hello_get0_compression_methods(s: *mut SSL, out: *mut *const c_uchar) -> size_t; - #[cfg(ossl111)] - pub fn SSL_client_hello_get1_extensions_present(s: *mut SSL, out: *mut *mut c_int, outlen: *mut size_t) -> c_int; - #[cfg(ossl111)] - pub fn SSL_client_hello_get0_ext(s: *mut SSL, type_: c_uint, out: *mut *const c_uchar, outlen: *mut size_t) -> c_int; - - pub fn SSL_free(ssl: *mut SSL); - pub fn SSL_accept(ssl: *mut SSL) -> c_int; - #[cfg(ossl111)] - pub fn SSL_stateless(s: *mut SSL) -> c_int; - pub fn SSL_connect(ssl: *mut SSL) -> c_int; - pub fn SSL_read(ssl: *mut SSL, buf: *mut c_void, num: c_int) -> c_int; - pub fn SSL_peek(ssl: *mut SSL, buf: *mut c_void, num: c_int) -> c_int; - #[cfg(any(ossl111, libressl340))] - pub fn SSL_read_early_data(s: *mut SSL, buf: *mut c_void, num: size_t, readbytes: *mut size_t) -> c_int; -} - -extern "C" { - pub fn SSL_write(ssl: *mut SSL, buf: *const c_void, num: c_int) -> c_int; - #[cfg(any(ossl111, libressl340))] - pub fn SSL_write_early_data(s: *mut SSL, buf: *const c_void, num: size_t, written: *mut size_t) -> c_int; - pub fn SSL_ctrl(ssl: *mut SSL, cmd: c_int, larg: c_long, parg: *mut c_void) -> c_long; - pub fn SSL_CTX_ctrl(ctx: *mut SSL_CTX, cmd: c_int, larg: c_long, parg: *mut c_void) -> c_long; - #[link_name = "SSL_CTX_callback_ctrl"] - pub fn SSL_CTX_callback_ctrl__fixed_rust(ctx: *mut SSL_CTX, cmd: c_int, fp: Option) -> c_long; -} - -cfg_if! { - if #[cfg(any(ossl110, libressl291))] { - extern "C" { - pub fn TLS_method() -> *const SSL_METHOD; - - pub fn DTLS_method() -> *const SSL_METHOD; - - pub fn TLS_server_method() -> *const SSL_METHOD; - - pub fn TLS_client_method() -> *const SSL_METHOD; - } - } else { - extern "C" { - #[cfg(not(osslconf = "OPENSSL_NO_SSL3_METHOD"))] - pub fn SSLv3_method() -> *const SSL_METHOD; - - pub fn SSLv23_method() -> *const SSL_METHOD; - - pub fn SSLv23_client_method() -> *const SSL_METHOD; - - pub fn SSLv23_server_method() -> *const SSL_METHOD; - - pub fn TLSv1_method() -> *const SSL_METHOD; - - pub fn TLSv1_1_method() -> *const SSL_METHOD; - - pub fn TLSv1_2_method() -> *const SSL_METHOD; - - pub fn DTLSv1_method() -> *const SSL_METHOD; - - #[cfg(ossl102)] - pub fn DTLSv1_2_method() -> *const SSL_METHOD; - } - } -} - -extern "C" { - pub fn SSL_get_error(ssl: *const SSL, ret: c_int) -> c_int; - pub fn SSL_get_version(ssl: *const SSL) -> *const c_char; - - pub fn SSL_do_handshake(ssl: *mut SSL) -> c_int; - pub fn SSL_shutdown(ssl: *mut SSL) -> c_int; - - pub fn SSL_CTX_set_client_CA_list(ctx: *mut SSL_CTX, list: *mut stack_st_X509_NAME); - - pub fn SSL_CTX_add_client_CA(ctx: *mut SSL_CTX, cacert: *mut X509) -> c_int; - - pub fn SSL_CTX_set_default_verify_paths(ctx: *mut SSL_CTX) -> c_int; - pub fn SSL_CTX_load_verify_locations(ctx: *mut SSL_CTX, CAfile: *const c_char, CApath: *const c_char) -> c_int; -} - -const_ptr_api! { - extern "C" { - pub fn SSL_get_ssl_method(ssl: #[const_ptr_if(ossl111b)] SSL) -> *const SSL_METHOD; - } -} - -extern "C" { - pub fn SSL_set_connect_state(s: *mut SSL); - pub fn SSL_set_accept_state(s: *mut SSL); - - #[cfg(not(ossl110))] - pub fn SSL_library_init() -> c_int; - - pub fn SSL_CIPHER_description(cipher: *const SSL_CIPHER, buf: *mut c_char, size: c_int) -> *mut c_char; - - pub fn SSL_get_certificate(ssl: *const SSL) -> *mut X509; -} -const_ptr_api! { - extern "C" { - pub fn SSL_get_privatekey(ssl: #[const_ptr_if(any(ossl102, libressl280))] SSL) -> *mut EVP_PKEY; - } -} - -extern "C" { - #[cfg(any(ossl102, libressl270))] - pub fn SSL_CTX_get0_certificate(ctx: *const SSL_CTX) -> *mut X509; - #[cfg(any(ossl102, libressl340))] - pub fn SSL_CTX_get0_privatekey(ctx: *const SSL_CTX) -> *mut EVP_PKEY; - - pub fn SSL_set_shutdown(ss: *mut SSL, mode: c_int); - pub fn SSL_get_shutdown(ssl: *const SSL) -> c_int; - pub fn SSL_version(ssl: *const SSL) -> c_int; - pub fn SSL_get_session(s: *const SSL) -> *mut SSL_SESSION; - pub fn SSL_get_SSL_CTX(ssl: *const SSL) -> *mut SSL_CTX; - pub fn SSL_set_SSL_CTX(ssl: *mut SSL, ctx: *mut SSL_CTX) -> *mut SSL_CTX; - - pub fn SSL_get_verify_result(ssl: *const SSL) -> c_long; - #[cfg(ossl110)] - pub fn SSL_get0_verified_chain(ssl: *const SSL) -> *mut stack_st_X509; - - #[cfg(any(ossl110, libressl270))] - pub fn SSL_get_client_random(ssl: *const SSL, out: *mut c_uchar, len: size_t) -> size_t; - #[cfg(any(ossl110, libressl270))] - pub fn SSL_get_server_random(ssl: *const SSL, out: *mut c_uchar, len: size_t) -> size_t; - #[cfg(any(ossl110, libressl273))] - pub fn SSL_SESSION_get_master_key(session: *const SSL_SESSION, out: *mut c_uchar, outlen: size_t) -> size_t; -} - -extern "C" { - #[cfg(not(ossl110))] - pub fn SSL_get_ex_new_index( - argl: c_long, - argp: *mut c_void, - new_func: Option, - dup_func: Option, - free_func: Option, - ) -> c_int; - - pub fn SSL_set_ex_data(ssl: *mut SSL, idx: c_int, data: *mut c_void) -> c_int; - pub fn SSL_get_ex_data(ssl: *const SSL, idx: c_int) -> *mut c_void; - - #[cfg(not(ossl110))] - pub fn SSL_CTX_get_ex_new_index( - argl: c_long, - argp: *mut c_void, - new_func: Option, - dup_func: Option, - free_func: Option, - ) -> c_int; - - pub fn SSL_CTX_set_ex_data(ctx: *mut SSL_CTX, idx: c_int, data: *mut c_void) -> c_int; - pub fn SSL_CTX_get_ex_data(ctx: *const SSL_CTX, idx: c_int) -> *mut c_void; - - pub fn SSL_get_ex_data_X509_STORE_CTX_idx() -> c_int; -} - -extern "C" { - #[link_name = "SSL_CTX_set_tmp_dh_callback"] - pub fn SSL_CTX_set_tmp_dh_callback__fixed_rust( - ctx: *mut SSL_CTX, - dh: Option *mut DH>, - ); - #[link_name = "SSL_set_tmp_dh_callback"] - pub fn SSL_set_tmp_dh_callback__fixed_rust( - ctx: *mut SSL, - dh: Option *mut DH>, - ); - #[cfg(not(ossl110))] - #[link_name = "SSL_CTX_set_tmp_ecdh_callback"] - pub fn SSL_CTX_set_tmp_ecdh_callback__fixed_rust( - ctx: *mut SSL_CTX, - ecdh: Option *mut EC_KEY>, - ); - #[cfg(not(ossl110))] - #[link_name = "SSL_set_tmp_ecdh_callback"] - pub fn SSL_set_tmp_ecdh_callback__fixed_rust( - ssl: *mut SSL, - ecdh: Option *mut EC_KEY>, - ); -} - -cfg_if! { - if #[cfg(libressl)] { - extern "C" { - pub fn SSL_get_current_compression(ssl: *mut SSL) -> *const libc::c_void; - } - } else if #[cfg(not(osslconf = "OPENSSL_NO_COMP"))] { - const_ptr_api! { - extern "C" { - pub fn SSL_get_current_compression(ssl: #[const_ptr_if(ossl111b)] SSL) -> *const COMP_METHOD; - } - } - } -} -cfg_if! { - if #[cfg(libressl)] { - extern "C" { - pub fn SSL_COMP_get_name(comp: *const libc::c_void) -> *const c_char; - } - } else if #[cfg(not(osslconf = "OPENSSL_NO_COMP"))] { - extern "C" { - pub fn SSL_COMP_get_name(comp: *const COMP_METHOD) -> *const c_char; - } - } -} - -#[cfg(not(osslconf = "OPENSSL_NO_COMP"))] -extern "C" { - #[cfg(ossl110)] - pub fn COMP_get_type(meth: *const COMP_METHOD) -> i32; -} - -extern "C" { - #[cfg(any(ossl110, libressl270))] - pub fn SSL_CIPHER_get_cipher_nid(c: *const SSL_CIPHER) -> c_int; - #[cfg(any(ossl110, libressl270))] - pub fn SSL_CIPHER_get_digest_nid(c: *const SSL_CIPHER) -> c_int; -} - -const_ptr_api! { - extern "C" { - #[cfg(ossl110)] - pub fn SSL_session_reused(ssl: #[const_ptr_if(ossl111c)] SSL) -> c_int; - } -} - -const_ptr_api! { - extern "C" { - #[cfg(any(ossl102, libressl273))] - pub fn SSL_is_server(s: #[const_ptr_if(any(ossl110f, libressl273))] SSL) -> c_int; - } -} - -extern "C" { - #[cfg(ossl110)] - pub fn OPENSSL_init_ssl(opts: u64, settings: *const OPENSSL_INIT_SETTINGS) -> c_int; -} - -extern "C" { - #[cfg(ossl111)] - pub fn SSL_CTX_set_num_tickets(ctx: *mut SSL_CTX, num_tickets: size_t) -> c_int; - - #[cfg(ossl111)] - pub fn SSL_set_num_tickets(s: *mut SSL, num_tickets: size_t) -> c_int; - - #[cfg(ossl111)] - pub fn SSL_CTX_get_num_tickets(ctx: *const SSL_CTX) -> size_t; - - #[cfg(ossl111)] - pub fn SSL_get_num_tickets(s: *const SSL) -> size_t; -} diff --git a/openssl-sys/src/handwritten/stack.rs b/openssl-sys/src/handwritten/stack.rs deleted file mode 100644 index 7f2feef..0000000 --- a/openssl-sys/src/handwritten/stack.rs +++ /dev/null @@ -1,45 +0,0 @@ -use libc::*; - -cfg_if! { - if #[cfg(ossl110)] { - pub enum OPENSSL_STACK {} - } else { - #[repr(C)] - pub struct _STACK { - pub num: c_int, - pub data: *mut *mut c_char, - pub sorted: c_int, - pub num_alloc: c_int, - pub comp: Option c_int>, - } - } -} - -cfg_if! { - if #[cfg(ossl110)] { - extern "C" { - pub fn OPENSSL_sk_num(stack: *const OPENSSL_STACK) -> c_int; - pub fn OPENSSL_sk_value(stack: *const OPENSSL_STACK, idx: c_int) -> *mut c_void; - - pub fn OPENSSL_sk_new_null() -> *mut OPENSSL_STACK; - pub fn OPENSSL_sk_free(st: *mut OPENSSL_STACK); - pub fn OPENSSL_sk_pop_free( - st: *mut OPENSSL_STACK, - free: Option, - ); - pub fn OPENSSL_sk_push(st: *mut OPENSSL_STACK, data: *const c_void) -> c_int; - pub fn OPENSSL_sk_pop(st: *mut OPENSSL_STACK) -> *mut c_void; - } - } else { - extern "C" { - pub fn sk_num(st: *const _STACK) -> c_int; - pub fn sk_value(st: *const _STACK, n: c_int) -> *mut c_void; - - pub fn sk_new_null() -> *mut _STACK; - pub fn sk_free(st: *mut _STACK); - pub fn sk_pop_free(st: *mut _STACK, free: Option); - pub fn sk_push(st: *mut _STACK, data: *mut c_void) -> c_int; - pub fn sk_pop(st: *mut _STACK) -> *mut c_void; - } - } -} diff --git a/openssl-sys/src/handwritten/tls1.rs b/openssl-sys/src/handwritten/tls1.rs deleted file mode 100644 index 8cf992f..0000000 --- a/openssl-sys/src/handwritten/tls1.rs +++ /dev/null @@ -1,28 +0,0 @@ -use super::super::*; -use libc::*; - -extern "C" { - pub fn SSL_get_servername(ssl: *const SSL, name_type: c_int) -> *const c_char; - - pub fn SSL_export_keying_material( - s: *mut SSL, - out: *mut c_uchar, - olen: size_t, - label: *const c_char, - llen: size_t, - context: *const c_uchar, - contextlen: size_t, - use_context: c_int, - ) -> c_int; - - #[cfg(ossl111)] - pub fn SSL_export_keying_material_early( - s: *mut SSL, - out: *mut c_uchar, - olen: size_t, - label: *const c_char, - llen: size_t, - context: *const c_uchar, - contextlen: size_t, - ) -> c_int; -} diff --git a/openssl-sys/src/handwritten/types.rs b/openssl-sys/src/handwritten/types.rs deleted file mode 100644 index b229a37..0000000 --- a/openssl-sys/src/handwritten/types.rs +++ /dev/null @@ -1,1078 +0,0 @@ -use libc::*; - -#[allow(unused_imports)] -use super::super::*; - -pub enum ASN1_INTEGER {} -pub enum ASN1_GENERALIZEDTIME {} -pub enum ASN1_STRING {} -pub enum ASN1_BIT_STRING {} -pub enum ASN1_TIME {} -pub enum ASN1_TYPE {} -pub enum ASN1_OBJECT {} -pub enum ASN1_OCTET_STRING {} - -pub enum bio_st {} // FIXME remove -cfg_if! { - if #[cfg(any(ossl110, libressl280))] { - pub enum BIO {} - } else { - #[repr(C)] - pub struct BIO { - pub method: *mut BIO_METHOD, - pub callback: Option< - unsafe extern "C" fn(*mut BIO, c_int, *const c_char, c_int, c_long, c_long) -> c_long, - >, - pub cb_arg: *mut c_char, - pub init: c_int, - pub shutdown: c_int, - pub flags: c_int, - pub retry_reason: c_int, - pub num: c_int, - pub ptr: *mut c_void, - pub next_bio: *mut BIO, - pub prev_bio: *mut BIO, - pub references: c_int, - pub num_read: c_ulong, - pub num_write: c_ulong, - pub ex_data: CRYPTO_EX_DATA, - } - } -} -cfg_if! { - if #[cfg(any(ossl110, libressl350))] { - pub enum BIGNUM {} - } else { - #[repr(C)] - pub struct BIGNUM { - pub d: *mut BN_ULONG, - pub top: c_int, - pub dmax: c_int, - pub neg: c_int, - pub flags: c_int, - } - } -} -pub enum BN_BLINDING {} -pub enum BN_MONT_CTX {} - -pub enum BN_CTX {} -pub enum BN_GENCB {} - -cfg_if! { - if #[cfg(any(ossl110, libressl280))] { - pub enum EVP_CIPHER {} - } else { - #[repr(C)] - pub struct EVP_CIPHER { - pub nid: c_int, - pub block_size: c_int, - pub key_len: c_int, - pub iv_len: c_int, - pub flags: c_ulong, - pub init: Option< - unsafe extern "C" fn(*mut EVP_CIPHER_CTX, *const c_uchar, *const c_uchar, c_int) -> c_int, - >, - pub do_cipher: Option< - unsafe extern "C" fn(*mut EVP_CIPHER_CTX, *mut c_uchar, *const c_uchar, size_t) -> c_int, - >, - pub cleanup: Option c_int>, - pub ctx_size: c_int, - pub set_asn1_parameters: - Option c_int>, - pub get_asn1_parameters: - Option c_int>, - pub ctrl: - Option c_int>, - pub app_data: *mut c_void, - } - } -} -pub enum EVP_CIPHER_CTX {} -pub enum EVP_MD {} -cfg_if! { - if #[cfg(any(ossl110, libressl280))] { - pub enum EVP_MD_CTX {} - } else { - #[repr(C)] - pub struct EVP_MD_CTX { - digest: *mut EVP_MD, - engine: *mut ENGINE, - flags: c_ulong, - md_data: *mut c_void, - pctx: *mut EVP_PKEY_CTX, - update: *mut c_void, - } - } -} - -pub enum PKCS8_PRIV_KEY_INFO {} - -pub enum EVP_PKEY_ASN1_METHOD {} - -pub enum EVP_PKEY_CTX {} - -cfg_if! { - if #[cfg(any(ossl110, libressl280))] { - pub enum HMAC_CTX {} - } else { - #[repr(C)] - pub struct HMAC_CTX { - md: *mut EVP_MD, - md_ctx: EVP_MD_CTX, - i_ctx: EVP_MD_CTX, - o_ctx: EVP_MD_CTX, - key_length: c_uint, - key: [c_uchar; 128], - } - } -} - -cfg_if! { - if #[cfg(any(ossl110, libressl280))] { - pub enum DH {} - } else { - #[repr(C)] - pub struct DH { - pub pad: c_int, - pub version: c_int, - pub p: *mut BIGNUM, - pub g: *mut BIGNUM, - pub length: c_long, - pub pub_key: *mut BIGNUM, - pub priv_key: *mut BIGNUM, - pub flags: c_int, - pub method_mont_p: *mut BN_MONT_CTX, - pub q: *mut BIGNUM, - pub j: *mut BIGNUM, - pub seed: *mut c_uchar, - pub seedlen: c_int, - pub counter: *mut BIGNUM, - pub references: c_int, - pub ex_data: CRYPTO_EX_DATA, - pub meth: *const DH_METHOD, - pub engine: *mut ENGINE, - } - } -} -pub enum DH_METHOD {} - -cfg_if! { - if #[cfg(any(ossl110, libressl280))] { - pub enum DSA {} - } else { - #[repr(C)] - pub struct DSA { - pub pad: c_int, - pub version: c_long, - pub write_params: c_int, - - pub p: *mut BIGNUM, - pub q: *mut BIGNUM, - pub g: *mut BIGNUM, - pub pub_key: *mut BIGNUM, - pub priv_key: *mut BIGNUM, - pub kinv: *mut BIGNUM, - pub r: *mut BIGNUM, - - pub flags: c_int, - pub method_mont_p: *mut BN_MONT_CTX, - pub references: c_int, - pub ex_data: CRYPTO_EX_DATA, - pub meth: *const DSA_METHOD, - pub engine: *mut ENGINE, - } - } -} -pub enum DSA_METHOD {} - -cfg_if! { - if #[cfg(any(ossl110, libressl280))] { - pub enum RSA {} - } else if #[cfg(libressl)] { - #[repr(C)] - pub struct RSA { - pub pad: c_int, - pub version: c_long, - pub meth: *const RSA_METHOD, - - pub engine: *mut ENGINE, - pub n: *mut BIGNUM, - pub e: *mut BIGNUM, - pub d: *mut BIGNUM, - pub p: *mut BIGNUM, - pub q: *mut BIGNUM, - pub dmp1: *mut BIGNUM, - pub dmq1: *mut BIGNUM, - pub iqmp: *mut BIGNUM, - - pub ex_data: CRYPTO_EX_DATA, - pub references: c_int, - pub flags: c_int, - - pub _method_mod_n: *mut BN_MONT_CTX, - pub _method_mod_p: *mut BN_MONT_CTX, - pub _method_mod_q: *mut BN_MONT_CTX, - - pub blinding: *mut BN_BLINDING, - pub mt_blinding: *mut BN_BLINDING, - } - } else { - #[repr(C)] - pub struct RSA { - pub pad: c_int, - pub version: c_long, - pub meth: *const RSA_METHOD, - - pub engine: *mut ENGINE, - pub n: *mut BIGNUM, - pub e: *mut BIGNUM, - pub d: *mut BIGNUM, - pub p: *mut BIGNUM, - pub q: *mut BIGNUM, - pub dmp1: *mut BIGNUM, - pub dmq1: *mut BIGNUM, - pub iqmp: *mut BIGNUM, - - pub ex_data: CRYPTO_EX_DATA, - pub references: c_int, - pub flags: c_int, - - pub _method_mod_n: *mut BN_MONT_CTX, - pub _method_mod_p: *mut BN_MONT_CTX, - pub _method_mod_q: *mut BN_MONT_CTX, - - pub bignum_data: *mut c_char, - pub blinding: *mut BN_BLINDING, - pub mt_blinding: *mut BN_BLINDING, - } - } -} -pub enum RSA_METHOD {} - -pub enum EC_KEY {} - -cfg_if! { - if #[cfg(any(ossl110, libressl280))] { - pub enum X509 {} - } else if #[cfg(libressl)] { - #[repr(C)] - pub struct X509 { - pub cert_info: *mut X509_CINF, - pub sig_alg: *mut X509_ALGOR, - pub signature: *mut ASN1_BIT_STRING, - pub valid: c_int, - pub references: c_int, - pub name: *mut c_char, - pub ex_data: CRYPTO_EX_DATA, - pub ex_pathlen: c_long, - pub ex_pcpathlen: c_long, - pub ex_flags: c_ulong, - pub ex_kusage: c_ulong, - pub ex_xkusage: c_ulong, - pub ex_nscert: c_ulong, - skid: *mut c_void, - akid: *mut c_void, - policy_cache: *mut c_void, - crldp: *mut c_void, - altname: *mut c_void, - nc: *mut c_void, - #[cfg(not(osslconf = "OPENSSL_NO_SHA"))] - sha1_hash: [c_uchar; 20], - aux: *mut c_void, - } - } else { - #[repr(C)] - pub struct X509 { - pub cert_info: *mut X509_CINF, - pub sig_alg: *mut X509_ALGOR, - pub signature: *mut ASN1_BIT_STRING, - pub valid: c_int, - pub references: c_int, - pub name: *mut c_char, - pub ex_data: CRYPTO_EX_DATA, - pub ex_pathlen: c_long, - pub ex_pcpathlen: c_long, - pub ex_flags: c_ulong, - pub ex_kusage: c_ulong, - pub ex_xkusage: c_ulong, - pub ex_nscert: c_ulong, - skid: *mut c_void, - akid: *mut c_void, - policy_cache: *mut c_void, - crldp: *mut c_void, - altname: *mut c_void, - nc: *mut c_void, - #[cfg(not(osslconf = "OPENSSL_NO_RFC3779"))] - rfc3779_addr: *mut c_void, - #[cfg(not(osslconf = "OPENSSL_NO_RFC3779"))] - rfc3779_asid: *mut c_void, - #[cfg(not(osslconf = "OPENSSL_NO_SHA"))] - sha1_hash: [c_uchar; 20], - aux: *mut c_void, - } - } -} -cfg_if! { - if #[cfg(ossl110)] { - pub enum X509_ALGOR {} - } else { - #[repr(C)] - pub struct X509_ALGOR { - pub algorithm: *mut ASN1_OBJECT, - parameter: *mut c_void, - } - } -} - -pub enum X509_LOOKUP_METHOD {} - -pub enum X509_NAME {} - -cfg_if! { - if #[cfg(any(ossl110, libressl270))] { - pub enum X509_STORE {} - } else { - #[repr(C)] - pub struct X509_STORE { - cache: c_int, - pub objs: *mut stack_st_X509_OBJECT, - get_cert_methods: *mut stack_st_X509_LOOKUP, - param: *mut X509_VERIFY_PARAM, - verify: Option c_int>, - verify_cb: Option c_int>, - get_issuer: Option< - extern "C" fn(issuer: *mut *mut X509, ctx: *mut X509_STORE_CTX, x: *mut X509) -> c_int, - >, - check_issued: - Option c_int>, - check_revocation: Option c_int>, - get_crl: Option< - extern "C" fn(ctx: *mut X509_STORE_CTX, crl: *mut *mut X509_CRL, x: *mut X509) -> c_int, - >, - check_crl: Option c_int>, - cert_crl: - Option c_int>, - lookup_certs: - Option *mut stack_st_X509>, - lookup_crls: Option< - extern "C" fn(ctx: *const X509_STORE_CTX, nm: *const X509_NAME) -> *mut stack_st_X509_CRL, - >, - cleanup: Option c_int>, - ex_data: CRYPTO_EX_DATA, - references: c_int, - } - } -} - -pub enum X509_STORE_CTX {} - -cfg_if! { - if #[cfg(any(ossl110, libressl280))] { - pub enum X509_VERIFY_PARAM {} - } else if #[cfg(libressl251)] { - #[repr(C)] - pub struct X509_VERIFY_PARAM { - pub name: *mut c_char, - pub check_time: time_t, - pub inh_flags: c_ulong, - pub flags: c_ulong, - pub purpose: c_int, - pub trust: c_int, - pub depth: c_int, - pub policies: *mut stack_st_ASN1_OBJECT, - id: *mut c_void, - } - } else if #[cfg(libressl)] { - #[repr(C)] - pub struct X509_VERIFY_PARAM { - pub name: *mut c_char, - pub check_time: time_t, - pub inh_flags: c_ulong, - pub flags: c_ulong, - pub purpose: c_int, - pub trust: c_int, - pub depth: c_int, - pub policies: *mut stack_st_ASN1_OBJECT, - //pub id: *mut X509_VERIFY_PARAM_ID, - } - } else { - #[repr(C)] - pub struct X509_VERIFY_PARAM { - pub name: *mut c_char, - pub check_time: time_t, - pub inh_flags: c_ulong, - pub flags: c_ulong, - pub purpose: c_int, - pub trust: c_int, - pub depth: c_int, - pub policies: *mut stack_st_ASN1_OBJECT, - #[cfg(ossl102)] - pub id: *mut X509_VERIFY_PARAM_ID, - } - } -} - -cfg_if! { - if #[cfg(any(ossl110, libressl270))] { - pub enum X509_OBJECT {} - } else { - #[repr(C)] - pub struct X509_OBJECT { - pub type_: c_int, - pub data: X509_OBJECT_data, - } - #[repr(C)] - pub union X509_OBJECT_data { - pub ptr: *mut c_char, - pub x509: *mut X509, - pub crl: *mut X509_CRL, - pub pkey: *mut EVP_PKEY, - } - } -} - -pub enum X509_LOOKUP {} - -#[repr(C)] -pub struct X509V3_CTX { - flags: c_int, - issuer_cert: *mut c_void, - subject_cert: *mut c_void, - subject_req: *mut c_void, - crl: *mut c_void, - db_meth: *mut c_void, - db: *mut c_void, - #[cfg(ossl300)] - issuer_pkey: *mut c_void, - // I like the last comment line, it is copied from OpenSSL sources: - // Maybe more here -} -pub enum CONF {} -#[cfg(ossl110)] -pub enum OPENSSL_INIT_SETTINGS {} - -pub enum ENGINE {} -cfg_if! { - if #[cfg(any(ossl110, libressl280))] { - pub enum SSL {} - } else if #[cfg(libressl251)] { - #[repr(C)] - pub struct SSL { - version: c_int, - method: *const SSL_METHOD, - rbio: *mut BIO, - wbio: *mut BIO, - bbio: *mut BIO, - pub server: c_int, - s3: *mut c_void, - d1: *mut c_void, - param: *mut c_void, - cipher_list: *mut stack_st_SSL_CIPHER, - cert: *mut c_void, - sid_ctx_length: c_uint, - sid_ctx: [c_uchar; SSL_MAX_SID_CTX_LENGTH as usize], - session: *mut SSL_SESSION, - verify_mode: c_int, - error: c_int, - error_code: c_int, - ctx: *mut SSL_CTX, - verify_result: c_long, - references: c_int, - client_version: c_int, - max_send_fragment: c_uint, - tlsext_hostname: *mut c_char, - tlsext_status_type: c_int, - initial_ctx: *mut SSL_CTX, - enc_read_ctx: *mut EVP_CIPHER_CTX, - read_hash: *mut EVP_MD_CTX, - internal: *mut c_void, - } - } else if #[cfg(libressl)] { - #[repr(C)] - pub struct SSL { - version: c_int, - type_: c_int, - method: *const SSL_METHOD, - rbio: *mut c_void, - wbio: *mut c_void, - bbio: *mut c_void, - rwstate: c_int, - in_handshake: c_int, - handshake_func: Option c_int>, - pub server: c_int, - new_session: c_int, - quiet_shutdown: c_int, - shutdown: c_int, - state: c_int, - rstate: c_int, - init_buf: *mut c_void, - init_msg: *mut c_void, - init_num: c_int, - init_off: c_int, - packet: *mut c_uchar, - packet_length: c_uint, - s3: *mut c_void, - d1: *mut c_void, - read_ahead: c_int, - msg_callback: Option< - unsafe extern "C" fn(c_int, - c_int, - c_int, - *const c_void, - size_t, - *mut SSL, - *mut c_void), - >, - msg_callback_arg: *mut c_void, - hit: c_int, - param: *mut c_void, - cipher_list: *mut stack_st_SSL_CIPHER, - cipher_list_by_id: *mut stack_st_SSL_CIPHER, - mac_flags: c_int, - aead_read_ctx: *mut c_void, - enc_read_ctx: *mut EVP_CIPHER_CTX, - read_hash: *mut EVP_MD_CTX, - aead_write_ctx: *mut c_void, - enc_write_ctx: *mut EVP_CIPHER_CTX, - write_hash: *mut EVP_MD_CTX, - cert: *mut c_void, - sid_ctx_length: c_uint, - sid_ctx: [c_uchar; SSL_MAX_SID_CTX_LENGTH as usize], - session: *mut SSL_SESSION, - generate_session_id: GEN_SESSION_CB, - verify_mode: c_int, - verify_callback: Option c_int>, - info_callback: Option, - error: c_int, - error_code: c_int, - ctx: *mut SSL_CTX, - debug: c_int, - verify_result: c_long, - ex_data: CRYPTO_EX_DATA, - client_CA: *mut stack_st_X509_NAME, - references: c_int, - options: c_ulong, - mode: c_ulong, - max_cert_list: c_long, - first_packet: c_int, - client_version: c_int, - max_send_fragment: c_uint, - tlsext_debug_cb: - Option, - tlsext_debug_arg: *mut c_void, - tlsext_hostname: *mut c_char, - servername_done: c_int, - tlsext_status_type: c_int, - tlsext_status_expected: c_int, - tlsext_ocsp_ids: *mut c_void, - tlsext_ocsp_exts: *mut c_void, - tlsext_ocsp_resp: *mut c_uchar, - tlsext_ocsp_resplen: c_int, - tlsext_ticket_expected: c_int, - tlsext_ecpointformatlist_length: size_t, - tlsext_ecpointformatlist: *mut c_uchar, - tlsext_ellipticcurvelist_length: size_t, - tlsext_ellipticcurvelist: *mut c_uchar, - tlsext_session_ticket: *mut c_void, - tlsext_session_ticket_ext_cb: tls_session_ticket_ext_cb_fn, - tls_session_ticket_ext_cb_arg: *mut c_void, - tls_session_secret_cb: tls_session_secret_cb_fn, - tls_session_secret_cb_arg: *mut c_void, - initial_ctx: *mut SSL_CTX, - next_proto_negotiated: *mut c_uchar, - next_proto_negotiated_len: c_uchar, - srtp_profiles: *mut c_void, - srtp_profile: *mut c_void, - tlsext_heartbeat: c_uint, - tlsext_hb_pending: c_uint, - tlsext_hb_seq: c_uint, - alpn_client_proto_list: *mut c_uchar, - alpn_client_proto_list_len: c_uint, - renegotiate: c_int, - } - } else { - #[repr(C)] - pub struct SSL { - version: c_int, - type_: c_int, - method: *const SSL_METHOD, - rbio: *mut c_void, - wbio: *mut c_void, - bbio: *mut c_void, - rwstate: c_int, - in_handshake: c_int, - handshake_func: Option c_int>, - pub server: c_int, - new_session: c_int, - quiet_session: c_int, - shutdown: c_int, - state: c_int, - rstate: c_int, - init_buf: *mut c_void, - init_msg: *mut c_void, - init_num: c_int, - init_off: c_int, - packet: *mut c_uchar, - packet_length: c_uint, - s2: *mut c_void, - s3: *mut c_void, - d1: *mut c_void, - read_ahead: c_int, - msg_callback: Option< - unsafe extern "C" fn(c_int, c_int, c_int, *const c_void, size_t, *mut SSL, *mut c_void), - >, - msg_callback_arg: *mut c_void, - hit: c_int, - param: *mut c_void, - cipher_list: *mut stack_st_SSL_CIPHER, - cipher_list_by_id: *mut stack_st_SSL_CIPHER, - mac_flags: c_int, - enc_read_ctx: *mut EVP_CIPHER_CTX, - read_hash: *mut EVP_MD_CTX, - expand: *mut c_void, - enc_write_ctx: *mut EVP_CIPHER_CTX, - write_hash: *mut EVP_MD_CTX, - compress: *mut c_void, - cert: *mut c_void, - sid_ctx_length: c_uint, - sid_ctx: [c_uchar; SSL_MAX_SID_CTX_LENGTH as usize], - session: *mut SSL_SESSION, - generate_session_id: GEN_SESSION_CB, - verify_mode: c_int, - verify_callback: Option c_int>, - info_callback: Option, - error: c_int, - error_code: c_int, - #[cfg(not(osslconf = "OPENSSL_NO_KRB5"))] - kssl_ctx: *mut c_void, - #[cfg(not(osslconf = "OPENSSL_NO_PSK"))] - psk_client_callback: Option< - unsafe extern "C" fn(*mut SSL, *const c_char, *mut c_char, c_uint, *mut c_uchar, c_uint) - -> c_uint, - >, - #[cfg(not(osslconf = "OPENSSL_NO_PSK"))] - psk_server_callback: - Option c_uint>, - ctx: *mut SSL_CTX, - debug: c_int, - verify_result: c_long, - ex_data: CRYPTO_EX_DATA, - client_CA: *mut stack_st_X509_NAME, - references: c_int, - options: c_ulong, - mode: c_ulong, - max_cert_list: c_long, - first_packet: c_int, - client_version: c_int, - max_send_fragment: c_uint, - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - tlsext_debug_cb: - Option, - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - tlsext_debug_arg: *mut c_void, - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - tlsext_hostname: *mut c_char, - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - servername_done: c_int, - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - tlsext_status_type: c_int, - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - tlsext_status_expected: c_int, - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - tlsext_ocsp_ids: *mut c_void, - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - tlsext_ocsp_exts: *mut c_void, - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - tlsext_ocsp_resp: *mut c_uchar, - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - tlsext_ocsp_resplen: c_int, - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - tlsext_ticket_expected: c_int, - #[cfg(all( - not(osslconf = "OPENSSL_NO_TLSEXT"), - not(osslconf = "OPENSSL_NO_EC") - ))] - tlsext_ecpointformatlist_length: size_t, - #[cfg(all( - not(osslconf = "OPENSSL_NO_TLSEXT"), - not(osslconf = "OPENSSL_NO_EC") - ))] - tlsext_ecpointformatlist: *mut c_uchar, - #[cfg(all( - not(osslconf = "OPENSSL_NO_TLSEXT"), - not(osslconf = "OPENSSL_NO_EC") - ))] - tlsext_ellipticcurvelist_length: size_t, - #[cfg(all( - not(osslconf = "OPENSSL_NO_TLSEXT"), - not(osslconf = "OPENSSL_NO_EC") - ))] - tlsext_ellipticcurvelist: *mut c_uchar, - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - tlsext_opaque_prf_input: *mut c_void, - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - tlsext_opaque_prf_input_len: size_t, - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - tlsext_session_ticket: *mut c_void, - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - tlsext_session_ticket_ext_cb: tls_session_ticket_ext_cb_fn, - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - tls_session_ticket_ext_cb_arg: *mut c_void, - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - tls_session_secret_cb: tls_session_secret_cb_fn, - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - tls_session_secret_cb_arg: *mut c_void, - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - initial_ctx: *mut SSL_CTX, - #[cfg(all( - not(osslconf = "OPENSSL_NO_TLSEXT"), - not(osslconf = "OPENSSL_NO_NEXTPROTONEG") - ))] - next_proto_negotiated: *mut c_uchar, - #[cfg(all( - not(osslconf = "OPENSSL_NO_TLSEXT"), - not(osslconf = "OPENSSL_NO_NEXTPROTONEG") - ))] - next_proto_negotiated_len: c_uchar, - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - srtp_profiles: *mut c_void, - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - srtp_profile: *mut c_void, - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - tlsext_heartbeat: c_uint, - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - tlsext_hb_pending: c_uint, - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - tlsext_hb_seq: c_uint, - renegotiate: c_int, - #[cfg(not(osslconf = "OPENSSL_NO_SRP"))] - srp_ctx: SRP_CTX, - #[cfg(all(not(osslconf = "OPENSSL_NO_TLSEXT"), ossl102))] - alpn_client_proto_list: *mut c_uchar, - #[cfg(all(not(osslconf = "OPENSSL_NO_TLSEXT"), ossl102))] - alpn_client_proto_list_len: c_uint, - } - } -} -cfg_if! { - if #[cfg(any(ossl110, libressl280))] { - pub enum SSL_CTX {} - } else if #[cfg(libressl251)] { - #[repr(C)] - pub struct SSL_CTX { - method: *const SSL_METHOD, - cipher_list: *mut stack_st_SSL_CIPHER, - cert_store: *mut c_void, - session_timeout: c_long, - pub references: c_int, - extra_certs: *mut stack_st_X509, - verify_mode: c_int, - sid_ctx_length: c_uint, - sid_ctx: [c_uchar; SSL_MAX_SID_CTX_LENGTH as usize], - param: *mut X509_VERIFY_PARAM, - default_passwd_callback: *mut c_void, - default_passwd_callback_userdata: *mut c_void, - internal: *mut c_void, - } - } else if #[cfg(libressl)] { - #[repr(C)] - pub struct SSL_CTX { - method: *mut c_void, - cipher_list: *mut c_void, - cipher_list_by_id: *mut c_void, - cert_store: *mut c_void, - sessions: *mut c_void, - session_cache_size: c_ulong, - session_cache_head: *mut c_void, - session_cache_tail: *mut c_void, - session_cache_mode: c_int, - session_timeout: c_long, - new_session_cb: *mut c_void, - remove_session_cb: *mut c_void, - get_session_cb: *mut c_void, - stats: [c_int; 11], - pub references: c_int, - app_verify_callback: *mut c_void, - app_verify_arg: *mut c_void, - default_passwd_callback: *mut c_void, - default_passwd_callback_userdata: *mut c_void, - client_cert_cb: *mut c_void, - app_gen_cookie_cb: *mut c_void, - app_verify_cookie_cb: *mut c_void, - ex_dat: CRYPTO_EX_DATA, - rsa_md5: *mut c_void, - md5: *mut c_void, - sha1: *mut c_void, - extra_certs: *mut c_void, - comp_methods: *mut c_void, - info_callback: *mut c_void, - client_CA: *mut c_void, - options: c_ulong, - mode: c_ulong, - max_cert_list: c_long, - cert: *mut c_void, - read_ahead: c_int, - msg_callback: *mut c_void, - msg_callback_arg: *mut c_void, - verify_mode: c_int, - sid_ctx_length: c_uint, - sid_ctx: [c_uchar; 32], - default_verify_callback: *mut c_void, - generate_session_id: *mut c_void, - param: *mut c_void, - quiet_shutdown: c_int, - max_send_fragment: c_uint, - - #[cfg(not(osslconf = "OPENSSL_NO_ENGINE"))] - client_cert_engine: *mut c_void, - - tlsext_servername_callback: *mut c_void, - tlsect_servername_arg: *mut c_void, - tlsext_tick_key_name: [c_uchar; 16], - tlsext_tick_hmac_key: [c_uchar; 16], - tlsext_tick_aes_key: [c_uchar; 16], - tlsext_ticket_key_cb: *mut c_void, - tlsext_status_cb: *mut c_void, - tlsext_status_arg: *mut c_void, - tlsext_opaque_prf_input_callback: *mut c_void, - tlsext_opaque_prf_input_callback_arg: *mut c_void, - - next_protos_advertised_cb: *mut c_void, - next_protos_advertised_cb_arg: *mut c_void, - next_proto_select_cb: *mut c_void, - next_proto_select_cb_arg: *mut c_void, - - srtp_profiles: *mut c_void, - } - } else { - #[repr(C)] - pub struct SSL_CTX { - method: *mut c_void, - cipher_list: *mut c_void, - cipher_list_by_id: *mut c_void, - cert_store: *mut c_void, - sessions: *mut c_void, - session_cache_size: c_ulong, - session_cache_head: *mut c_void, - session_cache_tail: *mut c_void, - session_cache_mode: c_int, - session_timeout: c_long, - new_session_cb: *mut c_void, - remove_session_cb: *mut c_void, - get_session_cb: *mut c_void, - stats: [c_int; 11], - pub references: c_int, - app_verify_callback: *mut c_void, - app_verify_arg: *mut c_void, - default_passwd_callback: *mut c_void, - default_passwd_callback_userdata: *mut c_void, - client_cert_cb: *mut c_void, - app_gen_cookie_cb: *mut c_void, - app_verify_cookie_cb: *mut c_void, - ex_dat: CRYPTO_EX_DATA, - rsa_md5: *mut c_void, - md5: *mut c_void, - sha1: *mut c_void, - extra_certs: *mut c_void, - comp_methods: *mut c_void, - info_callback: *mut c_void, - client_CA: *mut c_void, - options: c_ulong, - mode: c_ulong, - max_cert_list: c_long, - cert: *mut c_void, - read_ahead: c_int, - msg_callback: *mut c_void, - msg_callback_arg: *mut c_void, - verify_mode: c_int, - sid_ctx_length: c_uint, - sid_ctx: [c_uchar; 32], - default_verify_callback: *mut c_void, - generate_session_id: *mut c_void, - param: *mut c_void, - quiet_shutdown: c_int, - max_send_fragment: c_uint, - - #[cfg(not(osslconf = "OPENSSL_NO_ENGINE"))] - client_cert_engine: *mut c_void, - - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - tlsext_servername_callback: *mut c_void, - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - tlsect_servername_arg: *mut c_void, - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - tlsext_tick_key_name: [c_uchar; 16], - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - tlsext_tick_hmac_key: [c_uchar; 16], - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - tlsext_tick_aes_key: [c_uchar; 16], - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - tlsext_ticket_key_cb: *mut c_void, - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - tlsext_status_cb: *mut c_void, - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - tlsext_status_arg: *mut c_void, - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - tlsext_opaque_prf_input_callback: *mut c_void, - #[cfg(not(osslconf = "OPENSSL_NO_TLSEXT"))] - tlsext_opaque_prf_input_callback_arg: *mut c_void, - - #[cfg(not(osslconf = "OPENSSL_NO_PSK"))] - psk_identity_hint: *mut c_void, - #[cfg(not(osslconf = "OPENSSL_NO_PSK"))] - psk_client_callback: *mut c_void, - #[cfg(not(osslconf = "OPENSSL_NO_PSK"))] - psk_server_callback: *mut c_void, - - #[cfg(not(osslconf = "OPENSSL_NO_BUF_FREELISTS"))] - freelist_max_len: c_uint, - #[cfg(not(osslconf = "OPENSSL_NO_BUF_FREELISTS"))] - wbuf_freelist: *mut c_void, - #[cfg(not(osslconf = "OPENSSL_NO_BUF_FREELISTS"))] - rbuf_freelist: *mut c_void, - - #[cfg(not(osslconf = "OPENSSL_NO_SRP"))] - srp_ctx: SRP_CTX, - - #[cfg(all( - not(osslconf = "OPENSSL_NO_TLSEXT"), - not(osslconf = "OPENSSL_NO_NEXTPROTONEG") - ))] - next_protos_advertised_cb: *mut c_void, - #[cfg(all( - not(osslconf = "OPENSSL_NO_TLSEXT"), - not(osslconf = "OPENSSL_NO_NEXTPROTONEG") - ))] - next_protos_advertised_cb_arg: *mut c_void, - #[cfg(all( - not(osslconf = "OPENSSL_NO_TLSEXT"), - not(osslconf = "OPENSSL_NO_NEXTPROTONEG") - ))] - next_proto_select_cb: *mut c_void, - #[cfg(all( - not(osslconf = "OPENSSL_NO_TLSEXT"), - not(osslconf = "OPENSSL_NO_NEXTPROTONEG") - ))] - next_proto_select_cb_arg: *mut c_void, - - #[cfg(all(not(osslconf = "OPENSSL_NO_TLSEXT"), ossl101))] - srtp_profiles: *mut c_void, - #[cfg(all(not(osslconf = "OPENSSL_NO_TLSEXT"), ossl102))] - alpn_select_cb: *mut c_void, - #[cfg(all(not(osslconf = "OPENSSL_NO_TLSEXT"), ossl102))] - alpn_select_cb_arg: *mut c_void, - #[cfg(all(not(osslconf = "OPENSSL_NO_TLSEXT"), ossl102))] - alpn_client_proto_list: *mut c_void, - #[cfg(all(not(osslconf = "OPENSSL_NO_TLSEXT"), ossl102))] - alpn_client_proto_list_len: c_uint, - - #[cfg(all( - not(osslconf = "OPENSSL_NO_TLSEXT"), - not(osslconf = "OPENSSL_NO_EC"), - ossl102 - ))] - tlsext_ecpointformatlist_length: size_t, - #[cfg(all( - not(osslconf = "OPENSSL_NO_TLSEXT"), - not(osslconf = "OPENSSL_NO_EC"), - ossl102 - ))] - tlsext_ecpointformatlist: *mut c_uchar, - #[cfg(all( - not(osslconf = "OPENSSL_NO_TLSEXT"), - not(osslconf = "OPENSSL_NO_EC"), - ossl102 - ))] - tlsext_ellipticcurvelist_length: size_t, - #[cfg(all( - not(osslconf = "OPENSSL_NO_TLSEXT"), - not(osslconf = "OPENSSL_NO_EC"), - ossl102 - ))] - tlsext_ellipticcurvelist: *mut c_uchar, - } - - #[repr(C)] - #[cfg(not(osslconf = "OPENSSL_NO_SRP"))] - pub struct SRP_CTX { - SRP_cb_arg: *mut c_void, - TLS_ext_srp_username_callback: *mut c_void, - SRP_verify_param_callback: *mut c_void, - SRP_give_srp_client_pwd_callback: *mut c_void, - login: *mut c_void, - N: *mut c_void, - g: *mut c_void, - s: *mut c_void, - B: *mut c_void, - A: *mut c_void, - a: *mut c_void, - b: *mut c_void, - v: *mut c_void, - info: *mut c_void, - stringth: c_int, - srp_Mask: c_ulong, - } - } -} - -pub enum COMP_CTX {} - -cfg_if! { - if #[cfg(any(ossl110, libressl350))] { - pub enum COMP_METHOD {} - } else { - #[repr(C)] - pub struct COMP_METHOD { - pub type_: c_int, - pub name: *const c_char, - init: Option c_int>, - finish: Option, - compress: Option< - unsafe extern "C" fn( - *mut COMP_CTX, - *mut c_uchar, - c_uint, - *mut c_uchar, - c_uint, - ) -> c_int, - >, - expand: Option< - unsafe extern "C" fn( - *mut COMP_CTX, - *mut c_uchar, - c_uint, - *mut c_uchar, - c_uint, - ) -> c_int, - >, - ctrl: Option c_long>, - callback_ctrl: Option c_long>, - } - } -} - -cfg_if! { - if #[cfg(any(ossl110, libressl280))] { - pub enum CRYPTO_EX_DATA {} - } else if #[cfg(libressl)] { - #[repr(C)] - pub struct CRYPTO_EX_DATA { - pub sk: *mut stack_st_void, - } - } else { - #[repr(C)] - pub struct CRYPTO_EX_DATA { - pub sk: *mut stack_st_void, - pub dummy: c_int, - } - } -} - -pub enum OCSP_RESPONSE {} - -#[cfg(ossl300)] -pub enum OSSL_PROVIDER {} - -#[cfg(ossl300)] -pub enum OSSL_LIB_CTX {} diff --git a/openssl-sys/src/handwritten/x509.rs b/openssl-sys/src/handwritten/x509.rs deleted file mode 100644 index 47ed544..0000000 --- a/openssl-sys/src/handwritten/x509.rs +++ /dev/null @@ -1,588 +0,0 @@ -use super::super::*; -use libc::*; - -#[repr(C)] -pub struct X509_VAL { - pub notBefore: *mut ASN1_TIME, - pub notAfter: *mut ASN1_TIME, -} - -pub enum X509_NAME_ENTRY {} - -stack!(stack_st_X509_NAME); - -pub enum X509_EXTENSION {} - -stack!(stack_st_X509_EXTENSION); - -stack!(stack_st_X509_ATTRIBUTE); - -cfg_if! { - if #[cfg(any(ossl110, libressl350))] { - pub enum X509_REQ_INFO {} - } else { - #[repr(C)] - pub struct X509_REQ_INFO { - pub enc: ASN1_ENCODING, - pub version: *mut ASN1_INTEGER, - pub subject: *mut X509_NAME, - pubkey: *mut c_void, - pub attributes: *mut stack_st_X509_ATTRIBUTE, - } - } -} - -cfg_if! { - if #[cfg(any(ossl110, libressl350))] { - pub enum X509_CRL {} - } else { - #[repr(C)] - pub struct X509_CRL { - pub crl: *mut X509_CRL_INFO, - sig_alg: *mut X509_ALGOR, - signature: *mut c_void, - references: c_int, - flags: c_int, - akid: *mut c_void, - idp: *mut c_void, - idp_flags: c_int, - idp_reasons: c_int, - crl_number: *mut ASN1_INTEGER, - base_crl_number: *mut ASN1_INTEGER, - sha1_hash: [c_uchar; 20], - issuers: *mut c_void, - meth: *const c_void, - meth_data: *mut c_void, - } - } -} - -stack!(stack_st_X509_CRL); - -cfg_if! { - if #[cfg(any(ossl110, libressl350))] { - pub enum X509_CRL_INFO {} - } else { - #[repr(C)] - pub struct X509_CRL_INFO { - version: *mut ASN1_INTEGER, - sig_alg: *mut X509_ALGOR, - pub issuer: *mut X509_NAME, - pub lastUpdate: *mut ASN1_TIME, - pub nextUpdate: *mut ASN1_TIME, - pub revoked: *mut stack_st_X509_REVOKED, - extensions: *mut stack_st_X509_EXTENSION, - enc: ASN1_ENCODING, - } - } -} - -cfg_if! { - if #[cfg(any(ossl110, libressl350))] { - pub enum X509_REVOKED {} - } else { - #[repr(C)] - pub struct X509_REVOKED { - pub serialNumber: *mut ASN1_INTEGER, - pub revocationDate: *mut ASN1_TIME, - pub extensions: *mut stack_st_X509_EXTENSION, - issuer: *mut stack_st_GENERAL_NAME, - reason: c_int, - sequence: c_int, - } - } -} - -stack!(stack_st_X509_REVOKED); - -cfg_if! { - if #[cfg(any(ossl110, libressl350))] { - pub enum X509_REQ {} - } else { - #[repr(C)] - pub struct X509_REQ { - pub req_info: *mut X509_REQ_INFO, - sig_alg: *mut c_void, - signature: *mut c_void, - references: c_int, - } - } -} - -cfg_if! { - if #[cfg(any(ossl110, libressl350))] { - pub enum X509_CINF {} - } else { - #[repr(C)] - pub struct X509_CINF { - version: *mut c_void, - serialNumber: *mut c_void, - signature: *mut c_void, - issuer: *mut c_void, - pub validity: *mut X509_VAL, - subject: *mut c_void, - key: *mut c_void, - issuerUID: *mut c_void, - subjectUID: *mut c_void, - pub extensions: *mut stack_st_X509_EXTENSION, - enc: ASN1_ENCODING, - } - } -} - -stack!(stack_st_X509); - -stack!(stack_st_X509_OBJECT); - -stack!(stack_st_X509_LOOKUP); - -extern "C" { - pub fn X509_verify_cert_error_string(n: c_long) -> *const c_char; - - pub fn X509_sign(x: *mut X509, pkey: *mut EVP_PKEY, md: *const EVP_MD) -> c_int; - - pub fn X509_digest(x: *const X509, digest: *const EVP_MD, buf: *mut c_uchar, len: *mut c_uint) -> c_int; - - pub fn X509_REQ_sign(x: *mut X509_REQ, pkey: *mut EVP_PKEY, md: *const EVP_MD) -> c_int; -} - -const_ptr_api! { - extern "C" { - pub fn i2d_X509_bio(b: *mut BIO, x: #[const_ptr_if(ossl300)] X509) -> c_int; - pub fn i2d_X509_REQ_bio(b: *mut BIO, x: #[const_ptr_if(ossl300)] X509_REQ) -> c_int; - pub fn i2d_PrivateKey_bio(b: *mut BIO, x: #[const_ptr_if(ossl300)] EVP_PKEY) -> c_int; - pub fn i2d_PUBKEY_bio(b: *mut BIO, x: #[const_ptr_if(ossl300)] EVP_PKEY) -> c_int; - - pub fn i2d_PUBKEY(k: #[const_ptr_if(ossl300)] EVP_PKEY, buf: *mut *mut u8) -> c_int; - pub fn i2d_RSA_PUBKEY(k: #[const_ptr_if(ossl300)] RSA, buf: *mut *mut u8) -> c_int; - pub fn i2d_DSA_PUBKEY(a: #[const_ptr_if(ossl300)] DSA, pp: *mut *mut c_uchar) -> c_int; - pub fn i2d_PrivateKey(k: #[const_ptr_if(ossl300)] EVP_PKEY, buf: *mut *mut u8) -> c_int; - pub fn i2d_ECPrivateKey(ec_key: #[const_ptr_if(ossl300)] EC_KEY, pp: *mut *mut c_uchar) -> c_int; - pub fn i2d_EC_PUBKEY(a: #[const_ptr_if(ossl300)] EC_KEY, pp: *mut *mut c_uchar) -> c_int; - } -} -extern "C" { - pub fn d2i_PUBKEY(k: *mut *mut EVP_PKEY, buf: *mut *const u8, len: c_long) -> *mut EVP_PKEY; - pub fn d2i_RSA_PUBKEY(k: *mut *mut RSA, buf: *mut *const u8, len: c_long) -> *mut RSA; - pub fn d2i_DSA_PUBKEY(k: *mut *mut DSA, pp: *mut *const c_uchar, length: c_long) -> *mut DSA; - pub fn d2i_EC_PUBKEY(a: *mut *mut EC_KEY, pp: *mut *const c_uchar, length: c_long) -> *mut EC_KEY; - - pub fn d2i_ECPrivateKey(k: *mut *mut EC_KEY, pp: *mut *const c_uchar, length: c_long) -> *mut EC_KEY; -} - -const_ptr_api! { - extern "C" { - #[cfg(any(ossl102, libressl350))] - pub fn X509_ALGOR_get0( - paobj: *mut #[const_ptr_if(any(ossl110, libressl350))] ASN1_OBJECT, - pptype: *mut c_int, - ppval: *mut #[const_ptr_if(any(ossl110, libressl350))] c_void, - alg: #[const_ptr_if(any(ossl110, libressl350))] X509_ALGOR, - ); - } -} - -extern "C" { - pub fn X509_gmtime_adj(time: *mut ASN1_TIME, adj: c_long) -> *mut ASN1_TIME; - - pub fn X509_to_X509_REQ(x: *mut X509, pkey: *mut EVP_PKEY, md: *const EVP_MD) -> *mut X509_REQ; - - pub fn X509_ALGOR_free(x: *mut X509_ALGOR); - - pub fn X509_REVOKED_new() -> *mut X509_REVOKED; - pub fn X509_REVOKED_free(x: *mut X509_REVOKED); -} -const_ptr_api! { - extern "C" { - #[cfg(any(ossl110, libressl270))] - pub fn X509_REVOKED_dup(rev: #[const_ptr_if(ossl300)] X509_REVOKED) -> *mut X509_REVOKED; - } -} - -extern "C" { - pub fn d2i_X509_REVOKED(a: *mut *mut X509_REVOKED, pp: *mut *const c_uchar, length: c_long) -> *mut X509_REVOKED; -} -const_ptr_api! { - extern "C" { - pub fn i2d_X509_REVOKED(x: #[const_ptr_if(ossl300)] X509_REVOKED, buf: *mut *mut u8) -> c_int; - } -} -extern "C" { - pub fn X509_CRL_new() -> *mut X509_CRL; - pub fn X509_CRL_free(x: *mut X509_CRL); - pub fn d2i_X509_CRL(a: *mut *mut X509_CRL, pp: *mut *const c_uchar, length: c_long) -> *mut X509_CRL; -} -const_ptr_api! { - extern "C" { - pub fn i2d_X509_CRL(x: #[const_ptr_if(ossl300)] X509_CRL, buf: *mut *mut u8) -> c_int; - #[cfg(any(ossl110, libressl270))] - pub fn X509_CRL_dup(x: #[const_ptr_if(ossl300)] X509_CRL) -> *mut X509_CRL; - } -} - -extern "C" { - pub fn X509_REQ_new() -> *mut X509_REQ; - pub fn X509_REQ_free(x: *mut X509_REQ); - pub fn d2i_X509_REQ(a: *mut *mut X509_REQ, pp: *mut *const c_uchar, length: c_long) -> *mut X509_REQ; -} -const_ptr_api! { - extern "C" { - pub fn i2d_X509_REQ(x: #[const_ptr_if(ossl300)] X509_REQ, buf: *mut *mut u8) -> c_int; - - #[cfg(any(ossl102, libressl273))] - pub fn X509_get0_signature( - psig: *mut #[const_ptr_if(any(ossl110, libressl273))] ASN1_BIT_STRING, - palg: *mut #[const_ptr_if(any(ossl110, libressl273))] X509_ALGOR, - x: *const X509, - ); - - #[cfg(any(ossl110, libressl270))] - pub fn X509_REQ_dup(x: #[const_ptr_if(ossl300)] X509_REQ) -> *mut X509_REQ; - } -} -extern "C" { - #[cfg(ossl102)] - pub fn X509_get_signature_nid(x: *const X509) -> c_int; - - pub fn X509_EXTENSION_free(ext: *mut X509_EXTENSION); - - pub fn X509_NAME_ENTRY_free(x: *mut X509_NAME_ENTRY); - - pub fn X509_NAME_new() -> *mut X509_NAME; - pub fn X509_NAME_free(x: *mut X509_NAME); - - pub fn X509_new() -> *mut X509; - pub fn X509_free(x: *mut X509); -} -const_ptr_api! { - extern "C" { - pub fn i2d_X509(x: #[const_ptr_if(ossl300)] X509, buf: *mut *mut u8) -> c_int; - #[cfg(any(ossl110, libressl270))] - pub fn X509_NAME_dup(x: #[const_ptr_if(ossl300)] X509_NAME) -> *mut X509_NAME; - #[cfg(any(ossl110, libressl270))] - pub fn X509_dup(x: #[const_ptr_if(ossl300)] X509) -> *mut X509; - #[cfg(any(ossl101, libressl350))] - pub fn X509_NAME_add_entry( - name: *mut X509_NAME, - ne: #[const_ptr_if(any(ossl110, libressl))] X509_NAME_ENTRY, - loc: c_int, - set: c_int, - ) -> c_int; - } -} -extern "C" { - pub fn d2i_X509(a: *mut *mut X509, pp: *mut *const c_uchar, length: c_long) -> *mut X509; - pub fn d2i_X509_bio(b: *mut BIO, a: *mut *mut X509) -> *mut X509; - - pub fn X509_get_pubkey(x: *mut X509) -> *mut EVP_PKEY; - - pub fn X509_set_version(x: *mut X509, version: c_long) -> c_int; - #[cfg(ossl110)] - pub fn X509_get_version(x: *const X509) -> c_long; - pub fn X509_set_serialNumber(x: *mut X509, sn: *mut ASN1_INTEGER) -> c_int; - pub fn X509_get_serialNumber(x: *mut X509) -> *mut ASN1_INTEGER; -} -const_ptr_api! { - extern "C" { - pub fn X509_set_issuer_name(x: *mut X509, name: #[const_ptr_if(ossl300)] X509_NAME) -> c_int; - } -} -extern "C" { - pub fn X509_issuer_name_hash(x: *mut X509) -> c_ulong; - pub fn X509_subject_name_hash(x: *mut X509) -> c_ulong; -} -const_ptr_api! { - extern "C" { - pub fn X509_get_issuer_name(x: #[const_ptr_if(any(ossl110, libressl280))] X509) -> *mut X509_NAME; - pub fn X509_set_subject_name(x: *mut X509, name: #[const_ptr_if(ossl300)] X509_NAME) -> c_int; - pub fn X509_get_subject_name(x: #[const_ptr_if(any(ossl110, libressl280))] X509) -> *mut X509_NAME; - } -} -cfg_if! { - if #[cfg(any(ossl110, libressl350))] { - extern "C" { - pub fn X509_set1_notBefore(x: *mut X509, tm: *const ASN1_TIME) -> c_int; - pub fn X509_set1_notAfter(x: *mut X509, tm: *const ASN1_TIME) -> c_int; - } - } else { - extern "C" { - pub fn X509_set_notBefore(x: *mut X509, tm: *const ASN1_TIME) -> c_int; - pub fn X509_set_notAfter(x: *mut X509, tm: *const ASN1_TIME) -> c_int; - } - } -} -extern "C" { - #[cfg(any(ossl110, libressl350))] - pub fn X509_REQ_get_version(req: *const X509_REQ) -> c_long; - pub fn X509_REQ_set_version(req: *mut X509_REQ, version: c_long) -> c_int; - #[cfg(any(ossl110, libressl350))] - pub fn X509_REQ_get_subject_name(req: *const X509_REQ) -> *mut X509_NAME; -} -const_ptr_api! { - extern "C" { - pub fn X509_REQ_set_subject_name(req: *mut X509_REQ, name: #[const_ptr_if(ossl300)] X509_NAME) -> c_int; - } -} -extern "C" { - pub fn X509_REQ_set_pubkey(req: *mut X509_REQ, pkey: *mut EVP_PKEY) -> c_int; - pub fn X509_REQ_get_pubkey(req: *mut X509_REQ) -> *mut EVP_PKEY; - pub fn X509_REQ_get_extensions(req: *mut X509_REQ) -> *mut stack_st_X509_EXTENSION; -} -const_ptr_api! { - extern "C" { - pub fn X509_REQ_add_extensions(req: *mut X509_REQ, exts: #[const_ptr_if(ossl300)] stack_st_X509_EXTENSION) - -> c_int; - } -} -extern "C" { - pub fn X509_set_pubkey(x: *mut X509, pkey: *mut EVP_PKEY) -> c_int; - pub fn X509_REQ_verify(req: *mut X509_REQ, pkey: *mut EVP_PKEY) -> c_int; - #[cfg(any(ossl110, libressl273))] - pub fn X509_getm_notBefore(x: *const X509) -> *mut ASN1_TIME; - #[cfg(any(ossl110, libressl273))] - pub fn X509_getm_notAfter(x: *const X509) -> *mut ASN1_TIME; - #[cfg(any(ossl110, libressl273))] - pub fn X509_up_ref(x: *mut X509) -> c_int; - - #[cfg(any(ossl110, libressl270))] - pub fn X509_REVOKED_get0_serialNumber(req: *const X509_REVOKED) -> *const ASN1_INTEGER; - #[cfg(any(ossl110, libressl270))] - pub fn X509_REVOKED_get0_revocationDate(req: *const X509_REVOKED) -> *const ASN1_TIME; - #[cfg(any(ossl110, libressl270))] - pub fn X509_REVOKED_get0_extensions(r: *const X509_REVOKED) -> *const stack_st_X509_EXTENSION; - - pub fn X509_REVOKED_set_serialNumber(r: *mut X509_REVOKED, serial: *mut ASN1_INTEGER) -> c_int; - pub fn X509_REVOKED_set_revocationDate(r: *mut X509_REVOKED, tm: *mut ASN1_TIME) -> c_int; - - pub fn X509_CRL_sign(x: *mut X509_CRL, pkey: *mut EVP_PKEY, md: *const EVP_MD) -> c_int; - pub fn X509_CRL_digest(x: *const X509_CRL, digest: *const EVP_MD, md: *mut c_uchar, len: *mut c_uint) -> c_int; - pub fn X509_CRL_verify(crl: *mut X509_CRL, pkey: *mut EVP_PKEY) -> c_int; - pub fn X509_CRL_get0_by_cert(x: *mut X509_CRL, ret: *mut *mut X509_REVOKED, cert: *mut X509) -> c_int; -} -const_ptr_api! { - extern "C" { - pub fn X509_CRL_get0_by_serial( - x: *mut X509_CRL, - ret: *mut *mut X509_REVOKED, - serial: #[const_ptr_if(ossl300)] ASN1_INTEGER, - ) -> c_int; - } -} - -extern "C" { - #[cfg(any(ossl110, libressl281))] - pub fn X509_CRL_get_REVOKED(crl: *mut X509_CRL) -> *mut stack_st_X509_REVOKED; - #[cfg(any(ossl110, libressl281))] - pub fn X509_CRL_get0_nextUpdate(x: *const X509_CRL) -> *const ASN1_TIME; - #[cfg(any(ossl110, libressl281))] - pub fn X509_CRL_get0_lastUpdate(x: *const X509_CRL) -> *const ASN1_TIME; - #[cfg(any(ossl110, libressl281))] - pub fn X509_CRL_get_issuer(x: *const X509_CRL) -> *mut X509_NAME; - - #[cfg(ossl110)] - pub fn X509_get0_extensions(req: *const X509) -> *const stack_st_X509_EXTENSION; - - pub fn X509_CRL_set_version(crl: *mut X509_CRL, version: c_long) -> c_int; -} -const_ptr_api! { - extern "C" { - pub fn X509_CRL_set_issuer_name(crl: *mut X509_CRL, name: #[const_ptr_if(ossl300)] X509_NAME) -> c_int; - } -} -extern "C" { - pub fn X509_CRL_sort(crl: *mut X509_CRL) -> c_int; - - #[cfg(any(ossl110, libressl270))] - pub fn X509_CRL_up_ref(crl: *mut X509_CRL) -> c_int; - pub fn X509_CRL_add0_revoked(crl: *mut X509_CRL, rev: *mut X509_REVOKED) -> c_int; -} -cfg_if! { - if #[cfg(any(ossl110, libressl270))] { - extern "C" { - pub fn X509_CRL_set1_lastUpdate(crl: *mut X509_CRL, tm: *const ASN1_TIME) -> c_int; - pub fn X509_CRL_set1_nextUpdate(crl: *mut X509_CRL, tm: *const ASN1_TIME) -> c_int; - } - } else { - // libressl270 kept them, ossl110 "#define"s them to the variants above - extern "C" { - pub fn X509_CRL_set_lastUpdate(crl: *mut X509_CRL, tm: *const ASN1_TIME) -> c_int; - pub fn X509_CRL_set_nextUpdate(crl: *mut X509_CRL, tm: *const ASN1_TIME) -> c_int; - } - } -} - -const_ptr_api! { - extern "C" { - pub fn X509_NAME_entry_count(n: #[const_ptr_if(any(ossl110, libressl280))] X509_NAME) -> c_int; - pub fn X509_NAME_get_index_by_NID(n: #[const_ptr_if(any(ossl300, libressl280))] X509_NAME, nid: c_int, last_pos: c_int) -> c_int; - pub fn X509_NAME_get_entry(n: #[const_ptr_if(any(ossl110, libressl280))] X509_NAME, loc: c_int) -> *mut X509_NAME_ENTRY; - pub fn X509_NAME_add_entry_by_NID( - x: *mut X509_NAME, - field: c_int, - ty: c_int, - bytes: #[const_ptr_if(any(ossl110, libressl280))] c_uchar, - len: c_int, - loc: c_int, - set: c_int, - ) -> c_int; - pub fn i2d_X509_NAME(n: #[const_ptr_if(ossl300)] X509_NAME, buf: *mut *mut u8) -> c_int; - pub fn X509_NAME_ENTRY_get_object(ne: #[const_ptr_if(any(ossl110, libressl280))] X509_NAME_ENTRY) -> *mut ASN1_OBJECT; - pub fn X509_NAME_ENTRY_get_data(ne: #[const_ptr_if(any(ossl110, libressl280))] X509_NAME_ENTRY) -> *mut ASN1_STRING; - } -} -extern "C" { - pub fn X509_NAME_add_entry_by_txt( - x: *mut X509_NAME, - field: *const c_char, - ty: c_int, - bytes: *const c_uchar, - len: c_int, - loc: c_int, - set: c_int, - ) -> c_int; - pub fn d2i_X509_NAME(n: *mut *mut X509_NAME, pp: *mut *const c_uchar, length: c_long) -> *mut X509_NAME; -} - -// "raw" X509_EXTENSION related functions -extern "C" { - // in X509 - pub fn X509_delete_ext(x: *mut X509, loc: c_int) -> *mut X509_EXTENSION; - pub fn X509_add_ext(x: *mut X509, ext: *mut X509_EXTENSION, loc: c_int) -> c_int; - pub fn X509_add1_ext_i2d(x: *mut X509, nid: c_int, value: *mut c_void, crit: c_int, flags: c_ulong) -> c_int; - // in X509_CRL - pub fn X509_CRL_delete_ext(x: *mut X509_CRL, loc: c_int) -> *mut X509_EXTENSION; - pub fn X509_CRL_add_ext(x: *mut X509_CRL, ext: *mut X509_EXTENSION, loc: c_int) -> c_int; - pub fn X509_CRL_add1_ext_i2d(x: *mut X509_CRL, nid: c_int, value: *mut c_void, crit: c_int, flags: c_ulong) -> c_int; - // in X509_REVOKED - pub fn X509_REVOKED_delete_ext(x: *mut X509_REVOKED, loc: c_int) -> *mut X509_EXTENSION; - pub fn X509_REVOKED_add_ext(x: *mut X509_REVOKED, ext: *mut X509_EXTENSION, loc: c_int) -> c_int; - pub fn X509_REVOKED_add1_ext_i2d(x: *mut X509_REVOKED, nid: c_int, value: *mut c_void, crit: c_int, flags: c_ulong) -> c_int; - // X509_EXTENSION stack - // - these getters always used *const STACK - pub fn X509v3_get_ext_count(x: *const stack_st_X509_EXTENSION) -> c_int; - pub fn X509v3_get_ext_by_NID(x: *const stack_st_X509_EXTENSION, nid: c_int, lastpos: c_int) -> c_int; - pub fn X509v3_get_ext_by_critical(x: *const stack_st_X509_EXTENSION, crit: c_int, lastpos: c_int) -> c_int; - pub fn X509v3_get_ext(x: *const stack_st_X509_EXTENSION, loc: c_int) -> *mut X509_EXTENSION; - pub fn X509v3_delete_ext(x: *mut stack_st_X509_EXTENSION, loc: c_int) -> *mut X509_EXTENSION; - pub fn X509v3_add_ext(x: *mut *mut stack_st_X509_EXTENSION, ex: *mut X509_EXTENSION, loc: c_int) -> *mut stack_st_X509_EXTENSION; - // - X509V3_add1_i2d in x509v3.rs - // X509_EXTENSION itself - pub fn X509_EXTENSION_create_by_NID(ex: *mut *mut X509_EXTENSION, nid: c_int, crit: c_int, data: *mut ASN1_OCTET_STRING) -> *mut X509_EXTENSION; - pub fn X509_EXTENSION_set_critical(ex: *mut X509_EXTENSION, crit: c_int) -> c_int; - pub fn X509_EXTENSION_set_data(ex: *mut X509_EXTENSION, data: *mut ASN1_OCTET_STRING) -> c_int; - pub fn X509_EXTENSION_get_object(ext: *mut X509_EXTENSION) -> *mut ASN1_OBJECT; - pub fn X509_EXTENSION_get_data(ext: *mut X509_EXTENSION) -> *mut ASN1_OCTET_STRING; -} -const_ptr_api! { - extern "C" { - // in X509 - pub fn X509_get_ext_count(x: #[const_ptr_if(any(ossl110, libressl280))] X509) -> c_int; - pub fn X509_get_ext_by_NID(x: #[const_ptr_if(any(ossl110, libressl280))] X509, nid: c_int, lastpos: c_int) -> c_int; - pub fn X509_get_ext_by_OBJ(x: #[const_ptr_if(any(ossl110, libressl280))] X509, obj: #[const_ptr_if(any(ossl110, libressl280))] ASN1_OBJECT, lastpos: c_int) -> c_int; - pub fn X509_get_ext_by_critical(x: #[const_ptr_if(any(ossl110, libressl280))] X509, crit: c_int, lastpos: c_int) -> c_int; - pub fn X509_get_ext(x: #[const_ptr_if(any(ossl110, libressl280))] X509, loc: c_int) -> *mut X509_EXTENSION; - pub fn X509_get_ext_d2i( - x: #[const_ptr_if(any(ossl110, libressl280))] X509, - nid: c_int, - crit: *mut c_int, - idx: *mut c_int, - ) -> *mut c_void; - // in X509_CRL - pub fn X509_CRL_get_ext_count(x: #[const_ptr_if(any(ossl110, libressl280))] X509_CRL) -> c_int; - pub fn X509_CRL_get_ext_by_NID(x: #[const_ptr_if(any(ossl110, libressl280))] X509_CRL, nid: c_int, lastpos: c_int) -> c_int; - pub fn X509_CRL_get_ext_by_OBJ(x: #[const_ptr_if(any(ossl110, libressl280))] X509_CRL, obj: #[const_ptr_if(any(ossl110, libressl280))] ASN1_OBJECT, lastpos: c_int) -> c_int; - pub fn X509_CRL_get_ext_by_critical(x: #[const_ptr_if(any(ossl110, libressl280))] X509_CRL, crit: c_int, lastpos: c_int) -> c_int; - pub fn X509_CRL_get_ext(x: #[const_ptr_if(any(ossl110, libressl280))] X509_CRL, loc: c_int) -> *mut X509_EXTENSION; - pub fn X509_CRL_get_ext_d2i( - x: #[const_ptr_if(any(ossl110, libressl280))] X509_CRL, - nid: c_int, - crit: *mut c_int, - idx: *mut c_int, - ) -> *mut c_void; - // in X509_REVOKED - pub fn X509_REVOKED_get_ext_count(x: #[const_ptr_if(any(ossl110, libressl280))] X509_REVOKED) -> c_int; - pub fn X509_REVOKED_get_ext_by_NID(x: #[const_ptr_if(any(ossl110, libressl280))] X509_REVOKED, nid: c_int, lastpos: c_int) -> c_int; - pub fn X509_REVOKED_get_ext_by_OBJ(x: #[const_ptr_if(any(ossl110, libressl280))] X509_REVOKED, obj: #[const_ptr_if(any(ossl110, libressl280))] ASN1_OBJECT, lastpos: c_int) -> c_int; - pub fn X509_REVOKED_get_ext_by_critical(x: #[const_ptr_if(any(ossl110, libressl280))] X509_REVOKED, crit: c_int, lastpos: c_int) -> c_int; - pub fn X509_REVOKED_get_ext(x: #[const_ptr_if(any(ossl110, libressl280))] X509_REVOKED, loc: c_int) -> *mut X509_EXTENSION; - pub fn X509_REVOKED_get_ext_d2i( - x: #[const_ptr_if(any(ossl110, libressl280))] X509_REVOKED, - nid: c_int, - crit: *mut c_int, - idx: *mut c_int, - ) -> *mut c_void; - // X509_EXTENSION stack - pub fn X509v3_get_ext_by_OBJ(x: *const stack_st_X509_EXTENSION, obj: #[const_ptr_if(any(ossl110, libressl280))] ASN1_OBJECT, lastpos: c_int) -> c_int; - // X509_EXTENSION itself - pub fn X509_EXTENSION_create_by_OBJ(ex: *mut *mut X509_EXTENSION, obj: #[const_ptr_if(any(ossl110, libressl280))] ASN1_OBJECT, crit: c_int, data: *mut ASN1_OCTET_STRING) -> *mut X509_EXTENSION; - pub fn X509_EXTENSION_set_object(ex: *mut X509_EXTENSION, obj: #[const_ptr_if(any(ossl110, libressl280))] ASN1_OBJECT) -> c_int; - pub fn X509_EXTENSION_get_critical(ex: #[const_ptr_if(any(ossl110, libressl280))] X509_EXTENSION) -> c_int; - } -} - -extern "C" { - pub fn X509_verify_cert(ctx: *mut X509_STORE_CTX) -> c_int; -} - -const_ptr_api! { - extern "C" { - #[cfg(any(ossl110, libressl270))] - pub fn X509_STORE_get0_objects(ctx: #[const_ptr_if(ossl300)] X509_STORE) -> *mut stack_st_X509_OBJECT; - } -} -#[cfg(any(ossl110, libressl270))] -extern "C" { - pub fn X509_OBJECT_get0_X509(x: *const X509_OBJECT) -> *mut X509; -} - -cfg_if! { - if #[cfg(any(ossl110, libressl350))] { - extern "C" { - pub fn X509_OBJECT_free(a: *mut X509_OBJECT); - } - } else { - extern "C" { - pub fn X509_OBJECT_free_contents(a: *mut X509_OBJECT); - } - } -} - -extern "C" { - pub fn X509_get_default_cert_file_env() -> *const c_char; - pub fn X509_get_default_cert_file() -> *const c_char; - pub fn X509_get_default_cert_dir_env() -> *const c_char; - pub fn X509_get_default_cert_dir() -> *const c_char; -} - -extern "C" { - pub fn X509_cmp(a: *const X509, b: *const X509) -> c_int; - pub fn X509_NAME_cmp(a: *const X509_NAME, b: *const X509_NAME) -> c_int; - pub fn X509_issuer_and_serial_cmp(a: *const X509, b: *const X509) -> c_int; - pub fn X509_issuer_name_cmp(a: *const X509, b: *const X509) -> c_int; - pub fn X509_subject_name_cmp(a: *const X509, b: *const X509) -> c_int; - pub fn X509_CRL_cmp(a: *const X509_CRL, b: *const X509_CRL) -> c_int; - pub fn X509_CRL_match(a: *const X509_CRL, b: *const X509_CRL) -> c_int; -} - -extern "C" { - pub fn X509_print(bio: *mut BIO, x509: *mut X509) -> c_int; - pub fn X509_REQ_print(bio: *mut BIO, req: *mut X509_REQ) -> c_int; -} - -#[repr(C)] -pub struct X509_PURPOSE { - pub purpose: c_int, - pub trust: c_int, // Default trust ID - pub flags: c_int, - pub check_purpose: Option c_int>, - pub name: *mut c_char, - pub sname: *mut c_char, - pub usr_data: *mut c_void, -} - -const_ptr_api! { - extern "C" { - pub fn X509_PURPOSE_get_by_sname(sname: #[const_ptr_if(any(ossl110, libressl280))] c_char) -> c_int; - pub fn X509_PURPOSE_get0(idx: c_int) -> *mut X509_PURPOSE; - } -} diff --git a/openssl-sys/src/handwritten/x509_vfy.rs b/openssl-sys/src/handwritten/x509_vfy.rs deleted file mode 100644 index 3b738c8..0000000 --- a/openssl-sys/src/handwritten/x509_vfy.rs +++ /dev/null @@ -1,110 +0,0 @@ -use super::super::*; -use libc::*; - -#[cfg(any(libressl, all(ossl102, not(ossl110))))] -pub enum X509_VERIFY_PARAM_ID {} - -extern "C" { - #[cfg(ossl110)] - pub fn X509_LOOKUP_meth_free(method: *mut X509_LOOKUP_METHOD); -} - -extern "C" { - pub fn X509_LOOKUP_free(ctx: *mut X509_LOOKUP); - pub fn X509_LOOKUP_hash_dir() -> *mut X509_LOOKUP_METHOD; - pub fn X509_LOOKUP_file() -> *mut X509_LOOKUP_METHOD; - pub fn X509_LOOKUP_ctrl(ctx: *mut X509_LOOKUP, cmd: c_int, argc: *const c_char, argl: c_long, ret: *mut *mut c_char) -> c_int; - pub fn X509_load_cert_file(ctx: *mut X509_LOOKUP, file: *const c_char, _type: c_int) -> c_int; - pub fn X509_load_crl_file(ctx: *mut X509_LOOKUP, file: *const c_char, _type: c_int) -> c_int; -} - -extern "C" { - pub fn X509_STORE_new() -> *mut X509_STORE; - pub fn X509_STORE_free(store: *mut X509_STORE); - - pub fn X509_STORE_CTX_new() -> *mut X509_STORE_CTX; - - pub fn X509_STORE_CTX_free(ctx: *mut X509_STORE_CTX); - pub fn X509_STORE_CTX_init(ctx: *mut X509_STORE_CTX, store: *mut X509_STORE, x509: *mut X509, chain: *mut stack_st_X509) -> c_int; - pub fn X509_STORE_CTX_cleanup(ctx: *mut X509_STORE_CTX); - - pub fn X509_STORE_add_cert(store: *mut X509_STORE, x: *mut X509) -> c_int; - - pub fn X509_STORE_add_lookup(store: *mut X509_STORE, meth: *mut X509_LOOKUP_METHOD) -> *mut X509_LOOKUP; - - pub fn X509_STORE_set_default_paths(store: *mut X509_STORE) -> c_int; - pub fn X509_STORE_set_flags(store: *mut X509_STORE, flags: c_ulong) -> c_int; - pub fn X509_STORE_set_purpose(ctx: *mut X509_STORE, purpose: c_int) -> c_int; - pub fn X509_STORE_set_trust(ctx: *mut X509_STORE, trust: c_int) -> c_int; - -} - -const_ptr_api! { - extern "C" { - pub fn X509_STORE_set1_param(store: *mut X509_STORE, pm: #[const_ptr_if(ossl300)] X509_VERIFY_PARAM) -> c_int; - } -} - -const_ptr_api! { - extern "C" { - pub fn X509_STORE_CTX_get_ex_data(ctx: #[const_ptr_if(ossl300)] X509_STORE_CTX, idx: c_int) -> *mut c_void; - pub fn X509_STORE_CTX_get_error(ctx: #[const_ptr_if(ossl300)] X509_STORE_CTX) -> c_int; - pub fn X509_STORE_CTX_get_error_depth(ctx: #[const_ptr_if(ossl300)] X509_STORE_CTX) -> c_int; - pub fn X509_STORE_CTX_get_current_cert(ctx: #[const_ptr_if(ossl300)] X509_STORE_CTX) -> *mut X509; - } -} -extern "C" { - pub fn X509_STORE_CTX_set_error(ctx: *mut X509_STORE_CTX, error: c_int); -} -cfg_if! { - if #[cfg(any(ossl110, libressl350))] { - const_ptr_api! { - extern "C" { - pub fn X509_STORE_CTX_get0_chain(ctx: #[const_ptr_if(ossl300)] X509_STORE_CTX) -> *mut stack_st_X509; - } - } - } else { - extern "C" { - pub fn X509_STORE_CTX_get_chain(ctx: *mut X509_STORE_CTX) -> *mut stack_st_X509; - } - } -} - -extern "C" { - #[cfg(any(ossl102, libressl261))] - pub fn X509_VERIFY_PARAM_new() -> *mut X509_VERIFY_PARAM; - #[cfg(any(ossl102, libressl261))] - pub fn X509_VERIFY_PARAM_free(param: *mut X509_VERIFY_PARAM); - - #[cfg(any(ossl102, libressl261))] - pub fn X509_VERIFY_PARAM_set_flags(param: *mut X509_VERIFY_PARAM, flags: c_ulong) -> c_int; - #[cfg(any(ossl102, libressl261))] - pub fn X509_VERIFY_PARAM_clear_flags(param: *mut X509_VERIFY_PARAM, flags: c_ulong) -> c_int; - - #[cfg(any(ossl102, libressl261))] - pub fn X509_VERIFY_PARAM_set_time(param: *mut X509_VERIFY_PARAM, t: time_t); - - #[cfg(any(ossl102, libressl261))] - pub fn X509_VERIFY_PARAM_set_depth(param: *mut X509_VERIFY_PARAM, depth: c_int); -} -const_ptr_api! { - extern "C" { - #[cfg(any(ossl102, libressl261))] - pub fn X509_VERIFY_PARAM_get_flags(param: #[const_ptr_if(ossl300)] X509_VERIFY_PARAM) -> c_ulong; - } -} - -extern "C" { - #[cfg(any(ossl102, libressl261))] - pub fn X509_VERIFY_PARAM_set1_host(param: *mut X509_VERIFY_PARAM, name: *const c_char, namelen: size_t) -> c_int; - #[cfg(any(ossl102, libressl261))] - pub fn X509_VERIFY_PARAM_set_hostflags(param: *mut X509_VERIFY_PARAM, flags: c_uint); - #[cfg(any(ossl102, libressl261))] - pub fn X509_VERIFY_PARAM_set1_ip(param: *mut X509_VERIFY_PARAM, ip: *const c_uchar, iplen: size_t) -> c_int; - #[cfg(ossl110)] - pub fn X509_VERIFY_PARAM_set_auth_level(param: *mut X509_VERIFY_PARAM, lvl: c_int); - #[cfg(ossl110)] - pub fn X509_VERIFY_PARAM_get_auth_level(param: *const X509_VERIFY_PARAM) -> c_int; - #[cfg(ossl102)] - pub fn X509_VERIFY_PARAM_set_purpose(param: *mut X509_VERIFY_PARAM, purpose: c_int) -> c_int; -} diff --git a/openssl-sys/src/handwritten/x509v3.rs b/openssl-sys/src/handwritten/x509v3.rs deleted file mode 100644 index c79f2f4..0000000 --- a/openssl-sys/src/handwritten/x509v3.rs +++ /dev/null @@ -1,86 +0,0 @@ -use super::super::*; -use libc::*; - -pub enum CONF_METHOD {} - -extern "C" { - pub fn GENERAL_NAME_free(name: *mut GENERAL_NAME); -} - -#[repr(C)] -pub struct ACCESS_DESCRIPTION { - pub method: *mut ASN1_OBJECT, - pub location: *mut GENERAL_NAME, -} - -stack!(stack_st_ACCESS_DESCRIPTION); - -extern "C" { - pub fn ACCESS_DESCRIPTION_free(ad: *mut ACCESS_DESCRIPTION); -} - -#[repr(C)] -pub struct AUTHORITY_KEYID { - pub keyid: *mut ASN1_OCTET_STRING, - pub issuer: *mut stack_st_GENERAL_NAME, - pub serial: *mut ASN1_INTEGER, -} - -extern "C" { - pub fn AUTHORITY_KEYID_free(akid: *mut AUTHORITY_KEYID); -} - -const_ptr_api! { - extern "C" { - pub fn X509V3_EXT_nconf_nid( - conf: *mut CONF, - ctx: *mut X509V3_CTX, - ext_nid: c_int, - value: #[const_ptr_if(any(ossl110, libressl280))] c_char, - ) -> *mut X509_EXTENSION; - pub fn X509V3_EXT_nconf( - conf: *mut CONF, - ctx: *mut X509V3_CTX, - name: #[const_ptr_if(any(ossl110, libressl280))] c_char, - value: #[const_ptr_if(any(ossl110, libressl280))] c_char, - ) -> *mut X509_EXTENSION; - } -} - -extern "C" { - pub fn X509_check_issued(issuer: *mut X509, subject: *mut X509) -> c_int; - pub fn X509_verify(req: *mut X509, pkey: *mut EVP_PKEY) -> c_int; - - pub fn X509V3_set_nconf(ctx: *mut X509V3_CTX, conf: *mut CONF); - - pub fn X509V3_set_ctx(ctx: *mut X509V3_CTX, issuer: *mut X509, subject: *mut X509, req: *mut X509_REQ, crl: *mut X509_CRL, flags: c_int); - - pub fn X509_get1_ocsp(x: *mut X509) -> *mut stack_st_OPENSSL_STRING; -} - -const_ptr_api! { - extern "C" { - pub fn X509V3_get_d2i( - x: #[const_ptr_if(any(ossl110, libressl280))] stack_st_X509_EXTENSION, - nid: c_int, - crit: *mut c_int, - idx: *mut c_int, - ) -> *mut c_void; - pub fn X509V3_extensions_print(out: *mut BIO, title: #[const_ptr_if(any(ossl110, libressl280))] c_char, exts: #[const_ptr_if(any(ossl110, libressl280))] stack_st_X509_EXTENSION, flag: c_ulong, indent: c_int) -> c_int; - } -} - -extern "C" { - pub fn X509V3_EXT_add_alias(nid_to: c_int, nid_from: c_int) -> c_int; - pub fn X509V3_EXT_d2i(ext: *mut X509_EXTENSION) -> *mut c_void; - pub fn X509V3_EXT_i2d(ext_nid: c_int, crit: c_int, ext: *mut c_void) -> *mut X509_EXTENSION; - pub fn X509V3_add1_i2d(x: *mut *mut stack_st_X509_EXTENSION, nid: c_int, value: *mut c_void, crit: c_int, flags: c_ulong) -> c_int; - pub fn X509V3_EXT_print(out: *mut BIO, ext: *mut X509_EXTENSION, flag: c_ulong, indent: c_int) -> c_int; - - #[cfg(ossl110)] - pub fn X509_get_extension_flags(x: *mut X509) -> u32; - #[cfg(ossl110)] - pub fn X509_get_key_usage(x: *mut X509) -> u32; - #[cfg(ossl110)] - pub fn X509_get_extended_key_usage(x: *mut X509) -> u32; -} diff --git a/openssl-sys/src/lib.rs b/openssl-sys/src/lib.rs deleted file mode 100644 index 1dd1bba..0000000 --- a/openssl-sys/src/lib.rs +++ /dev/null @@ -1,182 +0,0 @@ -#![allow( - clippy::missing_safety_doc, - clippy::unreadable_literal, - clippy::uninlined_format_args, - clippy::upper_case_acronyms, - dead_code, - non_camel_case_types, - non_snake_case, - non_upper_case_globals, - overflowing_literals, - unused_imports -)] -#![doc(html_root_url = "https://docs.rs/openssl-sys/0.9")] -#![recursion_limit = "128"] // configure fixed limit across all rust versions - -extern crate libc; -pub use libc::*; - -#[cfg(boringssl)] -extern crate bssl_sys; -#[cfg(boringssl)] -pub use bssl_sys::*; - -#[cfg(openssl)] -#[path = "."] -mod openssl { - use libc::*; - - #[cfg(feature = "bindgen")] - include!(concat!(env!("OUT_DIR"), "/bindgen.rs")); - - pub use self::aes::*; - pub use self::asn1::*; - pub use self::bio::*; - pub use self::bn::*; - pub use self::cms::*; - pub use self::crypto::*; - pub use self::dtls1::*; - pub use self::ec::*; - pub use self::err::*; - pub use self::evp::*; - #[cfg(not(feature = "bindgen"))] - pub use self::handwritten::*; - pub use self::obj_mac::*; - pub use self::ocsp::*; - pub use self::pem::*; - pub use self::pkcs7::*; - pub use self::rsa::*; - pub use self::sha::*; - pub use self::srtp::*; - pub use self::ssl::*; - pub use self::ssl3::*; - pub use self::tls1::*; - pub use self::types::*; - pub use self::x509::*; - pub use self::x509_vfy::*; - pub use self::x509v3::*; - - #[macro_use] - mod macros; - - mod aes; - mod asn1; - mod bio; - mod bn; - mod cms; - mod crypto; - mod dtls1; - mod ec; - mod err; - mod evp; - #[cfg(not(feature = "bindgen"))] - mod handwritten; - mod obj_mac; - mod ocsp; - mod pem; - mod pkcs7; - mod rsa; - mod sha; - mod srtp; - mod ssl; - mod ssl3; - mod tls1; - mod types; - mod x509; - mod x509_vfy; - mod x509v3; - - use std::sync::Once; - // explicitly initialize to work around https://github.com/openssl/openssl/issues/3505 - static INIT: Once = Once::new(); - - // FIXME remove - pub type PasswordCallback = unsafe extern "C" fn(buf: *mut c_char, size: c_int, rwflag: c_int, user_data: *mut c_void) -> c_int; - - #[cfg(ossl110)] - pub fn init() { - use std::ptr; - - #[cfg(not(ossl111b))] - let init_options = OPENSSL_INIT_LOAD_SSL_STRINGS; - #[cfg(ossl111b)] - let init_options = OPENSSL_INIT_LOAD_SSL_STRINGS | OPENSSL_INIT_NO_ATEXIT; - - INIT.call_once(|| unsafe { - OPENSSL_init_ssl(init_options, ptr::null_mut()); - }) - } - - #[cfg(not(ossl110))] - pub fn init() { - use std::io::{self, Write}; - use std::mem; - use std::process; - use std::sync::{Mutex, MutexGuard}; - - static mut MUTEXES: *mut Vec> = 0 as *mut Vec>; - static mut GUARDS: *mut Vec>> = 0 as *mut Vec>>; - - unsafe extern "C" fn locking_function(mode: c_int, n: c_int, _file: *const c_char, _line: c_int) { - let mutex = &(*MUTEXES)[n as usize]; - - if mode & CRYPTO_LOCK != 0 { - (*GUARDS)[n as usize] = Some(mutex.lock().unwrap()); - } else { - if let None = (*GUARDS)[n as usize].take() { - let _ = writeln!(io::stderr(), "BUG: rust-openssl lock {} already unlocked, aborting", n); - process::abort(); - } - } - } - - cfg_if! { - if #[cfg(unix)] { - fn set_id_callback() { - unsafe extern "C" fn thread_id() -> c_ulong { - ::libc::pthread_self() as c_ulong - } - - unsafe { - CRYPTO_set_id_callback__fixed_rust(Some(thread_id)); - } - } - } else { - fn set_id_callback() {} - } - } - - INIT.call_once(|| unsafe { - SSL_library_init(); - SSL_load_error_strings(); - OPENSSL_add_all_algorithms_noconf(); - - let num_locks = CRYPTO_num_locks(); - let mut mutexes = Box::new(Vec::new()); - for _ in 0..num_locks { - mutexes.push(Mutex::new(())); - } - MUTEXES = mem::transmute(mutexes); - let guards: Box>>> = Box::new((0..num_locks).map(|_| None).collect()); - GUARDS = mem::transmute(guards); - - CRYPTO_set_locking_callback__fixed_rust(Some(locking_function)); - set_id_callback(); - }) - } - - /// Disable explicit initialization of the openssl libs. - /// - /// This is only appropriate to use if the openssl crate is being consumed by an application - /// that will be performing the initialization explicitly. - /// - /// # Safety - /// - /// In some versions of openssl, skipping initialization will fall back to the default procedure - /// while other will cause difficult to debug errors so care must be taken when calling this. - pub unsafe fn assume_init() { - INIT.call_once(|| {}); - } -} -#[cfg(openssl)] -pub use openssl::*; diff --git a/openssl-sys/src/macros.rs b/openssl-sys/src/macros.rs deleted file mode 100644 index e1b08c4..0000000 --- a/openssl-sys/src/macros.rs +++ /dev/null @@ -1,298 +0,0 @@ -#![allow(unused_macros)] - -// vendored from the cfg-if crate to avoid breaking ctest -macro_rules! cfg_if { - // match if/else chains with a final `else` - ($( - if #[cfg($($meta:meta),*)] { $($it:item)* } - ) else * else { - $($it2:item)* - }) => { - cfg_if! { - @__items - () ; - $( ( ($($meta),*) ($($it)*) ), )* - ( () ($($it2)*) ), - } - }; - - // match if/else chains lacking a final `else` - ( - if #[cfg($($i_met:meta),*)] { $($i_it:item)* } - $( - else if #[cfg($($e_met:meta),*)] { $($e_it:item)* } - )* - ) => { - cfg_if! { - @__items - () ; - ( ($($i_met),*) ($($i_it)*) ), - $( ( ($($e_met),*) ($($e_it)*) ), )* - ( () () ), - } - }; - - // Internal and recursive macro to emit all the items - // - // Collects all the negated cfgs in a list at the beginning and after the - // semicolon is all the remaining items - (@__items ($($not:meta,)*) ; ) => {}; - (@__items ($($not:meta,)*) ; ( ($($m:meta),*) ($($it:item)*) ), $($rest:tt)*) => { - // Emit all items within one block, applying an appropriate #[cfg]. The - // #[cfg] will require all `$m` matchers specified and must also negate - // all previous matchers. - cfg_if! { @__apply cfg(all($($m,)* not(any($($not),*)))), $($it)* } - - // Recurse to emit all other items in `$rest`, and when we do so add all - // our `$m` matchers to the list of `$not` matchers as future emissions - // will have to negate everything we just matched as well. - cfg_if! { @__items ($($not,)* $($m,)*) ; $($rest)* } - }; - - // Internal macro to Apply a cfg attribute to a list of items - (@__apply $m:meta, $($it:item)*) => { - $(#[$m] $it)* - }; -} - -macro_rules! stack { - ($t:ident) => { - cfg_if! { - if #[cfg(ossl110)] { - pub enum $t {} - } else { - #[repr(C)] - pub struct $t { - pub stack: $crate::_STACK, - } - } - } - }; -} - -#[cfg(const_fn)] -macro_rules! const_fn { - ($(pub const fn $name:ident($($arg:ident: $t:ty),*) -> $ret:ty $b:block)*) => { - $( - pub const fn $name($($arg: $t),*) -> $ret $b - )* - } -} - -#[cfg(not(const_fn))] -macro_rules! const_fn { - ($(pub const fn $name:ident($($arg:ident: $t:ty),*) -> $ret:ty $b:block)*) => { - $( - pub fn $name($($arg: $t),*) -> $ret $b - )* - } -} - -// openssl changes `*mut` to `*const` in certain parameters in certain versions; -// in C this is ABI and (mostly) API compatible. -// -// We need to handle this explicitly, and this macro helps annotate which -// parameter got converted in which version. -// -// Input is: -// extern "C" { -// #[attributes...] -// pub fn name(args) -> rettype; // `-> rettype` optional -// // more functions... -// } -// -// This macro replaces `#[const_ptr_if(...)]` in types with `*const` or `*mut` -// (depending on the inner cfg flags) -// -// Walks through all argument and return types, but only finds inner types of -// `*const` and `*mut`; doesn't walk arrays or generics. -// -// NOTE: can't abstract `pub` as `$fn_vis:vis`, as ctest macro handling doesn't -// support it (old syntax crate). But we really only need `pub` anyway. -// -// NOTE: ctest seams to simply ignore macros it can't expand (whatever the -// reason) -macro_rules! const_ptr_api { - // ---------------------------------------------------------------- - // (partialarg): partial argument, waiting for "final" argument type - // MAGIC PART 1: hande conditional const ptr in argument type - ( (partialarg) - { $(#[$fn_attr:meta])* pub fn $fn_name:ident } - $args_packed:tt - [ $($part_arg:tt)* ] - [ #[const_ptr_if( $($cfg:tt)* )] $($arg_rem:tt)* ] - $ret_packed:tt - ) => { - const_ptr_api!( (partialarg) { #[cfg($($cfg)*)] $(#[$fn_attr])* pub fn $fn_name } $args_packed [ $($part_arg)* *const ] [ $($arg_rem)* ] $ret_packed ); - const_ptr_api!( (partialarg) { #[cfg(not($($cfg)*))] $(#[$fn_attr])* pub fn $fn_name } $args_packed [ $($part_arg)* *mut ] [ $($arg_rem)* ] $ret_packed ); - }; - // continue partial argument with `*mut` pointer (might need special const handling in inner type) - ( (partialarg) - $def_packed:tt - $args_packed:tt - [ $($part_arg:tt)* ] - [ *mut $($arg_rem:tt)* ] - $ret_packed:tt - ) => { - const_ptr_api!( (partialarg) $def_packed $args_packed [ $($part_arg)* *mut ] [ $($arg_rem)* ] $ret_packed ); - }; - // continue partial argument with `*const` pointer (might need special const handling in inner type) - ( (partialarg) - $def_packed:tt - $args_packed:tt - [ $($part_arg:tt)* ] - [ *const $($arg_rem:tt)* ] - $ret_packed:tt - ) => { - const_ptr_api!( (partialarg) $def_packed $args_packed [ $($part_arg)* *const ] [ $($arg_rem)* ] $ret_packed ); - }; - // finish partial argument with trailing comma - ( (partialarg) - $def_packed:tt - { $($args_tt:tt)* } - [ $($part_arg:tt)* ] - [ $arg_ty:ty, $($arg_rem:tt)* ] - $ret_packed:tt - ) => { - const_ptr_api!( (parseargs) $def_packed { $($args_tt)* { $($part_arg)* $arg_ty } } [ $($arg_rem)* ] $ret_packed ); - }; - // finish final partial argument (no trailing comma) - ( (partialarg) - $def_packed:tt - { $($args_tt:tt)* } - [ $($part_arg:tt)* ] - [ $arg_ty:ty ] - $ret_packed:tt - ) => { - const_ptr_api!( (parseargs) $def_packed { $($args_tt)* { $($part_arg)* $arg_ty } } [ ] $ret_packed ); - }; - - // ---------------------------------------------------------------- - // (parseargs): parsing arguments - // start next argument - ( (parseargs) - $def_packed:tt - $args_packed:tt - [ $arg_name:ident : $($arg_rem:tt)* ] - $ret_packed:tt - ) => { - const_ptr_api!( (partialarg) $def_packed $args_packed [ $arg_name: ] [ $($arg_rem)* ] $ret_packed ); - }; - // end of arguments, there is a return type; start parsing it - ( (parseargs) - $def_packed:tt - $args_packed:tt - [ ] - [ -> $($rem:tt)* ] - ) => { - const_ptr_api!( (partialret) $def_packed $args_packed [] [ $($rem)* ] ); - }; - // end of arguments, no return type - ( (parseargs) - $def_packed:tt - $args_packed:tt - [ ] - [ ] - ) => { - const_ptr_api!( (generate) $def_packed $args_packed { () } ); - }; - - // ---------------------------------------------------------------- - // (partialret): have partial return type, waiting for final return type - // MAGIC PART 2: hande conditional const ptr in return type - ( (partialret) - { $(#[$fn_attr:meta])* pub fn $fn_name:ident } - $args_packed:tt - [ $($part_ret:tt)* ] - [ #[const_ptr_if( $($cfg:tt)* )] $($rem:tt)* ] - ) => { - const_ptr_api!( (partialret) { #[cfg($($cfg)*)] $(#[$fn_attr])* pub fn $fn_name } $args_packed [ $($part_ret)* *const ] [ $($rem)* ] ); - const_ptr_api!( (partialret) { #[cfg(not($($cfg)*))] $(#[$fn_attr])* pub fn $fn_name } $args_packed [ $($part_ret)* *mut ] [ $($rem)* ] ); - }; - // `* mut` part in return type; continue parsing to find inner conditional const ptr - ( (partialret) - $def_packed:tt - $args_packed:tt - [ $($part_ret:tt)* ] - [ *mut $($rem:tt)* ] - ) => { - const_ptr_api!( (partialret) $def_packed $args_packed [ $($part_ret)* *mut ] [ $($rem)* ] ); - }; - // `* const` part in return type; continue parsing to find inner conditional const ptr - ( (partialret) - $def_packed:tt - $args_packed:tt - [ $($part_ret:tt)* ] - [ *const $($rem:tt)* ] - ) => { - const_ptr_api!( (partialret) $def_packed $args_packed [ $($part_ret)* *const ] [ $($rem)* ] ); - }; - // final part of return type - ( (partialret) - $def_packed:tt - $args_packed:tt - [ $($part_ret:tt)* ] - [ $ret_ty:ty ] - ) => { - const_ptr_api!( (generate) $def_packed $args_packed { $($part_ret)* $ret_ty } ); - }; - - // ---------------------------------------------------------------- - // generate - ( (generate) - { $(#[$fn_attr:meta])* pub fn $fn_name:ident } - { $({ $arg_name:ident: $($arg_ty:tt)* })* } - { $ret_ty:ty } - ) => { - extern "C" { - $(#[$fn_attr])* - pub fn $fn_name( $( - $arg_name: $($arg_ty)* - ),* ) -> $ret_ty; - } - }; - - // ---------------------------------------------------------------- - // (fn): gather tokens for return type until ";" - // found end; start parsing current function, and parse remaining functions - ( (fn) - $def_packed:tt - $arg_tts_packed:tt - $ret_packed:tt - [ ; $($rem:tt)* ] - ) => { - const_ptr_api!( (parseargs) $def_packed {} $arg_tts_packed $ret_packed ); - const_ptr_api!( (extern) [ $($rem)* ] ); - }; - // not ";" - all other tokens are part of the return type. - // don't expand return type yet; otherwise we'd have to remember in which branch `rem` needs - // to be used to parse further functions. - ( (fn) - $def_packed:tt - $arg_tts_packed:tt - [ $($ret_tt:tt)* ] - [ $tt:tt $($rem:tt)* ] - ) => { - const_ptr_api!( (fn) $def_packed $arg_tts_packed [ $($ret_tt)* $tt ] [ $($rem)* ] ); - }; - - // ---------------------------------------------------------------- - // (extern): in extern block, find next function - // try to split into functions as fast as possible to reduce recursion depth - ( (extern) [ - $(#[$fn_attr:meta])* - pub fn $fn_name:ident( $($arg_rem:tt)* ) $($rem:tt)* - ] ) => { - const_ptr_api!( (fn) - { $(#[$fn_attr])* pub fn $fn_name } [ $($arg_rem)* ] [] [ $($rem)* ] - ); - }; - // end of extern block - ( (extern) [] ) => {}; - - // ---------------------------------------------------------------- - // macro start; find extern block - ( extern "C" { $($rem:tt)* } ) => { - const_ptr_api!( (extern) [ $($rem)* ] ); - }; -} diff --git a/openssl-sys/src/obj_mac.rs b/openssl-sys/src/obj_mac.rs deleted file mode 100644 index ed50ebc..0000000 --- a/openssl-sys/src/obj_mac.rs +++ /dev/null @@ -1,978 +0,0 @@ -use libc::*; - -pub const NID_undef: c_int = 0; -pub const NID_itu_t: c_int = 645; -pub const NID_ccitt: c_int = 404; -pub const NID_iso: c_int = 181; -pub const NID_joint_iso_itu_t: c_int = 646; -pub const NID_joint_iso_ccitt: c_int = 393; -pub const NID_member_body: c_int = 182; -pub const NID_identified_organization: c_int = 676; -pub const NID_hmac_md5: c_int = 780; -pub const NID_hmac_sha1: c_int = 781; -pub const NID_certicom_arc: c_int = 677; -pub const NID_international_organizations: c_int = 647; -pub const NID_wap: c_int = 678; -pub const NID_wap_wsg: c_int = 679; -pub const NID_selected_attribute_types: c_int = 394; -pub const NID_clearance: c_int = 395; -pub const NID_ISO_US: c_int = 183; -pub const NID_X9_57: c_int = 184; -pub const NID_X9cm: c_int = 185; -pub const NID_dsa: c_int = 116; -pub const NID_dsaWithSHA1: c_int = 113; -pub const NID_ansi_X9_62: c_int = 405; -pub const NID_X9_62_prime_field: c_int = 406; -pub const NID_X9_62_characteristic_two_field: c_int = 407; -pub const NID_X9_62_id_characteristic_two_basis: c_int = 680; -pub const NID_X9_62_onBasis: c_int = 681; -pub const NID_X9_62_tpBasis: c_int = 682; -pub const NID_X9_62_ppBasis: c_int = 683; -pub const NID_X9_62_id_ecPublicKey: c_int = 408; -pub const NID_X9_62_c2pnb163v1: c_int = 684; -pub const NID_X9_62_c2pnb163v2: c_int = 685; -pub const NID_X9_62_c2pnb163v3: c_int = 686; -pub const NID_X9_62_c2pnb176v1: c_int = 687; -pub const NID_X9_62_c2tnb191v1: c_int = 688; -pub const NID_X9_62_c2tnb191v2: c_int = 689; -pub const NID_X9_62_c2tnb191v3: c_int = 690; -pub const NID_X9_62_c2onb191v4: c_int = 691; -pub const NID_X9_62_c2onb191v5: c_int = 692; -pub const NID_X9_62_c2pnb208w1: c_int = 693; -pub const NID_X9_62_c2tnb239v1: c_int = 694; -pub const NID_X9_62_c2tnb239v2: c_int = 695; -pub const NID_X9_62_c2tnb239v3: c_int = 696; -pub const NID_X9_62_c2onb239v4: c_int = 697; -pub const NID_X9_62_c2onb239v5: c_int = 698; -pub const NID_X9_62_c2pnb272w1: c_int = 699; -pub const NID_X9_62_c2pnb304w1: c_int = 700; -pub const NID_X9_62_c2tnb359v1: c_int = 701; -pub const NID_X9_62_c2pnb368w1: c_int = 702; -pub const NID_X9_62_c2tnb431r1: c_int = 703; -pub const NID_X9_62_prime192v1: c_int = 409; -pub const NID_X9_62_prime192v2: c_int = 410; -pub const NID_X9_62_prime192v3: c_int = 411; -pub const NID_X9_62_prime239v1: c_int = 412; -pub const NID_X9_62_prime239v2: c_int = 413; -pub const NID_X9_62_prime239v3: c_int = 414; -pub const NID_X9_62_prime256v1: c_int = 415; -pub const NID_ecdsa_with_SHA1: c_int = 416; -pub const NID_ecdsa_with_Recommended: c_int = 791; -pub const NID_ecdsa_with_Specified: c_int = 792; -pub const NID_ecdsa_with_SHA224: c_int = 793; -pub const NID_ecdsa_with_SHA256: c_int = 794; -pub const NID_ecdsa_with_SHA384: c_int = 795; -pub const NID_ecdsa_with_SHA512: c_int = 796; -pub const NID_secp112r1: c_int = 704; -pub const NID_secp112r2: c_int = 705; -pub const NID_secp128r1: c_int = 706; -pub const NID_secp128r2: c_int = 707; -pub const NID_secp160k1: c_int = 708; -pub const NID_secp160r1: c_int = 709; -pub const NID_secp160r2: c_int = 710; -pub const NID_secp192k1: c_int = 711; -pub const NID_secp224k1: c_int = 712; -pub const NID_secp224r1: c_int = 713; -pub const NID_secp256k1: c_int = 714; -pub const NID_secp384r1: c_int = 715; -pub const NID_secp521r1: c_int = 716; -pub const NID_sect113r1: c_int = 717; -pub const NID_sect113r2: c_int = 718; -pub const NID_sect131r1: c_int = 719; -pub const NID_sect131r2: c_int = 720; -pub const NID_sect163k1: c_int = 721; -pub const NID_sect163r1: c_int = 722; -pub const NID_sect163r2: c_int = 723; -pub const NID_sect193r1: c_int = 724; -pub const NID_sect193r2: c_int = 725; -pub const NID_sect233k1: c_int = 726; -pub const NID_sect233r1: c_int = 727; -pub const NID_sect239k1: c_int = 728; -pub const NID_sect283k1: c_int = 729; -pub const NID_sect283r1: c_int = 730; -pub const NID_sect409k1: c_int = 731; -pub const NID_sect409r1: c_int = 732; -pub const NID_sect571k1: c_int = 733; -pub const NID_sect571r1: c_int = 734; -#[cfg(ossl110)] -pub const NID_brainpoolP256r1: c_int = 927; -#[cfg(ossl110)] -pub const NID_brainpoolP384r1: c_int = 931; -#[cfg(ossl110)] -pub const NID_brainpoolP512r1: c_int = 933; -pub const NID_wap_wsg_idm_ecid_wtls1: c_int = 735; -pub const NID_wap_wsg_idm_ecid_wtls3: c_int = 736; -pub const NID_wap_wsg_idm_ecid_wtls4: c_int = 737; -pub const NID_wap_wsg_idm_ecid_wtls5: c_int = 738; -pub const NID_wap_wsg_idm_ecid_wtls6: c_int = 739; -pub const NID_wap_wsg_idm_ecid_wtls7: c_int = 740; -pub const NID_wap_wsg_idm_ecid_wtls8: c_int = 741; -pub const NID_wap_wsg_idm_ecid_wtls9: c_int = 742; -pub const NID_wap_wsg_idm_ecid_wtls10: c_int = 743; -pub const NID_wap_wsg_idm_ecid_wtls11: c_int = 744; -pub const NID_wap_wsg_idm_ecid_wtls12: c_int = 745; -pub const NID_cast5_cbc: c_int = 108; -pub const NID_cast5_ecb: c_int = 109; -pub const NID_cast5_cfb64: c_int = 110; -pub const NID_cast5_ofb64: c_int = 111; -pub const NID_pbeWithMD5AndCast5_CBC: c_int = 112; -pub const NID_id_PasswordBasedMAC: c_int = 782; -pub const NID_id_DHBasedMac: c_int = 783; -pub const NID_rsadsi: c_int = 1; -pub const NID_pkcs: c_int = 2; -pub const NID_pkcs1: c_int = 186; -pub const NID_rsaEncryption: c_int = 6; -pub const NID_md2WithRSAEncryption: c_int = 7; -pub const NID_md4WithRSAEncryption: c_int = 396; -pub const NID_md5WithRSAEncryption: c_int = 8; -pub const NID_sha1WithRSAEncryption: c_int = 65; -pub const NID_rsaesOaep: c_int = 919; -pub const NID_mgf1: c_int = 911; -pub const NID_rsassaPss: c_int = 912; -pub const NID_sha256WithRSAEncryption: c_int = 668; -pub const NID_sha384WithRSAEncryption: c_int = 669; -pub const NID_sha512WithRSAEncryption: c_int = 670; -pub const NID_sha224WithRSAEncryption: c_int = 671; -pub const NID_pkcs3: c_int = 27; -pub const NID_dhKeyAgreement: c_int = 28; -pub const NID_pkcs5: c_int = 187; -pub const NID_pbeWithMD2AndDES_CBC: c_int = 9; -pub const NID_pbeWithMD5AndDES_CBC: c_int = 10; -pub const NID_pbeWithMD2AndRC2_CBC: c_int = 168; -pub const NID_pbeWithMD5AndRC2_CBC: c_int = 169; -pub const NID_pbeWithSHA1AndDES_CBC: c_int = 170; -pub const NID_pbeWithSHA1AndRC2_CBC: c_int = 68; -pub const NID_id_pbkdf2: c_int = 69; -pub const NID_pbes2: c_int = 161; -pub const NID_pbmac1: c_int = 162; -pub const NID_pkcs7: c_int = 20; -pub const NID_pkcs7_data: c_int = 21; -pub const NID_pkcs7_signed: c_int = 22; -pub const NID_pkcs7_enveloped: c_int = 23; -pub const NID_pkcs7_signedAndEnveloped: c_int = 24; -pub const NID_pkcs7_digest: c_int = 25; -pub const NID_pkcs7_encrypted: c_int = 26; -pub const NID_pkcs9: c_int = 47; -pub const NID_pkcs9_emailAddress: c_int = 48; -pub const NID_pkcs9_unstructuredName: c_int = 49; -pub const NID_pkcs9_contentType: c_int = 50; -pub const NID_pkcs9_messageDigest: c_int = 51; -pub const NID_pkcs9_signingTime: c_int = 52; -pub const NID_pkcs9_countersignature: c_int = 53; -pub const NID_pkcs9_challengePassword: c_int = 54; -pub const NID_pkcs9_unstructuredAddress: c_int = 55; -pub const NID_pkcs9_extCertAttributes: c_int = 56; -pub const NID_ext_req: c_int = 172; -pub const NID_SMIMECapabilities: c_int = 167; -pub const NID_SMIME: c_int = 188; -pub const NID_id_smime_mod: c_int = 189; -pub const NID_id_smime_ct: c_int = 190; -pub const NID_id_smime_aa: c_int = 191; -pub const NID_id_smime_alg: c_int = 192; -pub const NID_id_smime_cd: c_int = 193; -pub const NID_id_smime_spq: c_int = 194; -pub const NID_id_smime_cti: c_int = 195; -pub const NID_id_smime_mod_cms: c_int = 196; -pub const NID_id_smime_mod_ess: c_int = 197; -pub const NID_id_smime_mod_oid: c_int = 198; -pub const NID_id_smime_mod_msg_v3: c_int = 199; -pub const NID_id_smime_mod_ets_eSignature_88: c_int = 200; -pub const NID_id_smime_mod_ets_eSignature_97: c_int = 201; -pub const NID_id_smime_mod_ets_eSigPolicy_88: c_int = 202; -pub const NID_id_smime_mod_ets_eSigPolicy_97: c_int = 203; -pub const NID_id_smime_ct_receipt: c_int = 204; -pub const NID_id_smime_ct_authData: c_int = 205; -pub const NID_id_smime_ct_publishCert: c_int = 206; -pub const NID_id_smime_ct_TSTInfo: c_int = 207; -pub const NID_id_smime_ct_TDTInfo: c_int = 208; -pub const NID_id_smime_ct_contentInfo: c_int = 209; -pub const NID_id_smime_ct_DVCSRequestData: c_int = 210; -pub const NID_id_smime_ct_DVCSResponseData: c_int = 211; -pub const NID_id_smime_ct_compressedData: c_int = 786; -pub const NID_id_ct_asciiTextWithCRLF: c_int = 787; -pub const NID_id_smime_aa_receiptRequest: c_int = 212; -pub const NID_id_smime_aa_securityLabel: c_int = 213; -pub const NID_id_smime_aa_mlExpandHistory: c_int = 214; -pub const NID_id_smime_aa_contentHint: c_int = 215; -pub const NID_id_smime_aa_msgSigDigest: c_int = 216; -pub const NID_id_smime_aa_encapContentType: c_int = 217; -pub const NID_id_smime_aa_contentIdentifier: c_int = 218; -pub const NID_id_smime_aa_macValue: c_int = 219; -pub const NID_id_smime_aa_equivalentLabels: c_int = 220; -pub const NID_id_smime_aa_contentReference: c_int = 221; -pub const NID_id_smime_aa_encrypKeyPref: c_int = 222; -pub const NID_id_smime_aa_signingCertificate: c_int = 223; -pub const NID_id_smime_aa_smimeEncryptCerts: c_int = 224; -pub const NID_id_smime_aa_timeStampToken: c_int = 225; -pub const NID_id_smime_aa_ets_sigPolicyId: c_int = 226; -pub const NID_id_smime_aa_ets_commitmentType: c_int = 227; -pub const NID_id_smime_aa_ets_signerLocation: c_int = 228; -pub const NID_id_smime_aa_ets_signerAttr: c_int = 229; -pub const NID_id_smime_aa_ets_otherSigCert: c_int = 230; -pub const NID_id_smime_aa_ets_contentTimestamp: c_int = 231; -pub const NID_id_smime_aa_ets_CertificateRefs: c_int = 232; -pub const NID_id_smime_aa_ets_RevocationRefs: c_int = 233; -pub const NID_id_smime_aa_ets_certValues: c_int = 234; -pub const NID_id_smime_aa_ets_revocationValues: c_int = 235; -pub const NID_id_smime_aa_ets_escTimeStamp: c_int = 236; -pub const NID_id_smime_aa_ets_certCRLTimestamp: c_int = 237; -pub const NID_id_smime_aa_ets_archiveTimeStamp: c_int = 238; -pub const NID_id_smime_aa_signatureType: c_int = 239; -pub const NID_id_smime_aa_dvcs_dvc: c_int = 240; -pub const NID_id_smime_alg_ESDHwith3DES: c_int = 241; -pub const NID_id_smime_alg_ESDHwithRC2: c_int = 242; -pub const NID_id_smime_alg_3DESwrap: c_int = 243; -pub const NID_id_smime_alg_RC2wrap: c_int = 244; -pub const NID_id_smime_alg_ESDH: c_int = 245; -pub const NID_id_smime_alg_CMS3DESwrap: c_int = 246; -pub const NID_id_smime_alg_CMSRC2wrap: c_int = 247; -pub const NID_id_alg_PWRI_KEK: c_int = 893; -pub const NID_id_smime_cd_ldap: c_int = 248; -pub const NID_id_smime_spq_ets_sqt_uri: c_int = 249; -pub const NID_id_smime_spq_ets_sqt_unotice: c_int = 250; -pub const NID_id_smime_cti_ets_proofOfOrigin: c_int = 251; -pub const NID_id_smime_cti_ets_proofOfReceipt: c_int = 252; -pub const NID_id_smime_cti_ets_proofOfDelivery: c_int = 253; -pub const NID_id_smime_cti_ets_proofOfSender: c_int = 254; -pub const NID_id_smime_cti_ets_proofOfApproval: c_int = 255; -pub const NID_id_smime_cti_ets_proofOfCreation: c_int = 256; -pub const NID_friendlyName: c_int = 156; -pub const NID_localKeyID: c_int = 157; -pub const NID_ms_csp_name: c_int = 417; -pub const NID_LocalKeySet: c_int = 856; -pub const NID_x509Certificate: c_int = 158; -pub const NID_sdsiCertificate: c_int = 159; -pub const NID_x509Crl: c_int = 160; -pub const NID_pbe_WithSHA1And128BitRC4: c_int = 144; -pub const NID_pbe_WithSHA1And40BitRC4: c_int = 145; -pub const NID_pbe_WithSHA1And3_Key_TripleDES_CBC: c_int = 146; -pub const NID_pbe_WithSHA1And2_Key_TripleDES_CBC: c_int = 147; -pub const NID_pbe_WithSHA1And128BitRC2_CBC: c_int = 148; -pub const NID_pbe_WithSHA1And40BitRC2_CBC: c_int = 149; -pub const NID_keyBag: c_int = 150; -pub const NID_pkcs8ShroudedKeyBag: c_int = 151; -pub const NID_certBag: c_int = 152; -pub const NID_crlBag: c_int = 153; -pub const NID_secretBag: c_int = 154; -pub const NID_safeContentsBag: c_int = 155; -pub const NID_md2: c_int = 3; -pub const NID_md4: c_int = 257; -pub const NID_md5: c_int = 4; -pub const NID_md5_sha1: c_int = 114; -pub const NID_hmacWithMD5: c_int = 797; -pub const NID_hmacWithSHA1: c_int = 163; -pub const NID_hmacWithSHA224: c_int = 798; -pub const NID_hmacWithSHA256: c_int = 799; -pub const NID_hmacWithSHA384: c_int = 800; -pub const NID_hmacWithSHA512: c_int = 801; -pub const NID_rc2_cbc: c_int = 37; -pub const NID_rc2_ecb: c_int = 38; -pub const NID_rc2_cfb64: c_int = 39; -pub const NID_rc2_ofb64: c_int = 40; -pub const NID_rc2_40_cbc: c_int = 98; -pub const NID_rc2_64_cbc: c_int = 166; -pub const NID_rc4: c_int = 5; -pub const NID_rc4_40: c_int = 97; -pub const NID_des_ede3_cbc: c_int = 44; -pub const NID_rc5_cbc: c_int = 120; -pub const NID_rc5_ecb: c_int = 121; -pub const NID_rc5_cfb64: c_int = 122; -pub const NID_rc5_ofb64: c_int = 123; -pub const NID_ms_ext_req: c_int = 171; -pub const NID_ms_code_ind: c_int = 134; -pub const NID_ms_code_com: c_int = 135; -pub const NID_ms_ctl_sign: c_int = 136; -pub const NID_ms_sgc: c_int = 137; -pub const NID_ms_efs: c_int = 138; -pub const NID_ms_smartcard_login: c_int = 648; -pub const NID_ms_upn: c_int = 649; -pub const NID_idea_cbc: c_int = 34; -pub const NID_idea_ecb: c_int = 36; -pub const NID_idea_cfb64: c_int = 35; -pub const NID_idea_ofb64: c_int = 46; -pub const NID_bf_cbc: c_int = 91; -pub const NID_bf_ecb: c_int = 92; -pub const NID_bf_cfb64: c_int = 93; -pub const NID_bf_ofb64: c_int = 94; -pub const NID_id_pkix: c_int = 127; -pub const NID_id_pkix_mod: c_int = 258; -pub const NID_id_pe: c_int = 175; -pub const NID_id_qt: c_int = 259; -pub const NID_id_kp: c_int = 128; -pub const NID_id_it: c_int = 260; -pub const NID_id_pkip: c_int = 261; -pub const NID_id_alg: c_int = 262; -pub const NID_id_cmc: c_int = 263; -pub const NID_id_on: c_int = 264; -pub const NID_id_pda: c_int = 265; -pub const NID_id_aca: c_int = 266; -pub const NID_id_qcs: c_int = 267; -pub const NID_id_cct: c_int = 268; -pub const NID_id_ppl: c_int = 662; -pub const NID_id_ad: c_int = 176; -pub const NID_id_pkix1_explicit_88: c_int = 269; -pub const NID_id_pkix1_implicit_88: c_int = 270; -pub const NID_id_pkix1_explicit_93: c_int = 271; -pub const NID_id_pkix1_implicit_93: c_int = 272; -pub const NID_id_mod_crmf: c_int = 273; -pub const NID_id_mod_cmc: c_int = 274; -pub const NID_id_mod_kea_profile_88: c_int = 275; -pub const NID_id_mod_kea_profile_93: c_int = 276; -pub const NID_id_mod_cmp: c_int = 277; -pub const NID_id_mod_qualified_cert_88: c_int = 278; -pub const NID_id_mod_qualified_cert_93: c_int = 279; -pub const NID_id_mod_attribute_cert: c_int = 280; -pub const NID_id_mod_timestamp_protocol: c_int = 281; -pub const NID_id_mod_ocsp: c_int = 282; -pub const NID_id_mod_dvcs: c_int = 283; -pub const NID_id_mod_cmp2000: c_int = 284; -pub const NID_info_access: c_int = 177; -pub const NID_biometricInfo: c_int = 285; -pub const NID_qcStatements: c_int = 286; -pub const NID_ac_auditEntity: c_int = 287; -pub const NID_ac_targeting: c_int = 288; -pub const NID_aaControls: c_int = 289; -pub const NID_sbgp_ipAddrBlock: c_int = 290; -pub const NID_sbgp_autonomousSysNum: c_int = 291; -pub const NID_sbgp_routerIdentifier: c_int = 292; -pub const NID_ac_proxying: c_int = 397; -pub const NID_sinfo_access: c_int = 398; -pub const NID_proxyCertInfo: c_int = 663; -pub const NID_id_qt_cps: c_int = 164; -pub const NID_id_qt_unotice: c_int = 165; -pub const NID_textNotice: c_int = 293; -pub const NID_server_auth: c_int = 129; -pub const NID_client_auth: c_int = 130; -pub const NID_code_sign: c_int = 131; -pub const NID_email_protect: c_int = 132; -pub const NID_ipsecEndSystem: c_int = 294; -pub const NID_ipsecTunnel: c_int = 295; -pub const NID_ipsecUser: c_int = 296; -pub const NID_time_stamp: c_int = 133; -pub const NID_OCSP_sign: c_int = 180; -pub const NID_dvcs: c_int = 297; -pub const NID_id_it_caProtEncCert: c_int = 298; -pub const NID_id_it_signKeyPairTypes: c_int = 299; -pub const NID_id_it_encKeyPairTypes: c_int = 300; -pub const NID_id_it_preferredSymmAlg: c_int = 301; -pub const NID_id_it_caKeyUpdateInfo: c_int = 302; -pub const NID_id_it_currentCRL: c_int = 303; -pub const NID_id_it_unsupportedOIDs: c_int = 304; -pub const NID_id_it_subscriptionRequest: c_int = 305; -pub const NID_id_it_subscriptionResponse: c_int = 306; -pub const NID_id_it_keyPairParamReq: c_int = 307; -pub const NID_id_it_keyPairParamRep: c_int = 308; -pub const NID_id_it_revPassphrase: c_int = 309; -pub const NID_id_it_implicitConfirm: c_int = 310; -pub const NID_id_it_confirmWaitTime: c_int = 311; -pub const NID_id_it_origPKIMessage: c_int = 312; -pub const NID_id_it_suppLangTags: c_int = 784; -pub const NID_id_regCtrl: c_int = 313; -pub const NID_id_regInfo: c_int = 314; -pub const NID_id_regCtrl_regToken: c_int = 315; -pub const NID_id_regCtrl_authenticator: c_int = 316; -pub const NID_id_regCtrl_pkiPublicationInfo: c_int = 317; -pub const NID_id_regCtrl_pkiArchiveOptions: c_int = 318; -pub const NID_id_regCtrl_oldCertID: c_int = 319; -pub const NID_id_regCtrl_protocolEncrKey: c_int = 320; -pub const NID_id_regInfo_utf8Pairs: c_int = 321; -pub const NID_id_regInfo_certReq: c_int = 322; -pub const NID_id_alg_des40: c_int = 323; -pub const NID_id_alg_noSignature: c_int = 324; -pub const NID_id_alg_dh_sig_hmac_sha1: c_int = 325; -pub const NID_id_alg_dh_pop: c_int = 326; -pub const NID_id_cmc_statusInfo: c_int = 327; -pub const NID_id_cmc_identification: c_int = 328; -pub const NID_id_cmc_identityProof: c_int = 329; -pub const NID_id_cmc_dataReturn: c_int = 330; -pub const NID_id_cmc_transactionId: c_int = 331; -pub const NID_id_cmc_senderNonce: c_int = 332; -pub const NID_id_cmc_recipientNonce: c_int = 333; -pub const NID_id_cmc_addExtensions: c_int = 334; -pub const NID_id_cmc_encryptedPOP: c_int = 335; -pub const NID_id_cmc_decryptedPOP: c_int = 336; -pub const NID_id_cmc_lraPOPWitness: c_int = 337; -pub const NID_id_cmc_getCert: c_int = 338; -pub const NID_id_cmc_getCRL: c_int = 339; -pub const NID_id_cmc_revokeRequest: c_int = 340; -pub const NID_id_cmc_regInfo: c_int = 341; -pub const NID_id_cmc_responseInfo: c_int = 342; -pub const NID_id_cmc_queryPending: c_int = 343; -pub const NID_id_cmc_popLinkRandom: c_int = 344; -pub const NID_id_cmc_popLinkWitness: c_int = 345; -pub const NID_id_cmc_confirmCertAcceptance: c_int = 346; -pub const NID_id_on_personalData: c_int = 347; -pub const NID_id_on_permanentIdentifier: c_int = 858; -pub const NID_id_pda_dateOfBirth: c_int = 348; -pub const NID_id_pda_placeOfBirth: c_int = 349; -pub const NID_id_pda_gender: c_int = 351; -pub const NID_id_pda_countryOfCitizenship: c_int = 352; -pub const NID_id_pda_countryOfResidence: c_int = 353; -pub const NID_id_aca_authenticationInfo: c_int = 354; -pub const NID_id_aca_accessIdentity: c_int = 355; -pub const NID_id_aca_chargingIdentity: c_int = 356; -pub const NID_id_aca_group: c_int = 357; -pub const NID_id_aca_role: c_int = 358; -pub const NID_id_aca_encAttrs: c_int = 399; -pub const NID_id_qcs_pkixQCSyntax_v1: c_int = 359; -pub const NID_id_cct_crs: c_int = 360; -pub const NID_id_cct_PKIData: c_int = 361; -pub const NID_id_cct_PKIResponse: c_int = 362; -pub const NID_id_ppl_anyLanguage: c_int = 664; -pub const NID_id_ppl_inheritAll: c_int = 665; -pub const NID_Independent: c_int = 667; -pub const NID_ad_OCSP: c_int = 178; -pub const NID_ad_ca_issuers: c_int = 179; -pub const NID_ad_timeStamping: c_int = 363; -pub const NID_ad_dvcs: c_int = 364; -pub const NID_caRepository: c_int = 785; -pub const NID_id_pkix_OCSP_basic: c_int = 365; -pub const NID_id_pkix_OCSP_Nonce: c_int = 366; -pub const NID_id_pkix_OCSP_CrlID: c_int = 367; -pub const NID_id_pkix_OCSP_acceptableResponses: c_int = 368; -pub const NID_id_pkix_OCSP_noCheck: c_int = 369; -pub const NID_id_pkix_OCSP_archiveCutoff: c_int = 370; -pub const NID_id_pkix_OCSP_serviceLocator: c_int = 371; -pub const NID_id_pkix_OCSP_extendedStatus: c_int = 372; -pub const NID_id_pkix_OCSP_valid: c_int = 373; -pub const NID_id_pkix_OCSP_path: c_int = 374; -pub const NID_id_pkix_OCSP_trustRoot: c_int = 375; -pub const NID_algorithm: c_int = 376; -pub const NID_md5WithRSA: c_int = 104; -pub const NID_des_ecb: c_int = 29; -pub const NID_des_cbc: c_int = 31; -pub const NID_des_ofb64: c_int = 45; -pub const NID_des_cfb64: c_int = 30; -pub const NID_rsaSignature: c_int = 377; -pub const NID_dsa_2: c_int = 67; -pub const NID_dsaWithSHA: c_int = 66; -pub const NID_shaWithRSAEncryption: c_int = 42; -pub const NID_des_ede_ecb: c_int = 32; -pub const NID_des_ede3_ecb: c_int = 33; -pub const NID_des_ede_cbc: c_int = 43; -pub const NID_des_ede_cfb64: c_int = 60; -pub const NID_des_ede3_cfb64: c_int = 61; -pub const NID_des_ede_ofb64: c_int = 62; -pub const NID_des_ede3_ofb64: c_int = 63; -pub const NID_desx_cbc: c_int = 80; -pub const NID_sha: c_int = 41; -pub const NID_sha1: c_int = 64; -pub const NID_dsaWithSHA1_2: c_int = 70; -pub const NID_sha1WithRSA: c_int = 115; -pub const NID_ripemd160: c_int = 117; -pub const NID_ripemd160WithRSA: c_int = 119; -pub const NID_sxnet: c_int = 143; -pub const NID_X500: c_int = 11; -pub const NID_X509: c_int = 12; -pub const NID_commonName: c_int = 13; -pub const NID_surname: c_int = 100; -pub const NID_serialNumber: c_int = 105; -pub const NID_countryName: c_int = 14; -pub const NID_localityName: c_int = 15; -pub const NID_stateOrProvinceName: c_int = 16; -pub const NID_streetAddress: c_int = 660; -pub const NID_organizationName: c_int = 17; -pub const NID_organizationalUnitName: c_int = 18; -pub const NID_title: c_int = 106; -pub const NID_description: c_int = 107; -pub const NID_searchGuide: c_int = 859; -pub const NID_businessCategory: c_int = 860; -pub const NID_postalAddress: c_int = 861; -pub const NID_postalCode: c_int = 661; -pub const NID_postOfficeBox: c_int = 862; -pub const NID_physicalDeliveryOfficeName: c_int = 863; -pub const NID_telephoneNumber: c_int = 864; -pub const NID_telexNumber: c_int = 865; -pub const NID_teletexTerminalIdentifier: c_int = 866; -pub const NID_facsimileTelephoneNumber: c_int = 867; -pub const NID_x121Address: c_int = 868; -pub const NID_internationaliSDNNumber: c_int = 869; -pub const NID_registeredAddress: c_int = 870; -pub const NID_destinationIndicator: c_int = 871; -pub const NID_preferredDeliveryMethod: c_int = 872; -pub const NID_presentationAddress: c_int = 873; -pub const NID_supportedApplicationContext: c_int = 874; -pub const NID_member: c_int = 875; -pub const NID_owner: c_int = 876; -pub const NID_roleOccupant: c_int = 877; -pub const NID_seeAlso: c_int = 878; -pub const NID_userPassword: c_int = 879; -pub const NID_userCertificate: c_int = 880; -pub const NID_cACertificate: c_int = 881; -pub const NID_authorityRevocationList: c_int = 882; -pub const NID_certificateRevocationList: c_int = 883; -pub const NID_crossCertificatePair: c_int = 884; -pub const NID_name: c_int = 173; -pub const NID_givenName: c_int = 99; -pub const NID_initials: c_int = 101; -pub const NID_generationQualifier: c_int = 509; -pub const NID_x500UniqueIdentifier: c_int = 503; -pub const NID_dnQualifier: c_int = 174; -pub const NID_enhancedSearchGuide: c_int = 885; -pub const NID_protocolInformation: c_int = 886; -pub const NID_distinguishedName: c_int = 887; -pub const NID_uniqueMember: c_int = 888; -pub const NID_houseIdentifier: c_int = 889; -pub const NID_supportedAlgorithms: c_int = 890; -pub const NID_deltaRevocationList: c_int = 891; -pub const NID_dmdName: c_int = 892; -pub const NID_pseudonym: c_int = 510; -pub const NID_role: c_int = 400; -pub const NID_X500algorithms: c_int = 378; -pub const NID_rsa: c_int = 19; -pub const NID_mdc2WithRSA: c_int = 96; -pub const NID_mdc2: c_int = 95; -pub const NID_id_ce: c_int = 81; -pub const NID_subject_directory_attributes: c_int = 769; -pub const NID_subject_key_identifier: c_int = 82; -pub const NID_key_usage: c_int = 83; -pub const NID_private_key_usage_period: c_int = 84; -pub const NID_subject_alt_name: c_int = 85; -pub const NID_issuer_alt_name: c_int = 86; -pub const NID_basic_constraints: c_int = 87; -pub const NID_crl_number: c_int = 88; -pub const NID_crl_reason: c_int = 141; -pub const NID_invalidity_date: c_int = 142; -pub const NID_delta_crl: c_int = 140; -pub const NID_issuing_distribution_point: c_int = 770; -pub const NID_certificate_issuer: c_int = 771; -pub const NID_name_constraints: c_int = 666; -pub const NID_crl_distribution_points: c_int = 103; -pub const NID_certificate_policies: c_int = 89; -pub const NID_any_policy: c_int = 746; -pub const NID_policy_mappings: c_int = 747; -pub const NID_authority_key_identifier: c_int = 90; -pub const NID_policy_constraints: c_int = 401; -pub const NID_ext_key_usage: c_int = 126; -pub const NID_freshest_crl: c_int = 857; -pub const NID_inhibit_any_policy: c_int = 748; -pub const NID_target_information: c_int = 402; -pub const NID_no_rev_avail: c_int = 403; -pub const NID_anyExtendedKeyUsage: c_int = 910; -pub const NID_netscape: c_int = 57; -pub const NID_netscape_cert_extension: c_int = 58; -pub const NID_netscape_data_type: c_int = 59; -pub const NID_netscape_cert_type: c_int = 71; -pub const NID_netscape_base_url: c_int = 72; -pub const NID_netscape_revocation_url: c_int = 73; -pub const NID_netscape_ca_revocation_url: c_int = 74; -pub const NID_netscape_renewal_url: c_int = 75; -pub const NID_netscape_ca_policy_url: c_int = 76; -pub const NID_netscape_ssl_server_name: c_int = 77; -pub const NID_netscape_comment: c_int = 78; -pub const NID_netscape_cert_sequence: c_int = 79; -pub const NID_ns_sgc: c_int = 139; -pub const NID_org: c_int = 379; -pub const NID_dod: c_int = 380; -pub const NID_iana: c_int = 381; -pub const NID_Directory: c_int = 382; -pub const NID_Management: c_int = 383; -pub const NID_Experimental: c_int = 384; -pub const NID_Private: c_int = 385; -pub const NID_Security: c_int = 386; -pub const NID_SNMPv2: c_int = 387; -pub const NID_Mail: c_int = 388; -pub const NID_Enterprises: c_int = 389; -pub const NID_dcObject: c_int = 390; -pub const NID_mime_mhs: c_int = 504; -pub const NID_mime_mhs_headings: c_int = 505; -pub const NID_mime_mhs_bodies: c_int = 506; -pub const NID_id_hex_partial_message: c_int = 507; -pub const NID_id_hex_multipart_message: c_int = 508; -pub const NID_zlib_compression: c_int = 125; -pub const NID_aes_128_ecb: c_int = 418; -pub const NID_aes_128_cbc: c_int = 419; -pub const NID_aes_128_ofb128: c_int = 420; -pub const NID_aes_128_cfb128: c_int = 421; -pub const NID_id_aes128_wrap: c_int = 788; -pub const NID_aes_128_gcm: c_int = 895; -pub const NID_aes_128_ccm: c_int = 896; -pub const NID_id_aes128_wrap_pad: c_int = 897; -pub const NID_aes_192_ecb: c_int = 422; -pub const NID_aes_192_cbc: c_int = 423; -pub const NID_aes_192_ofb128: c_int = 424; -pub const NID_aes_192_cfb128: c_int = 425; -pub const NID_id_aes192_wrap: c_int = 789; -pub const NID_aes_192_gcm: c_int = 898; -pub const NID_aes_192_ccm: c_int = 899; -pub const NID_id_aes192_wrap_pad: c_int = 900; -pub const NID_aes_256_ecb: c_int = 426; -pub const NID_aes_256_cbc: c_int = 427; -pub const NID_aes_256_ofb128: c_int = 428; -pub const NID_aes_256_cfb128: c_int = 429; -pub const NID_id_aes256_wrap: c_int = 790; -pub const NID_aes_256_gcm: c_int = 901; -pub const NID_aes_256_ccm: c_int = 902; -pub const NID_id_aes256_wrap_pad: c_int = 903; -pub const NID_aes_128_cfb1: c_int = 650; -pub const NID_aes_192_cfb1: c_int = 651; -pub const NID_aes_256_cfb1: c_int = 652; -pub const NID_aes_128_cfb8: c_int = 653; -pub const NID_aes_192_cfb8: c_int = 654; -pub const NID_aes_256_cfb8: c_int = 655; -pub const NID_aes_128_ctr: c_int = 904; -pub const NID_aes_192_ctr: c_int = 905; -pub const NID_aes_256_ctr: c_int = 906; -pub const NID_aes_128_xts: c_int = 913; -pub const NID_aes_256_xts: c_int = 914; -pub const NID_des_cfb1: c_int = 656; -pub const NID_des_cfb8: c_int = 657; -pub const NID_des_ede3_cfb1: c_int = 658; -pub const NID_des_ede3_cfb8: c_int = 659; -pub const NID_sha256: c_int = 672; -pub const NID_sha384: c_int = 673; -pub const NID_sha512: c_int = 674; -pub const NID_sha224: c_int = 675; -pub const NID_dsa_with_SHA224: c_int = 802; -pub const NID_dsa_with_SHA256: c_int = 803; -pub const NID_hold_instruction_code: c_int = 430; -pub const NID_hold_instruction_none: c_int = 431; -pub const NID_hold_instruction_call_issuer: c_int = 432; -pub const NID_hold_instruction_reject: c_int = 433; -pub const NID_data: c_int = 434; -pub const NID_pss: c_int = 435; -pub const NID_ucl: c_int = 436; -pub const NID_pilot: c_int = 437; -pub const NID_pilotAttributeType: c_int = 438; -pub const NID_pilotAttributeSyntax: c_int = 439; -pub const NID_pilotObjectClass: c_int = 440; -pub const NID_pilotGroups: c_int = 441; -pub const NID_iA5StringSyntax: c_int = 442; -pub const NID_caseIgnoreIA5StringSyntax: c_int = 443; -pub const NID_pilotObject: c_int = 444; -pub const NID_pilotPerson: c_int = 445; -pub const NID_account: c_int = 446; -pub const NID_document: c_int = 447; -pub const NID_room: c_int = 448; -pub const NID_documentSeries: c_int = 449; -pub const NID_Domain: c_int = 392; -pub const NID_rFC822localPart: c_int = 450; -pub const NID_dNSDomain: c_int = 451; -pub const NID_domainRelatedObject: c_int = 452; -pub const NID_friendlyCountry: c_int = 453; -pub const NID_simpleSecurityObject: c_int = 454; -pub const NID_pilotOrganization: c_int = 455; -pub const NID_pilotDSA: c_int = 456; -pub const NID_qualityLabelledData: c_int = 457; -pub const NID_userId: c_int = 458; -pub const NID_textEncodedORAddress: c_int = 459; -pub const NID_rfc822Mailbox: c_int = 460; -pub const NID_info: c_int = 461; -pub const NID_favouriteDrink: c_int = 462; -pub const NID_roomNumber: c_int = 463; -pub const NID_photo: c_int = 464; -pub const NID_userClass: c_int = 465; -pub const NID_host: c_int = 466; -pub const NID_manager: c_int = 467; -pub const NID_documentIdentifier: c_int = 468; -pub const NID_documentTitle: c_int = 469; -pub const NID_documentVersion: c_int = 470; -pub const NID_documentAuthor: c_int = 471; -pub const NID_documentLocation: c_int = 472; -pub const NID_homeTelephoneNumber: c_int = 473; -pub const NID_secretary: c_int = 474; -pub const NID_otherMailbox: c_int = 475; -pub const NID_lastModifiedTime: c_int = 476; -pub const NID_lastModifiedBy: c_int = 477; -pub const NID_domainComponent: c_int = 391; -pub const NID_aRecord: c_int = 478; -pub const NID_pilotAttributeType27: c_int = 479; -pub const NID_mXRecord: c_int = 480; -pub const NID_nSRecord: c_int = 481; -pub const NID_sOARecord: c_int = 482; -pub const NID_cNAMERecord: c_int = 483; -pub const NID_associatedDomain: c_int = 484; -pub const NID_associatedName: c_int = 485; -pub const NID_homePostalAddress: c_int = 486; -pub const NID_personalTitle: c_int = 487; -pub const NID_mobileTelephoneNumber: c_int = 488; -pub const NID_pagerTelephoneNumber: c_int = 489; -pub const NID_friendlyCountryName: c_int = 490; -pub const NID_organizationalStatus: c_int = 491; -pub const NID_janetMailbox: c_int = 492; -pub const NID_mailPreferenceOption: c_int = 493; -pub const NID_buildingName: c_int = 494; -pub const NID_dSAQuality: c_int = 495; -pub const NID_singleLevelQuality: c_int = 496; -pub const NID_subtreeMinimumQuality: c_int = 497; -pub const NID_subtreeMaximumQuality: c_int = 498; -pub const NID_personalSignature: c_int = 499; -pub const NID_dITRedirect: c_int = 500; -pub const NID_audio: c_int = 501; -pub const NID_documentPublisher: c_int = 502; -pub const NID_id_set: c_int = 512; -pub const NID_set_ctype: c_int = 513; -pub const NID_set_msgExt: c_int = 514; -pub const NID_set_attr: c_int = 515; -pub const NID_set_policy: c_int = 516; -pub const NID_set_certExt: c_int = 517; -pub const NID_set_brand: c_int = 518; -pub const NID_setct_PANData: c_int = 519; -pub const NID_setct_PANToken: c_int = 520; -pub const NID_setct_PANOnly: c_int = 521; -pub const NID_setct_OIData: c_int = 522; -pub const NID_setct_PI: c_int = 523; -pub const NID_setct_PIData: c_int = 524; -pub const NID_setct_PIDataUnsigned: c_int = 525; -pub const NID_setct_HODInput: c_int = 526; -pub const NID_setct_AuthResBaggage: c_int = 527; -pub const NID_setct_AuthRevReqBaggage: c_int = 528; -pub const NID_setct_AuthRevResBaggage: c_int = 529; -pub const NID_setct_CapTokenSeq: c_int = 530; -pub const NID_setct_PInitResData: c_int = 531; -pub const NID_setct_PI_TBS: c_int = 532; -pub const NID_setct_PResData: c_int = 533; -pub const NID_setct_AuthReqTBS: c_int = 534; -pub const NID_setct_AuthResTBS: c_int = 535; -pub const NID_setct_AuthResTBSX: c_int = 536; -pub const NID_setct_AuthTokenTBS: c_int = 537; -pub const NID_setct_CapTokenData: c_int = 538; -pub const NID_setct_CapTokenTBS: c_int = 539; -pub const NID_setct_AcqCardCodeMsg: c_int = 540; -pub const NID_setct_AuthRevReqTBS: c_int = 541; -pub const NID_setct_AuthRevResData: c_int = 542; -pub const NID_setct_AuthRevResTBS: c_int = 543; -pub const NID_setct_CapReqTBS: c_int = 544; -pub const NID_setct_CapReqTBSX: c_int = 545; -pub const NID_setct_CapResData: c_int = 546; -pub const NID_setct_CapRevReqTBS: c_int = 547; -pub const NID_setct_CapRevReqTBSX: c_int = 548; -pub const NID_setct_CapRevResData: c_int = 549; -pub const NID_setct_CredReqTBS: c_int = 550; -pub const NID_setct_CredReqTBSX: c_int = 551; -pub const NID_setct_CredResData: c_int = 552; -pub const NID_setct_CredRevReqTBS: c_int = 553; -pub const NID_setct_CredRevReqTBSX: c_int = 554; -pub const NID_setct_CredRevResData: c_int = 555; -pub const NID_setct_PCertReqData: c_int = 556; -pub const NID_setct_PCertResTBS: c_int = 557; -pub const NID_setct_BatchAdminReqData: c_int = 558; -pub const NID_setct_BatchAdminResData: c_int = 559; -pub const NID_setct_CardCInitResTBS: c_int = 560; -pub const NID_setct_MeAqCInitResTBS: c_int = 561; -pub const NID_setct_RegFormResTBS: c_int = 562; -pub const NID_setct_CertReqData: c_int = 563; -pub const NID_setct_CertReqTBS: c_int = 564; -pub const NID_setct_CertResData: c_int = 565; -pub const NID_setct_CertInqReqTBS: c_int = 566; -pub const NID_setct_ErrorTBS: c_int = 567; -pub const NID_setct_PIDualSignedTBE: c_int = 568; -pub const NID_setct_PIUnsignedTBE: c_int = 569; -pub const NID_setct_AuthReqTBE: c_int = 570; -pub const NID_setct_AuthResTBE: c_int = 571; -pub const NID_setct_AuthResTBEX: c_int = 572; -pub const NID_setct_AuthTokenTBE: c_int = 573; -pub const NID_setct_CapTokenTBE: c_int = 574; -pub const NID_setct_CapTokenTBEX: c_int = 575; -pub const NID_setct_AcqCardCodeMsgTBE: c_int = 576; -pub const NID_setct_AuthRevReqTBE: c_int = 577; -pub const NID_setct_AuthRevResTBE: c_int = 578; -pub const NID_setct_AuthRevResTBEB: c_int = 579; -pub const NID_setct_CapReqTBE: c_int = 580; -pub const NID_setct_CapReqTBEX: c_int = 581; -pub const NID_setct_CapResTBE: c_int = 582; -pub const NID_setct_CapRevReqTBE: c_int = 583; -pub const NID_setct_CapRevReqTBEX: c_int = 584; -pub const NID_setct_CapRevResTBE: c_int = 585; -pub const NID_setct_CredReqTBE: c_int = 586; -pub const NID_setct_CredReqTBEX: c_int = 587; -pub const NID_setct_CredResTBE: c_int = 588; -pub const NID_setct_CredRevReqTBE: c_int = 589; -pub const NID_setct_CredRevReqTBEX: c_int = 590; -pub const NID_setct_CredRevResTBE: c_int = 591; -pub const NID_setct_BatchAdminReqTBE: c_int = 592; -pub const NID_setct_BatchAdminResTBE: c_int = 593; -pub const NID_setct_RegFormReqTBE: c_int = 594; -pub const NID_setct_CertReqTBE: c_int = 595; -pub const NID_setct_CertReqTBEX: c_int = 596; -pub const NID_setct_CertResTBE: c_int = 597; -pub const NID_setct_CRLNotificationTBS: c_int = 598; -pub const NID_setct_CRLNotificationResTBS: c_int = 599; -pub const NID_setct_BCIDistributionTBS: c_int = 600; -pub const NID_setext_genCrypt: c_int = 601; -pub const NID_setext_miAuth: c_int = 602; -pub const NID_setext_pinSecure: c_int = 603; -pub const NID_setext_pinAny: c_int = 604; -pub const NID_setext_track2: c_int = 605; -pub const NID_setext_cv: c_int = 606; -pub const NID_set_policy_root: c_int = 607; -pub const NID_setCext_hashedRoot: c_int = 608; -pub const NID_setCext_certType: c_int = 609; -pub const NID_setCext_merchData: c_int = 610; -pub const NID_setCext_cCertRequired: c_int = 611; -pub const NID_setCext_tunneling: c_int = 612; -pub const NID_setCext_setExt: c_int = 613; -pub const NID_setCext_setQualf: c_int = 614; -pub const NID_setCext_PGWYcapabilities: c_int = 615; -pub const NID_setCext_TokenIdentifier: c_int = 616; -pub const NID_setCext_Track2Data: c_int = 617; -pub const NID_setCext_TokenType: c_int = 618; -pub const NID_setCext_IssuerCapabilities: c_int = 619; -pub const NID_setAttr_Cert: c_int = 620; -pub const NID_setAttr_PGWYcap: c_int = 621; -pub const NID_setAttr_TokenType: c_int = 622; -pub const NID_setAttr_IssCap: c_int = 623; -pub const NID_set_rootKeyThumb: c_int = 624; -pub const NID_set_addPolicy: c_int = 625; -pub const NID_setAttr_Token_EMV: c_int = 626; -pub const NID_setAttr_Token_B0Prime: c_int = 627; -pub const NID_setAttr_IssCap_CVM: c_int = 628; -pub const NID_setAttr_IssCap_T2: c_int = 629; -pub const NID_setAttr_IssCap_Sig: c_int = 630; -pub const NID_setAttr_GenCryptgrm: c_int = 631; -pub const NID_setAttr_T2Enc: c_int = 632; -pub const NID_setAttr_T2cleartxt: c_int = 633; -pub const NID_setAttr_TokICCsig: c_int = 634; -pub const NID_setAttr_SecDevSig: c_int = 635; -pub const NID_set_brand_IATA_ATA: c_int = 636; -pub const NID_set_brand_Diners: c_int = 637; -pub const NID_set_brand_AmericanExpress: c_int = 638; -pub const NID_set_brand_JCB: c_int = 639; -pub const NID_set_brand_Visa: c_int = 640; -pub const NID_set_brand_MasterCard: c_int = 641; -pub const NID_set_brand_Novus: c_int = 642; -pub const NID_des_cdmf: c_int = 643; -pub const NID_rsaOAEPEncryptionSET: c_int = 644; -pub const NID_ipsec3: c_int = 749; -pub const NID_ipsec4: c_int = 750; -pub const NID_whirlpool: c_int = 804; -pub const NID_cryptopro: c_int = 805; -pub const NID_cryptocom: c_int = 806; -pub const NID_id_GostR3411_94_with_GostR3410_2001: c_int = 807; -pub const NID_id_GostR3411_94_with_GostR3410_94: c_int = 808; -pub const NID_id_GostR3411_94: c_int = 809; -pub const NID_id_HMACGostR3411_94: c_int = 810; -pub const NID_id_GostR3410_2001: c_int = 811; -pub const NID_id_GostR3410_94: c_int = 812; -pub const NID_id_Gost28147_89: c_int = 813; -pub const NID_gost89_cnt: c_int = 814; -pub const NID_id_Gost28147_89_MAC: c_int = 815; -pub const NID_id_GostR3411_94_prf: c_int = 816; -pub const NID_id_GostR3410_2001DH: c_int = 817; -pub const NID_id_GostR3410_94DH: c_int = 818; -pub const NID_id_Gost28147_89_CryptoPro_KeyMeshing: c_int = 819; -pub const NID_id_Gost28147_89_None_KeyMeshing: c_int = 820; -pub const NID_id_GostR3411_94_TestParamSet: c_int = 821; -pub const NID_id_GostR3411_94_CryptoProParamSet: c_int = 822; -pub const NID_id_Gost28147_89_TestParamSet: c_int = 823; -pub const NID_id_Gost28147_89_CryptoPro_A_ParamSet: c_int = 824; -pub const NID_id_Gost28147_89_CryptoPro_B_ParamSet: c_int = 825; -pub const NID_id_Gost28147_89_CryptoPro_C_ParamSet: c_int = 826; -pub const NID_id_Gost28147_89_CryptoPro_D_ParamSet: c_int = 827; -pub const NID_id_Gost28147_89_CryptoPro_Oscar_1_1_ParamSet: c_int = 828; -pub const NID_id_Gost28147_89_CryptoPro_Oscar_1_0_ParamSet: c_int = 829; -pub const NID_id_Gost28147_89_CryptoPro_RIC_1_ParamSet: c_int = 830; -pub const NID_id_GostR3410_94_TestParamSet: c_int = 831; -pub const NID_id_GostR3410_94_CryptoPro_A_ParamSet: c_int = 832; -pub const NID_id_GostR3410_94_CryptoPro_B_ParamSet: c_int = 833; -pub const NID_id_GostR3410_94_CryptoPro_C_ParamSet: c_int = 834; -pub const NID_id_GostR3410_94_CryptoPro_D_ParamSet: c_int = 835; -pub const NID_id_GostR3410_94_CryptoPro_XchA_ParamSet: c_int = 836; -pub const NID_id_GostR3410_94_CryptoPro_XchB_ParamSet: c_int = 837; -pub const NID_id_GostR3410_94_CryptoPro_XchC_ParamSet: c_int = 838; -pub const NID_id_GostR3410_2001_TestParamSet: c_int = 839; -pub const NID_id_GostR3410_2001_CryptoPro_A_ParamSet: c_int = 840; -pub const NID_id_GostR3410_2001_CryptoPro_B_ParamSet: c_int = 841; -pub const NID_id_GostR3410_2001_CryptoPro_C_ParamSet: c_int = 842; -pub const NID_id_GostR3410_2001_CryptoPro_XchA_ParamSet: c_int = 843; -pub const NID_id_GostR3410_2001_CryptoPro_XchB_ParamSet: c_int = 844; -pub const NID_id_GostR3410_94_a: c_int = 845; -pub const NID_id_GostR3410_94_aBis: c_int = 846; -pub const NID_id_GostR3410_94_b: c_int = 847; -pub const NID_id_GostR3410_94_bBis: c_int = 848; -pub const NID_id_Gost28147_89_cc: c_int = 849; -pub const NID_id_GostR3410_94_cc: c_int = 850; -pub const NID_id_GostR3410_2001_cc: c_int = 851; -pub const NID_id_GostR3411_94_with_GostR3410_94_cc: c_int = 852; -pub const NID_id_GostR3411_94_with_GostR3410_2001_cc: c_int = 853; -pub const NID_id_GostR3410_2001_ParamSet_cc: c_int = 854; -pub const NID_camellia_128_cbc: c_int = 751; -pub const NID_camellia_192_cbc: c_int = 752; -pub const NID_camellia_256_cbc: c_int = 753; -pub const NID_id_camellia128_wrap: c_int = 907; -pub const NID_id_camellia192_wrap: c_int = 908; -pub const NID_id_camellia256_wrap: c_int = 909; -pub const NID_camellia_128_ecb: c_int = 754; -pub const NID_camellia_128_ofb128: c_int = 766; -pub const NID_camellia_128_cfb128: c_int = 757; -pub const NID_camellia_192_ecb: c_int = 755; -pub const NID_camellia_192_ofb128: c_int = 767; -pub const NID_camellia_192_cfb128: c_int = 758; -pub const NID_camellia_256_ecb: c_int = 756; -pub const NID_camellia_256_ofb128: c_int = 768; -pub const NID_camellia_256_cfb128: c_int = 759; -pub const NID_camellia_128_cfb1: c_int = 760; -pub const NID_camellia_192_cfb1: c_int = 761; -pub const NID_camellia_256_cfb1: c_int = 762; -pub const NID_camellia_128_cfb8: c_int = 763; -pub const NID_camellia_192_cfb8: c_int = 764; -pub const NID_camellia_256_cfb8: c_int = 765; -pub const NID_kisa: c_int = 773; -pub const NID_seed_ecb: c_int = 776; -pub const NID_seed_cbc: c_int = 777; -pub const NID_seed_cfb128: c_int = 779; -pub const NID_seed_ofb128: c_int = 778; -pub const NID_hmac: c_int = 855; -pub const NID_cmac: c_int = 894; -pub const NID_rc4_hmac_md5: c_int = 915; -pub const NID_aes_128_cbc_hmac_sha1: c_int = 916; -pub const NID_aes_192_cbc_hmac_sha1: c_int = 917; -pub const NID_aes_256_cbc_hmac_sha1: c_int = 918; -#[cfg(ossl111)] -pub const NID_X25519: c_int = 1034; -#[cfg(ossl111)] -pub const NID_X448: c_int = 1035; -#[cfg(ossl110)] -pub const NID_hkdf: c_int = 1036; -#[cfg(ossl111)] -pub const NID_ED25519: c_int = 1087; -#[cfg(ossl111)] -pub const NID_ED448: c_int = 1088; -#[cfg(ossl111)] -pub const NID_sm3: c_int = 1143; -#[cfg(libressl291)] -pub const NID_sm3: c_int = 968; -#[cfg(ossl111)] -pub const NID_sm3WithRSAEncryption: c_int = 1144; -#[cfg(libressl291)] -pub const NID_sm3WithRSAEncryption: c_int = 969; -#[cfg(ossl111)] -pub const NID_sm4_ecb: c_int = 1133; -#[cfg(libressl291)] -pub const NID_sm4_ecb: c_int = 973; -#[cfg(ossl111)] -pub const NID_sm4_cbc: c_int = 1134; -#[cfg(libressl291)] -pub const NID_sm4_cbc: c_int = 974; -#[cfg(ossl111)] -pub const NID_sm4_ofb128: c_int = 1135; -#[cfg(libressl291)] -pub const NID_sm4_ofb128: c_int = 975; -#[cfg(ossl111)] -pub const NID_sm4_cfb128: c_int = 1137; -#[cfg(libressl291)] -pub const NID_sm4_cfb128: c_int = 976; -#[cfg(ossl111)] -pub const NID_sm4_cfb1: c_int = 1136; -#[cfg(libressl291)] -pub const NID_sm4_cfb1: c_int = 977; -#[cfg(ossl111)] -pub const NID_sm4_cfb8: c_int = 1138; -#[cfg(libressl291)] -pub const NID_sm4_cfb8: c_int = 978; -#[cfg(ossl111)] -pub const NID_sm4_ctr: c_int = 1139; -#[cfg(libressl291)] -pub const NID_sm4_ctr: c_int = 979; -#[cfg(ossl111)] -pub const NID_sha3_224: c_int = 1096; -#[cfg(ossl111)] -pub const NID_sha3_256: c_int = 1097; -#[cfg(ossl111)] -pub const NID_sha3_384: c_int = 1098; -#[cfg(ossl111)] -pub const NID_sha3_512: c_int = 1099; -#[cfg(ossl111)] -pub const NID_shake128: c_int = 1100; -#[cfg(ossl111)] -pub const NID_shake256: c_int = 1101; diff --git a/openssl-sys/src/ocsp.rs b/openssl-sys/src/ocsp.rs deleted file mode 100644 index fc0db39..0000000 --- a/openssl-sys/src/ocsp.rs +++ /dev/null @@ -1,35 +0,0 @@ -use libc::*; - -pub const OCSP_REVOKED_STATUS_NOSTATUS: c_int = -1; -pub const OCSP_REVOKED_STATUS_UNSPECIFIED: c_int = 0; -pub const OCSP_REVOKED_STATUS_KEYCOMPROMISE: c_int = 1; -pub const OCSP_REVOKED_STATUS_CACOMPROMISE: c_int = 2; -pub const OCSP_REVOKED_STATUS_AFFILIATIONCHANGED: c_int = 3; -pub const OCSP_REVOKED_STATUS_SUPERSEDED: c_int = 4; -pub const OCSP_REVOKED_STATUS_CESSATIONOFOPERATION: c_int = 5; -pub const OCSP_REVOKED_STATUS_CERTIFICATEHOLD: c_int = 6; -pub const OCSP_REVOKED_STATUS_REMOVEFROMCRL: c_int = 8; - -pub const OCSP_NOCERTS: c_ulong = 0x1; -pub const OCSP_NOINTERN: c_ulong = 0x2; -pub const OCSP_NOSIGS: c_ulong = 0x4; -pub const OCSP_NOCHAIN: c_ulong = 0x8; -pub const OCSP_NOVERIFY: c_ulong = 0x10; -pub const OCSP_NOEXPLICIT: c_ulong = 0x20; -pub const OCSP_NOCASIGN: c_ulong = 0x40; -pub const OCSP_NODELEGATED: c_ulong = 0x80; -pub const OCSP_NOCHECKS: c_ulong = 0x100; -pub const OCSP_TRUSTOTHER: c_ulong = 0x200; -pub const OCSP_RESPID_KEY: c_ulong = 0x400; -pub const OCSP_NOTIME: c_ulong = 0x800; - -pub const OCSP_RESPONSE_STATUS_SUCCESSFUL: c_int = 0; -pub const OCSP_RESPONSE_STATUS_MALFORMEDREQUEST: c_int = 1; -pub const OCSP_RESPONSE_STATUS_INTERNALERROR: c_int = 2; -pub const OCSP_RESPONSE_STATUS_TRYLATER: c_int = 3; -pub const OCSP_RESPONSE_STATUS_SIGREQUIRED: c_int = 5; -pub const OCSP_RESPONSE_STATUS_UNAUTHORIZED: c_int = 6; - -pub const V_OCSP_CERTSTATUS_GOOD: c_int = 0; -pub const V_OCSP_CERTSTATUS_REVOKED: c_int = 1; -pub const V_OCSP_CERTSTATUS_UNKNOWN: c_int = 2; diff --git a/openssl-sys/src/pem.rs b/openssl-sys/src/pem.rs deleted file mode 100644 index f7dd8ac..0000000 --- a/openssl-sys/src/pem.rs +++ /dev/null @@ -1,3 +0,0 @@ -use libc::*; - -pub const PEM_R_NO_START_LINE: c_int = 108; diff --git a/openssl-sys/src/pkcs7.rs b/openssl-sys/src/pkcs7.rs deleted file mode 100644 index 0a56225..0000000 --- a/openssl-sys/src/pkcs7.rs +++ /dev/null @@ -1,20 +0,0 @@ -use libc::*; - -pub const PKCS7_TEXT: c_int = 0x1; -pub const PKCS7_NOCERTS: c_int = 0x2; -pub const PKCS7_NOSIGS: c_int = 0x4; -pub const PKCS7_NOCHAIN: c_int = 0x8; -pub const PKCS7_NOINTERN: c_int = 0x10; -pub const PKCS7_NOVERIFY: c_int = 0x20; -pub const PKCS7_DETACHED: c_int = 0x40; -pub const PKCS7_BINARY: c_int = 0x80; -pub const PKCS7_NOATTR: c_int = 0x100; -pub const PKCS7_NOSMIMECAP: c_int = 0x200; -pub const PKCS7_NOOLDMIMETYPE: c_int = 0x400; -pub const PKCS7_CRLFEOL: c_int = 0x800; -pub const PKCS7_STREAM: c_int = 0x1000; -pub const PKCS7_NOCRL: c_int = 0x2000; -pub const PKCS7_PARTIAL: c_int = 0x4000; -pub const PKCS7_REUSE_DIGEST: c_int = 0x8000; -#[cfg(not(any(ossl101, ossl102, libressl)))] -pub const PKCS7_NO_DUAL_CONTENT: c_int = 0x10000; diff --git a/openssl-sys/src/rsa.rs b/openssl-sys/src/rsa.rs deleted file mode 100644 index 19b0543..0000000 --- a/openssl-sys/src/rsa.rs +++ /dev/null @@ -1,90 +0,0 @@ -use libc::*; -use std::ptr; - -use super::super::*; - -pub const RSA_F4: c_long = 0x10001; - -cfg_if! { - if #[cfg(not(ossl300))] { - pub unsafe fn EVP_PKEY_CTX_set_rsa_padding(ctx: *mut EVP_PKEY_CTX, pad: c_int) -> c_int { - EVP_PKEY_CTX_ctrl( - ctx, - EVP_PKEY_RSA, - -1, - EVP_PKEY_CTRL_RSA_PADDING, - pad, - ptr::null_mut(), - ) - } - pub unsafe fn EVP_PKEY_CTX_get_rsa_padding(ctx: *mut EVP_PKEY_CTX, ppad: *mut c_int) -> c_int { - EVP_PKEY_CTX_ctrl( - ctx, - EVP_PKEY_RSA, - -1, - EVP_PKEY_CTRL_GET_RSA_PADDING, - 0, - ppad as *mut c_void, - ) - } - - pub unsafe fn EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx: *mut EVP_PKEY_CTX, len: c_int) -> c_int { - EVP_PKEY_CTX_ctrl( - ctx, - EVP_PKEY_RSA, - EVP_PKEY_OP_SIGN | EVP_PKEY_OP_VERIFY, - EVP_PKEY_CTRL_RSA_PSS_SALTLEN, - len, - ptr::null_mut(), - ) - } - - pub unsafe fn EVP_PKEY_CTX_set_rsa_mgf1_md(ctx: *mut EVP_PKEY_CTX, md: *mut EVP_MD) -> c_int { - EVP_PKEY_CTX_ctrl( - ctx, - EVP_PKEY_RSA, - EVP_PKEY_OP_TYPE_SIG | EVP_PKEY_OP_TYPE_CRYPT, - EVP_PKEY_CTRL_RSA_MGF1_MD, - 0, - md as *mut c_void, - ) - } - } -} - -#[cfg(any(ossl102, libressl310))] -pub unsafe fn EVP_PKEY_CTX_set_rsa_oaep_md(ctx: *mut EVP_PKEY_CTX, md: *mut EVP_MD) -> c_int { - EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_RSA, EVP_PKEY_OP_TYPE_CRYPT, EVP_PKEY_CTRL_RSA_OAEP_MD, 0, md as *mut c_void) -} - -#[cfg(any(ossl102, libressl310))] -pub unsafe fn EVP_PKEY_CTX_set0_rsa_oaep_label(ctx: *mut EVP_PKEY_CTX, label: *mut c_void, len: c_int) -> c_int { - EVP_PKEY_CTX_ctrl( - ctx, - EVP_PKEY_RSA, - EVP_PKEY_OP_TYPE_CRYPT, - EVP_PKEY_CTRL_RSA_OAEP_LABEL, - len, - label as *mut c_void, - ) -} - -pub const EVP_PKEY_CTRL_RSA_PADDING: c_int = EVP_PKEY_ALG_CTRL + 1; -pub const EVP_PKEY_CTRL_RSA_PSS_SALTLEN: c_int = EVP_PKEY_ALG_CTRL + 2; - -pub const EVP_PKEY_CTRL_RSA_MGF1_MD: c_int = EVP_PKEY_ALG_CTRL + 5; - -pub const EVP_PKEY_CTRL_GET_RSA_PADDING: c_int = EVP_PKEY_ALG_CTRL + 6; - -#[cfg(any(ossl102, libressl310))] -pub const EVP_PKEY_CTRL_RSA_OAEP_MD: c_int = EVP_PKEY_ALG_CTRL + 9; -#[cfg(any(ossl102, libressl310))] -pub const EVP_PKEY_CTRL_RSA_OAEP_LABEL: c_int = EVP_PKEY_ALG_CTRL + 10; - -pub const RSA_PKCS1_PADDING: c_int = 1; -#[cfg(not(ossl300))] -pub const RSA_SSLV23_PADDING: c_int = 2; -pub const RSA_NO_PADDING: c_int = 3; -pub const RSA_PKCS1_OAEP_PADDING: c_int = 4; -pub const RSA_X931_PADDING: c_int = 5; -pub const RSA_PKCS1_PSS_PADDING: c_int = 6; diff --git a/openssl-sys/src/sha.rs b/openssl-sys/src/sha.rs deleted file mode 100644 index 4ad0c17..0000000 --- a/openssl-sys/src/sha.rs +++ /dev/null @@ -1,103 +0,0 @@ -use super::*; -use libc::*; -use std::ptr; - -#[cfg(not(osslconf = "OPENSSL_NO_DEPRECATED_3_0"))] -pub const SHA_LBLOCK: c_int = 16; - -#[cfg(not(osslconf = "OPENSSL_NO_DEPRECATED_3_0"))] -pub type SHA_LONG = c_uint; - -cfg_if! { - if #[cfg(ossl300)] { - #[cfg(ossl300)] - // Ideally we'd macro define these, but that crashes ctest :( - pub unsafe fn SHA1(d: *const c_uchar, n: size_t, md: *mut c_uchar) -> *mut c_uchar { - if EVP_Q_digest( - ptr::null_mut(), - "SHA1\0".as_ptr() as *const c_char, - ptr::null(), - d as *const c_void, - n, - md, - ptr::null_mut(), - ) != 0 - { - md - } else { - ptr::null_mut() - } - } - - pub unsafe fn SHA224(d: *const c_uchar, n: size_t, md: *mut c_uchar) -> *mut c_uchar { - if EVP_Q_digest( - ptr::null_mut(), - "SHA224\0".as_ptr() as *const c_char, - ptr::null(), - d as *const c_void, - n, - md, - ptr::null_mut(), - ) != 0 { - md - } else { - ptr::null_mut() - } - } - - pub unsafe fn SHA256(d: *const c_uchar, n: size_t, md: *mut c_uchar) -> *mut c_uchar { - if EVP_Q_digest( - ptr::null_mut(), - "SHA256\0".as_ptr() as *const c_char, - ptr::null(), - d as *const c_void, - n, - md, - ptr::null_mut(), - ) != 0 { - md - } else { - ptr::null_mut() - } - } - } -} - -#[cfg(not(osslconf = "OPENSSL_NO_DEPRECATED_3_0"))] -pub type SHA_LONG64 = u64; - -cfg_if! { - if #[cfg(ossl300)] { - pub unsafe fn SHA384(d: *const c_uchar, n: size_t, md: *mut c_uchar) -> *mut c_uchar { - if EVP_Q_digest( - ptr::null_mut(), - "SHA384\0".as_ptr() as *const c_char, - ptr::null(), - d as *const c_void, - n, - md, - ptr::null_mut(), - ) != 0 { - md - } else { - ptr::null_mut() - } - } - - pub unsafe fn SHA512(d: *const c_uchar, n: size_t, md: *mut c_uchar) -> *mut c_uchar { - if EVP_Q_digest( - ptr::null_mut(), - "SHA512\0".as_ptr() as *const c_char, - ptr::null(), - d as *const c_void, - n, - md, - ptr::null_mut(), - ) != 0 { - md - } else { - ptr::null_mut() - } - } - } -} diff --git a/openssl-sys/src/srtp.rs b/openssl-sys/src/srtp.rs deleted file mode 100644 index 93c7797..0000000 --- a/openssl-sys/src/srtp.rs +++ /dev/null @@ -1,14 +0,0 @@ -use libc::*; - -pub const SRTP_AES128_CM_SHA1_80: c_ulong = 0x0001; -pub const SRTP_AES128_CM_SHA1_32: c_ulong = 0x0002; -pub const SRTP_AES128_F8_SHA1_80: c_ulong = 0x0003; -pub const SRTP_AES128_F8_SHA1_32: c_ulong = 0x0004; -pub const SRTP_NULL_SHA1_80: c_ulong = 0x0005; -pub const SRTP_NULL_SHA1_32: c_ulong = 0x0006; - -/* AEAD SRTP protection profiles from RFC 7714 */ -#[cfg(ossl110)] -pub const SRTP_AEAD_AES_128_GCM: c_ulong = 0x0007; -#[cfg(ossl110)] -pub const SRTP_AEAD_AES_256_GCM: c_ulong = 0x0008; diff --git a/openssl-sys/src/ssl.rs b/openssl-sys/src/ssl.rs deleted file mode 100644 index 7c64fd9..0000000 --- a/openssl-sys/src/ssl.rs +++ /dev/null @@ -1,591 +0,0 @@ -use libc::*; -use std::ptr; - -use super::*; - -#[cfg(not(ossl110))] -pub const SSL_MAX_KRB5_PRINCIPAL_LENGTH: c_int = 256; - -#[cfg(not(ossl110))] -pub const SSL_MAX_SSL_SESSION_ID_LENGTH: c_int = 32; -#[cfg(not(ossl110))] -pub const SSL_MAX_SID_CTX_LENGTH: c_int = 32; - -#[cfg(not(ossl110))] -pub const SSL_MAX_KEY_ARG_LENGTH: c_int = 8; -#[cfg(not(ossl110))] -pub const SSL_MAX_MASTER_KEY_LENGTH: c_int = 48; - -pub const SSL_SENT_SHUTDOWN: c_int = 1; -pub const SSL_RECEIVED_SHUTDOWN: c_int = 2; - -pub const SSL_FILETYPE_PEM: c_int = X509_FILETYPE_PEM; -pub const SSL_FILETYPE_ASN1: c_int = X509_FILETYPE_ASN1; - -#[cfg(ossl111)] -pub const SSL_EXT_TLS_ONLY: c_uint = 0x0001; -/* This extension is only allowed in DTLS */ -#[cfg(ossl111)] -pub const SSL_EXT_DTLS_ONLY: c_uint = 0x0002; -/* Some extensions may be allowed in DTLS but we don't implement them for it */ -#[cfg(ossl111)] -pub const SSL_EXT_TLS_IMPLEMENTATION_ONLY: c_uint = 0x0004; -/* Most extensions are not defined for SSLv3 but EXT_TYPE_renegotiate is */ -#[cfg(ossl111)] -pub const SSL_EXT_SSL3_ALLOWED: c_uint = 0x0008; -/* Extension is only defined for TLS1.2 and below */ -#[cfg(ossl111)] -pub const SSL_EXT_TLS1_2_AND_BELOW_ONLY: c_uint = 0x0010; -/* Extension is only defined for TLS1.3 and above */ -#[cfg(ossl111)] -pub const SSL_EXT_TLS1_3_ONLY: c_uint = 0x0020; -/* Ignore this extension during parsing if we are resuming */ -#[cfg(ossl111)] -pub const SSL_EXT_IGNORE_ON_RESUMPTION: c_uint = 0x0040; -#[cfg(ossl111)] -pub const SSL_EXT_CLIENT_HELLO: c_uint = 0x0080; -/* Really means TLS1.2 or below */ -#[cfg(ossl111)] -pub const SSL_EXT_TLS1_2_SERVER_HELLO: c_uint = 0x0100; -#[cfg(ossl111)] -pub const SSL_EXT_TLS1_3_SERVER_HELLO: c_uint = 0x0200; -#[cfg(ossl111)] -pub const SSL_EXT_TLS1_3_ENCRYPTED_EXTENSIONS: c_uint = 0x0400; -#[cfg(ossl111)] -pub const SSL_EXT_TLS1_3_HELLO_RETRY_REQUEST: c_uint = 0x0800; -#[cfg(ossl111)] -pub const SSL_EXT_TLS1_3_CERTIFICATE: c_uint = 0x1000; -#[cfg(ossl111)] -pub const SSL_EXT_TLS1_3_NEW_SESSION_TICKET: c_uint = 0x2000; -#[cfg(ossl111)] -pub const SSL_EXT_TLS1_3_CERTIFICATE_REQUEST: c_uint = 0x4000; - -cfg_if! { - if #[cfg(ossl300)] { - macro_rules! ssl_op_type { - () => {u64}; - } - } else { - macro_rules! ssl_op_type { - () => {c_ulong}; - } - } -} - -pub const SSL_OP_LEGACY_SERVER_CONNECT: ssl_op_type!() = 0x00000004; -cfg_if! { - if #[cfg(libressl261)] { - pub const SSL_OP_TLSEXT_PADDING: ssl_op_type!() = 0x0; - } else if #[cfg(any(ossl102, libressl))] { - pub const SSL_OP_TLSEXT_PADDING: ssl_op_type!() = 0x10; - } -} -#[cfg(ossl101)] -pub const SSL_OP_SAFARI_ECDHE_ECDSA_BUG: ssl_op_type!() = 0x00000040; - -pub const SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS: ssl_op_type!() = 0x00000800; - -pub const SSL_OP_NO_QUERY_MTU: ssl_op_type!() = 0x00001000; -pub const SSL_OP_COOKIE_EXCHANGE: ssl_op_type!() = 0x00002000; -pub const SSL_OP_NO_TICKET: ssl_op_type!() = 0x00004000; -cfg_if! { - if #[cfg(ossl101)] { - pub const SSL_OP_CISCO_ANYCONNECT: ssl_op_type!() = 0x00008000; - } else { - pub const SSL_OP_CISCO_ANYCONNECT: ssl_op_type!() = 0x0; - } -} - -pub const SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION: ssl_op_type!() = 0x00010000; -cfg_if! { - if #[cfg(ossl101)] { - pub const SSL_OP_NO_COMPRESSION: ssl_op_type!() = 0x00020000; - pub const SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION: ssl_op_type!() = 0x00040000; - } else { - pub const SSL_OP_NO_COMPRESSION: ssl_op_type!() = 0x0; - pub const SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION: ssl_op_type!() = 0x0; - } -} - -#[cfg(ossl111)] -pub const SSL_OP_ENABLE_MIDDLEBOX_COMPAT: ssl_op_type!() = 0x00100000; -#[cfg(ossl111)] -pub const SSL_OP_PRIORITIZE_CHACHA: ssl_op_type!() = 0x00200000; - -pub const SSL_OP_CIPHER_SERVER_PREFERENCE: ssl_op_type!() = 0x00400000; -cfg_if! { - if #[cfg(libressl280)] { - pub const SSL_OP_TLS_ROLLBACK_BUG: ssl_op_type!() = 0; - } else { - pub const SSL_OP_TLS_ROLLBACK_BUG: ssl_op_type!() = 0x00800000; - } -} - -cfg_if! { - if #[cfg(ossl101)] { - pub const SSL_OP_NO_SSLv3: ssl_op_type!() = 0x02000000; - } else { - pub const SSL_OP_NO_SSLv3: ssl_op_type!() = 0x0; - } -} -pub const SSL_OP_NO_TLSv1_1: ssl_op_type!() = 0x10000000; -pub const SSL_OP_NO_TLSv1_2: ssl_op_type!() = 0x08000000; - -pub const SSL_OP_NO_TLSv1: ssl_op_type!() = 0x04000000; -cfg_if! { - if #[cfg(ossl102)] { - pub const SSL_OP_NO_DTLSv1: ssl_op_type!() = 0x04000000; - pub const SSL_OP_NO_DTLSv1_2: ssl_op_type!() = 0x08000000; - } else if #[cfg(libressl332)] { - pub const SSL_OP_NO_DTLSv1: ssl_op_type!() = 0x40000000; - pub const SSL_OP_NO_DTLSv1_2: ssl_op_type!() = 0x80000000; - } -} -#[cfg(any(ossl111, libressl340))] -pub const SSL_OP_NO_TLSv1_3: ssl_op_type!() = 0x20000000; - -#[cfg(ossl110h)] -pub const SSL_OP_NO_RENEGOTIATION: ssl_op_type!() = 0x40000000; - -cfg_if! { - if #[cfg(ossl111)] { - pub const SSL_OP_NO_SSL_MASK: ssl_op_type!() = SSL_OP_NO_SSLv2 - | SSL_OP_NO_SSLv3 - | SSL_OP_NO_TLSv1 - | SSL_OP_NO_TLSv1_1 - | SSL_OP_NO_TLSv1_2 - | SSL_OP_NO_TLSv1_3; - } else if #[cfg(ossl102)] { - pub const SSL_OP_NO_SSL_MASK: ssl_op_type!() = - SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1 | SSL_OP_NO_TLSv1_2; - } -} - -cfg_if! { - if #[cfg(libressl261)] { - pub const SSL_OP_CRYPTOPRO_TLSEXT_BUG: ssl_op_type!() = 0x0; - } else { - pub const SSL_OP_CRYPTOPRO_TLSEXT_BUG: ssl_op_type!() = 0x80000000; - } -} - -cfg_if! { - if #[cfg(ossl300)] { - pub const SSL_OP_ALL: ssl_op_type!() = SSL_OP_CRYPTOPRO_TLSEXT_BUG - | SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS - | SSL_OP_TLSEXT_PADDING - | SSL_OP_SAFARI_ECDHE_ECDSA_BUG; - } else if #[cfg(ossl110f)] { - pub const SSL_OP_ALL: ssl_op_type!() = SSL_OP_CRYPTOPRO_TLSEXT_BUG - | SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS - | SSL_OP_LEGACY_SERVER_CONNECT - | SSL_OP_TLSEXT_PADDING - | SSL_OP_SAFARI_ECDHE_ECDSA_BUG; - } else if #[cfg(libressl261)] { - pub const SSL_OP_ALL: ssl_op_type!() = 0x4; - } else if #[cfg(libressl)] { - pub const SSL_OP_ALL: ssl_op_type!() = 0x80000014; - } else { - pub const SSL_OP_ALL: ssl_op_type!() = 0x80000BFF; - } -} - -cfg_if! { - if #[cfg(ossl110)] { - pub const SSL_OP_MICROSOFT_SESS_ID_BUG: ssl_op_type!() = 0x00000000; - pub const SSL_OP_NETSCAPE_CHALLENGE_BUG: ssl_op_type!() = 0x00000000; - pub const SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG: ssl_op_type!() = 0x00000000; - pub const SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER: ssl_op_type!() = 0x00000000; - pub const SSL_OP_SSLEAY_080_CLIENT_DH_BUG: ssl_op_type!() = 0x00000000; - pub const SSL_OP_TLS_D5_BUG: ssl_op_type!() = 0x00000000; - pub const SSL_OP_TLS_BLOCK_PADDING_BUG: ssl_op_type!() = 0x00000000; - pub const SSL_OP_SINGLE_ECDH_USE: ssl_op_type!() = 0x00000000; - pub const SSL_OP_SINGLE_DH_USE: ssl_op_type!() = 0x00000000; - pub const SSL_OP_NO_SSLv2: ssl_op_type!() = 0x00000000; - } else if #[cfg(ossl101)] { - pub const SSL_OP_MICROSOFT_SESS_ID_BUG: ssl_op_type!() = 0x00000001; - pub const SSL_OP_NETSCAPE_CHALLENGE_BUG: ssl_op_type!() = 0x00000002; - pub const SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG: ssl_op_type!() = 0x00000008; - pub const SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER: ssl_op_type!() = 0x00000020; - pub const SSL_OP_SSLEAY_080_CLIENT_DH_BUG: ssl_op_type!() = 0x00000080; - pub const SSL_OP_TLS_D5_BUG: ssl_op_type!() = 0x00000100; - pub const SSL_OP_TLS_BLOCK_PADDING_BUG: ssl_op_type!() = 0x00000200; - pub const SSL_OP_SINGLE_ECDH_USE: ssl_op_type!() = 0x00080000; - pub const SSL_OP_SINGLE_DH_USE: ssl_op_type!() = 0x00100000; - pub const SSL_OP_NO_SSLv2: ssl_op_type!() = 0x01000000; - } else { - pub const SSL_OP_MICROSOFT_SESS_ID_BUG: ssl_op_type!() = 0x0; - pub const SSL_OP_NETSCAPE_CHALLENGE_BUG: ssl_op_type!() = 0x0; - pub const SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG: ssl_op_type!() = 0x0; - pub const SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER: ssl_op_type!() = 0x0; - pub const SSL_OP_SSLEAY_080_CLIENT_DH_BUG: ssl_op_type!() = 0x0; - pub const SSL_OP_TLS_D5_BUG: ssl_op_type!() = 0x0; - pub const SSL_OP_TLS_BLOCK_PADDING_BUG: ssl_op_type!() = 0x0; - #[cfg(libressl261)] - pub const SSL_OP_SINGLE_ECDH_USE: ssl_op_type!() = 0x0; - #[cfg(not(libressl261))] - pub const SSL_OP_SINGLE_ECDH_USE: ssl_op_type!() = 0x00080000; - pub const SSL_OP_SINGLE_DH_USE: ssl_op_type!() = 0x00100000; - pub const SSL_OP_NO_SSLv2: ssl_op_type!() = 0x0; - } -} - -pub const SSL_MODE_ENABLE_PARTIAL_WRITE: c_long = 0x1; -pub const SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER: c_long = 0x2; -pub const SSL_MODE_AUTO_RETRY: c_long = 0x4; -pub const SSL_MODE_NO_AUTO_CHAIN: c_long = 0x8; -pub const SSL_MODE_RELEASE_BUFFERS: c_long = 0x10; -#[cfg(ossl101)] -pub const SSL_MODE_SEND_CLIENTHELLO_TIME: c_long = 0x20; -#[cfg(ossl101)] -pub const SSL_MODE_SEND_SERVERHELLO_TIME: c_long = 0x40; -#[cfg(ossl101)] -pub const SSL_MODE_SEND_FALLBACK_SCSV: c_long = 0x80; - -pub unsafe fn SSL_CTX_set_mode(ctx: *mut SSL_CTX, op: c_long) -> c_long { - SSL_CTX_ctrl(ctx, SSL_CTRL_MODE, op, ptr::null_mut()) -} - -#[cfg(ossl111)] -pub const SSL_COOKIE_LENGTH: c_int = 4096; - -cfg_if! { - if #[cfg(not(ossl110))] { - pub unsafe fn SSL_CTX_get_options(ctx: *const SSL_CTX) -> c_ulong { - SSL_CTX_ctrl(ctx as *mut _, SSL_CTRL_OPTIONS, 0, ptr::null_mut()) as c_ulong - } - - pub unsafe fn SSL_CTX_set_options(ctx: *const SSL_CTX, op: c_ulong) -> c_ulong { - SSL_CTX_ctrl( - ctx as *mut _, - SSL_CTRL_OPTIONS, - op as c_long, - ptr::null_mut(), - ) as c_ulong - } - - pub unsafe fn SSL_CTX_clear_options(ctx: *const SSL_CTX, op: c_ulong) -> c_ulong { - SSL_CTX_ctrl( - ctx as *mut _, - SSL_CTRL_CLEAR_OPTIONS, - op as c_long, - ptr::null_mut(), - ) as c_ulong - } - } -} - -pub unsafe fn SSL_set_mtu(ssl: *mut SSL, mtu: c_long) -> c_long { - SSL_ctrl(ssl, SSL_CTRL_SET_MTU, mtu, ptr::null_mut()) -} - -#[cfg(ossl110)] -pub unsafe fn SSL_get_extms_support(ssl: *mut SSL) -> c_long { - SSL_ctrl(ssl, SSL_CTRL_GET_EXTMS_SUPPORT, 0, ptr::null_mut()) -} - -pub const SSL_SESS_CACHE_OFF: c_long = 0x0; -pub const SSL_SESS_CACHE_CLIENT: c_long = 0x1; -pub const SSL_SESS_CACHE_SERVER: c_long = 0x2; -pub const SSL_SESS_CACHE_BOTH: c_long = SSL_SESS_CACHE_CLIENT | SSL_SESS_CACHE_SERVER; -pub const SSL_SESS_CACHE_NO_AUTO_CLEAR: c_long = 0x80; -pub const SSL_SESS_CACHE_NO_INTERNAL_LOOKUP: c_long = 0x100; -pub const SSL_SESS_CACHE_NO_INTERNAL_STORE: c_long = 0x200; -pub const SSL_SESS_CACHE_NO_INTERNAL: c_long = SSL_SESS_CACHE_NO_INTERNAL_LOOKUP | SSL_SESS_CACHE_NO_INTERNAL_STORE; - -pub const OPENSSL_NPN_UNSUPPORTED: c_int = 0; -pub const OPENSSL_NPN_NEGOTIATED: c_int = 1; -pub const OPENSSL_NPN_NO_OVERLAP: c_int = 2; - -pub const SSL_AD_ILLEGAL_PARAMETER: c_int = SSL3_AD_ILLEGAL_PARAMETER; -pub const SSL_AD_DECODE_ERROR: c_int = TLS1_AD_DECODE_ERROR; -pub const SSL_AD_UNRECOGNIZED_NAME: c_int = TLS1_AD_UNRECOGNIZED_NAME; -pub const SSL_ERROR_NONE: c_int = 0; -pub const SSL_ERROR_SSL: c_int = 1; -pub const SSL_ERROR_SYSCALL: c_int = 5; -pub const SSL_ERROR_WANT_ACCEPT: c_int = 8; -pub const SSL_ERROR_WANT_CONNECT: c_int = 7; -pub const SSL_ERROR_WANT_READ: c_int = 2; -pub const SSL_ERROR_WANT_WRITE: c_int = 3; -pub const SSL_ERROR_WANT_X509_LOOKUP: c_int = 4; -pub const SSL_ERROR_ZERO_RETURN: c_int = 6; -#[cfg(ossl111)] -pub const SSL_ERROR_WANT_CLIENT_HELLO_CB: c_int = 11; -pub const SSL_VERIFY_NONE: c_int = 0; -pub const SSL_VERIFY_PEER: c_int = 1; -pub const SSL_VERIFY_FAIL_IF_NO_PEER_CERT: c_int = 2; -pub const SSL_CTRL_SET_TMP_DH: c_int = 3; -pub const SSL_CTRL_SET_TMP_ECDH: c_int = 4; -#[cfg(any(libressl, all(ossl101, not(ossl110))))] -pub const SSL_CTRL_GET_SESSION_REUSED: c_int = 8; -pub const SSL_CTRL_EXTRA_CHAIN_CERT: c_int = 14; -pub const SSL_CTRL_SET_MTU: c_int = 17; -#[cfg(any(libressl, all(ossl101, not(ossl110))))] -pub const SSL_CTRL_OPTIONS: c_int = 32; -pub const SSL_CTRL_MODE: c_int = 33; -pub const SSL_CTRL_SET_READ_AHEAD: c_int = 41; -pub const SSL_CTRL_SET_SESS_CACHE_SIZE: c_int = 42; -pub const SSL_CTRL_GET_SESS_CACHE_SIZE: c_int = 43; -pub const SSL_CTRL_SET_SESS_CACHE_MODE: c_int = 44; -pub const SSL_CTRL_SET_TLSEXT_SERVERNAME_CB: c_int = 53; -pub const SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG: c_int = 54; -pub const SSL_CTRL_SET_TLSEXT_HOSTNAME: c_int = 55; -pub const SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB: c_int = 63; -pub const SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB_ARG: c_int = 64; -pub const SSL_CTRL_SET_TLSEXT_STATUS_REQ_TYPE: c_int = 65; -pub const SSL_CTRL_GET_TLSEXT_STATUS_REQ_OCSP_RESP: c_int = 70; -pub const SSL_CTRL_SET_TLSEXT_STATUS_REQ_OCSP_RESP: c_int = 71; -#[cfg(any(libressl, all(ossl101, not(ossl110))))] -pub const SSL_CTRL_CLEAR_OPTIONS: c_int = 77; -pub const SSL_CTRL_GET_EXTRA_CHAIN_CERTS: c_int = 82; -#[cfg(ossl102)] -pub const SSL_CTRL_CHAIN_CERT: c_int = 89; -#[cfg(any(ossl111, libressl252))] -pub const SSL_CTRL_SET_GROUPS_LIST: c_int = 92; -#[cfg(any(libressl, all(ossl102, not(ossl110))))] -pub const SSL_CTRL_SET_ECDH_AUTO: c_int = 94; -#[cfg(ossl102)] -pub const SSL_CTRL_SET_SIGALGS_LIST: c_int = 98; -#[cfg(ossl102)] -pub const SSL_CTRL_SET_VERIFY_CERT_STORE: c_int = 106; -#[cfg(ossl110)] -pub const SSL_CTRL_GET_EXTMS_SUPPORT: c_int = 122; -#[cfg(any(ossl110, libressl261))] -pub const SSL_CTRL_SET_MIN_PROTO_VERSION: c_int = 123; -#[cfg(any(ossl110, libressl261))] -pub const SSL_CTRL_SET_MAX_PROTO_VERSION: c_int = 124; -#[cfg(any(ossl110g, libressl270))] -pub const SSL_CTRL_GET_MIN_PROTO_VERSION: c_int = 130; -#[cfg(any(ossl110g, libressl270))] -pub const SSL_CTRL_GET_MAX_PROTO_VERSION: c_int = 131; - -pub unsafe fn SSL_CTX_set_tmp_dh(ctx: *mut SSL_CTX, dh: *mut DH) -> c_long { - SSL_CTX_ctrl(ctx, SSL_CTRL_SET_TMP_DH, 0, dh as *mut c_void) -} - -pub unsafe fn SSL_CTX_set_tmp_ecdh(ctx: *mut SSL_CTX, key: *mut EC_KEY) -> c_long { - SSL_CTX_ctrl(ctx, SSL_CTRL_SET_TMP_ECDH, 0, key as *mut c_void) -} - -pub unsafe fn SSL_set_tmp_dh(ssl: *mut SSL, dh: *mut DH) -> c_long { - SSL_ctrl(ssl, SSL_CTRL_SET_TMP_DH, 0, dh as *mut c_void) -} - -pub unsafe fn SSL_set_tmp_ecdh(ssl: *mut SSL, key: *mut EC_KEY) -> c_long { - SSL_ctrl(ssl, SSL_CTRL_SET_TMP_ECDH, 0, key as *mut c_void) -} - -pub unsafe fn SSL_CTX_add_extra_chain_cert(ctx: *mut SSL_CTX, x509: *mut X509) -> c_long { - SSL_CTX_ctrl(ctx, SSL_CTRL_EXTRA_CHAIN_CERT, 0, x509 as *mut c_void) -} - -pub unsafe fn SSL_CTX_get_extra_chain_certs(ctx: *mut SSL_CTX, chain: *mut *mut stack_st_X509) -> c_long { - SSL_CTX_ctrl(ctx, SSL_CTRL_GET_EXTRA_CHAIN_CERTS, 0, chain as *mut c_void) -} - -#[cfg(ossl102)] -pub unsafe fn SSL_CTX_set0_verify_cert_store(ctx: *mut SSL_CTX, st: *mut X509_STORE) -> c_long { - SSL_CTX_ctrl(ctx, SSL_CTRL_SET_VERIFY_CERT_STORE, 0, st as *mut c_void) -} - -#[cfg(ossl102)] -pub unsafe fn SSL_set0_verify_cert_store(ssl: *mut SSL, st: *mut X509_STORE) -> c_long { - SSL_ctrl(ssl, SSL_CTRL_SET_VERIFY_CERT_STORE, 0, st as *mut c_void) -} - -cfg_if! { - if #[cfg(ossl111)] { - pub unsafe fn SSL_CTX_set1_groups_list(ctx: *mut SSL_CTX, s: *const c_char) -> c_long { - SSL_CTX_ctrl( - ctx, - SSL_CTRL_SET_GROUPS_LIST, - 0, - s as *const c_void as *mut c_void, - ) - } - } else if #[cfg(libressl251)] { - extern "C" { - pub fn SSL_CTX_set1_groups_list(ctx: *mut SSL_CTX, s: *const c_char) -> c_int; - } - } -} - -#[cfg(ossl102)] -pub unsafe fn SSL_add0_chain_cert(ssl: *mut SSL, ptr: *mut X509) -> c_long { - SSL_ctrl(ssl, SSL_CTRL_CHAIN_CERT, 0, ptr as *mut c_void) -} - -#[cfg(ossl102)] -pub unsafe fn SSL_CTX_set1_sigalgs_list(ctx: *mut SSL_CTX, s: *const c_char) -> c_long { - SSL_CTX_ctrl(ctx, SSL_CTRL_SET_SIGALGS_LIST, 0, s as *const c_void as *mut c_void) -} - -#[cfg(any(libressl, all(ossl102, not(ossl110))))] -pub unsafe fn SSL_CTX_set_ecdh_auto(ctx: *mut SSL_CTX, onoff: c_int) -> c_int { - SSL_CTX_ctrl(ctx, SSL_CTRL_SET_ECDH_AUTO, onoff as c_long, ptr::null_mut()) as c_int -} - -#[cfg(any(libressl, all(ossl102, not(ossl110))))] -pub unsafe fn SSL_set_ecdh_auto(ssl: *mut SSL, onoff: c_int) -> c_int { - SSL_ctrl(ssl, SSL_CTRL_SET_ECDH_AUTO, onoff as c_long, ptr::null_mut()) as c_int -} - -cfg_if! { - if #[cfg(ossl110)] { - pub unsafe fn SSL_CTX_set_min_proto_version(ctx: *mut SSL_CTX, version: c_int) -> c_int { - SSL_CTX_ctrl( - ctx, - SSL_CTRL_SET_MIN_PROTO_VERSION, - version as c_long, - ptr::null_mut(), - ) as c_int - } - - pub unsafe fn SSL_CTX_set_max_proto_version(ctx: *mut SSL_CTX, version: c_int) -> c_int { - SSL_CTX_ctrl( - ctx, - SSL_CTRL_SET_MAX_PROTO_VERSION, - version as c_long, - ptr::null_mut(), - ) as c_int - } - - pub unsafe fn SSL_set_min_proto_version(s: *mut SSL, version: c_int) -> c_int { - SSL_ctrl( - s, - SSL_CTRL_SET_MIN_PROTO_VERSION, - version as c_long, - ptr::null_mut(), - ) as c_int - } - - pub unsafe fn SSL_set_max_proto_version(s: *mut SSL, version: c_int) -> c_int { - SSL_ctrl( - s, - SSL_CTRL_SET_MAX_PROTO_VERSION, - version as c_long, - ptr::null_mut(), - ) as c_int - } - } -} - -cfg_if! { - if #[cfg(ossl110g)] { - pub unsafe fn SSL_CTX_get_min_proto_version(ctx: *mut SSL_CTX) -> c_int { - SSL_CTX_ctrl(ctx, SSL_CTRL_GET_MIN_PROTO_VERSION, 0, ptr::null_mut()) as c_int - } - - pub unsafe fn SSL_CTX_get_max_proto_version(ctx: *mut SSL_CTX) -> c_int { - SSL_CTX_ctrl(ctx, SSL_CTRL_GET_MAX_PROTO_VERSION, 0, ptr::null_mut()) as c_int - } - pub unsafe fn SSL_get_min_proto_version(s: *mut SSL) -> c_int { - SSL_ctrl(s, SSL_CTRL_GET_MIN_PROTO_VERSION, 0, ptr::null_mut()) as c_int - } - pub unsafe fn SSL_get_max_proto_version(s: *mut SSL) -> c_int { - SSL_ctrl(s, SSL_CTRL_GET_MAX_PROTO_VERSION, 0, ptr::null_mut()) as c_int - } - } -} - -#[cfg(ossl111)] -pub const SSL_CLIENT_HELLO_SUCCESS: c_int = 1; -#[cfg(ossl111)] -pub const SSL_CLIENT_HELLO_ERROR: c_int = 0; -#[cfg(ossl111)] -pub const SSL_CLIENT_HELLO_RETRY: c_int = -1; - -#[cfg(any(ossl111, libressl340))] -pub const SSL_READ_EARLY_DATA_ERROR: c_int = 0; -#[cfg(any(ossl111, libressl340))] -pub const SSL_READ_EARLY_DATA_SUCCESS: c_int = 1; -#[cfg(any(ossl111, libressl340))] -pub const SSL_READ_EARLY_DATA_FINISH: c_int = 2; - -cfg_if! { - if #[cfg(ossl110)] { - pub unsafe fn SSL_get_ex_new_index( - l: c_long, - p: *mut c_void, - newf: Option, - dupf: Option, - freef: Option, - ) -> c_int { - CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL, l, p, newf, dupf, freef) - } - } -} -cfg_if! { - if #[cfg(ossl110)] { - pub unsafe fn SSL_CTX_get_ex_new_index( - l: c_long, - p: *mut c_void, - newf: Option, - dupf: Option, - freef: Option, - ) -> c_int { - CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL_CTX, l, p, newf, dupf, freef) - } - } -} - -pub unsafe fn SSL_CTX_sess_set_cache_size(ctx: *mut SSL_CTX, t: c_long) -> c_long { - SSL_CTX_ctrl(ctx, SSL_CTRL_SET_SESS_CACHE_SIZE, t, ptr::null_mut()) -} - -pub unsafe fn SSL_CTX_sess_get_cache_size(ctx: *mut SSL_CTX) -> c_long { - SSL_CTX_ctrl(ctx, SSL_CTRL_GET_SESS_CACHE_SIZE, 0, ptr::null_mut()) -} - -pub unsafe fn SSL_CTX_set_session_cache_mode(ctx: *mut SSL_CTX, m: c_long) -> c_long { - SSL_CTX_ctrl(ctx, SSL_CTRL_SET_SESS_CACHE_MODE, m, ptr::null_mut()) -} - -pub unsafe fn SSL_CTX_set_read_ahead(ctx: *mut SSL_CTX, m: c_long) -> c_long { - SSL_CTX_ctrl(ctx, SSL_CTRL_SET_READ_AHEAD, m, ptr::null_mut()) -} - -#[allow(clashing_extern_declarations)] -extern "C" { - #[deprecated(note = "use SSL_CTX_set_tmp_dh_callback__fixed_rust instead")] - pub fn SSL_CTX_set_tmp_dh_callback(ctx: *mut SSL_CTX, dh: unsafe extern "C" fn(ssl: *mut SSL, is_export: c_int, keylength: c_int) -> *mut DH); - #[deprecated(note = "use SSL_set_tmp_dh_callback__fixed_rust instead")] - pub fn SSL_set_tmp_dh_callback(ctx: *mut SSL, dh: unsafe extern "C" fn(ssl: *mut SSL, is_export: c_int, keylength: c_int) -> *mut DH); - #[deprecated(note = "use SSL_CTX_set_tmp_ecdh_callback__fixed_rust instead")] - #[cfg(not(ossl110))] - pub fn SSL_CTX_set_tmp_ecdh_callback( - ctx: *mut SSL_CTX, - ecdh: unsafe extern "C" fn(ssl: *mut SSL, is_export: c_int, keylength: c_int) -> *mut EC_KEY, - ); - #[deprecated(note = "use SSL_set_tmp_ecdh_callback__fixed_rust instead")] - #[cfg(not(ossl110))] - pub fn SSL_set_tmp_ecdh_callback(ssl: *mut SSL, ecdh: unsafe extern "C" fn(ssl: *mut SSL, is_export: c_int, keylength: c_int) -> *mut EC_KEY); - - #[deprecated(note = "use SSL_CTX_callback_ctrl__fixed_rust instead")] - pub fn SSL_CTX_callback_ctrl(ctx: *mut SSL_CTX, cmd: c_int, fp: Option) -> c_long; - - #[deprecated(note = "use SSL_CTX_set_alpn_select_cb__fixed_rust instead")] - #[cfg(any(ossl102, libressl261))] - pub fn SSL_CTX_set_alpn_select_cb( - ssl: *mut SSL_CTX, - cb: extern "C" fn( - ssl: *mut SSL, - out: *mut *const c_uchar, - outlen: *mut c_uchar, - inbuf: *const c_uchar, - inlen: c_uint, - arg: *mut c_void, - ) -> c_int, - arg: *mut c_void, - ); -} - -#[cfg(not(ossl110))] -pub unsafe fn SSL_session_reused(ssl: *mut SSL) -> c_int { - SSL_ctrl(ssl, SSL_CTRL_GET_SESSION_REUSED, 0, ptr::null_mut()) as c_int -} - -#[cfg(ossl110)] -pub const OPENSSL_INIT_LOAD_SSL_STRINGS: u64 = 0x00200000; -#[cfg(ossl111b)] -pub const OPENSSL_INIT_NO_ATEXIT: u64 = 0x00080000; diff --git a/openssl-sys/src/ssl3.rs b/openssl-sys/src/ssl3.rs deleted file mode 100644 index 822613e..0000000 --- a/openssl-sys/src/ssl3.rs +++ /dev/null @@ -1,5 +0,0 @@ -use libc::*; - -pub const SSL3_VERSION: c_int = 0x300; - -pub const SSL3_AD_ILLEGAL_PARAMETER: c_int = 47; diff --git a/openssl-sys/src/tls1.rs b/openssl-sys/src/tls1.rs deleted file mode 100644 index abc842e..0000000 --- a/openssl-sys/src/tls1.rs +++ /dev/null @@ -1,67 +0,0 @@ -use libc::*; -use std::mem; -use std::ptr; - -use super::*; - -pub const TLS1_VERSION: c_int = 0x301; -pub const TLS1_1_VERSION: c_int = 0x302; -pub const TLS1_2_VERSION: c_int = 0x303; -#[cfg(any(ossl111, libressl340))] -pub const TLS1_3_VERSION: c_int = 0x304; - -pub const TLS1_AD_DECODE_ERROR: c_int = 50; -pub const TLS1_AD_UNRECOGNIZED_NAME: c_int = 112; - -pub const TLSEXT_NAMETYPE_host_name: c_int = 0; -pub const TLSEXT_STATUSTYPE_ocsp: c_int = 1; - -pub unsafe fn SSL_set_tlsext_host_name(s: *mut SSL, name: *mut c_char) -> c_long { - SSL_ctrl(s, SSL_CTRL_SET_TLSEXT_HOSTNAME, TLSEXT_NAMETYPE_host_name as c_long, name as *mut c_void) -} - -pub unsafe fn SSL_set_tlsext_status_type(s: *mut SSL, type_: c_int) -> c_long { - SSL_ctrl(s, SSL_CTRL_SET_TLSEXT_STATUS_REQ_TYPE, type_ as c_long, ptr::null_mut()) -} - -pub unsafe fn SSL_get_tlsext_status_ocsp_resp(ssl: *mut SSL, resp: *mut *mut c_uchar) -> c_long { - SSL_ctrl(ssl, SSL_CTRL_GET_TLSEXT_STATUS_REQ_OCSP_RESP, 0, resp as *mut c_void) -} - -pub unsafe fn SSL_set_tlsext_status_ocsp_resp(ssl: *mut SSL, resp: *mut c_uchar, len: c_long) -> c_long { - SSL_ctrl(ssl, SSL_CTRL_SET_TLSEXT_STATUS_REQ_OCSP_RESP, len, resp as *mut c_void) -} - -#[deprecated(note = "use SSL_CTX_set_tlsext_servername_callback__fixed_rust instead")] -#[allow(deprecated)] -pub unsafe fn SSL_CTX_set_tlsext_servername_callback( - ctx: *mut SSL_CTX, - // FIXME should have the right signature - cb: Option, -) -> c_long { - SSL_CTX_callback_ctrl(ctx, SSL_CTRL_SET_TLSEXT_SERVERNAME_CB, cb) -} - -pub unsafe fn SSL_CTX_set_tlsext_servername_callback__fixed_rust( - ctx: *mut SSL_CTX, - cb: Option c_int>, -) -> c_long { - SSL_CTX_callback_ctrl__fixed_rust(ctx, SSL_CTRL_SET_TLSEXT_SERVERNAME_CB, mem::transmute(cb)) -} - -pub const SSL_TLSEXT_ERR_OK: c_int = 0; -pub const SSL_TLSEXT_ERR_ALERT_WARNING: c_int = 1; -pub const SSL_TLSEXT_ERR_ALERT_FATAL: c_int = 2; -pub const SSL_TLSEXT_ERR_NOACK: c_int = 3; - -pub unsafe fn SSL_CTX_set_tlsext_servername_arg(ctx: *mut SSL_CTX, arg: *mut c_void) -> c_long { - SSL_CTX_ctrl(ctx, SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG, 0, arg) -} - -pub unsafe fn SSL_CTX_set_tlsext_status_cb(ctx: *mut SSL_CTX, cb: Option c_int>) -> c_long { - SSL_CTX_callback_ctrl__fixed_rust(ctx, SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB, mem::transmute(cb)) -} - -pub unsafe fn SSL_CTX_set_tlsext_status_arg(ctx: *mut SSL_CTX, arg: *mut c_void) -> c_long { - SSL_CTX_ctrl(ctx, SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB_ARG, 0, arg) -} diff --git a/openssl-sys/src/types.rs b/openssl-sys/src/types.rs deleted file mode 100644 index 10c8f67..0000000 --- a/openssl-sys/src/types.rs +++ /dev/null @@ -1,21 +0,0 @@ -use libc::*; - -use super::*; - -cfg_if! { - if #[cfg(any(ossl110, libressl280))] { - pub enum EVP_PKEY {} - } else { - #[repr(C)] - pub struct EVP_PKEY { - pub type_: c_int, - pub save_type: c_int, - pub references: c_int, - pub ameth: *const EVP_PKEY_ASN1_METHOD, - pub engine: *mut ENGINE, - pub pkey: *mut c_void, - pub save_parameters: c_int, - pub attributes: *mut stack_st_X509_ATTRIBUTE, - } - } -} diff --git a/openssl-sys/src/x509.rs b/openssl-sys/src/x509.rs deleted file mode 100644 index 714b06c..0000000 --- a/openssl-sys/src/x509.rs +++ /dev/null @@ -1,15 +0,0 @@ -use libc::*; - -pub const X509_FILETYPE_PEM: c_int = 1; -pub const X509_FILETYPE_ASN1: c_int = 2; -pub const X509_FILETYPE_DEFAULT: c_int = 3; - -pub const ASN1_R_HEADER_TOO_LONG: c_int = 123; - -cfg_if! { - if #[cfg(not(any(ossl110, libressl350)))] { - pub const X509_LU_FAIL: c_int = 0; - pub const X509_LU_X509: c_int = 1; - pub const X509_LU_CRL: c_int = 2; - } -} diff --git a/openssl-sys/src/x509_vfy.rs b/openssl-sys/src/x509_vfy.rs deleted file mode 100644 index 0cdc3d8..0000000 --- a/openssl-sys/src/x509_vfy.rs +++ /dev/null @@ -1,139 +0,0 @@ -use libc::*; - -use super::*; - -pub const X509_V_OK: c_int = 0; -#[cfg(ossl102f)] -pub const X509_V_ERR_UNSPECIFIED: c_int = 1; -pub const X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT: c_int = 2; -pub const X509_V_ERR_UNABLE_TO_GET_CRL: c_int = 3; -pub const X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE: c_int = 4; -pub const X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE: c_int = 5; -pub const X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY: c_int = 6; -pub const X509_V_ERR_CERT_SIGNATURE_FAILURE: c_int = 7; -pub const X509_V_ERR_CRL_SIGNATURE_FAILURE: c_int = 8; -pub const X509_V_ERR_CERT_NOT_YET_VALID: c_int = 9; -pub const X509_V_ERR_CERT_HAS_EXPIRED: c_int = 10; -pub const X509_V_ERR_CRL_NOT_YET_VALID: c_int = 11; -pub const X509_V_ERR_CRL_HAS_EXPIRED: c_int = 12; -pub const X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD: c_int = 13; -pub const X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD: c_int = 14; -pub const X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD: c_int = 15; -pub const X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD: c_int = 16; -pub const X509_V_ERR_OUT_OF_MEM: c_int = 17; -pub const X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT: c_int = 18; -pub const X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN: c_int = 19; -pub const X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY: c_int = 20; -pub const X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE: c_int = 21; -pub const X509_V_ERR_CERT_CHAIN_TOO_LONG: c_int = 22; -pub const X509_V_ERR_CERT_REVOKED: c_int = 23; -cfg_if! { - if #[cfg(ossl300)] { - pub const X509_V_ERR_NO_ISSUER_PUBLIC_KEY: c_int = 24; - } else { - pub const X509_V_ERR_INVALID_CA: c_int = 24; - } -} -pub const X509_V_ERR_PATH_LENGTH_EXCEEDED: c_int = 25; -pub const X509_V_ERR_INVALID_PURPOSE: c_int = 26; -pub const X509_V_ERR_CERT_UNTRUSTED: c_int = 27; -pub const X509_V_ERR_CERT_REJECTED: c_int = 28; -pub const X509_V_ERR_SUBJECT_ISSUER_MISMATCH: c_int = 29; -pub const X509_V_ERR_AKID_SKID_MISMATCH: c_int = 30; -pub const X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH: c_int = 31; -pub const X509_V_ERR_KEYUSAGE_NO_CERTSIGN: c_int = 32; -pub const X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER: c_int = 33; -pub const X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION: c_int = 34; -pub const X509_V_ERR_KEYUSAGE_NO_CRL_SIGN: c_int = 35; -pub const X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION: c_int = 36; -pub const X509_V_ERR_INVALID_NON_CA: c_int = 37; -pub const X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED: c_int = 38; -pub const X509_V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE: c_int = 39; -pub const X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED: c_int = 40; -pub const X509_V_ERR_INVALID_EXTENSION: c_int = 41; -pub const X509_V_ERR_INVALID_POLICY_EXTENSION: c_int = 42; -pub const X509_V_ERR_NO_EXPLICIT_POLICY: c_int = 43; -pub const X509_V_ERR_DIFFERENT_CRL_SCOPE: c_int = 44; -pub const X509_V_ERR_UNSUPPORTED_EXTENSION_FEATURE: c_int = 45; -pub const X509_V_ERR_UNNESTED_RESOURCE: c_int = 46; -pub const X509_V_ERR_PERMITTED_VIOLATION: c_int = 47; -pub const X509_V_ERR_EXCLUDED_VIOLATION: c_int = 48; -pub const X509_V_ERR_SUBTREE_MINMAX: c_int = 49; -pub const X509_V_ERR_APPLICATION_VERIFICATION: c_int = 50; -pub const X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPE: c_int = 51; -pub const X509_V_ERR_UNSUPPORTED_CONSTRAINT_SYNTAX: c_int = 52; -pub const X509_V_ERR_UNSUPPORTED_NAME_SYNTAX: c_int = 53; -pub const X509_V_ERR_CRL_PATH_VALIDATION_ERROR: c_int = 54; -#[cfg(ossl102)] -pub const X509_V_ERR_SUITE_B_INVALID_VERSION: c_int = 56; -#[cfg(ossl102)] -pub const X509_V_ERR_SUITE_B_INVALID_ALGORITHM: c_int = 57; -#[cfg(ossl102)] -pub const X509_V_ERR_SUITE_B_INVALID_CURVE: c_int = 58; -#[cfg(ossl102)] -pub const X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM: c_int = 59; -#[cfg(ossl102)] -pub const X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED: c_int = 60; -#[cfg(ossl102)] -pub const X509_V_ERR_SUITE_B_CANNOT_SIGN_P_384_WITH_P_256: c_int = 61; -#[cfg(ossl102)] -pub const X509_V_ERR_HOSTNAME_MISMATCH: c_int = 62; -#[cfg(ossl102)] -pub const X509_V_ERR_EMAIL_MISMATCH: c_int = 63; -#[cfg(ossl102)] -pub const X509_V_ERR_IP_ADDRESS_MISMATCH: c_int = 64; -cfg_if! { - if #[cfg(ossl110)] { - pub const X509_V_ERR_DANE_NO_MATCH: c_int = 65; - pub const X509_V_ERR_EE_KEY_TOO_SMALL: c_int = 66; - pub const X509_V_ERR_CA_KEY_TOO_SMALL: c_int = 67; - pub const X509_V_ERR_CA_MD_TOO_WEAK: c_int = 68; - pub const X509_V_ERR_INVALID_CALL: c_int = 69; - pub const X509_V_ERR_STORE_LOOKUP: c_int = 70; - pub const X509_V_ERR_NO_VALID_SCTS: c_int = 71; - } else if #[cfg(ossl102h)] { - pub const X509_V_ERR_INVALID_CALL: c_int = 65; - pub const X509_V_ERR_STORE_LOOKUP: c_int = 66; - pub const X509_V_ERR_PROXY_SUBJECT_NAME_VIOLATION: c_int = 67; - } -} -#[cfg(ossl300)] -pub const X509_V_ERR_INVALID_CA: c_int = 79; - -#[cfg(not(any(ossl110, libressl370)))] -pub const X509_V_FLAG_CB_ISSUER_CHECK: c_ulong = 0x1; -#[cfg(any(ossl110, libressl370))] -pub const X509_V_FLAG_CB_ISSUER_CHECK: c_ulong = 0x0; -pub const X509_V_FLAG_USE_CHECK_TIME: c_ulong = 0x2; -pub const X509_V_FLAG_CRL_CHECK: c_ulong = 0x4; -pub const X509_V_FLAG_CRL_CHECK_ALL: c_ulong = 0x8; -pub const X509_V_FLAG_IGNORE_CRITICAL: c_ulong = 0x10; -pub const X509_V_FLAG_X509_STRICT: c_ulong = 0x20; -pub const X509_V_FLAG_ALLOW_PROXY_CERTS: c_ulong = 0x40; -pub const X509_V_FLAG_POLICY_CHECK: c_ulong = 0x80; -pub const X509_V_FLAG_EXPLICIT_POLICY: c_ulong = 0x100; -pub const X509_V_FLAG_INHIBIT_ANY: c_ulong = 0x200; -pub const X509_V_FLAG_INHIBIT_MAP: c_ulong = 0x400; -pub const X509_V_FLAG_NOTIFY_POLICY: c_ulong = 0x800; -pub const X509_V_FLAG_EXTENDED_CRL_SUPPORT: c_ulong = 0x1000; -pub const X509_V_FLAG_USE_DELTAS: c_ulong = 0x2000; -pub const X509_V_FLAG_CHECK_SS_SIGNATURE: c_ulong = 0x4000; -#[cfg(ossl102)] -pub const X509_V_FLAG_TRUSTED_FIRST: c_ulong = 0x8000; -#[cfg(ossl102)] -pub const X509_V_FLAG_SUITEB_128_LOS_ONLY: c_ulong = 0x10000; -#[cfg(ossl102)] -pub const X509_V_FLAG_SUITEB_192_LOS: c_ulong = 0x20000; -#[cfg(ossl102)] -pub const X509_V_FLAG_SUITEB_128_LOS: c_ulong = 0x30000; -#[cfg(ossl102)] -pub const X509_V_FLAG_PARTIAL_CHAIN: c_ulong = 0x80000; -#[cfg(ossl110)] -pub const X509_V_FLAG_NO_ALT_CHAINS: c_ulong = 0x100000; -#[cfg(ossl110)] -pub const X509_V_FLAG_NO_CHECK_TIME: c_ulong = 0x200000; - -pub unsafe fn X509_LOOKUP_add_dir(ctx: *mut X509_LOOKUP, name: *const c_char, _type: c_int) -> c_int { - const X509_L_ADD_DIR: c_int = 2; - X509_LOOKUP_ctrl(ctx, X509_L_ADD_DIR, name, _type as c_long, std::ptr::null_mut()) -} diff --git a/openssl-sys/src/x509v3.rs b/openssl-sys/src/x509v3.rs deleted file mode 100644 index 5ae4439..0000000 --- a/openssl-sys/src/x509v3.rs +++ /dev/null @@ -1,93 +0,0 @@ -use libc::*; - -use super::*; - -#[repr(C)] -pub struct GENERAL_NAME { - pub type_: c_int, - // FIXME should be a union - pub d: *mut c_void, -} - -stack!(stack_st_GENERAL_NAME); - -pub const GEN_OTHERNAME: c_int = 0; -pub const GEN_EMAIL: c_int = 1; -pub const GEN_DNS: c_int = 2; -pub const GEN_X400: c_int = 3; -pub const GEN_DIRNAME: c_int = 4; -pub const GEN_EDIPARTY: c_int = 5; -pub const GEN_URI: c_int = 6; -pub const GEN_IPADD: c_int = 7; -pub const GEN_RID: c_int = 8; - -#[cfg(any(ossl102, libressl261))] -pub const X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT: c_uint = 0x1; -#[cfg(any(ossl102, libressl261))] -pub const X509_CHECK_FLAG_NO_WILDCARDS: c_uint = 0x2; -#[cfg(any(ossl102, libressl261))] -pub const X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS: c_uint = 0x4; -#[cfg(any(ossl102, libressl261))] -pub const X509_CHECK_FLAG_MULTI_LABEL_WILDCARDS: c_uint = 0x8; -#[cfg(any(ossl102, libressl261))] -pub const X509_CHECK_FLAG_SINGLE_LABEL_SUBDOMAINS: c_uint = 0x10; -#[cfg(ossl110)] -pub const X509_CHECK_FLAG_NEVER_CHECK_SUBJECT: c_uint = 0x20; - -pub const X509V3_ADD_DEFAULT: c_ulong = 0; -pub const X509V3_ADD_APPEND: c_ulong = 1; -pub const X509V3_ADD_REPLACE: c_ulong = 2; -pub const X509V3_ADD_REPLACE_EXISTING: c_ulong = 3; -pub const X509V3_ADD_KEEP_EXISTING: c_ulong = 4; -pub const X509V3_ADD_DELETE: c_ulong = 5; -pub const X509V3_ADD_SILENT: c_ulong = 0x10; - -pub const EXFLAG_BCONS: u32 = 0x1; -pub const EXFLAG_KUSAGE: u32 = 0x2; -pub const EXFLAG_XKUSAGE: u32 = 0x4; -pub const EXFLAG_NSCERT: u32 = 0x8; -pub const EXFLAG_CA: u32 = 0x10; -pub const EXFLAG_SI: u32 = 0x20; -pub const EXFLAG_V1: u32 = 0x40; -pub const EXFLAG_INVALID: u32 = 0x80; -pub const EXFLAG_SET: u32 = 0x100; -pub const EXFLAG_CRITICAL: u32 = 0x200; -pub const EXFLAG_PROXY: u32 = 0x400; -pub const EXFLAG_INVALID_POLICY: u32 = 0x800; -pub const EXFLAG_FRESHEST: u32 = 0x1000; -#[cfg(any(ossl102, libressl261))] -pub const EXFLAG_SS: u32 = 0x2000; - -pub const X509v3_KU_DIGITAL_SIGNATURE: u32 = 0x0080; -pub const X509v3_KU_NON_REPUDIATION: u32 = 0x0040; -pub const X509v3_KU_KEY_ENCIPHERMENT: u32 = 0x0020; -pub const X509v3_KU_DATA_ENCIPHERMENT: u32 = 0x0010; -pub const X509v3_KU_KEY_AGREEMENT: u32 = 0x0008; -pub const X509v3_KU_KEY_CERT_SIGN: u32 = 0x0004; -pub const X509v3_KU_CRL_SIGN: u32 = 0x0002; -pub const X509v3_KU_ENCIPHER_ONLY: u32 = 0x0001; -pub const X509v3_KU_DECIPHER_ONLY: u32 = 0x8000; -pub const X509v3_KU_UNDEF: u32 = 0xffff; - -pub const XKU_SSL_SERVER: u32 = 0x1; -pub const XKU_SSL_CLIENT: u32 = 0x2; -pub const XKU_SMIME: u32 = 0x4; -pub const XKU_CODE_SIGN: u32 = 0x8; -pub const XKU_SGC: u32 = 0x10; -pub const XKU_OCSP_SIGN: u32 = 0x20; -pub const XKU_TIMESTAMP: u32 = 0x40; -pub const XKU_DVCS: u32 = 0x80; -#[cfg(ossl110)] -pub const XKU_ANYEKU: u32 = 0x100; - -pub const X509_PURPOSE_SSL_CLIENT: c_int = 1; -pub const X509_PURPOSE_SSL_SERVER: c_int = 2; -pub const X509_PURPOSE_NS_SSL_SERVER: c_int = 3; -pub const X509_PURPOSE_SMIME_SIGN: c_int = 4; -pub const X509_PURPOSE_SMIME_ENCRYPT: c_int = 5; -pub const X509_PURPOSE_CRL_SIGN: c_int = 6; -pub const X509_PURPOSE_ANY: c_int = 7; -pub const X509_PURPOSE_OCSP_HELPER: c_int = 8; -pub const X509_PURPOSE_TIMESTAMP_SIGN: c_int = 9; -pub const X509_PURPOSE_MIN: c_int = 1; -pub const X509_PURPOSE_MAX: c_int = 9; diff --git a/crypto-glue/src/aes_gmac_siv_openssl.rs b/src/aes_gmac_siv_openssl.rs similarity index 81% rename from crypto-glue/src/aes_gmac_siv_openssl.rs rename to src/aes_gmac_siv_openssl.rs index c898a0b..96eeb07 100644 --- a/crypto-glue/src/aes_gmac_siv_openssl.rs +++ b/src/aes_gmac_siv_openssl.rs @@ -8,7 +8,9 @@ use std::ptr; -use crate::{cipher_ctx::CipherCtx, ZEROES}; +use crate::ZEROES; +use zssp::crypto_impl::openssl_sys as ffi; +use zssp::crypto_impl::CipherCtx; /// AES-GMAC-SIV encryptor/decryptor. pub struct AesGmacSiv { @@ -32,7 +34,7 @@ impl AesGmacSiv { 32 => ffi::EVP_aes_256_gcm(), _ => panic!("Aes KEY_SIZE must be 16, 24 or 32"), }; - gmac.cipher_init::(t, k0.as_ptr(), ptr::null_mut()).unwrap(); + assert!(gmac.cipher_init::(t, k0.as_ptr(), ptr::null_mut())); } let ctr = CipherCtx::new().unwrap(); unsafe { @@ -42,7 +44,7 @@ impl AesGmacSiv { 32 => ffi::EVP_aes_256_ctr(), _ => panic!("Aes KEY_SIZE must be 16, 24 or 32"), }; - ctr.cipher_init::(t, k1.as_ptr(), ptr::null_mut()).unwrap(); + assert!(ctr.cipher_init::(t, k1.as_ptr(), ptr::null_mut())); } let ecb_enc = CipherCtx::new().unwrap(); unsafe { @@ -52,7 +54,7 @@ impl AesGmacSiv { 32 => ffi::EVP_aes_256_ecb(), _ => panic!("Aes KEY_SIZE must be 16, 24 or 32"), }; - ecb_enc.cipher_init::(t, k1.as_ptr(), ptr::null_mut()).unwrap(); + assert!(ecb_enc.cipher_init::(t, k1.as_ptr(), ptr::null_mut())); ffi::EVP_CIPHER_CTX_set_padding(ecb_enc.as_ptr(), 0); } let ecb_dec = CipherCtx::new().unwrap(); @@ -63,7 +65,7 @@ impl AesGmacSiv { 32 => ffi::EVP_aes_256_ecb(), _ => panic!("Aes KEY_SIZE must be 16, 24 or 32"), }; - ecb_dec.cipher_init::(t, k1.as_ptr(), ptr::null_mut()).unwrap(); + assert!(ecb_dec.cipher_init::(t, k1.as_ptr(), ptr::null_mut())); ffi::EVP_CIPHER_CTX_set_padding(ecb_dec.as_ptr(), 0); } @@ -87,9 +89,9 @@ impl AesGmacSiv { self.tag[0..8].copy_from_slice(iv); self.tag[8..12].fill(0); unsafe { - self.gmac - .cipher_init::(ptr::null_mut(), ptr::null_mut(), self.tag[0..12].as_ptr()) - .unwrap(); + assert!(self + .gmac + .cipher_init::(ptr::null_mut(), ptr::null_mut(), self.tag[0..12].as_ptr())); } } @@ -98,11 +100,11 @@ impl AesGmacSiv { #[inline(always)] pub fn encrypt_set_aad(&mut self, data: &[u8]) { unsafe { - self.gmac.update::(data, ptr::null_mut()).unwrap(); + assert!(self.gmac.update::(data, ptr::null_mut())); let mut pad = data.len() & 0xf; if pad != 0 { pad = 16 - pad; - self.gmac.update::(&ZEROES[0..pad], ptr::null_mut()).unwrap(); + assert!(self.gmac.update::(&ZEROES[0..pad], ptr::null_mut())); } } } @@ -112,7 +114,7 @@ impl AesGmacSiv { #[inline(always)] pub fn encrypt_first_pass(&mut self, plaintext: &[u8]) { unsafe { - self.gmac.update::(plaintext, ptr::null_mut()).unwrap(); + assert!(self.gmac.update::(plaintext, ptr::null_mut())); } } @@ -120,8 +122,8 @@ impl AesGmacSiv { #[inline(always)] pub fn encrypt_first_pass_finish(&mut self) { unsafe { - self.gmac.finalize::().unwrap(); - self.gmac.tag(&mut self.tmp).unwrap(); + assert!(self.gmac.finalize::()); + assert!(self.gmac.get_tag(&mut self.tmp)); } self.tag[8] = self.tmp[0] ^ self.tmp[8]; @@ -136,7 +138,7 @@ impl AesGmacSiv { let mut tag_tmp = [0_u8; 16]; unsafe { - self.ecb_enc.update::(&self.tag, tag_tmp.as_mut_ptr()).unwrap(); + assert!(self.ecb_enc.update::(&self.tag, tag_tmp.as_mut_ptr())); } self.tag.copy_from_slice(&tag_tmp); self.tmp.copy_from_slice(&tag_tmp); @@ -144,9 +146,9 @@ impl AesGmacSiv { self.tmp[12] &= 0x7f; unsafe { - self.ctr - .cipher_init::(ptr::null_mut(), ptr::null_mut(), self.tmp.as_ptr()) - .unwrap(); + assert!(self + .ctr + .cipher_init::(ptr::null_mut(), ptr::null_mut(), self.tmp.as_ptr())); } } @@ -155,7 +157,7 @@ impl AesGmacSiv { #[inline(always)] pub fn encrypt_second_pass(&mut self, plaintext: &[u8], ciphertext: &mut [u8]) { unsafe { - self.ctr.update::(plaintext, ciphertext.as_mut_ptr()).unwrap(); + assert!(self.ctr.update::(plaintext, ciphertext.as_mut_ptr())); } } @@ -165,7 +167,7 @@ impl AesGmacSiv { pub fn encrypt_second_pass_in_place(&mut self, plaintext_to_ciphertext: &mut [u8]) { unsafe { let out = plaintext_to_ciphertext.as_mut_ptr(); - self.ctr.update::(plaintext_to_ciphertext, out).unwrap(); + assert!(self.ctr.update::(plaintext_to_ciphertext, out)); } } @@ -184,23 +186,23 @@ impl AesGmacSiv { self.tmp[12] &= 0x7f; unsafe { - self.ctr - .cipher_init::(ptr::null_mut(), ptr::null_mut(), self.tmp.as_ptr()) - .unwrap(); + assert!(self + .ctr + .cipher_init::(ptr::null_mut(), ptr::null_mut(), self.tmp.as_ptr())); } let mut tag_tmp = [0_u8; 16]; unsafe { - self.ecb_dec.update::(tag, tag_tmp.as_mut_ptr()).unwrap(); + assert!(self.ecb_dec.update::(tag, tag_tmp.as_mut_ptr())); } self.tag.copy_from_slice(&tag_tmp); tag_tmp[8..12].fill(0); unsafe { - self.gmac - .cipher_init::(ptr::null_mut(), ptr::null_mut(), tag_tmp.as_ptr()) - .unwrap(); + assert!(self + .gmac + .cipher_init::(ptr::null_mut(), ptr::null_mut(), tag_tmp.as_ptr())); } } @@ -215,8 +217,8 @@ impl AesGmacSiv { #[inline(always)] pub fn decrypt(&mut self, ciphertext: &[u8], plaintext: &mut [u8]) { unsafe { - self.ctr.update::(ciphertext, plaintext.as_mut_ptr()).unwrap(); - self.gmac.update::(plaintext, ptr::null_mut()).unwrap(); + assert!(self.ctr.update::(ciphertext, plaintext.as_mut_ptr())); + assert!(self.gmac.update::(plaintext, ptr::null_mut())); } } @@ -235,8 +237,8 @@ impl AesGmacSiv { #[inline(always)] pub fn decrypt_finish(&mut self) -> Option<&[u8; 16]> { unsafe { - self.gmac.finalize::().unwrap(); - self.gmac.tag(&mut self.tmp).unwrap(); + assert!(self.gmac.finalize::()); + assert!(self.gmac.get_tag(&mut self.tmp)); } if (self.tag[8] == self.tmp[0] ^ self.tmp[8]) && (self.tag[9] == self.tmp[1] ^ self.tmp[9]) diff --git a/src/aes_openssl.rs b/src/aes_openssl.rs new file mode 100644 index 0000000..daf5efe --- /dev/null +++ b/src/aes_openssl.rs @@ -0,0 +1,86 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * (c) ZeroTier, Inc. + * https://www.zerotier.com/ + */ + +use std::ptr; + +use zssp::crypto::*; +use zssp::crypto_impl::openssl_sys as ffi; + +use zssp::crypto_impl::CipherCtx; + +/// An OpenSSL AES_GCM context. Automatically frees itself on drop. +/// The current interface is custom made for ZeroTier, but could easily be adapted for other uses. +/// Whether `ENCRYPT` is true or false decides respectively whether this context encrypts or decrypts. +/// Even though OpenSSL lets you set this dynamically almost no operations work when you do this +/// without resetting the context. +/// +/// This object cannot be mutated by multiple threads at the same time so wrap it in a Mutex if +/// you need to do this. As far as I have read a Mutex can safely implement Send and Sync. +pub struct AesGcm(CipherCtx); + +impl AesGcm { + /// Create an AesGcm context with the given key. + /// OpenSSL internally processes and caches this key, so it is recommended to reuse this context whenever encrypting under the same key. Call `reset_init_gcm` to change the IV for each reuse. + pub fn new(key: &[u8; AES_256_KEY_SIZE]) -> Self { + let ctx = CipherCtx::new().unwrap(); + unsafe { + let t = ffi::EVP_aes_256_gcm(); + assert!(ctx.cipher_init::(t, key.as_ptr(), ptr::null())); + ffi::EVP_CIPHER_CTX_set_padding(ctx.as_ptr(), 0); + } + + AesGcm(ctx) + } + + /// Set the IV of this AesGcm context. This call resets the IV but leaves the key and encryption algorithm alone. + /// This method must be called before any other method on AesGcm. + /// `iv` must be exactly 12 bytes in length, because that is what Aes supports. + pub fn reset_iv(&mut self, iv: &[u8]) { + unsafe { + assert!(self.0.cipher_init::(ptr::null(), ptr::null(), iv.as_ptr())); + } + } + + /// Add additional authentication data to AesGcm (same operation with CTR mode). + #[inline(always)] + pub fn set_aad(&mut self, aad: &[u8]) { + unsafe { assert!(self.0.update::(aad, ptr::null_mut())) }; + } + + /// Encrypt or decrypt (same operation with CTR mode) + #[inline(always)] + pub fn crypt(&mut self, input: &[u8], output: &mut [u8]) { + unsafe { assert!(self.0.update::(input, output.as_mut_ptr())) }; + } + + /// Encrypt or decrypt in place (same operation with CTR mode). + #[inline(always)] + pub fn crypt_in_place(&mut self, data: &mut [u8]) { + let ptr = data.as_mut_ptr(); + unsafe { assert!(self.0.update::(data, ptr)) } + } +} +impl AesGcm { + /// Produce the gcm authentication tag. + #[inline(always)] + pub fn finish_encrypt(&mut self, output: &mut [u8; AES_GCM_TAG_SIZE]) { + unsafe { + assert!(self.0.finalize::()); + assert!(self.0.get_tag(output)); + } + } +} +impl AesGcm { + /// Check the gcm authentication tag. Outputs true if it matches the just decrypted message, outputs false otherwise. + #[inline(always)] + pub fn finish_decrypt(&mut self, expected_tag: &[u8; AES_GCM_TAG_SIZE]) -> bool { + unsafe { self.0.set_tag(expected_tag) && self.0.finalize::() } + } +} + +/* Start of ZSSP Impl */ diff --git a/crypto-glue/src/aes_tests.rs b/src/aes_tests.rs similarity index 99% rename from crypto-glue/src/aes_tests.rs rename to src/aes_tests.rs index 2f49e39..2c2b7a3 100644 --- a/crypto-glue/src/aes_tests.rs +++ b/src/aes_tests.rs @@ -12,7 +12,6 @@ mod test { use crate::aes_gmac_siv::AesGmacSiv; use hex_literal::hex; use std::time::SystemTime; - use zssp::crypto::aes_gcm::{AesGcmDec, AesGcmEnc}; fn to_hex(b: &[u8]) -> String { let mut s = String::new(); @@ -35,32 +34,32 @@ mod test { let mut cipher_out = [0u8; 127]; let mut plain_out = [0u8; 127]; - enc.set_iv(&iv0); - enc.encrypt(&plain, &mut cipher_out); + enc.reset_iv(&iv0); + enc.crypt(&plain, &mut cipher_out); enc.finish_encrypt(&mut tag_out); - dec.set_iv(&iv0); - dec.decrypt(&cipher_out, &mut plain_out); + dec.reset_iv(&iv0); + dec.crypt(&cipher_out, &mut plain_out); assert!(dec.finish_decrypt(&tag_out)); assert_eq!(plain, plain_out); - enc.set_iv(&iv1); - enc.encrypt(&plain, &mut cipher_out); + enc.reset_iv(&iv1); + enc.crypt(&plain, &mut cipher_out); enc.finish_encrypt(&mut tag_out); - dec.set_iv(&iv1); - dec.decrypt(&cipher_out, &mut plain_out); + dec.reset_iv(&iv1); + dec.crypt(&cipher_out, &mut plain_out); assert!(dec.finish_decrypt(&tag_out)); assert_eq!(plain, plain_out); - enc.set_iv(&iv0); - enc.encrypt(&plain, &mut cipher_out); + enc.reset_iv(&iv0); + enc.crypt(&plain, &mut cipher_out); enc.finish_encrypt(&mut tag_out); - dec.set_iv(&iv1); - dec.decrypt(&cipher_out, &mut plain_out); + dec.reset_iv(&iv1); + dec.crypt(&cipher_out, &mut plain_out); assert!(!dec.finish_decrypt(&tag_out)); } @@ -77,8 +76,8 @@ mod test { let benchmark_iterations: usize = 80000; let start = SystemTime::now(); for _ in 0..benchmark_iterations { - c.set_iv(&iv); - c.encrypt_in_place(&mut buf); + c.reset_iv(&iv); + c.crypt_in_place(&mut buf); } let duration = SystemTime::now().duration_since(start).unwrap(); println!( @@ -90,8 +89,8 @@ mod test { let start = SystemTime::now(); for _ in 0..benchmark_iterations { - c.set_iv(&iv); - c.decrypt_in_place(&mut buf); + c.reset_iv(&iv); + c.crypt_in_place(&mut buf); } let duration = SystemTime::now().duration_since(start).unwrap(); println!( @@ -106,25 +105,25 @@ mod test { let mut tag = [0u8; 16]; for tv in NIST_AES_GCM_TEST_VECTORS.iter() { let mut gcm = AesGcm::::new(&tv.key); - gcm.set_iv(tv.nonce); + gcm.reset_iv(tv.nonce); gcm.set_aad(tv.aad); let mut ciphertext = Vec::new(); ciphertext.resize(tv.plaintext.len(), 0); - gcm.encrypt(tv.plaintext, ciphertext.as_mut()); + gcm.crypt(tv.plaintext, ciphertext.as_mut()); gcm.finish_encrypt(&mut tag); assert!(tag.eq(tv.tag)); assert!(ciphertext.as_slice().eq(tv.ciphertext)); let mut gcm = AesGcm::::new(&tv.key); - gcm.set_iv(tv.nonce); + gcm.reset_iv(tv.nonce); gcm.set_aad(tv.aad); let mut ct_copy = ciphertext.clone(); - gcm.decrypt_in_place(ct_copy.as_mut()); + gcm.crypt_in_place(ct_copy.as_mut()); assert!(gcm.finish_decrypt(&tag)); - gcm.set_iv(tv.nonce); + gcm.reset_iv(tv.nonce); gcm.set_aad(tv.aad); - gcm.decrypt_in_place(ciphertext.as_mut()); + gcm.crypt_in_place(ciphertext.as_mut()); tag[0] ^= 1; assert!(!gcm.finish_decrypt(&tag)); } diff --git a/crypto-glue/src/hash.rs b/src/hash.rs similarity index 93% rename from crypto-glue/src/hash.rs rename to src/hash.rs index 4b24367..51c28ed 100644 --- a/crypto-glue/src/hash.rs +++ b/src/hash.rs @@ -12,7 +12,8 @@ use std::mem::MaybeUninit; use std::os::raw::{c_int, c_uint}; use std::ptr::null; -use zssp::crypto::sha512; +use zssp::crypto::{Sha512Hash, Sha512Hmac}; +use zssp::crypto_impl::openssl_sys as ffi; pub const SHA512_HASH_SIZE: usize = 64; pub const HMAC_SHA512_SIZE: usize = 64; @@ -20,7 +21,6 @@ pub const SHA384_HASH_SIZE: usize = 48; pub const HMAC_SHA384_SIZE: usize = 48; pub struct SHA512(ffi::SHA512_CTX); - impl SHA512 { #[inline(always)] pub fn hash(data: &[u8]) -> [u8; SHA512_HASH_SIZE] { @@ -72,7 +72,6 @@ impl SHA512 { } } } - impl Write for SHA512 { #[inline(always)] fn write(&mut self, b: &[u8]) -> std::io::Result { @@ -87,23 +86,7 @@ impl Write for SHA512 { } unsafe impl Send for SHA512 {} -impl sha512::Sha512 for SHA512 { - fn new() -> Self { - SHA512::new() - } - fn reset(&mut self) { - self.reset() - } - fn update(&mut self, input: &[u8]) { - self.update(input) - } - fn finish(&mut self, output: &mut [u8; sha512::SHA512_HASH_SIZE]) { - self.finish_into(output) - } -} - pub struct SHA384(ffi::SHA512_CTX); - impl SHA384 { #[inline(always)] pub fn hash(data: &[u8]) -> [u8; SHA384_HASH_SIZE] { @@ -153,7 +136,6 @@ impl SHA384 { } } } - impl Write for SHA384 { #[inline(always)] fn write(&mut self, b: &[u8]) -> std::io::Result { @@ -166,10 +148,8 @@ impl Write for SHA384 { Ok(()) } } - unsafe impl Send for SHA384 {} -//#[link(name="crypto")] extern "C" { fn HMAC_CTX_new() -> *mut c_void; fn HMAC_CTX_reset(ctx: *mut c_void) -> c_int; @@ -191,7 +171,6 @@ pub struct HMACSHA512 { ctx: *mut c_void, evp_md: *const c_void, } - impl HMACSHA512 { #[inline(always)] pub fn new(key: &[u8]) -> Self { @@ -241,7 +220,6 @@ impl HMACSHA512 { tmp } } - impl Drop for HMACSHA512 { #[inline(always)] fn drop(&mut self) { @@ -250,26 +228,10 @@ impl Drop for HMACSHA512 { } unsafe impl Send for HMACSHA512 {} -impl sha512::HmacSha512 for HMACSHA512 { - fn new() -> Self { - HMACSHA512::new(&[]) - } - fn reset(&mut self, key: &[u8]) { - self.reset(key) - } - fn update(&mut self, input: &[u8]) { - self.update(input) - } - fn finish(&mut self, output: &mut [u8; sha512::SHA512_HASH_SIZE]) { - *output = self.finish() - } -} - pub struct HMACSHA384 { ctx: *mut c_void, evp_md: *const c_void, } - impl HMACSHA384 { #[inline(always)] pub fn new(key: &[u8]) -> Self { @@ -319,14 +281,12 @@ impl HMACSHA384 { tmp } } - impl Drop for HMACSHA384 { #[inline(always)] fn drop(&mut self) { unsafe { HMAC_CTX_free(self.ctx) }; } } - unsafe impl Send for HMACSHA384 {} #[inline(always)] @@ -335,3 +295,32 @@ pub fn hmac_sha384(key: &[u8], msg: &[u8]) -> [u8; HMAC_SHA384_SIZE] { hm.update(msg); hm.finish() } + +/* Start of ZSSP Impl */ + +impl Sha512Hmac for HMACSHA512 { + fn new() -> Self { + HMACSHA512::new(&[]) + } + + fn hash(&mut self, key: &[u8], full_input: &[u8], output: &mut [u8; SHA512_HASH_SIZE]) { + self.reset(key); + self.update(full_input); + self.finish_into(output); + } +} + +impl Sha512Hash for SHA512 { + fn new() -> Self { + SHA512::new() + } + + fn update(&mut self, data: &[u8]) { + self.update(data); + } + + fn finish_and_reset(&mut self, output: &mut [u8; SHA512_HASH_SIZE]) { + self.finish_into(output); + self.reset(); + } +} diff --git a/crypto-glue/src/lib.rs b/src/lib.rs similarity index 69% rename from crypto-glue/src/lib.rs rename to src/lib.rs index ad21bd8..729c562 100644 --- a/crypto-glue/src/lib.rs +++ b/src/lib.rs @@ -6,45 +6,31 @@ * https://www.zerotier.com/ */ -mod cipher_ctx; -mod error; +//mod error; +mod aes_tests; pub mod hash; pub mod p384; pub mod random; -pub mod secret; pub mod poly1305; pub mod salsa; pub mod typestate; pub mod x25519; -#[cfg(target_os = "macos")] -pub mod aes_fruity; -#[cfg(target_os = "macos")] -pub use aes_fruity as aes; - -#[cfg(not(target_os = "macos"))] pub mod aes_openssl; -#[cfg(not(target_os = "macos"))] pub use aes_openssl as aes; -mod aes_tests; - -//#[cfg(target_os = "macos")] -//pub mod aes_gmac_siv_fruity; -//#[cfg(target_os = "macos")] -//pub use aes_gmac_siv_fruity as aes_gmac_siv; - -//#[cfg(not(target_os = "macos"))] pub mod aes_gmac_siv_openssl; -//#[cfg(not(target_os = "macos"))] pub use aes_gmac_siv_openssl as aes_gmac_siv; -use ctor::ctor; +/// Dependency re-exports +pub use zssp; + +use ctor::ctor; #[ctor] fn openssl_init() { - ffi::init(); + zssp::crypto_impl::openssl_sys::init(); } /// Constant time byte slice equality. diff --git a/crypto-glue/src/p384.rs b/src/p384.rs similarity index 79% rename from crypto-glue/src/p384.rs rename to src/p384.rs index 1dc0026..6cc9b06 100644 --- a/crypto-glue/src/p384.rs +++ b/src/p384.rs @@ -11,19 +11,46 @@ use std::os::raw::{c_int, c_ulong, c_void}; use std::sync::Mutex; use std::{mem, ptr}; -use crate::error::{cvt, cvt_n, cvt_p, ErrorStack}; +//use crate::error::{cvt, cvt_n, cvt_p, ErrorStack}; use crate::hash::SHA384; -use crate::secret::Secret; use crate::secure_eq; use once_cell::sync::Lazy; -use zssp::crypto::p384; +use rand_xoshiro::rand_core::{CryptoRng, RngCore}; +use zssp::crypto_impl::openssl_sys as ffi; pub const P384_PUBLIC_KEY_SIZE: usize = 49; pub const P384_SECRET_KEY_SIZE: usize = 48; pub const P384_ECDSA_SIGNATURE_SIZE: usize = 96; pub const P384_ECDH_SHARED_SECRET_SIZE: usize = 48; +#[inline] +pub fn check_ptr(r: *mut T) -> Result<*mut T, ()> { + if r.is_null() { + Err(()) + } else { + Ok(r) + } +} + +#[inline] +pub fn check_gtz(r: c_int) -> Result { + if r <= 0 { + Err(()) + } else { + Ok(r) + } +} + +#[inline] +pub fn check_gteqz(r: c_int) -> Result { + if r < 0 { + Err(()) + } else { + Ok(r) + } +} + extern "C" { fn ECDH_compute_key( out: *mut u8, @@ -74,7 +101,7 @@ impl P384PublicKey { let s = OSSLBN::from_slice(&signature[CAP..]); if let (Ok(r), Ok(s)) = (r, s) { // Create the OpenSSL object that actually supports verification. - if let Ok(sig) = cvt_p(ffi::ECDSA_SIG_new()) { + if let Ok(sig) = check_ptr(ffi::ECDSA_SIG_new()) { let is_valid = if ffi::ECDSA_SIG_set0(sig, r.0, s.0) == 1 { // For some reason this one random function, `ECDSA_SIG_set0`, takes // ownership of its parameters. I've double checked and it is the only one @@ -135,22 +162,19 @@ impl P384KeyPair { unsafe { let pair = OSSLKey::new().unwrap(); // Ask OpenSSL to securely generate the keypair. - cvt(ffi::EC_KEY_generate_key(pair.0)).unwrap(); + check_gtz(ffi::EC_KEY_generate_key(pair.0)).unwrap(); // Read out the raw public key into a buffer. let public_key = ffi::EC_KEY_get0_public_key(pair.0); let mut buffer = [0_u8; P384_PUBLIC_KEY_SIZE]; let bnc = OSSLBNC::new().unwrap(); - let len = ffi::EC_POINT_point2oct( + assert!(ffi::EC_POINT_point2oct( GROUP_P384.0, public_key, ffi::point_conversion_form_t::POINT_CONVERSION_COMPRESSED, buffer.as_mut_ptr(), P384_PUBLIC_KEY_SIZE, bnc.0, - ); - if len <= 0 { - Err::<(), _>(ErrorStack::get()).unwrap(); - } + ) > 0); Self { pair: Mutex::new(pair), pub_bytes: buffer } } } @@ -166,7 +190,7 @@ impl P384KeyPair { let private = OSSLBN::from_slice(secret_bytes).ok()?; // Tell OpenSSL to assign the private key to the public key. // This makes the public key into a proper keypair. - if cvt(ffi::EC_KEY_set_private_key(pair.0, private.0)).is_ok() { + if check_gtz(ffi::EC_KEY_set_private_key(pair.0, private.0)).is_ok() { // Get OpenSSL to double check if this final key makes sense. // It will be read-only after this point. if ffi::EC_KEY_check_key(pair.0) == 1 { @@ -194,19 +218,17 @@ impl P384KeyPair { /// They are wrapped in a container which will erase them on drop. /// /// **Only write these to 100% trusted storage mediums. Avoid calling this function in general.** - pub fn secret_key_bytes(&self) -> Secret { + pub fn secret_key_bytes(&self, output: &mut [u8; P384_SECRET_KEY_SIZE]) { unsafe { - let mut tmp: Secret = Secret::default(); let keypair = self.pair.lock().unwrap(); // Get a temporary handle to the private key. let ptr = ffi::EC_KEY_get0_private_key(keypair.0); // Read the key's raw bytes out of OpenSSL. - let size = cvt_n(ffi::BN_bn2bin(ptr, tmp.as_bytes_mut().as_mut_ptr())).unwrap() as usize; + let size = check_gteqz(ffi::BN_bn2bin(ptr, output.as_mut_ptr())).unwrap() as usize; drop(keypair); // Double check big-endian-ness. - tmp.0.copy_within(..size, P384_SECRET_KEY_SIZE - size); - tmp + output.copy_within(..size, P384_SECRET_KEY_SIZE - size); } } @@ -217,7 +239,7 @@ impl P384KeyPair { unsafe { let keypair = self.pair.lock().unwrap(); // Actually create the signature with ECDSA. - let sig = cvt_p(ffi::ECDSA_do_sign(data.as_ptr(), data.len() as c_int, keypair.0)); + let sig = check_ptr(ffi::ECDSA_do_sign(data.as_ptr(), data.len() as c_int, keypair.0)); drop(keypair); let sig = sig.unwrap(); @@ -227,7 +249,7 @@ impl P384KeyPair { ffi::ECDSA_SIG_get0(sig, &mut r, &mut s); if r.is_null() || s.is_null() { ffi::ECDSA_SIG_free(sig); - Err::<(), _>(ErrorStack::get()).unwrap(); + assert!(false); } // Determine the size of the buffers to guarantee sanity and big-endian-ness. let r_len = ((ffi::BN_num_bits(r) + 7) / 8) as usize; @@ -235,7 +257,7 @@ impl P384KeyPair { const CAP: usize = P384_ECDSA_SIGNATURE_SIZE / 2; if !(r_len > 0 && s_len > 0 && r_len <= CAP && s_len <= CAP) { ffi::ECDSA_SIG_free(sig); - Err::<(), _>(ErrorStack::get()).unwrap(); + assert!(false); } let mut b = [0_u8; P384_ECDSA_SIGNATURE_SIZE]; @@ -253,24 +275,18 @@ impl P384KeyPair { /// Perform ECDH key agreement, returning the raw (un-hashed!) ECDH secret. /// /// This secret should not be used directly. It should be hashed and perhaps used in a KDF. - pub fn agree(&self, other_public: &P384PublicKey) -> Option> { + pub fn agree(&self, other_public: &P384PublicKey, output: &mut [u8; P384_ECDH_SHARED_SECRET_SIZE]) -> bool { let keypair = self.pair.lock().unwrap(); let other_key = other_public.key.lock().unwrap(); unsafe { - let mut s: Secret = Secret::default(); // Ask OpenSSL to perform DH between the keypair and the other key's public key object. - if ECDH_compute_key( - s.as_bytes_mut().as_mut_ptr(), + ECDH_compute_key( + output.as_mut_ptr(), P384_ECDH_SHARED_SECRET_SIZE as c_ulong, ffi::EC_KEY_get0_public_key(other_key.0), keypair.0, ptr::null(), ) == P384_ECDH_SHARED_SECRET_SIZE as c_int - { - Some(s) - } else { - None - } } } } @@ -278,8 +294,8 @@ impl P384KeyPair { /// OpenSSL wrapper for a BN_CTX handle that guarantees free will be called. struct OSSLBNC(*mut ffi::BN_CTX); impl OSSLBNC { - unsafe fn new() -> Result { - cvt_p(ffi::BN_CTX_new()).map(Self) + unsafe fn new() -> Result { + check_ptr(ffi::BN_CTX_new()).map(Self) } } impl Drop for OSSLBNC { @@ -294,8 +310,8 @@ struct OSSLBN(*mut ffi::BIGNUM); impl OSSLBN { /// We would use OpenSSL's newer API for p384 if it actually supported raw byte encodings of keys. /// Until then we are stuck with the old API. - unsafe fn from_slice(n: &[u8]) -> Result { - cvt_p(ffi::BN_bin2bn(n.as_ptr(), n.len() as c_int, ptr::null_mut())).map(Self) + unsafe fn from_slice(n: &[u8]) -> Result { + check_ptr(ffi::BN_bin2bn(n.as_ptr(), n.len() as c_int, ptr::null_mut())).map(Self) } } impl Drop for OSSLBN { @@ -309,21 +325,21 @@ impl Drop for OSSLBN { struct OSSLKey(*mut ffi::EC_KEY); impl OSSLKey { /// Create an empty key, guaranteeing to the caller it has the correct group and will be freed. - unsafe fn new() -> Result { - let key = cvt_p(ffi::EC_KEY_new())?; - cvt(ffi::EC_KEY_set_group(key, GROUP_P384.0))?; + unsafe fn new() -> Result { + let key = check_ptr(ffi::EC_KEY_new())?; + check_gtz(ffi::EC_KEY_set_group(key, GROUP_P384.0))?; Ok(Self(key)) } /// Create a key, guaranteeing to the caller it has the correct group, has a public key and will be freed. /// /// We would use OpenSSL's newer API for p384 if it actually supported raw byte encodings of keys. /// Until then we are stuck with the old API. - unsafe fn pub_from_slice(buffer: &[u8]) -> Result> { + unsafe fn pub_from_slice(buffer: &[u8]) -> Result { /// The public key is an ec_point, we need to be sure we free its memory struct Point(*mut ffi::EC_POINT); impl Point { - unsafe fn new() -> Result { - cvt_p(ffi::EC_POINT_new(GROUP_P384.0)).map(Self) + unsafe fn new() -> Result { + check_ptr(ffi::EC_POINT_new(GROUP_P384.0)).map(Self) } } impl Drop for Point { @@ -336,7 +352,7 @@ impl OSSLKey { let bnc = OSSLBNC::new()?; let point = Point::new()?; // Ask OpenSSL to read the raw bytes into the OpenSSL object. - cvt(ffi::EC_POINT_oct2point( + check_gtz(ffi::EC_POINT_oct2point( GROUP_P384.0, point.0, buffer.as_ptr(), @@ -344,24 +360,24 @@ impl OSSLKey { bnc.0, ))?; // Check if the object is valid. - if cvt_n(ffi::EC_POINT_is_on_curve(GROUP_P384.0, point.0, bnc.0))? == 1 { + if check_gteqz(ffi::EC_POINT_is_on_curve(GROUP_P384.0, point.0, bnc.0))? == 1 { // Create an OpenSSL key and guarantee to the caller that the key was initialized with a // public key. let ec_key = OSSLKey::new()?; - cvt(ffi::EC_KEY_set_public_key(ec_key.0, point.0))?; + check_gtz(ffi::EC_KEY_set_public_key(ec_key.0, point.0))?; Ok(ec_key) } else { - Err(None) + Err(()) } } /// Create a `Send`-able clone of the public key. We don't reference count for this reason. - fn clone_public(&self) -> Result { + fn clone_public(&self) -> Result { unsafe { let point = ffi::EC_KEY_get0_public_key(self.0); // Create an OpenSSL key and guarantee to the caller that the key was initialized with a // public key. let key = OSSLKey::new()?; - cvt(ffi::EC_KEY_set_public_key(key.0, point))?; + check_gtz(ffi::EC_KEY_set_public_key(key.0, point))?; Ok(key) } } @@ -379,43 +395,42 @@ struct OSSLGroup(*mut ffi::EC_GROUP); unsafe impl Send for OSSLGroup {} unsafe impl Sync for OSSLGroup {} static GROUP_P384: Lazy = - Lazy::new(|| unsafe { OSSLGroup(cvt_p(ffi::EC_GROUP_new_by_curve_name(ffi::NID_secp384r1)).unwrap()) }); + Lazy::new(|| unsafe { OSSLGroup(check_ptr(ffi::EC_GROUP_new_by_curve_name(ffi::NID_secp384r1)).unwrap()) }); -impl p384::P384PublicKey for P384PublicKey { - fn from_bytes(raw_key: &[u8; p384::P384_PUBLIC_KEY_SIZE]) -> Option { +/* Start of ZSSP Impl */ + +impl zssp::crypto::P384PublicKey for P384PublicKey { + fn from_bytes(raw_key: &[u8; P384_PUBLIC_KEY_SIZE]) -> Option { Self::from_bytes(raw_key) } - fn as_bytes(&self) -> &[u8; p384::P384_PUBLIC_KEY_SIZE] { - self.as_bytes() + fn to_bytes(&self) -> [u8; P384_PUBLIC_KEY_SIZE] { + self.bytes } } -impl p384::P384KeyPair for P384KeyPair { +impl zssp::crypto::P384KeyPair for P384KeyPair { type PublicKey = P384PublicKey; - type Rng = super::random::SecureRandom; - fn generate(_: &mut Self::Rng) -> Self { + fn generate(_: &mut Rng) -> Self { Self::generate() } - fn public_key_bytes(&self) -> &[u8; p384::P384_PUBLIC_KEY_SIZE] { - self.public_key_bytes() + fn public_key_bytes(&self) -> [u8; P384_PUBLIC_KEY_SIZE] { + *self.public_key_bytes() } - fn agree(&self, other_public: &P384PublicKey, output: &mut [u8; p384::P384_ECDH_SHARED_SECRET_SIZE]) -> bool { - if let Some(s) = self.agree(other_public) { - *output = s.0; - true - } else { - false - } + fn agree(&self, other_public: &P384PublicKey, output: &mut [u8; P384_ECDH_SHARED_SECRET_SIZE]) -> bool { + self.agree(other_public, output) } } #[cfg(test)] mod tests { - use crate::{p384::P384KeyPair, secure_eq}; + use crate::{ + p384::{P384KeyPair, P384_ECDH_SHARED_SECRET_SIZE, P384_SECRET_KEY_SIZE}, + secure_eq, + }; #[test] fn generate_sign_verify_agree() { @@ -432,21 +447,25 @@ mod tests { panic!("ECDSA verify succeeded for incorrect message"); } - let sec0 = kp.agree(&kp2_pub).unwrap(); - let sec1 = kp2.agree(&kp_pub).unwrap(); + let mut sec0 = [0u8; P384_ECDH_SHARED_SECRET_SIZE]; + let mut sec1 = [0u8; P384_ECDH_SHARED_SECRET_SIZE]; + assert!(kp.agree(&kp2_pub, &mut sec0)); + assert!(kp2.agree(&kp_pub, &mut sec1)); if !secure_eq(&sec0, &sec1) { panic!("ECDH secrets do not match"); } let pkb = kp.public_key_bytes(); - let skb = kp.secret_key_bytes(); + let mut skb = [0u8; P384_SECRET_KEY_SIZE]; + kp.secret_key_bytes(&mut skb); let kp3 = P384KeyPair::from_bytes(pkb, skb.as_ref()).unwrap(); + let mut skb3 = [0u8; P384_SECRET_KEY_SIZE]; let pkb3 = kp3.public_key_bytes(); - let skb3 = kp3.secret_key_bytes(); + kp.secret_key_bytes(&mut skb3); assert_eq!(pkb, pkb3); - assert_eq!(skb.as_bytes(), skb3.as_bytes()); + assert_eq!(skb, skb3); let sig = kp3.sign(&[3_u8; 16]); if !kp_pub.verify(&[3_u8; 16], &sig) { diff --git a/crypto-glue/src/poly1305.rs b/src/poly1305.rs similarity index 100% rename from crypto-glue/src/poly1305.rs rename to src/poly1305.rs diff --git a/src/random.rs b/src/random.rs new file mode 100644 index 0000000..1b6c472 --- /dev/null +++ b/src/random.rs @@ -0,0 +1,105 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * (c) ZeroTier, Inc. + * https://www.zerotier.com/ + */ + +use std::sync::Mutex; +use zssp::crypto_impl::openssl_sys::*; + +use libc::c_int; +use once_cell::unsync::Lazy; +use rand_xoshiro::rand_core::{CryptoRng, Error, RngCore, SeedableRng}; + +pub use rand_xoshiro::rand_core; +/// This crate contains the most modern, feature rich and high-quality variants of the Xorshift family of random +/// number generators. +/// While they are not cryptographically secure, they are also faster and several times harder to +/// reverse than Xorshift64, so I think we should prefer them. +/// I read the source of this crate and it is low level and efficient. +pub use rand_xoshiro; +/// Xoshiro256** according to my benchmarking is surprisingly twice as fast as vanilla +/// Xorshift64 because there are fewer dependency chains in Xoshiro256** compared to Xorshift64. +pub use rand_xoshiro::Xoshiro256StarStar; + +/// Fill buffer with cryptographically strong pseudo-random bytes. +#[derive(Default, Clone, Copy)] +pub struct SecureRandom; +impl SecureRandom { + pub fn get_bytes(&mut self) -> [u8; SIZE] { + let mut dest = [0u8; SIZE]; + self.fill_bytes(&mut dest); + dest + } + pub fn create_xorshift(&mut self) -> Xoshiro256StarStar { + Xoshiro256StarStar::from_rng(self).unwrap() + } +} +impl RngCore for SecureRandom { + fn next_u32(&mut self) -> u32 { + let mut tmp = [0u8; 4]; + self.fill_bytes(&mut tmp); + u32::from_ne_bytes(tmp) + } + + fn next_u64(&mut self) -> u64 { + let mut tmp = [0u8; 8]; + self.fill_bytes(&mut tmp); + u64::from_ne_bytes(tmp) + } + + fn fill_bytes(&mut self, dest: &mut [u8]) { + unsafe { + debug_assert!(dest.len() <= c_int::max_value() as usize); + assert!(RAND_bytes(dest.as_mut_ptr(), dest.len() as c_int) > 0); + } + } + + fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { + self.fill_bytes(dest); + Ok(()) + } +} +impl CryptoRng for SecureRandom {} +unsafe impl Sync for SecureRandom {} +unsafe impl Send for SecureRandom {} + +/// A global Xoshiro256** wrapped in a mutex and a OnceCell. +/// Unsync OnceCell is just a wrapped `Option<>` and is very fast. +/// Also OnceCell is about to be stabilized into Rust std. +static GLOBAL_XORSHIFT: Mutex> = + Mutex::new(Lazy::new(|| SecureRandom.create_xorshift())); + +pub struct XorshiftRandom; +impl XorshiftRandom { + pub fn get_bytes(&mut self) -> [u8; COUNT] { + let mut tmp = [0u8; COUNT]; + self.fill_bytes(&mut tmp); + tmp + } + pub fn create_xorshift(&mut self) -> Xoshiro256StarStar { + let mut state = GLOBAL_XORSHIFT.lock().unwrap(); + let ret = state.clone(); + state.jump(); + ret + } +} +impl RngCore for XorshiftRandom { + fn next_u32(&mut self) -> u32 { + GLOBAL_XORSHIFT.lock().unwrap().next_u32() + } + + fn next_u64(&mut self) -> u64 { + GLOBAL_XORSHIFT.lock().unwrap().next_u64() + } + + fn fill_bytes(&mut self, dest: &mut [u8]) { + GLOBAL_XORSHIFT.lock().unwrap().fill_bytes(dest); + } + + fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error> { + GLOBAL_XORSHIFT.lock().unwrap().try_fill_bytes(dest) + } +} diff --git a/crypto-glue/src/salsa.rs b/src/salsa.rs similarity index 100% rename from crypto-glue/src/salsa.rs rename to src/salsa.rs diff --git a/crypto-glue/src/typestate.rs b/src/typestate.rs similarity index 100% rename from crypto-glue/src/typestate.rs rename to src/typestate.rs diff --git a/src/x25519.rs b/src/x25519.rs new file mode 100644 index 0000000..d8de9a5 --- /dev/null +++ b/src/x25519.rs @@ -0,0 +1,150 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * (c) ZeroTier, Inc. + * https://www.zerotier.com/ + */ + +use std::convert::TryInto; + +use ed25519_dalek::Digest; +use zssp::crypto::zeroize::Zeroizing; + +use crate::random::SecureRandom; + +pub const C25519_PUBLIC_KEY_SIZE: usize = 32; +pub const C25519_SECRET_KEY_SIZE: usize = 32; +pub const C25519_SHARED_SECRET_SIZE: usize = 32; +pub const ED25519_PUBLIC_KEY_SIZE: usize = 32; +pub const ED25519_SECRET_KEY_SIZE: usize = 32; +pub const ED25519_SIGNATURE_SIZE: usize = 64; + +/// Curve25519 key pair for ECDH key agreement. +pub struct X25519KeyPair(x25519_dalek::StaticSecret, x25519_dalek::PublicKey); + +impl X25519KeyPair { + pub fn generate() -> X25519KeyPair { + let sk = x25519_dalek::StaticSecret::random_from_rng(SecureRandom); + let pk = x25519_dalek::PublicKey::from(&sk); + X25519KeyPair(sk, pk) + } + + #[must_use] + pub fn from_bytes( + public_key: &[u8; C25519_PUBLIC_KEY_SIZE], + secret_key: &[u8; C25519_SECRET_KEY_SIZE], + ) -> Option { + /* NOTE: we keep the original secret separately from x25519_dalek's StaticSecret + * due to how "clamping" is done in the old C++ code vs x25519_dalek. Clamping + * is explained here: + * + * https://www.jcraige.com/an-explainer-on-ed25519-clamping + * + * The old code does clamping at the time of use. In other words the code that + * performs things like key agreement or signing clamps the secret before doing + * the operation. The x25519_dalek code does clamping at generation or when + * from() is used to get a key from a raw byte array. + * + * Unfortunately this introduces issues when interoperating with old code. The + * old system generates secrets that are not clamped (since they're clamped at + * use!) and assumes that these exact binary keys will be preserved in e.g. + * identities. So to preserve this behavior we store the secret separately + * so secret_bytes() will return it as-is. + * + * The new code will still clamp at generation resulting in secrets that are + * pre-clamped, but the old code won't care about this. It's only a problem when + * going the other way. + * + * This has no cryptographic implication since regardless of where, the clamping + * is done. It's just an API thing. + */ + let pk = x25519_dalek::PublicKey::from(*public_key); + let sk = x25519_dalek::StaticSecret::from(*secret_key); + Some(X25519KeyPair(sk, pk)) + } + + #[inline(always)] + pub fn public_bytes(&self) -> [u8; C25519_PUBLIC_KEY_SIZE] { + self.1.to_bytes() + } + + #[inline(always)] + pub fn secret_bytes(&self, output: &mut [u8; C25519_SECRET_KEY_SIZE]) { + *output = self.0.to_bytes() + } + + /// Execute ECDH agreement and return a raw (un-hashed) shared secret key. + pub fn agree(&self, their_public: &[u8; C25519_PUBLIC_KEY_SIZE], output: &mut [u8; C25519_SHARED_SECRET_SIZE]) { + let pk = x25519_dalek::PublicKey::from(*their_public); + let sec = self.0.diffie_hellman(&pk); + output.copy_from_slice(sec.as_bytes()); + } +} + +/// Ed25519 key pair for EDDSA signatures. +pub struct Ed25519KeyPair(ed25519_dalek::SigningKey); + +impl Ed25519KeyPair { + #[must_use] + pub fn generate() -> Ed25519KeyPair { + let kp = ed25519_dalek::SigningKey::generate(&mut SecureRandom); + Ed25519KeyPair(kp) + } + + pub fn from_bytes( + public_bytes: &[u8; ED25519_PUBLIC_KEY_SIZE], + secret_bytes: &[u8; ED25519_SECRET_KEY_SIZE], + ) -> Option { + let mut buf = Zeroizing::new([0u8; { ED25519_PUBLIC_KEY_SIZE + ED25519_SECRET_KEY_SIZE }]); + buf[..ED25519_PUBLIC_KEY_SIZE].copy_from_slice(public_bytes); + buf[ED25519_PUBLIC_KEY_SIZE..].copy_from_slice(secret_bytes); + let keypair = ed25519_dalek::SigningKey::from_keypair_bytes(&buf).ok()?; + Some(Ed25519KeyPair(keypair)) + } + + #[inline(always)] + pub fn public_bytes(&self) -> [u8; ED25519_PUBLIC_KEY_SIZE] { + self.0.verifying_key().to_bytes() + } + + #[inline(always)] + pub fn secret_bytes(&self, output: &mut [u8; ED25519_SECRET_KEY_SIZE]) { + *output = self.0.to_bytes(); + } + + pub fn sign(&self, msg: &[u8]) -> [u8; ED25519_SIGNATURE_SIZE] { + let mut h = ed25519_dalek::Sha512::new(); + let _ = h.update(msg); + self.0.sign_prehashed(h.clone(), None).unwrap().to_bytes() + } + + /// Create a signature with the first 32 bytes of the SHA512 hash appended. + /// ZeroTier does this for legacy reasons, but it's ignored in newer versions. + pub fn sign_zt(&self, msg: &[u8]) -> [u8; 96] { + let mut h = ed25519_dalek::Sha512::new(); + let _ = h.update(msg); + let sig = self.0.sign_prehashed(h.clone(), None).unwrap(); + let s = sig.to_bytes(); + let mut s2 = [0_u8; 96]; + s2[0..64].copy_from_slice(&s); + let h = h.finalize(); + s2[64..96].copy_from_slice(&h.as_slice()[0..32]); + s2 + } +} + +#[must_use] +pub fn ed25519_verify(public_key: &[u8; ED25519_PUBLIC_KEY_SIZE], signature: &[u8], msg: &[u8]) -> bool { + if signature.len() >= 64 { + ed25519_dalek::VerifyingKey::from_bytes(public_key.try_into().unwrap()).map_or(false, |pk| { + let mut h = ed25519_dalek::Sha512::new(); + let _ = h.update(msg); + let sig: [u8; 64] = signature[0..64].try_into().unwrap(); + pk.verify_prehashed(h, None, &ed25519_dalek::Signature::from(sig)) + .is_ok() + }) + } else { + false + } +}