botan-sys-1.20250506.0/.cargo_vcs_info.json0000644000000001470000000000100135170ustar { "git": { "sha1": "401dd4b2b9bea5dd298245a2daff9593546249e5" }, "path_in_vcs": "botan-sys" }botan-sys-1.20250506.0/Cargo.lock0000644000000017640000000000100115000ustar # This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 3 [[package]] name = "botan-src" version = "0.30900.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a88e12835792947b309b91713daccb011f814092997b8784c1d4d5695d2d7739" [[package]] name = "botan-sys" version = "1.20250506.0" dependencies = [ "botan-src", "cc", "pkg-config", ] [[package]] name = "cc" version = "1.2.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3a42d84bb6b69d3a8b3eaacf0d88f179e1929695e1ad012b6cf64d9caaa5fd2" dependencies = [ "shlex", ] [[package]] name = "pkg-config" version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" [[package]] name = "shlex" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" botan-sys-1.20250506.0/Cargo.toml0000644000000026130000000000100115150ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2021" rust-version = "1.64" name = "botan-sys" version = "1.20250506.0" authors = ["Jack Lloyd "] build = "build/main.rs" links = "botan" autolib = false autobins = false autoexamples = false autotests = false autobenches = false description = "FFI wrapper for Botan cryptography library" homepage = "https://botan.randombit.net/" documentation = "https://docs.rs/botan-sys" readme = "README.md" categories = [ "cryptography", "external-ffi-bindings", "no-std", ] license = "MIT" repository = "https://github.com/randombit/botan-rs" [features] default = [] pkg-config = ["dep:pkg-config"] static = [] vendored = ["botan-src"] [lib] name = "botan_sys" path = "src/lib.rs" [[test]] name = "tests" path = "tests/tests.rs" [build-dependencies.botan-src] version = "0.30900.1" optional = true [build-dependencies.cc] version = "1" [build-dependencies.pkg-config] version = "0.3.30" optional = true botan-sys-1.20250506.0/Cargo.toml.orig000064400000000000000000000013411046102023000151730ustar 00000000000000[package] name = "botan-sys" version = "1.20250506.0" authors = ["Jack Lloyd "] links = "botan" build = "build/main.rs" description = "FFI wrapper for Botan cryptography library" license = "MIT" homepage = "https://botan.randombit.net/" repository = "https://github.com/randombit/botan-rs" documentation = "https://docs.rs/botan-sys" readme = "README.md" categories = [ "cryptography", "external-ffi-bindings", "no-std" ] edition = "2021" rust-version = "1.64" [features] default = [] vendored = ["botan-src"] static = [] pkg-config = ["dep:pkg-config"] [build-dependencies] botan-src = { version = "0.30900.1", optional = true, path = "../botan-src" } pkg-config = { version = "0.3.30", optional = true } cc = "1" botan-sys-1.20250506.0/README.md000064400000000000000000000025031046102023000135640ustar 00000000000000# botan-sys This crate contains the FFI declarations for calling the C API included in the [Botan](https://botan.randombit.net/) cryptography library as well as the rules for linking to it. A high level Rust interface built on these declarations is included in the [botan](https://crates.io/crates/botan) crate. This crate is always `no_std` ## Features * `vendored`: Build against the `botan-src` crate * `static`: Statically link the library. This is always used if `vendored` is set * `pkg-config`: Use `pkg-config` instead of probing to find the library ## Exported cfg This crate will detect which version of the FFI interface is supported and enable features on that basis. The feature sets can be checked using * `#[cfg(botan_ffi_20230403)]`: Botan 3.0 * `#[cfg(botan_ffi_20240408)]`: Botan 3.4 * `#[cfg(botan_ffi_20250506)]`: Botan 3.8 ## Environment Variables The following environment variables are used to guide features * `BOTAN_INCLUDE_DIR` the base path to where the relevant library includes are found. For example if the headers are in `/opt/foo/botan-3/botan`, this variable should be set to `/opt/foo`. If not set, tries a few common locations. This variable is ignored if the `pkg-config` or `vendored` features are used. * `BOTAN_LIB_DIR` the directory to search for pre-build shared or static libraries. botan-sys-1.20250506.0/build/main.rs000064400000000000000000000176301046102023000147050ustar 00000000000000use std::collections::HashMap; use std::path::PathBuf; const KNOWN_FFI_VERSIONS: [(u32, u32); 7] = [ (3, 20250506), // 3.8 (3, 20240408), // 3.4 (3, 20231009), // 3.2 (3, 20230711), // 3.1 (3, 20230403), // 3.0 (2, 20210220), // 2.18 (2, 20191214), // 2.13 ]; const LATEST_KNOWN_FFI: u32 = 20250506; #[cfg(feature = "vendored")] fn emit_dylibs() -> Vec<&'static str> { // Windows doesn't need to dynamically link the C++ runtime // but we do need to link to DLLs with needed functionality: if cfg!(target_os = "windows") { return vec!["user32", "crypt32"]; } // On Linux we use libstdc++ if cfg!(any(target_os = "linux")) { return vec!["stdc++"]; } // For all other platforms, link to libc++ from LLVM/Clang vec!["c++"] } fn sanity_check_ffi(major_version: u32, minor_version: u32, ffi_version: u32) -> u32 { if ffi_version == 0 { panic!("The libbotan found does not support the FFI feature"); } if ffi_version < 20191214 { panic!("This version of Botan is too old; at least 2.13.0 is required"); } if major_version < 2 { panic!("Major version 1 or lower not supported"); } if major_version > 4 { panic!("Major version unexpectedly high"); } if major_version >= 3 && ffi_version > LATEST_KNOWN_FFI { // Some future version; assume FFI is additive return LATEST_KNOWN_FFI; } for (mv, fv) in &KNOWN_FFI_VERSIONS { if ffi_version == *fv && major_version >= *mv { return *fv; } } panic!( "Unexpected version settings major={major_version} minor={minor_version} ffi={ffi_version}" ); } #[allow(dead_code)] fn env_var(key: &str) -> Option { println!("cargo:rerun-if-env-changed={key}"); std::env::var(key).ok() } #[derive(Debug, Copy, Clone)] struct DetectedVersionInfo { major_version: u32, #[allow(dead_code)] minor_version: u32, ffi_version: u32, } impl DetectedVersionInfo { fn library_link_name(&self) -> String { if cfg!(target_os = "windows") && self.major_version == 2 { // For some unknown reason, Botan 2.x does not include // the major version in the name of the Windows library "botan".to_string() } else { format!("botan-{}", self.major_version) } } #[allow(dead_code)] fn latest_for_docs_rs() -> Self { Self { major_version: 3, minor_version: 8, ffi_version: LATEST_KNOWN_FFI, } } fn from_map(map: HashMap) -> Self { let major_version = *map.get("MAJOR_VERSION").expect("Missing MAJOR_VERSION"); let minor_version = *map.get("MINOR_VERSION").expect("Missing MINOR_VERSION"); let ffi_version = *map.get("FFI_VERSION").expect("Missing FFI_VERSION"); let ffi_version = sanity_check_ffi(major_version, minor_version, ffi_version); Self { major_version, minor_version, ffi_version, } } fn from_header(include_dir: &PathBuf) -> Self { println!("cargo:rerun-if-changed=build/version.c"); let mut cc = cc::Build::new(); cc.include(include_dir); match cc.file("build/version.c").try_expand() { Ok(o) => { let expanded = String::from_utf8(o).expect("Output is not valid UTF8"); let mut map = HashMap::new(); for line in expanded.split('\n') { if line.is_empty() || line.starts_with('#') { continue; } let line = line.replace('\r', ""); let parts = line.split(' ').collect::>(); if parts.len() != 2 { continue; } if parts[0] == "MAJOR_VERSION" || parts[0] == "MINOR_VERSION" || parts[0] == "FFI_VERSION" { if let Ok(code) = parts[1].parse::() { map.insert(parts[0].to_owned(), code); } else { panic!("Unexpected line '{line}'"); } } } DetectedVersionInfo::from_map(map) } Err(e) => { panic!("Failed to expand header {e:?}"); } } } } #[cfg(not(feature = "vendored"))] fn find_botan_include_dir() -> std::path::PathBuf { #[cfg(feature = "pkg-config")] { for major in [3, 2] { let lib_name = format!("botan-{}", major); let statik = cfg!(feature = "static"); if let Ok(config) = pkg_config::Config::new().statik(statik).probe(&lib_name) { return config.include_paths[0].clone(); } } panic!("Unable to find the headers corresponding with any supported version of Botan"); } #[cfg(not(feature = "pkg-config"))] { if let Some(dir) = env_var("BOTAN_INCLUDE_DIR") { return dir.into(); } fn possible_header_locations() -> Vec { let dirs = [ "/opt/homebrew/include", "/usr/local/include", "/usr/include", "/opt/include", ]; let mut paths = vec![]; for dirname in dirs { let path = PathBuf::from(dirname); if path.exists() { paths.push(path); } } paths } for major_version in [3, 2] { let dir = PathBuf::from(format!("botan-{major_version}")); for basedir in possible_header_locations() { let inc_dir = basedir.join(dir.clone()); if inc_dir.exists() { return inc_dir; } } } panic!("Unable to find the headers corresponding with any supported version of Botan"); } } fn main() { for (_, v) in &KNOWN_FFI_VERSIONS { println!("cargo:rustc-check-cfg=cfg(botan_ffi_{v})"); } // TODO refactor this to avoid duplication between the two branches #[cfg(feature = "vendored")] { let (lib_dir, inc_dir) = botan_src::build(); let version = DetectedVersionInfo::from_header(&inc_dir); println!("cargo:vendored=1"); println!("cargo:rustc-link-search=native={}", &lib_dir); println!( "cargo:rustc-link-lib=static={}", version.library_link_name() ); for dylib in emit_dylibs() { println!("cargo:rustc-flags=-l dylib={}", dylib); } println!("cargo:ffi_version={}", version.ffi_version); for (_, ffi) in &KNOWN_FFI_VERSIONS { if *ffi <= version.ffi_version { println!("cargo:rustc-cfg=botan_ffi_{}", ffi); } } } #[cfg(not(feature = "vendored"))] { let version = if std::env::var("DOCS_RS").is_ok() { DetectedVersionInfo::latest_for_docs_rs() } else { DetectedVersionInfo::from_header(&find_botan_include_dir()) }; if let Some(dir) = env_var("BOTAN_LIB_DIR") { println!("cargo:rustc-link-search=native={dir}"); } if cfg!(feature = "static") { println!( "cargo:rustc-link-lib=static={}", version.library_link_name() ); } else { println!("cargo:rustc-link-lib={}", version.library_link_name()); } // TODO(MSRV) cargo::metadata after 1.77 println!("cargo:ffi_version={}", version.ffi_version); for (_, ffi) in &KNOWN_FFI_VERSIONS { if *ffi <= version.ffi_version { println!("cargo:rustc-cfg=botan_ffi_{ffi}"); } } } } botan-sys-1.20250506.0/build/version.c000064400000000000000000000002571046102023000152410ustar 00000000000000#include MAJOR_VERSION BOTAN_VERSION_MAJOR MINOR_VERSION BOTAN_VERSION_MINOR #if defined(BOTAN_HAS_FFI) FFI_VERSION BOTAN_HAS_FFI #else FFI_VERSION 0 #endif botan-sys-1.20250506.0/src/block.rs000064400000000000000000000024531046102023000145400ustar 00000000000000use crate::ffi_types::{c_char, c_int}; pub enum botan_block_cipher_struct {} pub type botan_block_cipher_t = *mut botan_block_cipher_struct; extern "C" { pub fn botan_block_cipher_init( bc: *mut botan_block_cipher_t, cipher_name: *const c_char, ) -> c_int; pub fn botan_block_cipher_destroy(bc: botan_block_cipher_t) -> c_int; pub fn botan_block_cipher_name( bc: botan_block_cipher_t, name: *mut c_char, name_len: *mut usize, ) -> c_int; pub fn botan_block_cipher_get_keyspec( bc: botan_block_cipher_t, min_keylen: *mut usize, max_keylen: *mut usize, mod_keylen: *mut usize, ) -> c_int; pub fn botan_block_cipher_clear(bc: botan_block_cipher_t) -> c_int; pub fn botan_block_cipher_set_key( bc: botan_block_cipher_t, key: *const u8, len: usize, ) -> c_int; pub fn botan_block_cipher_block_size(bc: botan_block_cipher_t) -> c_int; pub fn botan_block_cipher_encrypt_blocks( bc: botan_block_cipher_t, input: *const u8, output: *mut u8, blocks: usize, ) -> c_int; pub fn botan_block_cipher_decrypt_blocks( bc: botan_block_cipher_t, input: *const u8, output: *mut u8, blocks: usize, ) -> c_int; } botan-sys-1.20250506.0/src/cipher.rs000064400000000000000000000041711046102023000147170ustar 00000000000000use crate::ffi_types::{c_char, c_int}; pub enum botan_cipher_struct {} pub type botan_cipher_t = *mut botan_cipher_struct; extern "C" { pub fn botan_cipher_init(cipher: *mut botan_cipher_t, name: *const c_char, flags: u32) -> c_int; pub fn botan_cipher_valid_nonce_length(cipher: botan_cipher_t, nl: usize) -> c_int; pub fn botan_cipher_get_tag_length(cipher: botan_cipher_t, tag_size: *mut usize) -> c_int; pub fn botan_cipher_get_default_nonce_length(cipher: botan_cipher_t, nl: *mut usize) -> c_int; pub fn botan_cipher_get_update_granularity(cipher: botan_cipher_t, ug: *mut usize) -> c_int; #[cfg(botan_ffi_20230403)] pub fn botan_cipher_get_ideal_update_granularity( cipher: botan_cipher_t, ug: *mut usize, ) -> c_int; pub fn botan_cipher_query_keylen( cipher: botan_cipher_t, out_minimum_keylength: *mut usize, out_maximum_keylength: *mut usize, ) -> c_int; pub fn botan_cipher_get_keyspec( cipher: botan_cipher_t, min_keylen: *mut usize, max_keylen: *mut usize, mod_keylen: *mut usize, ) -> c_int; pub fn botan_cipher_set_key(cipher: botan_cipher_t, key: *const u8, key_len: usize) -> c_int; pub fn botan_cipher_set_associated_data( cipher: botan_cipher_t, ad: *const u8, ad_len: usize, ) -> c_int; pub fn botan_cipher_start(cipher: botan_cipher_t, nonce: *const u8, nonce_len: usize) -> c_int; pub fn botan_cipher_update( cipher: botan_cipher_t, flags: u32, output: *mut u8, output_size: usize, output_written: *mut usize, input_bytes: *const u8, input_size: usize, input_consumed: *mut usize, ) -> c_int; pub fn botan_cipher_name( cipher: botan_cipher_t, name: *mut c_char, name_len: *mut usize, ) -> c_int; pub fn botan_cipher_output_length( cipher: botan_cipher_t, inlen: usize, outlen: *mut usize, ) -> c_int; pub fn botan_cipher_clear(cipher: botan_cipher_t) -> c_int; pub fn botan_cipher_destroy(cipher: botan_cipher_t) -> c_int; } botan-sys-1.20250506.0/src/ec_group.rs000064400000000000000000000045261046102023000152540ustar 00000000000000#[cfg(botan_ffi_20250506)] use crate::ffi_types::{botan_view_bin_fn, botan_view_ctx, botan_view_str_fn, c_char, c_int}; #[cfg(botan_ffi_20250506)] use crate::{botan_asn1_oid_t, botan_mp_t}; #[cfg(botan_ffi_20250506)] pub enum botan_ec_group_struct {} #[cfg(botan_ffi_20250506)] pub type botan_ec_group_t = *mut botan_ec_group_struct; #[cfg(botan_ffi_20250506)] extern "C" { pub fn botan_ec_group_destroy(bc: botan_ec_group_t) -> c_int; pub fn botan_ec_group_supports_application_specific_group(res: *mut c_int) -> c_int; pub fn botan_ec_group_supports_named_group(name: *const c_char, res: *mut c_int) -> c_int; pub fn botan_ec_group_from_params( group: *mut botan_ec_group_t, oid: botan_asn1_oid_t, p: botan_mp_t, a: botan_mp_t, b: botan_mp_t, g_x: botan_mp_t, g_y: botan_mp_t, order: botan_mp_t, ) -> c_int; pub fn botan_ec_group_from_ber( group: *mut botan_ec_group_t, ber: *const u8, ber_len: usize, ) -> c_int; pub fn botan_ec_group_from_pem(group: *mut botan_ec_group_t, pem: *const c_char) -> c_int; pub fn botan_ec_group_from_oid(group: *mut botan_ec_group_t, oid: botan_asn1_oid_t) -> c_int; pub fn botan_ec_group_from_name(group: *mut botan_ec_group_t, name: *const c_char) -> c_int; pub fn botan_ec_group_view_der( group: botan_ec_group_t, ctx: botan_view_ctx, view: botan_view_bin_fn, ) -> c_int; pub fn botan_ec_group_view_pem( group: botan_ec_group_t, ctx: botan_view_ctx, view: botan_view_str_fn, ) -> c_int; pub fn botan_ec_group_get_curve_oid( oid: *mut botan_asn1_oid_t, group: botan_ec_group_t, ) -> c_int; pub fn botan_ec_group_get_p(p: *mut botan_mp_t, group: botan_ec_group_t) -> c_int; pub fn botan_ec_group_get_a(a: *mut botan_mp_t, group: botan_ec_group_t) -> c_int; pub fn botan_ec_group_get_b(b: *mut botan_mp_t, group: botan_ec_group_t) -> c_int; pub fn botan_ec_group_get_g_x(g_x: *mut botan_mp_t, group: botan_ec_group_t) -> c_int; pub fn botan_ec_group_get_g_y(g_y: *mut botan_mp_t, group: botan_ec_group_t) -> c_int; pub fn botan_ec_group_get_order(order: *mut botan_mp_t, group: botan_ec_group_t) -> c_int; pub fn botan_ec_group_equal(group1: botan_ec_group_t, group2: botan_ec_group_t) -> c_int; } botan-sys-1.20250506.0/src/errors.rs000064400000000000000000000032511046102023000147570ustar 00000000000000use crate::ffi_types::{c_char, c_int}; #[allow(clippy::upper_case_acronyms)] pub type BOTAN_FFI_ERROR = c_int; pub const BOTAN_FFI_SUCCESS: BOTAN_FFI_ERROR = 0; pub const BOTAN_FFI_INVALID_VERIFIER: BOTAN_FFI_ERROR = 1; pub const BOTAN_FFI_ERROR_INVALID_INPUT: BOTAN_FFI_ERROR = -1; pub const BOTAN_FFI_ERROR_BAD_MAC: BOTAN_FFI_ERROR = -2; pub const BOTAN_FFI_ERROR_NO_VALUE: BOTAN_FFI_ERROR = -3; pub const BOTAN_FFI_ERROR_INSUFFICIENT_BUFFER_SPACE: BOTAN_FFI_ERROR = -10; pub const BOTAN_FFI_ERROR_STRING_CONVERSION_ERROR: BOTAN_FFI_ERROR = -11; pub const BOTAN_FFI_ERROR_EXCEPTION_THROWN: BOTAN_FFI_ERROR = -20; pub const BOTAN_FFI_ERROR_OUT_OF_MEMORY: BOTAN_FFI_ERROR = -21; pub const BOTAN_FFI_ERROR_SYSTEM_ERROR: BOTAN_FFI_ERROR = -22; pub const BOTAN_FFI_ERROR_INTERNAL_ERROR: BOTAN_FFI_ERROR = -23; pub const BOTAN_FFI_ERROR_BAD_FLAG: BOTAN_FFI_ERROR = -30; pub const BOTAN_FFI_ERROR_NULL_POINTER: BOTAN_FFI_ERROR = -31; pub const BOTAN_FFI_ERROR_BAD_PARAMETER: BOTAN_FFI_ERROR = -32; pub const BOTAN_FFI_ERROR_KEY_NOT_SET: BOTAN_FFI_ERROR = -33; pub const BOTAN_FFI_ERROR_INVALID_KEY_LENGTH: BOTAN_FFI_ERROR = -34; pub const BOTAN_FFI_ERROR_INVALID_OBJECT_STATE: BOTAN_FFI_ERROR = -35; pub const BOTAN_FFI_ERROR_NOT_IMPLEMENTED: BOTAN_FFI_ERROR = -40; pub const BOTAN_FFI_ERROR_INVALID_OBJECT: BOTAN_FFI_ERROR = -50; pub const BOTAN_FFI_ERROR_TLS_ERROR: BOTAN_FFI_ERROR = -75; pub const BOTAN_FFI_ERROR_HTTP_ERROR: BOTAN_FFI_ERROR = -76; pub const BOTAN_FFI_ERROR_UNKNOWN_ERROR: BOTAN_FFI_ERROR = -100; extern "C" { pub fn botan_error_description(err: BOTAN_FFI_ERROR) -> *const c_char; #[cfg(botan_ffi_20230403)] pub fn botan_error_last_exception_message() -> *const c_char; } botan-sys-1.20250506.0/src/fpe.rs000064400000000000000000000012711046102023000142150ustar 00000000000000use crate::ffi_types::c_int; use crate::mp::botan_mp_t; pub enum botan_fpe_struct {} pub type botan_fpe_t = *mut botan_fpe_struct; extern "C" { pub fn botan_fpe_fe1_init( fpe: *mut botan_fpe_t, n: botan_mp_t, key: *const u8, key_len: usize, rounds: usize, flags: u32, ) -> c_int; pub fn botan_fpe_destroy(fpe: botan_fpe_t) -> c_int; pub fn botan_fpe_encrypt( fpe: botan_fpe_t, x: botan_mp_t, tweak: *const u8, tweak_len: usize, ) -> c_int; pub fn botan_fpe_decrypt( fpe: botan_fpe_t, x: botan_mp_t, tweak: *const u8, tweak_len: usize, ) -> c_int; } botan-sys-1.20250506.0/src/hash.rs000064400000000000000000000015721046102023000143720ustar 00000000000000use crate::ffi_types::{c_char, c_int}; pub enum botan_hash_struct {} pub type botan_hash_t = *mut botan_hash_struct; extern "C" { pub fn botan_hash_init(hash: *mut botan_hash_t, hash_name: *const c_char, flags: u32) -> c_int; pub fn botan_hash_copy_state(dest: *mut botan_hash_t, source: botan_hash_t) -> c_int; pub fn botan_hash_name(hash: botan_hash_t, name: *mut c_char, name_len: *mut usize) -> c_int; pub fn botan_hash_output_length(hash: botan_hash_t, output_length: *mut usize) -> c_int; pub fn botan_hash_block_size(hash: botan_hash_t, block_size: *mut usize) -> c_int; pub fn botan_hash_update(hash: botan_hash_t, data: *const u8, len: usize) -> c_int; pub fn botan_hash_final(hash: botan_hash_t, digest: *mut u8) -> c_int; pub fn botan_hash_clear(hash: botan_hash_t) -> c_int; pub fn botan_hash_destroy(hash: botan_hash_t) -> c_int; } botan-sys-1.20250506.0/src/kdf.rs000064400000000000000000000032771046102023000142170ustar 00000000000000use crate::ffi_types::{c_char, c_int}; extern "C" { pub fn botan_pbkdf( pbkdf_algo: *const c_char, out: *mut u8, out_len: usize, passphrase: *const c_char, salt: *const u8, salt_len: usize, iterations: usize, ) -> c_int; pub fn botan_pbkdf_timed( pbkdf_algo: *const c_char, out: *mut u8, out_len: usize, passphrase: *const c_char, salt: *const u8, salt_len: usize, milliseconds_to_run: usize, out_iterations_used: *mut usize, ) -> c_int; pub fn botan_pwdhash( algo: *const c_char, param1: usize, param2: usize, param3: usize, out: *mut u8, out_len: usize, passphrase: *const c_char, passphrase_len: usize, salt: *const u8, salt_len: usize, ) -> c_int; pub fn botan_pwdhash_timed( algo: *const c_char, msec: u32, param1: *mut usize, param2: *mut usize, param3: *mut usize, out: *mut u8, out_len: usize, passphrase: *const c_char, passphrase_len: usize, salt: *const u8, salt_len: usize, ) -> c_int; pub fn botan_scrypt( out: *mut u8, out_len: usize, passphrase: *const c_char, salt: *const u8, salt_len: usize, N: usize, r: usize, p: usize, ) -> c_int; pub fn botan_kdf( kdf_algo: *const c_char, out: *mut u8, out_len: usize, secret: *const u8, secret_len: usize, salt: *const u8, salt_len: usize, label: *const u8, label_len: usize, ) -> c_int; } botan-sys-1.20250506.0/src/keywrap.rs000064400000000000000000000021511046102023000151230ustar 00000000000000use crate::ffi_types::{c_char, c_int}; extern "C" { pub fn botan_key_wrap3394( input: *const u8, input_len: usize, kek: *const u8, kek_len: usize, wrapped_key: *mut u8, wrapped_key_len: *mut usize, ) -> c_int; pub fn botan_key_unwrap3394( wrapped_key: *const u8, wrapped_key_len: usize, kek: *const u8, kek_len: usize, unwrapped_key: *mut u8, unwrapped_key_len: *mut usize, ) -> c_int; #[cfg(botan_ffi_20230403)] pub fn botan_nist_kw_enc( cipher_algo: *const c_char, padding: c_int, input: *const u8, input_len: usize, kek: *const u8, kek_len: usize, wrapped_key: *mut u8, wrapped_key_len: *mut usize, ) -> c_int; #[cfg(botan_ffi_20230403)] pub fn botan_nist_kw_dec( cipher_algo: *const c_char, padding: c_int, wrapped_key: *const u8, wrapped_key_len: usize, kek: *const u8, kek_len: usize, unwrapped_key: *mut u8, unwrapped_key_len: *mut usize, ) -> c_int; } botan-sys-1.20250506.0/src/lib.rs000064400000000000000000000021211046102023000142040ustar 00000000000000#![no_std] #![allow(non_camel_case_types)] #![allow(unused_imports)] mod block; mod cipher; mod ec_group; mod errors; mod fpe; mod hash; mod kdf; mod keywrap; mod mac; mod mp; mod oid; mod otp; mod passhash; mod pk_ops; mod pubkey; mod rng; mod utils; mod version; mod x509; mod zfec; pub mod ffi_types { pub use core::ffi::{c_char, c_int, c_uint, c_void}; #[cfg(botan_ffi_20230403)] pub type botan_view_ctx = *mut c_void; #[cfg(botan_ffi_20230403)] pub type botan_view_bin_fn = extern "C" fn(view_ctx: botan_view_ctx, data: *const u8, len: usize) -> c_int; #[cfg(botan_ffi_20230403)] pub type botan_view_str_fn = extern "C" fn(view_ctx: botan_view_ctx, data: *const c_char, len: usize) -> c_int; } pub use block::*; pub use cipher::*; pub use ec_group::*; pub use errors::*; pub use fpe::*; pub use hash::*; pub use kdf::*; pub use keywrap::*; pub use mac::*; pub use mp::*; pub use oid::*; pub use otp::*; pub use passhash::*; pub use pk_ops::*; pub use pubkey::*; pub use rng::*; pub use utils::*; pub use version::*; pub use x509::*; pub use zfec::*; botan-sys-1.20250506.0/src/mac.rs000064400000000000000000000020601046102023000142000ustar 00000000000000use crate::ffi_types::{c_char, c_int}; pub enum botan_mac_struct {} pub type botan_mac_t = *mut botan_mac_struct; extern "C" { pub fn botan_mac_init(mac: *mut botan_mac_t, mac_name: *const c_char, flags: u32) -> c_int; pub fn botan_mac_output_length(mac: botan_mac_t, output_length: *mut usize) -> c_int; pub fn botan_mac_set_key(mac: botan_mac_t, key: *const u8, key_len: usize) -> c_int; #[cfg(botan_ffi_20230403)] pub fn botan_mac_set_nonce(mac: botan_mac_t, nonce: *const u8, nonce_len: usize) -> c_int; pub fn botan_mac_name(mac: botan_mac_t, name: *mut c_char, name_len: *mut usize) -> c_int; pub fn botan_mac_get_keyspec( mac: botan_mac_t, min_keylen: *mut usize, max_keylen: *mut usize, mod_keylen: *mut usize, ) -> c_int; pub fn botan_mac_update(mac: botan_mac_t, buf: *const u8, len: usize) -> c_int; pub fn botan_mac_final(mac: botan_mac_t, out: *mut u8) -> c_int; pub fn botan_mac_clear(mac: botan_mac_t) -> c_int; pub fn botan_mac_destroy(mac: botan_mac_t) -> c_int; } botan-sys-1.20250506.0/src/mp.rs000064400000000000000000000067541046102023000140720ustar 00000000000000use crate::ffi_types::{c_char, c_int}; use crate::rng::botan_rng_t; pub enum botan_mp_struct {} pub type botan_mp_t = *mut botan_mp_struct; extern "C" { pub fn botan_mp_init(mp: *mut botan_mp_t) -> c_int; pub fn botan_mp_destroy(mp: botan_mp_t) -> c_int; pub fn botan_mp_to_hex(mp: botan_mp_t, out: *mut c_char) -> c_int; pub fn botan_mp_to_str( mp: botan_mp_t, base: u8, out: *mut c_char, out_len: *mut usize, ) -> c_int; pub fn botan_mp_clear(mp: botan_mp_t) -> c_int; pub fn botan_mp_set_from_int(mp: botan_mp_t, initial_value: c_int) -> c_int; pub fn botan_mp_set_from_mp(dest: botan_mp_t, source: botan_mp_t) -> c_int; pub fn botan_mp_set_from_str(dest: botan_mp_t, str: *const c_char) -> c_int; pub fn botan_mp_set_from_radix_str(dest: botan_mp_t, str: *const c_char, radix: usize) -> c_int; pub fn botan_mp_num_bits(n: botan_mp_t, bits: *mut usize) -> c_int; pub fn botan_mp_num_bytes(n: botan_mp_t, bytes: *mut usize) -> c_int; pub fn botan_mp_to_bin(mp: botan_mp_t, vec: *mut u8) -> c_int; pub fn botan_mp_from_bin(mp: botan_mp_t, vec: *const u8, vec_len: usize) -> c_int; pub fn botan_mp_to_uint32(mp: botan_mp_t, val: *mut u32) -> c_int; pub fn botan_mp_is_positive(mp: botan_mp_t) -> c_int; pub fn botan_mp_is_negative(mp: botan_mp_t) -> c_int; pub fn botan_mp_flip_sign(mp: botan_mp_t) -> c_int; pub fn botan_mp_is_zero(mp: botan_mp_t) -> c_int; pub fn botan_mp_is_odd(mp: botan_mp_t) -> c_int; pub fn botan_mp_is_even(mp: botan_mp_t) -> c_int; pub fn botan_mp_add(result: botan_mp_t, x: botan_mp_t, y: botan_mp_t) -> c_int; pub fn botan_mp_sub(result: botan_mp_t, x: botan_mp_t, y: botan_mp_t) -> c_int; pub fn botan_mp_add_u32(result: botan_mp_t, x: botan_mp_t, y: u32) -> c_int; pub fn botan_mp_sub_u32(result: botan_mp_t, x: botan_mp_t, y: u32) -> c_int; pub fn botan_mp_mul(result: botan_mp_t, x: botan_mp_t, y: botan_mp_t) -> c_int; pub fn botan_mp_div( quotient: botan_mp_t, remainder: botan_mp_t, x: botan_mp_t, y: botan_mp_t, ) -> c_int; pub fn botan_mp_mod_mul( result: botan_mp_t, x: botan_mp_t, y: botan_mp_t, mod_: botan_mp_t, ) -> c_int; pub fn botan_mp_equal(x: botan_mp_t, y: botan_mp_t) -> c_int; pub fn botan_mp_cmp(result: *mut c_int, x: botan_mp_t, y: botan_mp_t) -> c_int; pub fn botan_mp_swap(x: botan_mp_t, y: botan_mp_t) -> c_int; pub fn botan_mp_powmod( out: botan_mp_t, base: botan_mp_t, exponent: botan_mp_t, modulus: botan_mp_t, ) -> c_int; pub fn botan_mp_lshift(out: botan_mp_t, in_: botan_mp_t, shift: usize) -> c_int; pub fn botan_mp_rshift(out: botan_mp_t, in_: botan_mp_t, shift: usize) -> c_int; pub fn botan_mp_mod_inverse(out: botan_mp_t, in_: botan_mp_t, modulus: botan_mp_t) -> c_int; pub fn botan_mp_rand_bits(rand_out: botan_mp_t, rng: botan_rng_t, bits: usize) -> c_int; pub fn botan_mp_rand_range( rand_out: botan_mp_t, rng: botan_rng_t, lower_bound: botan_mp_t, upper_bound: botan_mp_t, ) -> c_int; pub fn botan_mp_gcd(out: botan_mp_t, x: botan_mp_t, y: botan_mp_t) -> c_int; pub fn botan_mp_is_prime(n: botan_mp_t, rng: botan_rng_t, test_prob: usize) -> c_int; pub fn botan_mp_get_bit(n: botan_mp_t, bit: usize) -> c_int; pub fn botan_mp_set_bit(n: botan_mp_t, bit: usize) -> c_int; pub fn botan_mp_clear_bit(n: botan_mp_t, bit: usize) -> c_int; } botan-sys-1.20250506.0/src/oid.rs000064400000000000000000000020251046102023000142140ustar 00000000000000#[cfg(botan_ffi_20250506)] use crate::ffi_types::{botan_view_ctx, botan_view_str_fn, c_char, c_int}; #[cfg(botan_ffi_20250506)] pub enum botan_asn1_oid_struct {} #[cfg(botan_ffi_20250506)] pub type botan_asn1_oid_t = *mut botan_asn1_oid_struct; #[cfg(botan_ffi_20250506)] extern "C" { pub fn botan_oid_destroy(bc: botan_asn1_oid_t) -> c_int; pub fn botan_oid_from_string(oid: *mut botan_asn1_oid_t, oid_str: *const c_char) -> c_int; pub fn botan_oid_register(oid: botan_asn1_oid_t, name: *const c_char) -> c_int; pub fn botan_oid_view_string( oid: botan_asn1_oid_t, ctx: botan_view_ctx, view_fn: botan_view_str_fn, ) -> c_int; pub fn botan_oid_view_name( oid: botan_asn1_oid_t, ctx: botan_view_ctx, view_fn: botan_view_str_fn, ) -> c_int; pub fn botan_oid_equal(oid1: botan_asn1_oid_t, oid2: botan_asn1_oid_t) -> c_int; pub fn botan_oid_cmp( result: *mut c_int, oid1: botan_asn1_oid_t, oid2: botan_asn1_oid_t, ) -> c_int; } botan-sys-1.20250506.0/src/otp.rs000064400000000000000000000023761046102023000142540ustar 00000000000000use crate::ffi_types::{c_char, c_int}; pub enum botan_hotp_struct {} pub type botan_hotp_t = *mut botan_hotp_struct; pub enum botan_totp_struct {} pub type botan_totp_t = *mut botan_totp_struct; extern "C" { pub fn botan_hotp_init( hotp: *mut botan_hotp_t, key: *const u8, key_len: usize, hash_algo: *const c_char, digits: usize, ) -> c_int; pub fn botan_hotp_destroy(hotp: botan_hotp_t) -> c_int; pub fn botan_hotp_generate(hotp: botan_hotp_t, hotp_code: *mut u32, hotp_counter: u64) -> c_int; pub fn botan_hotp_check( hotp: botan_hotp_t, next_counter: *mut u64, hotp_code: u32, hotp_counter: u64, resync_range: usize, ) -> c_int; pub fn botan_totp_init( totp: *mut botan_totp_t, key: *const u8, key_len: usize, hash_algo: *const c_char, digits: usize, time_step: usize, ) -> c_int; pub fn botan_totp_destroy(totp: botan_totp_t) -> c_int; pub fn botan_totp_generate(totp: botan_totp_t, totp_code: *mut u32, timestamp: u64) -> c_int; pub fn botan_totp_check( totp: botan_totp_t, totp_code: u32, timestamp: u64, acceptable_drift: usize, ) -> c_int; } botan-sys-1.20250506.0/src/passhash.rs000064400000000000000000000005751046102023000152630ustar 00000000000000use crate::ffi_types::{c_char, c_int}; use crate::rng::botan_rng_t; extern "C" { pub fn botan_bcrypt_generate( out: *mut u8, out_len: *mut usize, password: *const c_char, rng: botan_rng_t, work_factor: usize, flags: u32, ) -> c_int; pub fn botan_bcrypt_is_valid(pass: *const c_char, hash: *const c_char) -> c_int; } botan-sys-1.20250506.0/src/pk_ops.rs000064400000000000000000000143001046102023000147330ustar 00000000000000use crate::ffi_types::*; use crate::pubkey::{botan_privkey_t, botan_pubkey_t}; use crate::rng::botan_rng_t; pub enum botan_pk_op_encrypt_struct {} pub type botan_pk_op_encrypt_t = *mut botan_pk_op_encrypt_struct; pub enum botan_pk_op_decrypt_struct {} pub type botan_pk_op_decrypt_t = *mut botan_pk_op_decrypt_struct; pub enum botan_pk_op_sign_struct {} pub type botan_pk_op_sign_t = *mut botan_pk_op_sign_struct; pub enum botan_pk_op_verify_struct {} pub type botan_pk_op_verify_t = *mut botan_pk_op_verify_struct; pub enum botan_pk_op_ka_struct {} pub type botan_pk_op_ka_t = *mut botan_pk_op_ka_struct; pub enum botan_pk_op_kem_encrypt_struct {} pub type botan_pk_op_kem_encrypt_t = *mut botan_pk_op_kem_encrypt_struct; pub enum botan_pk_op_kem_decrypt_struct {} pub type botan_pk_op_kem_decrypt_t = *mut botan_pk_op_kem_decrypt_struct; extern "C" { pub fn botan_pk_op_encrypt_create( op: *mut botan_pk_op_encrypt_t, key: botan_pubkey_t, padding: *const c_char, flags: u32, ) -> c_int; pub fn botan_pk_op_encrypt_destroy(op: botan_pk_op_encrypt_t) -> c_int; pub fn botan_pk_op_encrypt_output_length( op: botan_pk_op_encrypt_t, inlen: usize, outlen: *mut usize, ) -> c_int; pub fn botan_pk_op_encrypt( op: botan_pk_op_encrypt_t, rng: botan_rng_t, out: *mut u8, out_len: *mut usize, plaintext: *const u8, plaintext_len: usize, ) -> c_int; pub fn botan_pk_op_decrypt_create( op: *mut botan_pk_op_decrypt_t, key: botan_privkey_t, padding: *const c_char, flags: u32, ) -> c_int; pub fn botan_pk_op_decrypt_output_length( op: botan_pk_op_decrypt_t, inlen: usize, outlen: *mut usize, ) -> c_int; pub fn botan_pk_op_decrypt_destroy(op: botan_pk_op_decrypt_t) -> c_int; pub fn botan_pk_op_decrypt( op: botan_pk_op_decrypt_t, out: *mut u8, out_len: *mut usize, ciphertext: *const u8, ciphertext_len: usize, ) -> c_int; pub fn botan_pk_op_sign_create( op: *mut botan_pk_op_sign_t, key: botan_privkey_t, hash_and_padding: *const c_char, flags: u32, ) -> c_int; pub fn botan_pk_op_sign_output_length(op: botan_pk_op_sign_t, siglen: *mut usize) -> c_int; pub fn botan_pk_op_sign_destroy(op: botan_pk_op_sign_t) -> c_int; pub fn botan_pk_op_sign_update(op: botan_pk_op_sign_t, in_: *const u8, in_len: usize) -> c_int; pub fn botan_pk_op_sign_finish( op: botan_pk_op_sign_t, rng: botan_rng_t, sig: *mut u8, sig_len: *mut usize, ) -> c_int; pub fn botan_pk_op_verify_create( op: *mut botan_pk_op_verify_t, key: botan_pubkey_t, hash_and_padding: *const c_char, flags: u32, ) -> c_int; pub fn botan_pk_op_verify_destroy(op: botan_pk_op_verify_t) -> c_int; pub fn botan_pk_op_verify_update( op: botan_pk_op_verify_t, in_: *const u8, in_len: usize, ) -> c_int; pub fn botan_pk_op_verify_finish( op: botan_pk_op_verify_t, sig: *const u8, sig_len: usize, ) -> c_int; pub fn botan_pk_op_key_agreement_create( op: *mut botan_pk_op_ka_t, key: botan_privkey_t, kdf: *const c_char, flags: u32, ) -> c_int; pub fn botan_pk_op_key_agreement_destroy(op: botan_pk_op_ka_t) -> c_int; pub fn botan_pk_op_key_agreement_size(op: botan_pk_op_ka_t, agreed_len: *mut usize) -> c_int; pub fn botan_pk_op_key_agreement_export_public( key: botan_privkey_t, out: *mut u8, out_len: *mut usize, ) -> c_int; pub fn botan_pk_op_key_agreement( op: botan_pk_op_ka_t, out: *mut u8, out_len: *mut usize, other_key: *const u8, other_key_len: usize, salt: *const u8, salt_len: usize, ) -> c_int; pub fn botan_pkcs_hash_id( hash_name: *const c_char, pkcs_id: *mut u8, pkcs_id_len: *mut usize, ) -> c_int; #[cfg(botan_ffi_20230403)] pub fn botan_pk_op_key_agreement_view_public( key: botan_privkey_t, view_ctx: botan_view_ctx, view_fn: botan_view_bin_fn, ) -> c_int; #[cfg(botan_ffi_20230403)] pub fn botan_pk_op_kem_encrypt_create( op: *mut botan_pk_op_kem_encrypt_t, key: botan_pubkey_t, kdf: *const c_char, ) -> c_int; #[cfg(botan_ffi_20230403)] pub fn botan_pk_op_kem_encrypt_destroy(op: botan_pk_op_kem_encrypt_t) -> c_int; #[cfg(botan_ffi_20230403)] pub fn botan_pk_op_kem_encrypt_shared_key_length( op: botan_pk_op_kem_encrypt_t, desired_shared_key_length: usize, output_shared_key_length: *mut usize, ) -> c_int; #[cfg(botan_ffi_20230403)] pub fn botan_pk_op_kem_encrypt_encapsulated_key_length( op: botan_pk_op_kem_encrypt_t, output_encapsulated_key_length: *mut usize, ) -> c_int; #[cfg(botan_ffi_20230403)] pub fn botan_pk_op_kem_encrypt_create_shared_key( op: botan_pk_op_kem_encrypt_t, rng: botan_rng_t, salt: *const u8, salt_len: usize, desired_shared_key_len: usize, shared_key: *mut u8, shared_key_len: *mut usize, encapsulated_key: *mut u8, encapsulated_key_len: *mut usize, ) -> c_int; #[cfg(botan_ffi_20230403)] pub fn botan_pk_op_kem_decrypt_destroy(op: botan_pk_op_kem_decrypt_t) -> c_int; #[cfg(botan_ffi_20230403)] pub fn botan_pk_op_kem_decrypt_create( op: *mut botan_pk_op_kem_decrypt_t, key: botan_privkey_t, kdf: *const c_char, ) -> c_int; #[cfg(botan_ffi_20230403)] pub fn botan_pk_op_kem_decrypt_shared_key_length( op: botan_pk_op_kem_decrypt_t, desired_shared_key_length: usize, output_shared_key_length: *mut usize, ) -> c_int; #[cfg(botan_ffi_20230403)] pub fn botan_pk_op_kem_decrypt_shared_key( op: botan_pk_op_kem_decrypt_t, salt: *const u8, salt_len: usize, encapsulated_key: *const u8, encapsulated_key_len: usize, desired_shared_key_len: usize, shared_key: *mut u8, shared_key_len: *mut usize, ) -> c_int; } botan-sys-1.20250506.0/src/pubkey.rs000064400000000000000000000333411046102023000147450ustar 00000000000000use crate::ffi_types::*; use crate::mp::botan_mp_t; use crate::rng::botan_rng_t; #[cfg(botan_ffi_20250506)] use crate::{botan_asn1_oid_t, botan_ec_group_t}; pub enum botan_pubkey_struct {} pub type botan_pubkey_t = *mut botan_pubkey_struct; pub enum botan_privkey_struct {} pub type botan_privkey_t = *mut botan_privkey_struct; extern "C" { pub fn botan_privkey_create( key: *mut botan_privkey_t, algo_name: *const c_char, algo_params: *const c_char, rng: botan_rng_t, ) -> c_int; pub fn botan_privkey_check_key(key: botan_privkey_t, rng: botan_rng_t, flags: u32) -> c_int; pub fn botan_privkey_create_rsa( key: *mut botan_privkey_t, rng: botan_rng_t, n_bits: usize, ) -> c_int; pub fn botan_privkey_create_ecdsa( key: *mut botan_privkey_t, rng: botan_rng_t, params: *const c_char, ) -> c_int; pub fn botan_privkey_create_ecdh( key: *mut botan_privkey_t, rng: botan_rng_t, params: *const c_char, ) -> c_int; pub fn botan_privkey_create_dh( key: *mut botan_privkey_t, rng: botan_rng_t, param: *const c_char, ) -> c_int; pub fn botan_privkey_create_dsa( key: *mut botan_privkey_t, rng: botan_rng_t, pbits: usize, qbits: usize, ) -> c_int; pub fn botan_privkey_create_elgamal( key: *mut botan_privkey_t, rng: botan_rng_t, pbits: usize, qbits: usize, ) -> c_int; pub fn botan_privkey_load( key: *mut botan_privkey_t, rng: botan_rng_t, bits: *const u8, len: usize, password: *const c_char, ) -> c_int; pub fn botan_privkey_destroy(key: botan_privkey_t) -> c_int; pub fn botan_privkey_export( key: botan_privkey_t, out: *mut u8, out_len: *mut usize, flags: u32, ) -> c_int; pub fn botan_privkey_export_encrypted( key: botan_privkey_t, out: *mut u8, out_len: *mut usize, rng: botan_rng_t, passphrase: *const c_char, encryption_algo: *const c_char, flags: u32, ) -> c_int; pub fn botan_privkey_export_encrypted_pbkdf_msec( key: botan_privkey_t, out: *mut u8, out_len: *mut usize, rng: botan_rng_t, passphrase: *const c_char, pbkdf_msec_runtime: u32, pbkdf_iterations_out: *mut usize, cipher_algo: *const c_char, pbkdf_algo: *const c_char, flags: u32, ) -> c_int; pub fn botan_privkey_export_encrypted_pbkdf_iter( key: botan_privkey_t, out: *mut u8, out_len: *mut usize, rng: botan_rng_t, passphrase: *const c_char, pbkdf_iterations: usize, cipher_algo: *const c_char, pbkdf_algo: *const c_char, flags: u32, ) -> c_int; pub fn botan_pubkey_load(key: *mut botan_pubkey_t, bits: *const u8, len: usize) -> c_int; pub fn botan_privkey_export_pubkey(out: *mut botan_pubkey_t, in_: botan_privkey_t) -> c_int; pub fn botan_pubkey_export( key: botan_pubkey_t, out: *mut u8, out_len: *mut usize, flags: u32, ) -> c_int; pub fn botan_privkey_algo_name( key: botan_privkey_t, out: *mut c_char, out_len: *mut usize, ) -> c_int; pub fn botan_pubkey_algo_name( key: botan_pubkey_t, out: *mut c_char, out_len: *mut usize, ) -> c_int; pub fn botan_pubkey_check_key(key: botan_pubkey_t, rng: botan_rng_t, flags: u32) -> c_int; pub fn botan_pubkey_estimated_strength(key: botan_pubkey_t, estimate: *mut usize) -> c_int; pub fn botan_pubkey_fingerprint( key: botan_pubkey_t, hash: *const c_char, out: *mut u8, out_len: *mut usize, ) -> c_int; pub fn botan_pubkey_destroy(key: botan_pubkey_t) -> c_int; pub fn botan_pubkey_get_field( output: botan_mp_t, key: botan_pubkey_t, field_name: *const c_char, ) -> c_int; pub fn botan_privkey_get_field( output: botan_mp_t, key: botan_privkey_t, field_name: *const c_char, ) -> c_int; pub fn botan_privkey_load_rsa( key: *mut botan_privkey_t, p: botan_mp_t, q: botan_mp_t, e: botan_mp_t, ) -> c_int; pub fn botan_privkey_load_rsa_pkcs1( key: *mut botan_privkey_t, bits: *const u8, len: usize, ) -> c_int; pub fn botan_privkey_rsa_get_p(p: botan_mp_t, rsa_key: botan_privkey_t) -> c_int; pub fn botan_privkey_rsa_get_q(q: botan_mp_t, rsa_key: botan_privkey_t) -> c_int; pub fn botan_privkey_rsa_get_d(d: botan_mp_t, rsa_key: botan_privkey_t) -> c_int; pub fn botan_privkey_rsa_get_n(n: botan_mp_t, rsa_key: botan_privkey_t) -> c_int; pub fn botan_privkey_rsa_get_e(e: botan_mp_t, rsa_key: botan_privkey_t) -> c_int; pub fn botan_pubkey_load_rsa(key: *mut botan_pubkey_t, n: botan_mp_t, e: botan_mp_t) -> c_int; pub fn botan_pubkey_rsa_get_e(e: botan_mp_t, rsa_key: botan_pubkey_t) -> c_int; pub fn botan_pubkey_rsa_get_n(n: botan_mp_t, rsa_key: botan_pubkey_t) -> c_int; pub fn botan_privkey_load_dsa( key: *mut botan_privkey_t, p: botan_mp_t, q: botan_mp_t, g: botan_mp_t, x: botan_mp_t, ) -> c_int; pub fn botan_pubkey_load_dsa( key: *mut botan_pubkey_t, p: botan_mp_t, q: botan_mp_t, g: botan_mp_t, y: botan_mp_t, ) -> c_int; pub fn botan_privkey_dsa_get_x(n: botan_mp_t, key: botan_privkey_t) -> c_int; pub fn botan_pubkey_dsa_get_p(p: botan_mp_t, key: botan_pubkey_t) -> c_int; pub fn botan_pubkey_dsa_get_q(q: botan_mp_t, key: botan_pubkey_t) -> c_int; pub fn botan_pubkey_dsa_get_g(d: botan_mp_t, key: botan_pubkey_t) -> c_int; pub fn botan_pubkey_dsa_get_y(y: botan_mp_t, key: botan_pubkey_t) -> c_int; pub fn botan_privkey_load_dh( key: *mut botan_privkey_t, p: botan_mp_t, g: botan_mp_t, x: botan_mp_t, ) -> c_int; pub fn botan_pubkey_load_dh( key: *mut botan_pubkey_t, p: botan_mp_t, g: botan_mp_t, y: botan_mp_t, ) -> c_int; pub fn botan_pubkey_load_elgamal( key: *mut botan_pubkey_t, p: botan_mp_t, g: botan_mp_t, y: botan_mp_t, ) -> c_int; pub fn botan_privkey_load_elgamal( key: *mut botan_privkey_t, p: botan_mp_t, g: botan_mp_t, x: botan_mp_t, ) -> c_int; pub fn botan_privkey_load_ed25519(key: *mut botan_privkey_t, privkey: *const u8) -> c_int; pub fn botan_pubkey_load_ed25519(key: *mut botan_pubkey_t, pubkey: *const u8) -> c_int; pub fn botan_privkey_ed25519_get_privkey(key: botan_privkey_t, output: *mut u8) -> c_int; pub fn botan_pubkey_ed25519_get_pubkey(key: botan_pubkey_t, pubkey: *mut u8) -> c_int; pub fn botan_privkey_load_x25519(key: *mut botan_privkey_t, privkey: *const u8) -> c_int; pub fn botan_pubkey_load_x25519(key: *mut botan_pubkey_t, pubkey: *const u8) -> c_int; pub fn botan_privkey_x25519_get_privkey(key: botan_privkey_t, output: *mut u8) -> c_int; pub fn botan_pubkey_x25519_get_pubkey(key: botan_pubkey_t, pubkey: *mut u8) -> c_int; #[cfg(botan_ffi_20240408)] pub fn botan_privkey_load_x448(key: *mut botan_privkey_t, privkey: *const u8) -> c_int; #[cfg(botan_ffi_20240408)] pub fn botan_pubkey_load_x448(key: *mut botan_pubkey_t, pubkey: *const u8) -> c_int; #[cfg(botan_ffi_20240408)] pub fn botan_privkey_load_ed448(key: *mut botan_privkey_t, privkey: *const u8) -> c_int; #[cfg(botan_ffi_20240408)] pub fn botan_pubkey_load_ed448(key: *mut botan_pubkey_t, pubkey: *const u8) -> c_int; pub fn botan_privkey_load_ecdsa( key: *mut botan_privkey_t, scalar: botan_mp_t, curve_name: *const c_char, ) -> c_int; pub fn botan_pubkey_load_ecdsa( key: *mut botan_pubkey_t, public_x: botan_mp_t, public_y: botan_mp_t, curve_name: *const c_char, ) -> c_int; pub fn botan_pubkey_load_ecdh( key: *mut botan_pubkey_t, public_x: botan_mp_t, public_y: botan_mp_t, curve_name: *const c_char, ) -> c_int; pub fn botan_privkey_load_ecdh( key: *mut botan_privkey_t, scalar: botan_mp_t, curve_name: *const c_char, ) -> c_int; pub fn botan_pubkey_load_sm2( key: *mut botan_pubkey_t, public_x: botan_mp_t, public_y: botan_mp_t, curve_name: *const c_char, ) -> c_int; pub fn botan_privkey_load_sm2( key: *mut botan_privkey_t, scalar: botan_mp_t, curve_name: *const c_char, ) -> c_int; pub fn botan_pubkey_load_sm2_enc( key: *mut botan_pubkey_t, public_x: botan_mp_t, public_y: botan_mp_t, curve_name: *const c_char, ) -> c_int; pub fn botan_privkey_load_sm2_enc( key: *mut botan_privkey_t, scalar: botan_mp_t, curve_name: *const c_char, ) -> c_int; pub fn botan_pubkey_sm2_compute_za( out: *mut u8, out_len: *mut usize, ident: *const c_char, hash_algo: *const c_char, key: botan_pubkey_t, ) -> c_int; #[cfg(botan_ffi_20230403)] pub fn botan_pubkey_view_raw( key: botan_pubkey_t, view_ctx: botan_view_ctx, view_fn: botan_view_bin_fn, ) -> c_int; #[cfg(botan_ffi_20230403)] pub fn botan_pubkey_view_der( key: botan_pubkey_t, view_ctx: botan_view_ctx, view_fn: botan_view_bin_fn, ) -> c_int; #[cfg(botan_ffi_20230403)] pub fn botan_pubkey_view_pem( key: botan_pubkey_t, view_ctx: botan_view_ctx, view_fn: botan_view_str_fn, ) -> c_int; #[cfg(botan_ffi_20230403)] pub fn botan_privkey_view_raw( key: botan_privkey_t, view_ctx: botan_view_ctx, view_fn: botan_view_bin_fn, ) -> c_int; #[cfg(botan_ffi_20230403)] pub fn botan_privkey_view_der( key: botan_privkey_t, view_ctx: botan_view_ctx, view_fn: botan_view_bin_fn, ) -> c_int; #[cfg(botan_ffi_20230403)] pub fn botan_privkey_view_pem( key: botan_privkey_t, view_ctx: botan_view_ctx, view_fn: botan_view_str_fn, ) -> c_int; #[cfg(botan_ffi_20230403)] pub fn botan_pubkey_view_ec_public_point( key: botan_pubkey_t, view_ctx: botan_view_ctx, view_fn: botan_view_bin_fn, ) -> c_int; #[cfg(botan_ffi_20230403)] pub fn botan_privkey_view_encrypted_der( key: botan_privkey_t, rng: botan_rng_t, passphrase: *const c_char, cipher_algo: *const c_char, pbkdf_algo: *const c_char, pbkdf_iterations: usize, view_ctx: botan_view_ctx, view_fn: botan_view_bin_fn, ) -> c_int; #[cfg(botan_ffi_20230403)] pub fn botan_privkey_view_encrypted_pem( key: botan_privkey_t, rng: botan_rng_t, passphrase: *const c_char, cipher_algo: *const c_char, pbkdf_algo: *const c_char, pbkdf_iterations: usize, view_ctx: botan_view_ctx, view_fn: botan_view_str_fn, ) -> c_int; #[cfg(botan_ffi_20250506)] pub fn botan_ec_privkey_create( key: *mut botan_privkey_t, algo: *const c_char, group: botan_ec_group_t, rng: botan_rng_t, ) -> c_int; #[cfg(botan_ffi_20250506)] pub fn botan_pubkey_oid(oid: *mut botan_asn1_oid_t, key: botan_pubkey_t) -> c_int; #[cfg(botan_ffi_20250506)] pub fn botan_privkey_oid(oid: *mut botan_asn1_oid_t, key: botan_privkey_t) -> c_int; #[cfg(botan_ffi_20250506)] pub fn botan_privkey_stateful_operation(key: botan_privkey_t, stateful: *mut c_int) -> c_int; #[cfg(botan_ffi_20250506)] pub fn botan_privkey_remaining_operations( key: botan_privkey_t, remaining_ops: *mut u64, ) -> c_int; #[cfg(botan_ffi_20250506)] pub fn botan_pubkey_load_frodokem( key: *mut botan_pubkey_t, bytes: *const u8, len: usize, mode: *const c_char, ) -> c_int; #[cfg(botan_ffi_20250506)] pub fn botan_privkey_load_frodokem( key: *mut botan_privkey_t, bytes: *const u8, len: usize, mode: *const c_char, ) -> c_int; #[cfg(botan_ffi_20250506)] pub fn botan_pubkey_load_classic_mceliece( key: *mut botan_pubkey_t, bytes: *const u8, len: usize, mode: *const c_char, ) -> c_int; #[cfg(botan_ffi_20250506)] pub fn botan_privkey_load_classic_mceliece( key: *mut botan_privkey_t, bytes: *const u8, len: usize, mode: *const c_char, ) -> c_int; #[cfg(botan_ffi_20250506)] pub fn botan_pubkey_load_ml_kem( key: *mut botan_pubkey_t, bytes: *const u8, len: usize, mode: *const c_char, ) -> c_int; #[cfg(botan_ffi_20250506)] pub fn botan_privkey_load_ml_kem( key: *mut botan_privkey_t, bytes: *const u8, len: usize, mode: *const c_char, ) -> c_int; #[cfg(botan_ffi_20250506)] pub fn botan_pubkey_load_slh_dsa( key: *mut botan_pubkey_t, bytes: *const u8, len: usize, mode: *const c_char, ) -> c_int; #[cfg(botan_ffi_20250506)] pub fn botan_privkey_load_slh_dsa( key: *mut botan_privkey_t, bytes: *const u8, len: usize, mode: *const c_char, ) -> c_int; #[cfg(botan_ffi_20250506)] pub fn botan_pubkey_load_ml_dsa( key: *mut botan_pubkey_t, bytes: *const u8, len: usize, mode: *const c_char, ) -> c_int; #[cfg(botan_ffi_20250506)] pub fn botan_privkey_load_ml_dsa( key: *mut botan_privkey_t, bytes: *const u8, len: usize, mode: *const c_char, ) -> c_int; } botan-sys-1.20250506.0/src/rng.rs000064400000000000000000000011511046102023000142260ustar 00000000000000use crate::ffi_types::{c_char, c_int}; pub enum botan_rng_struct {} pub type botan_rng_t = *mut botan_rng_struct; extern "C" { pub fn botan_rng_init(rng: *mut botan_rng_t, rng_type: *const c_char) -> c_int; pub fn botan_rng_get(rng: botan_rng_t, out: *mut u8, out_len: usize) -> c_int; pub fn botan_rng_reseed(rng: botan_rng_t, bits: usize) -> c_int; pub fn botan_rng_reseed_from_rng(rng: botan_rng_t, src: botan_rng_t, bits: usize) -> c_int; pub fn botan_rng_add_entropy(rng: botan_rng_t, data: *const u8, len: usize) -> c_int; pub fn botan_rng_destroy(rng: botan_rng_t) -> c_int; } botan-sys-1.20250506.0/src/utils.rs000064400000000000000000000014071046102023000146040ustar 00000000000000use crate::ffi_types::{c_char, c_int, c_void}; extern "C" { pub fn botan_constant_time_compare(x: *const u8, y: *const u8, len: usize) -> c_int; pub fn botan_scrub_mem(mem: *mut c_void, bytes: usize) -> c_int; pub fn botan_hex_encode(x: *const u8, len: usize, out: *mut c_char, flags: u32) -> c_int; pub fn botan_hex_decode( hex_str: *const c_char, in_len: usize, out: *mut u8, out_len: *mut usize, ) -> c_int; pub fn botan_base64_encode( x: *const u8, len: usize, out: *mut c_char, out_len: *mut usize, ) -> c_int; pub fn botan_base64_decode( base64_str: *const c_char, in_len: usize, out: *mut u8, out_len: *mut usize, ) -> c_int; } botan-sys-1.20250506.0/src/version.rs000064400000000000000000000006001046102023000151230ustar 00000000000000use crate::ffi_types::{c_char, c_int}; extern "C" { pub fn botan_ffi_api_version() -> u32; pub fn botan_ffi_supports_api(api_version: u32) -> c_int; pub fn botan_version_string() -> *const c_char; pub fn botan_version_major() -> u32; pub fn botan_version_minor() -> u32; pub fn botan_version_patch() -> u32; pub fn botan_version_datestamp() -> u32; } botan-sys-1.20250506.0/src/x509.rs000064400000000000000000000112461046102023000141530ustar 00000000000000use crate::ffi_types::*; use crate::pubkey::{botan_privkey_t, botan_pubkey_t}; use crate::rng::botan_rng_t; pub enum botan_x509_cert_struct {} pub type botan_x509_cert_t = *mut botan_x509_cert_struct; pub enum botan_x509_crl_struct {} pub type botan_x509_crl_t = *mut botan_x509_crl_struct; #[repr(u32)] #[allow(clippy::upper_case_acronyms)] pub enum X509KeyConstraints { NO_CONSTRAINTS = 0, DIGITAL_SIGNATURE = 32768, NON_REPUDIATION = 16384, KEY_ENCIPHERMENT = 8192, DATA_ENCIPHERMENT = 4096, KEY_AGREEMENT = 2048, KEY_CERT_SIGN = 1024, CRL_SIGN = 512, ENCIPHER_ONLY = 256, DECIPHER_ONLY = 128, } extern "C" { pub fn botan_x509_cert_load( cert_obj: *mut botan_x509_cert_t, cert: *const u8, cert_len: usize, ) -> c_int; pub fn botan_x509_cert_dup(cert_obj: *mut botan_x509_cert_t, cert: botan_x509_cert_t) -> c_int; pub fn botan_x509_cert_load_file( cert_obj: *mut botan_x509_cert_t, filename: *const c_char, ) -> c_int; pub fn botan_x509_cert_destroy(cert: botan_x509_cert_t) -> c_int; pub fn botan_x509_cert_gen_selfsigned( cert: *mut botan_x509_cert_t, key: botan_privkey_t, rng: botan_rng_t, common_name: *const c_char, org_name: *const c_char, ) -> c_int; pub fn botan_x509_cert_get_time_starts( cert: botan_x509_cert_t, out: *mut c_char, out_len: *mut usize, ) -> c_int; pub fn botan_x509_cert_get_time_expires( cert: botan_x509_cert_t, out: *mut c_char, out_len: *mut usize, ) -> c_int; pub fn botan_x509_cert_not_before(cert: botan_x509_cert_t, timestamp: *mut u64) -> c_int; pub fn botan_x509_cert_not_after(cert: botan_x509_cert_t, timestamp: *mut u64) -> c_int; pub fn botan_x509_cert_get_fingerprint( cert: botan_x509_cert_t, hash: *const c_char, out: *mut u8, out_len: *mut usize, ) -> c_int; pub fn botan_x509_cert_get_serial_number( cert: botan_x509_cert_t, out: *mut u8, out_len: *mut usize, ) -> c_int; pub fn botan_x509_cert_get_authority_key_id( cert: botan_x509_cert_t, out: *mut u8, out_len: *mut usize, ) -> c_int; pub fn botan_x509_cert_get_subject_key_id( cert: botan_x509_cert_t, out: *mut u8, out_len: *mut usize, ) -> c_int; pub fn botan_x509_cert_get_public_key_bits( cert: botan_x509_cert_t, out: *mut u8, out_len: *mut usize, ) -> c_int; pub fn botan_x509_cert_get_public_key( cert: botan_x509_cert_t, key: *mut botan_pubkey_t, ) -> c_int; pub fn botan_x509_cert_get_issuer_dn( cert: botan_x509_cert_t, key: *const c_char, index: usize, out: *mut u8, out_len: *mut usize, ) -> c_int; pub fn botan_x509_cert_get_subject_dn( cert: botan_x509_cert_t, key: *const c_char, index: usize, out: *mut u8, out_len: *mut usize, ) -> c_int; pub fn botan_x509_cert_to_string( cert: botan_x509_cert_t, out: *mut c_char, out_len: *mut usize, ) -> c_int; pub fn botan_x509_cert_allowed_usage(cert: botan_x509_cert_t, key_usage: c_uint) -> c_int; pub fn botan_x509_cert_hostname_match( cert: botan_x509_cert_t, hostname: *const c_char, ) -> c_int; pub fn botan_x509_cert_verify( validation_result: *mut c_int, ee_cert: botan_x509_cert_t, intermediates: *const botan_x509_cert_t, intermediates_len: usize, trusted: *const botan_x509_cert_t, trusted_len: usize, trusted_path: *const c_char, required_key_strength: usize, hostname: *const c_char, reference_time: u64, ) -> c_int; pub fn botan_x509_cert_validation_status(code: c_int) -> *const c_char; #[cfg(botan_ffi_20230403)] pub fn botan_x509_cert_view_public_key_bits( cert: botan_x509_cert_t, view_ctx: botan_view_ctx, view_fn: botan_view_bin_fn, ) -> c_int; #[cfg(botan_ffi_20230403)] pub fn botan_x509_cert_view_as_string( cert: botan_x509_cert_t, view_ctx: botan_view_ctx, view_fn: botan_view_str_fn, ) -> c_int; pub fn botan_x509_crl_load_file(crl: *mut botan_x509_crl_t, file_path: *const c_char) -> c_int; pub fn botan_x509_crl_load( crl: *mut botan_x509_crl_t, data: *const u8, data_len: usize, ) -> c_int; pub fn botan_x509_crl_destroy(crl: botan_x509_crl_t) -> c_int; pub fn botan_x509_is_revoked(crl: botan_x509_crl_t, cert: botan_x509_cert_t) -> c_int; // TODO: botan_x509_cert_verify_with_crl } botan-sys-1.20250506.0/src/zfec.rs000064400000000000000000000007451046102023000143770ustar 00000000000000extern "C" { #[cfg(botan_ffi_20230403)] pub fn botan_zfec_encode( k: usize, n: usize, input: *const u8, input_len: usize, outputs: *mut *mut u8, ) -> crate::ffi_types::c_int; #[cfg(botan_ffi_20230403)] pub fn botan_zfec_decode( k: usize, n: usize, indexes: *const usize, shares: *const *const u8, share_size: usize, outputs: *mut *mut u8, ) -> crate::ffi_types::c_int; } botan-sys-1.20250506.0/tests/tests.rs000064400000000000000000000045771046102023000151740ustar 00000000000000extern crate botan_sys; use std::ffi::CString; use botan_sys::*; #[test] fn test_hex() { let bin = vec![0x42, 0x23, 0x45, 0x8F]; let mut out = vec![0; bin.len() * 2]; unsafe { assert_eq!( botan_hex_encode(bin.as_ptr(), bin.len(), out.as_mut_ptr(), 0), 0 ); } assert_eq!(out[0], '4' as _); assert_eq!(out[1], '2' as _); assert_eq!(out[2], '2' as _); assert_eq!(out[3], '3' as _); assert_eq!(out[4], '4' as _); assert_eq!(out[5], '5' as _); assert_eq!(out[6], '8' as _); assert_eq!(out[7], 'F' as _); let mut decoded = vec![0; 1024]; let mut out_len = decoded.len(); unsafe { assert_eq!( botan_hex_decode(out.as_ptr(), out.len(), decoded.as_mut_ptr(), &mut out_len), 0 ); } assert_eq!(out_len, bin.len()); decoded.resize(out_len, 0); assert_eq!(bin, decoded); } #[test] fn test_hash() { unsafe { let mut hash = std::ptr::null_mut(); let hash_name = CString::new("SHA-384").unwrap(); assert_eq!(botan_hash_init(&mut hash, hash_name.as_ptr(), 0u32), 0); let input = [97, 98, 99]; assert_eq!(botan_hash_update(hash, input.as_ptr(), input.len()), 0); assert_eq!(botan_hash_update(hash, input.as_ptr(), input.len()), 0); let mut output_len = 0; assert_eq!(botan_hash_output_length(hash, &mut output_len), 0); assert!(output_len == 48); let mut digest = vec![0u8; output_len]; assert_eq!(botan_hash_final(hash, digest.as_mut_ptr()), 0); assert_eq!(digest[0], 0xCA); assert_eq!(digest[1], 0xF3); assert_eq!(digest[47], 0x8D); assert_eq!(botan_hash_destroy(hash), 0); } } #[test] fn test_version() { unsafe { let api_version = botan_ffi_api_version(); assert!(botan_ffi_supports_api(api_version) == 0); assert!(botan_ffi_supports_api(api_version + 1) != 0); } } #[test] fn test_rng() { unsafe { let mut rng = std::ptr::null_mut(); botan_rng_init(&mut rng, std::ptr::null()); let mut rng1 = vec![0u8; 16]; let mut rng2 = vec![0u8; 16]; assert_eq!(botan_rng_get(rng, rng1.as_mut_ptr(), rng1.len()), 0); assert_eq!(botan_rng_get(rng, rng2.as_mut_ptr(), rng2.len()), 0); assert!(rng1 != rng2); assert_eq!(botan_rng_destroy(rng), 0); } }