diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c1db55cfea5e4f97f4898347b61af1e717acae28..db97db9e3f61f8613d25821620c744a2a700b908 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -147,6 +147,9 @@ jobs: - x86_64-unknown-linux-gnu - i686-unknown-linux-gnu - arm-unknown-linux-gnueabihf + bindgen: + - true + - false library: - name: openssl version: vendored @@ -167,14 +170,26 @@ jobs: dl-path: /old/1.0.1 include: - target: x86_64-unknown-linux-gnu + bindgen: true library: name: libressl version: 2.5.5 - target: x86_64-unknown-linux-gnu + bindgen: true library: name: libressl version: 3.4.2 - name: ${{ matrix.target }}-${{ matrix.library.name }}-${{ matrix.library.version }} + - target: x86_64-unknown-linux-gnu + bindgen: false + library: + name: libressl + version: 2.5.5 + - target: x86_64-unknown-linux-gnu + bindgen: false + library: + name: libressl + version: 3.4.2 + name: ${{ matrix.target }}-${{ matrix.library.name }}-${{ matrix.library.version }}-${{ matrix.bindgen }} runs-on: ubuntu-latest env: OPENSSL_DIR: /opt/openssl @@ -203,6 +218,7 @@ jobs: sudo apt-get update sudo apt-get install -y $packages + - run: sudo apt-get remove -y libssl-dev - uses: actions/cache@v2 with: path: /opt/openssl @@ -254,7 +270,9 @@ jobs: make make install_sw if: matrix.library.version != 'vendored' && !steps.openssl-cache.outputs.cache-hit - - run: echo "RUST_TEST_THREADS=1" >> $GITHUB_ENV + - run: | + echo "RUST_TEST_THREADS=1" >> $GITHUB_ENV + echo BINDGEN_EXTRA_CLANG_ARGS="--sysroot /usr/arm-linux-gnueabihf" >> $GITHUB_ENV if: matrix.target == 'arm-unknown-linux-gnueabihf' - uses: actions/cache@v1 with: @@ -271,22 +289,31 @@ jobs: - uses: actions/cache@v1 with: path: target - key: target-${{ matrix.target }}-${{ matrix.library.name }}-${{ matrix.library.version }}-${{ steps.rust-version.outputs.version }}-${{ hashFiles('Cargo.lock') }} + key: target-${{ matrix.target }}-${{ matrix.bindgen }}-${{ matrix.library.name }}-${{ matrix.library.version }}-${{ steps.rust-version.outputs.version }}-${{ hashFiles('Cargo.lock') }} - name: Run systest run: | if [[ "${{ matrix.library.version }}" == "vendored" ]]; then features="--features vendored" fi + if [[ "${{ matrix.bindgen }}" == "true" ]]; then + features="$features --features bindgen" + fi cargo run --manifest-path=systest/Cargo.toml --target ${{ matrix.target }} $features - name: Test openssl run: | if [[ "${{ matrix.library.version }}" == "vendored" ]]; then features="--features vendored" fi + if [[ "${{ matrix.bindgen }}" == "true" ]]; then + features="$features --features bindgen" + fi cargo test --manifest-path=openssl/Cargo.toml --target ${{ matrix.target }} $features - name: Test openssl-errors run: | if [[ "${{ matrix.library.version }}" == "vendored" ]]; then features="--features openssl-sys/vendored" fi + if [[ "${{ matrix.bindgen }}" == "true" ]]; then + features="$features --features openssl-sys/bindgen" + fi cargo test --manifest-path=openssl-errors/Cargo.toml --target ${{ matrix.target }} $features diff --git a/Cargo.toml b/Cargo.toml index c33c3475a7e9e93515f27a2b2c369b4ee0583c0b..63e983aef2b200f6eed727043feb424d87221413 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,6 @@ members = [ "openssl-sys", "systest", ] + +[patch.crates-io] +bindgen = { git = "https://github.com/daviddrysdale/rust-bindgen", branch = "allowlist-file" } diff --git a/openssl-sys/Cargo.toml b/openssl-sys/Cargo.toml index aad015e6d4f4188abe5274dc16b4979e480b9d39..8bba02e94fcf311132df0b43c123072c05ae6388 100644 --- a/openssl-sys/Cargo.toml +++ b/openssl-sys/Cargo.toml @@ -20,6 +20,7 @@ vendored = ['openssl-src'] libc = "0.2" [build-dependencies] +bindgen = { version = "0.59.2", optional = true } cc = "1.0" openssl-src = { version = "111", optional = true } pkg-config = "0.3.9" diff --git a/openssl-sys/build/find_normal.rs b/openssl-sys/build/find_normal.rs index babaf9cdb9e0ec9ac8b6e0277d94dc6299066b10..f012cdc0271abf4db2f14cada56393877074f57d 100644 --- a/openssl-sys/build/find_normal.rs +++ b/openssl-sys/build/find_normal.rs @@ -209,7 +209,7 @@ fn try_pkg_config() { } }; - super::validate_headers(&lib.include_paths); + super::postprocess(&lib.include_paths); for include in lib.include_paths.iter() { println!("cargo:include={}", include.display()); @@ -227,17 +227,18 @@ 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 = vcpkg::Config::new() + let lib = match vcpkg::Config::new() .emit_includes(true) - .find_package("openssl"); - - if let Err(e) = lib { - println!("note: vcpkg did not find openssl: {}", e); - return; - } + .find_package("openssl") + { + Ok(lib) => lib, + Err(e) => { + println!("note: vcpkg did not find openssl: {}", e); + return; + } + }; - let lib = lib.unwrap(); - super::validate_headers(&lib.include_paths); + super::postprocess(&lib.include_paths); println!("cargo:rustc-link-lib=user32"); println!("cargo:rustc-link-lib=gdi32"); diff --git a/openssl-sys/build/main.rs b/openssl-sys/build/main.rs index 243f146bf34f8c10fe97f7748cc444f02d557ed0..0c079f3723f788cbc940c5b5f2ad67fd00cc0a77 100644 --- a/openssl-sys/build/main.rs +++ b/openssl-sys/build/main.rs @@ -1,6 +1,8 @@ #![allow(clippy::inconsistent_digit_grouping, clippy::unusual_byte_groupings)] extern crate autocfg; +#[cfg(feature = "bindgen")] +extern crate bindgen; extern crate cc; #[cfg(feature = "vendored")] extern crate openssl_src; @@ -12,12 +14,13 @@ 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 { @@ -83,7 +86,7 @@ fn main() { ); println!("cargo:include={}", include_dir.to_string_lossy()); - let version = validate_headers(&[include_dir]); + let version = postprocess(&[include_dir]); let libs_env = env("OPENSSL_LIBS"); let libs = match libs_env.as_ref().and_then(|s| s.to_str()) { @@ -135,6 +138,15 @@ fn check_rustc_versions() { } } +#[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 diff --git a/openssl-sys/build/run_bindgen.rs b/openssl-sys/build/run_bindgen.rs new file mode 100644 index 0000000000000000000000000000000000000000..8a9254631f675c6a5ca0449059fa116b81c6138f --- /dev/null +++ b/openssl-sys/build/run_bindgen.rs @@ -0,0 +1,125 @@ +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 >= 0x010100000 +#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 index a03a9e7852f6ff9bc38ac096ce1c9e8dc85916f5..ade6e842f49678781169c9a6c4bbfe5e9ff73813 100644 --- a/openssl-sys/src/aes.rs +++ b/openssl-sys/src/aes.rs @@ -5,40 +5,3 @@ pub const AES_DECRYPT: c_int = 0; pub const AES_MAXNR: c_int = 14; pub const AES_BLOCK_SIZE: c_int = 16; - -#[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; - - 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/asn1.rs b/openssl-sys/src/asn1.rs index 679cb30b9aac93f23e14b152230f9a2fbc5fcfb3..a5106d4676bcffef06cf7dcfa864bb79b5dc99b6 100644 --- a/openssl-sys/src/asn1.rs +++ b/openssl-sys/src/asn1.rs @@ -37,59 +37,3 @@ 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; - -#[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_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/bio.rs b/openssl-sys/src/bio.rs index d738a8af0be307c1de82c218b4f29111da01f855..b4beab6ca110fd19e0bf3831267552b7c7500aef 100644 --- a/openssl-sys/src/bio.rs +++ b/openssl-sys/src/bio.rs @@ -10,11 +10,6 @@ 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; -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 unsafe fn BIO_set_retry_read(b: *mut BIO) { BIO_set_flags(b, BIO_FLAGS_READ | BIO_FLAGS_SHOULD_RETRY) } @@ -33,94 +28,42 @@ 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 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>, - } - } -} - 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) } -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); - // FIXME should wrap in Option + #[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, diff --git a/openssl-sys/src/bn.rs b/openssl-sys/src/bn.rs index 963808dc15e0a9d6ca291e3ce94d3437033c9ac2..f7393d0f5048aa414aa26639a419341cb2992072 100644 --- a/openssl-sys/src/bn.rs +++ b/openssl-sys/src/bn.rs @@ -15,165 +15,3 @@ pub const BN_FLG_STATIC_DATA: c_int = 0x02; pub const BN_FLG_CONSTTIME: c_int = 0x04; #[cfg(ossl110)] pub const BN_FLG_SECURE: c_int = 0x08; - -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; - 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; - 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(ossl110)] - 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; - pub fn BN_is_prime_ex( - p: *const BIGNUM, - checks: c_int, - ctx: *mut BN_CTX, - cb: *mut BN_GENCB, - ) -> c_int; - 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(ossl110)] { - 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/cms.rs b/openssl-sys/src/cms.rs index 59596307f9c135aa43690c93680d44ac1b398877..59c770e5dc40a35e36ea155ea19b943dbbe16750 100644 --- a/openssl-sys/src/cms.rs +++ b/openssl-sys/src/cms.rs @@ -1,29 +1,6 @@ use libc::*; use *; -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 const CMS_TEXT: c_uint = 0x1; #[cfg(ossl101)] @@ -68,35 +45,3 @@ pub const CMS_DEBUG_DECRYPT: c_uint = 0x20000; pub const CMS_KEY_PARAM: c_uint = 0x40000; #[cfg(ossl110)] pub const CMS_ASCIICRLF: c_uint = 0x80000; - -extern "C" { - #[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_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/crypto.rs b/openssl-sys/src/crypto.rs index 6d0ffb305b5d4f5cb85966489624ce38849d7a12..842faa4e2f033aa95dc4452ebb0076455774c402 100644 --- a/openssl-sys/src/crypto.rs +++ b/openssl-sys/src/crypto.rs @@ -1,6 +1,62 @@ use libc::*; use *; +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] @@ -49,8 +105,6 @@ pub const CRYPTO_LOCK_SSL_CTX: c_int = 12; #[cfg(not(ossl110))] pub const CRYPTO_LOCK_SSL_SESSION: c_int = 14; -stack!(stack_st_void); - cfg_if! { if #[cfg(ossl110)] { pub const CRYPTO_EX_INDEX_SSL: c_int = 0; @@ -60,22 +114,15 @@ cfg_if! { pub const CRYPTO_EX_INDEX_SSL_CTX: c_int = 2; } } + 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; - } 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 { - extern "C" { - pub fn SSLeay() -> c_ulong; - pub fn SSLeay_version(key: c_int) -> *const c_char; - } pub const SSLEAY_VERSION: c_int = 0; pub const SSLEAY_CFLAGS: c_int = 2; pub const SSLEAY_BUILT_ON: c_int = 3; @@ -84,90 +131,4 @@ cfg_if! { } } -// FIXME should be options -pub type CRYPTO_EX_new = unsafe extern "C" fn( - parent: *mut c_void, - ptr: *mut c_void, - ad: *const CRYPTO_EX_DATA, - idx: c_int, - argl: c_long, - argp: *const c_void, -) -> c_int; -pub type CRYPTO_EX_dup = unsafe extern "C" fn( - to: *mut CRYPTO_EX_DATA, - from: *mut CRYPTO_EX_DATA, - from_d: *mut c_void, - 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, -); -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; -} - pub const CRYPTO_LOCK: c_int = 1; - -extern "C" { - #[cfg(not(ossl110))] - pub fn CRYPTO_num_locks() -> c_int; - #[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), - ); - - #[cfg(not(ossl110))] - pub fn CRYPTO_set_id_callback(func: unsafe extern "C" fn() -> c_ulong); - - #[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/ec.rs b/openssl-sys/src/ec.rs index d7427918613f4a39a0abf330d69ae0eeaa28444b..c01d6f22af6950dea349f2c9f59dfddd3434ecdd 100644 --- a/openssl-sys/src/ec.rs +++ b/openssl-sys/src/ec.rs @@ -3,246 +3,8 @@ use std::ptr; use *; -#[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 {} - pub const OPENSSL_EC_NAMED_CURVE: c_int = 1; -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_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; - - #[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; -} - #[cfg(ossl300)] pub unsafe fn EVP_EC_gen(curve: *const c_char) -> *mut EVP_PKEY { EVP_PKEY_Q_keygen( diff --git a/openssl-sys/src/err.rs b/openssl-sys/src/err.rs index 565cfd2ff20d2690615f541bf49719b0c2d54e66..85d9e15d61766902dbb8ba09bf2af369851000d7 100644 --- a/openssl-sys/src/err.rs +++ b/openssl-sys/src/err.rs @@ -68,56 +68,3 @@ cfg_if! { } } } - -#[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/evp.rs b/openssl-sys/src/evp.rs index 70561c92f33536c8d1f87d967417ec9a6e97254c..4bc6d4b8de7b3ccfb8abca7689ce6d5fc4b5f005 100644 --- a/openssl-sys/src/evp.rs +++ b/openssl-sys/src/evp.rs @@ -33,28 +33,6 @@ pub unsafe fn EVP_get_digestbynid(type_: c_int) -> *const EVP_MD { cfg_if! { if #[cfg(ossl300)] { - extern "C" { - 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_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; - } - #[inline] pub unsafe fn EVP_MD_size(md: *const EVP_MD) -> c_int { EVP_MD_get_size(md) @@ -99,381 +77,34 @@ cfg_if! { pub unsafe fn EVP_CIPHER_CTX_iv_length(ctx: *const EVP_CIPHER_CTX) -> c_int { EVP_CIPHER_CTX_get_iv_length(ctx) } - } else { - extern "C" { - 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_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_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_if! { - if #[cfg(ossl300)] { - extern "C" { - pub fn EVP_DigestSignUpdate( - ctx: *mut EVP_MD_CTX, - data: *const c_void, - dsize: size_t, - ) -> c_int; - } - } else { - #[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) - } - } -} -extern "C" { - 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_if! { - if #[cfg(ossl300)] { - extern "C" { - pub fn EVP_DigestVerifyUpdate( - ctx: *mut EVP_MD_CTX, - data: *const c_void, - dsize: size_t, - ) -> c_int; - } - } else { - #[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) - } - } -} -extern "C" { - 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; - } - - #[inline] - pub unsafe fn EVP_PKEY_size(pkey: *const EVP_PKEY) -> c_int { - EVP_PKEY_get_size(pkey) - } - } 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; - 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(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(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)] { - 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; - } - #[inline] pub unsafe fn EVP_PKEY_id(pkey: *const EVP_PKEY) -> c_int { EVP_PKEY_get_id(pkey) @@ -483,75 +114,8 @@ cfg_if! { pub unsafe fn EVP_PKEY_bits(pkey: *const EVP_PKEY) -> c_int { EVP_PKEY_get_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; - } - } } } -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 const EVP_PKEY_OP_KEYGEN: c_int = 1 << 2; cfg_if! { @@ -614,207 +178,74 @@ 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; -extern "C" { - 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; -} - -// HKDF Functions -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; - } - } else { - #[cfg(ossl111)] - 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(ossl110)] - 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(ossl110)] - 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(ossl110)] - 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(ossl110)] - 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, - ) - } - } -} - -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; +#[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 new file mode 100644 index 0000000000000000000000000000000000000000..241848eccfeda58976be5aad2b005ad1b850beb5 --- /dev/null +++ b/openssl-sys/src/handwritten/aes.rs @@ -0,0 +1,39 @@ +use libc::*; +use *; + +#[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; + + 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 new file mode 100644 index 0000000000000000000000000000000000000000..326300c5d723e972c2221de7c7ccc10d4d127813 --- /dev/null +++ b/openssl-sys/src/handwritten/asn1.rs @@ -0,0 +1,58 @@ +use libc::*; +use *; + +#[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_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 new file mode 100644 index 0000000000000000000000000000000000000000..7241df0f3eb56177a806eb1a0cdd58bf7aa73c76 --- /dev/null +++ b/openssl-sys/src/handwritten/bio.rs @@ -0,0 +1,107 @@ +use libc::*; +use *; + +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 new file mode 100644 index 0000000000000000000000000000000000000000..91e498c88b4081d119ea1fb8a38befe590659dd1 --- /dev/null +++ b/openssl-sys/src/handwritten/bn.rs @@ -0,0 +1,164 @@ +use libc::*; +use *; + +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; + 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; + 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(ossl110)] + 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; + pub fn BN_is_prime_ex( + p: *const BIGNUM, + checks: c_int, + ctx: *mut BN_CTX, + cb: *mut BN_GENCB, + ) -> c_int; + 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(ossl110)] { + 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 new file mode 100644 index 0000000000000000000000000000000000000000..291bc798b7d2eb38f2f729e0888e3a56facd5365 --- /dev/null +++ b/openssl-sys/src/handwritten/cms.rs @@ -0,0 +1,55 @@ +use libc::*; +use *; + +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_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/conf.rs b/openssl-sys/src/handwritten/conf.rs similarity index 100% rename from openssl-sys/src/conf.rs rename to openssl-sys/src/handwritten/conf.rs diff --git a/openssl-sys/src/handwritten/crypto.rs b/openssl-sys/src/handwritten/crypto.rs new file mode 100644 index 0000000000000000000000000000000000000000..ab17d2fa9e79df00ac29bf4af68da275bc4a1e08 --- /dev/null +++ b/openssl-sys/src/handwritten/crypto.rs @@ -0,0 +1,85 @@ +use libc::*; +use *; + +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/dh.rs b/openssl-sys/src/handwritten/dh.rs similarity index 100% rename from openssl-sys/src/dh.rs rename to openssl-sys/src/handwritten/dh.rs diff --git a/openssl-sys/src/dsa.rs b/openssl-sys/src/handwritten/dsa.rs similarity index 100% rename from openssl-sys/src/dsa.rs rename to openssl-sys/src/handwritten/dsa.rs diff --git a/openssl-sys/src/handwritten/ec.rs b/openssl-sys/src/handwritten/ec.rs new file mode 100644 index 0000000000000000000000000000000000000000..0470ef404b8a42e04169b33f1e2170f31f71ca61 --- /dev/null +++ b/openssl-sys/src/handwritten/ec.rs @@ -0,0 +1,240 @@ +use libc::*; +use *; + +#[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_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; + + #[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 new file mode 100644 index 0000000000000000000000000000000000000000..d8f36e49704fd216d508fd67b82e8a05d6a8edd4 --- /dev/null +++ b/openssl-sys/src/handwritten/err.rs @@ -0,0 +1,55 @@ +use libc::*; +use *; + +#[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 new file mode 100644 index 0000000000000000000000000000000000000000..83513ef39120ebd3314d7ad2871822a091f6b119 --- /dev/null +++ b/openssl-sys/src/handwritten/evp.rs @@ -0,0 +1,546 @@ +use libc::*; +use *; + +cfg_if! { + if #[cfg(ossl300)] { + extern "C" { + 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_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; + } + } else { + extern "C" { + 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_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_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; + 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(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; + } + + #[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) + } + } 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; + } + } + } +} +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/hmac.rs b/openssl-sys/src/handwritten/hmac.rs similarity index 100% rename from openssl-sys/src/hmac.rs rename to openssl-sys/src/handwritten/hmac.rs diff --git a/openssl-sys/src/handwritten/kdf.rs b/openssl-sys/src/handwritten/kdf.rs new file mode 100644 index 0000000000000000000000000000000000000000..b8e6c63bb1096b6dcd17c83122664c63533cb9a0 --- /dev/null +++ b/openssl-sys/src/handwritten/kdf.rs @@ -0,0 +1,26 @@ +use libc::*; +use *; + +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 new file mode 100644 index 0000000000000000000000000000000000000000..2f28c5541b08f768c37da4a281aafa667c89d3a3 --- /dev/null +++ b/openssl-sys/src/handwritten/mod.rs @@ -0,0 +1,63 @@ +pub use handwritten::aes::*; +pub use handwritten::asn1::*; +pub use handwritten::bio::*; +pub use handwritten::bn::*; +pub use handwritten::cms::*; +pub use handwritten::conf::*; +pub use handwritten::crypto::*; +pub use handwritten::dh::*; +pub use handwritten::dsa::*; +pub use handwritten::ec::*; +pub use handwritten::err::*; +pub use handwritten::evp::*; +pub use handwritten::hmac::*; +pub use handwritten::kdf::*; +pub use handwritten::object::*; +pub use handwritten::ocsp::*; +pub use handwritten::pem::*; +pub use handwritten::pkcs12::*; +pub use handwritten::pkcs7::*; +pub use handwritten::rand::*; +pub use handwritten::rsa::*; +pub use handwritten::safestack::*; +pub use handwritten::sha::*; +pub use handwritten::srtp::*; +pub use handwritten::ssl::*; +pub use handwritten::stack::*; +pub use handwritten::tls1::*; +pub use handwritten::types::*; +pub use handwritten::x509::*; +pub use handwritten::x509_vfy::*; +pub use handwritten::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 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/object.rs b/openssl-sys/src/handwritten/object.rs similarity index 100% rename from openssl-sys/src/object.rs rename to openssl-sys/src/handwritten/object.rs diff --git a/openssl-sys/src/handwritten/ocsp.rs b/openssl-sys/src/handwritten/ocsp.rs new file mode 100644 index 0000000000000000000000000000000000000000..bb194c2860726a5a6ba8f54b64a28748fd677e57 --- /dev/null +++ b/openssl-sys/src/handwritten/ocsp.rs @@ -0,0 +1,89 @@ +use libc::*; +use *; + +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 new file mode 100644 index 0000000000000000000000000000000000000000..ebce932b6c4f68a4fe9cf29568f0ad70d9af52fc --- /dev/null +++ b/openssl-sys/src/handwritten/pem.rs @@ -0,0 +1,191 @@ +use libc::*; +use *; + +pub type pem_password_cb = Option< + unsafe extern "C" fn( + buf: *mut c_char, + size: c_int, + rwflag: c_int, + user_data: *mut c_void, + ) -> 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/pkcs12.rs b/openssl-sys/src/handwritten/pkcs12.rs similarity index 100% rename from openssl-sys/src/pkcs12.rs rename to openssl-sys/src/handwritten/pkcs12.rs diff --git a/openssl-sys/src/handwritten/pkcs7.rs b/openssl-sys/src/handwritten/pkcs7.rs new file mode 100644 index 0000000000000000000000000000000000000000..fc0239e7b8fe324725d82ea3e4d4e0410aa07c29 --- /dev/null +++ b/openssl-sys/src/handwritten/pkcs7.rs @@ -0,0 +1,70 @@ +use libc::*; +use *; + +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/rand.rs b/openssl-sys/src/handwritten/rand.rs similarity index 100% rename from openssl-sys/src/rand.rs rename to openssl-sys/src/handwritten/rand.rs diff --git a/openssl-sys/src/handwritten/rsa.rs b/openssl-sys/src/handwritten/rsa.rs new file mode 100644 index 0000000000000000000000000000000000000000..d2a1439beec0725e66a893dad8ff58dd1e4fbabd --- /dev/null +++ b/openssl-sys/src/handwritten/rsa.rs @@ -0,0 +1,129 @@ +use libc::*; +use *; + +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/safestack.rs b/openssl-sys/src/handwritten/safestack.rs similarity index 100% rename from openssl-sys/src/safestack.rs rename to openssl-sys/src/handwritten/safestack.rs diff --git a/openssl-sys/src/handwritten/sha.rs b/openssl-sys/src/handwritten/sha.rs new file mode 100644 index 0000000000000000000000000000000000000000..64fe2ce8835589c079bc6a9e2266b8d5de3fe919 --- /dev/null +++ b/openssl-sys/src/handwritten/sha.rs @@ -0,0 +1,101 @@ +use libc::*; +use *; + +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 new file mode 100644 index 0000000000000000000000000000000000000000..7500584be8a065eaa8e9e780419cd43dd6cbebfb --- /dev/null +++ b/openssl-sys/src/handwritten/srtp.rs @@ -0,0 +1,10 @@ +use libc::*; +use *; + +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 new file mode 100644 index 0000000000000000000000000000000000000000..0460c75fef876326ecc2788070b7c931d49f9831 --- /dev/null +++ b/openssl-sys/src/handwritten/ssl.rs @@ -0,0 +1,889 @@ +use libc::*; +use *; + +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< + unsafe extern "C" fn( + *mut SSL, + *mut c_void, + *mut c_int, + *mut stack_st_SSL_CIPHER, + *mut *mut SSL_CIPHER, + *mut c_void, + ) -> 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< + unsafe extern "C" fn( + ssl: *mut ::SSL, + ext_type: c_uint, + context: c_uint, + out: *const c_uchar, + add_arg: *mut c_void, + ), +>; + +#[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< + extern "C" fn(ssl: *mut SSL, cookie: *mut c_uchar, cookie_len: *mut c_uint) -> 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< + unsafe extern "C" fn( + ssl: *mut SSL, + cookie: *mut c_uchar, + cookie_len: *mut size_t, + ) -> c_int, + >, + ); + #[cfg(ossl111)] + pub fn SSL_CTX_set_stateless_cookie_verify_cb( + s: *mut SSL_CTX, + cb: Option< + unsafe extern "C" fn( + ssl: *mut SSL, + cookie: *const c_uchar, + cookie_len: size_t, + ) -> 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< + extern "C" fn( + *mut SSL, + *const c_char, + *mut c_char, + c_uint, + *mut c_uchar, + c_uint, + ) -> c_uint, + >, + ); + pub fn SSL_CTX_set_psk_server_callback( + ssl: *mut SSL_CTX, + psk_server_cb: Option< + extern "C" fn(*mut SSL, *const c_char, *mut c_uchar, c_uint) -> c_uint, + >, + ); +} + +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(ossl111)] + pub fn SSL_CTX_set_max_early_data(ctx: *mut SSL_CTX, max_early_data: u32) -> c_int; + #[cfg(ossl111)] + pub fn SSL_CTX_get_max_early_data(ctx: *const SSL_CTX) -> u32; + #[cfg(ossl111)] + pub fn SSL_set_max_early_data(ctx: *mut SSL, max_early_data: u32) -> c_int; + #[cfg(ossl111)] + 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; + } + } +} + +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; + } + } +} + +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(ossl111)] + pub fn SSL_CTX_set_ciphersuites(ctx: *mut SSL_CTX, str: *const c_char) -> c_int; + #[cfg(ossl111)] + pub fn SSL_set_ciphersuites(ssl: *mut ::SSL, str: *const c_char) -> 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_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(ossl110)] + pub fn SSL_SESSION_get_protocol_version(s: *const SSL_SESSION) -> c_int; + + #[cfg(ossl111)] + pub fn SSL_SESSION_set_max_early_data(ctx: *mut SSL_SESSION, max_early_data: u32) -> c_int; + #[cfg(ossl111)] + 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(ossl111)] + 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(ossl111)] + 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(ossl111)] + 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); + + #[cfg(not(libressl))] + 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(ossl102)] + pub fn SSL_CTX_get0_certificate(ctx: *const SSL_CTX) -> *mut X509; + #[cfg(ossl102)] + 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(ossl110)] + pub fn SSL_get_client_random(ssl: *const SSL, out: *mut c_uchar, len: size_t) -> size_t; + #[cfg(ossl110)] + 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<::CRYPTO_EX_new>, + dup_func: Option<::CRYPTO_EX_dup>, + free_func: Option<::CRYPTO_EX_free>, + ) -> 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< + unsafe extern "C" fn(ssl: *mut SSL, is_export: c_int, keylength: c_int) -> *mut DH, + >, + ); + #[link_name = "SSL_set_tmp_dh_callback"] + pub fn SSL_set_tmp_dh_callback__fixed_rust( + ctx: *mut SSL, + dh: Option< + unsafe extern "C" fn(ssl: *mut SSL, is_export: c_int, keylength: c_int) -> *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< + unsafe extern "C" fn( + ssl: *mut ::SSL, + is_export: c_int, + keylength: c_int, + ) -> *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< + unsafe extern "C" fn(ssl: *mut SSL, is_export: c_int, keylength: c_int) -> *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(ossl110)] + pub fn SSL_CIPHER_get_cipher_nid(c: *const SSL_CIPHER) -> c_int; + #[cfg(ossl110)] + 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; +} diff --git a/openssl-sys/src/stack.rs b/openssl-sys/src/handwritten/stack.rs similarity index 100% rename from openssl-sys/src/stack.rs rename to openssl-sys/src/handwritten/stack.rs diff --git a/openssl-sys/src/handwritten/tls1.rs b/openssl-sys/src/handwritten/tls1.rs new file mode 100644 index 0000000000000000000000000000000000000000..a54dcbc80d5731ca35e099ea01c63789d7672561 --- /dev/null +++ b/openssl-sys/src/handwritten/tls1.rs @@ -0,0 +1,28 @@ +use libc::*; +use *; + +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/ossl_typ.rs b/openssl-sys/src/handwritten/types.rs similarity index 98% rename from openssl-sys/src/ossl_typ.rs rename to openssl-sys/src/handwritten/types.rs index 41221f092cdb214fc72550ebf9b921afb71ab023..c4e7f837843a23cf5ecb637792fa6fbad71a8791 100644 --- a/openssl-sys/src/ossl_typ.rs +++ b/openssl-sys/src/handwritten/types.rs @@ -105,23 +105,6 @@ cfg_if! { } } } -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, - } - } -} pub enum PKCS8_PRIV_KEY_INFO {} @@ -430,6 +413,27 @@ cfg_if! { } } +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, @@ -1066,3 +1070,6 @@ cfg_if! { } pub enum OCSP_RESPONSE {} + +#[cfg(ossl300)] +pub enum OSSL_LIB_CTX {} diff --git a/openssl-sys/src/handwritten/x509.rs b/openssl-sys/src/handwritten/x509.rs new file mode 100644 index 0000000000000000000000000000000000000000..2d3a4ccd21088bfea6845985b7ce8a8f7e303c5f --- /dev/null +++ b/openssl-sys/src/handwritten/x509.rs @@ -0,0 +1,615 @@ +use libc::*; +use *; + +#[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(ossl110)] { + 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(ossl110)] { + 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(ossl110)] { + 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(ossl110)] { + 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(ossl110)] { + 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(ossl110)] { + 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(ossl102)] + pub fn X509_ALGOR_get0( + paobj: *mut #[const_ptr_if(ossl110)] ASN1_OBJECT, + pptype: *mut c_int, + ppval: *mut #[const_ptr_if(ossl110)] c_void, + alg: #[const_ptr_if(ossl110)] 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; + } +} + +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, + ); + } +} +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; + } +} +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_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(ossl110)] { + 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(ossl110)] + 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(ossl110)] + 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(ossl110)] { + 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; +} diff --git a/openssl-sys/src/handwritten/x509_vfy.rs b/openssl-sys/src/handwritten/x509_vfy.rs new file mode 100644 index 0000000000000000000000000000000000000000..82dd516fab220d542d9e561d5254e70e530e570c --- /dev/null +++ b/openssl-sys/src/handwritten/x509_vfy.rs @@ -0,0 +1,106 @@ +use libc::*; +use *; + +#[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_ctrl( + ctx: *mut X509_LOOKUP, + cmd: c_int, + argc: *const c_char, + argl: c_long, + ret: *mut *mut c_char, + ) -> 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; +} + +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(ossl110)] { + 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_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; +} +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; +} diff --git a/openssl-sys/src/handwritten/x509v3.rs b/openssl-sys/src/handwritten/x509v3.rs new file mode 100644 index 0000000000000000000000000000000000000000..f0a3a2a1f27c895761e6f79b728992060e055a27 --- /dev/null +++ b/openssl-sys/src/handwritten/x509v3.rs @@ -0,0 +1,103 @@ +use libc::*; +use *; + +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_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 index fd92209c2901ae93e67472604fdd2bc75f0f658f..2cf9c132767f118bd0733966be5bc8c76d9788ce 100644 --- a/openssl-sys/src/lib.rs +++ b/openssl-sys/src/lib.rs @@ -16,35 +16,30 @@ extern crate libc; use libc::*; +#[cfg(feature = "bindgen")] +include!(concat!(env!("OUT_DIR"), "/bindgen.rs")); + pub use aes::*; pub use asn1::*; pub use bio::*; pub use bn::*; pub use cms::*; -pub use conf::*; pub use crypto::*; -pub use dh::*; -pub use dsa::*; pub use dtls1::*; pub use ec::*; pub use err::*; pub use evp::*; -pub use hmac::*; +#[cfg(not(feature = "bindgen"))] +pub use handwritten::*; pub use obj_mac::*; -pub use object::*; pub use ocsp::*; -pub use ossl_typ::*; pub use pem::*; -pub use pkcs12::*; pub use pkcs7::*; -pub use rand::*; pub use rsa::*; -pub use safestack::*; pub use sha::*; pub use srtp::*; pub use ssl::*; pub use ssl3::*; -pub use stack::*; pub use tls1::*; pub use types::*; pub use x509::*; @@ -59,30 +54,22 @@ mod asn1; mod bio; mod bn; mod cms; -mod conf; mod crypto; -mod dh; -mod dsa; mod dtls1; mod ec; mod err; mod evp; -mod hmac; +#[cfg(not(feature = "bindgen"))] +mod handwritten; mod obj_mac; -mod object; mod ocsp; -mod ossl_typ; mod pem; -mod pkcs12; mod pkcs7; -mod rand; mod rsa; -mod safestack; mod sha; mod srtp; mod ssl; mod ssl3; -mod stack; mod tls1; mod types; mod x509; @@ -156,7 +143,7 @@ pub fn init() { } unsafe { - CRYPTO_set_id_callback(thread_id); + CRYPTO_set_id_callback__fixed_rust(Some(thread_id)); } } } else { @@ -181,7 +168,7 @@ pub fn init() { Box::new((0..num_locks).map(|_| None).collect()); GUARDS = mem::transmute(guards); - CRYPTO_set_locking_callback(locking_function); + CRYPTO_set_locking_callback__fixed_rust(Some(locking_function)); set_id_callback(); }) } diff --git a/openssl-sys/src/macros.rs b/openssl-sys/src/macros.rs index 7b4a875f8818f3bce3d1e4def19c1b1561e73597..2f8bf77c39f93f9feef3f68e408ffe8611ebbce1 100644 --- a/openssl-sys/src/macros.rs +++ b/openssl-sys/src/macros.rs @@ -1,3 +1,5 @@ +#![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` diff --git a/openssl-sys/src/ocsp.rs b/openssl-sys/src/ocsp.rs index 4a9f7752c0d5f57079dea83d07d69eba21813ebd..7efac4d449f59a779ae1c508d8bebcdea66374a8 100644 --- a/openssl-sys/src/ocsp.rs +++ b/openssl-sys/src/ocsp.rs @@ -25,12 +25,6 @@ pub const OCSP_TRUSTOTHER: c_ulong = 0x200; pub const OCSP_RESPID_KEY: c_ulong = 0x400; pub const OCSP_NOTIME: c_ulong = 0x800; -pub enum OCSP_CERTID {} - -pub enum OCSP_ONEREQ {} - -pub enum OCSP_REQUEST {} - 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; @@ -41,84 +35,3 @@ 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; - -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/pem.rs b/openssl-sys/src/pem.rs index 978ec42da80add279c052f8ce7f4758107847044..2a05ad58cdd306ee31aa88ae7d7dad625ee74454 100644 --- a/openssl-sys/src/pem.rs +++ b/openssl-sys/src/pem.rs @@ -2,193 +2,4 @@ use libc::*; use *; -pub type pem_password_cb = Option< - unsafe extern "C" fn( - buf: *mut c_char, - size: c_int, - rwflag: c_int, - user_data: *mut c_void, - ) -> 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; -} - pub const PEM_R_NO_START_LINE: c_int = 108; diff --git a/openssl-sys/src/pkcs7.rs b/openssl-sys/src/pkcs7.rs index d8d0fdfcc0cf6d75bf67c153bc4771736d0221dc..188693f9f2c253009ae82494847f03c36cb7045b 100644 --- a/openssl-sys/src/pkcs7.rs +++ b/openssl-sys/src/pkcs7.rs @@ -2,13 +2,6 @@ use libc::*; use *; -pub enum PKCS7_SIGNED {} -pub enum PKCS7_ENVELOPE {} -pub enum PKCS7_SIGN_ENVELOPE {} -pub enum PKCS7_DIGEST {} -pub enum PKCS7_ENCRYPT {} -pub enum PKCS7 {} - pub const PKCS7_TEXT: c_int = 0x1; pub const PKCS7_NOCERTS: c_int = 0x2; pub const PKCS7_NOSIGS: c_int = 0x4; @@ -27,64 +20,3 @@ 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; - -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/rsa.rs b/openssl-sys/src/rsa.rs index 85359cd669801d5175a31d89283313ace63f1e4d..351ac84c0328a4b884627628b6658caf158d536c 100644 --- a/openssl-sys/src/rsa.rs +++ b/openssl-sys/src/rsa.rs @@ -6,15 +6,7 @@ use *; pub const RSA_F4: c_long = 0x10001; 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; - } - } else { + 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, @@ -107,118 +99,3 @@ 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; - -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/sha.rs b/openssl-sys/src/sha.rs index faa57d47fbb10fbb3397a78578fe32e71c03b2eb..8b77f546c66cf91870ced74d5cb87a86e5588492 100644 --- a/openssl-sys/src/sha.rs +++ b/openssl-sys/src/sha.rs @@ -2,36 +2,15 @@ use libc::*; use std::ptr; use *; -cfg_if! { - if #[cfg(not(osslconf = "OPENSSL_NO_DEPRECATED_3_0"))] { - pub type SHA_LONG = c_uint; - - pub const SHA_LBLOCK: c_int = 16; - - #[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, - } +#[cfg(not(osslconf = "OPENSSL_NO_DEPRECATED_3_0"))] +pub const SHA_LBLOCK: c_int = 16; - 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(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( @@ -42,45 +21,14 @@ cfg_if! { n, md, ptr::null_mut(), - ) != 0 { + ) != 0 + { md } else { ptr::null_mut() } } - } else { - 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(ossl300)] { 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(), @@ -112,40 +60,11 @@ cfg_if! { ptr::null_mut() } } - } else { - 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"))] { - pub type SHA_LONG64 = u64; - - #[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(not(osslconf = "OPENSSL_NO_DEPRECATED_3_0"))] +pub type SHA_LONG64 = u64; cfg_if! { if #[cfg(ossl300)] { @@ -180,10 +99,5 @@ cfg_if! { ptr::null_mut() } } - } else { - 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/srtp.rs b/openssl-sys/src/srtp.rs index d39b2ab6dae3c46735c5eb6efc1d665507985fbb..78298d23ec91e6917dbc292da08c2bc007948bee 100644 --- a/openssl-sys/src/srtp.rs +++ b/openssl-sys/src/srtp.rs @@ -14,11 +14,3 @@ pub const SRTP_NULL_SHA1_32: c_ulong = 0x0006; pub const SRTP_AEAD_AES_128_GCM: c_ulong = 0x0007; #[cfg(ossl110)] pub const SRTP_AEAD_AES_256_GCM: c_ulong = 0x0008; - -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/ssl.rs b/openssl-sys/src/ssl.rs index db9a18dab298cb1ef597a3bca3f8eb9f61dcab1a..171040ab4e9deb23439cf08194fe535e726662d8 100644 --- a/openssl-sys/src/ssl.rs +++ b/openssl-sys/src/ssl.rs @@ -22,158 +22,6 @@ 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; -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< - unsafe extern "C" fn( - *mut SSL, - *mut c_void, - *mut c_int, - *mut stack_st_SSL_CIPHER, - *mut *mut SSL_CIPHER, - *mut c_void, - ) -> c_int, ->; - #[cfg(ossl111)] pub const SSL_EXT_TLS_ONLY: c_uint = 0x0001; /* This extension is only allowed in DTLS */ @@ -212,47 +60,6 @@ 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(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< - unsafe extern "C" fn( - ssl: *mut ::SSL, - ext_type: c_uint, - context: c_uint, - out: *mut *const c_uchar, - add_arg: *mut c_void, - ), ->; - -#[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)] { macro_rules! ssl_op_type { @@ -441,19 +248,7 @@ pub unsafe fn SSL_CTX_set_mode(ctx: *mut SSL_CTX, op: c_long) -> c_long { pub const SSL_COOKIE_LENGTH: c_int = 4096; 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; - } - } else { + 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 } @@ -487,9 +282,6 @@ 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 type GEN_SESSION_CB = - Option c_int>; - 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; @@ -500,229 +292,10 @@ 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; -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< - extern "C" fn(ssl: *mut SSL, cookie: *mut c_uchar, cookie_len: *mut c_uint) -> 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< - unsafe extern "C" fn( - ssl: *mut SSL, - cookie: *mut c_uchar, - cookie_len: *mut size_t, - ) -> c_int, - >, - ); - #[cfg(ossl111)] - pub fn SSL_CTX_set_stateless_cookie_verify_cb( - s: *mut SSL_CTX, - cb: Option< - unsafe extern "C" fn( - ssl: *mut SSL, - cookie: *const c_uchar, - cookie_len: size_t, - ) -> 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; -} - 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; -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; - // FIXME should take an Option - #[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(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< - extern "C" fn( - *mut SSL, - *const c_char, - *mut c_char, - c_uint, - *mut c_uchar, - c_uint, - ) -> c_uint, - >, - ); - pub fn SSL_CTX_set_psk_server_callback( - ssl: *mut SSL_CTX, - psk_server_cb: Option< - extern "C" fn(*mut SSL, *const c_char, *mut c_uchar, c_uint) -> c_uint, - >, - ); -} - -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(ossl111)] - pub fn SSL_CTX_set_max_early_data(ctx: *mut SSL_CTX, max_early_data: u32) -> c_int; - #[cfg(ossl111)] - pub fn SSL_CTX_get_max_early_data(ctx: *const SSL_CTX) -> u32; - #[cfg(ossl111)] - pub fn SSL_set_max_early_data(ctx: *mut SSL, max_early_data: u32) -> c_int; - #[cfg(ossl111)] - 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; - } -} - 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; @@ -874,11 +447,6 @@ cfg_if! { ptr::null_mut(), ) as c_int } - } else 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; - } } } @@ -891,11 +459,6 @@ cfg_if! { 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 } - } else 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; - } } } @@ -929,134 +492,6 @@ 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 } -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(ossl111)] - pub fn SSL_CTX_set_ciphersuites(ctx: *mut SSL_CTX, str: *const c_char) -> c_int; - #[cfg(ossl111)] - pub fn SSL_set_ciphersuites(ssl: *mut ::SSL, str: *const c_char) -> 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_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(ossl110)] - pub fn SSL_SESSION_get_protocol_version(s: *const SSL_SESSION) -> c_int; - - #[cfg(ossl111)] - pub fn SSL_SESSION_set_max_early_data(ctx: *mut SSL_SESSION, max_early_data: u32) -> c_int; - #[cfg(ossl111)] - 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(ossl111)] - 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 const SSL_CLIENT_HELLO_SUCCESS: c_int = 1; #[cfg(ossl111)] @@ -1064,61 +499,6 @@ pub const SSL_CLIENT_HELLO_ERROR: c_int = 0; #[cfg(ossl111)] pub const SSL_CLIENT_HELLO_RETRY: c_int = -1; -#[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(ossl111)] - pub fn SSL_read_early_data( - s: *mut ::SSL, - buf: *mut c_void, - num: size_t, - readbytes: *mut size_t, - ) -> c_int; -} - #[cfg(ossl111)] pub const SSL_READ_EARLY_DATA_ERROR: c_int = 0; #[cfg(ossl111)] @@ -1126,136 +506,6 @@ pub const SSL_READ_EARLY_DATA_SUCCESS: c_int = 1; #[cfg(ossl111)] pub const SSL_READ_EARLY_DATA_FINISH: c_int = 2; -extern "C" { - pub fn SSL_write(ssl: *mut SSL, buf: *const c_void, num: c_int) -> c_int; - #[cfg(ossl111)] - 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; - pub fn SSL_CTX_callback_ctrl( - 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); - - #[cfg(not(libressl))] - 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(ossl102)] - pub fn SSL_CTX_get0_certificate(ctx: *const SSL_CTX) -> *mut X509; - #[cfg(ossl102)] - 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(ossl110)] - pub fn SSL_get_client_random(ssl: *const SSL, out: *mut c_uchar, len: size_t) -> size_t; - #[cfg(ossl110)] - 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; -} - cfg_if! { if #[cfg(ossl110)] { pub unsafe fn SSL_get_ex_new_index( @@ -1267,22 +517,8 @@ cfg_if! { ) -> c_int { CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL, l, p, newf, dupf, freef) } - } else { - extern "C" { - 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; - } } } -extern "C" { - 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_if! { if #[cfg(ossl110)] { pub unsafe fn SSL_CTX_get_ex_new_index( @@ -1294,24 +530,8 @@ cfg_if! { ) -> c_int { CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL_CTX, l, p, newf, dupf, freef) } - } else { - extern "C" { - pub fn SSL_CTX_get_ex_new_index( - argl: c_long, - argp: *mut c_void, - new_func: Option<::CRYPTO_EX_new>, - dup_func: Option<::CRYPTO_EX_dup>, - free_func: Option<::CRYPTO_EX_free>, - ) -> c_int; - } } } -extern "C" { - 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; -} 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()) @@ -1329,18 +549,19 @@ 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" { - // FIXME should take an option + #[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, ); - // FIXME should take an option + #[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, ); - // FIXME should take an option + #[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, @@ -1350,7 +571,7 @@ extern "C" { keylength: c_int, ) -> *mut ::EC_KEY, ); - // FIXME should take an option + #[deprecated(note = "use SSL_set_tmp_ecdh_callback__fixed_rust instead")] #[cfg(not(ossl110))] pub fn SSL_set_tmp_ecdh_callback( ssl: *mut SSL, @@ -1360,72 +581,36 @@ extern "C" { keylength: c_int, ) -> *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; -} + #[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; -extern "C" { - #[cfg(ossl110)] - pub fn SSL_CIPHER_get_cipher_nid(c: *const SSL_CIPHER) -> c_int; - #[cfg(ossl110)] - pub fn SSL_CIPHER_get_digest_nid(c: *const SSL_CIPHER) -> c_int; + #[deprecated(note = "use SSL_CTX_set_alpn_select_cb 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_if! { - if #[cfg(ossl110)] { - const_ptr_api! { - extern "C" { - pub fn SSL_session_reused(ssl: #[const_ptr_if(ossl111c)] SSL) -> c_int; - } - } - } else { - 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 - } - } -} -const_ptr_api! { - extern "C" { - #[cfg(any(ossl102, libressl273))] - pub fn SSL_is_server(s: #[const_ptr_if(any(ossl110f, libressl273))] SSL) -> c_int; - } +#[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; - -extern "C" { - #[cfg(ossl110)] - pub fn OPENSSL_init_ssl(opts: u64, settings: *const OPENSSL_INIT_SETTINGS) -> c_int; -} diff --git a/openssl-sys/src/tls1.rs b/openssl-sys/src/tls1.rs index c336257d43f90839f05d789e60d5e0000a0ecb95..86c6c8f35aae1bfe71e3d269f4b44db3088c8f4a 100644 --- a/openssl-sys/src/tls1.rs +++ b/openssl-sys/src/tls1.rs @@ -16,32 +16,6 @@ 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; -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; -} - pub unsafe fn SSL_set_tlsext_host_name(s: *mut SSL, name: *mut c_char) -> c_long { SSL_ctrl( s, @@ -82,6 +56,8 @@ pub unsafe fn SSL_set_tlsext_status_ocsp_resp( ) } +#[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 @@ -90,6 +66,13 @@ pub unsafe fn SSL_CTX_set_tlsext_servername_callback( 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; @@ -103,7 +86,7 @@ pub unsafe fn SSL_CTX_set_tlsext_status_cb( ctx: *mut SSL_CTX, cb: Option c_int>, ) -> c_long { - SSL_CTX_callback_ctrl(ctx, SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB, mem::transmute(cb)) + 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 { diff --git a/openssl-sys/src/types.rs b/openssl-sys/src/types.rs index 7598fb428f387e01f938c4611180eb5a965a292f..dbf11291afc9cfa60a94d13a0bb4a4442a1c20e6 100644 --- a/openssl-sys/src/types.rs +++ b/openssl-sys/src/types.rs @@ -1,2 +1,20 @@ -#[cfg(ossl300)] -pub enum OSSL_LIB_CTX {} +use libc::*; +use *; + +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 index 02dd181d4d5ea1e2b30199135a39a061f566a498..ee81842012dae6b4f84cf667de2ae178f40fa977 100644 --- a/openssl-sys/src/x509.rs +++ b/openssl-sys/src/x509.rs @@ -8,137 +8,6 @@ pub const X509_FILETYPE_DEFAULT: c_int = 3; pub const ASN1_R_HEADER_TOO_LONG: c_int = 123; -#[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(ossl110)] { - 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(ossl110)] { - 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(ossl110)] { - 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(ossl110)] { - 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(ossl110)] { - 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(ossl110)] { - 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); - cfg_if! { if #[cfg(not(ossl110))] { pub const X509_LU_FAIL: c_int = 0; @@ -146,506 +15,3 @@ cfg_if! { pub const X509_LU_CRL: c_int = 2; } } - -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, - } - } -} - -stack!(stack_st_X509_OBJECT); - -pub enum X509_LOOKUP {} - -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(ossl102)] - pub fn X509_ALGOR_get0( - paobj: *mut #[const_ptr_if(ossl110)] ASN1_OBJECT, - pptype: *mut c_int, - ppval: *mut #[const_ptr_if(ossl110)] c_void, - alg: #[const_ptr_if(ossl110)] 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; - } -} - -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, - ); - } -} -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; - } -} -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_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(ossl110)] { - 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(ossl110)] - 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(ossl110)] - 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(ossl110)] { - 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; -} diff --git a/openssl-sys/src/x509_vfy.rs b/openssl-sys/src/x509_vfy.rs index 341d7201884c07d49a8e634959d5015c93229181..403c60bf8536d1101db4524b45d88fb3dc3b2658 100644 --- a/openssl-sys/src/x509_vfy.rs +++ b/openssl-sys/src/x509_vfy.rs @@ -2,9 +2,6 @@ use libc::*; use *; -#[cfg(any(libressl, all(ossl102, not(ossl110))))] -pub enum X509_VERIFY_PARAM_ID {} - pub const X509_V_OK: c_int = 0; #[cfg(ossl102f)] pub const X509_V_ERR_UNSPECIFIED: c_int = 1; @@ -134,23 +131,6 @@ pub const X509_V_FLAG_NO_ALT_CHAINS: c_ulong = 0x100000; #[cfg(ossl110)] pub const X509_V_FLAG_NO_CHECK_TIME: c_ulong = 0x200000; -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_ctrl( - ctx: *mut X509_LOOKUP, - cmd: c_int, - argc: *const c_char, - argl: c_long, - ret: *mut *mut c_char, - ) -> c_int; -} - pub unsafe fn X509_LOOKUP_add_dir( ctx: *mut X509_LOOKUP, name: *const c_char, @@ -165,87 +145,3 @@ pub unsafe fn X509_LOOKUP_add_dir( std::ptr::null_mut(), ) } - -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; -} - -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(ossl110)] { - 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_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; -} -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; -} diff --git a/openssl-sys/src/x509v3.rs b/openssl-sys/src/x509v3.rs index 90fc77b87c6748a367ab197e7295a44b3683b2c5..ac826b601be82f952d151e2ffe6b89659c9ba7a4 100644 --- a/openssl-sys/src/x509v3.rs +++ b/openssl-sys/src/x509v3.rs @@ -2,7 +2,14 @@ use libc::*; use *; -pub enum CONF_METHOD {} +#[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; @@ -14,42 +21,6 @@ pub const GEN_URI: c_int = 6; pub const GEN_IPADD: c_int = 7; pub const GEN_RID: c_int = 8; -#[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); - -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); -} - #[cfg(any(ossl102, libressl261))] pub const X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT: c_uint = 0x1; #[cfg(any(ossl102, libressl261))] @@ -63,54 +34,6 @@ pub const X509_CHECK_FLAG_SINGLE_LABEL_SUBDOMAINS: c_uint = 0x10; #[cfg(ossl110)] pub const X509_CHECK_FLAG_NEVER_CHECK_SUBJECT: c_uint = 0x20; -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; - } -} - -// X509V3_add1_i2d (and *_add1_ext_i2d) pub const X509V3_ADD_DEFAULT: c_ulong = 0; pub const X509V3_ADD_APPEND: c_ulong = 1; pub const X509V3_ADD_REPLACE: c_ulong = 2; @@ -119,7 +42,6 @@ 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; -// X509_get_extension_flags pub const EXFLAG_BCONS: u32 = 0x1; pub const EXFLAG_KUSAGE: u32 = 0x2; pub const EXFLAG_XKUSAGE: u32 = 0x4; @@ -133,22 +55,9 @@ 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; -// before ossl102 / libressl260 EXFLAG_SS was 0x20 (the same as EXFLAG_SI); probably not useful semantic #[cfg(any(ossl102, libressl261))] pub const EXFLAG_SS: u32 = 0x2000; -/* -cfg_if! { - // probably gonna be in openssl-3.0.0-alpha7 - if #[cfg(any(ossl300))] { - pub const EXFLAG_BCONS_CRITICAL: u32 = 0x10000; - pub const EXFLAG_AKID_CRITICAL: u32 = 0x20000; - pub const EXFLAG_SKID_CRITICAL: u32 = 0x40000; - pub const EXFLAG_SAN_CRITICAL: u32 = 0x80000; - } -} -*/ -// X509_get_key_usage pub const X509v3_KU_DIGITAL_SIGNATURE: u32 = 0x0080; pub const X509v3_KU_NON_REPUDIATION: u32 = 0x0040; pub const X509v3_KU_KEY_ENCIPHERMENT: u32 = 0x0020; @@ -160,7 +69,6 @@ pub const X509v3_KU_ENCIPHER_ONLY: u32 = 0x0001; pub const X509v3_KU_DECIPHER_ONLY: u32 = 0x8000; pub const X509v3_KU_UNDEF: u32 = 0xffff; -// X509_get_extended_key_usage pub const XKU_SSL_SERVER: u32 = 0x1; pub const XKU_SSL_CLIENT: u32 = 0x2; pub const XKU_SMIME: u32 = 0x4; @@ -171,28 +79,3 @@ pub const XKU_TIMESTAMP: u32 = 0x40; pub const XKU_DVCS: u32 = 0x80; #[cfg(ossl110)] pub const XKU_ANYEKU: u32 = 0x100; - -extern "C" { - 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/Cargo.toml b/openssl/Cargo.toml index fb5bff0455f7288bade981be9b5d582e4af7d99f..acd6857ef8c562faaaf0ab72400d3aa2639d2173 100644 --- a/openssl/Cargo.toml +++ b/openssl/Cargo.toml @@ -18,6 +18,7 @@ v110 = [] v111 = [] vendored = ['ffi/vendored'] +bindgen = ['ffi/bindgen'] [dependencies] bitflags = "1.0" diff --git a/openssl/src/ssl/bio.rs b/openssl/src/ssl/bio.rs index 1a045bebdd1f0587a19d8418a1bda6bd17e38148..afc48d17934ef96905aa007d0f105c0992458703 100644 --- a/openssl/src/ssl/bio.rs +++ b/openssl/src/ssl/bio.rs @@ -205,12 +205,12 @@ cfg_if! { unsafe { let ptr = cvt_p(ffi::BIO_meth_new(ffi::BIO_TYPE_NONE, b"rust\0".as_ptr() as *const _))?; let method = BIO_METHOD(ptr); - cvt(ffi::BIO_meth_set_write(method.0, bwrite::))?; - cvt(ffi::BIO_meth_set_read(method.0, bread::))?; - cvt(ffi::BIO_meth_set_puts(method.0, bputs::))?; - cvt(ffi::BIO_meth_set_ctrl(method.0, ctrl::))?; - cvt(ffi::BIO_meth_set_create(method.0, create))?; - cvt(ffi::BIO_meth_set_destroy(method.0, destroy::))?; + cvt(ffi::BIO_meth_set_write__fixed_rust(method.0, Some(bwrite::)))?; + cvt(ffi::BIO_meth_set_read__fixed_rust(method.0, Some(bread::)))?; + cvt(ffi::BIO_meth_set_puts__fixed_rust(method.0, Some(bputs::)))?; + cvt(ffi::BIO_meth_set_ctrl__fixed_rust(method.0, Some(ctrl::)))?; + cvt(ffi::BIO_meth_set_create__fixed_rust(method.0, Some(create)))?; + cvt(ffi::BIO_meth_set_destroy__fixed_rust(method.0, Some(destroy::)))?; Ok(method) } } diff --git a/openssl/src/ssl/callbacks.rs b/openssl/src/ssl/callbacks.rs index 116c5445e07b6786f08f34b7ee09026cb72bb90f..f33f6ec0aafa1a6237e885d33d711642dbbf03f8 100644 --- a/openssl/src/ssl/callbacks.rs +++ b/openssl/src/ssl/callbacks.rs @@ -612,7 +612,7 @@ pub extern "C" fn raw_custom_ext_free( ssl: *mut ffi::SSL, _: c_uint, _: c_uint, - _: *mut *const c_uchar, + _: *const c_uchar, _: *mut c_void, ) where T: 'static + Sync + Send, diff --git a/openssl/src/ssl/mod.rs b/openssl/src/ssl/mod.rs index c7df4e6eb1e532c612e243baf6d69151e8aefc80..0e640bb0ef869ccf3b8398c742556dff8dc663ee 100644 --- a/openssl/src/ssl/mod.rs +++ b/openssl/src/ssl/mod.rs @@ -723,9 +723,10 @@ impl SslContextBuilder { let arg = self.set_ex_data_inner(SslContext::cached_ex_index::(), callback); ffi::SSL_CTX_set_tlsext_servername_arg(self.as_ptr(), arg); - let f: extern "C" fn(_, _, _) -> _ = raw_sni::; - let f: extern "C" fn() = mem::transmute(f); - ffi::SSL_CTX_set_tlsext_servername_callback(self.as_ptr(), Some(f)); + ffi::SSL_CTX_set_tlsext_servername_callback__fixed_rust( + self.as_ptr(), + Some(raw_sni::), + ); } } @@ -804,7 +805,7 @@ impl SslContextBuilder { { unsafe { self.set_ex_data(SslContext::cached_ex_index::(), callback); - ffi::SSL_CTX_set_tmp_dh_callback(self.as_ptr(), raw_tmp_dh::); + ffi::SSL_CTX_set_tmp_dh_callback__fixed_rust(self.as_ptr(), Some(raw_tmp_dh::)); } } @@ -831,7 +832,7 @@ impl SslContextBuilder { { unsafe { self.set_ex_data(SslContext::cached_ex_index::(), callback); - ffi::SSL_CTX_set_tmp_ecdh_callback(self.as_ptr(), raw_tmp_ecdh::); + ffi::SSL_CTX_set_tmp_ecdh_callback__fixed_rust(self.as_ptr(), Some(raw_tmp_ecdh::)); } } @@ -1203,9 +1204,9 @@ impl SslContextBuilder { { unsafe { self.set_ex_data(SslContext::cached_ex_index::(), callback); - ffi::SSL_CTX_set_alpn_select_cb( + ffi::SSL_CTX_set_alpn_select_cb__fixed_rust( self.as_ptr(), - callbacks::raw_alpn_select::, + Some(callbacks::raw_alpn_select::), ptr::null_mut(), ); } @@ -2284,7 +2285,7 @@ impl SslRef { unsafe { // this needs to be in an Arc since the callback can register a new callback! self.set_ex_data(Ssl::cached_ex_index(), Arc::new(callback)); - ffi::SSL_set_tmp_dh_callback(self.as_ptr(), raw_tmp_dh_ssl::); + ffi::SSL_set_tmp_dh_callback__fixed_rust(self.as_ptr(), Some(raw_tmp_dh_ssl::)); } } @@ -2309,7 +2310,7 @@ impl SslRef { unsafe { // this needs to be in an Arc since the callback can register a new callback! self.set_ex_data(Ssl::cached_ex_index(), Arc::new(callback)); - ffi::SSL_set_tmp_ecdh_callback(self.as_ptr(), raw_tmp_ecdh_ssl::); + ffi::SSL_set_tmp_ecdh_callback__fixed_rust(self.as_ptr(), Some(raw_tmp_ecdh_ssl::)); } } diff --git a/systest/Cargo.toml b/systest/Cargo.toml index 50f6662a055a614d245dc5ef10733b1c5c213068..97a5405b0ef702e919fa31ef099aa75505abf0ea 100644 --- a/systest/Cargo.toml +++ b/systest/Cargo.toml @@ -13,3 +13,4 @@ ctest2 = "0.4" [features] vendored = ['openssl-sys/vendored'] +bindgen = ['openssl-sys/bindgen'] diff --git a/systest/src/main.rs b/systest/src/main.rs index cbfa3da67e537bc06c4d92228634e2ce630a945a..c4583dd5b19e115d4ae2614e90adbc99b1f4d3a1 100644 --- a/systest/src/main.rs +++ b/systest/src/main.rs @@ -1,4 +1,4 @@ -#![allow(bad_style, clippy::all)] +#![allow(bad_style, deprecated, clippy::all)] use libc::*; use openssl_sys::*;