From da1229814ca916df40e5676334d5a913261d4948 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Tue, 16 Apr 2024 16:11:09 +0200 Subject: [PATCH] Add support for `SCRAM-SHA-512-PLUS` Patch written by @matthias-hmb This fixes #241 Signed-off-by: Steffen Jaeckel --- src/common.h | 6 ++++-- src/scram.c | 11 +++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/common.h b/src/common.h index 0cba032..fbb4034 100644 --- a/src/common.h +++ b/src/common.h @@ -175,9 +175,11 @@ struct _xmpp_send_queue_t { #define SASL_MASK_EXTERNAL (1 << 6) #define SASL_MASK_SCRAMSHA1_PLUS (1 << 7) #define SASL_MASK_SCRAMSHA256_PLUS (1 << 8) +#define SASL_MASK_SCRAMSHA512_PLUS (1 << 9) -#define SASL_MASK_SCRAM_PLUS \ - (SASL_MASK_SCRAMSHA1_PLUS | SASL_MASK_SCRAMSHA256_PLUS) +#define SASL_MASK_SCRAM_PLUS \ + (SASL_MASK_SCRAMSHA1_PLUS | SASL_MASK_SCRAMSHA256_PLUS | \ + SASL_MASK_SCRAMSHA512_PLUS) #define SASL_MASK_SCRAM_WEAK \ (SASL_MASK_SCRAMSHA1 | SASL_MASK_SCRAMSHA256 | SASL_MASK_SCRAMSHA512) #define SASL_MASK_SCRAM (SASL_MASK_SCRAM_PLUS | SASL_MASK_SCRAM_WEAK) diff --git a/src/scram.c b/src/scram.c index 568ac5d..35a62db 100644 --- a/src/scram.c +++ b/src/scram.c @@ -78,12 +78,23 @@ const struct hash_alg scram_sha512 = { (void (*)(void *, const uint8_t *, size_t))sha512_process, (void (*)(void *, uint8_t *))sha512_done}; +const struct hash_alg scram_sha512_plus = { + "SCRAM-SHA-512-PLUS", + SASL_MASK_SCRAMSHA512_PLUS, + SHA512_DIGEST_SIZE, + (void (*)(const uint8_t *, size_t, uint8_t *))sha512_hash, + (void (*)(void *))sha512_init, + (void (*)(void *, const uint8_t *, size_t))sha512_process, + (void (*)(void *, uint8_t *))sha512_done}; + /* The order of this list defines the order in which the SCRAM algorithms are * tried if the server supports them. * Their order is derived from * https://datatracker.ietf.org/doc/html/draft-ietf-kitten-password-storage */ const struct hash_alg *scram_algs[] = { + /* *1 */ + &scram_sha512_plus, /* *1 */ &scram_sha256_plus, /* *1 */