C/C++ API
HSM Dinamo
Loading...
Looking for...
No entries found
m_of_n.c

Example of M of N.

See Note on examples.
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <dinamo.h> /* header do Dinamo */
#define HOST_ADDR "127.0.0.1"
int main()
{
int nRet = 0;
struct AUTH_PWD authPwd;
HSESSIONCTX hSession = NULL;
DN_M_OF_N_SPLIT_INFO stSplitInfo = {};
BYTE secret[DN_M_OF_N_S_LEN] = {};
//Inicializa as bibliotecas do Dinamo
nRet = DInitialize(0);
if (nRet){
printf("Function failure: DInitialize \nError code: %d\n", nRet);
goto clean;
}
printf("Libraries initialized.\n");
/*
Initializes the structure for connecting to the HSM using a
anonymous session.
*/
strncpy(authPwd. szAddr, HOST_ADDR, sizeof(authPwd.szAddr));
authPwd. nPort = DEFAULT_PORT;
nRet = DOpenSession(&hSession, SS_ANONYMOUS,(BYTE *)&authPwd, sizeof(authPwd), ENCRYPTED_CONN);
if (nRet){
printf("Function failure: DOpenSession \nError code: %d\n", nRet);
goto clean;
}
printf("Session with Dinamo established.\n");
/*
It divides the secret into an M of N scheme, where there is a set of
6 parts and 2 parts are needed to rebuild the secret.
In this case, as NULL was passed in the secret parameter, the secret is
randomly generated within the HSM.
*/
nRet = DMofNSplit(hSession, 2, 6, NULL, 0, &stSplitInfo, 0);
if (nRet)
{
printf("\nFunction failure: DMofNSplit\nError code: %d\n\n", nRet);
goto clean;
}
printf("Secret of M from N split successfully.\n");
nRet = DMofNRecover(hSession, stSplitInfo. pstParts, stSplitInfo. dwPartCount, secret, 0);
if (nRet)
{
printf("\nFunction failure: DMofNRecover\nError code: %d\n\n", nRet);
goto clean;
}
printf("Secret of M of N successfully retrieved.\n");
clean:
if (hSession) {
DCloseSession(&hSession, 0);
printf("Session closed.\n");
}
printf("Libraries finished.\n");
return nRet;
}
HSM Application Programming Interface (API) Dinamo.
void * HSESSIONCTX
Definition dinamo.h:68
#define DEFAULT_PORT
Definition dinamo.h:1948
unsigned char BYTE
Definition dinamo.h:45
#define SS_ANONYMOUS
Definition dinamo.h:575
#define DN_M_OF_N_S_LEN
Definition dinamo.h:3536
#define ENCRYPTED_CONN
Definition dinamo.h:585
int AAP_API DMofNRecover(HSESSIONCTX hSession, DN_M_OF_N_PART *pstParts, DWORD dwPartsCount, BYTE *pbSecret, DWORD dwReserved)
int AAP_API DMofNSplit(HSESSIONCTX hSession, BYTE bM, BYTE bN, BYTE *pbSecret, DWORD dwSecretLen, DN_M_OF_N_SPLIT_INFO *pstSplitInfo, DWORD dwReserved)
int AAP_API DOpenSession(HSESSIONCTX *phSession, DWORD dwParam, BYTE *pbData, DWORD dwDataLen, DWORD dwFlags)
int AAP_API DCloseSession(HSESSIONCTX *phSession, DWORD dwFlags)
int AAP_API DInitialize(DWORD dwReserved)
int AAP_API DFinalize()
Definition dinamo.h:3089
int nPort
Definition dinamo.h:3091
char szAddr[MAX_ADDR_LEN]
Definition dinamo.h:3090
Definition dinamo.h:3565
DWORD dwPartCount
Definition dinamo.h:3569
DN_M_OF_N_PART pstParts[DN_M_OF_N_S_MAX]
Definition dinamo.h:3568