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: <aQtbmWLqtFXvT8Bc@smile.fi.intel.com>
Date: Wed, 5 Nov 2025 16:13:45 +0200
From: Andy Shevchenko <andriy.shevchenko@...el.com>
To: David Laight <david.laight.linux@...il.com>
Cc: Kuan-Wei Chiu <visitorckw@...il.com>,
	Guan-Chun Wu <409411716@....tku.edu.tw>,
	Andrew Morton <akpm@...ux-foundation.org>, ebiggers@...nel.org,
	tytso@....edu, jaegeuk@...nel.org, xiubli@...hat.com,
	idryomov@...il.com, kbusch@...nel.org, axboe@...nel.dk, hch@....de,
	sagi@...mberg.me, home7438072@...il.com,
	linux-nvme@...ts.infradead.org, linux-fscrypt@...r.kernel.org,
	ceph-devel@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v4 0/6] lib/base64: add generic encoder/decoder, migrate
 users

On Wed, Nov 05, 2025 at 09:48:27AM +0000, David Laight wrote:
> On Tue, 4 Nov 2025 11:48:57 +0200
> Andy Shevchenko <andriy.shevchenko@...el.com> wrote:
> > On Tue, Nov 04, 2025 at 09:03:26AM +0000, David Laight wrote:
> > > On Mon, 3 Nov 2025 19:07:24 +0800
> > > Kuan-Wei Chiu <visitorckw@...il.com> wrote:  
> > > > On Mon, Nov 03, 2025 at 11:24:35AM +0100, Andy Shevchenko wrote:  

...

> > > > Since I believe many people test and care about W=1 builds, I think we
> > > > need to find another way to avoid this warning? Perhaps we could
> > > > consider what you suggested:
> > > > 
> > > > #define BASE64_REV_INIT(val_plus, val_comma, val_minus, val_slash, val_under) { \
> > > > 	[ 0 ... '+'-1 ] = -1, \
> > > > 	[ '+' ] = val_plus, val_comma, val_minus, -1, val_slash, \
> > > > 	[ '0' ] = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, \
> > > > 	[ '9'+1 ... 'A'-1 ] = -1, \
> > > > 	[ 'A' ] = 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, \
> > > > 		  23, 24, 25, 26, 27, 28, 28, 30, 31, 32, 33, 34, 35, \
> > > > 	[ 'Z'+1 ... '_'-1 ] = -1, \
> > > > 	[ '_' ] = val_under, \
> > > > 	[ '_'+1 ... 'a'-1 ] = -1, \
> > > > 	[ 'a' ] = 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, \
> > > > 		  49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, \
> > > > 	[ 'z'+1 ... 255 ] = -1 \
> > > > }  
> > > 
> > > I've a slightly better version:
> > > 
> > > #define INIT_62_63(ch, ch_62, ch_63) \
> > > 	[ ch ] = ch == ch_62 ? 62 : ch == ch_63 ? 63 : -1
> > > 
> > > #define BASE64_REV_INIT(ch_62, ch_63) { \
> > > 	[ 0 ... '0' - 6 ] = -1, \
> > > 	INIT_62_63('+', ch_62, ch_63), \
> > > 	INIT_62_63(',', ch_62, ch_63), \
> > > 	INIT_62_63('-', ch_62, ch_63), \
> > > 	INIT_62_63('.', ch_62, ch_63), \
> > > 	INIT_62_63('/', ch_62, ch_63), \
> > > 	[ '0' ] = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, \
> > > 	[ '9' + 1 ... 'A' - 1 ] = -1, \
> > > 	[ 'A' ] = 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, \
> > > 		  23, 24, 25, 26, 27, 28, 28, 30, 31, 32, 33, 34, 35, \
> > > 	[ 'Z' + 1 ... '_' - 1 ] = -1, \
> > > 	INIT_62_63('_', ch_62, ch_63), \
> > > 	[ '_' + 1 ... 'a' - 1 ] = -1, \
> > > 	[ 'a' ] = 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, \
> > > 		  49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, \
> > > 	[ 'z' + 1 ... 255 ] = -1 \
> > > }
> > > 
> > > that only requires that INIT_62_63() be used for all the characters
> > > that are used for 62 and 63 - it can be used for extra ones (eg '.').
> > > If some code wants to use different characters; the -1 need replacing
> > > with INIT_62_63() but nothing else has to be changed.
> > > 
> > > I used '0' - 6 (rather than '+' - 1 - or any other expression for 0x2a)
> > > to (possibly) make the table obviously correct without referring to the
> > > ascii code table.  
> > 
> > Still it's heavily depends on the values of '+,-./_' as an index that
> > makes it not so flexible.
> 
> How about this one?

Better than previous one(s) but quite cryptic to understand. Will need a
comment explaining the logic behind, if we go this way.

> #define INIT_1(v, ch_lo, ch_hi, off, ch_62, ch_63) \
> 	[ v ] = ((v) >= ch_lo && (v) <= ch_hi) ? (v) - ch_lo + off \
> 		: (v) == ch_62 ? 62 : (v) == ch_63 ? 63 : -1
> #define INIT_2(v, ...) INIT_1(v, __VA_ARGS__), INIT_1((v) + 1, __VA_ARGS__)
> #define INIT_4(v, ...) INIT_2(v, __VA_ARGS__), INIT_2((v) + 2, __VA_ARGS__)
> #define INIT_8(v, ...) INIT_4(v, __VA_ARGS__), INIT_4((v) + 4, __VA_ARGS__)
> #define INIT_16(v, ...) INIT_8(v, __VA_ARGS__), INIT_8((v) + 8, __VA_ARGS__)
> #define INIT_32(v, ...) INIT_16(v, __VA_ARGS__), INIT_16((v) + 16, __VA_ARGS__)
> 
> #define BASE64_REV_INIT(ch_62, ch_63) { \
> 	[ 0 ... 0x1f ] = -1, \
> 	INIT_32(0x20, '0', '9', 0, ch_62, ch_63), \
> 	INIT_32(0x40, 'A', 'Z', 10, ch_62, ch_63), \
> 	INIT_32(0x60, 'a', 'z', 26, ch_62, ch_63), \
> 	[ 0x80 ... 0xff ] = -1 }
> 
> which gets the pre-processor to do all the work.
> ch_62 and ch_63 can be any printable characters.
> 
> Note that the #define names are all in a .c file - so don't need any
> kind of namespace protection.

> They can also all be #undef after the initialiser.

Yes, that's too.

> > Moreover this table is basically a dup of the strings in the first array.
> > Which already makes an unnecessary duplication.
> 
> That is what the self tests are for.
> 
> > That's why I prefer to
> > see a script (one source of data) to generate the header or something like
> > this to have the tables and strings robust against typos.
> 
> We have to differ on that one.
> Especially in cases (like this) where generating that data is reasonably trivial.
> 
> > The above is simply an unreadable mess.

-- 
With Best Regards,
Andy Shevchenko



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ