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
Aes-ctr yields different result openssl #12
Comments
Looks like OpenSSL and For random nonces (which is a common recommendation) chances to stumble upon this difference for 1 MB payload is around 4.4e-16. But in your case you use @tarcieri |
Thanks for helping me out! To give a little bit of context: I discovered this while writing some differential fuzz testing tool to compare your implementation against openssl. If you change to a 128 bit variant, this could help you to ensure correctness of your implementation. |
@newpavlov implementing both makes sense to me |
I looked into fixing/implementing this. Supporting u64 (current), u128 (like openssl) and u32 from #41 ... Not sure how that should be realized given I know nothing of any design constraints that come with simd (re #41). Any suggestions how this should be implemented? Simply switching the counter of Ctr128 to u128, fixing some casts makes a modified poc pass. I needed to modify the original attachments (main.rs):
|
poc was originally reported in issue #12
@koivunej I will open source the fuzzer I used to find this bug asap. Would you be interested in a PR? This could be in addition to the unit-test created by you. |
@koivunej Find the fuzzer here: https://github.com/viniul/diff_fuzz_rust_aes. It should help you verify the correctness of the implementation. Longterm I would recommend integrating the libraries into https://github.com/google/oss-fuzz. |
I didn't add the randomized tests against openssl as I didn't see (or look hard enough to find) any existing tests against other implementations. While these interop tests sound really good in general I did not research if there are any lisensing issues and such. I'll try to take a look at your fuzzer if for nothing else than out of interest. Let's wait for RustCrypto maintainers on how to proceed. |
The CTR mode presently exposed by the There are also two different kinds of 32-bit counter mode presently being used (impl'd as in-crate private I'd say the 32-bit counter modes are probably more important in terms of usage, and also with consideration to performance. |
Is there any plan to expose some sort of configuration for this. So, for example, users of the library can select endianness and size of the counter? Do any other libraries do this sort of thing? Thanks. |
poc was originally reported in issue #12
It's rather tricky because of all of the variants of "AES-CTR" In the cases of AES-GCM and AES-GCM-SIV (which use two different variants of AES-CTR!), I've vendored the CTR implementations (which both use a 32-bit counter, but with different endianness) into the respective crates:
It should be possible to extract a common implementation useful for both into the |
Thanks for the response @tarcieri. |
Fixed in #195 |
When I provide a certain combination of key, iv and data, I get different results from the
openssl
and theaes-ctr
encryption.In particular, I used this wrapper:
And caledl it like so:
cargo run debug.crash
(file is attached), which reveals the following difference in encryption results between openssl and aes-ctr is revealed:
Oddly enough, if I change the nonce in the file, openssl and aes-ctr produce the same result. Is this a bug or am I misusing the library?
Attached is a zip to easily reproduce this and the input the triggers the difference:
poc.zip
Run like so:
The text was updated successfully, but these errors were encountered: