summaryrefslogtreecommitdiff
path: root/src/lib/libc/crypt
diff options
context:
space:
mode:
authortedu <>2015-07-23 22:19:03 +0000
committertedu <>2015-07-23 22:19:03 +0000
commitb0a4e3250103e15fb19435a32d84c8adcd24e008 (patch)
tree8f8eb62831121f52db9afbde95f95d3a6fc0461e /src/lib/libc/crypt
parentf172031c7c6d9ab690706ae078322d7db8f6f19e (diff)
downloadopenbsd-b0a4e3250103e15fb19435a32d84c8adcd24e008.tar.gz
openbsd-b0a4e3250103e15fb19435a32d84c8adcd24e008.tar.bz2
openbsd-b0a4e3250103e15fb19435a32d84c8adcd24e008.zip
permit "bcrypt" as an alias for "blowfish". this is, after all, what
99% of the world calls it. allow just "bcrypt" without params to mean auto-tune ("bcrypt,a"). default remains 8 rounds (for now) ok deraadt
Diffstat (limited to 'src/lib/libc/crypt')
-rw-r--r--src/lib/libc/crypt/cryptutil.c38
1 files changed, 27 insertions, 11 deletions
diff --git a/src/lib/libc/crypt/cryptutil.c b/src/lib/libc/crypt/cryptutil.c
index 75c48c52f7..d750933ffb 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.9 2015/02/24 19:19:32 tedu Exp $ */ 1/* $OpenBSD: cryptutil.c,v 1.10 2015/07/23 22:19:03 tedu Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Ted Unangst <tedu@openbsd.org> 3 * Copyright (c) 2014 Ted Unangst <tedu@openbsd.org>
4 * 4 *
@@ -57,23 +57,39 @@ crypt_newhash(const char *pass, const char *pref, char *hash, size_t hashlen)
57 int rv = -1; 57 int rv = -1;
58 const char *defaultpref = "blowfish,8"; 58 const char *defaultpref = "blowfish,8";
59 const char *errstr; 59 const char *errstr;
60 const char *choices[] = { "blowfish", "bcrypt" };
61 size_t maxchoice = sizeof(choices) / sizeof(choices[0]);
62 int i;
60 int rounds; 63 int rounds;
61 64
62 if (pref == NULL) 65 if (pref == NULL)
63 pref = defaultpref; 66 pref = defaultpref;
64 if (strncmp(pref, "blowfish,", 9) != 0) { 67
68 for (i = 0; i < maxchoice; i++) {
69 const char *choice = choices[i];
70 size_t len = strlen(choice);
71 if (strcmp(pref, choice) == 0) {
72 rounds = bcrypt_autorounds();
73 break;
74 } else if (strncmp(pref, choice, len) == 0 &&
75 pref[len] == ',') {
76 if (strcmp(pref + len + 1, "a") == 0) {
77 rounds = bcrypt_autorounds();
78 } else {
79 rounds = strtonum(pref + len + 1, 4, 31, &errstr);
80 if (errstr) {
81 errno = EINVAL;
82 goto err;
83 }
84 }
85 break;
86 }
87 }
88 if (i == maxchoice) {
65 errno = EINVAL; 89 errno = EINVAL;
66 goto err; 90 goto err;
67 } 91 }
68 if (strcmp(pref + 9, "a") == 0) { 92
69 rounds = bcrypt_autorounds();
70 } else {
71 rounds = strtonum(pref + 9, 4, 31, &errstr);
72 if (errstr) {
73 errno = EINVAL;
74 goto err;
75 }
76 }
77 rv = bcrypt_newhash(pass, rounds, hash, hashlen); 93 rv = bcrypt_newhash(pass, rounds, hash, hashlen);
78 94
79err: 95err: