- Notifications
You must be signed in to change notification settings - Fork5.2k
One Shot ECB#52510
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
One Shot ECB#52510
Uh oh!
There was an error while loading.Please reload this page.
Conversation
ghost commentedMay 8, 2021
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
ghost commentedMay 8, 2021
Tagging subscribers to this area:@bartonjs,@vcsjones,@krwq,@GrabYourPitchforks Issue DetailsThis is a work-in progress for ECB one shots. Remaining tasks:
Implementation notes so far:
|
The CNG types were calculating their padding size based on an instancemethod that used the Mode property instead of the actual mode beingused.Most of the time, this will just end up being whatever the block size ofthe algorithm is going to be. However, in the case of CFB8, that is nottrue. Even if the algorithm instance is in CFB8 mode, the EncryptEcb andDecryptEcb one-shots should continue to function as ECB mode.
src/libraries/Common/src/Internal/Cryptography/UniversalCryptoDecryptor.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
The overlapping buffer check was renting a buffer every time unlessthe input and output overlap exactly. We only need to rent when theydo overlap partially, or no overlapping at all.
vcsjones commentedMay 14, 2021
@bartonjs This is not yet complete but, as time permits for you, this is probably nearing close to done minus the remaining tasks above and could be reviewed at least for design / approach. |
src/libraries/Common/src/Internal/Cryptography/UniversalCryptoDecryptor.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
| [Theory] | ||
| [MemberData(nameof(EcbTestCases))] | ||
| publicstaticvoidEcbRoundtrip(byte[]plaintext,byte[]ciphertext,PaddingModepadding) |
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.
I wonder (genuine curiosity, not presupposing an answer) if doing subclass for ICryptoTransform vs OneShot would be goodness like with the places we use subclassing for Array vs Span (e.g. RSA)
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.
Not sure I follow, can you expand on that a bit?
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.
We already have a bunch of tests that are encrypting or decrypting AES (and 3DES, etc) via the CreateEncryptor/CreateDecryptor methods.
- Move the data verification tests to a class different than the property validators and such (assuming they aren't already).
- Make all the methods instance methods, instead of static methods.
- Make them call (e.g.)
protected abstract byte[] Decrypt(Aes cipher, ReadOnlySpan<byte> iv, ReadOnlySpan<byte> ciphertext, PaddingMode paddingMode, CipherMode blockMode, int feedbackSize); - Make N derived types, AesCipherTests_CryptoTransform, AesCipherTests_OneShot, (AesCipherTests_CryptoTransform_Chunked, AesCipherTests_CryptoTransform_OneByteAtATime, etc)
- Each derived type writes its version of Encrypt/Decrypt, and now all of the same scenario/theory/whatever data is being tried in all the input models.
Comparative example:
Lines 8 to 20 ind71182a
| publicsealedclassSignVerify_Span:SignVerify | |
| { | |
| protectedoverridebyte[]SignData(RSArsa,byte[]data,HashAlgorithmNamehashAlgorithm,RSASignaturePaddingpadding)=> | |
| TryWithOutputArray(dest=>rsa.TrySignData(data,dest,hashAlgorithm,padding,outintbytesWritten)?(true,bytesWritten):(false,0)); | |
| protectedoverridebyte[]SignHash(RSArsa,byte[]hash,HashAlgorithmNamehashAlgorithm,RSASignaturePaddingpadding)=> | |
| TryWithOutputArray(dest=>rsa.TrySignHash(hash,dest,hashAlgorithm,padding,outintbytesWritten)?(true,bytesWritten):(false,0)); | |
| protectedoverrideboolVerifyData(RSArsa,byte[]data,byte[]signature,HashAlgorithmNamehashAlgorithm,RSASignaturePaddingpadding)=> | |
| rsa.VerifyData((ReadOnlySpan<byte>)data,(ReadOnlySpan<byte>)signature,hashAlgorithm,padding); | |
| protectedoverrideboolVerifyHash(RSArsa,byte[]hash,byte[]signature,HashAlgorithmNamehashAlgorithm,RSASignaturePaddingpadding)=> | |
| rsa.VerifyHash((ReadOnlySpan<byte>)hash,(ReadOnlySpan<byte>)signature,hashAlgorithm,padding); |
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.
(OneShot can also then use OneShot_InPlace, OneShot_ForwardOverlapped, OneShot_NegativeOverlapped, etc)
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.
Hm, I typically shy away from that approach, mostly as a matter of preference and more confidence that we were not losing any existing test coverage mistakenly through a refactoring.
I see the desire though. One of my remaining check items is some test work. I'll noodle with it to see if turns in to something I don't dislike.
...on/tests/System/Security/Cryptography/AlgorithmImplementations/AES/AesCipherTests.OneShot.csShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
bartonjs commentedJun 23, 2021
We're only a couple of weeks away from the target platform complete date. What's left for the ECB part, and do you need help? I don't want to have ECB and CBC split across a release boundary, so we either need to finish this off relatively soon or push it out to 7. |
vcsjones commentedJun 23, 2021
I think the "musts" that are remaining are XML docs and a few more test cases to make me feel better about failure scenarios. I can commit to getting ECB in shape by end of the week (Sunday if not sooner) and it should be relatively straight forward to do the work for CBC/CFB. |
vcsjones commentedJun 24, 2021
@bartonjs this should be in a reviewable state now, caveated on the things in the top post are not done where they are not checked off. |
bartonjs left a comment
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.
Added a whole heap'o periods, a few missing<returns>es, and two pieces of technical feedback.
...stem.Security.Cryptography.Primitives/src/System/Security/Cryptography/SymmetricAlgorithm.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
...stem.Security.Cryptography.Primitives/src/System/Security/Cryptography/SymmetricAlgorithm.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
...stem.Security.Cryptography.Primitives/src/System/Security/Cryptography/SymmetricAlgorithm.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
...stem.Security.Cryptography.Primitives/src/System/Security/Cryptography/SymmetricAlgorithm.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
...stem.Security.Cryptography.Primitives/src/System/Security/Cryptography/SymmetricAlgorithm.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
...stem.Security.Cryptography.Primitives/src/System/Security/Cryptography/SymmetricAlgorithm.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
...stem.Security.Cryptography.Primitives/src/System/Security/Cryptography/SymmetricAlgorithm.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
...stem.Security.Cryptography.Primitives/src/System/Security/Cryptography/SymmetricAlgorithm.csShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
...stem.Security.Cryptography.Primitives/src/System/Security/Cryptography/SymmetricAlgorithm.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
...stem.Security.Cryptography.Primitives/src/System/Security/Cryptography/SymmetricAlgorithm.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Jeremy Barton <jbarton@microsoft.com>
vcsjones commentedJun 25, 2021
@bartonjs sincere thank you for the proofing and taking the time to put all of the suggestions in. Will address the rest of the feedback in the next day or two. |
src/libraries/Common/src/Internal/Cryptography/UniversalCryptoDecryptor.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
...stem.Security.Cryptography.Primitives/src/System/Security/Cryptography/SymmetricAlgorithm.cs OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
GrabYourPitchforks commentedJun 25, 2021
I came into this late, but it looks great! Feeling kinda guilty that the only comments I can offer are stylistic nits. |
vcsjones commentedJun 26, 2021
@bartonjs I think I got all your feedback applied consistently.
There will be plenty more opportunities to say, "Kevin... what on earth are you doing??" |
bartonjs commentedJun 28, 2021
Woohoo! Thanks,@vcsjones. |
vcsjones commentedJun 28, 2021
It's done — Frodo Will get CBC / CFB in ASAP. |
Uh oh!
There was an error while loading.Please reload this page.
This is a work-in progress for ECB one shots. Remaining tasks:
SymmetricAlgorithmthrows aNotImplementedException. Ideally for existing inherited classes, they can fallback to the transform methodsKeyproperty for example)AesCng,TripleDESCng, etc. is not implemented.Implementation notes so far:
AesCryptoServiceProvider,AesManaged, andRijndaelManagedwill not get a custom implementation since they are being obsoleted.My intention is to implement ECB "fully" and get it reviewed, then it can more or less serve as a pattern for CBC and CFB.
Contributes to#2406