Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Rust-FFI conversions for Attributes #13

Merged
merged 1 commit into from
May 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions psa-crypto-sys/src/c/shim.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@ 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)
{
Expand Down Expand Up @@ -152,3 +170,63 @@ psa_algorithm_t
shim_PSA_ALG_DETERMINISTIC_ECDSA(psa_algorithm_t hash_alg) {
return PSA_ALG_DETERMINISTIC_ECDSA(hash_alg);
}

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_ecc_curve_t
shim_PSA_KEY_TYPE_GET_CURVE(psa_key_type_t key_type)
{
return PSA_KEY_TYPE_GET_CURVE(key_type);
}

psa_dh_group_t
shim_PSA_KEY_TYPE_GET_GROUP(psa_key_type_t key_type)
{
return PSA_KEY_TYPE_GET_GROUP(key_type);
}

psa_key_type_t
shim_PSA_KEY_TYPE_ECC_KEY_PAIR(psa_ecc_curve_t curve)
{
return PSA_KEY_TYPE_ECC_KEY_PAIR(curve);
}

psa_key_type_t
shim_PSA_KEY_TYPE_ECC_PUBLIC_KEY(psa_ecc_curve_t curve)
{
return PSA_KEY_TYPE_ECC_PUBLIC_KEY(curve);
}

psa_key_type_t
shim_PSA_KEY_TYPE_DH_KEY_PAIR(psa_dh_group_t group)
{
return PSA_KEY_TYPE_DH_KEY_PAIR(group);
}

psa_key_type_t
shim_PSA_KEY_TYPE_DH_PUBLIC_KEY(psa_dh_group_t group)
{
return PSA_KEY_TYPE_DH_PUBLIC_KEY(group);
}
67 changes: 36 additions & 31 deletions psa-crypto-sys/src/c/shim.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,42 +40,22 @@ const psa_key_type_t shim_PSA_KEY_TYPE_AES = PSA_KEY_TYPE_AES;
const psa_key_type_t shim_PSA_KEY_TYPE_DES = PSA_KEY_TYPE_DES;
const psa_key_type_t shim_PSA_KEY_TYPE_CAMELLIA = PSA_KEY_TYPE_CAMELLIA;
const psa_key_type_t shim_PSA_KEY_TYPE_ARC4 = PSA_KEY_TYPE_ARC4;
const psa_key_type_t shim_PSA_KEY_TYPE_CHACHA20 = PSA_KEY_TYPE_CHACHA20;
const psa_key_type_t shim_PSA_KEY_TYPE_RSA_PUBLIC_KEY = PSA_KEY_TYPE_RSA_PUBLIC_KEY;
const psa_key_type_t shim_PSA_KEY_TYPE_RSA_KEY_PAIR = PSA_KEY_TYPE_RSA_KEY_PAIR;
const psa_key_type_t shim_PSA_KEY_TYPE_DSA_PUBLIC_KEY = PSA_KEY_TYPE_DSA_PUBLIC_KEY;
const psa_key_type_t shim_PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE = PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE;
const psa_key_type_t shim_PSA_KEY_TYPE_ECC_KEY_PAIR_BASE = PSA_KEY_TYPE_ECC_KEY_PAIR_BASE;
const psa_key_type_t shim_PSA_KEY_TYPE_ECC_CURVE_MASK = PSA_KEY_TYPE_ECC_CURVE_MASK;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_SECT163K1 = PSA_ECC_CURVE_SECT163K1;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_SECT163R1 = PSA_ECC_CURVE_SECT163R1;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_SECT163R2 = PSA_ECC_CURVE_SECT163R2;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_SECT193R1 = PSA_ECC_CURVE_SECT193R1;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_SECT193R2 = PSA_ECC_CURVE_SECT193R2;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_SECT233K1 = PSA_ECC_CURVE_SECT233K1;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_SECT233R1 = PSA_ECC_CURVE_SECT233R1;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_SECT239K1 = PSA_ECC_CURVE_SECT239K1;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_SECT283K1 = PSA_ECC_CURVE_SECT283K1;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_SECT283R1 = PSA_ECC_CURVE_SECT283R1;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_SECT409K1 = PSA_ECC_CURVE_SECT409K1;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_SECT409R1 = PSA_ECC_CURVE_SECT409R1;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_SECT571K1 = PSA_ECC_CURVE_SECT571K1;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_SECT571R1 = PSA_ECC_CURVE_SECT571R1;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_SECP160K1 = PSA_ECC_CURVE_SECP160K1;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_SECP160R1 = PSA_ECC_CURVE_SECP160R1;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_SECP160R2 = PSA_ECC_CURVE_SECP160R2;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_SECP192K1 = PSA_ECC_CURVE_SECP192K1;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_SECP192R1 = PSA_ECC_CURVE_SECP192R1;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_SECP224K1 = PSA_ECC_CURVE_SECP224K1;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_SECP224R1 = PSA_ECC_CURVE_SECP224R1;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_SECP256K1 = PSA_ECC_CURVE_SECP256K1;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_SECP256R1 = PSA_ECC_CURVE_SECP256R1;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_SECP384R1 = PSA_ECC_CURVE_SECP384R1;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_SECP521R1 = PSA_ECC_CURVE_SECP521R1;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_BRAINPOOL_P256R1 = PSA_ECC_CURVE_BRAINPOOL_P256R1;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_BRAINPOOL_P384R1 = PSA_ECC_CURVE_BRAINPOOL_P384R1;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_BRAINPOOL_P512R1 = PSA_ECC_CURVE_BRAINPOOL_P512R1;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_CURVE25519 = PSA_ECC_CURVE_CURVE25519;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_CURVE448 = PSA_ECC_CURVE_CURVE448;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_SECP_K1 = PSA_ECC_CURVE_SECP_K1;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_SECP_R1 = PSA_ECC_CURVE_SECP_R1;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_SECP_R2 = PSA_ECC_CURVE_SECP_R2;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_SECT_K1 = PSA_ECC_CURVE_SECT_K1;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_SECT_R1 = PSA_ECC_CURVE_SECT_R1;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_SECT_R2 = PSA_ECC_CURVE_SECT_R2;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_BRAINPOOL_P_R1 = PSA_ECC_CURVE_BRAINPOOL_P_R1;
const psa_ecc_curve_t shim_PSA_ECC_CURVE_MONTGOMERY = PSA_ECC_CURVE_MONTGOMERY;
const psa_dh_group_t shim_PSA_DH_GROUP_RFC7919 = PSA_DH_GROUP_RFC7919;
const psa_algorithm_t shim_PSA_ALG_VENDOR_FLAG = PSA_ALG_VENDOR_FLAG;
const psa_algorithm_t shim_PSA_ALG_CATEGORY_MASK = PSA_ALG_CATEGORY_MASK;
const psa_algorithm_t shim_PSA_ALG_CATEGORY_HASH = PSA_ALG_CATEGORY_HASH;
Expand Down Expand Up @@ -150,7 +130,12 @@ shim_get_key_bits(const psa_key_attributes_t *attributes);

psa_key_type_t
shim_get_key_type(const psa_key_attributes_t *attributes);

psa_key_lifetime_t
shim_get_key_lifetime(const psa_key_attributes_t *attributes);
psa_algorithm_t
shim_get_key_algorithm(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);

Expand Down Expand Up @@ -212,3 +197,23 @@ psa_algorithm_t
shim_PSA_ALG_DETERMINISTIC_ECDSA(psa_algorithm_t hash_alg);
psa_algorithm_t
shim_PSA_ALG_SIGN_GET_HASH(psa_algorithm_t alg);
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_curve_t
shim_PSA_KEY_TYPE_GET_CURVE(psa_key_type_t key_type);
psa_dh_group_t
shim_PSA_KEY_TYPE_GET_GROUP(psa_key_type_t key_type);
psa_key_type_t
shim_PSA_KEY_TYPE_ECC_KEY_PAIR(psa_ecc_curve_t curve);
psa_key_type_t
shim_PSA_KEY_TYPE_ECC_PUBLIC_KEY(psa_ecc_curve_t curve);
psa_key_type_t
shim_PSA_KEY_TYPE_DH_KEY_PAIR(psa_dh_group_t group);
psa_key_type_t
shim_PSA_KEY_TYPE_DH_PUBLIC_KEY(psa_dh_group_t group);
40 changes: 10 additions & 30 deletions psa-crypto-sys/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,42 +49,22 @@ pub const PSA_KEY_TYPE_AES: psa_key_type_t = shim_PSA_KEY_TYPE_AES;
pub const PSA_KEY_TYPE_DES: psa_key_type_t = shim_PSA_KEY_TYPE_DES;
pub const PSA_KEY_TYPE_CAMELLIA: psa_key_type_t = shim_PSA_KEY_TYPE_CAMELLIA;
pub const PSA_KEY_TYPE_ARC4: psa_key_type_t = shim_PSA_KEY_TYPE_ARC4;
pub const PSA_KEY_TYPE_CHACHA20: psa_key_type_t = shim_PSA_KEY_TYPE_CHACHA20;
pub const PSA_KEY_TYPE_RSA_PUBLIC_KEY: psa_key_type_t = shim_PSA_KEY_TYPE_RSA_PUBLIC_KEY;
pub const PSA_KEY_TYPE_RSA_KEY_PAIR: psa_key_type_t = shim_PSA_KEY_TYPE_RSA_KEY_PAIR;
pub const PSA_KEY_TYPE_DSA_PUBLIC_KEY: psa_key_type_t = shim_PSA_KEY_TYPE_DSA_PUBLIC_KEY;
pub const PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE: psa_key_type_t = shim_PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE;
pub const PSA_KEY_TYPE_ECC_KEY_PAIR_BASE: psa_key_type_t = shim_PSA_KEY_TYPE_ECC_KEY_PAIR_BASE;
pub const PSA_KEY_TYPE_ECC_CURVE_MASK: psa_key_type_t = shim_PSA_KEY_TYPE_ECC_CURVE_MASK;
pub const PSA_ECC_CURVE_SECT163K1: psa_ecc_curve_t = shim_PSA_ECC_CURVE_SECT163K1;
pub const PSA_ECC_CURVE_SECT163R1: psa_ecc_curve_t = shim_PSA_ECC_CURVE_SECT163R1;
pub const PSA_ECC_CURVE_SECT163R2: psa_ecc_curve_t = shim_PSA_ECC_CURVE_SECT163R2;
pub const PSA_ECC_CURVE_SECT193R1: psa_ecc_curve_t = shim_PSA_ECC_CURVE_SECT193R1;
pub const PSA_ECC_CURVE_SECT193R2: psa_ecc_curve_t = shim_PSA_ECC_CURVE_SECT193R2;
pub const PSA_ECC_CURVE_SECT233K1: psa_ecc_curve_t = shim_PSA_ECC_CURVE_SECT233K1;
pub const PSA_ECC_CURVE_SECT233R1: psa_ecc_curve_t = shim_PSA_ECC_CURVE_SECT233R1;
pub const PSA_ECC_CURVE_SECT239K1: psa_ecc_curve_t = shim_PSA_ECC_CURVE_SECT239K1;
pub const PSA_ECC_CURVE_SECT283K1: psa_ecc_curve_t = shim_PSA_ECC_CURVE_SECT283K1;
pub const PSA_ECC_CURVE_SECT283R1: psa_ecc_curve_t = shim_PSA_ECC_CURVE_SECT283R1;
pub const PSA_ECC_CURVE_SECT409K1: psa_ecc_curve_t = shim_PSA_ECC_CURVE_SECT409K1;
pub const PSA_ECC_CURVE_SECT409R1: psa_ecc_curve_t = shim_PSA_ECC_CURVE_SECT409R1;
pub const PSA_ECC_CURVE_SECT571K1: psa_ecc_curve_t = shim_PSA_ECC_CURVE_SECT571K1;
pub const PSA_ECC_CURVE_SECT571R1: psa_ecc_curve_t = shim_PSA_ECC_CURVE_SECT571R1;
pub const PSA_ECC_CURVE_SECP160K1: psa_ecc_curve_t = shim_PSA_ECC_CURVE_SECP160K1;
pub const PSA_ECC_CURVE_SECP160R1: psa_ecc_curve_t = shim_PSA_ECC_CURVE_SECP160R1;
pub const PSA_ECC_CURVE_SECP160R2: psa_ecc_curve_t = shim_PSA_ECC_CURVE_SECP160R2;
pub const PSA_ECC_CURVE_SECP192K1: psa_ecc_curve_t = shim_PSA_ECC_CURVE_SECP192K1;
pub const PSA_ECC_CURVE_SECP192R1: psa_ecc_curve_t = shim_PSA_ECC_CURVE_SECP192R1;
pub const PSA_ECC_CURVE_SECP224K1: psa_ecc_curve_t = shim_PSA_ECC_CURVE_SECP224K1;
pub const PSA_ECC_CURVE_SECP224R1: psa_ecc_curve_t = shim_PSA_ECC_CURVE_SECP224R1;
pub const PSA_ECC_CURVE_SECP256K1: psa_ecc_curve_t = shim_PSA_ECC_CURVE_SECP256K1;
pub const PSA_ECC_CURVE_SECP256R1: psa_ecc_curve_t = shim_PSA_ECC_CURVE_SECP256R1;
pub const PSA_ECC_CURVE_SECP384R1: psa_ecc_curve_t = shim_PSA_ECC_CURVE_SECP384R1;
pub const PSA_ECC_CURVE_SECP521R1: psa_ecc_curve_t = shim_PSA_ECC_CURVE_SECP521R1;
pub const PSA_ECC_CURVE_BRAINPOOL_P256R1: psa_ecc_curve_t = shim_PSA_ECC_CURVE_BRAINPOOL_P256R1;
pub const PSA_ECC_CURVE_BRAINPOOL_P384R1: psa_ecc_curve_t = shim_PSA_ECC_CURVE_BRAINPOOL_P384R1;
pub const PSA_ECC_CURVE_BRAINPOOL_P512R1: psa_ecc_curve_t = shim_PSA_ECC_CURVE_BRAINPOOL_P512R1;
pub const PSA_ECC_CURVE_CURVE25519: psa_ecc_curve_t = shim_PSA_ECC_CURVE_CURVE25519;
pub const PSA_ECC_CURVE_CURVE448: psa_ecc_curve_t = shim_PSA_ECC_CURVE_CURVE448;
pub const PSA_ECC_CURVE_SECP_K1: psa_ecc_curve_t = shim_PSA_ECC_CURVE_SECP_K1;
pub const PSA_ECC_CURVE_SECP_R1: psa_ecc_curve_t = shim_PSA_ECC_CURVE_SECP_R1;
pub const PSA_ECC_CURVE_SECP_R2: psa_ecc_curve_t = shim_PSA_ECC_CURVE_SECP_R2;
pub const PSA_ECC_CURVE_SECT_K1: psa_ecc_curve_t = shim_PSA_ECC_CURVE_SECT_K1;
pub const PSA_ECC_CURVE_SECT_R1: psa_ecc_curve_t = shim_PSA_ECC_CURVE_SECT_R1;
pub const PSA_ECC_CURVE_SECT_R2: psa_ecc_curve_t = shim_PSA_ECC_CURVE_SECT_R2;
pub const PSA_ECC_CURVE_BRAINPOOL_P_R1: psa_ecc_curve_t = shim_PSA_ECC_CURVE_BRAINPOOL_P_R1;
pub const PSA_ECC_CURVE_MONTGOMERY: psa_ecc_curve_t = shim_PSA_ECC_CURVE_MONTGOMERY;
pub const PSA_DH_GROUP_RFC7919: psa_dh_group_t = shim_PSA_DH_GROUP_RFC7919;
pub const PSA_ALG_VENDOR_FLAG: psa_algorithm_t = shim_PSA_ALG_VENDOR_FLAG;
pub const PSA_ALG_CATEGORY_MASK: psa_algorithm_t = shim_PSA_ALG_CATEGORY_MASK;
pub const PSA_ALG_CATEGORY_HASH: psa_algorithm_t = shim_PSA_ALG_CATEGORY_HASH;
Expand Down
52 changes: 52 additions & 0 deletions psa-crypto-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ pub unsafe fn psa_get_key_type(attributes: *const psa_key_attributes_t) -> psa_k
shim_get_key_type(attributes)
}

pub unsafe fn psa_get_key_lifetime(attributes: *const psa_key_attributes_t) -> psa_key_lifetime_t {
shim_get_key_lifetime(attributes)
}

pub unsafe fn psa_get_key_algorithm(attributes: *const psa_key_attributes_t) -> psa_algorithm_t {
shim_get_key_algorithm(attributes)
}

pub unsafe fn psa_get_key_usage_flags(attributes: *const psa_key_attributes_t) -> psa_key_usage_t {
shim_get_key_usage_flags(attributes)
}

pub unsafe fn psa_key_attributes_init() -> psa_key_attributes_t {
shim_key_attributes_init()
}
Expand Down Expand Up @@ -139,3 +151,43 @@ pub fn PSA_ALG_ECDSA(hash_alg: psa_algorithm_t) -> psa_algorithm_t {
pub fn PSA_ALG_DETERMINISTIC_ECDSA(hash_alg: psa_algorithm_t) -> psa_algorithm_t {
unsafe { shim_PSA_ALG_DETERMINISTIC_ECDSA(hash_alg) }
}

pub fn PSA_KEY_TYPE_IS_ECC_KEY_PAIR(key_type: psa_key_type_t) -> bool {
unsafe { 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 { 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 { 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 { shim_PSA_KEY_TYPE_IS_DH_PUBLIC_KEY(key_type) == 1 }
}

pub fn PSA_KEY_TYPE_GET_CURVE(key_type: psa_key_type_t) -> psa_ecc_curve_t {
unsafe { shim_PSA_KEY_TYPE_GET_CURVE(key_type) }
}

pub fn PSA_KEY_TYPE_GET_GROUP(key_type: psa_key_type_t) -> psa_dh_group_t {
unsafe { shim_PSA_KEY_TYPE_GET_GROUP(key_type) }
}

pub fn PSA_KEY_TYPE_ECC_KEY_PAIR(curve: psa_ecc_curve_t) -> psa_key_type_t {
unsafe { shim_PSA_KEY_TYPE_ECC_KEY_PAIR(curve) }
}

pub fn PSA_KEY_TYPE_ECC_PUBLIC_KEY(curve: psa_ecc_curve_t) -> psa_key_type_t {
unsafe { shim_PSA_KEY_TYPE_ECC_PUBLIC_KEY(curve) }
}

pub fn PSA_KEY_TYPE_DH_KEY_PAIR(group: psa_dh_group_t) -> psa_key_type_t {
unsafe { shim_PSA_KEY_TYPE_DH_KEY_PAIR(group) }
}

pub fn PSA_KEY_TYPE_DH_PUBLIC_KEY(group: psa_dh_group_t) -> psa_key_type_t {
unsafe { shim_PSA_KEY_TYPE_DH_PUBLIC_KEY(group) }
}
9 changes: 5 additions & 4 deletions psa-crypto/src/operations/key_management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
use crate::initialized;
use crate::types::key::{Attributes, Id};
use crate::types::status::{Result, Status};
use core::convert::TryFrom;

/// Generate a key
pub fn generate_key(attributes: Attributes, id: Option<u32>) -> Result<Id> {
initialized()?;

let mut attributes = psa_crypto_sys::psa_key_attributes_t::from(attributes);
let mut attributes = psa_crypto_sys::psa_key_attributes_t::try_from(attributes)?;
let id = if let Some(id) = id {
unsafe { psa_crypto_sys::psa_set_key_id(&mut attributes, id) };
id
Expand All @@ -23,7 +24,7 @@ pub fn generate_key(attributes: Attributes, id: Option<u32>) -> Result<Id> {
Status::from(unsafe { psa_crypto_sys::psa_generate_key(&attributes, &mut handle) })
.to_result()?;

unsafe { psa_crypto_sys::psa_reset_key_attributes(&mut attributes) };
Attributes::reset(&mut attributes);

Ok(Id {
id,
Expand All @@ -47,7 +48,7 @@ pub unsafe fn destroy_key(key: Id) -> Result<()> {
pub fn import_key(attributes: Attributes, id: Option<u32>, data: &[u8]) -> Result<Id> {
initialized()?;

let mut attributes = psa_crypto_sys::psa_key_attributes_t::from(attributes);
let mut attributes = psa_crypto_sys::psa_key_attributes_t::try_from(attributes)?;
let id = if let Some(id) = id {
unsafe { psa_crypto_sys::psa_set_key_id(&mut attributes, id) };
id
Expand All @@ -61,7 +62,7 @@ pub fn import_key(attributes: Attributes, id: Option<u32>, data: &[u8]) -> Resul
})
.to_result()?;

unsafe { psa_crypto_sys::psa_reset_key_attributes(&mut attributes) };
Attributes::reset(&mut attributes);

Ok(Id {
id,
Expand Down
Loading