Commit c9062953 authored by root's avatar root
Browse files

Minor bug fixes

parent 478f4a0c
......@@ -72,7 +72,7 @@ args = parser.parse_args()
if args.keylength == 1024 or args.keylength == 2048:
keylength = args.keylength
if args.size != None and int(args.size) > 10 and int(args.size) > 800000:
if args.size != None and int(args.size) > 10 and int(args.size) < 800000:
db_size = int(args.size)
......@@ -806,7 +806,8 @@ def redeem(points):
exit()
com_list = reader_k.prepare_committed_record(
[db_size, reader_k.l_store[0]["x"][db_size]]
# [db_size, reader_k.l_store[0]["x"][db_size]]
[db_size]
)
p = reader_k.read(sid, p, com_list)
......@@ -868,7 +869,7 @@ def profile(start, end, val):
for i in range(start, end + 1):
com_list = reader_k.prepare_committed_record(
[db_size, reader_k.l_store[0]["x"][db_size]]
[i]
)
p = reader_k.read(sid, p, com_list)
updater.update(sid, p, empty_db_list)
......
......@@ -19,6 +19,7 @@ from uuhd.jsonobjects import dict_from_class
from uuhd.primitives import PaillierEncryption, SHA256, DSA, IntegerCommitment
from uuhd.sigmaprotocol import (
SigmaProtocol,
get_record_by_i,
get_record_by_index,
num_to_str,
sign_u,
......@@ -281,7 +282,7 @@ class FZK_RD:
(self.public_key, self.secret_key) = self.paillier_encryption.keygen(
self.keylength
)
SigmaProtocol.range_proof(
(c,y) = SigmaProtocol.range_proof(
(v_n - points), com_v_n, open_v_n, points, ped_g, ped_h, group
)
v_n_c = self.paillier_encryption.encrypt(
......@@ -377,7 +378,7 @@ class FZK_RD:
dsa = DSA(dsa_p, dsa_q)
dsa_keys = dsa.generate_keys(self.keylength)
hash_y = SHA256(str(y_2).encode("utf-8"))
hash_y = SHA256(str(y).encode("utf-8"))
dsa_a = dsa.generate_random()
dsa_b = dsa.generate_random()
g_d = dsa_keys[0]["g"] ** dsa_a
......@@ -386,7 +387,7 @@ class FZK_RD:
) * (dsa_keys[0]["y"] ** g_d)
dsa_c = (g_d ** dsa_b) * (tag ** integer(hash_y))
hash_m = SHA256(str(y_2).encode("utf-8"))
hash_m = SHA256(str(y).encode("utf-8"))
dsa_h = (
dsa_keys[0]["g"] ** integer(SHA256(str(sid).encode("utf-8")))
) * (dsa_keys[0]["y"] ** g_d)
......@@ -447,8 +448,8 @@ class FZK_PR3:
s_ppe = 1
for instance_record in instance_pr:
witness_record = self.get_record_by_index(
witness_pr, instance_record["i"]
witness_record = get_record_by_i(
instance_record["i"], witness_pr
)
random_v, random_opening_v = group.random(ZR), group.random(ZR)
y_list.append(
......@@ -538,9 +539,9 @@ class FZK_PR3:
s_o_v = random_opening_v + (c * witness_record["openv"])
if not (
(
self.get_record_by_index(t_list, witness_record["i"])["e"]
get_record_by_i(witness_record["i"], t_list)["e"]
* (
self.get_record_by_index(y_list, witness_record["i"])[
get_record_by_i(witness_record["i"], y_list)[
"e"
]
)
......@@ -551,8 +552,6 @@ class FZK_PR3:
print("Abort: (FZK_PR) PPE Check failed.")
exit()
s_ppe = s_ppe * pair(g, gt) ** (s_v)
# integer_commitment_record = self.get_record_by_index(integer_commitments, witness_record["i"])
# randinteger_commitment_record = self.get_record_by_index(random_integer_commitments, witness_record["i"])
hash_random_v = integer(SHA256(bytes(str(random_v), "utf-8")))
hash_random_open_v = integer(
SHA256(bytes(str(random_opening_v), "utf-8"))
......@@ -692,7 +691,7 @@ class FZK_PR3:
ped_h = par_c["h"]
for witness_record in witness_pr:
open_i = witness_record["openi"]
com_i = self.get_record_by_index(instance_pr, witness_record["i"])[
com_i = get_record_by_i(witness_record["i"], instance_pr)[
"comi"
]
SigmaProtocol.range_proof(
......
......@@ -12,7 +12,7 @@ import json
from collections import namedtuple
from charm.core.engine.util import objectToBytes, bytesToObject
from charm.toolbox.pairinggroup import PairingGroup, pair, ZR
from charm.toolbox.pairinggroup import PairingGroup, pair, ZR, G2
from charm.toolbox.integergroup import RSAGroup
from charm.core.engine.util import serializeList
from charm.core.math.integer import integer
......@@ -33,6 +33,10 @@ def get_record_by_index(index, list):
if item["index"] == index:
return item
def get_record_by_i(index, list):
for item in list:
if item["i"] == index:
return item
def generate_n_random_exponents(n):
exponents = []
......@@ -40,15 +44,15 @@ def generate_n_random_exponents(n):
exponents.append(pairing_group.random(ZR))
return exponents
def num_to_str(self, num, length):
str_num = str(num)
if len(str_num) < length:
str_num = "0" * (length - len(str_num)) + str_num
def num_to_str(num, length):
str_num = str(num)
if len(str_num) < length:
str_num = "0" * (length - len(str_num)) + str_num
return str_num
return str_num
def sign_u(self, i, g, x):
def sign_u(i, g, x):
return g ** ((x + i) ** -1)
......@@ -171,14 +175,14 @@ class SigmaProtocol:
return (
(pair(record["sig"]["R_id"], self.v) ** self.one)
* (pair(record["sig"]["S_id"], self.gt) ** self.one)
* (pair(self.g ** self.sid, self.w2) ** self.one)
* (pair(self.g ** self.sid, self.w_2) ** self.one)
* (pair(self.g, self.z) ** -1)
)
else:
return (
(pair(self.h, self.v) ** d_i_1)
* (pair(self.h, self.gt) ** d_i_2)
* (pair(self.g, self.w1) ** -i)
* (pair(self.g, self.w_1) ** -i)
)
def compute_ppe_6(self, index, d_i_1, d_i_3, d_i_4, side):
......@@ -189,7 +193,7 @@ class SigmaProtocol:
pair(record["sig"]["R_id"], record["sig"]["T_id"])
** self.one
)
* (pair(self.u1, record["phd_i"]) ** self.one)
* (pair(self.u_1, record["phd_i"]) ** self.one)
* (pair(self.h, self.ht) ** (d_i_1 * d_i_3))
* (pair(self.g, self.gt) ** -1)
)
......@@ -198,7 +202,7 @@ class SigmaProtocol:
return (
(pair(record["sig"]["R_id"], self.ht) ** d_i_3)
* (pair(self.h, record["sig"]["T_id"]) ** d_i_1)
* (pair(self.u1, self.ht) ** d_i_4)
* (pair(self.u_1, self.ht) ** d_i_4)
)
def compute_ppe_7(self, index, d_i_4, d_i_5, vr, side):
......@@ -1031,7 +1035,7 @@ class SigmaProtocol:
for subwitness in witness["wit_i"]:
#
[d_i_1, di_2, d_i_3, d_i_4, d_i_5] = (
[d_i_1, d_i_2, d_i_3, d_i_4, d_i_5] = (
subwitness["di_1"],
subwitness["di_2"],
subwitness["di_3"],
......@@ -1149,19 +1153,19 @@ class SigmaProtocol:
subwitness["di_4"],
subwitness["di_5"],
)
ciphertext_d_i_1 = self.integer_commitment.commit(
commitment_d_i_1 = self.integer_commitment.commit(
self.par_ic, integer(SHA256(bytes(str(d_i_1), "utf-8")))
)
ciphertext_d_i_2 = self.integer_commitment.commit(
commitment_d_i_2 = self.integer_commitment.commit(
self.par_ic, integer(SHA256(bytes(str(d_i_2), "utf-8")))
)
ciphertext_d_i_3 = self.integer_commitment.commit(
commitment_d_i_3 = self.integer_commitment.commit(
self.par_ic, integer(SHA256(bytes(str(d_i_3), "utf-8")))
)
ciphertext_d_i_4 = self.integer_commitment.commit(
commitment_d_i_4 = self.integer_commitment.commit(
self.par_ic, integer(SHA256(bytes(str(d_i_4), "utf-8")))
)
ciphertext_d_i_5 = self.integer_commitment.commit(
commitment_d_i_5 = self.integer_commitment.commit(
self.par_ic, integer(SHA256(bytes(str(d_i_5), "utf-8")))
)
if is_random:
......@@ -1376,18 +1380,18 @@ class SigmaProtocol:
u_list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
a_i = [
self.sign_u(0, ped_g, x),
self.sign_u(1, ped_g, x),
self.sign_u(2, ped_g, x),
self.sign_u(3, ped_g, x),
self.sign_u(4, ped_g, x),
self.sign_u(5, ped_g, x),
self.sign_u(6, ped_g, x),
self.sign_u(7, ped_g, x),
self.sign_u(8, ped_g, x),
self.sign_u(9, ped_g, x),
sign_u(0, ped_g, x),
sign_u(1, ped_g, x),
sign_u(2, ped_g, x),
sign_u(3, ped_g, x),
sign_u(4, ped_g, x),
sign_u(5, ped_g, x),
sign_u(6, ped_g, x),
sign_u(7, ped_g, x),
sign_u(8, ped_g, x),
sign_u(9, ped_g, x),
]
str_num = self.num_to_str(value, 4)
str_num = num_to_str(value, 4)
# Verifier selects V_j at random
v_0 = group.random(ZR)
......@@ -1495,3 +1499,4 @@ class SigmaProtocol:
* ((ped_g ** ((10 ** 3) * z_s_3)))
):
print("Abort: (FZK_PR) D check failed.")
return c , y
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment