summaryrefslogtreecommitdiff
path: root/src/lib/libc/crypt/cryptutil.c
diff options
context:
space:
mode:
authortedu <>2014-11-17 16:47:28 +0000
committertedu <>2014-11-17 16:47:28 +0000
commit1d73abd6ebdd0b8188330f94e644727d86b1d336 (patch)
treef8c67ffae926873c4b6b8eb4d6a4dc43ef63d29c /src/lib/libc/crypt/cryptutil.c
parentd6b346577efe94c30d6ba08ca7f8feae71688a3c (diff)
downloadopenbsd-1d73abd6ebdd0b8188330f94e644727d86b1d336.tar.gz
openbsd-1d73abd6ebdd0b8188330f94e644727d86b1d336.tar.bz2
openbsd-1d73abd6ebdd0b8188330f94e644727d86b1d336.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 'src/lib/libc/crypt/cryptutil.c')
-rw-r--r--src/lib/libc/crypt/cryptutil.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/lib/libc/crypt/cryptutil.c b/src/lib/libc/crypt/cryptutil.c
index 36deda778e..4a8c46be49 100644
--- a/src/lib/libc/crypt/cryptutil.c
+++ b/src/lib/libc/crypt/cryptutil.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: cryptutil.c,v 1.1 2014/05/12 19:13:14 tedu Exp $ */ 1/* $OpenBSD: cryptutil.c,v 1.2 2014/11/17 16:47:28 tedu Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Ted Unangst <tedu@openbsd.org> 3 * Copyright (c) 2014 Ted Unangst <tedu@openbsd.org>
4 * 4 *
@@ -18,6 +18,7 @@
18#include <unistd.h> 18#include <unistd.h>
19#include <string.h> 19#include <string.h>
20#include <pwd.h> 20#include <pwd.h>
21#include <login_cap.h>
21#include <errno.h> 22#include <errno.h>
22 23
23int 24int
@@ -52,3 +53,30 @@ fail:
52 errno = EACCES; 53 errno = EACCES;
53 return -1; 54 return -1;
54} 55}
56
57int
58crypt_newhash(const char *pass, login_cap_t *lc, char *hash, size_t hashlen)
59{
60 int rv = -1;
61 char *pref;
62 char *defaultpref = "blowfish,8";
63 const char *errstr;
64 int rounds;
65
66 if (lc == NULL ||
67 (pref = login_getcapstr(lc, "localcipher", NULL, NULL)) == NULL)
68 pref = defaultpref;
69 if (strncmp(pref, "blowfish,", 9) != 0) {
70 errno = EINVAL;
71 goto err;
72 }
73 rounds = strtonum(pref + 9, 4, 31, &errstr);
74 if (errstr)
75 goto err;
76 rv = bcrypt_newhash(pass, rounds, hash, hashlen);
77
78err:
79 if (pref != defaultpref)
80 free(pref);
81 return rv;
82}