Browse Source

Test the upper limit for the max # of rounds to, to avoid wrapping and ending

up with a low number of rounds. Spotted by mpech@; ok mpech@ millert@
OPENBSD_3_7
otto 20 years ago
parent
commit
4bcb70b1fc
1 changed files with 7 additions and 2 deletions
  1. +7
    -2
      src/lib/libc/crypt/bcrypt.c

+ 7
- 2
src/lib/libc/crypt/bcrypt.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: bcrypt.c,v 1.18 2003/08/07 00:28:45 deraadt Exp $ */
/* $OpenBSD: bcrypt.c,v 1.19 2004/12/22 17:33:25 otto Exp $ */
/* /*
* Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de> * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
@ -164,6 +164,8 @@ bcrypt_gensalt(u_int8_t log_rounds)
if (log_rounds < 4) if (log_rounds < 4)
log_rounds = 4; log_rounds = 4;
else if (log_rounds > 31)
log_rounds = 31;
encode_salt(gsalt, csalt, BCRYPT_MAXSALT, log_rounds); encode_salt(gsalt, csalt, BCRYPT_MAXSALT, log_rounds);
return gsalt; return gsalt;
@ -212,7 +214,10 @@ bcrypt(const char *key, const char *salt)
return error; return error;
/* Computer power doesn't increase linear, 2^x should be fine */ /* Computer power doesn't increase linear, 2^x should be fine */
if ((rounds = (u_int32_t) 1 << (logr = atoi(salt))) < BCRYPT_MINROUNDS)
logr = atoi(salt);
if (logr > 31)
return error;
if ((rounds = (u_int32_t) 1 << logr) < BCRYPT_MINROUNDS)
return error; return error;
/* Discard num rounds + "$" identifier */ /* Discard num rounds + "$" identifier */


Loading…
Cancel
Save