From 1d52ec5aaef4bf7baab73b102b98c2cab53e45e4 Mon Sep 17 00:00:00 2001 From: n0rbed Date: Sat, 1 Mar 2025 14:46:23 +0200 Subject: [PATCH] [#504] Optimize SALT We do this by removing the independent HMAC context initializations from the HMAC iterations present in salted_password Signed-off-by: Yassin ElBedwihy --- AUTHORS | 1 + doc/manual/97-acknowledgement.md | 1 + doc/manual/advanced/97-acknowledgement.md | 1 + src/libpgagroal/security.c | 19 ++++++++++--------- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/AUTHORS b/AUTHORS index b0501962..09e29b09 100644 --- a/AUTHORS +++ b/AUTHORS @@ -16,3 +16,4 @@ Haoran Zhang Mohanad Khaled Christian Englert Georg Pfuetzenreuter +Yassin ElBedwihy diff --git a/doc/manual/97-acknowledgement.md b/doc/manual/97-acknowledgement.md index cef9be35..9a63305c 100644 --- a/doc/manual/97-acknowledgement.md +++ b/doc/manual/97-acknowledgement.md @@ -23,6 +23,7 @@ Mohanad Khaled Haoran Zhang Christian Englert Georg Pfuetzenreuter +Yassin ElBedwihy ``` ## Committers diff --git a/doc/manual/advanced/97-acknowledgement.md b/doc/manual/advanced/97-acknowledgement.md index cef9be35..9a63305c 100644 --- a/doc/manual/advanced/97-acknowledgement.md +++ b/doc/manual/advanced/97-acknowledgement.md @@ -23,6 +23,7 @@ Mohanad Khaled Haoran Zhang Christian Englert Georg Pfuetzenreuter +Yassin ElBedwihy ``` ## Committers diff --git a/src/libpgagroal/security.c b/src/libpgagroal/security.c index 7ffca53d..93534576 100644 --- a/src/libpgagroal/security.c +++ b/src/libpgagroal/security.c @@ -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) {