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

Example of PIN block verification .

Example of PIN block verification .

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"
#define USER_ID "master"
#define USER_PWD "12345678"
#define PGK_KEY_TYPE ALG_3DES_168
#define PTK_KEY_TYPE ALG_3DES_112
int main()
{
int nRet = 0;
struct AUTH_PWD authPwd;
HSESSIONCTX hSession = NULL;
HKEYCTX hPgkKey = NULL;
HKEYCTX hPtkKey = NULL;
BYTE pbPgkKeyData[] = {0x12, 0x22, 0x22, 0x22, 0x22, 0x22, 0x23,
0x12, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x23,
0x12, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x23};
BYTE pbPtkKeyData[] = {0xF2, 0x15, 0x75, 0xBA, 0x54, 0x68, 0xC4, 0x1C,
0xD5, 0xC7, 0x4A, 0xFE, 0x64, 0x94, 0x08, 0x37};
BYTE pbPinBlock[] = {0x19, 0x37, 0x35, 0x9B, 0x46, 0x93, 0x2D, 0x3C};
char szPgk[] = "pgk";
char szPtk[] = "ptk";
char szPan[] = "4987654321098765";
char szOffset[] = "3152";
// 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");
// Importa chave PGK (PIN Generation Key)
nRet = DImportKey(hSession, szPgk, NULL, PLAINTEXTKEY_BLOB, PGK_KEY_TYPE,
TEMPORARY_KEY, pbPgkKeyData, sizeof(pbPgkKeyData), &hPgkKey);
if(nRet){
printf("Function failure: DImportKey\nError code: %d\n", nRet);
goto clean;
}
printf("PGK key imported successfully!\n");
/*
* The key context can be released now. We will only need
* key name from now on.
*/
DDestroyKey(&hPgkKey, 0);
// Importa chave PTK (PIN Transport Key)
nRet = DImportKey(hSession, szPtk, NULL, PLAINTEXTKEY_BLOB, PTK_KEY_TYPE,
TEMPORARY_KEY, pbPtkKeyData, sizeof(pbPtkKeyData), &hPtkKey);
if (nRet)
{
printf("Function failure: DImportKey\nError code: %d\n", nRet);
goto clean;
}
printf("PTK key imported successfully!\n");
/*
* The key context can be released now. We will only need
* key name from now on.
*/
DDestroyKey(&hPtkKey, 0);
// Verifica o PIN block
nRet = DVerifyPINBlock(hSession, szPtk, szPgk, szPan, szOffset, pbPinBlock, 0);
if(nRet){
printf("Function failure: DVerifyPINBlock\nError code: %d\n", nRet);
goto clean;
}
printf("PIN block successfully verified!\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 TEMPORARY_KEY
Definition dinamo.h:1424
unsigned char BYTE
Definition dinamo.h:45
#define ENCRYPTED_CONN
Definition dinamo.h:585
#define SS_USER_PWD
Definition dinamo.h:576
void * HKEYCTX
Definition dinamo.h:70
#define PLAINTEXTKEY_BLOB
Definition dinamo.h:1381
int AAP_API DVerifyPINBlock(HSESSIONCTX hSession, char *szPTK, char *szPGK, char *szPAN, char *szOffset, BYTE *pbInPinBlock, DWORD dwParam)
int AAP_API DDestroyKey(HKEYCTX *phKey, DWORD dwFlags)
int AAP_API DImportKey(HSESSIONCTX hSession, char *szKeyId, HKEYCTX hKEKey, DWORD dwBlobType, int nAlgId, DWORD dwFlags, BYTE *pbData, DWORD dwDataLen, HKEYCTX *phKey)
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