From: Stephan Bosch Date: Mon, 26 Sep 2022 20:16:35 +0000 (+0200) Subject: auth: password-scheme-scram - Move Hi() to auth-scram.c. X-Git-Tag: 2.4.0~3150 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=39ff0e1ab2aa96dfa4b88981b290bb6a0b0bbd60;p=thirdparty%2Fdovecot%2Fcore.git auth: password-scheme-scram - Move Hi() to auth-scram.c. --- diff --git a/src/auth/auth-scram.c b/src/auth/auth-scram.c new file mode 100644 index 0000000000..abdcb3a854 --- /dev/null +++ b/src/auth/auth-scram.c @@ -0,0 +1,26 @@ +static void +Hi(const struct hash_method *hmethod, const unsigned char *str, size_t str_size, + const unsigned char *salt, size_t salt_size, unsigned int i, + unsigned char *result) +{ + struct hmac_context ctx; + unsigned char U[hmethod->digest_size]; + unsigned int j, k; + + /* Calculate U1 */ + hmac_init(&ctx, str, str_size, hmethod); + hmac_update(&ctx, salt, salt_size); + hmac_update(&ctx, "\0\0\0\1", 4); + hmac_final(&ctx, U); + + memcpy(result, U, hmethod->digest_size); + + /* Calculate U2 to Ui and Hi */ + for (j = 2; j <= i; j++) { + hmac_init(&ctx, str, str_size, hmethod); + hmac_update(&ctx, U, sizeof(U)); + hmac_final(&ctx, U); + for (k = 0; k < hmethod->digest_size; k++) + result[k] ^= U[k]; + } +} diff --git a/src/auth/password-scheme-scram.c b/src/auth/password-scheme-scram.c index ada19b644d..bb58456386 100644 --- a/src/auth/password-scheme-scram.c +++ b/src/auth/password-scheme-scram.c @@ -25,32 +25,7 @@ #define SCRAM_DEFAULT_ITERATE_COUNT 4096 -static void -Hi(const struct hash_method *hmethod, const unsigned char *str, size_t str_size, - const unsigned char *salt, size_t salt_size, unsigned int i, - unsigned char *result) -{ - struct hmac_context ctx; - unsigned char U[hmethod->digest_size]; - unsigned int j, k; - - /* Calculate U1 */ - hmac_init(&ctx, str, str_size, hmethod); - hmac_update(&ctx, salt, salt_size); - hmac_update(&ctx, "\0\0\0\1", 4); - hmac_final(&ctx, U); - - memcpy(result, U, hmethod->digest_size); - - /* Calculate U2 to Ui and Hi */ - for (j = 2; j <= i; j++) { - hmac_init(&ctx, str, str_size, hmethod); - hmac_update(&ctx, U, sizeof(U)); - hmac_final(&ctx, U); - for (k = 0; k < hmethod->digest_size; k++) - result[k] ^= U[k]; - } -} +#include "auth-scram.c" int scram_scheme_parse(const struct hash_method *hmethod, const char *name, const unsigned char *credentials, size_t size,