-
Notifications
You must be signed in to change notification settings - Fork 36
Add PBKDF2 Hashing support #596
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
MohamedSabthar
merged 27 commits into
ballerina-platform:master
from
randilt:PBKDF2-support
Apr 16, 2025
+674
−233
Merged
Changes from 11 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
6240e8a
[Automated] Update the native jar versions
randilt f11b98a
Move password hashing methods to Password class removing PasswordArgo…
randilt d5744d5
Add PBKDF2 configuration and validation methods in PasswordUtils
randilt 719fa07
Implement PBKDF2 hashing and verification methods in the crypto module
randilt 8dd8018
Update PBKDF2 parameters and validation in tests and PasswordUtils
randilt 6a83815
Remove generateSaltPbkdf2 function and related tests from hash module
randilt 37188f0
Add PBKDF2 password hashing and verification support to changelog
randilt 3c667ff
Fix changelog, move the PBKDF2 support change to unreleased
randilt 095e270
Add proposal for PBKDF2-based password hashing APIs in Ballerina cryp…
randilt af9ef35
Add PBKDF2 password hashing and verification documentation to the spe…
randilt b0afd37
Add PBKDF2 algorithm implementation to the specification
randilt be53244
Update ballerina/hash.bal
randilt 49781ca
Enhance PBKDF2 hashing function to have an enum for algorithm param
randilt fbeaadd
Merge branch 'PBKDF2-support' of https://github.com/randilt/module-ba…
randilt 096e08e
Update PBKDF2 hashing proposal hashPbkdf2 func
randilt 75e1ca2
Add HmacAlgorithm enum for PBKDF2 and update related functions
randilt 92b2dba
Fix algorithm parameter documentation and update default value in has…
randilt 94dbed3
Rename validatePBKDF2Algorithm method to validatePbkdf2Algorithm for …
randilt 176b244
Add minimum memory cost constant for PBKDF2 and update validation logic
randilt 85a6f0f
Fix formatting in error message for minimum memory cost in PBKDF2 val…
randilt 709dbc3
Refactor error messages in Argon2 and Bcrypt tests to use string inte…
randilt ce4da8e
Add password hashing constants and refactor formatting methods for BC…
randilt 0e29066
Update ballerina/hash.bal
randilt 19b5260
Introduce HmacAlgorithm enum for PBKDF2 hashing API
randilt 1d832b1
Update the spec for Pbkdf2 APIs
randilt 2029369
Remove default parameters for BCrypt, Argon2, and PBKDF2 in PasswordU…
randilt 3a5bac0
Update spec for PBKDF2
randilt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # Proposal: Introduce PBKDF2-Based Password Hashing to Ballerina Crypto Module | ||
|
|
||
| _Authors_: @randilt | ||
| _Reviewers_: | ||
| _Created_: 2025/03/18 | ||
| _Updated_: 2025/03/18 | ||
| _Issues_: [#43926](https://github.com/ballerina-platform/ballerina-lang/issues/43926) | ||
|
|
||
| ## Summary | ||
| The Ballerina crypto module currently lacks built-in support for PBKDF2 password hashing, a widely used key derivation function for secure password storage. This proposal introduces two new APIs to provide PBKDF2-based password hashing and verification. | ||
|
|
||
| ## Goals | ||
| - Introduce PBKDF2 password hashing support with configurable parameters | ||
| - Provide a verification function to check hashed passwords against user inputs | ||
| - Support common HMAC algorithms (`SHA1`, `SHA256`, `SHA512`) and iteration count customization | ||
|
|
||
| ## Motivation | ||
| Password hashing is a fundamental security requirement for authentication systems. PBKDF2 is a widely recognized key derivation function that enhances security by applying multiple iterations of a cryptographic hash function. By integrating PBKDF2 support, the Ballerina crypto module will offer a standardized and secure method for password storage and verification. | ||
|
|
||
| ## Description | ||
| This proposal aims to introduce secure PBKDF2 password hashing and verification capabilities in the Ballerina crypto module. | ||
|
|
||
| ### API Additions | ||
|
|
||
| #### PBKDF2 Hashing Function | ||
| A new API will be introduced to generate PBKDF2 hashes with configurable parameters: | ||
|
|
||
| ```ballerina | ||
| public isolated function hashPbkdf2( | ||
| string password, | ||
| int iterations = 10000, | ||
| string algorithm = "SHA256" | ||
MohamedSabthar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) returns string|Error; | ||
| ``` | ||
|
|
||
| #### PBKDF2 Verification Function | ||
| A corresponding API will be introduced to verify a password against a PBKDF2 hash: | ||
|
|
||
| ```ballerina | ||
| public isolated function verifyPbkdf2( | ||
| string password, | ||
| string hashedPassword | ||
| ) returns boolean|Error; | ||
| ``` | ||
|
|
||
| These functions will allow developers to securely hash and verify passwords using PBKDF2 with customizable parameters for increased security. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,6 +105,7 @@ The conforming implementation of the specification is released and included in t | |
| 10. [Password hashing](#10-password-hashing) | ||
| * 10.1 [BCrypt](#101-bcrypt) | ||
| * 10.2 [Argon2](#102-argon2) | ||
| * 10.3 [PBKDF2](#103-pbkdf2) | ||
|
|
||
|
|
||
| ## 1. [Overview](#1-overview) | ||
|
|
@@ -1184,3 +1185,41 @@ string hashedPassword1 = check crypto:hashArgon2(password); | |
| string hashedPassword2 = check crypto:hashArgon2(password, iterations = 4, memory = 131072, parallelism = 8); | ||
| boolean isValid = check crypto:verifyArgon2(password, hashedPassword1); | ||
| ``` | ||
| ### 10.3 [PBKDF2](#103-pbkdf2) | ||
|
|
||
| Implements the PBKDF2 (Password-Based Key Derivation Function 2) algorithm for password hashing. | ||
|
|
||
| ```ballerina | ||
| public isolated function hashPbkdf2(string password, int iterations = 10000, | ||
|
||
| string algorithm = "SHA256") returns string|Error | ||
| ``` | ||
|
|
||
| Parameters: | ||
| - `password`: The plain text password to hash | ||
| - `iterations`: Optional number of iterations (default: 10000) | ||
| - `algorithm`: Optional HMAC algorithm (SHA1, SHA256, SHA512). Default is SHA256 | ||
|
|
||
| Example: | ||
| ```ballerina | ||
| string password = "mySecurePassword123"; | ||
| // Hash with default parameters | ||
| string hashedPassword = check crypto:hashPbkdf2(password); | ||
| // Hash with custom parameters | ||
| string customHashedPassword = check crypto:hashPbkdf2(password, iterations = 15000, algorithm = "SHA512"); | ||
| ``` | ||
|
|
||
| ```ballerina | ||
| public isolated function verifyPbkdf2(string password, string hashedPassword) returns boolean|Error | ||
| ``` | ||
|
|
||
| Parameters: | ||
| - `password`: The plain text password to verify | ||
| - `hashedPassword`: PBKDF2 hashed password to verify against | ||
|
|
||
| Example: | ||
| ```ballerina | ||
| string password = "mySecurePassword123"; | ||
| string hashedPassword = "$pbkdf2-sha256$i=10000$salt$hash"; | ||
| // Verify the hashed password | ||
| boolean isValid = check crypto:verifyPbkdf2(password, hashedPassword); | ||
| ``` | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.