Skip to content

SNOW-0000: Move rust to random-access and general polish#8

Open
sfc-gh-grubin wants to merge 6 commits intomainfrom
03-18-snow-0000_initial_move_to_ra_core_for_rust
Open

SNOW-0000: Move rust to random-access and general polish#8
sfc-gh-grubin wants to merge 6 commits intomainfrom
03-18-snow-0000_initial_move_to_ra_core_for_rust

Conversation

@sfc-gh-grubin
Copy link
Copy Markdown
Collaborator

This PR is the first of several to prepare the rust reference code for more general use.

  1. Buildable and testable directly through cargo (required duplicating KATs)
  2. Refactored to use and expose the random-access APIs
  3. Added initial documentation
  4. Simplified some errors

Further work includes:

  1. Better testing
  2. Better documentation
  3. no-alloc/no-std builds for some consumers.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Errors cannot have Box in them when this is no-std. I will look for a way around this during this pass

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just stripped them out and accepted that we won't be able to track errors.

}

impl FloeCryptor for FloeEncryptor {
impl FloeSequentialCryptor for FloeSequentialEncryptor {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These names are really close to each other. Could you make them separate? If not, is it necessary that there be a trait at all?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it makes it easier to build higher level constructions which use FLOE as an underlying transformation. For example, I want to create a transforming iterator at some point in the future, and almost all of the logic can be made generic over this common interface.

*
* // Normally you'd save your key in some safe location. But for the demo we'll generate a random one
* // GCM256_IV256_1M is a generally useful chunk size
* let sample_key = FloeKey::new_random(GCM256_IV256_1M);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for future: the norm now is that you put these functions behind a default getrandom feature. The fallback is a function that just takes an RNG

* ```
*/
pub trait FloeCryptor {
pub trait FloeSequentialCryptor {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would you want a trait that covers both encryption and decryption? Why a trait at all, and not just a separate API for the encryptors and decryptors?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See prior note. I find it makes higher constructions simpler. I'm willing to accept that this is a bad idea and remove it though.

rust/Cargo.toml Outdated
path="floe/src/lib.rs"

[dependencies]
aead = { version = "0.5.2", features = ["std"] }
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the std will have to go eventually

poljar and others added 3 commits March 31, 2026 13:03
…ust (#9)

* refactor: Use the chain_update method when deriving a key

Since we have a lot of update calls in a sequence it is nicer to use the
chain_update method which was created just for such scenarios.

* chore: Rename raw to key_array inside the FloeKey::derive_key method

Raw is a weak keyword[1] in used for the raw borrow operators[2], so let's avoid that name.

[1]: https://doc.rust-lang.org/reference/keywords.html#weak-keywords
[2]: https://doc.rust-lang.org/reference/expressions/operator-expr.html#raw-borrow-operators

* refactor: Copy secret key material bytes directly instead of using to_owned

It is an open secret that Rust will compile a move of a value into a
memory copy[1].

While using to_owned on a byte slice isn't a move, copying the bytes
directly makes it more obvious that no moving will happen under the
hood.

[1]: https://benma.github.io/2020/10/16/rust-zeroize-move.html

* fix: Zeroize the intermediate secret key bytes in derive_key

* docs: Add some documentation for the derive_key method and FloePurpose enum

* refactor: Avoid allocations in the FloePurpose::as_bytes method
@sfc-gh-grubin sfc-gh-grubin force-pushed the 03-18-snow-0000_initial_move_to_ra_core_for_rust branch from 6153278 to 5a751f6 Compare April 3, 2026 23:26
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.

3 participants