Fix issues found in Quarkslab audit #276
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A Quarkslab audit (to be published shortly) looked through the
curve25519-dalek
source code; this PR fixes the issues they identified.The only serious one is that, although the rest of the
Scalar
API works with canonical scalars, the API has an "invariant loophole",Scalar::from_bits
, which allows constructing non-reduced scalars for use in, e.g., X/Ed25519, which mandate the use of non-reduced scalars.However, although the group operations (scalar, point) were designed to operate on non-reduced scalars, this was not true of (scalar, scalar) addition and subtraction, and so it was possible to use the API to explicitly construct large, unreduced
Scalar
s viafrom_bits
and then perform additions and subtractions which compute incorrect results. This is now fixed, with tests that ensure that addition and subtraction work correctly on very largeScalar
values.A search of
Scalar::from_bits
of all Rust code on Github suggests that the function is mostly only used to implement X/Ed25519, which don't do those operations, so it's unlikely that this issue affects any existing code. This issue was noticed independently by @str4d in #238.Closes #238.