|
1 | 1 | # JCProfiler |
2 | 2 | Performance profiler for Java Card code |
| 3 | + |
| 4 | +The performance profiling parts of Java Card applet code is a notoriously difficult task. As the card environment is build to protect stored and processed secrets even against an attacker with direct physical access, it's difficult to obtain precise timing trace for the executed code. We are not aware of any free performance profiler for Java Card platform so we decided to build one. |
| 5 | + |
| 6 | +The usage is simple: |
| 7 | +1. Developer signalizes interseting parts of code to profile by insertion of fixed strings |
| 8 | +2. JCProfiler tool automatically generates all necessary testing code |
| 9 | +3. Developer sets proper applet AID, applet CLA and APDU command which will trigger inspected operation |
| 10 | +4. Performance measurement client is executed to collect all required measurements |
| 11 | +5. Applet source code is annotted with measured timings |
| 12 | + |
| 13 | +Please read [wiki](https://github.com/petrs/JCProfiler/wiki) for all details. |
| 14 | + |
| 15 | +## Simple example |
| 16 | +The code below was automatically transformed and profiled after insertion of perfromance traps 'PM.check(PM.TRAP...'. Time in milliseconds provides time necessary to reach particular trap from the previous one. A name of card and unique profiling session ID in braces (gd60,1500968219581). |
| 17 | + |
| 18 | +```` java |
| 19 | +private short multiplication_x_KA(Bignat scalar, byte[] outBuffer, short outBufferOffset) { |
| 20 | + PM.check(PM.TRAP_ECPOINT_MULT_X_1); // 40 ms (gd60,1500968219581) |
| 21 | + priv.setS(scalar.as_byte_array(), (short) 0, scalar.length()); |
| 22 | + PM.check(PM.TRAP_ECPOINT_MULT_X_2); // 12 ms (gd60,1500968219581) |
| 23 | + |
| 24 | + keyAgreement.init(priv); |
| 25 | + PM.check(PM.TRAP_ECPOINT_MULT_X_3); // 120 ms (gd60,1500968219581) |
| 26 | + |
| 27 | + short len = this.getW(point_arr1, (short) 0); |
| 28 | + PM.check(PM.TRAP_ECPOINT_MULT_X_4); // 9 ms (gd60,1500968219581) |
| 29 | + len = keyAgreement.generateSecret(point_arr1, (short) 0, len, outBuffer, outBufferOffset); |
| 30 | + PM.check(PM.TRAP_ECPOINT_MULT_X_5); // 186 ms (gd60,1500968219581) |
| 31 | + |
| 32 | + return COORD_SIZE; |
| 33 | +} |
| 34 | +```` |
| 35 | + |
| 36 | + |
| 37 | +### Satisfied users |
| 38 | +* JCMathLib library for Bignat and ECPoint operations |
| 39 | +* You? Give it a try - love to hear the feedback :) |
| 40 | + |
| 41 | +### Future work |
| 42 | +* Averaging from multiple results instead of single run |
| 43 | +* Better analysis of applet and detection of developer-provided info |
| 44 | +* Code improvements (a lot of hardcoded strings etc. ) |
| 45 | + |
0 commit comments