psa-crypto-sys-0.9.3/.cargo_vcs_info.json 0000644 00000000154 00000000001 0013762 0 ustar {
"git": {
"sha1": "833f949b367713f8e23815cdb020c718b093ce3e"
},
"path_in_vcs": "psa-crypto-sys"
} psa-crypto-sys-0.9.3/.gitignore 0000644 0000000 0000000 00000000021 10461020230 0014533 0 ustar 0000000 0000000 target
Cargo.lock psa-crypto-sys-0.9.3/Cargo.toml 0000644 00000002276 00000000001 0011767 0 ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.
[package]
edition = "2018"
name = "psa-crypto-sys"
version = "0.9.3"
authors = ["Parsec Project Contributors"]
links = "mbedcrypto"
description = "Wrapper around the PSA Cryptography API"
readme = "README.md"
keywords = [
"psa",
"crypto",
"cryptography",
]
categories = [
"api-bindings",
"external-ffi-bindings",
"cryptography",
]
license = "Apache-2.0"
repository = "https://github.com/parallaxsecond/rust-psa-crypto"
[build-dependencies.bindgen]
version = "0.59.2"
optional = true
[build-dependencies.cc]
version = "1.0.59"
[build-dependencies.cmake]
version = "0.1.44"
[build-dependencies.walkdir]
version = "2.3.1"
[features]
default = ["operations"]
interface = ["bindgen"]
operations = ["interface"]
static = []
psa-crypto-sys-0.9.3/Cargo.toml.orig 0000644 00000001172 00000000001 0012720 0 ustar [package]
name = "psa-crypto-sys"
version = "0.9.3"
authors = ["Parsec Project Contributors"]
edition = "2018"
description = "Wrapper around the PSA Cryptography API"
readme = "README.md"
keywords = ["psa", "crypto", "cryptography"]
categories = ["api-bindings", "external-ffi-bindings", "cryptography"]
license = "Apache-2.0"
repository = "https://github.com/parallaxsecond/rust-psa-crypto"
links = "mbedcrypto"
[build-dependencies]
bindgen = { version = "0.59.2", optional = true }
cc = "1.0.59"
cmake = "0.1.44"
walkdir = "2.3.1"
[features]
default = ["operations"]
static = []
interface = ["bindgen"]
operations = ["interface"]
psa-crypto-sys-0.9.3/Cargo.toml.orig 0000644 0000000 0000000 00000001172 10461020230 0015442 0 ustar 0000000 0000000 [package]
name = "psa-crypto-sys"
version = "0.9.3"
authors = ["Parsec Project Contributors"]
edition = "2018"
description = "Wrapper around the PSA Cryptography API"
readme = "README.md"
keywords = ["psa", "crypto", "cryptography"]
categories = ["api-bindings", "external-ffi-bindings", "cryptography"]
license = "Apache-2.0"
repository = "https://github.com/parallaxsecond/rust-psa-crypto"
links = "mbedcrypto"
[build-dependencies]
bindgen = { version = "0.59.2", optional = true }
cc = "1.0.59"
cmake = "0.1.44"
walkdir = "2.3.1"
[features]
default = ["operations"]
static = []
interface = ["bindgen"]
operations = ["interface"]
psa-crypto-sys-0.9.3/LICENSE 0000644 0000000 0000000 00000026136 10461020230 0013567 0 ustar 0000000 0000000
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed 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.
psa-crypto-sys-0.9.3/README.md 0000644 0000000 0000000 00000005071 10461020230 0014034 0 ustar 0000000 0000000 # PSA Cryptography API Rust Wrapper
This is the lower-level wrapper that exposes a minimal low-level C
interface to Rust.
## Dependencies
This crate exposes an interface for the PSA Crypto API and thus
links to libraries that expose this interface. The expected name
of the library is derived from the reference implementation of the
API - `mbedcrypto`.
If the library and its headers folder are already installed locally you can
specify their location (the full absolute path) using the `MBEDTLS_LIB_DIR` and
`MBEDTLS_INCLUDE_DIR` environment variables at build time. By default dynamic
linking is attempted - if you wish to link statically you can enable the
`static` feature or pass the `MBEDCRYPTO_STATIC` environment variable, set to
any value.
Alternatively, the crate will attempt to build the library from scratch and
link against it statically. In this use case enabling the `static` feature
makes no difference and there is no way to allow dynamic linking. The
requirements for configuring and building MbedTLS can be found
[on their repository homepage](https://github.com/ARMmbed/mbedtls#tool-versions).
Linking and generating implementation-specific APIs is controlled by the
`operations` feature that is enabled by default. Therefore, if you
require only the specification-defined bits of the API (namely the constants and types)
you can simply disable default features.
You might want to only use the interface part (including the
implementation-defined bits) of this crate to build for example a PSA Secure
Element Driver. With the feature `interface`, this crate will only produce the
implementation-defined types and their helpers/accessors using the
`MBEDTLS_INCLUDE_DIR` variable that you need to pass.
## Cross-compilation
The `interface` and `operations` features need a C toolchain. When cross-compiling, the
appropriate C toolchain will automatically be selected. Compilation will fail if it is
not available on your system.
The CI currently tests cross-compilation for the following targets:
- `aarch64-unknown-linux-gnu`
- `armv7-unknown-linux-gnueabihf`
psa-crypto-sys-0.9.3/build.rs 0000644 0000000 0000000 00000017316 10461020230 0014227 0 ustar 0000000 0000000 // Copyright 2020 Contributors to the Parsec project.
// SPDX-License-Identifier: Apache-2.0
#![deny(
nonstandard_style,
const_err,
dead_code,
improper_ctypes,
non_shorthand_field_patterns,
no_mangle_generic_items,
overflowing_literals,
path_statements,
patterns_in_fns_without_body,
private_in_public,
unconditional_recursion,
unused,
unused_allocation,
unused_comparisons,
unused_parens,
while_true,
missing_debug_implementations,
trivial_casts,
trivial_numeric_casts,
unused_extern_crates,
unused_import_braces,
unused_qualifications,
unused_results,
missing_copy_implementations
)]
// This one is hard to avoid.
#![allow(clippy::multiple_crate_versions)]
fn main() -> std::io::Result<()> {
#[cfg(feature = "operations")]
return operations::script_operations();
#[cfg(all(feature = "interface", not(feature = "operations")))]
return interface::script_interface();
#[cfg(not(any(feature = "interface", feature = "operations")))]
Ok(())
}
#[cfg(any(feature = "interface", feature = "operations"))]
mod common {
use std::env;
use std::io::{Error, ErrorKind, Result};
use std::path::{Path, PathBuf};
pub fn configure_mbed_crypto() -> Result<()> {
let mbedtls_dir = String::from("./vendor");
let mbedtls_config = mbedtls_dir + "/scripts/config.py";
println!("cargo:rerun-if-changed=src/c/shim.c");
println!("cargo:rerun-if-changed=src/c/shim.h");
let out_dir = env::var("OUT_DIR").unwrap();
// Check for Mbed TLS sources
if !Path::new(&mbedtls_config).exists() {
return Err(Error::new(
ErrorKind::Other,
"MbedTLS config.py is missing. Have you run 'git submodule update --init'?",
));
}
// Configure the MbedTLS build for making Mbed Crypto
if !::std::process::Command::new(mbedtls_config)
.arg("--write")
.arg(&(out_dir + "/config.h"))
.arg("crypto")
.status()
.map_err(|_| Error::new(ErrorKind::Other, "configuring mbedtls failed"))?
.success()
{
return Err(Error::new(
ErrorKind::Other,
"config.py returned an error status",
));
}
Ok(())
}
pub fn generate_mbed_crypto_bindings(mbed_include_dir: String) -> Result<()> {
let header = mbed_include_dir.clone() + "/psa/crypto.h";
println!("cargo:rerun-if-changed={}", header);
let out_dir = env::var("OUT_DIR").unwrap();
let shim_bindings = bindgen::Builder::default()
.clang_arg(format!("-I{}", out_dir))
.clang_arg("-DMBEDTLS_CONFIG_FILE=")
.clang_arg(format!("-I{}", mbed_include_dir))
.rustfmt_bindings(true)
.header("src/c/shim.h")
.blocklist_type("max_align_t")
.generate_comments(false)
.size_t_is_usize(true)
.generate()
.map_err(|_| {
Error::new(
ErrorKind::Other,
"Unable to generate bindings to mbed crypto",
)
})?;
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
shim_bindings.write_to_file(out_path.join("shim_bindings.rs"))?;
Ok(())
}
pub fn compile_shim_library(include_dir: String) -> Result<()> {
let out_dir = env::var("OUT_DIR").unwrap();
// Compile and package the shim library
cc::Build::new()
.include(&out_dir)
.define("MBEDTLS_CONFIG_FILE", "")
.include(include_dir)
.file("./src/c/shim.c")
.warnings(true)
.flag("-Werror")
.opt_level(2)
.try_compile("libshim.a")
.map_err(|_| Error::new(ErrorKind::Other, "compiling shim.c failed"))?;
// Also link shim library
println!("cargo:rustc-link-search=native={}", out_dir);
println!("cargo:rustc-link-lib=static=shim");
Ok(())
}
}
#[cfg(all(feature = "interface", not(feature = "operations")))]
mod interface {
use super::common;
use std::env;
use std::io::{Error, ErrorKind, Result};
// Build script when the interface feature is on and not the operations one
pub fn script_interface() -> Result<()> {
if let Ok(include_dir) = env::var("MBEDTLS_INCLUDE_DIR") {
common::configure_mbed_crypto()?;
common::generate_mbed_crypto_bindings(include_dir.clone())?;
common::compile_shim_library(include_dir)
} else {
Err(Error::new(
ErrorKind::Other,
"interface feature necessitates MBEDTLS_INCLUDE_DIR environment variable",
))
}
}
}
#[cfg(feature = "operations")]
mod operations {
use super::common;
use cmake::Config;
use std::env;
use std::io::{Error, ErrorKind, Result};
use std::path::PathBuf;
use walkdir::WalkDir;
fn compile_mbed_crypto() -> Result {
let mbedtls_dir = String::from("./vendor");
let out_dir = env::var("OUT_DIR").unwrap();
// Rerun build if any file under the vendor directory has changed.
for entry in WalkDir::new(&mbedtls_dir)
.into_iter()
.filter_map(|entry| entry.ok())
{
if let Ok(metadata) = entry.metadata() {
if metadata.is_file() {
println!("cargo:rerun-if-changed={}", entry.path().display());
}
}
}
// Build the MbedTLS libraries
let mbed_build_path = Config::new(&mbedtls_dir)
.cflag(format!("-I{}", out_dir))
.cflag("-DMBEDTLS_CONFIG_FILE=''")
.define("ENABLE_PROGRAMS", "OFF")
.define("ENABLE_TESTING", "OFF")
.build();
Ok(mbed_build_path)
}
fn link_to_lib(lib_path: String, link_statically: bool) {
let link_type = if link_statically { "static" } else { "dylib" };
// Request rustc to link the Mbed Crypto library
println!("cargo:rustc-link-search=native={}", lib_path,);
println!("cargo:rustc-link-lib={}=mbedcrypto", link_type);
}
// Build script when the operations feature is on
pub fn script_operations() -> Result<()> {
let lib;
let statically;
let include;
if env::var("MBEDTLS_LIB_DIR").is_err() ^ env::var("MBEDTLS_INCLUDE_DIR").is_err() {
return Err(Error::new(
ErrorKind::Other,
"both environment variables MBEDTLS_LIB_DIR and MBEDTLS_INCLUDE_DIR need to be set for operations feature",
));
}
common::configure_mbed_crypto()?;
if let (Ok(lib_dir), Ok(include_dir)) =
(env::var("MBEDTLS_LIB_DIR"), env::var("MBEDTLS_INCLUDE_DIR"))
{
lib = lib_dir;
include = include_dir;
statically = cfg!(feature = "static") || env::var("MBEDCRYPTO_STATIC").is_ok();
} else {
println!("Did not find environment variables, building MbedTLS!");
let mut mbed_lib_dir = compile_mbed_crypto()?;
let mut mbed_include_dir = mbed_lib_dir.clone();
mbed_lib_dir.push("lib");
mbed_include_dir.push("include");
lib = mbed_lib_dir.to_str().unwrap().to_owned();
include = mbed_include_dir.to_str().unwrap().to_owned();
statically = true;
}
// Linking to PSA Crypto library is only needed for the operations.
link_to_lib(lib, statically);
common::generate_mbed_crypto_bindings(include.clone())?;
common::compile_shim_library(include)
}
}
psa-crypto-sys-0.9.3/src/c/shim.c 0000644 0000000 0000000 00000023341 10461020230 0014672 0 ustar 0000000 0000000 // Copyright 2020 Contributors to the Parsec project.
// SPDX-License-Identifier: Apache-2.0
// This file is needed to provide linkable versions of certain
// PSA Crypto functions that may be declared static inline.
// See: https://github.com/ARMmbed/mbedtls/issues/3230
#include "shim.h"
psa_key_id_t
shim_get_key_id(const psa_key_attributes_t *attributes)
{
return psa_get_key_id(attributes);
}
size_t
shim_get_key_bits(const psa_key_attributes_t *attributes)
{
return psa_get_key_bits(attributes);
}
psa_key_type_t
shim_get_key_type(const psa_key_attributes_t *attributes)
{
return psa_get_key_type(attributes);
}
psa_key_lifetime_t
shim_get_key_lifetime(const psa_key_attributes_t *attributes)
{
return psa_get_key_lifetime(attributes);
}
psa_algorithm_t
shim_get_key_algorithm(const psa_key_attributes_t *attributes)
{
return psa_get_key_algorithm(attributes);
}
psa_key_usage_t
shim_get_key_usage_flags(const psa_key_attributes_t *attributes)
{
return psa_get_key_usage_flags(attributes);
}
psa_key_attributes_t
shim_key_attributes_init(void)
{
return psa_key_attributes_init();
}
psa_cipher_operation_t
shim_cipher_operation_init(void)
{
return psa_cipher_operation_init();
}
psa_key_derivation_operation_t
shim_key_derivation_operation_init(void)
{
return psa_key_derivation_operation_init();
}
void
shim_set_key_algorithm(psa_key_attributes_t *attributes,
psa_algorithm_t alg)
{
psa_set_key_algorithm(attributes, alg);
}
void
shim_set_key_bits(psa_key_attributes_t *attributes,
size_t bits)
{
psa_set_key_bits(attributes, bits);
}
void
shim_set_key_id(psa_key_attributes_t *attributes,
psa_key_id_t id)
{
psa_set_key_id(attributes, id);
}
void
shim_set_key_lifetime(psa_key_attributes_t *attributes,
psa_key_lifetime_t lifetime)
{
psa_set_key_lifetime(attributes, lifetime);
}
void
shim_set_key_type(psa_key_attributes_t *attributes,
psa_key_type_t type_)
{
psa_set_key_type(attributes, type_);
}
void
shim_set_key_usage_flags(psa_key_attributes_t *attributes,
psa_key_usage_t usage_flags)
{
psa_set_key_usage_flags(attributes, usage_flags);
}
int
shim_PSA_ALG_IS_HASH(psa_algorithm_t alg)
{
return PSA_ALG_IS_HASH(alg);
}
int
shim_PSA_ALG_IS_MAC(psa_algorithm_t alg) {
return PSA_ALG_IS_MAC(alg);
}
int
shim_PSA_ALG_IS_HMAC(psa_algorithm_t alg) {
return PSA_ALG_IS_HMAC(alg);
}
int
shim_PSA_ALG_IS_BLOCK_CIPHER_MAC (psa_algorithm_t alg) {
return PSA_ALG_IS_BLOCK_CIPHER_MAC (alg);
}
int
shim_PSA_ALG_IS_CIPHER(psa_algorithm_t alg) {
return PSA_ALG_IS_CIPHER(alg);
}
int
shim_PSA_ALG_IS_AEAD(psa_algorithm_t alg) {
return PSA_ALG_IS_AEAD(alg);
}
int
shim_PSA_ALG_IS_SIGN(psa_algorithm_t alg) {
return PSA_ALG_IS_SIGN(alg);
}
int
shim_PSA_ALG_IS_ASYMMETRIC_ENCRYPTION(psa_algorithm_t alg) {
return PSA_ALG_IS_ASYMMETRIC_ENCRYPTION(alg);
}
int
shim_PSA_ALG_IS_RSA_OAEP(psa_algorithm_t alg) {
return PSA_ALG_IS_RSA_OAEP(alg);
}
int
shim_PSA_ALG_IS_KEY_AGREEMENT(psa_algorithm_t alg) {
return PSA_ALG_IS_KEY_AGREEMENT(alg);
}
int
shim_PSA_ALG_IS_RAW_KEY_AGREEMENT (psa_algorithm_t alg) {
return PSA_ALG_IS_RAW_KEY_AGREEMENT(alg);
}
int
shim_PSA_ALG_IS_FFDH(psa_algorithm_t alg) {
return PSA_ALG_IS_FFDH(alg);
}
int
shim_PSA_ALG_IS_ECDH(psa_algorithm_t alg) {
return PSA_ALG_IS_ECDH(alg);
}
int
shim_PSA_ALG_IS_KEY_DERIVATION(psa_algorithm_t alg) {
return PSA_ALG_IS_KEY_DERIVATION(alg);
}
int
shim_PSA_ALG_IS_RSA_PKCS1V15_SIGN(psa_algorithm_t alg) {
return PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg);
}
int
shim_PSA_ALG_IS_RSA_PSS(psa_algorithm_t alg) {
return PSA_ALG_IS_RSA_PSS(alg);
}
int
shim_PSA_ALG_IS_ECDSA(psa_algorithm_t alg) {
return PSA_ALG_IS_ECDSA(alg);
}
int
shim_PSA_ALG_IS_DETERMINISTIC_ECDSA(psa_algorithm_t alg) {
return PSA_ALG_IS_DETERMINISTIC_ECDSA(alg);
}
int
shim_PSA_ALG_IS_HKDF(psa_algorithm_t alg) {
return PSA_ALG_IS_HKDF(alg);
}
int
shim_PSA_ALG_IS_TLS12_PRF(psa_algorithm_t alg) {
return PSA_ALG_IS_TLS12_PRF(alg);
}
int
shim_PSA_ALG_IS_TLS12_PSK_TO_MS(psa_algorithm_t alg) {
return PSA_ALG_IS_TLS12_PSK_TO_MS(alg);
}
psa_algorithm_t
shim_PSA_ALG_SIGN_GET_HASH(psa_algorithm_t sign_alg) {
return PSA_ALG_SIGN_GET_HASH(sign_alg);
}
psa_algorithm_t
shim_PSA_ALG_RSA_OAEP_GET_HASH(psa_algorithm_t rsa_oaep_alg) {
return PSA_ALG_RSA_OAEP_GET_HASH(rsa_oaep_alg);
}
psa_algorithm_t
shim_PSA_ALG_HMAC_GET_HASH(psa_algorithm_t hmac_alg) {
return PSA_ALG_HMAC_GET_HASH(hmac_alg);
}
psa_algorithm_t
shim_PSA_ALG_HKDF_GET_HASH(psa_algorithm_t hkdf_alg) {
return PSA_ALG_HKDF_GET_HASH(hkdf_alg);
}
psa_algorithm_t
shim_PSA_ALG_TLS12_PRF_GET_HASH(psa_algorithm_t tls12_prf_alg) {
return PSA_ALG_TLS12_PRF_GET_HASH(tls12_prf_alg);
}
psa_algorithm_t
shim_PSA_ALG_TLS12_PSK_TO_MS_GET_HASH(psa_algorithm_t tls12_psk_to_ms_alg) {
return PSA_ALG_TLS12_PSK_TO_MS_GET_HASH(tls12_psk_to_ms_alg);
}
psa_algorithm_t
shim_PSA_ALG_KEY_AGREEMENT_GET_BASE(psa_algorithm_t alg) {
return PSA_ALG_KEY_AGREEMENT_GET_BASE(alg);
}
psa_algorithm_t
shim_PSA_ALG_KEY_AGREEMENT_GET_KDF(psa_algorithm_t alg) {
return PSA_ALG_KEY_AGREEMENT_GET_KDF(alg);
}
psa_algorithm_t
shim_PSA_ALG_RSA_PKCS1V15_SIGN(psa_algorithm_t hash_alg) {
return PSA_ALG_RSA_PKCS1V15_SIGN(hash_alg);
}
psa_algorithm_t
shim_PSA_ALG_RSA_PSS(psa_algorithm_t hash_alg) {
return PSA_ALG_RSA_PSS(hash_alg);
}
psa_algorithm_t
shim_PSA_ALG_ECDSA(psa_algorithm_t hash_alg) {
return PSA_ALG_ECDSA(hash_alg);
}
psa_algorithm_t
shim_PSA_ALG_DETERMINISTIC_ECDSA(psa_algorithm_t hash_alg) {
return PSA_ALG_DETERMINISTIC_ECDSA(hash_alg);
}
psa_algorithm_t
shim_PSA_ALG_HMAC(psa_algorithm_t hash_alg) {
return PSA_ALG_HMAC(hash_alg);
}
psa_algorithm_t
shim_PSA_ALG_TRUNCATED_MAC(psa_algorithm_t mac_alg, size_t mac_length) {
return PSA_ALG_TRUNCATED_MAC(mac_alg, mac_length);
}
psa_algorithm_t
shim_PSA_ALG_FULL_LENGTH_MAC(psa_algorithm_t mac_alg) {
return PSA_ALG_FULL_LENGTH_MAC(mac_alg);
}
psa_algorithm_t
shim_PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG(psa_algorithm_t aead_alg) {
return PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG(aead_alg);
}
psa_algorithm_t
shim_PSA_ALG_AEAD_WITH_SHORTENED_TAG(psa_algorithm_t aead_alg, size_t tag_length) {
return PSA_ALG_AEAD_WITH_SHORTENED_TAG(aead_alg, tag_length);
}
psa_algorithm_t
shim_PSA_ALG_HKDF(psa_algorithm_t hash_alg) {
return PSA_ALG_HKDF(hash_alg);
}
psa_algorithm_t
shim_PSA_ALG_TLS12_PRF(psa_algorithm_t hash_alg) {
return PSA_ALG_TLS12_PRF(hash_alg);
}
psa_algorithm_t
shim_PSA_ALG_TLS12_PSK_TO_MS(psa_algorithm_t hash_alg) {
return PSA_ALG_TLS12_PSK_TO_MS(hash_alg);
}
psa_algorithm_t
shim_PSA_ALG_KEY_AGREEMENT(psa_algorithm_t raw_key_agreement, psa_algorithm_t key_derivation) {
return PSA_ALG_KEY_AGREEMENT(raw_key_agreement, key_derivation);
}
int
shim_PSA_KEY_TYPE_IS_ECC_KEY_PAIR(psa_key_type_t key_type)
{
return PSA_KEY_TYPE_IS_ECC_KEY_PAIR(key_type);
}
int
shim_PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY(psa_key_type_t key_type)
{
return PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY(key_type);
}
int
shim_PSA_KEY_TYPE_IS_DH_PUBLIC_KEY(psa_key_type_t key_type)
{
return PSA_KEY_TYPE_IS_DH_PUBLIC_KEY(key_type);
}
int
shim_PSA_KEY_TYPE_IS_DH_KEY_PAIR(psa_key_type_t key_type)
{
return PSA_KEY_TYPE_IS_DH_KEY_PAIR(key_type);
}
psa_algorithm_t
shim_PSA_ALG_RSA_OAEP(psa_algorithm_t hash_alg)
{
return PSA_ALG_RSA_OAEP(hash_alg);
}
psa_ecc_family_t
shim_PSA_KEY_TYPE_ECC_GET_FAMILY(psa_key_type_t key_type)
{
return PSA_KEY_TYPE_ECC_GET_FAMILY(key_type);
}
psa_dh_family_t
shim_PSA_KEY_TYPE_DH_GET_FAMILY(psa_key_type_t key_type)
{
return PSA_KEY_TYPE_DH_GET_FAMILY(key_type);
}
psa_key_type_t
shim_PSA_KEY_TYPE_ECC_KEY_PAIR(psa_ecc_family_t curve)
{
return PSA_KEY_TYPE_ECC_KEY_PAIR(curve);
}
psa_key_type_t
shim_PSA_KEY_TYPE_ECC_PUBLIC_KEY(psa_ecc_family_t curve)
{
return PSA_KEY_TYPE_ECC_PUBLIC_KEY(curve);
}
psa_key_type_t
shim_PSA_KEY_TYPE_DH_KEY_PAIR(psa_dh_family_t group)
{
return PSA_KEY_TYPE_DH_KEY_PAIR(group);
}
psa_key_type_t
shim_PSA_KEY_TYPE_DH_PUBLIC_KEY(psa_dh_family_t group)
{
return PSA_KEY_TYPE_DH_PUBLIC_KEY(group);
}
psa_key_type_t
shim_PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(psa_key_type_t key_type)
{
return PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(key_type);
}
size_t
shim_PSA_SIGN_OUTPUT_SIZE(psa_key_type_t key_type, size_t key_bits, psa_algorithm_t alg)
{
return PSA_SIGN_OUTPUT_SIZE(key_type, key_bits, alg);
}
size_t
shim_PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(psa_key_type_t key_type, size_t key_bits, psa_algorithm_t alg)
{
return PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(key_type, key_bits, alg);
}
size_t
shim_PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(psa_key_type_t key_type, size_t key_bits, psa_algorithm_t alg)
{
return PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(key_type, key_bits, alg);
}
size_t
shim_PSA_EXPORT_KEY_OUTPUT_SIZE(psa_key_type_t key_type, size_t key_bits)
{
return PSA_EXPORT_KEY_OUTPUT_SIZE(key_type, key_bits);
}
size_t
shim_PSA_HASH_LENGTH(psa_algorithm_t alg)
{
return PSA_HASH_LENGTH(alg);
}
size_t
shim_PSA_MAC_LENGTH(psa_key_type_t key_type, size_t key_bits, psa_algorithm_t alg)
{
return PSA_MAC_LENGTH(key_type, key_bits, alg);
}
size_t
shim_PSA_MAC_TRUNCATED_LENGTH(psa_algorithm_t alg)
{
return PSA_MAC_TRUNCATED_LENGTH(alg);
}
size_t
shim_PSA_AEAD_TAG_LENGTH(psa_key_type_t key_type, size_t key_bits, psa_algorithm_t alg)
{
return PSA_AEAD_TAG_LENGTH(key_type, key_bits, alg);
}
size_t
shim_PSA_AEAD_ENCRYPT_OUTPUT_SIZE(psa_key_type_t key_type, psa_algorithm_t aead_alg, size_t plaintext_length)
{
return PSA_AEAD_ENCRYPT_OUTPUT_SIZE(key_type, aead_alg, plaintext_length);
}
size_t
shim_PSA_AEAD_DECRYPT_OUTPUT_SIZE(psa_key_type_t key_type, psa_algorithm_t aead_alg, size_t ciphertext_length)
{
return PSA_AEAD_DECRYPT_OUTPUT_SIZE(key_type, aead_alg, ciphertext_length);
}
psa-crypto-sys-0.9.3/src/c/shim.h 0000644 0000000 0000000 00000014230 10461020230 0014674 0 ustar 0000000 0000000 // Copyright 2020 Contributors to the Parsec project.
// SPDX-License-Identifier: Apache-2.0
#include "mbedtls/build_info.h"
#include
#include
const psa_key_derivation_step_t shim_PSA_KEY_DERIVATION_INPUT_SECRET = PSA_KEY_DERIVATION_INPUT_SECRET;
const psa_key_derivation_step_t shim_PSA_KEY_DERIVATION_INPUT_LABEL = PSA_KEY_DERIVATION_INPUT_LABEL;
const psa_key_derivation_step_t shim_PSA_KEY_DERIVATION_INPUT_SALT = PSA_KEY_DERIVATION_INPUT_SALT;
const psa_key_derivation_step_t shim_PSA_KEY_DERIVATION_INPUT_INFO = PSA_KEY_DERIVATION_INPUT_INFO;
const psa_key_derivation_step_t shim_PSA_KEY_DERIVATION_INPUT_SEED = PSA_KEY_DERIVATION_INPUT_SEED;
psa_algorithm_t shim_get_key_algorithm(const psa_key_attributes_t *attributes);
size_t shim_get_key_bits(const psa_key_attributes_t *attributes);
psa_key_id_t shim_get_key_id(const psa_key_attributes_t *attributes);
psa_key_lifetime_t shim_get_key_lifetime(const psa_key_attributes_t *attributes);
psa_key_type_t shim_get_key_type(const psa_key_attributes_t *attributes);
psa_key_usage_t shim_get_key_usage_flags(const psa_key_attributes_t *attributes);
psa_key_attributes_t shim_key_attributes_init(void);
psa_cipher_operation_t shim_cipher_operation_init(void);
psa_key_derivation_operation_t shim_key_derivation_operation_init(void);
void shim_set_key_algorithm(psa_key_attributes_t *attributes, psa_algorithm_t alg);
void shim_set_key_bits(psa_key_attributes_t *attributes, size_t bits);
void shim_set_key_id(psa_key_attributes_t *attributes, psa_key_id_t id);
void shim_set_key_lifetime(psa_key_attributes_t *attributes, psa_key_lifetime_t lifetime);
void shim_set_key_type(psa_key_attributes_t *attributes, psa_key_type_t type_);
void shim_set_key_usage_flags(psa_key_attributes_t *attributes, psa_key_usage_t usage_flags);
int shim_PSA_ALG_IS_HASH(psa_algorithm_t alg);
int shim_PSA_ALG_IS_MAC(psa_algorithm_t alg);
int shim_PSA_ALG_IS_HMAC(psa_algorithm_t alg);
int shim_PSA_ALG_IS_BLOCK_CIPHER_MAC(psa_algorithm_t alg);
int shim_PSA_ALG_IS_CIPHER(psa_algorithm_t alg);
int shim_PSA_ALG_IS_AEAD(psa_algorithm_t alg);
int shim_PSA_ALG_IS_SIGN(psa_algorithm_t alg);
int shim_PSA_ALG_IS_ASYMMETRIC_ENCRYPTION(psa_algorithm_t alg);
int shim_PSA_ALG_IS_RSA_OAEP(psa_algorithm_t alg);
int shim_PSA_ALG_IS_KEY_AGREEMENT(psa_algorithm_t alg);
int shim_PSA_ALG_IS_RAW_KEY_AGREEMENT(psa_algorithm_t alg);
int shim_PSA_ALG_IS_FFDH(psa_algorithm_t alg);
int shim_PSA_ALG_IS_ECDH(psa_algorithm_t alg);
int shim_PSA_ALG_IS_KEY_DERIVATION(psa_algorithm_t alg);
int shim_PSA_ALG_IS_RSA_PKCS1V15_SIGN(psa_algorithm_t alg);
int shim_PSA_ALG_IS_RSA_PSS(psa_algorithm_t alg);
int shim_PSA_ALG_IS_ECDSA(psa_algorithm_t alg);
int shim_PSA_ALG_IS_DETERMINISTIC_ECDSA(psa_algorithm_t alg);
int shim_PSA_ALG_IS_HKDF(psa_algorithm_t alg);
int shim_PSA_ALG_IS_TLS12_PRF(psa_algorithm_t alg);
int shim_PSA_ALG_IS_TLS12_PSK_TO_MS(psa_algorithm_t alg);
psa_algorithm_t shim_PSA_ALG_RSA_OAEP(psa_algorithm_t hash_alg);
psa_algorithm_t shim_PSA_ALG_RSA_PKCS1V15_SIGN(psa_algorithm_t hash_alg);
psa_algorithm_t shim_PSA_ALG_RSA_PSS(psa_algorithm_t hash_alg);
psa_algorithm_t shim_PSA_ALG_ECDSA(psa_algorithm_t hash_alg);
psa_algorithm_t shim_PSA_ALG_DETERMINISTIC_ECDSA(psa_algorithm_t hash_alg);
psa_algorithm_t shim_PSA_ALG_HMAC(psa_algorithm_t hash_alg);
psa_algorithm_t shim_PSA_ALG_SIGN_GET_HASH(psa_algorithm_t sign_alg);
psa_algorithm_t shim_PSA_ALG_RSA_OAEP_GET_HASH(psa_algorithm_t rsa_oaep_alg);
psa_algorithm_t shim_PSA_ALG_HMAC_GET_HASH(psa_algorithm_t hmac_alg);
psa_algorithm_t shim_PSA_ALG_HKDF_GET_HASH(psa_algorithm_t hkdf_alg);
psa_algorithm_t shim_PSA_ALG_TLS12_PRF_GET_HASH(psa_algorithm_t tls12_prf_alg);
psa_algorithm_t shim_PSA_ALG_TLS12_PSK_TO_MS_GET_HASH(psa_algorithm_t tls12_psk_to_ms_alg);
psa_algorithm_t shim_PSA_ALG_KEY_AGREEMENT_GET_BASE(psa_algorithm_t alg);
psa_algorithm_t shim_PSA_ALG_KEY_AGREEMENT_GET_KDF(psa_algorithm_t alg);
psa_algorithm_t shim_PSA_ALG_TRUNCATED_MAC(psa_algorithm_t mac_alg, size_t mac_length);
psa_algorithm_t shim_PSA_ALG_FULL_LENGTH_MAC(psa_algorithm_t mac_alg);
psa_algorithm_t shim_PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG(psa_algorithm_t aead_alg);
psa_algorithm_t shim_PSA_ALG_AEAD_WITH_SHORTENED_TAG(psa_algorithm_t aead_alg, size_t tag_length);
psa_algorithm_t shim_PSA_ALG_HKDF(psa_algorithm_t hash_alg);
psa_algorithm_t shim_PSA_ALG_TLS12_PRF(psa_algorithm_t hash_alg);
psa_algorithm_t shim_PSA_ALG_TLS12_PSK_TO_MS(psa_algorithm_t hash_alg);
psa_algorithm_t shim_PSA_ALG_KEY_AGREEMENT(psa_algorithm_t raw_key_agreement, psa_algorithm_t key_derivation);
int shim_PSA_KEY_TYPE_IS_ECC_KEY_PAIR(psa_key_type_t key_type);
int shim_PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY(psa_key_type_t key_type);
int shim_PSA_KEY_TYPE_IS_DH_PUBLIC_KEY(psa_key_type_t key_type);
int shim_PSA_KEY_TYPE_IS_DH_KEY_PAIR(psa_key_type_t key_type);
psa_ecc_family_t shim_PSA_KEY_TYPE_ECC_GET_FAMILY(psa_key_type_t key_type);
psa_dh_family_t shim_PSA_KEY_TYPE_DH_GET_FAMILY(psa_key_type_t key_type);
psa_key_type_t shim_PSA_KEY_TYPE_ECC_KEY_PAIR(psa_ecc_family_t curve);
psa_key_type_t shim_PSA_KEY_TYPE_ECC_PUBLIC_KEY(psa_ecc_family_t curve);
psa_key_type_t shim_PSA_KEY_TYPE_DH_KEY_PAIR(psa_dh_family_t group);
psa_key_type_t shim_PSA_KEY_TYPE_DH_PUBLIC_KEY(psa_dh_family_t group);
psa_key_type_t shim_PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(psa_key_type_t key_type);
size_t shim_PSA_SIGN_OUTPUT_SIZE(psa_key_type_t key_type, size_t key_bits, psa_algorithm_t alg);
size_t shim_PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(psa_key_type_t key_type, size_t key_bits, psa_algorithm_t alg);
size_t shim_PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(psa_key_type_t key_type, size_t key_bits, psa_algorithm_t alg);
size_t shim_PSA_EXPORT_KEY_OUTPUT_SIZE(psa_key_type_t key_type, size_t key_bits);
size_t shim_PSA_HASH_LENGTH(psa_algorithm_t alg);
size_t shim_PSA_MAC_LENGTH(psa_key_type_t key_type, size_t key_bits, psa_algorithm_t alg);
size_t shim_PSA_MAC_TRUNCATED_LENGTH(psa_algorithm_t alg);
size_t shim_PSA_AEAD_TAG_LENGTH(psa_key_type_t key_type, size_t key_bits, psa_algorithm_t alg);
size_t shim_PSA_AEAD_ENCRYPT_OUTPUT_SIZE(psa_key_type_t key_type, psa_algorithm_t aead_alg, size_t plaintext_length);
size_t shim_PSA_AEAD_DECRYPT_OUTPUT_SIZE(psa_key_type_t key_type, psa_algorithm_t aead_alg, size_t ciphertext_length);
psa-crypto-sys-0.9.3/src/constants.rs 0000644 0000000 0000000 00000014200 10461020230 0015720 0 ustar 0000000 0000000 // Copyright 2020 Contributors to the Parsec project.
// SPDX-License-Identifier: Apache-2.0
//! Specification-defined constants
#![allow(missing_docs)]
use super::types::*;
pub const PSA_ALG_ANY_HASH: psa_algorithm_t = 0x020000ff;
pub const PSA_ALG_CBC_MAC: psa_algorithm_t = 0x03c00100;
pub const PSA_ALG_CBC_NO_PADDING: psa_algorithm_t = 0x04404000;
pub const PSA_ALG_CBC_PKCS7: psa_algorithm_t = 0x04404100;
pub const PSA_ALG_CCM: psa_algorithm_t = 0x05500100;
pub const PSA_ALG_CFB: psa_algorithm_t = 0x04c01100;
pub const PSA_ALG_CHACHA20_POLY1305: psa_algorithm_t = 0x05100500;
pub const PSA_ALG_CMAC: psa_algorithm_t = 0x03c00200;
pub const PSA_ALG_CTR: psa_algorithm_t = 0x04c01000;
pub const PSA_ALG_ECB_NO_PADDING: psa_algorithm_t = 0x04404400;
pub const PSA_ALG_ECDH: psa_algorithm_t = 0x09020000;
pub const PSA_ALG_ECDSA_ANY: psa_algorithm_t = 0x06000600;
pub const PSA_ALG_FFDH: psa_algorithm_t = 0x09010000;
pub const PSA_ALG_GCM: psa_algorithm_t = 0x05500200;
pub const PSA_ALG_MD2: psa_algorithm_t = 0x02000001;
pub const PSA_ALG_MD4: psa_algorithm_t = 0x02000002;
pub const PSA_ALG_MD5: psa_algorithm_t = 0x02000003;
pub const PSA_ALG_NONE: psa_algorithm_t = 0;
pub const PSA_ALG_OFB: psa_algorithm_t = 0x04c01200;
pub const PSA_ALG_RIPEMD160: psa_algorithm_t = 0x02000004;
pub const PSA_ALG_RSA_PKCS1V15_CRYPT: psa_algorithm_t = 0x07000200;
pub const PSA_ALG_RSA_PKCS1V15_SIGN_RAW: psa_algorithm_t = 0x06000200;
pub const PSA_ALG_SHA3_224: psa_algorithm_t = 0x02000010;
pub const PSA_ALG_SHA3_256: psa_algorithm_t = 0x02000011;
pub const PSA_ALG_SHA3_384: psa_algorithm_t = 0x02000012;
pub const PSA_ALG_SHA3_512: psa_algorithm_t = 0x02000013;
pub const PSA_ALG_SHA_1: psa_algorithm_t = 0x02000005;
pub const PSA_ALG_SHA_224: psa_algorithm_t = 0x02000008;
pub const PSA_ALG_SHA_256: psa_algorithm_t = 0x02000009;
pub const PSA_ALG_SHA_384: psa_algorithm_t = 0x0200000a;
pub const PSA_ALG_SHA_512: psa_algorithm_t = 0x0200000b;
pub const PSA_ALG_SHA_512_224: psa_algorithm_t = 0x0200000c;
pub const PSA_ALG_SHA_512_256: psa_algorithm_t = 0x0200000d;
pub const PSA_ALG_SM3: psa_algorithm_t = 0x02000014;
pub const PSA_ALG_STREAM_CIPHER: psa_algorithm_t = 0x04800100;
pub const PSA_ALG_XTS: psa_algorithm_t = 0x0440ff00;
pub const PSA_DH_FAMILY_RFC7919: psa_dh_family_t = 0x03;
pub const PSA_ECC_FAMILY_BRAINPOOL_P_R1: psa_ecc_family_t = 0x30;
pub const PSA_ECC_FAMILY_FRP: psa_ecc_family_t = 0x33;
pub const PSA_ECC_FAMILY_MONTGOMERY: psa_ecc_family_t = 0x41;
pub const PSA_ECC_FAMILY_SECP_K1: psa_ecc_family_t = 0x17;
pub const PSA_ECC_FAMILY_SECP_R1: psa_ecc_family_t = 0x12;
pub const PSA_ECC_FAMILY_SECP_R2: psa_ecc_family_t = 0x1b;
pub const PSA_ECC_FAMILY_SECT_K1: psa_ecc_family_t = 0x27;
pub const PSA_ECC_FAMILY_SECT_R1: psa_ecc_family_t = 0x22;
pub const PSA_ECC_FAMILY_SECT_R2: psa_ecc_family_t = 0x2b;
pub const PSA_ERROR_ALREADY_EXISTS: psa_status_t = -139;
pub const PSA_ERROR_BAD_STATE: psa_status_t = -137;
pub const PSA_ERROR_BUFFER_TOO_SMALL: psa_status_t = -138;
pub const PSA_ERROR_COMMUNICATION_FAILURE: psa_status_t = -145;
pub const PSA_ERROR_CORRUPTION_DETECTED: psa_status_t = -151;
pub const PSA_ERROR_DATA_CORRUPT: psa_status_t = -152;
pub const PSA_ERROR_DATA_INVALID: psa_status_t = -153;
pub const PSA_ERROR_DOES_NOT_EXIST: psa_status_t = -140;
pub const PSA_ERROR_GENERIC_ERROR: psa_status_t = -132;
pub const PSA_ERROR_HARDWARE_FAILURE: psa_status_t = -147;
pub const PSA_ERROR_INSUFFICIENT_DATA: psa_status_t = -143;
pub const PSA_ERROR_INSUFFICIENT_ENTROPY: psa_status_t = -148;
pub const PSA_ERROR_INSUFFICIENT_MEMORY: psa_status_t = -141;
pub const PSA_ERROR_INSUFFICIENT_STORAGE: psa_status_t = -142;
pub const PSA_ERROR_INVALID_ARGUMENT: psa_status_t = -135;
pub const PSA_ERROR_INVALID_HANDLE: psa_status_t = -136;
pub const PSA_ERROR_INVALID_PADDING: psa_status_t = -150;
pub const PSA_ERROR_INVALID_SIGNATURE: psa_status_t = -149;
pub const PSA_ERROR_NOT_PERMITTED: psa_status_t = -133;
pub const PSA_ERROR_NOT_SUPPORTED: psa_status_t = -134;
pub const PSA_ERROR_STORAGE_FAILURE: psa_status_t = -146;
pub const PSA_HASH_SUSPEND_ALGORITHM_FIELD_LENGTH: usize = 4;
pub const PSA_KEY_ID_NULL: psa_key_id_t = 0;
pub const PSA_KEY_ID_USER_MAX: psa_key_id_t = 0x3fffffff;
pub const PSA_KEY_ID_USER_MIN: psa_key_id_t = 0x00000001;
pub const PSA_KEY_ID_VENDOR_MAX: psa_key_id_t = 0x7fffffff;
pub const PSA_KEY_ID_VENDOR_MIN: psa_key_id_t = 0x40000000;
pub const PSA_KEY_LIFETIME_PERSISTENT: psa_key_lifetime_t = 0x00000001;
pub const PSA_KEY_LIFETIME_VOLATILE: psa_key_lifetime_t = 0x00000000;
pub const PSA_KEY_LOCATION_LOCAL_STORAGE: psa_key_location_t = 0x000000;
pub const PSA_KEY_LOCATION_PRIMARY_SECURE_ELEMENT: psa_key_location_t = 0x000001;
pub const PSA_KEY_PERSISTENCE_DEFAULT: psa_key_persistence_t = 0x01;
pub const PSA_KEY_PERSISTENCE_READ_ONLY: psa_key_persistence_t = 0xff;
pub const PSA_KEY_PERSISTENCE_VOLATILE: psa_key_persistence_t = 0x00;
pub const PSA_KEY_TYPE_AES: psa_key_type_t = 0x2400;
pub const PSA_KEY_TYPE_ARC4: psa_key_type_t = 0x2002;
pub const PSA_KEY_TYPE_CAMELLIA: psa_key_type_t = 0x2403;
pub const PSA_KEY_TYPE_CHACHA20: psa_key_type_t = 0x2004;
pub const PSA_KEY_TYPE_DERIVE: psa_key_type_t = 0x1200;
pub const PSA_KEY_TYPE_DES: psa_key_type_t = 0x2301;
pub const PSA_KEY_TYPE_HMAC: psa_key_type_t = 0x1100;
pub const PSA_KEY_TYPE_NONE: psa_key_type_t = 0x0000;
pub const PSA_KEY_TYPE_RAW_DATA: psa_key_type_t = 0x1001;
pub const PSA_KEY_TYPE_RSA_KEY_PAIR: psa_key_type_t = 0x7001;
pub const PSA_KEY_TYPE_RSA_PUBLIC_KEY: psa_key_type_t = 0x4001;
pub const PSA_KEY_TYPE_SM4: psa_key_type_t = 0x2405;
pub const PSA_KEY_USAGE_CACHE: psa_key_usage_t = 0x00000004;
pub const PSA_KEY_USAGE_COPY: psa_key_usage_t = 0x00000002;
pub const PSA_KEY_USAGE_DECRYPT: psa_key_usage_t = 0x00000200;
pub const PSA_KEY_USAGE_DERIVE: psa_key_usage_t = 0x00004000;
pub const PSA_KEY_USAGE_ENCRYPT: psa_key_usage_t = 0x00000100;
pub const PSA_KEY_USAGE_EXPORT: psa_key_usage_t = 0x00000001;
pub const PSA_KEY_USAGE_SIGN_HASH: psa_key_usage_t = 0x00001000;
pub const PSA_KEY_USAGE_SIGN_MESSAGE: psa_key_usage_t = 0x00000400;
pub const PSA_KEY_USAGE_VERIFY_HASH: psa_key_usage_t = 0x00002000;
pub const PSA_KEY_USAGE_VERIFY_MESSAGE: psa_key_usage_t = 0x00000800;
pub const PSA_SUCCESS: psa_status_t = 0;
psa-crypto-sys-0.9.3/src/extras.rs 0000644 0000000 0000000 00000005025 10461020230 0015217 0 ustar 0000000 0000000 // Copyright 2020 Contributors to the Parsec project.
// SPDX-License-Identifier: Apache-2.0
#![allow(non_snake_case)]
//! Additional functionality required that PSA Crypto does not provide
use crate::types::{psa_algorithm_t, psa_key_type_t};
/// Retrieves the tag length from an aead_alg.
/// Note: `aead_alg` is an AEAD algorithm, such that `PSA_ALG_IS_AEAD(aead_alg)` is `true`.
pub fn PSA_ALG_AEAD_TAG_TRUNCATED_LENGTH(aead_alg: psa_algorithm_t) -> usize {
const TAG_LENGTH_MASK: u32 = 0b111111; // tag lengths are 6 bits in length
const PSA_V1_0_0_TAG_LENGTH_START_BIT: u32 = 16; // tag length at bit position [21:16]
let pre_mask_tag_length = aead_alg >> PSA_V1_0_0_TAG_LENGTH_START_BIT;
(pre_mask_tag_length & TAG_LENGTH_MASK) as usize
}
/// Retrieves the output size of an ECDH raw key agreement operation shared secret.
/// Caller must ensure key type is compatible.
/// Returns 0 if key size is too large.
/// This does not match any PSA macro, it will be replaces by PSA_RAW_KEY_AGREEMENT_OUTPUT_SIZE once
/// mbedTLS adds support for it.
pub unsafe fn PSA_RAW_ECDH_KEY_AGREEMENT_OUTPUT_SIZE(
_key_type: psa_key_type_t,
key_bits: usize,
) -> usize {
/*
The size of the shared secret is always `ceiling(m/8)` bytes long where `m` is the bit size associated with the curve,
i.e. the bit size of the order of the curve's coordinate field. When m is not a multiple of 8, the byte containing the most
significant bit of the shared secret is padded with zero bits.
*/
if let Some(numerator) = key_bits.checked_add(7) {
numerator / 8
} else {
0
}
}
#[test]
fn truncated_aead_length_1() {
let test_aead_alg = 0b11001110010010110001110011010011; // 21:16 is 001011
assert_eq!(11, PSA_ALG_AEAD_TAG_TRUNCATED_LENGTH(test_aead_alg));
}
#[test]
fn truncated_aead_length_2() {
let test_aead_alg = 0b11001110010000000001110011010011; // 21:16 is 000000
assert_eq!(0, PSA_ALG_AEAD_TAG_TRUNCATED_LENGTH(test_aead_alg));
}
#[test]
fn truncated_aead_length_3() {
let test_aead_alg = 0b11001110011111110001110011010011; // 21:16 is 111111
assert_eq!(63, PSA_ALG_AEAD_TAG_TRUNCATED_LENGTH(test_aead_alg));
}
#[test]
fn truncated_aead_length_full_range() {
// Test from 0 to 63
let base_mask = 0b11001110010000000001110011010011;
for test_val in 0..63 {
let test_mask = test_val << 16;
let test_aead_alg = base_mask | test_mask;
assert_eq!(
test_val as usize,
PSA_ALG_AEAD_TAG_TRUNCATED_LENGTH(test_aead_alg)
);
}
}
psa-crypto-sys-0.9.3/src/lib.rs 0000644 0000000 0000000 00000004376 10461020230 0014467 0 ustar 0000000 0000000 // Copyright 2020 Contributors to the Parsec project.
// SPDX-License-Identifier: Apache-2.0
//! # PSA Cryptography API Wrapper
//!
//! This crate provides abstraction over an implementation of the PSA Cryptography API.
//! You can find the API
//! [here](https://developer.arm.com/architectures/security-architectures/platform-security-architecture/documentation).
// This one is hard to avoid.
#![allow(clippy::multiple_crate_versions)]
#![allow(clippy::missing_safety_doc)]
// Respect the C API case
#![allow(non_snake_case)]
#[allow(
non_snake_case,
non_camel_case_types,
non_upper_case_globals,
dead_code,
trivial_casts
)]
#[allow(clippy::all)]
#[cfg(feature = "interface")]
mod psa_crypto_binding {
include!(concat!(env!("OUT_DIR"), "/shim_bindings.rs"));
}
mod constants;
#[cfg(feature = "interface")]
mod extras;
#[cfg(feature = "interface")]
mod shim;
mod types;
pub use constants::*;
pub use types::*;
#[cfg(feature = "operations")]
pub use psa_crypto_binding::{
psa_aead_decrypt, psa_aead_encrypt, psa_asymmetric_decrypt, psa_asymmetric_encrypt,
psa_cipher_abort, psa_cipher_decrypt_setup, psa_cipher_encrypt_setup, psa_cipher_finish,
psa_cipher_set_iv, psa_cipher_update, psa_close_key, psa_copy_key, psa_crypto_init,
psa_destroy_key, psa_export_key, psa_export_public_key, psa_generate_key, psa_generate_random,
psa_get_key_attributes, psa_hash_compare, psa_hash_compute, psa_import_key,
psa_key_derivation_abort, psa_key_derivation_input_bytes, psa_key_derivation_input_key,
psa_key_derivation_key_agreement, psa_key_derivation_output_key,
psa_key_derivation_set_capacity, psa_key_derivation_setup, psa_mac_compute, psa_mac_verify,
psa_open_key, psa_raw_key_agreement, psa_reset_key_attributes, psa_sign_hash, psa_verify_hash,
};
#[cfg(feature = "interface")]
pub use psa_crypto_binding::{
psa_cipher_operation_t, psa_key_attributes_t, psa_key_derivation_operation_t,
};
// Secure Element Driver definitions
#[cfg(feature = "interface")]
pub use psa_crypto_binding::{
psa_drv_se_asymmetric_t, psa_drv_se_context_t, psa_drv_se_key_management_t, psa_drv_se_t,
psa_key_creation_method_t, psa_key_slot_number_t,
};
#[cfg(feature = "interface")]
pub use extras::*;
#[cfg(feature = "interface")]
pub use shim::*;
psa-crypto-sys-0.9.3/src/shim.rs 0000644 0000000 0000000 00000032612 10461020230 0014653 0 ustar 0000000 0000000 // Copyright 2020 Contributors to the Parsec project.
// SPDX-License-Identifier: Apache-2.0
//! The shim module is needed to expose from this crate the methods or constants that are not
//! generated by bindgen, such as #define or static inline functions.
use super::psa_crypto_binding::{
self, psa_algorithm_t, psa_cipher_operation_t, psa_dh_family_t, psa_ecc_family_t,
psa_key_attributes_t, psa_key_derivation_operation_t, psa_key_derivation_step_t, psa_key_id_t,
psa_key_lifetime_t, psa_key_type_t, psa_key_usage_t,
};
pub const PSA_KEY_DERIVATION_INPUT_SECRET: psa_key_derivation_step_t =
psa_crypto_binding::shim_PSA_KEY_DERIVATION_INPUT_SECRET;
pub const PSA_KEY_DERIVATION_INPUT_LABEL: psa_key_derivation_step_t =
psa_crypto_binding::shim_PSA_KEY_DERIVATION_INPUT_LABEL;
pub const PSA_KEY_DERIVATION_INPUT_SALT: psa_key_derivation_step_t =
psa_crypto_binding::shim_PSA_KEY_DERIVATION_INPUT_SALT;
pub const PSA_KEY_DERIVATION_INPUT_INFO: psa_key_derivation_step_t =
psa_crypto_binding::shim_PSA_KEY_DERIVATION_INPUT_INFO;
pub const PSA_KEY_DERIVATION_INPUT_SEED: psa_key_derivation_step_t =
psa_crypto_binding::shim_PSA_KEY_DERIVATION_INPUT_SEED;
pub unsafe fn psa_get_key_bits(attributes: *const psa_key_attributes_t) -> usize {
psa_crypto_binding::shim_get_key_bits(attributes)
}
pub unsafe fn psa_get_key_type(attributes: *const psa_key_attributes_t) -> psa_key_type_t {
psa_crypto_binding::shim_get_key_type(attributes)
}
pub unsafe fn psa_get_key_lifetime(attributes: *const psa_key_attributes_t) -> psa_key_lifetime_t {
psa_crypto_binding::shim_get_key_lifetime(attributes)
}
pub unsafe fn psa_get_key_algorithm(attributes: *const psa_key_attributes_t) -> psa_algorithm_t {
psa_crypto_binding::shim_get_key_algorithm(attributes)
}
pub unsafe fn psa_get_key_usage_flags(attributes: *const psa_key_attributes_t) -> psa_key_usage_t {
psa_crypto_binding::shim_get_key_usage_flags(attributes)
}
pub unsafe fn psa_key_attributes_init() -> psa_key_attributes_t {
psa_crypto_binding::shim_key_attributes_init()
}
pub unsafe fn psa_cipher_operation_init() -> psa_cipher_operation_t {
psa_crypto_binding::shim_cipher_operation_init()
}
pub fn psa_key_derivation_operation_init() -> psa_key_derivation_operation_t {
unsafe { psa_crypto_binding::shim_key_derivation_operation_init() }
}
pub unsafe fn psa_set_key_algorithm(attributes: *mut psa_key_attributes_t, alg: psa_algorithm_t) {
psa_crypto_binding::shim_set_key_algorithm(attributes, alg);
}
pub unsafe fn psa_set_key_bits(attributes: *mut psa_key_attributes_t, bits: usize) {
psa_crypto_binding::shim_set_key_bits(attributes, bits);
}
pub unsafe fn psa_set_key_id(attributes: *mut psa_key_attributes_t, id: psa_key_id_t) {
psa_crypto_binding::shim_set_key_id(attributes, id);
}
pub unsafe fn psa_set_key_lifetime(
attributes: *mut psa_key_attributes_t,
lifetime: psa_key_lifetime_t,
) {
psa_crypto_binding::shim_set_key_lifetime(attributes, lifetime);
}
pub unsafe fn psa_set_key_type(attributes: *mut psa_key_attributes_t, type_: psa_key_type_t) {
psa_crypto_binding::shim_set_key_type(attributes, type_);
}
pub unsafe fn psa_set_key_usage_flags(
attributes: *mut psa_key_attributes_t,
usage_flags: psa_key_usage_t,
) {
psa_crypto_binding::shim_set_key_usage_flags(attributes, usage_flags);
}
pub unsafe fn psa_get_key_id(attributes: *const psa_key_attributes_t) -> psa_key_id_t {
psa_crypto_binding::shim_get_key_id(attributes)
}
pub fn PSA_ALG_IS_HASH(alg: psa_algorithm_t) -> bool {
unsafe { psa_crypto_binding::shim_PSA_ALG_IS_HASH(alg) == 1 }
}
pub fn PSA_ALG_IS_MAC(alg: psa_algorithm_t) -> bool {
unsafe { psa_crypto_binding::shim_PSA_ALG_IS_MAC(alg) == 1 }
}
pub fn PSA_ALG_IS_HMAC(alg: psa_algorithm_t) -> bool {
unsafe { psa_crypto_binding::shim_PSA_ALG_IS_HMAC(alg) == 1 }
}
pub fn PSA_ALG_IS_BLOCK_CIPHER_MAC(alg: psa_algorithm_t) -> bool {
unsafe { psa_crypto_binding::shim_PSA_ALG_IS_BLOCK_CIPHER_MAC(alg) == 1 }
}
pub fn PSA_ALG_IS_CIPHER(alg: psa_algorithm_t) -> bool {
unsafe { psa_crypto_binding::shim_PSA_ALG_IS_CIPHER(alg) == 1 }
}
pub fn PSA_ALG_IS_AEAD(alg: psa_algorithm_t) -> bool {
unsafe { psa_crypto_binding::shim_PSA_ALG_IS_AEAD(alg) == 1 }
}
pub fn PSA_ALG_IS_SIGN(alg: psa_algorithm_t) -> bool {
unsafe { psa_crypto_binding::shim_PSA_ALG_IS_SIGN(alg) == 1 }
}
pub fn PSA_ALG_IS_ASYMMETRIC_ENCRYPTION(alg: psa_algorithm_t) -> bool {
unsafe { psa_crypto_binding::shim_PSA_ALG_IS_ASYMMETRIC_ENCRYPTION(alg) == 1 }
}
pub unsafe fn PSA_ALG_IS_RSA_OAEP(alg: psa_algorithm_t) -> bool {
psa_crypto_binding::shim_PSA_ALG_IS_RSA_OAEP(alg) == 1
}
pub fn PSA_ALG_IS_KEY_AGREEMENT(alg: psa_algorithm_t) -> bool {
unsafe { psa_crypto_binding::shim_PSA_ALG_IS_KEY_AGREEMENT(alg) == 1 }
}
pub fn PSA_ALG_IS_RAW_KEY_AGREEMENT(alg: psa_algorithm_t) -> bool {
unsafe { psa_crypto_binding::shim_PSA_ALG_IS_RAW_KEY_AGREEMENT(alg) == 1 }
}
pub fn PSA_ALG_IS_FFDH(alg: psa_algorithm_t) -> bool {
unsafe { psa_crypto_binding::shim_PSA_ALG_IS_FFDH(alg) == 1 }
}
pub fn PSA_ALG_IS_ECDH(alg: psa_algorithm_t) -> bool {
unsafe { psa_crypto_binding::shim_PSA_ALG_IS_ECDH(alg) == 1 }
}
pub fn PSA_ALG_IS_KEY_DERIVATION(alg: psa_algorithm_t) -> bool {
unsafe { psa_crypto_binding::shim_PSA_ALG_IS_KEY_DERIVATION(alg) == 1 }
}
pub fn PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg: psa_algorithm_t) -> bool {
unsafe { psa_crypto_binding::shim_PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) == 1 }
}
pub fn PSA_ALG_IS_RSA_PSS(alg: psa_algorithm_t) -> bool {
unsafe { psa_crypto_binding::shim_PSA_ALG_IS_RSA_PSS(alg) == 1 }
}
pub fn PSA_ALG_IS_ECDSA(alg: psa_algorithm_t) -> bool {
unsafe { psa_crypto_binding::shim_PSA_ALG_IS_ECDSA(alg) == 1 }
}
pub fn PSA_ALG_IS_DETERMINISTIC_ECDSA(alg: psa_algorithm_t) -> bool {
unsafe { psa_crypto_binding::shim_PSA_ALG_IS_DETERMINISTIC_ECDSA(alg) == 1 }
}
pub fn PSA_ALG_IS_HKDF(alg: psa_algorithm_t) -> bool {
unsafe { psa_crypto_binding::shim_PSA_ALG_IS_HKDF(alg) == 1 }
}
pub fn PSA_ALG_IS_TLS12_PRF(alg: psa_algorithm_t) -> bool {
unsafe { psa_crypto_binding::shim_PSA_ALG_IS_TLS12_PRF(alg) == 1 }
}
pub fn PSA_ALG_IS_TLS12_PSK_TO_MS(alg: psa_algorithm_t) -> bool {
unsafe { psa_crypto_binding::shim_PSA_ALG_IS_TLS12_PSK_TO_MS(alg) == 1 }
}
pub fn PSA_ALG_SIGN_GET_HASH(sign_alg: psa_algorithm_t) -> psa_algorithm_t {
unsafe { psa_crypto_binding::shim_PSA_ALG_SIGN_GET_HASH(sign_alg) }
}
pub fn PSA_ALG_RSA_OAEP_GET_HASH(rsa_oaep_alg: psa_algorithm_t) -> psa_algorithm_t {
unsafe { psa_crypto_binding::shim_PSA_ALG_RSA_OAEP_GET_HASH(rsa_oaep_alg) }
}
pub fn PSA_ALG_HMAC_GET_HASH(hmac_alg: psa_algorithm_t) -> psa_algorithm_t {
unsafe { psa_crypto_binding::shim_PSA_ALG_HMAC_GET_HASH(hmac_alg) }
}
pub fn PSA_ALG_HKDF_GET_HASH(hkdf_alg: psa_algorithm_t) -> psa_algorithm_t {
unsafe { psa_crypto_binding::shim_PSA_ALG_HKDF_GET_HASH(hkdf_alg) }
}
pub fn PSA_ALG_TLS12_PRF_GET_HASH(tls12_prf_alg: psa_algorithm_t) -> psa_algorithm_t {
unsafe { psa_crypto_binding::shim_PSA_ALG_TLS12_PRF_GET_HASH(tls12_prf_alg) }
}
pub fn PSA_ALG_TLS12_PSK_TO_MS_GET_HASH(tls12_psk_to_ms_alg: psa_algorithm_t) -> psa_algorithm_t {
unsafe { psa_crypto_binding::shim_PSA_ALG_TLS12_PSK_TO_MS_GET_HASH(tls12_psk_to_ms_alg) }
}
pub unsafe fn PSA_ALG_KEY_AGREEMENT_GET_BASE(alg: psa_algorithm_t) -> psa_algorithm_t {
psa_crypto_binding::shim_PSA_ALG_KEY_AGREEMENT_GET_BASE(alg)
}
pub unsafe fn PSA_ALG_KEY_AGREEMENT_GET_KDF(alg: psa_algorithm_t) -> psa_algorithm_t {
psa_crypto_binding::shim_PSA_ALG_KEY_AGREEMENT_GET_KDF(alg)
}
pub fn PSA_ALG_RSA_PKCS1V15_SIGN(hash_alg: psa_algorithm_t) -> psa_algorithm_t {
unsafe { psa_crypto_binding::shim_PSA_ALG_RSA_PKCS1V15_SIGN(hash_alg) }
}
pub fn PSA_ALG_RSA_PSS(hash_alg: psa_algorithm_t) -> psa_algorithm_t {
unsafe { psa_crypto_binding::shim_PSA_ALG_RSA_PSS(hash_alg) }
}
pub fn PSA_ALG_ECDSA(hash_alg: psa_algorithm_t) -> psa_algorithm_t {
unsafe { psa_crypto_binding::shim_PSA_ALG_ECDSA(hash_alg) }
}
pub fn PSA_ALG_DETERMINISTIC_ECDSA(hash_alg: psa_algorithm_t) -> psa_algorithm_t {
unsafe { psa_crypto_binding::shim_PSA_ALG_DETERMINISTIC_ECDSA(hash_alg) }
}
pub unsafe fn PSA_ALG_RSA_OAEP(hash_alg: psa_algorithm_t) -> psa_algorithm_t {
psa_crypto_binding::shim_PSA_ALG_RSA_OAEP(hash_alg)
}
pub unsafe fn PSA_ALG_HMAC(hash_alg: psa_algorithm_t) -> psa_algorithm_t {
psa_crypto_binding::shim_PSA_ALG_HMAC(hash_alg)
}
pub unsafe fn PSA_ALG_TRUNCATED_MAC(
mac_alg: psa_algorithm_t,
mac_length: usize,
) -> psa_algorithm_t {
psa_crypto_binding::shim_PSA_ALG_TRUNCATED_MAC(mac_alg, mac_length)
}
pub unsafe fn PSA_ALG_FULL_LENGTH_MAC(mac_alg: psa_algorithm_t) -> psa_algorithm_t {
psa_crypto_binding::shim_PSA_ALG_FULL_LENGTH_MAC(mac_alg)
}
pub unsafe fn PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG(aead_alg: psa_algorithm_t) -> psa_algorithm_t {
psa_crypto_binding::shim_PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG(aead_alg)
}
pub unsafe fn PSA_ALG_AEAD_WITH_SHORTENED_TAG(
aead_alg: psa_algorithm_t,
tag_length: usize,
) -> psa_algorithm_t {
psa_crypto_binding::shim_PSA_ALG_AEAD_WITH_SHORTENED_TAG(aead_alg, tag_length)
}
pub unsafe fn PSA_ALG_HKDF(hash_alg: psa_algorithm_t) -> psa_algorithm_t {
psa_crypto_binding::shim_PSA_ALG_HKDF(hash_alg)
}
pub unsafe fn PSA_ALG_TLS12_PRF(hash_alg: psa_algorithm_t) -> psa_algorithm_t {
psa_crypto_binding::shim_PSA_ALG_TLS12_PRF(hash_alg)
}
pub unsafe fn PSA_ALG_TLS12_PSK_TO_MS(hash_alg: psa_algorithm_t) -> psa_algorithm_t {
psa_crypto_binding::shim_PSA_ALG_TLS12_PSK_TO_MS(hash_alg)
}
pub unsafe fn PSA_ALG_KEY_AGREEMENT(
raw_key_agreement: psa_algorithm_t,
key_derivation: psa_algorithm_t,
) -> psa_algorithm_t {
psa_crypto_binding::shim_PSA_ALG_KEY_AGREEMENT(raw_key_agreement, key_derivation)
}
pub fn PSA_KEY_TYPE_IS_ECC_KEY_PAIR(key_type: psa_key_type_t) -> bool {
unsafe { psa_crypto_binding::shim_PSA_KEY_TYPE_IS_ECC_KEY_PAIR(key_type) == 1 }
}
pub fn PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY(key_type: psa_key_type_t) -> bool {
unsafe { psa_crypto_binding::shim_PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY(key_type) == 1 }
}
pub fn PSA_KEY_TYPE_IS_DH_KEY_PAIR(key_type: psa_key_type_t) -> bool {
unsafe { psa_crypto_binding::shim_PSA_KEY_TYPE_IS_DH_KEY_PAIR(key_type) == 1 }
}
pub fn PSA_KEY_TYPE_IS_DH_PUBLIC_KEY(key_type: psa_key_type_t) -> bool {
unsafe { psa_crypto_binding::shim_PSA_KEY_TYPE_IS_DH_PUBLIC_KEY(key_type) == 1 }
}
pub fn PSA_KEY_TYPE_ECC_GET_FAMILY(key_type: psa_key_type_t) -> psa_ecc_family_t {
unsafe { psa_crypto_binding::shim_PSA_KEY_TYPE_ECC_GET_FAMILY(key_type) }
}
pub fn PSA_KEY_TYPE_DH_GET_FAMILY(key_type: psa_key_type_t) -> psa_dh_family_t {
unsafe { psa_crypto_binding::shim_PSA_KEY_TYPE_DH_GET_FAMILY(key_type) }
}
pub fn PSA_KEY_TYPE_ECC_KEY_PAIR(curve: psa_ecc_family_t) -> psa_key_type_t {
unsafe { psa_crypto_binding::shim_PSA_KEY_TYPE_ECC_KEY_PAIR(curve) }
}
pub fn PSA_KEY_TYPE_ECC_PUBLIC_KEY(curve: psa_ecc_family_t) -> psa_key_type_t {
unsafe { psa_crypto_binding::shim_PSA_KEY_TYPE_ECC_PUBLIC_KEY(curve) }
}
pub fn PSA_KEY_TYPE_DH_KEY_PAIR(group: psa_dh_family_t) -> psa_key_type_t {
unsafe { psa_crypto_binding::shim_PSA_KEY_TYPE_DH_KEY_PAIR(group) }
}
pub fn PSA_KEY_TYPE_DH_PUBLIC_KEY(group: psa_dh_family_t) -> psa_key_type_t {
unsafe { psa_crypto_binding::shim_PSA_KEY_TYPE_DH_PUBLIC_KEY(group) }
}
pub unsafe fn PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(key_type: psa_key_type_t) -> psa_key_type_t {
psa_crypto_binding::shim_PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(key_type)
}
pub unsafe fn PSA_SIGN_OUTPUT_SIZE(
key_type: psa_key_type_t,
key_bits: usize,
alg: psa_algorithm_t,
) -> usize {
psa_crypto_binding::shim_PSA_SIGN_OUTPUT_SIZE(key_type, key_bits, alg)
}
pub unsafe fn PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(
key_type: psa_key_type_t,
key_bits: usize,
alg: psa_algorithm_t,
) -> usize {
psa_crypto_binding::shim_PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(key_type, key_bits, alg)
}
pub unsafe fn PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(
key_type: psa_key_type_t,
key_bits: usize,
alg: psa_algorithm_t,
) -> usize {
psa_crypto_binding::shim_PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(key_type, key_bits, alg)
}
pub unsafe fn PSA_EXPORT_KEY_OUTPUT_SIZE(key_type: psa_key_type_t, key_bits: usize) -> usize {
psa_crypto_binding::shim_PSA_EXPORT_KEY_OUTPUT_SIZE(key_type, key_bits)
}
pub fn PSA_HASH_LENGTH(alg: psa_algorithm_t) -> usize {
unsafe { psa_crypto_binding::shim_PSA_HASH_LENGTH(alg) }
}
pub unsafe fn PSA_MAC_LENGTH(
key_type: psa_key_type_t,
key_bits: usize,
alg: psa_algorithm_t,
) -> usize {
psa_crypto_binding::shim_PSA_MAC_LENGTH(key_type, key_bits, alg)
}
pub unsafe fn PSA_MAC_TRUNCATED_LENGTH(alg: psa_algorithm_t) -> usize {
// No longer in PSA spec but required to convert form psa_algorithm_to to algorithm/Mac
psa_crypto_binding::shim_PSA_MAC_TRUNCATED_LENGTH(alg)
}
pub fn PSA_AEAD_TAG_LENGTH(
key_type: psa_key_type_t,
key_bits: usize,
alg: psa_algorithm_t,
) -> usize {
unsafe { psa_crypto_binding::shim_PSA_AEAD_TAG_LENGTH(key_type, key_bits, alg) }
}
pub unsafe fn PSA_AEAD_ENCRYPT_OUTPUT_SIZE(
key_type: psa_key_type_t,
alg: psa_algorithm_t,
plaintext_length: usize,
) -> usize {
psa_crypto_binding::shim_PSA_AEAD_ENCRYPT_OUTPUT_SIZE(key_type, alg, plaintext_length)
}
pub unsafe fn PSA_AEAD_DECRYPT_OUTPUT_SIZE(
key_type: psa_key_type_t,
alg: psa_algorithm_t,
ciphertext_length: usize,
) -> usize {
psa_crypto_binding::shim_PSA_AEAD_DECRYPT_OUTPUT_SIZE(key_type, alg, ciphertext_length)
}
psa-crypto-sys-0.9.3/src/types.rs 0000644 0000000 0000000 00000001014 10461020230 0015047 0 ustar 0000000 0000000 // Copyright 2020 Contributors to the Parsec project.
// SPDX-License-Identifier: Apache-2.0
#![allow(non_camel_case_types)]
//! Specification-defined types
pub type psa_status_t = i32;
pub type psa_key_type_t = u16;
pub type psa_ecc_family_t = u8;
pub type psa_dh_family_t = u8;
pub type psa_algorithm_t = u32;
pub type psa_key_lifetime_t = u32;
pub type psa_key_persistence_t = u8;
pub type psa_key_location_t = u32;
pub type psa_key_id_t = u32;
pub type psa_key_usage_t = u32;
pub type psa_key_derivation_step_t = u16;