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

core/crypto: More improvements #4124

Merged
merged 14 commits into from
Mar 23, 2025
Merged

Conversation

Yawning
Copy link
Contributor

@Yawning Yawning commented Aug 23, 2024

  • Cleanups/improvements
    • Refactor the blake2 code to use SIMD? (Kind of not worth it with just SSE2)
    • (AMD64) Support hardware accelerated SHA-224/SHA-256.
    • Switch to using context-less panic
    • Improve/add benchmarks
    • Use ensure to enforce API contracts
  • More algorithms?
    • Add X448
    • AEGIS
    • Deoxys-II
    • Argon2 (Delayed to next patch series)
    • ChaCha8Rng (Delayed to next patch series)

@Yawning Yawning force-pushed the feature/crypto branch 9 times, most recently from 8450ddd to 26fb0a1 Compare August 30, 2024 19:26
@Yawning Yawning force-pushed the feature/crypto branch 6 times, most recently from b6f512d to 363df33 Compare September 5, 2024 20:26
@Yawning Yawning force-pushed the feature/crypto branch 3 times, most recently from 4198575 to f69bb60 Compare September 15, 2024 22:43
@Yawning Yawning force-pushed the feature/crypto branch 7 times, most recently from 7d37012 to 00e013b Compare September 26, 2024 07:17
@Yawning Yawning force-pushed the feature/crypto branch 4 times, most recently from 6f62ca6 to e8dc9bc Compare October 13, 2024 17:32
st.rate = _RATE_128L

for _ in 0 ..< 10 {
update_hw_128l(st, iv, key)

Choose a reason for hiding this comment

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

For a bit of performance improvement: since the input is constant, and we don't need to compute a key stream here, the state can be kept in bitsliced form during the initialization rounds. Same for finalization.
In bitsliced form, the rotation of the AES blocks is just a one-bit shift of the bytes.

During AD absorption, you can also keep the state in bitsliced form, and only bitslice the input blocks.

Also for the sbox, there are faster circuits than the Boyar-Peralta: https://eprint.iacr.org/2019/802.pdf

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for the delay in replying to this. I will leave adding those optimizations for a future pass, since my time has been somewhat limited as of late, and what is there is easy to review and gets adequate performance.

@Yawning Yawning force-pushed the feature/crypto branch 2 times, most recently from 567e5f8 to 8da0ae1 Compare February 21, 2025 07:35
@Yawning Yawning marked this pull request as ready for review March 21, 2025 22:07
Copy link
Collaborator

@laytan laytan left a comment

Choose a reason for hiding this comment

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

General question about all the contextless procedures and contextless panics/ensures, is that because it actually performs better, or some other reason?

@@ -235,7 +235,7 @@ gctr_hw :: proc(
// BUG: Sticking this in gctr_hw (like the other implementations) crashes
// the compiler.
//
// src/check_expr.cpp(7892): Assertion Failure: `c->curr_proc_decl->entity`
// src/check_expr.cpp(8104): Assertion Failure: `c->curr_proc_decl->entity`
Copy link
Collaborator

Choose a reason for hiding this comment

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

prob good idea to make an issue with steps to reproduce so this can get fixed

@Yawning
Copy link
Contributor Author

Yawning commented Mar 22, 2025

General question about all the contextless procedures and contextless panics/ensures, is that because it actually performs better, or some other reason?

To be honest it probably doesn't matter either way.

A lot of the crypto code was contextless when I started working on it, and it is exceedingly rare that anything except panic/ensure needs the context. Going from "with context" to "without context" is easier than the reverse in terms of not breaking code that calls the routines, so my inclination is to continue the trend.

@laytan
Copy link
Collaborator

laytan commented Mar 22, 2025

Going from "with context" to "without context" is easier than the reverse in terms of not breaking code that calls the routines, so my inclination is to continue the trend.

Definitely, but then the panics and ensures can't be overwritten, so it's a bit of a balance act. I'm fine with it though, just wanted to know the reasoning, I am glad it isn't performance.

@Kelimion Kelimion merged commit 242f59a into odin-lang:master Mar 23, 2025
7 checks passed
@Yawning Yawning deleted the feature/crypto branch March 23, 2025 10:52
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.

4 participants