Bcrypt: Difference between revisions
m →top: WP:CHECKWIKI error fixes using AWB (12095) |
Rescuing 1 sources and tagging 0 as dead. #IABot (v1.2.6) |
||
Line 3: | Line 3: | ||
'''bcrypt''' is a [[Cryptographic hash function#Password verification|password hashing function]] designed by [[Niels Provos]] and David Mazières, based on the [[Blowfish (cipher)|Blowfish]] cipher, and presented at [[USENIX]] in 1999.<ref name=provos>{{cite journal | url = http://www.usenix.org/events/usenix99/provos/provos_html/node1.html | title = A Future-Adaptable Password Scheme | first = Niels | last = Provos |author2=Mazières, David | year = 1999 |author3=Talan Jason Sutton 2012 | journal = Proceedings of 1999 USENIX Annual Technical Conference | pages = 81–92}}</ref> Besides incorporating a [[salt (cryptography)|salt]] to protect against [[rainbow table]] attacks, bcrypt is an adaptive function: over time, the iteration count can be increased to make it slower, so it remains resistant to [[brute-force search]] attacks even with increasing computation power. |
'''bcrypt''' is a [[Cryptographic hash function#Password verification|password hashing function]] designed by [[Niels Provos]] and David Mazières, based on the [[Blowfish (cipher)|Blowfish]] cipher, and presented at [[USENIX]] in 1999.<ref name=provos>{{cite journal | url = http://www.usenix.org/events/usenix99/provos/provos_html/node1.html | title = A Future-Adaptable Password Scheme | first = Niels | last = Provos |author2=Mazières, David | year = 1999 |author3=Talan Jason Sutton 2012 | journal = Proceedings of 1999 USENIX Annual Technical Conference | pages = 81–92}}</ref> Besides incorporating a [[salt (cryptography)|salt]] to protect against [[rainbow table]] attacks, bcrypt is an adaptive function: over time, the iteration count can be increased to make it slower, so it remains resistant to [[brute-force search]] attacks even with increasing computation power. |
||
The bcrypt function is the default password hash algorithm for [[OpenBSD]]<ref name=original>{{cite web|url=//cvsweb.openbsd.org/cgi-bin/cvsweb/src/lib/libc/crypt/bcrypt.c|title= Commit of first work to repo|date=13 Feb 1997}}</ref> and other systems including some [[Linux distribution]]s such as [[SUSE Linux]].<ref>{{cite web|url=https://www.suse.com/support/security/advisories/2011_35_blowfish.html|title= |
The bcrypt function is the default password hash algorithm for [[OpenBSD]]<ref name=original>{{cite web|url=//cvsweb.openbsd.org/cgi-bin/cvsweb/src/lib/libc/crypt/bcrypt.c|title= Commit of first work to repo|date=13 Feb 1997}}</ref> and other systems including some [[Linux distribution]]s such as [[SUSE Linux]].<ref>{{cite web|url=https://www.suse.com/support/security/advisories/2011_35_blowfish.html |title=SUSE Security Announcement: (SUSE-SA:2011:035) |date=23 August 2011 |access-date=20 August 2015 |quote=SUSE's crypt() implementation supports the blowfish password hashing function (id $2a) and system logins by default also use this method. |deadurl=yes |archiveurl=https://web.archive.org/web/20160304094921/https://www.suse.com/support/security/advisories/2011_35_blowfish.html |archivedate=4 March 2016 |df= }}</ref> |
||
The prefix "$2a$" or "$2b$" (or "$2y$") in a hash string in a [[shadow password]] file indicates that hash string is a bcrypt hash in modular crypt format.<ref> |
The prefix "$2a$" or "$2b$" (or "$2y$") in a hash string in a [[shadow password]] file indicates that hash string is a bcrypt hash in modular crypt format.<ref> |
||
passlib. |
passlib. |
Revision as of 06:18, 29 October 2016
bcrypt is a password hashing function designed by Niels Provos and David Mazières, based on the Blowfish cipher, and presented at USENIX in 1999.[1] Besides incorporating a salt to protect against rainbow table attacks, bcrypt is an adaptive function: over time, the iteration count can be increased to make it slower, so it remains resistant to brute-force search attacks even with increasing computation power.
The bcrypt function is the default password hash algorithm for OpenBSD[2] and other systems including some Linux distributions such as SUSE Linux.[3] The prefix "$2a$" or "$2b$" (or "$2y$") in a hash string in a shadow password file indicates that hash string is a bcrypt hash in modular crypt format.[4] The rest of the hash string includes the cost parameter, a 128-bit salt (base-64 encoded as 22 characters), and 184 bits of the resulting hash value (base-64 encoded as 31 characters).[5] The cost parameter specifies a key expansion iteration count as a power of two, which is an input to the crypt algorithm.
For example, the shadow password record $2a$10$N9qo8uLOickgx2ZMRZoMyeIjZAgcfl7p92ldGxad68LJZdL17lhWy
specifies a cost parameter of 10, indicating 210 key expansion rounds. The salt is N9qo8uLOickgx2ZMRZoMye
and the resulting hash is IjZAgcfl7p92ldGxad68LJZdL17lhWy
. Per standard practice, the user's password itself is not stored.
There are implementations of bcrypt for C, C#, Java, JavaScript, Perl, PHP, Python,[6] Ruby, NodeJS[7] and other languages.
Background
Blowfish is notable among block ciphers for its expensive key setup phase. It starts off with subkeys in a standard state, then uses this state to perform a block encryption using part of the key, and uses the result of that encryption (which is more accurately a hashing) to replace some of the subkeys. Then it uses this modified state to encrypt another part of the key, and uses the result to replace more of the subkeys. It proceeds in this fashion, using a progressively modified state to hash the key and replace bits of state, until all subkeys have been set.
Provos and Mazières took advantage of this, and took it further. They developed a new key setup algorithm for Blowfish, dubbing the resulting cipher "Eksblowfish" ("expensive key schedule Blowfish"). The key setup begins with a modified form of the standard Blowfish key setup, in which both the salt and password are used to set all subkeys. There are then a number of rounds in which the standard Blowfish keying algorithm is applied, using alternatively the salt and the password as the key, each round starting with the subkey state from the previous round. In theory, this is no stronger than the standard Blowfish key schedule, but the number of rekeying rounds is configurable; this process can therefore be made arbitrarily slow, which helps deter brute-force attacks upon the hash or salt.
Algorithm
The bcrypt algorithm depends heavily on its "Eksblowfish" key setup algorithm, which runs as follows:
EksBlowfishSetup(cost, salt, key) state InitState() state ExpandKey(state, salt, key) repeat (2cost) state ExpandKey(state, 0, key) state ExpandKey(state, 0, salt) return state
InitState works as in the original Blowfish algorithm, populating the P-array and S-box entries with the fractional part of in hexadecimal.
The ExpandKey function does the following:
ExpandKey(state, salt, key) for(n = 1..18) Pn key[32(n-1)..32n-1] Pn //treat the key as cyclic ctext Encrypt(salt[0..63]) P1 ctext[0..31] P2 ctext[32..63] for(n = 2..9) ctext Encrypt(ctext salt[64(n-1)..64n-1]) //encrypt using the current key schedule and treat the salt as cyclic P2n-1) ctext[0..31] P2n ctext[32..63] for(i = 1..4) for(n = 0..127) ctext Encrypt(ctext salt[64(n-1)..64n-1]) //as above Si[2n] ctext[0..31] Si[2n+1] ctext[32..63] return state
Hence, ExpandKey(state, 0, key)
is the same as regular Blowfish key schedule since all XORs with the all-zero salt value are ineffectual. ExpandKey(state, 0, salt)
is similar, but uses the salt as a 128-bit key.
The full bcrypt algorithm utilizes these functions to compute a hash from a given input derived from the password, as follows:
bcrypt(cost, salt, input) state EksBlowfishSetup(cost, salt, input) ctext "OrpheanBeholderScryDoubt" //three 64-bit blocks repeat (64) ctext EncryptECB(state, ctext) //encrypt using standard Blowfish in ECB mode return Concatenate(cost, salt, ctext)
User input
Many implementations of bcrypt truncate the password to the first 72 bytes.
The mathematical algorithm itself requires initialization with 18 32-bit subkeys (equivalent to 72 octets/bytes). The original specification[1] of bcrypt does not mandate any one particular method for mapping text-based passwords from userland into numeric values for the algorithm. One brief comment in the text mentions, but does not mandate, the possibility of simply using the ASCII encoded value of a character string, "Finally, the key argument is a secret encryption key, which can be a user-chosen password of up to 56 bytes (including a terminating zero byte when the key is an ASCII string)."
Note that the quote above mentions passwords "up to 56 bytes" even though the algorithm itself makes use of a 72 byte initial value. Although Provos and Mazières do not state the reason for the shorter restriction, they may have been motivated by the following statement from Bruce Schneier's original specification of Blowfish,[8] "The 448 [bit] limit on the key size ensures that the[sic] every bit of every subkey depends on every bit of the key."
Implementations have varied in their approach of converting passwords into initial numeric values, including sometimes reducing the strength of passwords containing special characters.[9]
See also
- Crypt (C)#Blowfish-based scheme crypt – password storage and verification scheme – Blowfish
- Key stretching
- PBKDF2 (Password-Based Key Derivation Function 2)
- scrypt
References
- ^ a b Provos, Niels; Mazières, David; Talan Jason Sutton 2012 (1999). "A Future-Adaptable Password Scheme". Proceedings of 1999 USENIX Annual Technical Conference: 81–92.
{{cite journal}}
: CS1 maint: numeric names: authors list (link) - ^ "Commit of first work to repo". 13 Feb 1997.
- ^ "SUSE Security Announcement: (SUSE-SA:2011:035)". 23 August 2011. Archived from the original on 4 March 2016. Retrieved 20 August 2015.
SUSE's crypt() implementation supports the blowfish password hashing function (id $2a) and system logins by default also use this method.
{{cite web}}
: Unknown parameter|deadurl=
ignored (|url-status=
suggested) (help) - ^ passlib. "Modular Crypt Format".
- ^ passlib. "BCrypt".
- ^ https://pypi.python.org/pypi/bcrypt/2.0.0
- ^ https://www.npmjs.com/package/bcrypt
- ^ Schneier, Bruce (1994). "Fast Software Encryption, Description of a New Variable-Length Key, 64-Bit Block Cipher (Blowfish)". Cambridge Security Workshop Proceedings (December 1993). Springer-Verlag: 191–204.
- ^ "jBCrypt security advisory". 1 February 2010. And "Changes in CRYPT_BLOWFISH in PHP 5.3.7". php.net.