packages feed

crypton 2.3.0 → 2.3.1

raw patch · API changes only · 31 files changed · hide whitespace changes · browse crypton-2.3.1

+519/−83 lines, 31 filesPVP ok

API changes (from Hackage documentation)

No changes to the public API.

version bump matches the API change (PVP)

Files

CHANGELOG.md view
@@ -1,5 +1,12 @@ # CHANGELOG for crypton +## 2.3.1++* Hash: unsafe calls for updates of at most 4 KiB+  [#395](https://github.com/kazu-yamamoto/crypton/pull/395)+* RFC 6979: HMAC_DRBG in C for SHA-2+  [#396](https://github.com/kazu-yamamoto/crypton/pull/396)+ ## 2.3.0  **Breaking changes.**  `Salsa.State` no longer exports its constructor
Crypto/Hash/Blake2.hs view
@@ -99,8 +99,15 @@     c_blake2s_init :: Ptr (Context a) -> Word32 -> IO () foreign import ccall unsafe "crypton_blake2s_init_key"     c_blake2s_init_key :: Ptr (Context a) -> Word32 -> Ptr Word8 -> Word32 -> IO ()++c_blake2s_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+c_blake2s_update = updateBySize c_blake2s_update_unsafe c_blake2s_update_safe++foreign import ccall unsafe "crypton_blake2s_update"+    c_blake2s_update_unsafe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+ foreign import ccall "crypton_blake2s_update"-    c_blake2s_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+    c_blake2s_update_safe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO () foreign import ccall unsafe "crypton_blake2s_finalize"     c_blake2s_finalize :: Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO () @@ -152,8 +159,15 @@     c_blake2b_init :: Ptr (Context a) -> Word32 -> IO () foreign import ccall unsafe "crypton_blake2b_init_key"     c_blake2b_init_key :: Ptr (Context a) -> Word32 -> Ptr Word8 -> Word32 -> IO ()++c_blake2b_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+c_blake2b_update = updateBySize c_blake2b_update_unsafe c_blake2b_update_safe++foreign import ccall unsafe "crypton_blake2b_update"+    c_blake2b_update_unsafe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+ foreign import ccall "crypton_blake2b_update"-    c_blake2b_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+    c_blake2b_update_safe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO () foreign import ccall unsafe "crypton_blake2b_finalize"     c_blake2b_finalize :: Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO () @@ -196,8 +210,15 @@     c_blake2sp_init :: Ptr (Context a) -> Word32 -> IO () foreign import ccall unsafe "crypton_blake2sp_init_key"     c_blake2sp_init_key :: Ptr (Context a) -> Word32 -> Ptr Word8 -> Word32 -> IO ()++c_blake2sp_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+c_blake2sp_update = updateBySize c_blake2sp_update_unsafe c_blake2sp_update_safe++foreign import ccall unsafe "crypton_blake2sp_update"+    c_blake2sp_update_unsafe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+ foreign import ccall "crypton_blake2sp_update"-    c_blake2sp_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+    c_blake2sp_update_safe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO () foreign import ccall unsafe "crypton_blake2sp_finalize"     c_blake2sp_finalize :: Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO () @@ -240,7 +261,14 @@     c_blake2bp_init :: Ptr (Context a) -> Word32 -> IO () foreign import ccall unsafe "crypton_blake2bp_init_key"     c_blake2bp_init_key :: Ptr (Context a) -> Word32 -> Ptr Word8 -> Word32 -> IO ()++c_blake2bp_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+c_blake2bp_update = updateBySize c_blake2bp_update_unsafe c_blake2bp_update_safe++foreign import ccall unsafe "crypton_blake2bp_update"+    c_blake2bp_update_unsafe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+ foreign import ccall "crypton_blake2bp_update"-    c_blake2bp_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+    c_blake2bp_update_safe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO () foreign import ccall unsafe "crypton_blake2bp_finalize"     c_blake2bp_finalize :: Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO ()
Crypto/Hash/Blake2b.hs view
@@ -103,8 +103,14 @@ foreign import ccall unsafe "crypton_blake2b_init"     c_blake2b_init :: Ptr (Context a) -> Word32 -> IO () +c_blake2b_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+c_blake2b_update = updateBySize c_blake2b_update_unsafe c_blake2b_update_safe++foreign import ccall unsafe "crypton_blake2b_update"+    c_blake2b_update_unsafe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+ foreign import ccall "crypton_blake2b_update"-    c_blake2b_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+    c_blake2b_update_safe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()  foreign import ccall unsafe "crypton_blake2b_finalize"     c_blake2b_finalize :: Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO ()
Crypto/Hash/Blake2bp.hs view
@@ -39,8 +39,14 @@ foreign import ccall unsafe "crypton_blake2bp_init"     c_blake2bp_init :: Ptr (Context a) -> Word32 -> IO () +c_blake2bp_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+c_blake2bp_update = updateBySize c_blake2bp_update_unsafe c_blake2bp_update_safe++foreign import ccall unsafe "crypton_blake2bp_update"+    c_blake2bp_update_unsafe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+ foreign import ccall "crypton_blake2bp_update"-    c_blake2bp_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+    c_blake2bp_update_safe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()  foreign import ccall unsafe "crypton_blake2bp_finalize"     c_blake2bp_finalize :: Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO ()
Crypto/Hash/Blake2s.hs view
@@ -71,8 +71,14 @@ foreign import ccall unsafe "crypton_blake2s_init"     c_blake2s_init :: Ptr (Context a) -> Word32 -> IO () +c_blake2s_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+c_blake2s_update = updateBySize c_blake2s_update_unsafe c_blake2s_update_safe++foreign import ccall unsafe "crypton_blake2s_update"+    c_blake2s_update_unsafe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+ foreign import ccall "crypton_blake2s_update"-    c_blake2s_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+    c_blake2s_update_safe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()  foreign import ccall unsafe "crypton_blake2s_finalize"     c_blake2s_finalize :: Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO ()
Crypto/Hash/Blake2sp.hs view
@@ -55,8 +55,14 @@ foreign import ccall unsafe "crypton_blake2sp_init"     c_blake2sp_init :: Ptr (Context a) -> Word32 -> IO () +c_blake2sp_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+c_blake2sp_update = updateBySize c_blake2sp_update_unsafe c_blake2sp_update_safe++foreign import ccall unsafe "crypton_blake2sp_update"+    c_blake2sp_update_unsafe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+ foreign import ccall "crypton_blake2sp_update"-    c_blake2sp_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+    c_blake2sp_update_safe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()  foreign import ccall unsafe "crypton_blake2sp_finalize"     c_blake2sp_finalize :: Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO ()
Crypto/Hash/IO.hs view
@@ -11,7 +11,18 @@ -- -- Generalized impure cryptographic hash interface module Crypto.Hash.IO (-    HashAlgorithm (..),+    -- hashInternalRfc6979 stays internal+    HashAlgorithm (+        HashBlockSize,+        HashDigestSize,+        HashInternalContextSize,+        hashBlockSize,+        hashDigestSize,+        hashInternalContextSize,+        hashInternalInit,+        hashInternalUpdate,+        hashInternalFinalize+    ),     MutableContext,     hashMutableInit,     hashMutableInitWith,
Crypto/Hash/Keccak.hs view
@@ -87,8 +87,14 @@ foreign import ccall unsafe "crypton_keccak_init"     c_keccak_init :: Ptr (Context a) -> Word32 -> IO () +c_keccak_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+c_keccak_update = updateBySize c_keccak_update_unsafe c_keccak_update_safe++foreign import ccall unsafe "crypton_keccak_update"+    c_keccak_update_unsafe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+ foreign import ccall "crypton_keccak_update"-    c_keccak_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+    c_keccak_update_safe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()  foreign import ccall unsafe "crypton_keccak_finalize"     c_keccak_finalize :: Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO ()
Crypto/Hash/MD2.hs view
@@ -37,8 +37,14 @@ foreign import ccall unsafe "crypton_md2_init"     c_md2_init :: Ptr (Context a) -> IO () +c_md2_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+c_md2_update = updateBySize c_md2_update_unsafe c_md2_update_safe++foreign import ccall unsafe "crypton_md2_update"+    c_md2_update_unsafe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+ foreign import ccall "crypton_md2_update"-    c_md2_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+    c_md2_update_safe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()  foreign import ccall unsafe "crypton_md2_finalize"     c_md2_finalize :: Ptr (Context a) -> Ptr (Digest a) -> IO ()
Crypto/Hash/MD4.hs view
@@ -37,8 +37,14 @@ foreign import ccall unsafe "crypton_md4_init"     c_md4_init :: Ptr (Context a) -> IO () +c_md4_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+c_md4_update = updateBySize c_md4_update_unsafe c_md4_update_safe++foreign import ccall unsafe "crypton_md4_update"+    c_md4_update_unsafe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+ foreign import ccall "crypton_md4_update"-    c_md4_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+    c_md4_update_safe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()  foreign import ccall unsafe "crypton_md4_finalize"     c_md4_finalize :: Ptr (Context a) -> Ptr (Digest a) -> IO ()
Crypto/Hash/MD5.hs view
@@ -40,8 +40,14 @@ foreign import ccall unsafe "crypton_md5_init"     c_md5_init :: Ptr (Context a) -> IO () +c_md5_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+c_md5_update = updateBySize c_md5_update_unsafe c_md5_update_safe++foreign import ccall unsafe "crypton_md5_update"+    c_md5_update_unsafe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+ foreign import ccall "crypton_md5_update"-    c_md5_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+    c_md5_update_safe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()  foreign import ccall unsafe "crypton_md5_finalize"     c_md5_finalize :: Ptr (Context a) -> Ptr (Digest a) -> IO ()
Crypto/Hash/RIPEMD160.hs view
@@ -37,8 +37,14 @@ foreign import ccall unsafe "crypton_ripemd160_init"     c_ripemd160_init :: Ptr (Context a) -> IO () +c_ripemd160_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+c_ripemd160_update = updateBySize c_ripemd160_update_unsafe c_ripemd160_update_safe++foreign import ccall unsafe "crypton_ripemd160_update"+    c_ripemd160_update_unsafe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+ foreign import ccall "crypton_ripemd160_update"-    c_ripemd160_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+    c_ripemd160_update_safe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()  foreign import ccall unsafe "crypton_ripemd160_finalize"     c_ripemd160_finalize :: Ptr (Context a) -> Ptr (Digest a) -> IO ()
Crypto/Hash/SHA1.hs view
@@ -40,8 +40,14 @@ foreign import ccall unsafe "crypton_sha1_init"     c_sha1_init :: Ptr (Context a) -> IO () +c_sha1_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+c_sha1_update = updateBySize c_sha1_update_unsafe c_sha1_update_safe++foreign import ccall unsafe "crypton_sha1_update"+    c_sha1_update_unsafe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+ foreign import ccall "crypton_sha1_update"-    c_sha1_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+    c_sha1_update_safe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()  foreign import ccall unsafe "crypton_sha1_finalize"     c_sha1_finalize :: Ptr (Context a) -> Ptr (Digest a) -> IO ()
Crypto/Hash/SHA224.hs view
@@ -33,6 +33,7 @@     hashInternalInit = c_sha224_init     hashInternalUpdate = c_sha224_update     hashInternalFinalize = c_sha224_finalize+    hashInternalRfc6979 _ = 1  instance HashAlgorithmPrefix SHA224 where     hashInternalFinalizePrefix = c_sha224_finalize_prefix@@ -40,8 +41,14 @@ foreign import ccall unsafe "crypton_sha224_init"     c_sha224_init :: Ptr (Context a) -> IO () +c_sha224_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+c_sha224_update = updateBySize c_sha224_update_unsafe c_sha224_update_safe++foreign import ccall unsafe "crypton_sha224_update"+    c_sha224_update_unsafe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+ foreign import ccall "crypton_sha224_update"-    c_sha224_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+    c_sha224_update_safe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()  foreign import ccall unsafe "crypton_sha224_finalize"     c_sha224_finalize :: Ptr (Context a) -> Ptr (Digest a) -> IO ()
Crypto/Hash/SHA256.hs view
@@ -33,6 +33,7 @@     hashInternalInit = c_sha256_init     hashInternalUpdate = c_sha256_update     hashInternalFinalize = c_sha256_finalize+    hashInternalRfc6979 _ = 2  instance HashAlgorithmPrefix SHA256 where     hashInternalFinalizePrefix = c_sha256_finalize_prefix@@ -40,8 +41,14 @@ foreign import ccall unsafe "crypton_sha256_init"     c_sha256_init :: Ptr (Context a) -> IO () +c_sha256_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+c_sha256_update = updateBySize c_sha256_update_unsafe c_sha256_update_safe++foreign import ccall unsafe "crypton_sha256_update"+    c_sha256_update_unsafe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+ foreign import ccall "crypton_sha256_update"-    c_sha256_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+    c_sha256_update_safe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()  foreign import ccall unsafe "crypton_sha256_finalize"     c_sha256_finalize :: Ptr (Context a) -> Ptr (Digest a) -> IO ()
Crypto/Hash/SHA3.hs view
@@ -87,8 +87,14 @@ foreign import ccall unsafe "crypton_sha3_init"     c_sha3_init :: Ptr (Context a) -> Word32 -> IO () +c_sha3_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+c_sha3_update = updateBySize c_sha3_update_unsafe c_sha3_update_safe++foreign import ccall unsafe "crypton_sha3_update"+    c_sha3_update_unsafe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+ foreign import ccall "crypton_sha3_update"-    c_sha3_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+    c_sha3_update_safe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()  foreign import ccall unsafe "crypton_sha3_finalize"     c_sha3_finalize :: Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO ()
Crypto/Hash/SHA384.hs view
@@ -33,6 +33,7 @@     hashInternalInit = c_sha384_init     hashInternalUpdate = c_sha384_update     hashInternalFinalize = c_sha384_finalize+    hashInternalRfc6979 _ = 3  instance HashAlgorithmPrefix SHA384 where     hashInternalFinalizePrefix = c_sha384_finalize_prefix@@ -40,8 +41,14 @@ foreign import ccall unsafe "crypton_sha384_init"     c_sha384_init :: Ptr (Context a) -> IO () +c_sha384_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+c_sha384_update = updateBySize c_sha384_update_unsafe c_sha384_update_safe++foreign import ccall unsafe "crypton_sha384_update"+    c_sha384_update_unsafe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+ foreign import ccall "crypton_sha384_update"-    c_sha384_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+    c_sha384_update_safe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()  foreign import ccall unsafe "crypton_sha384_finalize"     c_sha384_finalize :: Ptr (Context a) -> Ptr (Digest a) -> IO ()
Crypto/Hash/SHA512.hs view
@@ -33,6 +33,7 @@     hashInternalInit = c_sha512_init     hashInternalUpdate = c_sha512_update     hashInternalFinalize = c_sha512_finalize+    hashInternalRfc6979 _ = 4  instance HashAlgorithmPrefix SHA512 where     hashInternalFinalizePrefix = c_sha512_finalize_prefix@@ -40,8 +41,14 @@ foreign import ccall unsafe "crypton_sha512_init"     c_sha512_init :: Ptr (Context a) -> IO () +c_sha512_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+c_sha512_update = updateBySize c_sha512_update_unsafe c_sha512_update_safe++foreign import ccall unsafe "crypton_sha512_update"+    c_sha512_update_unsafe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+ foreign import ccall "crypton_sha512_update"-    c_sha512_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+    c_sha512_update_safe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()  foreign import ccall unsafe "crypton_sha512_finalize"     c_sha512_finalize :: Ptr (Context a) -> Ptr (Digest a) -> IO ()
Crypto/Hash/SHA512t.hs view
@@ -55,8 +55,14 @@ foreign import ccall unsafe "crypton_sha512t_init"     c_sha512t_init :: Ptr (Context a) -> Word32 -> IO () +c_sha512t_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+c_sha512t_update = updateBySize c_sha512t_update_unsafe c_sha512t_update_safe++foreign import ccall unsafe "crypton_sha512t_update"+    c_sha512t_update_unsafe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+ foreign import ccall "crypton_sha512t_update"-    c_sha512t_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+    c_sha512t_update_safe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()  foreign import ccall unsafe "crypton_sha512t_finalize"     c_sha512t_finalize :: Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO ()
Crypto/Hash/SHAKE.hs view
@@ -123,8 +123,14 @@ foreign import ccall unsafe "crypton_sha3_init"     c_sha3_init :: Ptr (Context a) -> Word32 -> IO () +c_sha3_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+c_sha3_update = updateBySize c_sha3_update_unsafe c_sha3_update_safe++foreign import ccall unsafe "crypton_sha3_update"+    c_sha3_update_unsafe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+ foreign import ccall "crypton_sha3_update"-    c_sha3_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+    c_sha3_update_safe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()  foreign import ccall unsafe "crypton_sha3_finalize_shake"     c_sha3_finalize_shake :: Ptr (Context a) -> IO ()
Crypto/Hash/Skein256.hs view
@@ -94,8 +94,14 @@ foreign import ccall unsafe "crypton_skein256_init"     c_skein256_init :: Ptr (Context a) -> Word32 -> IO () +c_skein256_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+c_skein256_update = updateBySize c_skein256_update_unsafe c_skein256_update_safe++foreign import ccall unsafe "crypton_skein256_update"+    c_skein256_update_unsafe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+ foreign import ccall "crypton_skein256_update"-    c_skein256_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+    c_skein256_update_safe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()  foreign import ccall unsafe "crypton_skein256_finalize"     c_skein256_finalize :: Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO ()
Crypto/Hash/Skein512.hs view
@@ -126,8 +126,14 @@ foreign import ccall unsafe "crypton_skein512_init"     c_skein512_init :: Ptr (Context a) -> Word32 -> IO () +c_skein512_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+c_skein512_update = updateBySize c_skein512_update_unsafe c_skein512_update_safe++foreign import ccall unsafe "crypton_skein512_update"+    c_skein512_update_unsafe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+ foreign import ccall "crypton_skein512_update"-    c_skein512_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+    c_skein512_update_safe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()  foreign import ccall unsafe "crypton_skein512_finalize"     c_skein512_finalize :: Ptr (Context a) -> Word32 -> Ptr (Digest a) -> IO ()
Crypto/Hash/Tiger.hs view
@@ -37,8 +37,14 @@ foreign import ccall unsafe "crypton_tiger_init"     c_tiger_init :: Ptr (Context a) -> IO () +c_tiger_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+c_tiger_update = updateBySize c_tiger_update_unsafe c_tiger_update_safe++foreign import ccall unsafe "crypton_tiger_update"+    c_tiger_update_unsafe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+ foreign import ccall "crypton_tiger_update"-    c_tiger_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+    c_tiger_update_safe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()  foreign import ccall unsafe "crypton_tiger_finalize"     c_tiger_finalize :: Ptr (Context a) -> Ptr (Digest a) -> IO ()
Crypto/Hash/Types.hs view
@@ -19,6 +19,7 @@     Context (..),     Digest (..),     updateBlocks,+    updateBySize, ) where  import Control.DeepSeq (deepseq)@@ -46,6 +47,21 @@ import Foreign.Ptr (Ptr, castPtr, plusPtr) import GHC.TypeLits (Nat) +-- | An unsafe call for an update of at most 4 KiB, which is over in+-- microseconds; a safe one above, so that a long update does not hold up+-- the capability.+updateBySize+    :: (ctx -> p -> Word32 -> IO ())+    -> (ctx -> p -> Word32 -> IO ())+    -> ctx+    -> p+    -> Word32+    -> IO ()+updateBySize short long ctx p n+    | n <= 4096 = short ctx p n+    | otherwise = long ctx p n+{-# INLINE updateBySize #-}+ -- | Feed a buffer of any length to 'hashInternalUpdate', in 2GB chunks: the -- C takes a @uint32_t@, and a longer length would be silently truncated. updateBlocks :: HashAlgorithm a => Ptr (Context a) -> Int -> Ptr Word8 -> IO ()@@ -94,6 +110,11 @@      -- | Finalize the context and set the digest raw memory to the right value     hashInternalFinalize :: Ptr (Context a) -> Ptr (Digest a) -> IO ()++    -- | Which hash the C RFC 6979 nonce generator runs as this one, 0 for+    -- none: the nonce then goes through 'hashInternalUpdate' instead.+    hashInternalRfc6979 :: a -> Int+    hashInternalRfc6979 _ = 0  -- | Hashing algorithms with a constant-time implementation. class HashAlgorithm a => HashAlgorithmPrefix a where
Crypto/Hash/Whirlpool.hs view
@@ -37,8 +37,14 @@ foreign import ccall unsafe "crypton_whirlpool_init"     c_whirlpool_init :: Ptr (Context a) -> IO () +c_whirlpool_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+c_whirlpool_update = updateBySize c_whirlpool_update_unsafe c_whirlpool_update_safe++foreign import ccall unsafe "crypton_whirlpool_update"+    c_whirlpool_update_unsafe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+ foreign import ccall "crypton_whirlpool_update"-    c_whirlpool_update :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()+    c_whirlpool_update_safe :: Ptr (Context a) -> Ptr Word8 -> Word32 -> IO ()  foreign import ccall unsafe "crypton_whirlpool_finalize"     c_whirlpool_finalize :: Ptr (Context a) -> Ptr (Digest a) -> IO ()
Crypto/PubKey/ECDSA.hs view
@@ -65,7 +65,7 @@ import Crypto.Internal.Imports import Crypto.Number.ModArithmetic (inverseSafe) import qualified Crypto.PubKey.ECC.P256 as P256-import Crypto.PubKey.Internal (getHashAlg, rfc6979Generate)+import Crypto.PubKey.Internal (getHashAlg, rfc6979GenerateBytes) import Crypto.Random.Types  import Data.Bits@@ -303,8 +303,8 @@     -> (Scalar curve -> Maybe a)     -> a nonceWith prx alg d digest extra go =-    rfc6979Generate alg (curveOrderBits prx) seed $ \k ->-        case scalarFromInteger prx k of+    rfc6979GenerateBytes alg (curveOrderBits prx) seed $ \k ->+        case decodeScalar prx k of             CryptoPassed s | scalarIsValid prx s -> go s             _ -> Nothing   where
Crypto/PubKey/Internal.hs view
@@ -14,11 +14,14 @@     getHashAlg,     rfc6979Nonce,     rfc6979Generate,+    rfc6979GenerateBytes, ) where  import Data.Bits (shiftR, xor) import qualified Data.List as L import Data.Word (Word8)+import Data.Word (Word32)+import Foreign.C.Types (CInt (..)) import Foreign.Marshal.Alloc (allocaBytes) import Foreign.Ptr (Ptr, castPtr, plusPtr) import Foreign.Storable (poke)@@ -99,6 +102,8 @@      . HashAlgorithm hash     => hash -> Int -> ScrubbedBytes -> (Integer -> Maybe a) -> a rfc6979Generate alg qlen seed go+    | hashInternalRfc6979 alg /= 0 =+        rfc6979GenerateBytes alg qlen seed (go . os2ip)     | dsize > bsize = slow     | otherwise = unsafeDoIO $         allocaBytes dsize $ \kp ->@@ -189,3 +194,35 @@     slowRun = do         k <- generatePrefix qlen         maybe slowRun pure (go k)++-- | 'rfc6979Generate' giving each candidate as its @(qlen + 7) / 8@+-- big-endian bytes.  The SHA-2 hashes run in C, with no crossing per HMAC.+rfc6979GenerateBytes+    :: HashAlgorithm hash+    => hash -> Int -> ScrubbedBytes -> (ScrubbedBytes -> Maybe a) -> a+rfc6979GenerateBytes alg qlen seed go+    | cid == 0 = rfc6979Generate alg qlen seed (go . i2ospOf_ tlen)+    | otherwise = unsafeDoIO $+        allocaBytes (fromIntegral c_rfc6979_size) $ \st ->+            B.withByteArray seed $ \sp -> do+                _ <- c_rfc6979_init st (fromIntegral cid) sp (fromIntegral (B.length seed))+                let loop = do+                        t <- B.alloc tlen $ \tp -> c_rfc6979_next st tp (fromIntegral qlen)+                        maybe loop return (go t)+                r <- loop+                c_rfc6979_wipe st+                return r+  where+    cid = hashInternalRfc6979 alg+    tlen = (qlen + 7) `div` 8++data RFC6979++foreign import ccall unsafe "crypton_rfc6979_size"+    c_rfc6979_size :: Word32+foreign import ccall unsafe "crypton_rfc6979_init"+    c_rfc6979_init :: Ptr RFC6979 -> CInt -> Ptr Word8 -> Word32 -> IO CInt+foreign import ccall unsafe "crypton_rfc6979_next"+    c_rfc6979_next :: Ptr RFC6979 -> Ptr Word8 -> Word32 -> IO ()+foreign import ccall unsafe "crypton_rfc6979_wipe"+    c_rfc6979_wipe :: Ptr RFC6979 -> IO ()
README.md view
@@ -116,7 +116,9 @@ `cabal build`, since a copy of the sources compiled by hand does not measure what a program linking the library gets, and leaves out whole implementations without saying so.  Each column of a table comes from one run on the machine-named above it.+named above it.  A public key figure is taken after a quarter of a second of+the same operation, so that a fresh process's first page faults are not+counted in it.  ### x86-64 @@ -125,33 +127,35 @@  Throughput in MB/s, **higher is better**: -| | crypton 1.1.5 | crypton 2.2.5 | OpenSSL | 2.2.5 / OpenSSL |+| | crypton 1.1.5 | crypton 2.3.1 | OpenSSL | 2.3.1 / OpenSSL | | --- | ---: | ---: | ---: | ---: |-| AES-128-GCM | 1335 | **6044** | 4046 | 1.49 |-| AES-256-GCM | 1093 | **5494** | 3764 | 1.46 |-| ChaCha20-Poly1305 | 399 | 2197 | 2212 | 0.99 |-| SHA-1 | 729 | 1663 | 1673 | 0.99 |-| SHA-256 | 289 | 1585 | 1571 | 1.01 |-| SHA-512 | 450 | 770 | 749 | 1.03 |-| SHA3-256 | 109 | 421 | 425 | 0.99 |+| AES-128-GCM | 1343 | **5928** | 4060 | 1.46 |+| AES-256-GCM | 1104 | **5443** | 3761 | 1.45 |+| ChaCha20-Poly1305 | 387 | 2197 | 2216 | 0.99 |+| SHA-1 | 722 | 1666 | 1679 | 0.99 |+| SHA-256 | 283 | 1587 | 1575 | 1.01 |+| SHA-512 | 444 | 771 | 749 | 1.03 |+| SHA3-256 | 109 | 422 | 437 | 0.97 |  Time per operation in microseconds, **lower is better**: -| | crypton 1.1.5 | crypton 2.2.5 | OpenSSL | OpenSSL / 2.2.5 |+| | crypton 1.1.5 | crypton 2.3.1 | OpenSSL | OpenSSL / 2.3.1 | | --- | ---: | ---: | ---: | ---: |-| X25519 | 44.31 | 28.56 | 36.51 | 1.28 |-| ECDH P-256 | 164.3 | 50.63 | 51.53 | 1.02 |-| ECDH P-384 | 2241 | **164.4** | 834.7 | 5.08 |-| Ed25519 sign | 29.33 | 18.57 | 33.68 | 1.81 |-| Ed25519 verify | 48.48 | 47.59 | 110.7 | 2.33 |-| ECDSA P-256 sign | 81.70 | 18.08 | 21.88 | 1.21 |-| ECDSA P-256 verify | 231.8 | 69.63 | 67.60 | 0.97 |-| ECDSA P-384 sign | 2273 | **303.9** | 877.6 | 2.89 |-| ECDSA P-384 verify | 2673 | **474.3** | 722.8 | 1.52 |-| RSA-2048 sign/decrypt | 759.5 | 633.9 | 659.4 | 1.04 |-| RSA-2048 verify/encrypt | 33.24 | 22.70 | 18.80 | 0.83 |-| RSA-3072 sign/decrypt | 2500 | 2232 | 2010 | 0.90 |-| RSA-3072 verify/encrypt | 65.79 | 61.73 | 40.09 | 0.65 |+| X25519 | 43.55 | 28.18 | 35.11 | 1.25 |+| ECDH P-256 | 164.5 | 49.92 | 51.42 | 1.03 |+| ECDH P-384 | 2208 | **161.2** | 851.1 | 5.28 |+| Ed25519 sign | 30.1 | 17.87 | 33.91 | 1.90 |+| Ed25519 verify | 49.17 | 48.83 | 115.1 | 2.36 |+| ECDSA P-256 sign | 73.83 | 15.65 | 21.41 | 1.37 |+| ECDSA P-256 sign (IO) | 88.5 | 20.42 | 21.5 | 1.05 |+| ECDSA P-256 verify | 227.9 | 66.68 | 67.13 | 1.01 |+| ECDSA P-384 sign | 2230 | **289.4** | 894.1 | 3.09 |+| ECDSA P-384 sign (IO) | 2258 | **295** | 895.3 | 3.03 |+| ECDSA P-384 verify | 2623 | **456.2** | 726.7 | 1.59 |+| RSA-2048 sign/decrypt | 755 | 620.5 | 658.5 | 1.06 |+| RSA-2048 verify/encrypt | 30.95 | 17.83 | 18.79 | 1.05 |+| RSA-3072 sign/decrypt | 2492 | 2185 | 2006 | 0.92 |+| RSA-3072 verify/encrypt | 62.98 | 41.35 | 39.98 | 0.97 |  ### AArch64 @@ -160,37 +164,39 @@  Throughput in MB/s, **higher is better**: -| | crypton 1.1.5 | crypton 2.2.5 | OpenSSL | 2.2.5 / OpenSSL |+| | crypton 1.1.5 | crypton 2.3.1 | OpenSSL | 2.3.1 / OpenSSL | | --- | ---: | ---: | ---: | ---: |-| AES-128-GCM | 134 | **12850** | 11215 | 1.15 |-| AES-256-GCM | 100 | **10356** | 9405 | 1.10 |-| ChaCha20-Poly1305 | 804 | 2425 | 2302 | 1.05 |-| SHA-1 | 1286 | 3389 | 3363 | 1.01 |-| SHA-256 | 500 | 3397 | 3363 | 1.01 |-| SHA-512 | 762 | 1881 | 1888 | 1.00 |-| SHA3-256 | 564 | 1125 | 1104 | 1.02 |+| AES-128-GCM | 133 | **12136** | 11091 | 1.09 |+| AES-256-GCM | 99 | **9864** | 9344 | 1.06 |+| ChaCha20-Poly1305 | 796 | 2388 | 2297 | 1.04 |+| SHA-1 | 1231 | 3389 | 3364 | 1.01 |+| SHA-256 | 494 | 3398 | 3372 | 1.01 |+| SHA-512 | 756 | 1880 | 1895 | 0.99 |+| SHA3-256 | 557 | 1118 | 1098 | 1.02 |  Time per operation in microseconds, **lower is better**: -| | crypton 1.1.5 | crypton 2.2.5 | OpenSSL | OpenSSL / 2.2.5 |+| | crypton 1.1.5 | crypton 2.3.1 | OpenSSL | OpenSSL / 2.3.1 | | --- | ---: | ---: | ---: | ---: |-| X25519 | 17.43 | **11.10** | 15.29 | 1.38 |-| ECDH P-256 | 63.98 | **19.70** | 24.14 | 1.23 |-| ECDH P-384 | 3181 | **68.57** | 371.6 | 5.42 |-| Ed25519 sign | 12.57 | **7.217** | 13.24 | 1.83 |-| Ed25519 verify | 17.62 | 17.75 | 34.72 | 1.96 |-| ECDSA P-256 sign | 30.53 | **6.333** | 10.46 | 1.65 |-| ECDSA P-256 verify | 91.95 | **26.52** | 31.97 | 1.21 |-| ECDSA P-384 sign | 3158 | **123.5** | 393.2 | 3.18 |-| ECDSA P-384 verify | 3790 | **200.5** | 327.0 | 1.63 |-| RSA-2048 sign/decrypt | 448.6 | 323.6 | 320.5 | 0.99 |-| RSA-2048 verify/encrypt | 18.12 | 9.683 | 8.366 | 0.86 |-| RSA-3072 sign/decrypt | 1468 | 952.9 | 925.6 | 0.97 |-| RSA-3072 verify/encrypt | 48.07 | 20.47 | 17.79 | 0.87 |+| X25519 | 17.6 | **11.88** | 15.34 | 1.29 |+| ECDH P-256 | 65.38 | **20.13** | 24.17 | 1.20 |+| ECDH P-384 | 3195 | **67.6** | 371.6 | 5.50 |+| Ed25519 sign | 13.23 | **7.783** | 13.23 | 1.70 |+| Ed25519 verify | 17.37 | 17.18 | 34.39 | 2.00 |+| ECDSA P-256 sign | 30.9 | **6.567** | 10.49 | 1.60 |+| ECDSA P-256 sign (IO) | 74.55 | **9.633** | 10.87 | 1.13 |+| ECDSA P-256 verify | 91.98 | **27.18** | 31.87 | 1.17 |+| ECDSA P-384 sign | 3223 | **121.8** | 395.3 | 3.25 |+| ECDSA P-384 sign (IO) | 3342 | **127.1** | 395.7 | 3.11 |+| ECDSA P-384 verify | 3885 | **201.8** | 331.6 | 1.64 |+| RSA-2048 sign/decrypt | 449.3 | 323.9 | 321.9 | 0.99 |+| RSA-2048 verify/encrypt | 18.2 | 9.517 | 8.376 | 0.88 |+| RSA-3072 sign/decrypt | 1478 | 960.2 | 935.5 | 0.97 |+| RSA-3072 verify/encrypt | 47.7 | 20.65 | 17.78 | 0.86 |  ### What the numbers say -There are two changes behind the 1.1.5 column and the 2.2.5 one, not a+There are two changes behind the 1.1.5 column and the 2.3.1 one, not a single steady improvement.  The first, in 2.0.0, was a rewrite: the bulk algorithms moved into C, the@@ -218,8 +224,8 @@ it is Apache-2.0 only, and Intel and CloudFlare hold copyright in it besides OpenSSL, so nobody is in a position to relicense it. -crypton is behind in a few rows now: RSA on both architectures, except-RSA-2048 signing on x86-64, and ECDSA P-256 verification on x86-64.  The+crypton is behind in a few rows now: RSA on AArch64, and RSA-3072 on+x86-64.  The AES-GCM rows were the other half of this section until 2.1.5; they are ahead on both machines now, and what the instructions do is still worth setting out. @@ -249,8 +255,9 @@ builds into itself there is compiled without optimisation ([ghc#28030](https://gitlab.haskell.org/ghc/ghc/-/work_items/28030)), which is most of what the RSA-3072 verification row on AArch64 gained.  Elsewhere GMP-keeps the sizes other than 2048 bits, and on x86-64 it is the reason the-RSA-3072 verification row is still where it was.+keeps the sizes other than 2048 bits, except on x86-64 with ADX, where the+C takes 3072 and 4096 bits as well from 2.2.6; that is what the RSA-3072+verification row there gained.  *The wide AES instructions.*  `VAES` and `VPCLMULQDQ` do two blocks where `AES-NI` and `PCLMULQDQ` do one, and four in their 512-bit form.  crypton uses@@ -260,7 +267,7 @@ BoringSSL and AWS-LC is Apache-2.0 and s2n-bignum has no GCM, so both files are crypton's own. -Having the 256-bit one is where the 1.49 in the x86-64 table comes from, and+Having the 256-bit one is where the 1.46 in the x86-64 table comes from, and it is narrower than it sounds.  The EPYC 7763 is Zen 3: VAES and VPCLMULQDQ, no AVX-512.  OpenSSL's x86-64 AES-GCM is `aesni-gcm-x86_64.pl`, which is 128-bit -- its `vaesenc`s are the VEX encoding of `AESENC` on `xmm`, and@@ -269,7 +276,7 @@ takes a block at a time where crypton takes two.  The same idea as theirs, one step further down the feature ladder; not a better one. -The 512-bit path arrived after 2.1.2, so it is in the 2.2.5 column -- but+The 512-bit path arrived after 2.1.2, so it is in the 2.3.1 column -- but neither machine in the tables above has AVX-512, so neither column shows it. On the runners that do, measured over 16 KiB in MB/s: an EPYC 9V45 (Zen 5) goes from 9616 to 14268 with it, a Xeon 6973P-C from 8095 to 9848, a Xeon@@ -290,11 +297,20 @@ written out in crypton's own intrinsics.  The AES there is ahead of OpenSSL's and always was; it was the GHASH beside it that was behind. +ECDSA signing has two rows.  `sign` is `signWith` given a nonce, the+arithmetic alone.  `sign (IO)` is `sign` run in `IO`, which is what a program+calls and what `openssl speed` measures: from 2.3.0 the nonce is RFC 6979's+with 32 bytes from the system generator added to it, and the system generator+asks the OS on every draw.  In 2.3.0 that cost about 6 microseconds on x86-64+and 3 on AArch64; 2.3.1 runs the nonce's HMAC_DRBG in C and takes back a third+of it.  A per-thread generator, through `setSystemRandomMode`, makes the draw+cheaper, and a program's own DRG, through `withDRG`, cheaper still.+ One row wants a word of its own: crypton's `Ed25519.sign` derives the public key from the secret key every time it signs, so that a caller who passes a public key that does not match cannot be made to leak the private one.  That costs a second scalar multiplication, which OpenSSL's signing does not pay ---and the row is still 1.83 on AArch64 and 1.81 on x86-64, so the safety is had+and the row is still 1.70 on AArch64 and 1.90 on x86-64, so the safety is had for nothing here rather than paid for.  Ed25519 verification wanted one too, for an unhappier reason, and 2.2.1
+ cbits/crypton_rfc6979.c view
@@ -0,0 +1,153 @@+/*+ * The HMAC_DRBG of RFC 6979 section 3.2 for SHA-224, SHA-256, SHA-384 and+ * SHA-512, kept in C so that a nonce costs its compressions and not a+ * crossing into C for each of them.+ */+#include <stdint.h>+#include <string.h>++#include "crypton_bzero.h"+#include "crypton_rfc6979.h"+#include "crypton_sha256.h"+#include "crypton_sha512.h"++static void h_init(const struct crypton_rfc6979 *st, union crypton_rfc6979_ctx *c)+{+	switch (st->alg) {+	case CRYPTON_RFC6979_SHA224: crypton_sha224_init(&c->s256); break;+	case CRYPTON_RFC6979_SHA256: crypton_sha256_init(&c->s256); break;+	case CRYPTON_RFC6979_SHA384: crypton_sha384_init(&c->s512); break;+	default: crypton_sha512_init(&c->s512); break;+	}+}++static void h_update(const struct crypton_rfc6979 *st, union crypton_rfc6979_ctx *c,+                     const uint8_t *p, uint32_t n)+{+	switch (st->alg) {+	case CRYPTON_RFC6979_SHA224: crypton_sha224_update(&c->s256, p, n); break;+	case CRYPTON_RFC6979_SHA256: crypton_sha256_update(&c->s256, p, n); break;+	case CRYPTON_RFC6979_SHA384: crypton_sha384_update(&c->s512, p, n); break;+	default: crypton_sha512_update(&c->s512, p, n); break;+	}+}++static void h_final(const struct crypton_rfc6979 *st, union crypton_rfc6979_ctx *c,+                    uint8_t *out)+{+	switch (st->alg) {+	case CRYPTON_RFC6979_SHA224: crypton_sha224_finalize(&c->s256, out); break;+	case CRYPTON_RFC6979_SHA256: crypton_sha256_finalize(&c->s256, out); break;+	case CRYPTON_RFC6979_SHA384: crypton_sha384_finalize(&c->s512, out); break;+	default: crypton_sha512_finalize(&c->s512, out); break;+	}+}++/* The ipad and opad contexts of the current K. */+static void rekey(struct crypton_rfc6979 *st)+{+	uint8_t pad[128];+	uint32_t i;++	memset(pad, 0, st->bsize);+	memcpy(pad, st->k, st->dsize);+	for (i = 0; i < st->bsize; i++)+		pad[i] ^= 0x36;+	h_init(st, &st->ictx);+	h_update(st, &st->ictx, pad, st->bsize);+	for (i = 0; i < st->bsize; i++)+		pad[i] ^= 0x36 ^ 0x5c;+	h_init(st, &st->octx);+	h_update(st, &st->octx, pad, st->bsize);+	crypton_bzero(pad, sizeof(pad));+}++/* out = HMAC_K(a || b || c); out may be K or V. */+static void mac(struct crypton_rfc6979 *st,+                const uint8_t *a, uint32_t alen,+                const uint8_t *b, uint32_t blen,+                const uint8_t *c, uint32_t clen,+                uint8_t *out)+{+	union crypton_rfc6979_ctx w;+	uint8_t inner[64];++	w = st->ictx;+	h_update(st, &w, a, alen);+	if (blen)+		h_update(st, &w, b, blen);+	if (clen)+		h_update(st, &w, c, clen);+	h_final(st, &w, inner);+	w = st->octx;+	h_update(st, &w, inner, st->dsize);+	h_final(st, &w, out);+	crypton_bzero(&w, sizeof(w));+	crypton_bzero(inner, sizeof(inner));+}++int crypton_rfc6979_init(struct crypton_rfc6979 *st, int alg,+                         const uint8_t *seed, uint32_t seedlen)+{+	static const uint8_t zero = 0x00, one = 0x01;++	switch (alg) {+	case CRYPTON_RFC6979_SHA224: st->dsize = 28; st->bsize = 64; break;+	case CRYPTON_RFC6979_SHA256: st->dsize = 32; st->bsize = 64; break;+	case CRYPTON_RFC6979_SHA384: st->dsize = 48; st->bsize = 128; break;+	case CRYPTON_RFC6979_SHA512: st->dsize = 64; st->bsize = 128; break;+	default: return -1;+	}+	st->alg = alg;+	st->started = 0;+	/* steps b to g */+	memset(st->v, 0x01, st->dsize);+	memset(st->k, 0x00, st->dsize);+	rekey(st);+	mac(st, st->v, st->dsize, &zero, 1, seed, seedlen, st->k);+	rekey(st);+	mac(st, st->v, st->dsize, NULL, 0, NULL, 0, st->v);+	mac(st, st->v, st->dsize, &one, 1, seed, seedlen, st->k);+	rekey(st);+	mac(st, st->v, st->dsize, NULL, 0, NULL, 0, st->v);+	return 0;+}++/*+ * The next candidate of step h: bits2int of qlen bits, big-endian in+ * (qlen + 7) / 8 bytes.  Every call after the first first moves past the+ * previous candidate, as step h.3 says.+ */+void crypton_rfc6979_next(struct crypton_rfc6979 *st, uint8_t *out, uint32_t qlen)+{+	static const uint8_t zero = 0x00;+	uint32_t tlen = (qlen + 7) / 8, off, n, shift, i;++	if (st->started) {+		mac(st, st->v, st->dsize, &zero, 1, NULL, 0, st->k);+		rekey(st);+		mac(st, st->v, st->dsize, NULL, 0, NULL, 0, st->v);+	}+	st->started = 1;+	for (off = 0; off < tlen; off += n) {+		mac(st, st->v, st->dsize, NULL, 0, NULL, 0, st->v);+		n = tlen - off < st->dsize ? tlen - off : st->dsize;+		memcpy(out + off, st->v, n);+	}+	shift = 8 * tlen - qlen;+	if (shift) {+		for (i = tlen; i-- > 1; )+			out[i] = (uint8_t)((out[i] >> shift) | (out[i - 1] << (8 - shift)));+		out[0] >>= shift;+	}+}++void crypton_rfc6979_wipe(struct crypton_rfc6979 *st)+{+	crypton_bzero(st, sizeof(*st));+}++uint32_t crypton_rfc6979_size(void)+{+	return sizeof(struct crypton_rfc6979);+}
+ cbits/crypton_rfc6979.h view
@@ -0,0 +1,32 @@+#ifndef CRYPTON_RFC6979_H+#define CRYPTON_RFC6979_H++#include <stdint.h>++#include "crypton_sha256.h"+#include "crypton_sha512.h"++#define CRYPTON_RFC6979_SHA224 1+#define CRYPTON_RFC6979_SHA256 2+#define CRYPTON_RFC6979_SHA384 3+#define CRYPTON_RFC6979_SHA512 4++union crypton_rfc6979_ctx {+	struct sha256_ctx s256;+	struct sha512_ctx s512;+};++struct crypton_rfc6979 {+	union crypton_rfc6979_ctx ictx, octx;+	uint8_t k[64], v[64];+	uint32_t dsize, bsize;+	int alg, started;+};++int crypton_rfc6979_init(struct crypton_rfc6979 *st, int alg,+                         const uint8_t *seed, uint32_t seedlen);+void crypton_rfc6979_next(struct crypton_rfc6979 *st, uint8_t *out, uint32_t qlen);+void crypton_rfc6979_wipe(struct crypton_rfc6979 *st);+uint32_t crypton_rfc6979_size(void);++#endif
crypton.cabal view
@@ -1,6 +1,6 @@ cabal-version:      3.0 name:               crypton-version:            2.3.0+version:            2.3.1 -- crypton's own code is BSD-3-Clause.  The parts of -- cbits/aes/gcm_fused_x86.c that follow picotls's fusion are MIT, and the -- vendored s2n-bignum assembly in cbits/s2n is taken under ISC, and the@@ -395,6 +395,7 @@         cbits/crypton_scrypt.c         cbits/crypton_sha1.c         cbits/crypton_sha256.c+        cbits/crypton_rfc6979.c         cbits/crypton_sha3.c         cbits/crypton_sha512.c         cbits/crypton_skein256.c