Skip to content

Benchmark Hashing Library

Théophile JR edited this page Oct 30, 2024 · 1 revision

Introduction

We needed to choose a library to hash the users passwords in the database.

Reasons for Choosing libsodium

1. Ease of Use and Integration

  • Simple API for Password Hashing: libsodium provides a straightforward API, making password hashing simple to implement and maintain.
  • Automatic Salting: With libsodium, salting is handled automatically, adding a unique, cryptographic salt to each hash without additional code complexity.

2. Supports Argon2 - A Strong Password Hashing Algorithm

  • Secure Against Attacks: Argon2 is designed to be memory-hard, providing a robust defense against brute-force and side-channel attacks.
  • Future-Proof Security: Argon2 has been widely recognized as one of the most secure hashing algorithms, making it a reliable choice for applications that require long-term security.

3. Cross-Platform Compatibility

  • Windows and Linux Support: libsodium is cross-platform, compatible with both Windows and Linux, ensuring consistent behavior regardless of the operating system.
  • Easy Installation with vcpkg: Installing libsodium through vcpkg (Visual Studio C++ Package Manager) simplifies setup and configuration, especially for C++ applications.

4. Efficient Performance

  • Optimized for Modern Processors: libsodium offers high-performance implementations of cryptographic algorithms, including hardware-optimized support where available.
  • Efficient Memory Use with Argon2: By adjusting parameters, developers can balance memory and processing time, optimizing for the specific performance needs of their application.

5. Comprehensive Security Features Beyond Password Hashing

  • Encryption and Decryption: In addition to hashing, libsodium supports encryption, making it an all-in-one library for multiple cryptographic needs.
  • Secure Random Number Generation: libsodium’s secure random number generator is useful for other security aspects, such as generating unique user IDs or session tokens.

Comparison with Other Hashing Libraries

Feature libsodium OpenSSL bcrypt
Hashing Algorithm Argon2 (modern) SHA256, SHA512, etc. bcrypt
Salting Automatic Manual Automatic
Ease of Use Very Easy Moderate Moderate
Installation with vcpkg Yes Limited No
Cross-Platform Yes (Win/Linux) Yes Yes
Security Level High (memory-hard) High (memory-hard) Moderate

Conclusion

libsodium is a powerful choice for secure password hashing due to its simplicity, cross-platform support, and use of Argon2. With easy installation through vcpkg and a straightforward API that includes automatic salting, libsodium provides a highly secure, developer-friendly solution for password hashing that works seamlessly on Windows and Linux.