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

Csprng rework #254

Closed
wants to merge 2 commits into from
Closed

Csprng rework #254

wants to merge 2 commits into from

Conversation

aPere3
Copy link
Collaborator

@aPere3 aPere3 commented Apr 14, 2022

Resolves:

zama-ai/concrete-core-internal#111
zama-ai/concrete-core-internal#112
zama-ai/concrete_internal#346

Description

When forked, the children of the parent generator sometimes get an incorrect bound whose byte_ctr is higher than 127 (which should not be the case).

Checklist

(Use '[x]' to check the checkboxes, or submit the PR and then click the checkboxes)

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • The PR description links to the related issue (to link an issue, use '#XXX'.)
  • The tests on AWS have been launched and are successful (apply the aws_test to the PR to launch the tests on AWS)
  • The draft release description has been updated
  • Check for breaking changes and add them to commit message following the conventional commit [specification][conventional-breaking]

@cla-bot cla-bot bot added the cla-signed label Apr 14, 2022
@aPere3 aPere3 force-pushed the bug/concrete_csprng_byte_ctr branch from b22a01d to 1293596 Compare April 14, 2022 12:08
@aPere3 aPere3 requested a review from agnesLeroy April 14, 2022 12:08
@aPere3 aPere3 marked this pull request as draft April 14, 2022 14:27
@aPere3 aPere3 force-pushed the bug/concrete_csprng_byte_ctr branch from 54a7391 to 3ef48df Compare April 20, 2022 09:30
@aPere3 aPere3 marked this pull request as ready for review April 20, 2022 09:31
@aPere3 aPere3 requested a review from IceTDrinker April 20, 2022 09:31
@aPere3 aPere3 changed the title fix(concrete_csprng): fixes a bug in concrete_csprng fork Csprng rework Apr 20, 2022
Copy link
Member

@IceTDrinker IceTDrinker left a comment

Choose a reason for hiding this comment

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

Haven't looked at generators and counter yet, some general questions for my understanding :)

Edit: btw sorry if there is some overlap with some explanations you provided but I started writing part of the comments before we talked about this PR!

concrete-csprng/Cargo.toml Show resolved Hide resolved
concrete-csprng/Cargo.toml Outdated Show resolved Hide resolved
concrete-csprng/Cargo.toml Outdated Show resolved Hide resolved
concrete-csprng/benches/benchmark.rs Outdated Show resolved Hide resolved
concrete-csprng/src/generators/aes_ctr/block_cipher.rs Outdated Show resolved Hide resolved
concrete-csprng/src/lib.rs Outdated Show resolved Hide resolved
concrete-csprng/src/lib.rs Show resolved Hide resolved
concrete-csprng/Cargo.toml Outdated Show resolved Hide resolved
concrete-csprng/src/seeders/implem/linux.rs Outdated Show resolved Hide resolved
concrete-csprng/src/seeders/mod.rs Outdated Show resolved Hide resolved
@aPere3 aPere3 force-pushed the bug/concrete_csprng_byte_ctr branch 2 times, most recently from 7172dd1 to df4c15e Compare April 21, 2022 07:38
@agnesLeroy agnesLeroy requested a review from damienligier April 21, 2022 09:52
concrete-csprng/src/generators/mod.rs Outdated Show resolved Hide resolved
concrete-csprng/src/generators/mod.rs Outdated Show resolved Hide resolved
concrete-csprng/src/generators/mod.rs Outdated Show resolved Hide resolved
concrete-csprng/src/generators/mod.rs Outdated Show resolved Hide resolved
concrete-csprng/src/generators/mod.rs Outdated Show resolved Hide resolved
concrete-csprng/src/generators/aes_ctr/generic.rs Outdated Show resolved Hide resolved
concrete-csprng/src/generators/aes_ctr/generic.rs Outdated Show resolved Hide resolved
concrete-csprng/src/generators/aes_ctr/generic.rs Outdated Show resolved Hide resolved
@aPere3 aPere3 force-pushed the bug/concrete_csprng_byte_ctr branch from df4c15e to 75fd849 Compare April 22, 2022 07:17
@aPere3
Copy link
Collaborator Author

aPere3 commented Apr 22, 2022

Thanks for your thorough reviews @agnesLeroy, @IceTDrinker !

I made the changes you requested !

@aPere3 aPere3 force-pushed the bug/concrete_csprng_byte_ctr branch 2 times, most recently from 4a0f82a to fa4b4d9 Compare April 22, 2022 07:46
@aPere3 aPere3 force-pushed the bug/concrete_csprng_byte_ctr branch from fa4b4d9 to 8c1d140 Compare April 22, 2022 08:44
Copy link
Member

@IceTDrinker IceTDrinker left a comment

Choose a reason for hiding this comment

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

It's a bit hard to tell if it's ok with the force push, but it seems you adressed all I saw, thanks !

@aPere3 aPere3 mentioned this pull request Apr 25, 2022
6 tasks
@aPere3 aPere3 force-pushed the bug/concrete_csprng_byte_ctr branch 2 times, most recently from 452eb1d to 2d19e32 Compare April 25, 2022 12:27
Copy link
Contributor

@agnesLeroy agnesLeroy left a comment

Choose a reason for hiding this comment

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

Hello! We went through the PR this morning with Damien, here come some first comments about it! :) He's going to continue reading it on his side. :)

concrete-csprng/src/seeders/mod.rs Outdated Show resolved Hide resolved
concrete-csprng/src/generators/mod.rs Outdated Show resolved Hide resolved
concrete-csprng/src/generators/mod.rs Show resolved Hide resolved
concrete-csprng/src/generators/mod.rs Outdated Show resolved Hide resolved
concrete-csprng/src/generators/mod.rs Outdated Show resolved Hide resolved
concrete-csprng/src/generators/aes_ctr/mod.rs Show resolved Hide resolved
Copy link
Member

@IceTDrinker IceTDrinker left a comment

Choose a reason for hiding this comment

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

btw would it be worth it to update the aes crate as aes_soft is marked as deprecated? The only bother for the new crate is that it does not seem easy to get the software variant enabled :|

@aPere3
Copy link
Collaborator Author

aPere3 commented Apr 26, 2022

@IceTDrinker Thanks for reminding us of that, I forgot that you mentioned it a few weeks ago. I see an aes_force_soft configuration flag, in the aes crate, which seems to do what we want. Now the question is, do we integrate it in this (already large) PR ?

@IceTDrinker
Copy link
Member

@IceTDrinker Thanks for reminding us of that, I forgot that you mentioned it a few weeks ago. I see an aes_force_soft configuration flag, in the aes crate, which seems to do what we want. Now the question is, do we integrate it in this (already large) PR ?

probably not, it's big enough as is IMO :) was just that I thought about it again, I don't know if the config flag is easy to use in the build system (vs. features IIRC) which is a bit of a shame really...

@aPere3
Copy link
Collaborator Author

aPere3 commented Apr 26, 2022

Yes, I got mixed up, I read configuration flag but thought feature flag. It would be interesting to understand why they chose to do it that way 🕵️

@aPere3 aPere3 force-pushed the bug/concrete_csprng_byte_ctr branch from 2d19e32 to 31d7c49 Compare April 26, 2022 13:43
@aPere3 aPere3 force-pushed the bug/concrete_csprng_byte_ctr branch from 31d7c49 to df7470c Compare April 26, 2022 13:49
aPere3 added 2 commits April 27, 2022 10:21
BREAKING_CHANGES:
+ `try_fork` and `par_try_fork` now return a result.
+ `remaining_bytes` now returns a `ByteCount`.
BREAKING_CHANGE: this commit completely breaks the previous API
@aPere3 aPere3 force-pushed the bug/concrete_csprng_byte_ctr branch from df7470c to 2c0e93d Compare April 27, 2022 08:23
@aPere3
Copy link
Collaborator Author

aPere3 commented Apr 27, 2022

@IceTDrinker : I asked the question on RustCrypto/block-ciphers#316 .

Copy link
Contributor

@damienligier damienligier left a comment

Choose a reason for hiding this comment

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

Very good upgrade! there are some spaces in middle of documentation probably because of the formatting. also misused of the verb yield. we should avoid it and use output of produce instead. i added many comments about that but i left some of them. please could you double check all of them?

It could also be useful to re implement the drop (cf @agnesLeroy) to set to zero all the prng values.

concrete-csprng/benches/benchmark.rs Show resolved Hide resolved
pub struct AesCtrGenerator<BlockCipher: AesBlockCipher> {
// The block cipher used in the background
pub(crate) block_cipher: BlockCipher,
// The state corresponding to the latest yielded byte.
Copy link
Contributor

Choose a reason for hiding this comment

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

is it the counter? the next randomness will be obtained from: this state+1?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes !

concrete-csprng/src/lib.rs Show resolved Hide resolved
concrete-csprng/src/lib.rs Show resolved Hide resolved
concrete-csprng/src/lib.rs Show resolved Hide resolved
concrete-csprng/src/lib.rs Show resolved Hide resolved
concrete-csprng/src/lib.rs Show resolved Hide resolved
@aPere3
Copy link
Collaborator Author

aPere3 commented May 3, 2022

Hello @damienligier ,

Thank you for this review !

I tried to address most points in the follow-up PR on zama-ai/concrete-core#8 . I integrated most of your remarks, and closed the related conversations here. The few remaining ones, I left open in case you want more informations / take actions.

Related to your remark on re-implementing the Drop trait, you raise a very valid point, and I would love to see this done ! That being said, it is tricky to do properly, as we have to use volatile memory operations and compiler fences to ensure the compiler does not get rid / reorder the clean-up code in a wrong way.

I would prefer to add that in a future PR, focused on this matter, as this one is already pretty big, what do you think ?

I close this PR so that we can leave the floor for the libs team here, but feel free to answer in the conversation 😉

Best,

Alex.

@aPere3 aPere3 closed this May 3, 2022
@tmontaigu tmontaigu deleted the bug/concrete_csprng_byte_ctr branch August 8, 2022 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants