heimdal: Add 64-bit integer support to ASN.1 compiler
authorDimitry Andric <dim@FreeBSD.org>
Tue, 16 Apr 2024 18:56:37 +0000 (20:56 +0200)
committerDimitry Andric <dim@FreeBSD.org>
Wed, 17 Apr 2024 16:12:43 +0000 (18:12 +0200)
commit1b7487592987c91020063a311a14dc15b6e58075
tree5e327a7058274c7a15567e481447f6d82caa1e43
parent75eda0096bf83b9b88996d9903b5d4e504047eba
heimdal: Add 64-bit integer support to ASN.1 compiler

Import upstream 19d378f44:

  ASN.1 INTEGERs will now compile to C int64_t or uint64_t, depending
  on whether the constraint ranges include numbers that cannot be
  represented in 32-bit ints and whether they include negative
  numbers.

  Template backend support included.  check-template is now built with
  --template, so we know we're testing it.

  Tests included.

Also adjusts the generated files:
* asn1parse.c, asn1parse.h (not strictly necessary, but nice to have)
* der-protos.h, which needs a bunch of new prototypes. I copied these
  from a der-protos.h generated by the upstream build system, which
  uses a perl script for this.
* adjust printf format strings for int64_t. Upstream uses %lld for this,
  but that is not portable, and leads to lots of -Werror warnings.

This should fix target-dependent differences between headers generated
by asn1_compile. For example, when cross compiling world from amd64 to
i386, the generated cms_asn1.h header has:

  CMSRC2CBCParameter ::= SEQUENCE {
    rc2ParameterVersion   INTEGER (0..-1),
    iv                    OCTET STRING,
  }

while a native build on i386 has:

  CMSRC2CBCParameter ::= SEQUENCE {
    rc2ParameterVersion   INTEGER (0..2147483647),
    iv                    OCTET STRING,
  }

These are _both_ wrong, since the source file, cms.asn1, has:

  CMSRC2CBCParameter ::= SEQUENCE {
          rc2ParameterVersion   INTEGER (0..4294967295),
          iv                    OCTET STRING -- exactly 8 octets
  }

PR: 276960
Reviewed by: cy, emaste
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D44814
Differential Revision: https://reviews.freebsd.org/D44815
21 files changed:
crypto/heimdal/lib/asn1/Makefile.am
crypto/heimdal/lib/asn1/asn1-template.h
crypto/heimdal/lib/asn1/asn1parse.c
crypto/heimdal/lib/asn1/asn1parse.h
crypto/heimdal/lib/asn1/asn1parse.y
crypto/heimdal/lib/asn1/check-gen.c
crypto/heimdal/lib/asn1/der-protos.h
crypto/heimdal/lib/asn1/der_copy.c
crypto/heimdal/lib/asn1/der_free.c
crypto/heimdal/lib/asn1/der_get.c
crypto/heimdal/lib/asn1/der_length.c
crypto/heimdal/lib/asn1/der_put.c
crypto/heimdal/lib/asn1/gen.c
crypto/heimdal/lib/asn1/gen_decode.c
crypto/heimdal/lib/asn1/gen_encode.c
crypto/heimdal/lib/asn1/gen_length.c
crypto/heimdal/lib/asn1/gen_template.c
crypto/heimdal/lib/asn1/lex.l
crypto/heimdal/lib/asn1/symbol.h
crypto/heimdal/lib/asn1/template.c
crypto/heimdal/lib/asn1/test.asn1