Skip to content

Blog

Installs fine, runs out of RAM: balancing a Java Card applet suite on the J3R452

Monoid is a set of Java Card applets I work on. Identity holds the card identity, the Secret PIN and the Bundle; Monoid manages keys, data and the Access PIN; Security Key implements FIDO2; an OTP applet that computes TOTP codes came later. The last three share one library package, and they call each other through a Shareable Interface. The suite had already passed its full flow on a D321 card. Moved to a J3R452 (D600), with all four CAP files byte-for-byte identical, LOAD and INSTALL succeeded — and the first Hello came back with an internal error. A diagnostic build named the cause: SystemException.NO_TRANSIENT_SPACE, raised while checking whether a PIN had been set.

This post is what the following rounds of debugging taught me: how Java Card accounts for RAM, why “a power cycle clears RAM” and “there’s plenty left when the command ends” are both unreliable intuitions, which buffers moved to persistent memory, and what it cost when the wrong things moved.

Hardware Ed25519 on the J3R452: recovering the JCOPX API from a CAP file

The J3R452 is a Java Card 3.0.5 Classic card running NXP JCOP 4.5. Its firmware contains a private JCOP eXtended (JCOPX) package that implements Ed25519 signing, verification and X25519 key agreement; the card-side library only calls into it. Curve25519-JavaCard is that thin layer. Its README quotes about 220 ms for an EdDSA signature and about 50 ms for X25519, says the full source is not provided for legal reasons, and invites anyone to disassemble the .cap to check that nothing funny is going on.

I took the invitation. I unpacked Curve25519.cap, recovered the private JCOPX interface it calls from the tokens and bytecode, rewrote the wrapper from source so that it links identically, and ran 20 checks on a real card, most of them byte-for-byte against an independent RFC 8032 / RFC 7748 implementation. This post is the write-up: what the CAP actually contains, how the private API was recovered, how the converter can be made to link against a package that only exists in card ROM, and what the card said when tested — including an X25519 byte-order trap the original README never mentions, and a J3R180 that refuses to load either version.

Talking between Java Card applets with shareable interfaces

Java Card applets live behind a firewall. One applet cannot simply new another applet, grab a reference and call a method. Cross-applet calls go through the one door the JCRE provides: a shareable interface.

That door has more rules than a method signature suggests. To pin them down I built a deliberately small case: a ticket-service applet owns a balance, a client applet buys tickets through the service, and an unauthorized applet tries the same call. Four classes in four packages, run on a contactless D600 card. I measured what could be measured; spec-only boundaries are called out separately.

Benchmarking two Java Card 3.0.5 cards

It started with one contactless Java Card 3.0.5 card (CPLC D600, commonly JCOP 4.5 / J3R452). Once the benchmark worked, a second card of the same generation but a different model showed up (CPLC D321, commonly JCOP 4 / J3R180). Both ran the same applet version (v10) through the same host code on the same reader, so every difference comes from the card itself — which says more about “Java Card performance” than a single card ever could. The D321 data was later re-measured on another card of the same model, cleaned down to the ISD, the GlobalPlatform support package and the benchmark applet.

The suite lives in the repository’s benchmark/ directory: an on-card applet, a Java driver that keeps one PC/SC session open, and a Node harness that orchestrates and verifies. Cross-card comparison is on the results page, each card’s full data (ATR, CPLC, memory, capabilities and performance tables) is linked from the card signals page, and the method is on the methodology page.