Skip to content

Add Argon2 memory-hard hashing and encoding#2773

Open
NotsoanoNimus wants to merge 23 commits intoc3lang:masterfrom
NotsoanoNimus:dev/argon2
Open

Add Argon2 memory-hard hashing and encoding#2773
NotsoanoNimus wants to merge 23 commits intoc3lang:masterfrom
NotsoanoNimus:dev/argon2

Conversation

@NotsoanoNimus
Copy link
Contributor

Implements Argon2 in accordance with RFC 9106 and establishes a canonical way to encode/decode Argon2 hash strings with their included options. This is a known standard, the PHC-SF.

Also includes a small rework of the inflexible way BLAKE2 hashing worked, in order to accommodate runtime hash lengths. This should be acceptable without deprecation notices since this change comes within the same compiler/stdlib version as BLAKE2's implementation.

If you want to know how to use Argon2, please see the related unit-test file.

Future versions of this software should aim to make use of SIMD optimizations for each parallel processing lane, and for the underlying BLAKE2-like round function. At the moment, this sort of optimization is left for the C3 compiler to take care of.

@ManuLinares
Copy link
Contributor

Nice, I'll test this later.

Just a reminder that https://github.com/c3lang/c3c/blob/master/lib/std/hash/blake3.c3#L67 isn't working and to replace it with something like #2727 (comment)

@NotsoanoNimus
Copy link
Contributor Author

Great! Thanks in advance, @ManuLinares.

And I appreciate the reminder: I have that code change hanging around in my SHA-3 branch but I haven't pushed it up yet. My next target is to finally finish that PR and open it for review, so it should be fixed then.

@lerno
Copy link
Collaborator

lerno commented Feb 6, 2026

We got a bunch of tests that are failing because unfortunately they are comparing with code that depends on the line numbers of certain functions, the right way to fix this is to cut away the line number parts of the comparison text.

@lerno
Copy link
Collaborator

lerno commented Feb 16, 2026

When compiled with --print-large-functions:

   14009 instructions found in std::crypto::argon2:decode (/Users/lerno/Projects/c3c/lib/std/crypto/argon2.c3) - function is very long.
   24059 instructions found in std::crypto::argon2:compress (/Users/lerno/Projects/c3c/lib/std/crypto/argon2.c3) - function is very long.

10 instructions are about 1 LOC, so those are 1400 and 2400 lines long functions. Very long functions are relatively slow to codegen in LLVM and may end up less efficient due to cache concerns.

@lerno
Copy link
Collaborator

lerno commented Feb 21, 2026

This unfortunately now have some merge conflicts.

@NotsoanoNimus
Copy link
Contributor Author

This unfortunately now have some merge conflicts.

👍 Will resolve, along with reducing instruction counts, when I return to my workstation in a few hours.

@ManuLinares
Copy link
Contributor

argon2.patch

one more thing you could do, extract the logic for parsing a single parameter into a separate helper

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants