History log of /openbsd-current/lib/libc/crypt/bcrypt.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.58 06-Jul-2020 pirofti

Add support for timeconting in userland.

This diff exposes parts of clock_gettime(2) and gettimeofday(2) to
userland via libc eliberating processes from the need for a context
switch everytime they want to count the passage of time.

If a timecounter clock can be exposed to userland than it needs to set
its tc_user member to a non-zero value. Tested with one or multiple
counters per architecture.

The timing data is shared through a pointer found in the new ELF
auxiliary vector AUX_openbsd_timekeep containing timehands information
that is frequently updated by the kernel.

Timing differences between the last kernel update and the current time
are adjusted in userland by the tc_get_timecount() function inside the
MD usertc.c file.

This permits a much more responsive environment, quite visible in
browsers, office programs and gaming (apparently one is are able to fly
in Minecraft now).

Tested by robert@, sthen@, naddy@, kmos@, phessler@, and many others!

OK from at least kettenis@, cheloha@, naddy@, sthen@


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE
# 1.57 26-Aug-2016 guenther

Pull in <time.h> for clock_gettime()

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.56 26-Jun-2016 tedu

increase the minimum for auto rounds to 6. that was the previous low bound
for login.conf, and we don't want to go lower.


Revision tags: OPENBSD_5_9_BASE
# 1.55 13-Sep-2015 guenther

Wrap <pwd.h> so that calls go direct and the symbols are all weak.
Hide bcrypt_autorounds(), prefixing with an underbar for static builds.


# 1.54 13-Sep-2015 millert

The number of rounds is just two digits in the salt. We've already
verified that they are there via isdigit() so we can convert from
ASCII to an int without using atoi(). OK guenther@ deraadt@


Revision tags: OPENBSD_5_8_BASE
# 1.53 18-Jul-2015 tedu

standards compliant error return (null). will make ruby happier, at least.
ok deraadt jeremy


Revision tags: OPENBSD_5_7_BASE
# 1.52 28-Jan-2015 tedu

dial the time back to about 0.1s, closer to the original targets and
friendlier for users. requested by deraadt


# 1.51 12-Jan-2015 tedu

rename blocks to words. bcrypt "blocks" are unrelated to blowfish blocks,
nor are they the same size.


# 1.50 07-Jan-2015 tedu

stupid me. need errno.h


# 1.49 07-Jan-2015 tedu

set errno = EINVAL for invalid salts and hashes in most functions.
remember to set EACCES in bcrypt_checkpass for hash differences.
the higher level crypt_checkpass function will reset errno to EACCES in
all cases, which is probably the right behavior, but this change gives code
working with the lower level functions the correct errno if they care.


# 1.48 05-Jan-2015 tedu

convert clock() to clock_gettime() for improved precision (and accuracy?)
guenther suggested using thread time, which actually may improve accuracy
if somebody puts this in a threaded program.


# 1.47 30-Dec-2014 tedu

copy bcrypt autotune from encrypt(1) and expose via crypt_newhash
ok deraadt miod


# 1.46 24-Nov-2014 tedu

introduce a hashspace define and check that there's enough space to
write out a hash. also simplify writing out the hash.


Revision tags: OPENBSD_5_6_BASE
# 1.45 20-Jul-2014 guenther

From ISO/IEC 9899:1999 and 9899:201x,
6.11.5 - Storage-class specifiers:
The placement of a storage-class specifier other than at the
beginning of the declaration specifiers in a declaration is
an obsolescent feature.

Diff from Jean-Philippe Ouellet (jean-philippe (at) ouellet.biz)


# 1.44 17-May-2014 chl

Add missing header needed by isdigit().
While there, sort headers.

ok tedu@


# 1.43 06-May-2014 tedu

fix stupid commit


# 1.42 06-May-2014 tedu

use explicit_bzero


# 1.41 03-May-2014 tedu

now that 5.5 has been released with compatibility for 2b hashes,
switch to generating them by default. prodded by deraadt and sthen


# 1.40 03-May-2014 tedu

1. Drop support for no minor. This variant doesn't exist anymore.
2. Pull up the actual minor processing code into the switch that
parses it.
3. atoi is actually simpler than strtonum in this case, but check the
input beforehand so we don't get unexpected results.
4. Slightly more consistent style between various parse and check and
increment operations on salt.
ok deraadt


# 1.39 19-Apr-2014 tedu

one small tweak to avoid ever going off the end of a string.


# 1.38 19-Apr-2014 tedu

improved checking for invalid hashes. from solar designer


# 1.37 08-Apr-2014 tedu

use char * for strings, saving casts. add return codes to base64 functions


# 1.36 24-Mar-2014 tedu

oops, merge error


# 1.35 23-Mar-2014 tedu

clear stack variables, suggested by djm


# 1.34 23-Mar-2014 tedu

some improvements suggested by djm.
use better constant for salt size.
always copy ":" to gerror, in case somebody is dumb enough to overwrite it
timingsafe_bcmp before somebody whines about strcmp


# 1.33 23-Mar-2014 tedu

two functions don't need to be exported


# 1.32 23-Mar-2014 tedu

minimal change to implementation of bcrypt to not require static globals.
add some friendlier functions.
move the classic static data api into wrapper functions.
a few more changes to come...


# 1.31 22-Mar-2014 tedu

switch to shorter ISC license. this was ok with Niels Provos.


# 1.30 19-Mar-2014 tedu

consolidate the base64 code in one place, and remove inadequate test code


Revision tags: OPENBSD_5_5_BASE
# 1.29 24-Feb-2014 tedu

solar's testsuite revealed insufficient validation of invalid input hashes.
add a more complete check for the rounds parameter. ok deraadt


# 1.28 17-Feb-2014 tedu

remove redundant test


# 1.27 17-Feb-2014 tedu

sticking strlen into a char leads to wraparound at 256. fix this and
introduce a new 'b' hash minor. still generate 'a' minors for now.
reported by solar designer. diff by some combination of solar and jca.
ok deraadt


# 1.26 19-Dec-2013 deraadt

pseudo-code corrections from Solar Designer <solar@openwall.com>


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.25 04-Sep-2012 tedu

arc4random_buf is the easy way to fill a buffer now. ok deraadt


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.24 02-Apr-2008 millert

Zero state buffers on return. OK deraadt@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.23 19-Mar-2007 ray

Get rid of useless #if 0 block, especially since the code is included
immediately after.

OK millert@.


Revision tags: OPENBSD_4_1_BASE
# 1.22 20-Feb-2007 ray

Change hard coded numbers to sizeof(buf). Also change some
sizeof(buf) - 1 to sizeof(buf), since fgets takes the whole buffer size.

Based on diff from Charles Longeau <chl at tuxfamily dot org> long ago.

OK millert@.


Revision tags: OPENBSD_4_0_BASE
# 1.21 04-Jul-2006 otto

allocate gsalt large enough; from Matthew R. Dempsky <mrd at alkemio
dot org>; ok djm@ deraadt@


# 1.20 03-Apr-2006 deraadt

be more careful with atoi() result; ok otto


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE
# 1.19 22-Dec-2004 otto

Test the upper limit for the max # of rounds to, to avoid wrapping and ending
up with a low number of rounds. Spotted by mpech@; ok mpech@ millert@


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE
# 1.18 07-Aug-2003 deraadt

ansi


# 1.17 25-Jun-2003 deraadt

protos


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE
# 1.16 19-Feb-2002 millert

We live in an ANSI C world. Remove lots of gratuitous #ifdef __STDC__ cruft.


# 1.15 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_2_9_BASE OPENBSD_3_0_BASE
# 1.14 04-Jan-2001 todd

grammer/spelling


Revision tags: OPENBSD_2_8_BASE
# 1.13 02-Aug-2000 provos

return error if salt is too small; pr 1336


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE
# 1.12 10-Aug-1998 provos

fix base64 encoding, this problem was reported by
Solar Designer <solar@false.com> some time ago.


Revision tags: OPENBSD_2_3_BASE
# 1.11 18-Feb-1998 provos

#if __STDC__ -> #ifdef __STDC__, now all of them.


Revision tags: OPENBSD_2_2_BASE
# 1.10 10-Sep-1997 deraadt

indentation cleanup


# 1.9 25-Jul-1997 mickey

#if __STDC__ --> #ifdef __STDC__


# 1.8 23-Jul-1997 kstailey

tabify


# 1.7 09-Jul-1997 millert

Clean up some -Wall flowers.


# 1.6 01-Jul-1997 provos

fix that repeating passwords yield same hash + increment minor


Revision tags: OPENBSD_2_1_BASE
# 1.5 30-Apr-1997 tholo

Be more careful about possible type promotion


# 1.4 27-Mar-1997 provos

yet another random() converted to arc4random()


# 1.3 16-Feb-1997 provos

prelim manpage, cleanup, fixed crippled plaintext: sed does a nice
job on replacing everything, just wouldnt skip it


# 1.2 14-Feb-1997 provos

header update


# 1.1 13-Feb-1997 provos

password hashing algorithm using blowfish


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.57 26-Aug-2016 guenther

Pull in <time.h> for clock_gettime()

ok deraadt@


Revision tags: OPENBSD_6_0_BASE
# 1.56 26-Jun-2016 tedu

increase the minimum for auto rounds to 6. that was the previous low bound
for login.conf, and we don't want to go lower.


Revision tags: OPENBSD_5_9_BASE
# 1.55 13-Sep-2015 guenther

Wrap <pwd.h> so that calls go direct and the symbols are all weak.
Hide bcrypt_autorounds(), prefixing with an underbar for static builds.


# 1.54 13-Sep-2015 millert

The number of rounds is just two digits in the salt. We've already
verified that they are there via isdigit() so we can convert from
ASCII to an int without using atoi(). OK guenther@ deraadt@


Revision tags: OPENBSD_5_8_BASE
# 1.53 18-Jul-2015 tedu

standards compliant error return (null). will make ruby happier, at least.
ok deraadt jeremy


Revision tags: OPENBSD_5_7_BASE
# 1.52 28-Jan-2015 tedu

dial the time back to about 0.1s, closer to the original targets and
friendlier for users. requested by deraadt


# 1.51 12-Jan-2015 tedu

rename blocks to words. bcrypt "blocks" are unrelated to blowfish blocks,
nor are they the same size.


# 1.50 07-Jan-2015 tedu

stupid me. need errno.h


# 1.49 07-Jan-2015 tedu

set errno = EINVAL for invalid salts and hashes in most functions.
remember to set EACCES in bcrypt_checkpass for hash differences.
the higher level crypt_checkpass function will reset errno to EACCES in
all cases, which is probably the right behavior, but this change gives code
working with the lower level functions the correct errno if they care.


# 1.48 05-Jan-2015 tedu

convert clock() to clock_gettime() for improved precision (and accuracy?)
guenther suggested using thread time, which actually may improve accuracy
if somebody puts this in a threaded program.


# 1.47 30-Dec-2014 tedu

copy bcrypt autotune from encrypt(1) and expose via crypt_newhash
ok deraadt miod


# 1.46 24-Nov-2014 tedu

introduce a hashspace define and check that there's enough space to
write out a hash. also simplify writing out the hash.


Revision tags: OPENBSD_5_6_BASE
# 1.45 20-Jul-2014 guenther

From ISO/IEC 9899:1999 and 9899:201x,
6.11.5 - Storage-class specifiers:
The placement of a storage-class specifier other than at the
beginning of the declaration specifiers in a declaration is
an obsolescent feature.

Diff from Jean-Philippe Ouellet (jean-philippe (at) ouellet.biz)


# 1.44 17-May-2014 chl

Add missing header needed by isdigit().
While there, sort headers.

ok tedu@


# 1.43 06-May-2014 tedu

fix stupid commit


# 1.42 06-May-2014 tedu

use explicit_bzero


# 1.41 03-May-2014 tedu

now that 5.5 has been released with compatibility for 2b hashes,
switch to generating them by default. prodded by deraadt and sthen


# 1.40 03-May-2014 tedu

1. Drop support for no minor. This variant doesn't exist anymore.
2. Pull up the actual minor processing code into the switch that
parses it.
3. atoi is actually simpler than strtonum in this case, but check the
input beforehand so we don't get unexpected results.
4. Slightly more consistent style between various parse and check and
increment operations on salt.
ok deraadt


# 1.39 19-Apr-2014 tedu

one small tweak to avoid ever going off the end of a string.


# 1.38 19-Apr-2014 tedu

improved checking for invalid hashes. from solar designer


# 1.37 08-Apr-2014 tedu

use char * for strings, saving casts. add return codes to base64 functions


# 1.36 24-Mar-2014 tedu

oops, merge error


# 1.35 23-Mar-2014 tedu

clear stack variables, suggested by djm


# 1.34 23-Mar-2014 tedu

some improvements suggested by djm.
use better constant for salt size.
always copy ":" to gerror, in case somebody is dumb enough to overwrite it
timingsafe_bcmp before somebody whines about strcmp


# 1.33 23-Mar-2014 tedu

two functions don't need to be exported


# 1.32 23-Mar-2014 tedu

minimal change to implementation of bcrypt to not require static globals.
add some friendlier functions.
move the classic static data api into wrapper functions.
a few more changes to come...


# 1.31 22-Mar-2014 tedu

switch to shorter ISC license. this was ok with Niels Provos.


# 1.30 19-Mar-2014 tedu

consolidate the base64 code in one place, and remove inadequate test code


Revision tags: OPENBSD_5_5_BASE
# 1.29 24-Feb-2014 tedu

solar's testsuite revealed insufficient validation of invalid input hashes.
add a more complete check for the rounds parameter. ok deraadt


# 1.28 17-Feb-2014 tedu

remove redundant test


# 1.27 17-Feb-2014 tedu

sticking strlen into a char leads to wraparound at 256. fix this and
introduce a new 'b' hash minor. still generate 'a' minors for now.
reported by solar designer. diff by some combination of solar and jca.
ok deraadt


# 1.26 19-Dec-2013 deraadt

pseudo-code corrections from Solar Designer <solar@openwall.com>


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.25 04-Sep-2012 tedu

arc4random_buf is the easy way to fill a buffer now. ok deraadt


Revision tags: OPENBSD_4_4_BASE OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE OPENBSD_4_8_BASE OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE
# 1.24 02-Apr-2008 millert

Zero state buffers on return. OK deraadt@


Revision tags: OPENBSD_4_2_BASE OPENBSD_4_3_BASE
# 1.23 19-Mar-2007 ray

Get rid of useless #if 0 block, especially since the code is included
immediately after.

OK millert@.


Revision tags: OPENBSD_4_1_BASE
# 1.22 20-Feb-2007 ray

Change hard coded numbers to sizeof(buf). Also change some
sizeof(buf) - 1 to sizeof(buf), since fgets takes the whole buffer size.

Based on diff from Charles Longeau <chl at tuxfamily dot org> long ago.

OK millert@.


Revision tags: OPENBSD_4_0_BASE
# 1.21 04-Jul-2006 otto

allocate gsalt large enough; from Matthew R. Dempsky <mrd at alkemio
dot org>; ok djm@ deraadt@


# 1.20 03-Apr-2006 deraadt

be more careful with atoi() result; ok otto


Revision tags: OPENBSD_3_7_BASE OPENBSD_3_8_BASE OPENBSD_3_9_BASE
# 1.19 22-Dec-2004 otto

Test the upper limit for the max # of rounds to, to avoid wrapping and ending
up with a low number of rounds. Spotted by mpech@; ok mpech@ millert@


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE
# 1.18 07-Aug-2003 deraadt

ansi


# 1.17 25-Jun-2003 deraadt

protos


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE OPENBSD_3_3_BASE
# 1.16 19-Feb-2002 millert

We live in an ANSI C world. Remove lots of gratuitous #ifdef __STDC__ cruft.


# 1.15 16-Feb-2002 millert

Part one of userland __P removal. Done with a simple regexp with some minor hand editing to make comments line up correctly. Another pass is forthcoming that handles the cases that could not be done automatically.


Revision tags: OPENBSD_2_9_BASE OPENBSD_3_0_BASE
# 1.14 04-Jan-2001 todd

grammer/spelling


Revision tags: OPENBSD_2_8_BASE
# 1.13 02-Aug-2000 provos

return error if salt is too small; pr 1336


Revision tags: OPENBSD_2_4_BASE OPENBSD_2_5_BASE OPENBSD_2_6_BASE OPENBSD_2_7_BASE
# 1.12 10-Aug-1998 provos

fix base64 encoding, this problem was reported by
Solar Designer <solar@false.com> some time ago.


Revision tags: OPENBSD_2_3_BASE
# 1.11 18-Feb-1998 provos

#if __STDC__ -> #ifdef __STDC__, now all of them.


Revision tags: OPENBSD_2_2_BASE
# 1.10 10-Sep-1997 deraadt

indentation cleanup


# 1.9 25-Jul-1997 mickey

#if __STDC__ --> #ifdef __STDC__


# 1.8 23-Jul-1997 kstailey

tabify


# 1.7 09-Jul-1997 millert

Clean up some -Wall flowers.


# 1.6 01-Jul-1997 provos

fix that repeating passwords yield same hash + increment minor


Revision tags: OPENBSD_2_1_BASE
# 1.5 30-Apr-1997 tholo

Be more careful about possible type promotion


# 1.4 27-Mar-1997 provos

yet another random() converted to arc4random()


# 1.3 16-Feb-1997 provos

prelim manpage, cleanup, fixed crippled plaintext: sed does a nice
job on replacing everything, just wouldnt skip it


# 1.2 14-Feb-1997 provos

header update


# 1.1 13-Feb-1997 provos

password hashing algorithm using blowfish