Commit 1e94064
authored
refactor: remove redundant heap allocation in OAEP decrypt_inner (#659)
`decrypt_inner` took `em` by reference but cloned it via `em.to_vec()` into the
returned `CtOption<(Vec<u8>, u32)>`. The caller then allocated again with
`out[index..].to_vec()`. Two heap allocations per decryption instead of
one.
Unlike PKCS#1 v1.5 which takes `Vec<u8>` by value, OAEP was forced to
clone due to borrowing. The clone was useless—the caller already had
`em`.
Changed return type from `CtOption<(Vec<u8>, u32)>` to `CtOption<u32>`
(index only). Callers now use `em` directly. One allocation removed;
behavior and constant-time properties unchanged.1 parent 16d8eaf commit 1e94064
1 file changed
Lines changed: 6 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
165 | | - | |
| 165 | + | |
166 | 166 | | |
167 | | - | |
| 167 | + | |
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
| |||
205 | 205 | | |
206 | 206 | | |
207 | 207 | | |
208 | | - | |
| 208 | + | |
209 | 209 | | |
210 | | - | |
| 210 | + | |
211 | 211 | | |
212 | 212 | | |
213 | 213 | | |
| |||
219 | 219 | | |
220 | 220 | | |
221 | 221 | | |
222 | | - | |
| 222 | + | |
223 | 223 | | |
224 | 224 | | |
225 | 225 | | |
| |||
256 | 256 | | |
257 | 257 | | |
258 | 258 | | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
| 259 | + | |
263 | 260 | | |
0 commit comments