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

Crypto: sancus_unwrap always fails if cipher_len is zero #26

Open
gianlu33 opened this issue Oct 6, 2021 · 5 comments
Open

Crypto: sancus_unwrap always fails if cipher_len is zero #26

gianlu33 opened this issue Oct 6, 2021 · 5 comments

Comments

@gianlu33
Copy link
Member

gianlu33 commented Oct 6, 2021

Ideally, what we would like to happen is a simple comparison between the provided MAC (tag) and the MAC calculated over the provided associated data (ad). This is not happening though, the return value of sancus_unwrap is always false.

Interestingly, sancus_wrap works fine if the plaintext length is zero. In fact, it returns true and the calculated MAC is correct.

Note that the result if the same no matter the value of the cipher pointer (NULL or not): if cipher_len is zero, sancus_unwrap always fails.

@fritzalder
Copy link
Member

That's interesting..do we have a sancus_wrap example? I think I never actively used sancus_wrap before.

@gianlu33
Copy link
Member Author

gianlu33 commented Oct 6, 2021

I just added a test on my repo: gianlu33/sancus-examples@19c68f9

You can adjust the value of MSG_SIZE to see what happens when the size is zero.

You can also experience the bug mentioned in #1 if you specify an odd number for MSG_SIZE (e.g., 1)

Edit: oops, I messed up with the TAG length.. I updated the commit

@jovanbulck
Copy link
Member

hm it seems like you want the inverse of sancus_tag, say sancus_untag. That indeed doesn't exist in sm_support.h and is not supported atm when manually calling sancus_wrap. This could probably be better documented.

In principle one could fix the hardware to support this, but not sure this is worth it. You essentially can call sancus_tag() in software and do a proper constant-time comparison in software.

@jovanbulck
Copy link
Member

That's interesting..do we have a sancus_wrap example? I think I never actively used sancus_wrap before.

there's sensor-reader for that, with a full round-trip: wrap of a random number in the sancus enclave and an unwrap later in the makefile to simulate the remote stakeholder

@jovanbulck
Copy link
Member

linking this to #27

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

No branches or pull requests

3 participants