calculate
Calls the PSI operator to implement the two-party or three-party PSI feature. This function currently supports string datasets as input from multiple parties, and returns either intersecting string data or the indices of the intersecting string data.
int calculate (
DG_TeeCtx *dgTeeCtx,
DG_AlgorithmsType type,
DG_TeeInput *input,
DG_TeeOutput **output,
DG_TeeMode outputMode
)
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
dgTeeCtx |
KCAL context |
Context initialized in section initTeeCtx. |
Input |
type |
Operator type DG_AlgorithmsType |
PSI or PSU. |
Input |
input |
Input data DG_TeeInput |
String arrays are supported. |
Input |
outputMode |
Output mode DG_TeeMode |
The enumerated type is TEE_OUTPUT_STRING or TEE_OUTPUT_INDEX. |
Input |
output |
Operator calculation result |
It is null as a single pointer and cannot be null as a double pointer. |
Output |
Name |
Type |
Description |
|---|---|---|
data |
DG_MpcDataUnion |
The types of the input data strings, doubleNumbers, and u64Numbers are respectively DG_String *, double *, and u64 *. |
size |
uint64_t |
Data volume |
dataType |
DG_MpcDataType |
The enumerated data types are as follows:
|
Name |
Type |
Description |
|---|---|---|
strings |
DG_String |
String array |
u64Numbers |
u64 |
u64 array |
doubleNumbers |
double |
Double array |
The DG_TeeOutput structure and the DG_TeeInput structure are of the same type.
Return Values
- Success: 0 is returned.
- Failure: The error code is returned.
Error Codes
Error Code |
Value |
Description |
Remarks |
|---|---|---|---|
DG_ERR_MPC_TEE_INVALID_PARAM |
4501 |
Parameter verification failure |
dgTeeCtx is null, the output double pointer is null, or the communication callback is not registered. The input is null, the size is less than 0, or the input string is null. |
DG_ERR_MPC_TEE_INVALID_NODE_INFO |
4503 |
Invalid node information |
The node IDs must be numbered from 0 and increment sequentially. |
DG_FAILURE |
1 |
Calculation failure |
Failed to perform hashing. Failed to swap buckets. Failed to obtain the intersection. |
Dependency
- teeOpts depends on the successful initialization in section DG_InitPsiOpts of the KCAL function group.
- Before executing the PSI operator, you need to call the setTeeNodeInfos API to set the information about all nodes.
- #include "data_guard_mpc.h": required header file
Example
#include "data_guard_mpc.h"
void BuildDgString(std::vector<std::string> &strings, DG_String **dg, unsigned int &size)
{
size = strings.size();
DG_String *dgString = new DG_String[strings.size()];
for (size_t i = 0; i < strings.size(); i++) {
dgString[i].str = strdup(strings[i].c_str());
dgString[i].size = strings[i].size() + 1;
}
*dg = dgString;
}
std::vector<std::string> datas = {"hello", "world"};
unsigned int size;
DG_String *strings = nullptr;
BuildDgString(datas, &strings, size);
DG_TeeInput teeInput;
teeInput.data.strings = strings;
teeInput.size = size;
teeInput.dataType = MPC_STRING;
struct DG_TeeOutput *output = nullptr;
// teeOpts is the result of the successful DG_InitPsiOpts call, and dgTee is the result of the successful initTeeCtx call.
int res = teeOpts.calculate(dgTee, PSI, &teeInput, &output, TEE_OUTPUT_STRING);
Running result: res is 0 and output is not null.
Call the calculate API using the teeOpts output of the successful DG_InitPsiOpts call.