Skip to content

Conversation

@daviddesmet
Copy link
Owner

@daviddesmet daviddesmet commented Aug 29, 2025

First take on .NET Hardware Intrinsics:

  • Support AVX2 and SSE3 in ChaCha20Base.ShuffleState
  • Support AVX2 and SSE3 in ChaCha20Base.QuarterRound

Implemented proper SSE2 and AdvSIMD optimizations for Poly1305:

  • ComputeMacSse2 - Uses SSE2 Vector128 intrinsics for:
    • SIMD loads for key and data blocks
    • SIMD store for the final 16-byte tag output
    • The polynomial multiplication remains scalar due to data dependencies inherent to Poly1305's design
  • ComputeMacAdvSimd - Uses ARM AdvSIMD Vector128 intrinsics with the same optimization pattern for ARM64 platforms (like macOS)
  • Updated ComputeMac dispatch to check for SSE2 and AdvSIMD support after AVX2

Pending:

  • Support AVX2 and SSE3 and ARM AdvSIMD in Salsa20Base

@daviddesmet daviddesmet requested a review from Copilot August 29, 2025 20:39
@daviddesmet daviddesmet self-assigned this Aug 29, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces .NET Hardware Intrinsics support for optimizing ChaCha20 cryptographic operations with AVX2, SSE3, and ARM AdvSIMD instruction sets. The implementation provides SIMD-accelerated versions of core ChaCha20 operations (ShuffleState and QuarterRound) while maintaining backward compatibility with scalar implementations.

Key changes:

  • Added hardware intrinsics support for ChaCha20 core operations with AVX2, SSE3, and ARM AdvSIMD
  • Enhanced build and test infrastructure to validate intrinsics across different platforms
  • Updated dependencies and improved code style consistency across benchmark files

Reviewed Changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/NaCl.Core/Base/ChaCha20Base.cs Core SIMD implementation with hardware intrinsics for ShuffleState and QuarterRound operations
src/NaCl.Core/Internal/BitUtils.cs Added SIMD-optimized rotation utilities for Vector128/256 operations
test/NaCl.Core.Benchmarks/ChaCha20IntrinsicsBenchmark.cs New benchmark class specifically for testing hardware intrinsics performance
build.cake Enhanced build script with platform-specific intrinsics testing
test/NaCl.Core.Benchmarks/*.cs Code style improvements and field naming consistency
src/NaCl.Core/Internal/ArrayUtils.cs Fixed method naming inconsistency
test/NaCl.Core.Tests/*.cs Updated test vectors URL and method visibility

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@daviddesmet daviddesmet changed the title feat: ShuffleState and QuarterRound AVX2 and SSE3 and AdvSIMD feat: ShuffleState and QuarterRound AVX2 and SSE3 and ARM AdvSIMD Aug 29, 2025
@codecov
Copy link

codecov bot commented Aug 29, 2025

Codecov Report

❌ Patch coverage is 98.03408% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.42%. Comparing base (b01b811) to head (d26a16e).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
src/NaCl.Core/Poly1305.cs 96.95% 9 Missing ⚠️
src/NaCl.Core/Base/ChaCha20Base.cs 97.87% 2 Missing ⚠️
src/NaCl.Core/Base/Salsa20Base.cs 98.54% 2 Missing ⚠️
src/NaCl.Core/Base/Snuffle.cs 95.74% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #159      +/-   ##
==========================================
- Coverage   99.78%   90.42%   -9.36%     
==========================================
  Files          14       14              
  Lines         455     1201     +746     
  Branches       57      128      +71     
==========================================
+ Hits          454     1086     +632     
- Misses          1      115     +114     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@daviddesmet daviddesmet added minor Requiring a minor version update according to semantic versioning enhancement New feature or request labels Aug 30, 2025
@daviddesmet daviddesmet added the maintenance Perform maintenance on the project but add no features or bug fixes label Nov 29, 2025
@daviddesmet daviddesmet merged commit 9e29983 into master Nov 29, 2025
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request maintenance Perform maintenance on the project but add no features or bug fixes minor Requiring a minor version update according to semantic versioning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants