Struct optee_utee::crypto_op::Asymmetric [−][src]
pub struct Asymmetric(_);
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
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.
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.
pub 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.
pub 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.
Create an Asymmetric operation without any specific algorithm or other data.
Function usage is similar to Digest::allocate.
Function usage is similar to Digest::info.
Function usage is similar to Digest::info_multiple.
Function usage is similar to Cipher::set_key.
Function usage is similar to Digest::copy.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Asymmetric
impl !Send for Asymmetric
impl !Sync for Asymmetric
impl Unpin for Asymmetric
impl UnwindSafe for Asymmetric
Blanket Implementations
pub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
pub fn from(t: T) -> T
pub fn from(t: T) -> T
Performs the conversion.
pub fn into(self) -> U
pub fn into(self) -> U
Performs the conversion.