Struct optee_utee::crypto_op::Digest
source · pub struct Digest(/* private fields */);
Expand description
An operation for digest the message.
Implementations§
source§impl Digest
impl Digest
sourcepub fn update(&self, chunk: &[u8])
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
chunk
: Chunk of data to be hashed
§Panics
- If the operation is not allocated with valid algorithms.
- if input data exceeds maximum length for algorithm.
- Hardware or cryptographic algorithm failure.
- If the Implementation detects any other error.
sourcepub fn do_final(&self, chunk: &[u8], hash: &mut [u8]) -> Result<usize>
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
chunk
: Last chunk of data to be hashed.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
ShortBuffer
: If thehash
is too small. Operation is not finalized for this error.
§Panics
- If the operation is not allocated with valid algorithms.
- if input data exceeds maximum length for algorithm.
- Hardware or cryptographic algorithm failure.
- If the Implementation detects any other error.
sourcepub fn allocate(algo: AlgorithmId) -> Result<Self>
pub fn allocate(algo: AlgorithmId) -> Result<Self>
Allocate a new cryptographic operation and sets the mode and algorithm type.
§Parameters
algo
: One of the algorithms that support Digest as listed in AlgorithmId.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
OutOfMemory
: If not enough resources are available to allocate the object handle.NotSupported
: If the key size is not supported or the object type is not supported.
§Panics
- If the Implementation detects any error associated with this function which is not explicitly associated with a defined return code for this function.
sourcepub fn info(&self) -> OperationInfo
pub fn info(&self) -> OperationInfo
sourcepub fn info_multiple(
&self,
info_buf: &mut [u8]
) -> Result<OperationInfoMultiple>
pub fn info_multiple( &self, info_buf: &mut [u8] ) -> Result<OperationInfoMultiple>
Return the characteristics of a Digest operation with multiple keys.
§Parameters
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:
ShortBuffer
: If theinfo_buf
is not large enough to hold an OperationInfoMultiple and the corresponding keys.
§Panics:
- If operation is not a valid opened object.
- If the Implementation detects any other error.
sourcepub fn reset(&mut self)
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
- If operation is not a valid opened object.
- If the key has not been set yet.
- Hardware or cryptographic algorithm failure.
- If the Implementation detects any other error.
sourcepub fn copy<T: OpHandle>(&mut self, src: &T)
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
src
: the source operation. 1.1) Ifsrc
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
- If the operation or source operation is not a valid opened operation.
- If the alogirhtm or mode differe in two perations.
- If
src
has akey and its size is greater than the maximum key size of the operation. - Hardware or cryptographic algorithm failure.
- If the Implementation detects any other error.