A sample code - usage of Python binding to MCL, as of Github repository.
from mcl import GT
from mcl import G2
from mcl import G1
from mcl import Fr
import time
G1_STR = b"1 3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507 1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569"
G2_STR = b"1 352701069587466618187139116011060144890029952792775240219908644239793785735715026873347600343865175952761926303160 3059144344244213709971259814753781636986470325476647558659373206291635324768958432433509563104347017837885763365758 1985150602287291935568054521177171638300868978215655730859378665066344726373823718423869104263333984641494340347905 927553665492332455747201965776037880757740193453592970025027978793976877002675564980949289727957565575433344219582"
a = Fr()
b = Fr()
c = Fr()
d = Fr()
e = Fr()
f = Fr()
a.setByCSPRNG()
b.setByCSPRNG()
c.setByCSPRNG()
a.setInt(2)
b.setInt(3)
c.setInt(5)
d.setInt(6)
e.setHash(b"1d")
g1 = G1()
g1.setStr(G1_STR)
h1 = G1()
h1 = G1.hashAndMapTo(b"abcd")
g2 = G2()
g2.setStr(G2_STR)
print(e.getStr())
t = time.time()
f.setHash(b"1d")
h1 = g1 * a * b
h1 = g1 * f
k2 = G2()
k1 = G1()
e6 = GT.pairing(h1 * e, g2 *f)
e1 = GT.pairing(g1 * a, g2 *b)
h1 = g1 * d
k1 = h1 - g1
e7 = GT.pairing(h1 * e * f, g2 *f)
e1 = GT.pairing(g1 * a, g2 *b)
print (time.time()-t)
t = time.time()
e2 = GT.pairing(g1, g2)
e7 = GT.pairing(k1, g2)
e3 = e2 * e2 * e2 * e2 * e2
print (time.time()-t)
print(e7.getStr())
print(e3.getStr() == e7.getStr())
print(e3 == e7)
t = time.time()
a.setByCSPRNG()
b.setByCSPRNG()
c.setByCSPRNG()
g1 = G1.hashAndMapTo(b"abcd")
h1 = g1 * a * b
k2 = G2()
g2 = G2.hashAndMapTo(b"abcd")
k2 = g2 * c
ee1 = GT.pairing(h1, k2)
ee2 = GT.pairing(g1, k2 * a * b)
print(ee1 == ee2)
a.setInt(2)
b.setInt(3)
c.setInt(6)
d.setByCSPRNG()
h1 = g1 * d
k1 = h1 - g1
z2 = g2 * d - g2
e7 = GT.pairing(k1, g2)
e8 = GT.pairing(g1, z2)
print(e8 == e7)
c.setInt(5)
h1 = g1 * d
k1 = h1 - g1
z2 = g2 * c - g2
e2 = GT.pairing(g1, g2)
e8 = GT.pairing(g1, z2)
e5 = e2 * e2 * e2 * e2
print(e8 == e5)
print (time.time()-t)
Python binging to MCL
a = new mcl.Fr()
x = new mcl.Fr()
c = new mcl.Fr()
s = new mcl.Fr()
Q = mcl.hashAndMapToG2('genQ')
a.setByCSPRNG()
A = mcl.mul(Q, a)
x.setByCSPRNG()
X = mcl.mul(Q, x)
c.setByCSPRNG()
s = mcl.add(x, mcl.mul(a, c))
S = mcl.mul(Q, s)
cA = mcl.mul(A, c)
XcA = mcl.add(X, cA)
Schnorr Identification Scheme - concept in MCL/JavaScript/WASM.
a1 = new mcl.Fr()
a2 = new mcl.Fr()
x1 = new mcl.Fr()
x2 = new mcl.Fr()
c = new mcl.Fr()
s1 = new mcl.Fr()
s2 = new mcl.Fr()
P = mcl.hashAndMapToG1('genP')
Q1 = mcl.hashAndMapToG2('genQ')
Q2 = mcl.hashAndMapToG2('genQ')
a1.setByCSPRNG()
A1 = mcl.mul(Q1, a1)
a2.setByCSPRNG()
A2 = mcl.mul(Q2, a2)
A = mcl.add(A1, A2)
x1.setByCSPRNG()
X1 = mcl.mul(Q1, x1)
x2.setByCSPRNG()
X2 = mcl.mul(Q2, x2)
X = mcl.add(X1, X2)
c.setByCSPRNG()
s1 = mcl.add(x1, mcl.mul(a1, c))
S1 = mcl.mul(Q1, s1)
s2 = mcl.add(x2, mcl.mul(a2, c))
S2 = mcl.mul(Q2, s2)
S = mcl.add(S1, S2)
cA = mcl.mul(A, c)
XcA = mcl.add(X, cA)
Okamoto Identification Scheme - concept in MCL/JavaScript/WASM.
Note: use MCL library (https://github.com/herumi/mcl). A Python binding to MCL is recommended, e.g. mcl-python.
from charm.toolbox.ecgroup import ECGroup,ZR,G
from charm.toolbox.eccurve import prime192v1
group = ECGroup(prime192v1)
g_1 = group.random(G)
g_2 = group.random(G)
a_1 = group.random(ZR)
a_2 = group.random(ZR)
A = g_1 ** a_1 * g_2 ** a_2
rng = 10000
assert group.InitBenchmark(), "failed to initialize benchmark"
group.StartBenchmark(["CpuTime"])
for i in range(rng):
x_1 = group.random(ZR)
x_2 = group.random(ZR)
X = g_1 ** x_1 * g_2 ** x_2
c = group.random(ZR)
s_1 = x_1 + a_1 * c
s_2 = x_2 + a_2 * c
Left = X * A ** c
Right = g_1 ** s_1 * g_2 ** s_2
group.EndBenchmark()
print("CP: ", group.GetBenchmark("CpuTime")/rng)
print(Left == Right)
Okamoto Identification Scheme - concept implementation in Charm-Crypto Python library.
from charm.toolbox.pairinggroup import PairingGroup,ZR,G1,G2,pair
from charm.toolbox.pairinggroup import *
#group = PairingGroup('MNT224')
group = PairingGroup('SS512')
g = group.random(G1)
h = group.random(G2)
a = group.random() # secret key
A = h ** a # public key
rng = 100
assert group.InitBenchmark(), "failed to initialize benchmark"
group.StartBenchmark(["CpuTime"])
for i in range(rng):
x = group.random() # ephemeral secret key
X = h ** x # ephemeral public key
c = group.random() # challenge
s = x + a * c
S = g ** s
e1 = pair(S, h)
e2 = pair(g, X + A ** c)
group.EndBenchmark()
print("CP: ", group.GetBenchmark("CpuTime")/rng)
print(e1 == e2)
Mod Schnorr Identification Scheme - concept implementation in Charm-Crypto Python library.
F. Sebé, J. Domingo-Ferrer, A. Martinez-Balleste, Y. Deswarte and J. Quisquater, in IEEE Transactions on Knowledge and Data Engineering, vol. 20, no. 8, pp. 1034-1038, Aug. 2008, doi: 10.1109/TKDE.2007.190647.
Taken from: Barsoum, Ayad F. and M. A. Hasan. “Provable Possession and Replication of Data over Cloud Servers”. (2011).
Golle P., Jarecki S., Mironov I. (2003). In: Blaze M. (eds) Financial Cryptography. FC 2002. Lecture Notes in Computer Science, vol 2357. Springer, Berlin, Heidelberg. https://doi.org/10.1007/3-540-36504-4_9
Taken from: Barsoum, Ayad F. and M. A. Hasan. “Provable Possession and Replication of Data over Cloud Servers”. (2011).
Giuseppe Ateniese, Randal Burns, Reza Curtmola, Joseph Herring, Lea Kissner, Zachary Peterson, and Dawn Song. 2007. In Proceedings of the 14th ACM conference on Computer and communications security (CCS '07). Association for Computing Machinery, New York, NY, USA, 598–609. DOI:https://doi.org/10.1145/1315245.1315318
Taken from: Barsoum, Ayad F. and M. A. Hasan. “Provable Possession and Replication of Data over Cloud Servers”. (2011).
J. Herranz and G. Sáez. 2007. In T. Johansson and S. Maitra, editors, INDOCRYPT, volume 2904 of Lecture Notes in Computer Science, pages 266–279. Springer, 2003
Taken from: Ł. Krzywiecki, M. Sulkowska, F. Zagórski, Hierarchical Ring Signatures Revisited - Unconditionally and Perfectly Anonymous Schnorr Version. SPACE 2015: 329-346.
"Anonymous Deniable Identification in Ephemeral Setup and Leakage Scenarios"
Taken from: Ł. Krzywiecki, M. Kutyłowski, J. Pezda, M. Słowik Anonymous Deniable Identification in Ephemeral Setup and Leakage Scenarios (Brief Announcement) . CSCML 2019: 320-323
Maxwell, G., Poelstra, A., Seurin, Y., Wuille, P.: Simple schnorr multi-signatures with applications to bitcoin. Designs, Codes and Cryptography 87(9), (Sep 2019) 2139–2164.
Based on (some differences in variable names): Maxwell, G., Poelstra, A., Seurin, Y., Wuille, P.: Simple schnorr multi-signatures with applications to bitcoin. Designs, Codes and Cryptography 87(9), (Sep 2019) 2139–2164.
Chou T., Orlandi C. (2015). The Simplest Protocol for Oblivious Transfer. In: Lauter K., Rodríguez-Henríquez F. (eds) Progress in Cryptology -- LATINCRYPT 2015. LATINCRYPT 2015. Lecture Notes in Computer Science, vol 9230. Springer, Cham. https://doi.org/10.1007/978-3-319-22174-8_3
Taken from: The Simplest Protocol for Oblivious Transfer. https://doi.org/10.1007/978-3-319-22174-8_3
Naor, M., Pinkas, B. Computationally Secure Oblivious Transfer. J Cryptology 18, 1–35 (2005). https://doi.org/10.1007/s00145-004-0102-6
Taken from: Computationally Secure Oblivious Transfer. J Cryptology 18, 1–35 (2005).
De Cristofaro E., Gasti P., Tsudik G. (2012). Fast and Private Computation of Cardinality of Set Intersection and Union. CANS 2012. Lecture Notes in Computer Science, vol 7712. https://doi.org/10.1007/978-3-642-35404-5_17
Taken from: De Cristofaro E., Gasti P., Tsudik G. (2012). Fast and Private Computation of Cardinality of Set Intersection and Union.
Moni Naor and Benny Pinkas. Taken from: Oblivious Polynomial Evaluation. SIAM Journal on Computing 2006 35:5, 1254-1281
Taken from: Oblivious Polynomial Evaluation. Moni Naor and Benny Pinkas. SIAM Journal on Computing 2006 35:5, 1254-1281
Note: use Python Charm-crypto library (recommended).
Students should solve, deliver and explain personally the solutions for the list of excercises to the tutor/superviser of the lab. A list can be passed only if all its exercises are solved. Please do not email the solutions. A student will pass the course only if all the lists are solved and delivered before the end of the semester.
© 2023 Łukasz Krzywiecki. Coded with W3.CSS