Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sancus_untag functions and fix sancus_unwrap_with_key #37

Merged
merged 5 commits into from
Oct 20, 2021

Conversation

gianlu33
Copy link
Member

@gianlu33 gianlu33 commented Oct 8, 2021

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!

}

// compare MAC with provided reference `tag`
return constant_time_cmp(tag, computed_tag, SANCUS_TAG_SIZE) == 0;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jovanbulck would this comparison be a security issue as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes good point,it might, so better to avoid this. Since the function already returns an int, no need to do this comparison to zero.

I changed the order of these functions so that we could call 
`sancus_untag_with_key` inside sancus_`unwrap_with_key`. To do so, the 
former needs to be declared before the latter
Normally, `sancus_unwrap_with_key` always fails if cipher_len is zero. 
This commit solves this issue by leveraging `sancus_untag_with_key`
@jovanbulck jovanbulck merged commit dc39101 into sancus-tee:master Oct 20, 2021
@jovanbulck
Copy link
Member

Merged, thanks @gianlu33 ! 👍

gianlu33 pushed a commit to AuthenticExecution/sancus-compiler that referenced this pull request Nov 4, 2021
Add `sancus_untag` functions and fix `sancus_unwrap_with_key`
gianlu33 pushed a commit to AuthenticExecution/sancus-compiler that referenced this pull request Nov 5, 2021
Add `sancus_untag` functions and fix `sancus_unwrap_with_key`
@gianlu33 gianlu33 deleted the sancus-untag branch November 9, 2021 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants