Repository navigation
RELIC Dual Build
Read this before touching anything that calls RELIC:
src/zml/,deps/relic/,Makefile.common. Mistakes here compile and link cleanly, and then silently compute wrong results.
The authoritative version of these notes is the header of deps/relic/check_ec_symbols.sh. This page explains the same thing with more context.
RELIC is configured at compile time for a single prime field size. OpenABE needs two different curves:
| Build | Curve | Configuration | Headers | Used by |
|---|---|---|---|---|
| bp | BN-254 pairing curve |
FP_PRIME=254, ARITH=easy
|
include/relic/ (unprefixed symbols) |
all ABE schemes |
| ec | NIST P-256 |
FP_PRIME=256, ARITH=gmp, LABEL=ec
|
include/relic_ec/ (ec_-prefixed symbols) |
PK-ENC and ECDSA |
Every OpenABE binary links both libraries (-lrelic -lrelic_ec).
Both builds install headers with identical include guards (#ifndef RLC_XXX_H). If one translation unit includes <relic/relic.h> and then <relic_ec/relic.h>, the second is silently skipped.
It gets worse. The ec build's relic_conf.h defines LABEL=ec, and relic_label.h then rewrites type names by macro (ep_t → ec_ep_t). Code compiled expecting 254-bit types can end up with 256-bit definitions, or vice versa, with no diagnostic.
Rule: a translation unit includes headers from exactly one RELIC build.
LABEL=ec is supposed to prefix every symbol of the ec build. In RELIC 0.7.0 it misses a few dozen: blake2s_*, SHA224/256/384/512*, ep_mul_sim_lot_*, several bn_* and md_xof_*. Both libraries then export them under the same name.
On ELF (Linux), the dynamic linker picks one definition for the whole process. If the wrong one wins, 256-bit code runs 254-bit arithmetic. Mach-O (macOS) resolves names differently, so the bug can hide on one platform and show on the other.
Fix in place: deps/relic/Makefile compiles the ec build with an explicit -D<symbol>=ec_<symbol> for each missed symbol (EC_RENAME). This forces the rename at compile time.
Guard in place: deps/relic/check_ec_symbols.sh (run by CI) fails if:
- any global symbol in
librelic_s_ec.alacks theec_prefix, or - any symbol is defined in both libraries.
Do not remove or bypass this check.
bp side (default) ec side (isolated)
───────────────── ──────────────────
zml/zelement.h includes <relic/relic.h> zml/zelement_ec_relic.h exposes only opaque types
zml/zelement.c thin byte-level wrappers zml/zelement_ec_relic.c built with -DLABEL=ec
and -I…/include/relic_ec
The boundary header exposes no RELIC types. Data crosses between the two sides only as uint8_t buffers, size_t lengths and ints, as big-endian byte strings.
- If you add code that calls RELIC, decide which build it belongs to and put it in that side's translation unit.
- Never include both
<relic/…>and<relic_ec/…>in one file, or in any include chain that crosses both trees. - Pass data across the boundary only as plain bytes, never as RELIC struct pointers.
- If you update RELIC, re-run
check_ec_symbols.sh. Any new unprefixed symbol must be added toEC_RENAMEindeps/relic/Makefile. - Test on both ELF and Mach-O when possible (
make testandmake -C src test). - The PK path exercises both builds end to end:
PKOPDHKemContext,PKSchemeContext,CryptoBoxPKEContextandtest_pke. Always check it after RELIC-related changes.
OpenABE · AGPL-3.0 · Found a mistake in this wiki? Open an issue.
Using OpenABE
Reference
Contributing
Design notes
Help