xref: /php-src/ext/standard/php_password.h (revision 42a85fc5)
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 
18 #ifndef PHP_PASSWORD_H
19 #define PHP_PASSWORD_H
20 
21 PHP_MINIT_FUNCTION(password);
22 PHP_MSHUTDOWN_FUNCTION(password);
23 
24 #define PHP_PASSWORD_DEFAULT    PHP_PASSWORD_BCRYPT
25 #define PHP_PASSWORD_BCRYPT_COST 12
26 
27 #ifdef HAVE_ARGON2LIB
28 /**
29  * When updating these values, synchronize ext/sodium/sodium_pwhash.c values.
30  * Note that libargon expresses memlimit in KB, while libsoidum uses bytes.
31  */
32 #define PHP_PASSWORD_ARGON2_MEMORY_COST (64 << 10)
33 #define PHP_PASSWORD_ARGON2_TIME_COST 4
34 #define PHP_PASSWORD_ARGON2_THREADS 1
35 #endif
36 
37 typedef struct _php_password_algo {
38 	const char *name;
39 	zend_string *(*hash)(const zend_string *password, zend_array *options);
40 	bool (*verify)(const zend_string *password, const zend_string *hash);
41 	bool (*needs_rehash)(const zend_string *password, zend_array *options);
42 	int (*get_info)(zval *return_value, const zend_string *hash);
43 	bool (*valid)(const zend_string *hash);
44 } php_password_algo;
45 
46 extern const php_password_algo php_password_algo_bcrypt;
47 #ifdef HAVE_ARGON2LIB
48 extern const php_password_algo php_password_algo_argon2i;
49 extern const php_password_algo php_password_algo_argon2id;
50 #endif
51 
52 PHPAPI int php_password_algo_register(const char*, const php_password_algo*);
53 PHPAPI void php_password_algo_unregister(const char*);
54 PHPAPI const php_password_algo* php_password_algo_default(void);
55 PHPAPI zend_string *php_password_algo_extract_ident(const zend_string*);
56 PHPAPI const php_password_algo* php_password_algo_find(const zend_string*);
57 
58 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)59 static inline const php_password_algo* php_password_algo_identify(const zend_string *hash) {
60 	return php_password_algo_identify_ex(hash, php_password_algo_default());
61 }
62 
63 
64 #endif
65