1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
/* ****************************************************************************
* eID Middleware Project.
* Copyright (C) 2008-2009 FedICT.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version
* 3.0 as published by the Free Software Foundation.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, see
* http://www.gnu.org/licenses/.
**************************************************************************** */
#include "csputil.h"
#include "../common/Log.h"
namespace eIDMW
{
BOOL FillProvParam(LPBYTE pbData, LPDWORD pcbDataLen,
const void *dataIn, size_t dataLen)
{
BOOL bReturnVal = TRUE;
if (pbData == NULL)
*pcbDataLen = (DWORD) dataLen;
else if (*pcbDataLen < dataLen)
{
SetLastError(ERROR_MORE_DATA);
bReturnVal = FALSE;
}
else
{
memcpy(pbData, dataIn, dataLen);
*pcbDataLen = (DWORD) dataLen;
}
return bReturnVal;
}
tHashAlgo GetHashAlgo(ALG_ID Algid)
{
switch (Algid)
{
case CALG_MD5:
return ALGO_MD5;
case CALG_SHA1:
return ALGO_SHA1;
case CALG_SSL3_SHAMD5:
return ALGO_MD5_SHA1;
default:
MWLOG(LEV_INFO, MOD_CSP, L" Hash algo: unknown (returning an error)");
throw CMWEXCEPTION(EIDMW_ERR_PARAM_BAD);
}
}
unsigned long GetSignAlgo(ALG_ID Algid)
{
switch (Algid)
{
case CALG_MD5:
return SIGN_ALGO_MD5_RSA_PKCS;
case CALG_SHA1:
return SIGN_ALGO_SHA1_RSA_PKCS;
case CALG_SSL3_SHAMD5:
return SIGN_ALGO_RSA_PKCS;
default:
MWLOG(LEV_INFO, MOD_CSP, L" Hash algo: unknown (returning an error)");
throw CMWEXCEPTION(EIDMW_ERR_PARAM_BAD);
}
}
void ReverseByteOrder (BYTE *pByte, DWORD dwLen)
{
for (DWORD i = 0; i < (dwLen / 2); i++)
{
BYTE ucTemp = pByte[dwLen-1-i];
pByte [dwLen-1-i] = pByte[i];
pByte[i] = ucTemp;
}
}
BOOL DuplicatePubKeyInfo(CERT_PUBLIC_KEY_INFO *pDest, const CERT_PUBLIC_KEY_INFO *pSrc)
{
BOOL bOK = FALSE;
*pDest = *pSrc;
pDest->Algorithm.Parameters.pbData = new unsigned char[pSrc->Algorithm.Parameters.cbData];
pDest->PublicKey.pbData = new unsigned char[pSrc->PublicKey.cbData];
bOK = pDest->Algorithm.Parameters.pbData && pDest->PublicKey.pbData;
if (bOK)
{
memcpy(pDest->Algorithm.Parameters.pbData, pSrc->Algorithm.Parameters.pbData,
pSrc->Algorithm.Parameters.cbData);
memcpy(pDest->PublicKey.pbData, pSrc->PublicKey.pbData, pSrc->PublicKey.cbData);
}
else
FreePubKeyInfo(pDest);
return bOK;
}
void FreePubKeyInfo(CERT_PUBLIC_KEY_INFO *pPubKeyInfo)
{
if (pPubKeyInfo->Algorithm.Parameters.pbData)
delete pPubKeyInfo->Algorithm.Parameters.pbData;
pPubKeyInfo->Algorithm.Parameters.pbData = NULL;
if (pPubKeyInfo->PublicKey.pbData)
delete pPubKeyInfo->PublicKey.pbData;
pPubKeyInfo->PublicKey.pbData = NULL;
}
}
|