diff --git a/HsOpenSSL.cabal b/HsOpenSSL.cabal
--- a/HsOpenSSL.cabal
+++ b/HsOpenSSL.cabal
@@ -5,13 +5,13 @@
         generate RSA and DSA keys, read and write PEM files, generate
         message digests, sign and verify messages, encrypt and decrypt
         messages.
-Version: 0.5
+Version: 0.5.1
 License: PublicDomain
 License-File: COPYING
 Author: Adam Langley <agl at imperialviolet.org>, PHO <pho at cielonegro.org>
 Maintainer: PHO <pho at cielonegro.org>
 Stability: experimental
-Homepage: http://cielonegro.org/HsOpenSSL/
+Homepage: http://cielonegro.org/HsOpenSSL.html
 Category: Cryptography
 Tested-With: GHC == 6.10.1
 Cabal-Version: >= 1.2.3
diff --git a/NEWS b/NEWS
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,12 @@
+-*- Coding: utf-8 -*-
+
+Changes from 0.5 to 0.5.1
+-------------------------
+* Fixed breakage on 64-bit architectures.
+  Reported by: Neumark Péter
+
 Changes from 0.4.2 to 0.5
-___________________________
+-------------------------
 * Fixed breakage on GHC 6.10.1. And now requires 6.10.1...
 * Applied a patch by Taru Karttunen:
   -  Add pkcs5_pbkdf2_hmac_sha1 to OpenSSL.EVP.Digest
diff --git a/OpenSSL.hsc b/OpenSSL.hsc
--- a/OpenSSL.hsc
+++ b/OpenSSL.hsc
@@ -8,8 +8,8 @@
 --
 -- Features that aren't (yet) supported:
 --
---   [/TLS\/SSL network connection/] ssl(3) functionalities aren't
---   fully covered yet.
+--   [/SSL network connection/] ssl(3) functionalities aren't fully
+--   covered yet. See "OpenSSL.Session".
 --
 --   [/Complete coverage of Low-level API to symmetric ciphers/] Only
 --   high-level APIs (EVP and BIO) are fully available. But I believe
@@ -28,7 +28,7 @@
 --   [/Low-level API to message digest functions/] Just use EVP
 --   instead of something like @MD5_Update@.
 --
---   [/API to PKCS\#12 functionality/] It should be covered someday.
+--   [/API to PKCS#12 functionality/] It should be covered someday.
 --
 --   [/BIO/] BIO isn't needed because we are Haskell hackers. Though
 --   HsOpenSSL itself uses BIO internally.
diff --git a/OpenSSL/ASN1.hsc b/OpenSSL/ASN1.hsc
--- a/OpenSSL/ASN1.hsc
+++ b/OpenSSL/ASN1.hsc
@@ -37,20 +37,20 @@
 data ASN1_OBJECT
 
 foreign import ccall unsafe "OBJ_obj2nid"
-        obj2nid :: Ptr ASN1_OBJECT -> IO Int
+        obj2nid :: Ptr ASN1_OBJECT -> IO CInt
 
 foreign import ccall unsafe "OBJ_nid2sn"
-        _nid2sn :: Int -> IO CString
+        _nid2sn :: CInt -> IO CString
 
 foreign import ccall unsafe "OBJ_nid2ln"
-        _nid2ln :: Int -> IO CString
+        _nid2ln :: CInt -> IO CString
 
 
-nid2sn :: Int -> IO String
+nid2sn :: CInt -> IO String
 nid2sn nid = _nid2sn nid >>= peekCString
 
 
-nid2ln :: Int -> IO String
+nid2ln :: CInt -> IO String
 nid2ln nid = _nid2ln nid >>= peekCString
 
 
@@ -118,7 +118,7 @@
         _ASN1_TIME_set :: Ptr ASN1_TIME -> CTime -> IO (Ptr ASN1_TIME)
 
 foreign import ccall unsafe "ASN1_TIME_print"
-        _ASN1_TIME_print :: Ptr BIO_ -> Ptr ASN1_TIME -> IO Int
+        _ASN1_TIME_print :: Ptr BIO_ -> Ptr ASN1_TIME -> IO CInt
 
 
 peekASN1Time :: Ptr ASN1_TIME -> IO UTCTime -- asn1/t_x509.c
diff --git a/OpenSSL/BIO.hsc b/OpenSSL/BIO.hsc
--- a/OpenSSL/BIO.hsc
+++ b/OpenSSL/BIO.hsc
@@ -100,10 +100,10 @@
         _push :: Ptr BIO_ -> Ptr BIO_ -> IO (Ptr BIO_)
 
 foreign import ccall unsafe "HsOpenSSL_BIO_set_flags"
-        _set_flags :: Ptr BIO_ -> Int -> IO ()
+        _set_flags :: Ptr BIO_ -> CInt -> IO ()
 
 foreign import ccall unsafe "HsOpenSSL_BIO_should_retry"
-        _should_retry :: Ptr BIO_ -> IO Int
+        _should_retry :: Ptr BIO_ -> IO CInt
 
 
 new :: Ptr BIO_METHOD -> IO BIO
@@ -170,7 +170,7 @@
 bioJoin (a:b:xs) = bioPush a b >> bioJoin (b:xs)
 
 
-setFlags :: BIO -> Int -> IO ()
+setFlags :: BIO -> CInt -> IO ()
 setFlags bio flags
     = withBioPtr bio $ \ bioPtr ->
       _set_flags bioPtr flags
@@ -184,13 +184,13 @@
 {- ctrl --------------------------------------------------------------------- -}
 
 foreign import ccall unsafe "HsOpenSSL_BIO_flush"
-        _flush :: Ptr BIO_ -> IO Int
+        _flush :: Ptr BIO_ -> IO CInt
 
 foreign import ccall unsafe "HsOpenSSL_BIO_reset"
-        _reset :: Ptr BIO_ -> IO Int
+        _reset :: Ptr BIO_ -> IO CInt
 
 foreign import ccall unsafe "HsOpenSSL_BIO_eof"
-        _eof :: Ptr BIO_ -> IO Int
+        _eof :: Ptr BIO_ -> IO CInt
 
 -- |@'bioFlush' bio@ normally writes out any internally buffered data,
 -- in some cases it is used to signal EOF and that no more data will
@@ -218,13 +218,13 @@
 {- I/O ---------------------------------------------------------------------- -}
 
 foreign import ccall unsafe "BIO_read"
-        _read :: Ptr BIO_ -> Ptr CChar -> Int -> IO Int
+        _read :: Ptr BIO_ -> Ptr CChar -> CInt -> IO CInt
 
 foreign import ccall unsafe "BIO_gets"
-        _gets :: Ptr BIO_ -> Ptr CChar -> Int -> IO Int
+        _gets :: Ptr BIO_ -> Ptr CChar -> CInt -> IO CInt
 
 foreign import ccall unsafe "BIO_write"
-        _write :: Ptr BIO_ -> Ptr CChar -> Int -> IO Int
+        _write :: Ptr BIO_ -> Ptr CChar -> CInt -> IO CInt
 
 -- |@'bioRead' bio@ lazily reads all data in @bio@.
 bioRead :: BIO -> IO String
@@ -238,14 +238,14 @@
 bioReadBS bio maxLen
     = withBioPtr bio       $ \ bioPtr ->
       createAndTrim maxLen $ \ bufPtr ->
-      _read bioPtr (castPtr bufPtr) maxLen >>= interpret
+      _read bioPtr (castPtr bufPtr) (fromIntegral maxLen) >>= interpret
     where
-      interpret :: Int -> IO Int
+      interpret :: CInt -> IO Int
       interpret n
           | n ==  0   = return 0
           | n == -1   = return 0
           | n <  -1   = raiseOpenSSLError
-          | otherwise = return n
+          | otherwise = return (fromIntegral n)
 
 -- |@'bioReadLBS' bio@ lazily reads all data in @bio@, then return a
 -- LazyByteString.
@@ -284,14 +284,14 @@
 bioGetsBS bio maxLen
     = withBioPtr bio       $ \ bioPtr ->
       createAndTrim maxLen $ \ bufPtr ->
-      _gets bioPtr (castPtr bufPtr) maxLen >>= interpret
+      _gets bioPtr (castPtr bufPtr) (fromIntegral maxLen) >>= interpret
     where
-      interpret :: Int -> IO Int
+      interpret :: CInt -> IO Int
       interpret n
           | n ==  0   = return 0
           | n == -1   = return 0
           | n <  -1   = raiseOpenSSLError
-          | otherwise = return n
+          | otherwise = return (fromIntegral n)
 
 -- |'bioGetsLBS' does the same as 'bioGets' but returns
 -- LazyByteString.
@@ -310,14 +310,15 @@
 bioWriteBS bio bs
     = withBioPtr bio           $ \ bioPtr ->
       unsafeUseAsCStringLen bs $ \ (buf, len) ->
-      _write bioPtr buf len >>= interpret
+      _write bioPtr buf (fromIntegral len) >>= interpret
     where
-      interpret :: Int -> IO ()
+      interpret :: CInt -> IO ()
       interpret n
-          | n == B8.length bs = return ()
-          | n == -1           = bioWriteBS bio bs -- full retry
-          | n <  -1           = raiseOpenSSLError
-          | otherwise         = bioWriteBS bio (B8.drop n bs) -- partial retry
+          | n == fromIntegral (B8.length bs)
+                      = return ()
+          | n == -1   = bioWriteBS bio bs -- full retry
+          | n <  -1   = raiseOpenSSLError
+          | otherwise = bioWriteBS bio (B8.drop (fromIntegral n) bs) -- partial retry
 
 -- |@'bioWriteLBS' bio lbs@ lazily writes entire @lbs@ to @bio@. The
 -- string doesn't necessarily have to be finite.
@@ -332,7 +333,7 @@
         f_base64 :: IO (Ptr BIO_METHOD)
 
 foreign import ccall unsafe "HsOpenSSL_BIO_FLAGS_BASE64_NO_NL"
-        _FLAGS_BASE64_NO_NL :: Int
+        _FLAGS_BASE64_NO_NL :: CInt
 
 -- |@'newBase64' noNL@ creates a Base64 BIO filter. This is a filter
 -- bio that base64 encodes any data written through it and decodes any
@@ -359,7 +360,7 @@
         f_buffer :: IO (Ptr BIO_METHOD)
 
 foreign import ccall unsafe "HsOpenSSL_BIO_set_buffer_size"
-        _set_buffer_size :: Ptr BIO_ -> Int -> IO Int
+        _set_buffer_size :: Ptr BIO_ -> CInt -> IO CInt
 
 
 -- |@'newBuffer' mBufSize@ creates a buffering BIO filter. Data
@@ -395,7 +396,7 @@
     = do bio <- new =<< f_buffer
          case bufSize of
            Just n  -> withBioPtr bio $ \ bioPtr ->
-                      _set_buffer_size bioPtr n
+                      _set_buffer_size bioPtr (fromIntegral n)
                            >>= failIf (/= 1) >> return ()
            Nothing -> return ()
          return bio
@@ -407,7 +408,7 @@
         s_mem :: IO (Ptr BIO_METHOD)
 
 foreign import ccall unsafe "BIO_new_mem_buf"
-        _new_mem_buf :: Ptr CChar -> Int -> IO (Ptr BIO_)
+        _new_mem_buf :: Ptr CChar -> CInt -> IO (Ptr BIO_)
 
 
 -- |@'newMem'@ creates a memory BIO sink\/source. Any data written to
@@ -416,7 +417,7 @@
 --
 -- Memory BIOs support 'bioGets'.
 --
--- Calling 'bioReset' on a erad write memory BIO clears any data in
+-- Calling 'bioReset' on a read write memory BIO clears any data in
 -- it. On a read only BIO it restores the BIO to its original state
 -- and the read only data can be read again.
 --
@@ -443,7 +444,7 @@
       in
         -- ByteString への參照を BIO の finalizer に持たせる。
         withForeignPtr foreignBuf $ \ buf ->
-        do bioPtr <- _new_mem_buf (castPtr $ buf `plusPtr` off) len
+        do bioPtr <- _new_mem_buf (castPtr $ buf `plusPtr` off) (fromIntegral len)
                      >>= failIfNull
 
            bio <- newForeignPtr _free bioPtr
diff --git a/OpenSSL/BN.hsc b/OpenSSL/BN.hsc
--- a/OpenSSL/BN.hsc
+++ b/OpenSSL/BN.hsc
@@ -2,7 +2,7 @@
 
 #include "HsOpenSSL.h"
 
--- #prune
+{-# OPTIONS_HADDOCK prune #-}
 
 -- |BN - multiprecision integer arithmetics
 
@@ -92,7 +92,7 @@
         _bn2dec :: Ptr BIGNUM -> IO CString
 
 foreign import ccall unsafe "BN_dec2bn"
-        _dec2bn :: Ptr (Ptr BIGNUM) -> CString -> IO Int
+        _dec2bn :: Ptr (Ptr BIGNUM) -> CString -> IO CInt
 
 foreign import ccall unsafe "HsOpenSSL_OPENSSL_free"
         _openssl_free :: Ptr a -> IO ()
diff --git a/OpenSSL/DSA.hsc b/OpenSSL/DSA.hsc
--- a/OpenSSL/DSA.hsc
+++ b/OpenSSL/DSA.hsc
@@ -1,6 +1,6 @@
 {- -*- haskell -*- -}
 
--- #prune
+{-# OPTIONS_HADDOCK prune #-}
 
 -- | The Digital Signature Algorithm (FIPS 186-2).
 --   See <http://www.openssl.org/docs/crypto/dsa.html>
@@ -61,16 +61,16 @@
         _dsa_generate_key :: Ptr DSA_ -> IO ()
 
 foreign import ccall unsafe "HsOpenSSL_dsa_sign"
-        _dsa_sign :: Ptr DSA_ -> CString -> Int -> Ptr (Ptr BIGNUM) -> Ptr (Ptr BIGNUM) -> IO Int
+        _dsa_sign :: Ptr DSA_ -> CString -> CInt -> Ptr (Ptr BIGNUM) -> Ptr (Ptr BIGNUM) -> IO CInt
 
 foreign import ccall unsafe "HsOpenSSL_dsa_verify"
-        _dsa_verify :: Ptr DSA_ -> CString -> Int -> Ptr BIGNUM -> Ptr BIGNUM -> IO Int
+        _dsa_verify :: Ptr DSA_ -> CString -> CInt -> Ptr BIGNUM -> Ptr BIGNUM -> IO CInt
 
 withDSAPtr :: DSA -> (Ptr DSA_ -> IO a) -> IO a
 withDSAPtr (DSA ptr) = withForeignPtr ptr
 
 foreign import ccall safe "DSA_generate_parameters"
-        _generate_params :: Int -> Ptr CChar -> Int -> Ptr CInt -> Ptr CInt -> Ptr () -> Ptr () -> IO (Ptr DSA_)
+        _generate_params :: CInt -> Ptr CChar -> CInt -> Ptr CInt -> Ptr CInt -> Ptr () -> Ptr () -> IO (Ptr DSA_)
 
 peekDSA :: (Ptr DSA_ -> IO (Ptr BIGNUM)) -> DSA -> IO (Maybe Integer)
 peekDSA peeker (DSA dsa) = do
@@ -93,7 +93,7 @@
       (\x -> case mseed of
                   Nothing -> x (nullPtr, 0)
                   Just seed -> BS.useAsCStringLen seed x) (\(seedptr, seedlen) -> do
-        ptr <- _generate_params nbits seedptr seedlen i1 i2 nullPtr nullPtr
+        ptr <- _generate_params (fromIntegral nbits) seedptr (fromIntegral seedlen) i1 i2 nullPtr nullPtr
         failIfNull ptr
         itcount <- peek i1
         gencount <- peek i2
@@ -191,7 +191,7 @@
   (\x -> case mseed of
               Nothing -> x (nullPtr, 0)
               Just seed -> BS.useAsCStringLen seed x) (\(seedptr, seedlen) -> do
-    ptr <- _generate_params nbits seedptr seedlen nullPtr nullPtr nullPtr nullPtr
+    ptr <- _generate_params (fromIntegral nbits) seedptr (fromIntegral seedlen) nullPtr nullPtr nullPtr nullPtr
     failIfNull ptr
     _dsa_generate_key ptr
     newForeignPtr _free ptr >>= return . DSA)
@@ -205,7 +205,7 @@
     alloca (\rptr -> do
       alloca (\sptr -> do
         withDSAPtr dsa (\dsaptr -> do
-          _dsa_sign dsaptr ptr len rptr sptr >>= failIf (== 0)
+          _dsa_sign dsaptr ptr (fromIntegral len) rptr sptr >>= failIf (== 0)
           r <- peek rptr >>= peekBN . wrapBN
           peek rptr >>= _bn_free
           s <- peek sptr >>= peekBN . wrapBN
@@ -219,4 +219,4 @@
     withBN r (\bnR -> do
       withBN s (\bnS -> do
         withDSAPtr dsa (\dsaptr -> do
-          _dsa_verify dsaptr ptr len (unwrapBN bnR) (unwrapBN bnS) >>= return . (== 1)))))
+          _dsa_verify dsaptr ptr (fromIntegral len) (unwrapBN bnR) (unwrapBN bnS) >>= return . (== 1)))))
diff --git a/OpenSSL/EVP/Base64.hsc b/OpenSSL/EVP/Base64.hsc
--- a/OpenSSL/EVP/Base64.hsc
+++ b/OpenSSL/EVP/Base64.hsc
@@ -44,7 +44,7 @@
 {- encode -------------------------------------------------------------------- -}
 
 foreign import ccall unsafe "EVP_EncodeBlock"
-        _EncodeBlock :: Ptr CChar -> Ptr CChar -> Int -> IO Int
+        _EncodeBlock :: Ptr CChar -> Ptr CChar -> CInt -> IO CInt
 
 
 encodeBlock :: B8.ByteString -> B8.ByteString
@@ -52,7 +52,7 @@
     = unsafePerformIO $
       unsafeUseAsCStringLen inBS $ \ (inBuf, inLen) ->
       createAndTrim maxOutLen $ \ outBuf ->
-      _EncodeBlock (castPtr outBuf) inBuf inLen
+      _EncodeBlock (castPtr outBuf) inBuf (fromIntegral inLen) >>= return . fromIntegral
     where
       maxOutLen = (inputLen `div` 3 + 1) * 4 + 1 -- +1: '\0'
       inputLen  = B8.length inBS
@@ -96,7 +96,7 @@
 {- decode -------------------------------------------------------------------- -}
 
 foreign import ccall unsafe "EVP_DecodeBlock"
-        _DecodeBlock :: Ptr CChar -> Ptr CChar -> Int -> IO Int
+        _DecodeBlock :: Ptr CChar -> Ptr CChar -> CInt -> IO CInt
 
 
 decodeBlock :: B8.ByteString -> B8.ByteString
@@ -105,8 +105,8 @@
       unsafePerformIO $
       unsafeUseAsCStringLen inBS $ \ (inBuf, inLen) ->
       createAndTrim (B8.length inBS) $ \ outBuf ->
-      _DecodeBlock (castPtr outBuf) inBuf inLen
-           >>= \ outLen -> return (outLen - paddingLen)
+      _DecodeBlock (castPtr outBuf) inBuf (fromIntegral inLen)
+           >>= \ outLen -> return (fromIntegral outLen - paddingLen)
     where
       paddingLen :: Int
       paddingLen = B8.count '=' inBS
diff --git a/OpenSSL/EVP/Cipher.hsc b/OpenSSL/EVP/Cipher.hsc
--- a/OpenSSL/EVP/Cipher.hsc
+++ b/OpenSSL/EVP/Cipher.hsc
@@ -1,6 +1,6 @@
 {- -*- haskell -*- -}
 
--- #prune
+{-# OPTIONS_HADDOCK prune #-}
 
 -- |An interface to symmetric cipher algorithms.
 
@@ -58,7 +58,7 @@
 
 
 foreign import ccall unsafe "HsOpenSSL_EVP_CIPHER_iv_length"
-        _iv_length :: Ptr EVP_CIPHER -> Int
+        _iv_length :: Ptr EVP_CIPHER -> CInt
 
 
 withCipherPtr :: Cipher -> (Ptr EVP_CIPHER -> IO a) -> IO a
@@ -83,7 +83,7 @@
 
 
 cipherIvLength :: Cipher -> Int
-cipherIvLength (Cipher cipherPtr) = _iv_length cipherPtr
+cipherIvLength (Cipher cipherPtr) = fromIntegral $ _iv_length cipherPtr
 
 
 {- EVP_CIPHER_CTX ------------------------------------------------------------ -}
@@ -99,7 +99,7 @@
         _ctx_cleanup :: FunPtr (Ptr EVP_CIPHER_CTX -> IO ())
 
 foreign import ccall unsafe "HsOpenSSL_EVP_CIPHER_CTX_block_size"
-        _ctx_block_size :: Ptr EVP_CIPHER_CTX -> Int
+        _ctx_block_size :: Ptr EVP_CIPHER_CTX -> CInt
 
 
 newCtx :: IO CipherCtx
@@ -150,7 +150,7 @@
 cipherUpdateBS ctx inBS
     = withCipherCtxPtr ctx $ \ ctxPtr ->
       unsafeUseAsCStringLen inBS $ \ (inBuf, inLen) ->
-      createAndTrim (inLen + _ctx_block_size ctxPtr - 1) $ \ outBuf ->
+      createAndTrim (inLen + fromIntegral (_ctx_block_size ctxPtr) - 1) $ \ outBuf ->
       alloca $ \ outLenPtr ->
       _CipherUpdate ctxPtr (castPtr outBuf) outLenPtr inBuf (fromIntegral inLen)
            >>= failIf (/= 1)
@@ -160,7 +160,7 @@
 cipherFinalBS :: CipherCtx -> IO B8.ByteString
 cipherFinalBS ctx
     = withCipherCtxPtr ctx $ \ ctxPtr ->
-      createAndTrim (_ctx_block_size ctxPtr) $ \ outBuf ->
+      createAndTrim (fromIntegral $ _ctx_block_size ctxPtr) $ \ outBuf ->
       alloca $ \ outLenPtr ->
       _CipherFinal ctxPtr (castPtr outBuf) outLenPtr
            >>= failIf (/= 1)
diff --git a/OpenSSL/EVP/Digest.hsc b/OpenSSL/EVP/Digest.hsc
--- a/OpenSSL/EVP/Digest.hsc
+++ b/OpenSSL/EVP/Digest.hsc
@@ -1,6 +1,6 @@
 {- -*- haskell -*- -}
 
--- #prune
+{-# OPTIONS_HADDOCK prune #-}
 
 -- |An interface to message digest algorithms.
 
@@ -103,13 +103,13 @@
 {- digest -------------------------------------------------------------------- -}
 
 foreign import ccall unsafe "EVP_DigestInit"
-        _DigestInit :: Ptr EVP_MD_CTX -> Ptr EVP_MD -> IO Int
+        _DigestInit :: Ptr EVP_MD_CTX -> Ptr EVP_MD -> IO CInt
 
 foreign import ccall unsafe "EVP_DigestUpdate"
-        _DigestUpdate :: Ptr EVP_MD_CTX -> Ptr CChar -> CSize -> IO Int
+        _DigestUpdate :: Ptr EVP_MD_CTX -> Ptr CChar -> CSize -> IO CInt
 
 foreign import ccall unsafe "EVP_DigestFinal"
-        _DigestFinal :: Ptr EVP_MD_CTX -> Ptr CChar -> Ptr CUInt -> IO Int
+        _DigestFinal :: Ptr EVP_MD_CTX -> Ptr CChar -> Ptr CUInt -> IO CInt
 
 
 digestInit :: Digest -> IO DigestCtx
diff --git a/OpenSSL/EVP/Open.hsc b/OpenSSL/EVP/Open.hsc
--- a/OpenSSL/EVP/Open.hsc
+++ b/OpenSSL/EVP/Open.hsc
@@ -24,10 +24,10 @@
         _OpenInit :: Ptr EVP_CIPHER_CTX
                   -> Cipher
                   -> Ptr CChar
-                  -> Int
+                  -> CInt
                   -> CString
                   -> Ptr EVP_PKEY
-                  -> IO Int
+                  -> IO CInt
 
 
 openInit :: Cipher -> String -> String -> PKey -> IO CipherCtx
@@ -37,7 +37,7 @@
              withCStringLen encKey $ \ (encKeyPtr, encKeyLen) ->
                  withCString iv $ \ ivPtr ->
                      withPKeyPtr pkey $ \ pkeyPtr ->
-                         _OpenInit ctxPtr cipher encKeyPtr encKeyLen ivPtr pkeyPtr
+                         _OpenInit ctxPtr cipher encKeyPtr (fromIntegral encKeyLen) ivPtr pkeyPtr
                               >>= failIf (== 0)
          return ctx
 
diff --git a/OpenSSL/EVP/PKey.hsc b/OpenSSL/EVP/PKey.hsc
--- a/OpenSSL/EVP/PKey.hsc
+++ b/OpenSSL/EVP/PKey.hsc
@@ -1,6 +1,6 @@
 {- -*- haskell -*- -}
 
--- #prune
+{-# OPTIONS_HADDOCK prune #-}
 
 -- |An interface to asymmetric cipher keypair.
 
@@ -28,6 +28,7 @@
     where
 
 import           Foreign
+import           Foreign.C
 import           OpenSSL.DSA
 import           OpenSSL.EVP.Digest hiding (digest)
 import           OpenSSL.RSA
@@ -47,7 +48,7 @@
         _pkey_free :: FunPtr (Ptr EVP_PKEY -> IO ())
 
 foreign import ccall unsafe "EVP_PKEY_size"
-        _pkey_size :: Ptr EVP_PKEY -> IO Int
+        _pkey_size :: Ptr EVP_PKEY -> IO CInt
 
 
 wrapPKeyPtr :: Ptr EVP_PKEY -> IO PKey
@@ -70,13 +71,13 @@
 pkeySize :: PKey -> IO Int
 pkeySize pkey
     = withPKeyPtr pkey $ \ pkeyPtr ->
-      _pkey_size pkeyPtr
+      _pkey_size pkeyPtr >>= return . fromIntegral
 
 
 pkeyDefaultMD :: PKey -> IO Digest
 pkeyDefaultMD pkey
     = withPKeyPtr pkey $ \ pkeyPtr ->
-      do pkeyType   <- (#peek EVP_PKEY, type) pkeyPtr :: IO Int
+      do pkeyType   <- (#peek EVP_PKEY, type) pkeyPtr :: IO CInt
          digestName <- case pkeyType of
 #ifndef OPENSSL_NO_RSA
                          (#const EVP_PKEY_RSA) -> return "sha1"
@@ -93,7 +94,7 @@
 
 #ifndef OPENSSL_NO_RSA
 foreign import ccall unsafe "EVP_PKEY_set1_RSA"
-        _set1_RSA :: Ptr EVP_PKEY -> Ptr RSA_ -> IO Int
+        _set1_RSA :: Ptr EVP_PKEY -> Ptr RSA_ -> IO CInt
 
 -- |@'newPKeyRSA' rsa@ encapsulates an RSA key into 'PKey'.
 newPKeyRSA :: RSA -> PKey
@@ -108,7 +109,7 @@
 
 #ifndef OPENSSL_NO_DSA
 foreign import ccall unsafe "EVP_PKEY_set1_DSA"
-        _set1_DSA :: Ptr EVP_PKEY -> Ptr DSA_ -> IO Int
+        _set1_DSA :: Ptr EVP_PKEY -> Ptr DSA_ -> IO CInt
 
 -- |@'newPKeyDSA' dsa@ encapsulates an 'DSA' key into 'PKey'.
 newPKeyDSA :: DSA -> PKey
diff --git a/OpenSSL/EVP/Seal.hsc b/OpenSSL/EVP/Seal.hsc
--- a/OpenSSL/EVP/Seal.hsc
+++ b/OpenSSL/EVP/Seal.hsc
@@ -24,11 +24,11 @@
         _SealInit :: Ptr EVP_CIPHER_CTX
                   -> Cipher
                   -> Ptr (Ptr CChar)
-                  -> Ptr Int
+                  -> Ptr CInt
                   -> CString
                   -> Ptr (Ptr EVP_PKEY)
-                  -> Int
-                  -> IO Int
+                  -> CInt
+                  -> IO CInt
 
 
 sealInit :: Cipher -> [PKey] -> IO (CipherCtx, [String], String)
@@ -67,13 +67,13 @@
 
          -- いよいよ EVP_SealInit を呼ぶ。
          ret <- withCipherCtxPtr ctx $ \ ctxPtr ->
-                _SealInit ctxPtr cipher encKeyBufsPtr encKeyBufsLenPtr ivPtr pubKeysPtr nKeys
+                _SealInit ctxPtr cipher encKeyBufsPtr encKeyBufsLenPtr ivPtr pubKeysPtr (fromIntegral nKeys)
 
          if ret == 0 then
              cleanup >> raiseOpenSSLError
            else
              do encKeysLen <- peekArray nKeys encKeyBufsLenPtr
-                encKeys    <- mapM peekCStringLen $ zip encKeyBufs encKeysLen
+                encKeys    <- mapM peekCStringCLen $ zip encKeyBufs encKeysLen
                 iv         <- peekCString ivPtr
                 cleanup
                 return (ctx, encKeys, iv)
diff --git a/OpenSSL/EVP/Sign.hsc b/OpenSSL/EVP/Sign.hsc
--- a/OpenSSL/EVP/Sign.hsc
+++ b/OpenSSL/EVP/Sign.hsc
@@ -21,7 +21,7 @@
 
 
 foreign import ccall unsafe "EVP_SignFinal"
-        _SignFinal :: Ptr EVP_MD_CTX -> Ptr CChar -> Ptr CUInt -> Ptr EVP_PKEY -> IO Int
+        _SignFinal :: Ptr EVP_MD_CTX -> Ptr CChar -> Ptr CUInt -> Ptr EVP_PKEY -> IO CInt
 
 
 signFinal :: DigestCtx -> PKey -> IO String
diff --git a/OpenSSL/EVP/Verify.hsc b/OpenSSL/EVP/Verify.hsc
--- a/OpenSSL/EVP/Verify.hsc
+++ b/OpenSSL/EVP/Verify.hsc
@@ -28,7 +28,7 @@
 
 
 foreign import ccall unsafe "EVP_VerifyFinal"
-        _VerifyFinal :: Ptr EVP_MD_CTX -> Ptr CChar -> CUInt -> Ptr EVP_PKEY -> IO Int
+        _VerifyFinal :: Ptr EVP_MD_CTX -> Ptr CChar -> CUInt -> Ptr EVP_PKEY -> IO CInt
 
 
 verifyFinalBS :: DigestCtx -> String -> PKey -> IO VerifyStatus
@@ -38,7 +38,7 @@
       withPKeyPtr pkey $ \ pkeyPtr ->
       _VerifyFinal ctxPtr buf (fromIntegral len) pkeyPtr >>= interpret
     where
-      interpret :: Int -> IO VerifyStatus
+      interpret :: CInt -> IO VerifyStatus
       interpret 1 = return VerifySuccess
       interpret 0 = return VerifyFailure
       interpret _ = raiseOpenSSLError
diff --git a/OpenSSL/Objects.hsc b/OpenSSL/Objects.hsc
--- a/OpenSSL/Objects.hsc
+++ b/OpenSSL/Objects.hsc
@@ -18,10 +18,10 @@
 
 
 foreign import ccall safe "OBJ_NAME_do_all"
-        _NAME_do_all :: Int -> FunPtr DoAllCallback -> Ptr () -> IO ()
+        _NAME_do_all :: CInt -> FunPtr DoAllCallback -> Ptr () -> IO ()
 
 foreign import ccall safe "OBJ_NAME_do_all_sorted"
-        _NAME_do_all_sorted :: Int -> FunPtr DoAllCallback -> Ptr () -> IO ()
+        _NAME_do_all_sorted :: CInt -> FunPtr DoAllCallback -> Ptr () -> IO ()
 
 foreign import ccall "wrapper"
         mkDoAllCallback :: DoAllCallback -> IO (FunPtr DoAllCallback)
@@ -32,7 +32,7 @@
                  | PKeyMethodType
                  | CompMethodType
 
-objNameTypeToInt :: ObjNameType -> Int
+objNameTypeToInt :: ObjNameType -> CInt
 objNameTypeToInt MDMethodType     = #const OBJ_NAME_TYPE_MD_METH
 objNameTypeToInt CipherMethodType = #const OBJ_NAME_TYPE_CIPHER_METH
 objNameTypeToInt PKeyMethodType   = #const OBJ_NAME_TYPE_PKEY_METH
diff --git a/OpenSSL/PEM.hsc b/OpenSSL/PEM.hsc
--- a/OpenSSL/PEM.hsc
+++ b/OpenSSL/PEM.hsc
@@ -126,10 +126,10 @@
                                    -> Ptr EVP_PKEY
                                    -> Ptr EVP_CIPHER
                                    -> Ptr CChar
-                                   -> Int
+                                   -> CInt
                                    -> FunPtr PemPasswordCallback'
                                    -> Ptr a
-                                   -> IO Int
+                                   -> IO CInt
 
 writePKCS8PrivateKey' :: BIO
                       -> PKey
@@ -148,7 +148,7 @@
                   Just (cipher, PwStr passStr)
                       -> withCStringLen passStr $ \ (passPtr, passLen) ->
                          withCipherPtr cipher   $ \ cipherPtr          ->
-                         _write_bio_PKCS8PrivateKey bioPtr pkeyPtr cipherPtr passPtr passLen nullFunPtr nullPtr
+                         _write_bio_PKCS8PrivateKey bioPtr pkeyPtr cipherPtr passPtr (fromIntegral passLen) nullFunPtr nullPtr
 
                   Just (cipher, PwCallback cb)
                       -> withCipherPtr cipher $ \ cipherPtr ->
@@ -222,7 +222,7 @@
 {- Public Key ---------------------------------------------------------------- -}
 
 foreign import ccall unsafe "PEM_write_bio_PUBKEY"
-        _write_bio_PUBKEY :: Ptr BIO_ -> Ptr EVP_PKEY -> IO Int
+        _write_bio_PUBKEY :: Ptr BIO_ -> Ptr EVP_PKEY -> IO CInt
 
 foreign import ccall unsafe "PEM_read_bio_PUBKEY"
         _read_bio_PUBKEY :: Ptr BIO_
@@ -266,7 +266,7 @@
 foreign import ccall unsafe "PEM_write_bio_X509_AUX"
         _write_bio_X509_AUX :: Ptr BIO_
                             -> Ptr X509_
-                            -> IO Int
+                            -> IO CInt
 
 foreign import ccall safe "PEM_read_bio_X509_AUX"
         _read_bio_X509_AUX :: Ptr BIO_
@@ -311,12 +311,12 @@
 foreign import ccall unsafe "PEM_write_bio_X509_REQ"
         _write_bio_X509_REQ :: Ptr BIO_
                             -> Ptr X509_REQ
-                            -> IO Int
+                            -> IO CInt
 
 foreign import ccall unsafe "PEM_write_bio_X509_REQ_NEW"
         _write_bio_X509_REQ_NEW :: Ptr BIO_
                                 -> Ptr X509_REQ
-                                -> IO Int
+                                -> IO CInt
 
 foreign import ccall safe "PEM_read_bio_X509_REQ"
         _read_bio_X509_REQ :: Ptr BIO_
@@ -376,7 +376,7 @@
 foreign import ccall unsafe "PEM_write_bio_X509_CRL"
         _write_bio_X509_CRL :: Ptr BIO_
                             -> Ptr X509_CRL
-                            -> IO Int
+                            -> IO CInt
 
 foreign import ccall safe "PEM_read_bio_X509_CRL"
         _read_bio_X509_CRL :: Ptr BIO_
@@ -422,7 +422,7 @@
 foreign import ccall unsafe "PEM_write_bio_PKCS7"
         _write_bio_PKCS7 :: Ptr BIO_
                          -> Ptr PKCS7
-                         -> IO Int
+                         -> IO CInt
 
 foreign import ccall safe "PEM_read_bio_PKCS7"
         _read_bio_PKCS7 :: Ptr BIO_
diff --git a/OpenSSL/PKCS7.hsc b/OpenSSL/PKCS7.hsc
--- a/OpenSSL/PKCS7.hsc
+++ b/OpenSSL/PKCS7.hsc
@@ -66,7 +66,7 @@
                | Pkcs7CRLFEOL
                  deriving (Show, Eq, Typeable)
 
-flagToInt :: Pkcs7Flag -> Int
+flagToInt :: Pkcs7Flag -> CInt
 flagToInt Pkcs7Text          = #const PKCS7_TEXT
 flagToInt Pkcs7NoCerts       = #const PKCS7_NOCERTS
 flagToInt Pkcs7NoSigs        = #const PKCS7_NOSIGS
@@ -91,7 +91,7 @@
       deriving (Show, Eq, Typeable)
 
 
-flagListToInt :: [Pkcs7Flag] -> Int
+flagListToInt :: [Pkcs7Flag] -> CInt
 flagListToInt = foldl' (.|.) 0 . map flagToInt
 
 
@@ -102,16 +102,16 @@
         _is_detached :: Ptr PKCS7 -> IO CLong
 
 foreign import ccall "PKCS7_sign"
-        _sign :: Ptr X509_ -> Ptr EVP_PKEY -> Ptr STACK -> Ptr BIO_ -> Int -> IO (Ptr PKCS7)
+        _sign :: Ptr X509_ -> Ptr EVP_PKEY -> Ptr STACK -> Ptr BIO_ -> CInt -> IO (Ptr PKCS7)
 
 foreign import ccall "PKCS7_verify"
-        _verify :: Ptr PKCS7 -> Ptr STACK -> Ptr X509_STORE -> Ptr BIO_ -> Ptr BIO_ -> Int -> IO Int
+        _verify :: Ptr PKCS7 -> Ptr STACK -> Ptr X509_STORE -> Ptr BIO_ -> Ptr BIO_ -> CInt -> IO CInt
 
 foreign import ccall "PKCS7_encrypt"
-        _encrypt :: Ptr STACK -> Ptr BIO_ -> Ptr EVP_CIPHER -> Int -> IO (Ptr PKCS7)
+        _encrypt :: Ptr STACK -> Ptr BIO_ -> Ptr EVP_CIPHER -> CInt -> IO (Ptr PKCS7)
 
 foreign import ccall "PKCS7_decrypt"
-        _decrypt :: Ptr PKCS7 -> Ptr EVP_PKEY -> Ptr X509_ -> Ptr BIO_ -> Int -> IO Int
+        _decrypt :: Ptr PKCS7 -> Ptr EVP_PKEY -> Ptr X509_ -> Ptr BIO_ -> CInt -> IO CInt
 
 
 wrapPkcs7Ptr :: Ptr PKCS7 -> IO Pkcs7
@@ -217,7 +217,7 @@
              _verify pkcs7Ptr certStack storePtr inDataPtr outDataPtr (flagListToInt flagList)
                   >>= interpret outData
     where
-      interpret :: Maybe BIO -> Int -> IO (Maybe BIO, Bool)
+      interpret :: Maybe BIO -> CInt -> IO (Maybe BIO, Bool)
       interpret bio 1 = return (bio    , True )
       interpret _   _ = return (Nothing, False)
 
@@ -346,7 +346,7 @@
 {- S/MIME -------------------------------------------------------------------- -}
 
 foreign import ccall unsafe "SMIME_write_PKCS7"
-        _SMIME_write_PKCS7 :: Ptr BIO_ -> Ptr PKCS7 -> Ptr BIO_ -> Int -> IO Int
+        _SMIME_write_PKCS7 :: Ptr BIO_ -> Ptr PKCS7 -> Ptr BIO_ -> CInt -> IO CInt
 
 foreign import ccall unsafe "SMIME_read_PKCS7"
         _SMIME_read_PKCS7 :: Ptr BIO_ -> Ptr (Ptr BIO_) -> IO (Ptr PKCS7)
diff --git a/OpenSSL/RSA.hsc b/OpenSSL/RSA.hsc
--- a/OpenSSL/RSA.hsc
+++ b/OpenSSL/RSA.hsc
@@ -1,6 +1,6 @@
 {- -*- haskell -*- -}
 
--- #prune
+{-# OPTIONS_HADDOCK prune #-}
 
 -- |An interface to RSA public key generator.
 
@@ -30,6 +30,7 @@
 
 import           Control.Monad
 import           Foreign
+import           Foreign.C
 import           OpenSSL.BN
 import           OpenSSL.Utils
 
@@ -74,7 +75,7 @@
         mkGenKeyCallback :: RSAGenKeyCallback' -> IO (FunPtr RSAGenKeyCallback')
 
 foreign import ccall safe "RSA_generate_key"
-        _generate_key :: Int -> Int -> FunPtr RSAGenKeyCallback' -> Ptr a -> IO (Ptr RSA_)
+        _generate_key :: CInt -> CInt -> FunPtr RSAGenKeyCallback' -> Ptr a -> IO (Ptr RSA_)
 
 -- |@'generateKey'@ generates an RSA keypair.
 generateKey :: Int    -- ^ The number of bits of the public modulus
@@ -86,14 +87,14 @@
             -> IO RSA -- ^ The generated keypair.
 
 generateKey nbits e Nothing
-    = do ptr <- _generate_key nbits e nullFunPtr nullPtr
+    = do ptr <- _generate_key (fromIntegral nbits) (fromIntegral e) nullFunPtr nullPtr
          failIfNull ptr
          newForeignPtr _free ptr >>= return . RSA
 
 generateKey nbits e (Just cb)
     = do cbPtr <- mkGenKeyCallback
                   $ \ arg1 arg2 _ -> cb arg1 arg2
-         ptr   <- _generate_key nbits e cbPtr nullPtr
+         ptr   <- _generate_key (fromIntegral nbits) (fromIntegral e) cbPtr nullPtr
          freeHaskellFunPtr cbPtr
          failIfNull ptr
          newForeignPtr _free ptr >>= return . RSA
diff --git a/OpenSSL/Session.hsc b/OpenSSL/Session.hsc
--- a/OpenSSL/Session.hsc
+++ b/OpenSSL/Session.hsc
@@ -80,7 +80,7 @@
   waitQSem sem
   finally (withForeignPtr ctxfp action) $ signalQSem sem
 
-contextLoadFile :: (Ptr SSLContext_ -> CString -> CInt -> IO Int)
+contextLoadFile :: (Ptr SSLContext_ -> CString -> CInt -> IO CInt)
                 -> SSLContext -> String -> IO ()
 contextLoadFile f context path =
   withContext context $ \ctx ->
@@ -91,9 +91,9 @@
          else f ctx cpath (#const SSL_FILETYPE_ASN1) >>= failIf (/= 1) >> return ()
 
 foreign import ccall unsafe "SSL_CTX_use_PrivateKey_file"
-   _ssl_ctx_use_privatekey_file :: Ptr SSLContext_ -> CString -> CInt -> IO Int
+   _ssl_ctx_use_privatekey_file :: Ptr SSLContext_ -> CString -> CInt -> IO CInt
 foreign import ccall unsafe "SSL_CTX_use_certificate_file"
-   _ssl_ctx_use_certificate_file :: Ptr SSLContext_ -> CString -> CInt -> IO Int
+   _ssl_ctx_use_certificate_file :: Ptr SSLContext_ -> CString -> CInt -> IO CInt
 
 -- | Install a private key file in a context. The key is given as a path to the
 --   file which contains the key. The file is parsed first as PEM and, if that
@@ -108,7 +108,7 @@
 contextSetCertificateFile = contextLoadFile _ssl_ctx_use_certificate_file
 
 foreign import ccall unsafe "SSL_CTX_set_cipher_list"
-   _ssl_ctx_set_cipher_list :: Ptr SSLContext_ -> CString -> IO Int
+   _ssl_ctx_set_cipher_list :: Ptr SSLContext_ -> CString -> IO CInt
 
 -- | Set the ciphers to be used by the given context. The string argument is a
 --   list of ciphers, comma separated, as given at
@@ -126,7 +126,7 @@
 contextSetDefaultCiphers = flip contextSetCiphers "DEFAULT"
 
 foreign import ccall unsafe "SSL_CTX_check_private_key"
-   _ssl_ctx_check_private_key :: Ptr SSLContext_ -> IO Int
+   _ssl_ctx_check_private_key :: Ptr SSLContext_ -> IO CInt
 
 -- | Return true iff the private key installed in the given context matches the
 --   certificate also installed.
diff --git a/OpenSSL/Stack.hsc b/OpenSSL/Stack.hsc
--- a/OpenSSL/Stack.hsc
+++ b/OpenSSL/Stack.hsc
@@ -8,6 +8,7 @@
 
 import           Control.Exception
 import           Foreign
+import           Foreign.C
 
 
 data STACK
@@ -23,17 +24,17 @@
         skPush :: Ptr STACK -> Ptr () -> IO ()
 
 foreign import ccall unsafe "sk_num"
-        skNum :: Ptr STACK -> IO Int
+        skNum :: Ptr STACK -> IO CInt
 
 foreign import ccall unsafe "sk_value"
-        skValue :: Ptr STACK -> Int -> IO (Ptr ())
+        skValue :: Ptr STACK -> CInt -> IO (Ptr ())
 
 
 mapStack :: (Ptr a -> IO b) -> Ptr STACK -> IO [b]
 mapStack m st
     = do num <- skNum st
          mapM (\ i -> skValue st i >>= return . castPtr >>= m)
-                  $ take num [0..]
+                  $ take (fromIntegral num) [0..]
 
 
 newStack :: [Ptr a] -> IO (Ptr STACK)
diff --git a/OpenSSL/Utils.hs b/OpenSSL/Utils.hs
--- a/OpenSSL/Utils.hs
+++ b/OpenSSL/Utils.hs
@@ -4,10 +4,12 @@
     , raiseOpenSSLError
     , toHex
     , fromHex
+    , peekCStringCLen
     )
     where
 
 import           Foreign
+import           Foreign.C
 import           OpenSSL.ERR
 import           Data.Bits ((.&.), (.|.), shiftR, shiftL)
 import           Data.List (unfoldr)
@@ -81,3 +83,8 @@
   byteHex 'E' = 14
   byteHex 'F' = 15
   byteHex _   = undefined
+
+
+peekCStringCLen :: (Ptr CChar, CInt) -> IO String
+peekCStringCLen (p, n)
+    = peekCStringLen (p, fromIntegral n)
diff --git a/OpenSSL/X509.hsc b/OpenSSL/X509.hsc
--- a/OpenSSL/X509.hsc
+++ b/OpenSSL/X509.hsc
@@ -1,6 +1,6 @@
 {- -*- haskell -*- -}
 
--- #prune
+{-# OPTIONS_HADDOCK prune #-}
 
 -- |An interface to X.509 certificate.
 
@@ -75,52 +75,52 @@
         _free :: FunPtr (Ptr X509_ -> IO ())
 
 foreign import ccall unsafe "X509_print"
-        _print :: Ptr BIO_ -> Ptr X509_ -> IO Int
+        _print :: Ptr BIO_ -> Ptr X509_ -> IO CInt
 
 foreign import ccall unsafe "X509_cmp"
-        _cmp :: Ptr X509_ -> Ptr X509_ -> IO Int
+        _cmp :: Ptr X509_ -> Ptr X509_ -> IO CInt
 
 foreign import ccall unsafe "HsOpenSSL_X509_get_version"
         _get_version :: Ptr X509_ -> IO CLong
 
 foreign import ccall unsafe "X509_set_version"
-        _set_version :: Ptr X509_ -> CLong -> IO Int
+        _set_version :: Ptr X509_ -> CLong -> IO CInt
 
 foreign import ccall unsafe "X509_get_serialNumber"
         _get_serialNumber :: Ptr X509_ -> IO (Ptr ASN1_INTEGER)
 
 foreign import ccall unsafe "X509_set_serialNumber"
-        _set_serialNumber :: Ptr X509_ -> Ptr ASN1_INTEGER -> IO Int
+        _set_serialNumber :: Ptr X509_ -> Ptr ASN1_INTEGER -> IO CInt
 
 foreign import ccall unsafe "X509_get_issuer_name"
         _get_issuer_name :: Ptr X509_ -> IO (Ptr X509_NAME)
 
 foreign import ccall unsafe "X509_set_issuer_name"
-        _set_issuer_name :: Ptr X509_ -> Ptr X509_NAME -> IO Int
+        _set_issuer_name :: Ptr X509_ -> Ptr X509_NAME -> IO CInt
 
 foreign import ccall unsafe "X509_get_subject_name"
         _get_subject_name :: Ptr X509_ -> IO (Ptr X509_NAME)
 
 foreign import ccall unsafe "X509_set_subject_name"
-        _set_subject_name :: Ptr X509_ -> Ptr X509_NAME -> IO Int
+        _set_subject_name :: Ptr X509_ -> Ptr X509_NAME -> IO CInt
 
 foreign import ccall unsafe "HsOpenSSL_X509_get_notBefore"
         _get_notBefore :: Ptr X509_ -> IO (Ptr ASN1_TIME)
 
 foreign import ccall unsafe "X509_set_notBefore"
-        _set_notBefore :: Ptr X509_ -> Ptr ASN1_TIME -> IO Int
+        _set_notBefore :: Ptr X509_ -> Ptr ASN1_TIME -> IO CInt
 
 foreign import ccall unsafe "HsOpenSSL_X509_get_notAfter"
         _get_notAfter :: Ptr X509_ -> IO (Ptr ASN1_TIME)
 
 foreign import ccall unsafe "X509_set_notAfter"
-        _set_notAfter :: Ptr X509_ -> Ptr ASN1_TIME -> IO Int
+        _set_notAfter :: Ptr X509_ -> Ptr ASN1_TIME -> IO CInt
 
 foreign import ccall unsafe "X509_get_pubkey"
         _get_pubkey :: Ptr X509_ -> IO (Ptr EVP_PKEY)
 
 foreign import ccall unsafe "X509_set_pubkey"
-        _set_pubkey :: Ptr X509_ -> Ptr EVP_PKEY -> IO Int
+        _set_pubkey :: Ptr X509_ -> Ptr EVP_PKEY -> IO CInt
 
 foreign import ccall unsafe "X509_get1_email"
         _get1_email :: Ptr X509_ -> IO (Ptr STACK)
@@ -129,10 +129,10 @@
         _email_free :: Ptr STACK -> IO ()
 
 foreign import ccall unsafe "X509_sign"
-        _sign :: Ptr X509_ -> Ptr EVP_PKEY -> Ptr EVP_MD -> IO Int
+        _sign :: Ptr X509_ -> Ptr EVP_PKEY -> Ptr EVP_MD -> IO CInt
 
 foreign import ccall unsafe "X509_verify"
-        _verify :: Ptr X509_ -> Ptr EVP_PKEY -> IO Int
+        _verify :: Ptr X509_ -> Ptr EVP_PKEY -> IO CInt
 
 -- |@'newX509'@ creates an empty certificate. You must set the
 -- following properties to and sign it (see 'signX509') to actually
@@ -180,7 +180,7 @@
       withX509Ptr cert2 $ \ cert2Ptr ->
       _cmp cert1Ptr cert2Ptr >>= return . interpret
     where
-      interpret :: Int -> Ordering
+      interpret :: CInt -> Ordering
       interpret n
           | n > 0     = GT
           | n < 0     = LT
@@ -215,7 +215,7 @@
       _verify x509Ptr pkeyPtr
            >>= interpret
     where
-      interpret :: Int -> IO VerifyStatus
+      interpret :: CInt -> IO VerifyStatus
       interpret 1 = return VerifySuccess
       interpret 0 = return VerifyFailure
       interpret _ = raiseOpenSSLError
diff --git a/OpenSSL/X509/Name.hsc b/OpenSSL/X509/Name.hsc
--- a/OpenSSL/X509/Name.hsc
+++ b/OpenSSL/X509/Name.hsc
@@ -26,13 +26,13 @@
         _free :: Ptr X509_NAME -> IO ()
 
 foreign import ccall unsafe "X509_NAME_add_entry_by_txt"
-        _add_entry_by_txt :: Ptr X509_NAME -> CString -> Int -> Ptr CChar -> Int -> Int -> Int -> IO Int
+        _add_entry_by_txt :: Ptr X509_NAME -> CString -> CInt -> Ptr CChar -> CInt -> CInt -> CInt -> IO CInt
 
 foreign import ccall unsafe "X509_NAME_entry_count"
-        _entry_count :: Ptr X509_NAME -> IO Int
+        _entry_count :: Ptr X509_NAME -> IO CInt
 
 foreign import ccall unsafe "X509_NAME_get_entry"
-        _get_entry :: Ptr X509_NAME -> Int -> IO (Ptr X509_NAME_ENTRY)
+        _get_entry :: Ptr X509_NAME -> CInt -> IO (Ptr X509_NAME_ENTRY)
 
 foreign import ccall unsafe "X509_NAME_ENTRY_get_object"
         _ENTRY_get_object :: Ptr X509_NAME_ENTRY -> IO (Ptr ASN1_OBJECT)
@@ -56,19 +56,19 @@
       addEntry namePtr (key, val)
           = withCString    key $ \ keyPtr ->
             withCStringLen val $ \ (valPtr, valLen) ->
-            _add_entry_by_txt namePtr keyPtr (#const MBSTRING_UTF8) valPtr valLen (-1) 0
+            _add_entry_by_txt namePtr keyPtr (#const MBSTRING_UTF8) valPtr (fromIntegral valLen) (-1) 0
                  >>= failIf (/= 1)
                  >>  return ()
 
 
 peekX509Name :: Ptr X509_NAME -> Bool -> IO [(String, String)]
 peekX509Name namePtr wantLongName
-    = do count <- _entry_count namePtr >>= failIf (< 0)
+    = do count <- return . fromIntegral =<< failIf (< 0) =<< _entry_count namePtr
          mapM peekEntry [0..count - 1]
     where
       peekEntry :: Int -> IO (String, String)
       peekEntry n
-          = do ent <- _get_entry namePtr n  >>= failIfNull
+          = do ent <- _get_entry namePtr (fromIntegral n) >>= failIfNull
                obj <- _ENTRY_get_object ent >>= failIfNull
                dat <- _ENTRY_get_data   ent >>= failIfNull
 
diff --git a/OpenSSL/X509/Request.hsc b/OpenSSL/X509/Request.hsc
--- a/OpenSSL/X509/Request.hsc
+++ b/OpenSSL/X509/Request.hsc
@@ -1,6 +1,6 @@
 {- -*- haskell -*- -}
 
--- #prune
+{-# OPTIONS_HADDOCK prune #-}
 
 -- |An interface to PKCS#10 certificate request.
 
@@ -58,31 +58,31 @@
         _free :: FunPtr (Ptr X509_REQ -> IO ())
 
 foreign import ccall unsafe "X509_REQ_sign"
-        _sign :: Ptr X509_REQ -> Ptr EVP_PKEY -> Ptr EVP_MD -> IO Int
+        _sign :: Ptr X509_REQ -> Ptr EVP_PKEY -> Ptr EVP_MD -> IO CInt
 
 foreign import ccall unsafe "X509_REQ_verify"
-        _verify :: Ptr X509_REQ -> Ptr EVP_PKEY -> IO Int
+        _verify :: Ptr X509_REQ -> Ptr EVP_PKEY -> IO CInt
 
 foreign import ccall unsafe "X509_REQ_print"
-        _print :: Ptr BIO_ -> Ptr X509_REQ -> IO Int
+        _print :: Ptr BIO_ -> Ptr X509_REQ -> IO CInt
 
 foreign import ccall unsafe "HsOpenSSL_X509_REQ_get_version"
         _get_version :: Ptr X509_REQ -> IO CLong
 
 foreign import ccall unsafe "X509_REQ_set_version"
-        _set_version :: Ptr X509_REQ -> CLong -> IO Int
+        _set_version :: Ptr X509_REQ -> CLong -> IO CInt
 
 foreign import ccall unsafe "HsOpenSSL_X509_REQ_get_subject_name"
         _get_subject_name :: Ptr X509_REQ -> IO (Ptr X509_NAME)
 
 foreign import ccall unsafe "X509_REQ_set_subject_name"
-        _set_subject_name :: Ptr X509_REQ -> Ptr X509_NAME -> IO Int
+        _set_subject_name :: Ptr X509_REQ -> Ptr X509_NAME -> IO CInt
 
 foreign import ccall unsafe "X509_REQ_get_pubkey"
         _get_pubkey :: Ptr X509_REQ -> IO (Ptr EVP_PKEY)
 
 foreign import ccall unsafe "X509_REQ_set_pubkey"
-        _set_pubkey :: Ptr X509_REQ -> Ptr EVP_PKEY -> IO Int
+        _set_pubkey :: Ptr X509_REQ -> Ptr EVP_PKEY -> IO CInt
 
 -- |@'newX509Req'@ creates an empty certificate request. You must set
 -- the following properties to and sign it (see 'signX509Req') to
@@ -135,7 +135,7 @@
       _verify reqPtr pkeyPtr
            >>= interpret
     where
-      interpret :: Int -> IO VerifyStatus
+      interpret :: CInt -> IO VerifyStatus
       interpret 1 = return VerifySuccess
       interpret 0 = return VerifyFailure
       interpret _ = raiseOpenSSLError
diff --git a/OpenSSL/X509/Revocation.hsc b/OpenSSL/X509/Revocation.hsc
--- a/OpenSSL/X509/Revocation.hsc
+++ b/OpenSSL/X509/Revocation.hsc
@@ -1,6 +1,6 @@
 {- -*- haskell -*- -}
 
--- #prune
+{-# OPTIONS_HADDOCK prune #-}
 
 -- |An interface to Certificate Revocation List.
 
@@ -81,46 +81,46 @@
         _free :: FunPtr (Ptr X509_CRL -> IO ())
 
 foreign import ccall unsafe "X509_CRL_sign"
-        _sign :: Ptr X509_CRL -> Ptr EVP_PKEY -> Ptr EVP_MD -> IO Int
+        _sign :: Ptr X509_CRL -> Ptr EVP_PKEY -> Ptr EVP_MD -> IO CInt
 
 foreign import ccall unsafe "X509_CRL_verify"
-        _verify :: Ptr X509_CRL -> Ptr EVP_PKEY -> IO Int
+        _verify :: Ptr X509_CRL -> Ptr EVP_PKEY -> IO CInt
 
 foreign import ccall unsafe "X509_CRL_print"
-        _print :: Ptr BIO_ -> Ptr X509_CRL -> IO Int
+        _print :: Ptr BIO_ -> Ptr X509_CRL -> IO CInt
 
 foreign import ccall unsafe "HsOpenSSL_X509_CRL_get_version"
         _get_version :: Ptr X509_CRL -> IO CLong
 
 foreign import ccall unsafe "X509_CRL_set_version"
-        _set_version :: Ptr X509_CRL -> CLong -> IO Int
+        _set_version :: Ptr X509_CRL -> CLong -> IO CInt
 
 foreign import ccall unsafe "HsOpenSSL_X509_CRL_get_lastUpdate"
         _get_lastUpdate :: Ptr X509_CRL -> IO (Ptr ASN1_TIME)
 
 foreign import ccall unsafe "X509_CRL_set_lastUpdate"
-        _set_lastUpdate :: Ptr X509_CRL -> Ptr ASN1_TIME -> IO Int
+        _set_lastUpdate :: Ptr X509_CRL -> Ptr ASN1_TIME -> IO CInt
 
 foreign import ccall unsafe "HsOpenSSL_X509_CRL_get_nextUpdate"
         _get_nextUpdate :: Ptr X509_CRL -> IO (Ptr ASN1_TIME)
 
 foreign import ccall unsafe "X509_CRL_set_nextUpdate"
-        _set_nextUpdate :: Ptr X509_CRL -> Ptr ASN1_TIME -> IO Int
+        _set_nextUpdate :: Ptr X509_CRL -> Ptr ASN1_TIME -> IO CInt
 
 foreign import ccall unsafe "HsOpenSSL_X509_CRL_get_issuer"
         _get_issuer_name :: Ptr X509_CRL -> IO (Ptr X509_NAME)
 
 foreign import ccall unsafe "X509_CRL_set_issuer_name"
-        _set_issuer_name :: Ptr X509_CRL -> Ptr X509_NAME -> IO Int
+        _set_issuer_name :: Ptr X509_CRL -> Ptr X509_NAME -> IO CInt
 
 foreign import ccall unsafe "HsOpenSSL_X509_CRL_get_REVOKED"
         _get_REVOKED :: Ptr X509_CRL -> IO (Ptr STACK)
 
 foreign import ccall unsafe "X509_CRL_add0_revoked"
-        _add0_revoked :: Ptr X509_CRL -> Ptr X509_REVOKED -> IO Int
+        _add0_revoked :: Ptr X509_CRL -> Ptr X509_REVOKED -> IO CInt
 
 foreign import ccall unsafe "X509_CRL_sort"
-        _sort :: Ptr X509_CRL -> IO Int
+        _sort :: Ptr X509_CRL -> IO CInt
 
 
 
@@ -131,10 +131,10 @@
         freeRevoked :: Ptr X509_REVOKED -> IO ()
 
 foreign import ccall unsafe "X509_REVOKED_set_serialNumber"
-        _set_serialNumber :: Ptr X509_REVOKED -> Ptr ASN1_INTEGER -> IO Int
+        _set_serialNumber :: Ptr X509_REVOKED -> Ptr ASN1_INTEGER -> IO CInt
 
 foreign import ccall unsafe "X509_REVOKED_set_revocationDate"
-        _set_revocationDate :: Ptr X509_REVOKED -> Ptr ASN1_TIME -> IO Int
+        _set_revocationDate :: Ptr X509_REVOKED -> Ptr ASN1_TIME -> IO CInt
 
 -- |@'newCRL'@ creates an empty revocation list. You must set the
 -- following properties to and sign it (see 'signCRL') to actually use
@@ -187,7 +187,7 @@
       _verify crlPtr pkeyPtr
            >>= interpret
     where
-      interpret :: Int -> IO VerifyStatus
+      interpret :: CInt -> IO VerifyStatus
       interpret 1 = return VerifySuccess
       interpret 0 = return VerifyFailure
       interpret _ = raiseOpenSSLError
diff --git a/OpenSSL/X509/Store.hsc b/OpenSSL/X509/Store.hsc
--- a/OpenSSL/X509/Store.hsc
+++ b/OpenSSL/X509/Store.hsc
@@ -1,6 +1,6 @@
 {- -*- haskell -*- -}
 
--- #prune
+{-# OPTIONS_HADDOCK prune #-}
 
 -- |An interface to X.509 certificate store.
 
@@ -17,6 +17,7 @@
     where
 
 import           Foreign
+import           Foreign.C
 import           OpenSSL.X509
 import           OpenSSL.X509.Revocation
 import           OpenSSL.Utils
@@ -35,10 +36,10 @@
         _free :: FunPtr (Ptr X509_STORE -> IO ())
 
 foreign import ccall unsafe "X509_STORE_add_cert"
-        _add_cert :: Ptr X509_STORE -> Ptr X509_ -> IO Int
+        _add_cert :: Ptr X509_STORE -> Ptr X509_ -> IO CInt
 
 foreign import ccall unsafe "X509_STORE_add_crl"
-        _add_crl :: Ptr X509_STORE -> Ptr X509_CRL -> IO Int
+        _add_crl :: Ptr X509_STORE -> Ptr X509_CRL -> IO CInt
 
 -- |@'newX509Store'@ creates an empty X.509 certificate store.
 newX509Store :: IO X509Store
diff --git a/examples/GenRSAKey.hs b/examples/GenRSAKey.hs
--- a/examples/GenRSAKey.hs
+++ b/examples/GenRSAKey.hs
@@ -43,4 +43,4 @@
 
           let pkey = newPKeyRSA rsa
           writePKCS8PrivateKey pkey Nothing >>= putStr
-          -- writePublicKey pkey >>= putStr
+          writePublicKey pkey >>= putStr
