Struct optee_utee::crypto_op::Digest

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

An operation for digest the message.

Implementations§

source§

impl Digest

source

pub fn update(&self, chunk: &[u8])

Accumulate message data for hashing. The message does not have to be block aligned. Subsequent calls to this function are possible. The operation may be in either initial or active state and becomes active.

§Parameters
  1. chunk: Chunk of data to be hashed
§Panics
  1. If the operation is not allocated with valid algorithms.
  2. if input data exceeds maximum length for algorithm.
  3. Hardware or cryptographic algorithm failure.
  4. If the Implementation detects any other error.
source

pub fn do_final(&self, chunk: &[u8], hash: &mut [u8]) -> Result<usize>

Finalize the message digest operation and produces the message hash. Afterwards the Message Digest operation is reset to initial state and can be reused.

§Parameters
  1. chunk: Last chunk of data to be hashed.
  2. hash: Output buffer filled with the message hash. This buffer should be large enough to hold the hash message. The real used size is returned by this function.
§Example
let chunk1 = [0u8;8];
let chunk2 = [1u8;8];
let mut hash = [0u8;32];
match Digest::allocate(AlgorithmId::Sha256) {
    Ok(operation) =>
    {
        operation.update(&chunk1);
        match operation.do_final(&chunk2, &mut hash) {
            Ok(hash_len) => {
                // ...
                Ok(())
            }
            Err(e) => Err(e),
        }
    }
    Err(e) => Err(e),
}
§Errors
  1. ShortBuffer: If the hash is too small. Operation is not finalized for this error.
§Panics
  1. If the operation is not allocated with valid algorithms.
  2. if input data exceeds maximum length for algorithm.
  3. Hardware or cryptographic algorithm failure.
  4. If the Implementation detects any other error.
source

pub fn null() -> Self

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

source

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

Allocate a new cryptographic operation and sets the mode and algorithm type.

§Parameters
  1. algo: One of the algorithms that support Digest as listed in AlgorithmId.
  2. max_key_size: The maximum key sizes of different algorithms as defined in TransientObjectType.
§Example
match Digest::allocate(AlgorithmId::Sha256) {
    Ok(operation) =>
    {
        // ...
        Ok(())
    }
    Err(e) => Err(e),
}
§Errors
  1. OutOfMemory: If not enough resources are available to allocate the object handle.
  2. NotSupported: If the key size is not supported or the object type is not supported.
§Panics
  1. If the Implementation detects any error associated with this function which is not explicitly associated with a defined return code for this function.
source

pub fn info(&self) -> OperationInfo

Return the characteristics of a Digest operation.

§Example
match Digest::allocate(AlgorithmId::Md5) {
    Ok(operation) =>
    {
        let info = operation.info();
        Ok(())
    }
    Err(e) => Err(e),
}
§Panics
  1. If the operation is not a valid opened operation.
  2. if the Implementation detecs any other error.
source

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

Return the characteristics of a Digest operation with multiple keys.

§Parameters
  1. info_buf: The buffer is supposed to save multiple keys, and its size should be large enough before passed in. The number of keys about this operation can be calculated as: OperationInfoMultiple::size - size_of(OperationInfoMultiple) / size_of ( raw::TEE_OperationInfoKey)+1.
§Example
match Digest::allocate(AlgorithmId::Md5) {
    Ok(operation) =>
    {
        let mut buffer = [0u8, 12];
        match operation.info_multiple(&mut buffer) {
            Ok(info_multiple) => {
                // ...
                Ok(())
            }
            Err(e) => Err(e),
        }
    }
    Err(e) => Err(e),
}
§Errors:
  1. ShortBuffer: If the info_buf is not large enough to hold an OperationInfoMultiple and the corresponding keys.
§Panics:
  1. If operation is not a valid opened object.
  2. If the Implementation detects any other error.
source

pub fn reset(&mut self)

Reset the operation state to the state after initial allocate with the add addition of any keys which were configured subsequent to this so that current operation can be reused with the same keys.

§Panics
  1. If operation is not a valid opened object.
  2. If the key has not been set yet.
  3. Hardware or cryptographic algorithm failure.
  4. If the Implementation detects any other error.
source

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

Copy an operation state to another operation. This also copies the key material associated with the source operation.

§Parameters
  1. src: the source operation. 1.1) If src has no key programmed, then the key of this operation is cleared. If there is a key programmed in srcOperation, then the maximum key size of current SHALL be greater than or equal to the actual key size of src.
§Example
match Digest::allocate(AlgorithmId::Sha256) {
    Ok(mut operation) =>
    {
        match Digest::allocate(AlgorithmId::Sha256) {
            Ok(operation2) =>
            {
                // ...
                operation.copy(&operation2);
                Ok(())
            },
            Err(e) => Err(e),
        }
    },
    Err(e) => Err(e),
}
§Panics
  1. If the operation or source operation is not a valid opened operation.
  2. If the alogirhtm or mode differe in two perations.
  3. If src has akey and its size is greater than the maximum key size of the operation.
  4. Hardware or cryptographic algorithm failure.
  5. If the Implementation detects any other error.

Trait Implementations§

source§

impl OpHandle for Digest

source§

fn handle(&self) -> TEE_OperationHandle

Return the handle of an operation.

Auto Trait Implementations§

§

impl Freeze for Digest

§

impl RefUnwindSafe for Digest

§

impl !Send for Digest

§

impl !Sync for Digest

§

impl Unpin for Digest

§

impl UnwindSafe for Digest

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.