cipher-aes128 0.1 → 0.2
raw patch · 6 files changed
+73/−5 lines, 6 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Crypto.Cipher.AES128.Internal: decryptCTR :: AESKey -> Ptr Word8 -> Ptr Word8 -> Ptr Word8 -> Int -> IO ()
+ Crypto.Cipher.AES128.Internal: encryptCTR :: AESKey -> Ptr Word8 -> Ptr Word8 -> Ptr Word8 -> Int -> IO ()
Files
- AUTHORS +2/−4
- Crypto/Cipher/AES128/Internal.hs +39/−0
- cbits/aes/aes.c +25/−0
- cbits/aes/generic/aes_generic.c +1/−0
- cbits/include/aes.h +5/−0
- cipher-aes128.cabal +1/−1
AUTHORS view
@@ -1,4 +1,2 @@-Vincent Hanquez implemented, in C, the AES routines.--Thomas M. DuBuisson is the original author of the implementation selection-routines in cbits/aes/aes.c and Haskell bindings.+Thomas DuBuisson: AES trampolines, Haskell code+Vincent Hanquez: AES algorithms for x86 and NI
Crypto/Cipher/AES128/Internal.hs view
@@ -6,6 +6,8 @@ , decryptECB , encryptGCM , decryptGCM+ , encryptCTR+ , decryptCTR ) where import Foreign.Ptr@@ -52,6 +54,22 @@ -> Ptr Word8 -> Ptr Word8 -- ^ Result PT and TAG -> IO () +foreign import ccall unsafe "aes/aes.h aes_encrypt_ctr"+ c_encrypt_ctr :: AESKeyPtr+ -> Ptr Word8 -- ^ 128 bit IV+ -> Ptr Word8 -- ^ Result+ -> Ptr Word8 -- ^ Input+ -> Word32 -- ^ Input length in bytes+ -> IO ()++c_decrypt_ctr :: AESKeyPtr+ -> Ptr Word8 -- ^ 128 bit IV+ -> Ptr Word8 -- ^ Result+ -> Ptr Word8 -- ^ Input+ -> Word32 -- ^ Input length in bytes+ -> IO ()+c_decrypt_ctr = c_encrypt_ctr+ blkSzC :: Word32 blkSzC = 16 @@ -124,3 +142,24 @@ decryptGCM (AESKey _ k) iv ivLen aad aadLen ct ctLen pt tag = withForeignPtr k $ \p -> do c_decrypt_gcm p iv (fromIntegral ivLen) aad (fromIntegral aadLen) ct (fromIntegral ctLen) pt tag {-# INLINE decryptGCM #-}++encryptCTR :: AESKey+ -> Ptr Word8 -- ^ IV+ -> Ptr Word8 -- ^ CT+ -> Ptr Word8 -- ^ PT+ -> Int -- ^ Length in bytes+ -> IO ()+encryptCTR (AESKey _ k) iv ct pt len = withForeignPtr k $ \p -> do+ c_encrypt_ctr p iv ct pt (fromIntegral len)+{-# INLINE encryptCTR #-}++decryptCTR :: AESKey+ -> Ptr Word8 -- ^ IV+ -> Ptr Word8 -- ^ CT+ -> Ptr Word8 -- ^ PT+ -> Int -- ^ Length in bytes+ -> IO ()++decryptCTR (AESKey _ k) iv ct pt len = withForeignPtr k $ \p -> do+ c_decrypt_ctr p iv ct pt (fromIntegral len)+{-# INLINE decryptCTR #-}
cbits/aes/aes.c view
@@ -363,3 +363,28 @@ a->q[0] = cpu_to_be64(a0); a->q[1] = cpu_to_be64(a1); }++void aes_encrypt_ctr(AESKey *key, uint8_t *iv, uint8_t *output, uint8_t *input, uint32_t len)+{+ aes_block block, o;+ uint32_t nb_blocks = len / 16;+ int i;++ /* preload IV in block */+ block128_copy(&block, (aes_block *)iv);++ for ( ; nb_blocks-- > 0; block128_inc_be(&block), output += 16, input += 16) {+ encrypt_ecb(key, (uint8_t *)&o, (uint8_t *)&block, 1);+ block128_vxor((block128 *) output, &o, (block128 *) input);+ }++ if ((len % 16) != 0) {+ encrypt_ecb(key, (uint8_t *)&o, (uint8_t *)&block, 1);+ for (i = 0; i < (len % 16); i++) {+ *output = ((uint8_t *) &o)[i] ^ *input;+ output += 1;+ input += 1;+ }+ }+}+
cbits/aes/generic/aes_generic.c view
@@ -440,3 +440,4 @@ expand_key(key->data, origkey, size, esz); return; }+
cbits/include/aes.h view
@@ -20,5 +20,10 @@ , uint8_t *aad, uint32_t aadLen , uint8_t *ct, uint32_t ctLen , uint8_t *pt, uint8_t *tag);+void aes_encrypt_ctr( AESKey *key+ , uint8_t *iv+ , uint8_t *dst+ , uint8_t *src+ , uint32_t nr); #endif
cipher-aes128.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: cipher-aes128-version: 0.1+version: 0.2 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