diff options
| author | tedu <> | 2015-07-23 22:19:03 +0000 |
|---|---|---|
| committer | tedu <> | 2015-07-23 22:19:03 +0000 |
| commit | e217f2cd00e15d8c7e2b29f02062884a4f6f298b (patch) | |
| tree | 8f8eb62831121f52db9afbde95f95d3a6fc0461e /src/lib/libc/crypt/cryptutil.c | |
| parent | 5b19a92414247f404fe068ef6515cf739568e936 (diff) | |
| download | openbsd-e217f2cd00e15d8c7e2b29f02062884a4f6f298b.tar.gz openbsd-e217f2cd00e15d8c7e2b29f02062884a4f6f298b.tar.bz2 openbsd-e217f2cd00e15d8c7e2b29f02062884a4f6f298b.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 '')
| -rw-r--r-- | src/lib/libc/crypt/cryptutil.c | 38 |
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 | ||
| 79 | err: | 95 | err: |
