Skip to content

zeroize Vec's capacity() by extending #180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2019
Merged

zeroize Vec's capacity() by extending #180

merged 1 commit into from
May 7, 2019

Conversation

FauxFaux
Copy link
Contributor

@FauxFaux FauxFaux commented May 6, 2019

Fixes #178.

I added a test which uses set_len to observe that data has been zero'd.

I feel that this is useful, as it tests my code change, but it in no way tests the actual (post-optimisation) functionality of the library. I'm happy for it to be dropped, if someone else hates it. It is probably not guaranteed to pass, or even be safe (i.e. if clear() is changed to deallocate the storage).

@tarcieri
Copy link
Collaborator

tarcieri commented May 6, 2019

Needs rustfmt, otherwise thanks, this looks good

@tarcieri tarcieri merged commit 7a27d27 into iqlusioninc:master May 7, 2019
@tarcieri
Copy link
Collaborator

tarcieri commented May 7, 2019

Thanks!

tarcieri pushed a commit that referenced this pull request Oct 13, 2019
This changes the trait bounds for the `Zeroize` impl on `Vec<Z>` from:

```
Z: Clone + Default + Zeroize
```

to just:

```
Z: Zeroize
```

This is based on my experience trying to switch `curve25519-dalek` from
`clear_on_drop` to `zeroize` in this PR:

dalek-cryptography/curve25519-dalek#289

Notably there were several places I was unable to use `Zeroizing` in
conjunction with `Vec` because it requires `Clone` and `Default` in
order for the current safe impl of zeroizing the excess capacity in
`Vec`s. IMO this is an implementation detail leaking out which places
undue burden on the user and reduces overall utility.

This is another way of saying: this change effectively reverts #180.
I think we can eventually bring this functionality back using an unsafe
impl which writes zeroes to the excess capacity.

In general my opinion is if you're storing secrets in `Vec`, it's best
to avoid mutating that `Vec` and causing reallocations in the first
place. This is the goal of the `SecretVec` type in `secrecy`:

https://docs.rs/secrecy/latest/secrecy/type.SecretVec.html
tarcieri pushed a commit that referenced this pull request Oct 13, 2019
This changes the trait bounds for the `Zeroize` impl on `Vec<Z>` from:

    Z: Clone + Default + Zeroize

to just:

    Z: Zeroize

This is based on my experience trying to switch `curve25519-dalek` from
`clear_on_drop` to `zeroize` in this PR:

dalek-cryptography/curve25519-dalek#289

Notably there were several places I was unable to use `Zeroizing` in
conjunction with `Vec` because it requires `Clone` and `Default` in
order for the current safe impl of zeroizing the excess capacity in
`Vec`s. IMO this is an implementation detail leaking out which places
undue burden on the user and reduces overall utility.

This is another way of saying: this change effectively reverts #180.
I think we can eventually bring this functionality back using an unsafe
impl which writes zeroes to the excess capacity.

In general my opinion is if you're storing secrets in `Vec`, it's best
to avoid mutating that `Vec` and causing reallocations in the first
place. This is the goal of the `SecretVec` type in `secrecy`:

https://docs.rs/secrecy/latest/secrecy/type.SecretVec.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

zeroize: zero Vec capacity, not length
2 participants