diff options
author | 2014-11-17 16:47:28 +0000 | |
---|---|---|
committer | 2014-11-17 16:47:28 +0000 | |
commit | dee4fe2a8a53c91ad298be944666f07f94dc5f6f (patch) | |
tree | 438e821bf152ebc26a06652aa1e12ed760614519 /lib/libc/crypt/cryptutil.c | |
parent | Add quirks for the "Realtek ALC885" found on MacMini3.1, unmutes the (diff) | |
download | wireguard-openbsd-dee4fe2a8a53c91ad298be944666f07f94dc5f6f.tar.xz wireguard-openbsd-dee4fe2a8a53c91ad298be944666f07f94dc5f6f.zip |
add new function crypt_newhash to simplify creating new hashes.
does most of the work pwd_gensalt did, but also creates the hash.
(unused yet)
Diffstat (limited to 'lib/libc/crypt/cryptutil.c')
-rw-r--r-- | lib/libc/crypt/cryptutil.c | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/lib/libc/crypt/cryptutil.c b/lib/libc/crypt/cryptutil.c index 36deda778e4..4a8c46be49d 100644 --- a/lib/libc/crypt/cryptutil.c +++ b/lib/libc/crypt/cryptutil.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cryptutil.c,v 1.1 2014/05/12 19:13:14 tedu Exp $ */ +/* $OpenBSD: cryptutil.c,v 1.2 2014/11/17 16:47:28 tedu Exp $ */ /* * Copyright (c) 2014 Ted Unangst <tedu@openbsd.org> * @@ -18,6 +18,7 @@ #include <unistd.h> #include <string.h> #include <pwd.h> +#include <login_cap.h> #include <errno.h> int @@ -52,3 +53,30 @@ fail: errno = EACCES; return -1; } + +int +crypt_newhash(const char *pass, login_cap_t *lc, char *hash, size_t hashlen) +{ + int rv = -1; + char *pref; + char *defaultpref = "blowfish,8"; + const char *errstr; + int rounds; + + if (lc == NULL || + (pref = login_getcapstr(lc, "localcipher", NULL, NULL)) == NULL) + pref = defaultpref; + if (strncmp(pref, "blowfish,", 9) != 0) { + errno = EINVAL; + goto err; + } + rounds = strtonum(pref + 9, 4, 31, &errstr); + if (errstr) + goto err; + rv = bcrypt_newhash(pass, rounds, hash, hashlen); + +err: + if (pref != defaultpref) + free(pref); + return rv; +} |