packages feed

cipher-aes128 0.2 → 0.2.1

raw patch · 3 files changed

+27/−53 lines, 3 filesdep ~basesetup-changed

Dependency ranges changed: base

Files

Setup.hs view
@@ -1,4 +1,5 @@ import Distribution.Simple+import Distribution.Simple.LocalBuildInfo import Distribution.Simple.Setup import Distribution.PackageDescription import Distribution.Simple.Utils@@ -7,62 +8,31 @@ import System.Process import System.Directory import System.Exit+import Text.Groom  main = defaultMainWithHooks hk  where- hk = simpleUserHooks { preBuild = \as fs -> do-                                        b <- (preBuild simpleUserHooks) as fs-                                        checkAndAddAES fs b }--checkAndAddAES :: BuildFlags -> HookedBuildInfo -> IO HookedBuildInfo-checkAndAddAES fs x@(m,as) = do-        b  <- canUseAesIntrinsicsFlag fs-        b2 <- haveNIInstrs fs-        let bi = maybe emptyBuildInfo id m-            op = if b && b2 then addNIintrinsicOpt else id-        return (Just (op emptyBuildInfo), as)+ hk = simpleUserHooks { buildHook = \pd lbi uh bf -> do+                                        print "yo yo yo"+                                        let ccProg = Program "gcc" undefined undefined undefined+                                            mConf = lookupProgram ccProg (withPrograms lbi)+                                            err = error "Could not determine C compiler"+                                            cc = locationPath . programLocation  . maybe err id $ mConf+                                        b <- canUseAesIntrinsicsFlag cc+                                        print (withPrograms lbi)+                                        let newWithPrograms1 = userSpecifyArgs "gcc" aesArgs (withPrograms lbi)+                                            newWithPrograms  = userSpecifyArgs "ghc" aesArgsHC newWithPrograms1+                                        buildHook simpleUserHooks pd (lbi {withPrograms = newWithPrograms }) uh bf+                      } -addNIintrinsicOpt :: BuildInfo -> BuildInfo-addNIintrinsicOpt bi = bi { ccOptions = ccOptions bi ++ ["-maes", "-mssse3", "-DHAVE_AES_INTRINSICS", "-DHAVE_NI"] }+aesArgs :: [String]+aesArgs = ["-maes", "-mssse3", "-DHAVE_AES_INTRINSICS"] --- Detect if we have AES NI instructions for acceleration on x86 CPUs-haveNIInstrs :: BuildFlags -> IO Bool-haveNIInstrs cf = do-        -- FIXME cf is always empty, how do we ensure we're testing the right C compiler?-        -- TODO: I am hooking Cabal at the wrong spot, need to hook one stage-        -- later!-        let prog = lookup "cc" (buildProgramPaths cf)-            cc = maybe "gcc" id prog-        withTempDirectory normal "" "testNI" $ \tmpDir -> do-         writeFile (tmpDir ++ "/testNI.c")-               (unlines ["#include <stdint.h>",-                        "/**",-                        " * Returns zero if false, non-zero otherwise",-                        " */",-                        "int cpu_has_ni()",-                        "{",-                        "uint32_t ax,bx,cx,dx,func=1;",-                        "uint32_t regs[4];",-                        "asm volatile (\"cpuid\":",-                        "\"=a\" (ax), \"=b\" (bx), \"=c\" (cx), \"=d\" (dx) : \"a\" (func));",-                        "return (cx & 0x2000000);",-                        "}",-                        "int main()",-                        "{",-                        "    if(cpu_has_ni()) return 0; else return -1;",-                        "}"]-                                )-         ec <- rawSystemExitCode normal cc ["-maes",tmpDir ++ "/testNI.c"]-         notice normal $ "Result of AES NI Test: " ++ show (ec == ExitSuccess)-         return (ec == ExitSuccess)+aesArgsHC :: [String]+aesArgsHC = map ("-optc" ++) aesArgs -canUseAesIntrinsicsFlag :: BuildFlags -> IO Bool-canUseAesIntrinsicsFlag cf = do-        -- FIXME cf is always empty, how do we ensure we're testing the right C compiler?-        -- TODO: I am hooking Cabal at the wrong spot, need to hook one stage-        -- later!-        let prog = lookup "cc" (buildProgramPaths cf)-            cc = maybe "gcc" id prog+canUseAesIntrinsicsFlag :: FilePath -> IO Bool+canUseAesIntrinsicsFlag cc = do         withTempDirectory normal "" "testIntrinsic" $ \tmpDir -> do         writeFile (tmpDir ++ "/testIntrinsic.c")                 (unlines        [ "#include <wmmintrin.h>"
cbits/aes/aes.c view
@@ -3,8 +3,6 @@ #include <string.h> #include <stdlib.h> -/* The "HAVE_NI" macro is also defined (or not) but we no longer need that- * since we're doing a runtime detection... again. */ #if (defined(__i386__) || defined(__x86_64__)) && defined(HAVE_AES_INTRINSICS) && !defined(AVOID_NI) #define TRY_NI #include "aes_x86ni.h"
cipher-aes128.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                cipher-aes128-version:             0.2+version:             0.2.1 synopsis:            AES128 using AES-NI when available. description:         AES128 with crypto-api instances and a trampoline between Vincent Hanquez's C-based and x86 NI-based AES.  Patches welcome to add additional high-performance backends (ARM?) license:             BSD3@@ -11,6 +11,8 @@ maintainer:          thomas.dubuisson@gmail.com copyright:           Thomas M. DuBuisson category:            Cryptography+homepage:            https://github.com/TomMD/cipher-aes128+bug-reports:         https://github.com/TomMD/cipher-aes128 build-type:          Custom cabal-version:       >=1.12 @@ -37,3 +39,7 @@                         , ./cbits/aes/generic/aes_generic.c   include-dirs:        cbits/include   cc-options:          -O3++source-repository head+  type:         git+  location:     https://github.com/TomMD/cipher-aes128