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
3
votes
2 answers

Updating LDAP encrypted password via JNDI

I need some pointers how to update an encrypted password in an LDAP (OpenLDAP) of a user within an LDAP tree. The passwords in the LDAP server are prefixed with {crypt} which I suppose indicates that it is encrypted (with DES?) I need to write a…
jbx
  • 21,365
  • 18
  • 90
  • 144
3
votes
1 answer

Variable is unexpectedly overwritten in for loop with crypt()

I'm trying to build a C program that will bruteforce a hash given in argument. Here is the code: #include #include #include #include const char setting[] = "$6$QSX8hjVa$"; const char values[] =…
hacb
  • 175
  • 2
  • 10
3
votes
1 answer

Validating against FreeBSD /etc/master.passwd

I am trying to take a plaintext password and hash it for comparison to password hashes stored in FreeBSD's /etc/master.passwd. My goal is to have a node.js program able to authenticate against the master.passwd database using existing account…
Dave H.
  • 538
  • 5
  • 11
3
votes
1 answer

how to implement php's crypt_md5 in java

I have a simple application in PHP which uses the following code to hash the password and store it in a db.
thr33pwood
  • 31
  • 5
3
votes
1 answer

How can I make a variable salt to be used in the crypt function in C?

As an assignment, I have to find a password of a user starting from the hash of that password (which was made using crypt). So, I'm trying to create a variable salt (2-letter string) which I then tend to use in the crypt function until the result…
Maxim
  • 31
  • 1
3
votes
4 answers

Why does MySQL's ENCRYPT return different results on each call?

I have an ugly server issue, and i'm trying not to overlook any details on this. My virtual email users' passwords are stored with MySQL's ENCRYPT function. My basic idea was I'll dump my virtual users' table from the old machine, then import it in…
fabrik
  • 14,094
  • 8
  • 55
  • 71
3
votes
1 answer

How to create md5 hash as the crypt function generates with a md5 salt using the md5 function, not the crypt function?

I prefer using crypt function in php for password encryption and other one way encryption requirements. Because I can use any supported encryption algorithm, by changing the salt and there are few other advantages. Normally, I don't use any salt and…
Debiprasad
  • 5,895
  • 16
  • 67
  • 95
3
votes
2 answers

How to replicate hash_hmac('sha256', $key, $secret_key) function in Swift 4?

I've tried generating the hash_hmac('sha256', $key, $secret_key) php function equivalent in Swift 4 without success, after using libraries like CommonCrypto, CryptoSwift. I need these function for API authentication, using Alamofire library, which…
iedi3
  • 41
  • 3
3
votes
3 answers

Is there a standard way to generate a salt for crypt syscall?

I need to implement account management for my application, and I would rather not use chpasswd subprocess, or otherwise let the plaintext password out my my application's memory space. I want to use putspent with a password hash I generate with…
immortal
  • 3,118
  • 20
  • 38
3
votes
1 answer

Recursively iterating over every character combination

Expected result: The program takes a hashed password as input; this is passed to the decrypt function. The function iterates over every mixed-case n-letter combination, hashing each such string. If it finds a match to the input, it prints out the…
Rupcio
  • 57
  • 6
3
votes
1 answer

How do I make cryptsetup automatically use a key file during mount time?

I am programmatically invoking cryptsetup and would like to pass in a key file on demand at the command line (not interactively). How can I use cryptsetup with luks to take in a key file at the command line?
steve landiss
  • 1,833
  • 3
  • 19
  • 30
3
votes
1 answer

C# emulating php crypt

I need to hash passwords with C# in a way that another software understands it . Originally php's crypt function is doing that. It has the following…
Erik Mandke
  • 1,577
  • 3
  • 23
  • 30
3
votes
1 answer

PHP crypt() - Returned md5 hash

The docs (http://php.net/manual/de/function.crypt.php) for the crypt() function show the following example for an MD5 hash: $1$rasmusle$rISCgZzpwk3UhDidwXvin0 I understand, that "$1$" is the prefix, which contains the information, that the hash is…
Tream
  • 1,049
  • 2
  • 13
  • 29
3
votes
1 answer

php blowfish hashing with crypt(): the CLI result differs from webserver's one

When I use php function crypt() using Blowfish algorithm with web-server:
Alexander
  • 287
  • 4
  • 13
3
votes
1 answer

C crypt_r really 32 times slower than crypt?

I'm doing a proof of concept descrypt bruteforcer, and have the single threaded version working nicely at around 190k hashes/s with a single core of i-7 860 cpu. I am now trying to make a multithreaded version of this program (my first time playing…