├── .gitattributes ├── .github └── workflows │ └── build.yml ├── .gitignore ├── .travis.yml ├── CREDITS ├── LICENSE ├── TODO ├── config.m4 ├── config.w32 ├── mcrypt.c ├── mcrypt_filter.c ├── package.xml ├── php_mcrypt.h ├── php_mcrypt_filter.h └── tests ├── blowfish.phpt ├── bug35496.phpt ├── bug37595.phpt ├── bug41252.phpt ├── bug43143.phpt ├── bug46010.phpt ├── bug49738.phpt ├── bug55169.phpt ├── bug70625.phpt ├── bug8040.phpt ├── mcrypt_cbc.phpt ├── mcrypt_cbc_3des_decrypt.phpt ├── mcrypt_cbc_3des_encrypt.phpt ├── mcrypt_cfb.phpt ├── mcrypt_create_iv.phpt ├── mcrypt_decrypt.phpt ├── mcrypt_decrypt_3des_cbc.phpt ├── mcrypt_decrypt_3des_ecb.phpt ├── mcrypt_ecb.phpt ├── mcrypt_ecb_3des_decrypt.phpt ├── mcrypt_ecb_3des_encrypt.phpt ├── mcrypt_enc_get_algorithms_name.phpt ├── mcrypt_enc_get_block_size.phpt ├── mcrypt_enc_get_iv_size.phpt ├── mcrypt_enc_get_key_size.phpt ├── mcrypt_enc_get_mode_name.phpt ├── mcrypt_enc_get_supported_key_sizes.phpt ├── mcrypt_enc_is_block_algorithm.phpt ├── mcrypt_enc_is_block_algorithm_mode.phpt ├── mcrypt_enc_is_block_mode.phpt ├── mcrypt_enc_self_test.phpt ├── mcrypt_encrypt_3des_cbc.phpt ├── mcrypt_encrypt_3des_ecb.phpt ├── mcrypt_filters.phpt ├── mcrypt_get_block_size.phpt ├── mcrypt_get_cipher_name.phpt ├── mcrypt_get_iv_size.phpt ├── mcrypt_get_key_size.phpt ├── mcrypt_list_algorithms.phpt ├── mcrypt_list_modes.phpt ├── mcrypt_module_get_algo_block_size.phpt ├── mcrypt_module_get_algo_key_size.phpt ├── mcrypt_module_get_supported_key_sizes.phpt ├── mcrypt_module_is_block_algorithm.phpt ├── mcrypt_module_is_block_algorithm_mode.phpt ├── mcrypt_module_is_block_mode.phpt ├── mcrypt_module_open.phpt ├── mcrypt_module_self_test.phpt ├── mcrypt_ofb.phpt ├── mcrypt_rijndael128_128BitKey.phpt ├── mcrypt_rijndael128_256BitKey.phpt └── vectors.txt /.gitattributes: -------------------------------------------------------------------------------- 1 | # Treat binary PHP test files as text when displaying diffs 2 | *.phpt diff 3 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | branches: [master] 6 | pull_request: 7 | release: 8 | types: [created] 9 | create: 10 | 11 | jobs: 12 | windows: 13 | runs-on: windows-latest 14 | name: "Windows: Build and test" 15 | defaults: 16 | run: 17 | shell: cmd 18 | strategy: 19 | fail-fast: false 20 | matrix: 21 | php: ["7.3", "7.4", "8.0", "8.1", "8.2"] 22 | arch: [x86, x64] 23 | ts: [nts, ts] 24 | experimental: [false] 25 | steps: 26 | - name: Checkout Repository 27 | uses: actions/checkout@v3 28 | - name: Extract Version 29 | shell: powershell 30 | run: | 31 | chcp 65001 32 | $r = Select-String -Path php_mcrypt.h -Pattern 'PHP_MCRYPT_VERSION\s+"(.*)"' 33 | $s = $r.Matches[0].Groups[1] 34 | echo "$s" 35 | $extension_version = 'EXTENSION_VERSION=' + $s 36 | echo $extension_version >> $env:GITHUB_ENV 37 | - name: Setup PHP 38 | id: setup-php 39 | uses: cmb69/setup-php-sdk@v0.7 40 | with: 41 | version: ${{matrix.php}} 42 | arch: ${{matrix.arch}} 43 | ts: ${{matrix.ts}} 44 | deps: "libmcrypt" 45 | - name: Enable Developer Command Prompt 46 | uses: ilammy/msvc-dev-cmd@v1 47 | with: 48 | arch: ${{matrix.arch}} 49 | toolset: ${{steps.setup-php.outputs.toolset}} 50 | - name: Generate Build Files 51 | run: phpize 52 | - name: Configure Build 53 | run: configure --with-mcrypt --with-prefix=${{steps.setup-php.outputs.prefix}} 54 | - name: Build 55 | run: nmake 56 | - name: Define Module Env 57 | shell: powershell 58 | run: | 59 | chcp 65001 60 | 61 | $dir = (Get-Location).Path + '\' 62 | if ('x64' -eq '${{matrix.arch}}') { $dir = $dir + 'x64\' } 63 | $dir = $dir + 'Release' 64 | if ('ts' -eq '${{matrix.ts}}') { $dir = $dir + '_TS' } 65 | 66 | $artifact_name = 'php_mcrypt-${{env.EXTENSION_VERSION}}-${{matrix.php}}' 67 | 68 | if ('7.2' -eq '${{matrix.php}}') { $artifact_name = $artifact_name + '-vc15' } 69 | if ('7.3' -eq '${{matrix.php}}') { $artifact_name = $artifact_name + '-vc15' } 70 | if ('7.4' -eq '${{matrix.php}}') { $artifact_name = $artifact_name + '-vc15' } 71 | if ('8.0' -eq '${{matrix.php}}') { $artifact_name = $artifact_name + '-vs16' } 72 | if ('8.1' -eq '${{matrix.php}}') { $artifact_name = $artifact_name + '-vs16' } 73 | if ('8.2' -eq '${{matrix.php}}') { $artifact_name = $artifact_name + '-vs16' } 74 | 75 | if ('nts' -eq '${{matrix.ts}}') { $artifact_name = $artifact_name + '-nts' } 76 | if ('x64' -eq '${{matrix.arch}}') { $artifact_name = $artifact_name + '-x86_64' } 77 | 78 | $extension_artifact_name = "ARTIFACT_NAME=" + $artifact_name 79 | echo $extension_artifact_name >> $env:GITHUB_ENV 80 | 81 | $from = $dir + '\php_mcrypt.dll' 82 | $to = $dir + '\' + $artifact_name + ".dll" 83 | Copy-Item $from -Destination $to 84 | $extension_artifact = "ARTIFACT=" + $to 85 | echo $extension_artifact >> $env:GITHUB_ENV 86 | 87 | - name: Upload artifacts 88 | uses: actions/upload-artifact@v3 89 | with: 90 | name: ${{env.ARTIFACT_NAME}} 91 | path: ${{env.ARTIFACT}} 92 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .deps 2 | .libs 3 | Makefile 4 | Makefile.fragments 5 | Makefile.global 6 | Makefile.objects 7 | acinclude.m4 8 | aclocal.m4 9 | autom4te.cache 10 | build 11 | config.guess 12 | config.h 13 | config.h.in 14 | config.log 15 | config.nice 16 | config.status 17 | config.sub 18 | configure 19 | configure.in 20 | configure.ac 21 | install-sh 22 | libtool 23 | ltmain.sh 24 | missing 25 | mkinstalldirs 26 | modules 27 | run-tests.php 28 | 29 | *.la 30 | *.lo 31 | *.o 32 | 33 | *.swp 34 | .*.rej 35 | *.rej 36 | .*~ 37 | *~ 38 | .#* 39 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | dist: bionic 3 | php: 4 | - 7.2 5 | - 7.3 6 | - 7.4 7 | - nightly 8 | sudo: false 9 | matrix: 10 | fast_finish: true 11 | env: 12 | - REPORT_EXIT_STATUS=1 NO_INTERACTION=1 13 | addons: 14 | apt: 15 | packages: 16 | - libmcrypt-dev 17 | update: true 18 | install: 19 | - phpize 20 | - ./configure 21 | - make 22 | script: TEST_PHP_EXECUTABLE=$(which php) php -n 23 | -d open_basedir= -d output_buffering=0 -d memory_limit=-1 24 | run-tests.php -n 25 | -d extension_dir=modules -d extension=mcrypt.so --show-diff 26 | tests 27 | -------------------------------------------------------------------------------- /CREDITS: -------------------------------------------------------------------------------- 1 | mcrypt 2 | Sascha Schumann, Derick Rethans 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------- 2 | The PHP License, version 3.01 3 | Copyright (c) 1999 - 2016 The PHP Group. All rights reserved. 4 | -------------------------------------------------------------------- 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, is permitted provided that the following conditions 8 | are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in 15 | the documentation and/or other materials provided with the 16 | distribution. 17 | 18 | 3. The name "PHP" must not be used to endorse or promote products 19 | derived from this software without prior written permission. For 20 | written permission, please contact group@php.net. 21 | 22 | 4. Products derived from this software may not be called "PHP", nor 23 | may "PHP" appear in their name, without prior written permission 24 | from group@php.net. You may indicate that your software works in 25 | conjunction with PHP by saying "Foo for PHP" instead of calling 26 | it "PHP Foo" or "phpfoo" 27 | 28 | 5. The PHP Group may publish revised and/or new versions of the 29 | license from time to time. Each version will be given a 30 | distinguishing version number. 31 | Once covered code has been published under a particular version 32 | of the license, you may always continue to use it under the terms 33 | of that version. You may also choose to use such covered code 34 | under the terms of any subsequent version of the license 35 | published by the PHP Group. No one other than the PHP Group has 36 | the right to modify the terms applicable to covered code created 37 | under this License. 38 | 39 | 6. Redistributions of any form whatsoever must retain the following 40 | acknowledgment: 41 | "This product includes PHP software, freely available from 42 | ". 43 | 44 | THIS SOFTWARE IS PROVIDED BY THE PHP DEVELOPMENT TEAM ``AS IS'' AND 45 | ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 46 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 47 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PHP 48 | DEVELOPMENT TEAM OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 49 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 50 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 51 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 52 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 53 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 54 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 55 | OF THE POSSIBILITY OF SUCH DAMAGE. 56 | 57 | -------------------------------------------------------------------- 58 | 59 | This software consists of voluntary contributions made by many 60 | individuals on behalf of the PHP Group. 61 | 62 | The PHP Group can be contacted via Email at group@php.net. 63 | 64 | For more information on the PHP Group and the PHP project, 65 | please see . 66 | 67 | PHP includes the Zend Engine, freely available at 68 | . 69 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | ToDo: 2 | - Convert to zend_parse_parameters 3 | - Unify error handling 4 | - Implement encryption streams 5 | -------------------------------------------------------------------------------- /config.m4: -------------------------------------------------------------------------------- 1 | AC_DEFUN([PHP_MCRYPT_CHECK_VERSION],[ 2 | old_CPPFLAGS=$CPPFLAGS 3 | CPPFLAGS=-I$MCRYPT_DIR/include 4 | AC_MSG_CHECKING(for libmcrypt version) 5 | AC_EGREP_CPP(yes,[ 6 | #include 7 | #if MCRYPT_API_VERSION >= 20021217 8 | yes 9 | #endif 10 | ],[ 11 | AC_MSG_RESULT(>= 2.5.6) 12 | ],[ 13 | AC_MSG_ERROR(libmcrypt version 2.5.6 or greater required.) 14 | ]) 15 | CPPFLAGS=$old_CPPFLAGS 16 | ]) 17 | 18 | 19 | PHP_ARG_WITH(mcrypt, for mcrypt support, 20 | [ --with-mcrypt[=DIR] Include mcrypt support]) 21 | 22 | if test "$PHP_MCRYPT" != "no"; then 23 | for i in $PHP_MCRYPT /usr/local /usr; do 24 | test -f $i/include/mcrypt.h && MCRYPT_DIR=$i && break 25 | done 26 | 27 | if test -z "$MCRYPT_DIR"; then 28 | AC_MSG_ERROR(mcrypt.h not found. Please reinstall libmcrypt.) 29 | fi 30 | 31 | PHP_MCRYPT_CHECK_VERSION 32 | 33 | PHP_CHECK_LIBRARY(mcrypt, mcrypt_module_open, 34 | [ 35 | PHP_ADD_LIBRARY(ltdl,, MCRYPT_SHARED_LIBADD) 36 | AC_DEFINE(HAVE_LIBMCRYPT,1,[ ]) 37 | ],[ 38 | PHP_CHECK_LIBRARY(mcrypt, mcrypt_module_open, 39 | [ 40 | AC_DEFINE(HAVE_LIBMCRYPT,1,[ ]) 41 | ],[ 42 | AC_MSG_ERROR([Sorry, I was not able to diagnose which libmcrypt version you have installed.]) 43 | ],[ 44 | -L$MCRYPT_DIR/$PHP_LIBDIR 45 | ]) 46 | ],[ 47 | -L$MCRYPT_DIR/$PHP_LIBDIR -lltdl 48 | ]) 49 | 50 | PHP_ADD_LIBRARY_WITH_PATH(mcrypt, $MCRYPT_DIR/$PHP_LIBDIR, MCRYPT_SHARED_LIBADD) 51 | PHP_ADD_INCLUDE($MCRYPT_DIR/include) 52 | 53 | PHP_SUBST(MCRYPT_SHARED_LIBADD) 54 | PHP_NEW_EXTENSION(mcrypt, mcrypt.c mcrypt_filter.c, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1) 55 | fi 56 | -------------------------------------------------------------------------------- /config.w32: -------------------------------------------------------------------------------- 1 | // vim:ft=javascript 2 | 3 | ARG_WITH("mcrypt", "mcrypt support", "no"); 4 | 5 | if (PHP_MCRYPT != "no") { 6 | 7 | if (CHECK_HEADER_ADD_INCLUDE('mcrypt.h', 'CFLAGS_MCRYPT') && 8 | CHECK_HEADER_ADD_INCLUDE('dirent.h', 'CFLAGS_MCRYPT') && 9 | CHECK_LIB('libmcrypt_a.lib;libmcrypt.lib', 'mcrypt') && 10 | CHECK_LIB('dirent_a.lib', 'mcrypt') && 11 | CHECK_LIB('Advapi32.lib', 'mcrypt') 12 | ) { 13 | 14 | EXTENSION('mcrypt', 'mcrypt.c mcrypt_filter.c', PHP_MCRYPT_SHARED, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1"); 15 | AC_DEFINE('HAVE_LIBMCRYPT', 1); 16 | AC_DEFINE('HAVE_LIBMCRYPT24', 1); 17 | } else { 18 | WARNING("mcrypt not enabled; libraries and headers not found"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /mcrypt.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 7 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2016 The PHP Group | 6 | +----------------------------------------------------------------------+ 7 | | This source file is subject to version 3.01 of the PHP license, | 8 | | that is bundled with this package in the file LICENSE, and is | 9 | | available through the world-wide-web at the following url: | 10 | | http://www.php.net/license/3_01.txt | 11 | | If you did not receive a copy of the PHP license and are unable to | 12 | | obtain it through the world-wide-web, please send a note to | 13 | | license@php.net so we can mail you a copy immediately. | 14 | +----------------------------------------------------------------------+ 15 | | Authors: Sascha Schumann | 16 | | Derick Rethans | 17 | +----------------------------------------------------------------------+ 18 | */ 19 | 20 | #ifdef HAVE_CONFIG_H 21 | #include "config.h" 22 | #endif 23 | 24 | #include "php.h" 25 | 26 | #if HAVE_LIBMCRYPT 27 | 28 | #if PHP_WIN32 29 | # include "win32/winutil.h" 30 | #endif 31 | 32 | #include "php_mcrypt.h" 33 | #include "fcntl.h" 34 | 35 | #define NON_FREE 36 | #define MCRYPT2 37 | #include "mcrypt.h" 38 | #include "php_ini.h" 39 | #include "php_globals.h" 40 | #include "ext/standard/info.h" 41 | #include "ext/standard/php_rand.h" 42 | #include "zend_smart_str.h" 43 | #include "php_mcrypt_filter.h" 44 | 45 | static int le_mcrypt; 46 | 47 | typedef struct _php_mcrypt { 48 | MCRYPT td; 49 | zend_bool init; 50 | } php_mcrypt; 51 | 52 | /* {{{ arginfo */ 53 | ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_module_open, 0, 0, 4) 54 | ZEND_ARG_INFO(0, cipher) 55 | ZEND_ARG_INFO(0, cipher_directory) 56 | ZEND_ARG_INFO(0, mode) 57 | ZEND_ARG_INFO(0, mode_directory) 58 | ZEND_END_ARG_INFO() 59 | 60 | ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_generic_init, 0, 0, 3) 61 | ZEND_ARG_INFO(0, td) 62 | ZEND_ARG_INFO(0, key) 63 | ZEND_ARG_INFO(0, iv) 64 | ZEND_END_ARG_INFO() 65 | 66 | ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_generic, 0, 0, 2) 67 | ZEND_ARG_INFO(0, td) 68 | ZEND_ARG_INFO(0, data) 69 | ZEND_END_ARG_INFO() 70 | 71 | ZEND_BEGIN_ARG_INFO_EX(arginfo_mdecrypt_generic, 0, 0, 2) 72 | ZEND_ARG_INFO(0, td) 73 | ZEND_ARG_INFO(0, data) 74 | ZEND_END_ARG_INFO() 75 | 76 | ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_enc_get_supported_key_sizes, 0, 0, 1) 77 | ZEND_ARG_INFO(0, td) 78 | ZEND_END_ARG_INFO() 79 | 80 | ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_enc_self_test, 0, 0, 1) 81 | ZEND_ARG_INFO(0, td) 82 | ZEND_END_ARG_INFO() 83 | 84 | ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_module_close, 0, 0, 1) 85 | ZEND_ARG_INFO(0, td) 86 | ZEND_END_ARG_INFO() 87 | 88 | ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_generic_deinit, 0, 0, 1) 89 | ZEND_ARG_INFO(0, td) 90 | ZEND_END_ARG_INFO() 91 | 92 | ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_enc_is_block_algorithm_mode, 0, 0, 1) 93 | ZEND_ARG_INFO(0, td) 94 | ZEND_END_ARG_INFO() 95 | 96 | ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_enc_is_block_algorithm, 0, 0, 1) 97 | ZEND_ARG_INFO(0, td) 98 | ZEND_END_ARG_INFO() 99 | 100 | ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_enc_is_block_mode, 0, 0, 1) 101 | ZEND_ARG_INFO(0, td) 102 | ZEND_END_ARG_INFO() 103 | 104 | ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_enc_get_block_size, 0, 0, 1) 105 | ZEND_ARG_INFO(0, td) 106 | ZEND_END_ARG_INFO() 107 | 108 | ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_enc_get_key_size, 0, 0, 1) 109 | ZEND_ARG_INFO(0, td) 110 | ZEND_END_ARG_INFO() 111 | 112 | ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_enc_get_iv_size, 0, 0, 1) 113 | ZEND_ARG_INFO(0, td) 114 | ZEND_END_ARG_INFO() 115 | 116 | ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_enc_get_algorithms_name, 0, 0, 1) 117 | ZEND_ARG_INFO(0, td) 118 | ZEND_END_ARG_INFO() 119 | 120 | ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_enc_get_modes_name, 0, 0, 1) 121 | ZEND_ARG_INFO(0, td) 122 | ZEND_END_ARG_INFO() 123 | 124 | ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_module_self_test, 0, 0, 1) 125 | ZEND_ARG_INFO(0, algorithm) 126 | ZEND_ARG_INFO(0, lib_dir) 127 | ZEND_END_ARG_INFO() 128 | 129 | ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_module_is_block_algorithm_mode, 0, 0, 1) 130 | ZEND_ARG_INFO(0, mode) 131 | ZEND_ARG_INFO(0, lib_dir) 132 | ZEND_END_ARG_INFO() 133 | 134 | ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_module_is_block_algorithm, 0, 0, 1) 135 | ZEND_ARG_INFO(0, algorithm) 136 | ZEND_ARG_INFO(0, lib_dir) 137 | ZEND_END_ARG_INFO() 138 | 139 | ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_module_is_block_mode, 0, 0, 1) 140 | ZEND_ARG_INFO(0, mode) 141 | ZEND_ARG_INFO(0, lib_dir) 142 | ZEND_END_ARG_INFO() 143 | 144 | ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_module_get_algo_block_size, 0, 0, 1) 145 | ZEND_ARG_INFO(0, algorithm) 146 | ZEND_ARG_INFO(0, lib_dir) 147 | ZEND_END_ARG_INFO() 148 | 149 | ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_module_get_algo_key_size, 0, 0, 1) 150 | ZEND_ARG_INFO(0, algorithm) 151 | ZEND_ARG_INFO(0, lib_dir) 152 | ZEND_END_ARG_INFO() 153 | 154 | ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_module_get_supported_key_sizes, 0, 0, 1) 155 | ZEND_ARG_INFO(0, algorithm) 156 | ZEND_ARG_INFO(0, lib_dir) 157 | ZEND_END_ARG_INFO() 158 | 159 | ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_list_algorithms, 0, 0, 0) 160 | ZEND_ARG_INFO(0, lib_dir) 161 | ZEND_END_ARG_INFO() 162 | 163 | ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_list_modes, 0, 0, 0) 164 | ZEND_ARG_INFO(0, lib_dir) 165 | ZEND_END_ARG_INFO() 166 | 167 | ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_get_key_size, 0, 0, 2) 168 | ZEND_ARG_INFO(0, cipher) 169 | ZEND_ARG_INFO(0, module) 170 | ZEND_END_ARG_INFO() 171 | 172 | ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_get_block_size, 0, 0, 2) 173 | ZEND_ARG_INFO(0, cipher) 174 | ZEND_ARG_INFO(0, module) 175 | ZEND_END_ARG_INFO() 176 | 177 | ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_get_iv_size, 0, 0, 2) 178 | ZEND_ARG_INFO(0, cipher) 179 | ZEND_ARG_INFO(0, module) 180 | ZEND_END_ARG_INFO() 181 | 182 | ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_get_cipher_name, 0, 0, 1) 183 | ZEND_ARG_INFO(0, cipher) 184 | ZEND_END_ARG_INFO() 185 | 186 | ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_encrypt, 0, 0, 4) 187 | ZEND_ARG_INFO(0, cipher) 188 | ZEND_ARG_INFO(0, key) 189 | ZEND_ARG_INFO(0, data) 190 | ZEND_ARG_INFO(0, mode) 191 | ZEND_ARG_INFO(0, iv) 192 | ZEND_END_ARG_INFO() 193 | 194 | ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_decrypt, 0, 0, 4) 195 | ZEND_ARG_INFO(0, cipher) 196 | ZEND_ARG_INFO(0, key) 197 | ZEND_ARG_INFO(0, data) 198 | ZEND_ARG_INFO(0, mode) 199 | ZEND_ARG_INFO(0, iv) 200 | ZEND_END_ARG_INFO() 201 | 202 | ZEND_BEGIN_ARG_INFO_EX(arginfo_mcrypt_create_iv, 0, 0, 1) 203 | ZEND_ARG_INFO(0, size) 204 | ZEND_ARG_INFO(0, source) 205 | ZEND_END_ARG_INFO() 206 | /* }}} */ 207 | 208 | const zend_function_entry mcrypt_functions[] = { /* {{{ */ 209 | PHP_DEP_FE(mcrypt_get_key_size, arginfo_mcrypt_get_key_size) 210 | PHP_DEP_FE(mcrypt_get_block_size, arginfo_mcrypt_get_block_size) 211 | PHP_DEP_FE(mcrypt_get_cipher_name, arginfo_mcrypt_get_cipher_name) 212 | PHP_DEP_FE(mcrypt_create_iv, arginfo_mcrypt_create_iv) 213 | 214 | PHP_DEP_FE(mcrypt_list_algorithms, arginfo_mcrypt_list_algorithms) 215 | PHP_DEP_FE(mcrypt_list_modes, arginfo_mcrypt_list_modes) 216 | PHP_DEP_FE(mcrypt_get_iv_size, arginfo_mcrypt_get_iv_size) 217 | PHP_DEP_FE(mcrypt_encrypt, arginfo_mcrypt_encrypt) 218 | PHP_DEP_FE(mcrypt_decrypt, arginfo_mcrypt_decrypt) 219 | 220 | PHP_DEP_FE(mcrypt_module_open, arginfo_mcrypt_module_open) 221 | PHP_DEP_FE(mcrypt_generic_init, arginfo_mcrypt_generic_init) 222 | PHP_DEP_FE(mcrypt_generic, arginfo_mcrypt_generic) 223 | PHP_DEP_FE(mdecrypt_generic, arginfo_mdecrypt_generic) 224 | PHP_DEP_FE(mcrypt_generic_deinit, arginfo_mcrypt_generic_deinit) 225 | 226 | PHP_DEP_FE(mcrypt_enc_self_test, arginfo_mcrypt_enc_self_test) 227 | PHP_DEP_FE(mcrypt_enc_is_block_algorithm_mode, arginfo_mcrypt_enc_is_block_algorithm_mode) 228 | PHP_DEP_FE(mcrypt_enc_is_block_algorithm, arginfo_mcrypt_enc_is_block_algorithm) 229 | PHP_DEP_FE(mcrypt_enc_is_block_mode, arginfo_mcrypt_enc_is_block_mode) 230 | PHP_DEP_FE(mcrypt_enc_get_block_size, arginfo_mcrypt_enc_get_block_size) 231 | PHP_DEP_FE(mcrypt_enc_get_key_size, arginfo_mcrypt_enc_get_key_size) 232 | PHP_DEP_FE(mcrypt_enc_get_supported_key_sizes, arginfo_mcrypt_enc_get_supported_key_sizes) 233 | PHP_DEP_FE(mcrypt_enc_get_iv_size, arginfo_mcrypt_enc_get_iv_size) 234 | PHP_DEP_FE(mcrypt_enc_get_algorithms_name, arginfo_mcrypt_enc_get_algorithms_name) 235 | PHP_DEP_FE(mcrypt_enc_get_modes_name, arginfo_mcrypt_enc_get_modes_name) 236 | PHP_DEP_FE(mcrypt_module_self_test, arginfo_mcrypt_module_self_test) 237 | 238 | PHP_DEP_FE(mcrypt_module_is_block_algorithm_mode, arginfo_mcrypt_module_is_block_algorithm_mode) 239 | PHP_DEP_FE(mcrypt_module_is_block_algorithm, arginfo_mcrypt_module_is_block_algorithm) 240 | PHP_DEP_FE(mcrypt_module_is_block_mode, arginfo_mcrypt_module_is_block_mode) 241 | PHP_DEP_FE(mcrypt_module_get_algo_block_size, arginfo_mcrypt_module_get_algo_block_size) 242 | PHP_DEP_FE(mcrypt_module_get_algo_key_size, arginfo_mcrypt_module_get_algo_key_size) 243 | PHP_DEP_FE(mcrypt_module_get_supported_key_sizes, arginfo_mcrypt_module_get_supported_key_sizes) 244 | 245 | PHP_DEP_FE(mcrypt_module_close, arginfo_mcrypt_module_close) 246 | PHP_FE_END 247 | }; 248 | /* }}} */ 249 | 250 | static PHP_MINFO_FUNCTION(mcrypt); 251 | static PHP_MINIT_FUNCTION(mcrypt); 252 | static PHP_MSHUTDOWN_FUNCTION(mcrypt); 253 | static PHP_GINIT_FUNCTION(mcrypt); 254 | static PHP_GSHUTDOWN_FUNCTION(mcrypt); 255 | 256 | ZEND_DECLARE_MODULE_GLOBALS(mcrypt) 257 | 258 | zend_module_entry mcrypt_module_entry = { 259 | STANDARD_MODULE_HEADER, 260 | "mcrypt", 261 | mcrypt_functions, 262 | PHP_MINIT(mcrypt), PHP_MSHUTDOWN(mcrypt), 263 | NULL, NULL, 264 | PHP_MINFO(mcrypt), 265 | PHP_MCRYPT_VERSION, 266 | PHP_MODULE_GLOBALS(mcrypt), 267 | PHP_GINIT(mcrypt), 268 | PHP_GSHUTDOWN(mcrypt), 269 | NULL, 270 | STANDARD_MODULE_PROPERTIES_EX 271 | }; 272 | 273 | #ifdef COMPILE_DL_MCRYPT 274 | #ifdef ZTS 275 | ZEND_TSRMLS_CACHE_DEFINE() 276 | #endif 277 | ZEND_GET_MODULE(mcrypt) 278 | #endif 279 | 280 | #define MCRYPT_ENCRYPT 0 281 | #define MCRYPT_DECRYPT 1 282 | 283 | typedef enum { 284 | RANDOM = 0, 285 | URANDOM, 286 | RAND 287 | } iv_source; 288 | 289 | #define MCRYPT_GET_INI \ 290 | cipher_dir_string = MCG(algorithms_dir); \ 291 | module_dir_string = MCG(modes_dir); 292 | 293 | /* 294 | * #warning is not ANSI C 295 | * #warning Invalidate resource if the param count is wrong, or other problems 296 | * #warning occurred during functions. 297 | */ 298 | 299 | #define MCRYPT_GET_CRYPT_ARGS \ 300 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "sssz|s", \ 301 | &cipher, &cipher_len, &key, &key_len, &data, &data_len, &mode, &iv, &iv_len) == FAILURE) { \ 302 | return; \ 303 | } 304 | 305 | #define MCRYPT_GET_TD_ARG \ 306 | zval *mcryptind; \ 307 | php_mcrypt *pm; \ 308 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &mcryptind) == FAILURE) { \ 309 | return; \ 310 | } \ 311 | if ((pm = (php_mcrypt *)zend_fetch_resource(Z_RES_P(mcryptind), "MCrypt", le_mcrypt)) == NULL) { \ 312 | RETURN_FALSE; \ 313 | } 314 | 315 | #define MCRYPT_GET_MODE_DIR_ARGS(DIRECTORY) \ 316 | char *dir = NULL; \ 317 | size_t dir_len; \ 318 | char *module; \ 319 | size_t module_len; \ 320 | if (zend_parse_parameters (ZEND_NUM_ARGS(), \ 321 | "s|s", &module, &module_len, &dir, &dir_len) == FAILURE) { \ 322 | return; \ 323 | } 324 | 325 | #define MCRYPT_OPEN_MODULE_FAILED "Module initialization failed" 326 | 327 | #define MCRYPT_ENTRY2_2_4(a,b) REGISTER_STRING_CONSTANT("MCRYPT_" #a, b, CONST_PERSISTENT) 328 | #define MCRYPT_ENTRY2_4(a) MCRYPT_ENTRY_NAMED(a, a) 329 | 330 | #define PHP_MCRYPT_INIT_CHECK \ 331 | if (!pm->init) { \ 332 | php_error_docref(NULL, E_WARNING, "Operation disallowed prior to mcrypt_generic_init()."); \ 333 | RETURN_FALSE; \ 334 | } \ 335 | 336 | PHP_INI_BEGIN() 337 | STD_PHP_INI_ENTRY("mcrypt.algorithms_dir", NULL, PHP_INI_ALL, OnUpdateString, algorithms_dir, zend_mcrypt_globals, mcrypt_globals) 338 | STD_PHP_INI_ENTRY("mcrypt.modes_dir", NULL, PHP_INI_ALL, OnUpdateString, modes_dir, zend_mcrypt_globals, mcrypt_globals) 339 | PHP_INI_END() 340 | 341 | static void php_mcrypt_module_dtor(zend_resource *rsrc) /* {{{ */ 342 | { 343 | php_mcrypt *pm = (php_mcrypt *) rsrc->ptr; 344 | if (pm) { 345 | mcrypt_generic_deinit(pm->td); 346 | mcrypt_module_close(pm->td); 347 | efree(pm); 348 | pm = NULL; 349 | } 350 | } 351 | /* }}} */ 352 | 353 | static PHP_GINIT_FUNCTION(mcrypt) 354 | {/*{{{*/ 355 | #if defined(COMPILE_DL_MCRYPT) && defined(ZTS) 356 | ZEND_TSRMLS_CACHE_UPDATE(); 357 | #endif 358 | mcrypt_globals->fd[RANDOM] = -1; 359 | mcrypt_globals->fd[URANDOM] = -1; 360 | }/*}}}*/ 361 | 362 | static PHP_GSHUTDOWN_FUNCTION(mcrypt) 363 | {/*{{{*/ 364 | if (mcrypt_globals->fd[RANDOM] > 0) { 365 | close(mcrypt_globals->fd[RANDOM]); 366 | mcrypt_globals->fd[RANDOM] = -1; 367 | } 368 | 369 | if (mcrypt_globals->fd[URANDOM] > 0) { 370 | close(mcrypt_globals->fd[URANDOM]); 371 | mcrypt_globals->fd[URANDOM] = -1; 372 | } 373 | }/*}}}*/ 374 | 375 | static PHP_MINIT_FUNCTION(mcrypt) /* {{{ */ 376 | { 377 | le_mcrypt = zend_register_list_destructors_ex(php_mcrypt_module_dtor, NULL, "mcrypt", module_number); 378 | 379 | /* modes for mcrypt_??? routines */ 380 | REGISTER_LONG_CONSTANT("MCRYPT_ENCRYPT", 0, CONST_PERSISTENT); 381 | REGISTER_LONG_CONSTANT("MCRYPT_DECRYPT", 1, CONST_PERSISTENT); 382 | 383 | /* sources for mcrypt_create_iv */ 384 | REGISTER_LONG_CONSTANT("MCRYPT_DEV_RANDOM", RANDOM, CONST_PERSISTENT); 385 | REGISTER_LONG_CONSTANT("MCRYPT_DEV_URANDOM", URANDOM, CONST_PERSISTENT); 386 | REGISTER_LONG_CONSTANT("MCRYPT_RAND", RAND, CONST_PERSISTENT); 387 | 388 | /* ciphers */ 389 | MCRYPT_ENTRY2_2_4(3DES, "tripledes"); 390 | MCRYPT_ENTRY2_2_4(ARCFOUR_IV, "arcfour-iv"); 391 | MCRYPT_ENTRY2_2_4(ARCFOUR, "arcfour"); 392 | MCRYPT_ENTRY2_2_4(BLOWFISH, "blowfish"); 393 | MCRYPT_ENTRY2_2_4(BLOWFISH_COMPAT, "blowfish-compat"); 394 | MCRYPT_ENTRY2_2_4(CAST_128, "cast-128"); 395 | MCRYPT_ENTRY2_2_4(CAST_256, "cast-256"); 396 | MCRYPT_ENTRY2_2_4(CRYPT, "crypt"); 397 | MCRYPT_ENTRY2_2_4(DES, "des"); 398 | MCRYPT_ENTRY2_2_4(ENIGNA, "crypt"); 399 | MCRYPT_ENTRY2_2_4(GOST, "gost"); 400 | MCRYPT_ENTRY2_2_4(LOKI97, "loki97"); 401 | MCRYPT_ENTRY2_2_4(PANAMA, "panama"); 402 | MCRYPT_ENTRY2_2_4(RC2, "rc2"); 403 | MCRYPT_ENTRY2_2_4(RIJNDAEL_128, "rijndael-128"); 404 | MCRYPT_ENTRY2_2_4(RIJNDAEL_192, "rijndael-192"); 405 | MCRYPT_ENTRY2_2_4(RIJNDAEL_256, "rijndael-256"); 406 | MCRYPT_ENTRY2_2_4(SAFER64, "safer-sk64"); 407 | MCRYPT_ENTRY2_2_4(SAFER128, "safer-sk128"); 408 | MCRYPT_ENTRY2_2_4(SAFERPLUS, "saferplus"); 409 | MCRYPT_ENTRY2_2_4(SERPENT, "serpent"); 410 | MCRYPT_ENTRY2_2_4(THREEWAY, "threeway"); 411 | MCRYPT_ENTRY2_2_4(TRIPLEDES, "tripledes"); 412 | MCRYPT_ENTRY2_2_4(TWOFISH, "twofish"); 413 | MCRYPT_ENTRY2_2_4(WAKE, "wake"); 414 | MCRYPT_ENTRY2_2_4(XTEA, "xtea"); 415 | 416 | MCRYPT_ENTRY2_2_4(IDEA, "idea"); 417 | MCRYPT_ENTRY2_2_4(MARS, "mars"); 418 | MCRYPT_ENTRY2_2_4(RC6, "rc6"); 419 | MCRYPT_ENTRY2_2_4(SKIPJACK, "skipjack"); 420 | /* modes */ 421 | MCRYPT_ENTRY2_2_4(MODE_CBC, "cbc"); 422 | MCRYPT_ENTRY2_2_4(MODE_CFB, "cfb"); 423 | MCRYPT_ENTRY2_2_4(MODE_ECB, "ecb"); 424 | MCRYPT_ENTRY2_2_4(MODE_NOFB, "nofb"); 425 | MCRYPT_ENTRY2_2_4(MODE_OFB, "ofb"); 426 | MCRYPT_ENTRY2_2_4(MODE_STREAM, "stream"); 427 | REGISTER_INI_ENTRIES(); 428 | 429 | php_stream_filter_register_factory("mcrypt.*", &php_mcrypt_filter_factory); 430 | php_stream_filter_register_factory("mdecrypt.*", &php_mcrypt_filter_factory); 431 | 432 | return SUCCESS; 433 | } 434 | /* }}} */ 435 | 436 | static PHP_MSHUTDOWN_FUNCTION(mcrypt) /* {{{ */ 437 | { 438 | php_stream_filter_unregister_factory("mcrypt.*"); 439 | php_stream_filter_unregister_factory("mdecrypt.*"); 440 | 441 | UNREGISTER_INI_ENTRIES(); 442 | return SUCCESS; 443 | } 444 | /* }}} */ 445 | 446 | #include "zend_smart_str.h" 447 | 448 | PHP_MINFO_FUNCTION(mcrypt) /* {{{ */ 449 | { 450 | char **modules; 451 | char mcrypt_api_no[16]; 452 | int i, count; 453 | smart_str tmp1 = {0}; 454 | smart_str tmp2 = {0}; 455 | 456 | modules = mcrypt_list_algorithms(MCG(algorithms_dir), &count); 457 | if (count == 0) { 458 | smart_str_appends(&tmp1, "none"); 459 | } 460 | for (i = 0; i < count; i++) { 461 | smart_str_appends(&tmp1, modules[i]); 462 | smart_str_appendc(&tmp1, ' '); 463 | } 464 | smart_str_0(&tmp1); 465 | mcrypt_free_p(modules, count); 466 | 467 | modules = mcrypt_list_modes(MCG(modes_dir), &count); 468 | if (count == 0) { 469 | smart_str_appends(&tmp2, "none"); 470 | } 471 | for (i = 0; i < count; i++) { 472 | smart_str_appends(&tmp2, modules[i]); 473 | smart_str_appendc(&tmp2, ' '); 474 | } 475 | smart_str_0 (&tmp2); 476 | mcrypt_free_p (modules, count); 477 | 478 | snprintf (mcrypt_api_no, 16, "%d", MCRYPT_API_VERSION); 479 | 480 | php_info_print_table_start(); 481 | php_info_print_table_header(2, "mcrypt support", "enabled"); 482 | php_info_print_table_header(2, "mcrypt_filter support", "enabled"); 483 | php_info_print_table_row(2, "Extension version", PHP_MCRYPT_VERSION); 484 | php_info_print_table_row(2, "Library version", LIBMCRYPT_VERSION); 485 | php_info_print_table_row(2, "Api No", mcrypt_api_no); 486 | php_info_print_table_row(2, "Supported ciphers", ZSTR_VAL(tmp1.s)); 487 | php_info_print_table_row(2, "Supported modes", ZSTR_VAL(tmp2.s)); 488 | smart_str_free(&tmp1); 489 | smart_str_free(&tmp2); 490 | 491 | php_info_print_table_end(); 492 | 493 | DISPLAY_INI_ENTRIES(); 494 | } 495 | /* }}} */ 496 | 497 | /* {{{ proto resource mcrypt_module_open(string cipher, string cipher_directory, string mode, string mode_directory) 498 | Opens the module of the algorithm and the mode to be used */ 499 | PHP_FUNCTION(mcrypt_module_open) 500 | { 501 | char *cipher, *cipher_dir; 502 | char *mode, *mode_dir; 503 | size_t cipher_len, cipher_dir_len; 504 | size_t mode_len, mode_dir_len; 505 | MCRYPT td; 506 | php_mcrypt *pm; 507 | 508 | if (zend_parse_parameters (ZEND_NUM_ARGS(), "ssss", 509 | &cipher, &cipher_len, &cipher_dir, &cipher_dir_len, 510 | &mode, &mode_len, &mode_dir, &mode_dir_len)) { 511 | return; 512 | } 513 | 514 | td = mcrypt_module_open ( 515 | cipher, 516 | cipher_dir_len > 0 ? cipher_dir : MCG(algorithms_dir), 517 | mode, 518 | mode_dir_len > 0 ? mode_dir : MCG(modes_dir) 519 | ); 520 | 521 | if (td == MCRYPT_FAILED) { 522 | php_error_docref(NULL, E_WARNING, "Could not open encryption module"); 523 | RETURN_FALSE; 524 | } else { 525 | pm = emalloc(sizeof(php_mcrypt)); 526 | pm->td = td; 527 | pm->init = 0; 528 | RETURN_RES(zend_register_resource(pm, le_mcrypt)); 529 | } 530 | } 531 | /* }}} */ 532 | 533 | /* {{{ proto int mcrypt_generic_init(resource td, string key, string iv) 534 | This function initializes all buffers for the specific module */ 535 | PHP_FUNCTION(mcrypt_generic_init) 536 | { 537 | char *key, *iv; 538 | size_t key_len, iv_len; 539 | zval *mcryptind; 540 | unsigned char *key_s, *iv_s; 541 | int max_key_size, key_size, iv_size; 542 | php_mcrypt *pm; 543 | int result = 0; 544 | 545 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "rss", &mcryptind, &key, &key_len, &iv, &iv_len) == FAILURE) { 546 | return; 547 | } 548 | 549 | if ((pm = (php_mcrypt *)zend_fetch_resource(Z_RES_P(mcryptind), "MCrypt", le_mcrypt)) == NULL) { 550 | RETURN_FALSE; 551 | } 552 | 553 | max_key_size = mcrypt_enc_get_key_size(pm->td); 554 | iv_size = mcrypt_enc_get_iv_size(pm->td); 555 | 556 | if (key_len == 0) { 557 | php_error_docref(NULL, E_WARNING, "Key size is 0"); 558 | } 559 | 560 | key_s = emalloc(key_len); 561 | memset(key_s, 0, key_len); 562 | 563 | iv_s = emalloc(iv_size + 1); 564 | memset(iv_s, 0, iv_size + 1); 565 | 566 | if (key_len > (size_t)max_key_size) { 567 | php_error_docref(NULL, E_WARNING, "Key size too large; supplied length: %zd, max: %d", key_len, max_key_size); 568 | key_size = max_key_size; 569 | } else { 570 | key_size = (int)key_len; 571 | } 572 | memcpy(key_s, key, key_len); 573 | 574 | if (iv_len != (size_t)iv_size) { 575 | php_error_docref(NULL, E_WARNING, "Iv size incorrect; supplied length: %zd, needed: %d", iv_len, iv_size); 576 | if (iv_len > (size_t)iv_size) { 577 | iv_len = iv_size; 578 | } 579 | } 580 | memcpy(iv_s, iv, iv_len); 581 | 582 | mcrypt_generic_deinit(pm->td); 583 | result = mcrypt_generic_init(pm->td, key_s, key_size, iv_s); 584 | 585 | /* If this function fails, close the mcrypt module to prevent crashes 586 | * when further functions want to access this resource */ 587 | if (result < 0) { 588 | zend_list_close(Z_RES_P(mcryptind)); 589 | switch (result) { 590 | case -3: 591 | php_error_docref(NULL, E_WARNING, "Key length incorrect"); 592 | break; 593 | case -4: 594 | php_error_docref(NULL, E_WARNING, "Memory allocation error"); 595 | break; 596 | case -1: 597 | default: 598 | php_error_docref(NULL, E_WARNING, "Unknown error"); 599 | break; 600 | } 601 | } else { 602 | pm->init = 1; 603 | } 604 | RETVAL_LONG(result); 605 | 606 | efree(iv_s); 607 | efree(key_s); 608 | } 609 | /* }}} */ 610 | 611 | /* {{{ proto string mcrypt_generic(resource td, string data) 612 | This function encrypts the plaintext */ 613 | PHP_FUNCTION(mcrypt_generic) 614 | { 615 | zval *mcryptind; 616 | char *data; 617 | size_t data_len; 618 | php_mcrypt *pm; 619 | zend_string* data_str; 620 | int block_size, data_size; 621 | 622 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &mcryptind, &data, &data_len) == FAILURE) { 623 | return; 624 | } 625 | 626 | if ((pm = (php_mcrypt *)zend_fetch_resource(Z_RES_P(mcryptind), "MCrypt", le_mcrypt)) == NULL) { 627 | RETURN_FALSE; 628 | } 629 | PHP_MCRYPT_INIT_CHECK 630 | 631 | if (data_len == 0) { 632 | php_error_docref(NULL, E_WARNING, "An empty string was passed"); 633 | RETURN_FALSE; 634 | } 635 | 636 | if (data_len > INT_MAX) { 637 | php_error_docref(NULL, E_WARNING, "Data size too large, %d maximum", INT_MAX); 638 | RETURN_FALSE; 639 | } 640 | /* Check blocksize */ 641 | if (mcrypt_enc_is_block_mode(pm->td) == 1) { /* It's a block algorithm */ 642 | block_size = mcrypt_enc_get_block_size(pm->td); 643 | data_size = ((((int)data_len - 1) / block_size) + 1) * block_size; 644 | if (data_size <= 0) { 645 | php_error_docref(NULL, E_WARNING, "Integer overflow in data size"); 646 | RETURN_FALSE; 647 | } 648 | data_str = zend_string_alloc(data_size, 0); 649 | memset(ZSTR_VAL(data_str), 0, data_size); 650 | memcpy(ZSTR_VAL(data_str), data, data_len); 651 | } else { /* It's not a block algorithm */ 652 | data_size = (int)data_len; 653 | data_str = zend_string_alloc(data_size, 0); 654 | memset(ZSTR_VAL(data_str), 0, data_size); 655 | memcpy(ZSTR_VAL(data_str), data, data_len); 656 | } 657 | 658 | mcrypt_generic(pm->td, ZSTR_VAL(data_str), data_size); 659 | ZSTR_VAL(data_str)[data_size] = '\0'; 660 | 661 | RETVAL_NEW_STR(data_str); 662 | } 663 | /* }}} */ 664 | 665 | /* {{{ proto string mdecrypt_generic(resource td, string data) 666 | This function decrypts the plaintext */ 667 | PHP_FUNCTION(mdecrypt_generic) 668 | { 669 | zval *mcryptind; 670 | char *data; 671 | size_t data_len; 672 | php_mcrypt *pm; 673 | char* data_s; 674 | int block_size, data_size; 675 | 676 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs", &mcryptind, &data, &data_len) == FAILURE) { 677 | return; 678 | } 679 | 680 | if ((pm = (php_mcrypt *)zend_fetch_resource(Z_RES_P(mcryptind), "MCrypt", le_mcrypt)) == NULL) { 681 | RETURN_FALSE; 682 | } 683 | PHP_MCRYPT_INIT_CHECK 684 | 685 | if (data_len == 0) { 686 | php_error_docref(NULL, E_WARNING, "An empty string was passed"); 687 | RETURN_FALSE; 688 | } 689 | 690 | /* Check blocksize */ 691 | if (data_len > INT_MAX) { 692 | php_error_docref(NULL, E_WARNING, "Data size too large, %d maximum", INT_MAX); 693 | RETURN_FALSE; 694 | } 695 | if (mcrypt_enc_is_block_mode(pm->td) == 1) { /* It's a block algorithm */ 696 | block_size = mcrypt_enc_get_block_size(pm->td); 697 | data_size = ((((int)data_len - 1) / block_size) + 1) * block_size; 698 | if (data_size <= 0) { 699 | php_error_docref(NULL, E_WARNING, "Integer overflow in data size"); 700 | RETURN_FALSE; 701 | } 702 | data_s = emalloc((size_t)data_size + 1); 703 | memset(data_s, 0, data_size); 704 | memcpy(data_s, data, data_len); 705 | } else { /* It's not a block algorithm */ 706 | data_size = (int)data_len; 707 | data_s = emalloc(data_size + 1); 708 | memset(data_s, 0, data_size); 709 | memcpy(data_s, data, data_len); 710 | } 711 | 712 | mdecrypt_generic(pm->td, data_s, data_size); 713 | 714 | RETVAL_STRINGL(data_s, data_size); 715 | efree(data_s); 716 | } 717 | /* }}} */ 718 | 719 | /* {{{ proto array mcrypt_enc_get_supported_key_sizes(resource td) 720 | This function decrypts the crypttext */ 721 | PHP_FUNCTION(mcrypt_enc_get_supported_key_sizes) 722 | { 723 | int i, count = 0; 724 | int *key_sizes; 725 | 726 | MCRYPT_GET_TD_ARG 727 | array_init(return_value); 728 | 729 | key_sizes = mcrypt_enc_get_supported_key_sizes(pm->td, &count); 730 | 731 | for (i = 0; i < count; i++) { 732 | add_index_long(return_value, i, key_sizes[i]); 733 | } 734 | 735 | mcrypt_free(key_sizes); 736 | } 737 | /* }}} */ 738 | 739 | /* {{{ proto int mcrypt_enc_self_test(resource td) 740 | This function runs the self test on the algorithm specified by the descriptor td */ 741 | PHP_FUNCTION(mcrypt_enc_self_test) 742 | { 743 | MCRYPT_GET_TD_ARG 744 | RETURN_LONG(mcrypt_enc_self_test(pm->td)); 745 | } 746 | /* }}} */ 747 | 748 | /* {{{ proto bool mcrypt_module_close(resource td) 749 | Free the descriptor td */ 750 | PHP_FUNCTION(mcrypt_module_close) 751 | { 752 | MCRYPT_GET_TD_ARG 753 | zend_list_close(Z_RES_P(mcryptind)); 754 | RETURN_TRUE; 755 | } 756 | /* }}} */ 757 | 758 | /* {{{ proto bool mcrypt_generic_deinit(resource td) 759 | This function terminates encrypt specified by the descriptor td */ 760 | PHP_FUNCTION(mcrypt_generic_deinit) 761 | { 762 | MCRYPT_GET_TD_ARG 763 | 764 | if (mcrypt_generic_deinit(pm->td) < 0) { 765 | php_error_docref(NULL, E_WARNING, "Could not terminate encryption specifier"); 766 | RETURN_FALSE; 767 | } 768 | pm->init = 0; 769 | RETURN_TRUE; 770 | } 771 | /* }}} */ 772 | 773 | /* {{{ proto bool mcrypt_enc_is_block_algorithm_mode(resource td) 774 | Returns TRUE if the mode is for use with block algorithms */ 775 | PHP_FUNCTION(mcrypt_enc_is_block_algorithm_mode) 776 | { 777 | MCRYPT_GET_TD_ARG 778 | 779 | if (mcrypt_enc_is_block_algorithm_mode(pm->td) == 1) { 780 | RETURN_TRUE; 781 | } else { 782 | RETURN_FALSE; 783 | } 784 | } 785 | /* }}} */ 786 | 787 | /* {{{ proto bool mcrypt_enc_is_block_algorithm(resource td) 788 | Returns TRUE if the alrogithm is a block algorithms */ 789 | PHP_FUNCTION(mcrypt_enc_is_block_algorithm) 790 | { 791 | MCRYPT_GET_TD_ARG 792 | 793 | if (mcrypt_enc_is_block_algorithm(pm->td) == 1) { 794 | RETURN_TRUE; 795 | } else { 796 | RETURN_FALSE; 797 | } 798 | } 799 | /* }}} */ 800 | 801 | /* {{{ proto bool mcrypt_enc_is_block_mode(resource td) 802 | Returns TRUE if the mode outputs blocks */ 803 | PHP_FUNCTION(mcrypt_enc_is_block_mode) 804 | { 805 | MCRYPT_GET_TD_ARG 806 | 807 | if (mcrypt_enc_is_block_mode(pm->td) == 1) { 808 | RETURN_TRUE; 809 | } else { 810 | RETURN_FALSE; 811 | } 812 | } 813 | /* }}} */ 814 | 815 | /* {{{ proto int mcrypt_enc_get_block_size(resource td) 816 | Returns the block size of the cipher specified by the descriptor td */ 817 | PHP_FUNCTION(mcrypt_enc_get_block_size) 818 | { 819 | MCRYPT_GET_TD_ARG 820 | RETURN_LONG(mcrypt_enc_get_block_size(pm->td)); 821 | } 822 | /* }}} */ 823 | 824 | /* {{{ proto int mcrypt_enc_get_key_size(resource td) 825 | Returns the maximum supported key size in bytes of the algorithm specified by the descriptor td */ 826 | PHP_FUNCTION(mcrypt_enc_get_key_size) 827 | { 828 | MCRYPT_GET_TD_ARG 829 | RETURN_LONG(mcrypt_enc_get_key_size(pm->td)); 830 | } 831 | /* }}} */ 832 | 833 | /* {{{ proto int mcrypt_enc_get_iv_size(resource td) 834 | Returns the size of the IV in bytes of the algorithm specified by the descriptor td */ 835 | PHP_FUNCTION(mcrypt_enc_get_iv_size) 836 | { 837 | MCRYPT_GET_TD_ARG 838 | RETURN_LONG(mcrypt_enc_get_iv_size(pm->td)); 839 | } 840 | /* }}} */ 841 | 842 | /* {{{ proto string mcrypt_enc_get_algorithms_name(resource td) 843 | Returns the name of the algorithm specified by the descriptor td */ 844 | PHP_FUNCTION(mcrypt_enc_get_algorithms_name) 845 | { 846 | char *name; 847 | MCRYPT_GET_TD_ARG 848 | 849 | name = mcrypt_enc_get_algorithms_name(pm->td); 850 | RETVAL_STRING(name); 851 | mcrypt_free(name); 852 | } 853 | /* }}} */ 854 | 855 | /* {{{ proto string mcrypt_enc_get_modes_name(resource td) 856 | Returns the name of the mode specified by the descriptor td */ 857 | PHP_FUNCTION(mcrypt_enc_get_modes_name) 858 | { 859 | char *name; 860 | MCRYPT_GET_TD_ARG 861 | 862 | name = mcrypt_enc_get_modes_name(pm->td); 863 | RETVAL_STRING(name); 864 | mcrypt_free(name); 865 | } 866 | /* }}} */ 867 | 868 | /* {{{ proto bool mcrypt_module_self_test(string algorithm [, string lib_dir]) 869 | Does a self test of the module "module" */ 870 | PHP_FUNCTION(mcrypt_module_self_test) 871 | { 872 | MCRYPT_GET_MODE_DIR_ARGS(algorithms_dir); 873 | 874 | if (mcrypt_module_self_test(module, dir) == 0) { 875 | RETURN_TRUE; 876 | } else { 877 | RETURN_FALSE; 878 | } 879 | } 880 | /* }}} */ 881 | 882 | /* {{{ proto bool mcrypt_module_is_block_algorithm_mode(string mode [, string lib_dir]) 883 | Returns TRUE if the mode is for use with block algorithms */ 884 | PHP_FUNCTION(mcrypt_module_is_block_algorithm_mode) 885 | { 886 | MCRYPT_GET_MODE_DIR_ARGS(modes_dir) 887 | 888 | if (mcrypt_module_is_block_algorithm_mode(module, dir) == 1) { 889 | RETURN_TRUE; 890 | } else { 891 | RETURN_FALSE; 892 | } 893 | } 894 | /* }}} */ 895 | 896 | /* {{{ proto bool mcrypt_module_is_block_algorithm(string algorithm [, string lib_dir]) 897 | Returns TRUE if the algorithm is a block algorithm */ 898 | PHP_FUNCTION(mcrypt_module_is_block_algorithm) 899 | { 900 | MCRYPT_GET_MODE_DIR_ARGS(algorithms_dir) 901 | 902 | if (mcrypt_module_is_block_algorithm(module, dir) == 1) { 903 | RETURN_TRUE; 904 | } else { 905 | RETURN_FALSE; 906 | } 907 | } 908 | /* }}} */ 909 | 910 | /* {{{ proto bool mcrypt_module_is_block_mode(string mode [, string lib_dir]) 911 | Returns TRUE if the mode outputs blocks of bytes */ 912 | PHP_FUNCTION(mcrypt_module_is_block_mode) 913 | { 914 | MCRYPT_GET_MODE_DIR_ARGS(modes_dir) 915 | 916 | if (mcrypt_module_is_block_mode(module, dir) == 1) { 917 | RETURN_TRUE; 918 | } else { 919 | RETURN_FALSE; 920 | } 921 | } 922 | /* }}} */ 923 | 924 | /* {{{ proto int mcrypt_module_get_algo_block_size(string algorithm [, string lib_dir]) 925 | Returns the block size of the algorithm */ 926 | PHP_FUNCTION(mcrypt_module_get_algo_block_size) 927 | { 928 | MCRYPT_GET_MODE_DIR_ARGS(algorithms_dir) 929 | 930 | RETURN_LONG(mcrypt_module_get_algo_block_size(module, dir)); 931 | } 932 | /* }}} */ 933 | 934 | /* {{{ proto int mcrypt_module_get_algo_key_size(string algorithm [, string lib_dir]) 935 | Returns the maximum supported key size of the algorithm */ 936 | PHP_FUNCTION(mcrypt_module_get_algo_key_size) 937 | { 938 | MCRYPT_GET_MODE_DIR_ARGS(algorithms_dir); 939 | 940 | RETURN_LONG(mcrypt_module_get_algo_key_size(module, dir)); 941 | } 942 | /* }}} */ 943 | 944 | /* {{{ proto array mcrypt_module_get_supported_key_sizes(string algorithm [, string lib_dir]) 945 | This function decrypts the crypttext */ 946 | PHP_FUNCTION(mcrypt_module_get_supported_key_sizes) 947 | { 948 | int i, count = 0; 949 | int *key_sizes; 950 | 951 | MCRYPT_GET_MODE_DIR_ARGS(algorithms_dir) 952 | array_init(return_value); 953 | 954 | key_sizes = mcrypt_module_get_algo_supported_key_sizes(module, dir, &count); 955 | 956 | for (i = 0; i < count; i++) { 957 | add_index_long(return_value, i, key_sizes[i]); 958 | } 959 | mcrypt_free(key_sizes); 960 | } 961 | /* }}} */ 962 | 963 | /* {{{ proto array mcrypt_list_algorithms([string lib_dir]) 964 | List all algorithms in "module_dir" */ 965 | PHP_FUNCTION(mcrypt_list_algorithms) 966 | { 967 | char **modules; 968 | char *lib_dir = MCG(algorithms_dir); 969 | size_t lib_dir_len; 970 | int i, count; 971 | 972 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", 973 | &lib_dir, &lib_dir_len) == FAILURE) { 974 | return; 975 | } 976 | 977 | array_init(return_value); 978 | modules = mcrypt_list_algorithms(lib_dir, &count); 979 | 980 | if (count == 0) { 981 | php_error_docref(NULL, E_WARNING, "No algorithms found in module dir"); 982 | } 983 | for (i = 0; i < count; i++) { 984 | add_index_string(return_value, i, modules[i]); 985 | } 986 | mcrypt_free_p(modules, count); 987 | } 988 | /* }}} */ 989 | 990 | /* {{{ proto array mcrypt_list_modes([string lib_dir]) 991 | List all modes "module_dir" */ 992 | PHP_FUNCTION(mcrypt_list_modes) 993 | { 994 | char **modules; 995 | char *lib_dir = MCG(modes_dir); 996 | size_t lib_dir_len; 997 | int i, count; 998 | 999 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", 1000 | &lib_dir, &lib_dir_len) == FAILURE) { 1001 | return; 1002 | } 1003 | 1004 | array_init(return_value); 1005 | modules = mcrypt_list_modes(lib_dir, &count); 1006 | 1007 | if (count == 0) { 1008 | php_error_docref(NULL, E_WARNING, "No modes found in module dir"); 1009 | } 1010 | for (i = 0; i < count; i++) { 1011 | add_index_string(return_value, i, modules[i]); 1012 | } 1013 | mcrypt_free_p(modules, count); 1014 | } 1015 | /* }}} */ 1016 | 1017 | /* {{{ proto int mcrypt_get_key_size(string cipher, string module) 1018 | Get the key size of cipher */ 1019 | PHP_FUNCTION(mcrypt_get_key_size) 1020 | { 1021 | char *cipher; 1022 | char *module; 1023 | size_t cipher_len, module_len; 1024 | char *cipher_dir_string; 1025 | char *module_dir_string; 1026 | MCRYPT td; 1027 | 1028 | MCRYPT_GET_INI 1029 | 1030 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", 1031 | &cipher, &cipher_len, &module, &module_len) == FAILURE) { 1032 | return; 1033 | } 1034 | 1035 | td = mcrypt_module_open(cipher, cipher_dir_string, module, module_dir_string); 1036 | if (td != MCRYPT_FAILED) { 1037 | RETVAL_LONG(mcrypt_enc_get_key_size(td)); 1038 | mcrypt_module_close(td); 1039 | } else { 1040 | php_error_docref(NULL, E_WARNING, MCRYPT_OPEN_MODULE_FAILED); 1041 | RETURN_FALSE; 1042 | } 1043 | } 1044 | /* }}} */ 1045 | 1046 | /* {{{ proto int mcrypt_get_block_size(string cipher, string module) 1047 | Get the key size of cipher */ 1048 | PHP_FUNCTION(mcrypt_get_block_size) 1049 | { 1050 | char *cipher; 1051 | char *module; 1052 | size_t cipher_len, module_len; 1053 | char *cipher_dir_string; 1054 | char *module_dir_string; 1055 | MCRYPT td; 1056 | 1057 | MCRYPT_GET_INI 1058 | 1059 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", 1060 | &cipher, &cipher_len, &module, &module_len) == FAILURE) { 1061 | return; 1062 | } 1063 | 1064 | td = mcrypt_module_open(cipher, cipher_dir_string, module, module_dir_string); 1065 | if (td != MCRYPT_FAILED) { 1066 | RETVAL_LONG(mcrypt_enc_get_block_size(td)); 1067 | mcrypt_module_close(td); 1068 | } else { 1069 | php_error_docref(NULL, E_WARNING, MCRYPT_OPEN_MODULE_FAILED); 1070 | RETURN_FALSE; 1071 | } 1072 | } 1073 | /* }}} */ 1074 | 1075 | /* {{{ proto int mcrypt_get_iv_size(string cipher, string module) 1076 | Get the IV size of cipher (Usually the same as the blocksize) */ 1077 | PHP_FUNCTION(mcrypt_get_iv_size) 1078 | { 1079 | char *cipher; 1080 | char *module; 1081 | size_t cipher_len, module_len; 1082 | char *cipher_dir_string; 1083 | char *module_dir_string; 1084 | MCRYPT td; 1085 | 1086 | MCRYPT_GET_INI 1087 | 1088 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", 1089 | &cipher, &cipher_len, &module, &module_len) == FAILURE) { 1090 | return; 1091 | } 1092 | 1093 | td = mcrypt_module_open(cipher, cipher_dir_string, module, module_dir_string); 1094 | if (td != MCRYPT_FAILED) { 1095 | RETVAL_LONG(mcrypt_enc_get_iv_size(td)); 1096 | mcrypt_module_close(td); 1097 | } else { 1098 | php_error_docref(NULL, E_WARNING, MCRYPT_OPEN_MODULE_FAILED); 1099 | RETURN_FALSE; 1100 | } 1101 | } 1102 | /* }}} */ 1103 | 1104 | /* {{{ proto string mcrypt_get_cipher_name(string cipher) 1105 | Get the key size of cipher */ 1106 | PHP_FUNCTION(mcrypt_get_cipher_name) 1107 | { 1108 | char *cipher_dir_string; 1109 | char *module_dir_string; 1110 | char *cipher_name; 1111 | char *cipher; 1112 | size_t cipher_len; 1113 | MCRYPT td; 1114 | 1115 | MCRYPT_GET_INI 1116 | 1117 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", 1118 | &cipher, &cipher_len) == FAILURE) { 1119 | return; 1120 | } 1121 | 1122 | /* The code below is actually not very nice, but I didn't see a better 1123 | * method */ 1124 | td = mcrypt_module_open(cipher, cipher_dir_string, "ecb", module_dir_string); 1125 | if (td != MCRYPT_FAILED) { 1126 | cipher_name = mcrypt_enc_get_algorithms_name(td); 1127 | mcrypt_module_close(td); 1128 | RETVAL_STRING(cipher_name); 1129 | mcrypt_free(cipher_name); 1130 | } else { 1131 | td = mcrypt_module_open(cipher, cipher_dir_string, "stream", module_dir_string); 1132 | if (td != MCRYPT_FAILED) { 1133 | cipher_name = mcrypt_enc_get_algorithms_name(td); 1134 | mcrypt_module_close(td); 1135 | RETVAL_STRING(cipher_name); 1136 | mcrypt_free(cipher_name); 1137 | } else { 1138 | php_error_docref(NULL, E_WARNING, MCRYPT_OPEN_MODULE_FAILED); 1139 | RETURN_FALSE; 1140 | } 1141 | } 1142 | } 1143 | /* }}} */ 1144 | 1145 | static char *php_mcrypt_get_key_size_str( 1146 | int max_key_size, const int *key_sizes, int key_size_count) /* {{{ */ 1147 | { 1148 | if (key_size_count == 0) { 1149 | char *str; 1150 | spprintf(&str, 0, "Only keys of size 1 to %d supported", max_key_size); 1151 | return str; 1152 | } else if (key_size_count == 1) { 1153 | char *str; 1154 | spprintf(&str, 0, "Only keys of size %d supported", key_sizes[0]); 1155 | return str; 1156 | } else { 1157 | int i; 1158 | char *result = NULL; 1159 | smart_str str = {0}; 1160 | smart_str_appends(&str, "Only keys of sizes "); 1161 | 1162 | for (i = 0; i < key_size_count; ++i) { 1163 | if (i == key_size_count - 1) { 1164 | smart_str_appends(&str, " or "); 1165 | } else if (i != 0) { 1166 | smart_str_appends(&str, ", "); 1167 | } 1168 | 1169 | smart_str_append_long(&str, key_sizes[i]); 1170 | } 1171 | 1172 | smart_str_appends(&str, " supported"); 1173 | smart_str_0(&str); 1174 | result = estrndup(ZSTR_VAL(str.s), ZSTR_LEN(str.s)); 1175 | smart_str_free(&str); 1176 | 1177 | return result; 1178 | } 1179 | } 1180 | /* }}} */ 1181 | 1182 | static zend_bool php_mcrypt_is_valid_key_size( 1183 | int key_size, int max_key_size, int *key_sizes, int key_size_count) /* {{{ */ 1184 | { 1185 | int i; 1186 | 1187 | if (key_size <= 0 || key_size > max_key_size) { 1188 | return 0; 1189 | } 1190 | 1191 | if (key_size_count == 0) { 1192 | /* All key sizes are valid */ 1193 | return 1; 1194 | } 1195 | 1196 | for (i = 0; i < key_size_count; i++) { 1197 | if (key_sizes[i] == key_size) { 1198 | return 1; 1199 | } 1200 | } 1201 | 1202 | return 0; 1203 | } 1204 | /* }}} */ 1205 | 1206 | static int php_mcrypt_ensure_valid_key_size(MCRYPT td, int key_size) /* {{{ */ 1207 | { 1208 | int key_size_count; 1209 | int max_key_size = mcrypt_enc_get_key_size(td); 1210 | int *key_sizes = mcrypt_enc_get_supported_key_sizes(td, &key_size_count); 1211 | 1212 | zend_bool is_valid_key_size = php_mcrypt_is_valid_key_size( 1213 | key_size, max_key_size, key_sizes, key_size_count 1214 | ); 1215 | if (!is_valid_key_size) { 1216 | char *key_size_str = php_mcrypt_get_key_size_str( 1217 | max_key_size, key_sizes, key_size_count 1218 | ); 1219 | php_error_docref(NULL, E_WARNING, 1220 | "Key of size %d not supported by this algorithm. %s", key_size, key_size_str 1221 | ); 1222 | efree(key_size_str); 1223 | } 1224 | 1225 | if (key_sizes) { 1226 | mcrypt_free(key_sizes); 1227 | } 1228 | 1229 | return is_valid_key_size ? SUCCESS : FAILURE; 1230 | } 1231 | /* }}} */ 1232 | 1233 | static int php_mcrypt_ensure_valid_iv(MCRYPT td, const char *iv, int iv_size) /* {{{ */ 1234 | { 1235 | if (mcrypt_enc_mode_has_iv(td) == 1) { 1236 | int expected_iv_size = mcrypt_enc_get_iv_size(td); 1237 | if (expected_iv_size == 0) { 1238 | /* Algorithm does not use IV, even though mode supports it */ 1239 | return SUCCESS; 1240 | } 1241 | 1242 | if (!iv) { 1243 | php_error_docref(NULL, E_WARNING, 1244 | "Encryption mode requires an initialization vector of size %d", expected_iv_size 1245 | ); 1246 | return FAILURE; 1247 | } 1248 | 1249 | if (iv_size != expected_iv_size) { 1250 | php_error_docref(NULL, E_WARNING, 1251 | "Received initialization vector of size %d, but size %d is required " 1252 | "for this encryption mode", iv_size, expected_iv_size 1253 | ); 1254 | return FAILURE; 1255 | } 1256 | } 1257 | 1258 | return SUCCESS; 1259 | } 1260 | /* }}} */ 1261 | 1262 | static void php_mcrypt_do_crypt(char* cipher, const char *key, size_t key_len, const char *data, size_t data_len, char *mode, const char *iv, size_t iv_len, size_t dencrypt, zval* return_value) /* {{{ */ 1263 | { 1264 | char *cipher_dir_string; 1265 | char *module_dir_string; 1266 | zend_long data_size; 1267 | char *data_s; 1268 | MCRYPT td; 1269 | 1270 | MCRYPT_GET_INI 1271 | 1272 | td = mcrypt_module_open(cipher, cipher_dir_string, mode, module_dir_string); 1273 | if (td == MCRYPT_FAILED) { 1274 | php_error_docref(NULL, E_WARNING, MCRYPT_OPEN_MODULE_FAILED); 1275 | RETURN_FALSE; 1276 | } 1277 | 1278 | if (php_mcrypt_ensure_valid_key_size(td, (int)key_len) == FAILURE) { 1279 | mcrypt_module_close(td); 1280 | RETURN_FALSE; 1281 | } 1282 | 1283 | if (php_mcrypt_ensure_valid_iv(td, iv, (int)iv_len) == FAILURE) { 1284 | mcrypt_module_close(td); 1285 | RETURN_FALSE; 1286 | } 1287 | 1288 | /* Check blocksize */ 1289 | if (mcrypt_enc_is_block_mode(td) == 1) { /* It's a block algorithm */ 1290 | int block_size = mcrypt_enc_get_block_size(td); 1291 | data_size = ((((zend_long)data_len - 1) / block_size) + 1) * block_size; 1292 | data_s = emalloc(data_size + 1); 1293 | memset(data_s, 0, data_size); 1294 | memcpy(data_s, data, data_len); 1295 | } else { /* It's not a block algorithm */ 1296 | data_size = data_len; 1297 | data_s = emalloc(data_size + 1); 1298 | memcpy(data_s, data, data_len); 1299 | } 1300 | 1301 | if (mcrypt_generic_init(td, (void *) key, (int)key_len, (void *) iv) < 0) { 1302 | efree(data_s); 1303 | zend_throw_error(NULL, "Mcrypt initialisation failed"); 1304 | mcrypt_module_close(td); 1305 | RETURN_FALSE; 1306 | } 1307 | 1308 | if (dencrypt == MCRYPT_ENCRYPT) { 1309 | mcrypt_generic(td, data_s, (int)data_size); 1310 | } else { 1311 | mdecrypt_generic(td, data_s, (int)data_size); 1312 | } 1313 | 1314 | data_s[data_size] = 0; 1315 | 1316 | RETVAL_STRINGL(data_s, data_size); 1317 | efree(data_s); 1318 | 1319 | /* freeing vars */ 1320 | mcrypt_generic_end(td); 1321 | } 1322 | /* }}} */ 1323 | 1324 | /* {{{ proto string mcrypt_encrypt(string cipher, string key, string data, string mode, string iv) 1325 | OFB crypt/decrypt data using key key with cipher cipher starting with iv */ 1326 | PHP_FUNCTION(mcrypt_encrypt) 1327 | { 1328 | char *cipher, *key, *data, *mode, *iv = NULL; 1329 | size_t cipher_len, key_len, data_len, mode_len, iv_len = 0; 1330 | 1331 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "ssss|s", &cipher, &cipher_len, 1332 | &key, &key_len, &data, &data_len, &mode, &mode_len, &iv, &iv_len) == FAILURE) { 1333 | return; 1334 | } 1335 | 1336 | php_mcrypt_do_crypt(cipher, key, key_len, data, data_len, mode, iv, iv_len, MCRYPT_ENCRYPT, return_value); 1337 | } 1338 | /* }}} */ 1339 | 1340 | /* {{{ proto string mcrypt_decrypt(string cipher, string key, string data, string mode, string iv) 1341 | OFB crypt/decrypt data using key key with cipher cipher starting with iv */ 1342 | PHP_FUNCTION(mcrypt_decrypt) 1343 | { 1344 | char *cipher, *key, *data, *mode, *iv = NULL; 1345 | size_t cipher_len, key_len, data_len, mode_len, iv_len = 0; 1346 | 1347 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "ssss|s", &cipher, &cipher_len, 1348 | &key, &key_len, &data, &data_len, &mode, &mode_len, &iv, &iv_len) == FAILURE) { 1349 | return; 1350 | } 1351 | 1352 | php_mcrypt_do_crypt(cipher, key, key_len, data, data_len, mode, iv, iv_len, MCRYPT_DECRYPT, return_value); 1353 | } 1354 | /* }}} */ 1355 | 1356 | /* {{{ proto string mcrypt_create_iv(int size, int source) 1357 | Create an initialization vector (IV) */ 1358 | PHP_FUNCTION(mcrypt_create_iv) 1359 | { 1360 | char *iv; 1361 | zend_long source = URANDOM; 1362 | zend_long size; 1363 | int n = 0; 1364 | 1365 | if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|l", &size, &source) == FAILURE) { 1366 | return; 1367 | } 1368 | 1369 | if (size <= 0 || size >= INT_MAX) { 1370 | php_error_docref(NULL, E_WARNING, "Cannot create an IV with a size of less than 1 or greater than %d", INT_MAX); 1371 | RETURN_FALSE; 1372 | } 1373 | 1374 | iv = ecalloc(size + 1, 1); 1375 | 1376 | if (source == RANDOM || source == URANDOM) { 1377 | #if PHP_WIN32 1378 | /* random/urandom equivalent on Windows */ 1379 | BYTE *iv_b = (BYTE *) iv; 1380 | if (php_win32_get_random_bytes(iv_b, (size_t) size) == FAILURE){ 1381 | efree(iv); 1382 | php_error_docref(NULL, E_WARNING, "Could not gather sufficient random data"); 1383 | RETURN_FALSE; 1384 | } 1385 | n = (int)size; 1386 | #else 1387 | int *fd = &MCG(fd[source]); 1388 | size_t read_bytes = 0; 1389 | 1390 | if (*fd < 0) { 1391 | *fd = open(source == RANDOM ? "/dev/random" : "/dev/urandom", O_RDONLY); 1392 | if (*fd < 0) { 1393 | efree(iv); 1394 | php_error_docref(NULL, E_WARNING, "Cannot open source device"); 1395 | RETURN_FALSE; 1396 | } 1397 | } 1398 | 1399 | while ((zend_long)read_bytes < size) { 1400 | n = read(*fd, iv + read_bytes, size - read_bytes); 1401 | if (n <= 0) { 1402 | break; 1403 | } 1404 | read_bytes += n; 1405 | } 1406 | n = read_bytes; 1407 | 1408 | if (n < size) { 1409 | efree(iv); 1410 | php_error_docref(NULL, E_WARNING, "Could not gather sufficient random data"); 1411 | RETURN_FALSE; 1412 | } 1413 | #endif 1414 | } else { 1415 | n = (int)size; 1416 | while (size) { 1417 | iv[--size] = (char) (255.0 * php_rand() / RAND_MAX); 1418 | } 1419 | } 1420 | RETVAL_STRINGL(iv, n); 1421 | efree(iv); 1422 | } 1423 | /* }}} */ 1424 | 1425 | #endif 1426 | 1427 | /* 1428 | * Local variables: 1429 | * tab-width: 4 1430 | * c-basic-offset: 4 1431 | * End: 1432 | * vim600: sw=4 ts=4 fdm=marker 1433 | * vim<600: sw=4 ts=4 1434 | */ 1435 | -------------------------------------------------------------------------------- /mcrypt_filter.c: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 7 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2016 The PHP Group | 6 | +----------------------------------------------------------------------+ 7 | | This source file is subject to version 3.01 of the PHP license, | 8 | | that is bundled with this package in the file LICENSE, and is | 9 | | available through the world-wide-web at the following url: | 10 | | http://www.php.net/license/3_01.txt | 11 | | If you did not receive a copy of the PHP license and are unable to | 12 | | obtain it through the world-wide-web, please send a note to | 13 | | license@php.net so we can mail you a copy immediately. | 14 | +----------------------------------------------------------------------+ 15 | | Author: Sara Golemon | 16 | +----------------------------------------------------------------------+ 17 | */ 18 | 19 | #include "php.h" 20 | 21 | #include "php_mcrypt_filter.h" 22 | #include "php_ini.h" 23 | #include 24 | 25 | typedef struct _php_mcrypt_filter_data { 26 | MCRYPT module; 27 | char encrypt; 28 | int blocksize; 29 | char *block_buffer; 30 | int block_used; 31 | char persistent; 32 | } php_mcrypt_filter_data; 33 | 34 | static php_stream_filter_status_t php_mcrypt_filter( 35 | php_stream *stream, 36 | php_stream_filter *thisfilter, 37 | php_stream_bucket_brigade *buckets_in, 38 | php_stream_bucket_brigade *buckets_out, 39 | size_t *bytes_consumed, 40 | int flags) 41 | { 42 | php_mcrypt_filter_data *data; 43 | php_stream_bucket *bucket; 44 | size_t consumed = 0; 45 | php_stream_filter_status_t exit_status = PSFS_FEED_ME; 46 | 47 | if (!thisfilter || !Z_PTR(thisfilter->abstract)) { 48 | /* Should never happen */ 49 | return PSFS_ERR_FATAL; 50 | } 51 | 52 | data = (php_mcrypt_filter_data *)(Z_PTR(thisfilter->abstract)); 53 | while(buckets_in->head) { 54 | bucket = buckets_in->head; 55 | 56 | consumed += bucket->buflen; 57 | 58 | if (data->blocksize) { 59 | /* Blockmode cipher */ 60 | char *outchunk; 61 | int chunklen = (int)(bucket->buflen + data->block_used), n; 62 | php_stream_bucket *newbucket; 63 | 64 | outchunk = pemalloc(chunklen, data->persistent); 65 | if (data->block_used) { 66 | memcpy(outchunk, data->block_buffer, data->block_used); 67 | } 68 | memcpy(outchunk + data->block_used, bucket->buf, bucket->buflen); 69 | 70 | for(n=0; (n + data->blocksize) <= chunklen; n += data->blocksize) { 71 | 72 | if (data->encrypt) { 73 | mcrypt_generic(data->module, outchunk + n, data->blocksize); 74 | } else { 75 | mdecrypt_generic(data->module, outchunk + n, data->blocksize); 76 | } 77 | } 78 | data->block_used = chunklen - n; 79 | memcpy(data->block_buffer, outchunk + n, data->block_used); 80 | 81 | newbucket = php_stream_bucket_new(stream, outchunk, n, 1, data->persistent); 82 | php_stream_bucket_append(buckets_out, newbucket); 83 | 84 | exit_status = PSFS_PASS_ON; 85 | 86 | php_stream_bucket_unlink(bucket); 87 | php_stream_bucket_delref(bucket); 88 | } else { 89 | /* Stream cipher */ 90 | php_stream_bucket_make_writeable(bucket); 91 | if (data->encrypt) { 92 | mcrypt_generic(data->module, bucket->buf, (int)bucket->buflen); 93 | } else { 94 | mdecrypt_generic(data->module, bucket->buf, (int)bucket->buflen); 95 | } 96 | php_stream_bucket_append(buckets_out, bucket); 97 | 98 | exit_status = PSFS_PASS_ON; 99 | } 100 | } 101 | 102 | if ((flags & PSFS_FLAG_FLUSH_CLOSE) && data->blocksize && data->block_used) { 103 | php_stream_bucket *newbucket; 104 | 105 | memset(data->block_buffer + data->block_used, 0, data->blocksize - data->block_used); 106 | if (data->encrypt) { 107 | mcrypt_generic(data->module, data->block_buffer, data->blocksize); 108 | } else { 109 | mdecrypt_generic(data->module, data->block_buffer, data->blocksize); 110 | } 111 | 112 | newbucket = php_stream_bucket_new(stream, data->block_buffer, data->blocksize, 0, data->persistent); 113 | php_stream_bucket_append(buckets_out, newbucket); 114 | 115 | exit_status = PSFS_PASS_ON; 116 | } 117 | 118 | if (bytes_consumed) { 119 | *bytes_consumed = consumed; 120 | } 121 | 122 | return exit_status; 123 | } 124 | 125 | static void php_mcrypt_filter_dtor(php_stream_filter *thisfilter) 126 | { 127 | if (thisfilter && Z_PTR(thisfilter->abstract)) { 128 | php_mcrypt_filter_data *data = (php_mcrypt_filter_data*) Z_PTR(thisfilter->abstract); 129 | 130 | if (data->block_buffer) { 131 | pefree(data->block_buffer, data->persistent); 132 | } 133 | 134 | mcrypt_generic_deinit(data->module); 135 | mcrypt_module_close(data->module); 136 | 137 | pefree(data, data->persistent); 138 | } 139 | } 140 | 141 | static php_stream_filter_ops php_mcrypt_filter_ops = { 142 | php_mcrypt_filter, 143 | php_mcrypt_filter_dtor, 144 | "mcrypt.*" 145 | }; 146 | 147 | /* {{{ php_mcrypt_filter_create 148 | * Instantiate mcrypt filter 149 | */ 150 | static php_stream_filter *php_mcrypt_filter_create(const char *filtername, zval *filterparams, uint8_t persistent) 151 | { 152 | int encrypt = 1, iv_len, key_len, keyl, result; 153 | const char *cipher = filtername + sizeof("mcrypt.") - 1; 154 | zval *tmpzval; 155 | MCRYPT mcrypt_module; 156 | char *iv = NULL, *key = NULL; 157 | char *algo_dir = INI_STR("mcrypt.algorithms_dir"); 158 | char *mode_dir = INI_STR("mcrypt.modes_dir"); 159 | char *mode = "cbc"; 160 | php_mcrypt_filter_data *data; 161 | 162 | php_error_docref(NULL, E_DEPRECATED, "mcrypt and mdecrypt stream filters have been deprecated"); 163 | 164 | if (strncasecmp(filtername, "mdecrypt.", sizeof("mdecrypt.") - 1) == 0) { 165 | encrypt = 0; 166 | cipher += sizeof("de") - 1; 167 | } else if (strncasecmp(filtername, "mcrypt.", sizeof("mcrypt.") - 1) != 0) { 168 | /* Should never happen */ 169 | return NULL; 170 | } 171 | 172 | if (!filterparams || Z_TYPE_P(filterparams) != IS_ARRAY) { 173 | php_error_docref(NULL, E_WARNING, "Filter parameters for %s must be an array", filtername); 174 | return NULL; 175 | } 176 | 177 | if ((tmpzval = zend_hash_str_find(Z_ARRVAL_P(filterparams), ZEND_STRL("mode")))) { 178 | if (Z_TYPE_P(tmpzval) == IS_STRING) { 179 | mode = Z_STRVAL_P(tmpzval); 180 | } else { 181 | php_error_docref(NULL, E_WARNING, "mode is not a string, ignoring"); 182 | } 183 | } 184 | 185 | if ((tmpzval=zend_hash_str_find(Z_ARRVAL_P(filterparams), ZEND_STRL("algorithms_dir")))) { 186 | if (Z_TYPE_P(tmpzval) == IS_STRING) { 187 | algo_dir = Z_STRVAL_P(tmpzval); 188 | } else { 189 | php_error_docref(NULL, E_WARNING, "algorithms_dir is not a string, ignoring"); 190 | } 191 | } 192 | 193 | if ((tmpzval=zend_hash_str_find(Z_ARRVAL_P(filterparams), ZEND_STRL("modes_dir")))) { 194 | if (Z_TYPE_P(tmpzval) == IS_STRING) { 195 | mode_dir = Z_STRVAL_P(tmpzval); 196 | } else { 197 | php_error_docref(NULL, E_WARNING, "modes_dir is not a string, ignoring"); 198 | } 199 | } 200 | 201 | if ((tmpzval = zend_hash_str_find(Z_ARRVAL_P(filterparams), ZEND_STRL("key"))) && 202 | Z_TYPE_P(tmpzval) == IS_STRING) { 203 | key = Z_STRVAL_P(tmpzval); 204 | key_len = (int)Z_STRLEN_P(tmpzval); 205 | } else { 206 | php_error_docref(NULL, E_WARNING, "key not specified or is not a string"); 207 | return NULL; 208 | } 209 | 210 | mcrypt_module = mcrypt_module_open((char *)cipher, algo_dir, mode, mode_dir); 211 | if (mcrypt_module == MCRYPT_FAILED) { 212 | php_error_docref(NULL, E_WARNING, "Could not open encryption module"); 213 | return NULL; 214 | } 215 | iv_len = mcrypt_enc_get_iv_size(mcrypt_module); 216 | keyl = mcrypt_enc_get_key_size(mcrypt_module); 217 | if (keyl < key_len) { 218 | key_len = keyl; 219 | } 220 | 221 | if (!(tmpzval = zend_hash_str_find(Z_ARRVAL_P(filterparams), ZEND_STRL("iv"))) || 222 | Z_TYPE_P(tmpzval) != IS_STRING) { 223 | php_error_docref(NULL, E_WARNING, "Filter parameter[iv] not provided or not of type: string"); 224 | mcrypt_module_close(mcrypt_module); 225 | return NULL; 226 | } 227 | 228 | iv = emalloc(iv_len + 1); 229 | if ((size_t)iv_len <= Z_STRLEN_P(tmpzval)) { 230 | memcpy(iv, Z_STRVAL_P(tmpzval), iv_len); 231 | } else { 232 | memcpy(iv, Z_STRVAL_P(tmpzval), Z_STRLEN_P(tmpzval)); 233 | memset(iv + Z_STRLEN_P(tmpzval), 0, iv_len - Z_STRLEN_P(tmpzval)); 234 | } 235 | 236 | result = mcrypt_generic_init(mcrypt_module, key, key_len, iv); 237 | efree(iv); 238 | if (result < 0) { 239 | switch (result) { 240 | case -3: 241 | php_error_docref(NULL, E_WARNING, "Key length incorrect"); 242 | break; 243 | case -4: 244 | php_error_docref(NULL, E_WARNING, "Memory allocation error"); 245 | break; 246 | case -1: 247 | default: 248 | php_error_docref(NULL, E_WARNING, "Unknown error"); 249 | break; 250 | } 251 | mcrypt_module_close(mcrypt_module); 252 | return NULL; 253 | } 254 | 255 | data = pemalloc(sizeof(php_mcrypt_filter_data), persistent); 256 | data->module = mcrypt_module; 257 | data->encrypt = encrypt; 258 | if (mcrypt_enc_is_block_mode(mcrypt_module)) { 259 | data->blocksize = mcrypt_enc_get_block_size(mcrypt_module); 260 | data->block_buffer = pemalloc(data->blocksize, persistent); 261 | } else { 262 | data->blocksize = 0; 263 | data->block_buffer = NULL; 264 | } 265 | data->block_used = 0; 266 | data->persistent = persistent; 267 | 268 | return php_stream_filter_alloc(&php_mcrypt_filter_ops, data, persistent); 269 | } 270 | /* }}} */ 271 | 272 | php_stream_filter_factory php_mcrypt_filter_factory = { 273 | php_mcrypt_filter_create 274 | }; 275 | 276 | /* 277 | * Local variables: 278 | * tab-width: 4 279 | * c-basic-offset: 4 280 | * End: 281 | * vim600: noet sw=4 ts=4 fdm=marker 282 | * vim<600: noet sw=4 ts=4 283 | */ 284 | -------------------------------------------------------------------------------- /package.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | mcrypt 4 | pecl.php.net 5 | Bindings for the libmcrypt library 6 | 7 | Provides bindings for the unmaintained libmcrypt. 8 | 9 | 10 | Derick Rethans 11 | derick 12 | derick@php.net 13 | no 14 | 15 | 16 | Sascha Schumann 17 | sas 18 | sascha@schumann.cx 19 | no 20 | 21 | 22 | Leigh 23 | leigh 24 | leigh@php.net 25 | yes 26 | 27 | 2023-12-12 28 | 29 | 1.0.7 30 | 1.0.0 31 | 32 | 33 | stable 34 | stable 35 | 36 | PHP License 37 | 38 | - Make release to advertise PHP 8.3 support, which it already had. 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 7.2.0 109 | 8.4.0 110 | 8.4.0 111 | 112 | 113 | 1.4.0 114 | 115 | 116 | 117 | mcrypt 118 | 119 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /php_mcrypt.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 7 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2019 The PHP Group | 6 | +----------------------------------------------------------------------+ 7 | | This source file is subject to version 3.01 of the PHP license, | 8 | | that is bundled with this package in the file LICENSE, and is | 9 | | available through the world-wide-web at the following url: | 10 | | http://www.php.net/license/3_01.txt | 11 | | If you did not receive a copy of the PHP license and are unable to | 12 | | obtain it through the world-wide-web, please send a note to | 13 | | license@php.net so we can mail you a copy immediately. | 14 | +----------------------------------------------------------------------+ 15 | | Authors: Sascha Schumann | 16 | | Derick Rethans | 17 | +----------------------------------------------------------------------+ 18 | */ 19 | 20 | #ifndef PHP_MCRYPT_H 21 | #define PHP_MCRYPT_H 22 | 23 | #if HAVE_LIBMCRYPT 24 | 25 | #ifdef ZTS 26 | #include "TSRM.h" 27 | #endif 28 | 29 | extern zend_module_entry mcrypt_module_entry; 30 | #define mcrypt_module_ptr &mcrypt_module_entry 31 | 32 | #define PHP_MCRYPT_VERSION "1.0.7" 33 | 34 | /* Functions for both old and new API */ 35 | PHP_FUNCTION(mcrypt_ecb); 36 | PHP_FUNCTION(mcrypt_cbc); 37 | PHP_FUNCTION(mcrypt_cfb); 38 | PHP_FUNCTION(mcrypt_ofb); 39 | PHP_FUNCTION(mcrypt_get_cipher_name); 40 | PHP_FUNCTION(mcrypt_get_block_size); 41 | PHP_FUNCTION(mcrypt_get_key_size); 42 | PHP_FUNCTION(mcrypt_create_iv); 43 | 44 | /* Support functions for old API */ 45 | PHP_FUNCTION(mcrypt_list_algorithms); 46 | PHP_FUNCTION(mcrypt_list_modes); 47 | PHP_FUNCTION(mcrypt_get_iv_size); 48 | PHP_FUNCTION(mcrypt_encrypt); 49 | PHP_FUNCTION(mcrypt_decrypt); 50 | 51 | /* Functions for new API */ 52 | PHP_FUNCTION(mcrypt_module_open); 53 | PHP_FUNCTION(mcrypt_generic_init); 54 | PHP_FUNCTION(mcrypt_generic); 55 | PHP_FUNCTION(mdecrypt_generic); 56 | PHP_FUNCTION(mcrypt_generic_deinit); 57 | 58 | PHP_FUNCTION(mcrypt_enc_self_test); 59 | PHP_FUNCTION(mcrypt_enc_is_block_algorithm_mode); 60 | PHP_FUNCTION(mcrypt_enc_is_block_algorithm); 61 | PHP_FUNCTION(mcrypt_enc_is_block_mode); 62 | PHP_FUNCTION(mcrypt_enc_get_block_size); 63 | PHP_FUNCTION(mcrypt_enc_get_key_size); 64 | PHP_FUNCTION(mcrypt_enc_get_supported_key_sizes); 65 | PHP_FUNCTION(mcrypt_enc_get_iv_size); 66 | PHP_FUNCTION(mcrypt_enc_get_algorithms_name); 67 | PHP_FUNCTION(mcrypt_enc_get_modes_name); 68 | PHP_FUNCTION(mcrypt_module_self_test); 69 | PHP_FUNCTION(mcrypt_module_is_block_algorithm_mode); 70 | PHP_FUNCTION(mcrypt_module_is_block_algorithm); 71 | PHP_FUNCTION(mcrypt_module_is_block_mode); 72 | PHP_FUNCTION(mcrypt_module_get_algo_block_size); 73 | PHP_FUNCTION(mcrypt_module_get_algo_key_size); 74 | PHP_FUNCTION(mcrypt_module_get_supported_key_sizes); 75 | PHP_FUNCTION(mcrypt_module_close); 76 | 77 | ZEND_BEGIN_MODULE_GLOBALS(mcrypt) 78 | int le_h; 79 | char *modes_dir; 80 | char *algorithms_dir; 81 | int fd[2]; // RANDOM = 0, URANDOM = 1 82 | ZEND_END_MODULE_GLOBALS(mcrypt) 83 | 84 | #define MCG(v) ZEND_MODULE_GLOBALS_ACCESSOR(mcrypt, v) 85 | 86 | #else 87 | #define mcrypt_module_ptr NULL 88 | #endif 89 | 90 | #define phpext_mcrypt_ptr mcrypt_module_ptr 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /php_mcrypt_filter.h: -------------------------------------------------------------------------------- 1 | /* 2 | +----------------------------------------------------------------------+ 3 | | PHP Version 7 | 4 | +----------------------------------------------------------------------+ 5 | | Copyright (c) 1997-2016 The PHP Group | 6 | +----------------------------------------------------------------------+ 7 | | This source file is subject to version 3.01 of the PHP license, | 8 | | that is bundled with this package in the file LICENSE, and is | 9 | | available through the world-wide-web at the following url: | 10 | | http://www.php.net/license/3_01.txt | 11 | | If you did not receive a copy of the PHP license and are unable to | 12 | | obtain it through the world-wide-web, please send a note to | 13 | | license@php.net so we can mail you a copy immediately. | 14 | +----------------------------------------------------------------------+ 15 | | Author: Sara Golemon | 16 | +----------------------------------------------------------------------+ 17 | */ 18 | 19 | #ifndef PHP_MCRYPT_FILTER_H 20 | #define PHP_MCRYPT_FILTER_H 21 | 22 | extern php_stream_filter_factory php_mcrypt_filter_factory; 23 | 24 | PHP_MINIT_FUNCTION(mcrypt_filter); 25 | PHP_MSHUTDOWN_FUNCTION(mcrypt_filter); 26 | PHP_MINFO_FUNCTION(mcrypt_filter); 27 | 28 | #endif /* PHP_MCRYPT_FILTER_H */ 29 | 30 | 31 | /* 32 | * Local variables: 33 | * tab-width: 4 34 | * c-basic-offset: 4 35 | * indent-tabs-mode: t 36 | * End: 37 | */ 38 | -------------------------------------------------------------------------------- /tests/blowfish.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test for blowfish compatibility 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 55 | --EXPECTF-- 56 | key plain crypt guess stat 57 | 58 | Deprecated: Function mcrypt_module_open() is deprecated in %s%eblowfish.php on line %d 59 | 0000000000000000 0000000000000000 60 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d 61 | 62 | Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d 63 | 4ef997456198dd78 4ef997456198dd78 OK 64 | FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF 65 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d 66 | 67 | Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d 68 | 51866fd5b85ecb8a 51866fd5b85ecb8a OK 69 | 3000000000000000 1000000000000001 70 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d 71 | 72 | Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d 73 | 7d856f9a613063f2 7d856f9a613063f2 OK 74 | 1111111111111111 1111111111111111 75 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d 76 | 77 | Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d 78 | 2466dd878b963c9d 2466dd878b963c9d OK 79 | 0123456789ABCDEF 1111111111111111 80 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d 81 | 82 | Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d 83 | 61f9c3802281b096 61f9c3802281b096 OK 84 | 1111111111111111 0123456789ABCDEF 85 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d 86 | 87 | Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d 88 | 7d0cc630afda1ec7 7d0cc630afda1ec7 OK 89 | FEDCBA9876543210 0123456789ABCDEF 90 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d 91 | 92 | Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d 93 | 0aceab0fc6a0a28d 0aceab0fc6a0a28d OK 94 | 7CA110454A1A6E57 01A1D6D039776742 95 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d 96 | 97 | Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d 98 | 59c68245eb05282b 59c68245eb05282b OK 99 | 0131D9619DC1376E 5CD54CA83DEF57DA 100 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d 101 | 102 | Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d 103 | b1b8cc0b250f09a0 b1b8cc0b250f09a0 OK 104 | 07A1133E4A0B2686 0248D43806F67172 105 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d 106 | 107 | Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d 108 | 1730e5778bea1da4 1730e5778bea1da4 OK 109 | 3849674C2602319E 51454B582DDF440A 110 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d 111 | 112 | Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d 113 | a25e7856cf2651eb a25e7856cf2651eb OK 114 | 04B915BA43FEB5B6 42FD443059577FA2 115 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d 116 | 117 | Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d 118 | 353882b109ce8f1a 353882b109ce8f1a OK 119 | 0113B970FD34F2CE 059B5E0851CF143A 120 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d 121 | 122 | Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d 123 | 48f4d0884c379918 48f4d0884c379918 OK 124 | 0170F175468FB5E6 0756D8E0774761D2 125 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d 126 | 127 | Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d 128 | 432193b78951fc98 432193b78951fc98 OK 129 | 43297FAD38E373FE 762514B829BF486A 130 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d 131 | 132 | Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d 133 | 13f04154d69d1ae5 13f04154d69d1ae5 OK 134 | 07A7137045DA2A16 3BDD119049372802 135 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d 136 | 137 | Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d 138 | 2eedda93ffd39c79 2eedda93ffd39c79 OK 139 | 04689104C2FD3B2F 26955F6835AF609A 140 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d 141 | 142 | Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d 143 | d887e0393c2da6e3 d887e0393c2da6e3 OK 144 | 37D06BB516CB7546 164D5E404F275232 145 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d 146 | 147 | Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d 148 | 5f99d04f5b163969 5f99d04f5b163969 OK 149 | 1F08260D1AC2465E 6B056E18759F5CCA 150 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d 151 | 152 | Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d 153 | 4a057a3b24d3977b 4a057a3b24d3977b OK 154 | 584023641ABA6176 004BD6EF09176062 155 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d 156 | 157 | Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d 158 | 452031c1e4fada8e 452031c1e4fada8e OK 159 | 025816164629B007 480D39006EE762F2 160 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d 161 | 162 | Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d 163 | 7555ae39f59b87bd 7555ae39f59b87bd OK 164 | 49793EBC79B3258F 437540C8698F3CFA 165 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d 166 | 167 | Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d 168 | 53c55f9cb49fc019 53c55f9cb49fc019 OK 169 | 4FB05E1515AB73A7 072D43A077075292 170 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d 171 | 172 | Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d 173 | 7a8e7bfa937e89a3 7a8e7bfa937e89a3 OK 174 | 49E95D6D4CA229BF 02FE55778117F12A 175 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d 176 | 177 | Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d 178 | cf9c5d7a4986adb5 cf9c5d7a4986adb5 OK 179 | 018310DC409B26D6 1D9D5C5018F728C2 180 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d 181 | 182 | Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d 183 | d1abb290658bc778 d1abb290658bc778 OK 184 | 1C587F1C13924FEF 305532286D6F295A 185 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d 186 | 187 | Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d 188 | 55cb3774d13ef201 55cb3774d13ef201 OK 189 | 0101010101010101 0123456789ABCDEF 190 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d 191 | 192 | Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d 193 | fa34ec4847b268b2 fa34ec4847b268b2 OK 194 | 1F1F1F1F0E0E0E0E 0123456789ABCDEF 195 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d 196 | 197 | Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d 198 | a790795108ea3cae a790795108ea3cae OK 199 | E0FEE0FEF1FEF1FE 0123456789ABCDEF 200 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d 201 | 202 | Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d 203 | c39e072d9fac631d c39e072d9fac631d OK 204 | 0000000000000000 FFFFFFFFFFFFFFFF 205 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d 206 | 207 | Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d 208 | 014933e0cdaff6e4 014933e0cdaff6e4 OK 209 | FFFFFFFFFFFFFFFF 0000000000000000 210 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d 211 | 212 | Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d 213 | f21e9a77b71c49bc f21e9a77b71c49bc OK 214 | 0123456789ABCDEF 0000000000000000 215 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d 216 | 217 | Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d 218 | 245946885754369a 245946885754369a OK 219 | FEDCBA9876543210 FFFFFFFFFFFFFFFF 220 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d 221 | 222 | Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d 223 | 6b5c5a9c5d9e0a5a 6b5c5a9c5d9e0a5a OK 224 | 225 | Deprecated: Function mcrypt_module_open() is deprecated in %s%eblowfish.php on line %d 226 | 227 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%eblowfish.php on line %d 228 | 229 | Deprecated: Function mcrypt_generic() is deprecated in %s%eblowfish.php on line %d 230 | 231 | 6b77b4d63006dee605b156e27403979358deb9e7154616d959f1652bd5ff92cc 232 | -------------------------------------------------------------------------------- /tests/bug35496.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Bug #35496 (Crash in mcrypt_generic()/mdecrypt_generic() without proper init). 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 11 | --EXPECTF-- 12 | Deprecated: Function mcrypt_module_open() is deprecated in %s%ebug35496.php on line 2 13 | 14 | Deprecated: Function mcrypt_generic() is deprecated in %s%ebug35496.php on line 3 15 | 16 | Warning: mcrypt_generic(): Operation disallowed prior to mcrypt_generic_init(). in %sbug35496.php on line 3 17 | 18 | Deprecated: Function mdecrypt_generic() is deprecated in %s%ebug35496.php on line 4 19 | 20 | Warning: mdecrypt_generic(): Operation disallowed prior to mcrypt_generic_init(). in %sbug35496.php on line 4 21 | -------------------------------------------------------------------------------- /tests/bug37595.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Bug #37595 (mcrypt_generic calculates data length in wrong way) 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 48 | --EXPECTF-- 49 | Deprecated: Function mcrypt_module_open() is deprecated in %s%ebug37595.php on line 18 50 | 51 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%ebug37595.php on line 30 52 | 53 | Deprecated: Function mcrypt_generic() is deprecated in %s%ebug37595.php on line 31 54 | 55 | Deprecated: Function mcrypt_generic_deinit() is deprecated in %s%ebug37595.php on line 33 56 | 57 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%ebug37595.php on line 35 58 | string(8) "12345678" 59 | 60 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%ebug37595.php on line 30 61 | 62 | Deprecated: Function mcrypt_generic() is deprecated in %s%ebug37595.php on line 31 63 | 64 | Deprecated: Function mcrypt_generic_deinit() is deprecated in %s%ebug37595.php on line 33 65 | 66 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%ebug37595.php on line 35 67 | string(16) "123456789" 68 | 69 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%ebug37595.php on line 30 70 | 71 | Deprecated: Function mcrypt_generic() is deprecated in %s%ebug37595.php on line 31 72 | 73 | Deprecated: Function mcrypt_generic_deinit() is deprecated in %s%ebug37595.php on line 33 74 | 75 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%ebug37595.php on line 35 76 | string(8) "1234567" 77 | 78 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%ebug37595.php on line 30 79 | 80 | Deprecated: Function mcrypt_generic() is deprecated in %s%ebug37595.php on line 31 81 | 82 | Warning: mcrypt_generic(): An empty string was passed in %s%ebug37595.php on line 31 83 | 84 | Deprecated: Function mcrypt_generic_deinit() is deprecated in %s%ebug37595.php on line 33 85 | 86 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%ebug37595.php on line 35 87 | bool(false) 88 | 89 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%ebug37595.php on line 30 90 | 91 | Deprecated: Function mcrypt_generic() is deprecated in %s%ebug37595.php on line 31 92 | 93 | Deprecated: Function mcrypt_generic_deinit() is deprecated in %s%ebug37595.php on line 33 94 | 95 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%ebug37595.php on line 35 96 | string(16) "1234567812345678" 97 | 98 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%ebug37595.php on line 30 99 | 100 | Deprecated: Function mcrypt_generic() is deprecated in %s%ebug37595.php on line 31 101 | 102 | Deprecated: Function mcrypt_generic_deinit() is deprecated in %s%ebug37595.php on line 33 103 | 104 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%ebug37595.php on line 35 105 | string(24) "12345678123456789" 106 | 107 | Deprecated: Function mcrypt_module_close() is deprecated in %s%ebug37595.php on line 39 108 | Done 109 | -------------------------------------------------------------------------------- /tests/bug41252.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Bug #41252 (Calling mcrypt_generic without first calling mcrypt_generic_init crashes) 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 11 | --EXPECTF-- 12 | Deprecated: Function mcrypt_module_open() is deprecated in %s%ebug41252.php on line 2 13 | 14 | Deprecated: Function mcrypt_generic() is deprecated in %s%ebug41252.php on line 3 15 | 16 | Warning: mcrypt_generic(): Operation disallowed prior to mcrypt_generic_init(). in %sbug41252.php on line 3 17 | I'm alive! 18 | -------------------------------------------------------------------------------- /tests/bug43143.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Bug #43143 (Warning about empty IV with MCRYPT_MODE_ECB) 3 | --SKIPIF-- 4 | 6 | --FILE-- 7 | 18 | --EXPECTF-- 19 | ECB 20 | 21 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%ebug43143.php on line 5 22 | CFB 23 | 24 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%ebug43143.php on line 9 25 | 26 | Warning: mcrypt_encrypt(): Encryption mode requires an initialization vector of size 32 in %sbug43143.php on line 9 27 | END 28 | -------------------------------------------------------------------------------- /tests/bug46010.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Bug #46010 (warnings incorrectly generated for iv in ecb mode) 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 14 | --EXPECTF-- 15 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%ebug46010.php on line 4 16 | string(16) "f7a2ce11d4002294" 17 | 18 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%ebug46010.php on line 5 19 | string(16) "f7a2ce11d4002294" 20 | 21 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%ebug46010.php on line 6 22 | string(16) "f7a2ce11d4002294" 23 | -------------------------------------------------------------------------------- /tests/bug49738.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Bug #49738 (calling mcrypt after mcrypt_generic_deinit crashes) 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 12 | --EXPECTF-- 13 | Deprecated: Function mcrypt_module_open() is deprecated in %s%ebug49738.php on line 2 14 | 15 | Deprecated: Function mcrypt_generic_init() is deprecated in %s%ebug49738.php on line 3 16 | 17 | Deprecated: Function mcrypt_generic_deinit() is deprecated in %s%ebug49738.php on line 4 18 | 19 | Deprecated: Function mcrypt_generic() is deprecated in %s%ebug49738.php on line 5 20 | 21 | Warning: mcrypt_generic(): Operation disallowed prior to mcrypt_generic_init(). in %sbug49738.php on line 5 22 | -------------------------------------------------------------------------------- /tests/bug55169.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | mcrypt_create_iv https://bugs.php.net/bug.php?id=55169 3 | --CREDITS-- 4 | Ryan Biesemeyer 5 | --SKIPIF-- 6 | 7 | --FILE-- 8 | 17 | --EXPECTF-- 18 | Input: 1 19 | 20 | Deprecated: Function mcrypt_create_iv() is deprecated in %s%ebug55169.php on line 4 21 | Length: 1 22 | Hex: %x 23 | 24 | Input: 2 25 | 26 | Deprecated: Function mcrypt_create_iv() is deprecated in %s%ebug55169.php on line 4 27 | Length: 2 28 | Hex: %x 29 | 30 | Input: 4 31 | 32 | Deprecated: Function mcrypt_create_iv() is deprecated in %s%ebug55169.php on line 4 33 | Length: 4 34 | Hex: %x 35 | 36 | Input: 8 37 | 38 | Deprecated: Function mcrypt_create_iv() is deprecated in %s%ebug55169.php on line 4 39 | Length: 8 40 | Hex: %x 41 | 42 | Input: 16 43 | 44 | Deprecated: Function mcrypt_create_iv() is deprecated in %s%ebug55169.php on line 4 45 | Length: 16 46 | Hex: %x 47 | 48 | Input: 32 49 | 50 | Deprecated: Function mcrypt_create_iv() is deprecated in %s%ebug55169.php on line 4 51 | Length: 32 52 | Hex: %x 53 | 54 | Input: 64 55 | 56 | Deprecated: Function mcrypt_create_iv() is deprecated in %s%ebug55169.php on line 4 57 | Length: 64 58 | Hex: %x 59 | -------------------------------------------------------------------------------- /tests/bug70625.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Bug #70625: mcrypt_encrypt() : won't return data when no IV was specified under RC4 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 15 | --EXPECTF-- 16 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%ebug70625.php on line 4 17 | string(14) "d5c9a57023d0f1" 18 | 19 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%ebug70625.php on line 6 20 | string(7) "payload" 21 | -------------------------------------------------------------------------------- /tests/bug8040.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Bug #8040 (MCRYPT_MODE_* do not seem to exist) 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 19 | --EXPECTF-- 20 | twofish 21 | cbc 22 | cbc 23 | cipher=twofish mode1=cbc 24 | -------------------------------------------------------------------------------- /tests/mcrypt_cbc.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | mcrypt_cbc 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 21 | --EXPECTF-- 22 | Deprecated: Function mcrypt_get_iv_size() is deprecated in %s%emcrypt_cbc.php on line 6 23 | 24 | Deprecated: Function mcrypt_create_iv() is deprecated in %s%emcrypt_cbc.php on line 6 25 | 26 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_cbc.php on line 7 27 | 28 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_cbc.php on line 10 29 | PHP Testfest 2008 30 | 31 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_cbc.php on line 13 32 | 33 | Warning: mcrypt_decrypt(): Encryption mode requires an initialization vector of size 16 in %s on line %d 34 | bool(false) 35 | -------------------------------------------------------------------------------- /tests/mcrypt_cbc_3des_decrypt.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test mcrypt_cbc() function : basic functionality 3 | --SKIPIF-- 4 | 9 | --FILE-- 10 | 64 | ===DONE=== 65 | --EXPECTF-- 66 | --- testing different key lengths 67 | 68 | key length=8 69 | 70 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_cbc_3des_decrypt.php on line 41 71 | 72 | Warning: mcrypt_decrypt(): Key of size 8 not supported by this algorithm. Only keys of size 24 supported in %s on line %d 73 | string(0) "" 74 | 75 | key length=20 76 | 77 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_cbc_3des_decrypt.php on line 41 78 | 79 | Warning: mcrypt_decrypt(): Key of size 20 not supported by this algorithm. Only keys of size 24 supported in %s on line %d 80 | string(0) "" 81 | 82 | key length=24 83 | 84 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_cbc_3des_decrypt.php on line 41 85 | string(32) "736563726574206d6573736167650000" 86 | 87 | key length=26 88 | 89 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_cbc_3des_decrypt.php on line 41 90 | 91 | Warning: mcrypt_decrypt(): Key of size 26 not supported by this algorithm. Only keys of size 24 supported in %s on line %d 92 | string(0) "" 93 | 94 | --- testing different iv lengths 95 | 96 | iv length=4 97 | 98 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_cbc_3des_decrypt.php on line 48 99 | 100 | Warning: mcrypt_decrypt(): Received initialization vector of size 4, but size 8 is required for this encryption mode in %s on line %d 101 | string(0) "" 102 | 103 | iv length=8 104 | 105 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_cbc_3des_decrypt.php on line 48 106 | string(32) "659ec947f4dc3a3b9c50de744598d3c8" 107 | 108 | iv length=9 109 | 110 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_cbc_3des_decrypt.php on line 48 111 | 112 | Warning: mcrypt_decrypt(): Received initialization vector of size 9, but size 8 is required for this encryption mode in %s on line %d 113 | string(0) "" 114 | ===DONE=== 115 | -------------------------------------------------------------------------------- /tests/mcrypt_cbc_3des_encrypt.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test mcrypt_cbc() function : basic functionality 3 | --SKIPIF-- 4 | 9 | --FILE-- 10 | 47 | ===DONE=== 48 | --EXPECTF-- 49 | --- testing different key lengths 50 | 51 | key length=8 52 | 53 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_cbc_3des_encrypt.php on line 28 54 | 55 | Warning: mcrypt_encrypt(): Key of size 8 not supported by this algorithm. Only keys of size 24 supported in %s on line %d 56 | string(0) "" 57 | 58 | key length=20 59 | 60 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_cbc_3des_encrypt.php on line 28 61 | 62 | Warning: mcrypt_encrypt(): Key of size 20 not supported by this algorithm. Only keys of size 24 supported in %s on line %d 63 | string(0) "" 64 | 65 | key length=24 66 | 67 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_cbc_3des_encrypt.php on line 28 68 | string(112) "b85e21072239d60c63a80e7c9ae493cb741a1cd407e52f451c5f43a0d103f55a7b62617eb2e44213c2d44462d388bc0b8f119384b12c84ac" 69 | 70 | key length=26 71 | 72 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_cbc_3des_encrypt.php on line 28 73 | 74 | Warning: mcrypt_encrypt(): Key of size 26 not supported by this algorithm. Only keys of size 24 supported in %s on line %d 75 | string(0) "" 76 | 77 | --- testing different iv lengths 78 | 79 | iv length=4 80 | 81 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_cbc_3des_encrypt.php on line 35 82 | 83 | Warning: mcrypt_encrypt(): Received initialization vector of size 4, but size 8 is required for this encryption mode in %s on line %d 84 | string(0) "" 85 | 86 | iv length=8 87 | 88 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_cbc_3des_encrypt.php on line 35 89 | string(112) "b85e21072239d60c63a80e7c9ae493cb741a1cd407e52f451c5f43a0d103f55a7b62617eb2e44213c2d44462d388bc0b8f119384b12c84ac" 90 | 91 | iv length=9 92 | 93 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_cbc_3des_encrypt.php on line 35 94 | 95 | Warning: mcrypt_encrypt(): Received initialization vector of size 9, but size 8 is required for this encryption mode in %s on line %d 96 | string(0) "" 97 | ===DONE=== 98 | -------------------------------------------------------------------------------- /tests/mcrypt_cfb.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | mcrypt_cfb 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 5 | --FILE-- 6 | 5 | --FILE-- 6 | 9 | --FILE-- 10 | 67 | ===DONE=== 68 | --EXPECTF-- 69 | *** Testing mcrypt_decrypt() : basic functionality *** 70 | 71 | --- testing different key lengths 72 | 73 | key length=8 74 | 75 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_decrypt_3des_cbc.php on line 44 76 | 77 | Warning: mcrypt_decrypt(): Key of size 8 not supported by this algorithm. Only keys of size 24 supported in %s on line %d 78 | string(0) "" 79 | 80 | key length=20 81 | 82 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_decrypt_3des_cbc.php on line 44 83 | 84 | Warning: mcrypt_decrypt(): Key of size 20 not supported by this algorithm. Only keys of size 24 supported in %s on line %d 85 | string(0) "" 86 | 87 | key length=24 88 | 89 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_decrypt_3des_cbc.php on line 44 90 | string(32) "736563726574206d6573736167650000" 91 | 92 | key length=26 93 | 94 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_decrypt_3des_cbc.php on line 44 95 | 96 | Warning: mcrypt_decrypt(): Key of size 26 not supported by this algorithm. Only keys of size 24 supported in %s on line %d 97 | string(0) "" 98 | 99 | --- testing different iv lengths 100 | 101 | iv length=4 102 | 103 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_decrypt_3des_cbc.php on line 51 104 | 105 | Warning: mcrypt_decrypt(): Received initialization vector of size 4, but size 8 is required for this encryption mode in %s on line %d 106 | string(0) "" 107 | 108 | iv length=8 109 | 110 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_decrypt_3des_cbc.php on line 51 111 | string(32) "659ec947f4dc3a3b9c50de744598d3c8" 112 | 113 | iv length=9 114 | 115 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_decrypt_3des_cbc.php on line 51 116 | 117 | Warning: mcrypt_decrypt(): Received initialization vector of size 9, but size 8 is required for this encryption mode in %s on line %d 118 | string(0) "" 119 | ===DONE=== 120 | -------------------------------------------------------------------------------- /tests/mcrypt_decrypt_3des_ecb.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test mcrypt_decrypt() function : basic functionality 3 | --SKIPIF-- 4 | 9 | --FILE-- 10 | 66 | ===DONE=== 67 | --EXPECTF-- 68 | *** Testing mcrypt_decrypt() : basic functionality *** 69 | 70 | --- testing different key lengths 71 | 72 | key length=8 73 | 74 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_decrypt_3des_ecb.php on line 43 75 | 76 | Warning: mcrypt_decrypt(): Key of size 8 not supported by this algorithm. Only keys of size 24 supported in %s on line %d 77 | string(0) "" 78 | 79 | key length=20 80 | 81 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_decrypt_3des_ecb.php on line 43 82 | 83 | Warning: mcrypt_decrypt(): Key of size 20 not supported by this algorithm. Only keys of size 24 supported in %s on line %d 84 | string(0) "" 85 | 86 | key length=24 87 | 88 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_decrypt_3des_ecb.php on line 43 89 | string(32) "736563726574206d6573736167650000" 90 | 91 | key length=26 92 | 93 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_decrypt_3des_ecb.php on line 43 94 | 95 | Warning: mcrypt_decrypt(): Key of size 26 not supported by this algorithm. Only keys of size 24 supported in %s on line %d 96 | string(0) "" 97 | 98 | --- testing different iv lengths 99 | 100 | iv length=4 101 | 102 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_decrypt_3des_ecb.php on line 50 103 | string(32) "a9298896ed1b7335f8f10f7ff6d7a239" 104 | 105 | iv length=8 106 | 107 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_decrypt_3des_ecb.php on line 50 108 | string(32) "a9298896ed1b7335f8f10f7ff6d7a239" 109 | 110 | iv length=9 111 | 112 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_decrypt_3des_ecb.php on line 50 113 | string(32) "a9298896ed1b7335f8f10f7ff6d7a239" 114 | ===DONE=== 115 | -------------------------------------------------------------------------------- /tests/mcrypt_ecb.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | mcrypt_ecb 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 9 | --FILE-- 10 | 65 | ===DONE=== 66 | --EXPECTF-- 67 | --- testing different key lengths 68 | 69 | key length=8 70 | 71 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_ecb_3des_decrypt.php on line 42 72 | 73 | Warning: mcrypt_decrypt(): Key of size 8 not supported by this algorithm. Only keys of size 24 supported in %s on line %d 74 | string(0) "" 75 | 76 | key length=20 77 | 78 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_ecb_3des_decrypt.php on line 42 79 | 80 | Warning: mcrypt_decrypt(): Key of size 20 not supported by this algorithm. Only keys of size 24 supported in %s on line %d 81 | string(0) "" 82 | 83 | key length=24 84 | 85 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_ecb_3des_decrypt.php on line 42 86 | string(32) "736563726574206d6573736167650000" 87 | 88 | key length=26 89 | 90 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_ecb_3des_decrypt.php on line 42 91 | 92 | Warning: mcrypt_decrypt(): Key of size 26 not supported by this algorithm. Only keys of size 24 supported in %s on line %d 93 | string(0) "" 94 | 95 | --- testing different iv lengths 96 | 97 | iv length=4 98 | 99 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_ecb_3des_decrypt.php on line 49 100 | string(32) "a9298896ed1b7335f8f10f7ff6d7a239" 101 | 102 | iv length=8 103 | 104 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_ecb_3des_decrypt.php on line 49 105 | string(32) "a9298896ed1b7335f8f10f7ff6d7a239" 106 | 107 | iv length=9 108 | 109 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_ecb_3des_decrypt.php on line 49 110 | string(32) "a9298896ed1b7335f8f10f7ff6d7a239" 111 | ===DONE=== 112 | -------------------------------------------------------------------------------- /tests/mcrypt_ecb_3des_encrypt.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test mcrypt_ecb() function : basic functionality 3 | --SKIPIF-- 4 | 9 | --FILE-- 10 | 50 | ===DONE=== 51 | --EXPECTF-- 52 | --- testing different key lengths 53 | 54 | key length=8 55 | 56 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_ecb_3des_encrypt.php on line 31 57 | 58 | Warning: mcrypt_encrypt(): Key of size 8 not supported by this algorithm. Only keys of size 24 supported in %s on line %d 59 | string(0) "" 60 | 61 | key length=20 62 | 63 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_ecb_3des_encrypt.php on line 31 64 | 65 | Warning: mcrypt_encrypt(): Key of size 20 not supported by this algorithm. Only keys of size 24 supported in %s on line %d 66 | string(0) "" 67 | 68 | key length=24 69 | 70 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_ecb_3des_encrypt.php on line 31 71 | string(112) "923eedcb20e18e3efa466a6ca1b842b34e6ac46aa3690ef739d0d68a26eb64e1a6ad42e7d18312ae8a57ab927e1dc892e5ff56c061864f27" 72 | 73 | key length=26 74 | 75 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_ecb_3des_encrypt.php on line 31 76 | 77 | Warning: mcrypt_encrypt(): Key of size 26 not supported by this algorithm. Only keys of size 24 supported in %s on line %d 78 | string(0) "" 79 | 80 | --- testing different iv lengths 81 | 82 | iv length=4 83 | 84 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_ecb_3des_encrypt.php on line 38 85 | string(112) "440a6f54601969b15e81df09cd381ef585fede5f3620587fd1a949c520aed9f6d10ebbabf2cea3e1f04c9251c2878c0ca37d51c80d490165" 86 | 87 | iv length=8 88 | 89 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_ecb_3des_encrypt.php on line 38 90 | string(112) "440a6f54601969b15e81df09cd381ef585fede5f3620587fd1a949c520aed9f6d10ebbabf2cea3e1f04c9251c2878c0ca37d51c80d490165" 91 | 92 | iv length=9 93 | 94 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_ecb_3des_encrypt.php on line 38 95 | string(112) "440a6f54601969b15e81df09cd381ef585fede5f3620587fd1a949c520aed9f6d10ebbabf2cea3e1f04c9251c2878c0ca37d51c80d490165" 96 | ===DONE=== 97 | -------------------------------------------------------------------------------- /tests/mcrypt_enc_get_algorithms_name.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | mcrypt_enc_get_algorithms_name 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 5 | --FILE-- 6 | 5 | --FILE-- 6 | 5 | --FILE-- 6 | 5 | --FILE-- 6 | 5 | --FILE-- 6 | 16 | int(16) 17 | [1]=> 18 | int(24) 19 | [2]=> 20 | int(32) 21 | } -------------------------------------------------------------------------------- /tests/mcrypt_enc_is_block_algorithm.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | mcrypt_enc_is_block_algorithm 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 5 | --FILE-- 6 | 5 | --FILE-- 6 | 5 | --FILE-- 6 | 9 | --FILE-- 10 | 60 | ===DONE=== 61 | --EXPECTF-- 62 | *** Testing mcrypt_encrypt() : TripleDES functionality *** 63 | 64 | --- testing different key lengths 65 | 66 | key length=8 67 | 68 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_encrypt_3des_cbc.php on line 40 69 | 70 | Warning: mcrypt_encrypt(): Key of size 8 not supported by this algorithm. Only keys of size 24 supported in %s on line %d 71 | string(0) "" 72 | 73 | key length=20 74 | 75 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_encrypt_3des_cbc.php on line 40 76 | 77 | Warning: mcrypt_encrypt(): Key of size 20 not supported by this algorithm. Only keys of size 24 supported in %s on line %d 78 | string(0) "" 79 | 80 | key length=24 81 | 82 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_encrypt_3des_cbc.php on line 40 83 | string(112) "b85e21072239d60c63a80e7c9ae493cb741a1cd407e52f451c5f43a0d103f55a7b62617eb2e44213c2d44462d388bc0b8f119384b12c84ac" 84 | 85 | key length=26 86 | 87 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_encrypt_3des_cbc.php on line 40 88 | 89 | Warning: mcrypt_encrypt(): Key of size 26 not supported by this algorithm. Only keys of size 24 supported in %s on line %d 90 | string(0) "" 91 | 92 | --- testing different iv lengths 93 | 94 | iv length=4 95 | 96 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_encrypt_3des_cbc.php on line 47 97 | 98 | Warning: mcrypt_encrypt(): Received initialization vector of size 4, but size 8 is required for this encryption mode in %s on line %d 99 | string(0) "" 100 | 101 | iv length=8 102 | 103 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_encrypt_3des_cbc.php on line 47 104 | string(112) "b85e21072239d60c63a80e7c9ae493cb741a1cd407e52f451c5f43a0d103f55a7b62617eb2e44213c2d44462d388bc0b8f119384b12c84ac" 105 | 106 | iv length=9 107 | 108 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_encrypt_3des_cbc.php on line 47 109 | 110 | Warning: mcrypt_encrypt(): Received initialization vector of size 9, but size 8 is required for this encryption mode in %s on line %d 111 | string(0) "" 112 | ===DONE=== 113 | -------------------------------------------------------------------------------- /tests/mcrypt_encrypt_3des_ecb.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test mcrypt_encrypt() function : TripleDES functionality 3 | --SKIPIF-- 4 | 9 | --FILE-- 10 | 52 | ===DONE=== 53 | --EXPECTF-- 54 | *** Testing mcrypt_encrypt() : TripleDES functionality *** 55 | 56 | --- testing different key lengths 57 | 58 | key length=8 59 | 60 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_encrypt_3des_ecb.php on line 25 61 | 62 | Warning: mcrypt_encrypt(): Key of size 8 not supported by this algorithm. Only keys of size 24 supported in %s on line %d 63 | string(0) "" 64 | 65 | key length=20 66 | 67 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_encrypt_3des_ecb.php on line 25 68 | 69 | Warning: mcrypt_encrypt(): Key of size 20 not supported by this algorithm. Only keys of size 24 supported in %s on line %d 70 | string(0) "" 71 | 72 | key length=24 73 | 74 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_encrypt_3des_ecb.php on line 25 75 | string(112) "923eedcb20e18e3efa466a6ca1b842b34e6ac46aa3690ef739d0d68a26eb64e1a6ad42e7d18312ae8a57ab927e1dc892e5ff56c061864f27" 76 | 77 | key length=26 78 | 79 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_encrypt_3des_ecb.php on line 25 80 | 81 | Warning: mcrypt_encrypt(): Key of size 26 not supported by this algorithm. Only keys of size 24 supported in %s on line %d 82 | string(0) "" 83 | 84 | --- testing different iv lengths 85 | 86 | iv length=4 87 | 88 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_encrypt_3des_ecb.php on line 39 89 | string(112) "923eedcb20e18e3efa466a6ca1b842b34e6ac46aa3690ef739d0d68a26eb64e1a6ad42e7d18312ae8a57ab927e1dc892e5ff56c061864f27" 90 | 91 | iv length=8 92 | 93 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_encrypt_3des_ecb.php on line 39 94 | string(112) "923eedcb20e18e3efa466a6ca1b842b34e6ac46aa3690ef739d0d68a26eb64e1a6ad42e7d18312ae8a57ab927e1dc892e5ff56c061864f27" 95 | 96 | iv length=9 97 | 98 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_encrypt_3des_ecb.php on line 39 99 | string(112) "923eedcb20e18e3efa466a6ca1b842b34e6ac46aa3690ef739d0d68a26eb64e1a6ad42e7d18312ae8a57ab927e1dc892e5ff56c061864f27" 100 | ===DONE=== 101 | -------------------------------------------------------------------------------- /tests/mcrypt_filters.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | mcrypt filters 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | $iv, 'key'=>$key); 20 | 21 | $fp = fopen($secretfile, 'wb'); 22 | stream_filter_append($fp, 'mcrypt.tripledes', STREAM_FILTER_WRITE, $opts); 23 | fwrite($fp, 'Secret secret secret data'); 24 | fclose($fp); 25 | 26 | echo md5_file($secretfile)."\n"; 27 | 28 | $fp = fopen($secretfile, 'rb'); 29 | stream_filter_append($fp, 'mdecrypt.tripledes', STREAM_FILTER_READ, $opts); 30 | $data = stream_get_contents($fp); 31 | fclose($fp); 32 | 33 | echo $data."\n"; 34 | 35 | @unlink($secretfile); 36 | 37 | --EXPECTF-- 38 | FOUND 39 | FOUND 40 | 41 | Deprecated: stream_filter_append(): mcrypt and mdecrypt stream filters have been deprecated in %s%emcrypt_filters.php on line 17 42 | 32e14bd3c31f2bd666e4290ebdb166a7 43 | 44 | Deprecated: stream_filter_append(): mcrypt and mdecrypt stream filters have been deprecated in %s%emcrypt_filters.php on line 24 45 | Secret secret secret data -------------------------------------------------------------------------------- /tests/mcrypt_get_block_size.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | mcrypt_get_block_size 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 5 | --FILE-- 6 | 5 | --FILE-- 6 | 5 | --FILE-- 6 | 5 | --FILE-- 6 | 5 | --FILE-- 6 | 12 | string(3) "cbc" 13 | [1]=> 14 | string(3) "cfb" 15 | [2]=> 16 | string(3) "ctr" 17 | [3]=> 18 | string(3) "ecb" 19 | [4]=> 20 | string(4) "ncfb" 21 | [5]=> 22 | string(4) "nofb" 23 | [6]=> 24 | string(3) "ofb" 25 | [7]=> 26 | string(6) "stream" 27 | } -------------------------------------------------------------------------------- /tests/mcrypt_module_get_algo_block_size.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | mcrypt_module_get_algo_block_size 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 14 | --EXPECTF-- 15 | Deprecated: Function mcrypt_module_get_algo_block_size() is deprecated in %s%emcrypt_module_get_algo_block_size.php on line 2 16 | int(32) 17 | 18 | Deprecated: Function mcrypt_module_get_algo_block_size() is deprecated in %s%emcrypt_module_get_algo_block_size.php on line 3 19 | int(24) 20 | 21 | Deprecated: Function mcrypt_module_get_algo_block_size() is deprecated in %s%emcrypt_module_get_algo_block_size.php on line 4 22 | int(8) 23 | 24 | Deprecated: Function mcrypt_module_get_algo_block_size() is deprecated in %s%emcrypt_module_get_algo_block_size.php on line 5 25 | int(8) 26 | 27 | Deprecated: Function mcrypt_module_get_algo_block_size() is deprecated in %s%emcrypt_module_get_algo_block_size.php on line 6 28 | int(16) 29 | 30 | Deprecated: Function mcrypt_module_get_algo_block_size() is deprecated in %s%emcrypt_module_get_algo_block_size.php on line 7 31 | int(8) 32 | -------------------------------------------------------------------------------- /tests/mcrypt_module_get_algo_key_size.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | mcrypt_module_get_algo_key_size 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 14 | --EXPECTF-- 15 | Deprecated: Function mcrypt_module_get_algo_key_size() is deprecated in %s%emcrypt_module_get_algo_key_size.php on line 2 16 | int(32) 17 | 18 | Deprecated: Function mcrypt_module_get_algo_key_size() is deprecated in %s%emcrypt_module_get_algo_key_size.php on line 3 19 | int(32) 20 | 21 | Deprecated: Function mcrypt_module_get_algo_key_size() is deprecated in %s%emcrypt_module_get_algo_key_size.php on line 4 22 | int(128) 23 | 24 | Deprecated: Function mcrypt_module_get_algo_key_size() is deprecated in %s%emcrypt_module_get_algo_key_size.php on line 5 25 | int(16) 26 | 27 | Deprecated: Function mcrypt_module_get_algo_key_size() is deprecated in %s%emcrypt_module_get_algo_key_size.php on line 6 28 | int(32) 29 | 30 | Deprecated: Function mcrypt_module_get_algo_key_size() is deprecated in %s%emcrypt_module_get_algo_key_size.php on line 7 31 | int(56) 32 | -------------------------------------------------------------------------------- /tests/mcrypt_module_get_supported_key_sizes.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | mcrypt_module_get_supported_key_sizes 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 13 | int(16) 14 | [1]=> 15 | int(24) 16 | [2]=> 17 | int(32) 18 | } 19 | 20 | Deprecated: Function mcrypt_module_get_supported_key_sizes() is deprecated in %s%emcrypt_module_get_supported_key_sizes.php on line 3 21 | array(0) { 22 | } -------------------------------------------------------------------------------- /tests/mcrypt_module_is_block_algorithm.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | mcrypt_module_is_block_algorithm 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 5 | --FILE-- 6 | 5 | --FILE-- 6 | 5 | --FILE-- 6 | 5 | --FILE-- 6 | 5 | --FILE-- 6 | 9 | --FILE-- 10 | 65 | ===DONE=== 66 | --EXPECTF-- 67 | *** Testing mcrypt : Rijndael128 functionality *** 68 | 69 | --- testing different key lengths 70 | 71 | key length=0 72 | 73 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_rijndael128_128BitKey.php on line %d 74 | 75 | Warning: mcrypt_encrypt(): Key of size 0 not supported by this algorithm. Only keys of sizes 16, 24 or 32 supported in %s on line %d 76 | string(0) "" 77 | 78 | key length=8 79 | 80 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_rijndael128_128BitKey.php on line %d 81 | 82 | Warning: mcrypt_encrypt(): Key of size 8 not supported by this algorithm. Only keys of sizes 16, 24 or 32 supported in %s on line %d 83 | string(0) "" 84 | 85 | key length=16 86 | 87 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_rijndael128_128BitKey.php on line %d 88 | string(128) "dc8f957ec530acf10cd95ba7da7b6405380fe19a2941e9a8de54680512f18491bc374e5464885ae6c2ae2aa7a6cdd2fbe12a06bbc4bd59dbbfaa15f09044f101" 89 | 90 | --- testing different iv lengths 91 | 92 | iv length=0 93 | 94 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_rijndael128_128BitKey.php on line %d 95 | 96 | Warning: mcrypt_decrypt(): Received initialization vector of size 0, but size 16 is required for this encryption mode in %s on line %d 97 | string(0) "" 98 | 99 | iv length=8 100 | 101 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_rijndael128_128BitKey.php on line %d 102 | 103 | Warning: mcrypt_decrypt(): Received initialization vector of size 8, but size 16 is required for this encryption mode in %s on line %d 104 | string(0) "" 105 | 106 | iv length=16 107 | 108 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_rijndael128_128BitKey.php on line %d 109 | string(32) "42adc8c0db19473f2c684ff2d6e828a5" 110 | 111 | iv length=17 112 | 113 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_rijndael128_128BitKey.php on line %d 114 | 115 | Warning: mcrypt_decrypt(): Received initialization vector of size 17, but size 16 is required for this encryption mode in %s on line %d 116 | string(0) "" 117 | ===DONE=== 118 | -------------------------------------------------------------------------------- /tests/mcrypt_rijndael128_256BitKey.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test mcrypt_encrypt() function : AES functionality 3 | --SKIPIF-- 4 | 9 | --FILE-- 10 | 58 | ===DONE=== 59 | --EXPECTF-- 60 | *** Testing mcrypt : Rijndael128 functionality *** 61 | 62 | --- testing different key lengths 63 | 64 | key length=20 65 | 66 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_rijndael128_256BitKey.php on line 43 67 | 68 | Warning: mcrypt_encrypt(): Key of size 20 not supported by this algorithm. Only keys of sizes 16, 24 or 32 supported in %s on line %d 69 | string(0) "" 70 | 71 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_rijndael128_256BitKey.php on line 45 72 | 73 | Warning: mcrypt_decrypt(): Key of size 20 not supported by this algorithm. Only keys of sizes 16, 24 or 32 supported in %s on line %d 74 | string(0) "" 75 | 76 | key length=24 77 | 78 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_rijndael128_256BitKey.php on line 43 79 | string(128) "8ecdf1ed5742aff16ef34c819c8d22c707c54f4d9ffc18e5f6ab79fe68c25705351e2c001a0b9f29e5def67570ca9da644efb69a8bb97940cb4bec094dae8bb5" 80 | 81 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_rijndael128_256BitKey.php on line 45 82 | string(128) "546869732069732074686520736563726574206d657373616765207768696368206d75737420626520656e637279707465640000000000000000000000000000" 83 | 84 | key length=30 85 | 86 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_rijndael128_256BitKey.php on line 43 87 | 88 | Warning: mcrypt_encrypt(): Key of size 30 not supported by this algorithm. Only keys of sizes 16, 24 or 32 supported in %s on line %d 89 | string(0) "" 90 | 91 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_rijndael128_256BitKey.php on line 45 92 | 93 | Warning: mcrypt_decrypt(): Key of size 30 not supported by this algorithm. Only keys of sizes 16, 24 or 32 supported in %s on line %d 94 | string(0) "" 95 | 96 | key length=32 97 | 98 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_rijndael128_256BitKey.php on line 43 99 | string(128) "f23bc103bfd0859a8318acee6d96e5f43dff68f3cdeae817a1e77c33492e32bdb82c5f660fcd1a2bfda70d9de4d5d8028ce179a9e2f7f9ee7dd61c7b4b409e95" 100 | 101 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_rijndael128_256BitKey.php on line 45 102 | string(128) "546869732069732074686520736563726574206d657373616765207768696368206d75737420626520656e637279707465640000000000000000000000000000" 103 | 104 | key length=40 105 | 106 | Deprecated: Function mcrypt_encrypt() is deprecated in %s%emcrypt_rijndael128_256BitKey.php on line 43 107 | 108 | Warning: mcrypt_encrypt(): Key of size 40 not supported by this algorithm. Only keys of sizes 16, 24 or 32 supported in %s on line %d 109 | string(0) "" 110 | 111 | Deprecated: Function mcrypt_decrypt() is deprecated in %s%emcrypt_rijndael128_256BitKey.php on line 45 112 | 113 | Warning: mcrypt_decrypt(): Key of size 40 not supported by this algorithm. Only keys of sizes 16, 24 or 32 supported in %s on line %d 114 | string(0) "" 115 | ===DONE=== 116 | -------------------------------------------------------------------------------- /tests/vectors.txt: -------------------------------------------------------------------------------- 1 | 0000000000000000 0000000000000000 4EF997456198DD78 2 | FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF 51866FD5B85ECB8A 3 | 3000000000000000 1000000000000001 7D856F9A613063F2 4 | 1111111111111111 1111111111111111 2466DD878B963C9D 5 | 0123456789ABCDEF 1111111111111111 61F9C3802281B096 6 | 1111111111111111 0123456789ABCDEF 7D0CC630AFDA1EC7 7 | FEDCBA9876543210 0123456789ABCDEF 0ACEAB0FC6A0A28D 8 | 7CA110454A1A6E57 01A1D6D039776742 59C68245EB05282B 9 | 0131D9619DC1376E 5CD54CA83DEF57DA B1B8CC0B250F09A0 10 | 07A1133E4A0B2686 0248D43806F67172 1730E5778BEA1DA4 11 | 3849674C2602319E 51454B582DDF440A A25E7856CF2651EB 12 | 04B915BA43FEB5B6 42FD443059577FA2 353882B109CE8F1A 13 | 0113B970FD34F2CE 059B5E0851CF143A 48F4D0884C379918 14 | 0170F175468FB5E6 0756D8E0774761D2 432193B78951FC98 15 | 43297FAD38E373FE 762514B829BF486A 13F04154D69D1AE5 16 | 07A7137045DA2A16 3BDD119049372802 2EEDDA93FFD39C79 17 | 04689104C2FD3B2F 26955F6835AF609A D887E0393C2DA6E3 18 | 37D06BB516CB7546 164D5E404F275232 5F99D04F5B163969 19 | 1F08260D1AC2465E 6B056E18759F5CCA 4A057A3B24D3977B 20 | 584023641ABA6176 004BD6EF09176062 452031C1E4FADA8E 21 | 025816164629B007 480D39006EE762F2 7555AE39F59B87BD 22 | 49793EBC79B3258F 437540C8698F3CFA 53C55F9CB49FC019 23 | 4FB05E1515AB73A7 072D43A077075292 7A8E7BFA937E89A3 24 | 49E95D6D4CA229BF 02FE55778117F12A CF9C5D7A4986ADB5 25 | 018310DC409B26D6 1D9D5C5018F728C2 D1ABB290658BC778 26 | 1C587F1C13924FEF 305532286D6F295A 55CB3774D13EF201 27 | 0101010101010101 0123456789ABCDEF FA34EC4847B268B2 28 | 1F1F1F1F0E0E0E0E 0123456789ABCDEF A790795108EA3CAE 29 | E0FEE0FEF1FEF1FE 0123456789ABCDEF C39E072D9FAC631D 30 | 0000000000000000 FFFFFFFFFFFFFFFF 014933E0CDAFF6E4 31 | FFFFFFFFFFFFFFFF 0000000000000000 F21E9A77B71C49BC 32 | 0123456789ABCDEF 0000000000000000 245946885754369A 33 | FEDCBA9876543210 FFFFFFFFFFFFFFFF 6B5C5A9C5D9E0A5A 34 | --------------------------------------------------------------------------------