Skip to content

Commit

Permalink
[agroal#504] Optimize SALT
Browse files Browse the repository at this point in the history
We do this by removing the independent HMAC context initializations from the HMAC iterations present in salted_password

Signed-off-by: Yassin ElBedwihy <eng.yassin.elbedwihy@gmail.com>
  • Loading branch information
n0rbed committed Mar 2, 2025
1 parent 400e019 commit 1d52ec5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ Haoran Zhang <andrewzhr9911@gmail.com>
Mohanad Khaled <mohanadkhaled87@gmail.com>
Christian Englert <code@c.roboticbrain.de>
Georg Pfuetzenreuter <georg.pfuetzenreuter@suse.com>
Yassin ElBedwihy <eng.yassin.elbedwihy@gmail.com>
1 change: 1 addition & 0 deletions doc/manual/97-acknowledgement.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Mohanad Khaled <mohanadkhaled87@gmail.com>
Haoran Zhang <andrewzhr9911@gmail.com>
Christian Englert <code@c.roboticbrain.de>
Georg Pfuetzenreuter <georg.pfuetzenreuter@suse.com>
Yassin ElBedwihy <eng.yassin.elbedwihy@gmail.com>
```

## Committers
Expand Down
1 change: 1 addition & 0 deletions doc/manual/advanced/97-acknowledgement.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Mohanad Khaled <mohanadkhaled87@gmail.com>
Haoran Zhang <andrewzhr9911@gmail.com>
Christian Englert <code@c.roboticbrain.de>
Georg Pfuetzenreuter <georg.pfuetzenreuter@suse.com>
Yassin ElBedwihy <eng.yassin.elbedwihy@gmail.com>
```

## Committers
Expand Down
19 changes: 10 additions & 9 deletions src/libpgagroal/security.c
Original file line number Diff line number Diff line change
Expand Up @@ -3824,17 +3824,18 @@ salted_password(char* password, char* salt, int salt_length, int iterations, uns
}
memcpy(r, &Ui_prev[0], size);

for (int i = 2; i <= iterations; i++)
if (HMAC_CTX_reset(ctx) != 1)
{
if (HMAC_CTX_reset(ctx) != 1)
{
goto error;
}
goto error;
}

if (HMAC_Init_ex(ctx, password, password_length, EVP_sha256(), NULL) != 1)
{
goto error;
}
if (HMAC_Init_ex(ctx, password, password_length, EVP_sha256(), NULL) != 1)
{
goto error;
}

for (int i = 2; i <= iterations; i++)
{

if (HMAC_Update(ctx, &Ui_prev[0], size) != 1)
{
Expand Down

0 comments on commit 1d52ec5

Please sign in to comment.