Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sage script for constants calculation for banderwagon and bandersnatch #369

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Changes from 15 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2621601
defined sqrtPrecomp_PrimitiveDyadicRoots function for banderwagon and…
rupam-04 Apr 22, 2024
7c3938c
corrected the 31st element of ret array
rupam-04 Apr 22, 2024
011b729
removed the values of 'a' and 'd'
rupam-04 Apr 22, 2024
32a7863
removed lines printing the values of 'a' and 'd'
rupam-04 Apr 22, 2024
c91f340
replaced array with hardcoded variables
rupam-04 Apr 23, 2024
8799d05
defined the sqrtPrecomp_PrimitiveDyadicRoots function as a comment
rupam-04 Apr 23, 2024
188681b
removed hardcoded values with a for loop
rupam-04 Apr 24, 2024
e12eaec
added function name as header
rupam-04 Apr 24, 2024
36cfff2
added sage script for sqrtPrecomp_PrecomputedBlocks function
rupam-04 Apr 26, 2024
cdd55ac
renamed ret to sqrtPrecomp_PrimitiveDyadicRoots
rupam-04 Apr 26, 2024
9d2855a
printed the values of ```i``` in function ```sqrtPrecomp_PrecomputedB…
rupam-04 May 3, 2024
9062c9c
fix: printing issue
advaita-saha May 3, 2024
ae78c67
printed the value of ```sqrtPrecomp_ReconstructionDyadicRoot```
rupam-04 May 3, 2024
a1d7bb9
added sage script function ```sqrtPrecomp_dlogLUT```
rupam-04 May 3, 2024
c560d60
converted point to limbs
rupam-04 May 3, 2024
da2424b
fixed errors in the ```sqrtPrecomp_dlogLUT``` function's script
rupam-04 May 4, 2024
172e1df
minor printing fix
rupam-04 May 4, 2024
36496de
replaced limbs representation of ```rootOfUnity``` with the calculate…
rupam-04 May 5, 2024
3cd8107
added padding and curve selection
rupam-04 May 6, 2024
581b970
Merge branch 'master' into issue-359
rupam-04 Jul 26, 2024
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
54 changes: 54 additions & 0 deletions sage/square_root_banderwagon_and_bandersnatch.sage
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#Parameters
p = 52435875175126190479447740508185965837690552500527637822603658699938581184513
Fp = GF(p)

# BaseField2Adicity = 32 #see https://github.com/crate-crypto/go-ipa/blob/408dbffb2041271c95979a3fb79d98b268bf2880/bandersnatch/fp/sqrt.go#L22
# sqrtPrecomp_PrimitiveDyadicRoots[] is an array of size BaseField2Adicity + 1.
# sqrtPrecomp_PrimitiveDyadicRoots[0] should be equal to 10238227357739495823651030575849232062558860180284477541189508159991286009131 (see https://github.com/crate-crypto/go-ipa/blob/408dbffb2041271c95979a3fb79d98b268bf2880/bandersnatch/fp/sqrt.go#L46)
sqrtPrecomp_PrimitiveDyadicRoots = {}
sqrtPrecomp_PrimitiveDyadicRoots[0] = 10238227357739495823651030575849232062558860180284477541189508159991286009131

print('p : ' + p.hex())

print('\n\nPrimitive Dyadic Roots:\n')
# function sqrtPrecomp_PrimitiveDyadicRoots:
print(hex(sqrtPrecomp_PrimitiveDyadicRoots[0]))
for i in range(0, 32):
sqrtPrecomp_PrimitiveDyadicRoots[i+1] = Fp(sqrtPrecomp_PrimitiveDyadicRoots[i]^2)
print(hex(sqrtPrecomp_PrimitiveDyadicRoots[i+1]))

sqrtPrecomp_ReconstructionDyadicRoot = int(sqrtPrecomp_PrimitiveDyadicRoots[24])

# function sqrtPrecomp_PrecomputedBlocks:
block = {}
print('\n\nPrecomputed Blocks:\n')
for i in range (0, 4):
block[i] = {}
block[i][0] = 1
print("\nFor i = " + str(i) + ":")
for j in range (1, 256):
block[i][j] = Fp(block[i][j-1] * sqrtPrecomp_PrimitiveDyadicRoots[i * 8])
print(hex(block[i][j]))


# function sqrtPrecomp_dlogLUT:
advaita-saha marked this conversation as resolved.
Show resolved Hide resolved
LUTSize = 256
sqrtPrecomp_dlogLUT = {}

rootOfUnity = {}
rootOfUnity[0] = 8589934590
rootOfUnity[1] = 6378425256633387010
rootOfUnity[2] = 11064306276430008309
rootOfUnity[3] = 1739710354780652911

print('\n\nsqrtPrecomp_ReconstructionDyadicRoot = ' + hex(sqrtPrecomp_ReconstructionDyadicRoot) + '\n')

rupam-04 marked this conversation as resolved.
Show resolved Hide resolved
for i in range(LUTSize):
mask = LUTSize - 1
minus_i = -i % sqrtPrecomp_ReconstructionDyadicRoot
sqrtPrecomp_dlogLUT[rootOfUnity[0] & 0xFFFF] = int(minus_i & mask)
print(str(rootOfUnity[0] & 0xFFFF) + ' : ' + str(sqrtPrecomp_dlogLUT[rootOfUnity[0] & 0xFFFF]) + '\n')
rootOfUnity = (rootOfUnity * sqrtPrecomp_ReconstructionDyadicRoot) % p