packages feed

crypto-api 0.4.1 → 0.5

raw patch · 4 files changed

+7/−152 lines, 4 filesdep ~basePVP ok

version bump matches the API change (PVP)

Dependency ranges changed: base

API changes (from Hackage documentation)

- Data.LargeWord: class LargeWord a
- Data.LargeWord: data LargeKey a b
- Data.LargeWord: instance (Eq a, Eq b) => Eq (LargeKey a b)
- Data.LargeWord: instance (Ord a, Bits a, Bounded a, Integral a, LargeWord a, Bits b, Bounded b, Integral b, LargeWord b) => Bounded (LargeKey a b)
- Data.LargeWord: instance (Ord a, Bits a, LargeWord a, Bits b, LargeWord b) => Bits (LargeKey a b)
- Data.LargeWord: instance (Ord a, Bits a, LargeWord a, Bits b, LargeWord b) => LargeWord (LargeKey a b)
- Data.LargeWord: instance (Ord a, Bits a, LargeWord a, Bits b, LargeWord b) => Num (LargeKey a b)
- Data.LargeWord: instance (Ord a, Bits a, LargeWord a, Bits b, LargeWord b) => Show (LargeKey a b)
- Data.LargeWord: instance (Ord a, Bits a, LargeWord a, Ord b, Bits b, LargeWord b) => Integral (LargeKey a b)
- Data.LargeWord: instance (Ord a, Bits a, LargeWord a, Ord b, Bits b, LargeWord b) => Real (LargeKey a b)
- Data.LargeWord: instance (Ord a, Ord b) => Ord (LargeKey a b)
- Data.LargeWord: instance Enum (LargeKey a b)
- Data.LargeWord: instance LargeWord Word32
- Data.LargeWord: instance LargeWord Word64
- Data.LargeWord: integerToLargeWord :: LargeWord a => Integer -> a
- Data.LargeWord: largeBitSize :: LargeWord a => a -> Int
- Data.LargeWord: largeWordAnd :: LargeWord a => a -> a -> a
- Data.LargeWord: largeWordOr :: LargeWord a => a -> a -> a
- Data.LargeWord: largeWordPlus :: LargeWord a => a -> a -> a
- Data.LargeWord: largeWordShift :: LargeWord a => a -> Int -> a
- Data.LargeWord: largeWordToInteger :: LargeWord a => a -> Integer
- Data.LargeWord: largeWordXor :: LargeWord a => a -> a -> a
- Data.LargeWord: type Word128 = LargeKey Word64 Word64
- Data.LargeWord: type Word160 = LargeKey Word32 Word128
- Data.LargeWord: type Word192 = LargeKey Word64 Word128
- Data.LargeWord: type Word224 = LargeKey Word32 Word192
- Data.LargeWord: type Word256 = LargeKey Word64 Word192
- Data.LargeWord: type Word96 = LargeKey Word32 Word64
- Crypto.Classes: keyLength :: BlockCipher k => k -> BitLength
+ Crypto.Classes: keyLength :: BlockCipher k => Tagged k BitLength

Files

Crypto/Classes.hs view
@@ -32,6 +32,7 @@ import qualified Data.ByteString as B import qualified Data.ByteString.Internal as I import Data.List (foldl')+import Data.Word (Word64) import Data.Tagged import Crypto.Types import Crypto.Random@@ -120,7 +121,7 @@   encryptBlock	:: k -> B.ByteString -> B.ByteString	-- ^ encrypt data of size @n*blockSize@ where @n `elem` [0..]@  (ecb encryption)   decryptBlock	:: k -> B.ByteString -> B.ByteString	-- ^ decrypt data of size @n*blockSize@ where @n `elem` [0..]@  (ecb decryption)   buildKey	:: B.ByteString -> Maybe k		-- ^ smart constructor for keys from a bytestring.-  keyLength	:: k -> BitLength			-- ^ keyLength may inspect its argument to return the length+  keyLength	:: Tagged k BitLength			-- ^ length of the cryptographic key  blockSizeBytes :: (BlockCipher k) => Tagged k ByteLength blockSizeBytes = fmap (`div` 8) blockSize
Crypto/Random.hs view
@@ -38,6 +38,7 @@ import Data.Bits (xor, setBit, shiftR, shiftL, (.&.)) import Data.List (foldl') import System.IO.Unsafe(unsafeInterleaveIO)+import qualified Foreign.ForeignPtr as FP  #if MIN_VERSION_tagged(0,2,0) import Data.Proxy
− Data/LargeWord.hs
@@ -1,147 +0,0 @@--------------------------------------------------------------------------------- |--- Module      :  Data.LargeWord--- Copyright   :  (c) Dominic Steinitz 2004--- License     :  BSD--- --- Maintainer  :  dominic.steinitz@blueyonder.co.uk--- Stability   :  experimental--- Portability :  portable------ Provides Word128, Word192 and Word256 and a way of producing other--- large words if required.-----------------------------------------------------------------------------------module Data.LargeWord-   (LargeWord(..),LargeKey,Word96,Word128,Word160,Word192,Word224,Word256) where--import Data.Word-import Data.Bits-import Numeric-import Data.Char---- Keys have certain capabilities.--class LargeWord a where-   largeWordToInteger :: a -> Integer-   integerToLargeWord :: Integer -> a-   largeWordPlus :: a -> a -> a-   largeWordAnd :: a -> a -> a-   largeWordOr :: a -> a -> a-   largeWordShift :: a -> Int -> a-   largeWordXor :: a -> a -> a-   largeBitSize :: a -> Int---- Word32 is a key in the obvious way.--instance LargeWord Word32 where-   largeWordToInteger = toInteger-   integerToLargeWord = fromInteger-   largeWordPlus = (+)-   largeWordAnd = (.&.)-   largeWordOr = (.|.)-   largeWordShift = shift-   largeWordXor = xor-   largeBitSize = bitSize---- Word64 is a key in the obvious way.--instance LargeWord Word64 where-   largeWordToInteger = toInteger-   integerToLargeWord = fromInteger-   largeWordPlus = (+)-   largeWordAnd = (.&.)-   largeWordOr = (.|.)-   largeWordShift = shift-   largeWordXor = xor-   largeBitSize = bitSize---- Define larger keys from smaller ones.--data LargeKey a b = LargeKey a b-   deriving (Eq, Ord)--instance (Ord a, Bits a, LargeWord a, Bits b, LargeWord b) =>-   LargeWord (LargeKey a b) where-      largeWordToInteger (LargeKey lo hi) =-         largeWordToInteger lo + (2^(bitSize lo)) * largeWordToInteger hi-      integerToLargeWord x =-         let (h,l) =  x `quotRem` (2^(bitSize lo))-             (lo,hi) = (integerToLargeWord l, integerToLargeWord h) in-                LargeKey lo hi-      largeWordPlus (LargeKey alo ahi) (LargeKey blo bhi) =-         LargeKey lo' hi' where-            lo' = alo + blo-            hi' = ahi + bhi + if lo' < alo then 1 else 0-      largeWordAnd (LargeKey alo ahi) (LargeKey blo bhi) =-         LargeKey lo' hi' where-            lo' = alo .&. blo-            hi' = ahi .&. bhi-      largeWordOr (LargeKey alo ahi) (LargeKey blo bhi) =-         LargeKey lo' hi' where-            lo' = alo .|. blo-            hi' = ahi .|. bhi-      largeWordXor (LargeKey alo ahi) (LargeKey blo bhi) =-         LargeKey lo' hi' where-            lo' = alo `xor` blo-            hi' = ahi `xor` bhi-      largeWordShift w 0 = w-      largeWordShift (LargeKey lo hi) x =-         if bitSize lo < bitSize hi-            then LargeKey (shift lo x) -                          (shift hi x .|. (shift (conv lo) (x - (bitSize lo))))-            else LargeKey (shift lo x)-                          (shift hi x .|. (conv $ shift lo (x - (bitSize lo))))-         where conv = integerToLargeWord . largeWordToInteger-      largeBitSize ~(LargeKey lo hi) = largeBitSize lo + largeBitSize hi--instance (Ord a, Bits a, LargeWord a, Bits b, LargeWord b) => Show (LargeKey a b) where-   showsPrec p = showInt . largeWordToInteger--instance (Ord a, Bits a, LargeWord a, Bits b, LargeWord b) => -   Num (LargeKey a b) where-      (+) = largeWordPlus-      fromInteger = integerToLargeWord ---- Larger keys are instances of Bits provided their constituents are keys.--instance (Ord a, Bits a, LargeWord a, Bits b, LargeWord b) => -   Bits (LargeKey a b) where-      (.&.) = largeWordAnd-      (.|.) = largeWordOr-      xor = largeWordXor-      shift = largeWordShift-      bitSize = largeBitSize--instance (Ord a, Bits a, Bounded a, Integral a, LargeWord a, -                 Bits b, Bounded b, Integral b, LargeWord b) => -   Bounded (LargeKey a b) where-      minBound = 0-      maxBound =-         result where-            result =-               fromIntegral $-               (1 + fromIntegral (maxBound `asTypeOf` (boflk result)))*-                  (1 + fromIntegral (maxBound `asTypeOf` (aoflk result))) - 1--aoflk :: (LargeKey a b) -> a-aoflk = undefined-boflk :: (LargeKey a b) -> b-boflk = undefined--instance (Ord a, Bits a, LargeWord a, Ord b, Bits b, LargeWord b) =>-   Integral (LargeKey a b) where-      toInteger = largeWordToInteger--instance (Ord a, Bits a, LargeWord a, Ord b, Bits b, LargeWord b) =>-   Real (LargeKey a b)--instance Enum (LargeKey a b)--type Word96  = LargeKey Word32 Word64-type Word128 = LargeKey Word64 Word64-type Word160 = LargeKey Word32 Word128-type Word192 = LargeKey Word64 Word128-type Word224 = LargeKey Word32 Word192-type Word256 = LargeKey Word64 Word192
crypto-api.cabal view
@@ -1,9 +1,9 @@ name:           crypto-api-version:        0.4.1+version:        0.5 license:        BSD3 license-file:   LICENSE-copyright:      Thomas DuBuisson <thomas.dubuisson@gmail.com>, Dominic Steinitz (see Data.LargeWord module)-author:         Thomas DuBuisson <thomas.dubuisson@gmail.com>, Dominic Steinitz+copyright:      Thomas DuBuisson <thomas.dubuisson@gmail.com>+author:         Thomas DuBuisson <thomas.dubuisson@gmail.com> maintainer:     Thomas DuBuisson <thomas.dubuisson@gmail.com> description:    A generic interface for cryptographic operations,                 platform independent quality RNG, property tests@@ -55,7 +55,7 @@                  tagged >= 0.1 && < 0.3   ghc-options:   -O2   hs-source-dirs:-  exposed-modules: Crypto.Classes, Crypto.Types, Crypto.HMAC, Data.LargeWord, Crypto.Modes, System.Crypto.Random, Crypto.Random, Crypto.Padding+  exposed-modules: Crypto.Classes, Crypto.Types, Crypto.HMAC, Crypto.Modes, System.Crypto.Random, Crypto.Random, Crypto.Padding   if os(windows)     cpp-options: -DisWindows     extra-libraries: advapi32