calculate
Performs calculation using basic operators. Currently, the following calculations are supported: cryptographic multiplication, comparison, division, averaging, summation, and sorting.
int calculate(
DG_TeeCtx *dgTeeCtx,
DG_AlgorithmsType type,
DG_MpcShareSet *shareSet,
DG_MpcShare **share
)
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
dgTeeCtx |
KCAL context |
Context initialized in section initTeeCtx. |
Input |
type |
Operator enumeration: DG_AlgorithmsType |
MULTI // Multiplication operator DIV // Division operator LT // Less than operator LT_EQ // Less than or equal to operator GT // Greater than operator GT_EQ // Greater than or equal to operator EQ // Equal to operator NEQ // Not equal to operator AVG // Average operator SUM // Sum operator ASCEND_SORT // Sort ascending operator DESCEND_SORT // Sort descending operator |
Input |
shareSet |
The type of the structure after concatenating the shares: DG_MpcShareSet |
The value is not null. |
Input |
share |
The type of the calculation result: DG_MpcShare |
It is null as a single pointer and cannot be null as a double pointer. |
Output |
Member |
Type |
Description |
|---|---|---|
shareSet |
DG_MpcShare |
Shares of each participant |
size |
unsigned long |
Number of participants |
Member |
Type |
Description |
|---|---|---|
dataShare |
Share* |
Share structure |
size |
unsigned long |
Data volume |
shareType |
DG_ShareType |
Share 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 |
Invalid parameter |
- |
DG_ERR_MPC_TEE_INVALID_ALGORITHM_TYPE |
4502 |
Invalid algorithm type |
- |
DG_ERR_MALLOC_FAIL |
51 |
Memory allocation failure |
- |
DG_ERR_MPC_DIVISION_BY_ZERO |
4020 |
Division by zero error |
- |
DG_FAILURE |
4501 |
Operator execution failure |
Failed to verify the parameters. Failed to share data. Failed to receive data from the other node. |
Dependency
- Call the calculate API using the dgTeeCtx output from the successful initTeeCtx call.
- The share output indicates the data share of a single party. You need to call the makeShare API multiple times and concatenate the DG_MpcShare data from both parties into the DG_MpcShareSet. The concatenation order is crucial. For example, after compute node 0 acquires share a, it calls the less-than operator to confirm that a < b (a originates from compute node 1 and b from compute node 0), and then places share a at bit 0 and share b at bit 1 in DG_MpcShareSet.
- The basic operations involve two parties.
Example
#include "data_guard_mpc.h" // Compute party DG_AlgorithmsType type = MULTI; std::unique_ptr<DG_MpcShareSet> shares = std::make_unique<DG_MpcShareSet>(); std::unique_ptr<DG_MpcShare[]> share_datas = std::make_unique<DG_MpcShare[]>(2); share_datas[0] = *share2; share_datas[1] = *share1; shares->shareSet = share_datas.get(); shares->size = 2; DG_MpcShare *share_out = nullptr; res = aritOpts.calculate(dgTee, type, shares.get(), &share_out);
The calculation is based on the multiplication operator. In the example, shares 1 and 2 serve as examples for reference but cannot be executed.
Running result: The shares are not null and res is 0.