-
Notifications
You must be signed in to change notification settings - Fork 10
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
edhoc-hacspec: declassify numbers before return from parse #60
edhoc-hacspec: declassify numbers before return from parse #60
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for hte PR! My main comment/question is whether we can homogenize the code such that declassify
does not appear in top-level functions? With the current code, some parts are declassified and some are not, which is not ideal IMO
hacspec/out/Edhoc_hacspec.fst
Outdated
@@ -0,0 +1,1129 @@ | |||
module Edhoc_hacspec |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the .fst file part of this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Committed it by mistake... removing.
hacspec/src/lib.rs
Outdated
// Step 2: verify that the selected cipher suite is supported | ||
if supported_suites[0u8].declassify() == EDHOC_SUPPORTED_SUITES[0u8].declassify() { | ||
if supported_suites[0] == EDHOC_SUPPORTED_SUITES[0u8].declassify() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's homogenize this so declassify
does not appear any more in *_process_message
?
hacspec/src/lib.rs
Outdated
@@ -220,7 +220,7 @@ pub fn r_process_message_3( | |||
let (kid, mac_3) = decode_plaintext_3(&plaintext_3); | |||
|
|||
// compare the kid received with the kid expected in id_cred_i | |||
if kid.declassify() == id_cred_i_expected[id_cred_i_expected.len() - 1].declassify() { | |||
if kid == id_cred_i_expected[id_cred_i_expected.len() - 1].declassify() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment as above
hacspec/src/lib.rs
Outdated
@@ -420,7 +420,7 @@ pub fn i_process_message_2( | |||
|
|||
// Check MAC before checking KID | |||
if mac_2.declassify_eq(&expected_mac_2) { | |||
if kid.declassify() == id_cred_r_expected[id_cred_r_expected.len() - 1].declassify() { | |||
if kid == id_cred_r_expected[id_cred_r_expected.len() - 1].declassify() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see above
2675302
to
caea2ad
Compare
I think it is a good idea to be more homogeneous. Just checking how we would do it:
|
Why not? Is it used elsewhere? It seems the cleanest IMO |
@@ -899,7 +900,10 @@ fn encode_kdf_context( | |||
// encode context in line | |||
// assumes ID_CRED_R and CRED_R are already CBOR-encoded | |||
let mut output = BytesMaxContextBuffer::new(); | |||
output = output.update(0, id_cred); | |||
for i in 0..id_cred.len() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why dont you use copy_from_slice
here? also, remove the code that is commented out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see why.. output
is a hacspec type.. nevermind the comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -1292,7 +1297,7 @@ mod tests { | |||
fn test_compute_mac_3() { | |||
let prk_4e3m_tv = BytesHashLen::from_hex(PRK_4E3M_TV); | |||
let th_3_tv = BytesHashLen::from_hex(TH_3_TV); | |||
let id_cred_i_tv = BytesIdCred::from_hex(ID_CRED_I_TV); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use ID_CRED_I_TV
directly in the call to compute_mac_3
below? i.e. you could remove line 1300
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also update it ssimilarly for other occurences, noted with "same comment"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sure, done.
PR should be ready now, just need to be able to check that fstar generation is still working. |
hacspec/src/lib.rs
Outdated
@@ -1426,7 +1429,7 @@ mod tests { | |||
|
|||
#[test] | |||
fn test_encode_plaintext_3() { | |||
let id_cred_i_tv = BytesIdCred::from_hex(ID_CRED_I_TV); | |||
let id_cred_i_tv = ID_CRED_I_TV; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment on using ID_CRED_I_TV
directly applies
hacspec/src/lib.rs
Outdated
@@ -1345,14 +1348,14 @@ mod tests { | |||
0, | |||
PLAINTEXT_2_TV.len() / 2, | |||
); | |||
let id_cred_r_tv = BytesIdCred::from_hex(ID_CRED_R_TV); | |||
let id_cred_r_tv = ID_CRED_R_TV; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment applies
hacspec/src/lib.rs
Outdated
@@ -1330,7 +1333,7 @@ mod tests { | |||
#[test] | |||
fn test_encode_plaintext_2() { | |||
let plaintext_2_tv = BytesPlaintext2::from_hex(PLAINTEXT_2_TV); | |||
let id_cred_r_tv = BytesIdCred::from_hex(ID_CRED_R_TV); | |||
let id_cred_r_tv = ID_CRED_R_TV; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment
hacspec/src/lib.rs
Outdated
@@ -1310,7 +1313,7 @@ mod tests { | |||
#[test] | |||
fn test_compute_and_verify_mac_2() { | |||
let prk_3e2m_tv = BytesHashLen::from_hex(PRK_3E2M_TV); | |||
let id_cred_r_tv = BytesIdCred::from_hex(ID_CRED_R_TV); | |||
let id_cred_r_tv = ID_CRED_R_TV; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment
@@ -1292,7 +1297,7 @@ mod tests { | |||
fn test_compute_mac_3() { | |||
let prk_4e3m_tv = BytesHashLen::from_hex(PRK_4E3M_TV); | |||
let th_3_tv = BytesHashLen::from_hex(TH_3_TV); | |||
let id_cred_i_tv = BytesIdCred::from_hex(ID_CRED_I_TV); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also update it ssimilarly for other occurences, noted with "same comment"
b393e38
to
838baf6
Compare
Still needed: test fstar generation after type changes. |
After the merge of #105 this is not applicable anymore. |
Addressing #49.