packages feed

cipher-aes128 0.6 → 0.6.1

raw patch · 2 files changed

+19/−11 lines, 2 files

Files

Crypto/Cipher/AES128/Internal.hs view
@@ -1,8 +1,8 @@ {-# LANGUAGE ForeignFunctionInterface, EmptyDataDecls, ViewPatterns #-} module Crypto.Cipher.AES128.Internal-        ( AESKey128(..), AESKey192(..), AESKey256(..), RawKey128(..), RawKey192(..), RawKey256(..), GCM(..)+        ( AESKey128(..), AESKey192(..), AESKey256(..), RawKey128(..), RawKey192(..), RawKey256(..), GCM(..), GCMpc         , generateKey128, generateKey192, generateKey256-        , generateGCM+        , generateGCM, precomputeGCMdata         , encryptECB         , decryptECB         , encryptCTR@@ -281,20 +281,28 @@ -- GCM generateGCM :: GetExpanded k             => k-            -> IO (Maybe (GCM k))-generateGCM keyStruct-    | otherwise                   = do+            -> IO (GCM k)+generateGCM keyStruct = do+    gcmPC <- precomputeGCMdata keyStruct     withForeignPtr (expandedKey keyStruct) $ \k -> do-      g <- c_allocate_gcm       c <- c_allocate_ctx-      allocaBytes 12 $ \ivPtr -> do+      allocaBytes 12 $ \ivPtr -> withGCMpc gcmPC $ \g -> do           mapM_ (\i -> pokeElemOff ivPtr i (0::Word8)) [0..11]-          c_gcm_init g k           c_ctx_init g c k ivPtr 12-      gFP <- newForeignPtr c_free_gcm g       cFP <- newForeignPtr c_free_ctx c-      return (Just $ GCM (GCMpc gFP) keyStruct cFP)+      return (GCM gcmPC keyStruct cFP) {-# INLINE generateGCM #-}++precomputeGCMdata :: GetExpanded k => k -> IO GCMpc+precomputeGCMdata k = do+    withForeignPtr (expandedKey k) $ \kp -> do+        g <- c_allocate_gcm+        c_gcm_init g kp+        gFP <- newForeignPtr c_free_gcm g+        return (GCMpc gFP)++withGCMpc :: GCMpc -> (AESGcmPtr -> IO a) -> IO a+withGCMpc (GCMpc p) = withForeignPtr p  -- An encrypt function that can handle up to blks < maxBound `div` 16 :: Word32 -- simultaneous blocks.
cipher-aes128.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                cipher-aes128-version:             0.6+version:             0.6.1 synopsis:            AES and common modes using AES-NI when available. description:         Cipher-aes128 is an implementation of AES and common modes of operation.  It borrows Hanquez's C AES code (see 'cipher-aes') but                      is unique due to including compile-time detection of