module Botan.Hash.Whirlpool
( Whirlpool(..)
, WhirlpoolDigest(..)
, whirlpool
, whirlpoolLazy
) where

import qualified Data.ByteString as ByteString
import qualified Data.ByteString.Lazy as Lazy
import qualified Data.Text as Text

import qualified Botan.Hash as Botan
import qualified Botan.Utility as Botan

import Botan.Hash.Class
import Botan.Prelude

-- Whirlpool type

data Whirlpool

newtype instance Digest Whirlpool = WhirlpoolDigest
    { Digest Whirlpool -> ByteString
getWhirlpoolByteString :: ByteString {- ByteVector n -} }
    deriving newtype (Digest Whirlpool -> Digest Whirlpool -> Bool
(Digest Whirlpool -> Digest Whirlpool -> Bool)
-> (Digest Whirlpool -> Digest Whirlpool -> Bool)
-> Eq (Digest Whirlpool)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Digest Whirlpool -> Digest Whirlpool -> Bool
== :: Digest Whirlpool -> Digest Whirlpool -> Bool
$c/= :: Digest Whirlpool -> Digest Whirlpool -> Bool
/= :: Digest Whirlpool -> Digest Whirlpool -> Bool
Eq, Eq (Digest Whirlpool)
Eq (Digest Whirlpool) =>
(Digest Whirlpool -> Digest Whirlpool -> Ordering)
-> (Digest Whirlpool -> Digest Whirlpool -> Bool)
-> (Digest Whirlpool -> Digest Whirlpool -> Bool)
-> (Digest Whirlpool -> Digest Whirlpool -> Bool)
-> (Digest Whirlpool -> Digest Whirlpool -> Bool)
-> (Digest Whirlpool -> Digest Whirlpool -> Digest Whirlpool)
-> (Digest Whirlpool -> Digest Whirlpool -> Digest Whirlpool)
-> Ord (Digest Whirlpool)
Digest Whirlpool -> Digest Whirlpool -> Bool
Digest Whirlpool -> Digest Whirlpool -> Ordering
Digest Whirlpool -> Digest Whirlpool -> Digest Whirlpool
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Digest Whirlpool -> Digest Whirlpool -> Ordering
compare :: Digest Whirlpool -> Digest Whirlpool -> Ordering
$c< :: Digest Whirlpool -> Digest Whirlpool -> Bool
< :: Digest Whirlpool -> Digest Whirlpool -> Bool
$c<= :: Digest Whirlpool -> Digest Whirlpool -> Bool
<= :: Digest Whirlpool -> Digest Whirlpool -> Bool
$c> :: Digest Whirlpool -> Digest Whirlpool -> Bool
> :: Digest Whirlpool -> Digest Whirlpool -> Bool
$c>= :: Digest Whirlpool -> Digest Whirlpool -> Bool
>= :: Digest Whirlpool -> Digest Whirlpool -> Bool
$cmax :: Digest Whirlpool -> Digest Whirlpool -> Digest Whirlpool
max :: Digest Whirlpool -> Digest Whirlpool -> Digest Whirlpool
$cmin :: Digest Whirlpool -> Digest Whirlpool -> Digest Whirlpool
min :: Digest Whirlpool -> Digest Whirlpool -> Digest Whirlpool
Ord)

type WhirlpoolDigest = Digest Whirlpool

instance Show (Digest Whirlpool) where
    show :: Digest Whirlpool -> String
    show :: Digest Whirlpool -> String
show (WhirlpoolDigest ByteString
bytes) = Text -> String
Text.unpack (Text -> String) -> Text -> String
forall a b. (a -> b) -> a -> b
$ ByteString -> HexCase -> Text
Botan.hexEncode ByteString
bytes HexCase
Botan.Lower

instance Hash Whirlpool where
    hash :: ByteString -> Digest Whirlpool
    hash :: ByteString -> Digest Whirlpool
hash = ByteString -> Digest Whirlpool
WhirlpoolDigest (ByteString -> Digest Whirlpool)
-> (ByteString -> ByteString) -> ByteString -> Digest Whirlpool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Hash -> ByteString -> ByteString
Botan.hash Hash
Botan.whirlpool

instance IncrementalHash Whirlpool where
    hashLazy :: Lazy.ByteString -> Digest Whirlpool
    hashLazy :: ByteString -> Digest Whirlpool
hashLazy = ByteString -> Digest Whirlpool
WhirlpoolDigest (ByteString -> Digest Whirlpool)
-> (ByteString -> ByteString) -> ByteString -> Digest Whirlpool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Hash -> ByteString -> ByteString
Botan.hashLazy Hash
Botan.whirlpool

-- Whirlpool hash

whirlpool :: ByteString -> WhirlpoolDigest
whirlpool :: ByteString -> Digest Whirlpool
whirlpool = ByteString -> Digest Whirlpool
forall hash. Hash hash => ByteString -> Digest hash
hash

whirlpoolLazy :: Lazy.ByteString -> WhirlpoolDigest
whirlpoolLazy :: ByteString -> Digest Whirlpool
whirlpoolLazy = ByteString -> Digest Whirlpool
forall hash. IncrementalHash hash => ByteString -> Digest hash
hashLazy