Conversation
|
Build failed only on insufficient memory and doxygen mistake: I'll add the boards after review: |
mtausig
left a comment
There was a problem hiding this comment.
TBH, I don't quite see the point of this cipher mode.
The code looks find,though, apart from minor things.
| /* MAC */ | ||
| 0x4F, 0xDE, 0x52, 0x90, 0x61, 0xF9, 0xC6, 0xF1 | ||
| }; | ||
| static const size_t TEST_IEEE_0537R2_3_EXPECTED_LEN = 38; |
There was a problem hiding this comment.
Could you maybe add some more test vectors with longer data. Since the CCM implementation had problems in the past in that area, it would be helpful.
There was a problem hiding this comment.
Does it make sense to add those? They both share the same base code, and those extended length cases are already tested in tests-crypto-modes-ccms.c, I could still generate some if you feel its needed.
There was a problem hiding this comment.
Why not just add one long sequence... Doesn't the above referenced document provide one?
There was a problem hiding this comment.
Nope, I added all the vectors provided in the document. I added in the last fixup some longer test vectors generated with PyCryptodome.
Fix naming
Fix and and comment on valid mac_length
More code comments
Returning 0 on an empty message is actually also a fix for ccm, so should be its own commit.
PeterKietzmann
left a comment
There was a problem hiding this comment.
Code looks good to me, just left some minor comments for improvement. Provided test passes.
sys/crypto/modes/ccm.c
Outdated
| const uint8_t *input, size_t input_len, | ||
| uint8_t *plain) | ||
| { | ||
| if(_validate_mac_length_ccms(mac_length)){ |
There was a problem hiding this comment.
Just to double check, this is the only difference to cipher_decrypt_ccm above?
There was a problem hiding this comment.
Yes and no. CCM* specifies as well that:
The nonce N shall encode the potential values for M such that one can uniquely determine from N the actually used value of M. The exact format of the nonce N is outside the scope of this specification and shall be determined and fixed by the actual implementation environment of the CCM* mode.
This part I did not address, this PR intended only to allow messages requiring only encryption. How to generate that nonce to encode M, and how to decode M from the nonce, was not required for me currently. I would address it latter if needed. But I realize this is not clear in the documentation I will add a comment.
There was a problem hiding this comment.
Did you check how this is implemented elsewhere? OpenWSN?
| } | ||
|
|
||
| #define do_test_decrypt_op(name) do { \ | ||
| test_decrypt_op(TEST_ ## name ## _KEY, TEST_ ## name ## _KEY_LEN, \ |
There was a problem hiding this comment.
I'm not familiar with the new tests/sys_crypto structure. Is it possible to share this between tests-crypto-modes-ccm.c and tests-crypto-modes-ccms.c ?
There was a problem hiding this comment.
The macros could be in a shared header file yes , and I could move the shared test_decrypt_op()/test_encrypt_op into a helper source file as well.
There was a problem hiding this comment.
Ah, this hasn't been addressed yet.
@mtausig the OpenWSN re-integration in #13824 requires it. This mode is involved in link layer security in TSCH networks. Do you have objections? |
No, if there is a valid reason for it I'm OK with it. Maybe add a disclaimer in the documentation to prevent it from beeing used for generic encryption. |
Add long plain text and aad tests
…test Fix ccm to ccms
_valid_mac_length_% return 1 if valid, 0 otherwise
Skip MAC computation when M=0
… test change doc to make explicit that plaintext=0 is allowed
Explicit plaintext length in header
PeterKietzmann
left a comment
There was a problem hiding this comment.
@fjmolinas thanks for addressing my comments! The code looks good, an adequate amount of documentation is in place and tests still pass. ACK from my side. Please squash
Add implemenation disclaimer.
Added a note in the documentation
Add more context on this in the documentation. Note that If at some point the nonce is encoded, this would depend on the application. Since this was out of scope of the specification they just use the |
Contiki's implementation also just receives the nonce. But let me take a second look elsewhere. |
I looked again into Also in the case of OpenWSN If I come around implementing a scheme for nonce encoding, I would re-open. |
|
Closed. |
Contribution description
This PR extends CCM to add CCM* (CCMS) . It differs from CCM in that it can be used for messages that require only encryption.
The test cases have been taken from [1] as well.
[1] https://mentor.ieee.org/802.15/dcn/04/15-04-0537-02-004b-formal-specification-ccm-star-mode-operation.pdf
Testing procedure
run test
make -C tests/sys_crypto/ all testtake a look at [1] to check the implementation (or better said adaptation of the already existing CCM)