summaryrefslogtreecommitdiff
path: root/src/openssl/digests.c
diff options
context:
space:
mode:
authorKonrad Lipinski <k.lipinski2@partner.samsung.com>2019-06-11 16:25:51 +0200
committerKonrad Lipinski <k.lipinski2@samsung.com>2019-08-01 14:37:53 +0200
commitcc6febdd37186eeea33bcbce89d79f661ee0009f (patch)
tree100542f7f8fd3b3c9548150362efe35adde47551 /src/openssl/digests.c
parentc40fbfa8503e7763ef630496852f4d6b5e63b58c (diff)
downloadxmlsec1-cc6febdd37186eeea33bcbce89d79f661ee0009f.tar.gz
xmlsec1-cc6febdd37186eeea33bcbce89d79f661ee0009f.tar.bz2
xmlsec1-cc6febdd37186eeea33bcbce89d79f661ee0009f.zip
Import upstream commit c4d0493d545b99194eea1b2b058930d5a9bb91b1 (1.2.28)
Change-Id: I10f71567cb140be223923e1cd0b5895e366ac23e
Diffstat (limited to 'src/openssl/digests.c')
-rw-r--r--src/openssl/digests.c119
1 files changed, 37 insertions, 82 deletions
diff --git a/src/openssl/digests.c b/src/openssl/digests.c
index 5ec5299a..537a7399 100644
--- a/src/openssl/digests.c
+++ b/src/openssl/digests.c
@@ -1,11 +1,19 @@
-/**
- * XMLSec library
+/*
+ * XML Security Library (http://www.aleksey.com/xmlsec).
+ *
*
* This is free software; see Copyright file in the source
* distribution for preciese wording.
*
* Copyright (C) 2002-2016 Aleksey Sanin <aleksey@aleksey.com>. All Rights Reserved.
*/
+/**
+ * SECTION:digests
+ * @Short_description: Digests transforms implementation for OpenSSL.
+ * @Stability: Private
+ *
+ */
+
#include "globals.h"
#include <string.h>
@@ -19,16 +27,7 @@
#include <xmlsec/openssl/crypto.h>
#include <xmlsec/openssl/evp.h>
-
-/* new API from OpenSSL 1.1.0 (https://www.openssl.org/docs/manmaster/crypto/EVP_DigestInit.html):
- *
- * EVP_MD_CTX_create() and EVP_MD_CTX_destroy() were renamed to EVP_MD_CTX_new() and EVP_MD_CTX_free() in OpenSSL 1.1.
- */
-#if !defined(XMLSEC_OPENSSL_110)
-#define EVP_MD_CTX_new() EVP_MD_CTX_create()
-#define EVP_MD_CTX_free(x) EVP_MD_CTX_destroy((x))
-#endif /* !defined(XMLSEC_OPENSSL_110) */
-
+#include "openssl_compat.h"
/**************************************************************************
*
@@ -131,8 +130,6 @@ xmlSecOpenSSLEvpDigestCheckId(xmlSecTransformPtr transform) {
{
return(0);
}
-
- return(0);
}
static int
@@ -194,11 +191,7 @@ xmlSecOpenSSLEvpDigestInitialize(xmlSecTransformPtr transform) {
if(xmlSecTransformCheckId(transform, xmlSecOpenSSLTransformGostR3411_94Id)) {
ctx->digest = EVP_get_digestbyname("md_gost94");
if (!ctx->digest) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
- NULL,
- XMLSEC_ERRORS_R_INVALID_TRANSFORM,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInvalidTransfromError(transform)
return(-1);
}
} else
@@ -209,11 +202,7 @@ xmlSecOpenSSLEvpDigestInitialize(xmlSecTransformPtr transform) {
ctx->digest = EVP_get_digestbyname("md_gost12_256");
if (!ctx->digest)
{
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
- NULL,
- XMLSEC_ERRORS_R_INVALID_TRANSFORM,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInvalidTransfromError(transform)
return(-1);
}
} else
@@ -222,33 +211,22 @@ xmlSecOpenSSLEvpDigestInitialize(xmlSecTransformPtr transform) {
ctx->digest = EVP_get_digestbyname("md_gost12_512");
if (!ctx->digest)
{
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
- NULL,
- XMLSEC_ERRORS_R_INVALID_TRANSFORM,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecInvalidTransfromError(transform)
return(-1);
}
} 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);
}
/* create digest CTX */
ctx->digestCtx = EVP_MD_CTX_new();
if(ctx->digestCtx == NULL) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
- "EVP_MD_CTX_new",
- XMLSEC_ERRORS_R_CRYPTO_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecOpenSSLError("EVP_MD_CTX_new",
+ xmlSecTransformGetName(transform));
return(-1);
}
@@ -291,24 +269,17 @@ xmlSecOpenSSLEvpDigestVerify(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 -1;
+ 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 -1;
+ return(0);
}
transform->status = xmlSecTransformStatusOk;
@@ -340,11 +311,8 @@ xmlSecOpenSSLEvpDigestExecute(xmlSecTransformPtr transform, int last, xmlSecTran
if(transform->status == xmlSecTransformStatusNone) {
ret = EVP_DigestInit(ctx->digestCtx, ctx->digest);
if(ret != 1) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
- "EVP_DigestInit",
- XMLSEC_ERRORS_R_CRYPTO_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecOpenSSLError("EVP_DigestInit",
+ xmlSecTransformGetName(transform));
return(-1);
}
transform->status = xmlSecTransformStatusWorking;
@@ -357,21 +325,17 @@ xmlSecOpenSSLEvpDigestExecute(xmlSecTransformPtr transform, int last, xmlSecTran
if(inSize > 0) {
ret = EVP_DigestUpdate(ctx->digestCtx, xmlSecBufferGetData(in), inSize);
if(ret != 1) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
- "EVP_DigestUpdate",
- XMLSEC_ERRORS_R_CRYPTO_FAILED,
- "size=%d", inSize);
+ xmlSecOpenSSLError2("EVP_DigestUpdate",
+ xmlSecTransformGetName(transform),
+ "size=%lu", (unsigned long)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);
}
}
@@ -382,11 +346,8 @@ xmlSecOpenSSLEvpDigestExecute(xmlSecTransformPtr transform, int last, xmlSecTran
ret = EVP_DigestFinal(ctx->digestCtx, ctx->dgst, &dgstSize);
if(ret != 1) {
- xmlSecError(XMLSEC_ERRORS_HERE,
- xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
- "EVP_DigestFinal",
- XMLSEC_ERRORS_R_CRYPTO_FAILED,
- XMLSEC_ERRORS_NO_MESSAGE);
+ xmlSecOpenSSLError("EVP_DigestFinal",
+ xmlSecTransformGetName(transform));
return(-1);
}
xmlSecAssert2(dgstSize > 0, -1);
@@ -396,11 +357,9 @@ xmlSecOpenSSLEvpDigestExecute(xmlSecTransformPtr transform, int last, xmlSecTran
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);
}
}
@@ -410,11 +369,7 @@ xmlSecOpenSSLEvpDigestExecute(xmlSecTransformPtr transform, int last, xmlSecTran
/* 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);
}