summaryrefslogtreecommitdiff
path: root/src/lib/libc/crypt/bcrypt.c
diff options
context:
space:
mode:
authortedu <>2014-12-30 10:27:24 +0000
committertedu <>2014-12-30 10:27:24 +0000
commit5be433bdbc930377f480e51c67406a3841179339 (patch)
tree047c9686f0cf60d1911a2a37db719790a8cbcb49 /src/lib/libc/crypt/bcrypt.c
parent91106b4c90b48b9064630173be7bc0822d7c8043 (diff)
downloadopenbsd-5be433bdbc930377f480e51c67406a3841179339.tar.gz
openbsd-5be433bdbc930377f480e51c67406a3841179339.tar.bz2
openbsd-5be433bdbc930377f480e51c67406a3841179339.zip
copy bcrypt autotune from encrypt(1) and expose via crypt_newhash
ok deraadt miod
Diffstat (limited to 'src/lib/libc/crypt/bcrypt.c')
-rw-r--r--src/lib/libc/crypt/bcrypt.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/src/lib/libc/crypt/bcrypt.c b/src/lib/libc/crypt/bcrypt.c
index 94758ca40b..abcbe138ca 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.46 2014/11/24 22:47:01 tedu Exp $ */ 1/* $OpenBSD: bcrypt.c,v 1.47 2014/12/30 10:27:24 tedu Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2014 Ted Unangst <tedu@openbsd.org> 4 * Copyright (c) 2014 Ted Unangst <tedu@openbsd.org>
@@ -225,6 +225,38 @@ bcrypt_checkpass(const char *pass, const char *goodhash)
225} 225}
226 226
227/* 227/*
228 * Measure this system's performance by measuring the time for 8 rounds.
229 * We are aiming for something that takes between 0.25 and 0.5 seconds.
230 */
231int
232bcrypt_autorounds(void)
233{
234 clock_t before, after;
235 int r = 8;
236 char buf[_PASSWORD_LEN];
237 int duration;
238
239 before = clock();
240 bcrypt_newhash("testpassword", r, buf, sizeof(buf));
241 after = clock();
242
243 duration = after - before;
244
245 /* too quick? slow it down. */
246 while (r < 16 && duration <= CLOCKS_PER_SEC / 4) {
247 r += 1;
248 duration *= 2;
249 }
250 /* too slow? speed it up. */
251 while (r > 4 && duration > CLOCKS_PER_SEC / 2) {
252 r -= 1;
253 duration /= 2;
254 }
255
256 return r;
257}
258
259/*
228 * internal utilities 260 * internal utilities
229 */ 261 */
230static const u_int8_t Base64Code[] = 262static const u_int8_t Base64Code[] =