#ifdef USE_GNUTLS_NETTLE
-static void MD5_Init(MD5_CTX *ctx)
+static int MD5_Init(MD5_CTX *ctx)
{
md5_init(ctx);
+ return 0;
}
static void MD5_Update(MD5_CTX *ctx,
md5_digest(ctx, 16, digest);
}
-static void SHA1_Init(SHA_CTX *ctx)
+static int SHA1_Init(SHA_CTX *ctx)
{
sha1_init(ctx);
+ return 0;
}
static void SHA1_Update(SHA_CTX *ctx,
sha1_digest(ctx, 20, digest);
}
-static void SHA256_Init(SHA256_CTX *ctx)
+static int SHA256_Init(SHA256_CTX *ctx)
{
sha256_init(ctx);
+ return 0;
}
static void SHA256_Update(SHA256_CTX *ctx,
#elif defined(USE_GNUTLS)
-static void MD5_Init(MD5_CTX *ctx)
+static int MD5_Init(MD5_CTX *ctx)
{
gcry_md_open(ctx, GCRY_MD_MD5, 0);
+ return 0;
}
static void MD5_Update(MD5_CTX *ctx,
gcry_md_close(*ctx);
}
-static void SHA1_Init(SHA_CTX *ctx)
+static int SHA1_Init(SHA_CTX *ctx)
{
gcry_md_open(ctx, GCRY_MD_SHA1, 0);
+ return 0;
}
static void SHA1_Update(SHA_CTX *ctx,
gcry_md_close(*ctx);
}
-static void SHA256_Init(SHA256_CTX *ctx)
+static int SHA256_Init(SHA256_CTX *ctx)
{
gcry_md_open(ctx, GCRY_MD_SHA256, 0);
+ return 0;
}
static void SHA256_Update(SHA256_CTX *ctx,
CryptReleaseContext(ctx->hCryptProv, 0);
}
-static void MD5_Init(MD5_CTX *ctx)
+static int MD5_Init(MD5_CTX *ctx)
{
if(CryptAcquireContext(&ctx->hCryptProv, NULL, NULL,
PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
CryptCreateHash(ctx->hCryptProv, CALG_MD5, 0, 0, &ctx->hHash);
}
+ return 0;
}
static void MD5_Update(MD5_CTX *ctx,
win32_crypto_final(ctx, digest, 16);
}
-static void SHA1_Init(SHA_CTX *ctx)
+static int SHA1_Init(SHA_CTX *ctx)
{
if(CryptAcquireContext(&ctx->hCryptProv, NULL, NULL,
PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
CryptCreateHash(ctx->hCryptProv, CALG_SHA1, 0, 0, &ctx->hHash);
}
+ return 0;
}
static void SHA1_Update(SHA_CTX *ctx,
win32_crypto_final(ctx, digest, 20);
}
-static void SHA256_Init(SHA256_CTX *ctx)
+static int SHA256_Init(SHA256_CTX *ctx)
{
if(CryptAcquireContext(&ctx->hCryptProv, NULL, NULL,
PROV_RSA_AES, CRYPT_VERIFYCONTEXT)) {
CryptCreateHash(ctx->hCryptProv, CALG_SHA_256, 0, 0, &ctx->hHash);
}
+ return 0;
}
static void SHA256_Update(SHA256_CTX *ctx,
ctxt->digest_hash = dparams;
- dparams->digest_init(ctxt->digest_hashctx);
+ if(dparams->digest_init(ctxt->digest_hashctx) != 0) {
+ free(ctxt);
+ return NULL;
+ }
return ctxt;
}
* Checksum didn't match.
* -1:
* Could not open file; or could not read data from file.
+ * -2:
+ * Hash algorithm not available.
*/
static int check_hash(const char *filename,
const metalink_digest_def *digest_def,
digest_def->hash_name, strerror(errno));
return -1;
}
+
dctx = Curl_digest_init(digest_def->dparams);
+ if(!dctx) {
+ fprintf(error, "Metalink: validating (%s) [%s] FAILED (%s)\n", filename,
+ digest_def->hash_name, "failed to initialize hash algorithm");
+ close(fd);
+ return -2;
+ }
+
result = malloc(digest_def->dparams->digest_resultlen);
while(1) {
unsigned char buf[4096];