Rate This Document
Findability
Accuracy
Completeness
Readability

makeShare

This function is called to split the original data of node 0 (compute party) and node 1 (non-compute party) into shares. When node 0 calls this function, it sets isRecvShare to 1 to receive the shares sent by node 1, and then sets isRecvShare to 0 to split its own data into shares. When the non-compute party calls this function, it sets isRecvShare to 0 to split its own data into shares and then sends the shares to the compute party.

int makeShare(
    DG_TeeCtx *dgTeeCtx,
    int isRecvShare,
    DG_TeeMatInput *input,
    DG_MpcMatShare **share 
)

Parameters

Parameter

Description

Value Range

Input/Output

dgTeeCtx

KCAL context

Context initialized in section initTeeCtx.

Input

isRecvShare

0: Splits the original data of a node itself into shares.

1: Receives data shares of the other node.

0 or 1.

Input

input

This is the original data. Only when isRecvShare is set to 0, input can be null.

Currently, only the double type is supported.

Input

share

The type of the matrix share result:

DG_MpcMatShare

It is null as a single pointer and cannot be null as a double pointer.

Output

Table 1 DG_TeeMatInput structure

Member

Type

Description

data

DG_MpcDataUnion

The types of the input data strings, doubleNumbers, and u64Numbers are respectively DG_String *, double *, and u64 *.

row

uint32_t

Number of rows in a matrix

col

uint32_t

Number of columns in a matrix

dataType

DG_MpcDataType

The enumerated data type is as follows:

MPC_DOUBLE (cryptographic matrix addition, subtraction, and multiplication)

Table 2 DG_MpcDataUnion

Member

Type

Description

strings

DG_String

String array

u64Numbers

u64

u64 array

doubleNumbers

double

Double array

Table 3 DG_MpcMatShare structure

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

ShareType
enum DG_ShareType {
    FIX_POINT, // Fixed-point number
    NON_FIX_POINT // Non-fixed-point number
};
Table 4 Share structure

Member

Type

Description

shares

u64*

Multiple shares corresponding to one piece of plaintext data

size

u64

The number of shares

Return Values

  • Success: 0 is returned.
  • Failure: The error code is returned.

Error Codes

Error Code

Value

Description

Remarks

DG_FAILURE

4501

Data share splitting failure

Failed to verify the parameters.

Failed to split data into shares.

Failed to receive data from the other node.

Dependency

  • aritOpts depends on the successful initialization in section DG_InitMatrixOpts of the function group for matrix arithmetic operators.
  • You need to call the negotiateSeeds API to distribute seeds to all nodes.
  • #include "data_guard_mpc.h": required header file

Example

#include  "data_guard_mpc.h"
std::unique_ptr<double[]> inData = std::make_unique<double[]>(datas.size());
for (int i = 0; i < datas.size(); i++) {
    inData[i] = (std::stod(datas[i].c_str())) * 1.0;
}
// DG_TeeMatInput teeInput indicates the data shares from the compute party.
teeInput.data.doubleNumbers = inData.get();
teeInput.row = row; // Assume that the number of rows in the matrix is row.
teeInput.col = col; // Assume that the number of columns in the matrix is col.
teeInput.dataType = MPC_DOUBLE;
printf("++++++++++input data size:%lu\n", teeInput.size);
int res = aritOpts.negotiateSeeds(dgTee);
printf("exchange seed res = %d\n", res);
DG_MpcMatShareSet shareDat;
std::unique_ptr<DG_MpcMatShare[]> share = std::make_unique<DG_MpcMatShare[]>(2);
DG_MpcMatShare *share1 = nullptr;
DG_MpcMatShare *share2 = nullptr;
DG_TeeMatOutput *output = nullptr;
if (nodeId == 0) {
res = aritOpts.makeShare(dgTee, 1, nullptr, &share1);  // &teeInput

Note: The example is for reference only. It describes how to read data from a file for testing and cannot be executed.

Test result: res is 0 and the shares are not null.

  • Call the makeShare API using the aritOpts output of the successful DG_InitMatrixOpts call.
  • If either node (node 0 or 1) returns an error code when calling an API, the node needs to use a task scheduling mechanism to notify the other node to terminate the service process. For example, if node 1 returns an error code when calling the makeShare API and node 0 is waiting to receive shares, node 1 needs to notify node 0 to stop receiving.