annotate MoinMoin/support/passlib/utils/md4.py @ 6096:86a41c2bedec

upgrade passlib from 1.6.2 to 1.6.5
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 05 Sep 2016 23:44:04 +0200
parents efd7c0be3339
children 7f0616feeae9
rev   line source
5919
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1 """
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
2 helper implementing insecure and obsolete md4 algorithm.
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
3 used for NTHASH format, which is also insecure and broken,
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
4 since it's just md4(password)
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
5
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
6 implementated based on rfc at http://www.faqs.org/rfcs/rfc1320.html
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
7
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
8 """
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
9
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
10 #=============================================================================
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
11 # imports
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
12 #=============================================================================
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
13 # core
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
14 from binascii import hexlify
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
15 import struct
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
16 from warnings import warn
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
17 # site
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
18 from passlib.utils.compat import b, bytes, bascii_to_str, irange, PY3
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
19 # local
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
20 __all__ = [ "md4" ]
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
21 #=============================================================================
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
22 # utils
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
23 #=============================================================================
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
24 def F(x,y,z):
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
25 return (x&y) | ((~x) & z)
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
26
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
27 def G(x,y,z):
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
28 return (x&y) | (x&z) | (y&z)
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
29
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
30 ##def H(x,y,z):
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
31 ## return x ^ y ^ z
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
32
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
33 MASK_32 = 2**32-1
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
34
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
35 #=============================================================================
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
36 # main class
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
37 #=============================================================================
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
38 class md4(object):
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
39 """pep-247 compatible implementation of MD4 hash algorithm
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
40
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
41 .. attribute:: digest_size
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
42
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
43 size of md4 digest in bytes (16 bytes)
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
44
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
45 .. method:: update
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
46
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
47 update digest by appending additional content
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
48
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
49 .. method:: copy
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
50
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
51 create clone of digest object, including current state
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
52
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
53 .. method:: digest
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
54
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
55 return bytes representing md4 digest of current content
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
56
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
57 .. method:: hexdigest
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
58
6096
86a41c2bedec upgrade passlib from 1.6.2 to 1.6.5
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5919
diff changeset
59 return hexadecimal version of digest
5919
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
60 """
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
61 # FIXME: make this follow hash object PEP better.
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
62 # FIXME: this isn't threadsafe
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
63 # XXX: should we monkeypatch ourselves into hashlib for general use? probably wouldn't be nice.
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
64
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
65 name = "md4"
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
66 digest_size = digestsize = 16
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
67
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
68 _count = 0 # number of 64-byte blocks processed so far (not including _buf)
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
69 _state = None # list of [a,b,c,d] 32 bit ints used as internal register
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
70 _buf = None # data processed in 64 byte blocks, this holds leftover from last update
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
71
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
72 def __init__(self, content=None):
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
73 self._count = 0
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
74 self._state = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476]
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
75 self._buf = b('')
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
76 if content:
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
77 self.update(content)
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
78
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
79 # round 1 table - [abcd k s]
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
80 _round1 = [
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
81 [0,1,2,3, 0,3],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
82 [3,0,1,2, 1,7],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
83 [2,3,0,1, 2,11],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
84 [1,2,3,0, 3,19],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
85
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
86 [0,1,2,3, 4,3],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
87 [3,0,1,2, 5,7],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
88 [2,3,0,1, 6,11],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
89 [1,2,3,0, 7,19],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
90
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
91 [0,1,2,3, 8,3],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
92 [3,0,1,2, 9,7],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
93 [2,3,0,1, 10,11],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
94 [1,2,3,0, 11,19],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
95
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
96 [0,1,2,3, 12,3],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
97 [3,0,1,2, 13,7],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
98 [2,3,0,1, 14,11],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
99 [1,2,3,0, 15,19],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
100 ]
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
101
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
102 # round 2 table - [abcd k s]
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
103 _round2 = [
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
104 [0,1,2,3, 0,3],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
105 [3,0,1,2, 4,5],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
106 [2,3,0,1, 8,9],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
107 [1,2,3,0, 12,13],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
108
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
109 [0,1,2,3, 1,3],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
110 [3,0,1,2, 5,5],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
111 [2,3,0,1, 9,9],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
112 [1,2,3,0, 13,13],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
113
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
114 [0,1,2,3, 2,3],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
115 [3,0,1,2, 6,5],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
116 [2,3,0,1, 10,9],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
117 [1,2,3,0, 14,13],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
118
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
119 [0,1,2,3, 3,3],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
120 [3,0,1,2, 7,5],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
121 [2,3,0,1, 11,9],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
122 [1,2,3,0, 15,13],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
123 ]
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
124
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
125 # round 3 table - [abcd k s]
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
126 _round3 = [
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
127 [0,1,2,3, 0,3],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
128 [3,0,1,2, 8,9],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
129 [2,3,0,1, 4,11],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
130 [1,2,3,0, 12,15],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
131
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
132 [0,1,2,3, 2,3],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
133 [3,0,1,2, 10,9],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
134 [2,3,0,1, 6,11],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
135 [1,2,3,0, 14,15],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
136
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
137 [0,1,2,3, 1,3],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
138 [3,0,1,2, 9,9],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
139 [2,3,0,1, 5,11],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
140 [1,2,3,0, 13,15],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
141
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
142 [0,1,2,3, 3,3],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
143 [3,0,1,2, 11,9],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
144 [2,3,0,1, 7,11],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
145 [1,2,3,0, 15,15],
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
146 ]
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
147
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
148 def _process(self, block):
6096
86a41c2bedec upgrade passlib from 1.6.2 to 1.6.5
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5919
diff changeset
149 """process 64 byte block"""
5919
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
150 # unpack block into 16 32-bit ints
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
151 X = struct.unpack("<16I", block)
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
152
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
153 # clone state
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
154 orig = self._state
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
155 state = list(orig)
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
156
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
157 # round 1 - F function - (x&y)|(~x & z)
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
158 for a,b,c,d,k,s in self._round1:
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
159 t = (state[a] + F(state[b],state[c],state[d]) + X[k]) & MASK_32
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
160 state[a] = ((t<<s) & MASK_32) + (t>>(32-s))
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
161
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
162 # round 2 - G function
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
163 for a,b,c,d,k,s in self._round2:
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
164 t = (state[a] + G(state[b],state[c],state[d]) + X[k] + 0x5a827999) & MASK_32
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
165 state[a] = ((t<<s) & MASK_32) + (t>>(32-s))
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
166
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
167 # round 3 - H function - x ^ y ^ z
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
168 for a,b,c,d,k,s in self._round3:
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
169 t = (state[a] + (state[b] ^ state[c] ^ state[d]) + X[k] + 0x6ed9eba1) & MASK_32
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
170 state[a] = ((t<<s) & MASK_32) + (t>>(32-s))
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
171
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
172 # add back into original state
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
173 for i in irange(4):
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
174 orig[i] = (orig[i]+state[i]) & MASK_32
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
175
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
176 def update(self, content):
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
177 if not isinstance(content, bytes):
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
178 raise TypeError("expected bytes")
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
179 buf = self._buf
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
180 if buf:
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
181 content = buf + content
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
182 idx = 0
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
183 end = len(content)
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
184 while True:
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
185 next = idx + 64
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
186 if next <= end:
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
187 self._process(content[idx:next])
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
188 self._count += 1
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
189 idx = next
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
190 else:
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
191 self._buf = content[idx:]
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
192 return
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
193
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
194 def copy(self):
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
195 other = _builtin_md4()
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
196 other._count = self._count
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
197 other._state = list(self._state)
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
198 other._buf = self._buf
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
199 return other
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
200
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
201 def digest(self):
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
202 # NOTE: backing up state so we can restore it after _process is called,
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
203 # in case object is updated again (this is only attr altered by this method)
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
204 orig = list(self._state)
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
205
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
206 # final block: buf + 0x80,
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
207 # then 0x00 padding until congruent w/ 56 mod 64 bytes
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
208 # then last 8 bytes = msg length in bits
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
209 buf = self._buf
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
210 msglen = self._count*512 + len(buf)*8
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
211 block = buf + b('\x80') + b('\x00') * ((119-len(buf)) % 64) + \
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
212 struct.pack("<2I", msglen & MASK_32, (msglen>>32) & MASK_32)
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
213 if len(block) == 128:
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
214 self._process(block[:64])
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
215 self._process(block[64:])
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
216 else:
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
217 assert len(block) == 64
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
218 self._process(block)
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
219
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
220 # render digest & restore un-finalized state
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
221 out = struct.pack("<4I", *self._state)
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
222 self._state = orig
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
223 return out
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
224
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
225 def hexdigest(self):
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
226 return bascii_to_str(hexlify(self.digest()))
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
227
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
228 #===================================================================
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
229 # eoc
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
230 #===================================================================
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
231
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
232 # keep ref around for unittest, 'md4' usually replaced by ssl wrapper, below.
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
233 _builtin_md4 = md4
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
234
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
235 #=============================================================================
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
236 # check if hashlib provides accelarated md4
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
237 #=============================================================================
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
238 import hashlib
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
239 from passlib.utils import PYPY
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
240
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
241 def _has_native_md4(): # pragma: no cover -- runtime detection
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
242 try:
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
243 h = hashlib.new("md4")
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
244 except ValueError:
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
245 # not supported - ssl probably missing (e.g. ironpython)
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
246 return False
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
247 result = h.hexdigest()
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
248 if result == '31d6cfe0d16ae931b73c59d7e0c089c0':
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
249 return True
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
250 if PYPY and result == '':
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
251 # workaround for https://bugs.pypy.org/issue957, fixed in PyPy 1.8
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
252 return False
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
253 # anything else and we should alert user
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
254 from passlib.exc import PasslibRuntimeWarning
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
255 warn("native md4 support disabled, sanity check failed!", PasslibRuntimeWarning)
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
256 return False
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
257
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
258 if _has_native_md4():
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
259 # overwrite md4 class w/ hashlib wrapper
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
260 def md4(content=None):
6096
86a41c2bedec upgrade passlib from 1.6.2 to 1.6.5
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5919
diff changeset
261 """wrapper for hashlib.new('md4')"""
5919
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
262 return hashlib.new('md4', content or b(''))
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
263
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
264 #=============================================================================
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
265 # eof
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
266 #=============================================================================