gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.3KB

  1. /*-------------------------------------------------------------------------
  2. *
  3. * scram-common.h
  4. * Declarations for helper functions used for SCRAM authentication
  5. *
  6. * Portions Copyright (c) 1996-2019, 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/sha2.h"
  16. /* Name of SCRAM mechanisms per IANA */
  17. #define SCRAM_SHA_256_NAME "SCRAM-SHA-256"
  18. #define SCRAM_SHA_256_PLUS_NAME "SCRAM-SHA-256-PLUS" /* with channel binding */
  19. /* Length of SCRAM keys (client and server) */
  20. #define SCRAM_KEY_LEN PG_SHA256_DIGEST_LENGTH
  21. /* length of HMAC */
  22. #define SHA256_HMAC_B PG_SHA256_BLOCK_LENGTH
  23. /*
  24. * Size of random nonce generated in the authentication exchange. This
  25. * is in "raw" number of bytes, the actual nonces sent over the wire are
  26. * encoded using only ASCII-printable characters.
  27. */
  28. #define SCRAM_RAW_NONCE_LEN 18
  29. /*
  30. * Length of salt when generating new verifiers, in bytes. (It will be stored
  31. * and sent over the wire encoded in Base64.) 16 bytes is what the example in
  32. * RFC 7677 uses.
  33. */
  34. #define SCRAM_DEFAULT_SALT_LEN 16
  35. /*
  36. * Default number of iterations when generating verifier. Should be at least
  37. * 4096 per RFC 7677.
  38. */
  39. #define SCRAM_DEFAULT_ITERATIONS 4096
  40. /*
  41. * Context data for HMAC used in SCRAM authentication.
  42. */
  43. typedef struct
  44. {
  45. pg_sha256_ctx sha256ctx;
  46. uint8 k_opad[SHA256_HMAC_B];
  47. } scram_HMAC_ctx;
  48. extern void scram_HMAC_init(scram_HMAC_ctx *ctx, const uint8 *key, int keylen);
  49. extern void scram_HMAC_update(scram_HMAC_ctx *ctx, const char *str, int slen);
  50. extern void scram_HMAC_final(uint8 *result, scram_HMAC_ctx *ctx);
  51. extern void scram_SaltedPassword(const char *password, const char *salt,
  52. int saltlen, int iterations, uint8 *result);
  53. extern void scram_H(const uint8 *str, int len, uint8 *result);
  54. extern void scram_ClientKey(const uint8 *salted_password, uint8 *result);
  55. extern void scram_ServerKey(const uint8 *salted_password, uint8 *result);
  56. extern char *scram_build_verifier(const char *salt, int saltlen, int iterations,
  57. const char *password);
  58. #endif /* SCRAM_COMMON_H */
上海开阖软件有限公司 沪ICP备12045867号-1