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

Small enchancement to the core functionality of ChaCha20 stream cipher #20470

Merged
merged 30 commits into from
Jan 10, 2024

Conversation

blackshirt
Copy link
Contributor

@blackshirt blackshirt commented Jan 10, 2024

This pull request adds some minor enhancement to the xor_key_stream and other core functionality, especially in speed of execution.
Local bench on my low end laptop shows up small nice improvement, like i paste on discord
Before patched

$ v run bench.v
 SPENT  7206.581 ms in chacha20.encrypt 40 bytes of plaintext with 500000 iterations, total bytes encrypted : 20000000 bytes
 SPENT  8056.834 ms in chacha20.encrypt 64 bytes of plaintext with 500000 iterations, total bytes encrypted : 32000000 bytes
 SPENT 11103.743 ms in chacha20.encrypt 128 bytes of plaintext with 500000 iterations, total bytes encrypted : 64000000 bytes
 SPENT 22957.365 ms in chacha20.encrypt 200 bytes of plaintext with 500000 iterations, total bytes encrypted : 100000000 bytes

And after being patched

$ v run bench.v
 SPENT  5193.056 ms in chacha20.encrypt 40 bytes of plaintext with 500000 iterations, total bytes encrypted : 20000000 bytes
 SPENT  5925.972 ms in chacha20.encrypt 64 bytes of plaintext with 500000 iterations, total bytes encrypted : 32000000 bytes
 SPENT 11119.856 ms in chacha20.encrypt 128 bytes of plaintext with 500000 iterations, total bytes encrypted : 64000000 bytes
 SPENT 19557.270 ms in chacha20.encrypt 200 bytes of plaintext with 500000 iterations, total bytes encrypted : 100000000 bytes

This PR adds some changes by :

  • Adds @[direct_array_access] attributes to the core function that likely needed
  • Reduces allocation of output buffer by using dst buffer directly
  • Use builtin vmemset to reset cipher's key and nonce
  • Some other minor changes

Please gives a review, comment and feedback.
Best regards

blackshirt and others added 28 commits January 6, 2024 14:25
Co-authored-by: JalonSolov <JalonSolov@gmail.com>
Co-authored-by: JalonSolov <JalonSolov@gmail.com>
Co-authored-by: JalonSolov <JalonSolov@gmail.com>
Co-authored-by: JalonSolov <JalonSolov@gmail.com>
Co-authored-by: JalonSolov <JalonSolov@gmail.com>
Co-authored-by: JalonSolov <JalonSolov@gmail.com>
Co-authored-by: JalonSolov <JalonSolov@gmail.com>
Co-authored-by: JalonSolov <JalonSolov@gmail.com>
Co-authored-by: JalonSolov <JalonSolov@gmail.com>
Co-authored-by: JalonSolov <JalonSolov@gmail.com>
Co-authored-by: JalonSolov <JalonSolov@gmail.com>
Co-authored-by: JalonSolov <JalonSolov@gmail.com>
Co-authored-by: JalonSolov <JalonSolov@gmail.com>
Co-authored-by: JalonSolov <JalonSolov@gmail.com>
Co-authored-by: JalonSolov <JalonSolov@gmail.com>
Co-authored-by: JalonSolov <JalonSolov@gmail.com>
Co-authored-by: JalonSolov <JalonSolov@gmail.com>
Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

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

Excellent work.

@spytheman spytheman merged commit 0713e39 into vlang:master Jan 10, 2024
42 checks passed
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.

None yet

2 participants