sancus-tee / sancus-compiler

Secure compilation of annotated C code to Sancus enclaves
GNU General Public License v3.0
6 stars 7 forks source link

Add `sancus_untag` functions and fix `sancus_unwrap_with_key` #37

Closed gianlu33 closed 3 years ago

gianlu33 commented 3 years ago

This implements what discussed in #36 and fixes (in sw of course) the bug mentioned in sancus-tee/sancus-core#26.

About the constant-time comparison function, I basically copied the NaCl function referenced in #31. However, I didn't really understand why they use this logic in the return statement:

return (1 & ((d - 1) >> 8)) - 1;

Is there a specific reason for this logic (I mean, in terms of security)? Can't this be simplified to something like return d == 0?

I also had to move sancus_tag and sancus_tag_with_key up in the file. The reason is because I added a call to sancus_untag_with_key inside sancus_unwrap_with_key, therefore the former needed to be declared before the latter.

Edit: I just read what @jovanbulck wrote in #31, so that logic in the return statement is to avoid having an if branch. Good!

jovanbulck commented 3 years ago

Merged, thanks @gianlu33 ! :+1: