]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Migrate message digest functions on Windows into archive_crypto.c and
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Sun, 28 Aug 2011 05:45:30 +0000 (01:45 -0400)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Sun, 28 Aug 2011 05:45:30 +0000 (01:45 -0400)
remove global function names, __la_hash_Init, __la_hash_Update and __la_hash_Final
since those are used only in archive_crypto.c.

SVN-Revision: 3660

libarchive/archive_crypto.c
libarchive/archive_crypto_private.h
libarchive/archive_windows.c

index 6513997acc21ca84ce6685622234001e5ddcc85f..427a40e9909d56f3563139112a6fb12a3b79b63f 100644 (file)
 #include "archive.h"
 #include "archive_crypto_private.h"
 
+/*
+ * Message digest functions for Windows platform.
+ */
+#if defined(ARCHIVE_CRYPTO_MD5_WIN)    ||\
+       defined(ARCHIVE_CRYPTO_SHA1_WIN)   ||\
+       defined(ARCHIVE_CRYPTO_SHA256_WIN) ||\
+       defined(ARCHIVE_CRYPTO_SHA384_WIN) ||\
+       defined(ARCHIVE_CRYPTO_SHA512_WIN)
+
+/*
+ * Initialize a Message digest.
+ */
+static int
+win_crypto_init(Digest_CTX *ctx, ALG_ID algId)
+{
+
+       ctx->valid = 0;
+       if (!CryptAcquireContext(&ctx->cryptProv, NULL, NULL,
+           PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
+               if (GetLastError() != (DWORD)NTE_BAD_KEYSET)
+                       return (ARCHIVE_FAILED);
+               if (!CryptAcquireContext(&ctx->cryptProv, NULL, NULL,
+                   PROV_RSA_FULL, CRYPT_NEWKEYSET))
+                       return (ARCHIVE_FAILED);
+       }
+
+       if (!CryptCreateHash(ctx->cryptProv, algId, 0, 0, &ctx->hash)) {
+               CryptReleaseContext(ctx->cryptProv, 0);
+               return (ARCHIVE_FAILED);
+       }
+
+       ctx->valid = 1;
+       return (ARCHIVE_OK);
+}
+
+/*
+ * Update a Message digest.
+ */
+static int
+win_crypto_Update(Digest_CTX *ctx, const unsigned char *buf, size_t len)
+{
+
+       if (!ctx->valid)
+               return (ARCHIVE_FAILED);
+
+       CryptHashData(ctx->hash,
+                     (unsigned char *)(uintptr_t)buf,
+                     (DWORD)len, 0);
+       return (ARCHIVE_OK);
+}
+
+static int
+win_crypto_Final(unsigned char *buf, size_t bufsize, Digest_CTX *ctx)
+{
+       DWORD siglen = bufsize;
+
+       if (!ctx->valid)
+               return (ARCHIVE_FAILED);
+
+       CryptGetHashParam(ctx->hash, HP_HASHVAL, buf, &siglen, 0);
+       CryptDestroyHash(ctx->hash);
+       CryptReleaseContext(ctx->cryptProv, 0);
+       ctx->valid = 0;
+       return (ARCHIVE_OK);
+}
+
+#endif /* defined(ARCHIVE_CRYPTO_*_WIN) */
+
+
 /* MD5 implementations */
 #if defined(ARCHIVE_CRYPTO_MD5_LIBC)
 
@@ -136,23 +205,20 @@ __archive_openssl_md5final(archive_md5_ctx *ctx, void *md)
 static int
 __archive_windowsapi_md5init(archive_md5_ctx *ctx)
 {
-  __la_hash_Init(ctx, CALG_MD5);
-  return (ARCHIVE_OK);
+  return (win_crypto_init(ctx, CALG_MD5));
 }
 
 static int
 __archive_windowsapi_md5update(archive_md5_ctx *ctx, const void *indata,
     size_t insize)
 {
-  __la_hash_Update(ctx, indata, insize);
-  return (ARCHIVE_OK);
+  return (win_crypto_Update(ctx, indata, insize));
 }
 
 static int
 __archive_windowsapi_md5final(archive_md5_ctx *ctx, void *md)
 {
-  __la_hash_Final(md, 16, ctx);
-  return (ARCHIVE_OK);
+  return (win_crypto_Final(md, 16, ctx));
 }
 
 #endif
@@ -339,23 +405,20 @@ __archive_openssl_sha1final(archive_sha1_ctx *ctx, void *md)
 static int
 __archive_windowsapi_sha1init(archive_sha1_ctx *ctx)
 {
-  __la_hash_Init(ctx, CALG_SHA1);
-  return (ARCHIVE_OK);
+  return (win_crypto_init(ctx, CALG_SHA1));
 }
 
 static int
 __archive_windowsapi_sha1update(archive_sha1_ctx *ctx, const void *indata,
     size_t insize)
 {
-  __la_hash_Update(ctx, indata, insize);
-  return (ARCHIVE_OK);
+  return (win_crypto_Update(ctx, indata, insize));
 }
 
 static int
 __archive_windowsapi_sha1final(archive_sha1_ctx *ctx, void *md)
 {
-  __la_hash_Final(md, 20, ctx);
-  return (ARCHIVE_OK);
+  return (win_crypto_Final(md, 20, ctx));
 }
 
 #endif
@@ -510,23 +573,20 @@ __archive_openssl_sha256final(archive_sha256_ctx *ctx, void *md)
 static int
 __archive_windowsapi_sha256init(archive_sha256_ctx *ctx)
 {
-  __la_hash_Init(ctx, CALG_SHA_256);
-  return (ARCHIVE_OK);
+  return (win_crypto_init(ctx, CALG_SHA_256));
 }
 
 static int
 __archive_windowsapi_sha256update(archive_sha256_ctx *ctx, const void *indata,
     size_t insize)
 {
-  __la_hash_Update(ctx, indata, insize);
-  return (ARCHIVE_OK);
+  return (win_crypto_Update(ctx, indata, insize));
 }
 
 static int
 __archive_windowsapi_sha256final(archive_sha256_ctx *ctx, void *md)
 {
-  __la_hash_Final(md, 32, ctx);
-  return (ARCHIVE_OK);
+  return (win_crypto_Final(md, 32, ctx));
 }
 
 #endif
@@ -681,23 +741,20 @@ __archive_openssl_sha384final(archive_sha384_ctx *ctx, void *md)
 static int
 __archive_windowsapi_sha384init(archive_sha384_ctx *ctx)
 {
-  __la_hash_Init(ctx, CALG_SHA_384);
-  return (ARCHIVE_OK);
+  return (win_crypto_init(ctx, CALG_SHA_384));
 }
 
 static int
 __archive_windowsapi_sha384update(archive_sha384_ctx *ctx, const void *indata,
     size_t insize)
 {
-  __la_hash_Update(ctx, indata, insize);
-  return (ARCHIVE_OK);
+  return (win_crypto_Update(ctx, indata, insize));
 }
 
 static int
 __archive_windowsapi_sha384final(archive_sha384_ctx *ctx, void *md)
 {
-  __la_hash_Final(md, 48, ctx);
-  return (ARCHIVE_OK);
+  return (win_crypto_Final(md, 48, ctx));
 }
 
 #endif
@@ -852,23 +909,20 @@ __archive_openssl_sha512final(archive_sha512_ctx *ctx, void *md)
 static int
 __archive_windowsapi_sha512init(archive_sha512_ctx *ctx)
 {
-  __la_hash_Init(ctx, CALG_SHA_512);
-  return (ARCHIVE_OK);
+  return (win_crypto_init(ctx, CALG_SHA_512));
 }
 
 static int
 __archive_windowsapi_sha512update(archive_sha512_ctx *ctx, const void *indata,
     size_t insize)
 {
-  __la_hash_Update(ctx, indata, insize);
-  return (ARCHIVE_OK);
+  return (win_crypto_Update(ctx, indata, insize));
 }
 
 static int
 __archive_windowsapi_sha512final(archive_sha512_ctx *ctx, void *md)
 {
-  __la_hash_Final(md, 64, ctx);
-  return (ARCHIVE_OK);
+  return (win_crypto_Final(md, 64, ctx));
 }
 
 #endif
index 8feb5cf9dbb2d0428ce562c97e281fec3370c08c..47d49cca61c875ae66fd53961f0a5431cba72e9c 100644 (file)
@@ -53,8 +53,7 @@
  * - MD5, SHA1 and SHA2 in libcrypto: with _ after algorithm name
  *
  * Windows:
- * - MD5, SHA1 and SHA2 in archive_windows.c: without algorithm name
- *   and with __la_ prefix.
+ * - MD5, SHA1 and SHA2 in archive_crypto.c using Windows crypto API
  */
 
 /* libc crypto headers */
@@ -122,9 +121,6 @@ typedef struct {
   HCRYPTPROV  cryptProv;
   HCRYPTHASH  hash;
 } Digest_CTX;
-extern void __la_hash_Init(Digest_CTX *, ALG_ID);
-extern void __la_hash_Final(unsigned char *, size_t, Digest_CTX *);
-extern void __la_hash_Update(Digest_CTX *, const unsigned char *, size_t);
 #endif
 
 /* typedefs */
index 20d7e9a7d5428d7d893fdea47391874722ff4b46..f61eb56a701003d6930d4660ce8f6c4bb6dce874 100644 (file)
@@ -754,72 +754,6 @@ __la_write(int fd, const void *buf, size_t nbytes)
 }
 
 
-/*
- * Message digest functions.
- *
- * Simulate the interface of OpenSSL's ones.
- *
- */
-#if defined(ARCHIVE_CRYPTO_MD5_WIN)    ||\
-       defined(ARCHIVE_CRYPTO_SHA1_WIN)   || defined(ARCHIVE_CRYPTO_SHA256_WIN) ||\
-       defined(ARCHIVE_CRYPTO_SHA384_WIN) || defined(ARCHIVE_CRYPTO_SHA512_WIN)
-
-/*
- * Initialize a Message digest.
- */
-void
-__la_hash_Init(Digest_CTX *ctx, ALG_ID algId)
-{
-
-       ctx->valid = 0;
-       if (!CryptAcquireContext(&ctx->cryptProv, NULL, NULL,
-           PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
-               if (GetLastError() != (DWORD)NTE_BAD_KEYSET)
-                       return;
-               if (!CryptAcquireContext(&ctx->cryptProv, NULL, NULL,
-                   PROV_RSA_FULL, CRYPT_NEWKEYSET))
-                       return;
-       }
-
-       if (!CryptCreateHash(ctx->cryptProv, algId, 0, 0, &ctx->hash)) {
-               CryptReleaseContext(ctx->cryptProv, 0);
-               return;
-       }
-
-       ctx->valid = 1;
-}
-
-/*
- * Update a Message digest.
- */
-void
-__la_hash_Update(Digest_CTX *ctx, const unsigned char *buf, size_t len)
-{
-
-       if (!ctx->valid)
-               return;
-
-       CryptHashData(ctx->hash,
-                     (unsigned char *)(uintptr_t)buf,
-                     (DWORD)len, 0);
-}
-
-void
-__la_hash_Final(unsigned char *buf, size_t bufsize, Digest_CTX *ctx)
-{
-       DWORD siglen = bufsize;
-
-       if (!ctx->valid)
-               return;
-
-       CryptGetHashParam(ctx->hash, HP_HASHVAL, buf, &siglen, 0);
-       CryptDestroyHash(ctx->hash);
-       CryptReleaseContext(ctx->cryptProv, 0);
-       ctx->valid = 0;
-}
-
-#endif /* defined(ARCHIVE_HASH_*_WIN) */
-
 /*
  * Create a temporary file.
  *