• Nicolai Stange's avatar
    lib/mpi: mpi_write_sgl(): fix skipping of leading zero limbs · f2d1362f
    Nicolai Stange authored
    Currently, if the number of leading zeros is greater than fits into a
    complete limb, mpi_write_sgl() skips them by iterating over them limb-wise.
    However, it fails to adjust its internal leading zeros tracking variable,
    lzeros, accordingly: it does a
      p -= sizeof(alimb);
    which should really have been a
      lzeros -= sizeof(alimb);
    Since lzeros never decreases if its initial value >= sizeof(alimb), nothing
    gets copied by mpi_write_sgl() in that case.
    Instead of skipping the high order zero limbs within the loop as shown
    above, fix the issue by adjusting the copying loop's bounds.
    Fixes: 2d4d1eea
     ("lib/mpi: Add mpi sgl helpers")
    Signed-off-by: default avatarNicolai Stange <nicstange@gmail.com>
    Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>