authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2020-10-06 14:02:06+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-10-06 19:48:26-04:00
logfb63a2cfaecb981010e0b9d656fd372dbb331888
treeb2485d4d7c47286785db204dfbfc396065ec150a
parentdd4771a5d2815004a75a90895fe45addb3a015d1

std/crypto: faster (mod 2^255-19) square root computation

251 squarings, 250 multiplications -> 251 squarings, 11 multiplications

1 files changed, 8 insertions(+), 6 deletions(-)

lib/std/crypto/25519/field.zig+8-6
...@@ -307,12 +307,14 @@ pub const Fe = struct {...@@ -307,12 +307,14 @@ pub const Fe = struct {
307 }307 }
308308
309 pub fn pow2523(a: Fe) Fe {309 pub fn pow2523(a: Fe) Fe {
310 var c = a;310 var t0 = a.mul(a.sq());
311 var i: usize = 0;311 var t1 = t0.mul(t0.sqn(2)).sq().mul(a);
312 while (i < 249) : (i += 1) {312 t0 = t1.sqn(5).mul(t1);
313 c = c.sq().mul(a);313 var t2 = t0.sqn(5).mul(t1);
314 }314 t1 = t2.sqn(15).mul(t2);
315 return c.sq().sq().mul(a);315 t2 = t1.sqn(30).mul(t1);
316 t1 = t2.sqn(60).mul(t2);
317 return t1.sqn(120).mul(t1).sqn(10).mul(t0).sqn(2).mul(a);
316 }318 }
317319
318 pub fn abs(a: Fe) Fe {320 pub fn abs(a: Fe) Fe {