Maintainer | The Haskell Cryptography Group |
---|---|
Portability | GHC only |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Synopsis
- authenticate :: StrictByteString -> AuthenticationKey -> IO AuthenticationTag
- verify :: AuthenticationTag -> AuthenticationKey -> StrictByteString -> Bool
- data AuthenticationKey
- newAuthenticationKey :: IO AuthenticationKey
- authenticationKeyFromHexByteString :: StrictByteString -> Either Text AuthenticationKey
- unsafeAuthenticationKeyToHexByteString :: AuthenticationKey -> StrictByteString
- data AuthenticationTag
- authenticationTagToHexByteString :: AuthenticationTag -> StrictByteString
- authenticationTagFromHexByteString :: StrictByteString -> Either Text AuthenticationTag
Introduction
The authenticate
function computes an authentication tag for a message and a secret key,
and provides a way to verify that a given tag is valid for a given message and a key.
The function computing the tag deterministic: the same (message, key)
tuple will always
produce the same output. However, even if the message is public, knowing the key is required
in order to be able to compute a valid tag.
Therefore, the key should remain confidential. The tag, however, can be public.
Usage
import Sel.SecretKey.Authentication qualified as Auth main = do -- The parties agree on a shared secret key authKey <- Auth.newAuthenticationKey -- An authentication tag is computed for the message by the server let message = "Hello, world!" tag <- Auth.authenticate message -- The server sends the message and its authentication tag -- […] -- The recipient of the message uses the shared secret to validate the message's tag Auth.verify tag authKey message -- => True
Operations
:: StrictByteString | Message to authenticate |
-> AuthenticationKey | Secret key for authentication |
-> IO AuthenticationTag | Cryptographic tag for authentication |
Compute an authentication tag for a message with a secret key shared by all parties.
Since: 0.0.1.0
verify :: AuthenticationTag -> AuthenticationKey -> StrictByteString -> Bool Source #
Verify that the tag is valid for the provided message and secret key.
Since: 0.0.1.0
Authentication key
data AuthenticationKey Source #
A secret authentication key of size cryptoAuthKeyBytes
.
Since: 0.0.1.0
Instances
newAuthenticationKey :: IO AuthenticationKey Source #
Generate a new random secret key.
Since: 0.0.1.0
authenticationKeyFromHexByteString :: StrictByteString -> Either Text AuthenticationKey Source #
Create an AuthenticationKey
from a binary StrictByteString
that you have obtained on your own,
usually from the network or disk.
The input secret key, once decoded from base16, must be of length
cryptoAuthKeyBytes
.
Since: 0.0.1.0
unsafeAuthenticationKeyToHexByteString :: AuthenticationKey -> StrictByteString Source #
Convert a 'AuthenticationKey to a hexadecimal-encoded StrictByteString
.
⚠️ Be prudent as to where you store it!
Since: 0.0.1.0
Authentication tag
data AuthenticationTag Source #
A secret authentication key of size cryptoAuthBytes
.
Since: 0.0.1.0
Instances
authenticationTagToHexByteString :: AuthenticationTag -> StrictByteString Source #
Convert an AuthenticationTag
to a hexadecimal-encoded StrictByteString
.
Since: 0.0.1.0
authenticationTagFromHexByteString :: StrictByteString -> Either Text AuthenticationTag Source #
Create an AuthenticationTag
from a binary StrictByteString
that you have obtained on your own,
usually from the network or disk.
The input secret key, once decoded from base16, must be of length
cryptoAuthBytes
.
Since: 0.0.1.0