diff options
author | Jack Lloyd <[email protected]> | 2019-04-21 11:41:02 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2019-04-21 11:41:02 -0400 |
commit | f6b3505d2837f07a7f68255440901586272b5225 (patch) | |
tree | 9fd2b5080136f1a24dff5650df65dafd321c2d3e /src/python | |
parent | e37bd06ea487a4d7b59b2e3f7e21fb955651daf9 (diff) |
More MPI functions
Diffstat (limited to 'src/python')
-rwxr-xr-x | src/python/botan2.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/python/botan2.py b/src/python/botan2.py index 311b00871..dc8376f65 100755 --- a/src/python/botan2.py +++ b/src/python/botan2.py @@ -1143,6 +1143,18 @@ class MPI(object): # For int or long (or whatever else), try converting to string: _DLL.botan_mp_set_from_str(self.__obj, _ctype_str(str(initial_value))) + @classmethod + def random(cls, rng_obj, bits): + bn = MPI() + _DLL.botan_mp_rand_bits(bn.handle_(), rng_obj.handle_(), c_size_t(bits)) + return bn + + @classmethod + def random_range(cls, rng_obj, lower, upper): + bn = MPI() + _DLL.botan_mp_rand_range(bn.handle_(), rng_obj.handle_(), lower.handle_(), upper.handle_()) + return bn + def __del__(self): _DLL.botan_mp_destroy(self.__obj) @@ -1178,6 +1190,20 @@ class MPI(object): rc = _DLL.botan_mp_is_negative(self.__obj) return rc == 1 + def is_positive(self): + rc = _DLL.botan_mp_is_positive(self.__obj) + return rc == 1 + + def is_zero(self): + rc = _DLL.botan_mp_is_zero(self.__obj) + return rc == 1 + + def is_odd(self): + return self.get_bit(0) == 1 + + def is_even(self): + return self.get_bit(0) == 0 + def flip_sign(self): _DLL.botan_mp_flip_sign(self.__obj) |