passlib.hash.crypt16
- Crypt16¶
Danger
This algorithm is dangerously insecure by modern standards. It is trivially broken, and should not be used if at all possible. For new code, see the list of recommended hashes.
This class implements the Crypt16 password hash, commonly
found on Ultrix and Tru64. It’s a minor modification of des_crypt
,
which allows passwords of up to 16 characters.
See also
password hash usage – for examples of how to use this class via the common hash interface.
Interface¶
-
class
passlib.hash.
crypt16
¶ This class implements the crypt16 password hash, and follows the PasswordHash API.
It supports a fixed-length salt.
The
using()
method accepts the following optional keywords:Parameters: - salt (str) – Optional salt string.
If not specified, one will be autogenerated (this is recommended).
If specified, it must be 2 characters, drawn from the regexp range
[./0-9A-Za-z]
. - truncate_error (bool) –
By default, crypt16 will silently truncate passwords larger than 16 bytes. Setting
truncate_error=True
will causehash()
to raise aPasswordTruncateError
instead.New in version 1.7.
- relaxed (bool) –
By default, providing an invalid value for one of the other keywords will result in a
ValueError
. Ifrelaxed=True
, and the error can be corrected, aPasslibHashWarning
will be issued instead. Correctable errors includesalt
strings that are too long.New in version 1.6.
- salt (str) – Optional salt string.
If not specified, one will be autogenerated (this is recommended).
If specified, it must be 2 characters, drawn from the regexp range
Format¶
An example hash (of the string passphrase
) is aaX/UmCcBrceQ0kQGGWKTbuE
.
A crypt16 hash string has the format saltchecksum_1checksum_2
, where:
salt
is the salt, stored as a 2 characterhash64
-encoded 12-bit integer (aa
in the example).- each
checksum_i
is a separate checksum, stored as an 11 characterhash64-big
-encoded 64-bit integer (X/UmCcBrceQ
and0kQGGWKTbuE
in the example).
Note
This hash is frequently confused with the bigcrypt
hash algorithm, as it has the same size and uses the same character
set as a bigcrypt
hash of a password with 9 to 16
characters; though the actual algorithms are different.
Algorithm¶
Security Issues¶
Crypt16 is dangerously flawed:
- It suffers from all the flaws of
des_crypt
. - Compared to des-crypt, its smaller number of rounds makes it even more vulnerable to brute-force attacks.
- For a given salt, passwords under 9 characters all have the same 2nd checksum. Given the 12-bit salt size, all such 2nd checksums can be easily pre-computed; making an attack easier, and giving away information about password size.
- Since both checksums use the same salt, they can be attacked at once (by doing 5 rounds, checking the result against checksum 2, doing 15 rounds more, and checking the result against checksum 1).
Deviations¶
This implementation of crypt16 deviates from public documentation of the format in one way:
Unicode Policy:
The original crypt16 algorithm was designed for 7-bit
us-ascii
encoding only (as evidenced by the fact that it discards the 8th bit of all password bytes).In order to provide support for unicode strings, Passlib will encode unicode passwords using
utf-8
before running them through crypt16. If a different encoding is desired by an application, the password should be encoded before handing it to Passlib.
Footnotes
[1] | One source of information about bigcrypt & crypt16 - http://www.mail-archive.com/exim-dev@exim.org/msg00970.html |