xref: /btstack/3rd-party/micro-ecc/README.md (revision af03003c8ac55cf0eea9563b597879b24aee256f)
1*af03003cSMatthias Ringwaldmicro-ecc
2*af03003cSMatthias Ringwald==========
3*af03003cSMatthias Ringwald
4*af03003cSMatthias RingwaldA small and fast ECDH and ECDSA implementation for 8-bit, 32-bit, and 64-bit processors.
5*af03003cSMatthias Ringwald
6*af03003cSMatthias RingwaldThe old version of micro-ecc can be found in the "old" branch.
7*af03003cSMatthias Ringwald
8*af03003cSMatthias RingwaldFeatures
9*af03003cSMatthias Ringwald--------
10*af03003cSMatthias Ringwald
11*af03003cSMatthias Ringwald * Resistant to known side-channel attacks.
12*af03003cSMatthias Ringwald * Written in C, with optional GCC inline assembly for AVR, ARM and Thumb platforms.
13*af03003cSMatthias Ringwald * Supports 8, 32, and 64-bit architectures.
14*af03003cSMatthias Ringwald * Small code size.
15*af03003cSMatthias Ringwald * No dynamic memory allocation.
16*af03003cSMatthias Ringwald * Support for 5 standard curves: secp160r1, secp192r1, secp224r1, secp256r1, and secp256k1.
17*af03003cSMatthias Ringwald * BSD 2-clause license.
18*af03003cSMatthias Ringwald
19*af03003cSMatthias RingwaldUsage Notes
20*af03003cSMatthias Ringwald-----------
21*af03003cSMatthias Ringwald### Point Representation ###
22*af03003cSMatthias RingwaldCompressed points are represented in the standard format as defined in http://www.secg.org/collateral/sec1_final.pdf; uncompressed points are represented in standard format, but without the `0x04` prefix. `uECC_make_key()`, `uECC_shared_secret()`, `uECC_sign()`, and `uECC_verify()` only handle uncompressed points; you can use `uECC_compress()` and `uECC_decompress()` to convert between compressed and uncompressed point representations.
23*af03003cSMatthias Ringwald
24*af03003cSMatthias RingwaldPrivate keys are represented in the standard format.
25*af03003cSMatthias Ringwald
26*af03003cSMatthias Ringwald### Using the Code ###
27*af03003cSMatthias Ringwald
28*af03003cSMatthias RingwaldI recommend just copying (or symlink) uECC.h, uECC.c, and the appropriate asm\_<arch>\_.inc (if any) into your project. Then just `#include "uECC.h"` to use the micro-ecc functions.
29*af03003cSMatthias Ringwald
30*af03003cSMatthias RingwaldFor use with Arduino, you can just create a symlink to the `uECC` directory in your Arduino `libraries` directory. You can then use uECC just like any other Arduino library (uECC should show up in the **Sketch**=>**Import Library** submenu).
31*af03003cSMatthias Ringwald
32*af03003cSMatthias RingwaldSee uECC.h for documentation for each function.
33*af03003cSMatthias Ringwald
34*af03003cSMatthias Ringwald### Compilation Notes ###
35*af03003cSMatthias Ringwald
36*af03003cSMatthias Ringwald * Should compile with any C/C++ compiler that supports stdint.h (this includes Visual Studio 2013).
37*af03003cSMatthias Ringwald * If you want to change the defaults for `uECC_CURVE` and `uECC_ASM`, you must change them in your Makefile or similar so that uECC.c is compiled with the desired values (ie, compile uECC.c with `-DuECC_CURVE=uECC_secp256r1` or whatever).
38*af03003cSMatthias Ringwald * When compiling for a Thumb-1 platform with inline assembly enabled (ie, `uECC_ASM` is defined to `uECC_asm_small` or `uECC_asm_fast`), you must use the `-fomit-frame-pointer` GCC option (this is enabled by default when compiling with `-O1` or higher).
39*af03003cSMatthias Ringwald * When compiling for an ARM/Thumb-2 platform with fast inline assembly enabled (ie, `uECC_ASM` is defined to `uECC_asm_fast`), you must use the `-fomit-frame-pointer` GCC option (this is enabled by default when compiling with `-O1` or higher).
40*af03003cSMatthias Ringwald * When compiling for AVR with inline assembly enabled, you must have optimizations enabled (compile with `-O1` or higher).
41*af03003cSMatthias Ringwald * When building for Windows, you will need to link in the `advapi32.lib` system library.
42*af03003cSMatthias Ringwald
43*af03003cSMatthias RingwaldARM Performance
44*af03003cSMatthias Ringwald---------------
45*af03003cSMatthias Ringwald
46*af03003cSMatthias RingwaldAll tests were built using gcc 4.8.2 with `-O3`, and were run on a Raspberry Pi B+. `uECC_ASM` was defined to `uECC_asm_fast` and `ECC_SQUARE_FUNC` was defined to `1` in all cases. All times are in milliseconds.
47*af03003cSMatthias Ringwald
48*af03003cSMatthias Ringwald<table>
49*af03003cSMatthias Ringwald	<tr>
50*af03003cSMatthias Ringwald		<th></th>
51*af03003cSMatthias Ringwald		<th>secp160r1</th>
52*af03003cSMatthias Ringwald		<th>secp192r1</th>
53*af03003cSMatthias Ringwald		<th>secp256r1</th>
54*af03003cSMatthias Ringwald		<th>secp256k1</th>
55*af03003cSMatthias Ringwald	</tr>
56*af03003cSMatthias Ringwald	<tr>
57*af03003cSMatthias Ringwald		<td><em>ECDH:</em></td>
58*af03003cSMatthias Ringwald		<td>2.3</td>
59*af03003cSMatthias Ringwald		<td>2.7</td>
60*af03003cSMatthias Ringwald		<td>7.9</td>
61*af03003cSMatthias Ringwald		<td>6.5</td>
62*af03003cSMatthias Ringwald	</tr>
63*af03003cSMatthias Ringwald	<tr>
64*af03003cSMatthias Ringwald		<td><em>ECDSA sign:</em></td>
65*af03003cSMatthias Ringwald		<td>2.8</td>
66*af03003cSMatthias Ringwald		<td>3.1</td>
67*af03003cSMatthias Ringwald		<td>8.6</td>
68*af03003cSMatthias Ringwald		<td>7.2</td>
69*af03003cSMatthias Ringwald	</tr>
70*af03003cSMatthias Ringwald	<tr>
71*af03003cSMatthias Ringwald		<td><em>ECDSA verify:</em></td>
72*af03003cSMatthias Ringwald		<td>2.7</td>
73*af03003cSMatthias Ringwald		<td>3.2</td>
74*af03003cSMatthias Ringwald		<td>9.2</td>
75*af03003cSMatthias Ringwald		<td>7.0</td>
76*af03003cSMatthias Ringwald	</tr>
77*af03003cSMatthias Ringwald</table>
78*af03003cSMatthias Ringwald
79*af03003cSMatthias RingwaldAVR Performance
80*af03003cSMatthias Ringwald---------------
81*af03003cSMatthias Ringwald
82*af03003cSMatthias RingwaldAll tests were built using avr-gcc 4.8.1 with `-Os`, and were run on a 16 MHz ATmega256RFR2. Code size refers to the space used by micro-ecc code and data.
83*af03003cSMatthias Ringwald
84*af03003cSMatthias Ringwald#### ECDH (fast) ####
85*af03003cSMatthias Ringwald
86*af03003cSMatthias RingwaldIn these tests, `uECC_ASM` was defined to `uECC_asm_fast` and `ECC_SQUARE_FUNC` was defined to `1` in all cases.
87*af03003cSMatthias Ringwald
88*af03003cSMatthias Ringwald<table>
89*af03003cSMatthias Ringwald	<tr>
90*af03003cSMatthias Ringwald		<th></th>
91*af03003cSMatthias Ringwald		<th>secp160r1</th>
92*af03003cSMatthias Ringwald		<th>secp192r1</th>
93*af03003cSMatthias Ringwald		<th>secp256r1</th>
94*af03003cSMatthias Ringwald		<th>secp256k1</th>
95*af03003cSMatthias Ringwald	</tr>
96*af03003cSMatthias Ringwald	<tr>
97*af03003cSMatthias Ringwald		<td><em>ECDH time (ms):</em></td>
98*af03003cSMatthias Ringwald		<td>470</td>
99*af03003cSMatthias Ringwald		<td>810</td>
100*af03003cSMatthias Ringwald		<td>2220</td>
101*af03003cSMatthias Ringwald		<td>1615</td>
102*af03003cSMatthias Ringwald	</tr>
103*af03003cSMatthias Ringwald	<tr>
104*af03003cSMatthias Ringwald		<td><em>Code size (bytes):</em></td>
105*af03003cSMatthias Ringwald		<td>10768</td>
106*af03003cSMatthias Ringwald		<td>13112</td>
107*af03003cSMatthias Ringwald		<td>20886</td>
108*af03003cSMatthias Ringwald		<td>21126</td>
109*af03003cSMatthias Ringwald	</tr>
110*af03003cSMatthias Ringwald</table>
111*af03003cSMatthias Ringwald
112*af03003cSMatthias Ringwald#### ECDH (small) ####
113*af03003cSMatthias Ringwald
114*af03003cSMatthias RingwaldIn these tests, `uECC_ASM` was defined to `uECC_asm_small` and `ECC_SQUARE_FUNC` was defined to `0` in all cases.
115*af03003cSMatthias Ringwald
116*af03003cSMatthias Ringwald<table>
117*af03003cSMatthias Ringwald	<tr>
118*af03003cSMatthias Ringwald		<th></th>
119*af03003cSMatthias Ringwald		<th>secp160r1</th>
120*af03003cSMatthias Ringwald		<th>secp192r1</th>
121*af03003cSMatthias Ringwald		<th>secp256r1</th>
122*af03003cSMatthias Ringwald		<th>secp256k1</th>
123*af03003cSMatthias Ringwald	</tr>
124*af03003cSMatthias Ringwald	<tr>
125*af03003cSMatthias Ringwald		<td><em>ECDH time (ms):</em></td>
126*af03003cSMatthias Ringwald		<td>1250</td>
127*af03003cSMatthias Ringwald		<td>1810</td>
128*af03003cSMatthias Ringwald		<td>4790</td>
129*af03003cSMatthias Ringwald		<td>4700</td>
130*af03003cSMatthias Ringwald	</tr>
131*af03003cSMatthias Ringwald	<tr>
132*af03003cSMatthias Ringwald		<td><em>Code size (bytes):</em></td>
133*af03003cSMatthias Ringwald		<td>3244</td>
134*af03003cSMatthias Ringwald		<td>3400</td>
135*af03003cSMatthias Ringwald		<td>5274</td>
136*af03003cSMatthias Ringwald		<td>3426</td>
137*af03003cSMatthias Ringwald	</tr>
138*af03003cSMatthias Ringwald</table>
139*af03003cSMatthias Ringwald
140*af03003cSMatthias Ringwald#### ECDSA (fast) ####
141*af03003cSMatthias Ringwald
142*af03003cSMatthias RingwaldIn these tests, `uECC_ASM` was defined to `uECC_asm_fast` and `ECC_SQUARE_FUNC` was defined to `1` in all cases.
143*af03003cSMatthias Ringwald
144*af03003cSMatthias Ringwald<table>
145*af03003cSMatthias Ringwald	<tr>
146*af03003cSMatthias Ringwald		<th></th>
147*af03003cSMatthias Ringwald		<th>secp160r1</th>
148*af03003cSMatthias Ringwald		<th>secp192r1</th>
149*af03003cSMatthias Ringwald		<th>secp256r1</th>
150*af03003cSMatthias Ringwald		<th>secp256k1</th>
151*af03003cSMatthias Ringwald	</tr>
152*af03003cSMatthias Ringwald	<tr>
153*af03003cSMatthias Ringwald		<td><em>ECDSA sign time (ms):</em></td>
154*af03003cSMatthias Ringwald		<td>555</td>
155*af03003cSMatthias Ringwald		<td>902</td>
156*af03003cSMatthias Ringwald		<td>2386</td>
157*af03003cSMatthias Ringwald		<td>1773</td>
158*af03003cSMatthias Ringwald	</tr>
159*af03003cSMatthias Ringwald	<tr>
160*af03003cSMatthias Ringwald		<td><em>ECDSA verify time (ms):</em></td>
161*af03003cSMatthias Ringwald		<td>590</td>
162*af03003cSMatthias Ringwald		<td>990</td>
163*af03003cSMatthias Ringwald		<td>2650</td>
164*af03003cSMatthias Ringwald		<td>1800</td>
165*af03003cSMatthias Ringwald	</tr>
166*af03003cSMatthias Ringwald	<tr>
167*af03003cSMatthias Ringwald		<td><em>Code size (bytes):</em></td>
168*af03003cSMatthias Ringwald		<td>13246</td>
169*af03003cSMatthias Ringwald		<td>14798</td>
170*af03003cSMatthias Ringwald		<td>22594</td>
171*af03003cSMatthias Ringwald		<td>22826</td>
172*af03003cSMatthias Ringwald	</tr>
173*af03003cSMatthias Ringwald</table>
174*af03003cSMatthias Ringwald
175*af03003cSMatthias Ringwald#### ECDSA (small) ####
176*af03003cSMatthias Ringwald
177*af03003cSMatthias RingwaldIn these tests, `uECC_ASM` was defined to `uECC_asm_small` and `ECC_SQUARE_FUNC` was defined to `0` in all cases.
178*af03003cSMatthias Ringwald
179*af03003cSMatthias Ringwald<table>
180*af03003cSMatthias Ringwald	<tr>
181*af03003cSMatthias Ringwald		<th></th>
182*af03003cSMatthias Ringwald		<th>secp160r1</th>
183*af03003cSMatthias Ringwald		<th>secp192r1</th>
184*af03003cSMatthias Ringwald		<th>secp256r1</th>
185*af03003cSMatthias Ringwald		<th>secp256k1</th>
186*af03003cSMatthias Ringwald	</tr>
187*af03003cSMatthias Ringwald	<tr>
188*af03003cSMatthias Ringwald		<td><em>ECDSA sign time (ms):</em></td>
189*af03003cSMatthias Ringwald		<td>1359</td>
190*af03003cSMatthias Ringwald		<td>1931</td>
191*af03003cSMatthias Ringwald		<td>4998</td>
192*af03003cSMatthias Ringwald		<td>4904</td>
193*af03003cSMatthias Ringwald	</tr>
194*af03003cSMatthias Ringwald	<tr>
195*af03003cSMatthias Ringwald		<td><em>ECDSA verify time (ms):</em></td>
196*af03003cSMatthias Ringwald		<td>1515</td>
197*af03003cSMatthias Ringwald		<td>2160</td>
198*af03003cSMatthias Ringwald		<td>5700</td>
199*af03003cSMatthias Ringwald		<td>5220</td>
200*af03003cSMatthias Ringwald	</tr>
201*af03003cSMatthias Ringwald	<tr>
202*af03003cSMatthias Ringwald		<td><em>Code size (bytes):</em></td>
203*af03003cSMatthias Ringwald		<td>5690</td>
204*af03003cSMatthias Ringwald		<td>5054</td>
205*af03003cSMatthias Ringwald		<td>6980</td>
206*af03003cSMatthias Ringwald		<td>5080</td>
207*af03003cSMatthias Ringwald	</tr>
208*af03003cSMatthias Ringwald</table>
209