caculate
Performs calculation using basic operators, including cryptographic matrix addition, subtraction, and multiplication operators.
int calculate(
DG_TeeCtx *dgTeeCtx,
DG_AlgorithmsType type,
DG_MpcMatShareSet *shareSet,
DG_MpcMatShare **share
)
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
dgTeeCtx |
KCAL context |
Context initialized in section initTeeCtx. |
Input |
type |
Operator enumeration: DG_AlgorithmsType |
MATRIX_ADD: matrix addition MATRIX_SUB: matrix subtraction MATRIX_MUL: matrix multiplication |
Input |
shareSet |
The type of the structure after concatenating the shares: DG_MpcMatShareSet |
The value is not null. |
Input |
share |
The type of the calculation result: DG_MpcMatShare |
It is null as a single pointer and cannot be null as a double pointer. |
Output |
Member |
Type |
Description |
|---|---|---|
shareSet |
DG_MpcMatShare |
Shares of each participant |
size |
unsigned long |
Number of participants |
Member |
Type |
Description |
|---|---|---|
dataShare |
Share* |
Share structure |
row |
unsigned long |
Number of rows in a matrix |
col |
unsigned long |
Number of columns in a matrix |
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 = MATRIX_MUL; std::unique_ptr<DG_MpcMatShareSet> shares = std::make_unique<DG_MpcMatShareSet>(); std::unique_ptr<DG_MpcMatShare[]> share_datas = std::make_unique<DG_MpcMatShare[]>(2); share_datas[0] = *share2; share_datas[1] = *share1; shares->shareSet = share_datas.get(); shares->row = 2; shares->col = 2; DG_MpcMatShare *share_out = nullptr; res = aritOpts.calculate(dgTee, type, shares.get(), &share_out);
Note: The calculation uses the matrix 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.
- 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_MpcMatShare data from both parties into DG_MpcMatShareSet. The concatenation order is crucial. For example, after compute node 0 acquires share a, it calls the matrix multiplication operator to calculate matrix a multiplying matrix 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_MpcMatShareSet.
- Only two-party operations are supported, with one party set to node 0 and the other to node 1.