ivila commented on code in PR #308:
URL:
https://github.com/apache/teaclave-trustzone-sdk/pull/308#discussion_r3472824707
##########
examples/aes-rs/ta/src/main.rs:
##########
@@ -149,31 +151,28 @@ pub fn set_aes_key(aes: &mut AesCipher, params: &mut
Parameters) -> Result<()> {
Ok(())
}
-pub fn reset_aes_iv(aes: &mut AesCipher, params: &mut Parameters) ->
Result<()> {
- let mut param0 = unsafe { params.0.as_memref()? };
- let iv = param0.buffer();
+pub fn reset_aes_iv(aes: &mut AesCipher, (p0, _, _, _): &mut
ParametersAny<'_>) -> Result<()> {
+ let iv = p0.as_memref_input()?.as_slice();
aes.cipher.init(iv);
trace_println!("[+] TA initial vectore reset done!");
Ok(())
}
-pub fn cipher_buffer(aes: &mut AesCipher, params: &mut Parameters) ->
Result<()> {
- let mut param0 = unsafe { params.0.as_memref()? };
- let mut param1 = unsafe { params.1.as_memref()? };
+pub fn cipher_buffer(aes: &mut AesCipher, (p0, p1, _, _): &mut
ParametersAny<'_>) -> Result<()> {
+ let (input, output) = (p0.as_memref_input()?, p1.as_memref_output()?);
- let input = param0.buffer();
- let output = param1.buffer();
-
- if output.len() < input.len() {
+ if output.get_capacity() < input.as_slice().len() {
return Err(ErrorKind::BadParameters.into());
}
trace_println!("[+] TA tries to update ciphers!");
- let tmp_size = aes.cipher.update(input, output)?;
- param1.set_updated_size(tmp_size);
+ let tmp_size = aes
+ .cipher
+ .update(input.as_slice(), unsafe { output.as_mut_slice() })?;
Review Comment:
making `as_mut_slice` is to inform developers that they must take care of
the updated_size after using it, and at most of the time the develoers should
use the safe `set_output` method.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]