DemesneGH commented on code in PR #308:
URL:
https://github.com/apache/teaclave-trustzone-sdk/pull/308#discussion_r3472690932
##########
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:
Since we have eliminated most `unsafe` in the example code, can we also
avoid using `unsafe` here?
The interfaces seems a bit not user-friendly when writing back to output.
--
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]