Rate This Document
Findability
Accuracy
Completeness
Readability

clientCalculate

The client sends a query key to the server to obtain a query result.

int clientCalculate(
     DG_TeeCtx *dgTeeCtx, 
     DG_DummyMode dummyMode, 
     DG_TeeInput *input, 
     DG_TeeOutput **output
)

Parameters

Table 1 Description

Parameter

Description

Value Range

Input/Output

dgTeeCtx

KCAL context

Context initialized in section initTeeCtx

Input

dummyMode

Dummy mode of the DG_DummyMode type

Normal mode or dummy mode

Input

input

Query key

DG_TeeInput

String arrays

Input

output

Query result

DG_TeeOutput

String arrays

Output

Table 2 DG_DummyMode enumeration

Name

Description

NORMAL

Normal mode: It hides the actual content of client queries.

DUMMY

Dummy mode: It hides the actual quantity and content of client queries through dummy hiding.

Table 3 DG_TeeInput structure

Name

Type

Description

data

union

The types of the input data strings, doubleNumbers, and u64Numbers are respectively DG_String *, double *, and u64 *.

size

int

Data volume

dataType

DG_MpcDataType

The enumerated data types are as follows:

MPC_STRING (intersecting strings from PSI and PIR queries)

MPC_INT (cryptographic comparison and indices of intersecting strings from PSI)

MPC_DOUBLE (cryptographic multiplication, division, sorting, averaging, and summation)

Table 4 Data union

Name

Type

Description

strings

DG_String

String array

u64Numbers

u64

u64 array

doubleNumbers

double

Double array

Return Values

  • Success: 0 is returned.
  • Failure: The error code is returned.

Error Codes

Table 5 Error codes

Error Code

Value

Description

Remarks

DG_SUCCESS

0

Success

-

DG_FAILURE

1

Communication failure

Failed to send and receive network requests.

DG_ERR_MALLOC_FAIL

51

Memory allocation failure

-

DG_ERR_STRCPY_FAIL

54

String copy failure

-

DG_ERR_MPC_TEE_INVALID_NODE_INFO

4503

Invalid TEE node information

-

DG_ERR_MPC_TEE_INVALID_PARAM

4501

Parameter verification failure

dgCfg is null or the dgTeeCtx double pointer is null.

Dependency

  • This API depends on the KCAL configuration in section 3.1, and the configured dgCfg is used as the input parameter of this API.
  • pirOpts depends on the successful initialization in section DG_InitPirOpts of the function group for the PIR operator.
  • #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;
}
 
DG_String *strings = nullptr;
BuildDgString(dataString, &strings, size);
DG_TeeInput teeInput;
teeInput.data.strings = strings;
teeInput.size = size;
teeInput.dataType = MPC_STRING;
DG_TeeOutput* output = nullptr;
// pirOpts is the result of the successful DG_InitPirOpts call, and dgTee is the result of the successful initTeeCtx call.
int rv = pirOpts.clientCalculate(dgTee, DUMMY, &teeInput, &output);
if (rv != 0) {
      return rv;
}

Call the clientCalculate API using the pirOpts output of the successful DG_InitPirOpts call.