ML-KEM and ML-DSA stack size in bytes on Cortex-M4 boards
An embedded team that needs post-quantum key exchange or signatures on a Cortex-M4 has to fit the peak stack of each operation into the RAM left over after the application, the RTOS and the network stack. The pqm4 benchmarks.md file reports peak stack in bytes for key generation, encapsulation and decapsulation of each ML-KEM parameter set, and for key generation, signing and verification of each ML-DSA parameter set, on the clean build, the m4fspeed build and the m4fstack build. For ML-KEM-768, the m4fstack build peaks at 2,820 bytes for key generation, 2,860 bytes for encapsulation and 2,844 bytes for decapsulation, against 10,248, 13,384 and 14,480 bytes for the clean build. Figures for the other parameter sets are in the same file, and the table on this page reproduces them without adjustment.
The primary readers are firmware and platform engineers choosing a parameter set and a build flag for a specific board. They use the stack figures to check headroom against the stack size their RTOS task or main stack is configured for, and the m4fstack column shows the smallest footprint pqm4 measured. Security architects and vendor-risk reviewers use the same numbers to judge whether a planned upgrade is realistic on hardware already deployed. Before relying on any figure, confirm the commit of pqm4 and the toolchain used, because the benchmarks.md figures are tied to the build settings pqm4 used when it measured them.
The stack binary in pqm4 measures stack use per procedure and does not count memory allocated outside those procedures. Public keys, secret keys, ciphertexts and signatures are therefore not included in these numbers and must be budgeted separately. The OQS liboqs datasheets give those object sizes: for ML-KEM-768 the public key is 1184 bytes, the secret key 2400 bytes and the ciphertext 1088 bytes, and for ML-DSA-65 the public key is 1952 bytes, the secret key 4032 bytes and the signature 3309 bytes. Add these to the stack figures when sizing a device. Code size is a separate question, and the pqm4 README excludes common code such as hashing and libc from its code-size numbers.
The pqm4 README states that the project is no longer under active maintenance and is planned to be archived read-only in or after January 2027. Teams that plan to depend on these figures should confirm whether a later fork or a vendor port is maintained, and should rerun the measurement with their own toolchain and board before committing a memory budget.
Peak stack and code size for ML-KEM and ML-DSA by build
This table lists peak stack use in bytes for key generation, encapsulation or signing, and decapsulation or verification, along with total code size, for each ML-KEM and ML-DSA parameter set across the pqm4 build variants clean, m4fspeed, m4fstack and m4f. Read each row against the build column to see the trade-off: the m4fstack build uses far less stack than clean or m4fspeed but usually carries a much larger code image, so the choice depends on whether RAM or flash is the tighter limit on your board. The stack figures measure only the procedures themselves and exclude keys, ciphertexts and signatures, so add those buffers when sizing RAM.
| Parameter set and build | Peak stack (bytes), keygen / encaps or sign / decaps or verify | Total code size (bytes) |
|---|---|---|
| ML-KEM-512, clean | 6,152 / 8,784 / 9,560 | 5,116 |
| ML-KEM-512, m4fspeed | 4,372 / 5,436 / 5,412 | 15,848 |
| ML-KEM-512, m4fstack | 2,300 / 2,348 / 2,332 | 13,328 |
| ML-KEM-768, clean | 10,248 / 13,384 / 14,480 | 5,120 |
| ML-KEM-768, m4fspeed | 5,396 / 6,468 / 6,452 | 16,016 |
| ML-KEM-768, m4fstack | 2,820 / 2,860 / 2,844 | 13,320 |
| ML-KEM-1024, clean | 15,128 / 18,776 / 20,352 | 6,160 |
| ML-KEM-1024, m4fspeed | 6,436 / 7,500 / 7,484 | 16,916 |
| ML-KEM-1024, m4fstack | 3,332 / 3,372 / 3,356 | 14,016 |
How to read the stack and code size columns
The stack figures in this topic are peak stack use per procedure, as reported by the stack binary in the pqm4 framework. Each value is the highest stack the measured procedure reaches during one call, reported in bytes for key generation, encapsulation and decapsulation (or sign and verify for signature schemes). The figures exclude memory allocated outside the procedures, such as public keys, secret keys, ciphertexts and signatures held by the calling application. When you size RAM for a device, add those buffers to the stack figure yourself. The key and ciphertext sizes in the sibling tables give you the values to add, and the stack figure alone will undercount the working memory a real handshake or signing task needs.
The code size columns report the .text, .data and .bss sections, measured with arm-none-eabi-size. Each section is listed separately, so check which one a figure belongs to before comparing builds. The measurement excludes common code such as hashing routines and the C standard library (libc), which means the numbers describe the algorithm implementation itself and not the full firmware image. Published pqm4 numbers were produced with the Arm GNU Toolchain 11.3.Rel1. A different compiler version, optimization level or library can change the figures, so confirm the toolchain you build with before using a value as a planning input.
The measured boards set the ceiling for the stack and code figures. The default target is the nucleo-l4r5zi, with 2 MB flash and 640 KB RAM. The other three are stm32f4discovery (1 MB flash, 192 KB RAM), nucleo-l476rg (1 MB flash, 128 KB RAM) and cw308t-stm32f3 (256 KB flash, 40 KB RAM). The cw308t-stm32f3 board is the tightest of the four, so a build that fits on the nucleo-l4r5zi may not fit there. Check each target's memory against the sum of code, static data and peak stack plus your application buffers before you select a part.
Where these stack and code sizes limit a device
Stack and code figures from pqm4 set only part of the memory budget on a microcontroller. The boards pqm4 targets differ widely in RAM and flash, so the same algorithm can fit one board and not another. Read each figure against the board it was measured on and the memory the rest of the firmware already uses.
RAM range across target boards
The pqm4 boards span a wide RAM range: the cw308t-stm32f3 has 40 KB, the nucleo-l476rg has 128 KB, the stm32f4discovery has 192 KB, and the nucleo-l4r5zi has 640 KB. A peak stack figure that fits comfortably on the largest board can exceed the smallest board's entire RAM. Compare each procedure's peak stack with the RAM left after your application, network stack and buffers take their share, and confirm the board you target before choosing an algorithm.
pqm4 READMEFlash range across target boards
Code size on the pqm4 boards is bounded by flash that ranges from 256 KB on the cw308t-stm32f3 to 2 MB on the nucleo-l4r5zi. The benchmark code size counts only the algorithm's own .text, .data and .bss, and excludes common code such as hashing and libc. Your firmware's other code and any certificate or update storage also use flash, so add the algorithm's code size to that existing usage before deciding whether a board has room.
pqm4 READMEClean build versus m4fstack build
The clean build and the m4fstack build of the same algorithm can differ by a large factor in peak stack. For ML-DSA-65 key generation, the pqm4 benchmarks list 60,832 bytes for the clean build and 4,408 bytes for m4fstack. Choose the build that matches your memory constraint, and check that the build you measure is the one you will ship. The m4fstack build is tuned for low stack, so confirm its speed and code size against your timing requirements.
- ML-DSA-65 keygen stack
- 60,832 vs 4,408 bytes
Keys and signatures sit outside stack figures
The pqm4 stack binary measures stack use per procedure and excludes memory allocated outside the procedures, such as keys, ciphertexts and signatures. A device that stores an ML-DSA-65 signature or ML-KEM-768 ciphertext needs that space in addition to the stack figure. Budget public keys, secret keys, ciphertexts and signatures as separate line items, using the sizes in the liboqs datasheets, before you conclude a device fits.
- ML-DSA-65 signature size
- 3,309 bytes
Benchmark maintenance status
The pqm4 README states that the project is no longer under active maintenance and is planned to be archived read-only in or after January 2027. Figures from pqm4 reflect the toolchain and builds it used, which the README gives as Arm GNU Toolchain 11.3.Rel1. Re-measure on your own toolchain and board before you rely on these numbers for a product decision.
pqm4 READMEML-KEM-512, ML-KEM-768 and ML-KEM-1024 stack figures
ML-KEM-512 is the smallest of the three parameter sets, and the liboqs datasheet names it as claimed NIST level 1. The pqm4 benchmarks report its peak stack for key generation, encapsulation and decapsulation on three builds. The clean build peaks at 6,152, 8,784 and 9,560 bytes, the m4fspeed build at 4,372, 5,436 and 5,412 bytes, and the m4fstack build at 2,300, 2,348 and 2,332 bytes. The clean build's code size is 5,116 bytes, all in .text, while m4fspeed is 15,848 bytes and m4fstack is 13,328 bytes. The datasheet gives a public key of 800 bytes, a secret key of 1,632 bytes, a ciphertext of 768 bytes and a shared secret of 32 bytes.
- Peak stack on the clean build: 6,152 bytes for key generation, 8,784 bytes for encapsulation and 9,560 bytes for decapsulation.
- Peak stack on m4fspeed: 4,372, 5,436 and 5,412 bytes for the same three procedures.
- Peak stack on m4fstack: 2,300, 2,348 and 2,332 bytes, the lowest of the three builds.
- Code size: 5,116 bytes on the clean build, 15,848 bytes on m4fspeed and 13,328 bytes on m4fstack.
- Sizes from the datasheet: 800-byte public key, 1,632-byte secret key, 768-byte ciphertext and 32-byte shared secret.
Check these figures against your own build. The pqm4 README says stack use excludes keys, ciphertexts and signatures, so add those buffers to your budget yourself.
ML-KEM-768 sits between the other two parameter sets, and the liboqs datasheet names it as claimed NIST level 3. The pqm4 benchmarks report a peak stack of 10,248, 13,384 and 14,480 bytes on the clean build for key generation, encapsulation and decapsulation. The m4fspeed build peaks at 5,396, 6,468 and 6,452 bytes, and the m4fstack build at 2,820, 2,860 and 2,844 bytes. Code size is 5,120 bytes on the clean build, 16,016 bytes on m4fspeed and 13,320 bytes on m4fstack. The datasheet gives a public key of 1,184 bytes, a secret key of 2,400 bytes, a ciphertext of 1,088 bytes and a shared secret of 32 bytes.
- Peak stack on the clean build: 10,248 bytes for key generation, 13,384 bytes for encapsulation and 14,480 bytes for decapsulation.
- Peak stack on m4fspeed: 5,396, 6,468 and 6,452 bytes.
- Peak stack on m4fstack: 2,820, 2,860 and 2,844 bytes.
- Code size: 5,120 bytes on the clean build, 16,016 bytes on m4fspeed and 13,320 bytes on m4fstack.
- Sizes from the datasheet: 1,184-byte public key, 2,400-byte secret key, 1,088-byte ciphertext and 32-byte shared secret.
Confirm the figures against the build and compiler you run, since the pqm4 numbers use Arm GNU Toolchain 11.3.Rel1. Note that the pqm4 project is no longer actively maintained.
ML-KEM-1024 is the largest parameter set in this group, and the liboqs datasheet names it as claimed NIST level 5. The pqm4 benchmarks report a peak stack of 15,128, 18,776 and 20,352 bytes on the clean build for key generation, encapsulation and decapsulation. The m4fspeed build peaks at 6,436, 7,500 and 7,484 bytes, and the m4fstack build at 3,332, 3,372 and 3,356 bytes. Code size is 6,160 bytes on the clean build, 16,916 bytes on m4fspeed and 14,016 bytes on m4fstack. The datasheet gives a public key of 1,568 bytes, a secret key of 3,168 bytes, a ciphertext of 1,568 bytes and a shared secret of 32 bytes.
- Peak stack on the clean build: 15,128 bytes for key generation, 18,776 bytes for encapsulation and 20,352 bytes for decapsulation, the highest figures in this group.
- Peak stack on m4fspeed: 6,436, 7,500 and 7,484 bytes.
- Peak stack on m4fstack: 3,332, 3,372 and 3,356 bytes.
- Code size: 6,160 bytes on the clean build, 16,916 bytes on m4fspeed and 14,016 bytes on m4fstack.
- Sizes from the datasheet: 1,568-byte public key, 3,168-byte secret key, 1,568-byte ciphertext and 32-byte shared secret.
Compare the m4fstack figures with the RAM of your target board. The pqm4 board list runs from 40 KB to 640 KB, and the smallest boards need the m4fstack build to leave room for the rest of the application.
How to use these figures on your board
This sequence turns the pqm4 peak stack and code size figures into a memory budget for your own board, so you can check whether a given ML-KEM or ML-DSA build fits in the RAM and flash you have before you commit to it. The figures are starting points, and the last step is a measurement on your hardware.
Confirm the parameter set and build variant
Start by writing down which algorithm, parameter set and build you plan to use: for example, ML-KEM-768 in the m4fstack build, or ML-DSA-65 in the clean build. The pqm4 benchmarks list peak stack and code size separately for each combination, so a figure is only meaningful when you match it to the exact set and variant. Confirm the choice against your application's security requirement and against the library you will actually compile. Done when the chosen parameter set and build variant are written in your design record and each one has a matching row in the pqm4 benchmarks.
Pick the board's RAM and flash
Look up the RAM and flash of the target board. The pqm4 README lists its default target, the nucleo-l4r5zi, with 2 MB flash and 640 KB RAM, along with other Cortex-M4 targets such as the stm32f4discovery (1 MB flash, 192 KB RAM), the nucleo-l476rg (1 MB flash, 128 KB RAM) and the cw308t-stm32f3 (256 KB flash, 40 KB RAM). Compare your own board against these figures and against your application's existing usage. Done when you have a RAM and flash total for your board and a note on how much of each your application already uses.
Add the buffers the stack figure excludes
The pqm4 stack figure covers only the memory used inside the procedures. It excludes keys, ciphertexts and signatures, which your application allocates itself. Add those sizes from the liboqs datasheets: for ML-KEM-768, for example, the public key is 1184 bytes, the secret key 2400 bytes, the ciphertext 1088 bytes and the shared secret 32 bytes. For ML-DSA-65 the public key is 1952 bytes, the secret key 4032 bytes and the signature 3309 bytes. Add these to the peak stack figure, because the buffers exist while the procedure runs. Done when you have one total per operation that combines the pqm4 peak stack and the buffers your code holds.
Add the code size to the flash budget
Take the total code size from the pqm4 benchmarks for your chosen set and variant, which is reported in bytes for .text. Note that the pqm4 code size measurement excludes common code such as hashing and libc, so you must add the hashing and libc your build uses separately. Place the post-quantum code size and the other firmware inside your flash total. Done when the flash budget shows the post-quantum code, the common code you added and the rest of your firmware, with the sum below your board's flash.
Rebuild with your own toolchain
Rebuild the library and your application with your own toolchain, rather than relying on the published numbers. The pqm4 code size figures use the Arm GNU Toolchain 11.3.Rel1, so a different compiler version or optimization setting can change the output. Measure code size with arm-none-eabi-size and record the .text, .data and .bss values separately, as the pqm4 README does. Done when you have the .text, .data and .bss sizes from your own build and you have compared them with the published figures.
Measure on your hardware before committing
Run the stack measurement on the actual board, using the same build you will ship, and compare the peak figure with the pqm4 benchmark. Confirm the total memory use against your RAM and flash budget with some headroom left for the rest of the application. The pqm4 project states it is no longer under active maintenance and plans to archive it read-only in or after January 2027, so do not rely on it as a moving reference. Done when your measured peak stack, code size and buffer totals fit inside the board's RAM and flash, and you have recorded the result in your memory budget before you commit to the algorithm.
What these figures do not show
The figures on this page come from pqm4, and the first thing to know about them is that the project is no longer under active maintenance. The pqm4 README says it is planned to be archived read-only in or after January 2027. Engineers should treat the benchmarks as a snapshot of the code and toolchain they were measured with, not as a stream of updates. Before relying on a figure in a design, check the repository's current state, confirm whether any fixes or ports have been merged, and decide how you will obtain support if you find a discrepancy on your own board.
The numbers also depend on the build. The pqm4 README says code size is measured with arm-none-eabi-size, excludes common code such as hashing and libc, and lists .text, .data and .bss separately, with its published numbers produced by Arm GNU Toolchain 11.3.Rel1. A different compiler version, optimization level, build flag set or board will change the result. The stack figures are per procedure and exclude memory for keys, ciphertexts and signatures, so a full RAM budget must add those sizes from the algorithm datasheets and your own buffers. Confirm the toolchain and flags you ship with, and re-measure on your target board before committing a flash or RAM limit.
The sources listed on this page do not give timing or throughput on these boards, so the memory figures should not be read as a statement about speed. Cycle counts and latency for these algorithms on constrained hardware need to come from the benchmark pages in the speed group or from your own measurements on the device you deploy. Ask any vendor or library team you rely on which board, clock speed, toolchain and build settings produced their timing data before you compare it with the memory numbers here.
Questions about post-quantum memory use on microcontrollers
How much stack does ML-KEM-768 need on a Cortex-M4?
The pqm4 benchmarks list peak stack for ML-KEM-768 at 10,248 bytes for key generation, 13,384 bytes for encapsulation and 14,480 bytes for decapsulation in the clean build. The m4fspeed build peaks at 5,396, 6,468 and 6,452 bytes, and the m4fstack build peaks at 2,820, 2,860 and 2,844 bytes for the same three operations. The clean build is therefore several times larger than the m4fstack build. Check which build your firmware uses, because the figure you plan around depends on it. These are stack figures for each procedure only. Confirm the numbers against the pqm4 benchmarks for the exact toolchain and commit you use.
Does ML-DSA-65 fit in 128 KB of RAM on a microcontroller?
The sources do not state a yes or no answer for a given RAM budget, so the answer depends on what else your firmware holds in memory. The pqm4 benchmarks give peak stack for ML-DSA-65 of 60,832 bytes for key generation, 79,624 bytes for signing and 57,736 bytes for verification in the clean build. The m4f build peaks at 60,824, 68,872 and 9,888 bytes, and the m4fstack build at 4,408, 6,616 and 2,712 bytes. Stack is only one part of RAM use. Keys, signatures and any buffers held outside the procedures are not included in these figures, so add them to your own budget before deciding. Measure on your target board with your application running.
What does the m4fstack build change compared with m4fspeed?
The m4fstack build reduces peak stack by trading some speed for lower memory use. For ML-KEM-768, peak stack falls from 5,396 to 2,820 bytes for key generation, and from 6,452 to 2,844 bytes for decapsulation, when compared with m4fspeed. For ML-DSA-65 signing, the figure falls from 68,872 bytes in the m4f build to 6,616 bytes in the m4fstack build. Code size grows in the m4fstack build: the pqm4 benchmarks list ML-KEM-768 at 13,320 bytes of .text in m4fstack, compared with 16,016 bytes in m4fspeed. The benchmark sources do not report speed figures in this comparison, so confirm the timing trade-off against the benchmark results for your board.
Are keys included in the stack figures for post-quantum algorithms?
No. The pqm4 stack binary measures stack use per procedure and excludes memory allocated outside the procedures. Keys, ciphertexts and signatures are not included in the stack figures. For ML-KEM-768 the OQS datasheet lists a public key of 1184 bytes, a secret key of 2400 bytes, a ciphertext of 1088 bytes and a shared secret of 32 bytes. For ML-DSA-65 the datasheet lists a public key of 1952 bytes, a secret key of 4032 bytes and a signature of 3309 bytes. Add these sizes to the stack peak when you plan RAM, and confirm whether your application holds them in static, heap or stack memory.
Which board is pqm4's default target?
The pqm4 README names the nucleo-l4r5zi as its default target. That board has 2 MB of flash and 640 KB of RAM. The README also lists other targets: the stm32f4discovery with 1 MB flash and 192 KB RAM, the nucleo-l476rg with 1 MB flash and 128 KB RAM, and the cw308t-stm32f3 with 256 KB flash and 40 KB RAM. If your device resembles one of the other boards, the RAM and flash limits on that board are the ones to plan around, not the default target's figures. Check the pqm4 README for the current target list before you rely on it.
Do the pqm4 memory figures apply to other microcontrollers?
The figures come from Arm Cortex-M4 boards built with the Arm GNU Toolchain 11.3.Rel1, as the pqm4 README describes. Other microcontrollers with different cores, compilers, compiler flags or library versions can produce different stack and code sizes. The pqm4 README also states that the project is no longer under active maintenance and is planned for read-only archiving in or after January 2027, so the figures do not track newer toolchains. Treat the published numbers as a starting point. Measure stack and code size on your own hardware, toolchain and build settings before you commit to a memory budget.
How is code size measured in the pqm4 benchmarks?
The pqm4 README states that code size is measured with arm-none-eabi-size. The measurement excludes common code such as hashing and libc, and it lists .text, .data and .bss separately. The published benchmark numbers list code size as total bytes, all in .text, for each algorithm and build. For example, the pqm4 benchmarks list ML-DSA-65 at 7,724 bytes in the clean build, 19,328 bytes in the m4f build and 24,120 bytes in the m4fstack build. Compare figures only when your build uses the same toolchain and section split, and measure your own firmware image for final flash planning.
Where stack and buffer memory sit on the device
The diagram starts with a procedure's code in flash, which the pqm4 build reads at run time. Stack memory is then allocated inside each procedure, and the pqm4 stack figure measures only that part. Keys, ciphertexts and signatures are held in buffers outside the procedures, so they are not counted in the stack number. Check the diagram's buffer step against your own design: the stack total from pqm4 is not your full RAM requirement, which also includes these buffers and any other data your application holds.
The pqm4 stack figure covers only memory used inside procedures, not the buffers outside them.
How DeployOpen helps teams plan post-quantum memory budgets
DeployOpen scopes, builds and documents memory planning for post-quantum algorithms on constrained devices, starting from the stack, RAM and flash figures published for Arm Cortex-M4 targets. We set the budget against the specific board, toolchain and build configuration your team uses, so the numbers your reviewers check match the hardware in your product.
How we scope
- We confirm which algorithms, parameter sets and operations your device must run, such as ML-KEM or ML-DSA key generation and signing.
- We record the target boards, flash and RAM limits, and the build options your firmware team intends to use.
- The written scope lists the memory figures we will measure and which key, ciphertext and signature buffers are counted separately.
- Engagements are fixed-scope, with scope and timelines agreed in writing before work starts.
How we build
- We compare published peak stack figures for each build variant against your board's RAM budget, noting which procedures they cover.
- We measure code size with the same toolchain family and section breakdown (.text, .data, .bss) so totals are comparable.
- We add key, ciphertext and signature buffer sizes from the algorithm datasheets, since the published stack figures exclude them.
- We test each configuration on your hardware and record where measured numbers differ from the reference figures.
How we hand over
- You receive a memory budget table per algorithm, parameter set and build variant, with each figure's source and unit stated.
- The document lists the assumptions behind each number, including toolchain version and excluded common code such as hashing and libc.
- Your firmware and security teams receive the measurement steps so they can repeat the checks on new builds.
How we support
- Ongoing support and continuous testing are available as a retainer, for teams whose firmware changes after handover.
- We can re-check the budget when you change the target board, the algorithm set or the compiler version.
- Reference libraries such as pqm4 are no longer actively maintained, so we confirm how your chosen code base will be updated over time.

