| Copyright | (c) Joseph Abrahamson 2013 |
|---|---|
| License | MIT |
| Maintainer | me@jspha.com |
| Stability | experimental |
| Portability | non-portable |
| Safe Haskell | None |
| Language | Haskell2010 |
Crypto.Saltine.Core.Hash
Contents
Description
The hash function hashes a message ByteString and returns a
hash. Hashes are always of length hash. The shorthash
function hashes a message ByteString with respect to a secret key
and returns a very short hash. Short hashes are always of length
shorthash.
The hash function is designed to be usable as a strong component
of DSA, RSA-PSS, key derivation, hash-based message-authentication
codes, hash-based ciphers, and various other common
applications. Strong means that the security of these
applications, when instantiated with hash, is the same as the
security of the applications against generic attacks. In
particular, the hash function is designed to make finding
collisions difficult.
hash is currently an implementation of SHA-512. shorthash is
currently an implementation of SipHash-2-4
(https://131002.net/siphash/).
There has been considerable degradation of public confidence in the security conjectures for many hash functions, including SHA-512. However, for the moment, there do not appear to be alternatives that inspire satisfactory levels of confidence. One can hope that NIST's SHA-3 competition will improve the situation.
Sodium includes an implementation of the Blake2b hash function
(https://blake2.net/) and is bound here as the generichash
function.
This is version 2010.08.30 of the hash.html web page. Information about SipHash has been added.
Synopsis
- data ShorthashKey
- hash :: ByteString -> ByteString
- shorthash :: ShorthashKey -> ByteString -> ByteString
- newShorthashKey :: IO ShorthashKey
- data GenerichashKey
- newGenerichashKey :: Int -> IO (Maybe GenerichashKey)
- data GenerichashOutLen
- generichashOutLen :: Int -> Maybe GenerichashOutLen
- generichash :: GenerichashKey -> ByteString -> GenerichashOutLen -> ByteString
- sha256 :: ByteString -> ByteString
Documentation
data ShorthashKey Source #
An opaque shorthash cryptographic secret key.
Instances
Arguments
| :: ByteString | Message |
| -> ByteString | Hash |
Computes a cryptographically collision-resistant hash making
hash m == hash m' ==> m == m' highly likely even when under
attack.
Arguments
| :: ShorthashKey | |
| -> ByteString | Message |
| -> ByteString | Hash |
Computes a very short, fast keyed hash. This function is defined here to break circulat module imports
newShorthashKey :: IO ShorthashKey Source #
Randomly generates a new key for shorthash.
data GenerichashKey Source #
An opaque generichash cryptographic secret key.
Instances
| NFData GenerichashKey Source # | |||||
Defined in Crypto.Saltine.Internal.Hash Methods rnf :: GenerichashKey -> () # | |||||
| Data GenerichashKey Source # | |||||
Defined in Crypto.Saltine.Internal.Hash Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> GenerichashKey -> c GenerichashKey # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c GenerichashKey # toConstr :: GenerichashKey -> Constr # dataTypeOf :: GenerichashKey -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c GenerichashKey) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c GenerichashKey) # gmapT :: (forall b. Data b => b -> b) -> GenerichashKey -> GenerichashKey # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> GenerichashKey -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> GenerichashKey -> r # gmapQ :: (forall d. Data d => d -> u) -> GenerichashKey -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> GenerichashKey -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> GenerichashKey -> m GenerichashKey # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> GenerichashKey -> m GenerichashKey # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> GenerichashKey -> m GenerichashKey # | |||||
| Generic GenerichashKey Source # | |||||
Defined in Crypto.Saltine.Internal.Hash Associated Types
Methods from :: GenerichashKey -> Rep GenerichashKey x # to :: Rep GenerichashKey x -> GenerichashKey # | |||||
| Show GenerichashKey Source # | |||||
Defined in Crypto.Saltine.Internal.Hash Methods showsPrec :: Int -> GenerichashKey -> ShowS # show :: GenerichashKey -> String # showList :: [GenerichashKey] -> ShowS # | |||||
| Eq GenerichashKey Source # | |||||
Defined in Crypto.Saltine.Internal.Hash Methods (==) :: GenerichashKey -> GenerichashKey -> Bool # (/=) :: GenerichashKey -> GenerichashKey -> Bool # | |||||
| Ord GenerichashKey Source # | |||||
Defined in Crypto.Saltine.Internal.Hash Methods compare :: GenerichashKey -> GenerichashKey -> Ordering # (<) :: GenerichashKey -> GenerichashKey -> Bool # (<=) :: GenerichashKey -> GenerichashKey -> Bool # (>) :: GenerichashKey -> GenerichashKey -> Bool # (>=) :: GenerichashKey -> GenerichashKey -> Bool # max :: GenerichashKey -> GenerichashKey -> GenerichashKey # min :: GenerichashKey -> GenerichashKey -> GenerichashKey # | |||||
| Hashable GenerichashKey Source # | |||||
Defined in Crypto.Saltine.Internal.Hash | |||||
| IsEncoding GenerichashKey Source # | |||||
Defined in Crypto.Saltine.Internal.Hash Methods encode :: GenerichashKey -> ByteString Source # decode :: ByteString -> Maybe GenerichashKey Source # encoded :: (Choice p, Applicative f) => p GenerichashKey (f GenerichashKey) -> p ByteString (f ByteString) Source # | |||||
| type Rep GenerichashKey Source # | |||||
Defined in Crypto.Saltine.Internal.Hash type Rep GenerichashKey = D1 ('MetaData "GenerichashKey" "Crypto.Saltine.Internal.Hash" "saltine-0.2.2.0-inplace" 'True) (C1 ('MetaCons "GhK" 'PrefixI 'True) (S1 ('MetaSel ('Just "unGhK") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ByteString))) | |||||
newGenerichashKey :: Int -> IO (Maybe GenerichashKey) Source #
Randomly generates a new key for generichash of the given length.
data GenerichashOutLen Source #
Instances
| NFData GenerichashOutLen Source # | |||||
Defined in Crypto.Saltine.Internal.Hash Methods rnf :: GenerichashOutLen -> () # | |||||
| Data GenerichashOutLen Source # | |||||
Defined in Crypto.Saltine.Internal.Hash Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> GenerichashOutLen -> c GenerichashOutLen # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c GenerichashOutLen # toConstr :: GenerichashOutLen -> Constr # dataTypeOf :: GenerichashOutLen -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c GenerichashOutLen) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c GenerichashOutLen) # gmapT :: (forall b. Data b => b -> b) -> GenerichashOutLen -> GenerichashOutLen # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> GenerichashOutLen -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> GenerichashOutLen -> r # gmapQ :: (forall d. Data d => d -> u) -> GenerichashOutLen -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> GenerichashOutLen -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> GenerichashOutLen -> m GenerichashOutLen # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> GenerichashOutLen -> m GenerichashOutLen # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> GenerichashOutLen -> m GenerichashOutLen # | |||||
| Generic GenerichashOutLen Source # | |||||
Defined in Crypto.Saltine.Internal.Hash Associated Types
Methods from :: GenerichashOutLen -> Rep GenerichashOutLen x # to :: Rep GenerichashOutLen x -> GenerichashOutLen # | |||||
| Eq GenerichashOutLen Source # | |||||
Defined in Crypto.Saltine.Internal.Hash Methods (==) :: GenerichashOutLen -> GenerichashOutLen -> Bool # (/=) :: GenerichashOutLen -> GenerichashOutLen -> Bool # | |||||
| Ord GenerichashOutLen Source # | |||||
Defined in Crypto.Saltine.Internal.Hash Methods compare :: GenerichashOutLen -> GenerichashOutLen -> Ordering # (<) :: GenerichashOutLen -> GenerichashOutLen -> Bool # (<=) :: GenerichashOutLen -> GenerichashOutLen -> Bool # (>) :: GenerichashOutLen -> GenerichashOutLen -> Bool # (>=) :: GenerichashOutLen -> GenerichashOutLen -> Bool # max :: GenerichashOutLen -> GenerichashOutLen -> GenerichashOutLen # min :: GenerichashOutLen -> GenerichashOutLen -> GenerichashOutLen # | |||||
| Hashable GenerichashOutLen Source # | |||||
Defined in Crypto.Saltine.Internal.Hash | |||||
| type Rep GenerichashOutLen Source # | |||||
Defined in Crypto.Saltine.Internal.Hash type Rep GenerichashOutLen = D1 ('MetaData "GenerichashOutLen" "Crypto.Saltine.Internal.Hash" "saltine-0.2.2.0-inplace" 'True) (C1 ('MetaCons "GhOL" 'PrefixI 'True) (S1 ('MetaSel ('Just "unGhOL") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Int))) | |||||
generichashOutLen :: Int -> Maybe GenerichashOutLen Source #
Create a validated Generichash output length
Arguments
| :: GenerichashKey | |
| -> ByteString | Message |
| -> GenerichashOutLen | Desired output hash length |
| -> ByteString | Hash |
Computes a generic, keyed hash.
Advanced: SHA-2
The SHA-256 function is provided for interoperability with
other applications. If you are looking for a generic hash
function and not specifically SHA-2, using generichash
(BLAKE2b) might be a better choice.
sha256 :: ByteString -> ByteString Source #
Computes a SHA256 hash.