From aefa4b4dc76c3feaab223ff7afe1293c7434fae0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Sun, 8 Nov 2026 15:08:02 +0100 Subject: Use ByteString in nonce-related functions --- src/crypto/crypton/Crypto.hs | 6 +++--- src/crypto/reflibs/Crypto/Cipher/ChaChaPoly1305.hs | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'src/crypto') diff --git a/src/crypto/crypton/Crypto.hs b/src/crypto/crypton/Crypto.hs index e84cec2..015bdb2 100644 --- a/src/crypto/crypton/Crypto.hs +++ b/src/crypto/crypton/Crypto.hs @@ -39,7 +39,7 @@ import Crypto.PubKey.Ed25519 qualified as Ed import Crypto.Random import Crypto.Random.Entropy -import Data.ByteArray (Bytes, ByteArray) +import Data.ByteArray (ByteArray) import Data.ByteArray qualified as BA import Data.ByteString (ByteString) @@ -55,10 +55,10 @@ type AeadState = C.State type Nonce = C.Nonce -nonce8 :: Bytes -> Bytes -> CryptoFailable Nonce +nonce8 :: ByteString -> ByteString -> CryptoFailable Nonce nonce8 = C.nonce8 -nonce12 :: Bytes -> CryptoFailable Nonce +nonce12 :: ByteString -> CryptoFailable Nonce nonce12 = C.nonce12 aeadInitialize :: ScrubbedBytes -> Nonce -> CryptoFailable AeadState diff --git a/src/crypto/reflibs/Crypto/Cipher/ChaChaPoly1305.hs b/src/crypto/reflibs/Crypto/Cipher/ChaChaPoly1305.hs index c849c0b..7f0ef20 100644 --- a/src/crypto/reflibs/Crypto/Cipher/ChaChaPoly1305.hs +++ b/src/crypto/reflibs/Crypto/Cipher/ChaChaPoly1305.hs @@ -27,16 +27,16 @@ data AeadState = AeadState newtype Nonce = Nonce ByteString deriving (Eq, ByteArrayAccess) -nonce8 :: Bytes -> Bytes -> CryptoFailable Nonce +nonce8 :: ByteString -> ByteString -> CryptoFailable Nonce nonce8 c iv - | BA.length c /= 4 = CryptoFailed CryptoError - | BA.length iv /= 8 = CryptoFailed CryptoError - | otherwise = CryptoPassed $ Nonce $ B.concat $ [ BA.convert c, BA.convert iv ] + | B.length c /= 4 = CryptoFailed CryptoError + | B.length iv /= 8 = CryptoFailed CryptoError + | otherwise = CryptoPassed $ Nonce $ B.concat [ c, iv ] -nonce12 :: Bytes -> CryptoFailable Nonce +nonce12 :: ByteString -> CryptoFailable Nonce nonce12 iv - | BA.length iv /= 12 = CryptoFailed CryptoError - | otherwise = CryptoPassed $ Nonce $ BA.convert iv + | B.length iv /= 12 = CryptoFailed CryptoError + | otherwise = CryptoPassed $ Nonce iv aeadInitialize :: ScrubbedBytes -> Nonce -> CryptoFailable AeadState aeadInitialize key nonce -- cgit v1.2.3