Struct optee_utee::crypto_op::Digest[][src]

pub struct Digest(_);
Expand description

An operation for digest the message.

Implementations

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.

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 chunk = [0u8;8];
let chunk = [1u8;8];
let hash = [0u8;32];
match Digest::allocate(AlgorithmId::Sha256) {
    Ok(operation) =>
    {
        operation.update(&chunk1);
        match operation.do_final(&chunk2, 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.

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

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.

Return the characteristics of a Digest operation.

Example

match Digest::allocate(AlgorithmId::Md5, 128) {
    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.

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, 128) {
    Ok(operation) =>
    {
        let mut buffer = [0u32, 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.

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.

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(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

Return the handle of an operation.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.