makeShare
Splits the original data into shares. isRecvShare is set to 1 for receiving shares of the other compute party, and is set to 0 for splitting data of a compute party itself into shares. Compute node 0 needs to receive data shares of compute node 1 and then splits the data of compute node 0 itself into shares. Correspondingly, compute node 1 splits the data of compute node 1 itself into shares, and then receives the data shares of compute node 0.
int makeShare (
DG_TeeCtx *dgTeeCtx,
int isRecvShare,
DG_TeeInput *input,
DG_MpcShare **share
)
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
dgTeeCtx |
KCAL context |
Context initialized in section initTeeCtx. |
Input |
isRecvShare |
|
0 or 1 |
Input |
input |
This is the original data. If isRecvShare is set to 0, input can be null. If isRecvShare is not set to 0, input cannot be null. |
Currently, only the double type is supported. |
Input |
share |
The type of the share result: DG_MpcShare |
It is null as a single pointer and cannot be null as a double pointer. |
Output |
Member |
Type |
Description |
|---|---|---|
data |
union |
The input strings are of type DG_String *, doubleNumbers are of type double *, and u64Numbers are of type u64 *. |
size |
int |
Data volume |
dataType |
DG_MpcDataType |
The enumerated data types are as follows:
|
Member |
Type |
Description |
|---|---|---|
dataShare |
Share |
Share structure |
size |
unsigned long |
Data volume |
shareType |
DG_ShareType |
Share type |
Member |
Description |
|---|---|
FIX_POINT |
Data is converted into the double type when revealShare is executed. |
NON_FIX_POINT |
Data is converted into the u64 type when revealShare is executed. |
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 sharing failure |
Failed to verify the parameters. Failed to share data. Failed to receive data from the other node. |
Dependency
- aritOpts depends on the KCAL function group initialized in section initTeeCtx.
- 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_TeeInput teeInput indicates the data shares.
teeInput.data.doubleNumbers = inData.get();
teeInput.size = static_cast<int>(datas.size());
teeInput.dataType = MPC_DOUBLE;
int res = aritOpts.negotiateSeeds(dgTee);
printf("exchange seed res = %d\n", res);
DG_MpcShareSet shareDat;
std::unique_ptr<DG_MpcShare[]> share = std::make_unique<DG_MpcShare[]>(2);
DG_MpcShare *share1 = nullptr;
DG_MpcShare *share2 = nullptr;
DG_TeeOutput *output = nullptr;
if (nodeId == 0) { // Compute node 0 receives the data shares of compute node 1 and then splits the data of compute node 0 itself into shares.
res = aritOpts.makeShare(dgTee, 1, nullptr, &share1); // teeInput
if (res != 0) {
printf("node 0 recv share data.[ret=%d]\n", res);
return res;
}
res = aritOpts.makeShare(dgTee, 0, teeInput, &share2);
if (res != 0) {
printf("node 0 make share self shar data fail.[ret=%d]\n", res);
return res;
}
} else { // Correspondingly, compute node 1 splits the data of compute node 1 itself into shares and then receives the data shares of compute node 0.
res = aritOpts.makeShare(dgTee, 0, teeInput, &share1);
if (res != 0) {
printf("node 1 make share self shar data fail.[ret=%d]\n", res);
return res;
}
res = aritOpts.makeShare(dgTee, 1, nullptr, &share2);
if (res != 0) {
printf("make share self shar data.[ret=%d]\n", res);
return res;
}
}
Test result: res is 0, and shares 1 and 2 are not null.
// Data shares
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_InitArithmeticOpts call.
- If either node (compute node 0 or compute node 1) returns an error code when calling an API, the node encountering the error needs to use a task scheduling mechanism to notify the other node to terminate the business process. For example, if compute node 1 returns an error code when calling the makeShare API and compute node 0 is waiting to receive shares, compute node 1 needs to notify compute node 0 to stop receiving.