1/*-------------------------------------------------------------------------
4 * Declarations for helper functions used for SCRAM authentication
6 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
9 * src/include/common/scram-common.h
11 *-------------------------------------------------------------------------
19/* Name of SCRAM mechanisms per IANA */
20 #define SCRAM_SHA_256_NAME "SCRAM-SHA-256"
21 #define SCRAM_SHA_256_PLUS_NAME "SCRAM-SHA-256-PLUS" /* with channel binding */
23/* Length of SCRAM keys (client and server) */
24 #define SCRAM_SHA_256_KEY_LEN PG_SHA256_DIGEST_LENGTH
27 * Size of buffers used internally by SCRAM routines, that should be the
28 * maximum of SCRAM_SHA_*_KEY_LEN among the hash methods supported.
30 #define SCRAM_MAX_KEY_LEN SCRAM_SHA_256_KEY_LEN
33 * Size of random nonce generated in the authentication exchange. This
34 * is in "raw" number of bytes, the actual nonces sent over the wire are
35 * encoded using only ASCII-printable characters.
37 #define SCRAM_RAW_NONCE_LEN 18
40 * Length of salt when generating new secrets, in bytes. (It will be stored
41 * and sent over the wire encoded in Base64.) 16 bytes is what the example in
44 #define SCRAM_DEFAULT_SALT_LEN 16
47 * Default number of iterations when generating secret. Should be at least
50 #define SCRAM_SHA_256_DEFAULT_ITERATIONS 4096
55 uint8 *result,
const char **errstr);
57 int key_length,
uint8 *result,
61 uint8 *result,
const char **errstr);
64 uint8 *result,
const char **errstr);
68 const char *
password,
const char **errstr);
70#endif /* SCRAM_COMMON_H */
int scram_ServerKey(const uint8 *salted_password, pg_cryptohash_type hash_type, int key_length, uint8 *result, const char **errstr)
int scram_SaltedPassword(const char *password, pg_cryptohash_type hash_type, int key_length, const uint8 *salt, int saltlen, int iterations, uint8 *result, const char **errstr)
char * scram_build_secret(pg_cryptohash_type hash_type, int key_length, const uint8 *salt, int saltlen, int iterations, const char *password, const char **errstr)
int scram_ClientKey(const uint8 *salted_password, pg_cryptohash_type hash_type, int key_length, uint8 *result, const char **errstr)
int scram_H(const uint8 *input, pg_cryptohash_type hash_type, int key_length, uint8 *result, const char **errstr)