Eliminate unnecessary includes from low-level crypto modules.
Beyond generally eliminating unnecessary includes, eliminate as many
includes of headers that declare/define particularly error-prone
functionality like strlen, malloc, and free. crypto/err/internal.h was
added to remove the dependency on openssl/thread.h from the public
openssl/err.h header. The include of <stdlib.h> in openssl/mem.h was
retained since it defines OPENSSL_malloc and friends as macros around
the stdlib.h functions. The public x509.h, x509v3.h, and ssl.h headers
were not changed in order to minimize breakage of source compatibility
with external code.
Change-Id: I0d264b73ad0a720587774430b2ab8f8275960329
Reviewed-on: https://boringssl-review.googlesource.com/4220
Reviewed-by: Adam Langley <agl@google.com>
diff --git a/include/openssl/asn1.h b/include/openssl/asn1.h
index 4baf81c..7c62161 100644
--- a/include/openssl/asn1.h
+++ b/include/openssl/asn1.h
@@ -61,8 +61,6 @@
#include <openssl/base.h>
-#include <time.h>
-
#include <openssl/bio.h>
#include <openssl/stack.h>
diff --git a/include/openssl/asn1t.h b/include/openssl/asn1t.h
index 72eb2cb..6c91134 100644
--- a/include/openssl/asn1t.h
+++ b/include/openssl/asn1t.h
@@ -58,7 +58,7 @@
#ifndef HEADER_ASN1T_H
#define HEADER_ASN1T_H
-#include <stddef.h>
+#include <openssl/base.h>
#include <openssl/asn1.h>
#ifdef OPENSSL_BUILD_SHLIBCRYPTO
diff --git a/include/openssl/base.h b/include/openssl/base.h
index 217908c..77549f7 100644
--- a/include/openssl/base.h
+++ b/include/openssl/base.h
@@ -56,8 +56,8 @@
/* This file should be the first included by all BoringSSL headers. */
+#include <stddef.h>
#include <stdint.h>
-#include <stdlib.h>
#include <sys/types.h>
#include <openssl/opensslfeatures.h>
@@ -175,6 +175,8 @@
typedef struct cbb_st CBB;
typedef struct cbs_st CBS;
typedef struct conf_st CONF;
+typedef struct conf_value_st CONF_VALUE;
+typedef int CRYPTO_THREADID;
typedef struct dh_method DH_METHOD;
typedef struct dh_st DH;
typedef struct dsa_method DSA_METHOD;
diff --git a/include/openssl/bio.h b/include/openssl/bio.h
index 0a637e4..6ce25bb 100644
--- a/include/openssl/bio.h
+++ b/include/openssl/bio.h
@@ -59,7 +59,6 @@
#include <openssl/base.h>
-#include <stdarg.h>
#include <stdio.h> /* For FILE */
#include <openssl/err.h> /* for ERR_print_errors_fp */
diff --git a/include/openssl/conf.h b/include/openssl/conf.h
index 05bad9b..84fc94f 100644
--- a/include/openssl/conf.h
+++ b/include/openssl/conf.h
@@ -79,11 +79,11 @@
*
* Config files are representated by a |CONF|. */
-typedef struct {
+struct conf_value_st {
char *section;
char *name;
char *value;
-} CONF_VALUE;
+};
struct conf_st {
LHASH_OF(CONF_VALUE) *data;
diff --git a/include/openssl/crypto.h b/include/openssl/crypto.h
index 44793f4..1dc8346 100644
--- a/include/openssl/crypto.h
+++ b/include/openssl/crypto.h
@@ -17,7 +17,6 @@
#include <openssl/base.h>
-#include <openssl/mem.h>
#if defined(__cplusplus)
extern "C" {
diff --git a/include/openssl/err.h b/include/openssl/err.h
index 738e8c5..552ea92 100644
--- a/include/openssl/err.h
+++ b/include/openssl/err.h
@@ -112,8 +112,6 @@
#include <stdio.h>
#include <openssl/base.h>
-#include <openssl/thread.h>
-#include <openssl/lhash.h>
#if defined(__cplusplus)
extern "C" {
diff --git a/include/openssl/evp.h b/include/openssl/evp.h
index 24fd038..ded7a58 100644
--- a/include/openssl/evp.h
+++ b/include/openssl/evp.h
@@ -58,7 +58,6 @@
#define OPENSSL_HEADER_EVP_H
#include <openssl/base.h>
-#include <openssl/stack.h>
/* OpenSSL included digest and cipher functions in this header so we include
* them for users that still expect that.
@@ -67,9 +66,7 @@
#include <openssl/aead.h>
#include <openssl/cipher.h>
#include <openssl/digest.h>
-#include <openssl/mem.h>
#include <openssl/obj.h>
-#include <openssl/thread.h>
#if defined(__cplusplus)
extern "C" {
diff --git a/include/openssl/mem.h b/include/openssl/mem.h
index 3bd01c0..42ec46a 100644
--- a/include/openssl/mem.h
+++ b/include/openssl/mem.h
@@ -58,6 +58,7 @@
#include <openssl/base.h>
+#include <stdlib.h>
#include <stdarg.h>
#if defined(__cplusplus)
diff --git a/include/openssl/pkcs8.h b/include/openssl/pkcs8.h
index e0d7b10..8dc7731 100644
--- a/include/openssl/pkcs8.h
+++ b/include/openssl/pkcs8.h
@@ -58,11 +58,9 @@
#define OPENSSL_HEADER_PKCS8_H
#include <openssl/base.h>
-
-#include <stdio.h>
-
#include <openssl/x509.h>
+
#if defined(__cplusplus)
extern "C" {
#endif
diff --git a/include/openssl/time_support.h b/include/openssl/time_support.h
index d03a99d..912e672 100644
--- a/include/openssl/time_support.h
+++ b/include/openssl/time_support.h
@@ -60,7 +60,6 @@
#include <openssl/base.h>
-#include <time.h>
#if defined(__cplusplus)
extern "C" {