hacspec_lib/
bigint_integers.rs1#![allow(unused_variables)]
2use crate::prelude::*;
3
4impl Integer for BigInt {
5 const NUM_BITS: usize = 0;
7
8 #[inline]
9 #[cfg_attr(feature = "use_attributes", not_hacspec)]
10 fn ZERO() -> Self {
11 BigInt::from(0)
12 }
13 #[inline]
14 #[cfg_attr(feature = "use_attributes", not_hacspec)]
15 fn ONE() -> Self {
16 BigInt::from(1)
17 }
18 #[inline]
19 #[cfg_attr(feature = "use_attributes", not_hacspec)]
20 fn TWO() -> Self {
21 BigInt::from(2)
22 }
23
24 #[inline]
25 #[cfg_attr(feature = "use_attributes", not_hacspec)]
26 fn from_literal(val: u128) -> Self {
27 BigInt::from(val)
28 }
29
30 #[inline]
31 #[cfg_attr(feature = "use_attributes", not_hacspec)]
32 fn from_hex_string(s: &String) -> Self {
33 BigInt::from_str(s).unwrap()
34 }
35
36 #[inline]
38 #[cfg_attr(feature = "use_attributes", in_hacspec)]
39 fn get_bit(self, i: usize) -> Self {
40 (self >> i) & Self::ONE()
41 }
42
43 #[inline]
46 #[cfg_attr(feature = "use_attributes", in_hacspec)]
47 fn set_bit(self, b: Self, i: usize) -> Self {
48 debug_assert!(b.clone().equal(Self::ONE()) || b.clone().equal(Self::ZERO()));
49 let tmp1 = Self::from_literal(!(1 << i));
50 let tmp2 = b << i;
51 (self & tmp1) | tmp2
52 }
53
54 #[inline]
56 #[cfg_attr(feature = "use_attributes", in_hacspec)]
57 fn set(self, pos: usize, y: Self, yi: usize) -> Self {
58 let b = y.get_bit(yi);
59 self.set_bit(b, pos)
60 }
61
62 #[allow(arithmetic_overflow)]
63 #[cfg_attr(feature = "use_attributes", in_hacspec)]
64 fn rotate_left(self, n: usize) -> Self {
65 assert!(n < Self::NUM_BITS, "not {} < {}", n, Self::NUM_BITS);
67 (self.clone() << n) | (self >> ((-(n as i32) as usize) & (Self::NUM_BITS - 1)))
68 }
69
70 #[allow(arithmetic_overflow)]
71 #[cfg_attr(feature = "use_attributes", in_hacspec)]
72 fn rotate_right(self, n: usize) -> Self {
73 assert!(n < Self::NUM_BITS);
75 (self.clone() >> n) | (self << ((-(n as i32) as usize) & (Self::NUM_BITS - 1)))
76 }
77}
78impl Numeric for BigInt {
79 #[cfg_attr(feature = "use_attributes", not_hacspec)]
81 fn max_val() -> Self {
82 unimplemented!();
83 }
84
85 #[cfg_attr(feature = "use_attributes", not_hacspec)]
86 fn wrap_add(self, rhs: Self) -> Self {
87 self + rhs
88 }
89 #[cfg_attr(feature = "use_attributes", not_hacspec)]
90 fn wrap_sub(self, rhs: Self) -> Self {
91 self - rhs
92 }
93 #[cfg_attr(feature = "use_attributes", not_hacspec)]
94 fn wrap_mul(self, rhs: Self) -> Self {
95 self * rhs
96 }
97 #[cfg_attr(feature = "use_attributes", not_hacspec)]
98 fn wrap_div(self, rhs: Self) -> Self {
99 unimplemented!();
100 }
101
102 #[cfg_attr(feature = "use_attributes", not_hacspec)]
104 fn exp(self, exp: u32) -> Self {
105 unimplemented!();
106 }
107 #[cfg_attr(feature = "use_attributes", not_hacspec)]
109 fn pow_self(self, exp: Self) -> Self {
110 unimplemented!();
111 }
112 #[cfg_attr(feature = "use_attributes", not_hacspec)]
114 fn divide(self, rhs: Self) -> Self {
115 unimplemented!();
116 }
117 #[cfg_attr(feature = "use_attributes", not_hacspec)]
119 fn inv(self, n: Self) -> Self {
120 unimplemented!();
121 }
122
123 #[cfg_attr(feature = "use_attributes", not_hacspec)]
125 fn equal(self, other: Self) -> bool {
126 self.eq(&other)
127 }
128 #[cfg_attr(feature = "use_attributes", not_hacspec)]
129 fn greater_than(self, other: Self) -> bool {
130 unimplemented!();
131 }
132 #[cfg_attr(feature = "use_attributes", not_hacspec)]
133 fn greater_than_or_equal(self, other: Self) -> bool {
134 unimplemented!();
135 }
136 #[cfg_attr(feature = "use_attributes", not_hacspec)]
137 fn less_than(self, other: Self) -> bool {
138 self.lt(&other)
139 }
140 #[cfg_attr(feature = "use_attributes", not_hacspec)]
141 fn less_than_or_equal(self, other: Self) -> bool {
142 unimplemented!();
143 }
144
145 #[cfg_attr(feature = "use_attributes", not_hacspec)]
147 fn not_equal_bm(self, other: Self) -> Self {
148 unimplemented!();
149 }
150 #[cfg_attr(feature = "use_attributes", not_hacspec)]
151 fn equal_bm(self, other: Self) -> Self {
152 unimplemented!();
153 }
154 #[cfg_attr(feature = "use_attributes", not_hacspec)]
155 fn greater_than_bm(self, other: Self) -> Self {
156 unimplemented!();
157 }
158 #[cfg_attr(feature = "use_attributes", not_hacspec)]
159 fn greater_than_or_equal_bm(self, other: Self) -> Self {
160 unimplemented!();
161 }
162 #[cfg_attr(feature = "use_attributes", not_hacspec)]
163 fn less_than_bm(self, other: Self) -> Self {
164 unimplemented!();
165 }
166 #[cfg_attr(feature = "use_attributes", not_hacspec)]
167 fn less_than_or_equal_bm(self, other: Self) -> Self {
168 unimplemented!();
169 }
170}
171
172impl ModNumeric for BigInt {
173 #[cfg_attr(feature = "use_attributes", not_hacspec)]
175 fn sub_mod(self, rhs: Self, n: Self) -> Self {
176 (self - rhs) % n
177 }
178 #[cfg_attr(feature = "use_attributes", not_hacspec)]
180 fn add_mod(self, rhs: Self, n: Self) -> Self {
181 (self + rhs) % n
182 }
183 #[cfg_attr(feature = "use_attributes", not_hacspec)]
185 fn mul_mod(self, rhs: Self, n: Self) -> Self {
186 (self * rhs) % n
187 }
188 #[cfg_attr(feature = "use_attributes", not_hacspec)]
190 fn pow_mod(self, exp: Self, n: Self) -> Self {
191 unimplemented!();
192 }
193 #[cfg_attr(feature = "use_attributes", not_hacspec)]
195 fn modulo(self, n: Self) -> Self {
196 self % n
197 }
198 #[cfg_attr(feature = "use_attributes", not_hacspec)]
200 fn signed_modulo(self, n: Self) -> Self {
201 unimplemented!();
202 }
203 #[cfg_attr(feature = "use_attributes", not_hacspec)]
205 fn absolute(self) -> Self {
206 self.abs()
207 }
208}
209
210impl PublicInteger for BigInt {
211 type SecretVersion = BigInt;
212}
213
214impl SecretInteger for BigInt {
215 type PublicVersion = BigInt;
216 #[cfg_attr(feature = "use_attributes", not_hacspec)]
217 fn classify(x: Self::PublicVersion) -> Self {
218 x
219 }
220}