xref: /php-src/ext/sodium/php_libsodium.h (revision 20c49f85)
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: Frank Denis <jedisct1@php.net>                              |
14    +----------------------------------------------------------------------+
15 */
16 
17 #ifndef PHP_LIBSODIUM_H
18 #define PHP_LIBSODIUM_H
19 
20 extern zend_module_entry sodium_module_entry;
21 #define phpext_sodium_ptr &sodium_module_entry
22 
23 #define PHP_SODIUM_VERSION PHP_VERSION
24 
25 #ifdef ZTS
26 # include "TSRM.h"
27 #endif
28 
29 #define SODIUM_LIBRARY_VERSION() (char *) (void *) sodium_version_string()
30 
31 #define SODIUM_CRYPTO_BOX_KEYPAIRBYTES() crypto_box_SECRETKEYBYTES + crypto_box_PUBLICKEYBYTES
32 
33 #define SODIUM_CRYPTO_KX_KEYPAIRBYTES() crypto_kx_SECRETKEYBYTES + crypto_kx_PUBLICKEYBYTES
34 
35 #define SODIUM_CRYPTO_SIGN_KEYPAIRBYTES() crypto_sign_SECRETKEYBYTES + crypto_sign_PUBLICKEYBYTES
36 
37 #if SODIUM_LIBRARY_VERSION_MAJOR > 9 || (SODIUM_LIBRARY_VERSION_MAJOR == 9 && SODIUM_LIBRARY_VERSION_MINOR >= 6)
38 
39 /**
40  * MEMLIMIT is normalized to KB even though sodium uses Bytes in order to
41  * present a consistent user-facing API.
42  *
43  * Threads are fixed at 1 by libsodium.
44  *
45  * When updating these values, synchronize ext/standard/php_password.h values.
46  */
47 #if defined(PHP_PASSWORD_ARGON2_MEMORY_COST)
48 #define PHP_SODIUM_PWHASH_MEMLIMIT PHP_PASSWORD_ARGON2_MEMORY_COST
49 #else
50 #define PHP_SODIUM_PWHASH_MEMLIMIT (64 << 10)
51 #endif
52 #if defined(PHP_PASSWORD_ARGON2_TIME_COST)
53 #define PHP_SODIUM_PWHASH_OPSLIMIT PHP_PASSWORD_ARGON2_TIME_COST
54 #else
55 #define PHP_SODIUM_PWHASH_OPSLIMIT 4
56 #endif
57 #if defined(PHP_SODIUM_PWHASH_THREADS)
58 #define PHP_SODIUM_PWHASH_THREADS PHP_SODIUM_PWHASH_THREADS
59 #else
60 #define PHP_SODIUM_PWHASH_THREADS 1
61 #endif
62 
63 #endif
64 
65 PHP_MINIT_FUNCTION(sodium);
66 PHP_MINIT_FUNCTION(sodium_password_hash);
67 PHP_MSHUTDOWN_FUNCTION(sodium);
68 PHP_RINIT_FUNCTION(sodium);
69 PHP_RSHUTDOWN_FUNCTION(sodium);
70 PHP_MINFO_FUNCTION(sodium);
71 
72 #endif	/* PHP_LIBSODIUM_H */
73