21#ifdef HAVE_OPENSSL_EXT
23#define phpext_openssl_ptr &openssl_module_entry
26#define PHP_OPENSSL_VERSION PHP_VERSION
28#include <openssl/opensslv.h>
29#ifdef LIBRESSL_VERSION_NUMBER
31#if LIBRESSL_VERSION_NUMBER < 0x20700000L
32#define PHP_OPENSSL_API_VERSION 0x10001
34#define PHP_OPENSSL_API_VERSION 0x10100
38#if OPENSSL_VERSION_NUMBER < 0x30000000L
39#define PHP_OPENSSL_API_VERSION 0x10100
40#elif OPENSSL_VERSION_NUMBER < 0x30200000L
41#define PHP_OPENSSL_API_VERSION 0x30000
43#define PHP_OPENSSL_API_VERSION 0x30200
47#define OPENSSL_RAW_DATA 1
48#define OPENSSL_ZERO_PADDING 2
49#define OPENSSL_DONT_ZERO_PAD_KEY 4
51#define OPENSSL_ERROR_X509_PRIVATE_KEY_VALUES_MISMATCH 0x0B080074
54#define OPENSSL_DEFAULT_RENEG_LIMIT 2
55#define OPENSSL_DEFAULT_RENEG_WINDOW 300
56#define OPENSSL_DEFAULT_STREAM_VERIFY_DEPTH 9
57#define OPENSSL_DEFAULT_STREAM_CIPHERS "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:" \
58 "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:" \
59 "DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:" \
60 "ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:" \
61 "ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:" \
62 "DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:" \
63 "AES256-GCM-SHA384:AES128:AES256:HIGH:!SSLv2:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!RC4:!ADH"
65#include <openssl/err.h>
68# define PHP_OPENSSL_API __declspec(dllexport)
69#elif defined(__GNUC__) && __GNUC__ >= 4
70# define PHP_OPENSSL_API __attribute__((visibility("default")))
72# define PHP_OPENSSL_API
75struct php_openssl_errors {
76 int buffer[ERR_NUM_ERRORS];
82 struct php_openssl_errors *errors;
83 struct php_openssl_errors *errors_mark;
86#define OPENSSL_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(openssl, v)
88#if defined(ZTS) && defined(COMPILE_DL_OPENSSL)
98 const char *file_path,
size_t file_path_len,
char *real_path, uint32_t
arg_num,
99 bool contains_file_protocol,
bool is_from_array,
const char *option_name);
102static inline bool php_openssl_check_path(
103 const char *file_path,
size_t file_path_len,
char *real_path, uint32_t
arg_num)
106 file_path, file_path_len, real_path,
arg_num,
false,
false,
NULL);
110static inline bool php_openssl_check_path_str_ex(
112 bool contains_file_protocol,
bool is_from_array,
const char *option_name)
116 is_from_array, option_name);
120static inline bool php_openssl_check_path_str(
123 return php_openssl_check_path_str_ex(file_path, real_path,
arg_num,
true,
false,
NULL);
130 const char *
data,
size_t data_len,
131 const char *method,
size_t method_len,
132 const char *password,
size_t password_len,
134 const char *iv,
size_t iv_len,
136 const char *aad,
size_t aad_len);
138 const char *
data,
size_t data_len,
139 const char *method,
size_t method_len,
140 const char *password,
size_t password_len,
142 const char *iv,
size_t iv_len,
144 const char *aad,
size_t aad_len);
148typedef struct _php_openssl_certificate_object {
151} php_openssl_certificate_object;
155static inline php_openssl_certificate_object *php_openssl_certificate_from_obj(
zend_object *obj) {
156 return (php_openssl_certificate_object *)((
char *)(obj) -
XtOffsetOf(php_openssl_certificate_object, std));
159#define Z_OPENSSL_CERTIFICATE_P(zv) php_openssl_certificate_from_obj(Z_OBJ_P(zv))
161#if defined(HAVE_OPENSSL_ARGON2)
169#if defined(PHP_PASSWORD_ARGON2_MEMORY_COST)
170#define PHP_OPENSSL_PWHASH_MEMLIMIT PHP_PASSWORD_ARGON2_MEMORY_COST
172#define PHP_OPENSSL_PWHASH_MEMLIMIT (64 << 10)
174#if defined(PHP_PASSWORD_ARGON2_TIME_COST)
175#define PHP_OPENSSL_PWHASH_ITERLIMIT PHP_PASSWORD_ARGON2_TIME_COST
177#define PHP_OPENSSL_PWHASH_ITERLIMIT 4
179#if defined(PHP_PASSWORD_ARGON2_THREADS)
180#define PHP_OPENSSL_PWHASH_THREADS PHP_PASSWORD_ARGON2_THREADS
182#define PHP_OPENSSL_PWHASH_THREADS 1
192#if defined(HAVE_OPENSSL_ARGON2)
197#define PHP_OPENSSL_BIO_MODE_R(flags) (((flags) & PKCS7_BINARY) ? "rb" : "r")
198#define PHP_OPENSSL_BIO_MODE_W(flags) (((flags) & PKCS7_BINARY) ? "wb" : "w")
200#define PHP_OPENSSL_BIO_MODE_R(flags) "r"
201#define PHP_OPENSSL_BIO_MODE_W(flags) "w"
206#define phpext_openssl_ptr NULL
PHP_OPENSSL_API zend_string * php_openssl_encrypt(const char *data, size_t data_len, const char *method, size_t method_len, const char *password, size_t password_len, zend_long options, const char *iv, size_t iv_len, zval *tag, zend_long tag_len, const char *aad, size_t aad_len)
PHP_OPENSSL_API zend_string * php_openssl_random_pseudo_bytes(zend_long buffer_length)
PHP_OPENSSL_API zend_long php_openssl_cipher_key_length(const char *method)
void php_openssl_store_errors(void)
zend_module_entry openssl_module_entry
PHP_OPENSSL_API zend_string * php_openssl_decrypt(const char *data, size_t data_len, const char *method, size_t method_len, const char *password, size_t password_len, zend_long options, const char *iv, size_t iv_len, const char *tag, zend_long tag_len, const char *aad, size_t aad_len)
zend_class_entry * php_openssl_certificate_ce
PHP_OPENSSL_API zend_long php_openssl_cipher_iv_length(const char *method)
bool php_openssl_check_path_ex(const char *file_path, size_t file_path_len, char *real_path, uint32_t arg_num, bool contains_file_protocol, bool is_from_array, const char *option_name)
#define PHP_MSHUTDOWN_FUNCTION
#define PHP_MINIT_FUNCTION
#define PHP_MINFO_FUNCTION
#define PHP_GINIT_FUNCTION
#define PHP_GSHUTDOWN_FUNCTION
PHP_JSON_API size_t int options
php_stream * php_stream_transport_factory_func(const char *proto, size_t protolen, const char *resourcename, size_t resourcenamelen, const char *persistent_id, int options, int flags, struct timeval *timeout, php_stream_context *context STREAMS_DC)
php_stream * php_openssl_ssl_socket_factory(const char *proto, size_t protolen, const char *resourcename, size_t resourcenamelen, const char *persistent_id, int options, int flags, struct timeval *timeout, php_stream_context *context STREAMS_DC)
#define ZEND_TSRMLS_CACHE_EXTERN()
#define ZEND_END_MODULE_GLOBALS(module_name)
#define ZEND_BEGIN_MODULE_GLOBALS(module_name)
struct _zend_string zend_string
struct _zend_module_entry zend_module_entry
#define XtOffsetOf(s_type, field)
struct _zend_class_entry zend_class_entry
struct _zend_object zend_object