The fastest and easiest to use Argon2 bindings for Go!
- Zero dependencies
- Easy to use API, including generation of raw and encoded hashes.
- Up to date & used in production environments.
- Contains Go-specific optimizations for a consistent 15% performance boost.
- Allows you to enable all possible optimizations in Argon2, improving performance by up to 40% in total!
See examples/example.go
for a simple introduction and try it out with:
go run examples/example.go
This library makes use of SSE, SSE2, SSSE3 and XOP, depending on whether they are enabled during compilation.
This can be done by adding appropriate gcc
optimization flags to the CGO_CFLAGS
environment variable.
Here's an example which you could set before running go build
etc.:
export CGO_CFLAGS="-Ofast -funroll-loops -march=native"
In this example -march=native
will optimize the program for the current platform you're compiling on.
If you are planning to deploy this library in a different environment you should replace it with a matching value listed here.
This way you can achieve an performance improvement of up to 25%. You can use this performance improvement as a free ticket for stronger hash settings and thus improved security at the same cost.
This package uses cgo
like all Go bindings and thus comes with all it's downsides:
cgo
makes cross-compilation hard.- Can cause excessive spawning of native threads. ¹
Due to the infinitely superior performance compared to a pure Go implementation I still personally believe that the benefits outweigh the drawbacks though.
¹
Let's say there is a situation where one or more Goroutines are stuck in a cgo
call and a new regular Goroutine is spawned.
If the scheduler can't find a suitable processor to run that Goroutine on, it will spawn a new processor.
Furthermore one of the Goroutines stuck in cgo
is then marked as a "native" thread, which is destroyed as soon as the call is finished.
This downside has been mostly offset though by optimizing Argon2 to not spawn native threads as long as Config.Parallelism
is 1 (which is the default).
Based on bc345e3.
- Moved blake2 code into the root source directory & adjusted include paths to match this.
- Merged
ref.{h,c}
andopt.{h,c}
into one file (ref_opt.{h,c}
) & adjusted include paths to match this. This allows us to use the__SSE__
precompiler flag for SSE detection instead of relying on a Makefile. - Optimized
core.c
'sfill_memory_blocks
(seecore.diff
). This will now prevent spawning additional threads wheneverConfig.Parallelism
is 1.