Skip to content

Commit

Permalink
Adding a prebuild .so for linux (and later for other platforms). The
Browse files Browse the repository at this point in the history
goal is to remove possible fragilities in the build process that would limit portability.
  • Loading branch information
rrnewton committed Feb 4, 2011
1 parent 9b051e6 commit aa7308d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
10 changes: 8 additions & 2 deletions Codec/Crypto/IntelAES.hs
Expand Up @@ -14,9 +14,10 @@

module Codec.Crypto.IntelAES
(
mkAESGen
mkAESGen,
CompoundAESRNG(),
-- Plus, instances exported of course.
, testIntelAES
testIntelAES
)
where

Expand All @@ -37,8 +38,12 @@ newtype CompoundCRG =
(Either (BCtoCRG (NI.IntelAES NI.N128))
(BCtoCRG (GA.AES GA.N128)))

-- | The type representing an AES-based random number generator which
-- | will use AESNI instructions when available, and invoke the
-- | portable Gladman implementation when not.
type CompoundAESRNG = CRGtoRG CompoundCRG

-- |
mkAESGen :: Int -> CompoundAESRNG
mkAESGen int = convertCRG gen
where
Expand Down Expand Up @@ -77,6 +82,7 @@ instance CryptoRandomGen CompoundCRG where

-- ByteLength -> CompoundCRG -> Either GenError (B.ByteString, CompoundCRG)
genBytes req (CompoundCRG (Left gen)) =
-- Let's try to reduce that boilerplate if we can...
#if 0
mapRight (mapSnd (CompoundCRG . Left) ) $ genBytes req gen
#else
Expand Down
27 changes: 21 additions & 6 deletions Setup.hs
Expand Up @@ -8,6 +8,7 @@ import Distribution.PackageDescription
import Distribution.Simple.LocalBuildInfo
import System.Cmd(system)
import System.Exit
import qualified System.Info as Info
import System.IO.Unsafe
import System.Directory
import Data.Maybe
Expand Down Expand Up @@ -107,12 +108,26 @@ filt str = not (isInfixOf "intel_aes" str)
my_preBuild :: Args -> BuildFlags -> IO HookedBuildInfo
my_preBuild args flags = do
putStrLn$ "\n================================================================================"
putStrLn$ " [intel-aes] Running Makefile to build C/asm source..."
rootdir <- getCurrentDirectory
setCurrentDirectory "./cbits/"
system "make"
setCurrentDirectory rootdir
putStrLn$ " [intel-aes] Done with external build job."
let
ext = case Info.os of
"linux" -> ".so"
"mac" -> ".dylib"
"windows" -> ".dll"
_ -> error$ "Unexpected "
cached_so = "./cbits/prebuilt/libintel_aes_"++ Info.os ++"_"++ Info.arch ++ ext
dest = "./cbits/libintel_aes"++ext
e <- doesFileExist cached_so
if e then do
putStrLn$ " [intel-aes] Using prebuilt dynamic library: "++ cached_so
copyFile cached_so dest
putStrLn$ " [intel-aes] Done copying into position: "++ dest
else do
putStrLn$ " [intel-aes] Running Makefile to build C/asm source..."
rootdir <- getCurrentDirectory
setCurrentDirectory "./cbits/"
system "make"
setCurrentDirectory rootdir
putStrLn$ " [intel-aes] Done with external build job."
putStrLn$ "================================================================================\n"

(preBuild simpleUserHooks) args flags
Expand Down
Binary file added cbits/prebuilt/libintel_aes_linux_x86_64.so
Binary file not shown.

0 comments on commit aa7308d

Please sign in to comment.