Skip to content

SHA1 rewrite.#3216

Merged
lerno merged 16 commits into
c3lang:masterfrom
p7r0x7:master
May 15, 2026
Merged

SHA1 rewrite.#3216
lerno merged 16 commits into
c3lang:masterfrom
p7r0x7:master

Conversation

@p7r0x7
Copy link
Copy Markdown
Contributor

@p7r0x7 p7r0x7 commented May 10, 2026

Made some adjustments based on https://github.com/halloweeks/sha1/blob/main/sha1.h

Not done yet

@p7r0x7
Copy link
Copy Markdown
Contributor Author

p7r0x7 commented May 10, 2026

@NotsoanoNimus I started.

@p7r0x7
Copy link
Copy Markdown
Contributor Author

p7r0x7 commented May 10, 2026

So far, std.hash.sha1.ll size reduced from 938620 bytes to 191464 bytes, where the original is 3.7% 181% faster.

@p7r0x7
Copy link
Copy Markdown
Contributor Author

p7r0x7 commented May 10, 2026

938620 -> 238203 bytes
Original is 3.2% faster.

@p7r0x7 p7r0x7 marked this pull request as ready for review May 11, 2026 16:30
@p7r0x7
Copy link
Copy Markdown
Contributor Author

p7r0x7 commented May 11, 2026

General rewrite; basically no difference, but is cheaper to compile and will compile smaller for less optimized builds.

@p7r0x7 p7r0x7 changed the title SHA1 improvements. SHA1 rewrite. May 11, 2026
@p7r0x7 p7r0x7 marked this pull request as draft May 11, 2026 17:22
@p7r0x7
Copy link
Copy Markdown
Contributor Author

p7r0x7 commented May 11, 2026

I'm trying to make it identical to current master, and it seems to be a tiny difference in how the compiler handles the same algorithm inlined differently.

@p7r0x7
Copy link
Copy Markdown
Contributor Author

p7r0x7 commented May 11, 2026

Nope. It's just the volatile erasure. Didn't realize not commenting it out in both parts was the only difference. Code is identical to master.

@p7r0x7 p7r0x7 marked this pull request as ready for review May 11, 2026 17:39
@p7r0x7
Copy link
Copy Markdown
Contributor Author

p7r0x7 commented May 11, 2026

@lerno Do we omit state erasure on the grounds that this primitive is broken?

Secure-erase omitted for the broken primitive.
@ManuLinares
Copy link
Copy Markdown
Member

Maybe make secure erasure a compile-time option/$feature instead of removing it entirely?

Most SHA1 usage probably does not benefit from wiping, but some users may still want the hardening for HMAC/password-related contexts 🤷️

@lerno
Copy link
Copy Markdown
Collaborator

lerno commented May 11, 2026

State erasure is good, but is it costly?

@p7r0x7
Copy link
Copy Markdown
Contributor Author

p7r0x7 commented May 11, 2026

State erasure is good, but is it costly?

0.8% faster without

@p7r0x7
Copy link
Copy Markdown
Contributor Author

p7r0x7 commented May 11, 2026

Ready to merge?

@lerno
Copy link
Copy Markdown
Collaborator

lerno commented May 11, 2026

Something's wrong, the tests fail:

RROR: 'Assert "sha.final() == x"84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1"" failed.'
  in std.os.posix.backtrace (/home/c3c/source/lib/std/os/posix/process.c3:91) [/tmp/tmp.n8MgTRHLfX/unit/testrun] [inline]
  in std.os.backtrace.capture_current (/home/c3c/source/lib/std/os/backtrace.c3:87) [/tmp/tmp.n8MgTRHLfX/unit/testrun] [inline]
  in std.core.builtin.print_backtrace (/home/c3c/source/lib/std/core/builtin.c3:227) [/tmp/tmp.n8MgTRHLfX/unit/testrun] [inline]
  in std.core.runtime.panic_test.20669 (/home/c3c/source/lib/std/core/runtime_test.c3:117) [/tmp/tmp.n8MgTRHLfX/unit/testrun] [inline]
  in std.hash.sha1_test.test_sha1_longer (/home/c3c/source/test/unit/stdlib/hash/sha1.c3:26) [/tmp/tmp.n8MgTRHLfX/unit/testrun] [inline]
  in std.core.runtime.run_tests (/home/c3c/source/lib/std/core/runtime_test.c3:333) [/tmp/tmp.n8MgTRHLfX/unit/testrun]
  in std.core.runtime.default_test_runner (/home/c3c/source/lib/std/core/runtime_test.c3:386) [/tmp/tmp.n8MgTRHLfX/unit/testrun] [inline]

Test failed ^^^ ( sha1.c3:26 ) Assert "sha.final() == x"84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1"" failed.

@p7r0x7
Copy link
Copy Markdown
Contributor Author

p7r0x7 commented May 11, 2026

Yikes, okay.

@p7r0x7
Copy link
Copy Markdown
Contributor Author

p7r0x7 commented May 11, 2026

Silly me; handled. Improved my test: 0.63% faster without zeroing.

@lerno
Copy link
Copy Markdown
Collaborator

lerno commented May 15, 2026

Interesting! This seems to have triggered a lowering bug. Don't change the code, I need to look at it.

@lerno lerno merged commit 78a0727 into c3lang:master May 15, 2026
16 checks passed
@lerno
Copy link
Copy Markdown
Collaborator

lerno commented May 15, 2026

Thank you!

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