RustCrypto / RustCrypto/crypto-bigint
Extra sizes and certain sizes not working with `ConcatMixed`
Open
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 309
- Forks
- 95
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 3
Description
The following example
// [dependencies]
// crypto-bigint = "0.7.0-rc.17"
use crypto_bigint::{ConcatMixed, U1024, U1536, U2048, U3072, U4096, Uint};
pub struct KeyGenerator<const LIMBS: usize, const LIMBS_HALF: usize, const LIMBS_TIMES_TWO: usize>
{}
impl<const LIMBS: usize, const LIMBS_HALF: usize, const LIMBS_TIMES_TWO: usize>
KeyGenerator<LIMBS, LIMBS_HALF, LIMBS_TIMES_TWO>
where
// LIMBS_HALF * LIMBS_HALF = LIMBS
Uint<LIMBS_HALF>: ConcatMixed<Uint<LIMBS_HALF>, MixedOutput = Uint<LIMBS>>,
// LIMBS * LIMBS = LIMBS_TIMES_TWO
Uint<LIMBS>: ConcatMixed<Uint<LIMBS>, MixedOutput = Uint<LIMBS_TIMES_TWO>>,
{
pub fn new() -> Self {
Self {}
}
}
fn main() {
let key_generator_2k = KeyGenerator::<_, { U1024::LIMBS }, _>::new();
let key_generator_3k = KeyGenerator::<_, { U1536::LIMBS }, _>::new();
let key_generator_4k = KeyGenerator::<_, { U2048::LIMBS }, _>::new();
// TODO: Following line fails
// let key_generator_6k = KeyGenerator::<_, { U3072::LIMBS }, _>::new();
let key_generator_8k = KeyGenerator::<_, { U4096::LIMBS }, _>::new();
}
results in the following error if the key_generator_6k line is uncommented:
error[E0599]: the function or associated item `new` exists for struct `KeyGenerator<_, 48, _>`, but its trait bounds were not satisfied
--> src/main.rs:533:68
|
513 | pub struct KeyGenerator<const LIMBS: usize, const LIMBS_HALF: usize, const LIMBS_TIMES_TWO: usize>
| -------------------------------------------------------------------------------------------------- function or associated item `new` not found for this struct
...
533 | let key_generator_6k = KeyGenerator::<_, { U3072::LIMBS }, _>::new();
| ^^^ function or associated item cannot be called on `KeyGenerator<_, 48, _>` due to unsatisfied trait bounds
|
::: /home/user/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/crypto-bigint-0.7.0-rc.17/src/uint.rs:88:1
|
88 | pub struct Uint<const LIMBS: usize> {
| ----------------------------------- doesn't satisfy `<Uint<96> as ConcatMixed>::MixedOutput = Uint<_>` or `Uint<96>: ConcatMixed`
|
note: trait bound `Uint<96>: ConcatMixed` was not satisfied
--> src/main.rs:522:18
|
517 | KeyGenerator<LIMBS, LIMBS_HALF, LIMBS_TIMES_TWO>
| ------------------------------------------------
...
522 | Uint<LIMBS>: ConcatMixed<Uint<LIMBS>, MixedOutput = Uint<LIMBS_TIMES_TWO>>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| | |
| | unsatisfied trait bound introduced here
| unsatisfied trait bound introduced here
= help: items from traits can only be used if the trait is implemented and in scope
= note: the following trait defines an item `new`, perhaps you need to implement it:
candidate #1: `Monty`
For more information about this error, try `rustc --explain E0599`.
error: could not compile `rust-tests` (bin "rust-tests" test) due to 1 previous error
which blocks us from using certain sizes (even with extra-sizes feature) in our code.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the provided Rust example with the extra sizes enabled and inspect the ConcatMixed trait implementations referenced by the compiler in uint.rs. Check why Uint<96> lacks the required implementation, then verify that the 6k example and the other listed sizes compile successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cryptography
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100