diff -up ./django/utils/crypto.py.orig ./django/utils/crypto.py
old
|
new
|
def bin_to_long(x):
|
75 | 75 | return long(x.encode('hex'), 16) |
76 | 76 | |
77 | 77 | |
78 | | def long_to_bin(x): |
| 78 | def long_to_bin(x, length=0): |
79 | 79 | """ |
80 | 80 | Convert a long integer into a binary string |
81 | 81 | """ |
82 | 82 | hex = "%x" % (x) |
83 | 83 | if len(hex) % 2 == 1: |
84 | 84 | hex = '0' + hex |
85 | | return binascii.unhexlify(hex) |
| 85 | bin = binascii.unhexlify(hex) |
| 86 | return chr(0)*(length-len(bin)) + bin |
86 | 87 | |
87 | 88 | |
88 | 89 | def fast_hmac(key, msg, digest): |
… |
… |
def pbkdf2(password, salt, iterations, d
|
129 | 130 | for j in xrange(int(iterations)): |
130 | 131 | u = fast_hmac(password, u, digest).digest() |
131 | 132 | yield bin_to_long(u) |
132 | | return long_to_bin(reduce(operator.xor, U())) |
| 133 | return long_to_bin(reduce(operator.xor, U()), hlen) |
133 | 134 | |
134 | 135 | T = [F(x) for x in range(1, l + 1)] |
135 | 136 | return ''.join(T[:-1]) + T[-1][:r] |