xref: /php-src/ext/standard/php_password.h (revision 32c5ce34)
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 values in
30  *     ext/sodium/php_libsodium.h
31  *     ext/openssl/php_openssl.h
32  * Note that libargon/openssl express memlimit in KB, while libsodium uses bytes.
33  */
34 #define PHP_PASSWORD_ARGON2_MEMORY_COST (64 << 10)
35 #define PHP_PASSWORD_ARGON2_TIME_COST 4
36 #define PHP_PASSWORD_ARGON2_THREADS 1
37 #endif
38 
39 typedef struct _php_password_algo {
40 	const char *name;
41 	zend_string *(*hash)(const zend_string *password, zend_array *options);
42 	bool (*verify)(const zend_string *password, const zend_string *hash);
43 	bool (*needs_rehash)(const zend_string *password, zend_array *options);
44 	int (*get_info)(zval *return_value, const zend_string *hash);
45 	bool (*valid)(const zend_string *hash);
46 } php_password_algo;
47 
48 extern const php_password_algo php_password_algo_bcrypt;
49 #ifdef HAVE_ARGON2LIB
50 extern const php_password_algo php_password_algo_argon2i;
51 extern const php_password_algo php_password_algo_argon2id;
52 #endif
53 
54 PHPAPI int php_password_algo_register(const char*, const php_password_algo*);
55 PHPAPI void php_password_algo_unregister(const char*);
56 PHPAPI const php_password_algo* php_password_algo_default(void);
57 PHPAPI zend_string *php_password_algo_extract_ident(const zend_string*);
58 PHPAPI const php_password_algo* php_password_algo_find(const zend_string*);
59 
60 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)61 static inline const php_password_algo* php_password_algo_identify(const zend_string *hash) {
62 	return php_password_algo_identify_ex(hash, php_password_algo_default());
63 }
64 
65 
66 #endif
67