crypt32(2/3): Store hash algorithm ID along with other parameters
when decoding a hash message
Juan Lang
juan.lang at gmail.com
Wed Jul 18 12:14:35 CDT 2007
--Juan
-------------- next part --------------
From 1cae1673f4e44ed923ef57fc80f3b93fe19d7fa1 Mon Sep 17 00:00:00 2001
From: Juan Lang <juanlang at juan.corp.google.com>
Date: Wed, 18 Jul 2007 09:38:03 -0700
Subject: [PATCH] Store hash algorithm ID along with other parameters when decoding a hash message
---
dlls/crypt32/msg.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++
dlls/crypt32/tests/msg.c | 2 --
2 files changed, 60 insertions(+), 2 deletions(-)
diff --git a/dlls/crypt32/msg.c b/dlls/crypt32/msg.c
index a261455..7565741 100644
--- a/dlls/crypt32/msg.c
+++ b/dlls/crypt32/msg.c
@@ -649,6 +649,48 @@ static BOOL CDecodeMsg_DecodeDataContent
return ret;
}
+static void CDecodeMsg_SaveAlgorithmID(CDecodeMsg *msg, DWORD param,
+ const CRYPT_ALGORITHM_IDENTIFIER *id)
+{
+ static const BYTE nullParams[] = { ASN_NULL, 0 };
+ CRYPT_ALGORITHM_IDENTIFIER *copy;
+ DWORD len = sizeof(CRYPT_ALGORITHM_IDENTIFIER);
+
+ /* Linearize algorithm id */
+ len += strlen(id->pszObjId) + 1;
+ len += id->Parameters.cbData;
+ copy = CryptMemAlloc(len);
+ if (copy)
+ {
+ copy->pszObjId =
+ (LPSTR)((BYTE *)copy + sizeof(CRYPT_ALGORITHM_IDENTIFIER));
+ strcpy(copy->pszObjId, id->pszObjId);
+ copy->Parameters.pbData = (BYTE *)copy->pszObjId + strlen(id->pszObjId)
+ + 1;
+ /* Trick: omit NULL parameters */
+ if (id->Parameters.cbData == sizeof(nullParams) &&
+ !memcmp(id->Parameters.pbData, nullParams, sizeof(nullParams)))
+ {
+ copy->Parameters.cbData = 0;
+ len -= sizeof(nullParams);
+ }
+ else
+ copy->Parameters.cbData = id->Parameters.cbData;
+ if (copy->Parameters.cbData)
+ memcpy(copy->Parameters.pbData, id->Parameters.pbData,
+ id->Parameters.cbData);
+ ContextPropertyList_SetProperty(msg->properties, param, (BYTE *)copy,
+ len);
+ CryptMemFree(copy);
+ }
+}
+
+static inline void CRYPT_FixUpAlgorithmID(CRYPT_ALGORITHM_IDENTIFIER *id)
+{
+ id->pszObjId = (LPSTR)((BYTE *)id + sizeof(CRYPT_ALGORITHM_IDENTIFIER));
+ id->Parameters.pbData = (BYTE *)id->pszObjId + strlen(id->pszObjId) + 1;
+}
+
/* Decodes the content in blob as the type given, and updates the value
* (type, parameters, etc.) of msg based on what blob contains.
* It doesn't just use msg's type, to allow a recursive call from an implicitly
@@ -679,6 +721,8 @@ static BOOL CDecodeMsg_DecodeContent(CDe
ContextPropertyList_SetProperty(msg->properties,
CMSG_VERSION_PARAM, (const BYTE *)&digestedData->version,
sizeof(digestedData->version));
+ CDecodeMsg_SaveAlgorithmID(msg, CMSG_HASH_ALGORITHM_PARAM,
+ &digestedData->DigestAlgorithm);
ContextPropertyList_SetProperty(msg->properties,
CMSG_INNER_CONTENT_TYPE_PARAM,
(const BYTE *)digestedData->ContentInfo.pszObjId,
@@ -775,6 +819,22 @@ static BOOL CDecodeMsg_GetParam(HCRYPTMS
ret = CRYPT_CopyParam(pvData, pcbData, (const BYTE *)&msg->type,
sizeof(msg->type));
break;
+ case CMSG_HASH_ALGORITHM_PARAM:
+ {
+ CRYPT_DATA_BLOB blob;
+
+ ret = ContextPropertyList_FindProperty(msg->properties, dwParamType,
+ &blob);
+ if (ret)
+ {
+ ret = CRYPT_CopyParam(pvData, pcbData, blob.pbData, blob.cbData);
+ if (ret && pvData)
+ CRYPT_FixUpAlgorithmID((CRYPT_ALGORITHM_IDENTIFIER *)pvData);
+ }
+ else
+ SetLastError(CRYPT_E_INVALID_MSG_TYPE);
+ break;
+ }
default:
{
CRYPT_DATA_BLOB blob;
diff --git a/dlls/crypt32/tests/msg.c b/dlls/crypt32/tests/msg.c
index 40da5fc..4a42bbd 100644
--- a/dlls/crypt32/tests/msg.c
+++ b/dlls/crypt32/tests/msg.c
@@ -1256,7 +1256,6 @@ static void test_decode_msg_get_param(vo
ret = CryptMsgUpdate(msg, hashEmptyContent, sizeof(hashEmptyContent), TRUE);
check_param("empty hash content", msg, CMSG_CONTENT_PARAM, NULL, 0);
check_param("empty hash hash data", msg, CMSG_HASH_DATA_PARAM, NULL, 0);
- todo_wine
check_algid_param("empty hash hash algo id", msg, CMSG_HASH_ALGORITHM_PARAM,
&hashID);
todo_wine
@@ -1269,7 +1268,6 @@ static void test_decode_msg_get_param(vo
sizeof(msgData));
check_param("hash hash data", msg, CMSG_HASH_DATA_PARAM, hashParam,
sizeof(hashParam));
- todo_wine
check_algid_param("hash hash algo id", msg, CMSG_HASH_ALGORITHM_PARAM,
&hashID);
todo_wine
--
1.4.1
More information about the wine-patches
mailing list