diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7454dd88..68efe744 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,8 +42,9 @@ jobs: runs-on: ubuntu-24.04-arm container: ghcr.io/ivila/teaclave-trustzone-sdk-ci-runner:ubuntu-24.04 - # Run systest of optee_teec and build systest of optee_utee on ARM64 - systest: + # Regenerate the committed `*-sys` bindings from the OP-TEE release pinned in + # optee-version.txt and fail if the committed files are stale. + check-generated-bindings: runs-on: ubuntu-24.04-arm container: ghcr.io/ivila/teaclave-trustzone-sdk-ci-runner:ubuntu-24.04 steps: @@ -56,23 +57,41 @@ jobs: path: | ~/.cargo/registry/cache ~/.cargo/registry/index - key: cargo-v1-systest-${{ hashFiles('rust-toolchain.toml') }} + key: cargo-v1-bindings-${{ hashFiles('rust-toolchain.toml') }} restore-keys: | - cargo-v1-systest- + cargo-v1-bindings- - - name: Prepare Environment + - name: Install libclang + run: | + # bindgen dlopens libclang at run time and the runner image does not + # ship it. + apt-get update + apt-get install -y --no-install-recommends libclang-dev + echo "LIBCLANG_PATH=$(dirname "$(find /usr/lib -name libclang.so -print -quit)")" >> "$GITHUB_ENV" + + - name: Regenerate the bindings run: | # Setup Rust and toolchains ./setup.sh source "$HOME/.cargo/env" - # Build optee_os and optee_client for qemu_v8 - ./build_optee_libraries.sh $HOME - # Setup environment - export OPTEE_DIR=$HOME + + # Build the dev kit and client export of the pinned OP-TEE release + ./build_optee_libraries.sh "$HOME" + export OPTEE_DIR="$HOME" source environment - # Run systest - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OPTEE_DIR/optee_client/export_arm64/usr/lib - (cd crates && cargo run -p optee-teec-systest && cargo build -p optee-utee-systest) + + cargo run --manifest-path xtask/Cargo.toml -- generate-bindings all + + - name: Fail if the committed bindings are stale + run: | + # The step runs as root inside the container while the workspace + # belongs to the runner user, so git has to be told that the + # repository is safe before it will read the index. + git config --global --add safe.directory "$GITHUB_WORKSPACE" + + git diff --exit-code -- \ + crates/optee-utee-sys/src/generated.rs \ + crates/optee-teec-sys/src/generated.rs # Build examples in the emulator image: arch × std. test-build-on-dev-docker: diff --git a/.gitignore b/.gitignore index c84de7e1..b9e63557 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,10 @@ rust/ !examples/ca/Cargo.lock !projects/web3/eth_wallet/ta/Cargo.lock +# Pin the exact bindgen (and its dependencies) used to regenerate the committed +# `*-sys` bindings. +!xtask/Cargo.lock + # Allow tracking Cargo.lock for cargo-optee tool !cargo-optee/Cargo.lock diff --git a/.licenserc.yaml b/.licenserc.yaml index e2f4dd4d..6bc4f681 100644 --- a/.licenserc.yaml +++ b/.licenserc.yaml @@ -33,3 +33,4 @@ header: - 'examples/ta/tls_server-rs/test-ca/**' - 'optee-version.txt' - '**/*.stderr' + - '**/*.in' diff --git a/crates/Cargo.toml b/crates/Cargo.toml index 716151c5..49f5d9b0 100644 --- a/crates/Cargo.toml +++ b/crates/Cargo.toml @@ -22,12 +22,10 @@ members = [ "optee-teec-build", "optee-teec-macros", "optee-teec-sys", - "optee-teec-systest", "optee-utee", "optee-utee-build", "optee-utee-macros", "optee-utee-sys", - "optee-utee-systest", "rustls_provider", "secure_db" ] @@ -62,8 +60,6 @@ serde = { version = "1.0.229" } serde_json = { version = "1.0.154" } log = "0.4.35" document-features = "0.2.12" -ctest = "0.5.1" -cc = "1.10.0" prettyplease = "0.3.0" libc_alloc = "1.0.7" strum = { version = "0.28", default-features = false } diff --git a/crates/optee-teec-build/src/plugin.rs b/crates/optee-teec-build/src/plugin.rs index f4d1c273..49211727 100644 --- a/crates/optee-teec-build/src/plugin.rs +++ b/crates/optee-teec-build/src/plugin.rs @@ -134,8 +134,8 @@ fn generate_binding( timeHiAndVersion: #uuid_f3, clockSeqAndNode: [#(#uuid_f4),*], }, - init: #init_fn_name, - invoke: #invoke_fn_name, + init: Some(#init_fn_name), + invoke: Some(#invoke_fn_name), }; }; } diff --git a/crates/optee-teec-macros/src/lib.rs b/crates/optee-teec-macros/src/lib.rs index 6ccf6d83..abaa8252 100644 --- a/crates/optee-teec-macros/src/lib.rs +++ b/crates/optee-teec-macros/src/lib.rs @@ -172,8 +172,8 @@ pub fn plugin_invoke(_args: TokenStream, input: TokenStream) -> TokenStream { cmd: u32, sub_cmd: u32, data: *mut core::ffi::c_void, - in_len: optee_teec::raw::size_t, - out_len: *mut optee_teec::raw::size_t, + in_len: usize, + out_len: *mut usize, ) -> optee_teec::raw::TEEC_Result { let mut parameter = match unsafe { optee_teec::PluginParameters::from_raw( diff --git a/crates/optee-teec-sys/src/generated.rs b/crates/optee-teec-sys/src/generated.rs new file mode 100644 index 00000000..1c74241b --- /dev/null +++ b/crates/optee-teec-sys/src/generated.rs @@ -0,0 +1,400 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +// @generated by `cargo run --manifest-path xtask/Cargo.toml -- generate-bindings teec` +// from the OP-TEE client headers. Do not edit by hand. +// +// Regenerate after changing the OP-TEE version in optee-version.txt. + +/* automatically generated by rust-bindgen 0.72.1 */ + +pub const TEEC_CONFIG_PAYLOAD_REF_COUNT: u32 = 4; +pub const TEEC_NONE: u32 = 0; +pub const TEEC_VALUE_INPUT: u32 = 1; +pub const TEEC_VALUE_OUTPUT: u32 = 2; +pub const TEEC_VALUE_INOUT: u32 = 3; +pub const TEEC_MEMREF_TEMP_INPUT: u32 = 5; +pub const TEEC_MEMREF_TEMP_OUTPUT: u32 = 6; +pub const TEEC_MEMREF_TEMP_INOUT: u32 = 7; +pub const TEEC_MEMREF_WHOLE: u32 = 12; +pub const TEEC_MEMREF_PARTIAL_INPUT: u32 = 13; +pub const TEEC_MEMREF_PARTIAL_OUTPUT: u32 = 14; +pub const TEEC_MEMREF_PARTIAL_INOUT: u32 = 15; +pub const TEEC_MEM_INPUT: u32 = 1; +pub const TEEC_MEM_OUTPUT: u32 = 2; +pub const TEEC_SUCCESS: u32 = 0; +pub const TEEC_ERROR_STORAGE_NOT_AVAILABLE: u32 = 4027580419; +pub const TEEC_ERROR_GENERIC: u32 = 4294901760; +pub const TEEC_ERROR_ACCESS_DENIED: u32 = 4294901761; +pub const TEEC_ERROR_CANCEL: u32 = 4294901762; +pub const TEEC_ERROR_ACCESS_CONFLICT: u32 = 4294901763; +pub const TEEC_ERROR_EXCESS_DATA: u32 = 4294901764; +pub const TEEC_ERROR_BAD_FORMAT: u32 = 4294901765; +pub const TEEC_ERROR_BAD_PARAMETERS: u32 = 4294901766; +pub const TEEC_ERROR_BAD_STATE: u32 = 4294901767; +pub const TEEC_ERROR_ITEM_NOT_FOUND: u32 = 4294901768; +pub const TEEC_ERROR_NOT_IMPLEMENTED: u32 = 4294901769; +pub const TEEC_ERROR_NOT_SUPPORTED: u32 = 4294901770; +pub const TEEC_ERROR_NO_DATA: u32 = 4294901771; +pub const TEEC_ERROR_OUT_OF_MEMORY: u32 = 4294901772; +pub const TEEC_ERROR_BUSY: u32 = 4294901773; +pub const TEEC_ERROR_COMMUNICATION: u32 = 4294901774; +pub const TEEC_ERROR_SECURITY: u32 = 4294901775; +pub const TEEC_ERROR_SHORT_BUFFER: u32 = 4294901776; +pub const TEE_ERROR_EXTERNAL_CANCEL: u32 = 4294901777; +pub const TEEC_ERROR_EXTERNAL_CANCEL: u32 = 4294901777; +pub const TEE_ERROR_OVERFLOW: u32 = 4294914063; +pub const TEE_ERROR_TARGET_DEAD: u32 = 4294914084; +pub const TEEC_ERROR_TARGET_DEAD: u32 = 4294914084; +pub const TEE_ERROR_STORAGE_NO_SPACE: u32 = 4294914113; +pub const TEEC_ERROR_STORAGE_NO_SPACE: u32 = 4294914113; +pub const TEE_ERROR_MAC_INVALID: u32 = 4294914161; +pub const TEE_ERROR_SIGNATURE_INVALID: u32 = 4294914162; +pub const TEE_ERROR_TIME_NOT_SET: u32 = 4294922240; +pub const TEE_ERROR_TIME_NEEDS_RESET: u32 = 4294922241; +pub const TEEC_ORIGIN_API: u32 = 1; +pub const TEEC_ORIGIN_COMMS: u32 = 2; +pub const TEEC_ORIGIN_TEE: u32 = 3; +pub const TEEC_ORIGIN_TRUSTED_APP: u32 = 4; +pub const TEEC_LOGIN_PUBLIC: u32 = 0; +pub const TEEC_LOGIN_USER: u32 = 1; +pub const TEEC_LOGIN_GROUP: u32 = 2; +pub const TEEC_LOGIN_APPLICATION: u32 = 4; +pub const TEEC_LOGIN_USER_APPLICATION: u32 = 5; +pub const TEEC_LOGIN_GROUP_APPLICATION: u32 = 6; +pub type TEEC_Result = u32; +/** struct TEEC_Context - Represents a connection between a client application + and a TEE.*/ +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TEEC_Context { + pub imp: TEEC_Context__bindgen_ty_1, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TEEC_Context__bindgen_ty_1 { + pub fd: ::core::ffi::c_int, + pub reg_mem: bool, + pub memref_null: bool, +} +/** This type contains a Universally Unique Resource Identifier (UUID) type as + defined in RFC4122. These UUID values are used to identify Trusted + Applications.*/ +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TEEC_UUID { + pub timeLow: u32, + pub timeMid: u16, + pub timeHiAndVersion: u16, + pub clockSeqAndNode: [u8; 8usize], +} +/** struct TEEC_SharedMemory - Memory to transfer data between a client + application and trusted code. + + @param buffer The memory buffer which is to be, or has been, shared + with the TEE. + @param size The size, in bytes, of the memory buffer. + @param flags Bit-vector which holds properties of buffer. + The bit-vector can contain either or both of the + TEEC_MEM_INPUT and TEEC_MEM_OUTPUT flags. + + A shared memory block is a region of memory allocated in the context of the + client application memory space that can be used to transfer data between + that client application and a trusted application. The user of this struct + is responsible to populate the buffer pointer.*/ +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TEEC_SharedMemory { + pub buffer: *mut ::core::ffi::c_void, + pub size: usize, + pub flags: u32, + pub imp: TEEC_SharedMemory__bindgen_ty_1, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TEEC_SharedMemory__bindgen_ty_1 { + pub id: ::core::ffi::c_int, + pub alloced_size: usize, + pub shadow_buffer: *mut ::core::ffi::c_void, + pub registered_fd: ::core::ffi::c_int, + pub flags: u32, +} +/** struct TEEC_TempMemoryReference - Temporary memory to transfer data between + a client application and trusted code, only used for the duration of the + operation. + + @param buffer The memory buffer which is to be, or has been shared with + the TEE. + @param size The size, in bytes, of the memory buffer. + + A memory buffer that is registered temporarily for the duration of the + operation to be called.*/ +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TEEC_TempMemoryReference { + pub buffer: *mut ::core::ffi::c_void, + pub size: usize, +} +/** struct TEEC_RegisteredMemoryReference - use a pre-registered or + pre-allocated shared memory block of memory to transfer data between + a client application and trusted code. + + @param parent Points to a shared memory structure. The memory reference + may utilize the whole shared memory or only a part of it. + Must not be NULL + + @param size The size, in bytes, of the memory buffer. + + @param offset The offset, in bytes, of the referenced memory region from + the start of the shared memory block. +*/ +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TEEC_RegisteredMemoryReference { + pub parent: *mut TEEC_SharedMemory, + pub size: usize, + pub offset: usize, +} +/** struct TEEC_Value - Small raw data container + + Instead of allocating a shared memory buffer this structure can be used + to pass small raw data between a client application and trusted code. + + @param a The first integer value. + + @param b The second value.*/ +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TEEC_Value { + pub a: u32, + pub b: u32, +} +/** union TEEC_Parameter - Memory container to be used when passing data between + client application and trusted code. + + Either the client uses a shared memory reference, parts of it or a small raw + data container. + + @param tmpref A temporary memory reference only valid for the duration + of the operation. + + @param memref The entire shared memory or parts of it. + + @param value The small raw data container to use*/ +#[repr(C)] +#[derive(Copy, Clone)] +pub union TEEC_Parameter { + pub tmpref: TEEC_TempMemoryReference, + pub memref: TEEC_RegisteredMemoryReference, + pub value: TEEC_Value, +} +/** struct TEEC_Session - Represents a connection between a client application + and a trusted application.*/ +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TEEC_Session { + pub imp: TEEC_Session__bindgen_ty_1, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TEEC_Session__bindgen_ty_1 { + pub ctx: *mut TEEC_Context, + pub session_id: u32, +} +/** struct TEEC_Operation - Holds information and memory references used in + TEEC_InvokeCommand(). + + @param started Client must initialize to zero if it needs to cancel + an operation about to be performed. + @param paramTypes Type of data passed. Use TEEC_PARAM_TYPES macro to + create the correct flags. + 0 means TEEC_NONE is passed for all params. + @param params Array of parameters of type TEEC_Parameter. + @param imp Implementation defined parameter. Here it is a struct + containing one parameter: session. session is an + internal pointer to the last session used by + TEEC_InvokeCommand with this operation. +*/ +#[repr(C)] +#[derive(Copy, Clone)] +pub struct TEEC_Operation { + pub started: u32, + pub paramTypes: u32, + pub params: [TEEC_Parameter; 4usize], + pub imp: TEEC_Operation__bindgen_ty_1, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TEEC_Operation__bindgen_ty_1 { + pub session: *mut TEEC_Session, +} +unsafe extern "C" { + /** TEEC_InitializeContext() - Initializes a context holding connection + information on the specific TEE, designated by the name string. + + @param name A zero-terminated string identifying the TEE to connect to. + If name is set to NULL, the default TEE is connected to. NULL + is the only supported value in this version of the API + implementation. + + @param context The context structure which is to be initialized. + + @return TEEC_SUCCESS The initialization was successful. + @return TEEC_Result Something failed.*/ + pub fn TEEC_InitializeContext( + name: *const ::core::ffi::c_char, + context: *mut TEEC_Context, + ) -> TEEC_Result; +} +unsafe extern "C" { + /** TEEC_FinalizeContext() - Destroys a context holding connection information + on the specific TEE. + + This function destroys an initialized TEE context, closing the connection + between the client application and the TEE. This function must only be + called when all sessions related to this TEE context have been closed and + all shared memory blocks have been released. + + @param context The context to be destroyed.*/ + pub fn TEEC_FinalizeContext(context: *mut TEEC_Context); +} +unsafe extern "C" { + /** TEEC_OpenSession() - Opens a new session with the specified trusted + application. + + @param context The initialized TEE context structure in which + scope to open the session. + @param session The session to initialize. + @param destination A structure identifying the trusted application + with which to open a session. + + @param connectionMethod The connection method to use. + @param connectionData Any data necessary to connect with the chosen + connection method. Not supported, should be set to + NULL. + @param operation An operation structure to use in the session. May + be set to NULL to signify no operation structure + needed. + + @param returnOrigin A parameter which will hold the error origin if + this function returns any value other than + TEEC_SUCCESS. + + @return TEEC_SUCCESS OpenSession successfully opened a new session. + @return TEEC_Result Something failed. +*/ + pub fn TEEC_OpenSession( + context: *mut TEEC_Context, + session: *mut TEEC_Session, + destination: *const TEEC_UUID, + connectionMethod: u32, + connectionData: *const ::core::ffi::c_void, + operation: *mut TEEC_Operation, + returnOrigin: *mut u32, + ) -> TEEC_Result; +} +unsafe extern "C" { + /** TEEC_CloseSession() - Closes the session which has been opened with the + specific trusted application. + + @param session The opened session to close.*/ + pub fn TEEC_CloseSession(session: *mut TEEC_Session); +} +unsafe extern "C" { + /** TEEC_InvokeCommand() - Executes a command in the specified trusted + application. + + @param session A handle to an open connection to the trusted + application. + @param commandID Identifier of the command in the trusted application + to invoke. + @param operation An operation structure to use in the invoke command. + May be set to NULL to signify no operation structure + needed. + @param returnOrigin A parameter which will hold the error origin if this + function returns any value other than TEEC_SUCCESS. + + @return TEEC_SUCCESS OpenSession successfully opened a new session. + @return TEEC_Result Something failed.*/ + pub fn TEEC_InvokeCommand( + session: *mut TEEC_Session, + commandID: u32, + operation: *mut TEEC_Operation, + returnOrigin: *mut u32, + ) -> TEEC_Result; +} +unsafe extern "C" { + /** TEEC_RegisterSharedMemory() - Register a block of existing memory as a + shared block within the scope of the specified context. + + @param context The initialized TEE context structure in which scope to + open the session. + @param sharedMem pointer to the shared memory structure to register. + + @return TEEC_SUCCESS The registration was successful. + @return TEEC_ERROR_OUT_OF_MEMORY Memory exhaustion. + @return TEEC_Result Something failed.*/ + pub fn TEEC_RegisterSharedMemory( + context: *mut TEEC_Context, + sharedMem: *mut TEEC_SharedMemory, + ) -> TEEC_Result; +} +unsafe extern "C" { + /** TEEC_AllocateSharedMemory() - Allocate shared memory for TEE. + + @param context The initialized TEE context structure in which scope to + open the session. + @param sharedMem Pointer to the allocated shared memory. + + @return TEEC_SUCCESS The registration was successful. + @return TEEC_ERROR_OUT_OF_MEMORY Memory exhaustion. + @return TEEC_Result Something failed.*/ + pub fn TEEC_AllocateSharedMemory( + context: *mut TEEC_Context, + sharedMem: *mut TEEC_SharedMemory, + ) -> TEEC_Result; +} +unsafe extern "C" { + /** TEEC_ReleaseSharedMemory() - Free or deregister the shared memory. + + @param sharedMem Pointer to the shared memory to be freed.*/ + pub fn TEEC_ReleaseSharedMemory(sharedMemory: *mut TEEC_SharedMemory); +} +unsafe extern "C" { + /** TEEC_RequestCancellation() - Request the cancellation of a pending open + session or command invocation. + + @param operation Pointer to an operation previously passed to open session + or invoke.*/ + pub fn TEEC_RequestCancellation(operation: *mut TEEC_Operation); +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct plugin_method { + pub name: *const ::core::ffi::c_char, + pub uuid: TEEC_UUID, + pub init: ::core::option::Option TEEC_Result>, + pub invoke: ::core::option::Option< + unsafe extern "C" fn( + cmd: ::core::ffi::c_uint, + sub_cmd: ::core::ffi::c_uint, + data: *mut ::core::ffi::c_void, + in_len: usize, + out_len: *mut usize, + ) -> TEEC_Result, + >, +} diff --git a/crates/optee-teec-sys/src/handwritten.rs b/crates/optee-teec-sys/src/handwritten.rs new file mode 100644 index 00000000..0b0cac51 --- /dev/null +++ b/crates/optee-teec-sys/src/handwritten.rs @@ -0,0 +1,68 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! Declarations that bindgen cannot generate from the C headers. +//! +//! `generated` is produced by +//! `cargo run --manifest-path xtask/Cargo.toml -- generate-bindings teec` from +//! the OP-TEE client headers listed in `HEADERS` in +//! `xtask/src/generate_bindings/teec/generate.rs`. An item belongs here only +//! when bindgen structurally cannot express it. + +use crate::generated::*; +use core::ffi::c_ulong; + +// Function-like macros from `tee_client_api.h`: +// +// #define TEEC_PARAM_TYPES(p0, p1, p2, p3) \ +// ((p0) | ((p1) << 4) | ((p2) << 8) | ((p3) << 12)) +// #define TEEC_PARAM_TYPE_GET(p, i) (((p) >> (i * 4)) & 0xF) +// +// bindgen does not expand function-like macros, so they are reimplemented as +// ordinary functions with the same arithmetic. The index is a `usize` so callers +// can pass array indices without casts. + +/// The four four-bit parameter types packed into one value by +/// [`TEEC_PARAM_TYPES`]. +/// +/// `tee_client_api.h` has no typedef for this: the parameter types are plain +/// `uint32_t` macros, so the alias only gives the packed value a name. +pub type TEEC_ParamType = u32; + +pub fn TEEC_PARAM_TYPES( + p0: TEEC_ParamType, + p1: TEEC_ParamType, + p2: TEEC_ParamType, + p3: TEEC_ParamType, +) -> TEEC_ParamType { + p0 | p1 << 4 | p2 << 8 | p3 << 12 +} + +pub fn TEEC_PARAM_TYPE_GET(p: TEEC_ParamType, i: usize) -> TEEC_ParamType { + (p >> (i * 4)) & 0xF +} + +/// `ULONG_MAX` from `tee_client_api.h`. +/// +/// Even with the clang macro fallback bindgen emits nothing for this one, so it +/// is hand-written. `c_ulong` keeps the value correct on both 32-bit and 64-bit +/// hosts instead of pinning the width of the target used for generation. +pub const TEEC_CONFIG_SHAREDMEM_MAX_SIZE: c_ulong = c_ulong::MAX; + +/// `tee_plugin_method.h` declares `struct plugin_method`; the SDK has always +/// exposed it under this name. +pub type PluginMethod = plugin_method; diff --git a/crates/optee-teec-sys/src/lib.rs b/crates/optee-teec-sys/src/lib.rs index a8c8336f..6e217b75 100644 --- a/crates/optee-teec-sys/src/lib.rs +++ b/crates/optee-teec-sys/src/lib.rs @@ -21,11 +21,16 @@ "## Feature flags\n", document_features::document_features!(), ))] -#![allow(non_camel_case_types, non_snake_case)] +#![allow(non_camel_case_types, non_snake_case, non_upper_case_globals)] -pub use plugin_method::*; -pub use tee_client_api::*; -pub type size_t = usize; +// The bindings live in their own module so `handwritten` can refer to them as +// `generated::*`. `include!` keeps the file out of `cargo fmt`: bindgen formats +// the C doc comments its own way and rewriting them here would make every +// regeneration a formatting diff. +mod generated { + include!("generated.rs"); +} +mod handwritten; -mod plugin_method; -mod tee_client_api; +pub use generated::*; +pub use handwritten::*; diff --git a/crates/optee-teec-sys/src/plugin_method.rs b/crates/optee-teec-sys/src/plugin_method.rs deleted file mode 100644 index dfa61209..00000000 --- a/crates/optee-teec-sys/src/plugin_method.rs +++ /dev/null @@ -1,33 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -use crate::{TEEC_Result, TEEC_UUID, size_t}; -use core::ffi::{c_char, c_void}; - -#[repr(C)] -pub struct PluginMethod { - pub name: *const c_char, - pub uuid: TEEC_UUID, - pub init: unsafe extern "C" fn() -> TEEC_Result, - pub invoke: unsafe extern "C" fn( - cmd: u32, - sub_cmd: u32, - data: *mut c_void, - in_len: size_t, - out_len: *mut size_t, - ) -> TEEC_Result, -} diff --git a/crates/optee-teec-sys/src/tee_client_api.rs b/crates/optee-teec-sys/src/tee_client_api.rs deleted file mode 100644 index 75f73d46..00000000 --- a/crates/optee-teec-sys/src/tee_client_api.rs +++ /dev/null @@ -1,201 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -use crate::size_t; -use core::ffi::*; - -pub fn TEEC_PARAM_TYPES(p0: u32, p1: u32, p2: u32, p3: u32) -> u32 { - let tmp = p1 << 4 | p2 << 8 | p3 << 12; - p0 | tmp -} - -pub const TEEC_CONFIG_PAYLOAD_REF_COUNT: u32 = 4; - -pub const TEEC_CONFIG_SHAREDMEM_MAX_SIZE: c_ulong = -1 as c_long as c_ulong; - -pub const TEEC_NONE: u32 = 0x00000000; -pub const TEEC_VALUE_INPUT: u32 = 0x00000001; -pub const TEEC_VALUE_OUTPUT: u32 = 0x00000002; -pub const TEEC_VALUE_INOUT: u32 = 0x00000003; -pub const TEEC_MEMREF_TEMP_INPUT: u32 = 0x00000005; -pub const TEEC_MEMREF_TEMP_OUTPUT: u32 = 0x00000006; -pub const TEEC_MEMREF_TEMP_INOUT: u32 = 0x00000007; -pub const TEEC_MEMREF_WHOLE: u32 = 0x0000000C; -pub const TEEC_MEMREF_PARTIAL_INPUT: u32 = 0x0000000D; -pub const TEEC_MEMREF_PARTIAL_OUTPUT: u32 = 0x0000000E; -pub const TEEC_MEMREF_PARTIAL_INOUT: u32 = 0x0000000F; - -pub const TEEC_MEM_INPUT: u32 = 0x00000001; -pub const TEEC_MEM_OUTPUT: u32 = 0x00000002; - -pub const TEEC_SUCCESS: u32 = 0x00000000; -pub const TEEC_ERROR_GENERIC: u32 = 0xFFFF0000; -pub const TEEC_ERROR_ACCESS_DENIED: u32 = 0xFFFF0001; -pub const TEEC_ERROR_CANCEL: u32 = 0xFFFF0002; -pub const TEEC_ERROR_ACCESS_CONFLICT: u32 = 0xFFFF0003; -pub const TEEC_ERROR_EXCESS_DATA: u32 = 0xFFFF0004; -pub const TEEC_ERROR_BAD_FORMAT: u32 = 0xFFFF0005; -pub const TEEC_ERROR_BAD_PARAMETERS: u32 = 0xFFFF0006; -pub const TEEC_ERROR_BAD_STATE: u32 = 0xFFFF0007; -pub const TEEC_ERROR_ITEM_NOT_FOUND: u32 = 0xFFFF0008; -pub const TEEC_ERROR_NOT_IMPLEMENTED: u32 = 0xFFFF0009; -pub const TEEC_ERROR_NOT_SUPPORTED: u32 = 0xFFFF000A; -pub const TEEC_ERROR_NO_DATA: u32 = 0xFFFF000B; -pub const TEEC_ERROR_OUT_OF_MEMORY: u32 = 0xFFFF000C; -pub const TEEC_ERROR_BUSY: u32 = 0xFFFF000D; -pub const TEEC_ERROR_COMMUNICATION: u32 = 0xFFFF000E; -pub const TEEC_ERROR_SECURITY: u32 = 0xFFFF000F; -pub const TEEC_ERROR_SHORT_BUFFER: u32 = 0xFFFF0010; -pub const TEEC_ERROR_EXTERNAL_CANCEL: u32 = 0xFFFF0011; -pub const TEEC_ERROR_TARGET_DEAD: u32 = 0xFFFF3024; - -pub const TEEC_ORIGIN_API: u32 = 0x00000001; -pub const TEEC_ORIGIN_COMMS: u32 = 0x00000002; -pub const TEEC_ORIGIN_TEE: u32 = 0x00000003; -pub const TEEC_ORIGIN_TRUSTED_APP: u32 = 0x00000004; - -pub const TEEC_LOGIN_PUBLIC: u32 = 0x00000000; -pub const TEEC_LOGIN_USER: u32 = 0x00000001; -pub const TEEC_LOGIN_GROUP: u32 = 0x00000002; -pub const TEEC_LOGIN_APPLICATION: u32 = 0x00000004; -pub const TEEC_LOGIN_USER_APPLICATION: u32 = 0x00000005; -pub const TEEC_LOGIN_GROUP_APPLICATION: u32 = 0x00000006; - -#[allow(non_camel_case_types)] -pub type TEEC_Result = u32; - -#[repr(C)] -pub struct TEEC_Context__Imp { - pub fd: c_int, - pub reg_mem: bool, - pub memref_null: bool, -} - -#[repr(C)] -pub struct TEEC_Context { - pub imp: TEEC_Context__Imp, -} - -#[repr(C)] -pub struct TEEC_UUID { - pub timeLow: u32, - pub timeMid: u16, - pub timeHiAndVersion: u16, - pub clockSeqAndNode: [u8; 8], -} - -#[repr(C)] -pub struct TEEC_Session__Imp { - pub ctx: *mut TEEC_Context, - pub session_id: u32, -} - -#[repr(C)] -pub struct TEEC_Session { - pub imp: TEEC_Session__Imp, -} - -#[repr(C)] -pub struct TEEC_SharedMemory__Imp { - pub id: c_int, - pub alloced_size: size_t, - pub shadow_buffer: *mut c_void, - pub registered_fd: c_int, - pub flags: u32, -} - -#[repr(C)] -pub struct TEEC_SharedMemory { - pub buffer: *mut c_void, - pub size: size_t, - pub flags: u32, - pub imp: TEEC_SharedMemory__Imp, -} - -#[derive(Copy, Clone)] -#[repr(C)] -pub struct TEEC_TempMemoryReference { - pub buffer: *mut c_void, - pub size: size_t, -} - -#[derive(Copy, Clone)] -#[repr(C)] -pub struct TEEC_RegisteredMemoryReference { - pub parent: *mut TEEC_SharedMemory, - pub size: size_t, - pub offset: size_t, -} - -#[derive(Copy, Clone)] -#[repr(C)] -pub struct TEEC_Value { - pub a: u32, - pub b: u32, -} - -#[repr(C)] -#[derive(Copy, Clone)] -pub union TEEC_Parameter { - pub tmpref: TEEC_TempMemoryReference, - pub memref: TEEC_RegisteredMemoryReference, - pub value: TEEC_Value, -} - -#[repr(C)] -pub struct TEEC_Operation__Imp { - pub session: *mut TEEC_Session, -} - -#[repr(C)] -pub struct TEEC_Operation { - pub started: u32, - pub paramTypes: u32, - pub params: [TEEC_Parameter; TEEC_CONFIG_PAYLOAD_REF_COUNT as usize], - pub imp: TEEC_Operation__Imp, -} - -unsafe extern "C" { - pub fn TEEC_InitializeContext(name: *const c_char, context: *mut TEEC_Context) -> TEEC_Result; - pub fn TEEC_FinalizeContext(context: *mut TEEC_Context); - pub fn TEEC_OpenSession( - context: *mut TEEC_Context, - session: *mut TEEC_Session, - destination: *const TEEC_UUID, - connectionMethod: u32, - connectionData: *const c_void, - operation: *mut TEEC_Operation, - returnOrigin: *mut u32, - ) -> TEEC_Result; - pub fn TEEC_CloseSession(session: *mut TEEC_Session); - pub fn TEEC_InvokeCommand( - session: *mut TEEC_Session, - commandID: u32, - operation: *mut TEEC_Operation, - returnOrigin: *mut u32, - ) -> TEEC_Result; - pub fn TEEC_RegisterSharedMemory( - context: *mut TEEC_Context, - sharedMem: *mut TEEC_SharedMemory, - ) -> TEEC_Result; - pub fn TEEC_AllocateSharedMemory( - context: *mut TEEC_Context, - sharedMem: *mut TEEC_SharedMemory, - ) -> TEEC_Result; - pub fn TEEC_ReleaseSharedMemory(sharedMemory: *mut TEEC_SharedMemory); - pub fn TEEC_RequestCancellation(operation: *mut TEEC_Operation); -} diff --git a/crates/optee-teec-systest/build.rs b/crates/optee-teec-systest/build.rs deleted file mode 100644 index 17e27d00..00000000 --- a/crates/optee-teec-systest/build.rs +++ /dev/null @@ -1,70 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -use std::{env, path::PathBuf}; - -fn main() { - let mut cfg = ctest::TestGenerator::new(); - let path = PathBuf::from(env::var("OPTEE_CLIENT_EXPORT").unwrap()).join("usr/include"); - cfg.language(ctest::Language::C) - .edition(2024) - .target("aarch64-unknown-linux-gnu") - .header("tee_client_api.h") - .header("tee_plugin_method.h") - .include(path.display().to_string()) - .rename_struct_ty(|ty| { - if ty.starts_with("TEEC") { - return Some(ty.to_string()); - } - if ty.eq("PluginMethod") { - return Some("struct plugin_method".to_string()); - } - None - }) - .rename_union_ty(|ty| { - if ty.starts_with("TEEC") { - return Some(ty.to_string()); - } - None - }) - .rename_struct_field(|_s, field| { - let field = field.ident(); - if field.starts_with("imp__") { - return Some(format!( - "imp.{}", - field.strip_prefix("imp__").expect("must ok") - )); - } - None - }) - .skip_struct(|s| s.ident().ends_with("__Imp")) - // The roundtrip implementation in ctest doesn't work with nested - // structs —it treats all bytes of TEEC_Session as if there’s no - // padding, which causes a mismatch in the last 4 padding bytes - // during the roundtrip test. - .skip_roundtrip(|s| s == "TEEC_Session") - .skip_struct_field_type(|s, field| { - let s = s.ident(); - let field = field.ident(); - (s == "TEEC_SharedMemory" - || s == "TEEC_Context" - || s == "TEEC_Session" - || s == "TEEC_Operation") - && field == "imp" - }); - ctest::generate_test(&mut cfg, "../optee-teec-sys/src/lib.rs", "all.rs").unwrap(); -} diff --git a/crates/optee-teec-systest/src/main.rs b/crates/optee-teec-systest/src/main.rs deleted file mode 100644 index dd060fc2..00000000 --- a/crates/optee-teec-systest/src/main.rs +++ /dev/null @@ -1,23 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -#![allow(clippy::all)] - -use core::ffi::*; -use optee_teec_sys::*; - -include!(concat!(env!("OUT_DIR"), "/all.rs")); diff --git a/crates/optee-teec/src/extension.rs b/crates/optee-teec/src/extension.rs index fc217bf3..a98ad6e2 100644 --- a/crates/optee-teec/src/extension.rs +++ b/crates/optee-teec/src/extension.rs @@ -15,10 +15,7 @@ // specific language governing permissions and limitations // under the License. -use crate::{ - raw::size_t, - {ErrorKind, Result}, -}; +use crate::{ErrorKind, Result}; use core::ffi::c_void; /// Parameters for a plugin invocation, carrying the command, sub-command, @@ -49,7 +46,7 @@ pub struct PluginParameters<'a, 'b> { /// (meaning the caller does not expect output). When present, /// every output-writing method automatically updates this value, /// ensuring `out_len` is never left unset. - out_len: Option<&'b mut size_t>, + out_len: Option<&'b mut usize>, } impl<'a, 'b> PluginParameters<'a, 'b> { @@ -68,8 +65,8 @@ impl<'a, 'b> PluginParameters<'a, 'b> { cmd: u32, sub_cmd: u32, buf: *mut c_void, - in_len: size_t, - out_len: *mut size_t, + in_len: usize, + out_len: *mut usize, ) -> Result { // Reject obviously invalid parameter combinations: // a non-zero in_len or a present out_len implies the caller expects diff --git a/crates/optee-utee-build/src/code_generator.rs b/crates/optee-utee-build/src/code_generator.rs index 3fd6b7ef..1dc2a109 100644 --- a/crates/optee-utee-build/src/code_generator.rs +++ b/crates/optee-utee-build/src/code_generator.rs @@ -53,7 +53,7 @@ impl HeaderFileGenerator { self.write_ta_head(conf)?; self.write_ta_heap(); - const LICENSE_STR: &str = include_str!("./license_str.txt"); + const LICENSE_STR: &str = include_str!("./license_header.txt"); let f = syn::parse2(self.code).unwrap(); // prettyplease will remove all of the comments in it, and the // maintainer will not support keeping comments, @@ -129,8 +129,8 @@ impl HeaderFileGenerator { let utee_value_conv_codes = property_value_as_utee_value_codes(&var_name, &prop.value); ext_property_codes.push(quote! { optee_utee::raw::user_ta_property { - name: #prop_name_codes.as_ptr(), - prop_type: #utee_type_name_codes, + name: #prop_name_codes.as_ptr().cast(), + type_: #utee_type_name_codes, value: #utee_value_conv_codes, } }); @@ -140,6 +140,19 @@ impl HeaderFileGenerator { let property_len = ORIGIN_PROPERTY_LEN + conf.ext_properties.len(); let no_mangle_attribute = no_mangle_attribute_codes(); self.code.extend(quote! { + /// The TA property table exported as `ta_props`. + /// + /// `libutee` reads it through an `extern const struct user_ta_property + /// ta_props[]`, so it must be a `static` with exactly this layout. + /// `user_ta_property` holds raw pointers and is therefore not `Sync` on + /// its own; every pointer in the table points to immutable data in the + /// TA image (`&'static` property names and values) and nothing ever + /// writes through it, so sharing the table is sound. + #[repr(transparent)] + pub struct TaProperties([optee_utee::raw::user_ta_property; N]); + + unsafe impl Sync for TaProperties {} + const IS_SINGLE_INSTANCE: bool = (TA_FLAGS & optee_utee::raw::TA_FLAG_SINGLE_INSTANCE) != 0; const IS_MULTI_SESSION: bool = (TA_FLAGS & optee_utee::raw::TA_FLAG_MULTI_SESSION) != 0; const IS_KEEP_ALIVE: bool = (TA_FLAGS & optee_utee::raw::TA_FLAG_INSTANCE_KEEP_ALIVE) != 0; @@ -149,59 +162,59 @@ impl HeaderFileGenerator { #no_mangle_attribute pub static ta_num_props: usize = #property_len; #no_mangle_attribute - pub static ta_props: [optee_utee::raw::user_ta_property; #property_len] = [ + pub static ta_props: TaProperties<#property_len> = TaProperties([ optee_utee::raw::user_ta_property { - name: optee_utee::raw::TA_PROP_STR_SINGLE_INSTANCE, - prop_type: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_BOOL, + name: optee_utee::raw::TA_PROP_STR_SINGLE_INSTANCE.as_ptr().cast(), + type_: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_BOOL, value: &IS_SINGLE_INSTANCE as *const bool as _, }, optee_utee::raw::user_ta_property { - name: optee_utee::raw::TA_PROP_STR_MULTI_SESSION, - prop_type: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_BOOL, + name: optee_utee::raw::TA_PROP_STR_MULTI_SESSION.as_ptr().cast(), + type_: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_BOOL, value: &IS_MULTI_SESSION as *const bool as _, }, optee_utee::raw::user_ta_property { - name: optee_utee::raw::TA_PROP_STR_KEEP_ALIVE, - prop_type: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_BOOL, + name: optee_utee::raw::TA_PROP_STR_KEEP_ALIVE.as_ptr().cast(), + type_: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_BOOL, value: &IS_KEEP_ALIVE as *const bool as _, }, optee_utee::raw::user_ta_property { - name: optee_utee::raw::TA_PROP_STR_KEEP_CRASHED, - prop_type: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_BOOL, + name: optee_utee::raw::TA_PROP_STR_KEEP_CRASHED.as_ptr().cast(), + type_: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_BOOL, value: &IS_KEEP_CRASHED as *const bool as _, }, optee_utee::raw::user_ta_property { - name: optee_utee::raw::TA_PROP_STR_DATA_SIZE, - prop_type: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_U32, + name: optee_utee::raw::TA_PROP_STR_DATA_SIZE.as_ptr().cast(), + type_: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_U32, value: &TA_DATA_SIZE as *const u32 as _, }, optee_utee::raw::user_ta_property { - name: optee_utee::raw::TA_PROP_STR_STACK_SIZE, - prop_type: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_U32, + name: optee_utee::raw::TA_PROP_STR_STACK_SIZE.as_ptr().cast(), + type_: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_U32, value: &TA_STACK_SIZE as *const u32 as _, }, optee_utee::raw::user_ta_property { - name: optee_utee::raw::TA_PROP_STR_VERSION, - prop_type: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_STRING, + name: optee_utee::raw::TA_PROP_STR_VERSION.as_ptr().cast(), + type_: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_STRING, value: TA_VERSION as *const [u8] as _, }, optee_utee::raw::user_ta_property { - name: optee_utee::raw::TA_PROP_STR_DESCRIPTION, - prop_type: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_STRING, + name: optee_utee::raw::TA_PROP_STR_DESCRIPTION.as_ptr().cast(), + type_: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_STRING, value: TA_DESCRIPTION as *const [u8] as _, }, optee_utee::raw::user_ta_property { - name: optee_utee::raw::TA_PROP_STR_ENDIAN, - prop_type: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_U32, + name: optee_utee::raw::TA_PROP_STR_ENDIAN.as_ptr().cast(), + type_: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_U32, value: &TA_ENDIAN as *const u32 as _, }, optee_utee::raw::user_ta_property { - name: optee_utee::raw::TA_PROP_STR_DOES_NOT_CLOSE_HANDLE_ON_CORRUPT_OBJECT, - prop_type: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_BOOL, + name: optee_utee::raw::TA_PROP_STR_DOES_NOT_CLOSE_HANDLE_ON_CORRUPT_OBJECT.as_ptr().cast(), + type_: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_BOOL, value: &DONT_CLOSE_HANDLE_ON_CORRUPT_OBJECT as *const bool as _, }, #(#ext_property_codes),* - ]; + ]); }); Ok(()) @@ -434,4 +447,26 @@ mod tests { .unwrap_or_else(|e| panic!("header must parse for {payload:?}: {e}")); } } + + /// Guarantees: a configured extra property is appended to `ta_props` and its + /// name is coerced to `*const c_char` like the built-in entries, so the + /// generated table keeps compiling on targets where `c_char` is signed. + #[test] + fn ext_property_is_appended_to_ta_props() { + let uuid = "26509cec-4a2b-4935-87ab-762d89fbf0b0"; + let conf = TaConfig::new_default(uuid, "0.1.0", "test") + .unwrap() + .add_ext_property("my.prop", PropertyValue::U32(1)); + let codes = HeaderFileGenerator::new().generate(&conf).unwrap(); + + syn::parse_file(&codes).expect("generated header must parse"); + assert!( + codes.contains("TaProperties<11usize>"), + "the extra property did not grow ta_props:\n{codes}" + ); + assert!( + codes.contains(r#"name: b"my.prop\0".as_ptr().cast()"#), + "the extra property name is not coerced to `*const c_char`:\n{codes}" + ); + } } diff --git a/crates/optee-utee-build/src/license_header.txt b/crates/optee-utee-build/src/license_header.txt new file mode 120000 index 00000000..cb4abbb1 --- /dev/null +++ b/crates/optee-utee-build/src/license_header.txt @@ -0,0 +1 @@ +../../../license_header.txt \ No newline at end of file diff --git a/crates/optee-utee-build/test_files/test_result.rs b/crates/optee-utee-build/test_files/test_result.rs index 682ce968..e9712a75 100644 --- a/crates/optee-utee-build/test_files/test_result.rs +++ b/crates/optee-utee-build/test_files/test_result.rs @@ -34,6 +34,17 @@ pub static trace_ext_prefix: [u8; 3usize] = *b"TA\0"; pub unsafe extern "C" fn tahead_get_trace_level() -> c_int { unsafe { trace_level } } +/// The TA property table exported as `ta_props`. +/// +/// `libutee` reads it through an `extern const struct user_ta_property +/// ta_props[]`, so it must be a `static` with exactly this layout. +/// `user_ta_property` holds raw pointers and is therefore not `Sync` on +/// its own; every pointer in the table points to immutable data in the +/// TA image (`&'static` property names and values) and nothing ever +/// writes through it, so sharing the table is sound. +#[repr(transparent)] +pub struct TaProperties([optee_utee::raw::user_ta_property; N]); +unsafe impl Sync for TaProperties {} const IS_SINGLE_INSTANCE: bool = (TA_FLAGS & optee_utee::raw::TA_FLAG_SINGLE_INSTANCE) != 0; const IS_MULTI_SESSION: bool = (TA_FLAGS & optee_utee::raw::TA_FLAG_MULTI_SESSION) != 0; @@ -47,58 +58,60 @@ const DONT_CLOSE_HANDLE_ON_CORRUPT_OBJECT: bool = (TA_FLAGS #[unsafe(no_mangle)] pub static ta_num_props: usize = 10usize; #[unsafe(no_mangle)] -pub static ta_props: [optee_utee::raw::user_ta_property; 10usize] = [ +pub static ta_props: TaProperties<10usize> = TaProperties([ optee_utee::raw::user_ta_property { - name: optee_utee::raw::TA_PROP_STR_SINGLE_INSTANCE, - prop_type: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_BOOL, + name: optee_utee::raw::TA_PROP_STR_SINGLE_INSTANCE.as_ptr().cast(), + type_: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_BOOL, value: &IS_SINGLE_INSTANCE as *const bool as _, }, optee_utee::raw::user_ta_property { - name: optee_utee::raw::TA_PROP_STR_MULTI_SESSION, - prop_type: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_BOOL, + name: optee_utee::raw::TA_PROP_STR_MULTI_SESSION.as_ptr().cast(), + type_: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_BOOL, value: &IS_MULTI_SESSION as *const bool as _, }, optee_utee::raw::user_ta_property { - name: optee_utee::raw::TA_PROP_STR_KEEP_ALIVE, - prop_type: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_BOOL, + name: optee_utee::raw::TA_PROP_STR_KEEP_ALIVE.as_ptr().cast(), + type_: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_BOOL, value: &IS_KEEP_ALIVE as *const bool as _, }, optee_utee::raw::user_ta_property { - name: optee_utee::raw::TA_PROP_STR_KEEP_CRASHED, - prop_type: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_BOOL, + name: optee_utee::raw::TA_PROP_STR_KEEP_CRASHED.as_ptr().cast(), + type_: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_BOOL, value: &IS_KEEP_CRASHED as *const bool as _, }, optee_utee::raw::user_ta_property { - name: optee_utee::raw::TA_PROP_STR_DATA_SIZE, - prop_type: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_U32, + name: optee_utee::raw::TA_PROP_STR_DATA_SIZE.as_ptr().cast(), + type_: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_U32, value: &TA_DATA_SIZE as *const u32 as _, }, optee_utee::raw::user_ta_property { - name: optee_utee::raw::TA_PROP_STR_STACK_SIZE, - prop_type: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_U32, + name: optee_utee::raw::TA_PROP_STR_STACK_SIZE.as_ptr().cast(), + type_: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_U32, value: &TA_STACK_SIZE as *const u32 as _, }, optee_utee::raw::user_ta_property { - name: optee_utee::raw::TA_PROP_STR_VERSION, - prop_type: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_STRING, + name: optee_utee::raw::TA_PROP_STR_VERSION.as_ptr().cast(), + type_: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_STRING, value: TA_VERSION as *const [u8] as _, }, optee_utee::raw::user_ta_property { - name: optee_utee::raw::TA_PROP_STR_DESCRIPTION, - prop_type: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_STRING, + name: optee_utee::raw::TA_PROP_STR_DESCRIPTION.as_ptr().cast(), + type_: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_STRING, value: TA_DESCRIPTION as *const [u8] as _, }, optee_utee::raw::user_ta_property { - name: optee_utee::raw::TA_PROP_STR_ENDIAN, - prop_type: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_U32, + name: optee_utee::raw::TA_PROP_STR_ENDIAN.as_ptr().cast(), + type_: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_U32, value: &TA_ENDIAN as *const u32 as _, }, optee_utee::raw::user_ta_property { - name: optee_utee::raw::TA_PROP_STR_DOES_NOT_CLOSE_HANDLE_ON_CORRUPT_OBJECT, - prop_type: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_BOOL, + name: optee_utee::raw::TA_PROP_STR_DOES_NOT_CLOSE_HANDLE_ON_CORRUPT_OBJECT + .as_ptr() + .cast(), + type_: optee_utee::raw::user_ta_prop_type::USER_TA_PROP_TYPE_BOOL, value: &DONT_CLOSE_HANDLE_ON_CORRUPT_OBJECT as *const bool as _, }, -]; +]); #[unsafe(no_mangle)] #[unsafe(link_section = ".ta_head")] pub static ta_head: optee_utee::raw::ta_head = optee_utee::raw::ta_head { diff --git a/crates/optee-utee-sys/src/generated.rs b/crates/optee-utee-sys/src/generated.rs new file mode 100644 index 00000000..12587550 --- /dev/null +++ b/crates/optee-utee-sys/src/generated.rs @@ -0,0 +1,1831 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +// @generated by `cargo run --manifest-path xtask/Cargo.toml -- generate-bindings utee` +// from the OP-TEE TA dev kit headers. Do not edit by hand. +// +// Regenerate after changing the OP-TEE version in optee-version.txt. + +/* automatically generated by rust-bindgen 0.72.1 */ + +#[repr(C)] +#[derive(Default)] +pub struct __IncompleteArrayField(::core::marker::PhantomData, [T; 0]); +impl __IncompleteArrayField { + #[inline] + pub const fn new() -> Self { + __IncompleteArrayField(::core::marker::PhantomData, []) + } + #[inline] + pub fn as_ptr(&self) -> *const T { + self as *const _ as *const T + } + #[inline] + pub fn as_mut_ptr(&mut self) -> *mut T { + self as *mut _ as *mut T + } + #[inline] + pub unsafe fn as_slice(&self, len: usize) -> &[T] { + unsafe { ::core::slice::from_raw_parts(self.as_ptr(), len) } + } + #[inline] + pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] { + unsafe { ::core::slice::from_raw_parts_mut(self.as_mut_ptr(), len) } + } +} +impl ::core::fmt::Debug for __IncompleteArrayField { + fn fmt(&self, fmt: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result { + fmt.write_str("__IncompleteArrayField") + } +} +pub const TEE_CORE_API_MAJOR_VERSION: u32 = 1; +pub const TEE_CORE_API_MINOR_VERSION: u32 = 3; +pub const TEE_CORE_API_MAINTENANCE_VERSION: u32 = 1; +pub const TEE_CORE_API_VERSION: u32 = 16974080; +pub const TEE_HANDLE_NULL: u32 = 0; +pub const TEE_TIMEOUT_INFINITE: u32 = 4294967295; +pub const TEE_SUCCESS: u32 = 0; +pub const TEE_ERROR_CORRUPT_OBJECT: u32 = 4027580417; +pub const TEE_ERROR_CORRUPT_OBJECT_2: u32 = 4027580418; +pub const TEE_ERROR_STORAGE_NOT_AVAILABLE: u32 = 4027580419; +pub const TEE_ERROR_STORAGE_NOT_AVAILABLE_2: u32 = 4027580420; +pub const TEE_ERROR_UNSUPPORTED_VERSION: u32 = 4027580421; +pub const TEE_ERROR_CIPHERTEXT_INVALID: u32 = 4027580422; +pub const TEE_ERROR_GENERIC: u32 = 4294901760; +pub const TEE_ERROR_ACCESS_DENIED: u32 = 4294901761; +pub const TEE_ERROR_CANCEL: u32 = 4294901762; +pub const TEE_ERROR_ACCESS_CONFLICT: u32 = 4294901763; +pub const TEE_ERROR_EXCESS_DATA: u32 = 4294901764; +pub const TEE_ERROR_BAD_FORMAT: u32 = 4294901765; +pub const TEE_ERROR_BAD_PARAMETERS: u32 = 4294901766; +pub const TEE_ERROR_BAD_STATE: u32 = 4294901767; +pub const TEE_ERROR_ITEM_NOT_FOUND: u32 = 4294901768; +pub const TEE_ERROR_NOT_IMPLEMENTED: u32 = 4294901769; +pub const TEE_ERROR_NOT_SUPPORTED: u32 = 4294901770; +pub const TEE_ERROR_NO_DATA: u32 = 4294901771; +pub const TEE_ERROR_OUT_OF_MEMORY: u32 = 4294901772; +pub const TEE_ERROR_BUSY: u32 = 4294901773; +pub const TEE_ERROR_COMMUNICATION: u32 = 4294901774; +pub const TEE_ERROR_SECURITY: u32 = 4294901775; +pub const TEE_ERROR_SHORT_BUFFER: u32 = 4294901776; +pub const TEE_ERROR_EXTERNAL_CANCEL: u32 = 4294901777; +pub const TEE_ERROR_TIMEOUT: u32 = 4294914049; +pub const TEE_ERROR_OVERFLOW: u32 = 4294914063; +pub const TEE_ERROR_TARGET_DEAD: u32 = 4294914084; +pub const TEE_ERROR_STORAGE_NO_SPACE: u32 = 4294914113; +pub const TEE_ERROR_MAC_INVALID: u32 = 4294914161; +pub const TEE_ERROR_SIGNATURE_INVALID: u32 = 4294914162; +pub const TEE_ERROR_TIME_NOT_SET: u32 = 4294922240; +pub const TEE_ERROR_TIME_NEEDS_RESET: u32 = 4294922241; +pub const TEE_PARAM_TYPE_NONE: u32 = 0; +pub const TEE_PARAM_TYPE_VALUE_INPUT: u32 = 1; +pub const TEE_PARAM_TYPE_VALUE_OUTPUT: u32 = 2; +pub const TEE_PARAM_TYPE_VALUE_INOUT: u32 = 3; +pub const TEE_PARAM_TYPE_MEMREF_INPUT: u32 = 5; +pub const TEE_PARAM_TYPE_MEMREF_OUTPUT: u32 = 6; +pub const TEE_PARAM_TYPE_MEMREF_INOUT: u32 = 7; +pub const TEE_LOGIN_PUBLIC: u32 = 0; +pub const TEE_LOGIN_USER: u32 = 1; +pub const TEE_LOGIN_GROUP: u32 = 2; +pub const TEE_LOGIN_APPLICATION: u32 = 4; +pub const TEE_LOGIN_APPLICATION_USER: u32 = 5; +pub const TEE_LOGIN_APPLICATION_GROUP: u32 = 6; +pub const TEE_LOGIN_TRUSTED_APP: u32 = 4026531840; +pub const TEE_ORIGIN_API: u32 = 1; +pub const TEE_ORIGIN_COMMS: u32 = 2; +pub const TEE_ORIGIN_TEE: u32 = 3; +pub const TEE_ORIGIN_TRUSTED_APP: u32 = 4; +pub const TEE_MEMORY_ACCESS_READ: u32 = 1; +pub const TEE_MEMORY_ACCESS_WRITE: u32 = 2; +pub const TEE_MEMORY_ACCESS_ANY_OWNER: u32 = 4; +pub const TEE_MALLOC_FILL_ZERO: u32 = 0; +pub const TEE_MALLOC_NO_FILL: u32 = 1; +pub const TEE_MALLOC_NO_SHARE: u32 = 2; +pub const TEE_DATA_SEEK_SET: u32 = 0; +pub const TEE_DATA_SEEK_CUR: u32 = 1; +pub const TEE_DATA_SEEK_END: u32 = 2; +pub const TEE_WHENCE_ILLEGAL_VALUE: u32 = 2147483647; +pub const TEE_MODE_ENCRYPT: u32 = 0; +pub const TEE_MODE_DECRYPT: u32 = 1; +pub const TEE_MODE_SIGN: u32 = 2; +pub const TEE_MODE_VERIFY: u32 = 3; +pub const TEE_MODE_MAC: u32 = 4; +pub const TEE_MODE_DIGEST: u32 = 5; +pub const TEE_MODE_DERIVE: u32 = 6; +pub const TEE_MODE_ILLEGAL_VALUE: u32 = 2147483647; +pub const TEE_STORAGE_PRIVATE: u32 = 1; +pub const TEE_DATA_FLAG_ACCESS_READ: u32 = 1; +pub const TEE_DATA_FLAG_ACCESS_WRITE: u32 = 2; +pub const TEE_DATA_FLAG_ACCESS_WRITE_META: u32 = 4; +pub const TEE_DATA_FLAG_SHARE_READ: u32 = 16; +pub const TEE_DATA_FLAG_SHARE_WRITE: u32 = 32; +pub const TEE_DATA_FLAG_OVERWRITE: u32 = 1024; +pub const TEE_DATA_MAX_POSITION: u32 = 4294967295; +pub const TEE_OBJECT_ID_MAX_LEN: u32 = 64; +pub const TEE_USAGE_EXTRACTABLE: u32 = 1; +pub const TEE_USAGE_ENCRYPT: u32 = 2; +pub const TEE_USAGE_DECRYPT: u32 = 4; +pub const TEE_USAGE_MAC: u32 = 8; +pub const TEE_USAGE_SIGN: u32 = 16; +pub const TEE_USAGE_VERIFY: u32 = 32; +pub const TEE_USAGE_DERIVE: u32 = 64; +pub const TEE_HANDLE_FLAG_PERSISTENT: u32 = 65536; +pub const TEE_HANDLE_FLAG_INITIALIZED: u32 = 131072; +pub const TEE_HANDLE_FLAG_KEY_SET: u32 = 262144; +pub const TEE_HANDLE_FLAG_EXPECT_TWO_KEYS: u32 = 524288; +pub const TEE_HANDLE_FLAG_EXTRACTING: u32 = 1048576; +pub const TEE_OPERATION_CIPHER: u32 = 1; +pub const TEE_OPERATION_MAC: u32 = 3; +pub const TEE_OPERATION_AE: u32 = 4; +pub const TEE_OPERATION_DIGEST: u32 = 5; +pub const TEE_OPERATION_ASYMMETRIC_CIPHER: u32 = 6; +pub const TEE_OPERATION_ASYMMETRIC_SIGNATURE: u32 = 7; +pub const TEE_OPERATION_KEY_DERIVATION: u32 = 8; +pub const TEE_OPERATION_STATE_INITIAL: u32 = 0; +pub const TEE_OPERATION_STATE_ACTIVE: u32 = 1; +pub const TEE_OPERATION_STATE_EXTRACTING: u32 = 2; +pub const TEE_ALG_AES_ECB_NOPAD: u32 = 268435472; +pub const TEE_ALG_AES_CBC_NOPAD: u32 = 268435728; +pub const TEE_ALG_AES_CTR: u32 = 268435984; +pub const TEE_ALG_AES_CTS: u32 = 268436240; +pub const TEE_ALG_AES_XTS: u32 = 268436496; +pub const TEE_ALG_AES_CBC_MAC_NOPAD: u32 = 805306640; +pub const TEE_ALG_AES_CBC_MAC_PKCS5: u32 = 805307664; +pub const TEE_ALG_AES_CMAC: u32 = 805307920; +pub const TEE_ALG_AES_CCM: u32 = 1073743632; +pub const TEE_ALG_AES_GCM: u32 = 1073743888; +pub const TEE_ALG_DES_ECB_NOPAD: u32 = 268435473; +pub const TEE_ALG_DES_CBC_NOPAD: u32 = 268435729; +pub const TEE_ALG_DES_CBC_MAC_NOPAD: u32 = 805306641; +pub const TEE_ALG_DES_CBC_MAC_PKCS5: u32 = 805307665; +pub const TEE_ALG_DES3_ECB_NOPAD: u32 = 268435475; +pub const TEE_ALG_DES3_CBC_NOPAD: u32 = 268435731; +pub const TEE_ALG_DES3_CBC_MAC_NOPAD: u32 = 805306643; +pub const TEE_ALG_DES3_CBC_MAC_PKCS5: u32 = 805307667; +pub const TEE_ALG_SM4_ECB_NOPAD: u32 = 268435476; +pub const TEE_ALG_SM4_CBC_NOPAD: u32 = 268435732; +pub const TEE_ALG_SM4_CTR: u32 = 268435988; +pub const TEE_ALG_RSASSA_PKCS1_V1_5_MD5: u32 = 1879054384; +pub const TEE_ALG_RSASSA_PKCS1_V1_5_SHA1: u32 = 1879058480; +pub const TEE_ALG_RSASSA_PKCS1_V1_5_SHA224: u32 = 1879062576; +pub const TEE_ALG_RSASSA_PKCS1_V1_5_SHA256: u32 = 1879066672; +pub const TEE_ALG_RSASSA_PKCS1_V1_5_SHA384: u32 = 1879070768; +pub const TEE_ALG_RSASSA_PKCS1_V1_5_SHA512: u32 = 1879074864; +pub const TEE_ALG_RSASSA_PKCS1_V1_5_MD5SHA1: u32 = 1879111728; +pub const TEE_ALG_RSASSA_PKCS1_V1_5_SHA3_224: u32 = 1879083056; +pub const TEE_ALG_RSASSA_PKCS1_V1_5_SHA3_256: u32 = 1879087152; +pub const TEE_ALG_RSASSA_PKCS1_V1_5_SHA3_384: u32 = 1879091248; +pub const TEE_ALG_RSASSA_PKCS1_V1_5_SHA3_512: u32 = 1879095344; +pub const TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA1: u32 = 1881221424; +pub const TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA224: u32 = 1882274096; +pub const TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA256: u32 = 1883326768; +pub const TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA384: u32 = 1884379440; +pub const TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA512: u32 = 1885432112; +pub const TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA3_224: u32 = 1887537456; +pub const TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA3_256: u32 = 1888590128; +pub const TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA3_384: u32 = 1889642800; +pub const TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA3_512: u32 = 1890695472; +pub const TEE_ALG_RSAES_PKCS1_V1_5: u32 = 1610613040; +pub const TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA1: u32 = 1612775984; +pub const TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA224: u32 = 1613824560; +pub const TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA256: u32 = 1614873136; +pub const TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA384: u32 = 1615921712; +pub const TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA512: u32 = 1616970288; +pub const TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA3_224: u32 = 1619067440; +pub const TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA3_256: u32 = 1620116016; +pub const TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA3_384: u32 = 1621164592; +pub const TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA3_512: u32 = 1622213168; +pub const TEE_ALG_RSA_NOPAD: u32 = 1610612784; +pub const TEE_ALG_DSA_SHA1: u32 = 1879056689; +pub const TEE_ALG_DSA_SHA224: u32 = 1879060785; +pub const TEE_ALG_DSA_SHA256: u32 = 1879064881; +pub const TEE_ALG_DSA_SHA3_224: u32 = 1879081265; +pub const TEE_ALG_DSA_SHA3_256: u32 = 1879085361; +pub const TEE_ALG_DSA_SHA3_384: u32 = 1879089457; +pub const TEE_ALG_DSA_SHA3_512: u32 = 1879093553; +pub const TEE_ALG_SM2_DSA_SM3: u32 = 1879072837; +pub const TEE_ALG_DH_DERIVE_SHARED_SECRET: u32 = 2147483698; +pub const TEE_ALG_SM2_KEP: u32 = 1610612805; +pub const TEE_ALG_MD5: u32 = 1342177281; +pub const TEE_ALG_SHA1: u32 = 1342177282; +pub const TEE_ALG_SHA224: u32 = 1342177283; +pub const TEE_ALG_SHA256: u32 = 1342177284; +pub const TEE_ALG_SHA384: u32 = 1342177285; +pub const TEE_ALG_SHA512: u32 = 1342177286; +pub const TEE_ALG_SHA3_224: u32 = 1342177288; +pub const TEE_ALG_SHA3_256: u32 = 1342177289; +pub const TEE_ALG_SHA3_384: u32 = 1342177290; +pub const TEE_ALG_SHA3_512: u32 = 1342177291; +pub const TEE_ALG_MD5SHA1: u32 = 1342177295; +pub const TEE_ALG_HMAC_MD5: u32 = 805306369; +pub const TEE_ALG_HMAC_SHA1: u32 = 805306370; +pub const TEE_ALG_HMAC_SHA224: u32 = 805306371; +pub const TEE_ALG_HMAC_SHA256: u32 = 805306372; +pub const TEE_ALG_HMAC_SHA384: u32 = 805306373; +pub const TEE_ALG_HMAC_SHA512: u32 = 805306374; +pub const TEE_ALG_HMAC_SM3: u32 = 805306375; +pub const TEE_ALG_HMAC_SHA3_224: u32 = 805306376; +pub const TEE_ALG_HMAC_SHA3_256: u32 = 805306377; +pub const TEE_ALG_HMAC_SHA3_384: u32 = 805306378; +pub const TEE_ALG_HMAC_SHA3_512: u32 = 805306379; +pub const TEE_ALG_ECDSA_P192: u32 = 1879052354; +pub const TEE_ALG_ECDSA_P224: u32 = 1879056450; +pub const TEE_ALG_ECDSA_P256: u32 = 1879060546; +pub const TEE_ALG_ECDSA_P384: u32 = 1879064642; +pub const TEE_ALG_ECDSA_P521: u32 = 1879068738; +pub const TEE_ALG_ECDH_P192: u32 = 2147483714; +pub const TEE_ALG_ECDH_P224: u32 = 2147483714; +pub const TEE_ALG_ECDH_P256: u32 = 2147483714; +pub const TEE_ALG_ECDH_P384: u32 = 2147483714; +pub const TEE_ALG_ECDH_P521: u32 = 2147483714; +pub const TEE_ALG_ECDH_DERIVE_SHARED_SECRET: u32 = 2147483714; +pub const TEE_ALG_ECDSA_SHA1: u32 = 1879052354; +pub const TEE_ALG_ECDSA_SHA224: u32 = 1879056450; +pub const TEE_ALG_ECDSA_SHA256: u32 = 1879060546; +pub const TEE_ALG_ECDSA_SHA384: u32 = 1879064642; +pub const TEE_ALG_ECDSA_SHA512: u32 = 1879068738; +pub const TEE_ALG_ECDSA_SHA3_224: u32 = 1879072834; +pub const TEE_ALG_ECDSA_SHA3_256: u32 = 1879076930; +pub const TEE_ALG_ECDSA_SHA3_384: u32 = 1879081026; +pub const TEE_ALG_ECDSA_SHA3_512: u32 = 1879085122; +pub const TEE_ALG_ED25519: u32 = 1879072835; +pub const TEE_ALG_ED448: u32 = 1879072836; +pub const TEE_ALG_SM2_PKE: u32 = 2147483718; +pub const TEE_ALG_HKDF: u32 = 2147483719; +pub const TEE_ALG_SM3: u32 = 1342177287; +pub const TEE_ALG_X25519: u32 = 2147483716; +pub const TEE_ALG_X448: u32 = 2147483717; +pub const TEE_ALG_SM4_ECB_PKCS5: u32 = 268435477; +pub const TEE_ALG_SM4_CBC_PKCS5: u32 = 268435733; +pub const TEE_ALG_ILLEGAL_VALUE: u32 = 4026531839; +pub const TEE_ALG_SHAKE128: u32 = 1342177537; +pub const TEE_ALG_SHAKE256: u32 = 1342177538; +pub const TEE_TYPE_AES: u32 = 2684354576; +pub const TEE_TYPE_DES: u32 = 2684354577; +pub const TEE_TYPE_DES3: u32 = 2684354579; +pub const TEE_TYPE_SM4: u32 = 2684354580; +pub const TEE_TYPE_HMAC_MD5: u32 = 2684354561; +pub const TEE_TYPE_HMAC_SHA1: u32 = 2684354562; +pub const TEE_TYPE_HMAC_SHA224: u32 = 2684354563; +pub const TEE_TYPE_HMAC_SHA256: u32 = 2684354564; +pub const TEE_TYPE_HMAC_SHA384: u32 = 2684354565; +pub const TEE_TYPE_HMAC_SHA512: u32 = 2684354566; +pub const TEE_TYPE_HMAC_SM3: u32 = 2684354567; +pub const TEE_TYPE_HMAC_SHA3_224: u32 = 2684354568; +pub const TEE_TYPE_HMAC_SHA3_256: u32 = 2684354569; +pub const TEE_TYPE_HMAC_SHA3_384: u32 = 2684354570; +pub const TEE_TYPE_HMAC_SHA3_512: u32 = 2684354571; +pub const TEE_TYPE_RSA_PUBLIC_KEY: u32 = 2684354608; +pub const TEE_TYPE_RSA_KEYPAIR: u32 = 2701131824; +pub const TEE_TYPE_DSA_PUBLIC_KEY: u32 = 2684354609; +pub const TEE_TYPE_DSA_KEYPAIR: u32 = 2701131825; +pub const TEE_TYPE_DH_KEYPAIR: u32 = 2701131826; +pub const TEE_TYPE_ECDSA_PUBLIC_KEY: u32 = 2684354625; +pub const TEE_TYPE_ECDSA_KEYPAIR: u32 = 2701131841; +pub const TEE_TYPE_ECDH_PUBLIC_KEY: u32 = 2684354626; +pub const TEE_TYPE_ECDH_KEYPAIR: u32 = 2701131842; +pub const TEE_TYPE_ED25519_PUBLIC_KEY: u32 = 2684354627; +pub const TEE_TYPE_ED25519_KEYPAIR: u32 = 2701131843; +pub const TEE_TYPE_ED448_PUBLIC_KEY: u32 = 2684354632; +pub const TEE_TYPE_ED448_KEYPAIR: u32 = 2701131848; +pub const TEE_TYPE_X448_PUBLIC_KEY: u32 = 2684354633; +pub const TEE_TYPE_X448_KEYPAIR: u32 = 2701131849; +pub const TEE_TYPE_SM2_DSA_PUBLIC_KEY: u32 = 2684354629; +pub const TEE_TYPE_SM2_DSA_KEYPAIR: u32 = 2701131845; +pub const TEE_TYPE_SM2_KEP_PUBLIC_KEY: u32 = 2684354630; +pub const TEE_TYPE_SM2_KEP_KEYPAIR: u32 = 2701131846; +pub const TEE_TYPE_SM2_PKE_PUBLIC_KEY: u32 = 2684354631; +pub const TEE_TYPE_SM2_PKE_KEYPAIR: u32 = 2701131847; +pub const TEE_TYPE_HKDF: u32 = 2684354634; +pub const TEE_TYPE_GENERIC_SECRET: u32 = 2684354560; +pub const TEE_TYPE_CORRUPTED_OBJECT: u32 = 2684354750; +pub const TEE_TYPE_DATA: u32 = 2684354751; +pub const TEE_TYPE_X25519_PUBLIC_KEY: u32 = 2684354628; +pub const TEE_TYPE_X25519_KEYPAIR: u32 = 2701131844; +pub const TEE_TYPE_ILLEGAL_VALUE: u32 = 4026531839; +pub const TEE_ATTR_SECRET_VALUE: u32 = 3221225472; +pub const TEE_ATTR_RSA_MODULUS: u32 = 3489661232; +pub const TEE_ATTR_RSA_PUBLIC_EXPONENT: u32 = 3489661488; +pub const TEE_ATTR_RSA_PRIVATE_EXPONENT: u32 = 3221226288; +pub const TEE_ATTR_RSA_PRIME1: u32 = 3221226544; +pub const TEE_ATTR_RSA_PRIME2: u32 = 3221226800; +pub const TEE_ATTR_RSA_EXPONENT1: u32 = 3221227056; +pub const TEE_ATTR_RSA_EXPONENT2: u32 = 3221227312; +pub const TEE_ATTR_RSA_COEFFICIENT: u32 = 3221227568; +pub const TEE_ATTR_DSA_PRIME: u32 = 3489665073; +pub const TEE_ATTR_DSA_SUBPRIME: u32 = 3489665329; +pub const TEE_ATTR_DSA_BASE: u32 = 3489665585; +pub const TEE_ATTR_DSA_PUBLIC_VALUE: u32 = 3489661233; +pub const TEE_ATTR_DSA_PRIVATE_VALUE: u32 = 3221226033; +pub const TEE_ATTR_DH_PRIME: u32 = 3489665074; +pub const TEE_ATTR_DH_SUBPRIME: u32 = 3489665330; +pub const TEE_ATTR_DH_BASE: u32 = 3489665586; +pub const TEE_ATTR_DH_X_BITS: u32 = 4026536754; +pub const TEE_ATTR_DH_PUBLIC_VALUE: u32 = 3489661234; +pub const TEE_ATTR_DH_PRIVATE_VALUE: u32 = 3221226034; +pub const TEE_ATTR_RSA_OAEP_LABEL: u32 = 3489663280; +pub const TEE_ATTR_RSA_OAEP_MGF_HASH: u32 = 3489663281; +pub const TEE_ATTR_RSA_PSS_SALT_LENGTH: u32 = 4026534448; +pub const TEE_ATTR_ECC_PUBLIC_VALUE_X: u32 = 3489661249; +pub const TEE_ATTR_ECC_PUBLIC_VALUE_Y: u32 = 3489661505; +pub const TEE_ATTR_ECC_PRIVATE_VALUE: u32 = 3221226305; +pub const TEE_ATTR_ECC_CURVE: u32 = 4026532929; +pub const TEE_ATTR_SM2_ID_INITIATOR: u32 = 3489662022; +pub const TEE_ATTR_SM2_ID_RESPONDER: u32 = 3489662278; +pub const TEE_ATTR_SM2_KEP_USER: u32 = 4026533446; +pub const TEE_ATTR_SM2_KEP_CONFIRMATION_IN: u32 = 3489662790; +pub const TEE_ATTR_SM2_KEP_CONFIRMATION_OUT: u32 = 3489663046; +pub const TEE_ATTR_ECC_EPHEMERAL_PUBLIC_VALUE_X: u32 = 3489661254; +pub const TEE_ATTR_ECC_EPHEMERAL_PUBLIC_VALUE_Y: u32 = 3489661510; +pub const TEE_ATTR_EDDSA_CTX: u32 = 3489662531; +pub const TEE_ATTR_ED25519_PUBLIC_VALUE: u32 = 3489662787; +pub const TEE_ATTR_ED25519_PRIVATE_VALUE: u32 = 3221227587; +pub const TEE_ATTR_X25519_PUBLIC_VALUE: u32 = 3489663300; +pub const TEE_ATTR_X25519_PRIVATE_VALUE: u32 = 3221228100; +pub const TEE_ATTR_EDDSA_PREHASH: u32 = 4026531844; +pub const TEE_ATTR_X448_PUBLIC_VALUE: u32 = 3489663557; +pub const TEE_ATTR_X448_PRIVATE_VALUE: u32 = 3221228102; +pub const TEE_ATTR_HKDF_SALT: u32 = 3489663302; +pub const TEE_ATTR_HKDF_INFO: u32 = 3489663558; +pub const TEE_ATTR_HKDF_HASH_ALGORITHM: u32 = 4026534726; +pub const TEE_ATTR_KDF_KEY_SIZE: u32 = 4026534982; +pub const TEE_ATTR_FLAG_PUBLIC: u32 = 268435456; +pub const TEE_ATTR_FLAG_VALUE: u32 = 536870912; +pub const TEE_ATTR_BIT_PROTECTED: u32 = 268435456; +pub const TEE_ATTR_BIT_VALUE: u32 = 536870912; +pub const TEE_CRYPTO_ELEMENT_NONE: u32 = 0; +pub const TEE_ECC_CURVE_NIST_P192: u32 = 1; +pub const TEE_ECC_CURVE_NIST_P224: u32 = 2; +pub const TEE_ECC_CURVE_NIST_P256: u32 = 3; +pub const TEE_ECC_CURVE_NIST_P384: u32 = 4; +pub const TEE_ECC_CURVE_NIST_P521: u32 = 5; +pub const TEE_ECC_CURVE_25519: u32 = 768; +pub const TEE_ECC_CURVE_SM2: u32 = 1024; +pub const TEE_PANIC_ID_TA_CLOSESESSIONENTRYPOINT: u32 = 257; +pub const TEE_PANIC_ID_TA_CREATEENTRYPOINT: u32 = 258; +pub const TEE_PANIC_ID_TA_DESTROYENTRYPOINT: u32 = 259; +pub const TEE_PANIC_ID_TA_INVOKECOMMANDENTRYPOINT: u32 = 260; +pub const TEE_PANIC_ID_TA_OPENSESSIONENTRYPOINT: u32 = 261; +pub const TEE_PANIC_ID_TEE_ALLOCATEPROPERTYENUMERATOR: u32 = 513; +pub const TEE_PANIC_ID_TEE_FREEPROPERTYENUMERATOR: u32 = 514; +pub const TEE_PANIC_ID_TEE_GETNEXTPROPERTY: u32 = 515; +pub const TEE_PANIC_ID_TEE_GETPROPERTYASBINARYBLOCK: u32 = 516; +pub const TEE_PANIC_ID_TEE_GETPROPERTYASBOOL: u32 = 517; +pub const TEE_PANIC_ID_TEE_GETPROPERTYASIDENTITY: u32 = 518; +pub const TEE_PANIC_ID_TEE_GETPROPERTYASSTRING: u32 = 519; +pub const TEE_PANIC_ID_TEE_GETPROPERTYASU32: u32 = 520; +pub const TEE_PANIC_ID_TEE_GETPROPERTYASUUID: u32 = 521; +pub const TEE_PANIC_ID_TEE_GETPROPERTYNAME: u32 = 522; +pub const TEE_PANIC_ID_TEE_RESETPROPERTYENUMERATOR: u32 = 523; +pub const TEE_PANIC_ID_TEE_STARTPROPERTYENUMERATOR: u32 = 524; +pub const TEE_PANIC_ID_TEE_PANIC: u32 = 769; +pub const TEE_PANIC_ID_TEE_CLOSETASESSION: u32 = 1025; +pub const TEE_PANIC_ID_TEE_INVOKETACOMMAND: u32 = 1026; +pub const TEE_PANIC_ID_TEE_OPENTASESSION: u32 = 1027; +pub const TEE_PANIC_ID_TEE_GETCANCELLATIONFLAG: u32 = 1281; +pub const TEE_PANIC_ID_TEE_MASKCANCELLATION: u32 = 1282; +pub const TEE_PANIC_ID_TEE_UNMASKCANCELLATION: u32 = 1283; +pub const TEE_PANIC_ID_TEE_CHECKMEMORYACCESSRIGHTS: u32 = 1537; +pub const TEE_PANIC_ID_TEE_FREE: u32 = 1538; +pub const TEE_PANIC_ID_TEE_GETINSTANCEDATA: u32 = 1539; +pub const TEE_PANIC_ID_TEE_MALLOC: u32 = 1540; +pub const TEE_PANIC_ID_TEE_MEMCOMPARE: u32 = 1541; +pub const TEE_PANIC_ID_TEE_MEMFILL: u32 = 1542; +pub const TEE_PANIC_ID_TEE_MEMMOVE: u32 = 1543; +pub const TEE_PANIC_ID_TEE_REALLOC: u32 = 1544; +pub const TEE_PANIC_ID_TEE_SETINSTANCEDATA: u32 = 1545; +pub const TEE_PANIC_ID_TEE_CLOSEOBJECT: u32 = 1793; +pub const TEE_PANIC_ID_TEE_GETOBJECTBUFFERATTRIBUTE: u32 = 1794; +pub const TEE_PANIC_ID_TEE_GETOBJECTINFO: u32 = 1795; +pub const TEE_PANIC_ID_TEE_GETOBJECTVALUEATTRIBUTE: u32 = 1796; +pub const TEE_PANIC_ID_TEE_RESTRICTOBJECTUSAGE: u32 = 1797; +pub const TEE_PANIC_ID_TEE_GETOBJECTINFO1: u32 = 1798; +pub const TEE_PANIC_ID_TEE_RESTRICTOBJECTUSAGE1: u32 = 1799; +pub const TEE_PANIC_ID_TEE_ALLOCATETRANSIENTOBJECT: u32 = 2049; +pub const TEE_PANIC_ID_TEE_COPYOBJECTATTRIBUTES: u32 = 2050; +pub const TEE_PANIC_ID_TEE_FREETRANSIENTOBJECT: u32 = 2051; +pub const TEE_PANIC_ID_TEE_GENERATEKEY: u32 = 2052; +pub const TEE_PANIC_ID_TEE_INITREFATTRIBUTE: u32 = 2053; +pub const TEE_PANIC_ID_TEE_INITVALUEATTRIBUTE: u32 = 2054; +pub const TEE_PANIC_ID_TEE_POPULATETRANSIENTOBJECT: u32 = 2055; +pub const TEE_PANIC_ID_TEE_RESETTRANSIENTOBJECT: u32 = 2056; +pub const TEE_PANIC_ID_TEE_COPYOBJECTATTRIBUTES1: u32 = 2057; +pub const TEE_PANIC_ID_TEE_CLOSEANDDELETEPERSISTENTOBJECT: u32 = 2305; +pub const TEE_PANIC_ID_TEE_CREATEPERSISTENTOBJECT: u32 = 2306; +pub const TEE_PANIC_ID_TEE_OPENPERSISTENTOBJECT: u32 = 2307; +pub const TEE_PANIC_ID_TEE_RENAMEPERSISTENTOBJECT: u32 = 2308; +pub const TEE_PANIC_ID_TEE_CLOSEANDDELETEPERSISTENTOBJECT1: u32 = 2309; +pub const TEE_PANIC_ID_TEE_ALLOCATEPERSISTENTOBJECTENUMERATOR: u32 = 2561; +pub const TEE_PANIC_ID_TEE_FREEPERSISTENTOBJECTENUMERATOR: u32 = 2562; +pub const TEE_PANIC_ID_TEE_GETNEXTPERSISTENTOBJECT: u32 = 2563; +pub const TEE_PANIC_ID_TEE_RESETPERSISTENTOBJECTENUMERATOR: u32 = 2564; +pub const TEE_PANIC_ID_TEE_STARTPERSISTENTOBJECTENUMERATOR: u32 = 2565; +pub const TEE_PANIC_ID_TEE_READOBJECTDATA: u32 = 2817; +pub const TEE_PANIC_ID_TEE_SEEKOBJECTDATA: u32 = 2818; +pub const TEE_PANIC_ID_TEE_TRUNCATEOBJECTDATA: u32 = 2819; +pub const TEE_PANIC_ID_TEE_WRITEOBJECTDATA: u32 = 2820; +pub const TEE_PANIC_ID_TEE_ALLOCATEOPERATION: u32 = 3073; +pub const TEE_PANIC_ID_TEE_COPYOPERATION: u32 = 3074; +pub const TEE_PANIC_ID_TEE_FREEOPERATION: u32 = 3075; +pub const TEE_PANIC_ID_TEE_GETOPERATIONINFO: u32 = 3076; +pub const TEE_PANIC_ID_TEE_RESETOPERATION: u32 = 3077; +pub const TEE_PANIC_ID_TEE_SETOPERATIONKEY: u32 = 3078; +pub const TEE_PANIC_ID_TEE_SETOPERATIONKEY2: u32 = 3079; +pub const TEE_PANIC_ID_TEE_GETOPERATIONINFOMULTIPLE: u32 = 3080; +pub const TEE_PANIC_ID_TEE_DIGESTDOFINAL: u32 = 3329; +pub const TEE_PANIC_ID_TEE_DIGESTUPDATE: u32 = 3330; +pub const TEE_PANIC_ID_TEE_CIPHERDOFINAL: u32 = 3585; +pub const TEE_PANIC_ID_TEE_CIPHERINIT: u32 = 3586; +pub const TEE_PANIC_ID_TEE_CIPHERUPDATE: u32 = 3587; +pub const TEE_PANIC_ID_TEE_MACCOMPAREFINAL: u32 = 3841; +pub const TEE_PANIC_ID_TEE_MACCOMPUTEFINAL: u32 = 3842; +pub const TEE_PANIC_ID_TEE_MACINIT: u32 = 3843; +pub const TEE_PANIC_ID_TEE_MACUPDATE: u32 = 3844; +pub const TEE_PANIC_ID_TEE_AEDECRYPTFINAL: u32 = 4097; +pub const TEE_PANIC_ID_TEE_AEENCRYPTFINAL: u32 = 4098; +pub const TEE_PANIC_ID_TEE_AEINIT: u32 = 4099; +pub const TEE_PANIC_ID_TEE_AEUPDATE: u32 = 4100; +pub const TEE_PANIC_ID_TEE_AEUPDATEAAD: u32 = 4101; +pub const TEE_PANIC_ID_TEE_ASYMMETRICDECRYPT: u32 = 4353; +pub const TEE_PANIC_ID_TEE_ASYMMETRICENCRYPT: u32 = 4354; +pub const TEE_PANIC_ID_TEE_ASYMMETRICSIGNDIGEST: u32 = 4355; +pub const TEE_PANIC_ID_TEE_ASYMMETRICVERIFYDIGEST: u32 = 4356; +pub const TEE_PANIC_ID_TEE_DERIVEKEY: u32 = 4609; +pub const TEE_PANIC_ID_TEE_GENERATERANDOM: u32 = 4865; +pub const TEE_PANIC_ID_TEE_GETREETIME: u32 = 5121; +pub const TEE_PANIC_ID_TEE_GETSYSTEMTIME: u32 = 5122; +pub const TEE_PANIC_ID_TEE_GETTAPERSISTENTTIME: u32 = 5123; +pub const TEE_PANIC_ID_TEE_SETTAPERSISTENTTIME: u32 = 5124; +pub const TEE_PANIC_ID_TEE_WAIT: u32 = 5125; +pub const TEE_PANIC_ID_TEE_BIGINTFMMCONTEXTSIZEINU32: u32 = 5377; +pub const TEE_PANIC_ID_TEE_BIGINTFMMSIZEINU32: u32 = 5378; +pub const TEE_PANIC_ID_TEE_BIGINTINIT: u32 = 5633; +pub const TEE_PANIC_ID_TEE_BIGINTINITFMM: u32 = 5634; +pub const TEE_PANIC_ID_TEE_BIGINTINITFMMCONTEXT: u32 = 5635; +pub const TEE_PANIC_ID_TEE_BIGINTCONVERTFROMOCTETSTRING: u32 = 5889; +pub const TEE_PANIC_ID_TEE_BIGINTCONVERTFROMS32: u32 = 5890; +pub const TEE_PANIC_ID_TEE_BIGINTCONVERTTOOCTETSTRING: u32 = 5891; +pub const TEE_PANIC_ID_TEE_BIGINTCONVERTTOS32: u32 = 5892; +pub const TEE_PANIC_ID_TEE_BIGINTCMP: u32 = 6145; +pub const TEE_PANIC_ID_TEE_BIGINTCMPS32: u32 = 6146; +pub const TEE_PANIC_ID_TEE_BIGINTGETBIT: u32 = 6147; +pub const TEE_PANIC_ID_TEE_BIGINTGETBITCOUNT: u32 = 6148; +pub const TEE_PANIC_ID_TEE_BIGINTSHIFTRIGHT: u32 = 6149; +pub const TEE_PANIC_ID_TEE_BIGINTADD: u32 = 6401; +pub const TEE_PANIC_ID_TEE_BIGINTDIV: u32 = 6402; +pub const TEE_PANIC_ID_TEE_BIGINTMUL: u32 = 6403; +pub const TEE_PANIC_ID_TEE_BIGINTNEG: u32 = 6404; +pub const TEE_PANIC_ID_TEE_BIGINTSQUARE: u32 = 6405; +pub const TEE_PANIC_ID_TEE_BIGINTSUB: u32 = 6406; +pub const TEE_PANIC_ID_TEE_BIGINTADDMOD: u32 = 6657; +pub const TEE_PANIC_ID_TEE_BIGINTINVMOD: u32 = 6658; +pub const TEE_PANIC_ID_TEE_BIGINTMOD: u32 = 6659; +pub const TEE_PANIC_ID_TEE_BIGINTMULMOD: u32 = 6660; +pub const TEE_PANIC_ID_TEE_BIGINTSQUAREMOD: u32 = 6661; +pub const TEE_PANIC_ID_TEE_BIGINTSUBMOD: u32 = 6662; +pub const TEE_PANIC_ID_TEE_BIGINTCOMPUTEEXTENDEDGCD: u32 = 6913; +pub const TEE_PANIC_ID_TEE_BIGINTISPROBABLEPRIME: u32 = 6914; +pub const TEE_PANIC_ID_TEE_BIGINTRELATIVEPRIME: u32 = 6915; +pub const TEE_PANIC_ID_TEE_BIGINTCOMPUTEFMM: u32 = 7169; +pub const TEE_PANIC_ID_TEE_BIGINTCONVERTFROMFMM: u32 = 7170; +pub const TEE_PANIC_ID_TEE_BIGINTCONVERTTOFMM: u32 = 7171; +pub const TEE_NUM_PARAMS: u32 = 4; +pub const TEE_MEM_INPUT: u32 = 1; +pub const TEE_MEM_OUTPUT: u32 = 2; +pub const TEE_MEMREF_0_USED: u32 = 1; +pub const TEE_MEMREF_1_USED: u32 = 2; +pub const TEE_MEMREF_2_USED: u32 = 4; +pub const TEE_MEMREF_3_USED: u32 = 8; +pub const TEE_SE_READER_NAME_MAX: u32 = 20; +pub const TEE_ALG_RSASSA_PKCS1_PSS_MGF1_MD5: u32 = 4027652400; +pub const TEE_ALG_RSAES_PKCS1_OAEP_MGF1_MD5: u32 = 4027646512; +pub const TEE_ERROR_DEFER_DRIVER_INIT: u32 = 2147483648; +pub const TEE_ERROR_NODE_DISABLED: u32 = 2147483649; +pub const TEE_ALG_HKDF_MD5_DERIVE_KEY: u32 = 2147487936; +pub const TEE_ALG_HKDF_SHA1_DERIVE_KEY: u32 = 2147492032; +pub const TEE_ALG_HKDF_SHA224_DERIVE_KEY: u32 = 2147496128; +pub const TEE_ALG_HKDF_SHA256_DERIVE_KEY: u32 = 2147500224; +pub const TEE_ALG_HKDF_SHA384_DERIVE_KEY: u32 = 2147504320; +pub const TEE_ALG_HKDF_SHA512_DERIVE_KEY: u32 = 2147508416; +pub const TEE_TYPE_HKDF_IKM: u32 = 2701131968; +pub const TEE_ATTR_HKDF_IKM: u32 = 3221225920; +pub const TEE_ATTR_HKDF_OKM_LENGTH: u32 = 4026533056; +pub const TEE_ALG_CONCAT_KDF_SHA1_DERIVE_KEY: u32 = 2147492033; +pub const TEE_ALG_CONCAT_KDF_SHA224_DERIVE_KEY: u32 = 2147496129; +pub const TEE_ALG_CONCAT_KDF_SHA256_DERIVE_KEY: u32 = 2147500225; +pub const TEE_ALG_CONCAT_KDF_SHA384_DERIVE_KEY: u32 = 2147504321; +pub const TEE_ALG_CONCAT_KDF_SHA512_DERIVE_KEY: u32 = 2147508417; +pub const TEE_TYPE_CONCAT_KDF_Z: u32 = 2701131969; +pub const TEE_ATTR_CONCAT_KDF_Z: u32 = 3221225921; +pub const TEE_ATTR_CONCAT_KDF_OTHER_INFO: u32 = 3489661633; +pub const TEE_ATTR_CONCAT_KDF_DKM_LENGTH: u32 = 4026532801; +pub const TEE_ALG_PBKDF2_HMAC_SHA1_DERIVE_KEY: u32 = 2147492034; +pub const TEE_ALG_PBKDF2_HMAC_SHA224_DERIVE_KEY: u32 = 2147496130; +pub const TEE_ALG_PBKDF2_HMAC_SHA256_DERIVE_KEY: u32 = 2147500226; +pub const TEE_ALG_PBKDF2_HMAC_SHA384_DERIVE_KEY: u32 = 2147504322; +pub const TEE_ALG_PBKDF2_HMAC_SHA512_DERIVE_KEY: u32 = 2147508418; +pub const TEE_ALG_PBKDF2_HMAC_SM3_DERIVE_KEY: u32 = 2147512514; +pub const TEE_TYPE_PBKDF2_PASSWORD: u32 = 2701131970; +pub const TEE_ATTR_PBKDF2_PASSWORD: u32 = 3221225922; +pub const TEE_ATTR_PBKDF2_SALT: u32 = 3489661634; +pub const TEE_ATTR_PBKDF2_ITERATION_COUNT: u32 = 4026532802; +pub const TEE_ATTR_PBKDF2_DKM_LENGTH: u32 = 4026533058; +pub const TEE_ALG_RSASSA_PKCS1_V1_5: u32 = 4026533936; +pub const TEE_ALG_DES3_CMAC: u32 = 4026533395; +pub const TEE_ALG_SM4_XTS: u32 = 4026532884; +pub const TEE_STORAGE_PRIVATE_REE: u32 = 2147483648; +pub const TEE_STORAGE_PRIVATE_RPMB: u32 = 2147483904; +pub const TEE_STORAGE_PRIVATE_SQL_RESERVED: u32 = 2147484160; +pub const TEE_MEMORY_ACCESS_NONSECURE: u32 = 268435456; +pub const TEE_MEMORY_ACCESS_SECURE: u32 = 536870912; +pub const TEE_LOGIN_REE_KERNEL: u32 = 2147483648; +pub const TEE_USER_MEM_HINT_NO_FILL_ZERO: u32 = 2147483648; +pub const TEE_ISOCKET_VERSION: u32 = 16777216; +pub const TEE_ISOCKET_ERROR_PROTOCOL: u32 = 4043337729; +pub const TEE_ISOCKET_ERROR_REMOTE_CLOSED: u32 = 4043337730; +pub const TEE_ISOCKET_ERROR_TIMEOUT: u32 = 4043337731; +pub const TEE_ISOCKET_ERROR_OUT_OF_RESOURCES: u32 = 4043337732; +pub const TEE_ISOCKET_ERROR_LARGE_BUFFER: u32 = 4043337733; +pub const TEE_ISOCKET_WARNING_PROTOCOL: u32 = 4043337734; +pub const TEE_ISOCKET_ERROR_HOSTNAME: u32 = 4043337735; +pub const TEE_ISOCKET_PROTOCOLID_TCP: u32 = 101; +pub const TEE_ISOCKET_TCP_WARNING_UNKNOWN_OUT_OF_BAND: u32 = 4043374594; +pub const TEE_ISOCKET_PROTOCOLID_UDP: u32 = 102; +pub const TEE_ISOCKET_UDP_WARNING_UNKNOWN_OUT_OF_BAND: u32 = 4043440130; +pub const TEE_UDP_CHANGEADDR: u32 = 1711276033; +pub const TEE_UDP_CHANGEPORT: u32 = 1711276034; +pub const TA_FLAG_USER_MODE: u32 = 0; +pub const TA_FLAG_EXEC_DDR: u32 = 0; +pub const TA_FLAG_SINGLE_INSTANCE: u32 = 4; +pub const TA_FLAG_MULTI_SESSION: u32 = 8; +pub const TA_FLAG_INSTANCE_KEEP_ALIVE: u32 = 16; +pub const TA_FLAG_SECURE_DATA_PATH: u32 = 32; +pub const TA_FLAG_REMAP_SUPPORT: u32 = 0; +pub const TA_FLAG_CACHE_MAINTENANCE: u32 = 128; +pub const TA_FLAG_CONCURRENT: u32 = 256; +pub const TA_FLAG_DEVICE_ENUM: u32 = 512; +pub const TA_FLAG_DEVICE_ENUM_SUPP: u32 = 1024; +pub const TA_FLAG_DONT_CLOSE_HANDLE_ON_CORRUPT_OBJECT: u32 = 2048; +pub const TA_FLAG_DEVICE_ENUM_TEE_STORAGE_PRIVATE: u32 = 4096; +pub const TA_FLAG_INSTANCE_KEEP_CRASHED: u32 = 8192; +pub const TA_FLAGS_MASK: u32 = 16383; +pub const TA_PROP_STR_SINGLE_INSTANCE: &[u8; 22] = b"gpd.ta.singleInstance\0"; +pub const TA_PROP_STR_MULTI_SESSION: &[u8; 20] = b"gpd.ta.multiSession\0"; +pub const TA_PROP_STR_KEEP_ALIVE: &[u8; 25] = b"gpd.ta.instanceKeepAlive\0"; +pub const TA_PROP_STR_KEEP_CRASHED: &[u8; 29] = b"optee.ta.instanceKeepCrashed\0"; +pub const TA_PROP_STR_DATA_SIZE: &[u8; 16] = b"gpd.ta.dataSize\0"; +pub const TA_PROP_STR_STACK_SIZE: &[u8; 17] = b"gpd.ta.stackSize\0"; +pub const TA_PROP_STR_VERSION: &[u8; 15] = b"gpd.ta.version\0"; +pub const TA_PROP_STR_DESCRIPTION: &[u8; 19] = b"gpd.ta.description\0"; +pub const TA_PROP_STR_ENDIAN: &[u8; 14] = b"gpd.ta.endian\0"; +pub const TA_PROP_STR_DOES_NOT_CLOSE_HANDLE_ON_CORRUPT_OBJECT: &[u8; 41] = b"gpd.ta.doesNotCloseHandleOnCorruptObject\0"; +pub const TEE_MAIN_ALGO_MD5: u32 = 1; +pub const TEE_MAIN_ALGO_SHA1: u32 = 2; +pub const TEE_MAIN_ALGO_SHA224: u32 = 3; +pub const TEE_MAIN_ALGO_SHA256: u32 = 4; +pub const TEE_MAIN_ALGO_SHA384: u32 = 5; +pub const TEE_MAIN_ALGO_SHA512: u32 = 6; +pub const TEE_MAIN_ALGO_SM3: u32 = 7; +pub const TEE_MAIN_ALGO_SHA3_224: u32 = 8; +pub const TEE_MAIN_ALGO_SHA3_256: u32 = 9; +pub const TEE_MAIN_ALGO_SHA3_384: u32 = 10; +pub const TEE_MAIN_ALGO_SHA3_512: u32 = 11; +pub const TEE_MAIN_ALGO_AES: u32 = 16; +pub const TEE_MAIN_ALGO_DES: u32 = 17; +pub const TEE_MAIN_ALGO_DES2: u32 = 18; +pub const TEE_MAIN_ALGO_DES3: u32 = 19; +pub const TEE_MAIN_ALGO_SM4: u32 = 20; +pub const TEE_MAIN_ALGO_RSA: u32 = 48; +pub const TEE_MAIN_ALGO_DSA: u32 = 49; +pub const TEE_MAIN_ALGO_DH: u32 = 50; +pub const TEE_MAIN_ALGO_ECDSA: u32 = 65; +pub const TEE_MAIN_ALGO_ECDH: u32 = 66; +pub const TEE_MAIN_ALGO_ED25519: u32 = 67; +pub const TEE_MAIN_ALGO_SM2_DSA_SM3: u32 = 69; +pub const TEE_MAIN_ALGO_SM2_KEP: u32 = 70; +pub const TEE_MAIN_ALGO_SM2_PKE: u32 = 71; +pub const TEE_MAIN_ALGO_HKDF: u32 = 192; +pub const TEE_MAIN_ALGO_CONCAT_KDF: u32 = 193; +pub const TEE_MAIN_ALGO_PBKDF2: u32 = 194; +pub const TEE_MAIN_ALGO_X25519: u32 = 68; +pub const TEE_MAIN_ALGO_SHAKE128: u32 = 195; +pub const TEE_MAIN_ALGO_SHAKE256: u32 = 196; +pub const TEE_MAIN_ALGO_X448: u32 = 73; +pub const TEE_CHAIN_MODE_ECB_NOPAD: u32 = 0; +pub const TEE_CHAIN_MODE_CBC_NOPAD: u32 = 1; +pub const TEE_CHAIN_MODE_CTR: u32 = 2; +pub const TEE_CHAIN_MODE_CTS: u32 = 3; +pub const TEE_CHAIN_MODE_XTS: u32 = 4; +pub const TEE_CHAIN_MODE_CBC_MAC_PKCS5: u32 = 5; +pub const TEE_CHAIN_MODE_CMAC: u32 = 6; +pub const TEE_CHAIN_MODE_CCM: u32 = 7; +pub const TEE_CHAIN_MODE_GCM: u32 = 8; +pub const TEE_CHAIN_MODE_PKCS1_PSS_MGF1: u32 = 9; +pub const TEE_AES_BLOCK_SIZE: u32 = 16; +pub const TEE_DES_BLOCK_SIZE: u32 = 8; +pub const TEE_SM4_BLOCK_SIZE: u32 = 16; +pub const TEE_AES_MAX_KEY_SIZE: u32 = 32; +pub const TEE_TIME_MILLIS_BASE: u32 = 1000; +pub const TEE_TCP_SET_RECVBUF: u32 = 1710227456; +pub const TEE_TCP_SET_SENDBUF: u32 = 1710227457; +pub type intmax_t = i64; +pub type TEE_Result = u32; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TEE_UUID { + pub timeLow: u32, + pub timeMid: u16, + pub timeHiAndVersion: u16, + pub clockSeqAndNode: [u8; 8usize], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TEE_Identity { + pub login: u32, + pub uuid: TEE_UUID, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union TEE_Param { + pub memref: TEE_Param__bindgen_ty_1, + pub value: TEE_Param__bindgen_ty_2, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TEE_Param__bindgen_ty_1 { + pub buffer: *mut ::core::ffi::c_void, + pub size: usize, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TEE_Param__bindgen_ty_2 { + pub a: u32, + pub b: u32, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct __TEE_TASessionHandle { + _unused: [u8; 0], +} +pub type TEE_TASessionHandle = *mut __TEE_TASessionHandle; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct __TEE_PropSetHandle { + _unused: [u8; 0], +} +pub type TEE_PropSetHandle = *mut __TEE_PropSetHandle; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct __TEE_ObjectHandle { + _unused: [u8; 0], +} +pub type TEE_ObjectHandle = *mut __TEE_ObjectHandle; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct __TEE_ObjectEnumHandle { + _unused: [u8; 0], +} +pub type TEE_ObjectEnumHandle = *mut __TEE_ObjectEnumHandle; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct __TEE_OperationHandle { + _unused: [u8; 0], +} +pub type TEE_OperationHandle = *mut __TEE_OperationHandle; +pub type TEE_ObjectType = u32; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TEE_ObjectInfo { + pub objectType: u32, + pub objectSize: u32, + pub maxObjectSize: u32, + pub objectUsage: u32, + pub dataSize: usize, + pub dataPosition: usize, + pub handleFlags: u32, +} +pub type TEE_Whence = u32; +#[repr(C)] +#[derive(Copy, Clone)] +pub struct TEE_Attribute { + pub attributeID: u32, + pub content: TEE_Attribute__bindgen_ty_1, +} +#[repr(C)] +#[derive(Copy, Clone)] +pub union TEE_Attribute__bindgen_ty_1 { + pub ref_: TEE_Attribute__bindgen_ty_1__bindgen_ty_1, + pub value: TEE_Attribute__bindgen_ty_1__bindgen_ty_2, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TEE_Attribute__bindgen_ty_1__bindgen_ty_1 { + pub buffer: *mut ::core::ffi::c_void, + pub length: usize, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TEE_Attribute__bindgen_ty_1__bindgen_ty_2 { + pub a: u32, + pub b: u32, +} +pub type TEE_OperationMode = u32; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TEE_OperationInfo { + pub algorithm: u32, + pub operationClass: u32, + pub mode: u32, + pub digestLength: u32, + pub maxKeySize: u32, + pub keySize: u32, + pub requiredKeyUsage: u32, + pub handleState: u32, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TEE_OperationInfoKey { + pub keySize: u32, + pub requiredKeyUsage: u32, +} +#[repr(C)] +#[derive(Debug)] +pub struct TEE_OperationInfoMultiple { + pub algorithm: u32, + pub operationClass: u32, + pub mode: u32, + pub digestLength: u32, + pub maxKeySize: u32, + pub handleState: u32, + pub operationState: u32, + pub numberOfKeys: u32, + pub keyInformation: __IncompleteArrayField, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TEE_Time { + pub seconds: u32, + pub millis: u32, +} +pub type TEE_BigInt = u32; +pub type TEE_BigIntFMM = u32; +pub type TEE_BigIntFMMContext = u32; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct __TEE_SEServiceHandle { + _unused: [u8; 0], +} +pub type TEE_SEServiceHandle = *mut __TEE_SEServiceHandle; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct __TEE_SEReaderHandle { + _unused: [u8; 0], +} +pub type TEE_SEReaderHandle = *mut __TEE_SEReaderHandle; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct __TEE_SESessionHandle { + _unused: [u8; 0], +} +pub type TEE_SESessionHandle = *mut __TEE_SESessionHandle; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct __TEE_SEChannelHandle { + _unused: [u8; 0], +} +pub type TEE_SEChannelHandle = *mut __TEE_SEChannelHandle; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TEE_SEReaderProperties { + pub sePresent: bool, + pub teeOnly: bool, + pub selectResponseEnable: bool, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TEE_SEAID { + pub buffer: *mut u8, + pub bufferLen: usize, +} +pub type TEE_ErrorOrigin = u32; +pub type TEE_Session = *mut ::core::ffi::c_void; +pub type TEE_iSocketHandle = *mut ::core::ffi::c_void; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TEE_iSocket_s { + pub TEE_iSocketVersion: u32, + pub protocolID: u8, + pub open: ::core::option::Option< + unsafe extern "C" fn( + ctx: *mut TEE_iSocketHandle, + setup: *mut ::core::ffi::c_void, + protocolError: *mut u32, + ) -> TEE_Result, + >, + pub close: ::core::option::Option< + unsafe extern "C" fn(ctx: TEE_iSocketHandle) -> TEE_Result, + >, + pub send: ::core::option::Option< + unsafe extern "C" fn( + ctx: TEE_iSocketHandle, + buf: *const ::core::ffi::c_void, + length: *mut u32, + timeout: u32, + ) -> TEE_Result, + >, + pub recv: ::core::option::Option< + unsafe extern "C" fn( + ctx: TEE_iSocketHandle, + buf: *mut ::core::ffi::c_void, + length: *mut u32, + timeout: u32, + ) -> TEE_Result, + >, + pub error: ::core::option::Option< + unsafe extern "C" fn(ctx: TEE_iSocketHandle) -> u32, + >, + pub ioctl: ::core::option::Option< + unsafe extern "C" fn( + ctx: TEE_iSocketHandle, + commandCode: u32, + buf: *mut ::core::ffi::c_void, + length: *mut u32, + ) -> TEE_Result, + >, +} +pub type TEE_iSocket = TEE_iSocket_s; +#[repr(u32)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub enum TEE_ipSocket_ipVersion_e { + TEE_IP_VERSION_DC = 0, + TEE_IP_VERSION_4 = 1, + TEE_IP_VERSION_6 = 2, +} +pub use self::TEE_ipSocket_ipVersion_e as TEE_ipSocket_ipVersion; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TEE_tcpSocket_Setup_s { + pub ipVersion: TEE_ipSocket_ipVersion, + pub server_addr: *mut ::core::ffi::c_char, + pub server_port: u16, +} +pub type TEE_tcpSocket_Setup = TEE_tcpSocket_Setup_s; +unsafe extern "C" { + pub static TEE_tcpSocket: *const TEE_iSocket_s; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct TEE_udpSocket_Setup_s { + pub ipVersion: TEE_ipSocket_ipVersion, + pub server_addr: *mut ::core::ffi::c_char, + pub server_port: u16, +} +pub type TEE_udpSocket_Setup = TEE_udpSocket_Setup_s; +unsafe extern "C" { + pub static TEE_udpSocket: *const TEE_iSocket_s; +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct ta_head { + pub uuid: TEE_UUID, + pub stack_size: u32, + pub flags: u32, + pub depr_entry: u64, +} +#[repr(u32)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub enum user_ta_prop_type { + USER_TA_PROP_TYPE_BOOL = 0, + USER_TA_PROP_TYPE_U32 = 1, + USER_TA_PROP_TYPE_UUID = 2, + USER_TA_PROP_TYPE_IDENTITY = 3, + USER_TA_PROP_TYPE_STRING = 4, + USER_TA_PROP_TYPE_BINARY_BLOCK = 5, + USER_TA_PROP_TYPE_U64 = 6, + USER_TA_PROP_TYPE_INVALID = 7, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct user_ta_property { + pub name: *const ::core::ffi::c_char, + pub type_: user_ta_prop_type, + pub value: *const ::core::ffi::c_void, +} +#[repr(u32)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub enum utee_time_category { + UTEE_TIME_CAT_SYSTEM = 0, + UTEE_TIME_CAT_TA_PERSISTENT = 1, + UTEE_TIME_CAT_REE = 2, +} +#[repr(u32)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub enum utee_entry_func { + UTEE_ENTRY_FUNC_OPEN_SESSION = 0, + UTEE_ENTRY_FUNC_CLOSE_SESSION = 1, + UTEE_ENTRY_FUNC_INVOKE_COMMAND = 2, + UTEE_ENTRY_FUNC_DUMP_MEMSTATS = 3, +} +#[repr(u32)] +#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] +pub enum utee_cache_operation { + TEE_CACHECLEAN = 0, + TEE_CACHEFLUSH = 1, + TEE_CACHEINVALIDATE = 2, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct utee_params { + pub types: u64, + pub vals: [u64; 8usize], +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct utee_attribute { + pub a: u64, + pub b: u64, + pub attribute_id: u32, +} +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct utee_object_info { + pub obj_type: u32, + pub obj_size: u32, + pub max_obj_size: u32, + pub obj_usage: u32, + pub data_size: u32, + pub data_pos: u32, + pub handle_flags: u32, +} +unsafe extern "C" { + pub fn _utee_return(ret: ::core::ffi::c_ulong) -> !; +} +unsafe extern "C" { + pub fn _utee_log(buf: *const ::core::ffi::c_void, len: usize); +} + +#[allow(unused_imports)] +#[cfg_attr(feature = "mock", mockall::automock)] +pub mod api { + use super::*; +/* automatically generated by rust-bindgen 0.72.1 */ + +unsafe extern "C" { + pub fn trace_ext_puts(str_: *const ::core::ffi::c_char); +} +unsafe extern "C" { + pub fn trace_ext_get_thread_id() -> ::core::ffi::c_int; +} +unsafe extern "C" { + pub fn trace_set_level(level: ::core::ffi::c_int); +} +unsafe extern "C" { + pub fn trace_get_level() -> ::core::ffi::c_int; +} +unsafe extern "C" { + pub fn trace_printf( + func: *const ::core::ffi::c_char, + line: ::core::ffi::c_int, + level: ::core::ffi::c_int, + level_ok: bool, + fmt: *const ::core::ffi::c_char, + ... + ); +} +unsafe extern "C" { + pub fn dhex_dump( + function: *const ::core::ffi::c_char, + line: ::core::ffi::c_int, + level: ::core::ffi::c_int, + buf: *const ::core::ffi::c_void, + len: ::core::ffi::c_int, + ); +} +unsafe extern "C" { + pub fn TEE_GetPropertyAsString( + propsetOrEnumerator: TEE_PropSetHandle, + name: *const ::core::ffi::c_char, + valueBuffer: *mut ::core::ffi::c_char, + valueBufferLen: *mut usize, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_GetPropertyAsBool( + propsetOrEnumerator: TEE_PropSetHandle, + name: *const ::core::ffi::c_char, + value: *mut bool, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_GetPropertyAsU32( + propsetOrEnumerator: TEE_PropSetHandle, + name: *const ::core::ffi::c_char, + value: *mut u32, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_GetPropertyAsU64( + propsetOrEnumerator: TEE_PropSetHandle, + name: *const ::core::ffi::c_char, + value: *mut u64, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_GetPropertyAsBinaryBlock( + propsetOrEnumerator: TEE_PropSetHandle, + name: *const ::core::ffi::c_char, + valueBuffer: *mut ::core::ffi::c_void, + valueBufferLen: *mut usize, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_GetPropertyAsUUID( + propsetOrEnumerator: TEE_PropSetHandle, + name: *const ::core::ffi::c_char, + value: *mut TEE_UUID, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_GetPropertyAsIdentity( + propsetOrEnumerator: TEE_PropSetHandle, + name: *const ::core::ffi::c_char, + value: *mut TEE_Identity, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_AllocatePropertyEnumerator( + enumerator: *mut TEE_PropSetHandle, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_FreePropertyEnumerator(enumerator: TEE_PropSetHandle); +} +unsafe extern "C" { + pub fn TEE_StartPropertyEnumerator( + enumerator: TEE_PropSetHandle, + propSet: TEE_PropSetHandle, + ); +} +unsafe extern "C" { + pub fn TEE_ResetPropertyEnumerator(enumerator: TEE_PropSetHandle); +} +unsafe extern "C" { + pub fn TEE_GetPropertyName( + enumerator: TEE_PropSetHandle, + nameBuffer: *mut ::core::ffi::c_void, + nameBufferLen: *mut usize, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_GetNextProperty(enumerator: TEE_PropSetHandle) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_Panic(panicCode: TEE_Result); +} +unsafe extern "C" { + pub fn TEE_OpenTASession( + destination: *const TEE_UUID, + cancellationRequestTimeout: u32, + paramTypes: u32, + params: *mut TEE_Param, + session: *mut TEE_TASessionHandle, + returnOrigin: *mut u32, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_CloseTASession(session: TEE_TASessionHandle); +} +unsafe extern "C" { + pub fn TEE_InvokeTACommand( + session: TEE_TASessionHandle, + cancellationRequestTimeout: u32, + commandID: u32, + paramTypes: u32, + params: *mut TEE_Param, + returnOrigin: *mut u32, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_GetCancellationFlag() -> bool; +} +unsafe extern "C" { + pub fn TEE_UnmaskCancellation() -> bool; +} +unsafe extern "C" { + pub fn TEE_MaskCancellation() -> bool; +} +unsafe extern "C" { + pub fn TEE_CheckMemoryAccessRights( + accessFlags: u32, + buffer: *mut ::core::ffi::c_void, + size: usize, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_SetInstanceData(instanceData: *const ::core::ffi::c_void); +} +unsafe extern "C" { + pub fn TEE_GetInstanceData() -> *const ::core::ffi::c_void; +} +unsafe extern "C" { + pub fn TEE_Malloc(size: usize, hint: u32) -> *mut ::core::ffi::c_void; +} +unsafe extern "C" { + pub fn TEE_Realloc( + buffer: *mut ::core::ffi::c_void, + newSize: usize, + ) -> *mut ::core::ffi::c_void; +} +unsafe extern "C" { + pub fn TEE_Free(buffer: *mut ::core::ffi::c_void); +} +unsafe extern "C" { + pub fn TEE_MemMove( + dest: *mut ::core::ffi::c_void, + src: *const ::core::ffi::c_void, + size: usize, + ); +} +unsafe extern "C" { + pub fn TEE_MemCompare( + buffer1: *const ::core::ffi::c_void, + buffer2: *const ::core::ffi::c_void, + size: usize, + ) -> i32; +} +unsafe extern "C" { + pub fn TEE_MemFill(buff: *mut ::core::ffi::c_void, x: u32, size: usize); +} +unsafe extern "C" { + pub fn TEE_GetObjectInfo(object: TEE_ObjectHandle, objectInfo: *mut TEE_ObjectInfo); +} +unsafe extern "C" { + pub fn TEE_GetObjectInfo1( + object: TEE_ObjectHandle, + objectInfo: *mut TEE_ObjectInfo, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_RestrictObjectUsage(object: TEE_ObjectHandle, objectUsage: u32); +} +unsafe extern "C" { + pub fn TEE_RestrictObjectUsage1( + object: TEE_ObjectHandle, + objectUsage: u32, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_GetObjectBufferAttribute( + object: TEE_ObjectHandle, + attributeID: u32, + buffer: *mut ::core::ffi::c_void, + size: *mut usize, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_GetObjectValueAttribute( + object: TEE_ObjectHandle, + attributeID: u32, + a: *mut u32, + b: *mut u32, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_CloseObject(object: TEE_ObjectHandle); +} +unsafe extern "C" { + pub fn TEE_AllocateTransientObject( + objectType: TEE_ObjectType, + maxObjectSize: u32, + object: *mut TEE_ObjectHandle, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_FreeTransientObject(object: TEE_ObjectHandle); +} +unsafe extern "C" { + pub fn TEE_ResetTransientObject(object: TEE_ObjectHandle); +} +unsafe extern "C" { + pub fn TEE_PopulateTransientObject( + object: TEE_ObjectHandle, + attrs: *const TEE_Attribute, + attrCount: u32, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_InitRefAttribute( + attr: *mut TEE_Attribute, + attributeID: u32, + buffer: *const ::core::ffi::c_void, + length: usize, + ); +} +unsafe extern "C" { + pub fn TEE_InitValueAttribute( + attr: *mut TEE_Attribute, + attributeID: u32, + a: u32, + b: u32, + ); +} +unsafe extern "C" { + pub fn TEE_CopyObjectAttributes( + destObject: TEE_ObjectHandle, + srcObject: TEE_ObjectHandle, + ); +} +unsafe extern "C" { + pub fn TEE_CopyObjectAttributes1( + destObject: TEE_ObjectHandle, + srcObject: TEE_ObjectHandle, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_GenerateKey( + object: TEE_ObjectHandle, + keySize: u32, + params: *const TEE_Attribute, + paramCount: u32, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_OpenPersistentObject( + storageID: u32, + objectID: *const ::core::ffi::c_void, + objectIDLen: usize, + flags: u32, + object: *mut TEE_ObjectHandle, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_CreatePersistentObject( + storageID: u32, + objectID: *const ::core::ffi::c_void, + objectIDLen: usize, + flags: u32, + attributes: TEE_ObjectHandle, + initialData: *const ::core::ffi::c_void, + initialDataLen: usize, + object: *mut TEE_ObjectHandle, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_CloseAndDeletePersistentObject(object: TEE_ObjectHandle); +} +unsafe extern "C" { + pub fn TEE_CloseAndDeletePersistentObject1(object: TEE_ObjectHandle) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_RenamePersistentObject( + object: TEE_ObjectHandle, + newObjectID: *const ::core::ffi::c_void, + newObjectIDLen: usize, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_AllocatePersistentObjectEnumerator( + objectEnumerator: *mut TEE_ObjectEnumHandle, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_FreePersistentObjectEnumerator(objectEnumerator: TEE_ObjectEnumHandle); +} +unsafe extern "C" { + pub fn TEE_ResetPersistentObjectEnumerator(objectEnumerator: TEE_ObjectEnumHandle); +} +unsafe extern "C" { + pub fn TEE_StartPersistentObjectEnumerator( + objectEnumerator: TEE_ObjectEnumHandle, + storageID: u32, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_GetNextPersistentObject( + objectEnumerator: TEE_ObjectEnumHandle, + objectInfo: *mut TEE_ObjectInfo, + objectID: *mut ::core::ffi::c_void, + objectIDLen: *mut usize, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_ReadObjectData( + object: TEE_ObjectHandle, + buffer: *mut ::core::ffi::c_void, + size: usize, + count: *mut usize, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_WriteObjectData( + object: TEE_ObjectHandle, + buffer: *const ::core::ffi::c_void, + size: usize, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_TruncateObjectData(object: TEE_ObjectHandle, size: usize) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_SeekObjectData( + object: TEE_ObjectHandle, + offset: intmax_t, + whence: TEE_Whence, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_AllocateOperation( + operation: *mut TEE_OperationHandle, + algorithm: u32, + mode: u32, + maxKeySize: u32, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_FreeOperation(operation: TEE_OperationHandle); +} +unsafe extern "C" { + pub fn TEE_GetOperationInfo( + operation: TEE_OperationHandle, + operationInfo: *mut TEE_OperationInfo, + ); +} +unsafe extern "C" { + pub fn TEE_GetOperationInfoMultiple( + operation: TEE_OperationHandle, + operationInfoMultiple: *mut TEE_OperationInfoMultiple, + operationSize: *mut usize, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_ResetOperation(operation: TEE_OperationHandle); +} +unsafe extern "C" { + pub fn TEE_SetOperationKey( + operation: TEE_OperationHandle, + key: TEE_ObjectHandle, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_SetOperationKey2( + operation: TEE_OperationHandle, + key1: TEE_ObjectHandle, + key2: TEE_ObjectHandle, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_CopyOperation( + dstOperation: TEE_OperationHandle, + srcOperation: TEE_OperationHandle, + ); +} +unsafe extern "C" { + pub fn TEE_IsAlgorithmSupported(algId: u32, element: u32) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_DigestUpdate( + operation: TEE_OperationHandle, + chunk: *const ::core::ffi::c_void, + chunkSize: usize, + ); +} +unsafe extern "C" { + pub fn TEE_DigestDoFinal( + operation: TEE_OperationHandle, + chunk: *const ::core::ffi::c_void, + chunkLen: usize, + hash: *mut ::core::ffi::c_void, + hashLen: *mut usize, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_DigestExtract( + operation: TEE_OperationHandle, + hash: *mut ::core::ffi::c_void, + hashLen: *mut usize, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_CipherInit( + operation: TEE_OperationHandle, + IV: *const ::core::ffi::c_void, + IVLen: usize, + ); +} +unsafe extern "C" { + pub fn TEE_CipherUpdate( + operation: TEE_OperationHandle, + srcData: *const ::core::ffi::c_void, + srcLen: usize, + destData: *mut ::core::ffi::c_void, + destLen: *mut usize, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_CipherDoFinal( + operation: TEE_OperationHandle, + srcData: *const ::core::ffi::c_void, + srcLen: usize, + destData: *mut ::core::ffi::c_void, + destLen: *mut usize, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_MACInit( + operation: TEE_OperationHandle, + IV: *const ::core::ffi::c_void, + IVLen: usize, + ); +} +unsafe extern "C" { + pub fn TEE_MACUpdate( + operation: TEE_OperationHandle, + chunk: *const ::core::ffi::c_void, + chunkSize: usize, + ); +} +unsafe extern "C" { + pub fn TEE_MACComputeFinal( + operation: TEE_OperationHandle, + message: *const ::core::ffi::c_void, + messageLen: usize, + mac: *mut ::core::ffi::c_void, + macLen: *mut usize, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_MACCompareFinal( + operation: TEE_OperationHandle, + message: *const ::core::ffi::c_void, + messageLen: usize, + mac: *const ::core::ffi::c_void, + macLen: usize, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_AEInit( + operation: TEE_OperationHandle, + nonce: *const ::core::ffi::c_void, + nonceLen: usize, + tagLen: u32, + AADLen: usize, + payloadLen: usize, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_AEUpdateAAD( + operation: TEE_OperationHandle, + AADdata: *const ::core::ffi::c_void, + AADdataLen: usize, + ); +} +unsafe extern "C" { + pub fn TEE_AEUpdate( + operation: TEE_OperationHandle, + srcData: *const ::core::ffi::c_void, + srcLen: usize, + destData: *mut ::core::ffi::c_void, + destLen: *mut usize, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_AEEncryptFinal( + operation: TEE_OperationHandle, + srcData: *const ::core::ffi::c_void, + srcLen: usize, + destData: *mut ::core::ffi::c_void, + destLen: *mut usize, + tag: *mut ::core::ffi::c_void, + tagLen: *mut usize, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_AEDecryptFinal( + operation: TEE_OperationHandle, + srcData: *const ::core::ffi::c_void, + srcLen: usize, + destData: *mut ::core::ffi::c_void, + destLen: *mut usize, + tag: *mut ::core::ffi::c_void, + tagLen: usize, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_AsymmetricEncrypt( + operation: TEE_OperationHandle, + params: *const TEE_Attribute, + paramCount: u32, + srcData: *const ::core::ffi::c_void, + srcLen: usize, + destData: *mut ::core::ffi::c_void, + destLen: *mut usize, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_AsymmetricDecrypt( + operation: TEE_OperationHandle, + params: *const TEE_Attribute, + paramCount: u32, + srcData: *const ::core::ffi::c_void, + srcLen: usize, + destData: *mut ::core::ffi::c_void, + destLen: *mut usize, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_AsymmetricSignDigest( + operation: TEE_OperationHandle, + params: *const TEE_Attribute, + paramCount: u32, + digest: *const ::core::ffi::c_void, + digestLen: usize, + signature: *mut ::core::ffi::c_void, + signatureLen: *mut usize, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_AsymmetricVerifyDigest( + operation: TEE_OperationHandle, + params: *const TEE_Attribute, + paramCount: u32, + digest: *const ::core::ffi::c_void, + digestLen: usize, + signature: *const ::core::ffi::c_void, + signatureLen: usize, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_DeriveKey( + operation: TEE_OperationHandle, + params: *const TEE_Attribute, + paramCount: u32, + derivedKey: TEE_ObjectHandle, + ); +} +unsafe extern "C" { + pub fn TEE_GenerateRandom( + randomBuffer: *mut ::core::ffi::c_void, + randomBufferLen: usize, + ); +} +unsafe extern "C" { + pub fn TEE_GetSystemTime(time: *mut TEE_Time); +} +unsafe extern "C" { + pub fn TEE_Wait(timeout: u32) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_GetTAPersistentTime(time: *mut TEE_Time) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_SetTAPersistentTime(time: *const TEE_Time) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_GetREETime(time: *mut TEE_Time); +} +unsafe extern "C" { + pub fn TEE_BigIntFMMSizeInU32(modulusSizeInBits: usize) -> usize; +} +unsafe extern "C" { + pub fn TEE_BigIntFMMContextSizeInU32(modulusSizeInBits: usize) -> usize; +} +unsafe extern "C" { + pub fn TEE_BigIntInit(bigInt: *mut TEE_BigInt, len: usize); +} +unsafe extern "C" { + pub fn TEE_BigIntInitFMMContext( + context: *mut TEE_BigIntFMMContext, + len: usize, + modulus: *const TEE_BigInt, + ); +} +unsafe extern "C" { + pub fn TEE_BigIntInitFMMContext1( + context: *mut TEE_BigIntFMMContext, + len: usize, + modulus: *const TEE_BigInt, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_BigIntInitFMM(bigIntFMM: *mut TEE_BigIntFMM, len: usize); +} +unsafe extern "C" { + pub fn TEE_BigIntConvertFromOctetString( + dest: *mut TEE_BigInt, + buffer: *const u8, + bufferLen: usize, + sign: i32, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_BigIntConvertToOctetString( + buffer: *mut u8, + bufferLen: *mut usize, + bigInt: *const TEE_BigInt, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_BigIntConvertFromS32(dest: *mut TEE_BigInt, shortVal: i32); +} +unsafe extern "C" { + pub fn TEE_BigIntConvertToS32(dest: *mut i32, src: *const TEE_BigInt) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_BigIntCmp(op1: *const TEE_BigInt, op2: *const TEE_BigInt) -> i32; +} +unsafe extern "C" { + pub fn TEE_BigIntCmpS32(op: *const TEE_BigInt, shortVal: i32) -> i32; +} +unsafe extern "C" { + pub fn TEE_BigIntShiftRight( + dest: *mut TEE_BigInt, + op: *const TEE_BigInt, + bits: usize, + ); +} +unsafe extern "C" { + pub fn TEE_BigIntGetBit(src: *const TEE_BigInt, bitIndex: u32) -> bool; +} +unsafe extern "C" { + pub fn TEE_BigIntGetBitCount(src: *const TEE_BigInt) -> u32; +} +unsafe extern "C" { + pub fn TEE_BigIntSetBit( + op: *mut TEE_BigInt, + bitIndex: u32, + value: bool, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_BigIntAssign(dest: *mut TEE_BigInt, src: *const TEE_BigInt) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_BigIntAbs(dest: *mut TEE_BigInt, src: *const TEE_BigInt) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_BigIntAdd( + dest: *mut TEE_BigInt, + op1: *const TEE_BigInt, + op2: *const TEE_BigInt, + ); +} +unsafe extern "C" { + pub fn TEE_BigIntSub( + dest: *mut TEE_BigInt, + op1: *const TEE_BigInt, + op2: *const TEE_BigInt, + ); +} +unsafe extern "C" { + pub fn TEE_BigIntNeg(dest: *mut TEE_BigInt, op: *const TEE_BigInt); +} +unsafe extern "C" { + pub fn TEE_BigIntMul( + dest: *mut TEE_BigInt, + op1: *const TEE_BigInt, + op2: *const TEE_BigInt, + ); +} +unsafe extern "C" { + pub fn TEE_BigIntSquare(dest: *mut TEE_BigInt, op: *const TEE_BigInt); +} +unsafe extern "C" { + pub fn TEE_BigIntDiv( + dest_q: *mut TEE_BigInt, + dest_r: *mut TEE_BigInt, + op1: *const TEE_BigInt, + op2: *const TEE_BigInt, + ); +} +unsafe extern "C" { + pub fn TEE_BigIntMod( + dest: *mut TEE_BigInt, + op: *const TEE_BigInt, + n: *const TEE_BigInt, + ); +} +unsafe extern "C" { + pub fn TEE_BigIntAddMod( + dest: *mut TEE_BigInt, + op1: *const TEE_BigInt, + op2: *const TEE_BigInt, + n: *const TEE_BigInt, + ); +} +unsafe extern "C" { + pub fn TEE_BigIntSubMod( + dest: *mut TEE_BigInt, + op1: *const TEE_BigInt, + op2: *const TEE_BigInt, + n: *const TEE_BigInt, + ); +} +unsafe extern "C" { + pub fn TEE_BigIntMulMod( + dest: *mut TEE_BigInt, + op1: *const TEE_BigInt, + op2: *const TEE_BigInt, + n: *const TEE_BigInt, + ); +} +unsafe extern "C" { + pub fn TEE_BigIntSquareMod( + dest: *mut TEE_BigInt, + op: *const TEE_BigInt, + n: *const TEE_BigInt, + ); +} +unsafe extern "C" { + pub fn TEE_BigIntInvMod( + dest: *mut TEE_BigInt, + op: *const TEE_BigInt, + n: *const TEE_BigInt, + ); +} +unsafe extern "C" { + pub fn TEE_BigIntExpMod( + dest: *mut TEE_BigInt, + op1: *const TEE_BigInt, + op2: *const TEE_BigInt, + n: *const TEE_BigInt, + context: *const TEE_BigIntFMMContext, + ) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_BigIntRelativePrime( + op1: *const TEE_BigInt, + op2: *const TEE_BigInt, + ) -> bool; +} +unsafe extern "C" { + pub fn TEE_BigIntComputeExtendedGcd( + gcd: *mut TEE_BigInt, + u: *mut TEE_BigInt, + v: *mut TEE_BigInt, + op1: *const TEE_BigInt, + op2: *const TEE_BigInt, + ); +} +unsafe extern "C" { + pub fn TEE_BigIntIsProbablePrime(op: *const TEE_BigInt, confidenceLevel: u32) -> i32; +} +unsafe extern "C" { + pub fn TEE_BigIntConvertToFMM( + dest: *mut TEE_BigIntFMM, + src: *const TEE_BigInt, + n: *const TEE_BigInt, + context: *const TEE_BigIntFMMContext, + ); +} +unsafe extern "C" { + pub fn TEE_BigIntConvertFromFMM( + dest: *mut TEE_BigInt, + src: *const TEE_BigIntFMM, + n: *const TEE_BigInt, + context: *const TEE_BigIntFMMContext, + ); +} +unsafe extern "C" { + pub fn TEE_BigIntComputeFMM( + dest: *mut TEE_BigIntFMM, + op1: *const TEE_BigIntFMM, + op2: *const TEE_BigIntFMM, + n: *const TEE_BigInt, + context: *const TEE_BigIntFMMContext, + ); +} +unsafe extern "C" { + pub fn TEE_CacheClean(buf: *mut ::core::ffi::c_char, len: usize) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_CacheFlush(buf: *mut ::core::ffi::c_char, len: usize) -> TEE_Result; +} +unsafe extern "C" { + pub fn TEE_CacheInvalidate(buf: *mut ::core::ffi::c_char, len: usize) -> TEE_Result; +} +unsafe extern "C" { + pub fn tee_invoke_supp_plugin( + uuid: *const TEE_UUID, + cmd: u32, + sub_cmd: u32, + buf: *mut ::core::ffi::c_void, + len: usize, + outlen: *mut usize, + ) -> TEE_Result; +} + +} diff --git a/crates/optee-utee-sys/src/handwritten.rs b/crates/optee-utee-sys/src/handwritten.rs new file mode 100644 index 00000000..ee2830ce --- /dev/null +++ b/crates/optee-utee-sys/src/handwritten.rs @@ -0,0 +1,139 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! Declarations that bindgen cannot generate from the C headers. +//! +//! `generated` is produced by +//! `cargo run --manifest-path xtask/Cargo.toml -- generate-bindings utee` from +//! the OP-TEE TA dev kit headers listed in `HEADERS` in +//! `xtask/src/generate_bindings/utee/generate.rs`. An item belongs here only +//! when bindgen structurally cannot express it: +//! +//! * macros that take arguments (`TEE_PARAM_TYPES`, `TEE_PARAM_TYPE_GET`); +//! * macros whose value is an integer cast to a pointer (`TEE_PROPSET_*`); +//! * definitions or non-exported declarations (`__utee_entry`, `__ta_entry`). +//! +//! Everything else must stay generated. The command above only rewrites +//! `generated.rs`, so re-read the items below against the headers when bumping +//! `optee-version.txt`. + +use crate::generated::*; +use core::ffi::c_ulong; + +// `tee_api_defines.h` defines the pseudo property-set handles as pointer casts: +// +// #define TEE_PROPSET_TEE_IMPLEMENTATION (TEE_PropSetHandle)0xFFFFFFFD +// +// and `TEE_PropSetHandle` is an opaque pointer (`*mut __TEE_PropSetHandle`). +// bindgen cannot fold an integer cast to a pointer type into a Rust constant and +// emits nothing for these macros, even with `clang_macro_fallback`. They are +// therefore hand-written. +// +// These values are sentinel pointers rather than real addresses: libutee and the +// TEE core compare them by value and never dereference them, so they must match +// the C definitions exactly. `TEE_PROPSET_TEE_IMPLEMENTATION` is the only one +// callers normally pass to `TEE_GetProperty*`; the other two exist because the +// header defines them. +pub const TEE_PROPSET_TEE_IMPLEMENTATION: TEE_PropSetHandle = 0xFFFFFFFD as *mut _; +pub const TEE_PROPSET_CURRENT_CLIENT: TEE_PropSetHandle = 0xFFFFFFFE as *mut _; +pub const TEE_PROPSET_CURRENT_TA: TEE_PropSetHandle = 0xFFFFFFFF as *mut _; + +/// The four four-bit parameter types packed into one value by +/// [`TEE_PARAM_TYPES`]. +/// +/// `tee_api_defines.h` has no typedef for this: the parameter types are plain +/// `uint32_t` macros, so the alias only gives the packed value a name. +pub type TEE_ParamType = u32; + +// Function-like macros from `tee_api_defines.h`: +// +// #define TEE_PARAM_TYPES(t0,t1,t2,t3) \ +// ((t0) | ((t1) << 4) | ((t2) << 8) | ((t3) << 12)) +// #define TEE_PARAM_TYPE_GET(t, i) ((((uint32_t)t) >> ((i)*4)) & 0xF) +// +// bindgen does not expand function-like macros, so they are reimplemented as +// ordinary functions with the same arithmetic. The index is a `usize` so callers +// can pass array indices without casts. +pub fn TEE_PARAM_TYPES( + t0: TEE_ParamType, + t1: TEE_ParamType, + t2: TEE_ParamType, + t3: TEE_ParamType, +) -> TEE_ParamType { + t0 | t1 << 4 | t2 << 8 | t3 << 12 +} + +pub fn TEE_PARAM_TYPE_GET(t: TEE_ParamType, i: usize) -> TEE_ParamType { + (t >> (i * 4)) & 0xF +} + +// libutee's entry point, called by `__ta_entry` below. It is declared in the TA +// dev kit's `src/user_ta_header.c`, which is not part of the exported `include/` +// tree, so bindgen cannot see it and the declaration has to live here. +// +// Together with `__ta_entry` this is a frozen ABI: the TEE core, libutee and +// every TA on the device agree on it, so a change would be a breaking change for +// OP-TEE itself. Neither declaration is checked against the dev kit at build +// time for that reason. +unsafe extern "C" { + fn __utee_entry( + func: c_ulong, + session_id: c_ulong, + up: *mut utee_params, + cmd_id: c_ulong, + ) -> TEE_Result; +} + +/// The TA entry point, `__ta_entry`. +/// +/// This symbol cannot be generated because it is a *definition*, not a +/// declaration, and it lives in `TA_DEV_KIT_DIR/src/user_ta_header.c`, which is +/// not part of the exported `include/` tree bindgen reads. The TA must provide +/// the symbol itself: the dev kit's `mk/link.mk` links TAs with `-e__ta_entry`, +/// and `crates/optee-utee-build/src/linker.rs` re-emits that flag for Rust TAs, +/// so without this function the TA would not link. +/// +/// The body mirrors the C implementation: forward to libutee's `__utee_entry` +/// and hand the result to `_utee_return`. +/// +/// * On ARM32 the C file compiles its definition as `__ta_entry_c` and gets the +/// `__ta_entry` alias from `ta/arch/arm/ta_entry_a32.S`, purely to stop +/// unwinding. A Rust TA defines `__ta_entry` directly on both targets, which +/// is the name the linker is asked for, and needs no unwinding shim. +/// * `_utee_return` is declared `-> !`, hence this function never returns. +/// * The C version also initialises the stack canary and calls `ftrace_return()` +/// under `CFG_TA_STACK_PROTECTOR` / `CFG_FTRACE_SUPPORT`. Rust TAs are not +/// built with those C options, so the trampoline stays minimal. +/// +/// # Safety +/// This function is the main entry point for a Trusted Application (TA) in +/// OP-TEE. It must only be called by the OP-TEE OS with valid parameters. The +/// `up` parameter is a raw pointer that must point to a valid `utee_params` +/// structure initialized by the OP-TEE runtime environment. This function +/// should never be called directly from user code - it is only exported for the +/// OP-TEE OS loader. +#[unsafe(no_mangle)] +unsafe fn __ta_entry( + func: c_ulong, + session_id: c_ulong, + up: *mut utee_params, + cmd_id: c_ulong, +) -> ! { + let res: TEE_Result = unsafe { __utee_entry(func, session_id, up, cmd_id) }; + + unsafe { _utee_return(res.into()) }; +} diff --git a/crates/optee-utee-sys/src/lib.rs b/crates/optee-utee-sys/src/lib.rs index a14a4d52..4f206c6f 100644 --- a/crates/optee-utee-sys/src/lib.rs +++ b/crates/optee-utee-sys/src/lib.rs @@ -15,8 +15,12 @@ // specific language governing permissions and limitations // under the License. +//! Native bindings to the libutee library. + #![cfg_attr(not(feature = "std"), no_std)] -#![allow(non_camel_case_types, non_snake_case)] +#![allow(non_camel_case_types, non_snake_case, non_upper_case_globals)] +// bindgen's `__IncompleteArrayField` helpers are generated without safety docs. +#![allow(clippy::missing_safety_doc)] #![cfg_attr(doc, doc = concat!( env!("CARGO_PKG_DESCRIPTION"), "\n", @@ -24,43 +28,18 @@ document_features::document_features!(), ))] -pub use tee_api::api::*; -pub use tee_api_defines::*; -pub use tee_api_types::*; -pub use tee_internal_api_extensions::api::*; -pub use tee_ipsocket::*; -pub use tee_isocket::*; -pub use tee_tcpsocket::*; -pub use tee_udpsocket::*; -pub use trace::*; -pub use user_ta_header::*; -pub use utee_syscalls::*; -pub use utee_types::*; - -mod tee_api; -mod tee_api_defines; -mod tee_api_types; -mod tee_internal_api_extensions; -mod tee_ipsocket; -mod tee_isocket; -mod tee_tcpsocket; -mod tee_udpsocket; -mod trace; -mod user_ta_header; -mod utee_syscalls; -mod utee_types; - -pub type size_t = usize; -// https://github.com/OP-TEE/optee_os/blob/c2b0684fcd89929976a8726e6e3af922b48dd2c7/lib/libutils/isoc/include/stdint.h#L92 -pub type intmax_t = i64; - -#[cfg(feature = "mock")] -pub mod mock_api { - pub use crate::tee_api::mock_api::*; - pub mod extension { - pub use crate::tee_internal_api_extensions::mock_api::*; - } +// The bindings live in their own module so `handwritten` can refer to them as +// `generated::*`. `include!` keeps the file out of `cargo fmt`: bindgen formats +// the C doc comments its own way and rewriting them here would make every +// regeneration a formatting diff. +mod generated { + include!("generated.rs"); } +mod handwritten; + +pub use generated::api::*; +pub use generated::*; +pub use handwritten::*; #[cfg(feature = "mock")] pub mod mock_utils; diff --git a/crates/optee-utee-sys/src/tee_api.rs b/crates/optee-utee-sys/src/tee_api.rs deleted file mode 100644 index 73a5dbb0..00000000 --- a/crates/optee-utee-sys/src/tee_api.rs +++ /dev/null @@ -1,554 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -#[cfg_attr(feature = "mock", mockall::automock)] -pub mod api { - use crate::*; - use core::ffi::*; - - unsafe extern "C" { - // Property access functions - - pub fn TEE_GetPropertyAsString( - propsetOrEnumerator: TEE_PropSetHandle, - name: *const c_char, - valueBuffer: *mut c_char, - valueBufferLen: *mut usize, - ) -> TEE_Result; - pub fn TEE_GetPropertyAsBool( - propsetOrEnumerator: TEE_PropSetHandle, - name: *const c_char, - value: *mut bool, - ) -> TEE_Result; - pub fn TEE_GetPropertyAsU32( - propsetOrEnumerator: TEE_PropSetHandle, - name: *const c_char, - value: *mut u32, - ) -> TEE_Result; - pub fn TEE_GetPropertyAsU64( - propsetOrEnumerator: TEE_PropSetHandle, - name: *const c_char, - value: *mut u64, - ) -> TEE_Result; - pub fn TEE_GetPropertyAsBinaryBlock( - propsetOrEnumerator: TEE_PropSetHandle, - name: *const c_char, - valueBuffer: *mut c_void, - valueBufferLen: *mut usize, - ) -> TEE_Result; - pub fn TEE_GetPropertyAsUUID( - propsetOrEnumerator: TEE_PropSetHandle, - name: *const c_char, - value: *mut TEE_UUID, - ) -> TEE_Result; - pub fn TEE_GetPropertyAsIdentity( - propsetOrEnumerator: TEE_PropSetHandle, - name: *const c_char, - value: *mut TEE_Identity, - ) -> TEE_Result; - pub fn TEE_AllocatePropertyEnumerator(enumerator: *mut TEE_PropSetHandle) -> TEE_Result; - pub fn TEE_FreePropertyEnumerator(enumerator: TEE_PropSetHandle); - pub fn TEE_StartPropertyEnumerator( - enumerator: TEE_PropSetHandle, - propSet: TEE_PropSetHandle, - ); - pub fn TEE_ResetPropertyEnumerator(enumerator: TEE_PropSetHandle); - pub fn TEE_GetPropertyName( - enumerator: TEE_PropSetHandle, - nameBuffer: *mut c_void, - nameBufferLen: *mut usize, - ) -> TEE_Result; - pub fn TEE_GetNextProperty(enumerator: TEE_PropSetHandle) -> TEE_Result; - - // System API - Misc - - pub fn TEE_Panic(panicCode: TEE_Result); - - // System API - Internal Client API - - pub fn TEE_OpenTASession( - destination: *const TEE_UUID, - cancellationRequestTimeout: u32, - paramTypes: u32, - params: *mut TEE_Param, - session: *mut TEE_TASessionHandle, - returnOrigin: *mut u32, - ) -> TEE_Result; - pub fn TEE_CloseTASession(session: TEE_TASessionHandle); - pub fn TEE_InvokeTACommand( - session: TEE_TASessionHandle, - cancellationRequestTimeout: u32, - commandID: u32, - paramTypes: u32, - params: *mut TEE_Param, - returnOrigin: *mut u32, - ) -> TEE_Result; - - // System API - Cancellations - - pub fn TEE_GetCancellationFlag() -> bool; - pub fn TEE_UnmaskCancellation() -> bool; - pub fn TEE_MaskCancellation() -> bool; - - // System API - Memory Management - - pub fn TEE_CheckMemoryAccessRights( - accessFlags: u32, - buffer: *mut c_void, - size: usize, - ) -> TEE_Result; - pub fn TEE_SetInstanceData(instanceData: *const c_void); - pub fn TEE_GetInstanceData() -> *const c_void; - pub fn TEE_Malloc(size: usize, hint: u32) -> *mut c_void; - pub fn TEE_Realloc(buffer: *mut c_void, newSize: usize) -> *mut c_void; - pub fn TEE_Free(buffer: *mut c_void); - pub fn TEE_MemMove(dest: *mut c_void, src: *const c_void, size: usize); - pub fn TEE_MemCompare(buffer1: *const c_void, buffer2: *const c_void, size: usize) -> i32; - pub fn TEE_MemFill(buff: *mut c_void, x: u32, size: usize); - - // Data and Key Storage API - Generic Object Functions - - pub fn TEE_GetObjectInfo(object: TEE_ObjectHandle, objectInfo: *mut TEE_ObjectInfo); - pub fn TEE_GetObjectInfo1( - object: TEE_ObjectHandle, - objectInfo: *mut TEE_ObjectInfo, - ) -> TEE_Result; - pub fn TEE_RestrictObjectUsage(object: TEE_ObjectHandle, objectUsage: u32); - pub fn TEE_RestrictObjectUsage1(object: TEE_ObjectHandle, objectUsage: u32) -> TEE_Result; - pub fn TEE_GetObjectBufferAttribute( - object: TEE_ObjectHandle, - attributeID: u32, - buffer: *mut c_void, - size: *mut usize, - ) -> TEE_Result; - pub fn TEE_GetObjectValueAttribute( - object: TEE_ObjectHandle, - attributeID: u32, - a: *mut u32, - b: *mut u32, - ) -> TEE_Result; - pub fn TEE_CloseObject(object: TEE_ObjectHandle); - - /* Data and Key Storage API - Transient Object Functions */ - - pub fn TEE_AllocateTransientObject( - objectType: TEE_ObjectType, - maxObjectSize: u32, - object: *mut TEE_ObjectHandle, - ) -> TEE_Result; - pub fn TEE_FreeTransientObject(object: TEE_ObjectHandle); - pub fn TEE_ResetTransientObject(object: TEE_ObjectHandle); - pub fn TEE_PopulateTransientObject( - object: TEE_ObjectHandle, - attrs: *const TEE_Attribute, - attrCount: u32, - ) -> TEE_Result; - pub fn TEE_InitRefAttribute( - attr: *mut TEE_Attribute, - attributeID: u32, - buffer: *const c_void, - length: usize, - ); - pub fn TEE_InitValueAttribute(attr: *mut TEE_Attribute, attributeID: u32, a: u32, b: u32); - pub fn TEE_CopyObjectAttributes(destObject: TEE_ObjectHandle, srcObject: TEE_ObjectHandle); - pub fn TEE_CopyObjectAttributes1( - destObject: TEE_ObjectHandle, - srcObject: TEE_ObjectHandle, - ) -> TEE_Result; - pub fn TEE_GenerateKey( - object: TEE_ObjectHandle, - keySize: u32, - params: *const TEE_Attribute, - paramCount: u32, - ) -> TEE_Result; - - // Data and Key Storage API - Persistent Object Functions - - pub fn TEE_OpenPersistentObject( - storageID: u32, - objectID: *const c_void, - objectIDLen: usize, - flags: u32, - object: *mut TEE_ObjectHandle, - ) -> TEE_Result; - pub fn TEE_CreatePersistentObject( - storageID: u32, - objectID: *const c_void, - objectIDLen: usize, - flags: u32, - attributes: TEE_ObjectHandle, - initialData: *const c_void, - initialDataLen: usize, - object: *mut TEE_ObjectHandle, - ) -> TEE_Result; - pub fn TEE_CloseAndDeletePersistentObject(object: TEE_ObjectHandle); - pub fn TEE_CloseAndDeletePersistentObject1(object: TEE_ObjectHandle) -> TEE_Result; - pub fn TEE_RenamePersistentObject( - object: TEE_ObjectHandle, - newObjectID: *const c_void, - newObjectIDLen: usize, - ) -> TEE_Result; - pub fn TEE_AllocatePersistentObjectEnumerator( - objectEnumerator: *mut TEE_ObjectEnumHandle, - ) -> TEE_Result; - pub fn TEE_FreePersistentObjectEnumerator(objectEnumerator: TEE_ObjectEnumHandle); - pub fn TEE_ResetPersistentObjectEnumerator(objectEnumerator: TEE_ObjectEnumHandle); - pub fn TEE_StartPersistentObjectEnumerator( - objectEnumerator: TEE_ObjectEnumHandle, - storageID: u32, - ) -> TEE_Result; - pub fn TEE_GetNextPersistentObject( - objectEnumerator: TEE_ObjectEnumHandle, - objectInfo: *mut TEE_ObjectInfo, - objectID: *mut c_void, - objectIDLen: *mut usize, - ) -> TEE_Result; - - // Data and Key Storage API - Data Stream Access Functions - - pub fn TEE_ReadObjectData( - object: TEE_ObjectHandle, - buffer: *mut c_void, - size: usize, - count: *mut usize, - ) -> TEE_Result; - pub fn TEE_WriteObjectData( - object: TEE_ObjectHandle, - buffer: *const c_void, - size: usize, - ) -> TEE_Result; - pub fn TEE_TruncateObjectData(object: TEE_ObjectHandle, size: usize) -> TEE_Result; - pub fn TEE_SeekObjectData( - object: TEE_ObjectHandle, - offset: intmax_t, - whence: TEE_Whence, - ) -> TEE_Result; - - // Cryptographic Operations API - Generic Operation Functions - - pub fn TEE_AllocateOperation( - operation: *mut TEE_OperationHandle, - algorithm: u32, - mode: u32, - maxKeySize: u32, - ) -> TEE_Result; - pub fn TEE_FreeOperation(operation: TEE_OperationHandle); - pub fn TEE_GetOperationInfo( - operation: TEE_OperationHandle, - operationInfo: *mut TEE_OperationInfo, - ); - pub fn TEE_GetOperationInfoMultiple( - operation: TEE_OperationHandle, - operationInfoMultiple: *mut TEE_OperationInfoMultiple, - operationSize: *mut usize, - ) -> TEE_Result; - pub fn TEE_ResetOperation(operation: TEE_OperationHandle); - pub fn TEE_SetOperationKey( - operation: TEE_OperationHandle, - key: TEE_ObjectHandle, - ) -> TEE_Result; - pub fn TEE_SetOperationKey2( - operation: TEE_OperationHandle, - key1: TEE_ObjectHandle, - key2: TEE_ObjectHandle, - ) -> TEE_Result; - pub fn TEE_CopyOperation( - dstOperation: TEE_OperationHandle, - srcOperation: TEE_OperationHandle, - ); - pub fn TEE_IsAlgorithmSupported(algId: u32, element: u32) -> TEE_Result; - - // Cryptographic Operations API - Message Digest Functions - - pub fn TEE_DigestUpdate( - operation: TEE_OperationHandle, - chunk: *const c_void, - chunkSize: usize, - ); - pub fn TEE_DigestDoFinal( - operation: TEE_OperationHandle, - chunk: *const c_void, - chunkLen: usize, - hash: *mut c_void, - hashLen: *mut usize, - ) -> TEE_Result; - - // Cryptographic Operations API - Symmetric Cipher Functions - - pub fn TEE_CipherInit(operation: TEE_OperationHandle, IV: *const c_void, IVLen: usize); - pub fn TEE_CipherUpdate( - operation: TEE_OperationHandle, - srcData: *const c_void, - srcLen: usize, - destData: *mut c_void, - destLen: *mut usize, - ) -> TEE_Result; - pub fn TEE_CipherDoFinal( - operation: TEE_OperationHandle, - srcData: *const c_void, - srcLen: usize, - destData: *mut c_void, - destLen: *mut usize, - ) -> TEE_Result; - - // Cryptographic Operations API - MAC Functions - - pub fn TEE_MACInit(operation: TEE_OperationHandle, IV: *const c_void, IVLen: usize); - pub fn TEE_MACUpdate( - operation: TEE_OperationHandle, - chunk: *const c_void, - chunkSize: usize, - ); - pub fn TEE_MACComputeFinal( - operation: TEE_OperationHandle, - message: *const c_void, - messageLen: usize, - mac: *mut c_void, - macLen: *mut usize, - ) -> TEE_Result; - pub fn TEE_MACCompareFinal( - operation: TEE_OperationHandle, - message: *const c_void, - messageLen: usize, - mac: *const c_void, - macLen: usize, - ) -> TEE_Result; - - // Cryptographic Operations API - Authenticated Encryption Functions - - pub fn TEE_AEInit( - operation: TEE_OperationHandle, - nonce: *const c_void, - nonceLen: usize, - tagLen: u32, - AADLen: usize, - payloadLen: usize, - ) -> TEE_Result; - pub fn TEE_AEUpdateAAD( - operation: TEE_OperationHandle, - AADdata: *const c_void, - AADdataLen: usize, - ); - pub fn TEE_AEUpdate( - operation: TEE_OperationHandle, - srcData: *const c_void, - srcLen: usize, - destData: *mut c_void, - destLen: *mut usize, - ) -> TEE_Result; - pub fn TEE_AEEncryptFinal( - operation: TEE_OperationHandle, - srcData: *const c_void, - srcLen: usize, - destData: *mut c_void, - destLen: *mut usize, - tag: *mut c_void, - tagLen: *mut usize, - ) -> TEE_Result; - pub fn TEE_AEDecryptFinal( - operation: TEE_OperationHandle, - srcData: *const c_void, - srcLen: usize, - destData: *mut c_void, - destLen: *mut usize, - tag: *mut c_void, - tagLen: usize, - ) -> TEE_Result; - - // Cryptographic Operations API - Asymmetric Functions - - pub fn TEE_AsymmetricEncrypt( - operation: TEE_OperationHandle, - params: *const TEE_Attribute, - paramCount: u32, - srcData: *const c_void, - srcLen: usize, - destData: *mut c_void, - destLen: *mut usize, - ) -> TEE_Result; - pub fn TEE_AsymmetricDecrypt( - operation: TEE_OperationHandle, - params: *const TEE_Attribute, - paramCount: u32, - srcData: *const c_void, - srcLen: usize, - destData: *mut c_void, - destLen: *mut usize, - ) -> TEE_Result; - pub fn TEE_AsymmetricSignDigest( - operation: TEE_OperationHandle, - params: *const TEE_Attribute, - paramCount: u32, - digest: *const c_void, - digestLen: usize, - signature: *mut c_void, - signatureLen: *mut usize, - ) -> TEE_Result; - pub fn TEE_AsymmetricVerifyDigest( - operation: TEE_OperationHandle, - params: *const TEE_Attribute, - paramCount: u32, - digest: *const c_void, - digestLen: usize, - signature: *const c_void, - signatureLen: usize, - ) -> TEE_Result; - - // Cryptographic Operations API - Key Derivation Functions - - pub fn TEE_DeriveKey( - operation: TEE_OperationHandle, - params: *const TEE_Attribute, - paramCount: u32, - derivedKey: TEE_ObjectHandle, - ); - - // Cryptographic Operations API - Random Number Generation Functions - - pub fn TEE_GenerateRandom(randomBuffer: *mut c_void, randomBufferLen: usize); - - // Date & Time API - - pub fn TEE_GetSystemTime(time: *mut TEE_Time); - pub fn TEE_Wait(timeout: u32) -> TEE_Result; - pub fn TEE_GetTAPersistentTime(time: *mut TEE_Time) -> TEE_Result; - pub fn TEE_SetTAPersistentTime(time: *const TEE_Time) -> TEE_Result; - pub fn TEE_GetREETime(time: *mut TEE_Time); - - // TEE Arithmetical API - Memory allocation and size of objects - - pub fn TEE_BigIntFMMSizeInU32(modulusSizeInBits: usize) -> usize; - pub fn TEE_BigIntFMMContextSizeInU32(modulusSizeInBits: usize) -> usize; - - // TEE Arithmetical API - Initialization functions - - pub fn TEE_BigIntInit(bigInt: *mut TEE_BigInt, len: usize); - pub fn TEE_BigIntInitFMMContext( - context: *mut TEE_BigIntFMMContext, - len: usize, - modulus: *const TEE_BigInt, - ); - pub fn TEE_BigIntInitFMM(bigIntFMM: *mut TEE_BigIntFMM, len: usize); - - // TEE Arithmetical API - Converter functions - - pub fn TEE_BigIntConvertFromOctetString( - dest: *mut TEE_BigInt, - buffer: *const u8, - bufferLen: usize, - sign: i32, - ) -> TEE_Result; - pub fn TEE_BigIntConvertToOctetString( - buffer: *mut u8, - bufferLen: *mut usize, - bigInt: *const TEE_BigInt, - ) -> TEE_Result; - pub fn TEE_BigIntConvertFromS32(dest: *mut TEE_BigInt, shortVal: i32); - pub fn TEE_BigIntConvertToS32(dest: *mut i32, src: *const TEE_BigInt) -> TEE_Result; - - // TEE Arithmetical API - Logical operations - - pub fn TEE_BigIntCmp(op1: *const TEE_BigInt, op2: *const TEE_BigInt) -> i32; - pub fn TEE_BigIntCmpS32(op: *const TEE_BigInt, shortVal: i32) -> i32; - pub fn TEE_BigIntShiftRight(dest: *mut TEE_BigInt, op: *const TEE_BigInt, bits: size_t); - pub fn TEE_BigIntGetBit(src: *const TEE_BigInt, bitIndex: u32) -> bool; - pub fn TEE_BigIntGetBitCount(src: *const TEE_BigInt) -> u32; - pub fn TEE_BigIntSetBit(src: *mut TEE_BigInt, bitIndex: u32, value: bool) -> TEE_Result; - pub fn TEE_BigIntAssign(dest: *mut TEE_BigInt, src: *const TEE_BigInt) -> TEE_Result; - pub fn TEE_BigIntAbs(dest: *mut TEE_BigInt, src: *const TEE_BigInt) -> TEE_Result; - pub fn TEE_BigIntAdd(dest: *mut TEE_BigInt, op1: *const TEE_BigInt, op2: *const TEE_BigInt); - pub fn TEE_BigIntSub(dest: *mut TEE_BigInt, op1: *const TEE_BigInt, op2: *const TEE_BigInt); - pub fn TEE_BigIntNeg(dest: *mut TEE_BigInt, op: *const TEE_BigInt); - pub fn TEE_BigIntMul(dest: *mut TEE_BigInt, op1: *const TEE_BigInt, op2: *const TEE_BigInt); - pub fn TEE_BigIntSquare(dest: *mut TEE_BigInt, op: *const TEE_BigInt); - pub fn TEE_BigIntDiv( - dest_q: *mut TEE_BigInt, - dest_r: *mut TEE_BigInt, - op1: *const TEE_BigInt, - op2: *const TEE_BigInt, - ); - - // TEE Arithmetical API - Modular arithmetic operations - - pub fn TEE_BigIntMod(dest: *mut TEE_BigInt, op: *const TEE_BigInt, n: *const TEE_BigInt); - pub fn TEE_BigIntAddMod( - dest: *mut TEE_BigInt, - op1: *const TEE_BigInt, - op2: *const TEE_BigInt, - n: *const TEE_BigInt, - ); - pub fn TEE_BigIntSubMod( - dest: *mut TEE_BigInt, - op1: *const TEE_BigInt, - op2: *const TEE_BigInt, - n: *const TEE_BigInt, - ); - pub fn TEE_BigIntMulMod( - dest: *mut TEE_BigInt, - op1: *const TEE_BigInt, - op2: *const TEE_BigInt, - n: *const TEE_BigInt, - ); - pub fn TEE_BigIntSquareMod( - dest: *mut TEE_BigInt, - op: *const TEE_BigInt, - n: *const TEE_BigInt, - ); - pub fn TEE_BigIntInvMod(dest: *mut TEE_BigInt, op: *const TEE_BigInt, n: *const TEE_BigInt); - pub fn TEE_BigIntExpMod( - dest: *mut TEE_BigInt, - op1: *const TEE_BigInt, - op2: *const TEE_BigInt, - n: *const TEE_BigInt, - context: *const TEE_BigIntFMMContext, - ) -> TEE_Result; - - // TEE Arithmetical API - Other arithmetic operations - - pub fn TEE_BigIntRelativePrime(op1: *const TEE_BigInt, op2: *const TEE_BigInt) -> bool; - pub fn TEE_BigIntComputeExtendedGcd( - gcd: *mut TEE_BigInt, - u: *mut TEE_BigInt, - v: *mut TEE_BigInt, - op1: *const TEE_BigInt, - op2: *const TEE_BigInt, - ); - pub fn TEE_BigIntIsProbablePrime(op: *const TEE_BigInt, confidenceLevel: u32) -> i32; - - // TEE Arithmetical API - Fast modular multiplication operations - - pub fn TEE_BigIntConvertToFMM( - dest: *mut TEE_BigIntFMM, - src: *const TEE_BigInt, - n: *const TEE_BigInt, - context: *const TEE_BigIntFMMContext, - ); - pub fn TEE_BigIntConvertFromFMM( - dest: *mut TEE_BigInt, - src: *const TEE_BigIntFMM, - n: *const TEE_BigInt, - context: *const TEE_BigIntFMMContext, - ); - pub fn TEE_BigIntComputeFMM( - dest: *mut TEE_BigIntFMM, - op1: *const TEE_BigIntFMM, - op2: *const TEE_BigIntFMM, - n: *const TEE_BigInt, - context: *const TEE_BigIntFMMContext, - ); - } -} diff --git a/crates/optee-utee-sys/src/tee_api_defines.rs b/crates/optee-utee-sys/src/tee_api_defines.rs deleted file mode 100644 index b66a48db..00000000 --- a/crates/optee-utee-sys/src/tee_api_defines.rs +++ /dev/null @@ -1,495 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -use super::tee_api_types::*; -use core::ptr::null; - -pub const TEE_CORE_API_MAJOR_VERSION: u32 = 0x00000001; -pub const TEE_CORE_API_MINOR_VERSION: u32 = 0x00000003; -pub const TEE_CORE_API_MAINTENANCE_VERSION: u32 = 0x00000001; - -pub const TEE_HANDLE_NULL: *const u32 = null(); - -pub const TEE_TIMEOUT_INFINITE: u32 = 0xFFFFFFFF; - -// API Error Codes -pub const TEE_SUCCESS: u32 = 0x00000000; -pub const TEE_ERROR_CORRUPT_OBJECT: u32 = 0xF0100001; -pub const TEE_ERROR_CORRUPT_OBJECT_2: u32 = 0xF0100002; -pub const TEE_ERROR_STORAGE_NOT_AVAILABLE: u32 = 0xF0100003; -pub const TEE_ERROR_STORAGE_NOT_AVAILABLE_2: u32 = 0xF0100004; -pub const TEE_ERROR_UNSUPPORTED_VERSION: u32 = 0xF0100005; -pub const TEE_ERROR_CIPHERTEXT_INVALID: u32 = 0xF0100006; -pub const TEE_ERROR_GENERIC: u32 = 0xFFFF0000; -pub const TEE_ERROR_ACCESS_DENIED: u32 = 0xFFFF0001; -pub const TEE_ERROR_CANCEL: u32 = 0xFFFF0002; -pub const TEE_ERROR_ACCESS_CONFLICT: u32 = 0xFFFF0003; -pub const TEE_ERROR_EXCESS_DATA: u32 = 0xFFFF0004; -pub const TEE_ERROR_BAD_FORMAT: u32 = 0xFFFF0005; -pub const TEE_ERROR_BAD_PARAMETERS: u32 = 0xFFFF0006; -pub const TEE_ERROR_BAD_STATE: u32 = 0xFFFF0007; -pub const TEE_ERROR_ITEM_NOT_FOUND: u32 = 0xFFFF0008; -pub const TEE_ERROR_NOT_IMPLEMENTED: u32 = 0xFFFF0009; -pub const TEE_ERROR_NOT_SUPPORTED: u32 = 0xFFFF000A; -pub const TEE_ERROR_NO_DATA: u32 = 0xFFFF000B; -pub const TEE_ERROR_OUT_OF_MEMORY: u32 = 0xFFFF000C; -pub const TEE_ERROR_BUSY: u32 = 0xFFFF000D; -pub const TEE_ERROR_COMMUNICATION: u32 = 0xFFFF000E; -pub const TEE_ERROR_SECURITY: u32 = 0xFFFF000F; -pub const TEE_ERROR_SHORT_BUFFER: u32 = 0xFFFF0010; -pub const TEE_ERROR_EXTERNAL_CANCEL: u32 = 0xFFFF0011; -pub const TEE_ERROR_TIMEOUT: u32 = 0xFFFF3001; -pub const TEE_ERROR_OVERFLOW: u32 = 0xFFFF300F; -pub const TEE_ERROR_TARGET_DEAD: u32 = 0xFFFF3024; -pub const TEE_ERROR_STORAGE_NO_SPACE: u32 = 0xFFFF3041; -pub const TEE_ERROR_MAC_INVALID: u32 = 0xFFFF3071; -pub const TEE_ERROR_SIGNATURE_INVALID: u32 = 0xFFFF3072; -pub const TEE_ERROR_TIME_NOT_SET: u32 = 0xFFFF5000; -pub const TEE_ERROR_TIME_NEEDS_RESET: u32 = 0xFFFF5001; - -// Parameter Type Constants -pub const TEE_PARAM_TYPE_NONE: u32 = 0; -pub const TEE_PARAM_TYPE_VALUE_INPUT: u32 = 1; -pub const TEE_PARAM_TYPE_VALUE_OUTPUT: u32 = 2; -pub const TEE_PARAM_TYPE_VALUE_INOUT: u32 = 3; -pub const TEE_PARAM_TYPE_MEMREF_INPUT: u32 = 5; -pub const TEE_PARAM_TYPE_MEMREF_OUTPUT: u32 = 6; -pub const TEE_PARAM_TYPE_MEMREF_INOUT: u32 = 7; - -// Login Type Constants -pub const TEE_LOGIN_PUBLIC: u32 = 0x00000000; -pub const TEE_LOGIN_USER: u32 = 0x00000001; -pub const TEE_LOGIN_GROUP: u32 = 0x00000002; -pub const TEE_LOGIN_APPLICATION: u32 = 0x00000004; -pub const TEE_LOGIN_APPLICATION_USER: u32 = 0x00000005; -pub const TEE_LOGIN_APPLICATION_GROUP: u32 = 0x00000006; -pub const TEE_LOGIN_TRUSTED_APP: u32 = 0xF0000000; - -// Origin Code Constants -pub const TEE_ORIGIN_API: u32 = 0x00000001; -pub const TEE_ORIGIN_COMMS: u32 = 0x00000002; -pub const TEE_ORIGIN_TEE: u32 = 0x00000003; -pub const TEE_ORIGIN_TRUSTED_APP: u32 = 0x00000004; - -// Property Sets pseudo handles -pub const TEE_PROPSET_TEE_IMPLEMENTATION: TEE_PropSetHandle = 0xFFFFFFFD as *mut _; -pub const TEE_PROPSET_CURRENT_CLIENT: TEE_PropSetHandle = 0xFFFFFFFE as *mut _; -pub const TEE_PROPSET_CURRENT_TA: TEE_PropSetHandle = 0xFFFFFFFF as *mut _; - -// Memory Access Rights Constants -pub const TEE_MEMORY_ACCESS_READ: u32 = 0x00000001; -pub const TEE_MEMORY_ACCESS_WRITE: u32 = 0x00000002; -pub const TEE_MEMORY_ACCESS_ANY_OWNER: u32 = 0x00000004; - -// Memory Management Constants -pub const TEE_MALLOC_FILL_ZERO: u32 = 0x00000000; -pub const TEE_MALLOC_NO_FILL: u32 = 0x00000001; -pub const TEE_MALLOC_NO_SHARE: u32 = 0x00000002; - -// TEE_Whence Constants -pub const TEE_DATA_SEEK_SET: u32 = 0x00000000; -pub const TEE_DATA_SEEK_CUR: u32 = 0x00000001; -pub const TEE_DATA_SEEK_END: u32 = 0x00000002; -pub const TEE_WHENCE_ILLEGAL_VALUE: u32 = 0x7FFFFFFF; - -// TEE_OperationMode Values -pub const TEE_MODE_ENCRYPT: u32 = 0x00000000; -pub const TEE_MODE_DECRYPT: u32 = 0x00000001; -pub const TEE_MODE_SIGN: u32 = 0x00000002; -pub const TEE_MODE_VERIFY: u32 = 0x00000003; -pub const TEE_MODE_MAC: u32 = 0x00000004; -pub const TEE_MODE_DIGEST: u32 = 0x00000005; -pub const TEE_MODE_DERIVE: u32 = 0x00000006; -pub const TEE_MODE_ILLEGAL_VALUE: u32 = 0x7FFFFFFF; - -// Other constants -pub const TEE_STORAGE_PRIVATE: u32 = 0x00000001; - -pub const TEE_DATA_FLAG_ACCESS_READ: u32 = 0x00000001; -pub const TEE_DATA_FLAG_ACCESS_WRITE: u32 = 0x00000002; -pub const TEE_DATA_FLAG_ACCESS_WRITE_META: u32 = 0x00000004; -pub const TEE_DATA_FLAG_SHARE_READ: u32 = 0x00000010; -pub const TEE_DATA_FLAG_SHARE_WRITE: u32 = 0x00000020; -pub const TEE_DATA_FLAG_OVERWRITE: u32 = 0x00000400; -pub const TEE_DATA_MAX_POSITION: u32 = 0xFFFFFFFF; -pub const TEE_OBJECT_ID_MAX_LEN: u32 = 64; -pub const TEE_USAGE_EXTRACTABLE: u32 = 0x00000001; -pub const TEE_USAGE_ENCRYPT: u32 = 0x00000002; -pub const TEE_USAGE_DECRYPT: u32 = 0x00000004; -pub const TEE_USAGE_MAC: u32 = 0x00000008; -pub const TEE_USAGE_SIGN: u32 = 0x00000010; -pub const TEE_USAGE_VERIFY: u32 = 0x00000020; -pub const TEE_USAGE_DERIVE: u32 = 0x00000040; -pub const TEE_HANDLE_FLAG_PERSISTENT: u32 = 0x00010000; -pub const TEE_HANDLE_FLAG_INITIALIZED: u32 = 0x00020000; -pub const TEE_HANDLE_FLAG_KEY_SET: u32 = 0x00040000; -pub const TEE_HANDLE_FLAG_EXPECT_TWO_KEYS: u32 = 0x00080000; -pub const TEE_HANDLE_FLAG_EXTRACTING: u32 = 0x00100000; -pub const TEE_OPERATION_CIPHER: u32 = 1; -pub const TEE_OPERATION_MAC: u32 = 3; -pub const TEE_OPERATION_AE: u32 = 4; -pub const TEE_OPERATION_DIGEST: u32 = 5; -pub const TEE_OPERATION_ASYMMETRIC_CIPHER: u32 = 6; -pub const TEE_OPERATION_ASYMMETRIC_SIGNATURE: u32 = 7; -pub const TEE_OPERATION_KEY_DERIVATION: u32 = 8; -pub const TEE_OPERATION_STATE_INITIAL: u32 = 0x00000000; -pub const TEE_OPERATION_STATE_ACTIVE: u32 = 0x00000001; -pub const TEE_OPERATION_STATE_EXTRACTING: u32 = 0x00000002; - -// below constants are not updated to 1.3.1 -// Algorithm Identifiers -pub const TEE_ALG_AES_ECB_NOPAD: u32 = 0x10000010; -pub const TEE_ALG_AES_CBC_NOPAD: u32 = 0x10000110; -pub const TEE_ALG_AES_CTR: u32 = 0x10000210; -pub const TEE_ALG_AES_CTS: u32 = 0x10000310; -pub const TEE_ALG_AES_XTS: u32 = 0x10000410; -pub const TEE_ALG_AES_CBC_MAC_NOPAD: u32 = 0x30000110; -pub const TEE_ALG_AES_CBC_MAC_PKCS5: u32 = 0x30000510; -pub const TEE_ALG_AES_CMAC: u32 = 0x30000610; -pub const TEE_ALG_AES_CCM: u32 = 0x40000710; -pub const TEE_ALG_AES_GCM: u32 = 0x40000810; -pub const TEE_ALG_DES_ECB_NOPAD: u32 = 0x10000011; -pub const TEE_ALG_DES_CBC_NOPAD: u32 = 0x10000111; -pub const TEE_ALG_DES_CBC_MAC_NOPAD: u32 = 0x30000111; -pub const TEE_ALG_DES_CBC_MAC_PKCS5: u32 = 0x30000511; -pub const TEE_ALG_DES3_ECB_NOPAD: u32 = 0x10000013; -pub const TEE_ALG_DES3_CBC_NOPAD: u32 = 0x10000113; -pub const TEE_ALG_DES3_CBC_MAC_NOPAD: u32 = 0x30000113; -pub const TEE_ALG_DES3_CBC_MAC_PKCS5: u32 = 0x30000513; -pub const TEE_ALG_SM4_ECB_NOPAD: u32 = 0x10000014; -pub const TEE_ALG_SM4_CBC_NOPAD: u32 = 0x10000114; -pub const TEE_ALG_SM4_CTR: u32 = 0x10000214; -pub const TEE_ALG_RSASSA_PKCS1_V1_5_MD5: u32 = 0x70001830; -pub const TEE_ALG_RSASSA_PKCS1_V1_5_SHA1: u32 = 0x70002830; -pub const TEE_ALG_RSASSA_PKCS1_V1_5_SHA224: u32 = 0x70003830; -pub const TEE_ALG_RSASSA_PKCS1_V1_5_SHA256: u32 = 0x70004830; -pub const TEE_ALG_RSASSA_PKCS1_V1_5_SHA384: u32 = 0x70005830; -pub const TEE_ALG_RSASSA_PKCS1_V1_5_SHA512: u32 = 0x70006830; -pub const TEE_ALG_RSASSA_PKCS1_V1_5_MD5SHA1: u32 = 0x7000F830; -pub const TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA1: u32 = 0x70212930; -pub const TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA224: u32 = 0x70313930; -pub const TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA256: u32 = 0x70414930; -pub const TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA384: u32 = 0x70515930; -pub const TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA512: u32 = 0x70616930; -pub const TEE_ALG_RSAES_PKCS1_V1_5: u32 = 0x60000130; -pub const TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA1: u32 = 0x60210230; -pub const TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA224: u32 = 0x60310230; -pub const TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA256: u32 = 0x60410230; -pub const TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA384: u32 = 0x60510230; -pub const TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA512: u32 = 0x60610230; -pub const TEE_ALG_RSA_NOPAD: u32 = 0x60000030; -pub const TEE_ALG_DSA_SHA1: u32 = 0x70002131; -pub const TEE_ALG_DSA_SHA224: u32 = 0x70003131; -pub const TEE_ALG_DSA_SHA256: u32 = 0x70004131; -pub const TEE_ALG_SM2_DSA_SM3: u32 = 0x70006045; -pub const TEE_ALG_DH_DERIVE_SHARED_SECRET: u32 = 0x80000032; -// PKCS #5 v2.0 PBKDF2 (RFC 2898), OP-TEE extensions, see -// tee_api_defines_extensions.h in OP-TEE. -pub const TEE_ALG_PBKDF2_HMAC_SHA1_DERIVE_KEY: u32 = 0x800020C2; -pub const TEE_ALG_PBKDF2_HMAC_SHA224_DERIVE_KEY: u32 = 0x800030C2; -pub const TEE_ALG_PBKDF2_HMAC_SHA256_DERIVE_KEY: u32 = 0x800040C2; -pub const TEE_ALG_PBKDF2_HMAC_SHA384_DERIVE_KEY: u32 = 0x800050C2; -pub const TEE_ALG_PBKDF2_HMAC_SHA512_DERIVE_KEY: u32 = 0x800060C2; -pub const TEE_ALG_PBKDF2_HMAC_SM3_DERIVE_KEY: u32 = 0x800070C2; -pub const TEE_ALG_SM2_KEP: u32 = 0x60000045; -pub const TEE_ALG_MD5: u32 = 0x50000001; -pub const TEE_ALG_SHA1: u32 = 0x50000002; -pub const TEE_ALG_SHA224: u32 = 0x50000003; -pub const TEE_ALG_SHA256: u32 = 0x50000004; -pub const TEE_ALG_SHA384: u32 = 0x50000005; -pub const TEE_ALG_SHA512: u32 = 0x50000006; -pub const TEE_ALG_MD5SHA1: u32 = 0x5000000F; -pub const TEE_ALG_HMAC_MD5: u32 = 0x30000001; -pub const TEE_ALG_HMAC_SHA1: u32 = 0x30000002; -pub const TEE_ALG_HMAC_SHA224: u32 = 0x30000003; -pub const TEE_ALG_HMAC_SHA256: u32 = 0x30000004; -pub const TEE_ALG_HMAC_SHA384: u32 = 0x30000005; -pub const TEE_ALG_HMAC_SHA512: u32 = 0x30000006; -pub const TEE_ALG_HMAC_SM3: u32 = 0x30000007; -pub const TEE_ALG_ECDSA_P192: u32 = 0x70001041; -pub const TEE_ALG_ECDSA_P224: u32 = 0x70002041; -pub const TEE_ALG_ECDSA_P256: u32 = 0x70003041; -pub const TEE_ALG_ECDSA_P384: u32 = 0x70004041; -pub const TEE_ALG_ECDSA_P521: u32 = 0x70005041; -pub const TEE_ALG_ECDH_P192: u32 = 0x80001042; -pub const TEE_ALG_ECDH_P224: u32 = 0x80002042; -pub const TEE_ALG_ECDH_P256: u32 = 0x80003042; -pub const TEE_ALG_ECDH_P384: u32 = 0x80004042; -pub const TEE_ALG_ECDH_P521: u32 = 0x80005042; -pub const TEE_ALG_SM2_PKE: u32 = 0x80000045; -pub const TEE_ALG_SM3: u32 = 0x50000007; -pub const TEE_ALG_ILLEGAL_VALUE: u32 = 0xEFFFFFFF; - -// Object Types -pub const TEE_TYPE_AES: u32 = 0xA0000010; -pub const TEE_TYPE_DES: u32 = 0xA0000011; -pub const TEE_TYPE_DES3: u32 = 0xA0000013; -pub const TEE_TYPE_SM4: u32 = 0xA0000014; -pub const TEE_TYPE_HMAC_MD5: u32 = 0xA0000001; -pub const TEE_TYPE_HMAC_SHA1: u32 = 0xA0000002; -pub const TEE_TYPE_HMAC_SHA224: u32 = 0xA0000003; -pub const TEE_TYPE_HMAC_SHA256: u32 = 0xA0000004; -pub const TEE_TYPE_HMAC_SHA384: u32 = 0xA0000005; -pub const TEE_TYPE_HMAC_SHA512: u32 = 0xA0000006; -pub const TEE_TYPE_HMAC_SM3: u32 = 0xA0000007; -pub const TEE_TYPE_RSA_PUBLIC_KEY: u32 = 0xA0000030; -pub const TEE_TYPE_RSA_KEYPAIR: u32 = 0xA1000030; -pub const TEE_TYPE_DSA_PUBLIC_KEY: u32 = 0xA0000031; -pub const TEE_TYPE_DSA_KEYPAIR: u32 = 0xA1000031; -pub const TEE_TYPE_DH_KEYPAIR: u32 = 0xA1000032; -pub const TEE_TYPE_ECDSA_PUBLIC_KEY: u32 = 0xA0000041; -pub const TEE_TYPE_ECDSA_KEYPAIR: u32 = 0xA1000041; -pub const TEE_TYPE_ECDH_PUBLIC_KEY: u32 = 0xA0000042; -pub const TEE_TYPE_ECDH_KEYPAIR: u32 = 0xA1000042; -pub const TEE_TYPE_SM2_DSA_PUBLIC_KEY: u32 = 0xA0000045; -pub const TEE_TYPE_SM2_DSA_KEYPAIR: u32 = 0xA1000045; -pub const TEE_TYPE_SM2_KEP_PUBLIC_KEY: u32 = 0xA0000046; -pub const TEE_TYPE_SM2_KEP_KEYPAIR: u32 = 0xA1000046; -pub const TEE_TYPE_SM2_PKE_PUBLIC_KEY: u32 = 0xA0000047; -pub const TEE_TYPE_SM2_PKE_KEYPAIR: u32 = 0xA1000047; -pub const TEE_TYPE_GENERIC_SECRET: u32 = 0xA0000000; -pub const TEE_TYPE_CORRUPTED_OBJECT: u32 = 0xA00000BE; -pub const TEE_TYPE_DATA: u32 = 0xA00000BF; -// OP-TEE extension, see tee_api_defines_extensions.h in OP-TEE. -pub const TEE_TYPE_PBKDF2_PASSWORD: u32 = 0xA10000C2; - -// List of Object or Operation Attributes -pub const TEE_ATTR_SECRET_VALUE: u32 = 0xC0000000; -pub const TEE_ATTR_RSA_MODULUS: u32 = 0xD0000130; -pub const TEE_ATTR_RSA_PUBLIC_EXPONENT: u32 = 0xD0000230; -pub const TEE_ATTR_RSA_PRIVATE_EXPONENT: u32 = 0xC0000330; -pub const TEE_ATTR_RSA_PRIME1: u32 = 0xC0000430; -pub const TEE_ATTR_RSA_PRIME2: u32 = 0xC0000530; -pub const TEE_ATTR_RSA_EXPONENT1: u32 = 0xC0000630; -pub const TEE_ATTR_RSA_EXPONENT2: u32 = 0xC0000730; -pub const TEE_ATTR_RSA_COEFFICIENT: u32 = 0xC0000830; -pub const TEE_ATTR_DSA_PRIME: u32 = 0xD0001031; -pub const TEE_ATTR_DSA_SUBPRIME: u32 = 0xD0001131; -pub const TEE_ATTR_DSA_BASE: u32 = 0xD0001231; -pub const TEE_ATTR_DSA_PUBLIC_VALUE: u32 = 0xD0000131; -pub const TEE_ATTR_DSA_PRIVATE_VALUE: u32 = 0xC0000231; -pub const TEE_ATTR_DH_PRIME: u32 = 0xD0001032; -pub const TEE_ATTR_DH_SUBPRIME: u32 = 0xD0001132; -pub const TEE_ATTR_DH_BASE: u32 = 0xD0001232; -pub const TEE_ATTR_DH_X_BITS: u32 = 0xF0001332; -pub const TEE_ATTR_DH_PUBLIC_VALUE: u32 = 0xD0000132; -pub const TEE_ATTR_DH_PRIVATE_VALUE: u32 = 0xC0000232; -pub const TEE_ATTR_RSA_OAEP_LABEL: u32 = 0xD0000930; -pub const TEE_ATTR_RSA_PSS_SALT_LENGTH: u32 = 0xF0000A30; -pub const TEE_ATTR_ECC_PUBLIC_VALUE_X: u32 = 0xD0000141; -pub const TEE_ATTR_ECC_PUBLIC_VALUE_Y: u32 = 0xD0000241; -pub const TEE_ATTR_ECC_PRIVATE_VALUE: u32 = 0xC0000341; -pub const TEE_ATTR_ECC_CURVE: u32 = 0xF0000441; -pub const TEE_ATTR_SM2_ID_INITIATOR: u32 = 0xD0000446; -pub const TEE_ATTR_SM2_ID_RESPONDER: u32 = 0xD0000546; -pub const TEE_ATTR_SM2_KEP_USER: u32 = 0xF0000646; -pub const TEE_ATTR_SM2_KEP_CONFIRMATION_IN: u32 = 0xD0000746; -pub const TEE_ATTR_SM2_KEP_CONFIRMATION_OUT: u32 = 0xD0000846; -pub const TEE_ATTR_ECC_EPHEMERAL_PUBLIC_VALUE_X: u32 = 0xD0000946; -pub const TEE_ATTR_ECC_EPHEMERAL_PUBLIC_VALUE_Y: u32 = 0xD0000A46; -// PKCS #5 v2.0 PBKDF2 (RFC 2898), OP-TEE extensions, see -// tee_api_defines_extensions.h in OP-TEE. -pub const TEE_ATTR_PBKDF2_PASSWORD: u32 = 0xC00001C2; -pub const TEE_ATTR_PBKDF2_SALT: u32 = 0xD00002C2; -pub const TEE_ATTR_PBKDF2_ITERATION_COUNT: u32 = 0xF00003C2; -pub const TEE_ATTR_PBKDF2_DKM_LENGTH: u32 = 0xF00004C2; -pub const TEE_ATTR_FLAG_PUBLIC: u32 = 1 << 28; -pub const TEE_ATTR_FLAG_VALUE: u32 = 1 << 29; -// Deprecated, but kept for backwards compatibility -pub const TEE_ATTR_BIT_PROTECTED: u32 = 1 << 28; -pub const TEE_ATTR_BIT_VALUE: u32 = 1 << 29; - -// List of Supported ECC Curves -pub const TEE_CRYPTO_ELEMENT_NONE: u32 = 0x00000000; -pub const TEE_ECC_CURVE_NIST_P192: u32 = 0x00000001; -pub const TEE_ECC_CURVE_NIST_P224: u32 = 0x00000002; -pub const TEE_ECC_CURVE_NIST_P256: u32 = 0x00000003; -pub const TEE_ECC_CURVE_NIST_P384: u32 = 0x00000004; -pub const TEE_ECC_CURVE_NIST_P521: u32 = 0x00000005; -pub const TEE_ECC_CURVE_SM2: u32 = 0x00000300; - -// Panicked Functions Identification -// TA Interface -pub const TEE_PANIC_ID_TA_CLOSESESSIONENTRYPOINT: u32 = 0x00000101; -pub const TEE_PANIC_ID_TA_CREATEENTRYPOINT: u32 = 0x00000102; -pub const TEE_PANIC_ID_TA_DESTROYENTRYPOINT: u32 = 0x00000103; -pub const TEE_PANIC_ID_TA_INVOKECOMMANDENTRYPOINT: u32 = 0x00000104; -pub const TEE_PANIC_ID_TA_OPENSESSIONENTRYPOINT: u32 = 0x00000105; -/* Property Access */ -pub const TEE_PANIC_ID_TEE_ALLOCATEPROPERTYENUMERATOR: u32 = 0x00000201; -pub const TEE_PANIC_ID_TEE_FREEPROPERTYENUMERATOR: u32 = 0x00000202; -pub const TEE_PANIC_ID_TEE_GETNEXTPROPERTY: u32 = 0x00000203; -pub const TEE_PANIC_ID_TEE_GETPROPERTYASBINARYBLOCK: u32 = 0x00000204; -pub const TEE_PANIC_ID_TEE_GETPROPERTYASBOOL: u32 = 0x00000205; -pub const TEE_PANIC_ID_TEE_GETPROPERTYASIDENTITY: u32 = 0x00000206; -pub const TEE_PANIC_ID_TEE_GETPROPERTYASSTRING: u32 = 0x00000207; -pub const TEE_PANIC_ID_TEE_GETPROPERTYASU32: u32 = 0x00000208; -pub const TEE_PANIC_ID_TEE_GETPROPERTYASUUID: u32 = 0x00000209; -pub const TEE_PANIC_ID_TEE_GETPROPERTYNAME: u32 = 0x0000020A; -pub const TEE_PANIC_ID_TEE_RESETPROPERTYENUMERATOR: u32 = 0x0000020B; -pub const TEE_PANIC_ID_TEE_STARTPROPERTYENUMERATOR: u32 = 0x0000020C; -// Panic Function -pub const TEE_PANIC_ID_TEE_PANIC: u32 = 0x00000301; -// Internal Client API -pub const TEE_PANIC_ID_TEE_CLOSETASESSION: u32 = 0x00000401; -pub const TEE_PANIC_ID_TEE_INVOKETACOMMAND: u32 = 0x00000402; -pub const TEE_PANIC_ID_TEE_OPENTASESSION: u32 = 0x00000403; -// Cancellation -pub const TEE_PANIC_ID_TEE_GETCANCELLATIONFLAG: u32 = 0x00000501; -pub const TEE_PANIC_ID_TEE_MASKCANCELLATION: u32 = 0x00000502; -pub const TEE_PANIC_ID_TEE_UNMASKCANCELLATION: u32 = 0x00000503; -// Memory Management -pub const TEE_PANIC_ID_TEE_CHECKMEMORYACCESSRIGHTS: u32 = 0x00000601; -pub const TEE_PANIC_ID_TEE_FREE: u32 = 0x00000602; -pub const TEE_PANIC_ID_TEE_GETINSTANCEDATA: u32 = 0x00000603; -pub const TEE_PANIC_ID_TEE_MALLOC: u32 = 0x00000604; -pub const TEE_PANIC_ID_TEE_MEMCOMPARE: u32 = 0x00000605; -pub const TEE_PANIC_ID_TEE_MEMFILL: u32 = 0x00000606; -pub const TEE_PANIC_ID_TEE_MEMMOVE: u32 = 0x00000607; -pub const TEE_PANIC_ID_TEE_REALLOC: u32 = 0x00000608; -pub const TEE_PANIC_ID_TEE_SETINSTANCEDATA: u32 = 0x00000609; -// Generic Object -pub const TEE_PANIC_ID_TEE_CLOSEOBJECT: u32 = 0x00000701; -pub const TEE_PANIC_ID_TEE_GETOBJECTBUFFERATTRIBUTE: u32 = 0x00000702; -// deprecated -pub const TEE_PANIC_ID_TEE_GETOBJECTINFO: u32 = 0x00000703; -pub const TEE_PANIC_ID_TEE_GETOBJECTVALUEATTRIBUTE: u32 = 0x00000704; -// deprecated -pub const TEE_PANIC_ID_TEE_RESTRICTOBJECTUSAGE: u32 = 0x00000705; -pub const TEE_PANIC_ID_TEE_GETOBJECTINFO1: u32 = 0x00000706; -pub const TEE_PANIC_ID_TEE_RESTRICTOBJECTUSAGE1: u32 = 0x00000707; -// Transient Object -pub const TEE_PANIC_ID_TEE_ALLOCATETRANSIENTOBJECT: u32 = 0x00000801; -// deprecated -pub const TEE_PANIC_ID_TEE_COPYOBJECTATTRIBUTES: u32 = 0x00000802; -pub const TEE_PANIC_ID_TEE_FREETRANSIENTOBJECT: u32 = 0x00000803; -pub const TEE_PANIC_ID_TEE_GENERATEKEY: u32 = 0x00000804; -pub const TEE_PANIC_ID_TEE_INITREFATTRIBUTE: u32 = 0x00000805; -pub const TEE_PANIC_ID_TEE_INITVALUEATTRIBUTE: u32 = 0x00000806; -pub const TEE_PANIC_ID_TEE_POPULATETRANSIENTOBJECT: u32 = 0x00000807; -pub const TEE_PANIC_ID_TEE_RESETTRANSIENTOBJECT: u32 = 0x00000808; -pub const TEE_PANIC_ID_TEE_COPYOBJECTATTRIBUTES1: u32 = 0x00000809; -// Persistent Object -// deprecated -pub const TEE_PANIC_ID_TEE_CLOSEANDDELETEPERSISTENTOBJECT: u32 = 0x00000901; -pub const TEE_PANIC_ID_TEE_CREATEPERSISTENTOBJECT: u32 = 0x00000902; -pub const TEE_PANIC_ID_TEE_OPENPERSISTENTOBJECT: u32 = 0x00000903; -pub const TEE_PANIC_ID_TEE_RENAMEPERSISTENTOBJECT: u32 = 0x00000904; -pub const TEE_PANIC_ID_TEE_CLOSEANDDELETEPERSISTENTOBJECT1: u32 = 0x00000905; -// Persistent Object Enumeration -pub const TEE_PANIC_ID_TEE_ALLOCATEPERSISTENTOBJECTENUMERATOR: u32 = 0x00000A01; -pub const TEE_PANIC_ID_TEE_FREEPERSISTENTOBJECTENUMERATOR: u32 = 0x00000A02; -pub const TEE_PANIC_ID_TEE_GETNEXTPERSISTENTOBJECT: u32 = 0x00000A03; -pub const TEE_PANIC_ID_TEE_RESETPERSISTENTOBJECTENUMERATOR: u32 = 0x00000A04; -pub const TEE_PANIC_ID_TEE_STARTPERSISTENTOBJECTENUMERATOR: u32 = 0x00000A05; -// Data Stream Access -pub const TEE_PANIC_ID_TEE_READOBJECTDATA: u32 = 0x00000B01; -pub const TEE_PANIC_ID_TEE_SEEKOBJECTDATA: u32 = 0x00000B02; -pub const TEE_PANIC_ID_TEE_TRUNCATEOBJECTDATA: u32 = 0x00000B03; -pub const TEE_PANIC_ID_TEE_WRITEOBJECTDATA: u32 = 0x00000B04; -// Generic Operation -pub const TEE_PANIC_ID_TEE_ALLOCATEOPERATION: u32 = 0x00000C01; -pub const TEE_PANIC_ID_TEE_COPYOPERATION: u32 = 0x00000C02; -pub const TEE_PANIC_ID_TEE_FREEOPERATION: u32 = 0x00000C03; -pub const TEE_PANIC_ID_TEE_GETOPERATIONINFO: u32 = 0x00000C04; -pub const TEE_PANIC_ID_TEE_RESETOPERATION: u32 = 0x00000C05; -pub const TEE_PANIC_ID_TEE_SETOPERATIONKEY: u32 = 0x00000C06; -pub const TEE_PANIC_ID_TEE_SETOPERATIONKEY2: u32 = 0x00000C07; -pub const TEE_PANIC_ID_TEE_GETOPERATIONINFOMULTIPLE: u32 = 0x00000C08; -// Message Digest -pub const TEE_PANIC_ID_TEE_DIGESTDOFINAL: u32 = 0x00000D01; -pub const TEE_PANIC_ID_TEE_DIGESTUPDATE: u32 = 0x00000D02; -// Symmetric Cipher -pub const TEE_PANIC_ID_TEE_CIPHERDOFINAL: u32 = 0x00000E01; -pub const TEE_PANIC_ID_TEE_CIPHERINIT: u32 = 0x00000E02; -pub const TEE_PANIC_ID_TEE_CIPHERUPDATE: u32 = 0x00000E03; -// MAC -pub const TEE_PANIC_ID_TEE_MACCOMPAREFINAL: u32 = 0x00000F01; -pub const TEE_PANIC_ID_TEE_MACCOMPUTEFINAL: u32 = 0x00000F02; -pub const TEE_PANIC_ID_TEE_MACINIT: u32 = 0x00000F03; -pub const TEE_PANIC_ID_TEE_MACUPDATE: u32 = 0x00000F04; -// Authenticated Encryption -pub const TEE_PANIC_ID_TEE_AEDECRYPTFINAL: u32 = 0x00001001; -pub const TEE_PANIC_ID_TEE_AEENCRYPTFINAL: u32 = 0x00001002; -pub const TEE_PANIC_ID_TEE_AEINIT: u32 = 0x00001003; -pub const TEE_PANIC_ID_TEE_AEUPDATE: u32 = 0x00001004; -pub const TEE_PANIC_ID_TEE_AEUPDATEAAD: u32 = 0x00001005; -// Asymmetric -pub const TEE_PANIC_ID_TEE_ASYMMETRICDECRYPT: u32 = 0x00001101; -pub const TEE_PANIC_ID_TEE_ASYMMETRICENCRYPT: u32 = 0x00001102; -pub const TEE_PANIC_ID_TEE_ASYMMETRICSIGNDIGEST: u32 = 0x00001103; -pub const TEE_PANIC_ID_TEE_ASYMMETRICVERIFYDIGEST: u32 = 0x00001104; -// Key Derivation -pub const TEE_PANIC_ID_TEE_DERIVEKEY: u32 = 0x00001201; -// Random Data Generation -pub const TEE_PANIC_ID_TEE_GENERATERANDOM: u32 = 0x00001301; -// Time -pub const TEE_PANIC_ID_TEE_GETREETIME: u32 = 0x00001401; -pub const TEE_PANIC_ID_TEE_GETSYSTEMTIME: u32 = 0x00001402; -pub const TEE_PANIC_ID_TEE_GETTAPERSISTENTTIME: u32 = 0x00001403; -pub const TEE_PANIC_ID_TEE_SETTAPERSISTENTTIME: u32 = 0x00001404; -pub const TEE_PANIC_ID_TEE_WAIT: u32 = 0x00001405; -// Memory Allocation and Size of Objects -pub const TEE_PANIC_ID_TEE_BIGINTFMMCONTEXTSIZEINU32: u32 = 0x00001501; -pub const TEE_PANIC_ID_TEE_BIGINTFMMSIZEINU32: u32 = 0x00001502; -// Initialization -pub const TEE_PANIC_ID_TEE_BIGINTINIT: u32 = 0x00001601; -pub const TEE_PANIC_ID_TEE_BIGINTINITFMM: u32 = 0x00001602; -pub const TEE_PANIC_ID_TEE_BIGINTINITFMMCONTEXT: u32 = 0x00001603; -// Converter -pub const TEE_PANIC_ID_TEE_BIGINTCONVERTFROMOCTETSTRING: u32 = 0x00001701; -pub const TEE_PANIC_ID_TEE_BIGINTCONVERTFROMS32: u32 = 0x00001702; -pub const TEE_PANIC_ID_TEE_BIGINTCONVERTTOOCTETSTRING: u32 = 0x00001703; -pub const TEE_PANIC_ID_TEE_BIGINTCONVERTTOS32: u32 = 0x00001704; -// Logical Operation -pub const TEE_PANIC_ID_TEE_BIGINTCMP: u32 = 0x00001801; -pub const TEE_PANIC_ID_TEE_BIGINTCMPS32: u32 = 0x00001802; -pub const TEE_PANIC_ID_TEE_BIGINTGETBIT: u32 = 0x00001803; -pub const TEE_PANIC_ID_TEE_BIGINTGETBITCOUNT: u32 = 0x00001804; -pub const TEE_PANIC_ID_TEE_BIGINTSHIFTRIGHT: u32 = 0x00001805; -// Basic Arithmetic -pub const TEE_PANIC_ID_TEE_BIGINTADD: u32 = 0x00001901; -pub const TEE_PANIC_ID_TEE_BIGINTDIV: u32 = 0x00001902; -pub const TEE_PANIC_ID_TEE_BIGINTMUL: u32 = 0x00001903; -pub const TEE_PANIC_ID_TEE_BIGINTNEG: u32 = 0x00001904; -pub const TEE_PANIC_ID_TEE_BIGINTSQUARE: u32 = 0x00001905; -pub const TEE_PANIC_ID_TEE_BIGINTSUB: u32 = 0x00001906; -// Modular Arithmetic -pub const TEE_PANIC_ID_TEE_BIGINTADDMOD: u32 = 0x00001A01; -pub const TEE_PANIC_ID_TEE_BIGINTINVMOD: u32 = 0x00001A02; -pub const TEE_PANIC_ID_TEE_BIGINTMOD: u32 = 0x00001A03; -pub const TEE_PANIC_ID_TEE_BIGINTMULMOD: u32 = 0x00001A04; -pub const TEE_PANIC_ID_TEE_BIGINTSQUAREMOD: u32 = 0x00001A05; -pub const TEE_PANIC_ID_TEE_BIGINTSUBMOD: u32 = 0x00001A06; -// Other Arithmetic -pub const TEE_PANIC_ID_TEE_BIGINTCOMPUTEEXTENDEDGCD: u32 = 0x00001B01; -pub const TEE_PANIC_ID_TEE_BIGINTISPROBABLEPRIME: u32 = 0x00001B02; -pub const TEE_PANIC_ID_TEE_BIGINTRELATIVEPRIME: u32 = 0x00001B03; -// Fast Modular Multiplication -pub const TEE_PANIC_ID_TEE_BIGINTCOMPUTEFMM: u32 = 0x00001C01; -pub const TEE_PANIC_ID_TEE_BIGINTCONVERTFROMFMM: u32 = 0x00001C02; -pub const TEE_PANIC_ID_TEE_BIGINTCONVERTTOFMM: u32 = 0x00001C03; - -pub fn TEE_PARAM_TYPES(t0: u32, t1: u32, t2: u32, t3: u32) -> u32 { - t0 | t1 << 4 | t2 << 8 | t3 << 12 -} - -pub fn TEE_PARAM_TYPE_GET(t: u32, i: usize) -> u32 { - (t >> (i * 4)) & 0xF -} - -pub const TEE_NUM_PARAMS: u32 = 4; diff --git a/crates/optee-utee-sys/src/tee_api_types.rs b/crates/optee-utee-sys/src/tee_api_types.rs deleted file mode 100644 index c527eefa..00000000 --- a/crates/optee-utee-sys/src/tee_api_types.rs +++ /dev/null @@ -1,260 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -// Common Definitions - -use crate::size_t; -use core::ffi::*; - -#[allow(non_camel_case_types)] -pub type TEE_Result = u32; - -#[repr(C)] -#[derive(Copy, Clone)] -pub struct TEE_UUID { - pub timeLow: u32, - pub timeMid: u16, - pub timeHiAndVersion: u16, - pub clockSeqAndNode: [u8; 8], -} - -#[derive(Copy, Clone)] -#[repr(C)] -pub struct TEE_Identity { - pub login: u32, - pub uuid: TEE_UUID, -} - -#[derive(Copy, Clone)] -#[repr(C)] -pub struct Memref { - pub buffer: *mut c_void, - pub size: usize, -} - -#[derive(Copy, Clone)] -#[repr(C)] -pub struct Value { - pub a: u32, - pub b: u32, -} - -#[derive(Copy, Clone)] -#[repr(C)] -pub union TEE_Param { - pub memref: Memref, - pub value: Value, -} - -#[repr(C)] -pub struct __TEE_TASessionHandle { - _unused: [u8; 0], -} -#[allow(non_camel_case_types)] -pub type TEE_TASessionHandle = *mut __TEE_TASessionHandle; - -#[repr(C)] -pub struct __TEE_PropSetHandle { - _unused: [u8; 0], -} -#[allow(non_camel_case_types)] -pub type TEE_PropSetHandle = *mut __TEE_PropSetHandle; - -#[repr(C)] -pub struct __TEE_ObjectHandle { - _unused: [u8; 0], -} -#[allow(non_camel_case_types)] -pub type TEE_ObjectHandle = *mut __TEE_ObjectHandle; - -#[repr(C)] -pub struct __TEE_ObjectEnumHandle { - _unused: [u8; 0], -} -#[allow(non_camel_case_types)] -pub type TEE_ObjectEnumHandle = *mut __TEE_ObjectEnumHandle; - -#[repr(C)] -pub struct __TEE_OperationHandle { - _unused: [u8; 0], -} -#[allow(non_camel_case_types)] -pub type TEE_OperationHandle = *mut __TEE_OperationHandle; - -// Storage Definitions - -#[allow(non_camel_case_types)] -pub type TEE_ObjectType = u32; - -#[repr(C)] -pub struct TEE_ObjectInfo { - pub objectType: u32, - pub objectSize: u32, - pub maxObjectSize: u32, - pub objectUsage: u32, - pub dataSize: usize, - pub dataPosition: usize, - pub handleFlags: u32, -} - -// Reserve the GP 1.1.1 type -#[repr(C)] -pub enum TEE_Whence { - TEE_DATA_SEEK_SET, - TEE_DATA_SEEK_CUR, - TEE_DATA_SEEK_END, -} - -#[derive(Copy, Clone)] -#[repr(C)] -pub union content { - pub memref: Memref, - pub value: Value, -} - -#[derive(Copy, Clone)] -#[repr(C)] -pub struct TEE_Attribute { - pub attributeID: u32, - pub content: content, -} - -// Cryptographic Operations API - -// Reserve the GP 1.1.1 type -#[repr(C)] -pub enum TEE_OperationMode { - TEE_MODE_ENCRYPT, - TEE_MODE_DECRYPT, - TEE_MODE_SIGN, - TEE_MODE_VERIFY, - TEE_MODE_MAC, - TEE_MODE_DIGEST, - TEE_MODE_DERIVE, -} - -#[repr(C)] -pub struct TEE_OperationInfo { - pub algorithm: u32, - pub operationClass: u32, - pub mode: u32, - pub digestLength: u32, - pub maxKeySize: u32, - pub keySize: u32, - pub requiredKeyUsage: u32, - pub handleState: u32, -} - -#[repr(C)] -#[derive(Clone, Copy)] -pub struct TEE_OperationInfoKey { - pub keySize: u32, - pub requiredKeyUsage: u32, -} - -/// Fixed header of a C flexible-array object. -/// -/// This type is deliberately not `Copy` or `Clone`: a copy would duplicate -/// only this header, not the `numberOfKeys` key entries that follow it in -/// the same allocation. -#[repr(C)] -pub struct TEE_OperationInfoMultiple { - pub algorithm: u32, - pub operationClass: u32, - pub mode: u32, - pub digestLength: u32, - pub maxKeySize: u32, - pub handleState: u32, - pub operationState: u32, - pub numberOfKeys: u32, - /// C flexible array member: the fixed part ends here and - /// `numberOfKeys` entries of [`TEE_OperationInfoKey`] follow the - /// struct in the same allocation. A zero-length array gives the - /// field the right offset without adding to `size_of`. - pub keyInformation: [TEE_OperationInfoKey; 0], -} - -// Time & Date API - -#[repr(C)] -pub struct TEE_Time { - pub seconds: u32, - pub millis: u32, -} - -// TEE Arithmetical APIs - -#[allow(non_camel_case_types)] -pub type TEE_BigInt = u32; -#[allow(non_camel_case_types)] -pub type TEE_BigIntFMM = u32; -#[allow(non_camel_case_types)] -pub type TEE_BigIntFMMContext = u32; - -// Tee Secure Element APIs - -#[repr(C)] -pub struct __TEE_SEServiceHandle { - _unused: [u8; 0], -} -#[allow(non_camel_case_types)] -pub type TEE_SEServiceHandle = *mut __TEE_SEServiceHandle; -#[repr(C)] -pub struct __TEE_SEReaderHandle { - _unused: [u8; 0], -} -#[allow(non_camel_case_types)] -pub type TEE_SEReaderHandle = *mut __TEE_SEReaderHandle; -#[repr(C)] -pub struct __TEE_SESessionHandle { - _unused: [u8; 0], -} -#[allow(non_camel_case_types)] -pub type TEE_SESessionHandle = *mut __TEE_SESessionHandle; -#[repr(C)] -pub struct __TEE_SEChannelHandle { - _unused: [u8; 0], -} -#[allow(non_camel_case_types)] -pub type TEE_SEChannelHandle = *mut __TEE_SEChannelHandle; - -#[repr(C)] -pub struct TEE_SEReaderProperties { - pub sePresent: bool, - pub teeOnly: bool, - pub selectResponseEnable: bool, -} - -#[repr(C)] -pub struct TEE_SEAID { - pub buffer: *mut u8, - pub bufferLen: size_t, -} - -// Other definitions -#[allow(non_camel_case_types)] -pub type TEE_ErrorOrigin = u32; -#[allow(non_camel_case_types)] -pub type TEE_Session = *mut c_void; - -pub const TEE_MEM_INPUT: u32 = 0x00000001; -pub const TEE_MEM_OUTPUT: u32 = 0x00000002; -pub const TEE_MEMREF_0_USED: u32 = 0x00000001; -pub const TEE_MEMREF_1_USED: u32 = 0x00000002; -pub const TEE_MEMREF_2_USED: u32 = 0x00000004; -pub const TEE_MEMREF_3_USED: u32 = 0x00000008; -pub const TEE_SE_READER_NAME_MAX: u32 = 20; diff --git a/crates/optee-utee-sys/src/tee_internal_api_extensions.rs b/crates/optee-utee-sys/src/tee_internal_api_extensions.rs deleted file mode 100644 index 3a42756e..00000000 --- a/crates/optee-utee-sys/src/tee_internal_api_extensions.rs +++ /dev/null @@ -1,42 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -#[cfg_attr(feature = "mock", mockall::automock)] -pub mod api { - use crate::*; - use core::ffi::*; - - unsafe extern "C" { - /// tee_invoke_supp_plugin() - invoke a tee-supplicant's plugin - /// @uuid: uuid of the plugin - /// @cmd: command for the plugin - /// @sub_cmd: subcommand for the plugin - /// @buf: data [for/from] the plugin [in/out] - /// @len: length of the input buf - /// @outlen: pointer to length of the output data (if they will be used) - /// Return TEE_SUCCESS on success or TEE_ERRROR_* on failure. - pub fn tee_invoke_supp_plugin( - uuid: *const TEE_UUID, - cmd: u32, - sub_cmd: u32, - buf: *mut c_void, - len: usize, - outlen: *mut usize, - ) -> TEE_Result; - - } -} diff --git a/crates/optee-utee-sys/src/tee_ipsocket.rs b/crates/optee-utee-sys/src/tee_ipsocket.rs deleted file mode 100644 index 123ceb25..00000000 --- a/crates/optee-utee-sys/src/tee_ipsocket.rs +++ /dev/null @@ -1,23 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -#[repr(C)] -pub enum TEE_ipSocket_ipVersion { - TEE_IP_VERSION_DC = 0, - TEE_IP_VERSION_4 = 1, - TEE_IP_VERSION_6 = 2, -} diff --git a/crates/optee-utee-sys/src/tee_isocket.rs b/crates/optee-utee-sys/src/tee_isocket.rs deleted file mode 100644 index 19a23fd4..00000000 --- a/crates/optee-utee-sys/src/tee_isocket.rs +++ /dev/null @@ -1,64 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -use super::*; -use core::ffi::*; - -pub type TEE_iSocketHandle = *mut c_void; -pub type TEE_iSocket = TEE_iSocket_s; - -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct TEE_iSocket_s { - pub TEE_iSocketVersion: u32, - pub protocolID: u8, - pub open: unsafe extern "C" fn( - ctx: *mut TEE_iSocketHandle, - setup: *mut c_void, - protocolError: *mut u32, - ) -> TEE_Result, - pub close: unsafe extern "C" fn(ctx: TEE_iSocketHandle) -> TEE_Result, - pub send: unsafe extern "C" fn( - ctx: TEE_iSocketHandle, - buf: *const c_void, - length: *mut u32, - timeout: u32, - ) -> TEE_Result, - pub recv: unsafe extern "C" fn( - ctx: TEE_iSocketHandle, - buf: *mut c_void, - length: *mut u32, - timeout: u32, - ) -> TEE_Result, - pub error: unsafe extern "C" fn(ctx: TEE_iSocketHandle) -> u32, - pub ioctl: unsafe extern "C" fn( - ctx: TEE_iSocketHandle, - commandCode: u32, - buf: *mut c_void, - length: *mut u32, - ) -> TEE_Result, -} - -pub const TEE_ISOCKET_VERSION: u32 = 0x01000000; - -pub const TEE_ISOCKET_ERROR_PROTOCOL: u32 = 0xF1007001; -pub const TEE_ISOCKET_ERROR_REMOTE_CLOSED: u32 = 0xF1007002; -pub const TEE_ISOCKET_ERROR_TIMEOUT: u32 = 0xF1007003; -pub const TEE_ISOCKET_ERROR_OUT_OF_RESOURCES: u32 = 0xF1007004; -pub const TEE_ISOCKET_ERROR_LARGE_BUFFER: u32 = 0xF1007005; -pub const TEE_ISOCKET_WARNING_PROTOCOL: u32 = 0xF1007006; -pub const TEE_ISOCKET_ERROR_HOSTNAME: u32 = 0xF1007007; diff --git a/crates/optee-utee-sys/src/tee_tcpsocket.rs b/crates/optee-utee-sys/src/tee_tcpsocket.rs deleted file mode 100644 index 10bc645d..00000000 --- a/crates/optee-utee-sys/src/tee_tcpsocket.rs +++ /dev/null @@ -1,37 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -use super::*; -use core::ffi::*; - -pub type TEE_tcpSocket_Setup = TEE_tcpSocket_Setup_s; -#[repr(C)] -pub struct TEE_tcpSocket_Setup_s { - pub ipVersion: TEE_ipSocket_ipVersion, - pub server_addr: *mut c_char, - pub server_port: u16, -} - -unsafe extern "C" { - pub static TEE_tcpSocket: *const TEE_iSocket; -} - -pub const TEE_ISOCKET_PROTOCOLID_TCP: u32 = 0x65; -pub const TEE_ISOCKET_TCP_WARNING_UNKNOWN_OUT_OF_BAND: u32 = 0xF1010002; - -pub const TEE_TCP_SET_RECVBUF: u32 = 0x65f00000; -pub const TEE_TCP_SET_SENDBUF: u32 = 0x65f00001; diff --git a/crates/optee-utee-sys/src/tee_udpsocket.rs b/crates/optee-utee-sys/src/tee_udpsocket.rs deleted file mode 100644 index 28a93c36..00000000 --- a/crates/optee-utee-sys/src/tee_udpsocket.rs +++ /dev/null @@ -1,36 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -use super::*; -use core::ffi::*; - -pub type TEE_udpSocket_Setup = TEE_udpSocket_Setup_s; -#[repr(C)] -pub struct TEE_udpSocket_Setup_s { - pub ipVersion: TEE_ipSocket_ipVersion, - pub server_addr: *mut c_char, - pub server_port: u16, -} - -unsafe extern "C" { - pub static TEE_udpSocket: *const TEE_iSocket; -} - -pub const TEE_ISOCKET_PROTOCOLID_UDP: u32 = 0x66; -pub const TEE_ISOCKET_UDP_WARNING_UNKNOWN_OUT_OF_BAND: u32 = 0xF1020002; -pub const TEE_UDP_CHANGEADDR: u32 = 0x66000001; -pub const TEE_UDP_CHANGEPORT: u32 = 0x66000002; diff --git a/crates/optee-utee-sys/src/trace.rs b/crates/optee-utee-sys/src/trace.rs deleted file mode 100644 index 77559e50..00000000 --- a/crates/optee-utee-sys/src/trace.rs +++ /dev/null @@ -1,40 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -use core::ffi::*; - -unsafe extern "C" { - pub fn trace_ext_puts(str: *const c_char); - pub fn trace_ext_get_thread_id() -> c_int; - pub fn trace_set_level(level: c_int); - pub fn trace_get_level() -> c_int; - pub fn trace_printf( - func: *const c_char, - line: c_int, - level: c_int, - level_ok: bool, - fmt: *const c_char, - ... - ); - pub fn dhex_dump( - function: *const c_char, - line: c_int, - level: c_int, - buf: *const c_void, - len: c_int, - ); -} diff --git a/crates/optee-utee-sys/src/user_ta_header.rs b/crates/optee-utee-sys/src/user_ta_header.rs deleted file mode 100644 index 3f495ab0..00000000 --- a/crates/optee-utee-sys/src/user_ta_header.rs +++ /dev/null @@ -1,106 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -use super::tee_api_types::*; -use super::utee_syscalls::*; -use super::utee_types::*; -use core::ffi::*; - -pub const TA_FLAG_SINGLE_INSTANCE: u32 = 1 << 2; -pub const TA_FLAG_MULTI_SESSION: u32 = 1 << 3; -pub const TA_FLAG_INSTANCE_KEEP_ALIVE: u32 = 1 << 4; -pub const TA_FLAG_SECURE_DATA_PATH: u32 = 1 << 5; -pub const TA_FLAG_REMAP_SUPPORT: u32 = 1 << 6; -pub const TA_FLAG_CACHE_MAINTENANCE: u32 = 1 << 7; -pub const TA_FLAG_CONCURRENT: u32 = 1 << 8; -pub const TA_FLAG_DEVICE_ENUM: u32 = 1 << 9; -pub const TA_FLAG_DEVICE_ENUM_SUPP: u32 = 1 << 10; -pub const TA_FLAG_DONT_CLOSE_HANDLE_ON_CORRUPT_OBJECT: u32 = 1 << 11; -pub const TA_FLAG_DEVICE_ENUM_TEE_STORAGE_PRIVATE: u32 = 1 << 12; -pub const TA_FLAG_INSTANCE_KEEP_CRASHED: u32 = 1 << 13; - -pub const TA_FLAG_EXEC_DDR: u32 = 0; -pub const TA_FLAG_USER_MODE: u32 = 0; -#[repr(C)] -pub struct ta_head { - pub uuid: TEE_UUID, - pub stack_size: u32, - pub flags: u32, - pub depr_entry: u64, -} - -unsafe extern "C" { - pub fn __utee_entry( - func: c_ulong, - session_id: c_ulong, - up: *mut utee_params, - cmd_id: c_ulong, - ) -> TEE_Result; -} - -/// # Safety -/// This function is the main entry point for a Trusted Application (TA) in OP-TEE. -/// It must only be called by the OP-TEE OS with valid parameters. The `up` parameter -/// is a raw pointer that must point to a valid `utee_params` structure initialized -/// by the OP-TEE runtime environment. This function should never be called directly -/// from user code - it is only exported for the OP-TEE OS loader. -#[unsafe(no_mangle)] -unsafe fn __ta_entry( - func: c_ulong, - session_id: c_ulong, - up: *mut utee_params, - cmd_id: c_ulong, -) -> ! { - let res: u32 = unsafe { __utee_entry(func, session_id, up, cmd_id) }; - - unsafe { _utee_return(res.into()) }; -} - -unsafe impl Sync for ta_head {} - -pub const TA_PROP_STR_SINGLE_INSTANCE: *const c_char = c"gpd.ta.singleInstance".as_ptr(); -pub const TA_PROP_STR_MULTI_SESSION: *const c_char = c"gpd.ta.multiSession".as_ptr(); -pub const TA_PROP_STR_KEEP_ALIVE: *const c_char = c"gpd.ta.instanceKeepAlive".as_ptr(); -pub const TA_PROP_STR_KEEP_CRASHED: *const c_char = c"gpd.ta.instanceKeepCrashed".as_ptr(); -pub const TA_PROP_STR_DATA_SIZE: *const c_char = c"gpd.ta.dataSize".as_ptr(); -pub const TA_PROP_STR_STACK_SIZE: *const c_char = c"gpd.ta.stackSize".as_ptr(); -pub const TA_PROP_STR_VERSION: *const c_char = c"gpd.ta.version".as_ptr(); -pub const TA_PROP_STR_DESCRIPTION: *const c_char = c"gpd.ta.description".as_ptr(); -pub const TA_PROP_STR_ENDIAN: *const c_char = c"gpd.ta.endian".as_ptr(); -pub const TA_PROP_STR_DOES_NOT_CLOSE_HANDLE_ON_CORRUPT_OBJECT: *const c_char = - c"gpd.ta.doesNotCloseHandleOnCorruptObject".as_ptr(); - -#[repr(C)] -pub enum user_ta_prop_type { - USER_TA_PROP_TYPE_BOOL, - USER_TA_PROP_TYPE_U32, - USER_TA_PROP_TYPE_UUID, - USER_TA_PROP_TYPE_IDENTITY, - USER_TA_PROP_TYPE_STRING, - USER_TA_PROP_TYPE_BINARY_BLOCK, - USER_TA_PROP_TYPE_U64, - USER_TA_PROP_TYPE_INVALID, -} - -#[repr(C)] -pub struct user_ta_property { - pub name: *const c_char, - pub prop_type: user_ta_prop_type, - pub value: *const c_void, -} - -unsafe impl Sync for user_ta_property {} diff --git a/crates/optee-utee-sys/src/utee_syscalls.rs b/crates/optee-utee-sys/src/utee_syscalls.rs deleted file mode 100644 index 7b08fa3b..00000000 --- a/crates/optee-utee-sys/src/utee_syscalls.rs +++ /dev/null @@ -1,232 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -use super::utee_types::utee_object_info; -use super::*; -use crate::size_t; -use core::ffi::*; - -unsafe extern "C" { - pub fn _utee_return(ret: c_ulong) -> !; - pub fn _utee_log(buf: *const c_void, len: size_t); - pub fn _utee_panic(code: c_ulong); - pub fn _utee_get_property( - prop_set: c_ulong, - index: c_ulong, - name: *mut c_void, - name_len: *mut u32, - buf: *mut c_void, - blen: *mut u32, - prop_type: *mut u32, - ) -> TEE_Result; - pub fn _utee_get_property_name_to_index( - prop_set: c_ulong, - name: *const c_void, - name_len: c_ulong, - index: *mut u32, - ) -> TEE_Result; - pub fn _utee_open_ta_session( - dest: *const TEE_UUID, - cancel_req_to: c_ulong, - params: *mut utee_params, - sess: *mut u32, - ret_orig: *mut u32, - ) -> TEE_Result; - pub fn _utee_close_ta_session(sess: c_ulong) -> TEE_Result; - pub fn _utee_invoke_ta_command( - sess: c_ulong, - cancel_req_to: c_ulong, - cmd_id: c_ulong, - params: *mut utee_params, - ret_orig: *mut u32, - ) -> TEE_Result; - pub fn _utee_check_access_rights(flags: u32, buf: *const c_void, len: size_t) -> TEE_Result; - pub fn _utee_get_cancellation_flag(cancel: *mut u32) -> TEE_Result; - pub fn _utee_unmask_cancellation(old_mask: *mut u32) -> TEE_Result; - pub fn _utee_mask_cancellation(old_mask: *mut u32) -> TEE_Result; - pub fn _utee_wait(timeout: c_ulong) -> TEE_Result; - pub fn _utee_get_time(cat: c_ulong, time: *mut TEE_Time) -> TEE_Result; - pub fn _utee_set_ta_time(time: *const TEE_Time) -> TEE_Result; - pub fn _utee_cryp_state_alloc( - algo: c_ulong, - op_mode: c_ulong, - key1: c_ulong, - key2: c_ulong, - state: *mut u32, - ) -> TEE_Result; - pub fn _utee_cryp_state_copy(dst: c_ulong, src: c_ulong) -> TEE_Result; - pub fn _utee_cryp_state_free(state: c_ulong) -> TEE_Result; - pub fn _utee_hash_init(state: c_ulong, iv: *const c_void, iv_len: size_t) -> TEE_Result; - pub fn _utee_hash_update( - state: c_ulong, - chunk: *const c_void, - chunk_size: size_t, - ) -> TEE_Result; - pub fn _utee_hash_final( - state: c_ulong, - chunk: *const c_void, - chunk_size: size_t, - hash: *mut c_void, - hash_len: *mut u64, - ) -> TEE_Result; - pub fn _utee_cipher_init(state: c_ulong, iv: *const c_void, iv_len: size_t) -> TEE_Result; - pub fn _utee_cipher_update( - state: c_ulong, - src: *const c_void, - src_len: size_t, - dest: *mut c_void, - dest_len: *mut u64, - ) -> TEE_Result; - pub fn _utee_cipher_final( - state: c_ulong, - src: *const c_void, - src_len: size_t, - dest: *mut c_void, - dest_len: *mut u64, - ) -> TEE_Result; - pub fn _utee_cryp_obj_get_info(obj: c_ulong, info: *mut utee_object_info) -> TEE_Result; - pub fn _utee_cryp_obj_restrict_usage(obj: c_ulong, usage: c_ulong) -> TEE_Result; - pub fn _utee_cryp_obj_get_attr( - obj: c_ulong, - attr_id: c_ulong, - buffer: *mut c_void, - size: *mut u64, - ) -> TEE_Result; - pub fn _utee_cryp_obj_alloc(ttype: c_ulong, max_size: c_ulong, obj: *mut u32) -> TEE_Result; - pub fn _utee_cryp_obj_close(obj: c_ulong) -> TEE_Result; - pub fn _utee_cryp_obj_reset(obj: c_ulong) -> TEE_Result; - pub fn _utee_cryp_obj_populate( - obj: c_ulong, - attrs: *mut utee_attribute, - attr_count: c_ulong, - ) -> TEE_Result; - pub fn _utee_cryp_obj_copy(dst_obj: c_ulong, src_obj: c_ulong) -> TEE_Result; - pub fn _utee_cryp_obj_generate_key( - obj: c_ulong, - key_size: c_ulong, - params: *const utee_attribute, - param_count: c_ulong, - ) -> TEE_Result; - pub fn _utee_cryp_derive_key( - state: c_ulong, - params: *const utee_attribute, - param_count: c_ulong, - derived_key: c_ulong, - ) -> TEE_Result; - pub fn _utee_cryp_random_number_generate(buf: *mut c_void, blen: size_t) -> TEE_Result; - pub fn _utee_authenc_init( - state: c_ulong, - nonce: *const c_void, - nonce_len: size_t, - tag_len: size_t, - aad_len: size_t, - payload_len: size_t, - ) -> TEE_Result; - pub fn _utee_authenc_update_aad( - state: c_ulong, - aad_data: *const c_void, - aad_data_len: size_t, - ) -> TEE_Result; - pub fn _utee_authenc_update_payload( - state: c_ulong, - src_data: *const c_void, - src_len: size_t, - dest_data: *mut c_void, - dest_len: *mut u64, - ) -> TEE_Result; - pub fn _utee_authenc_enc_final( - state: c_ulong, - src_data: *const c_void, - src_len: size_t, - dest_data: *mut c_void, - dest_len: *mut u64, - tag: *mut c_void, - tag_len: *mut u64, - ) -> TEE_Result; - pub fn _utee_authenc_dec_final( - state: c_ulong, - src_data: *const c_void, - src_len: size_t, - dest_data: *mut c_void, - dest_len: *mut u64, - tag: *const c_void, - tag_len: size_t, - ) -> TEE_Result; - pub fn _utee_asymm_operate( - state: c_ulong, - params: *const utee_attribute, - num_params: c_ulong, - src_data: *const c_void, - src_len: size_t, - dest_data: *mut c_void, - dest_len: *mut u64, - ) -> TEE_Result; - pub fn _utee_asymm_verify( - state: c_ulong, - params: *const utee_attribute, - num_params: c_ulong, - data: *const c_void, - data_len: size_t, - sig: *const c_void, - sig_len: size_t, - ) -> TEE_Result; - pub fn _utee_storage_obj_open( - storage_id: c_ulong, - object_id: *const c_void, - object_id_len: size_t, - flags: c_ulong, - obj: *mut u32, - ) -> TEE_Result; - pub fn _utee_storage_obj_create( - storage_id: c_ulong, - object_id: *const c_void, - object_id_len: size_t, - flags: c_ulong, - attr: c_ulong, - data: *const c_void, - len: size_t, - obj: *mut u32, - ) -> TEE_Result; - pub fn _utee_storage_obj_del(obj: c_ulong) -> TEE_Result; - pub fn _utee_storage_obj_rename( - obj: c_ulong, - new_obj_id: *const c_void, - new_obj_id_len: size_t, - ) -> TEE_Result; - pub fn _utee_storage_alloc_enum(obj_enum: *mut u32) -> TEE_Result; - pub fn _utee_storage_free_enum(obj_enum: c_ulong) -> TEE_Result; - pub fn _utee_storage_reset_enum(obj_enum: c_ulong) -> TEE_Result; - pub fn _utee_storage_start_enum(obj_enum: c_ulong, storage_id: c_ulong) -> TEE_Result; - pub fn _utee_storage_next_enum( - obj_enum: c_ulong, - info: *mut utee_object_info, - obj_id: *mut c_void, - len: *mut u64, - ) -> TEE_Result; - pub fn _utee_storage_obj_read( - obj: c_ulong, - data: *mut c_void, - len: size_t, - count: *mut u64, - ) -> TEE_Result; - pub fn _utee_storage_obj_write(obj: c_ulong, data: *const c_void, len: size_t) -> TEE_Result; - pub fn _utee_storage_obj_trunc(obj: c_ulong, len: size_t) -> TEE_Result; - pub fn _utee_storage_obj_seek(obj: c_ulong, offset: i32, whence: c_ulong) -> TEE_Result; - pub fn _utee_cache_operation(va: *mut c_void, l: size_t, op: c_ulong) -> TEE_Result; - // unimplemented syscall - // pub fn utee_gprof_send(buf: *mut c_void, size: size_t, id: *mut u32) -> TEE_Result; -} diff --git a/crates/optee-utee-sys/src/utee_types.rs b/crates/optee-utee-sys/src/utee_types.rs deleted file mode 100644 index c1624582..00000000 --- a/crates/optee-utee-sys/src/utee_types.rs +++ /dev/null @@ -1,64 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -use super::*; - -#[repr(C)] -pub enum utee_time_category { - UTEE_TIME_CAT_SYSTEM, - UTEE_TIME_CAT_TA_PERSISTENT, - UTEE_TIME_CAT_REE, -} - -#[repr(C)] -pub enum utee_entry_func { - UTEE_ENTRY_FUNC_OPEN_SESSION, - UTEE_ENTRY_FUNC_CLOSE_SESSION, - UTEE_ENTRY_FUNC_INVOKE_COMMAND, -} - -#[allow(non_camel_case_types)] -#[repr(C)] -pub enum utee_cache_operation { - TEE_CACHECLEAN, - TEE_CACHEFLUSH, - TEE_CACHEINVALIDATE, -} - -#[repr(C)] -pub struct utee_params { - types: u64, - vals: [u64; TEE_NUM_PARAMS as usize * 2], -} - -#[repr(C)] -pub struct utee_attribute { - a: u64, - b: u64, - attribute_id: u32, -} - -#[repr(C)] -pub struct utee_object_info { - obj_type: u32, - obj_size: u32, - max_obj_size: u32, - obj_usage: u32, - data_size: u32, - data_pos: u32, - handle_flags: u32, -} diff --git a/crates/optee-utee-systest/Cargo.toml b/crates/optee-utee-systest/Cargo.toml deleted file mode 100644 index a9631909..00000000 --- a/crates/optee-utee-systest/Cargo.toml +++ /dev/null @@ -1,32 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -[package] -name = "optee-utee-systest" -description = "Automatic testing of FFI bindings for the libutee library." -version.workspace = true -authors.workspace = true -license.workspace = true -repository.workspace = true -edition.workspace = true - -[dependencies] -optee-utee-sys.workspace = true - -[build-dependencies] -ctest = { workspace = true } -cc = { workspace = true } diff --git a/crates/optee-utee-systest/build.rs b/crates/optee-utee-systest/build.rs deleted file mode 100644 index 97d9bf68..00000000 --- a/crates/optee-utee-systest/build.rs +++ /dev/null @@ -1,166 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -use std::env; -use std::fs::File; -use std::io::Write; -use std::path::PathBuf; - -fn main() { - let ta_include_path = { - let ta_dev_kit_dir = env::var("TA_DEV_KIT_DIR").expect("TA_DEV_KIT_DIR not set"); - let include_path = PathBuf::from(ta_dev_kit_dir).join("include"); - if !include_path.exists() { - panic!( - "TA_DEV_KIT_DIR include path {} does not exist", - include_path.display() - ); - } - include_path - }; - let mut cfg = generate_cfg(ta_include_path.clone()); - ctest::generate_test(&mut cfg, "../optee-utee-sys/src/lib.rs", "all.rs").unwrap(); - println!("cargo:rustc-link-lib=static=mbedtls"); - println!("cargo:rustc-link-lib=static=utee"); - println!("cargo:rustc-link-lib=static=utils"); - println!("cargo:rustc-link-lib=static=dl"); - - build_and_link_undefined(ta_include_path); -} - -fn generate_cfg(ta_include_path: PathBuf) -> ctest::TestGenerator { - let mut cfg = ctest::TestGenerator::new(); - cfg.edition(2024) - .language(ctest::Language::C) - .header("tee_api_types.h") - .header("tee_api_defines.h") - .header("utee_types.h") - .header("user_ta_header.h") - .header("tee_api.h") - .header("utee_syscalls.h") - .header("tee_tcpsocket.h") - .header("tee_udpsocket.h") - .header("tee_internal_api.h") - .header("tee_internal_api_extensions.h") - .header("tee_api_defines_extensions.h") - .header("__tee_tcpsocket_defines_extensions.h") - .include(ta_include_path.display().to_string()) - .rename_type(|s| match s { - "u64" => Some("uint64_t".to_string()), - "u32" => Some("uint32_t".to_string()), - "u16" => Some("uint16_t".to_string()), - "c_char" => Some("char".to_string()), - _ => None, - }) - .rename_struct_ty(|ty| { - if ty.starts_with("TEE") { - return Some(ty.to_string()); - } - None - }) - .skip_struct(|s| { - let s = s.ident(); - match s { - "Memref" - | "Value" - | "ta_prop" - | "user_ta_property" - | "TEE_iSocket_s" - | "TEE_udpSocket_Setup_s" - | "TEE_tcpSocket_Setup_s" - | "TEE_SEReaderProperties" - | "TEE_SEAID" => true, - _ => s.ends_with("Handle"), - } - }) - .skip_struct_field(|s, field| { - let s = s.ident(); - let field = field.ident(); - (s == "ta_head" && field == "entry") - || (s == "TEE_OperationInfoMultiple" && field == "keyInformation") // flexible array member - || (s == "TEE_Attribute" && field == "content") // anonymous union fields - }) - .skip_fn(|s| { - let s = s.ident(); - matches!(s, "__utee_entry") - }) - .skip_union(|s| { - let s = s.ident(); - matches!(s, "content") - }) - .skip_union_field(|s, _field| { - let s = s.ident(); - s == "TEE_Param" // TEE_Param only have anonymous fields - }) - .rename_union_ty(|s| match s { - "TEE_Param" => Some(s.to_string()), - _ => None, - }); - cfg -} - -fn build_and_link_undefined(ta_include_path: PathBuf) { - let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); - let undefined_path = out_dir.join("undefined.c"); - - let mut buffer = File::create(&undefined_path).unwrap(); - write!( - buffer, - " - #include - void* ta_props = 0; - void* ta_num_props = 0; - void* trace_level = 0; - const char trace_ext_prefix[] = \"TA\"; - void* ta_head = 0; - uint8_t ta_heap[1] = {{ 0 }}; - size_t ta_heap_size = 0; - void TA_DestroyEntryPoint(void) {{}}; - TEE_Result tee_uuid_from_str(TEE_UUID __unused *uuid, const char __unused *s) {{ - return TEE_SUCCESS; - }}; - int tahead_get_trace_level(void) {{ - return 0; - }}; - TEE_Result TA_OpenSessionEntryPoint(uint32_t __unused pt, - TEE_Param __unused params[TEE_NUM_PARAMS], - void __unused **sess_ctx) {{ - return TEE_SUCCESS; - }}; - void TA_CloseSessionEntryPoint(void *sess __unused) {{}}; - TEE_Result TA_CreateEntryPoint(void) {{ - return TEE_SUCCESS; - }} - TEE_Result TA_InvokeCommandEntryPoint(void __unused *sess_ctx, - uint32_t __unused cmd_id, - uint32_t __unused pt, - TEE_Param __unused params[TEE_NUM_PARAMS]) {{ - return TEE_SUCCESS; - }}; - " - ) - .unwrap(); - - let mut builder = cc::Build::new(); - builder - .include(ta_include_path.display().to_string()) - .file(undefined_path.display().to_string()) - .compile("undefined"); - - println!("cargo:rustc-link-search=native={}", out_dir.display()); - println!("cargo:rustc-link-lib=static=undefined"); -} diff --git a/crates/optee-utee-systest/src/main.rs b/crates/optee-utee-systest/src/main.rs deleted file mode 100644 index 4cf58b18..00000000 --- a/crates/optee-utee-systest/src/main.rs +++ /dev/null @@ -1,22 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -#![allow(clippy::all)] - -use optee_utee_sys::*; - -include!(concat!(env!("OUT_DIR"), "/all.rs")); diff --git a/crates/optee-utee/src/extension.rs b/crates/optee-utee/src/extension.rs index 105f2989..d4fd6bf6 100644 --- a/crates/optee-utee/src/extension.rs +++ b/crates/optee-utee/src/extension.rs @@ -205,7 +205,7 @@ pub mod test_loadable_plugin { } fn expect_success_request( - ctx: &mock_api::extension::__tee_invoke_supp_plugin::Context, + ctx: &mock_api::__tee_invoke_supp_plugin::Context, exp_uuid: &Uuid, exp_cmd: u32, exp_sub_cmd: u32, @@ -244,7 +244,7 @@ pub mod test_loadable_plugin { let run_test = |request_size: usize, response_size: usize| { let (cmd, sub_cmd, request, exp_response) = generate_test_pairs(request_size, response_size); - let fn1 = mock_api::extension::tee_invoke_supp_plugin_context(); + let fn1 = mock_api::tee_invoke_supp_plugin_context(); expect_success_request(&fn1, &uuid, cmd, sub_cmd, &request, &exp_response); let response = plugin.invoke(cmd, sub_cmd, &request).expect("should be ok"); std::println!("*TA*: response is {:?}", response); @@ -261,7 +261,7 @@ pub mod test_loadable_plugin { { let (cmd, sub_cmd, request, exp_response) = generate_test_pairs(REQUEST_LEN, 2 * REQUEST_LEN); - let fn1 = mock_api::extension::tee_invoke_supp_plugin_context(); + let fn1 = mock_api::tee_invoke_supp_plugin_context(); fn1.expect().return_once_st(move |_, _, _, _, _, outlen| { unsafe { *outlen = exp_response.len() }; raw::TEE_SUCCESS @@ -285,7 +285,7 @@ pub mod test_loadable_plugin { let run_test = |request_size: usize, response_size: usize| { let (cmd, sub_cmd, request, exp_response) = generate_test_pairs(request_size, response_size); - let fn1 = mock_api::extension::tee_invoke_supp_plugin_context(); + let fn1 = mock_api::tee_invoke_supp_plugin_context(); expect_success_request(&fn1, &uuid, cmd, sub_cmd, &request, &exp_response); let response = plugin @@ -310,7 +310,7 @@ pub mod test_loadable_plugin { let _lock = SERIAL_TEST_LOCK.lock().expect("should get the lock"); let uuid: Uuid = random_uuid(); let plugin = LoadablePlugin::new(&uuid); - let fn1 = mock_api::extension::tee_invoke_supp_plugin_context(); + let fn1 = mock_api::tee_invoke_supp_plugin_context(); // impl a writer for Command struct Wrapper<'a, 'b>(&'b mut LoadablePluginCommand<'a>); impl<'a, 'b> std::io::Write for Wrapper<'a, 'b> { @@ -346,7 +346,7 @@ pub mod test_loadable_plugin { let uuid: Uuid = random_uuid(); let plugin = LoadablePlugin::new(&uuid); - let fn1 = mock_api::extension::tee_invoke_supp_plugin_context(); + let fn1 = mock_api::tee_invoke_supp_plugin_context(); const OUTPUT_LEN: usize = 50; let (cmd, sub_cmd, request, exp_response) = generate_test_pairs(0, OUTPUT_LEN); expect_success_request(&fn1, &uuid, cmd, sub_cmd, &request, &exp_response); diff --git a/crates/optee-utee/src/net/error.rs b/crates/optee-utee/src/net/error.rs index b62ece2f..9222dd9c 100644 --- a/crates/optee-utee/src/net/error.rs +++ b/crates/optee-utee/src/net/error.rs @@ -43,7 +43,8 @@ impl SocketError { raw::TEE_ERROR_CANCEL | raw::TEE_ERROR_COMMUNICATION | raw::TEE_ERROR_OUT_OF_MEMORY - | raw::TEE_ERROR_BAD_PARAMETERS => Self::Tee(crate::Error::from_raw_error(code).kind()), + | raw::TEE_ERROR_BAD_PARAMETERS + | raw::TEE_ERROR_NOT_SUPPORTED => Self::Tee(crate::Error::from_raw_error(code).kind()), _ => Self::Unknown(code), } } diff --git a/crates/optee-utee/src/net/optee.rs b/crates/optee-utee/src/net/optee.rs index b4c6dc57..0f0e240d 100644 --- a/crates/optee-utee/src/net/optee.rs +++ b/crates/optee-utee/src/net/optee.rs @@ -79,19 +79,25 @@ fn handle_socket_operation_error( handle: raw::TEE_iSocketHandle, code: u32, ) -> SocketError { + // `error` is optional, so an implementation that omits it reports the + // protocol-specific code as 0 instead of panicking. + let protocol_error = || match unsafe { (*socket).error } { + Some(error) => unsafe { error(handle) }, + None => 0, + }; match code { - raw::TEE_ISOCKET_ERROR_PROTOCOL => { - let protocol_error = unsafe { ((*socket).error)(handle) }; - SocketError::ErrorProtocol(protocol_error) - } - raw::TEE_ISOCKET_WARNING_PROTOCOL => { - let protocol_error = unsafe { ((*socket).error)(handle) }; - SocketError::WarningProtocol(protocol_error) - } + raw::TEE_ISOCKET_ERROR_PROTOCOL => SocketError::ErrorProtocol(protocol_error()), + raw::TEE_ISOCKET_WARNING_PROTOCOL => SocketError::WarningProtocol(protocol_error()), _ => SocketError::from_raw_error(code, 0), } } +/// Error reported when OP-TEE's socket implementation leaves a callback unset, +/// for example an operation the selected protocol does not provide. +fn not_supported() -> SocketError { + SocketError::from_raw_error(raw::TEE_ERROR_NOT_SUPPORTED, 0) +} + impl SocketAdapter for TcpAdapter { type Setup = Setup; type Handle = Self; @@ -104,8 +110,9 @@ impl SocketAdapter for TcpAdapter { server_addr: setup.addr.as_ptr() as _, server_port: setup.port, }; + let open = unsafe { (*raw::TEE_tcpSocket).open }.ok_or_else(not_supported)?; let ret = unsafe { - ((*raw::TEE_tcpSocket).open)( + open( &mut handle, &mut setup as *mut raw::TEE_tcpSocket_Setup as _, &mut protocol_error, @@ -118,9 +125,8 @@ impl SocketAdapter for TcpAdapter { } fn send(handle: &mut Self::Handle, buf: &[u8], timeout: u32) -> Result { let mut length: u32 = buf.len() as _; - let ret = unsafe { - ((*raw::TEE_tcpSocket).send)(handle.0, buf.as_ptr() as _, &mut length, timeout) - }; + let send = unsafe { (*raw::TEE_tcpSocket).send }.ok_or_else(not_supported)?; + let ret = unsafe { send(handle.0, buf.as_ptr() as _, &mut length, timeout) }; match ret { raw::TEE_SUCCESS => Ok(length as usize), _ => Err(handle_socket_operation_error( @@ -132,9 +138,8 @@ impl SocketAdapter for TcpAdapter { } fn recv(handle: &mut Self::Handle, buf: &mut [u8], timeout: u32) -> Result { let mut length: u32 = buf.len() as _; - let ret = unsafe { - ((*raw::TEE_tcpSocket).recv)(handle.0, buf.as_mut_ptr() as _, &mut length, timeout) - }; + let recv = unsafe { (*raw::TEE_tcpSocket).recv }.ok_or_else(not_supported)?; + let ret = unsafe { recv(handle.0, buf.as_mut_ptr() as _, &mut length, timeout) }; match ret { raw::TEE_SUCCESS => Ok(length as usize), _ => Err(handle_socket_operation_error( @@ -148,9 +153,9 @@ impl SocketAdapter for TcpAdapter { impl Drop for TcpAdapter { fn drop(&mut self) { - // Ignore any errors on close. - unsafe { - ((*raw::TEE_tcpSocket).close)(self.0); + // Ignore any errors on close, including a missing callback. + if let Some(close) = unsafe { (*raw::TEE_tcpSocket).close } { + unsafe { close(self.0) }; } } } @@ -167,8 +172,9 @@ impl SocketAdapter for UdpAdapter { server_addr: setup.addr.as_ptr() as _, server_port: setup.port, }; + let open = unsafe { (*raw::TEE_udpSocket).open }.ok_or_else(not_supported)?; let ret = unsafe { - ((*raw::TEE_udpSocket).open)( + open( &mut handle, &mut setup as *mut raw::TEE_udpSocket_Setup as _, &mut protocol_error, @@ -181,9 +187,8 @@ impl SocketAdapter for UdpAdapter { } fn send(handle: &mut Self::Handle, buf: &[u8], timeout: u32) -> Result { let mut length: u32 = buf.len() as _; - let ret = unsafe { - ((*raw::TEE_udpSocket).send)(handle.0, buf.as_ptr() as _, &mut length, timeout) - }; + let send = unsafe { (*raw::TEE_udpSocket).send }.ok_or_else(not_supported)?; + let ret = unsafe { send(handle.0, buf.as_ptr() as _, &mut length, timeout) }; match ret { raw::TEE_SUCCESS => Ok(length as usize), _ => Err(handle_socket_operation_error( @@ -195,9 +200,8 @@ impl SocketAdapter for UdpAdapter { } fn recv(handle: &mut Self::Handle, buf: &mut [u8], timeout: u32) -> Result { let mut length: u32 = buf.len() as _; - let ret = unsafe { - ((*raw::TEE_udpSocket).recv)(handle.0, buf.as_mut_ptr() as _, &mut length, timeout) - }; + let recv = unsafe { (*raw::TEE_udpSocket).recv }.ok_or_else(not_supported)?; + let ret = unsafe { recv(handle.0, buf.as_mut_ptr() as _, &mut length, timeout) }; match ret { raw::TEE_SUCCESS => Ok(length as usize), _ => Err(handle_socket_operation_error( @@ -211,9 +215,9 @@ impl SocketAdapter for UdpAdapter { impl Drop for UdpAdapter { fn drop(&mut self) { - // Ignore any errors on close. - unsafe { - ((*raw::TEE_udpSocket).close)(self.0); + // Ignore any errors on close, including a missing callback. + if let Some(close) = unsafe { (*raw::TEE_udpSocket).close } { + unsafe { close(self.0) }; } } } diff --git a/crates/optee-utee/src/object/attribute.rs b/crates/optee-utee/src/object/attribute.rs index 1292c5c1..86ad36e0 100644 --- a/crates/optee-utee/src/object/attribute.rs +++ b/crates/optee-utee/src/object/attribute.rs @@ -64,10 +64,10 @@ impl<'attrref> AttributeMemref<'attrref> { fn new_ref() -> Self { let raw = raw::TEE_Attribute { attributeID: 0, - content: raw::content { - memref: raw::Memref { + content: raw::TEE_Attribute__bindgen_ty_1 { + ref_: raw::TEE_Attribute__bindgen_ty_1__bindgen_ty_1 { buffer: core::ptr::null_mut(), - size: 0, + length: 0, }, }, }; @@ -119,8 +119,8 @@ impl AttributeValue { fn new_value() -> Self { let raw = raw::TEE_Attribute { attributeID: 0, - content: raw::content { - value: raw::Value { a: 0, b: 0 }, + content: raw::TEE_Attribute__bindgen_ty_1 { + value: raw::TEE_Attribute__bindgen_ty_1__bindgen_ty_2 { a: 0, b: 0 }, }, }; Self { raw } @@ -153,72 +153,72 @@ impl AttributeValue { #[repr(u32)] pub enum AttributeId { /// Used for all secret keys for symmetric ciphers, MACs, and HMACs - SecretValue = 0xC0000000, + SecretValue = raw::TEE_ATTR_SECRET_VALUE, /// RSA modulus: `n` - RsaModulus = 0xD0000130, + RsaModulus = raw::TEE_ATTR_RSA_MODULUS, /// RSA public key exponent: `e` - RsaPublicExponent = 0xD0000230, + RsaPublicExponent = raw::TEE_ATTR_RSA_PUBLIC_EXPONENT, /// RSA private key exponent: `d` - RsaPrivateExponent = 0xC0000330, + RsaPrivateExponent = raw::TEE_ATTR_RSA_PRIVATE_EXPONENT, /// RSA prime number: `p` - RsaPrime1 = 0xC0000430, + RsaPrime1 = raw::TEE_ATTR_RSA_PRIME1, /// RSA prime number: `q` - RsaPrime2 = 0xC0000530, + RsaPrime2 = raw::TEE_ATTR_RSA_PRIME2, /// RSA exponent: `dp` - RsaExponent1 = 0xC0000630, + RsaExponent1 = raw::TEE_ATTR_RSA_EXPONENT1, /// RSA exponent: `dq` - RsaExponent2 = 0xC0000730, + RsaExponent2 = raw::TEE_ATTR_RSA_EXPONENT2, /// RSA coefficient: `iq` - RsaCoefficient = 0xC0000830, + RsaCoefficient = raw::TEE_ATTR_RSA_COEFFICIENT, /// DSA prime number: `p` - DsaPrime = 0xD0001031, + DsaPrime = raw::TEE_ATTR_DSA_PRIME, /// DSA sub prime number: `q` - DsaSubprime = 0xD0001131, + DsaSubprime = raw::TEE_ATTR_DSA_SUBPRIME, /// DSA base: `g` - DsaBase = 0xD0001231, + DsaBase = raw::TEE_ATTR_DSA_BASE, /// DSA public value: `y` - DsaPublicValue = 0xD0000131, + DsaPublicValue = raw::TEE_ATTR_DSA_PUBLIC_VALUE, /// DSA private value: `x` - DsaPrivateValue = 0xC0000231, + DsaPrivateValue = raw::TEE_ATTR_DSA_PRIVATE_VALUE, /// Diffie-Hellman prime number: `p` - DhPrime = 0xD0001032, + DhPrime = raw::TEE_ATTR_DH_PRIME, /// Diffie-Hellman subprime number: `q` - DhSubprime = 0xD0001132, + DhSubprime = raw::TEE_ATTR_DH_SUBPRIME, /// Diffie-Hellman base: `g` - DhBase = 0xD0001232, + DhBase = raw::TEE_ATTR_DH_BASE, /// Diffie-Hellman x bits: `l` - DhXBits = 0xF0001332, + DhXBits = raw::TEE_ATTR_DH_X_BITS, /// Diffie-Hellman public value: `y` - DhPublicValue = 0xD0000132, + DhPublicValue = raw::TEE_ATTR_DH_PUBLIC_VALUE, /// Diffie-Hellman public value: `x` - DhPrivateValue = 0xC0000232, + DhPrivateValue = raw::TEE_ATTR_DH_PRIVATE_VALUE, /// PBKDF2 password, bytes of the password - Pbkdf2Password = 0xC00001C2, + Pbkdf2Password = raw::TEE_ATTR_PBKDF2_PASSWORD, /// PBKDF2 salt, bytes of the salt - Pbkdf2Salt = 0xD00002C2, + Pbkdf2Salt = raw::TEE_ATTR_PBKDF2_SALT, /// PBKDF2 iteration count - Pbkdf2IterationCount = 0xF00003C2, + Pbkdf2IterationCount = raw::TEE_ATTR_PBKDF2_ITERATION_COUNT, /// PBKDF2 derived key material length in bytes - Pbkdf2DkmLength = 0xF00004C2, - RsaOaepLabel = 0xD0000930, - RsaOaepMgf1Hash = 0xD0000931, - RsaPssSaltLength = 0xF0000A30, + Pbkdf2DkmLength = raw::TEE_ATTR_PBKDF2_DKM_LENGTH, + RsaOaepLabel = raw::TEE_ATTR_RSA_OAEP_LABEL, + RsaOaepMgf1Hash = raw::TEE_ATTR_RSA_OAEP_MGF_HASH, + RsaPssSaltLength = raw::TEE_ATTR_RSA_PSS_SALT_LENGTH, /// ECC public value: `x` - EccPublicValueX = 0xD0000141, + EccPublicValueX = raw::TEE_ATTR_ECC_PUBLIC_VALUE_X, /// ECC public value: `y` - EccPublicValueY = 0xD0000241, + EccPublicValueY = raw::TEE_ATTR_ECC_PUBLIC_VALUE_Y, /// ECC private value: `d` - EccPrivateValue = 0xC0000341, + EccPrivateValue = raw::TEE_ATTR_ECC_PRIVATE_VALUE, /// Ed25519 public value - Ed25519PublicValue = 0xD0000743, + Ed25519PublicValue = raw::TEE_ATTR_ED25519_PUBLIC_VALUE, /// Ed25519 private value - Ed25519PrivateValue = 0xC0000843, + Ed25519PrivateValue = raw::TEE_ATTR_ED25519_PRIVATE_VALUE, /// X25519 public value - X25519PublicValue = 0xD0000944, + X25519PublicValue = raw::TEE_ATTR_X25519_PUBLIC_VALUE, /// X25519 private value - X25519PrivateValue = 0xC0000A44, + X25519PrivateValue = raw::TEE_ATTR_X25519_PRIVATE_VALUE, /// ECC Curve algorithm - EccCurve = 0xF0000441, - BitProtected = (1 << 28), - BitValue = (1 << 29), + EccCurve = raw::TEE_ATTR_ECC_CURVE, + BitProtected = raw::TEE_ATTR_BIT_PROTECTED, + BitValue = raw::TEE_ATTR_BIT_VALUE, } diff --git a/crates/optee-utee/src/object/object_define.rs b/crates/optee-utee/src/object/object_define.rs index 80691703..58ffc954 100644 --- a/crates/optee-utee/src/object/object_define.rs +++ b/crates/optee-utee/src/object/object_define.rs @@ -32,18 +32,19 @@ pub enum Whence { impl From for raw::TEE_Whence { fn from(val: Whence) -> Self { match val { - Whence::DataSeekSet => raw::TEE_Whence::TEE_DATA_SEEK_SET, - Whence::DataSeekCur => raw::TEE_Whence::TEE_DATA_SEEK_CUR, - Whence::DataSeekEnd => raw::TEE_Whence::TEE_DATA_SEEK_END, + Whence::DataSeekSet => raw::TEE_DATA_SEEK_SET, + Whence::DataSeekCur => raw::TEE_DATA_SEEK_CUR, + Whence::DataSeekEnd => raw::TEE_DATA_SEEK_END, } } } #[repr(u32)] pub enum ObjectStorageConstants { - Private = 0x00000001, - PrivateRee = 0x80000000, - PrivateRpmb = 0x80000100, + Private = raw::TEE_STORAGE_PRIVATE, + PrivateRee = raw::TEE_STORAGE_PRIVATE_REE, + PrivateRpmb = raw::TEE_STORAGE_PRIVATE_RPMB, + /// OP-TEE has no macro for this value, so it stays a literal. IllegalValue = 0x7FFFFFFF, } @@ -53,28 +54,28 @@ bitflags! { pub struct DataFlag: u32 { /// The object is opened with the read access right. This allows the /// Trusted Application to call the function `TEE_ReadObjectData`. - const ACCESS_READ = 0x00000001; + const ACCESS_READ = raw::TEE_DATA_FLAG_ACCESS_READ; /// The object is opened with the write access right. This allows the /// Trusted Application to call the functions `TEE_WriteObjectData` and /// `TEE_TruncateObjectData`. - const ACCESS_WRITE = 0x00000002; + const ACCESS_WRITE = raw::TEE_DATA_FLAG_ACCESS_WRITE; /// The object is opened with the write-meta access right. This allows /// the Trusted Application to call the functions /// `TEE_CloseAndDeletePersistentObject1` and /// `TEE_RenamePersistentObject`. - const ACCESS_WRITE_META = 0x00000004; + const ACCESS_WRITE_META = raw::TEE_DATA_FLAG_ACCESS_WRITE_META; /// The caller allows another handle on the object to be created with /// read access. - const SHARE_READ = 0x00000010; + const SHARE_READ = raw::TEE_DATA_FLAG_SHARE_READ; /// The caller allows another handle on the object to be created with /// write access. - const SHARE_WRITE = 0x00000020; + const SHARE_WRITE = raw::TEE_DATA_FLAG_SHARE_WRITE; /// * If this flag is present and the object exists, then the object is /// deleted and re-created as an atomic operation: that is, the TA /// sees either the old object or the new one. /// * If the flag is absent and the object exists, then the function /// SHALL return `TEE_ERROR_ACCESS_CONFLICT`. - const OVERWRITE = 0x00000400; + const OVERWRITE = raw::TEE_DATA_FLAG_OVERWRITE; } } @@ -82,19 +83,19 @@ bitflags! { /// A set of flags that defines usages of data in TEE secure storage. pub struct UsageFlag: u32 { /// The object [Attribute](Attribute) can be extracted. - const EXTRACTABLE = 0x00000001; + const EXTRACTABLE = raw::TEE_USAGE_EXTRACTABLE; /// The object can be used for encryption. - const ENCRYPT = 0x00000002; + const ENCRYPT = raw::TEE_USAGE_ENCRYPT; /// The object can be used for decryption. - const DECRYPT = 0x00000004; + const DECRYPT = raw::TEE_USAGE_DECRYPT; /// The object can be used for mac operation. - const MAC = 0x00000008; + const MAC = raw::TEE_USAGE_MAC; /// The object can be used for signature. - const SIGN = 0x00000010; + const SIGN = raw::TEE_USAGE_SIGN; /// The object can be used for verification of a signature. - const VERIFY = 0x00000020; + const VERIFY = raw::TEE_USAGE_VERIFY; /// The object can be used for deriving a key. - const DERIVE = 0x00000040; + const DERIVE = raw::TEE_USAGE_DERIVE; } } @@ -102,29 +103,29 @@ bitflags! { #[repr(u32)] pub enum MiscellaneousConstants { /// Maximum offset of a data object. - TeeDataMaxPosition = 0xFFFFFFFF, + TeeDataMaxPosition = raw::TEE_DATA_MAX_POSITION, /// Maximum length of an object id. - TeeObjectIdMaxLen = 64, + TeeObjectIdMaxLen = raw::TEE_OBJECT_ID_MAX_LEN, } bitflags! { /// A set of flags that defines Handle features. pub struct HandleFlag: u32{ /// Set for a [PersistentObject](crate::PersistentObject). - const PERSISTENT = 0x00010000; + const PERSISTENT = raw::TEE_HANDLE_FLAG_PERSISTENT; /// 1) For a [PersistentObject](crate::PersistentObject), always set. /// 2) For a [TransientObject](crate::TransientObject), initially /// cleared, then set when the object becomes initialized. - const INITIALIZED = 0x00020000; + const INITIALIZED = raw::TEE_HANDLE_FLAG_INITIALIZED; /// Following two flags are for crypto operation handles: /// 1) Set if the required operation key has been set. /// 2) Always set for digest operations. - const KEY_SET = 0x00040000; + const KEY_SET = raw::TEE_HANDLE_FLAG_KEY_SET; /// Set if the algorithm expects two keys to be set, using /// `TEE_SetOperationKey2`. /// This happens only if algorithm is set to /// [AesXts](crate::AlgorithmId::AesXts) /// or `TEE_ALG_SM2_KEP`(not supported now). - const EXPECT_TWO_KEYS = 0x00080000; + const EXPECT_TWO_KEYS = raw::TEE_HANDLE_FLAG_EXPECT_TWO_KEYS; } } diff --git a/crates/optee-utee/src/parameter/deprecated.rs b/crates/optee-utee/src/parameter/deprecated.rs index 52d7c9ea..563bb470 100644 --- a/crates/optee-utee/src/parameter/deprecated.rs +++ b/crates/optee-utee/src/parameter/deprecated.rs @@ -82,7 +82,7 @@ impl Parameters { /// [`super::value::ParameterValueWrite`] (for `set_a/set_b`) on the typed /// wrappers ([`super::value::ParameterValueInput`], etc.) instead. pub struct ParamValue<'parameter> { - raw: *mut raw::Value, + raw: *mut raw::TEE_Param__bindgen_ty_2, param_type: ParamType, _marker: marker::PhantomData<&'parameter mut u32>, } @@ -121,7 +121,7 @@ impl<'parameter> ParamValue<'parameter> { /// and [`super::memref::ParameterMemrefWrite`] (for `set_updated_size`, /// `set_output`, `write_at`) on the typed wrappers instead. pub struct ParamMemref<'parameter> { - raw: *mut raw::Memref, + raw: *mut raw::TEE_Param__bindgen_ty_1, param_type: ParamType, _marker: marker::PhantomData<&'parameter mut [u8]>, } @@ -135,7 +135,7 @@ impl<'parameter> ParamMemref<'parameter> { self.param_type } - pub fn raw(&mut self) -> *mut raw::Memref { + pub fn raw(&mut self) -> *mut raw::TEE_Param__bindgen_ty_1 { self.raw } diff --git a/crates/optee-utee/src/parameter/memref.rs b/crates/optee-utee/src/parameter/memref.rs index 260c2e15..3ff6b586 100644 --- a/crates/optee-utee/src/parameter/memref.rs +++ b/crates/optee-utee/src/parameter/memref.rs @@ -300,7 +300,7 @@ mod tests { fn memref(buffer: *mut u8, size: usize) -> TEE_Param { TEE_Param { - memref: raw::Memref { + memref: raw::TEE_Param__bindgen_ty_1 { buffer: buffer.cast(), size, }, diff --git a/crates/optee-utee/src/property.rs b/crates/optee-utee/src/property.rs index 25303ce9..2d1d797f 100644 --- a/crates/optee-utee/src/property.rs +++ b/crates/optee-utee/src/property.rs @@ -17,7 +17,8 @@ use crate::{Error, ErrorKind, Result, tee_check}; use crate::{Identity, Uuid}; -use alloc::{ffi::CString, string::String, vec::Vec}; +use alloc::{string::String, vec::Vec}; +use core::ffi::CStr; use optee_utee_sys as raw; /// Represents a TEE property set according to the TEE Internal API. @@ -50,24 +51,19 @@ pub trait PropertyValue: Sized { /// This function is unsafe because it dereferences raw pointers from the TEE API. /// The caller must ensure that the `set` handle is valid and that the TEE environment /// is properly initialized. - unsafe fn from_raw(set: raw::TEE_PropSetHandle, key: CString) -> Result; + unsafe fn from_raw(set: raw::TEE_PropSetHandle, key: &CStr) -> Result; } /// Implements the PropertyValue trait for all return types: /// String, Bool, u32, u64, BinaryBlock, UUID, Identity. impl PropertyValue for String { - unsafe fn from_raw(set: raw::TEE_PropSetHandle, key: CString) -> Result { + unsafe fn from_raw(set: raw::TEE_PropSetHandle, key: &CStr) -> Result { let mut out_size = 0; // The first call is to get the size of the string // So we pass a null pointer and a size of 0 let res = unsafe { - raw::TEE_GetPropertyAsString( - set, - key.as_ptr() as *const _, - core::ptr::null_mut(), - &mut out_size, - ) + raw::TEE_GetPropertyAsString(set, key.as_ptr(), core::ptr::null_mut(), &mut out_size) }; match res { raw::TEE_SUCCESS => { @@ -84,7 +80,7 @@ impl PropertyValue for String { let res = unsafe { raw::TEE_GetPropertyAsString( set, - key.as_ptr() as *const _, + key.as_ptr(), out_buffer.as_mut_ptr() as *mut _, &mut out_size, ) @@ -92,7 +88,7 @@ impl PropertyValue for String { tee_check(res)?; // Convert the char buffer with null terminator to a C string - let c_str = core::ffi::CStr::from_bytes_with_nul(&out_buffer) + let c_str = CStr::from_bytes_with_nul(&out_buffer) .map_err(|_| Error::new(ErrorKind::BadFormat))?; // Convert the C string to a Rust string let result = c_str.to_string_lossy().into_owned(); @@ -105,10 +101,10 @@ impl PropertyValue for String { } impl PropertyValue for bool { - unsafe fn from_raw(set: raw::TEE_PropSetHandle, key: CString) -> Result { + unsafe fn from_raw(set: raw::TEE_PropSetHandle, key: &CStr) -> Result { let mut b: bool = false; - let res = unsafe { raw::TEE_GetPropertyAsBool(set, key.as_ptr() as *const _, &mut b) }; + let res = unsafe { raw::TEE_GetPropertyAsBool(set, key.as_ptr(), &mut b) }; tee_check(res)?; Ok(b) @@ -116,10 +112,10 @@ impl PropertyValue for bool { } impl PropertyValue for u32 { - unsafe fn from_raw(set: raw::TEE_PropSetHandle, key: CString) -> Result { + unsafe fn from_raw(set: raw::TEE_PropSetHandle, key: &CStr) -> Result { let mut value = 0; - let res = unsafe { raw::TEE_GetPropertyAsU32(set, key.as_ptr() as *const _, &mut value) }; + let res = unsafe { raw::TEE_GetPropertyAsU32(set, key.as_ptr(), &mut value) }; tee_check(res)?; Ok(value) @@ -127,10 +123,10 @@ impl PropertyValue for u32 { } impl PropertyValue for u64 { - unsafe fn from_raw(set: raw::TEE_PropSetHandle, key: CString) -> Result { + unsafe fn from_raw(set: raw::TEE_PropSetHandle, key: &CStr) -> Result { let mut value = 0; - let res = unsafe { raw::TEE_GetPropertyAsU64(set, key.as_ptr() as *const _, &mut value) }; + let res = unsafe { raw::TEE_GetPropertyAsU64(set, key.as_ptr(), &mut value) }; tee_check(res)?; Ok(value) @@ -138,7 +134,7 @@ impl PropertyValue for u64 { } impl PropertyValue for Vec { - unsafe fn from_raw(set: raw::TEE_PropSetHandle, key: CString) -> Result { + unsafe fn from_raw(set: raw::TEE_PropSetHandle, key: &CStr) -> Result { let mut out_size = 0; // The first call is to get the size of the binary block @@ -146,7 +142,7 @@ impl PropertyValue for Vec { let res = unsafe { raw::TEE_GetPropertyAsBinaryBlock( set, - key.as_ptr() as *const _, + key.as_ptr(), core::ptr::null_mut(), &mut out_size, ) @@ -167,7 +163,7 @@ impl PropertyValue for Vec { let res = unsafe { raw::TEE_GetPropertyAsBinaryBlock( set, - key.as_ptr() as *const _, + key.as_ptr(), buf.as_mut_ptr() as *mut _, &mut out_size, ) @@ -181,7 +177,7 @@ impl PropertyValue for Vec { } impl PropertyValue for Uuid { - unsafe fn from_raw(set: raw::TEE_PropSetHandle, key: CString) -> Result { + unsafe fn from_raw(set: raw::TEE_PropSetHandle, key: &CStr) -> Result { let mut raw_uuid = raw::TEE_UUID { timeLow: 0, timeMid: 0, @@ -189,8 +185,7 @@ impl PropertyValue for Uuid { clockSeqAndNode: [0; 8], }; - let res = - unsafe { raw::TEE_GetPropertyAsUUID(set, key.as_ptr() as *const _, &mut raw_uuid) }; + let res = unsafe { raw::TEE_GetPropertyAsUUID(set, key.as_ptr(), &mut raw_uuid) }; tee_check(res)?; Ok(Uuid::from(raw_uuid)) @@ -198,7 +193,7 @@ impl PropertyValue for Uuid { } impl PropertyValue for Identity { - unsafe fn from_raw(set: raw::TEE_PropSetHandle, key: CString) -> Result { + unsafe fn from_raw(set: raw::TEE_PropSetHandle, key: &CStr) -> Result { // Allocate a buffer for the raw identity let mut raw_id = raw::TEE_Identity { login: 0, @@ -210,8 +205,7 @@ impl PropertyValue for Identity { }, }; - let res = - unsafe { raw::TEE_GetPropertyAsIdentity(set, key.as_ptr() as *const _, &mut raw_id) }; + let res = unsafe { raw::TEE_GetPropertyAsIdentity(set, key.as_ptr(), &mut raw_id) }; tee_check(res)?; Ok(Identity::from(raw_id)) @@ -226,7 +220,8 @@ impl PropertyValue for Identity { /// such as "gpd.client.identity" or "gpd.tee.apiversion". pub trait PropertyKey { type Output: PropertyValue; - fn key(&self) -> CString; + /// The property name, as a NUL-terminated C string. + fn key(&self) -> &'static CStr; fn set(&self) -> PropertySet; fn get(&self) -> Result { @@ -235,27 +230,94 @@ pub trait PropertyKey { } /// Macro to define a property key. -/// This macro generates a struct that implements the -/// PropertyKey trait. +/// +/// This macro generates a struct that implements the [`PropertyKey`] trait. +/// +/// The key can be given in two forms: +/// +/// * a string literal, to which the NUL terminator expected by the C API is +/// appended (`"gpd.ta.appID"`); +/// * a NUL-terminated byte-string constant, such as the `TA_PROP_STR_*` items +/// exported by `optee_utee_sys` (`raw::TA_PROP_STR_SINGLE_INSTANCE`). These +/// are generated from the OP-TEE headers, so prefer them over repeating the +/// string by hand. +/// +/// Keys are compile-time constants. `CStr::from_bytes_with_nul` is a `const` +/// function, so the conversion happens during const evaluation and a key that +/// is not NUL-terminated or has an interior NUL fails to compile. +/// +/// ``` +/// use optee_utee::define_property_key; +/// use optee_utee::property::PropertyKey; +/// use optee_utee::Uuid; +/// use optee_utee_sys as raw; +/// +/// define_property_key!(MyAppId, CurrentTa, "gpd.ta.appID", Uuid); +/// define_property_key!( +/// MySingleInstance, +/// CurrentTa, +/// raw::TA_PROP_STR_SINGLE_INSTANCE, +/// bool +/// ); +/// +/// fn main() { +/// assert_eq!(MyAppId.key().to_bytes(), b"gpd.ta.appID"); +/// assert_eq!( +/// MySingleInstance.key().to_bytes(), +/// b"gpd.ta.singleInstance" +/// ); +/// } +/// ``` +/// +/// A key with an interior NUL byte is rejected at compile time: +/// +/// ```compile_fail,E0080 +/// use optee_utee::define_property_key; +/// +/// define_property_key!(BadKey, CurrentTa, "gpd\0ta.appID", u32); +/// +/// fn main() {} +/// ``` +/// +/// So is a constant that is not NUL-terminated: +/// +/// ```compile_fail,E0080 +/// use optee_utee::define_property_key; +/// +/// const NOT_TERMINATED: &[u8; 3] = b"abc"; +/// define_property_key!(BadKey, CurrentTa, NOT_TERMINATED, u32); +/// +/// fn main() {} +/// ``` #[macro_export] macro_rules! define_property_key { - ( - $name:ident, - $set:ident, - $key:literal, - $output:ty - ) => { + ($name:ident, $set:ident, $key:literal, $output:ty) => { + // `concat!` appends the terminator without allocating. + $crate::define_property_key!(@key $name, $set, $output, concat!($key, "\0").as_bytes()); + }; + ($name:ident, $set:ident, $key:expr, $output:ty) => { + // The generated `TA_PROP_STR_*` constants already include it. + $crate::define_property_key!(@key $name, $set, $output, $key); + }; + (@key $name:ident, $set:ident, $output:ty, $bytes:expr) => { pub struct $name; - impl PropertyKey for $name { + impl $crate::property::PropertyKey for $name { type Output = $output; - fn key(&self) -> CString { - CString::new($key).unwrap_or_default() + fn key(&self) -> &'static ::core::ffi::CStr { + const KEY: &::core::ffi::CStr = + match ::core::ffi::CStr::from_bytes_with_nul($bytes) { + Ok(key) => key, + Err(_) => panic!( + "property key must be NUL-terminated without interior NUL bytes" + ), + }; + KEY } - fn set(&self) -> PropertySet { - PropertySet::$set + fn set(&self) -> $crate::property::PropertySet { + $crate::property::PropertySet::$set } } }; @@ -263,9 +325,15 @@ macro_rules! define_property_key { // Define all existing property keys for the TEE property set. // The format is: -// `define_property_key!(Name, Set, "key", OutputType);` +// `define_property_key!(Name, Set, Key, OutputType);` // The `Set` is one of the PropertySet it belongs to. -// The `key` is the raw property key string. +// The `Key` is either a string literal or a NUL-terminated `TA_PROP_STR_*` +// constant from `optee_utee_sys`; prefer the latter, as it is generated from +// the OP-TEE headers. The remaining `gpd.*` names have no macro counterpart: +// OP-TEE only spells them out as string literals in `core/tee/tee_svc.c` and +// `lib/libutee/tee_api_property.c`, which bindgen does not read. Only the +// properties those files implement are listed here; callers that need another +// name can define their own key with `define_property_key!`. // The `OutputType` is the type of the property value. // // To get the property value, use the `get` method. @@ -277,29 +345,44 @@ macro_rules! define_property_key { // let my_property = TaAppId.get()?; // ``` define_property_key!(TaAppId, CurrentTa, "gpd.ta.appID", Uuid); -define_property_key!(TaSingleInstance, CurrentTa, "gpd.ta.singleInstance", bool); -define_property_key!(TaMultiSession, CurrentTa, "gpd.ta.multiSession", bool); +define_property_key!( + TaSingleInstance, + CurrentTa, + raw::TA_PROP_STR_SINGLE_INSTANCE, + bool +); +define_property_key!( + TaMultiSession, + CurrentTa, + raw::TA_PROP_STR_MULTI_SESSION, + bool +); define_property_key!( TaInstanceKeepAlive, CurrentTa, - "gpd.ta.instanceKeepAlive", + raw::TA_PROP_STR_KEEP_ALIVE, bool ); define_property_key!( TaInstanceKeepCrashed, CurrentTa, - "gpd.ta.instanceKeepCrashed", + raw::TA_PROP_STR_KEEP_CRASHED, bool ); -define_property_key!(TaDataSize, CurrentTa, "gpd.ta.dataSize", u32); -define_property_key!(TaStackSize, CurrentTa, "gpd.ta.stackSize", u32); -define_property_key!(TaVersion, CurrentTa, "gpd.ta.version", String); -define_property_key!(TaDescription, CurrentTa, "gpd.ta.description", String); -define_property_key!(TaEndian, CurrentTa, "gpd.ta.endian", u32); +define_property_key!(TaDataSize, CurrentTa, raw::TA_PROP_STR_DATA_SIZE, u32); +define_property_key!(TaStackSize, CurrentTa, raw::TA_PROP_STR_STACK_SIZE, u32); +define_property_key!(TaVersion, CurrentTa, raw::TA_PROP_STR_VERSION, String); +define_property_key!( + TaDescription, + CurrentTa, + raw::TA_PROP_STR_DESCRIPTION, + String +); +define_property_key!(TaEndian, CurrentTa, raw::TA_PROP_STR_ENDIAN, u32); define_property_key!( TaDoesNotCloseHandleOnCorruptObject, CurrentTa, - "gpd.ta.doesNotCloseHandleOnCorruptObject", + raw::TA_PROP_STR_DOES_NOT_CLOSE_HANDLE_ON_CORRUPT_OBJECT, bool ); define_property_key!( @@ -347,58 +430,22 @@ define_property_key!( u32 ); define_property_key!( - TeeCryptographyEcc, - TeeImplementation, - "gpd.tee.cryptography.ecc", - bool -); -define_property_key!( - TeeCryptographyNist, - TeeImplementation, - "gpd.tee.cryptography.nist", - bool -); -define_property_key!( - TeeCryptographyBsiR, + TeeSocketsVersion, TeeImplementation, - "gpd.tee.cryptography.bsi-r", - bool -); -define_property_key!( - TeeCryptographyBsiT, - TeeImplementation, - "gpd.tee.cryptography.bsi-t", - bool -); -define_property_key!( - TeeCryptographyIetf, - TeeImplementation, - "gpd.tee.cryptography.ietf", - bool -); -define_property_key!( - TeeCryptographyOcta, - TeeImplementation, - "gpd.tee.cryptography.octa", - bool -); -define_property_key!( - TeeTrustedStoragePrivateRollbackProtection, - TeeImplementation, - "gpd.tee.trustedStorage.private.rollbackProtection", + "gpd.tee.sockets.version", u32 ); define_property_key!( - TeeTrustedStoragePersoRollbackProtection, + TeeSocketsTcpVersion, TeeImplementation, - "gpd.tee.trustedStorage.perso.rollbackProtection", + "gpd.tee.sockets.tcp.version", u32 ); define_property_key!( - TeeTrustedStorageProtectedRollbackProtection, + TeeCryptographyEcc, TeeImplementation, - "gpd.tee.trustedStorage.protected.rollbackProtection", - u32 + "gpd.tee.cryptography.ecc", + bool ); define_property_key!( TeeTrustedStorageAntiRollbackProtectionLevel, @@ -406,12 +453,6 @@ define_property_key!( "gpd.tee.trustedStorage.antiRollback.protectionLevel", u32 ); -define_property_key!( - TeeTrustedStorageRollbackDetectionProtectionLevel, - TeeImplementation, - "gpd.tee.trustedStorage.rollbackDetection.protectionLevel", - u32 -); define_property_key!( TeeTrustedOsImplementationVersion, TeeImplementation, @@ -448,9 +489,3 @@ define_property_key!( "gpd.tee.firmware.manufacturer", String ); -define_property_key!( - TeeEventMaxSources, - TeeImplementation, - "gpd.tee.event.maxSources", - u32 -); diff --git a/crates/optee-utee/src/tee_parameter.rs b/crates/optee-utee/src/tee_parameter.rs index c01ebe0b..4a13e4b2 100644 --- a/crates/optee-utee/src/tee_parameter.rs +++ b/crates/optee-utee/src/tee_parameter.rs @@ -115,37 +115,37 @@ impl<'a> Param<'a> { fn as_raw(&mut self) -> raw::TEE_Param { match &mut self.content { ParamContent::None => raw::TEE_Param { - memref: raw::Memref { + memref: raw::TEE_Param__bindgen_ty_1 { buffer: core::ptr::null_mut(), size: 0, }, }, ParamContent::MemrefInput { buffer } => raw::TEE_Param { - memref: raw::Memref { + memref: raw::TEE_Param__bindgen_ty_1 { buffer: (*buffer).as_ptr() as *mut core::ffi::c_void, size: buffer.len(), }, }, ParamContent::MemrefOutput { buffer, written: _ } => raw::TEE_Param { - memref: raw::Memref { + memref: raw::TEE_Param__bindgen_ty_1 { buffer: (*buffer).as_mut_ptr() as *mut core::ffi::c_void, size: buffer.len(), }, }, ParamContent::MemrefInout { buffer, written: _ } => raw::TEE_Param { - memref: raw::Memref { + memref: raw::TEE_Param__bindgen_ty_1 { buffer: (*buffer).as_mut_ptr() as *mut core::ffi::c_void, size: buffer.len(), }, }, ParamContent::ValueInput { a, b } => raw::TEE_Param { - value: raw::Value { a: *a, b: *b }, + value: raw::TEE_Param__bindgen_ty_2 { a: *a, b: *b }, }, ParamContent::ValueInout { a, b } => raw::TEE_Param { - value: raw::Value { a: *a, b: *b }, + value: raw::TEE_Param__bindgen_ty_2 { a: *a, b: *b }, }, ParamContent::ValueOutput { a, b } => raw::TEE_Param { - value: raw::Value { a: *a, b: *b }, + value: raw::TEE_Param__bindgen_ty_2 { a: *a, b: *b }, }, } } diff --git a/docs/ai-development.md b/docs/ai-development.md index b1538089..a2c4a2a0 100644 --- a/docs/ai-development.md +++ b/docs/ai-development.md @@ -46,7 +46,7 @@ Use the repository-pinned toolchain unless a task explicitly requires investigat - Do not assume a dependency is always enabled or a feature is enabled only for the crate being edited. Inspect feature definitions and the build paths that activate them. - If a feature-specific implementation replaces or excludes a dependency, consider both enabled and disabled configurations relevant to the change. - Keep host-side and TEE-side dependencies distinct. A crate that builds on the host may require a different target, toolchain, or environment when built for the TEE. -- `STD=y` affects environment setup. Set it before sourcing `environment` when configuring standard-library examples; see §8.3. +- `STD=y` affects environment setup. Set it before sourcing `environment` when configuring standard-library examples; see §8.2. - Avoid changing lockfiles or broad dependency constraints unless required by the task. - Keep `*-sys` crates as thin mappings of the underlying OP-TEE C interfaces; do not add unrelated high-level abstractions to them. @@ -210,26 +210,7 @@ To run the CI helper script, execute it from the `ci/` directory because it uses (cd ci && ./ci.sh) ``` -### 8.2 System Tests - -The `optee-teec-systest` system test is run as a CI job on an ARM64 host using the ARM64 OP-TEE client libraries: - -```bash -export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$OPTEE_DIR/optee_client/export_arm64/usr/lib" -cd crates -cargo run -p optee-teec-systest -``` - -The UTEE system-test build can be checked with: - -```bash -cd crates -cargo build -p optee-utee-systest -``` - -The TEEC system test runs on the host, while the UTEE command builds the trusted-side test crate. - -### 8.3 Examples and QEMU +### 8.2 Examples and QEMU Build no-std examples from the repository root: @@ -270,7 +251,7 @@ The repository's QEMU test scripts include `tests/test_*.sh`. Follow their curre If reproducing the `test-build-on-dev-docker` CI job, inspect its steps in `ci.yml`, including configuration switching and the `$RUST_STD_DIR` symlink setup. -### 8.4 Tools +### 8.3 Tools Run the `cargo-optee` tests from `tools/`: diff --git a/docs/crates-io-ownership.md b/docs/crates-io-ownership.md index 11125087..2c0ee243 100644 --- a/docs/crates-io-ownership.md +++ b/docs/crates-io-ownership.md @@ -22,7 +22,7 @@ when checking or changing crate ownership. > folded into the `mock` feature of [`optee-utee-sys`], which [`optee-utee`] > enables for host-side unit tests. -`optee-teec-systest`, `rustls_provider`, and `secure_db` are not published +`rustls_provider` and `secure_db` are not published (`publish = false`); the `cargo-optee` tool is not published either. ## Maintainers & crates.io owners diff --git a/docs/release-tips.md b/docs/release-tips.md index d11b3691..0b41aee0 100644 --- a/docs/release-tips.md +++ b/docs/release-tips.md @@ -43,6 +43,38 @@ The timeline is flexible and can be adjusted based on the actual circumstances. ## Specific for TrustZone SDK +### Check the bindings before bumping the release version + +The release candidate is what gets voted on, so the generated bindings and the +property list must be final before the version bump and the RC is cut; anything +found afterwards needs a new vote. When moving to a new OP-TEE release: + +1. Set `optee-version.txt` to the new release in the working tree and point + `TA_DEV_KIT_DIR` / `OPTEE_CLIENT_EXPORT` at exports built from it. +2. Regenerate both crates: + + ```bash + cargo run --manifest-path xtask/Cargo.toml -- generate-bindings all \ + --ta-dev-kit-dir /path/to/ta_dev_kit \ + --optee-client-dir /path/to/optee_client/export + ``` + +3. Review the result with `git diff`. Look for renamed or removed constants, + changed struct layouts, and new or removed functions, then adapt the + consumers in `optee-utee` / `optee-teec` and the items left in the + `handwritten.rs` files. The `utee` generator rejects a TA dev kit whose + version disagrees with `optee-version.txt`. + +The property keys in `crates/optee-utee/src/property.rs` need a manual pass as +well. They are not generated and intentionally cover only the properties OP-TEE +implements, so compare the list with the property tables in `core/tee/tee_svc.c` +and `lib/libutee/tee_api_property.c` of the new release: add new properties, +drop removed ones, and make sure the names still match. The `TA_PROP_STR_*` +macros in `user_ta_header.h` are already taken from `optee-utee-sys`. + +Once the bindings and the property list are settled, commit them together with +the version bump and cut the release candidate. + ### Publish on `crates.io` We maintain the optee-\* Rust crates at , diff --git a/docs/security-model.md b/docs/security-model.md index 3fc314a9..6d290db6 100644 --- a/docs/security-model.md +++ b/docs/security-model.md @@ -110,7 +110,8 @@ type-erased `ParametersAny<'_>` — before your TA logic runs. Normal-World memory. Validate the values; there is no pointer/length to worry about. - **`ParameterMemrefInput` / `ParameterMemrefInout` / `ParameterMemrefOutput`** - — a **shared-memory reference**: a `{buffer, size}` pair (`raw::Memref`). + — a **shared-memory reference**: a `{buffer, size}` pair (the `memref` + member of `TEE_Param`). This is the high-risk case. The typed API is copy-based: reads go through `ParameterMemrefRead::read_to_vec` (whole buffer) / `read_at` (partial range) and writes through `ParameterMemrefWrite::set_output` / `write_at`, @@ -168,7 +169,7 @@ applies to a file. This is the key reference for an automated reviewer. | `crates/optee-teec/` | CA library (Normal World) | **Untrusted side** | This runs in the adversary's world. "Missing input validation" here is generally **not** a TA-security finding — the TA cannot trust this code regardless. Focus instead on memory safety and not mishandling secrets returned to the CA. | | `crates/optee-teec-sys/` | Raw FFI for the CA | Untrusted side / FFI | FFI correctness only. | | `crates/secure_db/`, `crates/rustls_provider/` | Run inside the TA | **Trusted, but process untrusted data** | Logic runs in the TEE, but inputs (DB contents persisted via Normal World storage, bytes from a TLS peer) originate outside the TCB. Apply the boundary invariants to those inputs. | -| `crates/*-build`, `*-macros`, `*-systest` | Build-time / test tooling | Build-time | Not in the runtime TCB. Review as ordinary tooling, not as boundary code. | +| `crates/*-build`, `*-macros` | Build-time / test tooling | Build-time | Not in the runtime TCB. Review as ordinary tooling, not as boundary code. | | `examples/` | Illustrative TA+CA pairs | **Illustrative, not hardened** | Demonstrate API usage. They are teaching material and may intentionally omit production hardening; do not report them as if they were production code, but *do* note where they model an unsafe pattern a developer might copy. | | `projects/` | Reference applications (e.g. `web3/eth_wallet`) | **Reference, with stated assumptions** | Read the project's own "Security Assumptions" section first; review against *that* stated threat model. | | `tests/`, `.patches/`, `tools/` | Test harness / tooling | Build/test-time | Not runtime TCB. | diff --git a/crates/optee-utee-build/src/license_str.txt b/license_header.txt similarity index 100% rename from crates/optee-utee-build/src/license_str.txt rename to license_header.txt diff --git a/xtask/Cargo.lock b/xtask/Cargo.lock new file mode 100644 index 00000000..1a622076 --- /dev/null +++ b/xtask/Cargo.lock @@ -0,0 +1,375 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "aho-corasick" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c982642fa9e8606056828ee9a8505737230110bb1099153c79efe865c59d12ba" +dependencies = [ + "memchr", +] + +[[package]] +name = "anstream" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000" + +[[package]] +name = "anstyle-parse" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" +dependencies = [ + "anstyle", + "once_cell_polyfill", + "windows-sys", +] + +[[package]] +name = "bindgen" +version = "0.72.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "993776b509cfb49c750f11b8f07a46fa23e0a1386ffc01fb1e7d343efc387895" +dependencies = [ + "bitflags", + "cexpr", + "clang-sys", + "itertools", + "log", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn 2.0.119", +] + +[[package]] +name = "bitflags" +version = "2.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" + +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + +[[package]] +name = "cfg-if" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" + +[[package]] +name = "clang-sys" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "157a8ba7b480713b56f4c09fd13fc3e0a22a5dfab8097ba61cbc5feef950788a" +dependencies = [ + "glob", + "libc", + "libloading", +] + +[[package]] +name = "clap" +version = "4.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa8876b300ab35ba921adea3dfd70157a46249b33f95c9084ae5709785478946" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0797fb7aeb1406c84efac526901f7ec3ead2124f946b494e72879d4b54704d" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9c751b79415d4e559e3d1fcf128e09e720eb673a06d26cf6f392d37d75b66e0" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "clap_lex" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c133bc6a41be0d194c306b5506d15e6feeea7b1d6604bd3f8310dfb2ca96486" + +[[package]] +name = "colorchoice" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" + +[[package]] +name = "either" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e9c71c2167ca323c882b99918929403426e2373ea17242ff5653e0d5e1058be" + +[[package]] +name = "glob" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4eba85ea1d0a966a983acd07deee566e67395d2d96b6fb39e62b5a833f1eb0b" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" + +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + +[[package]] +name = "libc" +version = "0.2.191" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" + +[[package]] +name = "libloading" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55" +dependencies = [ + "cfg-if", + "windows-link", +] + +[[package]] +name = "log" +version = "0.4.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c" + +[[package]] +name = "memchr" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "once_cell_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" + +[[package]] +name = "prettyplease" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" +dependencies = [ + "proc-macro2", + "syn 2.0.119", +] + +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "regex" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f020237b6c8eed93db2e2cb53c00c60a8e1bc73da7d073199a1180401450218d" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad8553b9b26413251cbf30e620595c7a41b3887f03da04579c0e6b0d6a06b4b2" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4" + +[[package]] +name = "rustc-hash" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d" + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "syn" +version = "2.0.119" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "3.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "xtask" +version = "0.1.0" +dependencies = [ + "bindgen", + "clap", +] diff --git a/crates/optee-teec-systest/Cargo.toml b/xtask/Cargo.toml similarity index 72% rename from crates/optee-teec-systest/Cargo.toml rename to xtask/Cargo.toml index d055da2e..334e8ac5 100644 --- a/crates/optee-teec-systest/Cargo.toml +++ b/xtask/Cargo.toml @@ -16,17 +16,11 @@ # under the License. [package] -name = "optee-teec-systest" -description = "Automatic testing of FFI bindings for the libteec library." -version.workspace = true -authors.workspace = true -license.workspace = true -repository.workspace = true -edition.workspace = true +name = "xtask" +version = "0.1.0" +edition = "2024" publish = false [dependencies] -optee-teec-sys.workspace = true - -[build-dependencies] -ctest = { workspace = true } +bindgen = "0.72.1" +clap = { version = "4.6", features = ["derive", "env"] } diff --git a/xtask/src/generate_bindings/mod.rs b/xtask/src/generate_bindings/mod.rs new file mode 100644 index 00000000..c7c4b7c6 --- /dev/null +++ b/xtask/src/generate_bindings/mod.rs @@ -0,0 +1,68 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! The `generate-bindings` command: regenerate the committed bindings of the +//! `*-sys` crates. +//! +//! One subcommand per system crate: `utee` covers `optee-utee-sys` (TA dev kit +//! headers), `teec` covers `optee-teec-sys` (client headers), and `all` runs +//! both. + +mod teec; +mod utee; + +use std::error::Error; + +/// The target used for generation. The generated types do not depend on the +/// pointer width (C `size_t` becomes `usize`, `long` becomes `c_long`, pointers +/// stay pointers), so one run is valid for both 32-bit and 64-bit targets. +const TARGET: &str = "aarch64-unknown-linux-gnu"; + +/// Apache license header prepended to every generated file. +const LICENSE_HEADER: &str = include_str!("../../../license_header.txt"); + +#[derive(clap::Args)] +pub(crate) struct Args { + #[command(subcommand)] + target: Target, +} + +#[derive(clap::Subcommand)] +enum Target { + /// Regenerate both crates. + All { + #[command(flatten)] + teec: teec::TeecArgs, + #[command(flatten)] + utee: utee::UteeArgs, + }, + /// Regenerate `crates/optee-teec-sys/src/generated.rs` from the client headers. + Teec(teec::TeecArgs), + /// Regenerate `crates/optee-utee-sys/src/generated.rs` from the TA dev kit. + Utee(utee::UteeArgs), +} + +pub(crate) fn run(args: Args) -> Result<(), Box> { + match args.target { + Target::All { teec, utee } => { + teec::run(teec)?; + utee::run(utee) + } + Target::Teec(args) => teec::run(args), + Target::Utee(args) => utee::run(args), + } +} diff --git a/xtask/src/generate_bindings/teec/generate.rs b/xtask/src/generate_bindings/teec/generate.rs new file mode 100644 index 00000000..12ec1a89 --- /dev/null +++ b/xtask/src/generate_bindings/teec/generate.rs @@ -0,0 +1,66 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! bindgen pass over the OP-TEE client headers. + +use std::error::Error; +use std::path::Path; + +/// Headers from the OP-TEE client export's `usr/include/` directory. +/// +/// `tee_plugin_method.h` includes `tee_client_api.h`, so these two cover the +/// whole client ABI. +const HEADERS: &[&str] = &["tee_client_api.h", "tee_plugin_method.h"]; + +fn bindgen_builder(include_dir: &Path, target: &str) -> bindgen::Builder { + let mut builder = bindgen::Builder::default() + .clang_arg(format!("-I{}", include_dir.display())) + .clang_arg(format!("--target={target}")) + .clang_arg("-ffreestanding") + .use_core() + .wrap_unsafe_ops(true) + .formatter(bindgen::Formatter::Prettyplease); + + for header in HEADERS { + builder = builder.header(include_dir.join(header).display().to_string()); + } + + builder +} + +/// Generates the bindings. +/// +/// Types, constants and functions all come from one bindgen run: unlike the TA +/// side, the client crate has no `mock` feature that would need the functions +/// wrapped in a module. +pub(super) fn generate(include_dir: &Path, target: &str) -> Result> { + let bindings = bindgen_builder(include_dir, target) + .allowlist_type("TEEC_.*") + .allowlist_type("plugin_method") + .allowlist_var("TEEC_.*") + .allowlist_var("TEE_ERROR_.*") + .allowlist_function("TEEC_.*") + // Error constants are aliases (`TEEC_ERROR_TARGET_DEAD` -> + // `TEE_ERROR_TARGET_DEAD`) and `TEEC_CONFIG_SHAREDMEM_MAX_SIZE` is + // `ULONG_MAX`, neither of which bindgen's token parser can evaluate. + .clang_macro_fallback() + // See the `utee` generator: the types are target independent, and the + // assertions would tie the output to the machine that ran bindgen. + .layout_tests(false) + .generate()?; + Ok(bindings.to_string()) +} diff --git a/xtask/src/generate_bindings/teec/generated_header.in b/xtask/src/generate_bindings/teec/generated_header.in new file mode 100644 index 00000000..99050310 --- /dev/null +++ b/xtask/src/generate_bindings/teec/generated_header.in @@ -0,0 +1,4 @@ +// @generated by `cargo run --manifest-path xtask/Cargo.toml -- generate-bindings teec` +// from the OP-TEE client headers. Do not edit by hand. +// +// Regenerate after changing the OP-TEE version in optee-version.txt. diff --git a/xtask/src/generate_bindings/teec/mod.rs b/xtask/src/generate_bindings/teec/mod.rs new file mode 100644 index 00000000..2b90c1bb --- /dev/null +++ b/xtask/src/generate_bindings/teec/mod.rs @@ -0,0 +1,75 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! `generate-bindings teec`: produce `crates/optee-teec-sys/src/generated.rs` +//! from the OP-TEE client headers. + +mod generate; + +use std::error::Error; +use std::fs; +use std::path::{Path, PathBuf}; + +use super::{LICENSE_HEADER, TARGET}; +use generate::generate; + +/// Note placed after the license header. +const GENERATED_HEADER: &str = include_str!("generated_header.in"); + +/// Committed bindings, relative to the repository root. +const OUTPUT: &str = "crates/optee-teec-sys/src/generated.rs"; + +#[derive(clap::Args)] +pub(super) struct TeecArgs { + /// OP-TEE client export directory (the one containing `usr/include/`). + #[arg(long, env = "OPTEE_CLIENT_EXPORT")] + optee_client_dir: Option, +} + +pub(super) fn run(args: TeecArgs) -> Result<(), Box> { + let repo_root = Path::new(env!("CARGO_MANIFEST_DIR")) + .parent() + .ok_or("xtask has no parent directory")?; + + let optee_client_dir = args + .optee_client_dir + .ok_or("OPTEE_CLIENT_EXPORT is not set; pass --optee-client-dir")?; + let include_dir = optee_client_dir.join("usr/include"); + if !include_dir.is_dir() { + return Err(format!( + "{} is not a directory; check OPTEE_CLIENT_EXPORT", + include_dir.display() + ) + .into()); + } + + let bindings = generate(&include_dir, TARGET)?; + + let mut output = String::new(); + output.push_str(LICENSE_HEADER); + output.push('\n'); + output.push_str(GENERATED_HEADER); + output.push('\n'); + output.push_str(&bindings); + + let output_path = repo_root.join(OUTPUT); + + fs::write(&output_path, output)?; + println!("wrote {}", output_path.display()); + + Ok(()) +} diff --git a/xtask/src/generate_bindings/utee/generate.rs b/xtask/src/generate_bindings/utee/generate.rs new file mode 100644 index 00000000..6bbe3ddf --- /dev/null +++ b/xtask/src/generate_bindings/utee/generate.rs @@ -0,0 +1,147 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! bindgen passes over the TA dev kit headers. + +use std::error::Error; +use std::path::Path; + +/// Headers from the OP-TEE TA dev kit `include/` directory. +/// +/// Only the top-level headers are listed; everything else comes in through +/// their `#include`s. The count matters: bindgen's macro fallback names its +/// precompiled header after all inputs but the last, and with more than about a +/// dozen names the filename exceeds the filesystem limit, silently disabling +/// the fallback (and with it the `TEE_ALG_ECDSA_P*` / `TEE_ALG_ECDH_P*` +/// aliases). +const HEADERS: &[&str] = &[ + "tee_api.h", + "tee_internal_api_extensions.h", + "tee_isocket.h", + "tee_tcpsocket.h", + "tee_udpsocket.h", + "user_ta_header.h", + "utee_syscalls.h", + "utee_defines.h", + "trace.h", + "__tee_tcpsocket_defines_extensions.h", +]; + +/// Creates the bindgen builder shared by every pass: the full header list, the +/// target triple, `no_std` (`use_core`), and the prettyplease formatter so the +/// committed output is stable. +fn bindgen_builder(include_dir: &Path, target: &str) -> bindgen::Builder { + let mut builder = bindgen::Builder::default() + .clang_arg(format!("-I{}", include_dir.display())) + .clang_arg(format!("--target={target}")) + .clang_arg("-ffreestanding") + .use_core() + .wrap_unsafe_ops(true) + .formatter(bindgen::Formatter::Prettyplease); + + for header in HEADERS { + builder = builder.header(include_dir.join(header).display().to_string()); + } + + builder +} + +/// Generates the bindings. +/// +/// Types, constants and the two used libutee syscalls come from one bindgen run. +/// The mockable API and trace functions are generated in a second run, wrapped in +/// a module so `#[automock]` can produce the crate's `mock_api`. +pub(super) fn generate(include_dir: &Path, target: &str) -> Result> { + let bindings = bindgen_builder(include_dir, target) + .default_enum_style(bindgen::EnumVariation::Rust { + non_exhaustive: false, + }) + // Types. + .allowlist_type("TEE_.*") + .allowlist_type("utee_.*") + .allowlist_type("ta_head") + .allowlist_type("user_ta_.*") + .allowlist_type("__TEE_.*") + .allowlist_type("intmax_t") + // Constants. + .allowlist_var("TEE_.*") + .allowlist_var("TA_FLAGS_MASK") + .allowlist_var("TA_PROP_STR_.*") + // `TA_FLAG_*` values are object-like macros whose bodies call `BIT32`; + // clang resolves them through the macro fallback below. + .allowlist_var("TA_FLAG_.*") + // Only these two libutee syscalls are used by the Rust TA; the rest of + // `utee_syscalls.h` is libutee's own business. `_utee_return` returns + // `!`, so it must stay out of the mocked `api` module below. + .allowlist_function("_utee_log|_utee_return") + // Some deprecated constants are aliases of other macros, for example + // `TEE_ALG_ECDSA_P192` -> `TEE_ALG_ECDSA_SHA1`. bindgen's token parser + // cannot evaluate those, so let clang resolve them. + .clang_macro_fallback() + // Layout assertions only repeat the target's own ABI: the generated + // types are the same on every target (C `size_t` is `usize`, `long` is + // `c_long`, pointers are pointers) and `#[repr(C)]` does the rest. + // Keeping them would make the output depend on the target used here. + .layout_tests(false) + .generate()?; + + let mut output = bindings.to_string(); + + // All mockable functions live in one module; `#[automock]` generates the + // crate's `mock_api` next to it. + let functions = generate_functions( + include_dir, + target, + &[ + "TEE_.*", + "tee_invoke_supp_plugin", + "trace_ext_puts", + "trace_ext_get_thread_id", + "trace_set_level", + "trace_get_level", + "trace_printf", + "dhex_dump", + ], + )?; + let api_module = [ + "", + "#[allow(unused_imports)]", + "#[cfg_attr(feature = \"mock\", mockall::automock)]", + "pub mod api {", + " use super::*;", + functions.as_str(), + "}", + "", + ]; + output.push_str(&api_module.join("\n")); + + Ok(output) +} + +fn generate_functions( + include_dir: &Path, + target: &str, + allowlist: &[&str], +) -> Result> { + let mut builder = bindgen_builder(include_dir, target) + .blocklist_type(".*") + .blocklist_var(".*"); + for pattern in allowlist { + builder = builder.allowlist_function(pattern); + } + Ok(builder.generate()?.to_string()) +} diff --git a/xtask/src/generate_bindings/utee/generated_header.in b/xtask/src/generate_bindings/utee/generated_header.in new file mode 100644 index 00000000..42994f0e --- /dev/null +++ b/xtask/src/generate_bindings/utee/generated_header.in @@ -0,0 +1,4 @@ +// @generated by `cargo run --manifest-path xtask/Cargo.toml -- generate-bindings utee` +// from the OP-TEE TA dev kit headers. Do not edit by hand. +// +// Regenerate after changing the OP-TEE version in optee-version.txt. diff --git a/xtask/src/generate_bindings/utee/mod.rs b/xtask/src/generate_bindings/utee/mod.rs new file mode 100644 index 00000000..05561d0d --- /dev/null +++ b/xtask/src/generate_bindings/utee/mod.rs @@ -0,0 +1,85 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! `generate-bindings utee`: produce `crates/optee-utee-sys/src/generated.rs` +//! from the OP-TEE TA dev kit headers. + +mod generate; +mod verify; + +use std::error::Error; +use std::fs; +use std::path::{Path, PathBuf}; + +use super::{LICENSE_HEADER, TARGET}; +use generate::generate; +use verify::check_optee_version; + +/// Note placed after the license header. +const GENERATED_HEADER: &str = include_str!("generated_header.in"); + +/// Committed bindings, relative to the repository root. +const OUTPUT: &str = "crates/optee-utee-sys/src/generated.rs"; + +#[derive(clap::Args)] +pub(super) struct UteeArgs { + /// OP-TEE TA dev kit directory (the one containing `include/`). + #[arg(long, env = "TA_DEV_KIT_DIR")] + ta_dev_kit_dir: Option, +} + +pub(super) fn run(args: UteeArgs) -> Result<(), Box> { + let repo_root = Path::new(env!("CARGO_MANIFEST_DIR")) + .parent() + .ok_or("xtask has no parent directory")?; + + let version = fs::read_to_string(repo_root.join("optee-version.txt"))?; + let version = version.trim(); + if version.is_empty() { + return Err("optee-version.txt is empty".into()); + } + + let ta_dev_kit_dir = args + .ta_dev_kit_dir + .ok_or("TA_DEV_KIT_DIR is not set; pass --ta-dev-kit-dir")?; + let include_dir = ta_dev_kit_dir.join("include"); + if !include_dir.is_dir() { + return Err(format!( + "{} is not a directory; check TA_DEV_KIT_DIR", + include_dir.display() + ) + .into()); + } + + check_optee_version(version, &ta_dev_kit_dir)?; + + let bindings = generate(&include_dir, TARGET)?; + + let mut output = String::new(); + output.push_str(LICENSE_HEADER); + output.push('\n'); + output.push_str(GENERATED_HEADER); + output.push('\n'); + output.push_str(&bindings); + + let output_path = repo_root.join(OUTPUT); + + fs::write(&output_path, output)?; + println!("wrote {}", output_path.display()); + + Ok(()) +} diff --git a/xtask/src/generate_bindings/utee/verify.rs b/xtask/src/generate_bindings/utee/verify.rs new file mode 100644 index 00000000..c155f2a8 --- /dev/null +++ b/xtask/src/generate_bindings/utee/verify.rs @@ -0,0 +1,68 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! Check run before generating bindings: the TA dev kit version. + +use std::error::Error; +use std::fs; +use std::path::Path; + +/// Fails unless the TA dev kit was exported from the OP-TEE release pinned in +/// `optee-version.txt`. +/// +/// The version is read from `host_include/conf.mk`, which every exported dev kit +/// carries (`# TEE version X.Y.Z`), so no OP-TEE source checkout is needed. A +/// dev kit that does not expose the version is only a warning: there is nothing +/// to compare against, but the headers may still be usable. +pub(super) fn check_optee_version( + expected: &str, + ta_dev_kit_dir: &Path, +) -> Result<(), Box> { + let path = ta_dev_kit_dir.join("host_include/conf.mk"); + let Ok(conf) = fs::read_to_string(&path) else { + eprintln!( + "warning: cannot read {}; skipping the version check against optee-version.txt \ + ({expected})", + path.display() + ); + return Ok(()); + }; + + const VERSION_PREFIX: &str = "# TEE version "; + let Some(found) = conf + .lines() + .find_map(|line| line.strip_prefix(VERSION_PREFIX)) + else { + eprintln!( + "warning: {} has no `# TEE version` line; skipping the version check against \ + optee-version.txt ({expected})", + path.display() + ); + return Ok(()); + }; + + let found = found.trim(); + if found != expected { + return Err(format!( + "the TA dev kit is from OP-TEE {found}, but optee-version.txt requests {expected}; \ + export the dev kit from the {expected} tag or update optee-version.txt" + ) + .into()); + } + + Ok(()) +} diff --git a/xtask/src/main.rs b/xtask/src/main.rs new file mode 100644 index 00000000..6e32db8a --- /dev/null +++ b/xtask/src/main.rs @@ -0,0 +1,50 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! Repository maintenance tasks. +//! +//! ```text +//! cargo run --manifest-path xtask/Cargo.toml -- generate-bindings all +//! cargo run --manifest-path xtask/Cargo.toml -- generate-bindings utee +//! cargo run --manifest-path xtask/Cargo.toml -- generate-bindings teec +//! ``` + +mod generate_bindings; + +use std::error::Error; + +use clap::{Parser, Subcommand}; + +#[derive(Parser)] +#[command(name = "xtask", about = "Repository maintenance tasks")] +struct Cli { + #[command(subcommand)] + command: Command, +} + +#[derive(Subcommand)] +enum Command { + /// Regenerate the committed bindings of the `*-sys` crates. + GenerateBindings(generate_bindings::Args), +} + +fn main() -> Result<(), Box> { + let cli = Cli::parse(); + match cli.command { + Command::GenerateBindings(args) => generate_bindings::run(args), + } +}