mirror of
https://github.com/data61/MP-SPDZ.git
synced 2026-01-09 13:37:58 -05:00
Secret sharing output for sfix and sfloat.
This commit is contained in:
@@ -84,6 +84,10 @@ def print_str(s, *args, print_secrets=False):
|
||||
if len(args) != s.count('%s'):
|
||||
raise CompilerError('Incorrect number of arguments for string format:', s)
|
||||
substrings = s.split('%s')
|
||||
def secret_error(x):
|
||||
raise CompilerError(
|
||||
'Cannot print secret value %s, activate printing of shares with '
|
||||
"'print_secrets=True'" % args[i])
|
||||
for i,ss in enumerate(substrings):
|
||||
print_plain_str(ss)
|
||||
if i < len(args):
|
||||
@@ -98,13 +102,14 @@ def print_str(s, *args, print_secrets=False):
|
||||
elif print_secrets and isinstance(val, (_secret, sbits)):
|
||||
val.output()
|
||||
else:
|
||||
raise CompilerError(
|
||||
'Cannot print secret value %s, activate printing of shares with '
|
||||
"'print_secrets=True'" % args[i])
|
||||
secret_error(args[i])
|
||||
elif isinstance(val, cfix):
|
||||
val.print_plain()
|
||||
elif isinstance(val, sfix) or isinstance(val, sfloat):
|
||||
raise CompilerError('Cannot print secret value:', args[i])
|
||||
if print_secrets:
|
||||
val.output()
|
||||
else:
|
||||
secret_error()
|
||||
elif isinstance(val, cfloat):
|
||||
val.print_float_plain()
|
||||
elif isinstance(val, (list, tuple)):
|
||||
|
||||
@@ -5148,6 +5148,11 @@ class sfix(_fix):
|
||||
def __repr__(self):
|
||||
return '<sfix{f=%d,k=%d} at %s>' % (self.f, self.k, self.v)
|
||||
|
||||
def output(self):
|
||||
library.print_str(
|
||||
'<sfix{f=%d,k=%d,v=%s}>' % (self.f, self.k, '%s'), self.v,
|
||||
print_secrets=True)
|
||||
|
||||
class unreduced_sfix(_single):
|
||||
int_type = sint
|
||||
|
||||
@@ -5828,6 +5833,11 @@ class sfloat(_number, _secret_structure):
|
||||
f = lambda x: type(self)(*x)
|
||||
return f, sint(list(self)), sint(list(other))
|
||||
|
||||
def output(self):
|
||||
library.print_str(
|
||||
'<sfloat{v=%s,p=%s,z=%s,s=%s}>', self.v, self.p, self.z, self.s,
|
||||
print_secrets=True)
|
||||
|
||||
class cfloat(Tape._no_truth):
|
||||
""" Helper class for printing revealed sfloats. """
|
||||
__slots__ = ['v', 'p', 'z', 's', 'nan']
|
||||
|
||||
Reference in New Issue
Block a user