Skip to content

Commit

Permalink
tool_metalink: Support polarssl as digest provider
Browse files Browse the repository at this point in the history
  • Loading branch information
mgorny authored and bagder committed Jun 16, 2014
1 parent b56dff7 commit c3c4fd2
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/tool_metalink.c
Expand Up @@ -55,6 +55,13 @@
# define SHA_CTX void *
# define SHA256_CTX void *
static NSSInitContext *nss_context;
#elif defined(USE_POLARSSL)
# include <polarssl/md5.h>
# include <polarssl/sha1.h>
# include <polarssl/sha256.h>
# define MD5_CTX md5_context
# define SHA_CTX sha1_context
# define SHA256_CTX sha256_context
#elif (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && \
(__MAC_OS_X_VERSION_MAX_ALLOWED >= 1040)) || \
(defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && \
Expand Down Expand Up @@ -318,6 +325,62 @@ static void SHA256_Final(unsigned char digest[32], SHA256_CTX *pctx)
nss_hash_final(pctx, digest, 32);
}

#elif defined(USE_POLARSSL)

static int MD5_Init(MD5_CTX *ctx)
{
md5_starts(ctx);
return 1;
}

static void MD5_Update(MD5_CTX *ctx,
const unsigned char *input,
unsigned int inputLen)
{
md5_update(ctx, input, inputLen);
}

static void MD5_Final(unsigned char digest[16], MD5_CTX *ctx)
{
md5_finish(ctx, digest);
}

static int SHA1_Init(SHA_CTX *ctx)
{
sha1_starts(ctx);
return 1;
}

static void SHA1_Update(SHA_CTX *ctx,
const unsigned char *input,
unsigned int inputLen)
{
sha1_update(ctx, input, inputLen);
}

static void SHA1_Final(unsigned char digest[20], SHA_CTX *ctx)
{
sha1_finish(ctx, digest);
}

static int SHA256_Init(SHA256_CTX *ctx)
{
sha256_starts(ctx, 0); /* 0 = sha256 */
return 1;
}

static void SHA256_Update(SHA256_CTX *ctx,
const unsigned char *input,
unsigned int inputLen)
{
sha256_update(ctx, input, inputLen);
}

static void SHA256_Final(unsigned char digest[32], SHA256_CTX *ctx)
{
sha256_finish(ctx, digest);
}

#elif defined(_WIN32) && !defined(USE_SSLEAY)

static void win32_crypto_final(struct win32_crypto_hash *ctx,
Expand Down

0 comments on commit c3c4fd2

Please sign in to comment.