From owner-svn-src-stable@FreeBSD.ORG Wed Jan 7 11:44:03 2009 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B962510656F5; Wed, 7 Jan 2009 11:44:03 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id A5B9E8FC18; Wed, 7 Jan 2009 11:44:03 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n07Bi382084744; Wed, 7 Jan 2009 11:44:03 GMT (envelope-from mav@svn.freebsd.org) Received: (from mav@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n07Bi3A3084743; Wed, 7 Jan 2009 11:44:03 GMT (envelope-from mav@svn.freebsd.org) Message-Id: <200901071144.n07Bi3A3084743@svn.freebsd.org> From: Alexander Motin Date: Wed, 7 Jan 2009 11:44:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org X-SVN-Group: stable-7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r186857 - in stable/7/sys: . contrib/pf crypto/rc4 dev/cxgb X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Jan 2009 11:44:04 -0000 Author: mav Date: Wed Jan 7 11:44:03 2009 New Revision: 186857 URL: http://svn.freebsd.org/changeset/base/186857 Log: MFC rev. 186179: Avoid 256 integer divisions per rc4_init() call. Replace it with using separate index variable. It gives more then double rc4_init() performance increase on tested i386 P4. It also gives about 15% speedup to PPTP VPN with stateless MPPE encryption (by ng_mppc) which calls rc4_init() for every packet. Modified: stable/7/sys/ (props changed) stable/7/sys/contrib/pf/ (props changed) stable/7/sys/crypto/rc4/rc4.c stable/7/sys/dev/cxgb/ (props changed) Modified: stable/7/sys/crypto/rc4/rc4.c ============================================================================== --- stable/7/sys/crypto/rc4/rc4.c Wed Jan 7 11:19:18 2009 (r186856) +++ stable/7/sys/crypto/rc4/rc4.c Wed Jan 7 11:44:03 2009 (r186857) @@ -61,7 +61,7 @@ void rc4_init(struct rc4_state *const state, const u_char *key, int keylen) { u_char j; - int i; + int i, k; /* Initialize state with identity permutation */ for (i = 0; i < 256; i++) @@ -70,9 +70,11 @@ rc4_init(struct rc4_state *const state, state->index2 = 0; /* Randomize the permutation using key data */ - for (j = i = 0; i < 256; i++) { - j += state->perm[i] + key[i % keylen]; + for (j = i = k = 0; i < 256; i++) { + j += state->perm[i] + key[k]; swap_bytes(&state->perm[i], &state->perm[j]); + if (++k >= keylen) + k = 0; } }