Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor pairing+elliptic curve code, especially targeting the 192-bit security level. #292

Merged
merged 37 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
a17e89d
Add new hash function.
dfaranha Mar 13, 2024
a22aec2
Change parameters again.
dfaranha Mar 13, 2024
42143dd
Fixes to the formulas.
dfaranha Mar 14, 2024
4ccd5c0
New hash function.
dfaranha Mar 14, 2024
e8c1572
Remove N16_P765 parameters.
dfaranha Mar 14, 2024
72daaa7
Fix compilation bug.
dfaranha Mar 14, 2024
1d746d7
Update presets.
dfaranha Mar 28, 2024
cf08580
Big refactoring of the EP module.
dfaranha Mar 29, 2024
3db85f8
Now refactor point doubling.
dfaranha Mar 29, 2024
1ffffb0
Fix bugs in conversion to template.
dfaranha Mar 29, 2024
b5e5a7c
Another big refactoring to include more coords for ep2.
dfaranha Mar 29, 2024
0881852
Fix for more coords.
dfaranha Mar 29, 2024
308412e
Fix bug in BN curves.
dfaranha Mar 30, 2024
eb8d511
Simplify ep_mul_lwreg.
dfaranha Mar 30, 2024
69d7dc6
Make LWREG use table.
dfaranha Mar 30, 2024
1e72f29
Fix GH Actions build.
dfaranha Mar 30, 2024
a5c1c9e
Configuration fix.
dfaranha Mar 30, 2024
7e86e21
API refacor for constant-time functions.
dfaranha Mar 30, 2024
427deda
Rename function to match new pattern.
dfaranha Mar 30, 2024
0d1e82d
Add missing benchmark.
dfaranha Mar 30, 2024
a4b5c62
More missing benchmarks.
dfaranha Mar 30, 2024
59a448a
Generalize exponentiation to more curves.
dfaranha Mar 30, 2024
856a097
Refactor API for RHS.
dfaranha Mar 30, 2024
184bfd7
Change API for general scalar mult to newer one.
dfaranha Mar 30, 2024
c39487b
Many documentation fixes and minor API changes.
dfaranha Mar 31, 2024
08ddd87
Save some space with the new APIs.
dfaranha Mar 31, 2024
7d6138c
Search for GMP harder.
dfaranha Mar 31, 2024
ac4b411
Simplify handling of QNRs.
dfaranha Mar 31, 2024
dc6bce0
Update preset.
dfaranha Mar 31, 2024
bd42269
Fix towering for BLS12-446 curve.
dfaranha Mar 31, 2024
2201eda
Restoring towering for BN-446.
dfaranha Mar 31, 2024
e28bb68
Minor polish to remove warnings.
dfaranha Mar 31, 2024
8bc067f
Reduce number of tests/benches to speed this one up.
dfaranha Mar 31, 2024
44ebbb9
Do not run tests for extensions we do not need.
dfaranha Mar 31, 2024
63f24c9
Add missing preset.
dfaranha Mar 31, 2024
e52d043
Rename ep_param_embed to ep_curve_embed.
dfaranha Apr 1, 2024
911ed2a
Remove redundant code by moving function from FPX to GT.
dfaranha Apr 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/gmp-sec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ jobs:
gcc
cmake
gmp
gmp-devel
update: true

- name: Run CMake (MingW)
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/gmp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ jobs:
gcc
cmake
gmp
gmp-devel
update: true

- name: Run CMake (MingW)
Expand Down
12 changes: 6 additions & 6 deletions bench/bench_dv.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ static void copy(void) {
BENCH_ADD(dv_copy(a, b, RLC_DV_DIGS));
} BENCH_END;

BENCH_RUN("dv_copy_cond") {
BENCH_RUN("dv_copy_sec") {
rand_bytes((uint8_t *)a, RLC_DV_DIGS * sizeof(dig_t));
rand_bytes((uint8_t *)b, RLC_DV_DIGS * sizeof(dig_t));
BENCH_ADD(dv_copy_cond(a, b, RLC_DV_DIGS, 1));
BENCH_ADD(dv_copy_sec(a, b, RLC_DV_DIGS, 1));
} BENCH_END;

BENCH_RUN("dv_swap_cond") {
BENCH_RUN("dv_swap_sec") {
rand_bytes((uint8_t *)a, RLC_DV_DIGS * sizeof(dig_t));
rand_bytes((uint8_t *)b, RLC_DV_DIGS * sizeof(dig_t));
BENCH_ADD(dv_swap_cond(a, b, RLC_DV_DIGS, 1));
BENCH_ADD(dv_swap_sec(a, b, RLC_DV_DIGS, 1));
} BENCH_END;

BENCH_RUN("dv_cmp") {
Expand All @@ -85,10 +85,10 @@ static void copy(void) {
BENCH_ADD(dv_cmp(a, b, RLC_DV_DIGS));
} BENCH_END;

BENCH_RUN("dv_cmp_const") {
BENCH_RUN("dv_cmp_sec") {
rand_bytes((uint8_t *)a, RLC_DV_DIGS * sizeof(dig_t));
rand_bytes((uint8_t *)b, RLC_DV_DIGS * sizeof(dig_t));
BENCH_ADD(dv_cmp_const(a, b, RLC_DV_DIGS));
BENCH_ADD(dv_cmp_sec(a, b, RLC_DV_DIGS));
} BENCH_END;

dv_free(a);
Expand Down
2 changes: 1 addition & 1 deletion bench/bench_eb.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ static void util(void) {

BENCH_RUN("eb_rhs") {
eb_rand(p);
BENCH_ADD(eb_rhs(q->x, p));
BENCH_ADD(eb_rhs(q->x, p->x));
} BENCH_END;

BENCH_RUN("eb_tab (4)") {
Expand Down
2 changes: 1 addition & 1 deletion bench/bench_ed.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ static void util(void) {

BENCH_RUN("ed_rhs") {
ed_rand(p);
BENCH_ADD(ed_rhs(q->x, p));
BENCH_ADD(ed_rhs(q->x, p->x));
} BENCH_END;

BENCH_RUN("ed_tab (4)") {
Expand Down
2 changes: 1 addition & 1 deletion bench/bench_ep.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ static void util(void) {

BENCH_RUN("ep_rhs") {
ep_rand(p);
BENCH_ADD(ep_rhs(q->x, p));
BENCH_ADD(ep_rhs(q->x, p->x));
} BENCH_END;

BENCH_RUN("ep_tab (4)") {
Expand Down
91 changes: 81 additions & 10 deletions bench/bench_epx.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,7 @@ static void arith2(void) {
ep2_rand(p);
ep2_add_projc(q, q, p);
BENCH_ADD(ep2_add_projc(r, p, q));
}
BENCH_END;
} BENCH_END;

BENCH_RUN("ep2_add_projc (z2 = 1)") {
ep2_rand(p);
Expand All @@ -250,17 +249,44 @@ static void arith2(void) {
ep2_rand(q);
ep2_norm(q, q);
BENCH_ADD(ep2_add_projc(r, p, q));
}
BENCH_END;
} BENCH_END;

BENCH_RUN("ep2_add_projc (z1,z2 = 1)") {
ep2_rand(p);
ep2_norm(p, p);
ep2_rand(q);
ep2_norm(q, q);
BENCH_ADD(ep2_add_projc(r, p, q));
}
BENCH_END;
} BENCH_END;
#endif

#if EP_ADD == JACOB || !defined(STRIP)
BENCH_RUN("ep2_add_jacob") {
ep2_rand(p);
ep2_rand(q);
ep2_add_jacob(p, p, q);
ep2_rand(q);
ep2_rand(p);
ep2_add_jacob(q, q, p);
BENCH_ADD(ep2_add_jacob(r, p, q));
} BENCH_END;

BENCH_RUN("ep2_add_jacob (z2 = 1)") {
ep2_rand(p);
ep2_rand(q);
ep2_add_jacob(p, p, q);
ep2_rand(q);
ep2_norm(q, q);
BENCH_ADD(ep2_add_jacob(r, p, q));
} BENCH_END;

BENCH_RUN("ep2_add_jacob (z1,z2 = 1)") {
ep2_rand(p);
ep2_norm(p, p);
ep2_rand(q);
ep2_norm(q, q);
BENCH_ADD(ep2_add_jacob(r, p, q));
} BENCH_END;
#endif

BENCH_RUN("ep2_sub") {
Expand Down Expand Up @@ -302,15 +328,28 @@ static void arith2(void) {
ep2_rand(q);
ep2_add_projc(p, p, q);
BENCH_ADD(ep2_dbl_projc(r, p));
}
BENCH_END;
} BENCH_END;

BENCH_RUN("ep2_dbl_projc (z1 = 1)") {
ep2_rand(p);
ep2_norm(p, p);
BENCH_ADD(ep2_dbl_projc(r, p));
}
BENCH_END;
} BENCH_END;
#endif

#if EP_ADD == JACOB || !defined(STRIP)
BENCH_RUN("ep2_dbl_jacob") {
ep2_rand(p);
ep2_rand(q);
ep2_add_jacob(p, p, q);
BENCH_ADD(ep2_dbl_jacob(r, p));
} BENCH_END;

BENCH_RUN("ep2_dbl_jacob (z1 = 1)") {
ep2_rand(p);
ep2_norm(p, p);
BENCH_ADD(ep2_dbl_jacob(r, p));
} BENCH_END;
#endif

BENCH_RUN("ep2_neg") {
Expand Down Expand Up @@ -357,6 +396,14 @@ static void arith2(void) {
} BENCH_END;
#endif

#if EP_MUL == LWREG || !defined(STRIP)
BENCH_RUN("ep2_mul_lwreg") {
bn_rand_mod(k, n);
ep2_rand(p);
BENCH_ADD(ep2_mul_lwreg(q, p, k));
} BENCH_END;
#endif

BENCH_RUN("ep2_mul_gen") {
bn_rand_mod(k, n);
BENCH_ADD(ep2_mul_gen(q, k));
Expand Down Expand Up @@ -902,6 +949,14 @@ static void arith3(void) {
} BENCH_END;
#endif

#if EP_MUL == LWREG || !defined(STRIP)
BENCH_RUN("ep3_mul_lwreg") {
bn_rand_mod(k, n);
ep3_rand(p);
BENCH_ADD(ep3_mul_lwreg(q, p, k));
} BENCH_END;
#endif

BENCH_RUN("ep3_mul_gen") {
bn_rand_mod(k, n);
BENCH_ADD(ep3_mul_gen(q, k));
Expand Down Expand Up @@ -1396,6 +1451,14 @@ static void arith4(void) {
} BENCH_END;
#endif

#if EP_MUL == LWREG || !defined(STRIP)
BENCH_RUN("ep4_mul_lwreg") {
bn_rand_mod(k, n);
ep4_rand(p);
BENCH_ADD(ep4_mul_lwreg(q, p, k));
} BENCH_END;
#endif

BENCH_RUN("ep4_mul_gen") {
bn_rand_mod(k, n);
BENCH_ADD(ep4_mul_gen(q, k));
Expand Down Expand Up @@ -1890,6 +1953,14 @@ static void arith8(void) {
} BENCH_END;
#endif

#if EP_MUL == LWREG || !defined(STRIP)
BENCH_RUN("ep8_mul_lwreg") {
bn_rand_mod(k, n);
ep8_rand(p);
BENCH_ADD(ep8_mul_lwreg(q, p, k));
} BENCH_END;
#endif

BENCH_RUN("ep8_mul_gen") {
bn_rand_mod(k, n);
BENCH_ADD(ep8_mul_gen(q, k));
Expand Down
12 changes: 12 additions & 0 deletions bench/bench_fp.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ static void util(void) {
}
BENCH_END;

BENCH_RUN("fp_copy_sec (0)") {
fp_rand(a);
BENCH_ADD(fp_copy_sec(b, a, 0));
}
BENCH_END;

BENCH_RUN("fp_copy_sec (1)") {
fp_rand(a);
BENCH_ADD(fp_copy_sec(b, a, 1));
}
BENCH_END;

BENCH_RUN("fp_zero") {
fp_rand(a);
BENCH_ADD(fp_zero(a));
Expand Down
Loading
Loading