Struct optee_utee::crypto_op::Asymmetric
source · pub struct Asymmetric(/* private fields */);
Expand description
An operation for conducting asymmetric encryption /decryption or asymmetric sign / verify. Note that asymmetric encryption is always “single-stage”, which differs from Cipher which are always “multi-stage”.
Implementations§
source§impl Asymmetric
impl Asymmetric
sourcepub fn encrypt(&self, params: &[Attribute], src: &[u8]) -> Result<Vec<u8>>
pub fn encrypt(&self, params: &[Attribute], src: &[u8]) -> Result<Vec<u8>>
Encrypt a message.
§Parameters
params
: Optional operation parameters.src
: Input plaintext buffer.
§Example
let clear = [1u8; 8];
match TransientObject::allocate(TransientObjectType::RsaKeypair, 256) {
Ok(key) => {
key.generate_key(256, &[])?;
match Asymmetric::allocate(
AlgorithmId::RsaesPkcs1V15,
OperationMode::Encrypt,
256) {
Ok(operation) => {
operation.set_key(&key)?;
match operation.encrypt(&[], &clear) {
Ok(ciph_text) => {
// Get cipher text as a vector
// ...
Ok(())
}
Err(e) => Err(e),
}
}
Err(e) => Err(e),
}
}
Err(e) => Err(e),
}
§Errors
ShortBuffer
: If the output buffer is not large enough to hold the result.BadParameters
: If the length of the input buffer is not consistent with the algorithm or key size.CiphertextInvalid
: If there is an error in the packing used on the ciphertext.
§Panics
- If the algorithm is not a valid algorithm for [Encrypt](OperationMode::Encrypt] of
Asymmetric
. - If no key is programmed in the operation.
- Hardware or cryptographic algorithm failure.
- If the Implementation detects any other error.
sourcepub fn decrypt(&self, params: &[Attribute], src: &[u8]) -> Result<Vec<u8>>
pub fn decrypt(&self, params: &[Attribute], src: &[u8]) -> Result<Vec<u8>>
Decrypt a message.
§Parameters
params
: Optional operation parameters.src
: Input ciphertext buffer.
§Errors
ShortBuffer
: If the output buffer is not large enough to hold the result.BadParameters
: If the length of the input buffer is not consistent with the algorithm or key size.CiphertextInvalid
: If there is an error in the packing used on the ciphertext.
§Panics
- If the algorithm is not a valid algorithm for [Decrypt](OperationMode::Decrypt] of
Asymmetric
. - If no key is programmed in the operation.
- Hardware or cryptographic algorithm failure.
- If the Implementation detects any other error.
sourcepub fn sign_digest(
&self,
params: &[Attribute],
digest: &[u8],
signature: &mut [u8]
) -> Result<usize>
pub fn sign_digest( &self, params: &[Attribute], digest: &[u8], signature: &mut [u8] ) -> Result<usize>
Sign a message digest.
§Parameters
params
: Optional operation parameters.digest
: Input buffer containing the input message digest.signature
: Output buffer written with the signature of the digest.
§Errors
ShortBuffer
: Ifsignature
is not large enough to hold the result.
§Panics
- If the algorithm is not a valid algorithm for [Sign](OperationMode::Sign] of
Asymmetric
. - If no key is programmed in the operation.
- If the mode is not set as [Sign](OperationMode::Sign].
- If
digest.len()
is not equal to the hash size of the algorithm. - Hardware or cryptographic algorithm failure.
- If the Implementation detects any other error.
sourcepub fn verify_digest(
&self,
params: &[Attribute],
digest: &[u8],
signature: &[u8]
) -> Result<()>
pub fn verify_digest( &self, params: &[Attribute], digest: &[u8], signature: &[u8] ) -> Result<()>
Verify a message digest.
§Parameters
params
: Optional operation parameters.digest
: Input buffer containing the input message digest.signature
: Input buffer containing the signature to verify.
§Errors
SignatureInvalid
: If the signature is invalid.
§Panics
- If the algorithm is not a valid algorithm for [Verify](OperationMode::Verify] of
Asymmetric
. - If no key is programmed in the operation.
- If the mode is not set as [Verify](OperationMode::Verify].
- If
digest.len()
is not equal to the hash size of the algorithm. - Hardware or cryptographic algorithm failure.
- If the Implementation detects any other error.
sourcepub fn null() -> Self
pub fn null() -> Self
Create an Asymmetric operation without any specific algorithm or other data.
sourcepub fn allocate(
algo: AlgorithmId,
mode: OperationMode,
max_key_size: usize
) -> Result<Self>
pub fn allocate( algo: AlgorithmId, mode: OperationMode, max_key_size: usize ) -> Result<Self>
Function usage is similar to Digest::allocate.
sourcepub fn info(&self) -> OperationInfo
pub fn info(&self) -> OperationInfo
Function usage is similar to Digest::info.
sourcepub fn info_multiple(
&self,
info_buf: &mut [u8]
) -> Result<OperationInfoMultiple>
pub fn info_multiple( &self, info_buf: &mut [u8] ) -> Result<OperationInfoMultiple>
Function usage is similar to Digest::info_multiple.
sourcepub fn set_key<T: GenericObject>(&self, object: &T) -> Result<()>
pub fn set_key<T: GenericObject>(&self, object: &T) -> Result<()>
Function usage is similar to Cipher::set_key.
sourcepub fn copy<T: OpHandle>(&mut self, src: &T)
pub fn copy<T: OpHandle>(&mut self, src: &T)
Function usage is similar to Digest::copy.
Trait Implementations§
source§impl OpHandle for Asymmetric
impl OpHandle for Asymmetric
source§fn handle(&self) -> TEE_OperationHandle
fn handle(&self) -> TEE_OperationHandle
Return the handle of an operation.
Auto Trait Implementations§
impl Freeze for Asymmetric
impl RefUnwindSafe for Asymmetric
impl !Send for Asymmetric
impl !Sync for Asymmetric
impl Unpin for Asymmetric
impl UnwindSafe for Asymmetric
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more