Skip to content

[Microsoft.Android.Build.Tasks] Modernize SHA256 hashing - #13608

Merged
jonathanpeppers merged 1 commit into
mainfrom
simonrozsival-modernize-sha256-hashing-fba
Nov 18, 2026
Merged

jonathanpeppers merged 1 commit into
mainfrom
simonrozsival-modernize-sha256-hashing-fba

Conversation

@simonrozsival

@simonrozsival simonrozsival commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

FastDeploy and MIBC profile generation were still constructing disposable System.Security.Cryptography.SHA256 instances for one-shot UTF-8 inputs. The owning task assembly targets net12.0, so these call sites can use the static, span-based hashing APIs without affecting the netstandard2.0 Maven download code.

Use a shared HashingHelper.Sha256Utf8() implementation with bounded stack allocation for ordinary inputs. FastDeploy continues to emit the same lowercase hexadecimal manifest hash, while MIBC profile generation continues to derive the same deterministic System.Reflection.Metadata.BlobContentId.

Validation:

  • dotnet build src/Microsoft.Android.Build.Tasks/Microsoft.Android.Build.Tasks.csproj -v minimal — passed
  • dotnet test src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Microsoft.Android.Build.Tasks.Tests.csproj -v minimal --filter 'FullyQualifiedName~FastDeployTests|FullyQualifiedName~GenerateMibcProfileTests' — 72/72 passed
  • git diff --check — passed

FastDeploy and MIBC profile generation created disposable SHA256 instances to hash single UTF-8 inputs.  Use the static span-based API for these one-shot operations and share the bounded UTF-8 buffering logic.  This preserves the FastDeploy lowercase hexadecimal manifest hash and the deterministic MIBC BlobContentId while avoiding intermediate UTF-8 and formatted-string allocations.

Validation:
  * dotnet build src/Microsoft.Android.Build.Tasks/Microsoft.Android.Build.Tasks.csproj -v minimal
  * dotnet test src/Microsoft.Android.Build.Tasks/Tests/Microsoft.Android.Build.Tasks.Tests/Microsoft.Android.Build.Tasks.Tests.csproj -v minimal --filter FullyQualifiedName~FastDeployTests|FullyQualifiedName~GenerateMibcProfileTests (72 passed)

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 10:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues block the SHA256 hashing modernization.

No open issues 🎉

What changed in this PR

Modernizes one-shot SHA256 hashing in the Android build tasks while preserving FastDeploy manifest hashes and deterministic MIBC content identifiers.

Changes:

  • Adds a shared UTF-8 hashing helper with stack allocation for inputs up to 256 bytes.
  • Replaces disposable SHA256 instances with the static span-based API.
  • Uses direct lowercase hexadecimal formatting for FastDeploy hashes.
File Description
src/​Microsoft.Android.Build.Tasks/​Utilities/​MibcProfileWriter.cs Uses the shared helper to generate deterministic content hashes.
src/​Microsoft.Android.Build.Tasks/​Utilities/​HashingHelper.cs Adds bounded UTF-8 buffering and static SHA256 hashing.
src/​Microsoft.Android.Build.Tasks/​Tasks/​FastDeploy.Manifest.cs Uses stack-allocated hash storage and direct lowercase hexadecimal formatting.

Review effort: Balanced

{
using var sha256 = SHA256.Create ();
byte[] hash = sha256.ComputeHash (Encoding.UTF8.GetBytes (fingerprint));
byte[] hash = new byte [SHA256.HashSizeInBytes];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🤖 This is the best we can do here. BlobContentId.FromHash only has public byte[] and ImmutableArray<byte> overloads (the ReadOnlySpan<byte> one is private), so stackalloc is not possible. ArrayPool would cost more than one 32-byte allocation that runs once per MIBC write.

@jonathanpeppers
jonathanpeppers merged commit 63f7c88 into main Nov 18, 2026
39 checks passed
@jonathanpeppers
jonathanpeppers deleted the simonrozsival-modernize-sha256-hashing-fba branch November 18, 2026 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants