From 813e24108a139c8059dad8bc679b2ab76b807ed9 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Fri, 30 Oct 2020 17:03:22 +0900 Subject: [PATCH] gpg: Fix SOS handling with libgcrypt version <= 1.8. * g10/misc.c (checksum_mpi): Don't depend new feature of gcry_mpi_print which supports opaque MPI. -- GnuPG-bug-id: 5116 Signed-off-by: NIIBE Yutaka --- g10/misc.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/g10/misc.c b/g10/misc.c index 111a916e8..0d457365b 100644 --- a/g10/misc.c +++ b/g10/misc.c @@ -257,6 +257,25 @@ checksum_mpi (gcry_mpi_t a) byte *buffer; size_t nbytes; + /* + * This code can be skipped when gcry_mpi_print + * supports opaque MPI. + */ + if (gcry_mpi_get_flag (a, GCRYMPI_FLAG_OPAQUE)) + { + const byte *p; + unsigned int nbits; + + p = gcry_mpi_get_opaque (a, &nbits); + if (!p) + return 0; + + csum = nbits >> 8; + csum += (nbits & 0xff); + csum += checksum (p, (nbits+7)/8); + return csum; + } + if ( gcry_mpi_print (GCRYMPI_FMT_PGP, NULL, 0, &nbytes, a) ) BUG (); /* Fixme: For numbers not in secure memory we should use a stack