Commit 857f6de
authored
elliptic-curve: remove insecure
Implementing the idea I had in
#1864 (comment),
which in hindsight I actually think is better.
The new implementation actually *should* take ownership instead of just
cloning *for* the user. See [C-CALLER-CONTROL API
guidelines](https://rust-lang.github.io/api-guidelines/flexibility.html?highlight=clone#caller-decides-where-to-copy-and-place-data-c-caller-control).
This has the advantage of getting rid of the insecure `batch_invert_mut`
API where users have to make sure to actually check the returned
`Choice` and discard the input slice.
I could also quickly add the following for even more control if
desirable:
```rust
#[cfg(feature = "alloc")]
impl<'this, T> BatchInvert<&'this mut [Self]> for T
where
T: Field,
{
type Output = &'this mut [Self];
fn batch_invert(field_elements: &'this mut [Self]) -> CtOption<&'this mut [Self]> {
let mut field_elements_pad: Vec<Self> = vec![Self::default(); field_elements.len()];
let inversion_succeeded = invert_batch_internal(field_elements, &mut field_elements_pad);
CtOption::new(field_elements, inversion_succeeded)
}
}
```BatchInvert API (#1865)1 parent b01c581 commit 857f6de
1 file changed
+36
-24
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | 24 | | |
35 | 25 | | |
36 | 26 | | |
| |||
39 | 29 | | |
40 | 30 | | |
41 | 31 | | |
42 | | - | |
43 | | - | |
44 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
45 | 36 | | |
46 | | - | |
| 37 | + | |
47 | 38 | | |
| 39 | + | |
48 | 40 | | |
49 | | - | |
50 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
51 | 51 | | |
52 | | - | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
| 57 | + | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
65 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
66 | 68 | | |
67 | | - | |
| 69 | + | |
68 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
69 | 79 | | |
70 | | - | |
| 80 | + | |
71 | 81 | | |
| 82 | + | |
| 83 | + | |
72 | 84 | | |
73 | | - | |
| 85 | + | |
74 | 86 | | |
75 | 87 | | |
76 | 88 | | |
| |||
0 commit comments