Skip to content

Commit 8ee56d7

Browse files
committed
Use bit_length to calculate NTT bit size
This will fix NTT size calculation bug (infinite loop) when multiplicand size is larger than 1<<31
1 parent fa02252 commit 8ee56d7

1 file changed

Lines changed: 1 addition & 3 deletions

File tree

ext/bigdecimal/ntt.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,7 @@ ntt_multiply(size_t a_size, size_t b_size, uint32_t *a, uint32_t *b, uint32_t *c
123123
return;
124124
}
125125

126-
int b_bits = 0;
127-
while (((uint32_t)1 << b_bits) < (uint32_t)b_size) b_bits++;
128-
int ntt_size_bits = b_bits + 1;
126+
int ntt_size_bits = bit_length(b_size - 1) + 1;
129127
if (ntt_size_bits > MAX_NTT32_BITS) {
130128
rb_raise(rb_eArgError, "Multiply size too large");
131129
}

0 commit comments

Comments
 (0)