conditional NIDs for 0.9.8e
diff --git a/cryptography/hazmat/bindings/openssl/nid.py b/cryptography/hazmat/bindings/openssl/nid.py
index a772d37..ab78121 100644
--- a/cryptography/hazmat/bindings/openssl/nid.py
+++ b/cryptography/hazmat/bindings/openssl/nid.py
@@ -14,6 +14,8 @@
 INCLUDES = ""
 
 TYPES = """
+static const int Cryptography_HAS_ECDSA_SHA2_NIDS;
+
 static const int NID_undef;
 static const int NID_dsa;
 static const int NID_dsaWithSHA;
@@ -31,10 +33,6 @@
 static const int NID_sha224;
 static const int NID_sha;
 static const int NID_ecdsa_with_SHA1;
-static const int NID_ecdsa_with_SHA224;
-static const int NID_ecdsa_with_SHA256;
-static const int NID_ecdsa_with_SHA384;
-static const int NID_ecdsa_with_SHA512;
 static const int NID_crl_reason;
 static const int NID_pbe_WithSHA1And3_Key_TripleDES_CBC;
 static const int NID_subject_alt_name;
@@ -186,9 +184,32 @@
 """
 
 MACROS = """
+/* These were added in OpenSSL 0.9.8g. When we drop support for RHEL/CentOS 5
+   we should be able to move these back to TYPES. */
+static const int NID_ecdsa_with_SHA224;
+static const int NID_ecdsa_with_SHA256;
+static const int NID_ecdsa_with_SHA384;
+static const int NID_ecdsa_with_SHA512;
 """
 
 CUSTOMIZATIONS = """
+// OpenSSL 0.9.8g+
+#if OPENSSL_VERSION_NUMBER >= 0x0090807fL
+static const long Cryptography_HAS_ECDSA_SHA2_NIDS = 1;
+#else
+static const long Cryptography_HAS_ECDSA_SHA2_NIDS = 0;
+static const int NID_ecdsa_with_SHA224 = 0;
+static const int NID_ecdsa_with_SHA256 = 0;
+static const int NID_ecdsa_with_SHA384 = 0;
+static const int NID_ecdsa_with_SHA512 = 0;
+#endif
 """
 
-CONDITIONAL_NAMES = {}
+CONDITIONAL_NAMES = {
+    "Cryptography_HAS_ECDSA_SHA2_NIDS": [
+        "NID_ecdsa_with_SHA224",
+        "NID_ecdsa_with_SHA256",
+        "NID_ecdsa_with_SHA384",
+        "NID_ecdsa_with_SHA512",
+    ],
+}