lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <53945633.20702@redhat.com>
Date:	Sun, 08 Jun 2014 14:25:23 +0200
From:	Daniel Borkmann <dborkman@...hat.com>
To:	George Spelvin <linux@...izon.com>
CC:	davem@...emloft.net, shemminger@...l.org, tytso@....edu,
	linux-kernel@...r.kernel.org, hannes@...essinduktion.org
Subject: Re: [PATCH 4/7] lib/random32.c: Use <asm/unaligned.h> instead of
 hand-rolling it

On 06/07/2014 10:25 AM, George Spelvin wrote:
> The functions exist for a reason; the manual byte-at-a-time code
> is unnecessarily slow (and bloated).
>
> Signed-off-by: George Spelvin <linux@...izon.com>

Seems fine by me, since it's random anyway archs might not care
about the *_le32, though this might yield additional work in some
cases I presume.

> ---
>   lib/random32.c | 23 +++++++++++------------
>   1 file changed, 11 insertions(+), 12 deletions(-)
>
> diff --git a/lib/random32.c b/lib/random32.c
> index e8f3557b..eee60100 100644
> --- a/lib/random32.c
> +++ b/lib/random32.c
> @@ -37,6 +37,7 @@
>   #include <linux/jiffies.h>
>   #include <linux/random.h>
>   #include <linux/sched.h>
> +#include <asm/unaligned.h>
>
>   #ifdef CONFIG_RANDOM32_SELFTEST
>   static void __init prandom_state_selftest(void);
> @@ -97,25 +98,23 @@ EXPORT_SYMBOL(prandom_u32);
>    */
>   void prandom_bytes_state(struct rnd_state *state, void *buf, int bytes)
>   {
> -	unsigned char *p = buf;
> +	u8 *p = buf;
>   	int i;
>
> -	for (i = 0; i < round_down(bytes, sizeof(u32)); i += sizeof(u32)) {
> -		u32 random = prandom_u32_state(state);
> -		int j;
> +	for (i = 0; i < round_down(bytes, sizeof(u32)); i += sizeof(u32))
> +		put_unaligned_le32(prandom_u32_state(state), p+i);

Nit: 'p + i'

>
> -		for (j = 0; j < sizeof(u32); j++) {
> -			p[i + j] = random;
> -			random >>= BITS_PER_BYTE;
> -		}
> -	}
>   	if (i < bytes) {
>   		u32 random = prandom_u32_state(state);
>
> -		for (; i < bytes; i++) {
> -			p[i] = random;
> -			random >>= BITS_PER_BYTE;
> +		if (bytes & 2) {
> +			put_unaligned_le16((u16)random, p+i);

Ditto.

> +			if ((bytes & 1) == 0)
> +				return;
> +			i += 2;
> +			random >>= 16;
>   		}
> +		p[i] = (u8)random;

Nit: '(u8) random'

You could probably use a switch statement with fall-through for
filling the remaining stuff, might simplify it further, perhaps.

>   	}
>   }
>   EXPORT_SYMBOL(prandom_bytes_state);
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ