]> Cypherpunks repositories - gostls13.git/commit
math/big: use optimized formula in ModSqrt for 3 mod 4 primes
authorDavid Leon Gil <coruus@gmail.com>
Fri, 26 Jun 2015 17:29:45 +0000 (10:29 -0700)
committerAdam Langley <agl@golang.org>
Sat, 29 Aug 2015 19:11:03 +0000 (19:11 +0000)
commitea0491b70a82a207a951f869c7c1e5a52dbf410f
treead18e5005258ccd1075a0cc2f2786cbdc1d417c7
parentfac1039615b7f252c38317ce5069d35b45da3cef
math/big: use optimized formula in ModSqrt for 3 mod 4 primes

For primes which are 3 mod 4, using Tonelli-Shanks is slower
and more complicated than using the identity

     a**((p+1)/4) mod p == sqrt(a)

For 2^450-2^225-1 and 2^10860-2^5430-1, which are 3 mod 4:

BenchmarkModSqrt225_TonelliTri      1000     1135375 ns/op
BenchmarkModSqrt225_3Mod4          10000      156009 ns/op
BenchmarkModSqrt5430_Tonelli           1  3448851386 ns/op
BenchmarkModSqrt5430_3Mod4             2   914616710 ns/op

~2.6x to 7x faster.

Fixes #11437 (which is a prime choice of issues to fix)

Change-Id: I813fb29454160483ec29825469e0370d517850c2
Reviewed-on: https://go-review.googlesource.com/11522
Reviewed-by: Adam Langley <agl@golang.org>
src/math/big/int.go
src/math/big/int_test.go