Skip to content

Conversation

@tarcieri
Copy link
Member

Implements Tonelli-Shank's algorithm for q mod 16 = 1 as synthesized using the ff_derive crate, then modified to use Self::pow_vartime (with a fixed exponent, where it is only variable time with respect to the exponent)

As part of implementing this, it was discovered that root_of_unity() was incorrect. I (re)calculated it using sage:

sage: n = 115792089210356248762697446949407573529996955224135760342422259061068512044369
sage: GF(n).primitive_element()
7
sage: s = 4
sage: t = (n - 1) >> s
sage: power_mod(7,t,n)
115695789336771192084080718687965001507772259361175921799893286721837170845186

Closes #170

Implements Tonelli-Shank's algorithm for q mod 16 = 1 as synthesized
using the `ff_derive` crate, then modified to use `Self::pow_vartime`
(with a fixed exponent, where it is only variable time with respect to
the exponent)

As part of implementing this, it was discovered that `root_of_unity()`
was incorrect. I calculated it using sage:

```sage
sage: n = 115792089210356248762697446949407573529996955224135760342422259061068512044369
sage: GF(n).primitive_element()
7
sage: s = 4
sage: t = (n - 1) >> s
sage: power_mod(7,t,n)
115695789336771192084080718687965001507772259361175921799893286721837170845186
```

Closes #170
@codecov-commenter
Copy link

codecov-commenter commented Jul 28, 2021

Codecov Report

Merging #392 (5c18f8e) into master (73e8089) will increase coverage by 0.33%.
The diff coverage is 84.84%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #392      +/-   ##
==========================================
+ Coverage   59.06%   59.40%   +0.33%     
==========================================
  Files          29       29              
  Lines        4175     4207      +32     
==========================================
+ Hits         2466     2499      +33     
+ Misses       1709     1708       -1     
Impacted Files Coverage Δ
p256/src/arithmetic/scalar.rs 80.62% <84.84%> (+2.02%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 73e8089...5c18f8e. Read the comment docs.

@tarcieri tarcieri merged commit fe737c5 into master Jul 28, 2021
@tarcieri tarcieri deleted the p256/sqrt branch July 28, 2021 19:32
tarcieri added a commit that referenced this pull request Aug 31, 2021
Implements Tonelli-Shank's algorithm for q mod 16 = 1 as synthesized
using the `ff_derive` crate, similar to #392 which implements it for the
`p256`.

Like `p256`, as part of implementing this it was discovered that
`root_of_unity()` was incorrect. Here it is (re)calculated with sage:

    sage: n = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
    sage: GF(n).primitive_element()
    7
    sage: s = 6
    sage: t = (n - 1) >> s
    sage: power_mod(7,t,n)
    5480320495727936603795231718619559942670027629901634955707709633242980176626

Note that the value was computed correctly originally, but the hex
digits were shifted such that the resulting value was left shifted by
4-bits. This has now been corrected.
tarcieri added a commit that referenced this pull request Aug 31, 2021
Implements Tonelli-Shank's algorithm for q mod 16 = 1 as synthesized
using the `ff_derive` crate, similar to #392 which implements it for the
`p256`.

Like `p256`, as part of implementing this it was discovered that
`root_of_unity()` was incorrect. Here it is (re)calculated with sage:

    sage: n = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
    sage: GF(n).primitive_element()
    7
    sage: s = 6
    sage: t = (n - 1) >> s
    sage: power_mod(7,t,n)
    5480320495727936603795231718619559942670027629901634955707709633242980176626

Note that the value was computed correctly originally, but the hex
digits were shifted such that the resulting value was left shifted by
4-bits. This has now been corrected.
tarcieri added a commit that referenced this pull request Aug 31, 2021
Implements Tonelli-Shank's algorithm for q mod 16 = 1 as synthesized
using the `ff_derive` crate, similar to #392 which implements it for the
`p256`.

Like `p256`, as part of implementing this it was discovered that
`root_of_unity()` was incorrect. Here it is (re)calculated with sage:

    sage: n = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
    sage: GF(n).primitive_element()
    7
    sage: s = 6
    sage: t = (n - 1) >> s
    sage: power_mod(7,t,n)
    5480320495727936603795231718619559942670027629901634955707709633242980176626

Note that the value was computed correctly originally, but the hex
digits were shifted such that the resulting value was left shifted by
4-bits. This has now been corrected.
@tarcieri tarcieri mentioned this pull request Aug 31, 2021
2 tasks
tarcieri added a commit that referenced this pull request Aug 31, 2021
Implements Tonelli-Shank's algorithm for q mod 16 = 1 as synthesized
using the `ff_derive` crate, similar to #392 which implements it for the
`p256`.

Like `p256`, as part of implementing this it was discovered that
`root_of_unity()` was incorrect. Here it is (re)calculated with sage:

    sage: n = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
    sage: GF(n).primitive_element()
    7
    sage: s = 6
    sage: t = (n - 1) >> s
    sage: power_mod(7,t,n)
    5480320495727936603795231718619559942670027629901634955707709633242980176626

Note that the value was computed correctly originally, but the hex
digits were shifted such that the resulting value was left shifted by
4-bits. This has now been corrected.
tarcieri added a commit that referenced this pull request Aug 31, 2021
Implements Tonelli-Shank's algorithm for q mod 16 = 1 as synthesized
using the `ff_derive` crate, similar to #392 which implements it for the
`p256`.

Like `p256`, as part of implementing this it was discovered that
`root_of_unity()` was incorrect. Here it is (re)calculated with sage:

    sage: n = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
    sage: GF(n).primitive_element()
    7
    sage: s = 6
    sage: t = (n - 1) >> s
    sage: power_mod(7,t,n)
    5480320495727936603795231718619559942670027629901634955707709633242980176626

Note that the value was computed correctly originally, but the hex
digits were shifted such that the resulting value was left shifted by
4-bits. This has now been corrected.
tarcieri added a commit that referenced this pull request Aug 31, 2021
Implements Tonelli-Shank's algorithm for q mod 16 = 1 as synthesized
using the `ff_derive` crate, similar to #392 which implements it for the
`p256`.

Like `p256`, as part of implementing this it was discovered that
`root_of_unity()` was incorrect. Here it is (re)calculated with sage:

    sage: n = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
    sage: GF(n).primitive_element()
    7
    sage: s = 6
    sage: t = (n - 1) >> s
    sage: power_mod(7,t,n)
    5480320495727936603795231718619559942670027629901634955707709633242980176626

Note that the value was computed correctly originally, but the hex
digits were shifted such that the resulting value was left shifted by
4-bits. This has now been corrected.
@tarcieri tarcieri mentioned this pull request Dec 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scalar::sqrt unimplemented

3 participants