Skip to content
kmackayPublic

About

ECDH and ECDSA for 8-bit, 32-bit, and 64-bit processors.

Resources

Stars

1.4k stars

Watchers

79 watching

Forks

Latest commit

 

History

374 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

micro-ecc

A small and fast ECDH and ECDSA implementation for 8-bit, 16-bit, 32-bit, and 64-bit processors.

The static version of micro-ecc (ie, where the curve was selected at compile-time) can be found in the "static" branch.

Features

  • Side-channel hardened: constant-time scalar multiplication with mandatory RNG blinding by default (uECC_CONSTANT_TIME=0), or full constant-time execution without RNG blinding dependence when built with -DuECC_CONSTANT_TIME=1 (see Compilation Notes).
  • Written in C, with optional inline assembly for AVR, ARM, Thumb, MSP430, MIPS (including PIC32M), PIC18, 16-bit PIC (PIC24 and dsPIC), dsPIC33A, RISC-V (RV32IM and RV64IM), and x86-64 (baseline and BMI2/ADX) platforms.
  • Supports 8, 16, 32, and 64-bit architectures.
  • Small code size.
  • No dynamic memory allocation.
  • Support for 8 short Weierstrass curves: secp160r1, secp192r1, secp224r1, secp256r1, secp256k1, plus opt-in secp384r1, brainpoolP256r1, and brainpoolP384r1 (RFC 5639), plus opt-in X25519 (Curve25519 ECDH, RFC 7748) and Ed25519 (Edwards-curve signatures, RFC 8032, with built-in or pluggable SHA-512, optional Ed25519ctx/Ed25519ph, and RFC 7748 Ed25519→X25519 key conversion when both are enabled) — opt-in curves are disabled by default; enable with -DuECC_SUPPORTS_<curve>=1 (e.g. -DuECC_SUPPORTS_x25519=1, -DuECC_SUPPORTS_ed25519=1) or CMake (-DUECC_SUPPORTS_SECP384R1=ON, -DUECC_SUPPORTS_BRAINPOOLP256R1=ON, -DUECC_SUPPORTS_BRAINPOOLP384R1=ON, -DUECC_SUPPORTS_X25519=ON, -DUECC_SUPPORTS_ED25519=ON). X25519 and Ed25519 can also be built standalone with all Weierstrass curves set to 0.
  • BSD 2-clause license.

Usage Notes

Point Representation

Compressed points are represented in the standard format as defined in http://www.secg.org/sec1-v2.pdf (curve_size + 1 bytes starting with 0x02 or 0x03); uncompressed points are represented in standard format, but without the 0x04 prefix. All functions except uECC_decompress() only accept uncompressed points, and uECC_decompress() only accepts compressed points (validating the 0x02/0x03 prefix, x < p, and curve membership, returning 1 on success or zeroing public_key and returning 0 on failure); use uECC_compress() and uECC_decompress() to convert between compressed and uncompressed point representations. uECC_shared_secret() and uECC_verify*() also validate uncompressed public keys internally (and uECC_shared_secret() zeroes secret on error). For Ed25519, uECC_ed25519_valid_public_key() and uECC_ed25519*_verify() reject small-order torsion keys ([8]A == O, and [8]R == O on commitments in verification); uECC_ed25519_public_key_to_x25519() additionally enforces strict prime-order subgroup membership (order(A) == L, rejecting mixed-order points as well).

Private keys are represented in the standard format (ceil(num_n_bits / 8) bytes: 21 bytes for secp160r1, matching curve size for all other curves). Note that secp160r1 ECDSA signatures are 40 bytes (20 bytes each for r and s, retrying if s >= 2^160; prepend a 0x00 byte to each component when interoperating with 42-byte ceil(161/8) libraries).

Optional ECDSA recoverable signing and public key recovery (uECC_sign_recoverable(), uECC_sign_deterministic_recoverable(), and uECC_recover_public_key()) and low-S signature canonicalization (uECC_normalize_signature()) can be enabled independently with -DuECC_SUPPORT_RECOVER_PUBKEY=1 / -DuECC_SUPPORT_NORMALIZE_SIGNATURE=1 (or CMake -DUECC_SUPPORT_RECOVER_PUBKEY=ON / -DUECC_SUPPORT_NORMALIZE_SIGNATURE=ON). Set -DuECC_SUPPORTS_ECDSA=0 (CMake -DUECC_SUPPORTS_ECDSA=OFF) to exclude all ECDSA functions and ECDSA curve-table ROM when only ECDH is needed.

Optional built-in SHA-256 and SHA-512 support can be enabled with -DuECC_SUPPORTS_SHA256=1 and -DuECC_SUPPORTS_SHA512=1 (or CMake -DUECC_SUPPORTS_SHA256=ON / -DUECC_SUPPORTS_SHA512=ON; shares the internal SHA-512 core when uECC_SUPPORTS_ed25519=1 is also enabled). Each provides a uECC_HashContext adapter (uECC_SHA256_HashContext_init() / uECC_SHA512_HashContext_init()) for uECC_sign_deterministic() or general hashing, plus raw-message deterministic ECDSA helpers (uECC_sign_sha256(), uECC_verify_sha256(), uECC_sign_sha512(), uECC_verify_sha512(), and uECC_sign_recoverable_sha*() / uECC_recover_public_key_sha*() when uECC_SUPPORT_RECOVER_PUBKEY=1) that hash the message internally without setting up a hash context. Both are disabled by default (0 B overhead). Low-level point arithmetic (uECC_point_add() and uECC_point_mult()) is exposed in uECC_vli.h when -DuECC_ENABLE_VLI_API=1.

The edge-case scalars / private keys 1, n - 2, and n - 1 (where n is the curve order) are not supported by the Co-Z Montgomery ladder path and will cause uECC_compute_public_key(), uECC_shared_secret(), or uECC_point_mult() to fail depending on the optimization level and algorithm selected (specifically when both uECC_FIXED_BASE_COMB == 0 and uECC_MULT_WINDOW == 0 for uECC_compute_public_key(), or when uECC_MULT_WINDOW == 0 for uECC_shared_secret() and uECC_point_mult()). uECC_make_key() and uECC_sign() retry automatically if an unsupported scalar is generated.

Using the Code

You can integrate micro-ecc in whichever way best fits your build system:

  • Direct source inclusion: Copy (or submodule/symlink) the micro-ecc files into your project, compile uECC.c, and #include "uECC.h".
  • CMake: Add the repository via add_subdirectory() or FetchContent and link against micro-ecc::micro-ecc. Compile-time options are exposed as CMake cache variables (e.g. UECC_OPTIMIZATION_LEVEL, UECC_CONSTANT_TIME, UECC_CACHE_SAFE, UECC_SUPPORTS_SECP256R1, UECC_EXTRA_DEFINES):
    cmake -B build -DUECC_OPTIMIZATION_LEVEL=3 -DUECC_CONSTANT_TIME=ON
    cmake --build build
    ctest --test-dir build --output-on-failure
  • Make: Build build/libuECC.a or run the standalone C tests directly:
    make                                           # builds build/libuECC.a
    make test                                      # builds & runs standalone C tests
    make CC=arm-none-eabi-gcc AR=arm-none-eabi-ar \
         CFLAGS="-mcpu=cortex-m4 -mthumb -Os" UECC_OPTIMIZATION_LEVEL=3
  • Arduino: Use the Library Manager to download micro-ecc (Sketch=>Include Library=>Manage Libraries), then include it via Sketch=>Import Library.

See uECC.h for API documentation, OPTIMIZATION.md for full per-architecture benchmarks and fine-grained tuning flags, and test/README.md for the cross-architecture verification scripts, benchmarks, and simulators.

Optimization Levels

Set -DuECC_OPTIMIZATION_LEVEL=<0..6> (default 2) to trade Flash/ROM size — and stack/RAM at levels 4–6 — for speed. Levels 1 through 6 monotonically increase code size and overall speed on every supported architecture, and automatically specialize when a single Weierstrass curve is enabled (using direct curve dispatch and compile-time curve dimensions, while keeping the uECC.h API unchanged).

  • 0 — Minimal pure C: Smallest portable code, no assembly or fast curve reductions. Very slow; only intended for extreme Flash constraints or debugging (not supported with uECC_CONSTANT_TIME=1).
  • 1 — Smallest practical build (lowest RAM): Enables curve-specific fast reductions and compact looped assembly with no lookup tables.
  • 2 — Default (recommended starting point, lowest RAM): Best size-to-speed sweet spot. Enables fast core assembly with zero precomputed point tables and minimal peak RAM.
  • 3 — Fast key generation & signing (low RAM): Adds a compact precomputed generator table across all architectures, roughly doubling to tripling key generation and signing speed with only ~0–110 B of extra RAM.
  • 4 — Balanced mid-high speed (low-to-medium RAM): Expands the generator table and enables faster modular inversion / unrolled field arithmetic (or faster verification on 8/16-bit targets).
  • 5 — High speed (medium RAM): Larger generator table and fast low-stack signature verification (plus unrolled multiplication for multi-curve 8/16-bit builds).
  • 6 — Maximum speed (higher RAM): Adds windowed ECDH acceleration, full unrolled squaring, the largest default generator table in single-curve builds, and automatic GLV acceleration when secp256k1 is the only enabled Weierstrass curve.

Size & Speed Overview — Single Curve (secp256r1)

Code size (KB, with % growth relative to L1) and overall speedup (geometric mean across ECDH, KeyGen, Sign, and Verify relative to L1), measured with uECC_CONSTANT_TIME=0. See OPTIMIZATION.md for raw cycle/instruction counts, per-operation timings, and L0 baselines.

Architecture L1 (Baseline) L2 (default) L3 L4 L5 L6 (max) Peak RAM (L1 -> L6)
ARM Cortex-M4 5.7 KB
(776 B RAM)
6.4 KB (+12%)
6.3x faster
7.9 KB (+37%)
9.6x faster
9.6 KB (+67%)
12.4x faster
11.3 KB (+97%)
14.0x faster
14.7 KB (+156%)
15.5x faster
776 -> 1,312 B
ARM Cortex-M3 5.7 KB
(776 B RAM)
7.1 KB (+24%)
3.6x faster
8.5 KB (+48%)
5.8x faster
10.5 KB (+84%)
7.5x faster
12.5 KB (+118%)
8.6x faster
15.3 KB (+166%)
9.7x faster
776 -> 1,308 B
ARM Cortex-M0+ 5.9 KB
(784 B RAM)
6.3 KB (+7%)
1.4x faster
7.6 KB (+29%)
2.3x faster
9.4 KB (+60%)
3.9x faster
11.8 KB (+102%)
4.6x faster
14.5 KB (+149%)
5.3x faster
784 -> 1,408 B
AVR (ATmega2560) 11.0 KB
(923 B RAM)
12.4 KB (+13%)
1.4x faster
14.2 KB (+29%)
2.3x faster
18.3 KB (+67%)
5.4x faster
23.2 KB (+112%)
6.8x faster
30.6 KB (+179%)
8.3x faster
923 -> 1,499 B
MSP430 (MPY32) 7.3 KB
(696 B RAM)
8.3 KB (+13%)
2.4x faster
10.0 KB (+36%)
4.1x faster
13.0 KB (+77%)
5.6x faster
16.1 KB (+120%)
6.4x faster
20.4 KB (+178%)
7.4x faster
696 -> 1,240 B
MSP430 (SW mult) 7.8 KB
(696 B RAM)
8.6 KB (+11%)
1.4x faster
10.4 KB (+33%)
2.4x faster
12.6 KB (+62%)
4.0x faster
16.6 KB (+114%)
5.1x faster
19.5 KB (+151%)
5.9x faster
696 -> 1,330 B
PIC18 (XC8) 15.8 KB
(1,293 B RAM)
16.7 KB (+6%)
2.1x faster
19.6 KB (+24%)
3.6x faster
25.3 KB (+60%)
5.9x faster
32.2 KB (+104%)
7.9x faster
35.9 KB (+127%)
8.8x faster
1,293 -> 2,149 B
16-bit PIC (PIC24/dsPIC) 10.7 KB
(1,072 B RAM)
11.3 KB (+6%)
1.7x faster
13.4 KB (+25%)
2.9x faster
18.9 KB (+77%)
4.6x faster
25.3 KB (+137%)
6.0x faster
30.7 KB (+188%)
6.9x faster
1,072 -> 1,586 B
dsPIC33A (XC-DSC) 14.4 KB
(1,284 B RAM)
15.3 KB (+6%)
1.6x faster
17.9 KB (+24%)
2.5x faster
20.0 KB (+39%)
3.0x faster
22.4 KB (+55%)
3.6x faster
25.5 KB (+77%)
4.1x faster
1,284 -> 1,784 B
MIPS32 (PIC32, XC32) 17.5 KB
(880 B RAM)
18.5 KB (+6%)
1.7x faster
21.3 KB (+22%)
3.2x faster
24.4 KB (+40%)
4.0x faster
26.9 KB (+54%)
4.6x faster
31.6 KB (+81%)
5.3x faster
880 -> 1,512 B
RISC-V (RV32IMAC) 8.9 KB
(756 B RAM)
10.1 KB (+13%)
1.6x faster
11.6 KB (+30%)
2.6x faster
14.3 KB (+60%)
3.2x faster
16.2 KB (+81%)
3.7x faster
19.0 KB (+113%)
4.3x faster
756 -> 1,296 B
RISC-V (RV64IMAC) 8.9 KB
(920 B RAM)
9.9 KB (+11%)
1.3x faster
11.5 KB (+29%)
2.2x faster
13.7 KB (+54%)
2.8x faster
15.6 KB (+75%)
3.1x faster
18.5 KB (+108%)
3.6x faster
920 -> 1,320 B
x86-64 (gcc -O2) 18.3 KB
(1,088 B RAM)
26.4 KB (+44%)
1.2x faster
31.2 KB (+70%)
2.1x faster
34.6 KB (+89%)
2.6x faster
36.2 KB (+98%)
3.1x faster
188.0 KB (+925%)
3.7x faster
1,088 -> 2,092 B
All 5 Curves Enabled (secp160r1, secp192r1, secp224r1, secp256r1, secp256k1) — Size & Speed vs. L1
Architecture L1 (Baseline) L2 (default) L3 L4 L5 L6 (max) Peak RAM (L1 -> L6)
ARM Cortex-M4 9.2 KB 11.9 KB (+29%)
7.3x
15.7 KB (+71%)
11.9x
19.9 KB (+116%)
15.6x
22.5 KB (+145%)
16.9x
28.5 KB (+210%)
18.8x
832 -> 1,384 B
ARM Cortex-M3 9.2 KB 12.8 KB (+40%)
4.6x
16.2 KB (+76%)
7.4x
20.4 KB (+122%)
9.5x
22.5 KB (+145%)
10.6x
28.3 KB (+208%)
11.7x
832 -> 1,424 B
ARM Cortex-M0+ 9.4 KB 11.3 KB (+21%)
1.7x
14.6 KB (+56%)
2.8x
19.4 KB (+108%)
4.2x
23.9 KB (+155%)
5.1x
29.9 KB (+220%)
5.9x
836 -> 1,484 B
AVR (ATmega2560) 16.7 KB 21.2 KB (+27%)
1.4x
25.2 KB (+51%)
2.5x
36.8 KB (+120%)
5.0x
48.1 KB (+188%)
6.8x
62.1 KB (+271%)
8.1x
1,691 -> 2,214 B
MSP430 (MPY32) 12.1 KB 14.3 KB (+18%)
2.7x
17.8 KB (+47%)
4.5x
20.5 KB (+69%)
5.3x
26.5 KB (+119%)
6.2x
40.8 KB (+237%)
7.7x
736 -> 1,276 B
MSP430 (SW mult) 12.3 KB 14.8 KB (+20%)
1.4x
18.4 KB (+49%)
2.5x
21.0 KB (+71%)
2.9x
28.8 KB (+134%)
4.2x
43.2 KB (+250%)
5.7x
736 -> 1,366 B
PIC18 (XC8) 21.9 KB 24.1 KB (+10%)
2.1x
28.9 KB (+32%)
3.6x
32.4 KB (+48%)
4.2x
49.1 KB (+124%)
6.2x
68.0 KB (+210%)
8.3x
1,445 -> 2,156 B
16-bit PIC (PIC24/dsPIC) 17.7 KB 19.8 KB (+12%)
1.7x
24.9 KB (+41%)
2.9x
28.8 KB (+62%)
3.4x
41.2 KB (+133%)
4.8x
61.6 KB (+248%)
6.5x
1,100 -> 1,624 B
dsPIC33A (XC-DSC) 23.8 KB 26.4 KB (+11%)
1.5x
31.3 KB (+31%)
2.5x
34.8 KB (+46%)
3.0x
41.6 KB (+74%)
3.4x
46.8 KB (+96%)
3.8x
1,344 -> 1,864 B
MIPS32 (PIC32, XC32) 21.9 KB 26.4 KB (+20%)
1.7x
31.3 KB (+43%)
3.1x
37.4 KB (+70%)
3.8x
45.7 KB (+108%)
4.5x
51.8 KB (+136%)
5.0x
896 -> 1,712 B
RISC-V (RV32IMAC) 14.1 KB 15.4 KB (+9%)
1.5x
19.8 KB (+40%)
2.6x
24.8 KB (+76%)
3.2x
31.1 KB (+120%)
3.7x
32.8 KB (+132%)
4.0x
800 -> 1,344 B
RISC-V (RV64IMAC) 13.9 KB 14.6 KB (+5%)
1.2x
19.9 KB (+43%)
2.1x
25.3 KB (+82%)
2.7x
31.9 KB (+130%)
3.1x
33.9 KB (+144%)
3.3x
1,032 -> 1,448 B
x86-64 (gcc -O2) 25.3 KB 40.8 KB (+61%)
1.3x
51.3 KB (+103%)
2.2x
56.2 KB (+122%)
2.7x
67.0 KB (+165%)
3.3x
654.8 KB (+2485%)
4.0x
1,960 -> 3,388 B

Note: KB = bytes / 1024. On 16-bit PIC (XC16), code size is reported in 24-bit instruction-byte units from the linker map.

For opt-in X25519 and Ed25519 (L0–L6) size, RAM, and speed tables across all architectures, see OPTIMIZATION.md (§6–§7).

Opt-In Optimizations

The options below are not enabled by default across general builds (either because they trade significantly more RAM/Flash than the main ladder or only help a single curve in multi-curve builds). Define them with -D<option>=<value> when compiling uECC.c (or via CMake options such as UECC_SECP256K1_GLV=ON, UECC_SECP256K1_GLV_ECDH=ON, and UECC_EXTRA_DEFINES).

Option Effect Extra Cost / Caveat Default
uECC_SECP256K1_GLV=1 Uses the secp256k1 GLV endomorphism in uECC_verify(), cutting point doublings in half (~37–55% faster secp256k1 verification). +0.8–2.2 KB code (single-curve) / larger in multi-curve builds with no gain on other curves. With uECC_VERIFY_METHOD=3 adds ~0 B peak RAM over L6 (+260–425 B with methods 0/1/2). Auto at L6 when secp256k1 is the only Weierstrass curve (and uECC_SUPPORTS_ECDSA=1); opt-in otherwise (0).
uECC_SECP256K1_GLV_ECDH=1 Uses constant-time GLV decomposition in uECC_shared_secret() for secp256k1 (~36–43% faster ECDH). Requires uECC_MULT_WINDOW (3 or 4). +0.8–2.1 KB code (single-curve) or +1.4–3.9 KB (5-curve), +28–80 B RAM. Auto at L6 when secp256k1 is the only Weierstrass curve; opt-in otherwise (0).
uECC_VERIFY_METHOD=2 Interleaved 4-bit wNAF signature verification (~23–30% faster Verify than method 0) with zero ROM tables — useful in multi-curve builds where Flash is tighter than RAM. +550–720 B peak RAM vs. method 0 (+80–208 B more than L6's uECC_MULT_WINDOW=4 on 9/10 embedded targets). Levels 5–6 use uECC_VERIFY_METHOD=3 instead to keep RAM lower. Opt-in (default is 0, 1, or 3 depending on level).
uECC_VERIFY_G_WINDOW=6..8 Larger precomputed ROM generator table for uECC_VERIFY_METHOD=3 (default is 4 at L5, 5 at L6 — except multi-curve MSP430 SW and secp256k1-only GLV builds, which stay at 4). Only ~+1.7–4% extra Verify speedup for +0.5–1.5 KB per curve at 6 (+1.5–4.6 KB at 7). Opt-in (default 4 or 5).
uECC_FIXED_BASE_COMB=3 + uECC_COMB_TEETH=5 64-point fixed-base generator table (~11–17% faster KeyGen/Sign than 32-point). Automatic at L6 for single-curve builds (+2.1–3.4 KB), but adds +8.7–13.1 KB ROM across 5 curves (overflows 48 KB MSP430 small-model ROM). Single-curve L6 only; opt-in for multi-curve builds.

For every individual algorithmic and assembly-tier override macro, see OPTIMIZATION.md.

Compilation Notes

  • Should compile with any C/C++ compiler that supports stdint.h (including Visual Studio 2013+).
  • To change any compile-time option (such as uECC_OPTIMIZATION_LEVEL), pass it when compiling uECC.c (e.g. -DuECC_OPTIMIZATION_LEVEL=3 in your Makefile or -DUECC_OPTIMIZATION_LEVEL=3 in CMake).
  • uECC_WORD_SIZE (1, 2, 4, or 8 bytes) is detected automatically if not defined; 2 (16-bit words) is intended for 16-bit platforms.
  • uECC_CONSTANT_TIME (default 0) controls whether low-level primitives execute in constant time on secret data. When uECC_CONSTANT_TIME=0, high-level scalar multiplication avoids secret-dependent scalar-bit branches and Weierstrass secret-key operations (uECC_shared_secret(), uECC_compute_public_key(), uECC_sign_deterministic*(), uECC_sign*_sha*(), uECC_point_mult()) require a functioning RNG set via uECC_set_rng() (failing closed if unset) to blind projective Z and ECDSA k inversions; X25519/Ed25519 secret operations opportunistically randomize projective Z when an RNG is set (falling back to Z = 1 without failing if unset) and always keep their secret inversions constant-time. Defining uECC_CONSTANT_TIME=1 makes all operations on secret data (uECC_shared_secret(), uECC_make_key(), uECC_compute_public_key(), the secret inputs of uECC_sign*() — including deterministic, recoverable, and SHA wrappers — uECC_x25519*(), and uECC_ed25519*_sign() / key derivation) execute in constant time at optimization levels >= 1 (level 0 with uECC_CONSTANT_TIME=1 emits a compile-time #error) on supported architectures (x86-64, ARM64, ARM, AVR, MSP430, PIC18, PIC24/dsPIC, dsPIC33A, MIPS32, RISC-V RV32IM/RV64IM) without depending on an RNG for blinding, assuming fixed-latency hardware multiply instructions on the target core (see the ARM, MIPS32, and RISC-V notes below for cores with early-out multipliers).
  • uECC_CACHE_SAFE (default 1 on x86-64 and ARM64, 0 on embedded targets) eliminates secret-dependent memory-access / pointer-swapping patterns that can leak via data caches (disables Weierstrass/X25519 pointer XOR swaps in favor of fixed-address conditional swaps, and uses fixed-address masked copy in uECC_vli_mmod() under uECC_CONSTANT_TIME=1). Define -DuECC_CACHE_SAFE=1 to opt in on cached embedded/SoC cores (e.g. Cortex-A/R, Cortex-M7/M55/M85, cached MIPS/RISC-V, 32-bit x86), or -DuECC_CACHE_SAFE=0 to opt out on desktop.
  • ARM / Thumb: When compiling for Thumb-1 — or for ARM/Thumb-2 at uECC_OPTIMIZATION_LEVEL >= 2 (or level 1 when all enabled curves share one word size) — you must pass -fomit-frame-pointer (enabled automatically at -O1 or higher). Inline assembly requires a GNU-compatible compiler (GCC, Clang, or Keil AC6); IAR, Keil AC5 (armcc), and MSVC ARM automatically fall back to portable C. Under uECC_CONSTANT_TIME=1, Cortex-M0/M0+/M4/M7/M33 execute with fixed-latency multiplies, whereas Cortex-M3 (UMULL/UMLAL/SMULL/SMLAL, 3–5 cycles) and legacy ARMv4T/v5TE cores have operand-dependent early-out long multipliers that can exhibit microarchitectural timing variation on local/physical measurements.
  • AVR: Must be compiled with optimizations enabled (-O1 or higher). MCUs without hardware mul / movw instructions (such as ATtiny84/ATtiny85) automatically fall back to C for multiplication, squaring, safegcd, secp256k1 reduction, Brainpool Montgomery reduction, and X25519/Ed25519 field arithmetic.
  • MSP430 / MSP430X: Supports classic CPU and MSP430X in both small and large memory models. uECC_MSP430_HWMULT selects the hardware multiplier (32 for MPY32, 16 for MPY16) or constant-time software multiplication (0), detected automatically from the -mmcu device header (GCC's -mhwmult does not affect it; define uECC_MSP430_HWMULT=0 explicitly to disable). uECC_MSP430_DISABLE_INTERRUPTS (default 1) disables interrupts while using the hardware multiplier, and uECC_MSP430_MPY_BASE overrides the hardware multiplier register base address (see platform-specific.inc). With Clang, pass -fno-integrated-as (Clang does not support -mlarge).
    • For 256-bit curves in the small memory model, peak RAM (static + stack) is ~670–740 B at levels 1–3, ~850–1,015 B at levels 4–5, and ~1,240–1,370 B at level 6 (add ~100–150 B for -mlarge, plus your application and ISR stack). Devices with 512 B RAM or less are too small.
  • PIC18 (XC8): Automatically detected with Microchip XC8 (tested with XC8 v3.10 at -O2 on PIC18F57Q84, PIC18F47K42, and PIC18F46K22):
    • Use XC8's default compiled stack or -mstack=hybrid (-mstack=reentrant is not supported due to its 128-byte frame limit).
    • Do not call uECC functions from interrupt handlers (compiled stack is not reentrant and XC8 does not track register usage inside inline assembly).
    • With uECC_vli.h, all uECC_word_t pointers must point to RAM.
    • Keep the RNG callback passed to uECC_set_rng() free of local variables (call a helper function instead) to avoid an XC8 v3.10 compiled-stack overlap bug on calls through function pointers.
    • Peak RAM for 256-bit curves is ~1.3–1.8 KB at levels 1–5 and ~2.1 KB at level 6; devices with less than 2 KB RAM are too small for 256-bit curves.
  • 16-bit PIC (PIC24F/H/E, dsPIC30F, dsPIC33F/E/C): Automatically detected with Microchip XC16 (tested v2.10 at -O2) and XC-DSC (tested v4.00, dsPIC33 only). Do not change PSVPAG/DSRPAG while uECC runs (ISRs must restore them, as auto_psv does). On EDS parts (>30 KB RAM, e.g. dsPIC33EP512MU810), pass -mno-eds-warn if stack and buffers stay in the first 32 KB of RAM. Peak RAM for 256-bit curves is ~1.0–1.3 KB at levels 1–5 and ~1.6 KB at level 6 with XC16 (XC-DSC adds ~50–60 B stack).
  • MIPS32 (PIC32MX / MZ / MK / MM, XC32): Automatically detected for MIPS32 releases 1–5 with HI/LO multiply (MIPS32 or microMIPS, not MIPS16; tested with XC32 v5.10 at -O2). Multiplications and uECC_SAFEGCD=1 matrix updates are scheduled to hide the 1–2-cycle rt-dependent early exit of fixed-latency and PIC32 fast-MDU cores (PIC32MX/MZ/MK/MM — M4K / microAptiv fast MDU; level 0 is disallowed with uECC_CONSTANT_TIME=1). Area-optimized MIPS32 cores synthesized with an iterative multi-cycle MDU (up to 16–32 cycles with operand-dependent early exit) may still exhibit multiply timing variation under uECC_CONSTANT_TIME=1. Peak RAM for 256-bit curves is ~0.9–1.0 KB at levels 1–4, ~1.2–1.3 KB at level 5, and ~1.5–1.7 KB at level 6.
  • dsPIC33A (32-bit DSC, XC-DSC): Automatically detected with Microchip XC-DSC (tested v4.00 at -O1/-O2/-Os). Assembly does not touch DSP accumulators, W14, or W15; the 32x32 multiplier is single-cycle for all operands (level 0 is disallowed with uECC_CONSTANT_TIME=1). Peak RAM for 256-bit curves is ~1.3 KB at levels 1–4, ~1.4–1.5 KB at level 5, and ~1.7–1.8 KB at level 6.
  • RISC-V (RV32IM / RV64IM): Automatically detected for both RV32 (uECC_riscv32, 32-bit words) and RV64 (uECC_riscv64, 64-bit words). GNU-compatible compilers (GCC, Clang) targeting 32-register cores with the M extension (__riscv_mul, excluding RV32E) use branchless inline assembly without requiring -fomit-frame-pointer (tested with riscv64-unknown-elf-gcc and Clang at -Os/-O2); RV32E and M-less RV32I/RV64I cores automatically fall back to portable C with branchless carry propagation. Under uECC_CONSTANT_TIME=1, fixed-latency M-extension multipliers (e.g. cores implementing Zkt or fixed-cycle multipliers) are assumed; area-optimized soft-cores with iterative early-out multipliers may exhibit operand-dependent multiply latency. Peak RAM for 256-bit curves is ~0.7–0.9 KB at levels 1–4, ~1.0–1.1 KB at level 5, and 1.3 KB at level 6 on RV32IMAC (0.8–1.2 KB at levels 1–5 and ~1.3–1.4 KB at level 6 on RV64IMAC).
  • Windows (including UWP and Xbox): Link against bcrypt.lib (uses CNG BCryptGenRandom).

About

ECDH and ECDSA for 8-bit, 32-bit, and 64-bit processors.

Resources

Stars

1.4k stars

Watchers

79 watching

Forks

Releases

Packages

Used by

Contributors

Languages