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[] = "Test_Key";
DWORD dwHashLen =
sizeof(pbHash);
DWORD dwSigLen =
sizeof(pbSig);
if (nRet){
printf("Function failure: DInitialize \nError code: %d\n", nRet);
goto clean;
}
printf("Libraries initialized.\n");
strncpy(authPwd.
szAddr, HOST_ADDR,
sizeof(authPwd
.szAddr));
strncpy(authPwd.
szUserId, USER_ID,
sizeof(authPwd
.szUserId));
strncpy(authPwd.
szPassword, USER_PWD,
sizeof(authPwd
.szPassword));
if (nRet){
printf("Function failure: DOpenSession \nError code: %d\n", nRet);
goto clean;
}
printf("Session with Dinamo established.\n");
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");
pbData,
sizeof(pbData),
pbHash,
&dwHashLen,
0);
if (nRet)
{
printf("Function failed: DBchainHashData \nError code: %d\n", nRet);
goto clean;
}
printf("Hash generated successfully.\n");
pbHash,
dwHashLen,
szId,
pbSig,
&dwSigLen,
0);
if(nRet){
printf("Function failure: DBchainSignHash \nError code: %d\n", nRet);
goto clean;
}
printf("Hash signed successfully.\n");
pbHash,
dwHashLen,
pbSig,
dwSigLen,
&pPbk,
0);
if (nRet)
{
printf("Function failed: DBchainRecoverPbkFromSignature \nError code: %d\n", nRet);
goto clean;
}
printf("Public key successfully retrieved from signature.\n");
pbHash,
dwHashLen,
pbSig,
dwSigLen,
0);
if (nRet)
{
printf("Function failure: DBchainVerify \nError code: %d\n", nRet);
goto clean;
}
printf("Signature successfully verified.\n");
clean:
if(nRet){
printf("Function failed: DRemoveObj \nError code: %d\n", nRet);
goto clean;
}
printf("Bchain key removed from HSM.\n");
if (hSession) {
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_HASH_KECCAK256_LEN
Definition dinamo.h:2188
unsigned char BYTE
Definition dinamo.h:45
#define DN_BCHAIN_HASH_KECCAK256
Definition dinamo.h:2181
#define DN_BCHAIN_SIG_RAW_ECDSA
Definition dinamo.h:2163
unsigned int DWORD
Definition dinamo.h:46
#define ENCRYPTED_CONN
Definition dinamo.h:585
#define SS_USER_PWD
Definition dinamo.h:576
#define DN_BCHAIN_MAX_SIG_LEN
Definition dinamo.h:2159
#define BCHAIN_KEY
Definition dinamo.h:1429
#define DN_BCHAIN_VER_BIP32_TESTNET
Definition dinamo.h:3474
#define DN_BCHAIN_BIP32_XPRV
Definition dinamo.h:3469
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
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
BYTE bLen
Definition dinamo.h:3528
BYTE pbPbk[DN_BCHAIN_MAX_PBK_LEN]
Definition dinamo.h:3529
BYTE bType
Definition dinamo.h:3527