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

Example of a Child Key Derivation (CKD) operation.

See Note on examples.
//#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dinamo.h" /* header of Dinamo */
#define HOST_ADDR "127.0.0.1"
#define USER_ID "master"
#define USER_PWD "12345678"
int main()
{
int nRet = 0;
struct AUTH_PWD authPwd;
HSESSIONCTX hSession = NULL;
char szId[] = "Test_Key";
char szDest[MAX_OBJ_ID_FQN_LEN] = "Child_Key";
DN_BCHAIN_KEY_INFO pbKeyInfo;
BYTE pbAddress[DN_BCHAIN_MAX_ADDR_LEN] = {0};
DWORD pdwAddressLen = sizeof(pbAddress);
//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");
//Inicializa a estrutura para conexao com o HSM
strncpy(authPwd. szAddr, HOST_ADDR, sizeof(authPwd.szAddr));
authPwd. nPort = DEFAULT_PORT;
strncpy(authPwd. szUserId, USER_ID, sizeof(authPwd.szUserId));
strncpy(authPwd. szPassword, USER_PWD, sizeof(authPwd.szPassword));
nRet = DOpenSession(&hSession, SS_USER_PWD,(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");
//Criacao da chave BIP32.
nRet = DBchainCreateXPrv(hSession,
szId,
&ver,
sizeof(see),
0);
if(nRet){
printf("Function failed: DBchainCreateXPrv \nError code: %d\n", nRet);
goto clean;
}
printf("Bip 32 key created successfully.\n");
//Operação de Child Key Derivation.
nRet = DBchainCreateBip32Ckd(hSession,
see,
szId,
szDest,
&pbKeyInfo,
0);
if(nRet){
printf("Function failed: DBchainCreateBip32Ckd \nError code: %d\n", nRet);
goto clean;
}
printf("Child Key Derivation done successfully.\n");
//Recupera o endereço da chave criada.
nRet = DBchainGetAddress(hSession,
szId,
pbAddress,
&pdwAddressLen,
0);
if(nRet){
printf("Function failure: DBchainGetAddress \nError code: %d\n", nRet);
goto clean;
}
printf("Bchain key address retrieved successfully.\n");
//Remoção da chave.
nRet = DRemoveObj(hSession, szId);
if(nRet){
printf("Function failed: DRemoveObj \nError code: %d\n", nRet);
goto clean;
}
printf("Bchain key removed from HSM.\n");
//Remoção da Child Key.
nRet = DRemoveObj(hSession, szDest);
if(nRet){
printf("Function failed: DRemoveObj \nError code: %d\n", nRet);
goto clean;
}
printf("Child Key removed from HSM.\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
#define DN_BCHAIN_VER_BTC_B32_WITVER
Definition dinamo.h:2147
#define DN_BCHAIN_SECURE_BIP32_INDEX_BASE
Definition dinamo.h:2121
unsigned char BYTE
Definition dinamo.h:45
unsigned int DWORD
Definition dinamo.h:46
#define ENCRYPTED_CONN
Definition dinamo.h:585
#define DN_BCHAIN_HRP_BTC_TEST_NET
Definition dinamo.h:2155
#define SS_USER_PWD
Definition dinamo.h:576
#define BCHAIN_KEY
Definition dinamo.h:1429
#define MAX_OBJ_ID_FQN_LEN
Definition dinamo.h:1713
#define DN_BCHAIN_VER_BIP32_TESTNET
Definition dinamo.h:3474
#define DN_BCHAIN_MAX_ADDR_LEN
Definition dinamo.h:2125
#define DN_BCHAIN_BIP32_XPRV
Definition dinamo.h:3469
#define DN_BCHAIN_AT_BTC_B32_PKH
Definition dinamo.h:2131
int AAP_API DBchainGetAddress(HSESSIONCTX hSession, BYTE bType, BYTE bVer, const char *cszHrp, const char *cszPk, BYTE *pbAddress, DWORD *pdwAddressLen, DWORD dwReserved)
int AAP_API DBchainCreateXPrv(HSESSIONCTX hSession, BYTE bType, DWORD dwAttributes, const char *szId, const BYTE *pcbData, DWORD dwDataLen, DWORD dwReserved)
int AAP_API DBchainCreateBip32Ckd(HSESSIONCTX hSession, BYTE bVersion, DWORD dwIndex, DWORD dwAttributes, const char *cszPar, const char *cszDst, DN_BCHAIN_KEY_INFO *pKeyInfo, DWORD dwReserved)
int AAP_API DRemoveObj(HSESSIONCTX hSession, char *szObjId)
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 szUserId[MAX_USR_LEN]
Definition dinamo.h:3092
char szAddr[MAX_ADDR_LEN]
Definition dinamo.h:3090
char szPassword[MAX_USR_PWD]
Definition dinamo.h:3093
Definition dinamo.h:3511