diff -ur libgcrypt-1.5.2-orig/cipher/ecc.c libgcrypt-1.5.2/cipher/ecc.c
--- libgcrypt-1.5.2-orig/cipher/ecc.c	2013-04-18 10:48:42 -0400
+++ libgcrypt-1.5.2/cipher/ecc.c	2013-06-23 21:41:30 -0400
@@ -60,6 +60,10 @@
 #include "mpi.h"
 #include "cipher.h"
 
+#ifdef _MSC_VER
+# define snprintf _snprintf
+#endif
+
 /* Definition of a curve.  */
 typedef struct
 {
diff -ur libgcrypt-1.5.2-orig/cipher/md.c libgcrypt-1.5.2/cipher/md.c
--- libgcrypt-1.5.2-orig/cipher/md.c	2013-04-18 10:48:42 -0400
+++ libgcrypt-1.5.2/cipher/md.c	2013-06-23 21:41:30 -0400
@@ -30,6 +30,10 @@
 
 #include "rmd.h"
 
+#ifdef _MSC_VER
+# define snprintf _snprintf
+#endif
+
 /* A dummy extraspec so that we do not need to tests the extraspec
    field from the module specification against NULL and instead
    directly test the respective fields of extraspecs.  */
diff -ur libgcrypt-1.5.2-orig/cipher/pubkey.c libgcrypt-1.5.2/cipher/pubkey.c
--- libgcrypt-1.5.2-orig/cipher/pubkey.c	2013-04-18 10:48:42 -0400
+++ libgcrypt-1.5.2/cipher/pubkey.c	2013-06-23 21:41:30 -0400
@@ -29,6 +29,9 @@
 #include "cipher.h"
 #include "ath.h"
 
+#ifdef _MSC_VER
+#define snprintf _snprintf
+#endif
 
 static gcry_err_code_t pubkey_decrypt (int algo, gcry_mpi_t *result,
                                        gcry_mpi_t *data, gcry_mpi_t *skey,
diff -ur libgcrypt-1.5.2-orig/mpi/Makefile.in libgcrypt-1.5.2/mpi/Makefile.in
--- libgcrypt-1.5.2-orig/mpi/Makefile.in	2013-04-18 11:06:03 -0400
+++ libgcrypt-1.5.2/mpi/Makefile.in	2013-06-23 21:41:30 -0400
@@ -128,7 +128,7 @@
 am__mv = mv -f
 CPPASCOMPILE = $(CCAS) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
 	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CCASFLAGS) $(CCASFLAGS)
-LTCPPASCOMPILE = $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+LTCPPASCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
 	--mode=compile $(CCAS) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
 	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CCASFLAGS) $(CCASFLAGS)
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
diff -ur libgcrypt-1.5.2-orig/random/random-csprng.c libgcrypt-1.5.2/random/random-csprng.c
--- libgcrypt-1.5.2-orig/random/random-csprng.c	2013-04-18 10:48:42 -0400
+++ libgcrypt-1.5.2/random/random-csprng.c	2013-06-23 21:41:30 -0400
@@ -37,7 +37,6 @@
 #include <stdlib.h>
 #include <errno.h>
 #include <string.h>
-#include <sys/time.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
@@ -62,6 +61,12 @@
 #include "cipher.h" /* Required for the rmd160_hash_buffer() prototype.  */
 #include "ath.h"
 
+#ifdef _MSC_VER
+# define S_IRUSR _S_IREAD
+# define S_IWUSR _S_IWRITE
+# define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
+#endif
+
 #ifndef RAND_MAX   /* For SunOS. */
 #define RAND_MAX 32767
 #endif
diff -ur libgcrypt-1.5.2-orig/random/rndw32.c libgcrypt-1.5.2/random/rndw32.c
--- libgcrypt-1.5.2-orig/random/rndw32.c	2013-03-19 11:50:25 -0400
+++ libgcrypt-1.5.2/random/rndw32.c	2013-06-23 21:41:30 -0400
@@ -78,8 +78,13 @@
 #include <stdint.h>
 #endif
 
+#define WIN32_LEAN_AND_MEAN
 #include <windows.h>
+#include <winperf.h>
 
+#ifdef _MSC_VER
+# define snprintf _snprintf
+#endif
 
 #include "types.h"
 #include "g10lib.h"
diff -ur libgcrypt-1.5.2-orig/src/ath.c libgcrypt-1.5.2/src/ath.c
--- libgcrypt-1.5.2-orig/src/ath.c	2013-04-18 10:48:42 -0400
+++ libgcrypt-1.5.2/src/ath.c	2013-06-23 21:41:30 -0400
@@ -27,7 +27,9 @@
 #ifdef HAVE_SYS_SELECT_H
 # include <sys/select.h>
 #else
-# include <sys/time.h>
+# ifndef _MSC_VER
+#  include <sys/time.h>
+# endif
 #endif
 #include <sys/types.h>
 #ifndef _WIN32
diff -ur libgcrypt-1.5.2-orig/src/ath.h libgcrypt-1.5.2/src/ath.h
--- libgcrypt-1.5.2-orig/src/ath.h	2013-04-18 10:48:42 -0400
+++ libgcrypt-1.5.2/src/ath.h	2013-06-23 21:41:54 -0400
@@ -24,6 +24,7 @@
 #include <config.h>
 
 #ifdef _WIN32
+# define WIN32_LEAN_AND_MEAN
 # include <windows.h>
 #else /* !_WIN32 */
 # ifdef HAVE_SYS_SELECT_H
@@ -39,6 +40,9 @@
 #endif /* !_WIN32 */
 #include <gpg-error.h>
 
+#ifdef _MSC_VER
+typedef long ssize_t;
+#endif
 
 
 /* Define _ATH_EXT_SYM_PREFIX if you want to give all external symbols
diff -ur libgcrypt-1.5.2-orig/src/fips.c libgcrypt-1.5.2/src/fips.c
--- libgcrypt-1.5.2-orig/src/fips.c	2013-04-18 10:48:42 -0400
+++ libgcrypt-1.5.2/src/fips.c	2013-06-23 21:41:30 -0400
@@ -35,6 +35,10 @@
 #include "cipher-proto.h"
 #include "hmac256.h"
 
+#if defined(_MSC_VER) && !defined(F_OK)
+# define F_OK 0
+#endif
+
 
 /* The name of the file used to foce libgcrypt into fips mode. */
 #define FIPS_FORCE_FILE "/etc/gcrypt/fips_enabled"
diff -ur libgcrypt-1.5.2-orig/src/gcrypt.h.in libgcrypt-1.5.2/src/gcrypt.h.in
--- libgcrypt-1.5.2-orig/src/gcrypt.h.in	2013-04-18 10:48:42 -0400
+++ libgcrypt-1.5.2/src/gcrypt.h.in	2013-06-23 21:41:30 -0400
@@ -37,8 +37,12 @@
 # include <ws2tcpip.h>
 # include <time.h>
 # ifndef __GNUC__
-  typedef long ssize_t;
-  typedef int  pid_t;
+#  ifndef ssize_t
+   typedef long ssize_t;
+#  endif
+#  ifndef pid_t
+   typedef int  pid_t;
+#  endif
 # endif /*!__GNUC__*/
 #else
 # include <sys/socket.h>
diff -ur libgcrypt-1.5.2-orig/src/libgcrypt.def libgcrypt-1.5.2/src/libgcrypt.def
--- libgcrypt-1.5.2-orig/src/libgcrypt.def	2013-06-23 21:40:28 -0400
+++ libgcrypt-1.5.2/src/libgcrypt.def	2013-06-23 21:41:30 -0400
@@ -1,215 +1,193 @@
-EXPORTS
-      gcry_check_version  @1
-      gcry_control  @2
-
-      gcry_malloc  @3
-      gcry_calloc  @4
-      gcry_malloc_secure  @5
-      gcry_calloc_secure  @6
-      gcry_realloc  @7
-      gcry_strdup  @8
-      gcry_xmalloc  @9
-      gcry_xcalloc  @10
-      gcry_xmalloc_secure  @11
-      gcry_xcalloc_secure  @12
-      gcry_xrealloc  @13
-      gcry_xstrdup  @14
-      gcry_is_secure  @15
-      gcry_free  @16
-
-      gcry_set_progress_handler  @17
-      gcry_set_allocation_handler  @18
-      gcry_set_outofcore_handler  @19
-      gcry_set_fatalerror_handler  @20
-      gcry_set_log_handler  @21
-      gcry_set_gettext_handler  @22
-
-      gcry_strerror  @23
-      gcry_strsource  @24
-      gcry_err_code_from_errno  @25
-      gcry_err_code_to_errno  @26
-      gcry_err_make_from_errno  @27
-      gcry_error_from_errno  @28
-
-      gcry_sexp_new  @29
-      gcry_sexp_create  @30
-      gcry_sexp_sscan  @31
-      gcry_sexp_build  @32
-      gcry_sexp_build_array  @33
-      gcry_sexp_release  @34
-      gcry_sexp_canon_len  @35
-      gcry_sexp_sprint  @36
-      gcry_sexp_dump  @37
-      gcry_sexp_cons  @38
-      gcry_sexp_alist  @39
-      gcry_sexp_vlist  @40
-      gcry_sexp_append  @41
-      gcry_sexp_prepend  @42
-      gcry_sexp_find_token  @43
-      gcry_sexp_length  @44
-      gcry_sexp_nth  @45
-      gcry_sexp_car  @46
-      gcry_sexp_cdr  @47
-      gcry_sexp_cadr  @48
-      gcry_sexp_nth_data  @49
-      gcry_sexp_nth_mpi  @50
-
-      gcry_mpi_new  @51
-      gcry_mpi_snew  @52
-      gcry_mpi_release  @53
-      gcry_mpi_copy  @54
-      gcry_mpi_set  @55
-      gcry_mpi_set_ui  @56
-      gcry_mpi_swap  @57
-      gcry_mpi_cmp  @58
-      gcry_mpi_cmp_ui  @59
-      gcry_mpi_scan  @60
-      gcry_mpi_print  @61
-      gcry_mpi_aprint  @62
-      gcry_mpi_dump  @63
-      gcry_mpi_add  @64
-      gcry_mpi_add_ui  @65
-      gcry_mpi_addm  @66
-      gcry_mpi_sub  @67
-      gcry_mpi_sub_ui  @68
-      gcry_mpi_subm  @69
-      gcry_mpi_mul  @70
-      gcry_mpi_mul_ui  @71
-      gcry_mpi_mulm  @72
-      gcry_mpi_mul_2exp  @73
-      gcry_mpi_div  @74
-      gcry_mpi_mod  @75
-      gcry_mpi_powm  @76
-      gcry_mpi_gcd  @77
-      gcry_mpi_invm  @78
-      gcry_mpi_get_nbits  @79
-      gcry_mpi_test_bit  @80
-      gcry_mpi_set_bit  @81
-      gcry_mpi_clear_bit  @82
-      gcry_mpi_set_highbit  @83
-      gcry_mpi_clear_highbit  @84
-      gcry_mpi_rshift  @85
-      gcry_mpi_set_opaque  @86
-      gcry_mpi_get_opaque  @87
-      gcry_mpi_set_flag  @88
-      gcry_mpi_clear_flag  @89
-      gcry_mpi_get_flag  @90
-
-
-      gcry_cipher_open  @92
-      gcry_cipher_close  @93
-      gcry_cipher_ctl  @94
-      gcry_cipher_info  @95
-      gcry_cipher_algo_info  @96
-      gcry_cipher_algo_name  @97
-      gcry_cipher_map_name  @98
-      gcry_cipher_mode_from_oid  @99
-      gcry_cipher_encrypt  @100
-      gcry_cipher_decrypt  @101
-      gcry_cipher_get_algo_keylen  @102
-      gcry_cipher_get_algo_blklen  @103
-      gcry_cipher_list  @104
-
-      gcry_pk_encrypt  @105
-      gcry_pk_decrypt  @106
-      gcry_pk_sign  @107
-      gcry_pk_verify  @108
-      gcry_pk_testkey  @109
-      gcry_pk_genkey  @110
-      gcry_pk_ctl  @111
-      gcry_pk_algo_info  @112
-      gcry_pk_algo_name  @113
-      gcry_pk_map_name  @114
-      gcry_pk_get_nbits  @115
-      gcry_pk_get_keygrip  @116
-      gcry_pk_list  @117
-
-      gcry_ac_data_new  @118
-      gcry_ac_data_destroy  @119
-      gcry_ac_data_set  @120
-      gcry_ac_data_copy  @121
-      gcry_ac_data_length  @122
-      gcry_ac_data_get_name  @123
-      gcry_ac_data_get_index  @124
-      gcry_ac_data_clear  @125
-      gcry_ac_open  @126
-      gcry_ac_close  @127
-      gcry_ac_key_init  @128
-      gcry_ac_key_pair_generate  @129
-      gcry_ac_key_pair_extract  @130
-      gcry_ac_key_data_get  @131
-      gcry_ac_key_test  @132
-      gcry_ac_key_get_nbits  @133
-      gcry_ac_key_get_grip  @134
-      gcry_ac_key_destroy  @135
-      gcry_ac_key_pair_destroy  @136
-      gcry_ac_data_encrypt  @137
-      gcry_ac_data_decrypt  @138
-      gcry_ac_data_sign  @139
-      gcry_ac_data_verify  @140
-      gcry_ac_id_to_name  @141
-      gcry_ac_name_to_id  @142
-
-      gcry_md_open  @143
-      gcry_md_close  @144
-      gcry_md_enable  @145
-      gcry_md_copy  @146
-      gcry_md_reset  @147
-      gcry_md_ctl  @148
-      gcry_md_write  @149
-      gcry_md_read  @150
-      gcry_md_hash_buffer  @151
-      gcry_md_get_algo  @152
-      gcry_md_get_algo_dlen  @153
-      gcry_md_is_enabled  @154
-      gcry_md_is_secure  @155
-      gcry_md_info  @156
-      gcry_md_algo_info  @157
-      gcry_md_algo_name  @158
-      gcry_md_map_name  @159
-      gcry_md_setkey  @160
-      gcry_md_list  @161
-
-      gcry_randomize  @162
-      gcry_random_add_bytes  @163
-      gcry_random_bytes  @164
-      gcry_random_bytes_secure  @165
-      gcry_mpi_randomize  @166
-
-      gcry_prime_generate  @167
-      gcry_prime_group_generator  @168
-      gcry_prime_release_factors  @169
-      gcry_prime_check  @170
-
-      gcry_create_nonce  @171
-
-      gcry_md_debug  @172
-
-      gcry_cipher_register  @173
-      gcry_cipher_unregister @174
-      gcry_md_register  @175
-      gcry_md_unregister @176
-      gcry_pk_register  @177
-      gcry_pk_unregister @178
-
-      gcry_ac_data_from_sexp  @179
-      gcry_ac_data_to_sexp  @180
-      gcry_ac_io_init  @181
-      gcry_ac_io_init_va  @182
-      gcry_ac_data_encrypt_scheme  @183
-      gcry_ac_data_decrypt_scheme  @184
-      gcry_ac_data_sign_scheme  @185
-      gcry_ac_data_verify_scheme  @186
-
-      gcry_sexp_nth_string  @187
-
-      gcry_cipher_setkey    @188
-      gcry_cipher_setiv     @189
-      gcry_cipher_setctr    @190
-
-      gcry_mpi_lshift       @191
-
-      gcry_pk_get_curve     @192
-      gcry_pk_get_param     @193
-
-      gcry_kdf_derive       @194
+gcry_check_version
+gcry_control
+gcry_malloc
+gcry_calloc
+gcry_malloc_secure
+gcry_calloc_secure
+gcry_realloc
+gcry_strdup
+gcry_xmalloc
+gcry_xcalloc
+gcry_xmalloc_secure
+gcry_xcalloc_secure
+gcry_xrealloc
+gcry_xstrdup
+gcry_is_secure
+gcry_free
+gcry_set_progress_handler
+gcry_set_allocation_handler
+gcry_set_outofcore_handler
+gcry_set_fatalerror_handler
+gcry_set_log_handler
+gcry_set_gettext_handler
+gcry_strerror
+gcry_strsource
+gcry_err_code_from_errno
+gcry_err_code_to_errno
+gcry_err_make_from_errno
+gcry_error_from_errno
+gcry_sexp_new
+gcry_sexp_create
+gcry_sexp_sscan
+gcry_sexp_build
+gcry_sexp_build_array
+gcry_sexp_release
+gcry_sexp_canon_len
+gcry_sexp_sprint
+gcry_sexp_dump
+gcry_sexp_cons
+gcry_sexp_alist
+gcry_sexp_vlist
+gcry_sexp_append
+gcry_sexp_prepend
+gcry_sexp_find_token
+gcry_sexp_length
+gcry_sexp_nth
+gcry_sexp_car
+gcry_sexp_cdr
+gcry_sexp_cadr
+gcry_sexp_nth_data
+gcry_sexp_nth_mpi
+gcry_mpi_new
+gcry_mpi_snew
+gcry_mpi_release
+gcry_mpi_copy
+gcry_mpi_set
+gcry_mpi_set_ui
+gcry_mpi_swap
+gcry_mpi_cmp
+gcry_mpi_cmp_ui
+gcry_mpi_scan
+gcry_mpi_print
+gcry_mpi_aprint
+gcry_mpi_dump
+gcry_mpi_add
+gcry_mpi_add_ui
+gcry_mpi_addm
+gcry_mpi_sub
+gcry_mpi_sub_ui
+gcry_mpi_subm
+gcry_mpi_mul
+gcry_mpi_mul_ui
+gcry_mpi_mulm
+gcry_mpi_mul_2exp
+gcry_mpi_div
+gcry_mpi_mod
+gcry_mpi_powm
+gcry_mpi_gcd
+gcry_mpi_invm
+gcry_mpi_get_nbits
+gcry_mpi_test_bit
+gcry_mpi_set_bit
+gcry_mpi_clear_bit
+gcry_mpi_set_highbit
+gcry_mpi_clear_highbit
+gcry_mpi_rshift
+gcry_mpi_set_opaque
+gcry_mpi_get_opaque
+gcry_mpi_set_flag
+gcry_mpi_clear_flag
+gcry_mpi_get_flag
+gcry_cipher_open
+gcry_cipher_close
+gcry_cipher_ctl
+gcry_cipher_info
+gcry_cipher_algo_info
+gcry_cipher_algo_name
+gcry_cipher_map_name
+gcry_cipher_mode_from_oid
+gcry_cipher_encrypt
+gcry_cipher_decrypt
+gcry_cipher_get_algo_keylen
+gcry_cipher_get_algo_blklen
+gcry_cipher_list
+gcry_pk_encrypt
+gcry_pk_decrypt
+gcry_pk_sign
+gcry_pk_verify
+gcry_pk_testkey
+gcry_pk_genkey
+gcry_pk_ctl
+gcry_pk_algo_info
+gcry_pk_algo_name
+gcry_pk_map_name
+gcry_pk_get_nbits
+gcry_pk_get_keygrip
+gcry_pk_list
+gcry_ac_data_new
+gcry_ac_data_destroy
+gcry_ac_data_set
+gcry_ac_data_copy
+gcry_ac_data_length
+gcry_ac_data_get_name
+gcry_ac_data_get_index
+gcry_ac_data_clear
+gcry_ac_open
+gcry_ac_close
+gcry_ac_key_init
+gcry_ac_key_pair_generate
+gcry_ac_key_pair_extract
+gcry_ac_key_data_get
+gcry_ac_key_test
+gcry_ac_key_get_nbits
+gcry_ac_key_get_grip
+gcry_ac_key_destroy
+gcry_ac_key_pair_destroy
+gcry_ac_data_encrypt
+gcry_ac_data_decrypt
+gcry_ac_data_sign
+gcry_ac_data_verify
+gcry_ac_id_to_name
+gcry_ac_name_to_id
+gcry_md_open
+gcry_md_close
+gcry_md_enable
+gcry_md_copy
+gcry_md_reset
+gcry_md_ctl
+gcry_md_write
+gcry_md_read
+gcry_md_hash_buffer
+gcry_md_get_algo
+gcry_md_get_algo_dlen
+gcry_md_is_enabled
+gcry_md_is_secure
+gcry_md_info
+gcry_md_algo_info
+gcry_md_algo_name
+gcry_md_map_name
+gcry_md_setkey
+gcry_md_list
+gcry_randomize
+gcry_random_add_bytes
+gcry_random_bytes
+gcry_random_bytes_secure
+gcry_mpi_randomize
+gcry_prime_generate
+gcry_prime_group_generator
+gcry_prime_release_factors
+gcry_prime_check
+gcry_create_nonce
+gcry_md_debug
+gcry_cipher_register
+gcry_cipher_unregister
+gcry_md_register
+gcry_md_unregister
+gcry_pk_register
+gcry_pk_unregister
+gcry_ac_data_from_sexp
+gcry_ac_data_to_sexp
+gcry_ac_io_init
+gcry_ac_io_init_va
+gcry_ac_data_encrypt_scheme
+gcry_ac_data_decrypt_scheme
+gcry_ac_data_sign_scheme
+gcry_ac_data_verify_scheme
+gcry_sexp_nth_string
+gcry_cipher_setkey
+gcry_cipher_setiv
+gcry_cipher_setctr
+gcry_mpi_lshift
+gcry_pk_get_curve
+gcry_pk_get_param
+gcry_kdf_derive
diff -ur libgcrypt-1.5.2-orig/tests/benchmark.c libgcrypt-1.5.2/tests/benchmark.c
--- libgcrypt-1.5.2-orig/tests/benchmark.c	2013-04-18 10:48:42 -0400
+++ libgcrypt-1.5.2/tests/benchmark.c	2013-06-23 21:41:30 -0400
@@ -25,7 +25,11 @@
 #include <time.h>
 #include <stdarg.h>
 #ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
 #include <windows.h>
+#ifdef _MSC_VER
+#define snprintf _snprintf
+#endif
 #else
 #include <sys/times.h>
 #endif
diff -ur libgcrypt-1.5.2-orig/tests/fipsdrv.c libgcrypt-1.5.2/tests/fipsdrv.c
--- libgcrypt-1.5.2-orig/tests/fipsdrv.c	2013-03-19 11:50:25 -0400
+++ libgcrypt-1.5.2/tests/fipsdrv.c	2013-06-23 21:41:30 -0400
@@ -34,6 +34,10 @@
 #include <assert.h>
 #include <unistd.h>
 
+#if defined(_MSC_VER) && !defined(R_OK)
+# define R_OK 4
+#endif
+
 #ifdef _GCRYPT_IN_LIBGCRYPT
 # include "../src/gcrypt.h"
 #else
