Javacard applet to measure memory usage. Uses JCSystem.getAvailableMemory.
Install ant and the Javacard SDKs.
Build using JC_HOME=SDKPATH/jc304_kit ant dist
Deploy to the card using gp --install javacard-memory.cap [ --params AABBCCDDEEEEEEEE ], with an optional 8-byte installation parameter:
| Offset | Length | Content |
|---|---|---|
| 0 | 4 | Total persistent memory baseline in bytes (32-bit big-endian unsigned) |
| 4 | 4 | Batch ID (optional, retrievable via INS_GET_BATCH) |
The baseline is the total persistent memory available on a freshly initialised chip, used to compute usage percentages. Known values:
| Device | Baseline | Parameter |
|---|---|---|
| flexSecure (NXP P71) | 167736 bytes | 00028F38 |
| VivoKey Apex Flex | 84336 bytes | 00014970 |
If no parameter is specified, the applet defaults to 00028F38 (flexSecure baseline).
On SELECT, the applet returns 12 bytes:
| Offset | Length | Content |
|---|---|---|
| 0 | 4 | Available persistent memory (32-bit big-endian) |
| 4 | 4 | Total persistent memory baseline (32-bit big-endian) |
| 8 | 2 | Available transient reset memory |
| 10 | 2 | Available transient deselect memory |
Send INS_GET_BATCH (00 01 00 00 00) after selection to retrieve the 4-byte batch ID.
Install Python3 and pyscard, and run ./measure.py. Measure once before installing your applet to test, and once afterwards. The script also queries the batch ID and applet version.