Merge pull request #78 from alex/check-cffi

Be stricter in type checking the C prototypes
diff --git a/cryptography/bindings/openssl/api.py b/cryptography/bindings/openssl/api.py
index 2843757..cb5afe3 100644
--- a/cryptography/bindings/openssl/api.py
+++ b/cryptography/bindings/openssl/api.py
@@ -32,16 +32,28 @@
     def __init__(self):
         self.ffi = cffi.FFI()
         includes = []
+        functions = []
         for name in self._modules:
             __import__("cryptography.bindings.openssl." + name)
             module = sys.modules["cryptography.bindings.openssl." + name]
             self.ffi.cdef(module.TYPES)
             self.ffi.cdef(module.FUNCTIONS)
+            self.ffi.cdef(module.MACROS)
+
+            functions.append(module.FUNCTIONS)
             includes.append(module.INCLUDES)
 
+        # We include functions here so that if we got any of their definitions
+        # wrong, the underlying C compiler will explode. In C you are allowed
+        # to re-declare a function if it has the same signature. That is:
+        #   int foo(int);
+        #   int foo(int);
+        # is legal, but the following will fail to compile:
+        #   int foo(int);
+        #   int foo(short);
         self.lib = self.ffi.verify(
-            source="\n".join(includes),
-            libraries=["crypto"]
+            source="\n".join(includes + functions),
+            libraries=["crypto"],
         )
 
         self.lib.OpenSSL_add_all_algorithms()
diff --git a/cryptography/bindings/openssl/evp.py b/cryptography/bindings/openssl/evp.py
index 0bc5cff..8afaf34 100644
--- a/cryptography/bindings/openssl/evp.py
+++ b/cryptography/bindings/openssl/evp.py
@@ -27,13 +27,16 @@
 void OpenSSL_add_all_algorithms();
 const EVP_CIPHER *EVP_get_cipherbyname(const char *);
 int EVP_EncryptInit_ex(EVP_CIPHER_CTX *, const EVP_CIPHER *, ENGINE *,
-                       unsigned char *, unsigned char *);
+                       const unsigned char *, const unsigned char *);
 int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *, int);
 int EVP_EncryptUpdate(EVP_CIPHER_CTX *, unsigned char *, int *,
-                      unsigned char *, int);
+                      const unsigned char *, int);
 int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *, unsigned char *, int *);
 int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *);
 const EVP_CIPHER *EVP_CIPHER_CTX_cipher(const EVP_CIPHER_CTX *);
 int EVP_CIPHER_block_size(const EVP_CIPHER *);
 void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *);
 """
+
+MACROS = """
+"""
diff --git a/cryptography/bindings/openssl/opensslv.py b/cryptography/bindings/openssl/opensslv.py
index 9b2db27..d1a1b3e 100644
--- a/cryptography/bindings/openssl/opensslv.py
+++ b/cryptography/bindings/openssl/opensslv.py
@@ -21,3 +21,6 @@
 
 FUNCTIONS = """
 """
+
+MACROS = """
+"""