From owner-svn-src-stable-9@FreeBSD.ORG Mon Jul 21 22:44:07 2014 Return-Path: Delivered-To: svn-src-stable-9@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 7027674A; Mon, 21 Jul 2014 22:44:07 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 5151A2CF8; Mon, 21 Jul 2014 22:44:07 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s6LMi7Jh090622; Mon, 21 Jul 2014 22:44:07 GMT (envelope-from pfg@svn.freebsd.org) Received: (from pfg@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s6LMi6lV090618; Mon, 21 Jul 2014 22:44:06 GMT (envelope-from pfg@svn.freebsd.org) Message-Id: <201407212244.s6LMi6lV090618@svn.freebsd.org> From: "Pedro F. Giffuni" Date: Mon, 21 Jul 2014 22:44:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r268963 - stable/9/lib/libc/gen X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-9@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for only the 9-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Jul 2014 22:44:07 -0000 Author: pfg Date: Mon Jul 21 22:44:06 2014 New Revision: 268963 URL: http://svnweb.freebsd.org/changeset/base/268963 Log: MFC r268642: libc/gen: small updates to code originating at OpenBSD arc4random.c - CVS rev. 1.22 Change arc4random_uniform() to calculate ``2**32 % upper_bound'' as ``-upper_bound % upper_bound''. Simplifies the code and makes it the same on both ILP32 and LP64 architectures, and also slightly faster on LP64 architectures by using a 32-bit remainder instead of a 64-bit remainder. - CVS rev. 1.23 Spacing readpassphrase.c -CVS rev. v 1.24 most obvious unsigned char casts for ctype Obtained from: OpenBSD Modified: stable/9/lib/libc/gen/arc4random.c stable/9/lib/libc/gen/readpassphrase.c Directory Properties: stable/9/lib/libc/ (props changed) Modified: stable/9/lib/libc/gen/arc4random.c ============================================================================== --- stable/9/lib/libc/gen/arc4random.c Mon Jul 21 22:37:33 2014 (r268962) +++ stable/9/lib/libc/gen/arc4random.c Mon Jul 21 22:44:06 2014 (r268963) @@ -1,4 +1,4 @@ -/* $OpenBSD: arc4random.c,v 1.22 2010/12/22 08:23:42 otto Exp $ */ +/* $OpenBSD: arc4random.c,v 1.24 2013/06/11 16:59:50 deraadt Exp $ */ /* * Copyright (c) 1996, David Mazieres @@ -182,8 +182,7 @@ arc4_stir_if_needed(void) { pid_t pid = getpid(); - if (arc4_count <= 0 || !rs_initialized || arc4_stir_pid != pid) - { + if (arc4_count <= 0 || !rs_initialized || arc4_stir_pid != pid) { arc4_stir_pid = pid; arc4_stir(); } @@ -276,18 +275,8 @@ arc4random_uniform(u_int32_t upper_bound if (upper_bound < 2) return 0; -#if (ULONG_MAX > 0xffffffffUL) - min = 0x100000000UL % upper_bound; -#else - /* Calculate (2**32 % upper_bound) avoiding 64-bit math */ - if (upper_bound > 0x80000000) - min = 1 + ~upper_bound; /* 2**32 - upper_bound */ - else { - /* (2**32 - (x * 2)) % x == 2**32 % x when x <= 2**31 */ - min = ((0xffffffff - (upper_bound * 2)) + 1) % upper_bound; - } -#endif - + /* 2**32 % x == (2**32 - x) % x */ + min = -upper_bound % upper_bound; /* * This could theoretically loop forever but each retry has * p > 0.5 (worst case, usually far better) of selecting a Modified: stable/9/lib/libc/gen/readpassphrase.c ============================================================================== --- stable/9/lib/libc/gen/readpassphrase.c Mon Jul 21 22:37:33 2014 (r268962) +++ stable/9/lib/libc/gen/readpassphrase.c Mon Jul 21 22:44:06 2014 (r268963) @@ -1,4 +1,4 @@ -/* $OpenBSD: readpassphrase.c,v 1.23 2010/05/14 13:30:34 millert Exp $ */ +/* $OpenBSD: readpassphrase.c,v 1.24 2013/11/24 23:51:29 deraadt Exp $ */ /* * Copyright (c) 2000-2002, 2007, 2010 @@ -122,11 +122,11 @@ restart: if (p < end) { if ((flags & RPP_SEVENBIT)) ch &= 0x7f; - if (isalpha(ch)) { + if (isalpha((unsigned char)ch)) { if ((flags & RPP_FORCELOWER)) - ch = (char)tolower(ch); + ch = (char)tolower((unsigned char)ch); if ((flags & RPP_FORCEUPPER)) - ch = (char)toupper(ch); + ch = (char)toupper((unsigned char)ch); } *p++ = ch; }