cryptostore 0.2.2.0 → 0.2.3.0
raw patch · 6 files changed
+40/−16 lines, 6 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- ChangeLog.md +4/−0
- cryptostore.cabal +1/−1
- src/Crypto/Store/CMS/Algorithms.hs +2/−2
- src/Crypto/Store/Cipher/RC2.hs +3/−3
- src/Crypto/Store/Cipher/RC2/Primitive.hs +8/−10
- src/Crypto/Store/Util.hs +22/−0
ChangeLog.md view
@@ -1,5 +1,9 @@ # Revision history for cryptostore +## 0.2.3.0 - 2022-11-05++* Fix RC2 on big-endian architectures+ ## 0.2.2.0 - 2022-04-16 * Fix buffer overrun in `pkcs12Derive`
cryptostore.cabal view
@@ -1,5 +1,5 @@ name: cryptostore-version: 0.2.2.0+version: 0.2.3.0 synopsis: Serialization of cryptographic data types description: Haskell implementation of PKCS \#8, PKCS \#12 and CMS (Cryptographic Message Syntax).
src/Crypto/Store/CMS/Algorithms.hs view
@@ -1174,8 +1174,8 @@ type AlgorithmType KeyDerivationFunc = KeyDerivationAlgorithm algorithmName _ = "key derivation algorithm"- algorithmType PBKDF2{..} = TypePBKDF2- algorithmType Scrypt{..} = TypeScrypt+ algorithmType PBKDF2{} = TypePBKDF2+ algorithmType Scrypt{} = TypeScrypt parameterASN1S PBKDF2{..} = asn1Container Sequence (salt . iters . keyLen . mprf)
src/Crypto/Store/Cipher/RC2.hs view
@@ -15,13 +15,13 @@ import Data.ByteArray (ByteArrayAccess) import qualified Data.ByteArray as B-import qualified Data.ByteArray.Mapping as B import Data.Maybe (fromMaybe) import Crypto.Error import Crypto.Cipher.Types import Crypto.Store.Cipher.RC2.Primitive+import Crypto.Store.Util -- | RC2 block cipher. Key is between 8 and 1024 bits. newtype RC2 = RC2 Key@@ -33,8 +33,8 @@ instance BlockCipher RC2 where blockSize _ = 8- ecbEncrypt (RC2 k) = B.mapAsWord64 (encrypt k)- ecbDecrypt (RC2 k) = B.mapAsWord64 (decrypt k)+ ecbEncrypt (RC2 k) = mapAsWord64LE (encrypt k)+ ecbDecrypt (RC2 k) = mapAsWord64LE (decrypt k) -- | Build a RC2 cipher with the specified effective key length (in bits). rc2WithEffectiveKeyLength :: ByteArrayAccess key
src/Crypto/Store/Cipher/RC2/Primitive.hs view
@@ -39,20 +39,18 @@ decomp64 :: Word64 -> Q decomp64 x =- let f = unBE . toBE . fromIntegral- a = f (x `shiftR` 48)- b = f (x `shiftR` 32)- c = f (x `shiftR` 16)- d = f x+ let d = fromIntegral (x `shiftR` 48)+ c = fromIntegral (x `shiftR` 32)+ b = fromIntegral (x `shiftR` 16)+ a = fromIntegral x in Q a b c d comp64 :: Q -> Word64 comp64 (Q a b c d) =- (f a `shiftL` 48) .|.- (f b `shiftL` 32) .|.- (f c `shiftL` 16) .|.- f d- where f = fromIntegral . unBE . toBE+ (fromIntegral d `shiftL` 48) .|.+ (fromIntegral c `shiftL` 32) .|.+ (fromIntegral b `shiftL` 16) .|.+ fromIntegral a getR :: Q -> Word8 -> Word16 getR (Q a b c d) i =
src/Crypto/Store/Util.hs view
@@ -14,14 +14,19 @@ , reverseBytes , constAllEq , mapLeft+ , mapAsWord64LE ) where import Data.Bits import Data.ByteArray (ByteArray, ByteArrayAccess) import qualified Data.ByteArray as B import Data.List+import Data.Memory.Endian import Data.Word +import Foreign.Ptr (plusPtr)+import Foreign.Storable+ import GHC.Exts -- | This is a strict version of &&.@@ -48,3 +53,20 @@ mapLeft :: (a -> b) -> Either a c -> Either b c mapLeft f (Left a) = Left (f a) mapLeft _ (Right c) = Right c++-- | Same as 'Data.ByteArray.Mapping.mapAsWord64' but with little-endian words.+mapAsWord64LE :: ByteArray bs => (Word64 -> Word64) -> bs -> bs+mapAsWord64LE f bs =+ B.allocAndFreeze len $ \dst ->+ B.withByteArray bs $ \src ->+ loop (len `div` 8) dst src+ where+ len = B.length bs++ loop :: Int -> Ptr (LE Word64) -> Ptr (LE Word64) -> IO ()+ loop 0 _ _ = return ()+ loop i d s = do+ w <- peek s+ let r = f (fromLE w)+ poke d (toLE r)+ loop (i - 1) (d `plusPtr` 8) (s `plusPtr` 8)