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!
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:
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
andsancus_tag_with_key
up in the file. The reason is because I added a call tosancus_untag_with_key
insidesancus_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!