 engines/ccgost/gost2001.c      | 5 +++++
 engines/ccgost/gost2001_keyx.c | 5 +++++
 engines/ccgost/gost94_keyx.c   | 5 +++++
 engines/ccgost/gost_ameth.c    | 5 +++++
 engines/ccgost/gost_asn1.c     | 5 +++++
 engines/ccgost/gost_crypt.c    | 5 +++++
 engines/ccgost/gost_ctl.c      | 5 +++++
 engines/ccgost/gost_eng.c      | 5 +++++
 engines/ccgost/gost_md.c       | 5 +++++
 engines/ccgost/gost_pmeth.c    | 5 +++++
 engines/ccgost/gost_sign.c     | 5 +++++
 engines/e_4758cca.c            | 6 +++---
 engines/e_aep.c                | 5 +++--
 engines/e_atalla.c             | 6 +++---
 engines/e_capi.c               | 5 +++++
 engines/e_capi_err.c           | 2 +-
 engines/e_chil.c               | 6 +++---
 engines/e_cswift.c             | 6 +++---
 engines/e_gmp.c                | 3 ++-
 engines/e_nuron.c              | 6 +++---
 engines/e_padlock.c            | 6 +++---
 engines/e_sureware.c           | 6 +++---
 engines/e_ubsec.c              | 6 +++---
 23 files changed, 90 insertions(+), 28 deletions(-)

diff --git a/engines/ccgost/gost2001.c b/engines/ccgost/gost2001.c
index b3eec8a..c2ab276 100644
--- a/engines/ccgost/gost2001.c
+++ b/engines/ccgost/gost2001.c
@@ -6,6 +6,9 @@
  *          Implementation of GOST R 34.10-2001                                   *
  *          Requires OpenSSL 0.9.9 for compilation                    *
  **********************************************************************/
+
+#ifndef OPENSSL_NO_ENGINE
+
 #include "gost_lcl.h"
 #include "gost_params.h"
 #include <string.h>
@@ -337,3 +340,5 @@ int gost2001_keygen(EC_KEY *ec)
     BN_free(order);
     return gost2001_compute_public(ec);
 }
+
+#endif /* !OPENSSL_NO_ENGINE */
diff --git a/engines/ccgost/gost2001_keyx.c b/engines/ccgost/gost2001_keyx.c
index db1bdc1..ff69ca4 100644
--- a/engines/ccgost/gost2001_keyx.c
+++ b/engines/ccgost/gost2001_keyx.c
@@ -7,6 +7,9 @@
  *   based PKCS7/SMIME support                                        *
  *          Requires OpenSSL 0.9.9 for compilation                    *
  **********************************************************************/
+
+ #ifndef OPENSSL_NO_ENGINE
+
 #include <openssl/evp.h>
 #include <openssl/rand.h>
 #include <string.h>
@@ -290,3 +293,5 @@ int pkey_GOST01cp_decrypt(EVP_PKEY_CTX *pctx, unsigned char *key,
         GOST_KEY_TRANSPORT_free(gkt);
     return ret;
 }
+
+#endif /* !OPENSSL_NO_ENGINE */
diff --git a/engines/ccgost/gost94_keyx.c b/engines/ccgost/gost94_keyx.c
index db7d402..7bbbf20 100644
--- a/engines/ccgost/gost94_keyx.c
+++ b/engines/ccgost/gost94_keyx.c
@@ -8,6 +8,9 @@
  *                                                                    *
  *          Requires OpenSSL 0.9.9 for compilation                    *
  **********************************************************************/
+
+#ifndef OPENSSL_NO_ENGINE
+
 #include <string.h>
 #include <openssl/dh.h>
 #include <openssl/rand.h>
@@ -277,3 +280,5 @@ int pkey_GOST94cp_decrypt(EVP_PKEY_CTX *ctx, unsigned char *key,
     GOST_KEY_TRANSPORT_free(gkt);
     return -1;
 }
+
+#endif /* !OPENSSL_NO_ENGINE */
diff --git a/engines/ccgost/gost_ameth.c b/engines/ccgost/gost_ameth.c
index ad8480d..f01796a 100644
--- a/engines/ccgost/gost_ameth.c
+++ b/engines/ccgost/gost_ameth.c
@@ -7,6 +7,9 @@
  *       for OpenSSL                                                  *
  *          Requires OpenSSL 0.9.9 for compilation                    *
  **********************************************************************/
+
+#ifndef OPENSSL_NO_ENGINE
+ 
 #include <string.h>
 #include <openssl/crypto.h>
 #include <openssl/err.h>
@@ -944,3 +947,5 @@ int register_ameth_gost(int nid, EVP_PKEY_ASN1_METHOD **ameth,
     }
     return 1;
 }
+
+#endif /* !OPENSSL_NO_ENGINE */
diff --git a/engines/ccgost/gost_asn1.c b/engines/ccgost/gost_asn1.c
index 1168633..499771b 100644
--- a/engines/ccgost/gost_asn1.c
+++ b/engines/ccgost/gost_asn1.c
@@ -6,6 +6,9 @@
  *   ASN1 structure definition for GOST key transport                 *
  *          Requires OpenSSL 0.9.9 for compilation                    *
  **********************************************************************/
+
+#ifndef OPENSSL_NO_ENGINE
+
 #include <stdio.h>
 #include <openssl/asn1t.h>
 #include <openssl/x509.h>
@@ -54,3 +57,5 @@ ASN1_NDEF_SEQUENCE(GOST_CLIENT_KEY_EXCHANGE_PARAMS) = { /* FIXME incomplete */
 
 ASN1_NDEF_SEQUENCE_END(GOST_CLIENT_KEY_EXCHANGE_PARAMS)
 IMPLEMENT_ASN1_FUNCTIONS(GOST_CLIENT_KEY_EXCHANGE_PARAMS)
+
+#endif /* !OPENSSL_NO_ENGINE */
diff --git a/engines/ccgost/gost_crypt.c b/engines/ccgost/gost_crypt.c
index 6c95497..04ff56d 100644
--- a/engines/ccgost/gost_crypt.c
+++ b/engines/ccgost/gost_crypt.c
@@ -6,6 +6,9 @@
  *       OpenSSL interface to GOST 28147-89 cipher functions          *
  *          Requires OpenSSL 0.9.9 for compilation                    *
  **********************************************************************/
+
+#ifndef OPENSSL_NO_ENGINE
+
 #include <string.h>
 #include "gost89.h"
 #include <openssl/err.h>
@@ -622,3 +625,5 @@ int gost_imit_cleanup(EVP_MD_CTX *ctx)
     memset(ctx->md_data, 0, sizeof(struct ossl_gost_imit_ctx));
     return 1;
 }
+
+#endif /* !OPENSSL_NO_ENGINE */
diff --git a/engines/ccgost/gost_ctl.c b/engines/ccgost/gost_ctl.c
index 6c93c45..5af9681 100644
--- a/engines/ccgost/gost_ctl.c
+++ b/engines/ccgost/gost_ctl.c
@@ -6,6 +6,9 @@
  *        Implementation of control commands for GOST engine          *
  *            OpenSSL 0.9.9 libraries required                        *
  **********************************************************************/
+
+#ifndef OPENSSL_NO_ENGINE
+
 #include <stdlib.h>
 #include <string.h>
 #include <openssl/crypto.h>
@@ -91,3 +94,5 @@ int gost_set_default_param(int param, const char *value)
 
     return 1;
 }
+
+#endif /* !OPENSSL_NO_ENGINE */
diff --git a/engines/ccgost/gost_eng.c b/engines/ccgost/gost_eng.c
index 5924791..274c181 100644
--- a/engines/ccgost/gost_eng.c
+++ b/engines/ccgost/gost_eng.c
@@ -7,6 +7,9 @@
  *       for OpenSSL                                                  *
  *          Requires OpenSSL 0.9.9 for compilation                    *
  **********************************************************************/
+
+#ifndef OPENSSL_NO_ENGINE
+
 #include <string.h>
 #include <openssl/crypto.h>
 #include <openssl/err.h>
@@ -279,3 +282,5 @@ void ENGINE_load_gost(void)
     ERR_clear_error();
 }
 #endif
+
+#endif /* !OPENSSL_NO_ENGINE */
diff --git a/engines/ccgost/gost_md.c b/engines/ccgost/gost_md.c
index 1ccc6be..a3c3d7d 100644
--- a/engines/ccgost/gost_md.c
+++ b/engines/ccgost/gost_md.c
@@ -6,6 +6,9 @@
  *       OpenSSL interface to GOST R 34.11-94 hash functions          *
  *          Requires OpenSSL 0.9.9 for compilation                    *
  **********************************************************************/
+
+#ifndef OPENSSL_NO_ENGINE
+ 
 #include <string.h>
 #include "gost_lcl.h"
 #include "gosthash.h"
@@ -74,3 +77,5 @@ int gost_digest_cleanup(EVP_MD_CTX *ctx)
         memset(ctx->md_data, 0, sizeof(struct ossl_gost_digest_ctx));
     return 1;
 }
+
+#endif /* !OPENSSL_NO_ENGINE */
diff --git a/engines/ccgost/gost_pmeth.c b/engines/ccgost/gost_pmeth.c
index f1220e8..b02085a 100644
--- a/engines/ccgost/gost_pmeth.c
+++ b/engines/ccgost/gost_pmeth.c
@@ -7,6 +7,9 @@
  *       for OpenSSL                                                  *
  *          Requires OpenSSL 0.9.9 for compilation                    *
  **********************************************************************/
+
+#ifndef OPENSSL_NO_ENGINE
+ 
 #include <openssl/evp.h>
 #include <openssl/objects.h>
 #include <openssl/ec.h>
@@ -620,3 +623,5 @@ int register_pmeth_gost(int id, EVP_PKEY_METHOD **pmeth, int flags)
 
     return 1;
 }
+
+#endif /* !OPENSSL_NO_ENGINE */
diff --git a/engines/ccgost/gost_sign.c b/engines/ccgost/gost_sign.c
index 5bcc296..cb9e78c 100644
--- a/engines/ccgost/gost_sign.c
+++ b/engines/ccgost/gost_sign.c
@@ -7,6 +7,9 @@
  *       for OpenSSL                                                  *
  *          Requires OpenSSL 0.9.9 for compilation                    *
  **********************************************************************/
+
+#ifndef OPENSSL_NO_ENGINE
+
 #include <string.h>
 #include <openssl/rand.h>
 #include <openssl/bn.h>
@@ -319,3 +322,5 @@ int store_bignum(BIGNUM *bn, unsigned char *buf, int len)
     BN_bn2bin(bn, buf + len - bytes);
     return 1;
 }
+
+#endif /* !OPENSSL_NO_ENGINE */
diff --git a/engines/e_4758cca.c b/engines/e_4758cca.c
index 5f77198..ea1d173 100644
--- a/engines/e_4758cca.c
+++ b/engines/e_4758cca.c
@@ -53,6 +53,9 @@
  *
  */
 
+ #ifndef OPENSSL_NO_HW
+# ifndef OPENSSL_NO_HW_4758_CCA
+
 #include <stdio.h>
 #include <string.h>
 #include <openssl/crypto.h>
@@ -66,9 +69,6 @@
 #endif
 #include <openssl/bn.h>
 
-#ifndef OPENSSL_NO_HW
-# ifndef OPENSSL_NO_HW_4758_CCA
-
 #  ifdef FLAT_INC
 #   include "hw_4758_cca.h"
 #  else
diff --git a/engines/e_aep.c b/engines/e_aep.c
index 93a4be7..a260b3c 100644
--- a/engines/e_aep.c
+++ b/engines/e_aep.c
@@ -52,6 +52,9 @@
  *
  */
 
+ #ifndef OPENSSL_NO_HW
+# ifndef OPENSSL_NO_HW_AEP
+
 #include <stdio.h>
 #include <openssl/bn.h>
 #include <string.h>
@@ -86,8 +89,6 @@ extern int GetThreadID(void);
 # include <openssl/dh.h>
 #endif
 
-#ifndef OPENSSL_NO_HW
-# ifndef OPENSSL_NO_HW_AEP
 #  ifdef FLAT_INC
 #   include "aep.h"
 #  else
diff --git a/engines/e_atalla.c b/engines/e_atalla.c
index 6a324e6..fedf207 100644
--- a/engines/e_atalla.c
+++ b/engines/e_atalla.c
@@ -57,6 +57,9 @@
  *
  */
 
+#ifndef OPENSSL_NO_HW
+# ifndef OPENSSL_NO_HW_ATALLA
+
 #include <stdio.h>
 #include <string.h>
 #include <openssl/crypto.h>
@@ -74,9 +77,6 @@
 #endif
 #include <openssl/bn.h>
 
-#ifndef OPENSSL_NO_HW
-# ifndef OPENSSL_NO_HW_ATALLA
-
 #  ifdef FLAT_INC
 #   include "atalla.h"
 #  else
diff --git a/engines/e_capi.c b/engines/e_capi.c
index f280397..718aa82 100644
--- a/engines/e_capi.c
+++ b/engines/e_capi.c
@@ -52,6 +52,8 @@
  * ====================================================================
  */
 
+#ifndef OPENSSL_NO_ENGINE
+
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
@@ -59,6 +61,7 @@
 #include <openssl/crypto.h>
 
 #ifdef OPENSSL_SYS_WIN32
+
 # ifndef OPENSSL_NO_CAPIENG
 
 #  include <openssl/buffer.h>
@@ -1896,3 +1899,5 @@ void ENGINE_load_capi(void)
 }
 # endif
 #endif
+
+#endif /* !OPENSSL_NO_ENGINE */
diff --git a/engines/e_capi_err.c b/engines/e_capi_err.c
index 9aae340..a0ec34d 100644
--- a/engines/e_capi_err.c
+++ b/engines/e_capi_err.c
@@ -1,6 +1,6 @@
 /* e_capi_err.c */
 /* ====================================================================
- * Copyright (c) 1999-2014 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1999-2009 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
diff --git a/engines/e_chil.c b/engines/e_chil.c
index 69d49d7..6c568ff 100644
--- a/engines/e_chil.c
+++ b/engines/e_chil.c
@@ -58,6 +58,9 @@
  *
  */
 
+ #ifndef OPENSSL_NO_HW
+# ifndef OPENSSL_NO_HW_CHIL
+
 #include <stdio.h>
 #include <string.h>
 #include <openssl/crypto.h>
@@ -74,9 +77,6 @@
 #endif
 #include <openssl/bn.h>
 
-#ifndef OPENSSL_NO_HW
-# ifndef OPENSSL_NO_HW_CHIL
-
 /*-
  * Attribution notice: nCipher have said several times that it's OK for
  * us to implement a general interface to their boxes, and recently declared
diff --git a/engines/e_cswift.c b/engines/e_cswift.c
index db94bf2..e90d347 100644
--- a/engines/e_cswift.c
+++ b/engines/e_cswift.c
@@ -57,6 +57,9 @@
  *
  */
 
+ #ifndef OPENSSL_NO_HW
+# ifndef OPENSSL_NO_HW_CSWIFT
+
 #include <stdio.h>
 #include <string.h>
 #include <openssl/crypto.h>
@@ -75,9 +78,6 @@
 #include <openssl/rand.h>
 #include <openssl/bn.h>
 
-#ifndef OPENSSL_NO_HW
-# ifndef OPENSSL_NO_HW_CSWIFT
-
 /*
  * Attribution notice: Rainbow have generously allowed me to reproduce the
  * necessary definitions here from their API. This means the support can
diff --git a/engines/e_gmp.c b/engines/e_gmp.c
index cf01016..c2c7d3c 100644
--- a/engines/e_gmp.c
+++ b/engines/e_gmp.c
@@ -84,6 +84,8 @@
  * chipsets might be a good deal more favourable to the GMP version (eg. PPC).
  * Feedback welcome. */
 
+ #ifndef OPENSSL_NO_HW
+
 #include <stdio.h>
 #include <string.h>
 #include <openssl/crypto.h>
@@ -94,7 +96,6 @@
 #endif
 #include <openssl/bn.h>
 
-#ifndef OPENSSL_NO_HW
 # ifndef OPENSSL_NO_GMP
 
 #  include <gmp.h>
diff --git a/engines/e_nuron.c b/engines/e_nuron.c
index 3437f36..bc20c57 100644
--- a/engines/e_nuron.c
+++ b/engines/e_nuron.c
@@ -57,6 +57,9 @@
  *
  */
 
+#ifndef OPENSSL_NO_HW
+# ifndef OPENSSL_NO_HW_NURON
+
 #include <stdio.h>
 #include <string.h>
 #include <openssl/crypto.h>
@@ -74,9 +77,6 @@
 #endif
 #include <openssl/bn.h>
 
-#ifndef OPENSSL_NO_HW
-# ifndef OPENSSL_NO_HW_NURON
-
 #  define NURON_LIB_NAME "nuron engine"
 #  include "e_nuron_err.c"
 
diff --git a/engines/e_padlock.c b/engines/e_padlock.c
index 9acca7d..62c81b2 100644
--- a/engines/e_padlock.c
+++ b/engines/e_padlock.c
@@ -62,6 +62,9 @@
  *
  */
 
+ #ifndef OPENSSL_NO_HW
+# ifndef OPENSSL_NO_HW_PADLOCK
+
 #include <stdio.h>
 #include <string.h>
 
@@ -77,9 +80,6 @@
 #include <openssl/err.h>
 #include <openssl/modes.h>
 
-#ifndef OPENSSL_NO_HW
-# ifndef OPENSSL_NO_HW_PADLOCK
-
 /* Attempt to have a single source for both 0.9.7 and 0.9.8 :-) */
 #  if (OPENSSL_VERSION_NUMBER >= 0x00908000L)
 #   ifndef OPENSSL_NO_DYNAMIC_ENGINE
diff --git a/engines/e_sureware.c b/engines/e_sureware.c
index 36f6f43..90cbba4 100644
--- a/engines/e_sureware.c
+++ b/engines/e_sureware.c
@@ -51,6 +51,9 @@
 *        SUCH DAMAGE.                                                                  *
 ====================================================================*/
 
+#ifndef OPENSSL_NO_HW
+# ifndef OPENSSL_NO_HW_SUREWARE
+
 #include <stdio.h>
 #include <string.h>
 #include <openssl/crypto.h>
@@ -69,9 +72,6 @@
 #endif
 #include <openssl/bn.h>
 
-#ifndef OPENSSL_NO_HW
-# ifndef OPENSSL_NO_HW_SUREWARE
-
 #  ifdef FLAT_INC
 #   include "sureware.h"
 #  else
diff --git a/engines/e_ubsec.c b/engines/e_ubsec.c
index 6f09ffb..798f87f 100644
--- a/engines/e_ubsec.c
+++ b/engines/e_ubsec.c
@@ -57,6 +57,9 @@
  *
  */
 
+#ifndef OPENSSL_NO_HW
+# ifndef OPENSSL_NO_HW_UBSEC
+
 #include <stdio.h>
 #include <string.h>
 #include <openssl/crypto.h>
@@ -74,9 +77,6 @@
 #endif
 #include <openssl/bn.h>
 
-#ifndef OPENSSL_NO_HW
-# ifndef OPENSSL_NO_HW_UBSEC
-
 #  ifdef FLAT_INC
 #   include "hw_ubsec.h"
 #  else
