Skip to content

Conversation

@rot256
Copy link
Contributor

@rot256 rot256 commented Feb 11, 2026

When using OpenSSL, objects allocated during matrix generation are never freed, leaking memory on every keygen, encapsulation, and decapsulation.

Can verify the memory leak (on macOS) using:

cargo test -p frodo-kem --features openssl --no-run 2>&1 | grep -o 'frodo_kem-[^ )]*' | head -1 | xargs -I{} sh -c 'MallocStackLogging=1 leaks --atExit -- target/debug/deps/{}'

With output:

<TRUNCATED>
7   frodo_kem-4b28b6bdda7d5aed            0x104d06a8c frodo_kem::Algorithm::inner_generate_keypair::h75a46a4868372de8 + 60  lib.rs:1358
6   frodo_kem-4b28b6bdda7d5aed            0x104d4357c frodo_kem::hazmat::traits::Kem::generate_keypair::ha8b1217d1779d0cb + 1064  traits.rs:162
5   frodo_kem-4b28b6bdda7d5aed            0x104d39624 _$LT$frodo_kem..hazmat..models..EphemeralFrodoKem$LT$P$C$E$C$S$GT$$u20$as$u20$frodo_kem..hazmat..traits..Expanded$GT$::expand_a::h2acb9f402f18b5b8 + 76  models.rs:626
4   frodo_kem-4b28b6bdda7d5aed            0x104d3a75c _$LT$frodo_kem..hazmat..models..FrodoAes$LT$P$GT$$u20$as$u20$frodo_kem..hazmat..traits..Expanded$GT$::expand_a::h949973832bb22364 + 684  models.rs:966
3   libcrypto.3.dylib                     0x105a27040 EVP_CIPHER_CTX_new + 28
2   libcrypto.3.dylib                     0x105b6887c CRYPTO_zalloc + 20
1   libcrypto.3.dylib                     0x105b68820 CRYPTO_malloc + 112
0   libsystem_malloc.dylib                0x19bba10f4 _malloc_zone_malloc_instrumented_or_legacy + 268 
====
    2 (640 bytes) ROOT LEAK: <malloc in CRYPTO_malloc 0x6000010b8540> [192]
       1 (448 bytes) <malloc in CRYPTO_malloc 0x14d98c8a0> [448]
<TRUNCATED>

EVP_CIPHER_CTX and EVP_MD_CTX objects allocated during matrix
generation are never freed, leaking memory on every keygen,
encapsulation, and decapsulation.
@rot256 rot256 force-pushed the fix/frodo-kem-openssl-ctx-leak branch from dfa398e to 47863da Compare February 11, 2026 16:06
@tarcieri tarcieri merged commit 910b86b into RustCrypto:master Feb 11, 2026
9 checks passed
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

Successfully merging this pull request may close these issues.

2 participants