mirror of
https://github.com/reactos/wine.git
synced 2024-11-29 06:30:37 +00:00
crypt32: Move digested data encoding to encode.c.
This commit is contained in:
parent
d212adbf10
commit
703a0f6fce
@ -67,23 +67,21 @@ BOOL WINAPI CRYPT_AsnEncodeConstructed(DWORD dwCertEncodingType,
|
||||
BOOL WINAPI CRYPT_AsnEncodeOid(DWORD dwCertEncodingType,
|
||||
LPCSTR lpszStructType, const void *pvStructInfo, DWORD dwFlags,
|
||||
PCRYPT_ENCODE_PARA pEncodePara, BYTE *pbEncoded, DWORD *pcbEncoded);
|
||||
BOOL WINAPI CRYPT_AsnEncodeInt(DWORD dwCertEncodingType,
|
||||
LPCSTR lpszStructType, const void *pvStructInfo, DWORD dwFlags,
|
||||
PCRYPT_ENCODE_PARA pEncodePara, BYTE *pbEncoded, DWORD *pcbEncoded);
|
||||
/* Like CRYPT_AsnEncodeAlgorithmId, but encodes parameters as an asn.1 NULL
|
||||
* if they are empty.
|
||||
*/
|
||||
BOOL WINAPI CRYPT_AsnEncodeAlgorithmIdWithNullParams(DWORD dwCertEncodingType,
|
||||
LPCSTR lpszStructType, const void *pvStructInfo, DWORD dwFlags,
|
||||
PCRYPT_ENCODE_PARA pEncodePara, BYTE *pbEncoded, DWORD *pcbEncoded);
|
||||
/* Like CRYPT_AsnEncodePKCSContentInfo, but allows the OID to be NULL */
|
||||
BOOL WINAPI CRYPT_AsnEncodePKCSContentInfoInternal(DWORD dwCertEncodingType,
|
||||
LPCSTR lpszStructType, const void *pvStructInfo, DWORD dwFlags,
|
||||
PCRYPT_ENCODE_PARA pEncodePara, BYTE *pbEncoded, DWORD *pcbEncoded);
|
||||
BOOL WINAPI CRYPT_AsnEncodeOctets(DWORD dwCertEncodingType,
|
||||
LPCSTR lpszStructType, const void *pvStructInfo, DWORD dwFlags,
|
||||
PCRYPT_ENCODE_PARA pEncodePara, BYTE *pbEncoded, DWORD *pcbEncoded);
|
||||
|
||||
typedef struct _CRYPT_DIGESTED_DATA
|
||||
{
|
||||
DWORD version;
|
||||
CRYPT_ALGORITHM_IDENTIFIER DigestAlgorithm;
|
||||
CRYPT_CONTENT_INFO ContentInfo;
|
||||
CRYPT_HASH_BLOB hash;
|
||||
} CRYPT_DIGESTED_DATA;
|
||||
|
||||
BOOL CRYPT_AsnEncodePKCSDigestedData(CRYPT_DIGESTED_DATA *digestedData,
|
||||
void *pvData, DWORD *pcbData);
|
||||
|
||||
/* Helper function to check *pcbEncoded, set it to the required size, and
|
||||
* optionally to allocate memory. Assumes pbEncoded is not NULL.
|
||||
* If CRYPT_ENCODE_ALLOC_FLAG is set in dwFlags, *pbEncoded will be set to a
|
||||
|
@ -78,6 +78,9 @@ static BOOL WINAPI CRYPT_AsnEncodeBits(DWORD dwCertEncodingType,
|
||||
static BOOL WINAPI CRYPT_AsnEncodeBitsSwapBytes(DWORD dwCertEncodingType,
|
||||
LPCSTR lpszStructType, const void *pvStructInfo, DWORD dwFlags,
|
||||
PCRYPT_ENCODE_PARA pEncodePara, BYTE *pbEncoded, DWORD *pcbEncoded);
|
||||
static BOOL WINAPI CRYPT_AsnEncodeInt(DWORD dwCertEncodingType,
|
||||
LPCSTR lpszStructType, const void *pvStructInfo, DWORD dwFlags,
|
||||
PCRYPT_ENCODE_PARA pEncodePara, BYTE *pbEncoded, DWORD *pcbEncoded);
|
||||
static BOOL WINAPI CRYPT_AsnEncodeInteger(DWORD dwCertEncodingType,
|
||||
LPCSTR lpszStructType, const void *pvStructInfo, DWORD dwFlags,
|
||||
PCRYPT_ENCODE_PARA pEncodePara, BYTE *pbEncoded, DWORD *pcbEncoded);
|
||||
@ -388,9 +391,13 @@ static BOOL WINAPI CRYPT_AsnEncodeValidity(DWORD dwCertEncodingType,
|
||||
return ret;
|
||||
}
|
||||
|
||||
BOOL WINAPI CRYPT_AsnEncodeAlgorithmIdWithNullParams(DWORD dwCertEncodingType,
|
||||
LPCSTR lpszStructType, const void *pvStructInfo, DWORD dwFlags,
|
||||
PCRYPT_ENCODE_PARA pEncodePara, BYTE *pbEncoded, DWORD *pcbEncoded)
|
||||
/* Like CRYPT_AsnEncodeAlgorithmId, but encodes parameters as an asn.1 NULL
|
||||
* if they are empty.
|
||||
*/
|
||||
static BOOL WINAPI CRYPT_AsnEncodeAlgorithmIdWithNullParams(
|
||||
DWORD dwCertEncodingType, LPCSTR lpszStructType, const void *pvStructInfo,
|
||||
DWORD dwFlags, PCRYPT_ENCODE_PARA pEncodePara, BYTE *pbEncoded,
|
||||
DWORD *pcbEncoded)
|
||||
{
|
||||
const CRYPT_ALGORITHM_IDENTIFIER *algo =
|
||||
(const CRYPT_ALGORITHM_IDENTIFIER *)pvStructInfo;
|
||||
@ -1439,9 +1446,11 @@ static BOOL WINAPI CRYPT_AsnEncodePKCSAttributes(DWORD dwCertEncodingType,
|
||||
return ret;
|
||||
}
|
||||
|
||||
BOOL WINAPI CRYPT_AsnEncodePKCSContentInfoInternal(DWORD dwCertEncodingType,
|
||||
LPCSTR lpszStructType, const void *pvStructInfo, DWORD dwFlags,
|
||||
PCRYPT_ENCODE_PARA pEncodePara, BYTE *pbEncoded, DWORD *pcbEncoded)
|
||||
/* Like CRYPT_AsnEncodePKCSContentInfo, but allows the OID to be NULL */
|
||||
static BOOL WINAPI CRYPT_AsnEncodePKCSContentInfoInternal(
|
||||
DWORD dwCertEncodingType, LPCSTR lpszStructType, const void *pvStructInfo,
|
||||
DWORD dwFlags, PCRYPT_ENCODE_PARA pEncodePara, BYTE *pbEncoded,
|
||||
DWORD *pcbEncoded)
|
||||
{
|
||||
const CRYPT_CONTENT_INFO *info = (const CRYPT_CONTENT_INFO *)pvStructInfo;
|
||||
struct AsnEncodeSequenceItem items[2] = {
|
||||
@ -1464,6 +1473,21 @@ BOOL WINAPI CRYPT_AsnEncodePKCSContentInfoInternal(DWORD dwCertEncodingType,
|
||||
cItem, dwFlags, pEncodePara, pbEncoded, pcbEncoded);
|
||||
}
|
||||
|
||||
BOOL CRYPT_AsnEncodePKCSDigestedData(CRYPT_DIGESTED_DATA *digestedData,
|
||||
void *pvData, DWORD *pcbData)
|
||||
{
|
||||
struct AsnEncodeSequenceItem items[] = {
|
||||
{ &digestedData->version, CRYPT_AsnEncodeInt, 0 },
|
||||
{ &digestedData->DigestAlgorithm, CRYPT_AsnEncodeAlgorithmIdWithNullParams,
|
||||
0 },
|
||||
{ &digestedData->ContentInfo, CRYPT_AsnEncodePKCSContentInfoInternal, 0 },
|
||||
{ &digestedData->hash, CRYPT_AsnEncodeOctets, 0 },
|
||||
};
|
||||
|
||||
return CRYPT_AsnEncodeSequence(X509_ASN_ENCODING, items,
|
||||
sizeof(items) / sizeof(items[0]), 0, NULL, pvData, pcbData);
|
||||
}
|
||||
|
||||
static BOOL WINAPI CRYPT_AsnEncodePKCSContentInfo(DWORD dwCertEncodingType,
|
||||
LPCSTR lpszStructType, const void *pvStructInfo, DWORD dwFlags,
|
||||
PCRYPT_ENCODE_PARA pEncodePara, BYTE *pbEncoded, DWORD *pcbEncoded)
|
||||
|
@ -347,56 +347,40 @@ static BOOL CRYPT_EncodePKCSDigestedData(CHashEncodeMsg *msg, void *pvData,
|
||||
ret = CryptGetHashParam(msg->hash, HP_ALGID, (BYTE *)&algID, &size, 0);
|
||||
if (ret)
|
||||
{
|
||||
CRYPT_ALGORITHM_IDENTIFIER algoId = { 0 };
|
||||
DWORD version = CMSG_HASHED_DATA_PKCS_1_5_VERSION;
|
||||
struct AsnEncodeSequenceItem items[7] = { { 0 } };
|
||||
DWORD cItem = 0;
|
||||
CRYPT_DATA_BLOB hash = { 0, NULL };
|
||||
CRYPT_CONTENT_INFO contentInfo = { NULL, { 0, NULL } };
|
||||
CRYPT_DIGESTED_DATA digestedData = { 0 };
|
||||
char oid_rsa_data[] = szOID_RSA_data;
|
||||
|
||||
items[cItem].pvStructInfo = &version;
|
||||
items[cItem].encodeFunc = CRYPT_AsnEncodeInt;
|
||||
cItem++;
|
||||
algoId.pszObjId = (LPSTR)CertAlgIdToOID(algID);
|
||||
/* FIXME: what about algoId.Parameters? */
|
||||
items[cItem].pvStructInfo = &algoId;
|
||||
items[cItem].encodeFunc = CRYPT_AsnEncodeAlgorithmIdWithNullParams;
|
||||
cItem++;
|
||||
digestedData.version = CMSG_HASHED_DATA_PKCS_1_5_VERSION;
|
||||
digestedData.DigestAlgorithm.pszObjId = (LPSTR)CertAlgIdToOID(algID);
|
||||
/* FIXME: what about digestedData.DigestAlgorithm.Parameters? */
|
||||
/* Quirk: OID is only encoded messages if an update has happened */
|
||||
if (msg->base.state != MsgStateInit)
|
||||
contentInfo.pszObjId = oid_rsa_data;
|
||||
digestedData.ContentInfo.pszObjId = oid_rsa_data;
|
||||
if (!(msg->base.open_flags & CMSG_DETACHED_FLAG) && msg->data.cbData)
|
||||
{
|
||||
ret = CRYPT_AsnEncodeOctets(0, NULL, &msg->data,
|
||||
CRYPT_ENCODE_ALLOC_FLAG, NULL,
|
||||
(LPBYTE)&contentInfo.Content.pbData,
|
||||
&contentInfo.Content.cbData);
|
||||
(LPBYTE)&digestedData.ContentInfo.Content.pbData,
|
||||
&digestedData.ContentInfo.Content.cbData);
|
||||
}
|
||||
items[cItem].pvStructInfo = &contentInfo;
|
||||
items[cItem].encodeFunc =
|
||||
CRYPT_AsnEncodePKCSContentInfoInternal;
|
||||
cItem++;
|
||||
if (msg->base.state == MsgStateFinalized)
|
||||
{
|
||||
size = sizeof(DWORD);
|
||||
ret = CryptGetHashParam(msg->hash, HP_HASHSIZE,
|
||||
(LPBYTE)&hash.cbData, &size, 0);
|
||||
(LPBYTE)&digestedData.hash.cbData, &size, 0);
|
||||
if (ret)
|
||||
{
|
||||
hash.pbData = CryptMemAlloc(hash.cbData);
|
||||
ret = CryptGetHashParam(msg->hash, HP_HASHVAL, hash.pbData,
|
||||
&hash.cbData, 0);
|
||||
digestedData.hash.pbData = CryptMemAlloc(
|
||||
digestedData.hash.cbData);
|
||||
ret = CryptGetHashParam(msg->hash, HP_HASHVAL,
|
||||
digestedData.hash.pbData, &digestedData.hash.cbData, 0);
|
||||
}
|
||||
}
|
||||
items[cItem].pvStructInfo = &hash;
|
||||
items[cItem].encodeFunc = CRYPT_AsnEncodeOctets;
|
||||
cItem++;
|
||||
if (ret)
|
||||
ret = CRYPT_AsnEncodeSequence(X509_ASN_ENCODING, items, cItem,
|
||||
0, NULL, pvData, pcbData);
|
||||
CryptMemFree(hash.pbData);
|
||||
LocalFree(contentInfo.Content.pbData);
|
||||
ret = CRYPT_AsnEncodePKCSDigestedData(&digestedData, pvData,
|
||||
pcbData);
|
||||
CryptMemFree(digestedData.hash.pbData);
|
||||
LocalFree(digestedData.ContentInfo.Content.pbData);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user