From patchwork Tue Aug 16 09:07:23 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: George Spelvin X-Patchwork-Id: 110161 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 2C2DDB6F6F for ; Tue, 16 Aug 2011 19:07:31 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751862Ab1HPJHZ (ORCPT ); Tue, 16 Aug 2011 05:07:25 -0400 Received: from science.horizon.com ([71.41.210.146]:60134 "HELO science.horizon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1751824Ab1HPJHZ (ORCPT ); Tue, 16 Aug 2011 05:07:25 -0400 Received: (qmail 18493 invoked by uid 1000); 16 Aug 2011 05:07:23 -0400 Date: 16 Aug 2011 05:07:23 -0400 Message-ID: <20110816090723.18492.qmail@science.horizon.com> From: "George Spelvin" To: davem@davemloft.net Subject: get_random_int() should use hash[1] Cc: linux@horizon.com, netdev@vger.kernel.org Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Re: commit e997d47bff5a467262ef224b4cf8cbba2d3eceea As long as you're using MD5, you should know that each round only modifies one word of the state. The order is [0], [3], [2], [1], repeating 64 times. Thus, on output, word [1] is the "most hashed" word. If you really wanted word [0], you could just skip the last 3 rounds. It's not really critical, but as long as you're performing the rounds, you might as well use them... Me, I'd also put jiffies and get_cycles into different words just on general principles, but that's up to you: - hash[0] += current->pid + jiffies + get_cycles(); + hash[1] += current->pid + jiffies; + hash[2] += get_cycles(); --- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- drivers/char/random.c.1 2011-08-16 05:02:09.000000000 -0400 +++ drivers/char/random.c.2 2011-08-16 05:02:43.000000000 -0400 @@ -1323,7 +1323,7 @@ hash[0] += current->pid + jiffies + get_cycles(); md5_transform(hash, random_int_secret); - ret = hash[0]; + ret = hash[1]; put_cpu_var(get_random_int_hash); return ret;