Add the INVPERM instruction

The IVMPERM instruction takes in a secret shared vector representing a permutation, and returns the corresponding secret shared inverse permutation.
This commit is contained in:
Kevin Witlox
2022-07-26 14:07:35 +02:00
parent 3f90cc3e7c
commit f469dfc473
9 changed files with 216 additions and 30 deletions

View File

@@ -113,6 +113,7 @@ enum
GENSECSHUFFLE = 0xFB,
APPLYSHUFFLE = 0xFC,
DELSHUFFLE = 0xFD,
INVPERM = 0xFE,
// Data access
TRIPLE = 0x50,
BIT = 0x51,

View File

@@ -283,6 +283,10 @@ void BaseInstruction::parse_operands(istream& s, int pos, int file_pos)
n = get_int(s);
get_vector(2, start, s);
break;
// instructions with 2 register operands
case INVPERM:
get_vector(2, start, s);
break;
// open instructions + read/write instructions with variable length args
case OPEN:
case GOPEN:
@@ -1076,6 +1080,9 @@ inline void Instruction::execute(Processor<sint, sgf2n>& Proc) const
case DELSHUFFLE:
Proc.Procp.delete_shuffle(Proc.read_Ci(r[0]));
return;
case INVPERM:
Proc.Procp.inverse_permutation(*this);
return;
case CHECK:
{
CheckJob job;

View File

@@ -77,6 +77,7 @@ public:
size_t generate_secure_shuffle(const Instruction& instruction);
void apply_shuffle(const Instruction& instruction, int handle);
void delete_shuffle(int handle);
void inverse_permutation(const Instruction& instruction);
void input_personal(const vector<int>& args);
void send_personal(const vector<int>& args);
@@ -101,6 +102,8 @@ public:
{
return C[i];
}
void inverse_permutation(const Instruction &instruction, int handle);
};
class ArithmeticProcessor : public ProcessorBase

View File

@@ -668,6 +668,12 @@ void SubProcessor<T>::delete_shuffle(int handle)
shuffler.del(handle);
}
template<class T>
void SubProcessor<T>::inverse_permutation(const Instruction& instruction) {
shuffler.inverse_permutation(S, instruction.get_size(), instruction.get_start()[0],
instruction.get_start()[1]);
}
template<class T>
void SubProcessor<T>::input_personal(const vector<int>& args)
{
@@ -686,6 +692,16 @@ void SubProcessor<T>::input_personal(const vector<int>& args)
S[args[i + 2] + j] = input.finalize(args[i + 1]);
}
/**
*
* @tparam T
* @param args Args contains four arguments
* a[0] = the size of the input (and output) vector
* a[1] = the player to which to reveal the output
* a[2] = the memory address of the input vector (sint) (i.e. the value to reveal)
* a[3] = the memory address of the output vector (cint) (i.e. the register to store the revealed value)
* // TODO: When would there be multiple sets of arguments? (for ... i < args.size(); i += 4 ... )
*/
template<class T>
void SubProcessor<T>::private_output(const vector<int>& args)
{