Commit Graph

124 Commits

Author SHA1 Message Date
mii
2548ca1ebe bugfix 2024-04-08 16:06:33 +09:00
38f98ff87e Update CHANGELOG 2018-08-13 21:41:22 +02:00
8ea296b57d Update Cargo.lock 2018-08-13 21:33:27 +02:00
06033f1c0e Fix wrong validation of threshold
Fortunately as both MIN_SHARES and MIN_THRESHOLD are both set to 2 in errors.rs,
the typo had no impact on validation correctness.
2018-08-13 21:29:39 +02:00
2066102afa Correct copy-pasted doc comment for split_secret_rng 2018-08-13 21:29:39 +02:00
f83ef1b2b6 Add support for custom RNGs in SSS and WrappedSecrets (#64) 2018-08-13 21:29:39 +02:00
e84ff133bd Add license name to README, and update year 2018-08-13 21:29:39 +02:00
82f3f34eec Add @nvesely to the list of authors 2018-08-13 21:29:39 +02:00
36bc055520 Add back Cargo.lock
Although RustySecrets is a library, it is important that all
contributors to the library are using the very same version
of every package, as we cannot always trust downstream deps
to follow SemVer to the letter.
2018-08-13 21:29:39 +02:00
17a9c14bf3 Add EditorConfig configuration file 2018-08-13 21:29:39 +02:00
2ed5bfbac7 Add rust-toolchain file 2018-08-13 21:29:39 +02:00
c25f661645 Rustfmt updates + refactor Travis configuration (#60)
* Update rustfmt compliance

Looks like rustfmt has made some improvements recently, so wanted to bring the
code up to date.

* Add rustfmt to nightly item in Travis matrix

* Use Travis Cargo cache

* Allow fast_finish in Travis

Items that match the `allow_failures` predicate (right now, just Rust nightly),
will still finish, but Travis won't wait for them to report a result if the
other builds have already finished.

* Run kcov in a separate matrix build in Travis

* Rework allowed_failures logic

We don't want rustfmt to match `allow_failures` just because it needs to use
nightly, while we do want nightly to match `allow_failures`. Env vars provide a
solution.

* Add --all switch to rustfmt Travis

* Test building docs in Travis

* Use exact Ubuntu dependencies listed for kcov

Some of the dependencies we were installing were not listed on
https://github.com/SimonKagstrom/kcov/blob/master/INSTALL.md, and we were
missing one dependency that was listed there. When `sudo: true` Travis uses
Ubuntu Trusty.

* No need to build before running kcov

kcov builds its own test executables.

* Generate `Cargo.lock` w/ `cargo update` before running kcov

As noted in aeb3906cce8e3e26c7bc80d6aec417b365f3d2f1 it is not necessary to
build the project before running kcov, but kcov does require a `Cargo.lock`
file, which can be generated with `cargo update`.
2018-08-13 21:29:39 +02:00
d6407c0e8a Adds no_more_than_five formatter
This should be useful when validating very large sets of shares. Wouldn't want
to print out up to 254 shares.
2018-08-13 21:29:39 +02:00
71064a686e Minor improvement to validation 2018-08-13 21:29:39 +02:00
3f215cdb39 Validation consistency between format & validation modules
The best place to catch share problems is immediately during parsing from
`&str`, however, because `validate_shares` takes any type that implements the
`IsShare` trait, and there's nothing about that trait that guarantees that the
share id, threshold, and secret length will be valid, I thought it best to leave
those three tests in `validate_shares` as a defensive coding practice.
2018-08-13 21:29:39 +02:00
88743caad8 Simplify share threshold and secret length consistency validation
I think that using hashmaps and hash sets was overkill and made the code much
longer and complicated than it needed to be.

The new code also produces more useful error messages that will hopefully help
users identify which share(s) are causing the inconsistency.
2018-08-13 21:29:39 +02:00
c437775169 Standardize validation var identifier on 2018-08-13 21:29:39 +02:00
840f5cce81 Change signatures of share validation fns
* Pass a ref to `Vec<Shares>` instead of recreating and moving the object
  through several functions.
* Return `slen`/ `data_len`, since we'll be using it anyway in `recover_secrets`
2018-08-13 21:29:39 +02:00
d098033f6f Disable dss benchmarks until we expose the module.
Closes #49
2018-08-13 21:29:39 +02:00
a6046dde48 Validate shares have the same data length 2018-08-13 21:29:39 +02:00
df091b07c1 More specific validation error when share thresholds mismatch 2018-08-13 21:29:39 +02:00
cb13a9b5db MissingShares should take u8 for required arg 2018-08-13 21:29:39 +02:00
fd74534fa1 Fix arg order missing shares validation
The arguments were provided in the wrong order.
2018-08-13 21:29:39 +02:00
5b35c69c8e Simplify threshold consistency validation
Since the validation already confirms `shares` is not empty, `k_sets` will never
match 0.
2018-08-13 21:29:39 +02:00
55b7c78a3a Add ErrorKind::ShareParsingInvalidShareThreshold
Ensures that threshold > 2 during the parsing process, since we ensure the same
during the splitting process.
2018-08-13 21:29:39 +02:00
cdcf012a59 Remove DuplicateShareData error and validation
It's possible that two different points have the same data.

To give a concrete example consider the secret polynomial `x^2 + x + s`, where
`s` is the secret byte. Plugging in 214 and 215 (both elements of the cyclic
subgroup of order 2) for `x` will give the same result, `1 + s`.

More broadly, for any polynomial `b*x^t + b*x^(t-1) + ... + x + s`, where `t` is
the order of at least one subgroup of GF(256), for all subgroups of order `t`,
all elements of that subgroup, when chosen for `x`, will produce the same
result.

There are certainly other types of polynomials that have "share collisions."
This type was just easy to find because it exploits the nature of finite fields.
2018-08-13 21:29:39 +02:00
ed867ba938 Remove ShareIdentifierTooBig error and validation
Since id is a `u8` it will never be greater than 255.
2018-08-13 21:29:39 +02:00
b03433af09 Add TODO note on unreleased Rng::try_fill_bytes 2018-08-13 21:29:39 +02:00
e34f45d954 Update rand to ^0.4.2
RustySecrets makes minimal use of the rand library. It only initializes
the `ChaChaRng` with a seed, and `OsRng` in the standard way, and then calls
their `fill_bytes` methods, provided by the same Trait, and whose function
signature has not changed.  I have confirmed by looking at the code changes,
that there have been no changes to the relevant interfaces this library uses.
2018-08-13 21:29:39 +02:00
8bf1c8bf54 Note algorithm in encode_secret_byte docstring 2018-08-13 21:29:39 +02:00
73e45bf032 Use Horner's method for evaluating polynomials
Horner's method is an algorithm for calculating polynomials, which consists of
transforming the monomial form into a computationally efficient form. It is
pretty easy to understand:
https://en.wikipedia.org/wiki/Horner%27s_method#Description_of_the_algorithm

This implementation has resulted in a noticeable secret share generation speedup
as the RustySecrets benchmarks show, especially when calculating larger
polynomials:

Before:
test sss::generate_1kb_10_25 ... bench: 3,104,391 ns/iter (+/- 113,824)
test sss::generate_1kb_3_5 ... bench: 951,807 ns/iter (+/- 41,067)

After:
test sss::generate_1kb_10_25        ... bench:   2,071,655 ns/iter (+/- 46,445)
test sss::generate_1kb_3_5          ... bench:     869,875 ns/iter (+/- 40,246)
2018-08-13 21:29:39 +02:00
b477d3d4ce Ensure there is at least one point in QuickCheck tests 2018-08-13 21:29:39 +02:00
36dc14e6ff Use barycentric Lagrange interpolation in all cases.
While this is a slight regression in performance in the case
where k < 5, in absolute terms it is small enough to be neglible.
2018-08-13 21:29:39 +02:00
e767f28d4c Initial barycentric Langrange interpolation
Implements barycentric Lagrange interpolation. Uses algorithm (3.1) from the
paper "Polynomial Interpolation: Langrange vs Newton" by Wilhelm Werner to find
the barycentric weights, and then evaluates at `Gf256::zero()` using the second
or "true" form of the barycentric interpolation formula.

I also earlier implemented a variant of this algorithm, Algorithm 2, from "A new
efficient algorithm for polynomial interpolation," which uses less total
operations than Werner's version, however, because it uses a lot more
multiplications or divisions (depending on how you choose to write it), it runs
slower given the running time of subtraction/ addition (equal) vs
multiplication, and especially division in the Gf256 module.

The new algorithm takes n^2 / 2 divisions and n^2 subtractions to calculate the
barycentric weights, and another n divisions, n multiplications, and 2n
additions to evaluate the polynomial*. The old algorithm runs in n^2 - n
divisions, n^2 multiplications, and n^2 subtractions. Without knowing the exact
running time of each of these operations, we can't say for sure, but I think a
good guess would be the new algorithm trends toward about 1/3 running time as n
-> infinity. It's also easy to see theoretically that for small n the original
lagrange algorithm is faster. This is backed up by benchmarks, which showed for
n >= 5, the new algorithm is faster. We can see that this is more or less what
we should expect given the running times in n of these algorithms.

To ensure we always run the faster algorithm, I've kept both versions and only
use the new one when 5 or more points are given.

Previously the tests in the lagrange module were allowed to pass nodes to the
interpolation algorithms with x = 0. Genuine shares will not be evaluated at x =
0, since then they would just be the secret, so:

1. Now nodes in tests start at x = 1 like `scheme::secret_share` deals them out.
2. I have added assert statements to reinforce this fact and guard against
   division by 0 panics.

This meant getting rid of the `evaluate_at_works` test, but
`interpolate_evaluate_at_0_eq_evaluate_at` provides a similar test.

Further work will include the use of barycentric weights in the `interpolate`
function.

A couple more interesting things to note about barycentric weights:

* Barycentric weights can be partially computed if less than threshold
  shares are present. When additional shares come in, computation can resume
  with no penalty to the total runtime.
* They can be determined totally independently from the y values of our points,
  and the x value we want to evaluate for. We only need to know the x values of
  our interpolation points.
2018-08-13 21:29:39 +02:00
f2a95add48 Small Rustfmt formatting fix to build.rs 2018-08-13 21:29:39 +02:00
910479f698 Start next development iteration 0.2.3-pre. 2018-05-17 10:53:01 +02:00
bdeb36d6d1 Release version 0.2.2. 2018-05-17 10:52:13 +02:00
a69d61dfbc Pin protobuf to >=1.4 && <1.6. Fixes #67 2018-05-17 10:37:05 +02:00
c112f7920b Start next development iteration 0.2.2-pre. 2018-03-08 00:41:31 +01:00
0148317495 Bump version to 0.2.1 2018-03-08 00:40:13 +01:00
e6ed97b7d7 Update changelog 2018-03-08 00:39:56 +01:00
9c123a900d Implement {Add, Div, Mul, Sub}Assign for Gf256 2018-03-06 13:45:48 +01:00
3de16890a4 Fix bug where threshold did not set deg of secret polynomial
Fixes #43.

Fixes a syntactic error. Threshold should determine the number of coefficients
in the secret polynomial. As is the code is equivalent to threshold always being
2.
2018-03-03 17:02:42 +01:00
3e89d1b1ca Add a test for issue #43.
Regardless of threshold, all polynomials are lines due to small syntactic error
2018-03-03 17:01:55 +01:00
7f9289eb1a Exclude protobuf-generated files from coverage report 2018-02-17 13:46:31 +01:00
efba922785 Configure kcov and coveralls.io 2018-02-16 17:03:39 +01:00
f5213706eb Update badges in README and fix CHANGELOG 2018-02-13 22:15:12 +01:00
13095ee690 Start next development iteration 0.1.1-pre. 2018-02-13 21:59:02 +01:00
1fbff5111f Release version 0.1.0. 2018-02-13 20:54:00 +01:00
474756e830 Remove generated documentation
The latest documentation will now be found in the `gh-pages` branch.
2018-02-13 20:48:41 +01:00