2 from CryptoPlus
.Hash
import SHA
as SHA1
, HMAC
6 def new(passphrase
, salt
, iterations
=1000, digestmodule
=SHA1
, macmodule
=HMAC
):
7 """PKCS#5 v2.0 Password-Based Key Derivation
9 passphrase = the passphrase, supplied as a raw string, to make a key from
10 salt = salt as raw string
11 iterations = amount of iterations (default = 1000)
12 digestmodule = digest function to use, supply as module
13 example: python_SHA from CryptoPlus.Hash
15 macmodule = mac function to use, supply as module
16 example: HMAC from CryptoPlus.Hash
19 => macmodule & digestmodule construct the pseudorandom function
20 => by default: HMAC-SHA1
22 Examples: (from: http://www.ietf.org/rfc/rfc3962.txt)
25 >>> from CryptoPlus.Hash import python_PBKDF2
27 >>> passphrase = "password"
28 >>> salt = "ATHENA.MIT.EDUraeburn"
30 >>> hasher = python_PBKDF2.new(passphrase,salt,iterations)
31 >>> hasher.hexread(16)
32 'cdedb5281bb2f801565a1122b2563515'
34 >>> passphrase = "password"
35 >>> salt = "ATHENA.MIT.EDUraeburn"
37 >>> hasher = python_PBKDF2.new(passphrase,salt,iterations)
38 >>> hasher.hexread(32)
39 '5c08eb61fdf71e4e4ec3cf6ba1f5512ba7e52ddbc5e5142f708a31e2e62b1e13'
41 >>> passphrase = "X"*64
42 >>> salt = "pass phrase equals block size"
44 >>> hasher = python_PBKDF2.new(passphrase,salt,iterations)
45 >>> hasher.hexread(32)
46 '139c30c0966bc32ba55fdbf212530ac9c5ec59f1a452f5cc9ad940fea0598ed1'
48 >>> passphrase = "X"*65
49 >>> salt = "pass phrase exceeds block size"
51 >>> hasher = python_PBKDF2.new(passphrase,salt,iterations)
52 >>> hasher.hexread(32)
53 '9ccad6d468770cd51b10e6a68721be611a8b4d282601db3b36be9246915ec82a'
55 return pypbkdf2
.PBKDF2(passphrase
, salt
, iterations
, digestmodule
, macmodule
)