Skip to content

Commit a7a68ab

Browse files
committed
Tighter checker: take elementary probes into account
1 parent b86326d commit a7a68ab

File tree

1 file changed

+49
-7
lines changed

1 file changed

+49
-7
lines changed

check_redundant.sage

+49-7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,35 @@ def is_share_better(x1_s, x2_s):
1818
return apply_mask(x1_s, x2_s) == x1_s
1919

2020

21+
def number_missing_share(x1_s, x2_s):
22+
res = 0
23+
for i1, i2 in zip(x1_s, x2_s):
24+
if i1 and not i2:
25+
res += 1
26+
return res
27+
28+
29+
def xor(x1_r, x2_r):
30+
return [i1^^i2 for i1,i2 in zip(x1_r, x2_r)]
31+
32+
33+
def hamming_weight(x):
34+
res = 0
35+
for i in x:
36+
if i:
37+
res += 1
38+
return res
39+
40+
def share_completion(res, x1_s, x_r_str, i, j, n_r=0):
41+
for x2_s in res[j][x_r_str]:
42+
n_s = number_missing_share(x1_s, x2_s)
43+
# using n elementary probes
44+
if n_r + n_s + j <= i:
45+
return True
46+
47+
return False
48+
49+
2150
def check(M, Mb, mask_r, mask_s, d):
2251
"""
2352
For given matrices `M` and `Mb` containing the probe description before
@@ -65,17 +94,30 @@ def check(M, Mb, mask_r, mask_s, d):
6594

6695
found = False
6796
for j in range(i, -1, -1):
68-
if x1_r_str not in res[j]:
69-
continue
70-
for x2_s in res[j][x1_r_str]:
71-
if is_share_better(x1_s, x2_s):
72-
found = True
97+
if x1_r_str in res[j]:
98+
# Check for already correct randomness
99+
found = share_completion(res, x1_s, x1_r_str, i, j)
100+
if found:
73101
break
102+
103+
# Tries to fix randomness with elementary probes
104+
for x2_r_str in res[j]:
105+
x2_r = [int(v) for v in x2_r_str]
106+
xf_r = xor(x2_r, x1_r)
107+
n_r = hamming_weight(xf_r)
108+
# number of elementary random probes already too high
109+
if n_r + j > i:
110+
continue
111+
# x2_r corrected with xf_r
112+
found = share_completion(res, x1_s, x2_r_str, i, j, n_r)
113+
if found:
114+
break
115+
74116
if found:
75117
break
76118

77119
if not found:
78-
print("Contradiction found!")
120+
print("Cannot remove the probes")
79121
return False
80122
return True
81123

@@ -110,7 +152,7 @@ def gen_matrices_and_masks(filename):
110152
# Filtering out probes
111153
for i in range(len(line)):
112154
s1 = ' '.join(line[:i+1])
113-
# HERE IS the criterion to filter out probes
155+
# HERE IS the criterion to filter out probes (see Section 5)
114156
if not s1.count('s') % 2 and i+1 < len(line) and 's' in line[i + 1]:
115157
to_del.append(i)
116158
probes_todel.append(s1)

0 commit comments

Comments
 (0)