Re: [PATCH v2 2/9] lib/asn1_encoder: Add asn1_encode_integer_bytes()
From: Jarkko Sakkinen
Date: Wed Nov 25 2026 - 17:10:39 EST
On Wed, Nov 25, 2026 at 09:33:33PM +0000, David Laight wrote:
> On Wed, 25 Nov 2026 17:38:55 +0200
> Jarkko Sakkinen <jarkko@xxxxxxxxxx> wrote:
>
> > On Wed, Nov 25, 2026 at 09:19:21AM +0000, David Laight wrote:
> > > On Tue, 24 Nov 2026 21:40:36 +0200
> > > Jarkko Sakkinen <jarkko@xxxxxxxxxx> wrote:
> > >
> > > > Add a helper encoding a positive integer from a byte array in big-endian
> > > > format.
> > >
> > > Interesting...
> > > You allow for integer values longer than 127 bytes but don't allow for the
> > > much more common likelyhood of the encoding being 'implicit'.
> >
> > This is the first thing I wrote in 2024 and have not touched since
> > without further feedback :-)
>
> I wrote an ASN.1 encoder/decoder for a tcap library a few years back.
> Pretty much everything was implicit and some of the tags exceed 5 bits.
> About the only things that needed multi-byte lengths were constructed.
> Oh - and you can't fit in a maximal length SMS if you use the indefinite
> length for constructed items between 128 and 255 bytes, you have to use
> the two-byte encoding.
>
> There were a few functions for 'add item to buffer', but I didn't need
> this one.
TCAP/SMS has pretty much the opposite profile from crypto DER in the
kernel, which deals with big numbers.
None of the other primitives in lib/asn1_encoder.c take an IMPLICIT tag
override either, so better to leave that out until something in-tree
actually needs it.
>
> David
Br, Jarkko