aboutsummaryrefslogtreecommitdiffstats
path: root/g10/build-packet.c
diff options
context:
space:
mode:
Diffstat (limited to 'g10/build-packet.c')
-rw-r--r--g10/build-packet.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/g10/build-packet.c b/g10/build-packet.c
index 67d4a6eef..19a13760a 100644
--- a/g10/build-packet.c
+++ b/g10/build-packet.c
@@ -306,7 +306,9 @@ gpg_mpi_write (iobuf_t out, gcry_mpi_t a, unsigned int *r_nwritten)
p = gcry_mpi_get_opaque (a, &nbits);
if (p)
{
- /* Strip leading zero bits. */
+ /* First get nbits back to full bytes. */
+ nbits = ((nbits + 7) / 8) * 8;
+ /* Then strip leading zero bits. */
for (; nbits >= 8 && !*p; p++, nbits -= 8)
;
if (nbits >= 8 && !(*p & 0x80))