summaryrefslogtreecommitdiffstats
path: root/lib/libc/crypt/cryptutil.c
diff options
context:
space:
mode:
authortedu <tedu@openbsd.org>2014-12-30 10:27:24 +0000
committertedu <tedu@openbsd.org>2014-12-30 10:27:24 +0000
commite08a42f854de4914aeb357f2b6cd9c7274f05e75 (patch)
tree222b45b541c74e946ea138eb39d86a05a50eaafb /lib/libc/crypt/cryptutil.c
parentlet the "make groff" maintainer target show groff warnings (diff)
downloadwireguard-openbsd-e08a42f854de4914aeb357f2b6cd9c7274f05e75.tar.xz
wireguard-openbsd-e08a42f854de4914aeb357f2b6cd9c7274f05e75.zip
copy bcrypt autotune from encrypt(1) and expose via crypt_newhash
ok deraadt miod
Diffstat (limited to 'lib/libc/crypt/cryptutil.c')
-rw-r--r--lib/libc/crypt/cryptutil.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/libc/crypt/cryptutil.c b/lib/libc/crypt/cryptutil.c
index f101240524e..7e93dad3c80 100644
--- a/lib/libc/crypt/cryptutil.c
+++ b/lib/libc/crypt/cryptutil.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cryptutil.c,v 1.6 2014/12/24 22:10:34 tedu Exp $ */
+/* $OpenBSD: cryptutil.c,v 1.7 2014/12/30 10:27:24 tedu Exp $ */
/*
* Copyright (c) 2014 Ted Unangst <tedu@openbsd.org>
*
@@ -21,6 +21,8 @@
#include <login_cap.h>
#include <errno.h>
+int bcrypt_autorounds(void);
+
int
crypt_checkpass(const char *pass, const char *goodhash)
{
@@ -64,9 +66,13 @@ crypt_newhash(const char *pass, const char *pref, char *hash, size_t hashlen)
errno = EINVAL;
goto err;
}
- rounds = strtonum(pref + 9, 4, 31, &errstr);
- if (errstr)
- goto err;
+ if (strcmp(pref + 9, "a") == 0) {
+ rounds = bcrypt_autorounds();
+ } else {
+ rounds = strtonum(pref + 9, 4, 31, &errstr);
+ if (errstr)
+ goto err;
+ }
rv = bcrypt_newhash(pass, rounds, hash, hashlen);
err: