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: <20171215053401.GH21978@ZenIV.linux.org.uk>
Date:   Fri, 15 Dec 2017 05:34:01 +0000
From:   Al Viro <viro@...IV.linux.org.uk>
To:     Jakub Kicinski <kubakici@...pl>
Cc:     Linus Torvalds <torvalds@...ux-foundation.org>,
        netdev@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [RFC][PATCH] Add primitives for manipulating bitfields both in
 host- and fixed-endian.

On Thu, Dec 14, 2017 at 09:07:13PM -0800, Jakub Kicinski wrote:
> Looks great to me!
> 
> On Fri, 15 Dec 2017 02:33:43 +0000, Al Viro wrote:
> > The following primitives are defined in linux/bitfield.h:
> > 
> > * u32 le32_get_bits(__le32 val, u32 field) extracts the contents of the
> >   bitfield specified by @field in little-endian 32bit value @val and
> >   converts it to host-endian.
> > 
> > * void le32p_replace_bits(__le32 *p, u32 v, u32 field) replaces
> >   the contents of the bitfield specified by @field in little-endian
> >   32bit object pointet to by *p with the value of @v.  New value is
> >   given in host-endian and stored as little-endian.
> > 
> > * __le32 le32_replace_bits(__le32 old, u32 v, u32 field) is equivalent to
> >   ({__le32 tmp = old; le32p_replace_bits(&old, v, field); tmp;})
> >   In other words, instead of modifying an object in memory, it takes
> >   the initial value and returns the modified one.
> 
> the current macros take filed/mask as first param, not sure if it's
> worth maintaining the order

Umm...  For something like Haskell that would be more natural (as in
replace_foo = replace_field foo), but it's C - no partially applied
functions here...

While we are at it, to cover the FIELD_PREP users it might make sense to
add

__le32 le32_encode_bits(u32 v, u32 field)
{
        if (__builtin_constant_p(v) &&
                    (v & ~(field/mask_to_multiplier(field))))
                                    __field_overflow();
	return cpu_to_le32((v * mask_to_multiplier(field)) & field);
}

turning the body of le32_replace_bits into
	return (old & ~cpu_to_le32(field)) | le32_encode_bits(v, field);

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ