Rewrite BN_bn2mpi() using CBB.
authorjsing <jsing@openbsd.org>
Sat, 22 Jun 2024 16:33:00 +0000 (16:33 +0000)
committerjsing <jsing@openbsd.org>
Sat, 22 Jun 2024 16:33:00 +0000 (16:33 +0000)
commit44db64637299036f3d8075801d5977531c3cc6af
tree4bbabe4f03fa9996ed0f816b3398259a269b2a2a
parent5de06c1d0d23388ea3e98ae4d3b06c2718e1c115
Rewrite BN_bn2mpi() using CBB.

The content is effectively a u32 length prefixed field, so use
CBB_add_u32_length_prefixed(). Use BN_bn2binpad() rather than manually
padding if we need to extend and use sensible variable names so that the
code becomes more readable.

Note that since CBB can fail we now need to be able to indicate failure.
This means that BN_bn2mpi() can now return -1 when it would not have
previously (correct callers will check that BN_bn2mpi() returns a positive
length).

ok tb@
lib/libcrypto/bn/bn_convert.c