summaryrefslogtreecommitdiff
path: root/src/mscrypto/digests.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mscrypto/digests.c')
-rw-r--r--src/mscrypto/digests.c216
1 files changed, 155 insertions, 61 deletions
diff --git a/src/mscrypto/digests.c b/src/mscrypto/digests.c
index 9394afdc..98251d1b 100644
--- a/src/mscrypto/digests.c
+++ b/src/mscrypto/digests.c
@@ -1,5 +1,6 @@
-/**
- * XMLSec library
+/*
+ * XML Security Library (http://www.aleksey.com/xmlsec).
+ *
*
* This is free software; see Copyright file in the source
* distribution for preciese wording.
@@ -7,6 +8,13 @@
* Copyright (C) 2003 Cordys R&D BV, All rights reserved.
* Copyright (c) 2005-2006 Cryptocom LTD (http://www.cryptocom.ru).
*/
+/**
+ * SECTION:digests
+ * @Short_description: Digests transforms implementation for Microsoft Crypto API.
+ * @Stability: Private
+ *
+ */
+
#include "globals.h"
#include <string.h>
@@ -33,7 +41,7 @@ struct _xmlSecMSCryptoDigestCtx {
const xmlSecMSCryptoProviderInfo * providers;
HCRYPTHASH mscHash;
unsigned char dgst[MSCRYPTO_MAX_HASH_SIZE];
- size_t dgstSize; /* dgst size in bytes */
+ xmlSecSize dgstSize; /* dgst size in bytes */
};
/******************************************************************************
@@ -94,7 +102,19 @@ static xmlSecMSCryptoProviderInfo xmlSecMSCryptoProviderInfo_Gost[] = {
{ CRYPTOPRO_CSP, PROV_CRYPTOPRO_GOST },
{ NULL, 0 }
};
-#endif /*ndef XMLSEC_NO_GOST*/
+#endif /* XMLSEC_NO_GOST*/
+
+#ifndef XMLSEC_NO_GOST2012
+static xmlSecMSCryptoProviderInfo xmlSecMSCryptoProviderInfo_Gost2012_256[] = {
+ { CRYPTOPRO_CSP_256, PROV_GOST_2012_256 },
+ { NULL, 0 }
+};
+
+static xmlSecMSCryptoProviderInfo xmlSecMSCryptoProviderInfo_Gost2012_512[] = {
+ { CRYPTOPRO_CSP_512, PROV_GOST_2012_512 },
+ { NULL, 0 }
+};
+#endif /* XMLSEC_NO_GOST2012*/
static int
xmlSecMSCryptoDigestCheckId(xmlSecTransformPtr transform) {
@@ -135,6 +155,15 @@ xmlSecMSCryptoDigestCheckId(xmlSecTransformPtr transform) {
}
#endif /* XMLSEC_NO_GOST*/
+#ifndef XMLSEC_NO_GOST2012
+ if(xmlSecTransformCheckId(transform, xmlSecMSCryptoTransformGostR3411_2012_256Id)) {
+ return(1);
+ }
+ if(xmlSecTransformCheckId(transform, xmlSecMSCryptoTransformGostR3411_2012_512Id)) {
+ return(1);
+ }
+#endif /* XMLSEC_NO_GOST2012*/
+
return(0);
}
@@ -193,22 +222,26 @@ xmlSecMSCryptoDigestInitialize(xmlSecTransformPtr transform) {
} else
#endif /* XMLSEC_NO_GOST*/
+#ifndef XMLSEC_NO_GOST2012
+ if(xmlSecTransformCheckId(transform, xmlSecMSCryptoTransformGostR3411_2012_256Id)) {
+ ctx->alg_id = CALG_GR3411_2012_256;
+ ctx->providers = xmlSecMSCryptoProviderInfo_Gost2012_256;
+ } else
+ if(xmlSecTransformCheckId(transform, xmlSecMSCryptoTransformGostR3411_2012_512Id)) {
+ ctx->alg_id = CALG_GR3411_2012_512;
+ ctx->providers = xmlSecMSCryptoProviderInfo_Gost2012_512;
+ } else
+#endif /* XMLSEC_NO_GOST2012*/
+
{
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
- NULL,
- XMLSEC_ERRORS_R_INVALID_TRANSFORM,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInvalidTransfromError(transform)
return(-1);
}
ctx->provider = xmlSecMSCryptoFindProvider(ctx->providers, NULL, CRYPT_VERIFYCONTEXT, TRUE);
if(ctx->provider == 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
- "xmlSecMSCryptoFindProvider",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInternalError("xmlSecMSCryptoFindProvider",
+ xmlSecTransformGetName(transform));
return(-1);
}
@@ -253,22 +286,15 @@ xmlSecMSCryptoDigestVerify(xmlSecTransformPtr transform,
xmlSecAssert2(ctx->dgstSize > 0, -1);
if(dataSize != ctx->dgstSize) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
- NULL,
- XMLSEC_ERRORS_R_INVALID_SIZE,
- "data_size=%d;dgst_size=%d",
- dataSize, ctx->dgstSize);
+ xmlSecInvalidSizeError("Digest", dataSize, ctx->dgstSize,
+ xmlSecTransformGetName(transform));
transform->status = xmlSecTransformStatusFail;
return(0);
}
if(memcmp(ctx->dgst, data, ctx->dgstSize) != 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
- NULL,
- XMLSEC_ERRORS_R_INVALID_DATA,
- "data and digest do not match");
+ xmlSecInvalidDataError("data and digest do not match",
+ xmlSecTransformGetName(transform));
transform->status = xmlSecTransformStatusFail;
return(0);
}
@@ -307,11 +333,7 @@ xmlSecMSCryptoDigestExecute(xmlSecTransformPtr transform,
&(ctx->mscHash));
if((ret == 0) || (ctx->mscHash == 0)) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
- "CryptCreateHash",
- XMLSEC_ERRORS_R_CRYPTO_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecMSCryptoError("CryptCreateHash", xmlSecTransformGetName(transform));
return(-1);
}
@@ -329,21 +351,17 @@ xmlSecMSCryptoDigestExecute(xmlSecTransformPtr transform,
0);
if(ret == 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
- "CryptHashData",
- XMLSEC_ERRORS_R_CRYPTO_FAILED,
- "size=%d", inSize);
+ xmlSecMSCryptoError2("CryptHashData",
+ xmlSecTransformGetName(transform),
+ "size=%d", inSize);
return(-1);
}
ret = xmlSecBufferRemoveHead(in, inSize);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
- "xmlSecBufferRemoveHead",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "size=%d", inSize);
+ xmlSecInternalError2("xmlSecBufferRemoveHead",
+ xmlSecTransformGetName(transform),
+ "size=%d", inSize);
return(-1);
}
}
@@ -354,21 +372,18 @@ xmlSecMSCryptoDigestExecute(xmlSecTransformPtr transform,
retLen = MSCRYPTO_MAX_HASH_SIZE;
ret = CryptGetHashParam(ctx->mscHash,
- HP_HASHVAL,
- ctx->dgst,
- &retLen,
- 0);
-
+ HP_HASHVAL,
+ ctx->dgst,
+ &retLen,
+ 0);
if (ret == 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
- "CryptGetHashParam(HP_HASHVAL)",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "size=%d", MSCRYPTO_MAX_HASH_SIZE);
+ xmlSecMSCryptoError2("CryptGetHashParam(HP_HASHVAL)",
+ xmlSecTransformGetName(transform),
+ "size=%d", MSCRYPTO_MAX_HASH_SIZE);
return(-1);
}
- ctx->dgstSize = (size_t)retLen;
+ ctx->dgstSize = XMLSEC_SIZE_BAD_CAST(retLen);
xmlSecAssert2(ctx->dgstSize > 0, -1);
@@ -376,11 +391,9 @@ xmlSecMSCryptoDigestExecute(xmlSecTransformPtr transform,
if(transform->operation == xmlSecTransformOperationSign) {
ret = xmlSecBufferAppend(out, ctx->dgst, ctx->dgstSize);
if(ret < 0) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
- "xmlSecBufferAppend",
- XMLSEC_ERRORS_R_XMLSEC_FAILED,
- "size=%d", ctx->dgstSize);
+ xmlSecInternalError2("xmlSecBufferAppend",
+ xmlSecTransformGetName(transform),
+ "size=%d", ctx->dgstSize);
return(-1);
}
}
@@ -390,11 +403,7 @@ xmlSecMSCryptoDigestExecute(xmlSecTransformPtr transform,
/* the only way we can get here is if there is no input */
xmlSecAssert2(xmlSecBufferGetSize(in) == 0, -1);
} else {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
- NULL,
- XMLSEC_ERRORS_R_INVALID_STATUS,
- "status=%d", transform->status);
+ xmlSecInvalidTransfromStatusError(transform);
return(-1);
}
@@ -664,5 +673,90 @@ xmlSecTransformId
xmlSecMSCryptoTransformGostR3411_94GetKlass(void) {
return(&xmlSecMSCryptoGostR3411_94Klass);
}
+
+/******************************************************************************
+ *
+ * GOSTR3411-2012/256
+ *
+ *****************************************************************************/
+static xmlSecTransformKlass xmlSecMSCryptoGostR3411_2012_256Klass = {
+ /* klass/object sizes */
+ sizeof(xmlSecTransformKlass), /* size_t klassSize */
+ xmlSecMSCryptoDigestSize, /* size_t objSize */
+
+ xmlSecNameGostR3411_2012_256, /* const xmlChar* name; */
+ xmlSecHrefGostR3411_2012_256, /* const xmlChar* href; */
+ xmlSecTransformUsageDigestMethod, /* xmlSecTransformUsage usage; */
+ xmlSecMSCryptoDigestInitialize, /* xmlSecTransformInitializeMethod initialize; */
+ xmlSecMSCryptoDigestFinalize, /* xmlSecTransformFinalizeMethod finalize; */
+ NULL, /* xmlSecTransformNodeReadMethod readNode; */
+ NULL, /* xmlSecTransformNodeWriteMethod writeNode; */
+ NULL, /* xmlSecTransformSetKeyReqMethod setKeyReq; */
+ NULL, /* xmlSecTransformSetKeyMethod setKey; */
+ xmlSecMSCryptoDigestVerify, /* xmlSecTransformVerifyMethod verify; */
+ xmlSecTransformDefaultGetDataType, /* xmlSecTransformGetDataTypeMethod getDataType; */
+ xmlSecTransformDefaultPushBin, /* xmlSecTransformPushBinMethod pushBin; */
+ xmlSecTransformDefaultPopBin, /* xmlSecTransformPopBinMethod popBin; */
+ NULL, /* xmlSecTransformPushXmlMethod pushXml; */
+ NULL, /* xmlSecTransformPopXmlMethod popXml; */
+ xmlSecMSCryptoDigestExecute, /* xmlSecTransformExecuteMethod execute; */
+ NULL, /* void* reserved0; */
+ NULL, /* void* reserved1; */
+};
+
+/**
+ * xmlSecMSCryptoTransformGostR3411_2012_256GetKlass:
+ *
+ * GOSTR3411_2012_256 digest transform klass.
+ *
+ * Returns: pointer to GOSTR3411_2012_256 digest transform klass.
+ */
+xmlSecTransformId
+xmlSecMSCryptoTransformGostR3411_2012_256GetKlass(void) {
+ return(&xmlSecMSCryptoGostR3411_2012_256Klass);
+}
+
+
+/******************************************************************************
+ *
+ * GOSTR3411-2012/512
+ *
+ *****************************************************************************/
+static xmlSecTransformKlass xmlSecMSCryptoGostR3411_2012_512Klass = {
+ /* klass/object sizes */
+ sizeof(xmlSecTransformKlass), /* size_t klassSize */
+ xmlSecMSCryptoDigestSize, /* size_t objSize */
+
+ xmlSecNameGostR3411_2012_512, /* const xmlChar* name; */
+ xmlSecHrefGostR3411_2012_512, /* const xmlChar* href; */
+ xmlSecTransformUsageDigestMethod, /* xmlSecTransformUsage usage; */
+ xmlSecMSCryptoDigestInitialize, /* xmlSecTransformInitializeMethod initialize; */
+ xmlSecMSCryptoDigestFinalize, /* xmlSecTransformFinalizeMethod finalize; */
+ NULL, /* xmlSecTransformNodeReadMethod readNode; */
+ NULL, /* xmlSecTransformNodeWriteMethod writeNode; */
+ NULL, /* xmlSecTransformSetKeyReqMethod setKeyReq; */
+ NULL, /* xmlSecTransformSetKeyMethod setKey; */
+ xmlSecMSCryptoDigestVerify, /* xmlSecTransformVerifyMethod verify; */
+ xmlSecTransformDefaultGetDataType, /* xmlSecTransformGetDataTypeMethod getDataType; */
+ xmlSecTransformDefaultPushBin, /* xmlSecTransformPushBinMethod pushBin; */
+ xmlSecTransformDefaultPopBin, /* xmlSecTransformPopBinMethod popBin; */
+ NULL, /* xmlSecTransformPushXmlMethod pushXml; */
+ NULL, /* xmlSecTransformPopXmlMethod popXml; */
+ xmlSecMSCryptoDigestExecute, /* xmlSecTransformExecuteMethod execute; */
+ NULL, /* void* reserved0; */
+ NULL, /* void* reserved1; */
+};
+
+/**
+ * xmlSecMSCryptoTransformGostR3411_2012_512GetKlass:
+ *
+ * GOSTR3411_2012_512 digest transform klass.
+ *
+ * Returns: pointer to GOSTR3411_2012_512 digest transform klass.
+ */
+xmlSecTransformId
+xmlSecMSCryptoTransformGostR3411_2012_512GetKlass(void) {
+ return(&xmlSecMSCryptoGostR3411_2012_512Klass);
+}
#endif /* XMLSEC_NO_GOST*/