Skip to content

Commit 7b6496a

Browse files
authored
example snippet added
1 parent b3365e0 commit 7b6496a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,29 @@
22

33
The JCMathLib is an open-source library for Java Card platform which provides objects and operations otherwise missing from standard Java Card API. Namely, we focus on adding support for low-level operations like addition or multiplication of points on elliptic curves in resource efficient way. As a bonus, we provide tooling for shared memory management and performance optimization.
44

5+
## Quick taste
6+
```java
7+
package opencrypto.jcmathlib;
8+
9+
// ... in applet's constructor
10+
// Pre-allocate all helper structures
11+
OCConfig occ = new OCConfig((short) 256);
12+
// Pre-allocate standard SecP256r1 curve and two EC points on this curve
13+
ECCurve curve = new ECCurve(false, SecP256r1.p, SecP256r1.a, SecP256r1.b, SecP256r1.G, SecP256r1.r, occ);
14+
ECPoint point1 = new ECPoint(curve, occ);
15+
ECPoint point2 = new ECPoint(curve, occ);
16+
17+
// ... in standard Java Card applet code
18+
// Generate first point at random
19+
point1.randomize();
20+
// Set second point to predefined value
21+
point2.setW(ECPOINT_TEST_VALUE, (short) 0, (short) ECPOINT_TEST_VALUE.length);
22+
// Add two points together
23+
point1.add(point2);
24+
// Multiply point by large scalar
25+
point1.multiplication(SCALAR_TEST_VALUE, (short) 0, (short) SCALAR_TEST_VALUE.length);
26+
```
27+
528
## FAQ
629
**Q:** Hold on, I thought elliptic curves are already supported on smart cards, right? <br>
730
**A:** Definitely not on each one. Take a look at [jcalgtest.org](https://jcalgtest.org) - out of 65 cards listed, only about 1/3 have some support.

0 commit comments

Comments
 (0)