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

Add support for AES-GCM and ChaCha20Poly1305 on iOS/tvOS/MacCatalyst via CryptoKit #104383

Merged
merged 9 commits into from
Jul 22, 2024

Conversation

akoeplinger
Copy link
Member

@akoeplinger akoeplinger commented Jul 3, 2024

Now that we support minimum OS versions that ship with Swift we can enable CryptoKit and pal_swiftbindings.swift.

Fixes #91523
Fixes #52482

…via CryptoKit

Now that we support minimum OS versions that ship with Swift we can enable CryptoKit and pal_swiftbindings.swift.

Fixes dotnet#91523
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, 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.

1 similar comment
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, 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.

Comment on lines +49 to +53
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(SWIFT_OPTIMIZATION_FLAG "-Onone")
elseif (CMAKE_BUILD_TYPE STREQUAL "Release")
set(SWIFT_OPTIMIZATION_FLAG "-O")
endif()
Copy link
Member Author

Choose a reason for hiding this comment

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

I noticed that we didn't compile the swift code with optimizations so fixed this as well

@vcsjones
Copy link
Member

vcsjones commented Jul 3, 2024

For NativeAOT failures, the "osx" restriction should be changed to $(_IsApplePlatform)' == 'true'

here

<NativeFramework Condition="'$(_targetOS)' == 'osx'" Include="CryptoKit" />

and here

<NativeSystemLibrary Include="swiftCore" Condition="'$(_targetOS)' == 'osx'" />
<NativeSystemLibrary Include="swiftFoundation" Condition="'$(_targetOS)' == 'osx'" />

@akoeplinger
Copy link
Member Author

For NativeAOT failures, the "osx" restriction should be changed to $(_IsApplePlatform)' == 'true'

Interesting, I explicitly checked this locally and it worked without that change for me.

@vcsjones
Copy link
Member

vcsjones commented Jul 3, 2024

@akoeplinger oh and probably

<LinkerArg Include="-L/usr/lib/swift" Condition="'$(_targetOS)' == 'osx'" />

@akoeplinger akoeplinger requested a review from marek-safar as a code owner July 22, 2024 17:22
Copy link
Member

@vcsjones vcsjones left a comment

Choose a reason for hiding this comment

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

The changes to the actual crypto parts seem reasonable to me. I will have to defer on the building and linking changes to the appropriate folks though.

@@ -203,7 +196,7 @@ public static void TwoEncryptionsAndDecryptionsUsingOneInstance()
byte[] nonce2 = "8ba10892e8b87d031196bf99".HexToByteArray();

byte[] expectedCiphertext1 = "f1af1fb2d4485cc536d618475d52ff".HexToByteArray();
byte[] expectedTag1 = PlatformDetection.IsOSX ?
byte[] expectedTag1 = (PlatformDetection.IsOSX || PlatformDetection.UsesMobileAppleCrypto) ?
Copy link
Member

Choose a reason for hiding this comment

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

Not blocking but we could simplify this to PlatformDetection.IsApplePlatform

Copy link
Member

@ivanpovazan ivanpovazan left a comment

Choose a reason for hiding this comment

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

LGTM!

@akoeplinger
Copy link
Member Author

/ba-g the one unknown test failure is happening on wasm so can't be related to the changes in this PR.

@akoeplinger akoeplinger merged commit 2c70e36 into dotnet:main Jul 22, 2024
153 of 158 checks passed
@akoeplinger akoeplinger deleted the ios-cryptokit branch July 22, 2024 21:11
@vcsjones vcsjones added the cryptographic-docs-impact Issues impacting cryptographic docs. Cleared and reused after documentation is updated each release. label Jul 31, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Aug 31, 2024
@bartonjs bartonjs added the tracking This issue is tracking the completion of other related issues. label Sep 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Security cryptographic-docs-impact Issues impacting cryptographic docs. Cleared and reused after documentation is updated each release. new-api-needs-documentation tracking This issue is tracking the completion of other related issues.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support AES-GCM for iOS-like platforms ChaCha20Poly1305.IsSupported always returns false on non-Windows
5 participants