Skip to content

crypto_box: select x25519-dalek backend automatically #55

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
Aug 10, 2022

Conversation

tarcieri
Copy link
Member

Introspects the target pointer width to automatically select either the u32_backend or u64_backend.

If the backend isn't 32/64-bit, generate a compile error with an informative message.

Removes the explicit u32_backend/u64_backend crate features in cargo_box itself. Now --all-features works.

Introspects the target pointer width to automatically select either the
`u32_backend` or `u64_backend`.

If the backend isn't 32/64-bit, generate a compile error with an
informative message.

Removes the explicit `u32_backend`/`u64_backend` crate features in
`cargo_box` itself. Now `--all-features` works.
@tarcieri tarcieri merged commit a994fbf into master Aug 10, 2022
@tarcieri tarcieri deleted the crypto_box/select-dalek-backend-automatically branch August 10, 2022 14:19
@tarcieri tarcieri mentioned this pull request Aug 10, 2022
tarcieri added a commit that referenced this pull request Aug 14, 2022
Introspects the target pointer width to automatically select either the
`u32_backend` or `u64_backend`, similar to #55.

If the backend isn't 32/64-bit, generate a compile error with an
informative message.
tarcieri added a commit that referenced this pull request Aug 14, 2022
Introspects the target pointer width to automatically select either the
`u32_backend` or `u64_backend`, similar to #55.

If the backend isn't 32/64-bit, generate a compile error with an
informative message.
@kurnevsky
Copy link
Contributor

kurnevsky commented Aug 14, 2022

Does this work when crypto_box is used as dependency (just adding crypto_box = "0.8")? It doesn't compile for me because for some reason u32_backend is enabled even though I have 64 bit architecture (which produces a lot of compilation errors).

@trevyn
Copy link
Contributor

trevyn commented Aug 14, 2022

I can also reproduce this, but I haven’t had a chance to fully debug what is going on.

@tarcieri
Copy link
Member Author

Sorry to hear this is causing issues. I can revert it. It would be great to get some more information about the error you're encountering though.

I can see how it might be an issue on 32-bit platforms, since u64_backend is enabled per default, and enabling two backends at once causes pages of compile errors, which you might encounter if you have another crate that also links curve25519-dalek. Is that what you're encountering?

FWIW, it builds on two 32-bit targets in CI. And I just pushed up a PR that adds full cross tests: #62

@trevyn
Copy link
Contributor

trevyn commented Aug 14, 2022

Here's the errors: https://github.com/trevyn/sealed_box/runs/7829889187

% cargo tree -i curve25519-dalek
curve25519-dalek v3.2.0
└── x25519-dalek v1.1.1
    └── crypto_box v0.8.0
        └── sealed_box v0.1.1 (/Users/e/Documents/GitHub/sealed_box)

@tarcieri
Copy link
Member Author

Yeah, that looks like two backends were activated at the same time. Is there not another dependency that uses curve25519-dalek?

Regardless I guess this doesn't work because other dependencies may activate a different backend so fine-grained control is needed to match.

@kurnevsky
Copy link
Contributor

kurnevsky commented Aug 15, 2022

Yeah, that looks like two backends were activated at the same time. Is there not another dependency that uses curve25519-dalek?

Yes, the only dependency I add is crypto_box = "0.8". Here is the cargo tree:

tox_crypto v0.1.1 (/home/kurnevsky/workspace/tox/tox_crypto)
└── crypto_box v0.8.0
    ├── aead v0.5.1
    │   ├── crypto-common v0.1.6
    │   │   ├── generic-array v0.14.6
    │   │   │   └── typenum v1.15.0
    │   │   │   [build-dependencies]
    │   │   │   └── version_check v0.9.4
    │   │   ├── rand_core v0.6.3
    │   │   │   └── getrandom v0.2.7
    │   │   │       ├── cfg-if v1.0.0
    │   │   │       └── libc v0.2.131
    │   │   └── typenum v1.15.0
    │   └── generic-array v0.14.6 (*)
    ├── chacha20 v0.9.0
    │   ├── cfg-if v1.0.0
    │   ├── cipher v0.4.3
    │   │   ├── crypto-common v0.1.6 (*)
    │   │   ├── inout v0.1.3
    │   │   │   └── generic-array v0.14.6 (*)
    │   │   └── zeroize v1.5.7
    │   │       └── zeroize_derive v1.3.2 (proc-macro)
    │   │           ├── proc-macro2 v1.0.43
    │   │           │   └── unicode-ident v1.0.3
    │   │           ├── quote v1.0.21
    │   │           │   └── proc-macro2 v1.0.43 (*)
    │   │           ├── syn v1.0.99
    │   │           │   ├── proc-macro2 v1.0.43 (*)
    │   │           │   ├── quote v1.0.21 (*)
    │   │           │   └── unicode-ident v1.0.3
    │   │           └── synstructure v0.12.6
    │   │               ├── proc-macro2 v1.0.43 (*)
    │   │               ├── quote v1.0.21 (*)
    │   │               ├── syn v1.0.99 (*)
    │   │               └── unicode-xid v0.2.3
    │   └── cpufeatures v0.2.2
    ├── chacha20poly1305 v0.10.1
    │   ├── aead v0.5.1 (*)
    │   ├── chacha20 v0.9.0 (*)
    │   ├── cipher v0.4.3 (*)
    │   ├── poly1305 v0.8.0
    │   │   ├── cpufeatures v0.2.2
    │   │   ├── opaque-debug v0.3.0
    │   │   └── universal-hash v0.5.0
    │   │       ├── crypto-common v0.1.6 (*)
    │   │       └── subtle v2.4.1
    │   └── zeroize v1.5.7 (*)
    ├── salsa20 v0.10.2
    │   └── cipher v0.4.3 (*)
    ├── x25519-dalek v1.1.1
    │   ├── curve25519-dalek v3.2.0
    │   │   ├── byteorder v1.4.3
    │   │   ├── digest v0.9.0
    │   │   │   └── generic-array v0.14.6 (*)
    │   │   ├── rand_core v0.5.1
    │   │   ├── subtle v2.4.1
    │   │   └── zeroize v1.5.7 (*)
    │   ├── rand_core v0.5.1
    │   └── zeroize v1.5.7 (*)
    ├── xsalsa20poly1305 v0.9.0
    │   ├── aead v0.5.1 (*)
    │   ├── poly1305 v0.8.0 (*)
    │   ├── salsa20 v0.10.2 (*)
    │   ├── subtle v2.4.1
    │   └── zeroize v1.5.7 (*)
    └── zeroize v1.5.7 (*)

Regardless I guess this doesn't work because other dependencies may activate a different backend so fine-grained control is needed to match.

So it's not the case :)

@kurnevsky
Copy link
Contributor

It seems it wasn't supposed to work in cargo: rust-lang/cargo#10053

tarcieri added a commit that referenced this pull request Aug 15, 2022
This reverts commit a994fbf

Automatic selection is not working correctly. See comments here:

#55
@tarcieri
Copy link
Member Author

PR to revert these changes here: #63

tarcieri added a commit that referenced this pull request Aug 15, 2022
#63)

This reverts commit a994fbf

Automatic selection is not working correctly. See comments here:

#55
@tarcieri
Copy link
Member Author

crypto_box v0.8.1 has been released with this PR reverted

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