From c8222f14f6824e3253c7b816e268f14b551e3cfa Mon Sep 17 00:00:00 2001 From: Marcel Keller Date: Thu, 15 Feb 2024 11:24:37 +1100 Subject: [PATCH] Implement output of GF(2^n) shares. --- Compiler/instructions.py | 1 + Compiler/library.py | 4 ++-- Compiler/types.py | 8 ++++---- Processor/Instruction.h | 1 + Processor/Instruction.hpp | 4 ++++ 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Compiler/instructions.py b/Compiler/instructions.py index f97d8412..9e7b23e7 100644 --- a/Compiler/instructions.py +++ b/Compiler/instructions.py @@ -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. diff --git a/Compiler/library.py b/Compiler/library.py index 270460f9..ff66f369 100644 --- a/Compiler/library.py +++ b/Compiler/library.py @@ -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( diff --git a/Compiler/types.py b/Compiler/types.py index 31f4fa3a..76623307 100644 --- a/Compiler/types.py +++ b/Compiler/types.py @@ -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 (``&, |, ^``). """ diff --git a/Processor/Instruction.h b/Processor/Instruction.h index 0121b6d1..265f18a2 100644 --- a/Processor/Instruction.h +++ b/Processor/Instruction.h @@ -303,6 +303,7 @@ enum GPRINTMEM = 0x1B0, GPRINTREG = 0X1B1, GPRINTREGPLAIN = 0x1B3, + GPRINTREGPLAINS = 0x1EA, GRAWOUTPUT = 0x1B7, GSTARTPRIVATEOUTPUT = 0x1B8, GSTOPPRIVATEOUTPUT = 0x1B9, diff --git a/Processor/Instruction.hpp b/Processor/Instruction.hpp index c91cf631..ef21e372 100644 --- a/Processor/Instruction.hpp +++ b/Processor/Instruction.hpp @@ -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& 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()) {