Skip to content

Commit b76b924

Browse files
authored
Implement Lizard encoding/decoding (#826)
* Vendor lizard hash to curve from Signal * Add invalid Lizard encoding test * Added lizard details to readme and changelog * Upgrade ristretto.sage to Python3 * Add lizard test vector generation to ristretto.sage * Added map_to_curve and its inverse * Use CtOption instead of bitmasks; other cleanup * Add README to lizard folder * Split map_to_curve into map_to_curve and map_to_curve_restricted; make its inverse return 16 elements * Consolidate Ristretto Elligator functions into its own file
1 parent c3a82a8 commit b76b924

File tree

18 files changed

+1681
-427
lines changed

18 files changed

+1681
-427
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Go ed25519
2+
3+
Portions of curve25519-dalek were originally derived from Adam Langley's
4+
Go ed25519 implementation, found at <https://github.com/agl/ed25519/>,
5+
under the following licence:
6+
7+
```
8+
Copyright (c) 2012 The Go Authors. All rights reserved.
9+
10+
Redistribution and use in source and binary forms, with or without
11+
modification, are permitted provided that the following conditions are
12+
met:
13+
14+
* Redistributions of source code must retain the above copyright
15+
notice, this list of conditions and the following disclaimer.
16+
* Redistributions in binary form must reproduce the above
17+
copyright notice, this list of conditions and the following disclaimer
18+
in the documentation and/or other materials provided with the
19+
distribution.
20+
* Neither the name of Google Inc. nor the names of its
21+
contributors may be used to endorse or promote products derived from
22+
this software without specific prior written permission.
23+
24+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25+
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26+
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
27+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
28+
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35+
```
36+
37+
# Lizard
38+
39+
The `src/lizard` directory was copied from [Signal's curve25519-dalek repo]( https://github.com/signalapp/curve25519-dalek/tree/7c6d34756355a3566a704da84dce7b1c039a6572). Its license is copied below
40+
41+
```
42+
MIT License
43+
44+
Copyright (c) 2019 Bas Westerbaan
45+
46+
Permission is hereby granted, free of charge, to any person obtaining a copy
47+
of this software and associated documentation files (the "Software"), to deal
48+
in the Software without restriction, including without limitation the rights
49+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
50+
copies of the Software, and to permit persons to whom the Software is
51+
furnished to do so, subject to the following conditions:
52+
53+
The above copyright notice and this permission notice shall be included in all
54+
copies or substantial portions of the Software.
55+
56+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
57+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
58+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
59+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
60+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
61+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
62+
SOFTWARE.
63+
```

curve25519-dalek/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ major series.
55

66
## 5.x series
77

8+
## Unreleased
9+
10+
* Add Lizard bytes-to-point injection for Ristretto. Gated under `lizard`.
11+
812
## 5.0.0-pre.1
913

1014
* Rename `Scalar::batch_invert` -> `Scalar::invert_batch` for consistency. Also make it no-alloc.

curve25519-dalek/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ legacy_compatibility = []
8383
group = ["dep:group", "rand_core"]
8484
group-bits = ["group", "ff/bits"]
8585
digest = ["dep:digest"]
86+
lizard = ["digest"]
8687

8788
[target.'cfg(all(not(curve25519_dalek_backend = "fiat"), not(curve25519_dalek_backend = "serial"), target_arch = "x86_64"))'.dependencies]
8889
curve25519-dalek-derive = "0.1"

curve25519-dalek/LICENSE

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,40 +26,4 @@ TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
2626
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
2727
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
2828
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29-
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30-
31-
========================================================================
32-
33-
Portions of curve25519-dalek were originally derived from Adam Langley's
34-
Go ed25519 implementation, found at <https://github.com/agl/ed25519/>,
35-
under the following licence:
36-
37-
========================================================================
38-
39-
Copyright (c) 2012 The Go Authors. All rights reserved.
40-
41-
Redistribution and use in source and binary forms, with or without
42-
modification, are permitted provided that the following conditions are
43-
met:
44-
45-
* Redistributions of source code must retain the above copyright
46-
notice, this list of conditions and the following disclaimer.
47-
* Redistributions in binary form must reproduce the above
48-
copyright notice, this list of conditions and the following disclaimer
49-
in the documentation and/or other materials provided with the
50-
distribution.
51-
* Neither the name of Google Inc. nor the names of its
52-
contributors may be used to endorse or promote products derived from
53-
this software without specific prior written permission.
54-
55-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
56-
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
57-
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
58-
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
59-
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
60-
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
61-
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
62-
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
63-
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
64-
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
6529
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

curve25519-dalek/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ curve25519-dalek = ">= 5.0, < 5.2"
5757
| `legacy_compatibility`| | Enables `Scalar::from_bits`, which allows the user to build unreduced scalars whose arithmetic is broken. Do not use this unless you know what you're doing. |
5858
| `group` | | Enables external `group` and `ff` crate traits. |
5959
| `group-bits` | | Enables `group` and impls `ff::PrimeFieldBits` for `Scalar`. |
60+
| `lizard` | | Enables the [Lizard](src/lizard/README.md) bytestring-to-point injection for `RistrettoPoint`. Specifically enables the methods `lizard_encode` and `lizard_decode`. |
6061

6162
To disable the default features when using `curve25519-dalek` as a dependency,
6263
add `default-features = false` to the dependency in your `Cargo.toml`. To

curve25519-dalek/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl std::fmt::Display for DalekBits {
1717
DalekBits::Dalek32 => "32",
1818
DalekBits::Dalek64 => "64",
1919
};
20-
write!(f, "{}", w_bits)
20+
write!(f, "{w_bits}")
2121
}
2222
}
2323

curve25519-dalek/src/field.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ impl ConstantTimeEq for FieldElement {
9898
}
9999
}
100100

101+
impl Default for FieldElement {
102+
fn default() -> Self {
103+
FieldElement::ZERO
104+
}
105+
}
106+
101107
impl FieldElement {
102108
/// Load a `FieldElement` from 64 bytes, by reducing modulo q.
103109
#[cfg(feature = "digest")]

curve25519-dalek/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ pub(crate) mod backend;
9090
// Generic code for window lookups
9191
pub(crate) mod window;
9292

93+
#[cfg(feature = "lizard")]
94+
pub mod lizard;
95+
9396
pub use crate::{
9497
edwards::EdwardsPoint, montgomery::MontgomeryPoint, ristretto::RistrettoPoint, scalar::Scalar,
9598
};

0 commit comments

Comments
 (0)