Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

One shot CBC#55184

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

Merged
bartonjs merged 23 commits intodotnet:mainfromvcsjones:2406-one-shot-cbc
Jul 7, 2021
Merged

One shot CBC#55184

bartonjs merged 23 commits intodotnet:mainfromvcsjones:2406-one-shot-cbc
Jul 7, 2021

Conversation

@vcsjones
Copy link
Member

@vcsjonesvcsjones commentedJul 5, 2021
edited by bartonjs
Loading

This implements the CBC one shots.

It should be noted that the implementation could be "better" and avoid a few allocations, such as around copying the initialization vector, which will likely be for .NET 7 since it's somewhat non-trivial. This work is already done in#55090 and will be re-opened after the branch for 6.0 is taken.

This also did a significant refactoring of the unit tests to avoid a product of duplicated code between modes and algorithms. This will make the CFB work much easier.

Contributes to#2406.

Work remaining:

  • XML docs

am11 reacted with thumbs up emoji
@ghost
Copy link

Note regarding thenew-api-needs-documentation label:

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
Copy link

Tagging subscribers to this area:@bartonjs,@vcsjones,@krwq,@GrabYourPitchforks
See info inarea-owners.md if you want to be subscribed.

Issue Details

This implements the CBC one shots.

It should be noted that the implementation could be "better" and avoid a few allocations, such as around copying the initialization vector, which will likely be for .NET 7 since it's somewhat non-trivial. This work is already done in#55090 and will be re-opened after the branch for 6.0 is taken.

This also did a significant refactoring of the unit tests to avoid a cross product of duplicated code between modes and algorithms. This will make the CFB work much easier.

Work remaining:

  • XML docs
Author:vcsjones
Assignees:-
Labels:

area-System.Security,new-api-needs-documentation

Milestone:-

@vcsjonesvcsjones marked this pull request as draftJuly 5, 2021 18:32
@vcsjones
Copy link
MemberAuthor

vcsjones commentedJul 5, 2021
edited
Loading

Opening as draft to get a run through CIand because the XML documentation is not done, but the code should be in a reviewable state.

@vcsjonesvcsjones marked this pull request as ready for reviewJuly 6, 2021 04:15
@vcsjones
Copy link
MemberAuthor

Seems like failures are either infrastructure or unrelated. Marking for review.

Assert.True(result, "TryDecrypt");
Assert.Equal(destinationBuffer.Length, bytesWritten);

AssertPlaintexts(plaintext, destinationBuffer.ToArray(), padding);
Copy link
Member

Choose a reason for hiding this comment

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

Seems like the helpers could be spanified. But doesn't really matter.

Copy link
Member

Choose a reason for hiding this comment

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

Or just split the array/span versions of destination:

-Span<byte> destinationBuffer = new byte[expectedPlaintextSize];+byte[] destination = new byte[expectedPlaintextSize];+Span<byte> destinationBuffer = destination;

Copy link
MemberAuthor

@vcsjonesvcsjonesJul 6, 2021
edited
Loading

Choose a reason for hiding this comment

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

I kept the assert helpers as taking arrays because asserting on arrays is nicer with Xunit. Taking aReadOnlySpan<byte> would mean doing anAssert.True(blah.SequenceEqual(otherBlah)) which doesn't have quite as useful output when the assertion fails.

Since it is test code, I find the better assertion output more valuable than less allocating.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah. And the version for strings is nicer than the one for arrays (particularlybyte[])... at least in the past the array mismatch one was most useful if it was in the first few elements. That's why there are so many Asserts over foo.ByteArrayToHex().

One of these days I should make an assert-equality routine and clean up all of the things to do non-allocated SequenceEqual then fall back to making the string on failure. Maybe it'd shave a non-trivial amount of time off of the test execution.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Oh. Actually it looks like we have one onAssertExtensions. Let me play with that a bit...

Assert.Equal(actual, expected);
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Consider a "test" to make sure the derived types all specified all the test methods:

[Fact]
publicvoidTestsDefined()
{
conststringDriverSuffix="Driver";
TypeimplType=GetType();
TypedefType=typeof(NonCryptoHashTestDriver);
List<string>?missingMethods=null;
foreach(MethodInfoinfoindefType.GetMethods(BindingFlags.Instance|BindingFlags.NonPublic))
{
if(info.IsFamily&&info.Name.EndsWith(DriverSuffix,StringComparison.Ordinal))
{
stringtargetMethodName=info.Name.Substring(0,info.Name.Length-DriverSuffix.Length);
MethodInfoinfo2=implType.GetMethod(
targetMethodName,
BindingFlags.Instance|BindingFlags.Public);
if(info2isnull)
{
missingMethods??=newList<string>();
missingMethods.Add(targetMethodName);
}
}
}
if(missingMethodsis notnull)
{
Assert.Empty(missingMethods);
}
}

@vcsjones
Copy link
MemberAuthor

@bartonjs some last second test improvements:

  1. UseAssertExtensions.SequenceEqual to assert spans. Its output is... acceptable.

      Error Message:   Showing first 10 differences Position 23: Expected: 181, Actual: 74 Total number of differences: 1 out of 24
  2. While switching toAssertExtensions I noticed two asserts were missing in the roundtrip test.

  3. Incorporated a reflection test as suggested.

@bartonjs
Copy link
Member

Its output is... acceptable.

Yeah. Maybe one day we'll slip in a specialization for byte spans that does hex strings once they're proven to be a mismatch. (At least, I usually find the hex easier to work with, being fixed width)

@bartonjs
Copy link
Member

While switching to AssertExtensions I noticed two asserts were missing in the roundtrip test.

I think I looked at that like a half dozen times trying to decide if they were needed or not, torn between "but all the things flow..." and "why are there two bidirectional blocks with only one assert each?". Clearly I should have just left a comment 😄.

@vcsjones
Copy link
MemberAuthor

Maybe one day we'll slip in a specialization for byte spans

Yeah. I can do that outside of this PR.

@vcsjones
Copy link
MemberAuthor

Failures appear unrelated.

@bartonjsbartonjs merged commit847cc56 intodotnet:mainJul 7, 2021
@bartonjs
Copy link
Member

Yay. CBC was the important one, but now CFB should give is feature completion.

vcsjones reacted with hooray emoji

@vcsjonesvcsjones deleted the 2406-one-shot-cbc branchJuly 8, 2021 06:33
@ghostghost locked asresolvedand limited conversation to collaboratorsAug 7, 2021
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

@bartonjsbartonjsbartonjs approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@vcsjones@bartonjs@jeffhandley

[8]ページ先頭

©2009-2025 Movatter.jp