Skip to main content

curve25519_dalek/ristretto/
elligator.rs

1//! Contains methods implementing Elligator2 maps from [RFC 9496](https://www.rfc-editor.org/rfc/rfc9496.html)
2
3use crate::{constants, field::FieldElement, ristretto::RistrettoPoint};
4use subtle::{ConditionallyNegatable, ConditionallySelectable};
5
6impl RistrettoPoint {
7    /// Computes the Ristretto Elligator map for the given field element. This is the second half of
8    /// the [`MAP`](https://www.rfc-editor.org/rfc/rfc9496.html#section-4.3.4-4) function defined in
9    /// the Ristretto spec.
10    ///
11    /// # Note
12    ///
13    /// This method is not public because it's just used for hashing
14    /// to a point -- proper elligator support is deferred for now.
15    pub(crate) fn elligator_ristretto_flavor(r_0: &FieldElement) -> RistrettoPoint {
16        let i = &constants::SQRT_M1;
17        let d = &constants::EDWARDS_D;
18        let one_minus_d_sq = &constants::ONE_MINUS_EDWARDS_D_SQUARED;
19        let d_minus_one_sq = &constants::EDWARDS_D_MINUS_ONE_SQUARED;
20        let mut c = constants::MINUS_ONE;
21
22        let one = FieldElement::ONE;
23
24        let r = i * &r_0.square();
25        let N_s = &(&r + &one) * one_minus_d_sq;
26        let D = &(&c - &(d * &r)) * &(&r + d);
27
28        let (Ns_D_is_sq, mut s) = FieldElement::sqrt_ratio_i(&N_s, &D);
29        let mut s_prime = &s * r_0;
30        let s_prime_is_pos = !s_prime.is_negative();
31        s_prime.conditional_negate(s_prime_is_pos);
32
33        s.conditional_assign(&s_prime, !Ns_D_is_sq);
34        c.conditional_assign(&r, !Ns_D_is_sq);
35
36        let N_t = &(&(&c * &(&r - &one)) * d_minus_one_sq) - &D;
37        let s_sq = s.square();
38
39        use crate::backend::serial::curve_models::CompletedPoint;
40
41        // The conversion from W_i is exactly the conversion from P1xP1.
42        RistrettoPoint(
43            CompletedPoint {
44                X: &(&s + &s) * &D,
45                Z: &N_t * &constants::SQRT_AD_MINUS_ONE,
46                Y: &FieldElement::ONE - &s_sq,
47                T: &FieldElement::ONE + &s_sq,
48            }
49            .as_extended(),
50        )
51    }
52
53    /// Interprets the given bytestring as a field element and computes the Ristretto Elligator map.
54    /// This is the [MAP](https://www.rfc-editor.org/rfc/rfc9496.html#section-4.3.4-4) function in
55    /// RFC 9496.
56    ///
57    /// # Warning
58    ///
59    /// This function does not produce cryptographically random-looking Ristretto points. Use
60    /// [`Self::from_uniform_bytes`] or [`Self::hash_from_bytes`] for that. DO NOT USE THIS FUNCTION
61    /// unless you really know what you're doing.
62    pub fn map_to_curve(bytes: [u8; 32]) -> RistrettoPoint {
63        // MAP must clear the top bit. This is done in `from_bytes` for every field backend, so we
64        // don't have to do it ourselves here
65        let fe = FieldElement::from_bytes(&bytes);
66        RistrettoPoint::elligator_ristretto_flavor(&fe)
67    }
68}
69
70#[cfg(test)]
71mod test {
72    use super::*;
73    use crate::ristretto::CompressedRistretto;
74
75    #[test]
76    fn elligator_vs_ristretto_sage() {
77        // Test vectors extracted from ristretto.sage.
78        //
79        // Notice that all of the byte sequences have bit 255 set to 0; this is because
80        // ristretto.sage does not mask the high bit of a field element.  When the high bit is set,
81        // the ristretto.sage elligator implementation gives different results, since it takes a
82        // different field element as input.
83        let bytes: [[u8; 32]; 16] = [
84            [
85                184, 249, 135, 49, 253, 123, 89, 113, 67, 160, 6, 239, 7, 105, 211, 41, 192, 249,
86                185, 57, 9, 102, 70, 198, 15, 127, 7, 26, 160, 102, 134, 71,
87            ],
88            [
89                229, 14, 241, 227, 75, 9, 118, 60, 128, 153, 226, 21, 183, 217, 91, 136, 98, 0,
90                231, 156, 124, 77, 82, 139, 142, 134, 164, 169, 169, 62, 250, 52,
91            ],
92            [
93                115, 109, 36, 220, 180, 223, 99, 6, 204, 169, 19, 29, 169, 68, 84, 23, 21, 109,
94                189, 149, 127, 205, 91, 102, 172, 35, 112, 35, 134, 69, 186, 34,
95            ],
96            [
97                16, 49, 96, 107, 171, 199, 164, 9, 129, 16, 64, 62, 241, 63, 132, 173, 209, 160,
98                112, 215, 105, 50, 157, 81, 253, 105, 1, 154, 229, 25, 120, 83,
99            ],
100            [
101                156, 131, 161, 162, 236, 251, 5, 187, 167, 171, 17, 178, 148, 210, 90, 207, 86, 21,
102                79, 161, 167, 215, 234, 1, 136, 242, 182, 248, 38, 85, 79, 86,
103            ],
104            [
105                251, 177, 124, 54, 18, 101, 75, 235, 245, 186, 19, 46, 133, 157, 229, 64, 10, 136,
106                181, 185, 78, 144, 254, 167, 137, 49, 107, 10, 61, 10, 21, 25,
107            ],
108            [
109                232, 193, 20, 68, 240, 77, 186, 77, 183, 40, 44, 86, 150, 31, 198, 212, 76, 81, 3,
110                217, 197, 8, 126, 128, 126, 152, 164, 208, 153, 44, 189, 77,
111            ],
112            [
113                173, 229, 149, 177, 37, 230, 30, 69, 61, 56, 172, 190, 219, 115, 167, 194, 71, 134,
114                59, 75, 28, 244, 118, 26, 162, 97, 64, 16, 15, 189, 30, 64,
115            ],
116            [
117                106, 71, 61, 107, 250, 117, 42, 151, 91, 202, 212, 100, 52, 188, 190, 21, 125, 218,
118                31, 18, 253, 241, 160, 133, 57, 242, 3, 164, 189, 68, 111, 75,
119            ],
120            [
121                112, 204, 182, 90, 220, 198, 120, 73, 173, 107, 193, 17, 227, 40, 162, 36, 150,
122                141, 235, 55, 172, 183, 12, 39, 194, 136, 43, 153, 244, 118, 91, 89,
123            ],
124            [
125                111, 24, 203, 123, 254, 189, 11, 162, 51, 196, 163, 136, 204, 143, 10, 222, 33,
126                112, 81, 205, 34, 35, 8, 66, 90, 6, 164, 58, 170, 177, 34, 25,
127            ],
128            [
129                225, 183, 30, 52, 236, 82, 6, 183, 109, 25, 227, 181, 25, 82, 41, 193, 80, 77, 161,
130                80, 242, 203, 79, 204, 136, 245, 131, 110, 237, 106, 3, 58,
131            ],
132            [
133                207, 246, 38, 56, 30, 86, 176, 90, 27, 200, 61, 42, 221, 27, 56, 210, 79, 178, 189,
134                120, 68, 193, 120, 167, 77, 185, 53, 197, 124, 128, 191, 126,
135            ],
136            [
137                1, 136, 215, 80, 240, 46, 63, 147, 16, 244, 230, 207, 82, 189, 74, 50, 106, 169,
138                138, 86, 30, 131, 214, 202, 166, 125, 251, 228, 98, 24, 36, 21,
139            ],
140            [
141                210, 207, 228, 56, 155, 116, 207, 54, 84, 195, 251, 215, 249, 199, 116, 75, 109,
142                239, 196, 251, 194, 246, 252, 228, 70, 146, 156, 35, 25, 39, 241, 4,
143            ],
144            [
145                34, 116, 123, 9, 8, 40, 93, 189, 9, 103, 57, 103, 66, 227, 3, 2, 157, 107, 134,
146                219, 202, 74, 230, 154, 78, 107, 219, 195, 214, 14, 84, 80,
147            ],
148        ];
149        let encoded_images: [CompressedRistretto; 16] = [
150            CompressedRistretto([
151                176, 157, 237, 97, 66, 29, 140, 166, 168, 94, 26, 157, 212, 216, 229, 160, 195,
152                246, 232, 239, 169, 112, 63, 193, 64, 32, 152, 69, 11, 190, 246, 86,
153            ]),
154            CompressedRistretto([
155                234, 141, 77, 203, 181, 225, 250, 74, 171, 62, 15, 118, 78, 212, 150, 19, 131, 14,
156                188, 238, 194, 244, 141, 138, 166, 162, 83, 122, 228, 201, 19, 26,
157            ]),
158            CompressedRistretto([
159                232, 231, 51, 92, 5, 168, 80, 36, 173, 179, 104, 68, 186, 149, 68, 40, 140, 170,
160                27, 103, 99, 140, 21, 242, 43, 62, 250, 134, 208, 255, 61, 89,
161            ]),
162            CompressedRistretto([
163                208, 120, 140, 129, 177, 179, 237, 159, 252, 160, 28, 13, 206, 5, 211, 241, 192,
164                218, 1, 97, 130, 241, 20, 169, 119, 46, 246, 29, 79, 80, 77, 84,
165            ]),
166            CompressedRistretto([
167                202, 11, 236, 145, 58, 12, 181, 157, 209, 6, 213, 88, 75, 147, 11, 119, 191, 139,
168                47, 142, 33, 36, 153, 193, 223, 183, 178, 8, 205, 120, 248, 110,
169            ]),
170            CompressedRistretto([
171                26, 66, 231, 67, 203, 175, 116, 130, 32, 136, 62, 253, 215, 46, 5, 214, 166, 248,
172                108, 237, 216, 71, 244, 173, 72, 133, 82, 6, 143, 240, 104, 41,
173            ]),
174            CompressedRistretto([
175                40, 157, 102, 96, 201, 223, 200, 197, 150, 181, 106, 83, 103, 126, 143, 33, 145,
176                230, 78, 6, 171, 146, 210, 143, 112, 5, 245, 23, 183, 138, 18, 120,
177            ]),
178            CompressedRistretto([
179                220, 37, 27, 203, 239, 196, 176, 131, 37, 66, 188, 243, 185, 250, 113, 23, 167,
180                211, 154, 243, 168, 215, 54, 171, 159, 36, 195, 81, 13, 150, 43, 43,
181            ]),
182            CompressedRistretto([
183                232, 121, 176, 222, 183, 196, 159, 90, 238, 193, 105, 52, 101, 167, 244, 170, 121,
184                114, 196, 6, 67, 152, 80, 185, 221, 7, 83, 105, 176, 208, 224, 121,
185            ]),
186            CompressedRistretto([
187                226, 181, 183, 52, 241, 163, 61, 179, 221, 207, 220, 73, 245, 242, 25, 236, 67, 84,
188                179, 222, 167, 62, 167, 182, 32, 9, 92, 30, 165, 127, 204, 68,
189            ]),
190            CompressedRistretto([
191                226, 119, 16, 242, 200, 139, 240, 87, 11, 222, 92, 146, 156, 243, 46, 119, 65, 59,
192                1, 248, 92, 183, 50, 175, 87, 40, 206, 53, 208, 220, 148, 13,
193            ]),
194            CompressedRistretto([
195                70, 240, 79, 112, 54, 157, 228, 146, 74, 122, 216, 88, 232, 62, 158, 13, 14, 146,
196                115, 117, 176, 222, 90, 225, 244, 23, 94, 190, 150, 7, 136, 96,
197            ]),
198            CompressedRistretto([
199                22, 71, 241, 103, 45, 193, 195, 144, 183, 101, 154, 50, 39, 68, 49, 110, 51, 44,
200                62, 0, 229, 113, 72, 81, 168, 29, 73, 106, 102, 40, 132, 24,
201            ]),
202            CompressedRistretto([
203                196, 133, 107, 11, 130, 105, 74, 33, 204, 171, 133, 221, 174, 193, 241, 36, 38,
204                179, 196, 107, 219, 185, 181, 253, 228, 47, 155, 42, 231, 73, 41, 78,
205            ]),
206            CompressedRistretto([
207                58, 255, 225, 197, 115, 208, 160, 143, 39, 197, 82, 69, 143, 235, 92, 170, 74, 40,
208                57, 11, 171, 227, 26, 185, 217, 207, 90, 185, 197, 190, 35, 60,
209            ]),
210            CompressedRistretto([
211                88, 43, 92, 118, 223, 136, 105, 145, 238, 186, 115, 8, 214, 112, 153, 253, 38, 108,
212                205, 230, 157, 130, 11, 66, 101, 85, 253, 110, 110, 14, 148, 112,
213            ]),
214        ];
215        for i in 0..16 {
216            let r_0 = FieldElement::from_bytes(&bytes[i]);
217            let Q = RistrettoPoint::elligator_ristretto_flavor(&r_0);
218            assert_eq!(Q.compress(), encoded_images[i]);
219        }
220    }
221
222    // Known answer tests for the one-way mapping function in the Ristretto RFC
223    #[test]
224    fn one_way_map() {
225        // These inputs are from
226        // https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-ristretto255-decaf448-04#appendix-A.3
227        let test_vectors: &[([u8; 64], CompressedRistretto)] = &[
228            (
229                [
230                    0x5d, 0x1b, 0xe0, 0x9e, 0x3d, 0x0c, 0x82, 0xfc, 0x53, 0x81, 0x12, 0x49, 0x0e,
231                    0x35, 0x70, 0x19, 0x79, 0xd9, 0x9e, 0x06, 0xca, 0x3e, 0x2b, 0x5b, 0x54, 0xbf,
232                    0xfe, 0x8b, 0x4d, 0xc7, 0x72, 0xc1, 0x4d, 0x98, 0xb6, 0x96, 0xa1, 0xbb, 0xfb,
233                    0x5c, 0xa3, 0x2c, 0x43, 0x6c, 0xc6, 0x1c, 0x16, 0x56, 0x37, 0x90, 0x30, 0x6c,
234                    0x79, 0xea, 0xca, 0x77, 0x05, 0x66, 0x8b, 0x47, 0xdf, 0xfe, 0x5b, 0xb6,
235                ],
236                CompressedRistretto([
237                    0x30, 0x66, 0xf8, 0x2a, 0x1a, 0x74, 0x7d, 0x45, 0x12, 0x0d, 0x17, 0x40, 0xf1,
238                    0x43, 0x58, 0x53, 0x1a, 0x8f, 0x04, 0xbb, 0xff, 0xe6, 0xa8, 0x19, 0xf8, 0x6d,
239                    0xfe, 0x50, 0xf4, 0x4a, 0x0a, 0x46,
240                ]),
241            ),
242            (
243                [
244                    0xf1, 0x16, 0xb3, 0x4b, 0x8f, 0x17, 0xce, 0xb5, 0x6e, 0x87, 0x32, 0xa6, 0x0d,
245                    0x91, 0x3d, 0xd1, 0x0c, 0xce, 0x47, 0xa6, 0xd5, 0x3b, 0xee, 0x92, 0x04, 0xbe,
246                    0x8b, 0x44, 0xf6, 0x67, 0x8b, 0x27, 0x01, 0x02, 0xa5, 0x69, 0x02, 0xe2, 0x48,
247                    0x8c, 0x46, 0x12, 0x0e, 0x92, 0x76, 0xcf, 0xe5, 0x46, 0x38, 0x28, 0x6b, 0x9e,
248                    0x4b, 0x3c, 0xdb, 0x47, 0x0b, 0x54, 0x2d, 0x46, 0xc2, 0x06, 0x8d, 0x38,
249                ],
250                CompressedRistretto([
251                    0xf2, 0x6e, 0x5b, 0x6f, 0x7d, 0x36, 0x2d, 0x2d, 0x2a, 0x94, 0xc5, 0xd0, 0xe7,
252                    0x60, 0x2c, 0xb4, 0x77, 0x3c, 0x95, 0xa2, 0xe5, 0xc3, 0x1a, 0x64, 0xf1, 0x33,
253                    0x18, 0x9f, 0xa7, 0x6e, 0xd6, 0x1b,
254                ]),
255            ),
256            (
257                [
258                    0x84, 0x22, 0xe1, 0xbb, 0xda, 0xab, 0x52, 0x93, 0x8b, 0x81, 0xfd, 0x60, 0x2e,
259                    0xff, 0xb6, 0xf8, 0x91, 0x10, 0xe1, 0xe5, 0x72, 0x08, 0xad, 0x12, 0xd9, 0xad,
260                    0x76, 0x7e, 0x2e, 0x25, 0x51, 0x0c, 0x27, 0x14, 0x07, 0x75, 0xf9, 0x33, 0x70,
261                    0x88, 0xb9, 0x82, 0xd8, 0x3d, 0x7f, 0xcf, 0x0b, 0x2f, 0xa1, 0xed, 0xff, 0xe5,
262                    0x19, 0x52, 0xcb, 0xe7, 0x36, 0x5e, 0x95, 0xc8, 0x6e, 0xaf, 0x32, 0x5c,
263                ],
264                CompressedRistretto([
265                    0x00, 0x6c, 0xcd, 0x2a, 0x9e, 0x68, 0x67, 0xe6, 0xa2, 0xc5, 0xce, 0xa8, 0x3d,
266                    0x33, 0x02, 0xcc, 0x9d, 0xe1, 0x28, 0xdd, 0x2a, 0x9a, 0x57, 0xdd, 0x8e, 0xe7,
267                    0xb9, 0xd7, 0xff, 0xe0, 0x28, 0x26,
268                ]),
269            ),
270            (
271                [
272                    0xac, 0x22, 0x41, 0x51, 0x29, 0xb6, 0x14, 0x27, 0xbf, 0x46, 0x4e, 0x17, 0xba,
273                    0xee, 0x8d, 0xb6, 0x59, 0x40, 0xc2, 0x33, 0xb9, 0x8a, 0xfc, 0xe8, 0xd1, 0x7c,
274                    0x57, 0xbe, 0xeb, 0x78, 0x76, 0xc2, 0x15, 0x0d, 0x15, 0xaf, 0x1c, 0xb1, 0xfb,
275                    0x82, 0x4b, 0xbd, 0x14, 0x95, 0x5f, 0x2b, 0x57, 0xd0, 0x8d, 0x38, 0x8a, 0xab,
276                    0x43, 0x1a, 0x39, 0x1c, 0xfc, 0x33, 0xd5, 0xba, 0xfb, 0x5d, 0xbb, 0xaf,
277                ],
278                CompressedRistretto([
279                    0xf8, 0xf0, 0xc8, 0x7c, 0xf2, 0x37, 0x95, 0x3c, 0x58, 0x90, 0xae, 0xc3, 0x99,
280                    0x81, 0x69, 0x00, 0x5d, 0xae, 0x3e, 0xca, 0x1f, 0xbb, 0x04, 0x54, 0x8c, 0x63,
281                    0x59, 0x53, 0xc8, 0x17, 0xf9, 0x2a,
282                ]),
283            ),
284            (
285                [
286                    0x16, 0x5d, 0x69, 0x7a, 0x1e, 0xf3, 0xd5, 0xcf, 0x3c, 0x38, 0x56, 0x5b, 0xee,
287                    0xfc, 0xf8, 0x8c, 0x0f, 0x28, 0x2b, 0x8e, 0x7d, 0xbd, 0x28, 0x54, 0x4c, 0x48,
288                    0x34, 0x32, 0xf1, 0xce, 0xc7, 0x67, 0x5d, 0xeb, 0xea, 0x8e, 0xbb, 0x4e, 0x5f,
289                    0xe7, 0xd6, 0xf6, 0xe5, 0xdb, 0x15, 0xf1, 0x55, 0x87, 0xac, 0x4d, 0x4d, 0x4a,
290                    0x1d, 0xe7, 0x19, 0x1e, 0x0c, 0x1c, 0xa6, 0x66, 0x4a, 0xbc, 0xc4, 0x13,
291                ],
292                CompressedRistretto([
293                    0xae, 0x81, 0xe7, 0xde, 0xdf, 0x20, 0xa4, 0x97, 0xe1, 0x0c, 0x30, 0x4a, 0x76,
294                    0x5c, 0x17, 0x67, 0xa4, 0x2d, 0x6e, 0x06, 0x02, 0x97, 0x58, 0xd2, 0xd7, 0xe8,
295                    0xef, 0x7c, 0xc4, 0xc4, 0x11, 0x79,
296                ]),
297            ),
298            (
299                [
300                    0xa8, 0x36, 0xe6, 0xc9, 0xa9, 0xca, 0x9f, 0x1e, 0x8d, 0x48, 0x62, 0x73, 0xad,
301                    0x56, 0xa7, 0x8c, 0x70, 0xcf, 0x18, 0xf0, 0xce, 0x10, 0xab, 0xb1, 0xc7, 0x17,
302                    0x2d, 0xdd, 0x60, 0x5d, 0x7f, 0xd2, 0x97, 0x98, 0x54, 0xf4, 0x7a, 0xe1, 0xcc,
303                    0xf2, 0x04, 0xa3, 0x31, 0x02, 0x09, 0x5b, 0x42, 0x00, 0xe5, 0xbe, 0xfc, 0x04,
304                    0x65, 0xac, 0xcc, 0x26, 0x31, 0x75, 0x48, 0x5f, 0x0e, 0x17, 0xea, 0x5c,
305                ],
306                CompressedRistretto([
307                    0xe2, 0x70, 0x56, 0x52, 0xff, 0x9f, 0x5e, 0x44, 0xd3, 0xe8, 0x41, 0xbf, 0x1c,
308                    0x25, 0x1c, 0xf7, 0xdd, 0xdb, 0x77, 0xd1, 0x40, 0x87, 0x0d, 0x1a, 0xb2, 0xed,
309                    0x64, 0xf1, 0xa9, 0xce, 0x86, 0x28,
310                ]),
311            ),
312            (
313                [
314                    0x2c, 0xdc, 0x11, 0xea, 0xeb, 0x95, 0xda, 0xf0, 0x11, 0x89, 0x41, 0x7c, 0xdd,
315                    0xdb, 0xf9, 0x59, 0x52, 0x99, 0x3a, 0xa9, 0xcb, 0x9c, 0x64, 0x0e, 0xb5, 0x05,
316                    0x8d, 0x09, 0x70, 0x2c, 0x74, 0x62, 0x2c, 0x99, 0x65, 0xa6, 0x97, 0xa3, 0xb3,
317                    0x45, 0xec, 0x24, 0xee, 0x56, 0x33, 0x5b, 0x55, 0x6e, 0x67, 0x7b, 0x30, 0xe6,
318                    0xf9, 0x0a, 0xc7, 0x7d, 0x78, 0x10, 0x64, 0xf8, 0x66, 0xa3, 0xc9, 0x82,
319                ],
320                CompressedRistretto([
321                    0x80, 0xbd, 0x07, 0x26, 0x25, 0x11, 0xcd, 0xde, 0x48, 0x63, 0xf8, 0xa7, 0x43,
322                    0x4c, 0xef, 0x69, 0x67, 0x50, 0x68, 0x1c, 0xb9, 0x51, 0x0e, 0xea, 0x55, 0x70,
323                    0x88, 0xf7, 0x6d, 0x9e, 0x50, 0x65,
324                ]),
325            ),
326            (
327                [
328                    0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
329                    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
330                    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
331                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
332                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
333                ],
334                CompressedRistretto([
335                    0x30, 0x42, 0x82, 0x79, 0x10, 0x23, 0xb7, 0x31, 0x28, 0xd2, 0x77, 0xbd, 0xcb,
336                    0x5c, 0x77, 0x46, 0xef, 0x2e, 0xac, 0x08, 0xdd, 0xe9, 0xf2, 0x98, 0x33, 0x79,
337                    0xcb, 0x8e, 0x5e, 0xf0, 0x51, 0x7f,
338                ]),
339            ),
340            (
341                [
342                    0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
343                    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
344                    0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
345                    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
346                    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
347                ],
348                CompressedRistretto([
349                    0x30, 0x42, 0x82, 0x79, 0x10, 0x23, 0xb7, 0x31, 0x28, 0xd2, 0x77, 0xbd, 0xcb,
350                    0x5c, 0x77, 0x46, 0xef, 0x2e, 0xac, 0x08, 0xdd, 0xe9, 0xf2, 0x98, 0x33, 0x79,
351                    0xcb, 0x8e, 0x5e, 0xf0, 0x51, 0x7f,
352                ]),
353            ),
354            (
355                [
356                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
357                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
358                    0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
359                    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
360                    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f,
361                ],
362                CompressedRistretto([
363                    0x30, 0x42, 0x82, 0x79, 0x10, 0x23, 0xb7, 0x31, 0x28, 0xd2, 0x77, 0xbd, 0xcb,
364                    0x5c, 0x77, 0x46, 0xef, 0x2e, 0xac, 0x08, 0xdd, 0xe9, 0xf2, 0x98, 0x33, 0x79,
365                    0xcb, 0x8e, 0x5e, 0xf0, 0x51, 0x7f,
366                ]),
367            ),
368            (
369                [
370                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
371                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
372                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
373                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
374                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
375                ],
376                CompressedRistretto([
377                    0x30, 0x42, 0x82, 0x79, 0x10, 0x23, 0xb7, 0x31, 0x28, 0xd2, 0x77, 0xbd, 0xcb,
378                    0x5c, 0x77, 0x46, 0xef, 0x2e, 0xac, 0x08, 0xdd, 0xe9, 0xf2, 0x98, 0x33, 0x79,
379                    0xcb, 0x8e, 0x5e, 0xf0, 0x51, 0x7f,
380                ]),
381            ),
382        ];
383        // Check that onewaymap(input) == output for all the above vectors
384        for (input, output) in test_vectors {
385            let Q = RistrettoPoint::from_uniform_bytes(input);
386            assert_eq!(&Q.compress(), output);
387        }
388    }
389}