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