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 #include <sodium.h> 30 31 #define SODIUM_LIBRARY_VERSION() (char *) (void *) sodium_version_string() 32 33 #define SODIUM_CRYPTO_BOX_KEYPAIRBYTES() crypto_box_SECRETKEYBYTES + crypto_box_PUBLICKEYBYTES 34 35 #define SODIUM_CRYPTO_KX_KEYPAIRBYTES() crypto_kx_SECRETKEYBYTES + crypto_kx_PUBLICKEYBYTES 36 37 #define SODIUM_CRYPTO_SIGN_KEYPAIRBYTES() crypto_sign_SECRETKEYBYTES + crypto_sign_PUBLICKEYBYTES 38 39 #if SODIUM_LIBRARY_VERSION_MAJOR > 9 || (SODIUM_LIBRARY_VERSION_MAJOR == 9 && SODIUM_LIBRARY_VERSION_MINOR >= 6) 40 41 /** 42 * MEMLIMIT is normalized to KB even though sodium uses Bytes in order to 43 * present a consistent user-facing API. 44 * 45 * Threads are fixed at 1 by libsodium. 46 * 47 * When updating these values, synchronize ext/standard/php_password.h values. 48 */ 49 #if defined(PHP_PASSWORD_ARGON2_MEMORY_COST) 50 #define PHP_SODIUM_PWHASH_MEMLIMIT PHP_PASSWORD_ARGON2_MEMORY_COST 51 #else 52 #define PHP_SODIUM_PWHASH_MEMLIMIT (64 << 10) 53 #endif 54 #if defined(PHP_PASSWORD_ARGON2_TIME_COST) 55 #define PHP_SODIUM_PWHASH_OPSLIMIT PHP_PASSWORD_ARGON2_TIME_COST 56 #else 57 #define PHP_SODIUM_PWHASH_OPSLIMIT 4 58 #endif 59 #if defined(PHP_SODIUM_PWHASH_THREADS) 60 #define PHP_SODIUM_PWHASH_THREADS PHP_SODIUM_PWHASH_THREADS 61 #else 62 #define PHP_SODIUM_PWHASH_THREADS 1 63 #endif 64 65 #endif 66 67 PHP_MINIT_FUNCTION(sodium); 68 PHP_MINIT_FUNCTION(sodium_password_hash); 69 PHP_MSHUTDOWN_FUNCTION(sodium); 70 PHP_RINIT_FUNCTION(sodium); 71 PHP_RSHUTDOWN_FUNCTION(sodium); 72 PHP_MINFO_FUNCTION(sodium); 73 74 #endif /* PHP_LIBSODIUM_H */ 75