-
Notifications
You must be signed in to change notification settings - Fork 142
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
[WIP]: switch to crypto-bigint for decryption #394
base: master
Are you sure you want to change the base?
Conversation
Is it reasonable to say the implementation is fairly close, and that the remaining items would only result in minor fixes? |
I can potentially pick up this branch if @dignifiedquire is too busy. It looks like there's still a decent number of things to do, though the tests appear to be broken due to a |
this is just pointing at this branch on my machine: https://github.com/RustCrypto/crypto-bigint/tree/feat-expand-mul |
The big changes needed to make this performant enough, is the work I started to allow different width of bigints to be operated on, as we are currently wasting a lot of time in operating on much larger values than we need to. Everything else is mostly done. So any help with that on the cryptobigint front would be appreciated. |
@dignifiedquire perhaps we should get an initial working implementation landed then follow up on performance separately? |
We could, but performance of this crate is already not great, and it goes down by at least a factor of 2 :( |
Better than a sidechannel vulnerability that leaks the private key! |
Is there work required in any of the dependencies that are blocking non-alloc types from being used? If there is, I can try a stab at it parallelly. |
@tarcieri you are right, I will try and pull out the version that worked for a first release |
@MasterAwesome the dependencies are largely ready to go, including The hard part will be making the implementation of |
@MasterAwesome in terms of something that would generally help with the migration, there are various avenues for |
5c3da17
to
56f6f27
Compare
Update: done
next steps
|
Almost all tests are broken, but |
Fixing for sede De/Serialize for BoxedUint - some TODO left there Also serde(skip) needs a default as it's not Option<> n_params The rest seems to be test data input migration - the previous had some str radix parse and be needs exact length |
let bits = (todo / (nprimes - i)) as u32; | ||
*prime = generate_prime_with_rng(rng, bits, bits); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs the precision
let bits = (todo / (nprimes - i)) as u32; | |
*prime = generate_prime_with_rng(rng, bits, bits); | |
let bits = (todo / (nprimes - i)) as u32; | |
let bits_precision = BoxedUint::zero_with_precision(bits).bits_precision(); | |
*prime = generate_prime_with_rng(rng, bits, bits_precision); |
One way to get it 🤷♀️
The bit precision (3nd arg) causes it to trip assert - need precision not length (2nd arg) supposedly
Behind has a tripwire:
let mut random = T::random_bits_with_precision(rng, bit_length, bits_precision);
assert!(random.bits_precision() == bits_precision);
random.bits_precision() = 128, bits_precision = 85, bit_length = 85
random.bits_precision() = 512, bits_precision = 512, bit_length = 512
random.bits_precision() = 64, bits_precision = 6, bit_length = 6
The tripwire behind the scenes calls impl RandomBits try_random_bits_with_precision which does:
let mut ret = BoxedUint::zero_with_precision(bits_precision);
let e = BoxedUint::from(e); | ||
|
||
let a1 = d * &e - &one; | ||
let a2 = (n.as_ref() - &one).gcd(&(d * e - &one)).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BY-GCD left side Odd but Odd-1 == Even in formula - crypto-bigint/590
Very, very WIP
Uncomplete, unordered task list
RsaPrivateKey
RsaPublicKey
decrypt
implementationBigUint
to return owned versions