Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions constantine/math/arithmetic/finite_fields_square_root.nim
Original file line number Diff line number Diff line change
Expand Up @@ -361,13 +361,13 @@ func invsqrt_if_square_vartime*[Name](r: var Fp[Name], a: Fp[Name]): SecretBool
# Legendre symbol / Euler's Criterion / Kronecker's symbol
# ------------------------------------------------------------

func isSquare*(a: Fp): SecretBool =
## Returns true if ``a`` is a square (quadratic residue) in 𝔽p
func isSquare*(a: FF): SecretBool =
Comment thread
mratsim marked this conversation as resolved.
Comment thread
mratsim marked this conversation as resolved.
## Returns true if ``a`` is a square (quadratic residue) in 𝔽p or 𝔽r
##
## Assumes that the prime modulus ``p`` is public.
var aa {.noInit.}: Fp.getBigInt()
## Assumes that the prime modulus ``p`` (or ``r``) is public.
Comment thread
mratsim marked this conversation as resolved.
var aa {.noInit.}: FF.getBigInt()
Comment thread
mratsim marked this conversation as resolved.
aa.fromField(a)
let symbol = legendre(aa.limbs, Fp.getModulus().limbs, aa.bits)
let symbol = legendre(aa.limbs, FF.getModulus().limbs, aa.bits)
Comment thread
mratsim marked this conversation as resolved.
return not(symbol == MaxWord)

{.pop.} # inline
Expand Down
14 changes: 14 additions & 0 deletions tests/math_fields/t_finite_fields_sqrt.nim
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,18 @@ proc main() =
a.fromHex"0x7ff7ffffffffffff1dfb7fafc0000000"
testSqrtImpl(a)

suite "isSquare on 𝔽r" & " [" & $WordBitWidth & "-bit words]":
test "𝔽r[BW6_761] is consistent with 𝔽p[BLS12_381]":
block:
var a: Fr[BW6_761]
a.fromHex"0x184d02ce4f24d5e59b4150a57a31b202fd40a4b41d7518c22b84bee475fbcb7763100448ef6b17a6ea603cf062e5db51"
check:
bool(not a.isSquare())
Comment thread
mratsim marked this conversation as resolved.

block:
var a: Fr[BW6_761]
a.fromHex"0x0f16d7854229d8804bcadd889f70411d6a482bde840d238033bf868e89558d39d52f9df60b2d745e02584375f16c34a3"
check:
bool(not a.isSquare())
Comment on lines +203 to +214
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The test description "𝔽r[BW6_761] is consistent with 𝔽p[BLS12_381]" is vague. It doesn't clearly state what consistency is being tested. Clarify the test description to explain the expected behavior or relationship between 𝔽r[BW6_761] and 𝔽p[BLS12_381].

Comment thread
mratsim marked this conversation as resolved.

main()
Loading