Skip to content

Instantly share code, notes, and snippets.

@maxtaco
Created October 22, 2013 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxtaco/7105751 to your computer and use it in GitHub Desktop.
Save maxtaco/7105751 to your computer and use it in GitHub Desktop.
# Cryptographic blinding: compute random r,
# r_e <- r^e mod n
# and x <- x*r_e mod n
n = @pub.n
await SRF().random_zn n, defer r
r_inv = r.modInverse(n)
r_e = r.modPow(@pub.e,n)
x_1 = x.multiply(r_e).mod(n)
# calculate xp and xq
xp = x_1.mod(@p).modPow(@dP, @p)
xq = x_1.mod(@q).modPow(@dQ, @q)
# xp must be larger than xq to avoid signed bit usage
while xp.compareTo(xq) < 0
xp = xp.add @p
# do last step
y_0 = xp.subtract(xq).multiply(@qInv).mod(@p).multiply(@q).add(xq)
# multiply by r^-1...
y = y_0.multiply(r_inv).mod(n)
cb y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment