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 ea3f50b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 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
38 changes: 19 additions & 19 deletions src/libpgagroal/security.c
Original file line number Diff line number Diff line change
Expand Up @@ -3826,31 +3826,31 @@ salted_password(char* password, char* salt, int salt_length, int iterations, uns

for (int i = 2; i <= iterations; i++)
{
if (HMAC_CTX_reset(ctx) != 1)
for (int j = 0; j < size; j++)
{
goto error;
*(r + j) ^= *(Ui + j);
}
memcpy(&Ui_prev[0], &Ui[0], size);
}

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

if (HMAC_Update(ctx, &Ui_prev[0], size) != 1)
{
goto error;
}
if (HMAC_Init_ex(ctx, password, password_length, EVP_sha256(), NULL) != 1)
{
goto error;
}

if (HMAC_Final(ctx, &Ui[0], &Ui_length) != 1)
{
goto error;
}
if (HMAC_Update(ctx, &Ui_prev[0], size) != 1)
{
goto error;
}

for (int j = 0; j < size; j++)
{
*(r + j) ^= *(Ui + j);
}
memcpy(&Ui_prev[0], &Ui[0], size);
if (HMAC_Final(ctx, &Ui[0], &Ui_length) != 1)
{
goto error;
}

*result = r;
Expand Down

0 comments on commit ea3f50b

Please sign in to comment.