summaryrefslogtreecommitdiff
path: root/src/crypto
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2026-11-08 15:40:59 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2026-11-08 20:41:24 +0100
commita69cd845e9daa95527b6c497dd7c75293bbeb917 (patch)
treed8f9a657d723811dd27d9c840620151ea5fb181e /src/crypto
parentaefa4b4dc76c3feaab223ff7afe1293c7434fae0 (diff)
Remove ByteArray constraints from internal crypto API
Diffstat (limited to 'src/crypto')
-rw-r--r--src/crypto/crypton/Crypto.hs5
-rw-r--r--src/crypto/reflibs/Crypto/Cipher/ChaChaPoly1305.hs10
2 files changed, 7 insertions, 8 deletions
diff --git a/src/crypto/crypton/Crypto.hs b/src/crypto/crypton/Crypto.hs
index 015bdb2..c933b0a 100644
--- a/src/crypto/crypton/Crypto.hs
+++ b/src/crypto/crypton/Crypto.hs
@@ -39,7 +39,6 @@ import Crypto.PubKey.Ed25519 qualified as Ed
import Crypto.Random
import Crypto.Random.Entropy
-import Data.ByteArray (ByteArray)
import Data.ByteArray qualified as BA
import Data.ByteString (ByteString)
@@ -70,10 +69,10 @@ aeadAppendAAD = C.appendAAD
aeadFinalizeAAD :: AeadState -> AeadState
aeadFinalizeAAD = C.finalizeAAD
-encrypt :: ByteArray ba => ba -> AeadState -> ( ba, AeadState )
+encrypt :: ByteString -> AeadState -> ( ByteString, AeadState )
encrypt = C.encrypt
-decrypt :: ByteArray ba => ( ba, Auth ) -> AeadState -> Maybe ba
+decrypt :: ( ByteString, Auth ) -> AeadState -> Maybe ByteString
decrypt ( ctext, auth ) st = do
let ( plain, st' ) = C.decrypt ctext st
guard (C.finalize st' `BA.constEq` auth)
diff --git a/src/crypto/reflibs/Crypto/Cipher/ChaChaPoly1305.hs b/src/crypto/reflibs/Crypto/Cipher/ChaChaPoly1305.hs
index 7f0ef20..9071d9f 100644
--- a/src/crypto/reflibs/Crypto/Cipher/ChaChaPoly1305.hs
+++ b/src/crypto/reflibs/Crypto/Cipher/ChaChaPoly1305.hs
@@ -54,17 +54,17 @@ aeadAppendAAD aad st = st { stAAD = stAAD st ++ [ aad ] }
aeadFinalizeAAD :: AeadState -> AeadState
aeadFinalizeAAD = id
-encrypt :: ByteArray ba => ba -> AeadState -> ( ba, AeadState )
+encrypt :: ByteString -> AeadState -> ( ByteString, AeadState )
encrypt ptext st =
let Nonce nonce = stNonce st
- ( ctext, mac ) = P.encrypt (B.concat $ stAAD st) (stKey st) nonce (convert ptext)
- in ( convert ctext, st { stAuth = Just $ Auth mac } )
+ ( ctext, mac ) = P.encrypt (B.concat $ stAAD st) (stKey st) nonce ptext
+ in ( ctext, st { stAuth = Just $ Auth mac } )
-decrypt :: ByteArray ba => ( ba, Auth ) -> AeadState -> Maybe ba
+decrypt :: ( ByteString, Auth ) -> AeadState -> Maybe ByteString
decrypt ( ctext, auth ) st = do
let Nonce nonce = stNonce st
Auth mac = auth
- fmap convert $ P.decrypt (B.concat $ stAAD st) (stKey st) nonce ( convert ctext, mac )
+ P.decrypt (B.concat $ stAAD st) (stKey st) nonce ( ctext, mac )
aeadFinalize :: AeadState -> Auth
aeadFinalize st = case stAuth st of