Insert leading octet if high bit of first nibble is 1
authortb <tb@openbsd.org>
Fri, 7 Jul 2023 06:41:59 +0000 (06:41 +0000)
committertb <tb@openbsd.org>
Fri, 7 Jul 2023 06:41:59 +0000 (06:41 +0000)
The reason the function this replaces is called ASN1_bn_print() is that it
actually prints a representation of the ASN.1 encoding.

ok jsing

lib/libcrypto/bn/bn_print.c

index 466aeb3..18984d7 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: bn_print.c,v 1.40 2023/07/06 14:37:39 tb Exp $ */
+/*     $OpenBSD: bn_print.c,v 1.41 2023/07/07 06:41:59 tb Exp $ */
 
 /*
  * Copyright (c) 2023 Theo Buehler <tb@openbsd.org>
@@ -102,6 +102,12 @@ bn_print_bignum(BIO *bio, const BIGNUM *bn, int indent)
                        if (BIO_printf(bio, "\n%*s", indent, "") <= 0)
                                goto err;
                }
+               /* First nibble has the high bit set. Insert leading 0 octet. */
+               if (octets == 1 && hi >= '8') {
+                       if (BIO_printf(bio, "00:") <= 0)
+                               goto err;
+                       octets++;
+               }
                if (CBS_len(&cbs) == 0)
                        sep = "";
                if (BIO_printf(bio, "%c%c%s", tolower(hi), tolower(lo), sep) <= 0)