Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions mp_pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ mp_err mp_pack(void *rop, size_t maxcount, size_t *written, mp_order order, size

mp_int t;

if ((size == 0u) || (nails >= (size * 8u))) {
return MP_VAL;
}

count = mp_pack_count(op, nails, size);

if (count > maxcount) {
Expand Down
6 changes: 5 additions & 1 deletion mp_pack_count.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@

size_t mp_pack_count(const mp_int *a, size_t nails, size_t size)
{
size_t bits = (size_t)mp_count_bits(a);
size_t bits;
if ((size == 0u) || (nails >= (size * 8u))) {
return 0u;
}
bits = (size_t)mp_count_bits(a);
return ((bits / ((size * 8u) - nails)) + (((bits % ((size * 8u) - nails)) != 0u) ? 1u : 0u));
}

Expand Down
Loading