summaryrefslogtreecommitdiff
path: root/lib/libc/crypt
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2015-07-23 22:19:04 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2015-07-23 22:19:04 +0000
commitc0a16205f81eae5a687f01ee5742e3da7330b701 (patch)
tree00c44cf9fafcd22f3dffb96d1aae83c4aa8ed5a6 /lib/libc/crypt
parentf6adf479880f83bfaf3688a47078476e44d7fdf6 (diff)
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 'lib/libc/crypt')
-rw-r--r--lib/libc/crypt/cryptutil.c38
1 files changed, 27 insertions, 11 deletions
diff --git a/lib/libc/crypt/cryptutil.c b/lib/libc/crypt/cryptutil.c
index 75c48c52f7e..d750933ffb4 100644
--- a/lib/libc/crypt/cryptutil.c
+++ b/lib/libc/crypt/cryptutil.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cryptutil.c,v 1.9 2015/02/24 19:19:32 tedu Exp $ */
+/* $OpenBSD: cryptutil.c,v 1.10 2015/07/23 22:19:03 tedu Exp $ */
/*
* Copyright (c) 2014 Ted Unangst <tedu@openbsd.org>
*
@@ -57,23 +57,39 @@ crypt_newhash(const char *pass, const char *pref, char *hash, size_t hashlen)
int rv = -1;
const char *defaultpref = "blowfish,8";
const char *errstr;
+ const char *choices[] = { "blowfish", "bcrypt" };
+ size_t maxchoice = sizeof(choices) / sizeof(choices[0]);
+ int i;
int rounds;
if (pref == NULL)
pref = defaultpref;
- if (strncmp(pref, "blowfish,", 9) != 0) {
+
+ for (i = 0; i < maxchoice; i++) {
+ const char *choice = choices[i];
+ size_t len = strlen(choice);
+ if (strcmp(pref, choice) == 0) {
+ rounds = bcrypt_autorounds();
+ break;
+ } else if (strncmp(pref, choice, len) == 0 &&
+ pref[len] == ',') {
+ if (strcmp(pref + len + 1, "a") == 0) {
+ rounds = bcrypt_autorounds();
+ } else {
+ rounds = strtonum(pref + len + 1, 4, 31, &errstr);
+ if (errstr) {
+ errno = EINVAL;
+ goto err;
+ }
+ }
+ break;
+ }
+ }
+ if (i == maxchoice) {
errno = EINVAL;
goto err;
}
- if (strcmp(pref + 9, "a") == 0) {
- rounds = bcrypt_autorounds();
- } else {
- rounds = strtonum(pref + 9, 4, 31, &errstr);
- if (errstr) {
- errno = EINVAL;
- goto err;
- }
- }
+
rv = bcrypt_newhash(pass, rounds, hash, hashlen);
err: