我要评分
获取效率
正确性
完整性
易理解

calculateByIndex

Performs calculation using basic cryptographic operators and outputs the result index. Currently, cryptographic maximum, minimum, and sorting operations are supported.
int calculateByIndex(
    DG_TeeCtx *dgTeeCtx, 
    DG_AlgorithmsType type,
    DG_MpcShareSet *shareSet,
    DG_MpcShare **share
)
Table 1 Description

Parameter

Description

Value Range

Input/Output

dgTeeCtx

KCAL context

Context initialized in section initTeeCtx.

Input

type

Operator enumeration:

DG_AlgorithmsType

ASCEND_SORT // Ascending sort operator

DESCEND_SORT // Descending sort 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

Table 2 DG_MpcShareSet structure

Name

Type

Description

*shareSet

DG_MpcShare

Shares of each participant

size

unsigned long

Number of participants

Table 3 DG_MpcShare structure

Name

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

Table 4 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

1

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 must be the result of a successful makeShare call.
  • The dependent header file is data_guard_mpc.h.

Example

  • Call the calculateByIndex 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. Currently, only the maximum, minimum, and sorting operators are supported. Therefore, only the data on node 0 is involved in the calculation.
  • Only two-party operations are supported, with one party set to node 0 and the other to node 1.
  • The calculation uses the maximum operator as an example, and share 1 is for reference and cannot be executed.
  • Running result: The shares are not null and res is 0.
#include  "data_guard_mpc.h" 
  // Compute party
DG_AlgorithmsType type = MAX;
std::unique_ptr<DG_MpcShareSet> shares = std::make_unique<DG_MpcShareSet>();
std::unique_ptr<DG_MpcShare[]> share_datas = std::make_unique<DG_MpcShare[]>(1);
share_datas[0] = *share1;
shares->shareSet = share_datas.get();
shares->size = 1;   
DG_MpcShare *share_out = nullptr;
res = aritOpts.calculateByIndex(dgTee, type, shares.get(), &share_out);