diff options
| author | nia <nia@NetBSD.org> | 2021-10-29 13:22:08 +0000 |
|---|---|---|
| committer | nia <nia@NetBSD.org> | 2021-10-29 13:22:08 +0000 |
| commit | b9d0fd49ae7fde92e8341bda86272f7a7155d436 (patch) | |
| tree | 7ad5988dc9c51d07d390ba993af32ae0e2be4ea7 /lib/libcrypt | |
| parent | 1cc516410767d9988778e409b7801a63eaf1f5ac (diff) | |
libcrypt: Fix a floating point exception when a low number of HMAC-SHA1
iterations are specified.
Diffstat (limited to 'lib/libcrypt')
| -rw-r--r-- | lib/libcrypt/crypt-sha1.c | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/lib/libcrypt/crypt-sha1.c b/lib/libcrypt/crypt-sha1.c index a307d33fad7..db9edf1ba45 100644 --- a/lib/libcrypt/crypt-sha1.c +++ b/lib/libcrypt/crypt-sha1.c @@ -1,4 +1,4 @@ -/* $NetBSD: crypt-sha1.c,v 1.9 2021/10/16 10:53:33 nia Exp $ */ +/* $NetBSD: crypt-sha1.c,v 1.10 2021/10/29 13:22:08 nia Exp $ */ /* * Copyright (c) 2004, Juniper Networks, Inc. @@ -31,7 +31,7 @@ #include <sys/cdefs.h> #if !defined(lint) -__RCSID("$NetBSD: crypt-sha1.c,v 1.9 2021/10/16 10:53:33 nia Exp $"); +__RCSID("$NetBSD: crypt-sha1.c,v 1.10 2021/10/29 13:22:08 nia Exp $"); #endif /* not lint */ #include <stdlib.h> @@ -71,24 +71,15 @@ __RCSID("$NetBSD: crypt-sha1.c,v 1.9 2021/10/16 10:53:33 nia Exp $"); crypt_private unsigned int __crypt_sha1_iterations (unsigned int hint) { - static int once = 1; - /* * We treat CRYPT_SHA1_ITERATIONS as a hint. * Make it harder for someone to pre-compute hashes for a * dictionary attack by not using the same iteration count for * every entry. */ - - if (once) { - int pid = getpid(); - - srandom(time(NULL) ^ (pid * pid)); - once = 0; - } - if (hint == 0) + if (hint < 4) hint = CRYPT_SHA1_ITERATIONS; - return hint - (random() % (hint / 4)); + return hint - arc4random_uniform(hint / 4); } /* |
