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

calculateByFile

Performs file calculation using basic operators, including cryptographic addition, subtraction, maximum, minimum, multiplication, division, averaging, summation, sorting, and comparison operators.
int calculateByFile(
    DG_TeeCtx *dgTeeCtx, 
    DG_AlgorithmsType type, 
    DG_MpcFileInputSet *input,
    DG_MpcFileOutput *output
)

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 // Ascending sort operator

DESCEND_SORT // Descending sort operator

ADD // Addition operator

SUB // Subtraction operator

MAX // Maximum operator

MIN // Minimum operator

MATRIX_ADD // Matrix addition operator

MATRIX_SUB // Matrix subtraction operator

MATRIX_MUL // Matrix multiplication operator

Input

input

The type of the structure after concatenating the file data:

DG_MpcFileInputSet

The value is not null.

Input

output

The type of the calculation result:

DG_MpcFileOutput

The value is not null.

Output

Table 1 DG_MpcFileInputSet structure

Name

Type

Description

shareInputSet

DG_MpcFileInput*

File shares of each participant

size

unsigned long

Number of participants

Table 2 DG_MpcFileInput structure

Name

Type

Description

filePath

char*

File path

pathLen

uint32_t

Path length

dataSize

uint64_t

Data size

Table 3 DG_MpcFileOutput structure

Name

Type

Description

filePath

char*

File path

pathLen

uint32_t

Path length

dataSize

uint64_t

Data size

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

This function depends on the result from revealShareByFile.

Example

  • Call the calculateByFile API using the dgTeeCtx output from the successful initTeeCtx call.
  • The share result obtained through share generation belongs to a single data party. You need to call makeShareByFile to output file shares of all parties.
  • For basic operations, the participating nodes are classified into compute and non-compute nodes. The assignment rules are as follows: node 0 serves as the compute node and node 1 as the non-compute node; and in three-party settings, node 0 remains the compute node, while nodes 1 and 2 are designated as non-compute nodes.
#include  "data_guard_mpc.h" 
 // Compute party
std::vector<DG_MpcFileInput> inputs(inputFilePaths.size());
for (size_t i = 0; i < inputFilePaths.size(); ++i) {
    inputs[i].filePath = const_cast<char *>(inputFilePaths[i].c_str());
    inputs[i].pathLen = static_cast<uint32_t>(inputFilePaths[i].length());
}
DG_MpcFileInputSet inputSet;
inputSet.shareInputSet = inputs.data();
inputSet.size = static_cast<uint32_t>(inputFilePaths.size());
DG_MpcFileOutput teeFileOutput;
teeFileOutput.filePath = const_cast<char *>(outputFilePath.c_str());
teeFileOutput.pathLen = static_cast<uint32_t>(outputFilePath.length());
int ret = opts_->calculateByFile(dgTeeCtx_, ADD, &inputSet, &teeFileOutput);