2
0

scram-common.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*-------------------------------------------------------------------------
  2. *
  3. * scram-common.h
  4. * Declarations for helper functions used for SCRAM authentication
  5. *
  6. * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
  7. * Portions Copyright (c) 1994, Regents of the University of California
  8. *
  9. * src/include/common/scram-common.h
  10. *
  11. *-------------------------------------------------------------------------
  12. */
  13. #ifndef SCRAM_COMMON_H
  14. #define SCRAM_COMMON_H
  15. #include "common/cryptohash.h"
  16. #include "common/sha2.h"
  17. /* Name of SCRAM mechanisms per IANA */
  18. #define SCRAM_SHA_256_NAME "SCRAM-SHA-256"
  19. #define SCRAM_SHA_256_PLUS_NAME "SCRAM-SHA-256-PLUS" /* with channel binding */
  20. /* Length of SCRAM keys (client and server) */
  21. #define SCRAM_KEY_LEN PG_SHA256_DIGEST_LENGTH
  22. /* length of HMAC */
  23. #define SHA256_HMAC_B PG_SHA256_BLOCK_LENGTH
  24. /*
  25. * Size of random nonce generated in the authentication exchange. This
  26. * is in "raw" number of bytes, the actual nonces sent over the wire are
  27. * encoded using only ASCII-printable characters.
  28. */
  29. #define SCRAM_RAW_NONCE_LEN 18
  30. /*
  31. * Length of salt when generating new secrets, in bytes. (It will be stored
  32. * and sent over the wire encoded in Base64.) 16 bytes is what the example in
  33. * RFC 7677 uses.
  34. */
  35. #define SCRAM_DEFAULT_SALT_LEN 16
  36. /*
  37. * Default number of iterations when generating secret. Should be at least
  38. * 4096 per RFC 7677.
  39. */
  40. #define SCRAM_DEFAULT_ITERATIONS 4096
  41. extern int scram_SaltedPassword(const char *password, const char *salt,
  42. int saltlen, int iterations, uint8 *result,
  43. const char **errstr);
  44. extern int scram_H(const uint8 *str, int len, uint8 *result,
  45. const char **errstr);
  46. extern int scram_ClientKey(const uint8 *salted_password, uint8 *result,
  47. const char **errstr);
  48. extern int scram_ServerKey(const uint8 *salted_password, uint8 *result,
  49. const char **errstr);
  50. extern char *scram_build_secret(const char *salt, int saltlen, int iterations,
  51. const char *password, const char **errstr);
  52. #endif /* SCRAM_COMMON_H */