com php-src: Add php_openssl_cipher_init: ext/openssl /openssl.c

From: Date: Mon, 26 Oct 2015 19:08:24 +0000
Subject: com php-src: Add php_openssl_cipher_init: ext/openssl /openssl.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-92490@lists.php.net to get a copy of this message
Commit: 496c46942f5f362af077cc58b19309f0e1e6b2e3 Author: Jakub Zelenka <bukka@php.net> Mon, 26 Oct 2015 19:08:24 +0000 Parents: 054b27d3f277e219144c9dc642d1d6c21f649f3a Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=496c46942f5f362af077cc58b19309f0e1e6b2e3 Log: Add php_openssl_cipher_init Changed paths: M ext/openssl/openssl.c Diff: diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c index 16ff7cb..2ea4a10 100644 --- a/ext/openssl/openssl.c +++ b/ext/openssl/openssl.c @@ -5265,6 +5265,26 @@ static zend_bool php_openssl_validate_iv(char **piv, size_t *piv_len, size_t iv_ } /* }}} */ +static int php_openssl_cipher_init(const EVP_CIPHER *cipher_type, EVP_CIPHER_CTX *cipher_ctx, + size_t password_len, size_t keylen, unsigned char *key, char *iv, zend_long options, int enc) /* {{{ */ +{ + if (!EVP_CipherInit_ex(cipher_ctx, cipher_type, NULL, NULL, NULL, enc)) { + return FAILURE; + } + if (password_len > keylen) { + EVP_CIPHER_CTX_set_key_length(cipher_ctx, (int)password_len); + } + if (!EVP_CipherInit_ex(cipher_ctx, NULL, NULL, key, (unsigned char *)iv, enc)) { + return FAILURE; + } + if (options & OPENSSL_ZERO_PADDING) { + EVP_CIPHER_CTX_set_padding(cipher_ctx, 0); + } + + return SUCCESS; +} +/* }}} */ + /* {{{ proto string openssl_encrypt(string data, string method, string password [, long options=0 [, string $iv=''[, string &$tag = ''[, string $aad = ''[, long $tag_length = 16]]]]]) Encrypts given data with given method and key, returns raw or base64 encoded string */ PHP_FUNCTION(openssl_encrypt)

« previous php.cvs (#92490) next »