You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 21e6ba7
Browse filesBrowse the repository at this point in the historyBrowse files
-[X]`argon2`: aka Argon2 (RFC 9106) with its i, d and id variants (relies on `argon2-cffi`, e.g. with `pip install codext[argon2]`)
413
414
-[X]`bcrypt`: aka bcrypt password hash (relies on `bcrypt` when available, e.g. with `pip install codext[bcrypt]`, pure Python otherwise)
415
+
-[X]`bigcrypt`: aka BigCrypt (DES-based crypt variant for long passwords)
414
416
-[X]`blake`: includes BLAKE2b and BLAKE2s (Python 3 only ; relies on `hashlib`)
417
+
-[X]`bsd-nthash`: NT hash in the `$3$$` modular crypt format of modern BSD
418
+
-[X]`bsdi-crypt`: aka BSDi extended DES crypt (parametrized with the number of rounds)
419
+
-[X]`cisco-asa`: Cisco ASA password hash (parametrized with the user name)
420
+
-[X]`cisco-pix`: Cisco PIX password hash (parametrized with the user name)
415
421
-[X]`crypt`: Unix's crypt hash for passwords (Python 3 and Unix only ; relies on `crypt`)
422
+
-[X]`crypt16`: aka crypt16 (DES-based crypt variant with two computations)
423
+
-[X]`ctph`: context triggered piecewise hash of the ctph.js library (as used by CyberChef)
416
424
-[X]`fnv`: aka Fowler-Noll-Vo ; includes FNV-1 and FNV-1a in 32, 64, 128, 256, 512 and 1024 bits
425
+
-[X]`gosthash`: aka Streebog (GOST R 34.11-2012) in 256 and 512 bits
426
+
-[X]`hmac`: keyed-hash message authentication code with MD5, SHA-1, SHA-2, SHA-3 or BLAKE2 (relies on `hmac`)
417
427
-[X]`keccak`: original Keccak (pre-SHA-3 padding, as used e.g. by Ethereum) in 224, 256, 384 and 512 bits
428
+
-[X]`ldap-md5`: RFC 2307 LDAP password schemes ; `ldap-sha1`, `ldap-salted-md5` and `ldap-salted-sha1` for the SHA-1 and salted variants
418
429
-[X]`lm`: aka LAN Manager hash, the legacy Windows password hash (with a pure Python DES)
419
430
-[X]`md`: aka Message Digest ; includes MD2, MD4 (relies on `hashlib` when available, pure Python otherwise), MD5 (relies on `hashlib`) and MD6 (digest sizes multiple of 8, up to 512 bits)
431
+
-[X]`mscash`: aka MS-CASH / Domain Cached Credentials v1 (parametrized with the user name) ; `mscash2` for v2 (PBKDF2)
432
+
-[X]`mssql2000`: Microsoft SQL Server 2000 password hash ; `mssql2005` for the 2005 version
420
433
-[X]`mysql`: MySQL password hashes ; includes the MySQL 3.23 hash and the MySQL 4.1+ native password hash
421
434
-[X]`ntlm`: aka NT hash, the Windows password hash (MD4 of the UTF-16LE password)
435
+
-[X]`oracle10`: legacy Oracle 10g password hash (parametrized with the user name) ; `oracle11` for the 11g version
436
+
-[X]`phpass`: portable PHP password hash (parametrized with the iteration count ; used e.g. by WordPress)
422
437
-[X]`ripemd160`: aka RIPEMD-160 (relies on `hashlib` when available, pure Python otherwise)
423
438
-[X]`sha`: aka Secure Hash Algorithms ; includes SHA0, SHA1, 224, 256, 384, 512 (Python2/3) but also SHA3-224, -256, -384 and -512 (Python 3 only ; relies on `hashlib`)
424
439
-[X]`shake`: aka SHAKE hashing (Python 3 only ; relies on `hashlib`)
425
440
-[X]`snefru`: aka Snefru (Merkle's hash function) in 32 to 480 bits, with 2 to 8 passes
441
+
-[X]`ssdeep`: ssdeep fuzzy hash (context triggered piecewise hash, same output as libfuzzy)
442
+
-[X]`sun-md5-crypt`: aka Sun MD5 crypt (parametrized with the number of rounds)
426
443
-[X]`whirlpool`: aka Whirlpool (relies on `hashlib` when available, pure Python otherwise)
427
444
428
445
> :warning: Hash functions are of course definitely **NOT** encoding functions ; they are implemented for convenience with the `.encode(...)` API from `codecs` and useful for chaning codecs.
Copy file name to clipboardExpand all lines: docs/pages/enc/hashing.md
+181Lines changed: 181 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,21 @@
2
2
3
3
-----
4
4
5
+
### Argon2
6
+
7
+
These one-way transformation functions compute the Argon2 password hash ([RFC 9106](https://datatracker.ietf.org/doc/html/rfc9106)), the memory-hard winner of the Password Hashing Competition, with its three variants (Argon2d, Argon2i and the default Argon2id). A random salt is generated each time. It relies on the [`argon2-cffi`](https://pypi.org/project/argon2-cffi/) package (`pip install codext[argon2]`) and is not available without it.
`argon2` | data --> Argon2(data) | `argon2i`, `argon2d`, `argon2id` | parametrized with the variant ; random salt
12
+
13
+
```python
14
+
>>> codext.encode("test", "argon2i")[:24]
15
+
'$argon2i$v=19$m=65536,t'
16
+
```
17
+
18
+
-----
19
+
5
20
### Bcrypt
6
21
7
22
This one-way transformation function is the password hash based on the Blowfish cipher, written in the modular crypt format (`$2b$<cost>$<salt><digest>`). A random salt is generated each time, hence the output differs between calls. It relies on the [`bcrypt`](https://pypi.org/project/bcrypt/) package when it is installed (`pip install codext[bcrypt]`), and on a pure Python implementation otherwise, which is much slower (a cost of 12 takes about 40 seconds).
@@ -70,6 +85,22 @@ These one-way transformation functions are mostly computed with a generic CRC.
70
85
71
86
-----
72
87
88
+
### Cisco PIX/ASA
89
+
90
+
These one-way transformation functions compute the password hashes of the Cisco PIX and ASA firewalls: the MD5 digest of the password (optionally salted with the user name), with every fourth byte dropped, written with the `./0-9A-Za-z` alphabet. The user name, when there is one, is given with the codec name.
`cisco-pix` | data --> PIX(data, user) | `cisco-pix-admin`, ... | parametrized with the user name (optional)
95
+
`cisco-asa` | data --> ASA(data, user) | `cisco-asa-admin`, ... | parametrized with the user name (optional)
96
+
97
+
```python
98
+
>>> codext.encode("password", "cisco-asa")
99
+
'NuLKvvWGg.x9HEKO'
100
+
```
101
+
102
+
-----
103
+
73
104
### Crypt
74
105
75
106
This one-way transformation function relies on the native [`crypt`](https://docs.python.org/3/library/crypt.html) library.
@@ -89,6 +120,43 @@ This one-way transformation function relies on the native [`crypt`](https://docs
89
120
90
121
-----
91
122
123
+
### Crypt Variants
124
+
125
+
These one-way transformation functions compute the traditional crypt(3) password hash variants not provided by the `crypt` module (hence available on every platform): `bigcrypt` and `crypt16` (DES-based, for long passwords), `bsdi-crypt` (the extended DES scheme of BSDi, with a configurable number of rounds), `bsd-nthash` (the NT hash in the `$3$$` modular crypt format) and `sun-md5-crypt` (the MD5-based scheme of Solaris). A random salt is generated each time (except for `bsd-nthash`).
`bigcrypt` | data --> bigcrypt(data) | | random salt
130
+
`crypt16` | data --> crypt16(data) | `crypt-16` | random salt
131
+
`bsdi-crypt` | data --> BSDi(data, rounds) | `bsdi-crypt-5001`, ... | parametrized with the rounds (default: 5001)
132
+
`bsd-nthash` | data --> NT(data) | `bsd-nt` |
133
+
`sun-md5-crypt` | data --> SunMD5(data, rounds) | `sun-md5-crypt-5000`, ... | parametrized with the rounds (default: 34000)
134
+
135
+
```python
136
+
>>> codext.encode("password", "bsd-nthash")
137
+
'$3$$8846f7eaee8fb117ad06bdd830b7586c'
138
+
```
139
+
140
+
-----
141
+
142
+
### CTPH
143
+
144
+
These one-way transformation functions compute context triggered piecewise hashes (aka fuzzy hashes), for which similar inputs give similar hashes: the data is split where a rolling hash of the last 7 bytes hits a trigger value depending on a block size, and each piece gives one Base64 character. `ssdeep` gives the hash of [ssdeep](https://ssdeep-project.github.io/ssdeep/) (`blocksize:hash1:hash2`), while `ctph` gives the variant of the [ctph.js](https://github.com/huwenshuo/ctph.js) library used by CyberChef's "CTPH" operation (larger minimum block size, hashes not truncated and block size written as the Base64 character of its exponent).
`ssdeep` | data --> ssdeep(data) | | same output as libfuzzy
149
+
`ctph` | data --> CTPH(data) | | same output as ctph.js
150
+
151
+
```python
152
+
>>> codext.encode("This is a test string !", "ssdeep")
153
+
'3:hMCEpFZnn:hurJn'
154
+
>>> codext.encode("This is a test string !", "ctph")
155
+
'A:4NUFkERB:4BMR'
156
+
```
157
+
158
+
-----
159
+
92
160
### Fowler-Noll-Vo
93
161
94
162
These one-way transformation functions are non-cryptographic hashes, used e.g. in hash tables.
@@ -109,6 +177,38 @@ These one-way transformation functions are non-cryptographic hashes, used e.g. i
109
177
110
178
-----
111
179
180
+
### GOST Hash (Streebog)
181
+
182
+
This one-way transformation function is the hash function of the Russian standard GOST R 34.11-2012 ([RFC 6986](https://datatracker.ietf.org/doc/html/rfc6986)), aka Streebog, with 256-bit and 512-bit digests. The digest is written in the byte order of the usual implementations (e.g. CyberChef's), which is the reverse of the order of the examples of RFC 6986.
This one-way transformation function computes keyed-hash message authentication codes ([RFC 2104](https://datatracker.ietf.org/doc/html/rfc2104)) with the hash functions guaranteed by `hashlib` (MD5, SHA-1, SHA-2, SHA-3 and BLAKE2). The hash function and the key (as text, possibly empty) are given in the codec name.
This one-way transformation function is the original Keccak, as submitted to the SHA-3 competition: it only differs from SHA-3 by the padding of the data (e.g. Ethereum uses Keccak-256).
@@ -126,6 +226,24 @@ This one-way transformation function is the original Keccak, as submitted to the
126
226
127
227
-----
128
228
229
+
### LDAP
230
+
231
+
These one-way transformation functions compute the RFC 2307 password schemes used by LDAP directories: a scheme name followed by the Base64 digest of the password, the salted variants (`{SMD5}` and `{SSHA}`) appending a random salt.
@@ -150,6 +268,38 @@ This one-way transformation function is the original Keccak, as submitted to the
150
268
151
269
-----
152
270
271
+
### MS-CASH
272
+
273
+
These one-way transformation functions compute the Windows domain cached credentials (Domain Cached Credentials): MS-CASHv1 (the MD4 digest of the NT hash and the lowercased user name) and MS-CASHv2 (PBKDF2-HMAC-SHA1 over it). The user name (the salt) is given with the codec name.
These one-way transformation functions compute the Microsoft SQL Server password hashes: `0x0100`, a 4-byte random salt and the SHA-1 digest of the salted password (encoded in UTF-16LE). The 2000 version appends a second digest of the uppercased password ; the 2005 version drops it.
`mssql2000` | data --> MSSQL2000(data) | `mssql-2000` | random salt
294
+
`mssql2005` | data --> MSSQL2005(data) | `mssql-2005` | random salt
295
+
296
+
```python
297
+
>>> codext.encode("test", "mssql2005")[:14]
298
+
'0x0100'# + salt and digest in hexadecimal
299
+
```
300
+
301
+
-----
302
+
153
303
### MySQL
154
304
155
305
These one-way transformation functions compute the password hashes of MySQL: the custom 64-bit hash of MySQL 3.23 (spaces and tabs being ignored) and the native password hash of MySQL 4.1 and later (SHA-1 of the binary SHA-1 digest).
@@ -168,6 +318,37 @@ These one-way transformation functions compute the password hashes of MySQL: the
168
318
169
319
-----
170
320
321
+
### Oracle
322
+
323
+
These one-way transformation functions compute the Oracle database password hashes: the legacy 10g hash (DES-CBC of the uppercased user name and password) and the 11g hash (`S:`, the SHA-1 digest of the password and a random 10-byte salt). The user name of the 10g hash (the salt) is given with the codec name.
`oracle10` | data --> Oracle10g(data, user) | `oracle-10g-SYSTEM`, ... | parametrized with the user name
328
+
`oracle11` | data --> Oracle11g(data) | `oracle-11g` | random salt
329
+
330
+
```python
331
+
>>> codext.encode("password", "oracle10-SYSTEM")
332
+
'EED9B65CCECDB2E9'
333
+
```
334
+
335
+
-----
336
+
337
+
### PHPass
338
+
339
+
These one-way transformation functions compute the portable PHP password hash (used e.g. by WordPress): `$P$`, an iteration count and an 8-character random salt, followed by the iterated MD5 digest. The iteration count (a power of 2, from 7 to 30) is given with the codec name (default: 13).
`phpass` | data --> PHPass(data) | `phpass-13`, `phpass_20`, ... | parametrized ; random salt
344
+
345
+
```python
346
+
>>> codext.encode("password", "phpass")[:3]
347
+
'$P$'
348
+
```
349
+
350
+
-----
351
+
171
352
### RIPEMD
172
353
173
354
This one-way transformation function, used e.g. in Bitcoin addresses, relies on [`hashlib`](https://docs.python.org/3/library/hashlib.html) when it provides it, and on a pure Python implementation otherwise (OpenSSL 3 only provides it in its legacy provider).
0 commit comments