Struct optee_utee::crypto_op::DeriveKey

source ·
pub struct DeriveKey(/* private fields */);
Expand description

An operation for derive a shared key object.

Implementations§

source§

impl DeriveKey

source

pub fn derive(&self, params: &[Attribute], object: &mut TransientObject)

Take one of the Asymmetric Derivation Operation Algorithm that supports this operation as defined in AlgorithmId, and output a key object.

§Parameters
  1. params: For algorithm DhDeriveSharedSecret, DhPublicValue is required as the passed in attribute.
  2. object: An uninitialized transient object to be filled with the derived key.
§Example

let attr_prime = AttributeMemref::from_ref(AttributeId::DhPrime, &[23u8]);
let attr_base = AttributeMemref::from_ref(AttributeId::DhBase, &[5u8]);
let mut public_1 = [0u8; 32];
match TransientObject::allocate(TransientObjectType::DhKeypair, 256) {
    Ok(key_pair_1) => {
        key_pair_1.generate_key(256, &[attr_prime.into(), attr_base.into()])?;
        key_pair_1.ref_attribute(AttributeId::DhPublicValue, &mut public_1)?;
        Ok(())
    },
    Err(e) => Err(e),
}


let attr_prime = AttributeMemref::from_ref(AttributeId::DhPrime, &[23u8]);
let attr_base = AttributeMemref::from_ref(AttributeId::DhBase, &[5u8]);
match TransientObject::allocate(TransientObjectType::DhKeypair, 256) {
    Ok(key_pair_2) => {
        key_pair_2.generate_key(256, &[attr_prime.into(), attr_base.into()])?;
        match DeriveKey::allocate(AlgorithmId::DhDeriveSharedSecret, 256) {
            Ok(operation) => {
                operation.set_key(&key_pair_2)?;
                match TransientObject::allocate(TransientObjectType::GenericSecret, 256) {
                    // Derived key is saved as an transient object
                    Ok(mut derived_key) => {
                        let attr_public = AttributeMemref::from_ref(AttributeId::DhPublicValue, &public_1);
                        operation.derive(&[attr_public.into()], &mut derived_key);
                        // ...
                        Ok(())
                    }
                    Err(e) => Err(e),
                }
            }
            Err(e) => Err(e),
        }
    }
    Err(e) => Err(e),
}
§Panics
  1. If the algorithm is not a valid algorithm for DeriveKey.
  2. If the object is too small for generated value.
  3. If no key is programmed in the operation.
  4. Hardware or cryptographic algorithm failure.
  5. If the Implementation detects any other error.
source

pub fn null() -> Self

Create a DeriveKey operation without any specific algorithm or other data.

source

pub fn allocate(algo: AlgorithmId, max_key_size: usize) -> Result<Self>

Function usage is similar to Digest::allocate. Currently only supports DhDeriveSharedSecret as algo.

source

pub fn info(&self) -> OperationInfo

Function usage is similar to Digest::info.

source

pub fn info_multiple( &self, info_buf: &mut [u8] ) -> Result<OperationInfoMultiple>

Function usage is similar to Digest::info_multiple.

source

pub fn set_key<T: GenericObject>(&self, object: &T) -> Result<()>

Function usage is similar to Cipher::set_key.

source

pub fn copy<T: OpHandle>(&mut self, src: &T)

Function usage is similar to Digest::copy.

Trait Implementations§

source§

impl OpHandle for DeriveKey

source§

fn handle(&self) -> TEE_OperationHandle

Return the handle of an operation.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.