Skip to content
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

Update to new Scalar API #293

Merged
merged 21 commits into from
Jun 12, 2023
Merged

Conversation

rozbb
Copy link
Contributor

@rozbb rozbb commented Mar 21, 2023

This removes all uses of Scalar::{from_bits, from_bits_clamped}. Some comments inline.

curve25519-dalek dependency is pinned to Git in Cargo.toml, with revision f460ae1 specified in Cargo.lock. I'll move this back to a semver dep once a new curve25519-dalek RC is cut.

@rozbb rozbb requested a review from tarcieri March 21, 2023 06:31
Cargo.toml Show resolved Hide resolved
src/signing.rs Outdated Show resolved Hide resolved
src/signing.rs Outdated Show resolved Hide resolved
src/signature.rs Show resolved Hide resolved
tests/x25519.rs Show resolved Hide resolved
@rozbb
Copy link
Contributor Author

rozbb commented Apr 1, 2023

Ready for final review.

Made a small change. ExpandedSecretKey::scalar_bytes should be unclamped bytes. This is both in keeping with what x25519-dalek does for its secret keys, and also is what age does.

Done. Tests are failing because we deprecated from_bits, and -D warnings doesn't like that. Gonna try to fix that. Then this is good to go.

Cargo.toml Show resolved Hide resolved
@tarcieri tarcieri mentioned this pull request Apr 2, 2023
.github/workflows/rust.yml Outdated Show resolved Hide resolved
@rozbb
Copy link
Contributor Author

rozbb commented Apr 10, 2023

@tarcieri ready again. Ended up not inlining check_scalar because the inline comments were extensive and useful. I just added doc comments to both versions.

Cargo.toml Show resolved Hide resolved
@rozbb
Copy link
Contributor Author

rozbb commented Jun 11, 2023

Ok should be ready to go. This also happens to fix the rare behavior change mentioned in #299 where ExpandedSecretKey deserialization might be different because it skipped clamping.

After this, I think this and x- need new passthrough feature flags simd, simd_avx2, simd_avx512, and that should be it for the next RC.

@tarcieri
Copy link
Contributor

After this, I think this and x- need new passthrough feature flags simd, simd_avx2, simd_avx512

I'm still definitely not sold on having a bunch of features for these backends.

I feel like we managed to remove a bunch of the complexity and knobs that introduced unnecessary choices which can be made by intermediate dependencies, only to reintroduce them.

We should probably reopen one of the issues we had discussing this or make a new one to (re-)discuss backend selection. There were many, many people opposed to the use of crate features for this and I think it provides unnecessary complexity with no immediate use cases.

@rozbb
Copy link
Contributor Author

rozbb commented Jun 12, 2023

Ok agreed. When you get a chance can you approve this?

src/hazmat.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@tarcieri tarcieri left a comment

Choose a reason for hiding this comment

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

This is fine but I'm not super wild about the use of unwrap.

@rozbb
Copy link
Contributor Author

rozbb commented Jun 12, 2023

Oh I'll change that

@rozbb
Copy link
Contributor Author

rozbb commented Jun 12, 2023

Ok I believe all the unwraps are entirely gone now

@rozbb rozbb merged commit 9b166b7 into dalek-cryptography:main Jun 12, 2023
Comment on lines +38 to +41
// `scalar_bytes` and `scalar` are separate, because the public key is computed as an unreduced
// scalar multiplication (ie `mul_base_clamped`), whereas the signing operations are done
// modulo l.
pub(crate) scalar_bytes: [u8; 32],
Copy link
Contributor

@tarcieri tarcieri Jun 30, 2023

Choose a reason for hiding this comment

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

I guess I overlooked this before.

@rozbb there are use cases like Ed25519-BIP32 where the private scalar is computed rather than clamped from bytes.

Adding this field means you can no longer construct an ExpandedSecretKey directly from a derived Scalar and prefix using the struct literal syntax ExpandedSecretKey { scalar, hash_prefix } and have to go through one of the constructor methods.

I guess the best you could do now if you have a scalar and a hash_prefix is to serialize the scalar with Scalar::to_bytes and concatenate it with the hash_prefix and use ExpandedSecretKey::from_bytes?

Also all that aside, I find a mixture of public and private fields weird. If you really want to go down this path it would probably be good to make scalar and hash_prefix into methods, removing the fields from pub visibility.

Copy link
Contributor

Choose a reason for hiding this comment

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

Opened a PR to make the other fields private: dalek-cryptography/curve25519-dalek#544

tarcieri added a commit to dalek-cryptography/curve25519-dalek that referenced this pull request Jul 2, 2023
Motivation can be found in this comment:

dalek-cryptography/ed25519-dalek#293 (review)

Replaces public fields with private fields + accessor methods.

Also adds an `ExpandedSecretKey::from_scalar_and_prefix` constructor
which makes it possible to construct `ExpandedSecretKey` using a
`Scalar` again, which is useful for protocols that derive the scalar
such as Ed25519-BIP32.

Additionally defines a `HashPrefix` type alias to make it semantically
clear which `[u8; 32]` is involved in type signatures.
tarcieri added a commit to dalek-cryptography/curve25519-dalek that referenced this pull request Jul 2, 2023
Motivation can be found in this comment:

dalek-cryptography/ed25519-dalek#293 (review)

Replaces public fields with private fields + accessor methods.

Also adds an `ExpandedSecretKey::from_scalar_and_prefix` constructor
which makes it possible to construct `ExpandedSecretKey` using a
`Scalar` again, which is useful for protocols that derive the scalar
such as Ed25519-BIP32.

Additionally defines a `HashPrefix` type alias to make it semantically
clear which `[u8; 32]` is involved in type signatures.
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.

2 participants