Remove string.h from base.h.

Including string.h in base.h causes any file that includes a BoringSSL
header to include string.h. Generally this wouldn't be a problem,
although string.h might slow down the compile if it wasn't otherwise
needed. However, it also causes problems for ipsec-tools in Android
because OpenSSL didn't have this behaviour.

This change removes string.h from base.h and, instead, adds it to each
.c file that requires it.

Change-Id: I5968e50b0e230fd3adf9b72dd2836e6f52d6fb37
Reviewed-on: https://boringssl-review.googlesource.com/3200
Reviewed-by: David Benjamin <davidben@chromium.org>
Reviewed-by: Adam Langley <agl@google.com>
diff --git a/crypto/asn1/a_bitstr.c b/crypto/asn1/a_bitstr.c
index 5038455..8055f0c 100644
--- a/crypto/asn1/a_bitstr.c
+++ b/crypto/asn1/a_bitstr.c
@@ -56,9 +56,12 @@
 
 #include <openssl/asn1.h>
 
+#include <string.h>
+
 #include <openssl/err.h>
 #include <openssl/mem.h>
 
+
 int ASN1_BIT_STRING_set(ASN1_BIT_STRING *x, unsigned char *d, int len)
 { return M_ASN1_BIT_STRING_set(x, d, len); }
 
diff --git a/crypto/asn1/a_bytes.c b/crypto/asn1/a_bytes.c
index b9dd816..8874f48 100644
--- a/crypto/asn1/a_bytes.c
+++ b/crypto/asn1/a_bytes.c
@@ -56,6 +56,8 @@
 
 #include <openssl/asn1.h>
 
+#include <string.h>
+
 #include <openssl/buf.h>
 #include <openssl/err.h>
 #include <openssl/mem.h>
diff --git a/crypto/asn1/a_enum.c b/crypto/asn1/a_enum.c
index d6d237a..a581a34 100644
--- a/crypto/asn1/a_enum.c
+++ b/crypto/asn1/a_enum.c
@@ -56,6 +56,8 @@
 
 #include <openssl/asn1.h>
 
+#include <string.h>
+
 #include <openssl/err.h>
 #include <openssl/mem.h>
 
diff --git a/crypto/asn1/a_gentm.c b/crypto/asn1/a_gentm.c
index b5bddb8..355feff 100644
--- a/crypto/asn1/a_gentm.c
+++ b/crypto/asn1/a_gentm.c
@@ -56,6 +56,8 @@
 
 #include <openssl/asn1.h>
 
+#include <string.h>
+
 #include <openssl/err.h>
 #include <openssl/mem.h>
 #include <openssl/time_support.h>
diff --git a/crypto/asn1/a_int.c b/crypto/asn1/a_int.c
index 6d7e225..eb0887a 100644
--- a/crypto/asn1/a_int.c
+++ b/crypto/asn1/a_int.c
@@ -56,6 +56,8 @@
 
 #include <openssl/asn1.h>
 
+#include <string.h>
+
 #include <openssl/err.h>
 #include <openssl/mem.h>
 
diff --git a/crypto/asn1/a_mbstr.c b/crypto/asn1/a_mbstr.c
index 007f0e1..9abe659 100644
--- a/crypto/asn1/a_mbstr.c
+++ b/crypto/asn1/a_mbstr.c
@@ -56,6 +56,8 @@
 
 #include <openssl/asn1.h>
 
+#include <string.h>
+
 #include <openssl/err.h>
 #include <openssl/mem.h>
 
diff --git a/crypto/asn1/a_object.c b/crypto/asn1/a_object.c
index 16d5e79..189886c 100644
--- a/crypto/asn1/a_object.c
+++ b/crypto/asn1/a_object.c
@@ -57,6 +57,7 @@
 #include <openssl/asn1.h>
 
 #include <limits.h>
+#include <string.h>
 
 #include <openssl/err.h>
 #include <openssl/mem.h>
diff --git a/crypto/asn1/a_strnid.c b/crypto/asn1/a_strnid.c
index e61de70..df849e1 100644
--- a/crypto/asn1/a_strnid.c
+++ b/crypto/asn1/a_strnid.c
@@ -57,6 +57,7 @@
 #include <openssl/asn1.h>
 
 #include <stdlib.h>  /* For bsearch */
+#include <string.h>
 
 #include <openssl/err.h>
 #include <openssl/mem.h>
diff --git a/crypto/asn1/a_time.c b/crypto/asn1/a_time.c
index 4786024..f0badcc 100644
--- a/crypto/asn1/a_time.c
+++ b/crypto/asn1/a_time.c
@@ -56,6 +56,8 @@
 
 #include <openssl/asn1.h>
 
+#include <string.h>
+
 #include <openssl/asn1t.h>
 #include <openssl/buf.h>
 #include <openssl/err.h>
diff --git a/crypto/asn1/a_utctm.c b/crypto/asn1/a_utctm.c
index cb29d4c..7a3f5f6 100644
--- a/crypto/asn1/a_utctm.c
+++ b/crypto/asn1/a_utctm.c
@@ -56,6 +56,8 @@
 
 #include <openssl/asn1.h>
 
+#include <string.h>
+
 #include <openssl/err.h>
 #include <openssl/mem.h>
 #include <openssl/time_support.h>
diff --git a/crypto/asn1/asn1_lib.c b/crypto/asn1/asn1_lib.c
index 83816c9..1fc2c06 100644
--- a/crypto/asn1/asn1_lib.c
+++ b/crypto/asn1/asn1_lib.c
@@ -57,6 +57,7 @@
 #include <openssl/asn1.h>
 
 #include <limits.h>
+#include <string.h>
 
 #include <openssl/asn1_mac.h>
 #include <openssl/err.h>
diff --git a/crypto/asn1/bio_asn1.c b/crypto/asn1/bio_asn1.c
index faea304..15f233b 100644
--- a/crypto/asn1/bio_asn1.c
+++ b/crypto/asn1/bio_asn1.c
@@ -57,6 +57,7 @@
 #include <openssl/asn1.h>
 
 #include <assert.h>
+#include <string.h>
 
 #include <openssl/bio.h>
 #include <openssl/mem.h>
diff --git a/crypto/asn1/t_bitst.c b/crypto/asn1/t_bitst.c
index cc2c50b..1ca6e08 100644
--- a/crypto/asn1/t_bitst.c
+++ b/crypto/asn1/t_bitst.c
@@ -56,6 +56,8 @@
 
 #include <openssl/asn1.h>
 
+#include <string.h>
+
 #include <openssl/mem.h>
 
 
diff --git a/crypto/asn1/tasn_dec.c b/crypto/asn1/tasn_dec.c
index e8c5cd8..4cece89 100644
--- a/crypto/asn1/tasn_dec.c
+++ b/crypto/asn1/tasn_dec.c
@@ -56,6 +56,8 @@
 
 #include <openssl/asn1.h>
 
+#include <string.h>
+
 #include <openssl/asn1t.h>
 #include <openssl/buf.h>
 #include <openssl/err.h>
diff --git a/crypto/asn1/tasn_enc.c b/crypto/asn1/tasn_enc.c
index 54f784a..38e14d2 100644
--- a/crypto/asn1/tasn_enc.c
+++ b/crypto/asn1/tasn_enc.c
@@ -56,6 +56,8 @@
 
 #include <openssl/asn1.h>
 
+#include <string.h>
+
 #include <openssl/asn1t.h>
 #include <openssl/mem.h>
 
diff --git a/crypto/asn1/tasn_new.c b/crypto/asn1/tasn_new.c
index 8a2b27d..b68eed7 100644
--- a/crypto/asn1/tasn_new.c
+++ b/crypto/asn1/tasn_new.c
@@ -56,6 +56,8 @@
 
 #include <openssl/asn1.h>
 
+#include <string.h>
+
 #include <openssl/asn1t.h>
 #include <openssl/err.h>
 #include <openssl/mem.h>
diff --git a/crypto/asn1/tasn_utl.c b/crypto/asn1/tasn_utl.c
index 250975a..f6045e4 100644
--- a/crypto/asn1/tasn_utl.c
+++ b/crypto/asn1/tasn_utl.c
@@ -56,6 +56,8 @@
 
 #include <openssl/asn1.h>
 
+#include <string.h>
+
 #include <openssl/asn1t.h>
 #include <openssl/mem.h>
 #include <openssl/obj.h>
diff --git a/crypto/asn1/x_long.c b/crypto/asn1/x_long.c
index a3f80ab..5c2f96e 100644
--- a/crypto/asn1/x_long.c
+++ b/crypto/asn1/x_long.c
@@ -56,6 +56,8 @@
 
 #include <openssl/asn1.h>
 
+#include <string.h>
+
 #include <openssl/asn1t.h>
 #include <openssl/bn.h>
 #include <openssl/err.h>
diff --git a/crypto/base64/base64.c b/crypto/base64/base64.c
index 5fe23a5..12a52cf 100644
--- a/crypto/base64/base64.c
+++ b/crypto/base64/base64.c
@@ -58,6 +58,7 @@
 
 #include <assert.h>
 #include <limits.h>
+#include <string.h>
 
 
 static const unsigned char data_bin2ascii[65] =
diff --git a/crypto/bio/bio.c b/crypto/bio/bio.c
index 7bd2976..4d947a6 100644
--- a/crypto/bio/bio.c
+++ b/crypto/bio/bio.c
@@ -57,8 +57,9 @@
 #include <openssl/bio.h>
 
 #include <errno.h>
-#include <stddef.h>
 #include <limits.h>
+#include <stddef.h>
+#include <string.h>
 
 #include <openssl/err.h>
 #include <openssl/mem.h>
diff --git a/crypto/bio/bio_mem.c b/crypto/bio/bio_mem.c
index 6e90db5..f3aad6f 100644
--- a/crypto/bio/bio_mem.c
+++ b/crypto/bio/bio_mem.c
@@ -57,6 +57,7 @@
 #include <openssl/bio.h>
 
 #include <limits.h>
+#include <string.h>
 
 #include <openssl/buf.h>
 #include <openssl/err.h>
diff --git a/crypto/bio/buffer.c b/crypto/bio/buffer.c
index 415a471..5e423a1 100644
--- a/crypto/bio/buffer.c
+++ b/crypto/bio/buffer.c
@@ -56,6 +56,8 @@
 
 #include <openssl/bio.h>
 
+#include <string.h>
+
 #include <openssl/buf.h>
 #include <openssl/err.h>
 #include <openssl/mem.h>
diff --git a/crypto/bio/connect.c b/crypto/bio/connect.c
index ef1f14d..66ac3a7 100644
--- a/crypto/bio/connect.c
+++ b/crypto/bio/connect.c
@@ -59,6 +59,7 @@
 #include <assert.h>
 #include <errno.h>
 #include <stdio.h>
+#include <string.h>
 
 #if !defined(OPENSSL_WINDOWS)
 #include <sys/socket.h>
diff --git a/crypto/bio/fd.c b/crypto/bio/fd.c
index c54647c..6b70eac 100644
--- a/crypto/bio/fd.c
+++ b/crypto/bio/fd.c
@@ -57,6 +57,7 @@
 #include <openssl/bio.h>
 
 #include <errno.h>
+#include <string.h>
 
 #if !defined(OPENSSL_WINDOWS)
 #include <unistd.h>
diff --git a/crypto/bio/file.c b/crypto/bio/file.c
index e1a67ca..7f57aad 100644
--- a/crypto/bio/file.c
+++ b/crypto/bio/file.c
@@ -76,6 +76,7 @@
 
 #include <errno.h>
 #include <stdio.h>
+#include <string.h>
 
 #include <openssl/buf.h>
 #include <openssl/err.h>
diff --git a/crypto/bio/hexdump.c b/crypto/bio/hexdump.c
index 61a2673..17f5518 100644
--- a/crypto/bio/hexdump.c
+++ b/crypto/bio/hexdump.c
@@ -57,6 +57,7 @@
 #include <openssl/bio.h>
 
 #include <limits.h>
+#include <string.h>
 
 
 /* hexdump_ctx contains the state of a hexdump. */
diff --git a/crypto/bio/pair.c b/crypto/bio/pair.c
index fe6a275..de2b4cb 100644
--- a/crypto/bio/pair.c
+++ b/crypto/bio/pair.c
@@ -53,6 +53,7 @@
 #include <openssl/bio.h>
 
 #include <assert.h>
+#include <string.h>
 
 #include <openssl/buf.h>
 #include <openssl/err.h>
diff --git a/crypto/bio/socket.c b/crypto/bio/socket.c
index 671a046..590447f 100644
--- a/crypto/bio/socket.c
+++ b/crypto/bio/socket.c
@@ -58,6 +58,7 @@
 #include <openssl/bio.h>
 
 #include <fcntl.h>
+#include <string.h>
 
 #if !defined(OPENSSL_WINDOWS)
 #include <unistd.h>
diff --git a/crypto/bio/socket_helper.c b/crypto/bio/socket_helper.c
index 3fb806e..52e1606 100644
--- a/crypto/bio/socket_helper.c
+++ b/crypto/bio/socket_helper.c
@@ -18,6 +18,7 @@
 #include <openssl/err.h>
 
 #include <fcntl.h>
+#include <string.h>
 #include <sys/types.h>
 
 #if !defined(OPENSSL_WINDOWS)
diff --git a/crypto/bn/bn.c b/crypto/bn/bn.c
index a996a47..368c4f1 100644
--- a/crypto/bn/bn.c
+++ b/crypto/bn/bn.c
@@ -57,6 +57,8 @@
 #include <openssl/bn.h>
 
 #include <limits.h>
+#include <string.h>
+
 #include <openssl/err.h>
 #include <openssl/mem.h>
 
diff --git a/crypto/bn/bn_test.c b/crypto/bn/bn_test.c
index 0fa5155..e342ed8 100644
--- a/crypto/bn/bn_test.c
+++ b/crypto/bn/bn_test.c
@@ -68,6 +68,7 @@
  * Laboratories. */
 
 #include <stdio.h>
+#include <string.h>
 
 #include <openssl/bio.h>
 #include <openssl/bn.h>
@@ -77,6 +78,7 @@
 
 #include "internal.h"
 
+
 static const int num0 = 100; /* number of tests */
 static const int num1 = 50;  /* additional tests for some functions */
 static const int num2 = 5;   /* number of tests for slow functions */
diff --git a/crypto/bn/convert.c b/crypto/bn/convert.c
index 1ba7cb6..f764eed 100644
--- a/crypto/bn/convert.c
+++ b/crypto/bn/convert.c
@@ -58,6 +58,7 @@
 
 #include <ctype.h>
 #include <stdio.h>
+#include <string.h>
 
 #include <openssl/bio.h>
 #include <openssl/err.h>
diff --git a/crypto/bn/ctx.c b/crypto/bn/ctx.c
index a89f87d..e54007b 100644
--- a/crypto/bn/ctx.c
+++ b/crypto/bn/ctx.c
@@ -54,6 +54,8 @@
 
 #include <openssl/bn.h>
 
+#include <string.h>
+
 #include <openssl/err.h>
 #include <openssl/mem.h>
 
diff --git a/crypto/bn/exponentiation.c b/crypto/bn/exponentiation.c
index afc4287..53f3e9c 100644
--- a/crypto/bn/exponentiation.c
+++ b/crypto/bn/exponentiation.c
@@ -109,6 +109,7 @@
 #include <openssl/bn.h>
 
 #include <assert.h>
+#include <string.h>
 
 #include <openssl/cpu.h>
 #include <openssl/err.h>
diff --git a/crypto/bn/montgomery.c b/crypto/bn/montgomery.c
index ddd2b26..65e177c 100644
--- a/crypto/bn/montgomery.c
+++ b/crypto/bn/montgomery.c
@@ -108,6 +108,8 @@
 
 #include <openssl/bn.h>
 
+#include <string.h>
+
 #include <openssl/mem.h>
 #include <openssl/thread.h>
 
diff --git a/crypto/bn/mul.c b/crypto/bn/mul.c
index 54b2083..80c6288 100644
--- a/crypto/bn/mul.c
+++ b/crypto/bn/mul.c
@@ -57,6 +57,7 @@
 #include <openssl/bn.h>
 
 #include <assert.h>
+#include <string.h>
 
 #include "internal.h"
 
diff --git a/crypto/bn/random.c b/crypto/bn/random.c
index 85fd447..285bf26 100644
--- a/crypto/bn/random.c
+++ b/crypto/bn/random.c
@@ -108,6 +108,8 @@
 
 #include <openssl/bn.h>
 
+#include <string.h>
+
 #include <openssl/err.h>
 #include <openssl/mem.h>
 #include <openssl/rand.h>
diff --git a/crypto/bn/shift.c b/crypto/bn/shift.c
index 384a697..1e3b7c3 100644
--- a/crypto/bn/shift.c
+++ b/crypto/bn/shift.c
@@ -56,8 +56,11 @@
 
 #include <openssl/bn.h>
 
+#include <string.h>
+
 #include "internal.h"
 
+
 int BN_lshift(BIGNUM *r, const BIGNUM *a, int n) {
   int i, nw, lb, rb;
   BN_ULONG *t, *f;
diff --git a/crypto/buf/buf.c b/crypto/buf/buf.c
index 3fd822e..5769e77 100644
--- a/crypto/buf/buf.c
+++ b/crypto/buf/buf.c
@@ -56,6 +56,8 @@
 
 #include <openssl/buf.h>
 
+#include <string.h>
+
 #include <openssl/mem.h>
 #include <openssl/err.h>
 
diff --git a/crypto/bytestring/ber.c b/crypto/bytestring/ber.c
index b5b373d..2729fa1 100644
--- a/crypto/bytestring/ber.c
+++ b/crypto/bytestring/ber.c
@@ -14,6 +14,8 @@
 
 #include <openssl/bytestring.h>
 
+#include <string.h>
+
 #include "internal.h"
 
 
diff --git a/crypto/bytestring/bytestring_test.c b/crypto/bytestring/bytestring_test.c
index ba70bcf..cd0155e 100644
--- a/crypto/bytestring/bytestring_test.c
+++ b/crypto/bytestring/bytestring_test.c
@@ -14,6 +14,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include <openssl/crypto.h>
 #include <openssl/bytestring.h>
diff --git a/crypto/bytestring/cbb.c b/crypto/bytestring/cbb.c
index f8e1070..4428836 100644
--- a/crypto/bytestring/cbb.c
+++ b/crypto/bytestring/cbb.c
@@ -15,6 +15,7 @@
 #include <openssl/bytestring.h>
 
 #include <assert.h>
+#include <string.h>
 
 #include <openssl/mem.h>
 
diff --git a/crypto/chacha/chacha_generic.c b/crypto/chacha/chacha_generic.c
index 3e73d8e..31cf4f0 100644
--- a/crypto/chacha/chacha_generic.c
+++ b/crypto/chacha/chacha_generic.c
@@ -16,8 +16,11 @@
 
 #include <openssl/chacha.h>
 
+#include <string.h>
+
 #include <openssl/cpu.h>
 
+
 #if defined(OPENSSL_WINDOWS) || (!defined(OPENSSL_X86_64) && !defined(OPENSSL_X86)) || !defined(__SSE2__)
 
 /* sigma contains the ChaCha constants, which happen to be an ASCII string. */
diff --git a/crypto/cipher/cipher_test.c b/crypto/cipher/cipher_test.c
index b91b505..2b04ad5 100644
--- a/crypto/cipher/cipher_test.c
+++ b/crypto/cipher/cipher_test.c
@@ -55,6 +55,7 @@
  * [including the GNU Public Licence.] */
 
 #include <stdio.h>
+#include <string.h>
 
 #include <openssl/bio.h>
 #include <openssl/cipher.h>
diff --git a/crypto/cipher/e_aes.c b/crypto/cipher/e_aes.c
index 5537659..f92bb8e 100644
--- a/crypto/cipher/e_aes.c
+++ b/crypto/cipher/e_aes.c
@@ -46,6 +46,8 @@
  * OF THE POSSIBILITY OF SUCH DAMAGE.
  * ==================================================================== */
 
+#include <string.h>
+
 #include <openssl/aead.h>
 #include <openssl/aes.h>
 #include <openssl/cipher.h>
diff --git a/crypto/cipher/e_chacha20poly1305.c b/crypto/cipher/e_chacha20poly1305.c
index 5c24717..1cdcbca 100644
--- a/crypto/cipher/e_chacha20poly1305.c
+++ b/crypto/cipher/e_chacha20poly1305.c
@@ -14,6 +14,8 @@
 
 #include <openssl/aead.h>
 
+#include <string.h>
+
 #include <openssl/chacha.h>
 #include <openssl/cipher.h>
 #include <openssl/err.h>
diff --git a/crypto/cipher/e_null.c b/crypto/cipher/e_null.c
index 196520d..cfe1d1b 100644
--- a/crypto/cipher/e_null.c
+++ b/crypto/cipher/e_null.c
@@ -56,6 +56,8 @@
 
 #include <openssl/cipher.h>
 
+#include <string.h>
+
 #include <openssl/obj.h>
 
 #include "internal.h"
diff --git a/crypto/cipher/e_rc4.c b/crypto/cipher/e_rc4.c
index 7f98884..04ddcb6 100644
--- a/crypto/cipher/e_rc4.c
+++ b/crypto/cipher/e_rc4.c
@@ -57,6 +57,7 @@
 #include <openssl/aead.h>
 
 #include <assert.h>
+#include <string.h>
 
 #include <openssl/cipher.h>
 #include <openssl/cpu.h>
diff --git a/crypto/cipher/tls_cbc.c b/crypto/cipher/tls_cbc.c
index 73952e5..8bca2f3 100644
--- a/crypto/cipher/tls_cbc.c
+++ b/crypto/cipher/tls_cbc.c
@@ -51,6 +51,7 @@
  * Hudson (tjh@cryptsoft.com). */
 
 #include <assert.h>
+#include <string.h>
 
 #include <openssl/digest.h>
 #include <openssl/obj.h>
diff --git a/crypto/cpu-intel.c b/crypto/cpu-intel.c
index 3f65e74..69f4570 100644
--- a/crypto/cpu-intel.c
+++ b/crypto/cpu-intel.c
@@ -63,8 +63,9 @@
 
 #if !defined(OPENSSL_NO_ASM) && (defined(OPENSSL_X86) || defined(OPENSSL_X86_64))
 
-#include <stdio.h>
 #include <inttypes.h>
+#include <stdio.h>
+#include <string.h>
 
 /* OPENSSL_ia32_cpuid is defined in cpu-x86_64-asm.pl. */
 extern uint64_t OPENSSL_ia32_cpuid(uint32_t*);
diff --git a/crypto/dh/dh.c b/crypto/dh/dh.c
index cee306b..7a50da7 100644
--- a/crypto/dh/dh.c
+++ b/crypto/dh/dh.c
@@ -56,6 +56,8 @@
 
 #include <openssl/dh.h>
 
+#include <string.h>
+
 #include <openssl/bn.h>
 #include <openssl/buf.h>
 #include <openssl/err.h>
diff --git a/crypto/dh/dh_test.c b/crypto/dh/dh_test.c
index 31b3dd9..3575f34 100644
--- a/crypto/dh/dh_test.c
+++ b/crypto/dh/dh_test.c
@@ -57,6 +57,7 @@
 #include <openssl/dh.h>
 
 #include <stdio.h>
+#include <string.h>
 
 #include <openssl/bio.h>
 #include <openssl/bn.h>
diff --git a/crypto/digest/md32_common.h b/crypto/digest/md32_common.h
index 51508a6..a4ce355 100644
--- a/crypto/digest/md32_common.h
+++ b/crypto/digest/md32_common.h
@@ -51,6 +51,8 @@
 
 #include <openssl/base.h>
 
+#include <string.h>
+
 
 #if defined(__cplusplus)
 extern "C" {
diff --git a/crypto/directory_posix.c b/crypto/directory_posix.c
index 695e964..c16701d 100644
--- a/crypto/directory_posix.c
+++ b/crypto/directory_posix.c
@@ -35,6 +35,7 @@
 
 #include <dirent.h>
 #include <errno.h>
+#include <string.h>
 
 #if defined(OPENSSL_PNACL)
 /* pnacl doesn't include readdir_r! So we do the best we can. */
diff --git a/crypto/directory_win.c b/crypto/directory_win.c
index 9415f1d..2e4600f 100644
--- a/crypto/directory_win.c
+++ b/crypto/directory_win.c
@@ -33,8 +33,9 @@
 #pragma warning(push, 3)
 #include <windows.h>
 #pragma warning(pop)
-#include <tchar.h>
 #include <errno.h>
+#include <string.h>
+#include <tchar.h>
 
 #ifndef NAME_MAX
 #define NAME_MAX 255
diff --git a/crypto/dsa/dsa.c b/crypto/dsa/dsa.c
index cbd36be..8816b63 100644
--- a/crypto/dsa/dsa.c
+++ b/crypto/dsa/dsa.c
@@ -59,6 +59,8 @@
 
 #include <openssl/dsa.h>
 
+#include <string.h>
+
 #include <openssl/asn1.h>
 #include <openssl/dh.h>
 #include <openssl/engine.h>
@@ -68,6 +70,7 @@
 
 #include "internal.h"
 
+
 extern const DSA_METHOD DSA_default_method;
 
 DSA *DSA_new(void) { return DSA_new_method(NULL); }
diff --git a/crypto/dsa/dsa_asn1.c b/crypto/dsa/dsa_asn1.c
index 72b2cc6..933fba7 100644
--- a/crypto/dsa/dsa_asn1.c
+++ b/crypto/dsa/dsa_asn1.c
@@ -54,6 +54,8 @@
 
 #include <openssl/dsa.h>
 
+#include <string.h>
+
 #include <openssl/asn1.h>
 #include <openssl/asn1t.h>
 #include <openssl/err.h>
diff --git a/crypto/dsa/dsa_impl.c b/crypto/dsa/dsa_impl.c
index fd027b0..6719758 100644
--- a/crypto/dsa/dsa_impl.c
+++ b/crypto/dsa/dsa_impl.c
@@ -59,6 +59,8 @@
 
 #include <openssl/dsa.h>
 
+#include <string.h>
+
 #include <openssl/bn.h>
 #include <openssl/digest.h>
 #include <openssl/err.h>
diff --git a/crypto/dsa/dsa_test.c b/crypto/dsa/dsa_test.c
index e38720c..1273638 100644
--- a/crypto/dsa/dsa_test.c
+++ b/crypto/dsa/dsa_test.c
@@ -59,6 +59,8 @@
 
 #include <openssl/dsa.h>
 
+#include <string.h>
+
 #include <openssl/bio.h>
 #include <openssl/bn.h>
 #include <openssl/crypto.h>
diff --git a/crypto/ec/ec.c b/crypto/ec/ec.c
index 931d4a4..f9d8dc5 100644
--- a/crypto/ec/ec.c
+++ b/crypto/ec/ec.c
@@ -67,6 +67,8 @@
 
 #include <openssl/ec.h>
 
+#include <string.h>
+
 #include <openssl/bn.h>
 #include <openssl/err.h>
 #include <openssl/mem.h>
diff --git a/crypto/ec/ec_asn1.c b/crypto/ec/ec_asn1.c
index a2f1488..ce9b3f4 100644
--- a/crypto/ec/ec_asn1.c
+++ b/crypto/ec/ec_asn1.c
@@ -53,6 +53,8 @@
 
 #include <openssl/ec.h>
 
+#include <string.h>
+
 #include <openssl/asn1.h>
 #include <openssl/asn1t.h>
 #include <openssl/bn.h>
diff --git a/crypto/ec/ec_key.c b/crypto/ec/ec_key.c
index 09944aa..c8f0624 100644
--- a/crypto/ec/ec_key.c
+++ b/crypto/ec/ec_key.c
@@ -67,6 +67,8 @@
 
 #include <openssl/ec_key.h>
 
+#include <string.h>
+
 #include <openssl/ec.h>
 #include <openssl/engine.h>
 #include <openssl/err.h>
diff --git a/crypto/ec/simple.c b/crypto/ec/simple.c
index 32089b2..b3f96fa 100644
--- a/crypto/ec/simple.c
+++ b/crypto/ec/simple.c
@@ -67,6 +67,8 @@
 
 #include <openssl/ec.h>
 
+#include <string.h>
+
 #include <openssl/bn.h>
 #include <openssl/err.h>
 #include <openssl/mem.h>
diff --git a/crypto/ec/wnaf.c b/crypto/ec/wnaf.c
index 1976460..9016328 100644
--- a/crypto/ec/wnaf.c
+++ b/crypto/ec/wnaf.c
@@ -67,6 +67,8 @@
 
 #include <openssl/ec.h>
 
+#include <string.h>
+
 #include <openssl/bn.h>
 #include <openssl/err.h>
 #include <openssl/mem.h>
diff --git a/crypto/ecdh/ecdh.c b/crypto/ecdh/ecdh.c
index 6f9d0de..d4497f1 100644
--- a/crypto/ecdh/ecdh.c
+++ b/crypto/ecdh/ecdh.c
@@ -66,6 +66,8 @@
 
 #include <openssl/ecdh.h>
 
+#include <string.h>
+
 #include <openssl/bn.h>
 #include <openssl/digest.h>
 #include <openssl/err.h>
diff --git a/crypto/ecdsa/ecdsa.c b/crypto/ecdsa/ecdsa.c
index 6442462..d389799 100644
--- a/crypto/ecdsa/ecdsa.c
+++ b/crypto/ecdsa/ecdsa.c
@@ -52,6 +52,8 @@
 
 #include <openssl/ecdsa.h>
 
+#include <string.h>
+
 #include <openssl/bn.h>
 #include <openssl/err.h>
 #include <openssl/mem.h>
diff --git a/crypto/engine/engine.c b/crypto/engine/engine.c
index 1453e61..5b8cf1c 100644
--- a/crypto/engine/engine.c
+++ b/crypto/engine/engine.c
@@ -14,6 +14,8 @@
 
 #include <openssl/engine.h>
 
+#include <string.h>
+
 #include <openssl/dh.h>
 #include <openssl/dsa.h>
 #include <openssl/ec_key.h>
diff --git a/crypto/err/err.c b/crypto/err/err.c
index eb6e526..ec2062e 100644
--- a/crypto/err/err.c
+++ b/crypto/err/err.c
@@ -113,6 +113,7 @@
 #include <inttypes.h>
 #include <stdarg.h>
 #include <stdio.h>
+#include <string.h>
 
 #if defined(OPENSSL_WINDOWS)
 #pragma warning(push, 3)
diff --git a/crypto/err/err_impl.c b/crypto/err/err_impl.c
index 8cfcb46..32cff35 100644
--- a/crypto/err/err_impl.c
+++ b/crypto/err/err_impl.c
@@ -109,6 +109,7 @@
 #include <openssl/err.h>
 
 #include <assert.h>
+#include <string.h>
 
 #include <openssl/lhash.h>
 #include <openssl/mem.h>
diff --git a/crypto/err/err_test.c b/crypto/err/err_test.c
index 09dc1f6..bf36201 100644
--- a/crypto/err/err_test.c
+++ b/crypto/err/err_test.c
@@ -13,6 +13,7 @@
  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
 
 #include <stdio.h>
+#include <string.h>
 
 #include <openssl/crypto.h>
 #include <openssl/err.h>
diff --git a/crypto/evp/evp.c b/crypto/evp/evp.c
index ab84b48..8a1d513 100644
--- a/crypto/evp/evp.c
+++ b/crypto/evp/evp.c
@@ -57,6 +57,7 @@
 #include <openssl/evp.h>
 
 #include <assert.h>
+#include <string.h>
 
 #include <openssl/bio.h>
 #include <openssl/dh.h>
diff --git a/crypto/evp/evp_ctx.c b/crypto/evp/evp_ctx.c
index e1c2886..a383725 100644
--- a/crypto/evp/evp_ctx.c
+++ b/crypto/evp/evp_ctx.c
@@ -57,6 +57,7 @@
 #include <openssl/evp.h>
 
 #include <stdio.h>
+#include <string.h>
 
 #include <openssl/err.h>
 #include <openssl/mem.h>
diff --git a/crypto/evp/p_ec.c b/crypto/evp/p_ec.c
index fd9685f..c274131 100644
--- a/crypto/evp/p_ec.c
+++ b/crypto/evp/p_ec.c
@@ -55,6 +55,8 @@
 
 #include <openssl/evp.h>
 
+#include <string.h>
+
 #include <openssl/asn1.h>
 #include <openssl/bn.h>
 #include <openssl/buf.h>
diff --git a/crypto/evp/p_hmac.c b/crypto/evp/p_hmac.c
index a04a74f..6d9a909 100644
--- a/crypto/evp/p_hmac.c
+++ b/crypto/evp/p_hmac.c
@@ -55,6 +55,8 @@
 
 #include <openssl/evp.h>
 
+#include <string.h>
+
 #include <openssl/asn1.h>
 #include <openssl/err.h>
 #include <openssl/hmac.h>
diff --git a/crypto/evp/p_rsa.c b/crypto/evp/p_rsa.c
index 1c42fbd..31f5aaa 100644
--- a/crypto/evp/p_rsa.c
+++ b/crypto/evp/p_rsa.c
@@ -55,6 +55,8 @@
 
 #include <openssl/evp.h>
 
+#include <string.h>
+
 #include <openssl/bn.h>
 #include <openssl/buf.h>
 #include <openssl/digest.h>
diff --git a/crypto/evp/pbkdf.c b/crypto/evp/pbkdf.c
index 4a18b08..be6ed86 100644
--- a/crypto/evp/pbkdf.c
+++ b/crypto/evp/pbkdf.c
@@ -55,6 +55,8 @@
 
 #include <openssl/evp.h>
 
+#include <string.h>
+
 #include <openssl/hmac.h>
 
 
diff --git a/crypto/evp/pbkdf_test.c b/crypto/evp/pbkdf_test.c
index 88b3dbe..e3ba616 100644
--- a/crypto/evp/pbkdf_test.c
+++ b/crypto/evp/pbkdf_test.c
@@ -13,6 +13,7 @@
  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
 
 #include <stdio.h>
+#include <string.h>
 
 #include <openssl/bio.h>
 #include <openssl/crypto.h>
diff --git a/crypto/hkdf/hkdf.c b/crypto/hkdf/hkdf.c
index be51bc3..bb7f5a4 100644
--- a/crypto/hkdf/hkdf.c
+++ b/crypto/hkdf/hkdf.c
@@ -15,6 +15,7 @@
 #include <openssl/hkdf.h>
 
 #include <assert.h>
+#include <string.h>
 
 #include <openssl/err.h>
 #include <openssl/hmac.h>
diff --git a/crypto/hkdf/hkdf_test.c b/crypto/hkdf/hkdf_test.c
index a098fba..7467fe0 100644
--- a/crypto/hkdf/hkdf_test.c
+++ b/crypto/hkdf/hkdf_test.c
@@ -13,6 +13,7 @@
  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
 
 #include <stdio.h>
+#include <string.h>
 
 #include <openssl/bio.h>
 #include <openssl/crypto.h>
diff --git a/crypto/hmac/hmac.c b/crypto/hmac/hmac.c
index c5b4bd1..f179fed 100644
--- a/crypto/hmac/hmac.c
+++ b/crypto/hmac/hmac.c
@@ -57,6 +57,7 @@
 #include <openssl/hmac.h>
 
 #include <assert.h>
+#include <string.h>
 
 #include <openssl/mem.h>
 
diff --git a/crypto/hmac/hmac_test.c b/crypto/hmac/hmac_test.c
index 0ebfb98..ecc418a 100644
--- a/crypto/hmac/hmac_test.c
+++ b/crypto/hmac/hmac_test.c
@@ -56,6 +56,7 @@
 
 #include <assert.h>
 #include <stdio.h>
+#include <string.h>
 
 #include <openssl/crypto.h>
 #include <openssl/digest.h>
diff --git a/crypto/lhash/lhash.c b/crypto/lhash/lhash.c
index ce1741a..c282fa8 100644
--- a/crypto/lhash/lhash.c
+++ b/crypto/lhash/lhash.c
@@ -57,6 +57,7 @@
 
 #include <assert.h>
 #include <limits.h>
+#include <string.h>
 
 #include <openssl/mem.h>
 
diff --git a/crypto/md4/md4.c b/crypto/md4/md4.c
index 8e86945..8fb357b 100644
--- a/crypto/md4/md4.c
+++ b/crypto/md4/md4.c
@@ -56,6 +56,8 @@
 
 #include <openssl/md4.h>
 
+#include <string.h>
+
 
 /* Implemented from RFC1186 The MD4 Message-Digest Algorithm. */
 
diff --git a/crypto/modes/cbc.c b/crypto/modes/cbc.c
index 83d58f0..a2ad26c 100644
--- a/crypto/modes/cbc.c
+++ b/crypto/modes/cbc.c
@@ -48,6 +48,7 @@
 #include <openssl/modes.h>
 
 #include <assert.h>
+#include <string.h>
 
 #include "internal.h"
 
diff --git a/crypto/modes/cfb.c b/crypto/modes/cfb.c
index df7cb77..738a438 100644
--- a/crypto/modes/cfb.c
+++ b/crypto/modes/cfb.c
@@ -49,6 +49,7 @@
 #include <openssl/modes.h>
 
 #include <assert.h>
+#include <string.h>
 
 #include "internal.h"
 
diff --git a/crypto/modes/ctr.c b/crypto/modes/ctr.c
index 3f8f91f..61832ba 100644
--- a/crypto/modes/ctr.c
+++ b/crypto/modes/ctr.c
@@ -48,6 +48,7 @@
 #include <openssl/modes.h>
 
 #include <assert.h>
+#include <string.h>
 
 #include "internal.h"
 
diff --git a/crypto/modes/gcm.c b/crypto/modes/gcm.c
index f09637b..eeaeeff 100644
--- a/crypto/modes/gcm.c
+++ b/crypto/modes/gcm.c
@@ -49,6 +49,7 @@
 #include <openssl/modes.h>
 
 #include <assert.h>
+#include <string.h>
 
 #include <openssl/mem.h>
 #include <openssl/cpu.h>
diff --git a/crypto/modes/gcm_test.c b/crypto/modes/gcm_test.c
index 5308976..29f9d95 100644
--- a/crypto/modes/gcm_test.c
+++ b/crypto/modes/gcm_test.c
@@ -47,6 +47,7 @@
  * ==================================================================== */
 
 #include <stdio.h>
+#include <string.h>
 
 #include <openssl/aes.h>
 #include <openssl/crypto.h>
diff --git a/crypto/obj/obj.c b/crypto/obj/obj.c
index bfcc08b..b04321b 100644
--- a/crypto/obj/obj.c
+++ b/crypto/obj/obj.c
@@ -57,6 +57,7 @@
 #include <openssl/obj.h>
 
 #include <limits.h>
+#include <string.h>
 
 #include <openssl/asn1.h>
 #include <openssl/buf.h>
diff --git a/crypto/pem/pem_info.c b/crypto/pem/pem_info.c
index c4974c2..3f02619 100644
--- a/crypto/pem/pem_info.c
+++ b/crypto/pem/pem_info.c
@@ -58,8 +58,9 @@
 
 #include <openssl/pem.h>
 
-#include <stdio.h>
 #include <assert.h>
+#include <stdio.h>
+#include <string.h>
 
 #include <openssl/buf.h>
 #include <openssl/dsa.h>
diff --git a/crypto/pem/pem_lib.c b/crypto/pem/pem_lib.c
index 0876008..ff72c44 100644
--- a/crypto/pem/pem_lib.c
+++ b/crypto/pem/pem_lib.c
@@ -58,6 +58,7 @@
 #include <assert.h>
 #include <ctype.h>
 #include <stdio.h>
+#include <string.h>
 
 #include <openssl/base64.h>
 #include <openssl/buf.h>
diff --git a/crypto/pem/pem_pkey.c b/crypto/pem/pem_pkey.c
index 0ef08d0..c0aba51 100644
--- a/crypto/pem/pem_pkey.c
+++ b/crypto/pem/pem_pkey.c
@@ -57,6 +57,7 @@
 #include <openssl/pem.h>
 
 #include <stdio.h>
+#include <string.h>
 
 #include <openssl/buf.h>
 #include <openssl/dh.h>
diff --git a/crypto/pkcs8/p5_pbe.c b/crypto/pkcs8/p5_pbe.c
index 7b18b6f..f30ae79 100644
--- a/crypto/pkcs8/p5_pbe.c
+++ b/crypto/pkcs8/p5_pbe.c
@@ -53,6 +53,8 @@
  * (eay@cryptsoft.com).  This product includes software written by Tim
  * Hudson (tjh@cryptsoft.com). */
 
+#include <string.h>
+
 #include <openssl/asn1t.h>
 #include <openssl/err.h>
 #include <openssl/pkcs8.h>
diff --git a/crypto/pkcs8/p5_pbev2.c b/crypto/pkcs8/p5_pbev2.c
index 1af2af2..9eb9848 100644
--- a/crypto/pkcs8/p5_pbev2.c
+++ b/crypto/pkcs8/p5_pbev2.c
@@ -53,6 +53,7 @@
  * (eay@cryptsoft.com).  This product includes software written by Tim
  * Hudson (tjh@cryptsoft.com). */
 
+#include <string.h>
 
 #include <openssl/asn1t.h>
 #include <openssl/cipher.h>
diff --git a/crypto/pkcs8/pkcs8.c b/crypto/pkcs8/pkcs8.c
index 2185579..0b1dfba 100644
--- a/crypto/pkcs8/pkcs8.c
+++ b/crypto/pkcs8/pkcs8.c
@@ -57,6 +57,7 @@
 
 #include <assert.h>
 #include <limits.h>
+#include <string.h>
 
 #include <openssl/asn1.h>
 #include <openssl/bn.h>
diff --git a/crypto/poly1305/poly1305_arm.c b/crypto/poly1305/poly1305_arm.c
index 002a4c4..61ebec5 100644
--- a/crypto/poly1305/poly1305_arm.c
+++ b/crypto/poly1305/poly1305_arm.c
@@ -19,6 +19,9 @@
 
 #if defined(OPENSSL_ARM) && !defined(OPENSSL_NO_ASM)
 
+#include <string.h>
+
+
 typedef struct {
   uint32_t v[12]; /* for alignment; only using 10 */
 } fe1305x2;
diff --git a/crypto/rand/windows.c b/crypto/rand/windows.c
index 5d12ae8..6f3f3a7 100644
--- a/crypto/rand/windows.c
+++ b/crypto/rand/windows.c
@@ -32,6 +32,7 @@
 
 #pragma warning(pop)
 
+
 void RAND_cleanup(void) {
 }
 
diff --git a/crypto/rsa/blinding.c b/crypto/rsa/blinding.c
index 04f672a..06f87a7 100644
--- a/crypto/rsa/blinding.c
+++ b/crypto/rsa/blinding.c
@@ -108,12 +108,15 @@
 
 #include <openssl/rsa.h>
 
+#include <string.h>
+
 #include <openssl/bn.h>
 #include <openssl/mem.h>
 #include <openssl/err.h>
 
 #include "internal.h"
 
+
 #define BN_BLINDING_COUNTER 32
 
 struct bn_blinding_st {
diff --git a/crypto/rsa/padding.c b/crypto/rsa/padding.c
index 4c25d9c..66fdf13 100644
--- a/crypto/rsa/padding.c
+++ b/crypto/rsa/padding.c
@@ -56,6 +56,7 @@
 #include <openssl/rsa.h>
 
 #include <assert.h>
+#include <string.h>
 
 #include <openssl/digest.h>
 #include <openssl/err.h>
diff --git a/crypto/rsa/rsa.c b/crypto/rsa/rsa.c
index 1ea5fef..cfdd7ff 100644
--- a/crypto/rsa/rsa.c
+++ b/crypto/rsa/rsa.c
@@ -56,6 +56,8 @@
 
 #include <openssl/rsa.h>
 
+#include <string.h>
+
 #include <openssl/bn.h>
 #include <openssl/engine.h>
 #include <openssl/err.h>
diff --git a/crypto/rsa/rsa_impl.c b/crypto/rsa/rsa_impl.c
index 7eb1bc5..d950d50 100644
--- a/crypto/rsa/rsa_impl.c
+++ b/crypto/rsa/rsa_impl.c
@@ -56,6 +56,8 @@
 
 #include <openssl/rsa.h>
 
+#include <string.h>
+
 #include <openssl/bn.h>
 #include <openssl/err.h>
 #include <openssl/mem.h>
diff --git a/crypto/rsa/rsa_test.c b/crypto/rsa/rsa_test.c
index 3a21864..75489e0 100644
--- a/crypto/rsa/rsa_test.c
+++ b/crypto/rsa/rsa_test.c
@@ -56,6 +56,8 @@
 
 #include <openssl/rsa.h>
 
+#include <string.h>
+
 #include <openssl/bio.h>
 #include <openssl/bn.h>
 #include <openssl/crypto.h>
diff --git a/crypto/stack/stack.c b/crypto/stack/stack.c
index f0b31cd..0b336ba 100644
--- a/crypto/stack/stack.c
+++ b/crypto/stack/stack.c
@@ -56,6 +56,8 @@
 
 #include <openssl/stack.h>
 
+#include <string.h>
+
 #include <openssl/mem.h>
 
 /* kMinSize is the number of pointers that will be initially allocated in a new
diff --git a/crypto/thread.c b/crypto/thread.c
index 6e8d494..f18bc13 100644
--- a/crypto/thread.c
+++ b/crypto/thread.c
@@ -57,6 +57,7 @@
 #include <openssl/thread.h>
 
 #include <errno.h>
+#include <string.h>
 
 #if defined(OPENSSL_WINDOWS)
 #pragma warning(push, 3)
@@ -67,6 +68,7 @@
 #include <openssl/mem.h>
 #include <openssl/type_check.h>
 
+
 /* lock_names contains the names of all the locks defined in thread.h. */
 static const char *const lock_names[] = {
     "<<ERROR>>",    "err",          "ex_data",       "x509",
diff --git a/crypto/x509/a_strex.c b/crypto/x509/a_strex.c
index 0d5dd9f..b194d18 100644
--- a/crypto/x509/a_strex.c
+++ b/crypto/x509/a_strex.c
@@ -56,6 +56,8 @@
 
 #include <openssl/x509.h>
 
+#include <string.h>
+
 #include <openssl/asn1.h>
 #include <openssl/mem.h>
 #include <openssl/obj.h>
diff --git a/crypto/x509/asn1_gen.c b/crypto/x509/asn1_gen.c
index 9246b93..750701e 100644
--- a/crypto/x509/asn1_gen.c
+++ b/crypto/x509/asn1_gen.c
@@ -56,6 +56,8 @@
 
 #include <openssl/x509.h>
 
+#include <string.h>
+
 #include <openssl/asn1.h>
 #include <openssl/err.h>
 #include <openssl/mem.h>
diff --git a/crypto/x509/by_dir.c b/crypto/x509/by_dir.c
index 659bc44..5a77b81 100644
--- a/crypto/x509/by_dir.c
+++ b/crypto/x509/by_dir.c
@@ -55,8 +55,9 @@
  * copied and put under another distribution licence
  * [including the GNU Public Licence.] */
 
-#include <sys/types.h>
+#include <string.h>
 #include <sys/stat.h>
+#include <sys/types.h>
 
 #include <openssl/buf.h>
 #include <openssl/err.h>
diff --git a/crypto/x509/pkcs7_test.c b/crypto/x509/pkcs7_test.c
index 2e20c40..4283022 100644
--- a/crypto/x509/pkcs7_test.c
+++ b/crypto/x509/pkcs7_test.c
@@ -14,6 +14,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include <openssl/bytestring.h>
 #include <openssl/crypto.h>
diff --git a/crypto/x509/x509_cmp.c b/crypto/x509/x509_cmp.c
index 0974ef6..712e36b 100644
--- a/crypto/x509/x509_cmp.c
+++ b/crypto/x509/x509_cmp.c
@@ -55,6 +55,8 @@
  * copied and put under another distribution licence
  * [including the GNU Public Licence.] */
 
+#include <string.h>
+
 #include <openssl/asn1.h>
 #include <openssl/buf.h>
 #include <openssl/digest.h>
diff --git a/crypto/x509/x509_lu.c b/crypto/x509/x509_lu.c
index 05d1598..090d341 100644
--- a/crypto/x509/x509_lu.c
+++ b/crypto/x509/x509_lu.c
@@ -55,6 +55,8 @@
  * copied and put under another distribution licence
  * [including the GNU Public Licence.] */
 
+#include <string.h>
+
 #include <openssl/err.h>
 #include <openssl/lhash.h>
 #include <openssl/mem.h>
diff --git a/crypto/x509/x509_obj.c b/crypto/x509/x509_obj.c
index 5f539ab..914e0de 100644
--- a/crypto/x509/x509_obj.c
+++ b/crypto/x509/x509_obj.c
@@ -55,6 +55,8 @@
  * copied and put under another distribution licence
  * [including the GNU Public Licence.] */
 
+#include <string.h>
+
 #include <openssl/buf.h>
 #include <openssl/err.h>
 #include <openssl/lhash.h>
diff --git a/crypto/x509/x509_vfy.c b/crypto/x509/x509_vfy.c
index 99d55bc..285bcaf 100644
--- a/crypto/x509/x509_vfy.c
+++ b/crypto/x509/x509_vfy.c
@@ -54,6 +54,7 @@
  * copied and put under another distribution licence
  * [including the GNU Public Licence.] */
 
+#include <string.h>
 #include <time.h>
 
 #include <openssl/asn1.h>
diff --git a/crypto/x509/x509_vpm.c b/crypto/x509/x509_vpm.c
index 442e070..3daaf61 100644
--- a/crypto/x509/x509_vpm.c
+++ b/crypto/x509/x509_vpm.c
@@ -52,6 +52,8 @@
  * (eay@cryptsoft.com).  This product includes software written by Tim
  * Hudson (tjh@cryptsoft.com). */
 
+#include <string.h>
+
 #include <openssl/buf.h>
 #include <openssl/lhash.h>
 #include <openssl/mem.h>
@@ -61,6 +63,7 @@
 
 #include "vpm_int.h"
 
+
 /* X509_VERIFY_PARAM functions */
 
 static void x509_verify_param_zero(X509_VERIFY_PARAM *param)
diff --git a/crypto/x509/x509name.c b/crypto/x509/x509name.c
index 4a5ea17..042d18b 100644
--- a/crypto/x509/x509name.c
+++ b/crypto/x509/x509name.c
@@ -54,6 +54,8 @@
  * copied and put under another distribution licence
  * [including the GNU Public Licence.] */
 
+#include <string.h>
+
 #include <openssl/asn1.h>
 #include <openssl/err.h>
 #include <openssl/evp.h>
diff --git a/crypto/x509/x509spki.c b/crypto/x509/x509spki.c
index 03823b7..9bab957 100644
--- a/crypto/x509/x509spki.c
+++ b/crypto/x509/x509spki.c
@@ -52,6 +52,8 @@
  * (eay@cryptsoft.com).  This product includes software written by Tim
  * Hudson (tjh@cryptsoft.com). */
 
+#include <string.h>
+
 #include <openssl/base64.h>
 #include <openssl/err.h>
 #include <openssl/mem.h>
diff --git a/crypto/x509/x_name.c b/crypto/x509/x_name.c
index 6e108f5..211f68f 100644
--- a/crypto/x509/x_name.c
+++ b/crypto/x509/x_name.c
@@ -55,6 +55,7 @@
  * [including the GNU Public Licence.] */
 
 #include <ctype.h>
+#include <string.h>
 
 #include <openssl/asn1.h>
 #include <openssl/asn1t.h>
diff --git a/crypto/x509/x_pkey.c b/crypto/x509/x_pkey.c
index 9fc9e3d..550078b 100644
--- a/crypto/x509/x_pkey.c
+++ b/crypto/x509/x_pkey.c
@@ -56,6 +56,8 @@
 
 #include <openssl/x509.h>
 
+#include <string.h>
+
 #include <openssl/asn1.h>
 #include <openssl/mem.h>
 #include <openssl/err.h>
diff --git a/crypto/x509v3/pcy_tree.c b/crypto/x509v3/pcy_tree.c
index a70a72b..682474d 100644
--- a/crypto/x509v3/pcy_tree.c
+++ b/crypto/x509v3/pcy_tree.c
@@ -55,6 +55,8 @@
  *
  */
 
+#include <string.h>
+
 #include <openssl/mem.h>
 #include <openssl/obj.h>
 #include <openssl/stack.h>
diff --git a/crypto/x509v3/v3_akey.c b/crypto/x509v3/v3_akey.c
index 67607d9..f6e6b69 100644
--- a/crypto/x509v3/v3_akey.c
+++ b/crypto/x509v3/v3_akey.c
@@ -55,6 +55,7 @@
  * Hudson (tjh@cryptsoft.com). */
 
 #include <stdio.h>
+#include <string.h>
 
 #include <openssl/asn1.h>
 #include <openssl/asn1t.h>
diff --git a/crypto/x509v3/v3_alt.c b/crypto/x509v3/v3_alt.c
index 54e0f0a..113cf45 100644
--- a/crypto/x509v3/v3_alt.c
+++ b/crypto/x509v3/v3_alt.c
@@ -55,6 +55,7 @@
  * Hudson (tjh@cryptsoft.com). */
 
 #include <stdio.h>
+#include <string.h>
 
 #include <openssl/conf.h>
 #include <openssl/err.h>
diff --git a/crypto/x509v3/v3_bcons.c b/crypto/x509v3/v3_bcons.c
index 881b922..a1381b4 100644
--- a/crypto/x509v3/v3_bcons.c
+++ b/crypto/x509v3/v3_bcons.c
@@ -56,6 +56,7 @@
 
 
 #include <stdio.h>
+#include <string.h>
 
 #include <openssl/asn1.h>
 #include <openssl/asn1t.h>
diff --git a/crypto/x509v3/v3_bitst.c b/crypto/x509v3/v3_bitst.c
index a4c3186..15e9859 100644
--- a/crypto/x509v3/v3_bitst.c
+++ b/crypto/x509v3/v3_bitst.c
@@ -55,6 +55,7 @@
  * Hudson (tjh@cryptsoft.com). */
 
 #include <stdio.h>
+#include <string.h>
 
 #include <openssl/conf.h>
 #include <openssl/err.h>
diff --git a/crypto/x509v3/v3_conf.c b/crypto/x509v3/v3_conf.c
index 48654cb..7606ac1 100644
--- a/crypto/x509v3/v3_conf.c
+++ b/crypto/x509v3/v3_conf.c
@@ -56,8 +56,9 @@
 
 /* extension creation utilities */
 
-#include <stdio.h>
 #include <ctype.h>
+#include <stdio.h>
+#include <string.h>
 
 #include <openssl/conf.h>
 #include <openssl/err.h>
diff --git a/crypto/x509v3/v3_cpols.c b/crypto/x509v3/v3_cpols.c
index b3d6fef..d5a8c3c 100644
--- a/crypto/x509v3/v3_cpols.c
+++ b/crypto/x509v3/v3_cpols.c
@@ -57,6 +57,7 @@
  */
 
 #include <stdio.h>
+#include <string.h>
 
 #include <openssl/asn1.h>
 #include <openssl/asn1t.h>
diff --git a/crypto/x509v3/v3_crld.c b/crypto/x509v3/v3_crld.c
index e2bd2ad..e41dd65 100644
--- a/crypto/x509v3/v3_crld.c
+++ b/crypto/x509v3/v3_crld.c
@@ -55,6 +55,7 @@
  * Hudson (tjh@cryptsoft.com). */
 
 #include <stdio.h>
+#include <string.h>
 
 #include <openssl/asn1.h>
 #include <openssl/asn1t.h>
diff --git a/crypto/x509v3/v3_ia5.c b/crypto/x509v3/v3_ia5.c
index 39d6ef8..ec57e9b 100644
--- a/crypto/x509v3/v3_ia5.c
+++ b/crypto/x509v3/v3_ia5.c
@@ -56,8 +56,8 @@
  *
  */
 
-
 #include <stdio.h>
+#include <string.h>
 
 #include <openssl/asn1.h>
 #include <openssl/conf.h>
diff --git a/crypto/x509v3/v3_info.c b/crypto/x509v3/v3_info.c
index 4ef744b..7558b2d 100644
--- a/crypto/x509v3/v3_info.c
+++ b/crypto/x509v3/v3_info.c
@@ -57,6 +57,7 @@
  */
 
 #include <stdio.h>
+#include <string.h>
 
 #include <openssl/asn1.h>
 #include <openssl/asn1t.h>
diff --git a/crypto/x509v3/v3_pci.c b/crypto/x509v3/v3_pci.c
index 54f28e1..aa93891 100644
--- a/crypto/x509v3/v3_pci.c
+++ b/crypto/x509v3/v3_pci.c
@@ -35,6 +35,7 @@
  */
 
 #include <stdio.h>
+#include <string.h>
 
 #include <openssl/conf.h>
 #include <openssl/err.h>
diff --git a/crypto/x509v3/v3_pcons.c b/crypto/x509v3/v3_pcons.c
index dac732c..f87c6a0 100644
--- a/crypto/x509v3/v3_pcons.c
+++ b/crypto/x509v3/v3_pcons.c
@@ -56,6 +56,7 @@
 
 
 #include <stdio.h>
+#include <string.h>
 
 #include <openssl/asn1.h>
 #include <openssl/asn1t.h>
diff --git a/crypto/x509v3/v3_purp.c b/crypto/x509v3/v3_purp.c
index 791927f..6daf632 100644
--- a/crypto/x509v3/v3_purp.c
+++ b/crypto/x509v3/v3_purp.c
@@ -56,6 +56,8 @@
 
 #include <stdio.h>
 
+#include <string.h>
+
 #include <openssl/buf.h>
 #include <openssl/err.h>
 #include <openssl/digest.h>
diff --git a/crypto/x509v3/v3_skey.c b/crypto/x509v3/v3_skey.c
index 116679a..471a1ab 100644
--- a/crypto/x509v3/v3_skey.c
+++ b/crypto/x509v3/v3_skey.c
@@ -56,6 +56,7 @@
 
 
 #include <stdio.h>
+#include <string.h>
 
 #include <openssl/digest.h>
 #include <openssl/err.h>
diff --git a/crypto/x509v3/v3_sxnet.c b/crypto/x509v3/v3_sxnet.c
index 7b8e3c5..bb5e214 100644
--- a/crypto/x509v3/v3_sxnet.c
+++ b/crypto/x509v3/v3_sxnet.c
@@ -57,6 +57,7 @@
  */
 
 #include <stdio.h>
+#include <string.h>
 
 #include <openssl/asn1.h>
 #include <openssl/asn1t.h>
diff --git a/crypto/x509v3/v3_utl.c b/crypto/x509v3/v3_utl.c
index b856efd..d081c1c 100644
--- a/crypto/x509v3/v3_utl.c
+++ b/crypto/x509v3/v3_utl.c
@@ -60,6 +60,7 @@
 
 #include <ctype.h>
 #include <stdio.h>
+#include <string.h>
 
 #include <openssl/bn.h>
 #include <openssl/buf.h>
diff --git a/include/openssl/base.h b/include/openssl/base.h
index c155ade..71223a0 100644
--- a/include/openssl/base.h
+++ b/include/openssl/base.h
@@ -58,7 +58,6 @@
 
 #include <stdint.h>
 #include <stdlib.h>
-#include <string.h>
 #include <sys/types.h>
 
 #include <openssl/opensslfeatures.h>
diff --git a/ssl/pqueue/pqueue.c b/ssl/pqueue/pqueue.c
index 4c94355..ecaa139 100644
--- a/ssl/pqueue/pqueue.c
+++ b/ssl/pqueue/pqueue.c
@@ -56,6 +56,8 @@
 
 #include <openssl/pqueue.h>
 
+#include <string.h>
+
 #include <openssl/mem.h>
 
 
diff --git a/ssl/test/async_bio.cc b/ssl/test/async_bio.cc
index 88f8e9a..c007ffa 100644
--- a/ssl/test/async_bio.cc
+++ b/ssl/test/async_bio.cc
@@ -15,8 +15,11 @@
 #include "async_bio.h"
 
 #include <errno.h>
+#include <string.h>
+
 #include <openssl/mem.h>
 
+
 namespace {
 
 extern const BIO_METHOD async_bio_method;
diff --git a/ssl/test/bssl_shim.cc b/ssl/test/bssl_shim.cc
index 19355af..37891b9 100644
--- a/ssl/test/bssl_shim.cc
+++ b/ssl/test/bssl_shim.cc
@@ -22,6 +22,7 @@
 #include <unistd.h>
 #endif
 
+#include <string.h>
 #include <sys/types.h>
 
 #include <openssl/bio.h>
diff --git a/ssl/test/packeted_bio.cc b/ssl/test/packeted_bio.cc
index 3894d85..93b2164 100644
--- a/ssl/test/packeted_bio.cc
+++ b/ssl/test/packeted_bio.cc
@@ -16,8 +16,11 @@
 
 #include <assert.h>
 #include <errno.h>
+#include <string.h>
+
 #include <openssl/mem.h>
 
+
 namespace {
 
 extern const BIO_METHOD packeted_bio_method;
diff --git a/tool/digest.cc b/tool/digest.cc
index e75b168..f95f412 100644
--- a/tool/digest.cc
+++ b/tool/digest.cc
@@ -22,6 +22,7 @@
 #include <fcntl.h>
 #include <limits.h>
 #include <stdio.h>
+#include <string.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 
@@ -42,6 +43,7 @@
 
 #include <openssl/digest.h>
 
+
 struct close_delete {
   void operator()(int *fd) {
     close(*fd);
diff --git a/tool/pkcs12.cc b/tool/pkcs12.cc
index fca8bb2..e0133e5 100644
--- a/tool/pkcs12.cc
+++ b/tool/pkcs12.cc
@@ -21,6 +21,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <stdint.h>
+#include <string.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #if defined(OPENSSL_WINDOWS)
diff --git a/tool/speed.cc b/tool/speed.cc
index 411f29e..2df6f90 100644
--- a/tool/speed.cc
+++ b/tool/speed.cc
@@ -18,6 +18,7 @@
 #include <vector>
 
 #include <stdint.h>
+#include <string.h>
 #include <time.h>
 
 #include <openssl/aead.h>
@@ -34,6 +35,7 @@
 #include <sys/time.h>
 #endif
 
+
 extern "C" {
 // These values are DER encoded, RSA private keys.
 extern const uint8_t kDERRSAPrivate2048[];
diff --git a/tool/transport_common.cc b/tool/transport_common.cc
index 453ff5e..c05742e 100644
--- a/tool/transport_common.cc
+++ b/tool/transport_common.cc
@@ -19,6 +19,7 @@
 
 #include <errno.h>
 #include <stdlib.h>
+#include <string.h>
 #include <sys/types.h>
 
 #if !defined(OPENSSL_WINDOWS)