aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/pubkey/ed25519/sc_reduce.cpp
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2018-03-20 17:18:00 -0400
committerJack Lloyd <[email protected]>2018-03-20 18:28:17 -0400
commitc22fc530382acb28c3d747baf5eef8f44059182a (patch)
tree8e117af3ccb8db2da640a7db6aa92a99dca4e001 /src/lib/pubkey/ed25519/sc_reduce.cpp
parent8a7559e4f8ad179802ef482131faa5dfc0a074ad (diff)
Add another Ed25519 helper to save a few hundred redundant lines
No impact on performance.
Diffstat (limited to 'src/lib/pubkey/ed25519/sc_reduce.cpp')
-rw-r--r--src/lib/pubkey/ed25519/sc_reduce.cpp122
1 files changed, 14 insertions, 108 deletions
diff --git a/src/lib/pubkey/ed25519/sc_reduce.cpp b/src/lib/pubkey/ed25519/sc_reduce.cpp
index ec8f94955..b9d0f9527 100644
--- a/src/lib/pubkey/ed25519/sc_reduce.cpp
+++ b/src/lib/pubkey/ed25519/sc_reduce.cpp
@@ -51,53 +51,12 @@ void sc_reduce(uint8_t* s)
int64_t s22 = MASK & (load_4(s + 57) >> 6);
int64_t s23 = (load_4(s + 60) >> 3);
- s11 += s23 * 666643;
- s12 += s23 * 470296;
- s13 += s23 * 654183;
- s14 -= s23 * 997805;
- s15 += s23 * 136657;
- s16 -= s23 * 683901;
- s23 = 0;
-
- s10 += s22 * 666643;
- s11 += s22 * 470296;
- s12 += s22 * 654183;
- s13 -= s22 * 997805;
- s14 += s22 * 136657;
- s15 -= s22 * 683901;
- s22 = 0;
-
- s9 += s21 * 666643;
- s10 += s21 * 470296;
- s11 += s21 * 654183;
- s12 -= s21 * 997805;
- s13 += s21 * 136657;
- s14 -= s21 * 683901;
- s21 = 0;
-
- s8 += s20 * 666643;
- s9 += s20 * 470296;
- s10 += s20 * 654183;
- s11 -= s20 * 997805;
- s12 += s20 * 136657;
- s13 -= s20 * 683901;
- s20 = 0;
-
- s7 += s19 * 666643;
- s8 += s19 * 470296;
- s9 += s19 * 654183;
- s10 -= s19 * 997805;
- s11 += s19 * 136657;
- s12 -= s19 * 683901;
- s19 = 0;
-
- s6 += s18 * 666643;
- s7 += s18 * 470296;
- s8 += s18 * 654183;
- s9 -= s18 * 997805;
- s10 += s18 * 136657;
- s11 -= s18 * 683901;
- s18 = 0;
+ redc_mul(s11, s12, s13, s14, s15, s16, s23);
+ redc_mul(s10, s11, s12, s13, s14, s15, s22);
+ redc_mul( s9, s10, s11, s12, s13, s14, s21);
+ redc_mul( s8, s9, s10, s11, s12, s13, s20);
+ redc_mul( s7, s8, s9, s10, s11, s12, s19);
+ redc_mul( s6, s7, s8, s9, s10, s11, s18);
carry<21>(s6, s7);
carry<21>(s8, s9);
@@ -112,53 +71,12 @@ void sc_reduce(uint8_t* s)
carry<21>(s13, s14);
carry<21>(s15, s16);
- s5 += s17 * 666643;
- s6 += s17 * 470296;
- s7 += s17 * 654183;
- s8 -= s17 * 997805;
- s9 += s17 * 136657;
- s10 -= s17 * 683901;
- s17 = 0;
-
- s4 += s16 * 666643;
- s5 += s16 * 470296;
- s6 += s16 * 654183;
- s7 -= s16 * 997805;
- s8 += s16 * 136657;
- s9 -= s16 * 683901;
- s16 = 0;
-
- s3 += s15 * 666643;
- s4 += s15 * 470296;
- s5 += s15 * 654183;
- s6 -= s15 * 997805;
- s7 += s15 * 136657;
- s8 -= s15 * 683901;
- s15 = 0;
-
- s2 += s14 * 666643;
- s3 += s14 * 470296;
- s4 += s14 * 654183;
- s5 -= s14 * 997805;
- s6 += s14 * 136657;
- s7 -= s14 * 683901;
- s14 = 0;
-
- s1 += s13 * 666643;
- s2 += s13 * 470296;
- s3 += s13 * 654183;
- s4 -= s13 * 997805;
- s5 += s13 * 136657;
- s6 -= s13 * 683901;
- s13 = 0;
-
- s0 += s12 * 666643;
- s1 += s12 * 470296;
- s2 += s12 * 654183;
- s3 -= s12 * 997805;
- s4 += s12 * 136657;
- s5 -= s12 * 683901;
- s12 = 0;
+ redc_mul(s5, s6, s7, s8, s9, s10, s17);
+ redc_mul(s4, s5, s6, s7, s8, s9, s16);
+ redc_mul(s3, s4, s5, s6, s7, s8, s15);
+ redc_mul(s2, s3, s4, s5, s6, s7, s14);
+ redc_mul(s1, s2, s3, s4, s5, s6, s13);
+ redc_mul(s0, s1, s2, s3, s4, s5, s12);
carry<21>(s0, s1);
carry<21>(s2, s3);
@@ -174,13 +92,7 @@ void sc_reduce(uint8_t* s)
carry<21>(s9, s10);
carry<21>(s11, s12);
- s0 += s12 * 666643;
- s1 += s12 * 470296;
- s2 += s12 * 654183;
- s3 -= s12 * 997805;
- s4 += s12 * 136657;
- s5 -= s12 * 683901;
- s12 = 0;
+ redc_mul(s0, s1, s2, s3, s4, s5, s12);
carry<21>(s0, s1);
carry<21>(s1, s2);
@@ -195,13 +107,7 @@ void sc_reduce(uint8_t* s)
carry<21>(s10, s11);
carry0<21>(s11, s12);
- s0 += s12 * 666643;
- s1 += s12 * 470296;
- s2 += s12 * 654183;
- s3 -= s12 * 997805;
- s4 += s12 * 136657;
- s5 -= s12 * 683901;
- s12 = 0;
+ redc_mul(s0, s1, s2, s3, s4, s5, s12);
carry0<21>(s0, s1);
carry0<21>(s1, s2);