Skip to content

Commit

Permalink
don't hard-code bit length
Browse files Browse the repository at this point in the history
  • Loading branch information
mitschabaude committed Dec 19, 2023
1 parent b0f0773 commit 5b52162
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/lib/crypto/kimchi_backend/common/field.ml
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,15 @@ module Make (F : Input_intf) :
let of_sexpable = of_bigint
end)

let two_to_32 = Bignum_bigint.of_int64 4294967296L

let to_bignum_bigint n =
let result = ref (Bignum_bigint.of_int (Bigint.test_uint32 n 7)) in
for i = 6 downto 0 do
let ni = Bignum_bigint.of_int (Bigint.test_uint32 n i) in
result := Bignum_bigint.(ni + (two_to_32 * !result))
let size_in_uint32 = (size_in_bits + 31) / 32

let to_bignum_bigint x =
let result =
ref (Bignum_bigint.of_int (Bigint.test_uint32 x (size_in_uint32 - 1)))
in
for i = size_in_uint32 - 2 downto 0 do
let xi = Bignum_bigint.of_int (Bigint.test_uint32 x i) in
result := Bignum_bigint.(xi + shift_left !result 32)
done ;
!result

Expand Down

0 comments on commit 5b52162

Please sign in to comment.