Skip to content

Commit 06114a5

Browse files
committed
Merge branch 'main' into symbol-asm
2 parents 3e107d3 + 26b8f13 commit 06114a5

File tree

188 files changed

+12442
-2162
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

188 files changed

+12442
-2162
lines changed

.github/workflows/cifuzz.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: CIFuzz
2+
on: [pull_request]
3+
jobs:
4+
Fuzzing:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- name: Build Fuzzers
8+
id: build
9+
uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master
10+
with:
11+
oss-fuzz-project-name: 'relic'
12+
dry-run: false
13+
language: c++
14+
- name: Run Fuzzers
15+
uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master
16+
with:
17+
oss-fuzz-project-name: 'relic'
18+
fuzz-seconds: 300
19+
dry-run: false
20+
language: c++
21+
- name: Upload Crash
22+
uses: actions/upload-artifact@v3
23+
if: failure() && steps.build.outcome == 'success'
24+
with:
25+
name: artifacts
26+
path: ./out/artifacts

.github/workflows/codeql.yml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: "CodeQL"
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
schedule:
9+
- cron: "54 0 * * 1"
10+
11+
jobs:
12+
analyze:
13+
name: Analyze
14+
runs-on: ubuntu-latest
15+
permissions:
16+
actions: read
17+
contents: read
18+
security-events: write
19+
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
language: [ cpp ]
24+
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v3
28+
29+
- name: Initialize CodeQL
30+
uses: github/codeql-action/init@v2
31+
with:
32+
languages: ${{ matrix.language }}
33+
queries: +security-and-quality
34+
35+
- name: Autobuild
36+
uses: github/codeql-action/autobuild@v2
37+
38+
- name: Perform CodeQL Analysis
39+
uses: github/codeql-action/analyze@v2
40+
with:
41+
category: "/language:${{ matrix.language }}"

.github/workflows/multi.yml

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ jobs:
4848
steps:
4949
- uses: actions/checkout@v2
5050

51+
- name: Install Linux Dependencies
52+
if: ${{ (runner.os == 'Linux') && (matrix.config.cc == 'clang') }}
53+
run: sudo apt install libomp5 libomp-dev
54+
5155
- name: Set Windows enviroment
5256
if: ${{ (runner.os == 'Windows') && (matrix.config.cc == 'cl') }}
5357
uses: ilammy/msvc-dev-cmd@v1

.indent.pro

+3
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,6 @@
6262
-T dis_t
6363
-T rsa_pub_t
6464
-T rsa_prv_t
65+
-T ers_t
66+
-T etrs_t
67+
-T smlers_t

CMakeLists.txt

+10-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ message(" WITH=FP Prime field arithmetic.")
7171
message(" WITH=FPX Prime extension field arithmetic.")
7272
message(" WITH=FB Binary field arithmetic.")
7373
message(" WITH=EP Elliptic curves over prime fields.")
74-
message(" WITH=EPX Elliptic curves over quadratic extensions of prime fields.")
74+
message(" WITH=EPX Elliptic curves over extensions of prime fields.")
7575
message(" WITH=EB Elliptic curves over binary fields.")
7676
message(" WITH=ED Elliptic Edwards curves over prime fields.")
7777
message(" WTTH=EC Elliptic curve cryptography.")
@@ -129,6 +129,15 @@ message(STATUS "Prefix to identify this build of the library (default = \"\"):\n
129129

130130
message(" LABEL=relic\n")
131131

132+
message(STATUS "Available switches (default = CHECK, VERBS, DOCUM):\n")
133+
134+
message(" RLC_DEPTH=w Width w in [2,8] of table for fixed exponentiation.")
135+
message(" RLC_WIDTH=w Width w in [2,6] of table for exponentiation.\n")
136+
137+
# Table sizes for exponentiation methods
138+
set(RLC_DEPTH "5" CACHE STRING "Width of precomputation table for fixed base exponentiation methods.")
139+
set(RLC_WIDTH "4" CACHE STRING "Width of window processing for general exponentiation methods.")
140+
132141
include(cmake/arch.cmake)
133142
include(cmake/err.cmake)
134143
include(cmake/bn.cmake)

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,4 @@ Starting from version 0.3.3, static linking and changes in the configuration or
6363

6464
### Disclaimer
6565

66-
RELIC is at most alpha-quality software. Implementations may not be correct or secure and may include patented algorithms. There are *many* configuration options which make the library horribly insecure. Backward API compatibility with early versions may not necessarily be maintained. Use at your own risk.
66+
RELIC is at best alpha-quality software. Implementations may not be correct or secure and may include patented algorithms. There are *many* configuration options which make the library horribly insecure. Backward API compatibility with early versions may not necessarily be maintained. Use at your own risk.

bench/bench_bn.c

+64-4
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,10 @@ static void util(void) {
282282

283283
static void arith(void) {
284284
bn_t a, b, c, d[3], e[3];
285+
bn_t t[16], u[16];
285286
crt_t crt;
286287
dig_t f;
287-
int len;
288+
size_t len;
288289

289290
bn_null(a);
290291
bn_null(b);
@@ -300,6 +301,10 @@ static void arith(void) {
300301
bn_new(d[j]);
301302
bn_new(e[j]);
302303
}
304+
for (int i = 0; i < 16; ++i) {
305+
bn_null(t[i]); bn_null(u[i]);
306+
bn_new(t[i]); bn_new(u[i]);
307+
}
303308
crt_new(crt);
304309

305310
BENCH_RUN("bn_add") {
@@ -667,6 +672,57 @@ static void arith(void) {
667672
}
668673
BENCH_END;
669674

675+
bn_set_2b(b, RLC_BN_BITS);
676+
bn_rand(c, RLC_POS, RLC_DIG);
677+
bn_sub(b, b, c);
678+
if (bn_is_even(b)) {
679+
bn_add_dig(b, b, 1);
680+
}
681+
for(int i = 0; i < 16; i++) {
682+
bn_rand_mod(t[i], b);
683+
bn_rand_mod(u[i], b);
684+
}
685+
686+
BENCH_RUN("bn_mxp_sim") {
687+
BENCH_ADD(bn_mxp_sim(c, t[0], u[0], t[1], u[1], b));
688+
}
689+
BENCH_END;
690+
691+
BENCH_RUN("bn_mxp_sim_few (2)") {
692+
BENCH_ADD(bn_mxp_sim_few(c, t, u, b, 2));
693+
}
694+
BENCH_END;
695+
696+
BENCH_RUN("bn_mxp_sim_few (4)") {
697+
BENCH_ADD(bn_mxp_sim_few(c, t, u, b, 4));
698+
}
699+
BENCH_END;
700+
701+
BENCH_RUN("bn_mxp_sim_few (8)") {
702+
BENCH_ADD(bn_mxp_sim_few(c, t, u, b, 8));
703+
}
704+
BENCH_END;
705+
706+
BENCH_RUN("bn_mxp_sim_lot (2)") {
707+
BENCH_ADD(bn_mxp_sim_lot(c, (const bn_t*)t, (const bn_t*)u, b, 2));
708+
}
709+
BENCH_END;
710+
711+
BENCH_RUN("bn_mxp_sim_lot (4)") {
712+
BENCH_ADD(bn_mxp_sim_lot(c, (const bn_t*)t, (const bn_t*)u, b, 4));
713+
}
714+
BENCH_END;
715+
716+
BENCH_RUN("bn_mxp_sim_lot (8)") {
717+
BENCH_ADD(bn_mxp_sim_lot(c, (const bn_t*)t, (const bn_t*)u, b, 8));
718+
}
719+
BENCH_END;
720+
721+
BENCH_RUN("bn_mxp_sim_lot (16)") {
722+
BENCH_ADD(bn_mxp_sim_lot(c, (const bn_t*)t, (const bn_t*)u, b, 16));
723+
}
724+
BENCH_END;
725+
670726
bn_gen_prime(crt->p, RLC_BN_BITS / 2);
671727
bn_gen_prime(crt->q, RLC_BN_BITS / 2);
672728
bn_mul(crt->n, crt->p, crt->q);
@@ -891,7 +947,7 @@ static void arith(void) {
891947

892948
BENCH_RUN("bn_rec_naf") {
893949
int8_t naf[RLC_BN_BITS + 1];
894-
int len;
950+
size_t len;
895951
bn_rand(a, RLC_POS, RLC_BN_BITS);
896952
BENCH_ADD((len = RLC_BN_BITS + 1, bn_rec_naf(naf, &len, a, 4)));
897953
}
@@ -901,7 +957,7 @@ static void arith(void) {
901957
if (eb_param_set_any_kbltz() == RLC_OK) {
902958
BENCH_RUN("bn_rec_tnaf") {
903959
int8_t tnaf[RLC_FB_BITS + 8];
904-
int len = RLC_BN_BITS + 1;
960+
size_t len = RLC_BN_BITS + 1;
905961
eb_curve_get_ord(b);
906962
bn_rand_mod(a, b);
907963
if (eb_curve_opt_a() == RLC_ZERO) {
@@ -928,7 +984,7 @@ static void arith(void) {
928984

929985
BENCH_RUN("bn_rec_reg") {
930986
int8_t naf[RLC_BN_BITS + 1];
931-
int len = RLC_BN_BITS + 1;
987+
size_t len = RLC_BN_BITS + 1;
932988
bn_rand(a, RLC_POS, RLC_BN_BITS);
933989
BENCH_ADD((len = RLC_BN_BITS + 1, bn_rec_reg(naf, &len, a, RLC_BN_BITS, 4)));
934990
}
@@ -962,6 +1018,10 @@ static void arith(void) {
9621018
bn_free(d[j]);
9631019
bn_free(e[j]);
9641020
}
1021+
for (int i = 0; i < 16; ++i) {
1022+
bn_free(t[i]);
1023+
bn_free(u[i]);
1024+
}
9651025
crt_free(crt);
9661026
}
9671027

bench/bench_cp.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -141,28 +141,28 @@ static void benaloh(void) {
141141
dig_t in, new;
142142
uint8_t out[RLC_BN_BITS / 8 + 1];
143143
size_t out_len;
144+
dig_t prime = 0xFB;
144145

145146
bdpe_null(pub);
146147
bdpe_null(prv);
147148

148149
bdpe_new(pub);
149150
bdpe_new(prv);
150151

151-
BENCH_ONE("cp_bdpe_gen", cp_bdpe_gen(pub, prv, bn_get_prime(47),
152-
RLC_BN_BITS), 1);
152+
BENCH_ONE("cp_bdpe_gen", cp_bdpe_gen(pub, prv, prime, RLC_BN_BITS), 1);
153153

154154
BENCH_RUN("cp_bdpe_enc") {
155155
out_len = RLC_BN_BITS / 8 + 1;
156156
rand_bytes(out, 1);
157-
in = out[0] % bn_get_prime(47);
157+
in = out[0] % prime;
158158
BENCH_ADD(cp_bdpe_enc(out, &out_len, in, pub));
159159
cp_bdpe_dec(&new, out, out_len, prv);
160160
} BENCH_END;
161161

162162
BENCH_RUN("cp_bdpe_dec") {
163163
out_len = RLC_BN_BITS / 8 + 1;
164164
rand_bytes(out, 1);
165-
in = out[0] % bn_get_prime(47);
165+
in = out[0] % prime;
166166
cp_bdpe_enc(out, &out_len, in, pub);
167167
BENCH_ADD(cp_bdpe_dec(&new, out, out_len, prv));
168168
} BENCH_END;
@@ -1328,7 +1328,7 @@ static void pss(void) {
13281328
}
13291329
}
13301330

1331-
#ifdef WITH_MPC
1331+
#if defined(WITH_MPC)
13321332

13331333
static void mpss(void) {
13341334
bn_t m[2], n, u[2], v[2], ms[10][2], _v[10][2];

bench/bench_epx.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@
3737
static void memory2(void) {
3838
ep2_t a[BENCH];
3939

40-
BENCH_FEW("ep2_null", ep4_null(a[i]), 1);
40+
BENCH_FEW("ep2_null", ep2_null(a[i]), 1);
4141

42-
BENCH_FEW("ep2_new", ep4_new(a[i]), 1);
42+
BENCH_FEW("ep2_new", ep2_new(a[i]), 1);
4343
for (int i = 0; i < BENCH; i++) {
4444
ep2_free(a[i]);
4545
}
4646

4747
for (int i = 0; i < BENCH; i++) {
4848
ep2_new(a[i]);
4949
}
50-
BENCH_FEW("ep2_free", ep4_free(a[i]), 1);
50+
BENCH_FEW("ep2_free", ep2_free(a[i]), 1);
5151

5252
(void)a;
5353
}

cmake/eb.cmake

-11
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ message(" EB_PLAIN=[off|on] Support for ordinary curves without endomorphis
66
message(" EB_KBLTZ=[off|on] Support for Koblitz anomalous binary curves.")
77
message(" EB_MIXED=[off|on] Use mixed coordinates.")
88
message(" EB_PRECO=[off|on] Build precomputation table for generator.")
9-
message(" EB_DEPTH=w Width w in [2,8] of precomputation table for fixed point methods.")
10-
message(" EB_WIDTH=w Width w in [2,6] of window processing for unknown point methods.\n")
119

1210
message(" ** Available binary elliptic curve methods (default = PROJC;LWNAF;COMBS;INTER):\n")
1311

@@ -34,15 +32,6 @@ message(" EB_METHD=TRICK Shamir's trick for simultaneous multiplication.
3432
message(" EB_METHD=INTER Interleaving of window (T)NAFs.")
3533
message(" EB_METHD=JOINT Joint sparse form.\n")
3634

37-
if (NOT EB_DEPTH)
38-
set(EB_DEPTH 4)
39-
endif(NOT EB_DEPTH)
40-
if (NOT EB_WIDTH)
41-
set(EB_WIDTH 4)
42-
endif(NOT EB_WIDTH)
43-
set(EB_DEPTH "${EB_DEPTH}" CACHE STRING "Width of precomputation table for fixed point methods.")
44-
set(EB_WIDTH "${EB_WIDTH}" CACHE STRING "Width of window processing for unknown point methods.")
45-
4635
option(EB_PLAIN "Support for ordinary curves without endomorphisms" on)
4736
option(EB_KBLTZ "Support for Koblitz anomalous binary curves" on)
4837
option(EB_MIXED "Use mixed coordinates" on)

cmake/ed.cmake

+1-11
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ message(STATUS "Elliptic Edwards curve over prime fields arithmetic configuratio
22

33
message(" ** Options for the prime elliptic Edwards curve module (default = all on):")
44
message(" ED_PRECO=[off|on] Build precomputation table for generator.")
5-
message(" ED_DEPTH=w Width w in [2,6] of precomputation table for fixed point methods.")
6-
message(" ED_WIDTH=w Width w in [2,6] of window processing for unknown point methods.\n")
5+
message(" RLC_DEPTH=w Width w in [2,6] of precomputation table for fixed point methods.")
76

87
message(" ** Available prime elliptic Edwards curve methods (default = PROJC;LWNAF;COMBS;INTER):")
98
message(" ED_METHD=BASIC Affine coordinates.")
@@ -31,15 +30,6 @@ message(" ED_METHD=JOINT Joint sparse form.\n")
3130

3231
message(" Note: these methods must be given in order. Ex: ED_METHD=\"EXTND;LWNAF;COMBD;TRICK\"\n")
3332

34-
if (NOT ED_DEPTH)
35-
set(ED_DEPTH 4)
36-
endif(NOT ED_DEPTH)
37-
if (NOT ED_WIDTH)
38-
set(ED_WIDTH 4)
39-
endif(NOT ED_WIDTH)
40-
set(ED_DEPTH "${ED_DEPTH}" CACHE STRING "Width of precomputation table for fixed point methods.")
41-
set(ED_WIDTH "${ED_WIDTH}" CACHE STRING "Width of window processing for unknown point methods.")
42-
4333
option(ED_PRECO "Build precomputation table for generator" on)
4434

4535
# Choose the arithmetic methods.

cmake/ep.cmake

+1-11
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ message(" EP_MIXED=[off|on] Use mixed coordinates.")
99
message(" EP_CTMAP=[off|on] Use contant-time SSWU and isogeny map for hashing.\n")
1010

1111
message(" EP_PRECO=[off|on] Build precomputation table for generator.")
12-
message(" EP_DEPTH=w Width w in [2,8] of precomputation table for fixed point methods.")
13-
message(" EP_WIDTH=w Width w in [2,6] of window processing for unknown point methods.\n")
12+
message(" RLC_DEPTH=w Width w in [2,8] of precomputation table for fixed point methods.")
1413

1514
message(" ** Available prime elliptic curve methods (default = PROJC;LWNAF;COMBS;INTER;SSWUM):\n")
1615

@@ -43,15 +42,6 @@ message(" EP_METHD=BASIC Hash to x-coordinate and increment.")
4342
message(" EP_METHD=SSWUM Simplified Shallue-van de Woestijne-Ulas method.")
4443
message(" EP_METHD=SWIFT SwiftEC hashing method.\n")
4544

46-
if (NOT EP_DEPTH)
47-
set(EP_DEPTH 4)
48-
endif(NOT EP_DEPTH)
49-
if (NOT EP_WIDTH)
50-
set(EP_WIDTH 4)
51-
endif(NOT EP_WIDTH)
52-
set(EP_DEPTH "${EP_DEPTH}" CACHE STRING "Width of precomputation table for fixed point methods.")
53-
set(EP_WIDTH "${EP_WIDTH}" CACHE STRING "Width of window processing for unknown point methods.")
54-
5545
option(EP_PLAIN "Support for ordinary curves without endomorphisms" on)
5646
option(EP_SUPER "Support for supersingular curves" on)
5747
option(EP_MIXED "Use mixed coordinates" on)

0 commit comments

Comments
 (0)