[xmlsec] fix types for crypto operations



commit 87179bc552a5b67bd5b402ec90dd6b3137103207
Author: Aleksey Sanin <aleksey aleksey com>
Date:   Wed Apr 28 16:15:34 2010 -0700

    fix types for crypto operations

 include/xmlsec/xmlsec.h  |    6 ++++++
 src/nss/digests.c        |    7 +++++--
 src/nss/hmac.c           |    6 +++---
 src/openssl/app.c        |    2 +-
 src/openssl/digests.c    |    9 ++++++---
 src/openssl/hmac.c       |    6 +++---
 src/openssl/signatures.c |   21 ++++++++++++---------
 7 files changed, 36 insertions(+), 21 deletions(-)
---
diff --git a/include/xmlsec/xmlsec.h b/include/xmlsec/xmlsec.h
index 25a9a79..81b8a39 100644
--- a/include/xmlsec/xmlsec.h
+++ b/include/xmlsec/xmlsec.h
@@ -44,6 +44,12 @@ typedef void*                                   xmlSecPtr;
 #else  /* XMLSEC_NO_SIZE_T */
 #define xmlSecSize                              size_t
 #endif /* XMLSEC_NO_SIZE_T */
+/**
+ * XMLSEC_SIZE_BAD_CAST:
+ *
+ * Bad cast to xmlSecSize
+ */
+#define XMLSEC_SIZE_BAD_CAST(val)               ((xmlSecSize)(val))
 
 /**
  * xmlSecByte:
diff --git a/src/nss/digests.c b/src/nss/digests.c
index 9cc1b91..8063b44 100644
--- a/src/nss/digests.c
+++ b/src/nss/digests.c
@@ -289,7 +289,9 @@ xmlSecNssDigestExecute(xmlSecTransformPtr transform, int last, xmlSecTransformCt
             }
         }
         if(last) {
-            rv = PK11_DigestFinal(ctx->digestCtx, ctx->dgst, &ctx->dgstSize, sizeof(ctx->dgst));
+            unsigned int dgstSize;
+
+            rv = PK11_DigestFinal(ctx->digestCtx, ctx->dgst, &dgstSize, sizeof(ctx->dgst));
             if(rv != SECSuccess) {
                 xmlSecError(XMLSEC_ERRORS_HERE,
                             xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
@@ -298,7 +300,8 @@ xmlSecNssDigestExecute(xmlSecTransformPtr transform, int last, xmlSecTransformCt
                             "error code=%d", PORT_GetError());
                 return(-1);
             }
-            xmlSecAssert2(ctx->dgstSize > 0, -1);
+            xmlSecAssert2(dgstSize > 0, -1);
+            ctx->dgstSize = XMLSEC_SIZE_BAD_CAST(dgstSize);
 
             if(transform->operation == xmlSecTransformOperationSign) {
                 ret = xmlSecBufferAppend(out, ctx->dgst, ctx->dgstSize);
diff --git a/src/nss/hmac.c b/src/nss/hmac.c
index bcea9df..1e1e817 100644
--- a/src/nss/hmac.c
+++ b/src/nss/hmac.c
@@ -517,7 +517,7 @@ xmlSecNssHmacExecute(xmlSecTransformPtr transform, int last, xmlSecTransformCtxP
             }
         }
         if(last) {
-            xmlSecSize dgstSize;
+            unsigned int dgstSize;
 
             rv = PK11_DigestFinal(ctx->digestCtx, ctx->dgst, &dgstSize, sizeof(ctx->dgst));
             if(rv != SECSuccess) {
@@ -532,8 +532,8 @@ xmlSecNssHmacExecute(xmlSecTransformPtr transform, int last, xmlSecTransformCtxP
 
             /* check/set the result digest size */
             if(ctx->dgstSize == 0) {
-                ctx->dgstSize = dgstSize * 8; /* no dgst size specified, use all we have */
-            } else if(ctx->dgstSize <= 8 * dgstSize) {
+                ctx->dgstSize = XMLSEC_SIZE_BAD_CAST(dgstSize * 8); /* no dgst size specified, use all we have */
+            } else if(ctx->dgstSize <= XMLSEC_SIZE_BAD_CAST(8 * dgstSize)) {
                 dgstSize = ((ctx->dgstSize + 7) / 8); /* we need to truncate result digest */
             } else {
                 xmlSecError(XMLSEC_ERRORS_HERE,
diff --git a/src/openssl/app.c b/src/openssl/app.c
index a52f507..f46a4d9 100644
--- a/src/openssl/app.c
+++ b/src/openssl/app.c
@@ -236,7 +236,7 @@ xmlSecOpenSSLAppKeyLoadBIO(BIO* bio, xmlSecKeyDataFormat format,
         /* try to read private key first */
             pKey = PEM_read_bio_PrivateKey(bio, NULL,
             (pwd != NULL) ? xmlSecOpenSSLDummyPasswordCallback : (pem_password_cb*)pwdCallback,
-            (pwd != NULL) ? pwd : pwdCallbackCtx);
+            (pwd != NULL) ? (void*)pwd : pwdCallbackCtx);
         if(pKey == NULL) {
             /* go to start of the file and try to read public key */
             BIO_reset(bio);
diff --git a/src/openssl/digests.c b/src/openssl/digests.c
index ff1d49e..2dc3236 100644
--- a/src/openssl/digests.c
+++ b/src/openssl/digests.c
@@ -307,10 +307,12 @@ xmlSecOpenSSLEvpDigestExecute(xmlSecTransformPtr transform, int last, xmlSecTran
             }
         }
         if(last) {
+            unsigned int dgstSize;
+
             xmlSecAssert2((xmlSecSize)EVP_MD_size(ctx->digest) <= sizeof(ctx->dgst), -1);
 
 #ifndef XMLSEC_OPENSSL_096
-            ret = EVP_DigestFinal(&(ctx->digestCtx), ctx->dgst, &ctx->dgstSize);
+            ret = EVP_DigestFinal(&(ctx->digestCtx), ctx->dgst, &dgstSize);
             if(ret != 1) {
                 xmlSecError(XMLSEC_ERRORS_HERE,
                             xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
@@ -320,9 +322,10 @@ xmlSecOpenSSLEvpDigestExecute(xmlSecTransformPtr transform, int last, xmlSecTran
                 return(-1);
             }
 #else /* XMLSEC_OPENSSL_096 */
-            EVP_DigestFinal(&(ctx->digestCtx), ctx->dgst, &ctx->dgstSize);
+            EVP_DigestFinal(&(ctx->digestCtx), ctx->dgst, &dgstSize);
 #endif /* XMLSEC_OPENSSL_096 */
-            xmlSecAssert2(ctx->dgstSize > 0, -1);
+            xmlSecAssert2(dgstSize > 0, -1);
+            ctx->dgstSize = XMLSEC_SIZE_BAD_CAST(dgstSize);
 
             /* copy result to output */
             if(transform->operation == xmlSecTransformOperationSign) {
diff --git a/src/openssl/hmac.c b/src/openssl/hmac.c
index 423b868..6964a34 100644
--- a/src/openssl/hmac.c
+++ b/src/openssl/hmac.c
@@ -473,15 +473,15 @@ xmlSecOpenSSLHmacExecute(xmlSecTransformPtr transform, int last, xmlSecTransform
         }
 
         if(last) {
-            xmlSecSize dgstSize;
+            unsigned int dgstSize;
 
             HMAC_Final(&(ctx->hmacCtx), ctx->dgst, &dgstSize);
             xmlSecAssert2(dgstSize > 0, -1);
 
             /* check/set the result digest size */
             if(ctx->dgstSize == 0) {
-                ctx->dgstSize = dgstSize * 8; /* no dgst size specified, use all we have */
-            } else if(ctx->dgstSize <= 8 * dgstSize) {
+                ctx->dgstSize = XMLSEC_SIZE_BAD_CAST(dgstSize * 8); /* no dgst size specified, use all we have */
+            } else if(ctx->dgstSize <= XMLSEC_SIZE_BAD_CAST(8 * dgstSize)) {
                 dgstSize = ((ctx->dgstSize + 7) / 8); /* we need to truncate result digest */
             } else {
                 xmlSecError(XMLSEC_ERRORS_HERE,
diff --git a/src/openssl/signatures.c b/src/openssl/signatures.c
index 3d8c506..38f42b3 100644
--- a/src/openssl/signatures.c
+++ b/src/openssl/signatures.c
@@ -360,7 +360,8 @@ static int
 xmlSecOpenSSLEvpSignatureExecute(xmlSecTransformPtr transform, int last, xmlSecTransformCtxPtr transformCtx) {
     xmlSecOpenSSLEvpSignatureCtxPtr ctx;
     xmlSecBufferPtr in, out;
-    xmlSecSize inSize, outSize;
+    xmlSecSize inSize;
+    xmlSecSize outSize;
     int ret;
 
     xmlSecAssert2(xmlSecOpenSSLEvpSignatureCheckId(transform), -1);
@@ -463,27 +464,29 @@ xmlSecOpenSSLEvpSignatureExecute(xmlSecTransformPtr transform, int last, xmlSecT
     if((transform->status == xmlSecTransformStatusWorking) && (last != 0)) {
         xmlSecAssert2(outSize == 0, -1);
         if(transform->operation == xmlSecTransformOperationSign) {
+            unsigned int signSize;
+
             /* this is a hack: for rsa signatures
              * we get size from EVP_PKEY_size(),
              * for dsa signature we use a fixed constant */
-            outSize = EVP_PKEY_size(ctx->pKey);
+            signSize = EVP_PKEY_size(ctx->pKey);
 #ifndef XMLSEC_NO_DSA
-            if(outSize < XMLSEC_OPENSSL_DSA_SIGNATURE_SIZE) {
-                outSize = XMLSEC_OPENSSL_DSA_SIGNATURE_SIZE;
+            if(signSize < XMLSEC_OPENSSL_DSA_SIGNATURE_SIZE) {
+                signSize = XMLSEC_OPENSSL_DSA_SIGNATURE_SIZE;
             }
 #endif /* XMLSEC_NO_DSA */
 
-            ret = xmlSecBufferSetMaxSize(out, outSize);
+            ret = xmlSecBufferSetMaxSize(out, signSize);
             if(ret < 0) {
                 xmlSecError(XMLSEC_ERRORS_HERE,
                             xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
                             "xmlSecBufferSetMaxSize",
                             XMLSEC_ERRORS_R_XMLSEC_FAILED,
-                            "size=%d", outSize);
+                            "size=%u", signSize);
                 return(-1);
             }
 
-            ret = EVP_SignFinal(&(ctx->digestCtx), xmlSecBufferGetData(out), &outSize, ctx->pKey);
+            ret = EVP_SignFinal(&(ctx->digestCtx), xmlSecBufferGetData(out), &signSize, ctx->pKey);
             if(ret != 1) {
                 xmlSecError(XMLSEC_ERRORS_HERE,
                             xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
@@ -493,13 +496,13 @@ xmlSecOpenSSLEvpSignatureExecute(xmlSecTransformPtr transform, int last, xmlSecT
                 return(-1);
             }
 
-            ret = xmlSecBufferSetSize(out, outSize);
+            ret = xmlSecBufferSetSize(out, signSize);
             if(ret < 0) {
                 xmlSecError(XMLSEC_ERRORS_HERE,
                             xmlSecErrorsSafeString(xmlSecTransformGetName(transform)),
                             "xmlSecBufferSetSize",
                             XMLSEC_ERRORS_R_XMLSEC_FAILED,
-                            "size=%d", outSize);
+                            "size=%u", signSize);
                 return(-1);
             }
         }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]