calculate
Performs calculation using basic operators, including cryptographic addition, subtraction, maximum, minimum, multiplication, division, averaging, summation, sorting, and comparison operators.
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 ADD // Addition operator SUB // Subtraction operator MAX // Maximum operator MIN // Minimum 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_TEE_DIV_IS_ZERO |
4512 |
Division by zero error |
- |
DG_FAILURE |
4501 |
Operator execution failure |
Failed to verify the parameters. Failed to split data into shares. Failed to receive data from the other node. |
Dependency
- dgTeeCtx depends on the successful initialization of initTeeCtx.
- The input parameter depends on the result of a successful makeShare call.
- #include "data_guard_mpc.h": required header file
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);
- 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 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.
- Two-party and three-party operations are supported. For two-party operations, one party is set to node 0 and the other is set to node 1. For three-party operations, nodes 0, 1, and 2 are used.
- The calculation uses the multiplication operator as an example, and shares 1 and 2 are for reference and cannot be executed.
- Running result: The shares are not null and res is 0.