-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
HIGHT cipher troubles with FileSource (CTR mode only) #1010
Comments
Thanks @clementmartin971. Yeah, something is going sideways here. Whatever is wrong is not a new break. I'm seeing the same result back to Crypto++ 5.6.2. We also lack a good set of test vectors for HIGHT in https://github.com/weidai11/cryptopp/blob/master/TestVectors/hight.txt. I don't think the missing test vectors affected this problem, however. Test vectors are run through a |
So I've got this tracked down to a function called AdditiveCipherTemplate::ProcessData around line 94. It calls a function called I think the problem is This is a tricky problem because the compiler is removing code without a diagnostic. We can't debug what is not there... I think we need to get on a code path that calls This class has caused us a lot of trouble in the past. Scroll down to around 200 and read the comments for CFB mode. Let me see what I can do to get this fixed. |
I can understand that it's not easy to fix. I have tried a little to see what was wrong and didn't success (else I would have post the patch :) ) That surprised me was that it works for Thank you for working on it |
You were right in analysis troubles occurred when For string source A patch can be done in I have done the following but I'm not sure to use correct allocation functions and if wiping is necessary (I didn't know enough cryptopp internals functions and way of protecting data)
|
No joy yet. PR #1019 cleaned up I also tried your patch with no joy. It failed to decrypt HIGHT ciphertext properly. It also broke OFB mode. (It did produce ciphertext, but I am not sure if it was correct). I'm scratching my head... |
We think this is another instance problem that surfaced under GH #683 when inString==outString. It violates aliasing rules and the compiler begins removing code. The ultimate workaround was to add a member variable m_tempOutString as scratch space when inString==outString. We did not loose much in the way of perforamce for some reason. It looks like AES/CTR lost about 0.03-0.05 cpb. When combined with the updated xorbuf from GH #1020, the net result was a speedup of 0.1-0.6 cpb. In fact, some ciphers like RC6, gained almost 5 cpb.
We think this is another instance problem that surfaced under GH #683 when inString==outString. It violates aliasing rules and the compiler begins removing code. The ultimate workaround was to add a member variable m_tempOutString as scratch space when inString==outString. We did not loose much in the way of perforamce for some reason. It looks like AES/CTR lost about 0.03-0.05 cpb. When combined with the updated xorbuf from GH #1020, the net result was a speedup of 0.1-0.6 cpb. In fact, some ciphers like RC6, gained almost 5 cpb.
Thanks again @clementmartin971, This issue was cleared at Commit 71a812ed9e7c and Commit bbc45ddfd7fc. (The first commit failed to check-in the updated header file). Re: this workaround + the
This was incorrect. My implementation was bad. I revisited it this morning and fixed my mistake. Thanks again for your help. |
Thanks a lot for the resolution. I was about to test again my "workaround" according to your comment of yesterday. |
We now have some self tests that use Also see Commit 07951c11e5d1 and Commit 0c88471e7aad. |
…, GH weidai11#1010, PR weidai11#1019) We found we can avoid the memcpy in the previous workaround by using a volatile pointer. The pointer appears to tame the optimizer so the compiler does not short-circuit some calls when outString == inString.
We think this is another instance problem that surfaced under GH weidai11#683 when inString==outString. It violates aliasing rules and the compiler begins removing code. The ultimate workaround was to add a member variable m_tempOutString as scratch space when inString==outString. We did not loose much in the way of perforamce for some reason. It looks like AES/CTR lost about 0.03-0.05 cpb. When combined with the updated xorbuf from GH weidai11#1020, the net result was a speedup of 0.1-0.6 cpb. In fact, some ciphers like RC6, gained almost 5 cpb.
We think this is another instance problem that surfaced under GH weidai11#683 when inString==outString. It violates aliasing rules and the compiler begins removing code. The ultimate workaround was to add a member variable m_tempOutString as scratch space when inString==outString. We did not loose much in the way of perforamce for some reason. It looks like AES/CTR lost about 0.03-0.05 cpb. When combined with the updated xorbuf from GH weidai11#1020, the net result was a speedup of 0.1-0.6 cpb. In fact, some ciphers like RC6, gained almost 5 cpb.
@PassMark, @dgm3333, @clementmartin971 I checked in some code to avoid the extra buffer and memcpy's. It is sitting on the The code tested Ok for me on x86_64. That's where HIGHT bock cipher had problems. ARMv7 had problems on Linux, and I it also tested Ok. Can you guys test it on your platforms, please? You can fetch the code with:
We announced the testing branch on the mailing list at strciphr.cpp updates. If I don't get any complaints over the next week or so, I will merge the changes. Thanks in advance. |
Hello, |
Thanks for this. I've been a bit swamped with another coding push but I should have a chance to rewrite the encryption routines to test impact of multithreading on timing later in the week. However for what it's worth an initial "single thread" (ie any multithreaded processing would be automatic compiler/operating system initiated) encryption/decryption loop of ~150GB / 15k files of data completed without triggering any warnings. (Test PC is running Win 10 pro 64 running on an AMD Ryzen 9 = 12 cores). |
I merged the changes into master last night. You should test master now. Jeff |
It turns out we went down a rabbit hole when we added the volatile cast gyrations in an attempt to change the compiler behavior. We are seeing the same failures from AES, Rabbit, HIGHT, HC-128 and HC-256 with and without the gyrations. We were able to work out the problems with Rabbit, HIGHT, HC-128 and HC-256. See GH #1231 and GH #1234. We are also not able to successfully cut-in Cryptogams AES on ARMv7, so it is now disabled. See GH #1236. Since the volatile casts were not a solution, we are backing it out along with associated comments.
Using the code provided as
HIGHT
example in Wiki and replacingCBC_Mode
byCTR_Mode
is working... but next switching fromStringSource
toFileSource
doesn't work anymore.The source code to reproduce:
The text was updated successfully, but these errors were encountered: