ppad-sha512-0.2.1: The SHA-512 and HMAC-SHA512 algorithms
Copyright(c) 2024 Jared Tobin
LicenseMIT
MaintainerJared Tobin <jared@ppad.tech>
Safe HaskellNone
LanguageHaskell2010

Crypto.Hash.SHA512

Description

SHA-512 and HMAC-SHA512 implementations for strict and lazy ByteStrings, as specified by RFC's 6234 and 2104.

The hash and hmac functions will use primitive instructions from the ARM cryptographic extensions via FFI if they're available, and will otherwise use a pure Haskell implementation.

Synopsis

SHA-512 message digest functions

hash :: ByteString -> ByteString Source #

Compute a condensed representation of a strict bytestring via SHA-512.

The 512-bit output digest is returned as a strict bytestring.

>>> hash "strict bytestring input"
"<strict 512-bit message digest>"

hash_lazy :: ByteString -> ByteString Source #

Compute a condensed representation of a lazy bytestring via SHA-512.

The 512-bit output digest is returned as a strict bytestring.

>>> hash_lazy "lazy bytestring input"
"<strict 512-bit message digest>"

SHA512-based MAC functions

newtype MAC Source #

A message authentication code.

Note that you should compare MACs for equality using the Eq instance, which performs the comparison in constant time, instead of unwrapping and comparing the underlying ByteStrings.

>>> let foo@(MAC bs0) = hmac key "hi"
>>> let bar@(MAC bs1) = hmac key "there"
>>> foo == bar -- do this
False
>>> bs0 == bs1 -- don't do this
False

Constructors

MAC ByteString 

Instances

Instances details
Show MAC Source # 
Instance details

Defined in Crypto.Hash.SHA512.Internal

Methods

showsPrec :: Int -> MAC -> ShowS #

show :: MAC -> String #

showList :: [MAC] -> ShowS #

Eq MAC Source # 
Instance details

Defined in Crypto.Hash.SHA512.Internal

Methods

(==) :: MAC -> MAC -> Bool #

(/=) :: MAC -> MAC -> Bool #

hmac Source #

Arguments

:: ByteString

key

-> ByteString

text

-> MAC 

Produce a message authentication code for a strict bytestring, based on the provided (strict, bytestring) key, via SHA-512.

The 512-bit MAC is returned as a strict bytestring.

Per RFC 2104, the key should be a minimum of 64 bytes long. Keys exceeding 128 bytes in length will first be hashed (via SHA-512).

>>> hmac "strict bytestring key" "strict bytestring input"
"<strict 512-bit MAC>"

hmac_lazy Source #

Arguments

:: ByteString

key

-> ByteString

text

-> MAC 

Produce a message authentication code for a lazy bytestring, based on the provided (strict, bytestring) key, via SHA-512.

The 512-bit MAC is returned as a strict bytestring.

Per RFC 2104, the key should be a minimum of 64 bytes long. Keys exceeding 128 bytes in length will first be hashed (via SHA-512).

>>> hmac_lazy "strict bytestring key" "lazy bytestring input"
"<strict 512-bit MAC>"