RFC: Expose AEAD, HKDF, and ECDH from mbedTLS #19166
Unanswered
beriberikix
asked this question in
Core Development
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
I'd like to propose exposing three cryptographic primitives that are already (or nearly) compiled into mbedTLS to Python:
cryptolibhashlibecmoduleThese primitives enable secure IoT protocols without requiring users to build native modules.
Motivation
Modern IoT protocols require cryptographic primitives beyond what MicroPython currently exposes:
Currently, projects needing these primitives must:
.mpymodules (complex, architecture-specific)This is significant friction when mbedTLS is already compiled into the firmware with these capabilities.
Current State
The common mbedTLS config (
extmod/mbedtls/mbedtls_config_common.h) already enables:These are used internally for TLS but not accessible from Python.
Not currently compiled:
MBEDTLS_HKDF_C— ~1KB additional codeMBEDTLS_CHACHA20_C/MBEDTLS_CHACHAPOLY_C— ~4KB (optional)Proposed API
1. AEAD in
cryptolib(extends existing module)Alternative one-shot API (simpler, lower memory):
2. HKDF in
hashlib(extends existing module)Note: CPython's
hashlibdoesn't include HKDF (it's in thecryptographypackage). This would be a documented MicroPython extension, following the pattern of other MicroPython-specific additions.3. ECDH in new
ecmoduleOptional future extension:
CPython Compatibility
cryptolib(already MicroPython-specific)hashlibhashlibas documented MicroPython extensionecmodule (MicroPython-specific)Per the contributor guidelines, these would be documented as MicroPython additions since CPython doesn't expose these in its standard library (they're in third-party packages like
cryptography).Configuration Flags
All features would be opt-in via
MICROPY_*flags, defaulting based onMICROPY_SSL_MBEDTLS:Ports with size constraints can disable specific features.
Code Size Estimate
ChaCha20-Poly1305 would add ~4 KB if enabled.
Test Vectors
Standard test vectors would be included:
Implementation Approach
I propose splitting this into three separate PRs for easier review:
MBEDTLS_HKDF_CEach PR would include:
Use Cases
Beyond the protocols listed above, these primitives enable:
Questions for Maintainers
cryptolibwith AEAD the right home, or should this be a new module?hashlib.hkdf_sha256()acceptable, or would a separatekdfmodule be preferred?aes) or one-shot functions?References
I'm happy to implement this if there's interest. I have a working proof-of-concept as a native module that could serve as a reference for the API design.
Beta Was this translation helpful? Give feedback.
All reactions