pbkdf 1.1.0.1 → 1.1.1.0
raw patch · 4 files changed
+99/−27 lines, 4 files
Files
- Crypto/PBKDF.hs +1/−3
- Crypto/PBKDF/ByteString.hs +60/−0
- Crypto/PBKDF/Core.hs +34/−21
- pbkdf.cabal +4/−3
Crypto/PBKDF.hs view
@@ -36,9 +36,7 @@ -- RFC-2898 (<http://www.ietf.org/rfc/rfc2898.txt>), based on the SHA-1, -- SHA-256 and SHA-256 hash functions. Each function takes the password and -- salt as a string and returns a hex string. To work with ByteStrings--- and provide your own hash function use the 'Crypto.PBKDF.Core.pbkdf1'--- and 'Crypto.PBKDF.Core.pbkdf2' functions on which these functions are--- based.+-- see Crypto.PBKDF.ByteString. sha1PBKDF1, sha256PBKDF1, sha512PBKDF1
+ Crypto/PBKDF/ByteString.hs view
@@ -0,0 +1,60 @@+{-# LANGUAGE BangPatterns #-}+{-# LANGUAGE RecordWildCards #-}++module Crypto.PBKDF.ByteString+ ( + + -- + -- * Password Based Key Derivation Functions+ --+ -- $summary++ -- + -- * SHA-based PBKDF1 functions+ --++ sha1PBKDF1+ , sha256PBKDF1+ , sha512PBKDF1++ --+ -- * SHA-based PBKDF2 functions+ --++ , sha1PBKDF2+ , sha256PBKDF2+ , sha512PBKDF2+ ) where++import Crypto.PBKDF.Core+import qualified Data.ByteString as BS+++-- $summary+--+-- This module provides stock implementations of the PBKDF functions from+-- RFC-2898 (<http://www.ietf.org/rfc/rfc2898.txt>), based on the SHA-1,+-- SHA-256 and SHA-256 hash functions. Each function takes the password and+-- salt as a ByteString and returns the Hash as a ByteString.+++sha1PBKDF1, sha256PBKDF1, sha512PBKDF1 + :: BS.ByteString -- ^ the password + -> BS.ByteString -- ^ the salt+ -> Int -- ^ the iteration count+ -> BS.ByteString -- ^ the result key+sha1PBKDF1 pw_s na_s c = pbkdf1 $ sha1PBKDF' pw_s na_s c 0+sha256PBKDF1 pw_s na_s c = pbkdf1 $ sha256PBKDF' pw_s na_s c 0+sha512PBKDF1 pw_s na_s c = pbkdf1 $ sha512PBKDF' pw_s na_s c 0+++sha1PBKDF2, sha256PBKDF2, sha512PBKDF2+ :: BS.ByteString -- ^ the password + -> BS.ByteString -- ^ the salt+ -> Int -- ^ the iteration count+ -> Int -- ^ the length of the key to be generated (in octets)+ -> BS.ByteString -- ^ the result key++sha1PBKDF2 pw_s na_s c dkLen = pbkdf2 $ sha1PBKDF' pw_s na_s c dkLen+sha256PBKDF2 pw_s na_s c dkLen = pbkdf2 $ sha256PBKDF' pw_s na_s c dkLen+sha512PBKDF2 pw_s na_s c dkLen = pbkdf2 $ sha512PBKDF' pw_s na_s c dkLen
Crypto/PBKDF/Core.hs view
@@ -3,8 +3,11 @@ module Crypto.PBKDF.Core ( sha1PBKDF+ , sha1PBKDF' , sha256PBKDF+ , sha256PBKDF' , sha512PBKDF+ , sha512PBKDF' , pbkdf , PBKDF(..) , PRF(..)@@ -22,11 +25,16 @@ import Data.Byteable --- | SHA-1 generator+-- | make a SHA-1 parameter blocks (String edition) sha1PBKDF :: String -> String -> Int -> Int -> PBKDF-sha1PBKDF =- pbkdf+sha1PBKDF pw na = sha1PBKDF' (BU.fromString pw) (BU.fromString na)++-- | make a SHA-1 parameter blocks (ByteString edition)++sha1PBKDF' :: BS.ByteString -> BS.ByteString -> Int -> Int -> PBKDF+sha1PBKDF' =+ PBKDF PRF { prf_hmac = hmac sha1 64 -- 512-bit block , prf_hash = sha1 -- SHA-1@@ -35,11 +43,16 @@ where sha1 = toBytes . (CH.hash :: BS.ByteString -> CH.Digest CH.SHA1) --- | SHA-256 generator+-- | make a SHA-256 parameter blocks (String edition) sha256PBKDF :: String -> String -> Int -> Int -> PBKDF-sha256PBKDF =- pbkdf+sha256PBKDF pw na = sha256PBKDF' (BU.fromString pw) (BU.fromString na)++-- | make a SHA-256 parameter blocks (ByteString edition)++sha256PBKDF' :: BS.ByteString -> BS.ByteString -> Int -> Int -> PBKDF+sha256PBKDF' =+ PBKDF PRF { prf_hmac = hmac sha256 64 -- 512-bit block , prf_hash = sha256 -- SHA-256@@ -48,11 +61,16 @@ where sha256 = toBytes . (CH.hash :: BS.ByteString -> CH.Digest CH.SHA256) --- | SHA-512 generator+-- | make a SHA-512 parameter blocks (String edition) sha512PBKDF :: String -> String -> Int -> Int -> PBKDF-sha512PBKDF =- pbkdf+sha512PBKDF pw na = sha512PBKDF' (BU.fromString pw) (BU.fromString na)++-- | make a SHA-512 parameter blocks (ByteString edition)++sha512PBKDF' :: BS.ByteString -> BS.ByteString -> Int -> Int -> PBKDF+sha512PBKDF' =+ PBKDF PRF { prf_hmac = hmac sha512 128 -- 1024-bit block , prf_hash = sha512 -- SHA-512@@ -61,19 +79,13 @@ where sha512 = toBytes . (CH.hash :: BS.ByteString -> CH.Digest CH.SHA512) --- | construct a PBKDF generator from a HMAC function+-- | construct a PBKDF parameter block for the key generators (String edition) pbkdf :: PRF -> String -> String -> Int -> Int -> PBKDF pbkdf prf pw_s na_s c dkLen =- PBKDF- { pbkdf_PRF = prf- , pbkdf_P = BU.fromString pw_s- , pbkdf_S = BU.fromString na_s- , pbkdf_c = c- , pbkdf_dkLen = dkLen- }+ PBKDF prf (BU.fromString pw_s) (BU.fromString na_s) c dkLen --- | PBKDF generator parameters+-- | the parameter block for the key generators data PBKDF = PBKDF@@ -84,7 +96,8 @@ , pbkdf_dkLen :: Int -- ^ the length of the o/p derived key } --- | the HMAC function and its underlying HASH function+-- | contains the HMAC function and its underlying HASH function, along with+-- the size of the hashes it generates data PRF = PRF@@ -94,14 +107,14 @@ } --- | the pbkdf1_ core function+-- | the pbkdf1 key derivation function pbkdf1 :: PBKDF -> BS.ByteString pbkdf1 PBKDF{..} = iterate_n pbkdf_c prf_hash $ pbkdf_P `BS.append` pbkdf_S where PRF{..} = pbkdf_PRF --- | the pbkdf2_ core function+-- | the pbkdf2 key derivation function pbkdf2 :: PBKDF -> BS.ByteString pbkdf2 PBKDF{..} = BS.take pbkdf_dkLen $ BS.concat $ map f $ zip zbs ivs
pbkdf.cabal view
@@ -1,8 +1,9 @@ Name: pbkdf-Version: 1.1.0.1+Version: 1.1.1.0 Synopsis: Haskell implementation of the PBKDF functions from RFC-2898. Description: The Password Based Key Derivation Functions described in RFC-2898 with a test suite to verify that it works with the test vectors published in RFC6070. Homepage: https://github.com/cdornan/pbkdf+Bug-reports: https://github.com/cdornan/pbkdf/issues License: BSD3 License-file: LICENSE Author: Chris Dornan@@ -10,13 +11,12 @@ Copyright: (C) Chris Dornan Category: Cryptography Build-type: Simple- Cabal-version: >=1.14 Source-repository this type: git location: https://github.com/cdornan/pbkdf.git- tag: 1.1.0.1+ tag: 1.1.1.0 Source-repository head type: git@@ -25,6 +25,7 @@ Library Exposed-modules: Crypto.PBKDF+ Crypto.PBKDF.ByteString Crypto.PBKDF.Core Build-depends: