Skip to content

Commit

Permalink
Make crypto_scalarmult CT on DOIT.
Browse files Browse the repository at this point in the history
  • Loading branch information
J08nY committed May 8, 2024
1 parent a28c27b commit e874ab0
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 20 deletions.
50 changes: 40 additions & 10 deletions src/crypto_scalarmult/curve25519/amd64/ref5/mul5.jinc
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,33 @@ inline fn __mul5_rss(stack u64[5] xa ya) -> reg u64[5]
cf, r[3] += mulrax;
_, mulr31 += mulrdx + cf;
mulredmask = 0x7FFFFFFFFFFFF;
?{}, mulr01 = #SHLD(mulr01, r[0], 13);
mulr01 <<= 13;
mulrax = r[0];
mulrax >>= 51;
mulr01 |= mulrax;
r[0] &= mulredmask;
?{}, mulr11 = #SHLD(mulr11, r[1], 13);
mulr11 <<= 13;
mulrax = r[1];
mulrax >>= 51;
mulr11 |= mulrax;
r[1] &= mulredmask;
r[1] += mulr01;
?{}, mulr21 = #SHLD(mulr21, r[2], 13);
mulr21 <<= 13;
mulrax = r[2];
mulrax >>= 51;
mulr21 |= mulrax;
r[2] &= mulredmask;
r[2] += mulr11;
?{}, mulr31 = #SHLD(mulr31, r[3], 13);
mulr31 <<= 13;
mulrax = r[3];
mulrax >>= 51;
mulr31 |= mulrax;
r[3] &= mulredmask;
r[3] += mulr21;
?{}, mulr41 = #SHLD(mulr41, r[4], 13);
mulr41 <<= 13;
mulrax = r[4];
mulrax >>= 51;
mulr41 |= mulrax;
r[4] &= mulredmask;
r[4] += mulr31;
mulr41 = mulr41 * 19;
Expand Down Expand Up @@ -293,18 +308,33 @@ fn _mul5_pp(reg ptr u64[5] xa ya) -> reg ptr u64[5]
cf, r[3] += mulrax;
_, mulr31 += mulrdx + cf;
mulredmask = 0x7FFFFFFFFFFFF;
?{}, mulr01 = #SHLD(mulr01, r[0], 13);
mulr01 <<= 13;
mulrax = r[0];
mulrax >>= 51;
mulr01 |= mulrax;
r[0] &= mulredmask;
?{}, mulr11 = #SHLD(mulr11, r[1], 13);
mulr11 <<= 13;
mulrax = r[1];
mulrax >>= 51;
mulr11 |= mulrax;
r[1] &= mulredmask;
r[1] += mulr01;
?{}, mulr21 = #SHLD(mulr21, r[2], 13);
mulr21 <<= 13;
mulrax = r[2];
mulrax >>= 51;
mulr21 |= mulrax;
r[2] &= mulredmask;
r[2] += mulr11;
?{}, mulr31 = #SHLD(mulr31, r[3], 13);
mulr31 <<= 13;
mulrax = r[3];
mulrax >>= 51;
mulr31 |= mulrax;
r[3] &= mulredmask;
r[3] += mulr21;
?{}, mulr41 = #SHLD(mulr41, r[4], 13);
mulr41 <<= 13;
mulrax = r[4];
mulrax >>= 51;
mulr41 |= mulrax;
r[4] &= mulredmask;
r[4] += mulr31;
mulr41 = mulr41 * 19;
Expand Down
50 changes: 40 additions & 10 deletions src/crypto_scalarmult/curve25519/amd64/ref5/sqr5.jinc
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,33 @@ inline fn __sqr5_rs(stack u64[5] xa) -> reg u64[5]
cf, r[3] += squarerax;
_, squarer31 += squarerdx + cf;
squareredmask = 0x7FFFFFFFFFFFF;
_, _, _, _, _, squarer01 = #SHLD(squarer01, r[0], 13);
squarer01 <<= 13;
squarerax = r[0];
squarerax >>= 51;
squarer01 |= squarerax;
r[0] &= squareredmask;
_, _, _, _, _, squarer11 = #SHLD(squarer11, r[1], 13);
squarer11 <<= 13;
squarerax = r[1];
squarerax >>= 51;
squarer11 |= squarerax;
r[1] &= squareredmask;
r[1] += squarer01;
_, _, _, _, _, squarer21 = #SHLD(squarer21, r[2], 13);
squarer21 <<= 13;
squarerax = r[2];
squarerax >>= 51;
squarer21 |= squarerax;
r[2] &= squareredmask;
r[2] += squarer11;
_, _, _, _, _, squarer31 = #SHLD(squarer31, r[3], 13);
squarer31 <<= 13;
squarerax = r[3];
squarerax >>= 51;
squarer31 |= squarerax;
r[3] &= squareredmask;
r[3] += squarer21;
_, _, _, _, _, squarer41 = #SHLD(squarer41, r[4], 13);
squarer41 <<= 13;
squarerax = r[4];
squarerax >>= 51;
squarer41 |= squarerax;
r[4] &= squareredmask;
r[4] += squarer31;
squarer41 = squarer41 * 19;
Expand Down Expand Up @@ -217,18 +232,33 @@ fn _sqr5_p(reg ptr u64[5] xa) -> reg ptr u64[5]
cf, r[3] += squarerax;
_, squarer31 += squarerdx + cf;
squareredmask = 0x7FFFFFFFFFFFF;
_, _, _, _, _, squarer01 = #SHLD(squarer01, r[0], 13);
squarer01 <<= 13;
squarerax = r[0];
squarerax >>= 51;
squarer01 |= squarerax;
r[0] &= squareredmask;
_, _, _, _, _, squarer11 = #SHLD(squarer11, r[1], 13);
squarer11 <<= 13;
squarerax = r[1];
squarerax >>= 51;
squarer11 |= squarerax;
r[1] &= squareredmask;
r[1] += squarer01;
_, _, _, _, _, squarer21 = #SHLD(squarer21, r[2], 13);
squarer21 <<= 13;
squarerax = r[2];
squarerax >>= 51;
squarer21 |= squarerax;
r[2] &= squareredmask;
r[2] += squarer11;
_, _, _, _, _, squarer31 = #SHLD(squarer31, r[3], 13);
squarer31 <<= 13;
squarerax = r[3];
squarerax >>= 51;
squarer31 |= squarerax;
r[3] &= squareredmask;
r[3] += squarer21;
_, _, _, _, _, squarer41 = #SHLD(squarer41, r[4], 13);
squarer41 <<= 13;
squarerax = r[4];
squarerax >>= 51;
squarer41 |= squarerax;
r[4] &= squareredmask;
r[4] += squarer31;
squarer41 = squarer41 * 19;
Expand Down

0 comments on commit e874ab0

Please sign in to comment.