module Botan.Easy
( Digest(..)
, hash
, verifyDigest
, BlockCipherKey(..)
, BlockCiphertext(..)
, newBlockCipherKey
, blockCipherEncrypt
, blockCipherDecrypt
, CipherKey(..)
, CipherNonce(..)
, Ciphertext(..)
, newCipherKey
, newCipherNonce
, cipherEncrypt
, cipherDecrypt
) where
import Botan.Prelude hiding (Ciphertext, LazyCiphertext)
import Data.ByteString (ByteString)
import Botan.RNG (MonadRandomIO(..))
import qualified Botan.Types.Class as Types
import qualified Botan.Hash.Class as Hash
import qualified Botan.Hash.SHA3 as Hash
import qualified Botan.BlockCipher.Class as BlockCipher
import qualified Botan.BlockCipher.AES as BlockCipher
import qualified Botan.Cipher.Class as Cipher
import qualified Botan.Cipher.ChaCha20Poly1305 as Cipher
type Digest = Hash.Digest Hash.SHA3_512
hash :: ByteString -> Digest
hash :: ByteString -> Digest
hash = ByteString -> Digest
forall hash. Hash hash => ByteString -> Digest hash
Hash.hash
verifyDigest :: Digest -> ByteString -> Bool
verifyDigest :: Digest -> ByteString -> Bool
verifyDigest Digest
d ByteString
bs = Digest
d Digest -> Digest -> Bool
forall a. Eq a => a -> a -> Bool
== ByteString -> Digest
hash ByteString
bs
type BlockCipherKey = BlockCipher.SecretKey BlockCipher.AES256
type BlockCiphertext = BlockCipher.Ciphertext BlockCipher.AES256
newBlockCipherKey :: (MonadRandomIO m) => m BlockCipherKey
newBlockCipherKey :: forall (m :: * -> *). MonadRandomIO m => m BlockCipherKey
newBlockCipherKey = m BlockCipherKey
forall alg (m :: * -> *). SecretKeyGen alg m => m (SecretKey alg)
Types.newSecretKey
blockCipherEncrypt :: BlockCipherKey -> ByteString -> Maybe (BlockCiphertext)
blockCipherEncrypt :: BlockCipherKey -> ByteString -> Maybe BlockCiphertext
blockCipherEncrypt = BlockCipherKey -> ByteString -> Maybe BlockCiphertext
forall bc.
BlockCipher bc =>
SecretKey bc -> ByteString -> Maybe (Ciphertext bc)
BlockCipher.blockCipherEncrypt
blockCipherDecrypt :: BlockCipherKey -> BlockCiphertext -> Maybe ByteString
blockCipherDecrypt :: BlockCipherKey -> BlockCiphertext -> Maybe ByteString
blockCipherDecrypt = BlockCipherKey -> BlockCiphertext -> Maybe ByteString
forall bc.
BlockCipher bc =>
SecretKey bc -> Ciphertext bc -> Maybe ByteString
BlockCipher.blockCipherDecrypt
type CipherKey = Cipher.SecretKey Cipher.ChaCha20Poly1305
type CipherNonce = Cipher.Nonce Cipher.ChaCha20Poly1305
type Ciphertext = Cipher.Ciphertext Cipher.ChaCha20Poly1305
newCipherKey :: (MonadRandomIO m) => m CipherKey
newCipherKey :: forall (m :: * -> *). MonadRandomIO m => m CipherKey
newCipherKey = m CipherKey
forall alg (m :: * -> *). SecretKeyGen alg m => m (SecretKey alg)
Types.newSecretKey
newCipherNonce :: (MonadRandomIO m) => m CipherNonce
newCipherNonce :: forall (m :: * -> *). MonadRandomIO m => m CipherNonce
newCipherNonce = m CipherNonce
forall alg (m :: * -> *). NonceGen alg m => m (Nonce alg)
Types.newNonce
cipherEncrypt :: CipherKey -> CipherNonce -> ByteString -> Ciphertext
cipherEncrypt :: CipherKey -> CipherNonce -> ByteString -> Ciphertext
cipherEncrypt = CipherKey -> CipherNonce -> ByteString -> Ciphertext
forall c.
Cipher c =>
SecretKey c -> Nonce c -> ByteString -> Ciphertext c
Cipher.cipherEncrypt
cipherDecrypt :: CipherKey -> CipherNonce -> Ciphertext -> Maybe ByteString
cipherDecrypt :: CipherKey -> CipherNonce -> Ciphertext -> Maybe ByteString
cipherDecrypt = CipherKey -> CipherNonce -> Ciphertext -> Maybe ByteString
forall c.
Cipher c =>
SecretKey c -> Nonce c -> Ciphertext c -> Maybe ByteString
Cipher.cipherDecrypt