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

Example of DUKPT key generation.

See Note on examples.
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "dinamo.h" /* header of Dinamo */
#define HOST_ADDR "127.0.0.1"
#define USER_ID "master"
#define USER_PWD "12345678"
#define KEY_ID "Test_Key"
#define KEY_TYPE ALG_3DES_112
int main()
{
int nRet = 0;
struct AUTH_PWD authPwd;
HSESSIONCTX hSession = NULL;
HKEYCTX hKey = NULL;
BYTE pbKSI[MIN_KSI_LEN]= {0};
BYTE pbDID_CRT[MIN_CTR_LEN] = {0x00, 0x00, 0x00, 0x00, 0x01};
BYTE szBDKName[MAX_OBJ_ID] = {0};
BYTE szDUKPT[MAX_OBJ_ID] = {0};
//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");
//Gera o nome da BDK a partir de uma KSI.
DGenerateBDKName(pbKSI,(char *)&szBDKName, 0);
if(szBDKName[0] == '\0'){
printf("Function failed: DGenerateBDKName.\n");
goto clean;
}
printf("BDK name generated from KSI.\n");
//Geração da chave 3DES
nRet = DGenerateKey(hSession,(char *)&szBDKName, KEY_TYPE, TEMPORARY_KEY, &hKey);
if(nRet){
printf("Function failure: DGenerateKey \nError code: %d\n", nRet);
goto clean;
}
printf("3DES key generated successfully.\n");
//Geração do DUKPT.
nRet = DGenerateDUKPT(hSession, pbKSI, pbDID_CRT,(char *)&szDUKPT, NEW_DUKPT_MODE_TMP);
if(nRet){
printf("Function failure: DGenerateDUKPT \nError code: %d\n", nRet);
goto clean;
}
printf("DUKPT key generated successfully.\n");
clean:
if(hKey){
//Remove a chave 3DES
printf("Key successfully removed.\n");
}
if (hSession) {
DCloseSession(&hSession, 0);
printf("Session closed.\n");
}
printf("Libraries finished.\n");
return nRet;
}
HSM Application Programming Interface (API) Dinamo.
#define MAX_OBJ_ID
Definition dinamo.h:1707
void * HSESSIONCTX
Definition dinamo.h:68
#define DEFAULT_PORT
Definition dinamo.h:1948
#define TEMPORARY_KEY
Definition dinamo.h:1424
#define REMOVE_FROM_HSM
Definition dinamo.h:1462
unsigned char BYTE
Definition dinamo.h:45
#define NEW_DUKPT_MODE_TMP
Definition dinamo.h:1992
#define ENCRYPTED_CONN
Definition dinamo.h:585
#define MIN_KSI_LEN
Definition dinamo.h:1718
#define SS_USER_PWD
Definition dinamo.h:576
void * HKEYCTX
Definition dinamo.h:70
#define MIN_CTR_LEN
Definition dinamo.h:1719
void AAP_API DGenerateBDKName(BYTE *pbKSI, char *szBDKName, DWORD dwParam)
int AAP_API DGenerateDUKPT(HSESSIONCTX hSession, BYTE *pbKSI, BYTE *pbDID_CTR, char *szDUKPT, DWORD dwParam)
int AAP_API DGenerateKey(HSESSIONCTX hSession, char *szKeyId, int nAlgId, DWORD dwFlags, HKEYCTX *phKey)
int AAP_API DDestroyKey(HKEYCTX *phKey, DWORD dwFlags)
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