Questions tagged [crypt]

crypt() is Unix C library function used for hashing passwords. It is also found in PHP, Perl, Python and various other languages.

crypt(3) is a Unix C library function used for hashing passwords. The crypt() function takes in a password and an optional salt string (chosen randomly if not supplied), and calculates a cryptographic message digest based on them. The digest includes the salt used to generate it, so that, when the user re-enters their password, the digest can be recalculated and compared with the previously stored value.

Despite its name, the crypt(3) function cannot actually be used to encrypt data; the transformation it implements is deliberately non-reversible, so that its output cannot be decrypted to recover the original password.

The "traditional" hashing algorithm used by the original Unix crypt(3) was based on a modified version of the DES block cipher, and only supported passwords of up to 8 characters, with 7 bits per character, and a two-character salt with 6 bits per character. This algorithm is nowadays considered insecure due to its limited keyspace and high speed, which allow an attacker using modern computers to test all possible passwords by brute force in a relatively short time. Nonetheless, most crypt(3) implementations still include it for the sake of backwards compatibility.

Most modern crypt(3) implementations include various alternative hashing algorithms, which typically support arbitrarily long passphrases, longer salts and adjustable iteration counts to deliberately slow down the digest calculation for key stretching. One well known example of such an algorithm is , which is based on the Blowfish cipher.

Functions similar in name and purpose to (and possibly implemented by) the Unix crypt(3) function are also found in several high-level languages, including PHP, Perl and Python.

The crypt(3) function should not be confused with the Unix command line utility crypt(1), which is an obsolete and insecure file encryption utility. For a modern replacement, see .

553 questions
5
votes
2 answers

Why does the crypt() function not have a memory leak?

From crypt(3) - Linux man page: char *crypt(const char *key, const char *salt); Return Value: A pointer to the encrypted password is returned. On error, NULL is returned. Since the return value is unknown unless key and salt is given, this should…
Figo
  • 1,700
  • 3
  • 15
  • 24
5
votes
4 answers

Which iteration rules apply on crypt() using CRYPT_EXT_DES?

My testcase as follows: echo crypt('string', '_....salt');//error echo crypt('string', '_A...salt');//fast echo crypt('string', '_AAAAsalt');//slow Explanation as stated at http://www.php.net/manual/en/function.crypt.php: CRYPT_EXT_DES - Extended…
mgutt
  • 5,867
  • 2
  • 50
  • 77
5
votes
1 answer

Crypt returning same hash for two different (similar) passwords

I have an issue using crypt() where if a user has a password (password1 in this example), and they change it to password2, the hashing returns the same result. You can test that here: OLD LINK Type password1 as current password, and password2 as…
dcclassics
  • 896
  • 1
  • 12
  • 38
5
votes
4 answers

PHP crypt() Blowfish Function Not Working

This is my first time using the crypt() function in PHP, and I can't figure out why it isn't working. My code is based on this article: http://www.techrepublic.com/blog/australia/securing-passwords-with-blowfish/1274 function blowfishHash ($pw) { …
Joel G
  • 67
  • 1
  • 7
5
votes
3 answers

How to automatically generate salt for crypt method with blowfish

I have just started learning PHP and I want to create a website with a login for my final year university project. I've read that blowfish is the best method for hashing in a number of places like here: openssl_digest vs hash vs hash_hmac?…
Connel
  • 1,844
  • 4
  • 23
  • 36
5
votes
5 answers

What does crypt() do in C?

crypt(text,"k7") I looked it up and apparently 'k7' is the salt, but I have no idea what that means nor what type of output will come from that, anyone know?
MetaGuru
  • 42,847
  • 67
  • 188
  • 294
4
votes
2 answers

How to get hex hash with crypt() function?

If i create a SHA-256 has in the terminal i get a nice looking hex hash: echo -n ChillyWilly | sha256sum 4c74e3994a247dfc31a515721528c78bb6ec09ccdcfd894d09f4aa44131393a8 - If i try to do the same with the crypt(3) function then i get something…
ele lont
  • 469
  • 1
  • 4
  • 11
4
votes
1 answer

Using crypt() from crypt.h

I am doing the week2 pset for CS50. When using the crypt function, the char pointers which point to the ciphertext of any string always point to the last thing I encrypted. For example: char password[] = "AAAA"; char toCrack[] =…
Zach LeFevre
  • 81
  • 1
  • 1
  • 5
4
votes
4 answers

use python to create compatible ldap password (md5crypt) on windows

Do you know how to create a ldap compatible password (preferred md5crypt) via python on Windows I used to write something like this in Linux but the crypt module is not present on Windows char_set = string.ascii_uppercase + string.digits salt =…
giskard
  • 698
  • 1
  • 7
  • 11
4
votes
2 answers

crypt() fallback for old hash salts in PHP7

I am working on upgrading my code base to PHP-7 and I'm having trouble with some old users that have a salt format that is not compatible with DES. My idea is to authenticate the user and then transform the hash salt into a new format like Blowfish…
lgomezma
  • 1,597
  • 2
  • 15
  • 30
4
votes
0 answers

How to use PBKDF2 password hashing in an embedded Linux device

I have a need to generate password hashes in a Windows application and, at a later time, download them to a Linux device to be inserted into the shadow password file. For marketing reasons using PBKDF2 is attractive at the Windows end as it provides…
Rob Smyth
  • 1,768
  • 11
  • 19
4
votes
2 answers

crypt does not work in osx, returns wrong value

I'm using an OSX 10.9 (last version) with the last Xcode. When I execute the following command: python -c 'import crypt; print crypt.crypt("test", "$6$random_salt")' I get this as an answer: $6asQOJRqB1i2 but if I execute the same in a debian…
Abraham
  • 531
  • 5
  • 13
4
votes
1 answer

(PHP) How to use crypt() with CRYPT_BLOWFISH?

First, I see that to use CRYPT_BLOWFISH, i need to use a 16 char salt starting with $2a$. However, the php.net documentation for crypt() says that some systems don't support CRYPT_BLOWFISH. How often is that the case? Next, from their example on the…
Tony Stark
  • 24,588
  • 41
  • 96
  • 113
4
votes
1 answer

Why does PHP crypt function use DES encryption algorithm?

Given that the rule of thumb is to store salted hashes of the password string, not the encrypted form of it, why does the PHP crypt() function use the DES-based algorithms? Isn't DES an encryption algorithm? The manual says ... crypt() will return…
user1720897
  • 1,216
  • 3
  • 12
  • 27
4
votes
2 answers

How best to upgrade to password_* functions from hash('sha512','salt')

I am keen to migrate my code to the new password_* functions provided natively by PHP. The existing hashes in the database have been generated as follows: hash ('sha512', '' . $email . $password); I'd like to move these…
fooquency
  • 1,575
  • 3
  • 16
  • 29