Implement output of GF(2^n) shares.

This commit is contained in:
Marcel Keller
2024-02-15 11:24:37 +11:00
parent ed8bdffcf0
commit c8222f14f6
5 changed files with 12 additions and 6 deletions

View File

@@ -1641,6 +1641,7 @@ class print_reg_plain(base.IOInstruction):
code = base.opcodes['PRINTREGPLAIN']
arg_format = ['c']
@base.gf2n
class print_reg_plains(base.IOInstruction):
""" Output secret register.

View File

@@ -3,7 +3,7 @@ This module defines functions directly available in high-level programs,
in particularly providing flow control and output.
"""
from Compiler.types import cint,sint,cfix,sfix,sfloat,MPCThread,Array,MemValue,cgf2n,sgf2n,_number,_mem,_register,regint,Matrix,_types, cfloat, _single, localint, personal, copy_doc, _vec, SubMultiArray
from Compiler.types import cint,sint,cfix,sfix,sfloat,MPCThread,Array,MemValue,cgf2n,sgf2n,_number,_mem,_register,regint,Matrix,_types, cfloat, _single, localint, personal, copy_doc, _vec, SubMultiArray, _secret
from Compiler.instructions import *
from Compiler.util import tuplify,untuplify,is_zero
from Compiler.allocator import RegintOptimizer, AllocPool
@@ -94,7 +94,7 @@ def print_str(s, *args, print_secrets=False):
if isinstance(val, Tape.Register):
if val.is_clear:
val.print_reg_plain()
elif print_secrets and isinstance(val, sint):
elif print_secrets and isinstance(val, _secret):
val.output()
else:
raise CompilerError(

View File

@@ -2340,6 +2340,10 @@ class _secret(_arithmetic_register, _secret_structure):
def raw_mod2m(self, m):
return self - (self.raw_right_shift(m) << m)
@set_instruction_type
@vectorize
def output(self):
print_reg_plains(self)
class sint(_secret, _int):
"""
@@ -3090,10 +3094,6 @@ class sint(_secret, _int):
concats(res, *args)
return res
@vectorize
def output(self):
print_reg_plains(self)
class sintbit(sint):
""" :py:class:`sint` holding a bit, supporting binary operations
(``&, |, ^``). """

View File

@@ -303,6 +303,7 @@ enum
GPRINTMEM = 0x1B0,
GPRINTREG = 0X1B1,
GPRINTREGPLAIN = 0x1B3,
GPRINTREGPLAINS = 0x1EA,
GRAWOUTPUT = 0x1B7,
GSTARTPRIVATEOUTPUT = 0x1B8,
GSTOPPRIVATEOUTPUT = 0x1B9,

View File

@@ -146,6 +146,7 @@ void BaseInstruction::parse_operands(istream& s, int pos, int file_pos)
case JMPI:
case GBIT:
case GPRINTREGPLAIN:
case GPRINTREGPLAINS:
case JOIN_TAPE:
case PUSHINT:
case POPINT:
@@ -1181,6 +1182,9 @@ inline void Instruction::execute(Processor<sint, sgf2n>& Proc) const
case PRINTREGPLAINS:
Proc.out << Proc.read_Sp(r[0]);
return;
case GPRINTREGPLAINS:
Proc.out << Proc.read_S2(r[0]);
return;
case CONDPRINTPLAIN:
if (not Proc.read_Cp(r[0]).is_zero())
{