Add API to generate a random nonce
This AEAD scheme is compatible with choosing the nonce randomly.
This commit is contained in:
parent
29f0fd1b7a
commit
3ae08ed509
@ -21,6 +21,7 @@
|
|||||||
module Crypto.Cipher.AESGCMSIV
|
module Crypto.Cipher.AESGCMSIV
|
||||||
( Nonce
|
( Nonce
|
||||||
, nonce
|
, nonce
|
||||||
|
, generateNonce
|
||||||
, encrypt
|
, encrypt
|
||||||
, decrypt
|
, decrypt
|
||||||
) where
|
) where
|
||||||
@ -42,6 +43,7 @@ import Crypto.Cipher.AES.Primitive
|
|||||||
import Crypto.Cipher.Types
|
import Crypto.Cipher.Types
|
||||||
import Crypto.Error
|
import Crypto.Error
|
||||||
import Crypto.Internal.Compat (unsafeDoIO)
|
import Crypto.Internal.Compat (unsafeDoIO)
|
||||||
|
import Crypto.Random
|
||||||
|
|
||||||
|
|
||||||
-- 12-byte nonces
|
-- 12-byte nonces
|
||||||
@ -55,6 +57,10 @@ nonce iv
|
|||||||
| B.length iv == 12 = CryptoPassed (Nonce $ B.convert iv)
|
| B.length iv == 12 = CryptoPassed (Nonce $ B.convert iv)
|
||||||
| otherwise = CryptoFailed CryptoError_IvSizeInvalid
|
| otherwise = CryptoFailed CryptoError_IvSizeInvalid
|
||||||
|
|
||||||
|
-- | Generate a random nonce for use with AES-GCM-SIV.
|
||||||
|
generateNonce :: MonadRandom m => m Nonce
|
||||||
|
generateNonce = Nonce <$> getRandomBytes 12
|
||||||
|
|
||||||
|
|
||||||
-- POLYVAL (mutable context)
|
-- POLYVAL (mutable context)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user