Repository navigation
Conversation
Jongy
left a comment
There was a problem hiding this comment.
Nice PR :) I'd like to see MicroPython getting support for such new features.
Left you some comments on the implementation. Should also add some tests - can base them on existing crypto tests at tests/extmod/ucryptolib_*.
|
On the subject of tests, I wrote some, but currently the tests are run on the Unix build and the Unix build doesn't pass the standard tests when built with mbedTLS, and this only runs with mbedTLS. The axTLS project seems to be dead, so we should probably switch the Unix build over to mbedTLS. At some point when I have time I will fix the standard tests to work with mbedTLS and at that time I'll expand that test coverage to cover this too, but at the moment any tests that I write for this won't be able to run under the existing test build setup. |
|
Is there any consensus on merging this? The Travis failure is a Zephyr docker image issue, which is unrelated to the PR, and the 0.004% reduction in coverage seems to be a sampling error since the changes are to do with things that are untouched by this PR. |
Add two stage reset for BLE
This comment was marked as outdated.
This comment was marked as outdated.
|
@nickovs Any updates on this? |
|
@AmirHmZz This probably now needs a substantial rework, given all the changes to Micropython over the last five years. If I get the chance I will look into rebasing it against the current mainline branch, but I have a lot of other things going on right now so I'm not sure when I can find the time. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #6389 +/- ##
=======================================
Coverage 98.38% 98.38%
=======================================
Files 171 171
Lines 22298 22363 +65
=======================================
+ Hits 21937 22002 +65
Misses 361 361 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Code size report: |
|
OK, I have rebased this to the latest master branch and I've also updated the tests to hopefully have full coverage of the new code. References to I have also changed the default value for |
There was a problem hiding this comment.
Hi @nickovs, thanks for updating this PR for more than five years! It looks very comprehensive.
I can see the benefit of supporting GCM mode in MicroPython, but we have to balance this against the code size impact for all users of boards where it's enabled. Do you (or anyone else watching this PR) have an example of what kind of applications use the AES-GCM mode directly from MicroPython?
I suppose the only viable alternative to putting this into the base firmware would be to implement different cipher modes in micropython-lib in Python, on top of the basic AES primitive from cryptolib. That's a lot of cryptographic code that we'd be "rolling our own", so probably not advisable even if someone wanted to do the work. 😬
There's a couple of unrelated issues with the current iteration of this PR:
- Some submodules are showing as updated, I assume accidentally. If you're having trouble getting these back in line then let me know and I can push an update to the branch.
- The CI checks didn't run on the latest push, I think they'll run once the merge conflict in the submodule is resolved.
|
@projectgus Thanks for picking this up. Aside from being the generally "recommended mode" for AES these days, AES-GCM shows up in a lot of modern protocols. Probably the one most likely to get used on its own in an embedded situation is JWE (JSON Web Encryption) but it also gets used in various datagram protocols (my need was for PSSST, but it's also in DTLS), it's used in a bunch of low level 802.11 WiFi security protocols, and of course it shows up in TLS and QUIC. Rolling our own in Regarding the submodules versioning, I find Git submodule handling mysterious and any update here was not intentional. If you have the ability to push an update that would be appreciated. I suspect that doing so will trigger a new CI event and hopefully that should un-block things. |
|
Thanks @nickovs for the quick reply!
Thanks for explaining. JWE and PSSST are good use cases, thanks! I'm aware it's also part of many common protocols like DTLS and TLS, etc. but we don't need a Python API to support these use cases.
I agree!
Yes. If the code size impact was a bit smaller then exposing the Python wrapper would be a really easy thing to approve. 500 bytes is not huge but it's not tiny either. I had a look at the code earlier to see if anything could be combined or refactored inside modcryptolib.c to reduce code size, but I didn't see anything really obvious.
Will do, one sec! This should also give us the latest code size numbers. |
d510d13 to
873e38e
Compare
Signed-off-by: Nicko van Someren <[email protected]>
|
Overall this looks like a good addition to me, especially since it's just wrapping existing mbedTLS code that's already in the firmware. And it's an extension of the existing ECB/CBC/CTR modes, implementing GCM. Three comments:
|
This PR implements support for AES using Galois Counter Mode, a mode for Authenticated Encryption with Additional Data (AEAD) that protects not only the confidentiality of the plaintext but the integrity of both the plaintext and optional additional data. AESGCM is widely used in internet protocols, is included included in many standards and is supported by the
cryptographyCPython library.This implementation currently only supports systems that use mbedTLS for cryptography and not axTLS. This is due to axTLS both not including the necessary code and being effectively a dead project from a development point of view.
The new functionality is enabled by setting the
MICROPY_PY_UCRYPTOLIB_GCMflag in thempconfigport.hheader. The PR sets this by default for theesp32build (since it builds with mbedTLS already and the size increase is modest).The PR also includes documentation for the new class and methods.
Note that the function signatures for the
encrypt()anddecrypt()methods differ from the ones for the basicaesclass. This is because AEAD operations both require more inputs and have different semantics to the underlying block cipher operations. This is also why the functionality was implemented as a new class rather than a new mode on the existing class.