php_password.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Copyright (c) The PHP Group |
  4. +----------------------------------------------------------------------+
  5. | This source file is subject to version 3.01 of the PHP license, |
  6. | that is bundled with this package in the file LICENSE, and is |
  7. | available through the world-wide-web at the following url: |
  8. | https://www.php.net/license/3_01.txt |
  9. | If you did not receive a copy of the PHP license and are unable to |
  10. | obtain it through the world-wide-web, please send a note to |
  11. | license@php.net so we can mail you a copy immediately. |
  12. +----------------------------------------------------------------------+
  13. | Authors: Anthony Ferrara <ircmaxell@php.net> |
  14. | Charles R. Portwood II <charlesportwoodii@erianna.com> |
  15. +----------------------------------------------------------------------+
  16. */
  17. #ifndef PHP_PASSWORD_H
  18. #define PHP_PASSWORD_H
  19. PHP_MINIT_FUNCTION(password);
  20. PHP_MSHUTDOWN_FUNCTION(password);
  21. #define PHP_PASSWORD_DEFAULT PHP_PASSWORD_BCRYPT
  22. #define PHP_PASSWORD_BCRYPT_COST 10
  23. #if HAVE_ARGON2LIB
  24. /**
  25. * When updating these values, synchronize ext/sodium/sodium_pwhash.c values.
  26. * Note that libargon expresses memlimit in KB, while libsoidum uses bytes.
  27. */
  28. #define PHP_PASSWORD_ARGON2_MEMORY_COST (64 << 10)
  29. #define PHP_PASSWORD_ARGON2_TIME_COST 4
  30. #define PHP_PASSWORD_ARGON2_THREADS 1
  31. #endif
  32. typedef struct _php_password_algo {
  33. const char *name;
  34. zend_string *(*hash)(const zend_string *password, zend_array *options);
  35. bool (*verify)(const zend_string *password, const zend_string *hash);
  36. bool (*needs_rehash)(const zend_string *password, zend_array *options);
  37. int (*get_info)(zval *return_value, const zend_string *hash);
  38. bool (*valid)(const zend_string *hash);
  39. } php_password_algo;
  40. extern const php_password_algo php_password_algo_bcrypt;
  41. #if HAVE_ARGON2LIB
  42. extern const php_password_algo php_password_algo_argon2i;
  43. extern const php_password_algo php_password_algo_argon2id;
  44. #endif
  45. PHPAPI int php_password_algo_register(const char*, const php_password_algo*);
  46. PHPAPI void php_password_algo_unregister(const char*);
  47. PHPAPI const php_password_algo* php_password_algo_default(void);
  48. PHPAPI zend_string *php_password_algo_extract_ident(const zend_string*);
  49. PHPAPI const php_password_algo* php_password_algo_find(const zend_string*);
  50. PHPAPI const php_password_algo* php_password_algo_identify_ex(const zend_string*, const php_password_algo*);
  51. static inline const php_password_algo* php_password_algo_identify(const zend_string *hash) {
  52. return php_password_algo_identify_ex(hash, php_password_algo_default());
  53. }
  54. #endif