]> granicus.if.org Git - curl/commitdiff
tool_metalink: fix error detection of hash alg initialization
authorKamil Dudka <kdudka@redhat.com>
Tue, 13 Nov 2012 12:09:43 +0000 (13:09 +0100)
committerKamil Dudka <kdudka@redhat.com>
Tue, 13 Nov 2012 12:17:45 +0000 (13:17 +0100)
The {MD5,SHA1,SHA256}_Init functions from OpenSSL are called directly
without any wrappers and they return 1 for success, 0 otherwise.  Hence,
we have to use the same approach in all the wrapper functions that are
used for the other crypto libraries.

This commit fixes a regression introduced in commit dca8ae5f.

src/tool_metalink.c
src/tool_metalink.h

index bf4bd107f161e1cab2cc396865aa2279d3540fb5..42b514ca3fc4ae3b42f9f499b1785de500086133 100644 (file)
@@ -124,7 +124,7 @@ struct win32_crypto_hash {
 static int MD5_Init(MD5_CTX *ctx)
 {
   md5_init(ctx);
-  return 0;
+  return 1;
 }
 
 static void MD5_Update(MD5_CTX *ctx,
@@ -142,7 +142,7 @@ static void MD5_Final(unsigned char digest[16], MD5_CTX *ctx)
 static int SHA1_Init(SHA_CTX *ctx)
 {
   sha1_init(ctx);
-  return 0;
+  return 1;
 }
 
 static void SHA1_Update(SHA_CTX *ctx,
@@ -160,7 +160,7 @@ static void SHA1_Final(unsigned char digest[20], SHA_CTX *ctx)
 static int SHA256_Init(SHA256_CTX *ctx)
 {
   sha256_init(ctx);
-  return 0;
+  return 1;
 }
 
 static void SHA256_Update(SHA256_CTX *ctx,
@@ -180,7 +180,7 @@ static void SHA256_Final(unsigned char digest[32], SHA256_CTX *ctx)
 static int MD5_Init(MD5_CTX *ctx)
 {
   gcry_md_open(ctx, GCRY_MD_MD5, 0);
-  return 0;
+  return 1;
 }
 
 static void MD5_Update(MD5_CTX *ctx,
@@ -199,7 +199,7 @@ static void MD5_Final(unsigned char digest[16], MD5_CTX *ctx)
 static int SHA1_Init(SHA_CTX *ctx)
 {
   gcry_md_open(ctx, GCRY_MD_SHA1, 0);
-  return 0;
+  return 1;
 }
 
 static void SHA1_Update(SHA_CTX *ctx,
@@ -218,7 +218,7 @@ static void SHA1_Final(unsigned char digest[20], SHA_CTX *ctx)
 static int SHA256_Init(SHA256_CTX *ctx)
 {
   gcry_md_open(ctx, GCRY_MD_SHA256, 0);
-  return 0;
+  return 1;
 }
 
 static void SHA256_Update(SHA256_CTX *ctx,
@@ -253,15 +253,15 @@ static int nss_hash_init(void **pctx, SECOidTag hash_alg)
 
   ctx = PK11_CreateDigestContext(hash_alg);
   if(!ctx)
-    return -1;
+    return /* failure */ 0;
 
   if(PK11_DigestBegin(ctx) != SECSuccess) {
     PK11_DestroyContext(ctx, PR_TRUE);
-    return -1;
+    return /* failure */ 0;
   }
 
   *pctx = ctx;
-  return 0;
+  return /* success */ 1;
 }
 
 static void nss_hash_final(void **pctx, unsigned char *out, unsigned int len)
@@ -345,7 +345,7 @@ static int MD5_Init(MD5_CTX *ctx)
                          PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
     CryptCreateHash(ctx->hCryptProv, CALG_MD5, 0, 0, &ctx->hHash);
   }
-  return 0;
+  return 1;
 }
 
 static void MD5_Update(MD5_CTX *ctx,
@@ -366,7 +366,7 @@ static int SHA1_Init(SHA_CTX *ctx)
                          PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
     CryptCreateHash(ctx->hCryptProv, CALG_SHA1, 0, 0, &ctx->hHash);
   }
-  return 0;
+  return 1;
 }
 
 static void SHA1_Update(SHA_CTX *ctx,
@@ -387,7 +387,7 @@ static int SHA256_Init(SHA256_CTX *ctx)
                          PROV_RSA_AES, CRYPT_VERIFYCONTEXT)) {
     CryptCreateHash(ctx->hCryptProv, CALG_SHA_256, 0, 0, &ctx->hHash);
   }
-  return 0;
+  return 1;
 }
 
 static void SHA256_Update(SHA256_CTX *ctx,
@@ -481,7 +481,7 @@ digest_context *Curl_digest_init(const digest_params *dparams)
 
   ctxt->digest_hash = dparams;
 
-  if(dparams->digest_init(ctxt->digest_hashctx) != 0) {
+  if(dparams->digest_init(ctxt->digest_hashctx) != 1) {
     free(ctxt);
     return NULL;
   }
index 3cb9461b6fede7cc7aa2ab802fee8147ae676610..0a69c459e6c8c29978e44f9215b9b2a5f9fd1f8e 100644 (file)
@@ -23,7 +23,9 @@
  ***************************************************************************/
 #include "tool_setup.h"
 
+/* returns 1 for success, 0 otherwise (we use OpenSSL *_Init fncs directly) */
 typedef int (* Curl_digest_init_func)(void *context);
+
 typedef void (* Curl_digest_update_func)(void *context,
                                          const unsigned char *data,
                                          unsigned int len);