Example of signature and hash verification. Includes hash operations and public key recovery from the signature.
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#define HOST_ADDR "127.0.0.1"
#define USER_ID "master"
#define USER_PWD "12345678"
int main()
{
int nRet = 0;
char szId[] = "Chave_Teste";
DWORD dwHashLen =
sizeof(pbHash);
DWORD dwSigLen =
sizeof(pbSig);
if (nRet){
printf("Falha na funcao: DInitialize \nCodigo de erro: %d\n", nRet);
goto clean;
}
printf("Bibliotecas inicializadas.\n");
if (nRet){
printf("Falha na funcao: DOpenSession \nCodigo de erro: %d\n", nRet);
goto clean;
}
printf("Sessao com o Dinamo estabelecida.\n");
szId,
&ver,
sizeof(ver),
0);
if(nRet){
printf("Falha na funcao: DBchainCreateXPrv \nCodigo de erro: %d\n", nRet);
goto clean;
}
printf("Chave Bip 32 criada com sucesso.\n");
pbData,
sizeof(pbData),
pbHash,
&dwHashLen,
0);
if (nRet)
{
printf("Falha na funcao: DBchainHashData \nCodigo de erro: %d\n", nRet);
goto clean;
}
printf("Hash gerado com sucesso.\n");
pbHash,
dwHashLen,
szId,
pbSig,
&dwSigLen,
0);
if(nRet){
printf("Falha na funcao: DBchainSignHash \nCodigo de erro: %d\n", nRet);
goto clean;
}
printf("Hash assinado com sucesso.\n");
pbHash,
dwHashLen,
pbSig,
dwSigLen,
&pPbk,
0);
if (nRet)
{
printf("Falha na funcao: DBchainRecoverPbkFromSignature \nCodigo de erro: %d\n", nRet);
goto clean;
}
printf("Chave publica recuperada da assinatura com sucesso.\n");
pbHash,
dwHashLen,
pbSig,
dwSigLen,
0);
if (nRet)
{
printf("Falha na funcao: DBchainVerify \nCodigo de erro: %d\n", nRet);
goto clean;
}
printf("Assinatura verificada com sucesso.\n");
clean:
if(nRet){
printf("Falha na funcao: DRemoveObj \nCodigo de erro: %d\n", nRet);
goto clean;
}
printf("Chave Bchain removida do HSM.\n");
if (hSession) {
printf("Sessao encerrada.\n");
}
printf("Bibliotecas finalizadas.\n");
return nRet;
}
Application Programming Interface (API) do HSM Dinamo.
void * HSESSIONCTX
Definição dinamo.h:68
#define DEFAULT_PORT
Definição dinamo.h:1949
#define DN_BCHAIN_HASH_KECCAK256_LEN
Definição dinamo.h:2189
unsigned char BYTE
Definição dinamo.h:45
#define DN_BCHAIN_HASH_KECCAK256
Definição dinamo.h:2182
#define DN_BCHAIN_SIG_RAW_ECDSA
Definição dinamo.h:2164
unsigned int DWORD
Definição dinamo.h:46
#define ENCRYPTED_CONN
Definição dinamo.h:585
#define SS_USER_PWD
Definição dinamo.h:576
#define DN_BCHAIN_MAX_SIG_LEN
Definição dinamo.h:2160
#define BCHAIN_KEY
Definição dinamo.h:1430
#define DN_BCHAIN_VER_BIP32_TESTNET
Definição dinamo.h:3475
#define DN_BCHAIN_BIP32_XPRV
Definição dinamo.h:3470
int AAP_API DBchainHashData(HSESSIONCTX hSession, BYTE bMode, BYTE *pbData, DWORD dwDataLen, BYTE *pbHash, DWORD *pdwHashLen, DWORD dwReserved)
int AAP_API DBchainSignHash(HSESSIONCTX hSession, BYTE bType, BYTE bHashMode, BYTE *pbHash, DWORD dwHashLen, const char *cszPk, BYTE *pbSig, DWORD *pdwSigLen, 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 DBchainRecoverPbkFromSignature(HSESSIONCTX hSession, BYTE bSigType, BYTE bHashMode, const BYTE *pbHash, DWORD dwHashLen, const BYTE *pbSig, DWORD dwSigLen, DN_BCHAIN_PBK *pPbk, DWORD dwReserved)
int AAP_API DBchainVerify(HSESSIONCTX hSession, BYTE bSigType, BYTE bHashMode, const BYTE *pbHash, DWORD dwHashLen, const BYTE *pbSig, DWORD dwSigLen, BYTE bInPbkType, const BYTE *pbInPbk, BYTE bInPbkLen, 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 nPort
Definição dinamo.h:3092
char szUserId[MAX_USR_LEN]
Definição dinamo.h:3093
char szAddr[MAX_ADDR_LEN]
Definição dinamo.h:3091
char szPassword[MAX_USR_PWD]
Definição dinamo.h:3094
BYTE bLen
Definição dinamo.h:3529
BYTE pbPbk[DN_BCHAIN_MAX_PBK_LEN]
Definição dinamo.h:3530
BYTE bType
Definição dinamo.h:3528