Giter Site home page Giter Site logo

lhecker / argon2 Goto Github PK

View Code? Open in Web Editor NEW
18.0 3.0 4.0 62 KB

Argon2 bindings for secure password hashing in Go!

Home Page: https://godoc.org/github.com/lhecker/argon2

License: MIT License

C 74.12% Go 12.72% C++ 13.15%
golang go argon argon2 argon2-library

argon2's Introduction

argon2

The fastest and easiest to use Argon2 bindings for Go!

⚠️ Notice ⚠️

In general I recommend using github.com/matthewhartstonge/argon2 for now, for the reasons explained below.
It has the the exact same API as this project and can be used as a drop in replacement.

If you do want to use this project please first download it on one of the actual machines you plan to deploy this project on and then run:

CGO_CFLAGS="-O3 -march=native" go test -run="^$" -bench=BenchmarkHash

You can adjust the Config used for benchmarking here.
If BenchmarkHash is slower or not significantly enough faster than BenchmarkHashXCryptoArgon2 I recommend checking out the alternative project above.

While you should actually still find that this project indeed is "up to twice as fast" as other projects (including those based on golang.org/x/crypto/argon2) on Linux and macOS on modern bare metal hardware, the primary issue is that this performance advantage cannot be reliably replicated when being used in any VMs, including those used by popular Cloud Providers.
I've failed to find a good enough explaination for this performance discrepancy between bare metal and virtualized hardware within a reasonable time frame and thus recommend the library above for now.

Features

  • Zero dependencies
  • Easy to use API, including generation of raw and encoded hashes
  • Up to date & used in production environments
  • Up to twice as fast as golang.org/x/crypto/argon2, allowing you to apply more secure settings while keeping the same latency

Usage

See examples/example.go for a simple introduction and try it out with:

go run examples/example.go

Performance

This library makes use of AVX/SSE, 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="-O3 -march=native"

In this example -march=native will optimize the program for the current platform you're compiling on. If you're planning to deploy this library in a different environment you should replace it with a matching value listed here.

This way you can achieve a significant performance improvement. You can use this performance improvement to apply stronger hash settings and thus improve security at the same cost.

Current downsides

This package uses cgo like all Go bindings and thus comes with all it's downsides. Among others:

  • cgo makes cross-compilation hard
  • Excessive thread spawning¹

¹ Almost every time this library hashes something the scheduler will notice that a Goroutine is blocked in a cgo call and will spawn a new, costly, native thread. To prevent this you may use my workerpool project to set up a worker pool like this.

Modifications to Argon2

Based on fba7b9a.

  • Moved blake2 code into the root source directory and adjusted include paths to match this change.
  • Merged ref.c and opt.c into one file (ref_opt.c). This allows us to use the __SSE__ precompiler flag for SSE detection instead of relying on a Makefile.

argon2's People

Contributors

lhecker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

argon2's Issues

Can not go get project

I tried to get the project via go get github.com/lhecker/argon2 but it fails. This error occurs:

# github.com/lhecker/argon2
go/src/github.com/lhecker/argon2/argon2.go:13:18: fatal error: core.h: No such file or directory
compilation terminated.

If you need any more details and I can afford them just contact me.

I would be really happy to hear from you soon.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.