49 Commits

Author SHA1 Message Date
aumetra
4e3ff9884c
feat: add arbitrary support
adds arbitrary support to BigInt and BigUint
2022-11-18 17:47:25 +01:00
Tony Arcieri
2aade9ddcb 2021 edition upgrade; MSRV 1.56
Upgrades the edition, with changes primarily performed by
`cargo fix --edition`.

In order to keep the changes to a minimum, this doesn't include
automated idiom fixes (i.e. `cargo fix --edition-idioms`).

This is needed to unblock the edition upgrade for the RSA crate:
https://github.com/RustCrypto/RSA/pull/135
2022-02-01 16:24:03 -07:00
phayes
58be206fa7
Updating rand dependency to 0.8 2021-02-15 07:37:51 -08:00
Friedel Ziegelmayer
3042607c90
feat: update dependencies 2019-12-11 00:48:19 +01:00
dignifiedquire
bb167d4a9a refactor: fix compiler warnings 2019-10-13 15:21:56 +02:00
Robin Lambertz
874ab0fbaa feat: no_std support
* no_std support

* Use integer log2 when possible to estimate allocations

* Remove std features from a few dependencies

* Use libm for missing funcs in nostd environment

* Use autocfg to detect presence of i128

* Better CI test for nostd environment

* Move benchmark to a separate crate

* Make the tests pass in no_std builds

* Use thumbv7m target for nostd build test

* Add documentation about the no-std compatibility

* Make zeroize and prime features no_std-compatible

* Test each feature in nostd context

* Fix mac test to work in no_std environment

* Avoid using thread_rng in nostd tests

* Fix prime tests in nostd mode

* Fix all warnings and errors

* Only test nostd builds on nightly on travis

* Travis: Only do nostd builds on nightly
2019-10-13 15:14:14 +02:00
goldenMetteyya
58fd3e4024 Fixing 2019-04-29 00:52:12 +03:00
dignifiedquire
ca8c31e097 feat(deps): upgrade to rand@0.6 2019-03-26 14:40:53 +01:00
Josh Stone
90531ea643 cargo fmt 2019-01-22 12:52:52 +01:00
Josh Stone
847ba7c3dd Test a range of round trips to/from_signed_bytes 2019-01-22 12:52:34 +01:00
Leonardo Yvens Schwarzstein
810f8c4b47 Fix to_signed_bytes_* for positive number with leading 0x80 2019-01-22 12:52:34 +01:00
Josh Stone
07a22d447b Use better initial guesses for Roots 2019-01-22 12:52:34 +01:00
Friedel Ziegelmayer
ad8355c2b0
feat: Lehmer GCD - and various improvements (#4) 2019-01-22 12:29:31 +01:00
dignifiedquire
bbea8a2e65 fix: ensure features are working independently, test prime on ci 2019-01-15 15:24:40 +01:00
goldenMetteyya
d4c0b721c9 feat: implement prime generation related features
also switches the benchmarks to criterion
2019-01-15 15:02:12 +01:00
dignifiedquire
ad076a8cd4 fix: test and some flags 2018-12-19 22:00:11 +01:00
dignifiedquire
2656a03c5a feat: use SmallVec as backing store 2018-12-19 19:46:26 +01:00
dignifiedquire
73a3f1eacb improve modpow perf and fix test 2018-12-19 19:10:19 +01:00
dignifiedquire
fb29d3cd80 update names 2018-12-12 14:14:34 +01:00
dignifiedquire
329aa2f5d4 some cleanup 2018-11-07 13:53:23 +01:00
dignifiedquire
4bb412640e alternative impl 2018-11-07 13:41:59 +01:00
dignifiedquire
a24a000e3c first round of u64 BigDigit support 2018-11-07 13:41:58 +01:00
dignifiedquire
35939287b9 feat: implement operators with 128bit 2018-08-07 12:56:00 +02:00
dignifiedquire
f7e8af05a4 chore: run rustfmt on all code 2018-08-06 15:13:09 -07:00
Thom Wiggers
5fe8a5fbdf
Get rid of num_traits::pow usage
See also #56
2018-07-19 17:12:38 +02:00
Thom Wiggers
d3ef15195e
also use BigInt::from 2018-07-19 17:02:36 +02:00
Thom Wiggers
ab3594f878
Also allow BigInt.pow(&$type) 2018-07-19 17:02:36 +02:00
Thom Wiggers
9009cf80d7
Address feedback 2018-07-19 17:02:35 +02:00
Thom Wiggers
3f79349614
Implement Pow directly on references 2018-07-19 17:02:35 +02:00
Thom Wiggers
136d7d9aab
Implement pow for BigInt 2018-07-19 17:02:35 +02:00
Thom Wiggers
cfe8ffb0cb
Support BigUint.pow() for primitives 2018-07-19 17:02:35 +02:00
Manca Bizjak
2b473e9403 Implement optimized sqrt, cbrt methods
This commit overrides default implementations of
Roots::sqrt and Roots::cbrt for BigInt and BigUint
with optimized ones. It also improves tests and
resolves minor inconsistencies.

Signed-off-by: Manca Bizjak <manca.bizjak@xlab.si>
2018-07-13 12:52:40 +02:00
Manca Bizjak
1f2590656b Implement Roots for BigInt and BigUint
This commit implements num-integer::Roots trait
for BigInt and BigUint types, and also adds sqrt,
cbrt, nth_root as inherent methods to allow access
to them without importing Roots trait. For each
type tests were added as submodules in the roots
test module.

Signed-off-by: Manca Bizjak <manca.bizjak@xlab.si>
2018-07-11 12:14:46 +02:00
Josh Stone
8b5a092010 Add tests for PRNG value stability 2018-07-02 11:09:07 -07:00
Josh Stone
e679836303 Add a RandomBits distribution 2018-05-23 20:57:29 -07:00
Josh Stone
ec181ea593 Update rand CI 2018-05-22 16:56:54 -07:00
Josh Stone
b72822bbde impl SampleUniform for BigInt 2018-05-22 14:59:36 -07:00
Josh Stone
4ef07c4625 impl SampleUniform for BigUint 2018-05-22 14:48:52 -07:00
Josh Stone
39104f5732 refactor tests/rand.rs 2018-05-22 14:38:59 -07:00
Josh Stone
04252b7716 Add basic conversions for i128 and u128 2018-05-15 18:01:14 -07:00
Josh Stone
96c1d69279 Implement assignment operators for BigInt
All of these operators were already implemented for `BigUint`, so
now `BigInt` support the same use.

Closes #7.
2018-05-09 16:36:29 -07:00
Josh Stone
dd4081721f sources shouldn't be executable 2018-05-09 16:18:56 -07:00
Josh Stone
087c4ecfd6 Add serde tests 2018-05-03 12:39:15 -07:00
Josh Stone
a849284320 Remove big_digit::* from the public API
The *idea* of `big_digit` and its type aliases is that we may someday
use something other than `u32` in the representation, perhaps even
different sizes for different targets.  That's still a possibility, but
I think it's not really feasible to expose this variation in the public
API.  Calling `BigUint::from_slice([1, 2, 3])` is only meaningful if you
know what that size is, and users can't really alternate this kind of
thing based on a type definition.  So for now, we just commit to `u32`
units in the public API, no matter what we may do internally.

This removal is a breaking change, part of the 0.2 semver bump.  If I'm
wrong and somebody can show a compelling use case for `big_digit`, we
can always add things back into the public API later.
2018-04-27 23:52:41 -07:00
Trevor Spiteri
e005dcc942 add tests for two's-complement bitwise operations 2018-03-04 10:22:29 +01:00
Josh Stone
8964eb9887 Chop the tests up
The test modules were getting huge, and some of its functions were
actually a huge amount of code due to macros, causing tests to take a
long time just to compile.  They are now separated into a few different
tests, and the scalar macros especially are now expanded more sparingly
in just a few `check()` functions.

Test compile times for me went from about 25 seconds to 1.5s in debug
mode, and from 300 seconds (!) to about 8s in release mode.
2018-02-26 22:13:25 -08:00
Josh Stone
f4cc2abff1 Add BigInt::modpow
This performs modular exponentiation on signed `BigInt`.  The exponent
must be positive, and the modulus must be non-zero.  The implementation
leverages `BigUint::modpow`, fixing the signs as needed afterward.
2018-02-08 13:57:55 -08:00
Alex Crichton
a6a399d52e Enable testing on stable Rust 2015-05-19 09:22:06 -07:00
Erick Tryzelaar
f4a69a6f01 Export the #[derive(FromPrimitive)] from rust proper
This changes the name to #[derive(NumFromPrimitive)]
in order to not conflict with the libsyntax macro.
2015-04-12 11:19:48 -07:00