Skip to content

Java Card 3.0.5 benchmarks

The benchmark covers two Java Card 3.0.5 cards. The goal is not a generic score but a clear account of what is measured, how, and what cannot be measured, so the same method can be moved to another card and every number has checkable context.

The full results are on the results page, signals and chip evidence are on card signals, and the code lives in the repository’s benchmark/ directory with a single-command rerun.

Both cards were measured through the same contactless reader (ACS ACR1552 1S CL Reader PICC 0), with the same host code. Each card’s ID, ATR, CPLC, GlobalPlatform data, free memory and algorithm capability matrix are recorded on the card signals page.

D600 and D321 are CPLC product codes; the marketing names (J3R452 / J3R180) are an external mapping, not a model read from the card, and the ATR is not used to identify the chip. getVersion() reports only 0x0300 and does not expose the patch level. No RAM size or clock frequency is inferred from public material; getAvailableMemory returns card-wide free space rather than an applet budget, and those values change as applets are installed or deleted. To keep that number comparable, the benchmark applet reads it at the top of its constructor, before allocating its own test buffers, and that reading is what the pages publish.

Java Card classic does not expose a clock, so the card cannot time itself, and the host cannot use the absolute duration of one APDU: it contains the contactless link, reader framing and command dispatch. That fixed cost is not small (ranges across the two cards):

  • an empty command round trip is about 3.3–4.1 ms;
  • echoing 64 bytes takes about 6.5–15.7 ms;
  • when the applet returns data with sendBytesLong, the card answers 61xx and the host sends GET RESPONSE, so every command with a response costs roughly two round trips; the fitted intercept is about 9.8–10.7 ms.

A single command’s wall-clock time therefore cannot be used as the duration of one operation. The applet runs the operation n times inside one command, the host measures the whole round trip, and a line is fitted:

elapsed(n) = fixed cost + per-operation cost × n

The n = 0 point measures the fixed cost directly. The slope is the per-operation cost, independent of the link.

Per test, the harness:

  1. warms up once, so keys, ciphers and digests are created outside the timed region;
  2. calibrates n until a command takes about 80 ms;
  3. runs one full pass over the sample points and discards it, avoiding the first-touch EEPROM state;
  4. samples n = 0, n₁, 2n₁, 4n₁ three times each and takes medians;
  5. fits by least squares and reports slope, intercept, R² and the per-point coefficient of variation.

Rows with R² < 0.99 are marked † in the results: their cost is not linear in n (EEPROM page effects or garbage collection), so the slope is only a local estimate.

Cross-card comparisons are only valid when the applet version matches. The result JSON stores appletVersion per card, and runs with different versions should not be compared directly. Both cards’ published data now comes from v10: v6 added the reading taken before the applet allocates its buffers, v7 only makes the write tests write different data on every command, and v8 added the 16/32/64-byte block writes; the other measurement loops and buffer sizes are unchanged. v9 only drops the redundant byte-loop command from the block-write family — it costs bytes times the single-byte write, so it is not reported (see “Reading the memory numbers” below) — and no reported test is affected. v10 only touches HMAC: it builds HMAC keys from their actual length in bits and adds five HMAC probes (see “Capability limits” below). On the D600 card, going from v6 to v7 moved the 31 non-write rows by a median of 0.32%, while the four write-related rows rose by two orders of magnitude; from v8 to v10 the 41 rows both versions measure moved by a median of 0.29% on D600 and 0.16% on D321.

Does applet size or a fixed memory footprint affect the numbers? The measurement loops only touch buffers of fixed size; adding the capability-probe and block-write commands (CAP grew from 42 KB all the way to 46,198 B in v8, was 45,794 B in v9 without the byte-loop command, and is 46,237 B in v10 with the HMAC probes) does not change those loops. The same D600 card was measured once with v4 and once with v5 (v5 only adds the probe command; the measured path is unchanged): across the 37 valid timing rows the median per-operation deviation was 0.5%, transport round trips differed by under 1.5%, and only the high-variance RSA key generation and allocate+delete rows moved substantially. A few kilobytes of applet code therefore do not change the comparison.

Free allocatable space on the card is the three numbers under “Memory and objects” on the card pages: 335,512 B persistent, 4,609 B transient RESET and 4,608 B transient DESELECT for D600, and 155,124 / 3,974 / 3,968 B for D321, all read with only the ISD, the GlobalPlatform support package and the benchmark applet installed. The benchmark applet’s own fixed cost — 4,316 B persistent and 1,184 B in each transient view (two views of the same pool, not two pools to add together; the persistent figure was 3,924 B in v6, grew by 388 B when the copy source became 448 bytes in v7, and is 4,316 B with the extra probes of v10) — only matters when you want to work back from a reading taken while the applet runs; it is not a card metric.

The same baseline drifts by a few hundred bytes across delete/install cycles: four installations on D321 read 155,632 / 155,496 / 155,140 / 155,124 B. That is under 0.4%, but it means the figure should be read as a value with error bars, not a constant accurate to the byte.

What does change the numbers is the applet’s data-buffer size (which forces a re-measurement) and other applets installed on the card: they consume persistent and transient memory and affect allocation, deletion and key generation, which depend on memory state. CPU and symmetric-crypto loops do not allocate, so they are largely unaffected. Every run records the card-wide free memory and measurement time and is merged by card.

A performance number without a correctness check is meaningless. Every block cipher, hash, signature and key-agreement result is recomputed on the host with the same vectors:

  • AES/DES/3DES and HMAC-SHA-256 are recomputed with Node’s crypto; OpenSSL 3 does not provide single DES by default, so single DES is checked as 3DES with the same 8-byte key repeated three times;
  • SHA-1/256/512 and RSA signatures are verified with the card’s own modulus and e = 65537;
  • RSA decryption is additionally cross-checked: the host encrypts with publicEncrypt, writes the PKCS#1 ciphertext into the applet in two commands, and decrypts it on the card;
  • ECDSA signatures are verified against a P-256 JWK built from the card’s public point; ECDH must return that point’s x coordinate;
  • CPU and memory tests must echo the requested n.

RSA encryption uses randomised padding, so the public key cannot recover the encoded message; it is checked by the round trip — the card decrypts its own ciphertext back to the message.

The applet does not assume that Java Card 3.0.5 implements an algorithm: it probes each API constant and returns the CryptoException reason. The two cards differ only on HMAC:

Algorithm D600 card D321 card
AES-128 ECB / CBC / CTR supported supported
AES-192 / AES-256 (ECB, CBC) NO_SUCH_ALGORITHM NO_SUCH_ALGORITHM
AES-GCM (AEADCipher) NO_SUCH_ALGORITHM NO_SUCH_ALGORITHM
DES / 3DES ECB supported supported
SHA-1 / SHA-256 / SHA-512 supported supported
HMAC-SHA-1 / SHA-256 / SHA-512 supported; the key length must be given in bits (see below) NO_SUCH_ALGORITHM: neither Signature.getInstance nor the HMAC key builder is supported
RSA-2048 (PKCS#1 sign/encrypt/decrypt) supported supported
ECDSA / ECDH P-256 supported, but the curve must be imported explicitly supported, but the curve must be imported explicitly
Secure random supported supported

HMAC has a unit trap. KeyBuilder.buildKey takes its length in bits, while constants such as LENGTH_HMAC_SHA_256_BLOCK_64 hold a block size (64). Passed straight in, that constant gives D600 a key that holds only 8 bytes: the same key accepts an 8 B setKey and returns ILLEGAL_VALUE for 16 B. v9 and earlier built every HMAC key this way, so 16-, 32- and 64-byte keys were all rejected and D600 was wrongly reported as having no HMAC. With keys built from their byte length times 8, v10 passes HMAC-SHA-256 with 16/32/64-byte keys as well as HMAC-SHA-1 and HMAC-SHA-512, and HMAC-SHA-256 now has an off-card-verified timing. D321, by contrast, returns NO_SUCH_ALGORITHM for everything from Signature.getInstance to building an HMAC key: it really has no HMAC. Probing every primitive matters instead of assuming that “same Java Card version” means “same algorithm set” — and a failed probe has to be ruled out as a usage error before it is called missing support.

EC has two traps, identical on both cards: there is no default EC curve — generating with new KeyPair(ALG_EC_FP, LENGTH_EC_FP_256) throws ILLEGAL_VALUE; and setG requires the IEEE 1363 uncompressed point (04 || x || y, 65 bytes). Passing the bare 64-byte x || y is rejected.

One platform behaviour deserves its own note: Signature.verify() returns false for a key pair generated in an earlier command, even though the modulus, exponent and signature bytes are all correct and the same signature verifies off-card. Sign + verify inside one command succeeds. Both cards behave this way, so the standalone RSA and ECDSA verify timings are marked “not reported” instead of being given a number.

The first trap in persistent writes is that writing the value that is already stored is not a write. The card skips programming bits that are already in the target state, so rewriting the same value costs only the interpreter loop (about 84 µs), while changing one byte is real programming: about 2.8–2.9 ms on both cards, with R² = 1.0000. Early versions of the write tests wrote the same fixed values on every command, so nearly every write in the timed region was a same-value rewrite and the rows reported those 84 µs — roughly 30× below the real cost. The occasional “~1.4 ms slow state” was a blend of the two: some of the writes in that period really did program, which turned the slope into an intermediate value and lowered R².

Every write command now advances a persistent seed and derives all written values from it, so each command writes different data. The copy tests also refill their 448-byte source array from the seed outside the timed loop and advance the source window (448 B) and the destination slot (512 B) at different rates, so every destination slot receives different content each pass. The seed is echoed in the first two response bytes, and the host runs each write test twice and fails the check if the two commands wrote the same value.

With that fixed, the memory rows read:

  • single-byte and short persistent writes cost about 2.8–2.9 ms, the same order as a 64-byte arrayCopy at 3.2–3.3 ms — both are dominated by page programming;
  • persistent reads cost only about 85–87 µs and transient reads/writes about 86–99 µs, close to the cost of the interpreter loop itself;
  • one transaction per byte write costs about 3.1–3.2 ms per write, roughly 0.3 ms more than a bare write (the journal).

To separate “cost per byte” from “cost per program”, v8 stores the same 16/32/64-byte payload in two styles that are not already covered by a simpler test (each cell is D600 / D321, in ms):

Style 16 B 32 B 64 B
the byte loop inside one transaction 6.09 / 6.94 8.86 / 10.5 14.7 / 18.1
one arrayCopy (the 64 B cell reuses the existing copy test) 2.98 / 3.06 3.07 / 3.14 3.22 / 3.30
  • one transaction holds 64 B to 14.7 ms (D321 18.1), but still charges 0.23–0.43 ms per byte — the transaction buffer is billed per byte, only the commit is shared;
  • arrayCopy is almost flat (3.0–3.3 ms): one copy is about one page program, and a page is roughly 64 bytes;
  • the byte loop without a transaction is not a row of its own: it is simply bytes times the single-byte write (16 B measured 45.5 ms in v8, which is 16 × 2.836 ms), and because the single-byte test already writes 120 adjacent bytes inside one command at 2.84 ms each, it also rules out coalescing of consecutive stores within a command.

So persistent-write cost on this card follows the number of programs, not the number of bytes: a loop without a transaction pays one page price per byte, a transaction pays one commit plus a buffer billed per byte, arrayCopy pays one page. “How long does 1 KB take” is meaningless without the style — the same payload spans two orders of magnitude.

You need JDK 11 (to compile the applet and run the converter), a Java Card 3.0.5 kit, gp.exe, and a Windows java.exe reachable from WSL (WSL has no pcscd; PC/SC runs on the Windows side).

终端窗口
cd benchmark
./build.sh # compile and convert to CAP
./install.sh # remove the old deployment and install on the contactless card
node host/bench.mjs # run the suite, write results/latest.json

Each run measures one card and merges the result by a card ID derived from the CPLC: different models get one entry each, and a second card of the same model needs --id to keep them apart. --groups cpu,memory runs a subset.

The suite runs in four phases (CPU/memory, symmetric crypto, P-256, RSA-2048) and sends RESET between them: the applet drops all crypto objects and requests object deletion, because the cards have only a few kilobytes of transient RAM (3,974 B on the D321 card and 4,609 B on the D600 card) and cannot hold the P-256 and RSA object sets at once.

Before installing, delete applets you do not need: every other applet on the card consumes persistent and transient memory and lowers the free-memory figures above. The factory test and payment packages on the D600 card and the non-platform packages on the D321 card have been removed; those figures were read after that cleanup, when the benchmark applet was reinstalled. Delete only applets installed by this project or those you are sure have no privileges and a known purpose — never a privileged applet such as one holding CardReset, and never one whose function is unknown, because deletion cannot be undone.

A full run takes about five to eight minutes, mostly RSA key generation, whose duration is decided by the prime search: in the latest (v10) run 1.7–3.6 s per key on the D600 card (median 2.2 s) and 2.1–8.9 s on the D321 card (median 7.0 s); the previous (v8) run on the same two cards gave 5.4–13.8 s and 4.7–20.1 s. Treat this as an order of magnitude.

Outputs:

  • benchmark/results/latest.json — the complete results, covering every card measured;
  • benchmark/results/latest.md / latest.csv — human-readable and spreadsheet versions;
  • benchmark/results/runs/ — one full copy per run.