1
(************************************************************************)
2
(* This file is part of SKS. SKS is free software; you can
3
redistribute it and/or modify it under the terms of the GNU General
4
Public License as published by the Free Software Foundation; either
5
version 2 of the License, or (at your option) any later version.
7
This program is distributed in the hope that it will be useful, but
8
WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
16
(***********************************************************************)
18
(** Basic operations and definitions for multi-precistion integers. *)
22
let two = big_int_of_int 2
23
let one = unit_big_int
24
let zero = zero_big_int
25
let neg_one = big_int_of_int (-1)
27
let ( *! ) = mult_big_int
28
let ( +! ) = add_big_int
29
let ( -! ) = sub_big_int
30
let ( %! ) = quomod_big_int
31
let ( /! ) = div_big_int
32
let ( **! ) = power_big_int_positive_big_int
33
let ( <>! ) x y = not (eq_big_int x y)
34
let ( =! ) = eq_big_int
35
let ( <! ) = lt_big_int
36
let ( >! ) = gt_big_int
37
let ( <=! ) = le_big_int
38
let ( >=! ) = ge_big_int
42
let width_pow = power_int_positive_int 2 width
45
let len = String.length s in
46
let copy = String.create len in
47
for i = 0 to len - 1 do
48
copy.[i] <- s.[len - 1 - i]
52
let revstring_inplace s =
53
let len = String.length s in
54
for i = 0 to (len - 2)/2 do
55
let j = len - 1 - i in
61
let bigint_to_bytes ~nbytes n =
62
if sign_big_int n = -1
63
then raise (Invalid_argument "N.to_bytes: negative argument");
64
let string = String.create nbytes in
68
let (a,b) = n %! width_pow in
69
string.[i] <- char_of_int (int_of_big_int b);
72
let str = loop n (nbytes - 1) in
73
revstring_inplace str;
76
let bigint_of_bytes str =
77
let str = revstring str in
78
let nbytes = String.length str in
82
let m = big_int_of_int (int_of_char str.[i]) in
83
loop (n *! width_pow +! m) (i+1)
94
val of_bytes : string -> t
95
val to_bytes : t -> string
97
val to_N : t -> big_int
98
val of_N : big_int -> t
103
val add : t -> t -> t
104
val div : t -> t -> t
105
val mul : t -> t -> t
106
val mult : t -> t -> t
109
val shl : t -> int -> t
111
val imult : t -> int -> t
113
val add_fast : t -> t -> t
114
val mul_fast : t -> t -> t
115
val mult_fast : t -> t -> t
117
val square_fast : t -> t
118
val canonicalize : t -> t
120
val sub : t -> t -> t
121
val print : t -> unit
123
val imul : t -> int -> t
125
val lt : t -> t -> bool
126
val gt : t -> t -> bool
127
val eq : t -> t -> bool
128
val neq : t -> t -> bool
131
val mult_in : tref -> t -> t -> unit
132
val mult_fast_in : tref -> t -> t -> unit
133
val add_in : tref -> t -> t -> unit
134
val add_fast_in : tref -> t -> t -> unit
135
val sub_in : tref -> t -> t -> unit
136
val sub_fast_in : tref -> t -> t -> unit
137
val copy_in : tref -> t -> unit
138
val copy_out : tref -> t
139
val make_ref : t -> tref
140
val canonicalize_in : tref -> unit
142
val points : int -> t array
143
val svalues : int -> zzarray
144
val to_string : t -> string
146
val add_el_array : points: t array -> t -> t array
147
val del_el_array : points: t array -> t -> t array
148
val mult_array : svalues: zzarray -> t array -> unit
151
val add_el : svalues:zzarray -> points:t array ->
152
t -> unit (* modifies svalues *)
153
val del_el : svalues:zzarray -> points:t array ->
154
t -> unit (* modifies svalues *)
156
val length : zzarray -> int
157
val zzarray_to_array : zzarray -> t array
158
val zzarray_of_array : t array -> zzarray
159
val zzarray_div : zzarray -> zzarray -> zzarray
160
val zzarray_copy : zzarray -> zzarray
162
val cmp : t -> t -> int