diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libc/crypt/bcrypt.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/lib/libc/crypt/bcrypt.c b/src/lib/libc/crypt/bcrypt.c index abcbe138ca..1114eae44e 100644 --- a/src/lib/libc/crypt/bcrypt.c +++ b/src/lib/libc/crypt/bcrypt.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: bcrypt.c,v 1.47 2014/12/30 10:27:24 tedu Exp $ */ | 1 | /* $OpenBSD: bcrypt.c,v 1.48 2015/01/05 13:10:10 tedu Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * Copyright (c) 2014 Ted Unangst <tedu@openbsd.org> | 4 | * Copyright (c) 2014 Ted Unangst <tedu@openbsd.org> |
| @@ -231,24 +231,26 @@ bcrypt_checkpass(const char *pass, const char *goodhash) | |||
| 231 | int | 231 | int |
| 232 | bcrypt_autorounds(void) | 232 | bcrypt_autorounds(void) |
| 233 | { | 233 | { |
| 234 | clock_t before, after; | 234 | struct timespec before, after; |
| 235 | int r = 8; | 235 | int r = 8; |
| 236 | char buf[_PASSWORD_LEN]; | 236 | char buf[_PASSWORD_LEN]; |
| 237 | int duration; | 237 | int duration; |
| 238 | 238 | ||
| 239 | before = clock(); | 239 | clock_gettime(CLOCK_THREAD_CPUTIME_ID, &before); |
| 240 | bcrypt_newhash("testpassword", r, buf, sizeof(buf)); | 240 | bcrypt_newhash("testpassword", r, buf, sizeof(buf)); |
| 241 | after = clock(); | 241 | clock_gettime(CLOCK_THREAD_CPUTIME_ID, &after); |
| 242 | 242 | ||
| 243 | duration = after - before; | 243 | duration = after.tv_sec - before.tv_sec; |
| 244 | duration *= 1000000; | ||
| 245 | duration += (after.tv_nsec - before.tv_nsec) / 1000; | ||
| 244 | 246 | ||
| 245 | /* too quick? slow it down. */ | 247 | /* too quick? slow it down. */ |
| 246 | while (r < 16 && duration <= CLOCKS_PER_SEC / 4) { | 248 | while (r < 16 && duration <= 1000000 / 4) { |
| 247 | r += 1; | 249 | r += 1; |
| 248 | duration *= 2; | 250 | duration *= 2; |
| 249 | } | 251 | } |
| 250 | /* too slow? speed it up. */ | 252 | /* too slow? speed it up. */ |
| 251 | while (r > 4 && duration > CLOCKS_PER_SEC / 2) { | 253 | while (r > 4 && duration > 1000000 / 2) { |
| 252 | r -= 1; | 254 | r -= 1; |
| 253 | duration /= 2; | 255 | duration /= 2; |
| 254 | } | 256 | } |
