diff options
author | tedu <> | 2014-02-24 19:45:43 +0000 |
---|---|---|
committer | tedu <> | 2014-02-24 19:45:43 +0000 |
commit | 243b9a0d1fb598b3c607d0e28050b90ad6ea19e9 (patch) | |
tree | 15f5f6c9290dd6ebb42d77c1a206602abf27656a /src/lib/libc/crypt | |
parent | fc9cdf81c5d40102231f7514d66658f928139594 (diff) | |
download | openbsd-243b9a0d1fb598b3c607d0e28050b90ad6ea19e9.tar.gz openbsd-243b9a0d1fb598b3c607d0e28050b90ad6ea19e9.tar.bz2 openbsd-243b9a0d1fb598b3c607d0e28050b90ad6ea19e9.zip |
solar's testsuite revealed insufficient validation of invalid input hashes.
add a more complete check for the rounds parameter. ok deraadt
Diffstat (limited to 'src/lib/libc/crypt')
-rw-r--r-- | src/lib/libc/crypt/bcrypt.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/lib/libc/crypt/bcrypt.c b/src/lib/libc/crypt/bcrypt.c index 7e283c43f1..b108cfe04c 100644 --- a/src/lib/libc/crypt/bcrypt.c +++ b/src/lib/libc/crypt/bcrypt.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bcrypt.c,v 1.28 2014/02/17 09:00:20 tedu Exp $ */ | 1 | /* $OpenBSD: bcrypt.c,v 1.29 2014/02/24 19:45:43 tedu Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de> | 4 | * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de> |
@@ -60,7 +60,7 @@ | |||
60 | #define BCRYPT_VERSION '2' | 60 | #define BCRYPT_VERSION '2' |
61 | #define BCRYPT_MAXSALT 16 /* Precomputation is just so nice */ | 61 | #define BCRYPT_MAXSALT 16 /* Precomputation is just so nice */ |
62 | #define BCRYPT_BLOCKS 6 /* Ciphertext blocks */ | 62 | #define BCRYPT_BLOCKS 6 /* Ciphertext blocks */ |
63 | #define BCRYPT_MINROUNDS 16 /* we have log2(rounds) in salt */ | 63 | #define BCRYPT_MINLOGROUNDS 4 /* we have log2(rounds) in salt */ |
64 | 64 | ||
65 | char *bcrypt_gensalt(u_int8_t); | 65 | char *bcrypt_gensalt(u_int8_t); |
66 | 66 | ||
@@ -173,7 +173,7 @@ bcrypt(const char *key, const char *salt) | |||
173 | u_int8_t ciphertext[4 * BCRYPT_BLOCKS] = "OrpheanBeholderScryDoubt"; | 173 | u_int8_t ciphertext[4 * BCRYPT_BLOCKS] = "OrpheanBeholderScryDoubt"; |
174 | u_int8_t csalt[BCRYPT_MAXSALT]; | 174 | u_int8_t csalt[BCRYPT_MAXSALT]; |
175 | u_int32_t cdata[BCRYPT_BLOCKS]; | 175 | u_int32_t cdata[BCRYPT_BLOCKS]; |
176 | int n; | 176 | char arounds[3]; |
177 | 177 | ||
178 | /* Discard "$" identifier */ | 178 | /* Discard "$" identifier */ |
179 | salt++; | 179 | salt++; |
@@ -204,13 +204,15 @@ bcrypt(const char *key, const char *salt) | |||
204 | /* Out of sync with passwd entry */ | 204 | /* Out of sync with passwd entry */ |
205 | return error; | 205 | return error; |
206 | 206 | ||
207 | /* Computer power doesn't increase linear, 2^x should be fine */ | 207 | memcpy(arounds, salt, sizeof(arounds)); |
208 | n = atoi(salt); | 208 | if (arounds[sizeof(arounds) - 1] != '$') |
209 | if (n > 31 || n < 0) | ||
210 | return error; | 209 | return error; |
211 | logr = (u_int8_t)n; | 210 | arounds[sizeof(arounds) - 1] = 0; |
212 | if ((rounds = (u_int32_t) 1 << logr) < BCRYPT_MINROUNDS) | 211 | logr = strtonum(arounds, BCRYPT_MINLOGROUNDS, 31, NULL); |
212 | if (logr == 0) | ||
213 | return error; | 213 | return error; |
214 | /* Computer power doesn't increase linearly, 2^x should be fine */ | ||
215 | rounds = 1U << logr; | ||
214 | 216 | ||
215 | /* Discard num rounds + "$" identifier */ | 217 | /* Discard num rounds + "$" identifier */ |
216 | salt += 3; | 218 | salt += 3; |