diff --git a/ChangeLog b/ChangeLog
index de37089da2e30453e3a5201e9de260e95008d319..fcff246da26d16329c51d4851ff29a7cbe403b72 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2003-05-12  Niels Möller  <nisse@cuckoo.hack.org>
+
+	* Reordered includes in most or all .c-files. All should now
+	include config.h.
+
 2003-05-12  Niels Möller  <niels@s3.kth.se>
 
 	* configure.ac: Use LSH_FUNC_ALLOCA.
diff --git a/aes-decrypt-table.c b/aes-decrypt-table.c
index 8eceb2bcef391b887f6b64b04f3e5642808caa43..b975b39d372fdad84cbe8b9e6a61003a73d3b937 100644
--- a/aes-decrypt-table.c
+++ b/aes-decrypt-table.c
@@ -23,6 +23,10 @@
  * MA 02111-1307, USA.
  */
 
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include "aes-internal.h"
 
 const struct aes_table
diff --git a/aes-decrypt.c b/aes-decrypt.c
index 50b7f86ffd8c39ead9c4c670657a472a877c1084..5eedffbdab8759434c357d9f5180c12bc4e3594b 100644
--- a/aes-decrypt.c
+++ b/aes-decrypt.c
@@ -23,10 +23,14 @@
  * MA 02111-1307, USA.
  */
 
-#include "aes-internal.h"
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <assert.h>
 
+#include "aes-internal.h"
+
 void
 aes_decrypt(struct aes_ctx *ctx,
 	    unsigned length, uint8_t *dst,
diff --git a/aes-encrypt-table.c b/aes-encrypt-table.c
index 89f796739f0a8c3918637660f523c44107df946b..de21ff9cb2512e791b65dfab7f6c964e2b7b9ed3 100644
--- a/aes-encrypt-table.c
+++ b/aes-encrypt-table.c
@@ -23,6 +23,10 @@
  * MA 02111-1307, USA.
  */
 
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include "aes-internal.h"
 
 /* Tables are assembled using little-endian byte order, including the
diff --git a/aes-encrypt.c b/aes-encrypt.c
index bc6a1cff68684eff7795d50d94f0c4c7e8edd059..466ca3722631ba3f31a7e6cae6803ada4fbbae51 100644
--- a/aes-encrypt.c
+++ b/aes-encrypt.c
@@ -23,10 +23,14 @@
  * MA 02111-1307, USA.
  */
 
-#include "aes-internal.h"
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <assert.h>
 
+#include "aes-internal.h"
+
 /* On my sparc, encryption is significantly slower than decryption,
  * even though the *only* difference is which table is passed to _aes_crypt.
  *
diff --git a/aes-meta.c b/aes-meta.c
index db2a84f0e9a29f2e75a6bccb50d0a3c461bf205b..7b6fc5ac32fb5078a11a32af2cde2b0c061839a3 100644
--- a/aes-meta.c
+++ b/aes-meta.c
@@ -20,6 +20,10 @@
  * MA 02111-1307, USA.
  */
 
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include "nettle-meta.h"
 
 #include "aes.h"
diff --git a/aes-set-decrypt-key.c b/aes-set-decrypt-key.c
index 0247a6e2b7094118d6919dad2cd6e62ed29655af..e0b75ea1705594e1f9b66d6e060c38c96f5373c2 100644
--- a/aes-set-decrypt-key.c
+++ b/aes-set-decrypt-key.c
@@ -25,9 +25,13 @@
 
 /* Originally written by Rafael R. Sevilla <dido@pacific.net.ph> */
 
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include "aes-internal.h"
 
-/* Tables for comoutations in the AES GF2 field. */
+/* Tables for computations in the AES GF2 field. */
 static const uint8_t log[0x100] =
 {
   0x00,0x00,0x19,0x01,0x32,0x02,0x1a,0xc6,
diff --git a/aes-set-encrypt-key.c b/aes-set-encrypt-key.c
index 1dcf05fb01ece59e329ed8d0a3243b7282ddf431..63fb1b46d8a69d9bf16da709dc6118f1def7de5f 100644
--- a/aes-set-encrypt-key.c
+++ b/aes-set-encrypt-key.c
@@ -25,10 +25,14 @@
 
 /* Originally written by Rafael R. Sevilla <dido@pacific.net.ph> */
 
-#include "aes-internal.h"
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <assert.h>
 
+#include "aes-internal.h"
+
 /* Tables for comoutations in the AES GF2 field. */
 static const uint8_t log[0x100] =
 {
diff --git a/aes.c b/aes.c
index cf7ed32845ceaff29b12e5916ad73abe4adfd940..bf5c827cff5bbfd397002c4e7c303204e57b995c 100644
--- a/aes.c
+++ b/aes.c
@@ -25,12 +25,16 @@
 
 /* Originally written by Rafael R. Sevilla <dido@pacific.net.ph> */
 
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <assert.h>
+
 #include "aes-internal.h"
 
 #include "macros.h"
 
-#include <assert.h>
-
 #ifndef AES_DEBUG
 # define AES_DEBUG 0
 #endif
diff --git a/aesdata.c b/aesdata.c
index cb6a5d87c537030690fe078ae9d6dd7fb366f46d..babb382fcfd65be13a756055bdbca9cc03fc92c2 100644
--- a/aesdata.c
+++ b/aesdata.c
@@ -1,3 +1,7 @@
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include <assert.h>
 #include <inttypes.h>
 #include <stdlib.h>
@@ -38,7 +42,7 @@ xtime(unsigned x)
   return x;
 }
 
-/* Computes the expoenntiatiom and logarithm tables for GF_2, to the
+/* Computes the exponentiatiom and logarithm tables for GF_2, to the
  * base x+1 (0x03). The unit element is 1 (0x01).*/
 static void
 compute_log(void)
diff --git a/arcfour-meta.c b/arcfour-meta.c
index 0886a61998f48d883ef9b1f81622cc2706149876..af988ce49921d4500ac31e898a31ce3ea62e8fa5 100644
--- a/arcfour-meta.c
+++ b/arcfour-meta.c
@@ -20,6 +20,10 @@
  * MA 02111-1307, USA.
  */
 
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include "nettle-meta.h"
 
 #include "arcfour.h"
diff --git a/arcfour.c b/arcfour.c
index 70d0fd35f33b70185afa032021ae6d3fd3a187cb..03c9cd8801e0a9bb8c9a2f678abe596c46871ff2 100644
--- a/arcfour.c
+++ b/arcfour.c
@@ -23,10 +23,14 @@
  * MA 02111-1307, USA.
  */
 
-#include "arcfour.h"
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <assert.h>
 
+#include "arcfour.h"
+
 #define SWAP(a,b) do { int _t = a; a = b; b = _t; } while(0)
 
 void
diff --git a/base16-decode.c b/base16-decode.c
index a5e6185c94d50250dce73995aab7c53f224dae8a..a76d0fe294d6ba4cefcf5ff7a8869a9c93bb5593 100644
--- a/base16-decode.c
+++ b/base16-decode.c
@@ -23,11 +23,15 @@
  * MA 02111-1307, USA.
  */
  
-#include "base16.h"
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <assert.h>
 #include <stdlib.h>
 
+#include "base16.h"
+
 void
 base16_decode_init(struct base16_decode_ctx *ctx)
 {
diff --git a/base16-encode.c b/base16-encode.c
index 48ce3006c4daa029a6e7d36831ab58bff7dc04e9..bc95bc9007c4d5f29b980f872a0167097b1e24a1 100644
--- a/base16-encode.c
+++ b/base16-encode.c
@@ -23,6 +23,10 @@
  * MA 02111-1307, USA.
  */
  
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include "base16.h"
 
 
diff --git a/base16-meta.c b/base16-meta.c
index 89d9a27de47f528ad70bff963d123088a17d5c0f..b3709f39cbfc73d3383c5a023b848a1cbf7fc0dd 100644
--- a/base16-meta.c
+++ b/base16-meta.c
@@ -20,6 +20,10 @@
  * MA 02111-1307, USA.
  */
 
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include "nettle-meta.h"
 
 #include "base16.h"
diff --git a/base64-decode.c b/base64-decode.c
index c1c0d2f08ec41015535caf15d3b779cb92d3edda..0ead7325d4fb9939e11f37ee43d158042135be99 100644
--- a/base64-decode.c
+++ b/base64-decode.c
@@ -22,11 +22,15 @@
  * MA 02111-1307, USA.
  */
 
-#include "base64.h"
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <assert.h>
 #include <stdlib.h>
 
+#include "base64.h"
+
 #define TABLE_INVALID -1
 #define TABLE_SPACE -2
 #define TABLE_END -3
diff --git a/base64-encode.c b/base64-encode.c
index 02aa14a655039c3b21a3cbcaa32b72d6fccaffaf..6fc5e6ba1d256bdec9237b4e35ce25d008a2dd4d 100644
--- a/base64-encode.c
+++ b/base64-encode.c
@@ -22,11 +22,14 @@
  * MA 02111-1307, USA.
  */
 
-#include "base64.h"
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <assert.h>
 #include <stdlib.h>
 
+#include "base64.h"
 
 static const uint8_t encode_table[64] =
   "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
diff --git a/base64-meta.c b/base64-meta.c
index 1c827db873786235e8dc85d34d8ca088edf9f258..608e7b6450ee9a4cf5115f200b4fa78c11e0647e 100644
--- a/base64-meta.c
+++ b/base64-meta.c
@@ -20,6 +20,10 @@
  * MA 02111-1307, USA.
  */
 
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include "nettle-meta.h"
 
 #include "base64.h"
diff --git a/bignum-random.c b/bignum-random.c
index 145ed9b025e51f7c2cf031d65a9a39c40b8c0eed..9b1a404b342bf4d241d8467411796fa497c76d00 100644
--- a/bignum-random.c
+++ b/bignum-random.c
@@ -24,15 +24,15 @@
  */
 
 #if HAVE_CONFIG_H
-#include "config.h"
+# include "config.h"
 #endif
 
 #if HAVE_LIBGMP
 
-#include "bignum.h"
-
 #include <stdlib.h>
 
+#include "bignum.h"
+
 void
 nettle_mpz_random_size(mpz_t x,
 		       void *ctx, nettle_random_func random,
diff --git a/bignum.c b/bignum.c
index 59bca94e01d4f1f8b11f02d028beb7f35043ba2d..f9f12034b7a0012b36c31b5b9ca540d5d77a5552 100644
--- a/bignum.c
+++ b/bignum.c
@@ -24,16 +24,16 @@
  */
 
 #if HAVE_CONFIG_H
-#include "config.h"
+# include "config.h"
 #endif
 
 #if HAVE_LIBGMP
 
-#include "bignum.h"
-
 #include <assert.h>
 #include <string.h>
 
+#include "bignum.h"
+
 /* Two's complement negation means that -x = ~x + 1, ~x = -(x+1),
  * and we use that x = ~~x = ~(-x-1).
  *
diff --git a/blowfish.c b/blowfish.c
index fa0657e0444ec9d8b59e228fcfe379eb0a041b70..3cfb76c3172ffe726e750a5d02156025b973d529 100644
--- a/blowfish.c
+++ b/blowfish.c
@@ -31,12 +31,16 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <assert.h>
+
 #include "blowfish.h"
 
 #include "macros.h"
 
-#include <assert.h>
-
 /* Initial keysetup state */
 static const struct blowfish_ctx
 initial_ctx =
diff --git a/buffer-init.c b/buffer-init.c
index 242cacad38d476728de29828811552ab694e2e19..1eccd7fc728985720a341e7346756a9df0d8cf8c 100644
--- a/buffer-init.c
+++ b/buffer-init.c
@@ -22,11 +22,15 @@
  * MA 02111-1307, USA.
  */
 
-#include "buffer.h"
-#include "realloc.h"
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <stdlib.h>
 
+#include "buffer.h"
+#include "realloc.h"
+
 /* This is in a separate file so that we don't link in realloc in
  * programs that don't need it. */
 
diff --git a/buffer.c b/buffer.c
index fe875412679b1806fac1bdcee41ef0be924a3ac7..4e96b552ede766d7e8181704561ae15c4c17b595 100644
--- a/buffer.c
+++ b/buffer.c
@@ -23,12 +23,16 @@
  * MA 02111-1307, USA.
  */
 
-#include "buffer.h"
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <assert.h>
 #include <stdlib.h>
 #include <string.h>
 
+#include "buffer.h"
+
 int
 nettle_buffer_grow(struct nettle_buffer *buffer,
 		   unsigned length)
diff --git a/cast128-meta.c b/cast128-meta.c
index a0343722e97aab0fe58dfc55ba86544a1cb68604..5c15a08e467b0b194a1222465be327e020b9d54e 100644
--- a/cast128-meta.c
+++ b/cast128-meta.c
@@ -20,6 +20,10 @@
  * MA 02111-1307, USA.
  */
 
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include "nettle-meta.h"
 
 #include "cast128.h"
diff --git a/cast128.c b/cast128.c
index 75783e5dd753addee9df20bf4190b31a4a7860e0..4abbafb358bba5ca85ac1e469dc077962ea451c6 100644
--- a/cast128.c
+++ b/cast128.c
@@ -29,13 +29,17 @@
  * MA 02111-1307, USA.
  */
 
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <assert.h>
+
 #include "cast128.h"
 #include "cast128_sboxes.h"
 
 #include "macros.h"
 
-#include <assert.h>
-
 #define CAST_SMALL_KEY 10
 #define CAST_SMALL_ROUNDS 12
 #define CAST_FULL_ROUNDS 16
diff --git a/cbc.c b/cbc.c
index 0eb96f022df27e0c1a586df7c686f9ad0599b775..7e9b4a3a2d44f86ad743d1e26a3697461cbd8f2e 100644
--- a/cbc.c
+++ b/cbc.c
@@ -23,14 +23,18 @@
  * MA 02111-1307, USA.
  */
 
-#include "cbc.h"
-
-#include "memxor.h"
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
 
 #include <assert.h>
 #include <stdlib.h>
 #include <string.h>
 
+#include "cbc.h"
+
+#include "memxor.h"
+
 void
 cbc_encrypt(void *ctx, void (*f)(void *ctx,
 				 unsigned length, uint8_t *dst,
diff --git a/des-compat.c b/des-compat.c
index da8f61a6244c6bb180d0a66046b09b6eeeab5777..51aada3e7ec6d3329cd0d13a6eb698816eb4cf9f 100644
--- a/des-compat.c
+++ b/des-compat.c
@@ -23,15 +23,19 @@
  * MA 02111-1307, USA.
  */
 
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <string.h>
+#include <assert.h>
+
 #include "des-compat.h"
 
 #include "cbc.h"
 #include "macros.h"
 #include "memxor.h"
 
-#include <string.h>
-#include <assert.h>
-
 struct des_compat_des3 { struct des_ctx *keys[3]; }; 
 
 typedef void (*cbc_crypt_func)(void *, uint32_t, uint8_t *, const uint8_t *);
diff --git a/des.c b/des.c
index 9f4f32522914ba3c10e0828fc13f0c8b1d1e0e07..cccfe0d46ac8603b7b6d34760824160c8a8b389a 100644
--- a/des.c
+++ b/des.c
@@ -30,12 +30,16 @@
  *	Please see the file `descore.README' for the complete copyright notice.
  */
 
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <assert.h>
+
 #include "des.h"
 
 #include "desCode.h"
 
-#include <assert.h>
-
 static ENCRYPT(DesSmallFipsEncrypt,TEMPSMALL, LOADFIPS,KEYMAPSMALL,SAVEFIPS)
 static DECRYPT(DesSmallFipsDecrypt,TEMPSMALL, LOADFIPS,KEYMAPSMALL,SAVEFIPS)
 
diff --git a/des3.c b/des3.c
index 85186c336b90d8e7202da43d9e0fb94cc8ffe620..6bba214de7236f58b4f2b3087314526615b64f9a 100644
--- a/des3.c
+++ b/des3.c
@@ -23,6 +23,10 @@
  * MA 02111-1307, USA.
  */
 
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include "des.h"
 
 /* It's possible to make some more general pipe construction, like the
diff --git a/dsa-keygen.c b/dsa-keygen.c
index 0e2b9cb7eb5cdbbc35c0e98bced96d40580f9a26..2bd9fd660398d5008c66368c4aeb22cde3cf67d5 100644
--- a/dsa-keygen.c
+++ b/dsa-keygen.c
@@ -24,18 +24,18 @@
  */
 
 #if HAVE_CONFIG_H
-#include "config.h"
+# include "config.h"
 #endif
 
 #if WITH_PUBLIC_KEY
 
+#include <stdlib.h>
+
 #include "dsa.h"
 
 #include "bignum.h"
 #include "memxor.h"
 
-#include <stdlib.h>
-
 /* The (slow) NIST method of generating DSA primes. Algorithm 4.56 of
  * Handbook of Applied Cryptography. */
 
diff --git a/dsa-sign.c b/dsa-sign.c
index 605a8ca0f496cf448ccf45a608c016e358816186..7204e7fc88adcef1d8c46a8ab900cbb3575edc91 100644
--- a/dsa-sign.c
+++ b/dsa-sign.c
@@ -24,17 +24,17 @@
  */
 
 #if HAVE_CONFIG_H
-#include "config.h"
+# include "config.h"
 #endif
 
 #if WITH_PUBLIC_KEY
 
+#include <stdlib.h>
+
 #include "dsa.h"
 
 #include "bignum.h"
 
-#include <stdlib.h>
-
 
 void
 dsa_sign_digest(const struct dsa_public_key *pub,
diff --git a/dsa-verify.c b/dsa-verify.c
index 87c2a48a091f2f8a94453bdafd2c16a4bc979fe1..798f1ab8664cf4692b5710757e4e390007a4225f 100644
--- a/dsa-verify.c
+++ b/dsa-verify.c
@@ -24,17 +24,17 @@
  */
 
 #if HAVE_CONFIG_H
-#include "config.h"
+# include "config.h"
 #endif
 
 #if WITH_PUBLIC_KEY
 
+#include <stdlib.h>
+
 #include "dsa.h"
 
 #include "bignum.h"
 
-#include <stdlib.h>
-
 int
 dsa_verify_digest(const struct dsa_public_key *key,
 		  const uint8_t *digest,
diff --git a/dsa.c b/dsa.c
index 8b9a37d61dd4c3668923ddd4a4dc75748a7dc062..ed733b6c4af345a79a612ea523dcf37161740774 100644
--- a/dsa.c
+++ b/dsa.c
@@ -24,7 +24,7 @@
  */
 
 #if HAVE_CONFIG_H
-#include "config.h"
+# include "config.h"
 #endif
 
 #if WITH_PUBLIC_KEY
diff --git a/examples/io.c b/examples/io.c
index 34d690825a7bec3432b16844be1849173132eb8b..48d7b801ea86f3780a742a23ec86d3613d29296e 100644
--- a/examples/io.c
+++ b/examples/io.c
@@ -25,13 +25,13 @@
 
 #if HAVE_CONFIG_H
 # include "config.h"
-#endif /* HAVE_CONFIG_H */
-
-#include "io.h"
+#endif
 
 #include <stdarg.h>
 #include <stdlib.h>
 
+#include "io.h"
+
 #define RANDOM_DEVICE "/dev/urandom"
 #define BUFSIZE 1000
 
diff --git a/examples/nettle-benchmark.c b/examples/nettle-benchmark.c
index 98799c1ca15cfafd75f2f05c68669adce95cd1f6..49e39f987f4805425c2b984b16df72581684187e 100644
--- a/examples/nettle-benchmark.c
+++ b/examples/nettle-benchmark.c
@@ -26,7 +26,15 @@
 
 #if HAVE_CONFIG_H
 # include "config.h"
-#endif /* HAVE_CONFIG_H */
+#endif
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <time.h>
 
 #include "aes.h"
 #include "arcfour.h"
@@ -41,19 +49,6 @@
 
 #include "cbc.h"
 
-#include <assert.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <time.h>
-
-#if __GNUC__
-# define UNUSED __attribute__ ((__unused__))
-#else
-# define UNUSED
-#endif
 
 /* Encrypt 10MB, 1K at a time. */
 #define BENCH_BLOCK 1024
diff --git a/examples/nettle-openssl.c b/examples/nettle-openssl.c
index 029fc637d3dbe4bd465a8f93f60179c568698a04..f50490aa21ddb0cfc124ace285627919fda80ab3 100644
--- a/examples/nettle-openssl.c
+++ b/examples/nettle-openssl.c
@@ -25,19 +25,19 @@
 
 #if HAVE_CONFIG_H
 # include "config.h"
-#endif /* HAVE_CONFIG_H */
+#endif
 
 /* Openssl glue, for comparative benchmarking only */
 
 #if HAVE_LIBCRYPTO
 
-#include "nettle-internal.h"
+#include <assert.h>
 
 #include <openssl/blowfish.h>
 #include <openssl/des.h>
 #include <openssl/cast.h>
 
-#include <assert.h>
+#include "nettle-internal.h"
 
 
 /* Blowfish */
diff --git a/examples/rsa-keygen.c b/examples/rsa-keygen.c
index 95c29b94f6cfe66c5dab6385783751c1b9ef9f48..da11eda8b74040b7bd86e402a222c9af934f1537 100644
--- a/examples/rsa-keygen.c
+++ b/examples/rsa-keygen.c
@@ -22,12 +22,9 @@
  * MA 02111-1307, USA.
  */
 
-#include "buffer.h"
-#include "rsa.h"
-#include "sexp.h"
-#include "yarrow.h"
-
-#include "io.h"
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <ctype.h>
 #include <errno.h>
@@ -38,6 +35,13 @@
 /* For getopt */
 #include <unistd.h>
 
+#include "buffer.h"
+#include "rsa.h"
+#include "sexp.h"
+#include "yarrow.h"
+
+#include "io.h"
+
 #define KEYSIZE 500
 #define ESIZE 30
 
diff --git a/examples/rsa-sign.c b/examples/rsa-sign.c
index ad653a534e456dabc0b86f09dc13472b40978fe8..3a97b26c55a16b2a1e5ce936edb8e53675ddd2d5 100644
--- a/examples/rsa-sign.c
+++ b/examples/rsa-sign.c
@@ -22,6 +22,10 @@
  * MA 02111-1307, USA.
  */
 
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include <errno.h>
 #include <stdlib.h>
 #include <stdio.h>
diff --git a/examples/rsa-verify.c b/examples/rsa-verify.c
index 95fa608d0c1aa014077faf3565c8958f7e264bc2..ad808d0f02741256da4681f13120d01e0ff60d7b 100644
--- a/examples/rsa-verify.c
+++ b/examples/rsa-verify.c
@@ -22,15 +22,18 @@
  * MA 02111-1307, USA.
  */
 
-
-#include "rsa.h"
-#include "io.h"
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <errno.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 
+#include "rsa.h"
+#include "io.h"
+
 static int
 read_signature(const char *name, mpz_t s)
 {
diff --git a/hmac-md5.c b/hmac-md5.c
index 647d0e6ed0f6fc94099dc0505598c786159b955b..99ce1f9347a0c20901d367616749364f8f9fdbd7 100644
--- a/hmac-md5.c
+++ b/hmac-md5.c
@@ -23,6 +23,10 @@
  * MA 02111-1307, USA.
  */
 
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include "hmac.h"
 
 void
diff --git a/hmac-sha1.c b/hmac-sha1.c
index fab0fe4d86ff367059514c79ae42f2d83bf8e3b2..64c079e52dd0408bcbbaf4bbaa6215a3921fa82c 100644
--- a/hmac-sha1.c
+++ b/hmac-sha1.c
@@ -23,6 +23,10 @@
  * MA 02111-1307, USA.
  */
 
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include "hmac.h"
 
 void
diff --git a/hmac-sha256.c b/hmac-sha256.c
index df285c59ba176b1a5513f4334da4340d73b6c4c5..9ead853b5ce358986be683ab23c17966e6ab7fe9 100644
--- a/hmac-sha256.c
+++ b/hmac-sha256.c
@@ -23,6 +23,10 @@
  * MA 02111-1307, USA.
  */
 
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include "hmac.h"
 
 void
diff --git a/hmac.c b/hmac.c
index c4fc7f02bd7e20c910ff4428e689ec5ba22d4cc0..2d8a61f6ace95f08adfb38069ea031b3d29560a5 100644
--- a/hmac.c
+++ b/hmac.c
@@ -23,13 +23,17 @@
  * MA 02111-1307, USA.
  */
 
-#include "hmac.h"
-
-#include "memxor.h"
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
 
 #include <assert.h>
 #include <string.h>
 
+#include "hmac.h"
+
+#include "memxor.h"
+
 #define IPAD 0x36
 #define OPAD 0x5c
 
diff --git a/knuth-lfib.c b/knuth-lfib.c
index 4188a0661f23631fd03e5f50dfb77bf4382f5542..bb867d2ff8c3e5964919d180e3182e22ebc1f4cb 100644
--- a/knuth-lfib.c
+++ b/knuth-lfib.c
@@ -31,13 +31,17 @@
  * applications. It is useful for generating deterministic but
  * random-looking test data, and is used by the Nettle testsuite. */
 
-#include "knuth-lfib.h"
-
-#include "macros.h"
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
 
 #include <assert.h>
 #include <stdlib.h>
 
+#include "knuth-lfib.h"
+
+#include "macros.h"
+
 #define KK _KNUTH_LFIB_KK
 #define LL 37
 #define MM (1UL << 30)
diff --git a/md5-compat.c b/md5-compat.c
index f6e0acf1abeccb5b0ace8a9436cbb6ab902c3bd0..1ed7b29adbc0982d62594ca58b8a30e13a93abf5 100644
--- a/md5-compat.c
+++ b/md5-compat.c
@@ -23,6 +23,10 @@
  * MA 02111-1307, USA.
  */
 
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
 #include "md5-compat.h"
 
 void
diff --git a/md5-meta.c b/md5-meta.c
index f0af237913cb14aba2e4a9cb9f347acc8dc7bd58..1bf34ccc3c67d56006e195b7660a3aedbd2a7b7a 100644
--- a/md5-meta.c
+++ b/md5-meta.c
@@ -20,6 +20,10 @@
  * MA 02111-1307, USA.
  */
 
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
 #include "nettle-meta.h"
 
 #include "md5.h"
diff --git a/md5.c b/md5.c
index e1a254214b7824dff9dbdd42cca44d2401288557..bdfc51c33aa651879ecd3c79031623aaa29693fd 100644
--- a/md5.c
+++ b/md5.c
@@ -26,13 +26,17 @@
 /* Based on public domain code hacked by Colin Plumb, Andrew Kuchling, and
  * Niels Möller. */
 
-#include "md5.h"
-
-#include "macros.h"
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
 
 #include <assert.h>
 #include <string.h>
 
+#include "md5.h"
+
+#include "macros.h"
+
 /* A block, treated as a sequence of 32-bit words. */
 #define MD5_DATA_LENGTH 16
 
diff --git a/memxor.c b/memxor.c
index b3a8ae22680776755f14e2b18136f21d3a5d777b..990b40f48df678d76e2b99be27f5eae3104f155f 100644
--- a/memxor.c
+++ b/memxor.c
@@ -7,6 +7,10 @@
    if the source overlaps with the destination.
    Return DESTADDR. */
 
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
 #include "memxor.h"
 
 uint8_t *memxor(uint8_t *dst, const uint8_t *src, size_t n)
diff --git a/nettle-internal.c b/nettle-internal.c
index 52e79b0bc5cf827c2b1a167c8f6bd0dc704a34d3..069dcce3c57ecd5804a5fb013e3e3a30d4ffb399 100644
--- a/nettle-internal.c
+++ b/nettle-internal.c
@@ -24,13 +24,17 @@
  * MA 02111-1307, USA.
  */
 
-#include "nettle-internal.h"
-#include "des.h"
-#include "blowfish.h"
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
 
 #include <assert.h>
 #include <stdlib.h>
 
+#include "nettle-internal.h"
+#include "des.h"
+#include "blowfish.h"
+
 /* DES uses a different signature for the key set function.
  * And we have to adjust parity. */
 static void
diff --git a/pgp-encode.c b/pgp-encode.c
index 744326ef415e0e485535e914b73d56583dd090c8..aa4b96b51f2d8bee3f87d42b8923acbbcd20313e 100644
--- a/pgp-encode.c
+++ b/pgp-encode.c
@@ -23,16 +23,20 @@
  * MA 02111-1307, USA.
  */
 
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
 #include "pgp.h"
 
 #include "base64.h"
 #include "buffer.h"
 #include "macros.h"
 
-#include <assert.h>
-#include <stdlib.h>
-#include <string.h>
-
 int
 pgp_put_uint32(struct nettle_buffer *buffer, uint32_t i)
 {
diff --git a/pkcs1-rsa-md5.c b/pkcs1-rsa-md5.c
index 5273ee8ed84113f465c3a901d56b9719085e3e74..c337232ddc14a1bb9ce30580940bcd44d83c8508 100644
--- a/pkcs1-rsa-md5.c
+++ b/pkcs1-rsa-md5.c
@@ -24,20 +24,20 @@
  */
 
 #if HAVE_CONFIG_H
-#include "config.h"
+# include "config.h"
 #endif
 
 #if WITH_PUBLIC_KEY
 
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
 #include "rsa.h"
 
 #include "bignum.h"
 #include "pkcs1.h"
 
-#include <assert.h>
-#include <stdlib.h>
-#include <string.h>
-
 /* From pkcs-1v2
  *
  *   md5 OBJECT IDENTIFIER ::=
diff --git a/pkcs1-rsa-sha1.c b/pkcs1-rsa-sha1.c
index 9517411945e06f9a81ef95d1b3ad3fea3b0ce983..b2f94a89635c440b9e64bdbc07f8d9bfb0ed75fa 100644
--- a/pkcs1-rsa-sha1.c
+++ b/pkcs1-rsa-sha1.c
@@ -24,20 +24,20 @@
  */
 
 #if HAVE_CONFIG_H
-#include "config.h"
+# include "config.h"
 #endif
 
 #if WITH_PUBLIC_KEY
 
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
 #include "rsa.h"
 
 #include "bignum.h"
 #include "pkcs1.h"
 
-#include <assert.h>
-#include <stdlib.h>
-#include <string.h>
-
 /* From pkcs-1v2
  *
  *   id-sha1 OBJECT IDENTIFIER ::=
diff --git a/pkcs1.c b/pkcs1.c
index 104af2acb158e5bde4f21dc8411fe3ab1ade4b14..f88936916019327a717da6465c01e3fcf0392a24 100644
--- a/pkcs1.c
+++ b/pkcs1.c
@@ -24,16 +24,16 @@
  */
 
 #if HAVE_CONFIG_H
-#include "config.h"
+# include "config.h"
 #endif
 
 #if WITH_PUBLIC_KEY
 
-#include "pkcs1.h"
-
 #include <assert.h>
 #include <string.h>
 
+#include "pkcs1.h"
+
 void
 pkcs1_signature_prefix(unsigned length,
 		       uint8_t *buffer,
diff --git a/realloc.c b/realloc.c
index 59500dfa7e390da640691782c6c2716eeda72b7b..57e6d428e68a09f5a4bea680b064f95b66f07254 100644
--- a/realloc.c
+++ b/realloc.c
@@ -26,11 +26,11 @@
 # include "config.h"
 #endif
 
-#include "realloc.h"
-
 #include <stdlib.h>
 #include <stdio.h>
 
+#include "realloc.h"
+
 void *
 nettle_realloc(void *ctx UNUSED, void *p, unsigned length)
 {
diff --git a/rsa-compat.c b/rsa-compat.c
index a5db6755138faddf535f0f8377d00bd6b28afb5f..6e9943856974deb0564447f6cdde4f8dc63229d6 100644
--- a/rsa-compat.c
+++ b/rsa-compat.c
@@ -24,7 +24,7 @@
  */
 
 #if HAVE_CONFIG_H
-#include "config.h"
+# include "config.h"
 #endif
 
 #if WITH_PUBLIC_KEY
diff --git a/rsa-decrypt.c b/rsa-decrypt.c
index 41f720a056ef3a2915116b8030c64f8b94fe01a7..6f53c3dbf745a3ec25c13993471262f659d38bb1 100644
--- a/rsa-decrypt.c
+++ b/rsa-decrypt.c
@@ -24,19 +24,19 @@
  */
 
 #if HAVE_CONFIG_H
-#include "config.h"
+# include "config.h"
 #endif
 
 #if WITH_PUBLIC_KEY
 
-#include "rsa.h"
-
-#include "bignum.h"
-
 #include <assert.h>
 #include <stdlib.h>
 #include <string.h>
 
+#include "rsa.h"
+
+#include "bignum.h"
+
 int
 rsa_decrypt(const struct rsa_private_key *key,
 	    unsigned *length, uint8_t *message,
diff --git a/rsa-encrypt.c b/rsa-encrypt.c
index 66a08c0fabf7c8f4b6a8c3c699cc7af82ec257b4..8dbf04bc73f50993ac429f8068360d4cda358314 100644
--- a/rsa-encrypt.c
+++ b/rsa-encrypt.c
@@ -24,19 +24,19 @@
  */
 
 #if HAVE_CONFIG_H
-#include "config.h"
+# include "config.h"
 #endif
 
 #if WITH_PUBLIC_KEY
 
-#include "rsa.h"
-
-#include "bignum.h"
-
 #include <assert.h>
 #include <stdlib.h>
 #include <string.h>
 
+#include "rsa.h"
+
+#include "bignum.h"
+
 int
 rsa_encrypt(const struct rsa_public_key *key,
 	    /* For padding */
diff --git a/rsa-keygen.c b/rsa-keygen.c
index 14f0063afc06b32627cdbf8cece43829925a4fec..fc465f6ff5bc8bfaa990caa5b60989b32107e52d 100644
--- a/rsa-keygen.c
+++ b/rsa-keygen.c
@@ -24,18 +24,18 @@
  */
 
 #if HAVE_CONFIG_H
-#include "config.h"
+# include "config.h"
 #endif
 
 #if WITH_PUBLIC_KEY
 
-#include "rsa.h"
-#include "bignum.h"
-
 #include <assert.h>
 #include <limits.h>
 #include <stdlib.h>
 
+#include "rsa.h"
+#include "bignum.h"
+
 #ifndef DEBUG
 # define DEBUG 0
 #endif
diff --git a/rsa-md5-sign.c b/rsa-md5-sign.c
index 4bcaf717a182cd39aa1973660796e833413d7b40..710baa78a850f9d5ea46dfcaeb604b6e9f643a75 100644
--- a/rsa-md5-sign.c
+++ b/rsa-md5-sign.c
@@ -24,18 +24,18 @@
  */
 
 #if HAVE_CONFIG_H
-#include "config.h"
+# include "config.h"
 #endif
 
 #if WITH_PUBLIC_KEY
 
+#include <assert.h>
+
 #include "rsa.h"
 
 #include "bignum.h"
 #include "pkcs1.h"
 
-#include <assert.h>
-
 void
 rsa_md5_sign(const struct rsa_private_key *key,
              struct md5_ctx *hash,
diff --git a/rsa-md5-verify.c b/rsa-md5-verify.c
index 727cc8e6f24adec6f9f1d6168cbedfafa200fc63..5b8d43410efe06c1013361fedad8f5cbf7941919 100644
--- a/rsa-md5-verify.c
+++ b/rsa-md5-verify.c
@@ -24,18 +24,18 @@
  */
 
 #if HAVE_CONFIG_H
-#include "config.h"
+# include "config.h"
 #endif
 
 #if WITH_PUBLIC_KEY
 
+#include <assert.h>
+
 #include "rsa.h"
 
 #include "bignum.h"
 #include "pkcs1.h"
 
-#include <assert.h>
-
 int
 rsa_md5_verify(const struct rsa_public_key *key,
                struct md5_ctx *hash,
diff --git a/rsa-sha1-sign.c b/rsa-sha1-sign.c
index d48bb802af3a30d66af303cfcb2bb14e3a22be81..a3eea7a6aed93cadfde959bef3abdee69c4c7454 100644
--- a/rsa-sha1-sign.c
+++ b/rsa-sha1-sign.c
@@ -24,18 +24,18 @@
  */
 
 #if HAVE_CONFIG_H
-#include "config.h"
+# include "config.h"
 #endif
 
 #if WITH_PUBLIC_KEY
 
-#include "rsa.h"
+#include <assert.h>
+
+include "rsa.h"
 
 #include "bignum.h"
 #include "pkcs1.h"
 
-#include <assert.h>
-
 void
 rsa_sha1_sign(const struct rsa_private_key *key,
               struct sha1_ctx *hash,
diff --git a/rsa-sha1-verify.c b/rsa-sha1-verify.c
index 717a392d5a72640e47ba75c3c8ef4567f192577f..f1dd2fd81f21f0c895a48995d7a3dc6e61064139 100644
--- a/rsa-sha1-verify.c
+++ b/rsa-sha1-verify.c
@@ -24,18 +24,18 @@
  */
 
 #if HAVE_CONFIG_H
-#include "config.h"
+# include "config.h"
 #endif
 
 #if WITH_PUBLIC_KEY
 
+#include <assert.h>
+
 #include "rsa.h"
 
 #include "bignum.h"
 #include "pkcs1.h"
 
-#include <assert.h>
-
 int
 rsa_sha1_verify(const struct rsa_public_key *key,
                 struct sha1_ctx *hash,
diff --git a/rsa-sign.c b/rsa-sign.c
index 7eb46280dbdf507c834c55dd942513d48f5e514b..5a89b4ac751952248a45dbec04b18c07bfb6d16a 100644
--- a/rsa-sign.c
+++ b/rsa-sign.c
@@ -24,7 +24,7 @@
  */
 
 #if HAVE_CONFIG_H
-#include "config.h"
+# include "config.h"
 #endif
 
 #if WITH_PUBLIC_KEY
diff --git a/rsa-verify.c b/rsa-verify.c
index 7a6d381fd59b13f4775214bf08967f2d4f1343f7..c872dd0221360d3f2a41819dcbef0bd19fb82d36 100644
--- a/rsa-verify.c
+++ b/rsa-verify.c
@@ -24,7 +24,7 @@
  */
 
 #if HAVE_CONFIG_H
-#include "config.h"
+# include "config.h"
 #endif
 
 #if WITH_PUBLIC_KEY
diff --git a/rsa.c b/rsa.c
index 1e1ffb8c73ec285c315086a7d4a77434e5200f55..9fd77c92a7b0537f17780377957bc70d74c67dbb 100644
--- a/rsa.c
+++ b/rsa.c
@@ -24,7 +24,7 @@
  */
 
 #if HAVE_CONFIG_H
-#include "config.h"
+# include "config.h"
 #endif
 
 #if WITH_PUBLIC_KEY
@@ -33,10 +33,6 @@
 
 #include "bignum.h"
 
-/* FIXME: Perhaps we should split this into several functions, so that
- * one can link in the signature functions without also getting the
- * verify functions. */
-
 void
 rsa_public_key_init(struct rsa_public_key *key)
 {
diff --git a/rsa2openpgp.c b/rsa2openpgp.c
index 87012855a0b40a82d71465c8a2e8ae4c087c923f..f3f01f07b9e4fbc0372f51a57910f8a52aeef963 100644
--- a/rsa2openpgp.c
+++ b/rsa2openpgp.c
@@ -23,15 +23,19 @@
  * MA 02111-1307, USA.
  */
 
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #if WITH_PUBLIC_KEY
 
+#include <time.h>
+
 #include "rsa.h"
 
 #include "buffer.h"
 #include "pgp.h"
 
-#include <time.h>
-
 
 /* According to RFC 2440, a public key consists of the following packets:
  *
diff --git a/rsa2sexp.c b/rsa2sexp.c
index 75f5645c75e01e3dfd0915ccde537110e6f471b8..26720aa9fd9f151e4cd5843b983e992ee0856c8c 100644
--- a/rsa2sexp.c
+++ b/rsa2sexp.c
@@ -23,7 +23,7 @@
  */
 
 #if HAVE_CONFIG_H
-#include "config.h"
+# include "config.h"
 #endif
 
 #if WITH_PUBLIC_KEY
diff --git a/serpent-meta.c b/serpent-meta.c
index b95c49dc3254868ebbf5c24fe5085afdf6664470..204d2a16fd1578b0322ee32acbc92729a60d0dca 100644
--- a/serpent-meta.c
+++ b/serpent-meta.c
@@ -20,6 +20,10 @@
  * MA 02111-1307, USA.
  */
 
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include "nettle-meta.h"
 
 #include "serpent.h"
diff --git a/serpent.c b/serpent.c
index 1e7cb419c75731b0a3410d4f20277b77e3ac59df..db41b820eac15aa472a0aed78b80db5c2facb797 100644
--- a/serpent.c
+++ b/serpent.c
@@ -35,16 +35,17 @@
  * selection process. No other use is allowed." However, the authors
  * later decided to GPL the code. /nisse */
 
-/* FIXME: Use the READ_UINT32 and WRITE_UINT32 macros, where
- * applicable. */
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <assert.h>
 
 #include "serpent.h"
 #include "serpent_sboxes.h"
 
 #include "macros.h"
 
-#include <assert.h>
-
 void
 serpent_set_key(struct serpent_ctx *ctx,
                 unsigned key_size, const uint8_t *key)
diff --git a/sexp-format.c b/sexp-format.c
index 134a081d5eb6f43fb053d577b8ba5d4181a25ca7..94601b6bc90856b8825377f441385a6fea8e9dd1 100644
--- a/sexp-format.c
+++ b/sexp-format.c
@@ -24,18 +24,18 @@
  */
 
 #if HAVE_CONFIG_H
-#include "config.h"
+# include "config.h"
 #endif
 
-#include "sexp.h"
-#include "buffer.h"
-
 #include <assert.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
+#include "sexp.h"
+#include "buffer.h"
+
 #if HAVE_LIBGMP
 # include "bignum.h"
 #endif
diff --git a/sexp-transport-format.c b/sexp-transport-format.c
index feb685dcd15adf39e496f9c5e71dd25f8cef458a..c8ac89cd4d819d6b1907cc1e035169d09c2bdc53 100644
--- a/sexp-transport-format.c
+++ b/sexp-transport-format.c
@@ -23,6 +23,10 @@
  * MA 02111-1307, USA.
  */
 
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include "sexp.h"
 
 #include "base64.h"
diff --git a/sexp-transport.c b/sexp-transport.c
index a0d7b1d3637d02bf2074139eff221a375474f6eb..37865e709dbc360d65bcbae84af029e88d626cee 100644
--- a/sexp-transport.c
+++ b/sexp-transport.c
@@ -23,13 +23,17 @@
  * MA 02111-1307, USA.
  */
 
-#include "sexp.h"
-
-#include "base64.h"
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <assert.h>
 #include <string.h>
 
+#include "sexp.h"
+
+#include "base64.h"
+
 /* NOTE: Decodes the input string in place */
 int
 sexp_transport_iterator_first(struct sexp_iterator *iterator,
diff --git a/sexp.c b/sexp.c
index e246211bb8ba57671ac29a5d001a755decaad463..e6dce172a593351b88ba08384e63f84d393f9e09 100644
--- a/sexp.c
+++ b/sexp.c
@@ -23,13 +23,17 @@
  * MA 02111-1307, USA.
  */
 
-#include "sexp.h"
-
-#include "macros.h"
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <stdlib.h>
 #include <string.h>
 
+#include "sexp.h"
+
+#include "macros.h"
+
 /* Initializes the iterator, but one has to call next to get to the
  * first element. */
 static void
diff --git a/sexp2bignum.c b/sexp2bignum.c
index e75e6988c6a3d6e626023dbfe98d1615b14512d6..56b5703e4193d415de26a2b55d6afbad589565d6 100644
--- a/sexp2bignum.c
+++ b/sexp2bignum.c
@@ -23,7 +23,7 @@
  */
 
 #if HAVE_CONFIG_H
-#include "config.h"
+# include "config.h"
 #endif
 
 #if HAVE_LIBGMP
diff --git a/sexp2dsa.c b/sexp2dsa.c
index 4d99cf4a7d0cf9cbef434399ab293732570ab4ea..cb76853fcdc978020adff014c1b93901ccd0229a 100644
--- a/sexp2dsa.c
+++ b/sexp2dsa.c
@@ -23,18 +23,18 @@
  */
 
 #if HAVE_CONFIG_H
-#include "config.h"
+# include "config.h"
 #endif
 
 #if WITH_PUBLIC_KEY
 
+#include <string.h>
+
 #include "dsa.h"
 
 #include "bignum.h"
 #include "sexp.h"
 
-#include <string.h>
-
 #define GET(x, l, v)				\
 do {						\
   if (!nettle_mpz_set_sexp((x), (l), (v))	\
diff --git a/sexp2rsa.c b/sexp2rsa.c
index f0084d60b3e87261ac252451bc9cdb574183ecf8..48fe3abef46f45d62f2a17822bf28ff519ef278a 100644
--- a/sexp2rsa.c
+++ b/sexp2rsa.c
@@ -23,18 +23,18 @@
  */
 
 #if HAVE_CONFIG_H
-#include "config.h"
+# include "config.h"
 #endif
 
 #if WITH_PUBLIC_KEY
 
+#include <string.h>
+
 #include "rsa.h"
 
 #include "bignum.h"
 #include "sexp.h"
 
-#include <string.h>
-
 #define GET(x, l, v)				\
 do {						\
   if (!nettle_mpz_set_sexp((x), (l), (v))	\
diff --git a/sha1-meta.c b/sha1-meta.c
index c2e0ebb6a4cfe2c79215c83957f39a626ef65d80..d201da8afe81246abd5f7a0bcae2ab90a2ac0359 100644
--- a/sha1-meta.c
+++ b/sha1-meta.c
@@ -20,6 +20,10 @@
  * MA 02111-1307, USA.
  */
 
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include "nettle-meta.h"
 
 #include "sha.h"
diff --git a/sha1.c b/sha1.c
index 18e644b92b8df58c8e27e60c52ef6341ffe34996..391f5479bf350798ca8d81628e1400f5c8d1f7c2 100644
--- a/sha1.c
+++ b/sha1.c
@@ -35,14 +35,18 @@
  * effort (for example the reengineering of a great many Capstone chips).
  */
 
-#include "sha.h"
-
-#include "macros.h"
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <assert.h>
 #include <stdlib.h>
 #include <string.h>
 
+#include "sha.h"
+
+#include "macros.h"
+
 /* A block, treated as a sequence of 32-bit words. */
 #define SHA1_DATA_LENGTH 16
 
diff --git a/sha256-meta.c b/sha256-meta.c
index f60c9fc6ec41bbad82ce7953f320d101d657caaa..c21c7924414510afc8187e8567f7280663217a6a 100644
--- a/sha256-meta.c
+++ b/sha256-meta.c
@@ -20,6 +20,10 @@
  * MA 02111-1307, USA.
  */
 
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include "nettle-meta.h"
 
 #include "sha.h"
diff --git a/sha256.c b/sha256.c
index 76ce5f35399ff2523a16d120e4c49ecde72a71c2..619cb72111926a27961b26bc06fea581f2c0a05d 100644
--- a/sha256.c
+++ b/sha256.c
@@ -25,14 +25,18 @@
 
 /* Modelled after the sha1.c code by Peter Gutmann. */
 
-#include "sha.h"
-
-#include "macros.h"
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <assert.h>
 #include <stdlib.h>
 #include <string.h>
 
+#include "sha.h"
+
+#include "macros.h"
+
 /* A block, treated as a sequence of 32-bit words. */
 #define SHA256_DATA_LENGTH 16
 
diff --git a/tools/input.c b/tools/input.c
index 4e9eda1cf25f04c1b23df8c1b12038296ea5137f..69addb7ebb0c32d59925c314d8f7c333d5f25052 100644
--- a/tools/input.c
+++ b/tools/input.c
@@ -20,13 +20,17 @@
  * MA 02111-1307, USA.
  */
 
-#include "input.h"
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <assert.h>
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
 
+#include "input.h"
+
 void
 sexp_input_init(struct sexp_input *input, FILE *f)
 {
diff --git a/tools/misc.c b/tools/misc.c
index 91c1d50c6e6437c84ac6845cb0517d0b2f297294..c49f81b0d002dd2d251b80f928e654b646cb91d1 100644
--- a/tools/misc.c
+++ b/tools/misc.c
@@ -20,12 +20,16 @@
  * MA 02111-1307, USA.
  */
 
-#include "misc.h"
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 
+#include "misc.h"
+
 void
 die(const char *format, ...)
 {
diff --git a/tools/output.c b/tools/output.c
index 53071d9ee0abc87f6c3a51b68ace666cc7c983a3..d9735f5cabd616b8e9ee1dee1d066d43425ca73c 100644
--- a/tools/output.c
+++ b/tools/output.c
@@ -20,7 +20,9 @@
  * MA 02111-1307, USA.
  */
 
-#include "output.h"
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <assert.h>
 #include <errno.h>
@@ -28,6 +30,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "output.h"
+
 void
 sexp_output_init(struct sexp_output *output, FILE *f,
 		 unsigned width, int prefer_hex)
diff --git a/tools/parse.c b/tools/parse.c
index 6c5f5ada2b4036d9cc2460d9132f1abcc0633338..f48d257831fdab08589cb5f113b1e14d9552e1d9 100644
--- a/tools/parse.c
+++ b/tools/parse.c
@@ -20,13 +20,17 @@
  * MA 02111-1307, USA.
  */
 
-#include "parse.h"
-
-#include "input.h"
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <assert.h>
 #include <stdlib.h>
 
+#include "parse.h"
+
+#include "input.h"
+
 void
 sexp_compound_token_init(struct sexp_compound_token *token)
 {
diff --git a/tools/sexp-conv.c b/tools/sexp-conv.c
index 9e8bc547aeb2aee382f9ec9e895ba8ef33a87eb2..0d6140634f5b744c78a523b4079f056e17b2d5f0 100644
--- a/tools/sexp-conv.c
+++ b/tools/sexp-conv.c
@@ -23,16 +23,9 @@
  * MA 02111-1307, USA.
  */
 
-#define BUG_ADDRESS "nettle-bugs@lists.lysator.liu.se"
-
-#include "buffer.h"
-#include "nettle-meta.h"
-
-#include "getopt.h"
-
-#include "input.h"
-#include "output.h"
-#include "parse.h"
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <assert.h>
 #include <errno.h>
@@ -40,9 +33,16 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "buffer.h"
+#include "nettle-meta.h"
 
+#include "getopt.h"
 
+#include "input.h"
+#include "output.h"
+#include "parse.h"
 
+#define BUG_ADDRESS "nettle-bugs@lists.lysator.liu.se"
 
 
 /* Conversion functions. */
diff --git a/twofish-meta.c b/twofish-meta.c
index 7c3d065ee7a840014dc39c67633d4e8822609bc8..7e463256c563035071dd6f0b59f752d8e63c434f 100644
--- a/twofish-meta.c
+++ b/twofish-meta.c
@@ -20,6 +20,10 @@
  * MA 02111-1307, USA.
  */
 
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include "nettle-meta.h"
 
 #include "twofish.h"
diff --git a/twofish.c b/twofish.c
index 2a341e844b0974c2487edc5e3983c56e9674e39a..9ebcf1b0e1d8a2399ccc71a0ca0207dbce755362 100644
--- a/twofish.c
+++ b/twofish.c
@@ -31,13 +31,17 @@
  * MA 02111-1307, USA.
  */
 
-#include "twofish.h"
-
-#include "macros.h"
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <assert.h>
 #include <string.h>
 
+#include "twofish.h"
+
+#include "macros.h"
+
 /* Bitwise rotations on 32-bit words.  These are defined as macros that
  * evaluate their argument twice, so do not apply to any expressions with
  * side effects.
diff --git a/yarrow256.c b/yarrow256.c
index 6a275d69a6defc77b0a2f9ff7b1d311f7c44c7ef..ba06fdc4ff9f885124dd38bcaa3c09148af558a8 100644
--- a/yarrow256.c
+++ b/yarrow256.c
@@ -23,14 +23,18 @@
  * MA 02111-1307, USA.
  */
 
-#include "yarrow.h"
-
-#include "macros.h"
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <assert.h>
 #include <stdlib.h>
 #include <string.h>
 
+#include "yarrow.h"
+
+#include "macros.h"
+
 #ifndef YARROW_DEBUG
 #define YARROW_DEBUG 0
 #endif
diff --git a/yarrow_key_event.c b/yarrow_key_event.c
index 9b25c96ceb9c6545a4568fc3664914ed4b6df2ef..92360d99e392aa450d7126b16795d040a2f7e1d1 100644
--- a/yarrow_key_event.c
+++ b/yarrow_key_event.c
@@ -22,6 +22,10 @@
  * MA 02111-1307, USA.
  */
 
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include "yarrow.h"
 
 void