doc: Fix section of functions age(xid) and mxid_age(xid)
[pgsql.git] / src / include / common / scram-common.h
blobce848aa328df9fc797cb844e7de350d843662819
1 /*-------------------------------------------------------------------------
3 * scram-common.h
4 * Declarations for helper functions used for SCRAM authentication
6 * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
9 * src/include/common/scram-common.h
11 *-------------------------------------------------------------------------
13 #ifndef SCRAM_COMMON_H
14 #define SCRAM_COMMON_H
16 #include "common/cryptohash.h"
17 #include "common/sha2.h"
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
42 * RFC 7677 uses.
44 #define SCRAM_DEFAULT_SALT_LEN 16
47 * Default number of iterations when generating secret. Should be at least
48 * 4096 per RFC 7677.
50 #define SCRAM_SHA_256_DEFAULT_ITERATIONS 4096
52 extern int scram_SaltedPassword(const char *password,
53 pg_cryptohash_type hash_type, int key_length,
54 const char *salt, int saltlen, int iterations,
55 uint8 *result, const char **errstr);
56 extern int scram_H(const uint8 *input, pg_cryptohash_type hash_type,
57 int key_length, uint8 *result,
58 const char **errstr);
59 extern int scram_ClientKey(const uint8 *salted_password,
60 pg_cryptohash_type hash_type, int key_length,
61 uint8 *result, const char **errstr);
62 extern int scram_ServerKey(const uint8 *salted_password,
63 pg_cryptohash_type hash_type, int key_length,
64 uint8 *result, const char **errstr);
66 extern char *scram_build_secret(pg_cryptohash_type hash_type, int key_length,
67 const char *salt, int saltlen, int iterations,
68 const char *password, const char **errstr);
70 #endif /* SCRAM_COMMON_H */