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  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]
Date:   Fri, 24 Mar 2017 17:16:44 +0000
From:   David Laight <David.Laight@...LAB.COM>
To:     'Alexey Dobriyan' <adobriyan@...il.com>,
        "steffen.klassert@...unet.com" <steffen.klassert@...unet.com>
CC:     "herbert@...dor.apana.org.au" <herbert@...dor.apana.org.au>,
        "davem@...emloft.net" <davem@...emloft.net>,
        "netdev@...r.kernel.org" <netdev@...r.kernel.org>
Subject: RE: [PATCH] xfrm: branchless addr4_match() on 64-bit

From: Alexey Dobriyan
> Sent: 23 March 2017 23:33
> Current addr4_match() code has special test for /0 prefixes because of
> standard required undefined behaviour. However, it is possible to omit
> it on 64-bit because shifting can be done in a 64-bit register and then
> truncated to the expected value (which is 0 mask).
> 
> Implicit truncation by htonl() fits nicely into R32-within-R64 model
> on x86-64.
...
>  static inline bool addr4_match(__be32 a1, __be32 a2, u8 prefixlen)
>  {
> +#ifdef CONFIG_64BIT
> +	/* L in UL is not a typo. */
> +	return !((a1 ^ a2) & htonl(~0UL << (32 - prefixlen)));
> +#else
>  	/* C99 6.5.7 (3): u32 << 32 is undefined behaviour */
>  	if (prefixlen == 0)
>  		return true;
>  	return !((a1 ^ a2) & htonl(0xFFFFFFFFu << (32 - prefixlen)));
> +#endif

Can't this just be written:

  	if (sizeof (long) == 4 && prefixlen == 0)
  		return true;
	return !((a1 ^ a2) & htonl(0xFFFFFFFFUL << (32 - prefixlen)));

	David

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux - Powered by OpenVZ