diff --git a/cryptoids/changes.md b/cryptoids/changes.md index 4a074a0..dc1efca 100644 --- a/cryptoids/changes.md +++ b/cryptoids/changes.md @@ -1,3 +1,7 @@ +# 0.4.0.0 + - Expose 'cipherBlockSize' + - Adjust 'Data.CryptoID.Poly' to allow for more dynamic padding + # 0.3.0.0 - Better exception type (does no longer leak private information) - 'Data.CryptoID.Poly' now supports padding the plaintext to a certain length before encryption diff --git a/cryptoids/cryptoids.cabal b/cryptoids/cryptoids.cabal index 2aa9240..e27c527 100644 --- a/cryptoids/cryptoids.cabal +++ b/cryptoids/cryptoids.cabal @@ -1,5 +1,5 @@ name: cryptoids -version: 0.3.0.0 +version: 0.4.0.0 synopsis: Reversable and secure encoding of object ids as a bytestring license: BSD3 license-file: LICENSE diff --git a/cryptoids/src/Data/CryptoID/ByteString.hs b/cryptoids/src/Data/CryptoID/ByteString.hs index eb5d31d..4b124c0 100644 --- a/cryptoids/src/Data/CryptoID/ByteString.hs +++ b/cryptoids/src/Data/CryptoID/ByteString.hs @@ -20,6 +20,7 @@ module Data.CryptoID.ByteString , decrypt , CryptoIDError(..) , CryptoCipher, CryptoHash + , cipherBlockSize ) where import Data.CryptoID @@ -32,8 +33,6 @@ import Data.ByteString (ByteString) import qualified Data.ByteString as ByteString import qualified Data.ByteString.Char8 as ByteString.Char -import qualified Data.ByteString.Lazy as Lazy (ByteString) - import Data.List (sortOn) import Data.Ord (Down(..)) @@ -71,6 +70,10 @@ type CryptoCipher = Blowfish -- -- Violation of this expectation causes runtime errors. type CryptoHash = SHAKE128 64 + + +cipherBlockSize :: Int +cipherBlockSize = blockSize (undefined :: CryptoCipher) -- | This newtype ensures only keys of the correct length can be created @@ -209,4 +212,3 @@ decrypt (keyMaterial -> key) CryptoID{..} = do cipher <- cryptoFailable (cipherInit key :: CryptoFailable CryptoCipher) namespace <- namespace' (Proxy :: Proxy namespace) return $ cbcDecrypt cipher namespace ciphertext - diff --git a/cryptoids/src/Data/CryptoID/Poly.hs b/cryptoids/src/Data/CryptoID/Poly.hs index 17769e3..65a4418 100644 --- a/cryptoids/src/Data/CryptoID/Poly.hs +++ b/cryptoids/src/Data/CryptoID/Poly.hs @@ -54,16 +54,16 @@ encrypt :: forall a m c namespace. ( KnownSymbol namespace , MonadThrow m , Binary a - ) => Maybe Int -- ^ Ensure the resulting ciphertext is of this size (needs to be a multiple of the block size of 'CryptoCipher' in bytes, otherwise an exception will be thrown at runtime) + ) => (ByteString -> m (Maybe Int)) -- ^ Ensure the resulting ciphertext is of the provided length (needs to be a multiple of the block size of 'CryptoCipher' in bytes, otherwise an exception will be thrown at runtime). The computation has access to the serialized plaintext -> (ByteString -> m c) -> CryptoIDKey -> a -> m (CryptoID namespace c) -encrypt pLength encode' key plaintext = do - cID <- ByteString.encrypt key <=< pad . Lazy.ByteString.toStrict $ encode plaintext +encrypt pLength' encode' key plaintext = do + cID <- ByteString.encrypt key <=< (\str -> pad str =<< pLength' str) . Lazy.ByteString.toStrict $ encode plaintext _ciphertext encode' cID where - pad str + pad str pLength | Just l <- pLength , l' <= l = return $ str <> ByteString.replicate (l - l') 0 | Just _ <- pLength = throwM $ CiphertextConversionFailed str diff --git a/uuid-crypto/changes.md b/uuid-crypto/changes.md index 7aaf13a..96f1360 100644 --- a/uuid-crypto/changes.md +++ b/uuid-crypto/changes.md @@ -1,3 +1,7 @@ +# 1.3.1.0 + - Fix documentation mistake + - Bump @cryptoids@ to @0.4.0.*@ + # 1.3.0.1 - Fix documentation typo diff --git a/uuid-crypto/src/Data/UUID/Cryptographic.hs b/uuid-crypto/src/Data/UUID/Cryptographic.hs index bad2a16..10a1c71 100644 --- a/uuid-crypto/src/Data/UUID/Cryptographic.hs +++ b/uuid-crypto/src/Data/UUID/Cryptographic.hs @@ -44,16 +44,13 @@ type CryptoUUID (namespace :: Symbol) = CryptoID namespace UUID -- | Encrypt an arbitrary serializable value -- -- We only expect to fail if the given value is not serialized in such a fashion --- that it fits within one 'CryptoCipher'-block. --- --- Larger values could likely not be contained wholly within 128 bits (the size --- of an 'UUID') in any case. +-- that it fits within 128 bits (the length of an 'UUID'). encrypt :: forall a m namespace. ( KnownSymbol namespace , Binary a , MonadThrow m ) => CryptoIDKey -> a -> m (CryptoUUID namespace) -encrypt = Poly.encrypt (Just 16) $ \str -> maybe (throwM $ CiphertextConversionFailed str) return . fromByteString $ Lazy.ByteString.fromStrict str +encrypt = Poly.encrypt (const . return $ Just 16) $ \str -> maybe (throwM $ CiphertextConversionFailed str) return . fromByteString $ Lazy.ByteString.fromStrict str -- | Decrypt an arbitrary serializable value diff --git a/uuid-crypto/uuid-crypto.cabal b/uuid-crypto/uuid-crypto.cabal index 6af244f..686474b 100644 --- a/uuid-crypto/uuid-crypto.cabal +++ b/uuid-crypto/uuid-crypto.cabal @@ -1,5 +1,5 @@ name: uuid-crypto -version: 1.3.0.1 +version: 1.3.1.0 synopsis: Reversable and secure encoding of object ids as uuids license: BSD3 license-file: LICENSE @@ -28,7 +28,7 @@ library other-extensions: ScopedTypeVariables build-depends: base >=4.9 && <4.11 , cryptoids-types ==0.0.0 - , cryptoids ==0.3.0.* + , cryptoids ==0.4.0.* , uuid >=1.3.13 && <1.4 , binary >=0.8.3.0 && <0.9 , bytestring >=0.10.8.1 && <0.11