├── AUTHORS ├── COPYING.LIB ├── ChangeLog ├── INSTALL ├── KNOWN-BUGS ├── Makefile ├── Makefile.am ├── Makefile.in ├── NEWS ├── README ├── THANKS ├── TODO ├── acinclude.m4 ├── aclocal.m4 ├── autom4te.cache ├── output.0 ├── output.1 ├── output.2 ├── requests ├── traces.0 ├── traces.1 └── traces.2 ├── autoscan.log ├── buildconf ├── config.guess ├── config.h ├── config.h.in ├── config.log ├── config.status ├── config.sub ├── configure ├── configure.in ├── depcomp ├── doc ├── Makefile.am ├── Makefile.in ├── README.config ├── README.key ├── README.xtea ├── example.c └── mcrypt.3 ├── include ├── Makefile.am ├── Makefile.in ├── mcrypt.h └── mutils │ ├── mcrypt.h │ └── mcrypt.h.in ├── install-sh ├── lib ├── Makefile.am ├── Makefile.in ├── autoscan.log ├── bzero.c ├── bzero.h ├── configure.scan ├── libdefs.h ├── libmcrypt-config.in ├── libmcrypt.m4 ├── libmcrypt.sym ├── mcrypt.c ├── mcrypt_extra.c ├── mcrypt_internal.h ├── mcrypt_modules.c ├── mcrypt_modules.h ├── mcrypt_symb.c ├── mcrypt_threads.c ├── win32_comp.c ├── win32_comp.h ├── xmemory.c └── xmemory.h ├── libltdl ├── COPYING.LIB ├── Makefile.am ├── Makefile.in ├── README ├── acinclude.m4 ├── aclocal.m4 ├── config-h.in ├── configure ├── configure.in ├── ltdl.c └── ltdl.h ├── libmcrypt.spec ├── libmcrypt.spec.in ├── libtool ├── ltmain.sh ├── missing ├── mkinstalldirs ├── modules ├── Makefile.am ├── Makefile.in ├── algorithms │ ├── 3-way.c │ ├── 3-way.h │ ├── Makefile.am │ ├── Makefile.in │ ├── arcfour.c │ ├── arcfour.h │ ├── blowfish-compat.c │ ├── blowfish.c │ ├── blowfish.h │ ├── cast-128.c │ ├── cast-128.h │ ├── cast-128_sboxes.h │ ├── cast-256.c │ ├── cast-256.h │ ├── des.c │ ├── des.h │ ├── enigma.c │ ├── enigma.h │ ├── gost.c │ ├── loki97.c │ ├── panama.c │ ├── panama.h │ ├── rc2.c │ ├── rc2.h │ ├── rijndael-128.c │ ├── rijndael-192.c │ ├── rijndael-256.c │ ├── rijndael.h │ ├── safer.h │ ├── safer128.c │ ├── safer64.c │ ├── saferplus.c │ ├── saferplus.h │ ├── serpent.c │ ├── serpent.h │ ├── tripledes.c │ ├── tripledes.h │ ├── twofish.c │ ├── twofish.h │ ├── wake.c │ ├── wake.h │ ├── xtea.c │ └── xtea.h └── modes │ ├── Makefile.am │ ├── Makefile.in │ ├── cbc.c │ ├── cbc.h │ ├── cfb.c │ ├── cfb.h │ ├── ctr.c │ ├── ctr.h │ ├── ecb.c │ ├── ecb.h │ ├── ncfb.c │ ├── ncfb.h │ ├── nofb.c │ ├── nofb.h │ ├── ofb.c │ ├── ofb.h │ ├── stream.c │ └── stream.h ├── src ├── Makefile.am ├── Makefile.in ├── aes_test.c └── cipher_test.c ├── stamp-h1 └── win32 ├── vc11 ├── libmcrypt.sln └── libmcrypt.vcxproj ├── vc14 ├── libmcrypt.sln └── libmcrypt.vcxproj ├── vc15 ├── libmcrypt.sln └── libmcrypt.vcxproj ├── vc6 ├── libmcrypt.dsp └── libmcrypt.dsw ├── vc8 ├── libmcrypt.sln └── libmcrypt.vcproj └── vc9 ├── libmcrypt.sln ├── libmcrypt.suo └── libmcrypt.vcproj /AUTHORS: -------------------------------------------------------------------------------- 1 | Author and maintainer of mcrypt is 2 | 3 | Nikos Mavroyanopoulos (nmav@hellug.gr) 4 | Arkadias 8, 5 | Halandri 15234, 6 | Greece 7 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | Basic Installation 2 | ================== 3 | 4 | These are generic installation instructions. 5 | 6 | The `configure' shell script attempts to guess correct values for 7 | various system-dependent variables used during compilation. It uses 8 | those values to create a `Makefile' in each directory of the package. 9 | It may also create one or more `.h' files containing system-dependent 10 | definitions. Finally, it creates a shell script `config.status' that 11 | you can run in the future to recreate the current configuration, a file 12 | `config.cache' that saves the results of its tests to speed up 13 | reconfiguring, and a file `config.log' containing compiler output 14 | (useful mainly for debugging `configure'). 15 | 16 | If you need to do unusual things to compile the package, please try 17 | to figure out how `configure' could check whether to do them, and mail 18 | diffs or instructions to the address given in the `README' so they can 19 | be considered for the next release. If at some point `config.cache' 20 | contains results you don't want to keep, you may remove or edit it. 21 | 22 | The file `configure.in' is used to create `configure' by a program 23 | called `autoconf'. You only need `configure.in' if you want to change 24 | it or regenerate `configure' using a newer version of `autoconf'. 25 | 26 | The simplest way to compile this package is: 27 | 28 | 1. `cd' to the directory containing the package's source code and type 29 | `./configure' to configure the package for your system. If you're 30 | using `csh' on an old version of System V, you might need to type 31 | `sh ./configure' instead to prevent `csh' from trying to execute 32 | `configure' itself. 33 | 34 | Running `configure' takes awhile. While running, it prints some 35 | messages telling which features it is checking for. 36 | 37 | 2. Type `make' to compile the package. 38 | 39 | 3. Optionally, type `make check' to run any self-tests that come with 40 | the package. 41 | 42 | 4. Type `make install' to install the programs and any data files and 43 | documentation. 44 | 45 | 5. You can remove the program binaries and object files from the 46 | source code directory by typing `make clean'. To also remove the 47 | files that `configure' created (so you can compile the package for 48 | a different kind of computer), type `make distclean'. There is 49 | also a `make maintainer-clean' target, but that is intended mainly 50 | for the package's developers. If you use it, you may have to get 51 | all sorts of other programs in order to regenerate files that came 52 | with the distribution. 53 | 54 | Compilers and Options 55 | ===================== 56 | 57 | Some systems require unusual options for compilation or linking that 58 | the `configure' script does not know about. You can give `configure' 59 | initial values for variables by setting them in the environment. Using 60 | a Bourne-compatible shell, you can do that on the command line like 61 | this: 62 | CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure 63 | 64 | Or on systems that have the `env' program, you can do it like this: 65 | env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure 66 | 67 | Compiling For Multiple Architectures 68 | ==================================== 69 | 70 | You can compile the package for more than one kind of computer at the 71 | same time, by placing the object files for each architecture in their 72 | own directory. To do this, you must use a version of `make' that 73 | supports the `VPATH' variable, such as GNU `make'. `cd' to the 74 | directory where you want the object files and executables to go and run 75 | the `configure' script. `configure' automatically checks for the 76 | source code in the directory that `configure' is in and in `..'. 77 | 78 | If you have to use a `make' that does not supports the `VPATH' 79 | variable, you have to compile the package for one architecture at a time 80 | in the source code directory. After you have installed the package for 81 | one architecture, use `make distclean' before reconfiguring for another 82 | architecture. 83 | 84 | Installation Names 85 | ================== 86 | 87 | By default, `make install' will install the package's files in 88 | `/usr/local/bin', `/usr/local/man', etc. You can specify an 89 | installation prefix other than `/usr/local' by giving `configure' the 90 | option `--prefix=PATH'. 91 | 92 | You can specify separate installation prefixes for 93 | architecture-specific files and architecture-independent files. If you 94 | give `configure' the option `--exec-prefix=PATH', the package will use 95 | PATH as the prefix for installing programs and libraries. 96 | Documentation and other data files will still use the regular prefix. 97 | 98 | In addition, if you use an unusual directory layout you can give 99 | options like `--bindir=PATH' to specify different values for particular 100 | kinds of files. Run `configure --help' for a list of the directories 101 | you can set and what kinds of files go in them. 102 | 103 | If the package supports it, you can cause programs to be installed 104 | with an extra prefix or suffix on their names by giving `configure' the 105 | option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. 106 | 107 | Optional Features 108 | ================= 109 | 110 | Some packages pay attention to `--enable-FEATURE' options to 111 | `configure', where FEATURE indicates an optional part of the package. 112 | They may also pay attention to `--with-PACKAGE' options, where PACKAGE 113 | is something like `gnu-as' or `x' (for the X Window System). The 114 | `README' should mention any `--enable-' and `--with-' options that the 115 | package recognizes. 116 | 117 | For packages that use the X Window System, `configure' can usually 118 | find the X include and library files automatically, but if it doesn't, 119 | you can use the `configure' options `--x-includes=DIR' and 120 | `--x-libraries=DIR' to specify their locations. 121 | 122 | Specifying the System Type 123 | ========================== 124 | 125 | There may be some features `configure' can not figure out 126 | automatically, but needs to determine by the type of host the package 127 | will run on. Usually `configure' can figure that out, but if it prints 128 | a message saying it can not guess the host type, give it the 129 | `--host=TYPE' option. TYPE can either be a short name for the system 130 | type, such as `sun4', or a canonical name with three fields: 131 | CPU-COMPANY-SYSTEM 132 | 133 | See the file `config.sub' for the possible values of each field. If 134 | `config.sub' isn't included in this package, then this package doesn't 135 | need to know the host type. 136 | 137 | If you are building compiler tools for cross-compiling, you can also 138 | use the `--target=TYPE' option to select the type of system they will 139 | produce code for and the `--build=TYPE' option to select the type of 140 | system on which you are compiling the package. 141 | 142 | Sharing Defaults 143 | ================ 144 | 145 | If you want to set default values for `configure' scripts to share, 146 | you can create a site shell script called `config.site' that gives 147 | default values for variables like `CC', `cache_file', and `prefix'. 148 | `configure' looks for `PREFIX/share/config.site' if it exists, then 149 | `PREFIX/etc/config.site' if it exists. Or, you can set the 150 | `CONFIG_SITE' environment variable to the location of the site script. 151 | A warning: not all `configure' scripts look for a site script. 152 | 153 | Operation Controls 154 | ================== 155 | 156 | `configure' recognizes the following options to control how it 157 | operates. 158 | 159 | `--cache-file=FILE' 160 | Use and save the results of the tests in FILE instead of 161 | `./config.cache'. Set FILE to `/dev/null' to disable caching, for 162 | debugging `configure'. 163 | 164 | `--help' 165 | Print a summary of the options to `configure', and exit. 166 | 167 | `--quiet' 168 | `--silent' 169 | `-q' 170 | Do not print messages saying which checks are being made. To 171 | suppress all normal output, redirect it to `/dev/null' (any error 172 | messages will still be shown). 173 | 174 | `--srcdir=DIR' 175 | Look for the package's source code in directory DIR. Usually 176 | `configure' can determine that directory automatically. 177 | 178 | `--version' 179 | Print the version of Autoconf used to generate the `configure' 180 | script, and exit. 181 | 182 | `configure' also accepts some other, not widely useful, options. 183 | -------------------------------------------------------------------------------- /KNOWN-BUGS: -------------------------------------------------------------------------------- 1 | - cast-256 and rc6 do not work properly on Alpha (64 bit) machines 2 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | 3 | INCLUDES = $(INCLTDL) 4 | EXTRA_DIST = KNOWN-BUGS THANKS NEWS libmcrypt.spec.in libmcrypt.spec COPYING.LIB 5 | DIST_SUBDIRS = libltdl modules include lib src doc 6 | SUBDIRS = $(LIBLTDL_DIR) modules include lib src doc 7 | 8 | ChangeLog: 9 | cvs2cl --utc --fsf -t -S --prune 10 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Libmcrypt is a thread-safe library providing a uniform interface 2 | to access several block and stream encryption algorithms. 3 | Check the manual page for more information on libmcrypt. 4 | 5 | Look at COPYING for license information and the individual files for more 6 | information. COPYING applies only for the mcrypt program and not the 7 | algorithms which most of them are public domain. 8 | 9 | A mailing list on mcrypt is mcrypt-dev@lists.hellug.gr 10 | Subscribe by visiting http://lists.hellug.gr/mailman/listinfo/mcrypt-dev 11 | 12 | ** 13 | ** Some hints: 14 | 15 | Since 2.5.4 libmcrypt does not use dynamic loading for the modules by default. 16 | All the algorithms and modes, are now included in the library. To enable 17 | the old dynamic loading behaviour use the --enable-dynamic-loading in the 18 | configure script. 19 | 20 | That way you can statically link the library and be 100% thread safe, 21 | since dlopen is not always thread safe. 22 | 23 | You can also enable dynamic loading and include some algorithms into the 24 | library. To include algorithms in the library use the 25 | --with-included-algos parameter in the configure script. 26 | Eg: ./configure --with-included-algos="rijndael-128 arcfour stream cbc cfb" 27 | 28 | 29 | -------------------------------------------------------------------------------- /THANKS: -------------------------------------------------------------------------------- 1 | mcrypt and libmcrypt was originaly created by Nikos Mavroyanopoulos , 2 | although many people contributed by sending bug reports, patches, and comments. 3 | 4 | - Sascha Schumann 5 | - Steve Underwood 6 | - Igor Schein 7 | - Alexander Demenshin 8 | - Koblinger Egmont 9 | - Larry Snyder 10 | - Robin Humble 11 | - Janusz A. Urbanowicz 12 | - Dan Stromberg 13 | - R Sriram 14 | - Robert Hanzlik 15 | - Lars Nordentoft 16 | - Don Sutherland 17 | - Salvatore Sanfilippo 18 | - Jerome Bertorelle 19 | - Andrew Libby 20 | - Jonathan Woolmington 21 | - Sami Farin 22 | - Barton C Massey 23 | - Derick Rethans 24 | - Phillip Oleson 25 | - Bernard Guillot 26 | - Stefan Hetzl 27 | - Gustavo Niemeyer 28 | - Germano Rizzo 29 | - Ilia A. 30 | - [and several others] 31 | 32 | The Designers of the algorithms: 33 | 34 | - DES: IBM & NSA 35 | - Lucifer (the algorithm that DES is based on): Roy Adler, Don Coppersmith, 36 | Horst Feistel, Edna Grossman, Alan Konheim, Carl Meyer, Bill Notz, 37 | Lynn Smith, Walt Tuchman and Bryant Tuckerman 38 | - CAST-128/CAST-256: Carlisle Adams 39 | - xTEA: David Wheeler & Roger M. Needham 40 | - 3-WAY: Joan Daemen 41 | - Blowfish: Bruce Schneier 42 | - Twofish: Bruce Schneier, Doug Whiting, John Kelsey, Chris Hall, David Wagner 43 | - GOST: A.Zabotin, G.P. Glazkov, and V.B. Isaeva 44 | - SAFER: J.L. Massey 45 | - RC2/RC4: Ron Rivest 46 | - LOKI97: Lawrie Brown, Josef Pieprzyk 47 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | - Documentation- documentation-... 2 | - Find test vectors for PANAMA and WAKE and check the implementation. 3 | -------------------------------------------------------------------------------- /acinclude.m4: -------------------------------------------------------------------------------- 1 | C_DEFUN([AM_SET_LIBTOOL_VARIABLE],[ 2 | LIBTOOL='$(SHELL) $(top_builddir)/libtool $1' 3 | ]) 4 | 5 | -------------------------------------------------------------------------------- /autoscan.log: -------------------------------------------------------------------------------- 1 | autoscan: warning: missing AC_CHECK_FUNCS([strchr]) wanted by: 2 | libltdl/ltdl.c:264 3 | libltdl/ltdl.c:267 4 | libltdl/ltdl.c:608 5 | libltdl/ltdl.c:1976 6 | libltdl/ltdl.c:3107 7 | autoscan: warning: missing AC_CHECK_FUNCS([strdup]) wanted by: 8 | lib/mcrypt_extra.c:54 9 | lib/mcrypt_extra.c:88 10 | lib/mcrypt_extra.c:146 11 | lib/mcrypt_extra.c:193 12 | lib/mcrypt_extra.c:250 13 | lib/mcrypt_modules.c:469 14 | lib/mcrypt_modules.c:547 15 | libltdl/ltdl.c:206 16 | libltdl/ltdl.c:209 17 | libltdl/ltdl.c:897 18 | libltdl/ltdl.c:1396 19 | autoscan: warning: missing AC_CHECK_FUNCS([strrchr]) wanted by: 20 | lib/mcrypt_extra.c:123 21 | lib/mcrypt_extra.c:229 22 | libltdl/ltdl.c:290 23 | libltdl/ltdl.c:293 24 | libltdl/ltdl.c:1193 25 | libltdl/ltdl.c:2243 26 | libltdl/ltdl.c:2498 27 | libltdl/ltdl.c:2590 28 | libltdl/ltdl.c:2613 29 | libltdl/ltdl.c:2785 30 | libltdl/ltdl.c:2963 31 | autoscan: warning: missing AC_CHECK_HEADERS([argz.h]) wanted by: 32 | libltdl/ltdl.c:86 33 | autoscan: warning: missing AC_CHECK_HEADERS([malloc.h]) wanted by: 34 | libltdl/ltdl.c:57 35 | autoscan: warning: missing AC_C_RESTRICT wanted by: 36 | modules/algorithms/panama.h:76 37 | modules/algorithms/panama.h:77 38 | modules/algorithms/panama.h:79 39 | modules/algorithms/panama.h:80 40 | modules/algorithms/panama.h:82 41 | modules/algorithms/panama.h:84 42 | modules/algorithms/panama.h:85 43 | modules/algorithms/panama.c:325 44 | modules/algorithms/panama.c:326 45 | modules/algorithms/panama.c:328 46 | modules/algorithms/panama.c:329 47 | modules/algorithms/panama.c:339 48 | modules/algorithms/panama.c:339 49 | modules/algorithms/panama.c:340 50 | modules/algorithms/panama.c:340 51 | modules/algorithms/panama.c:418 52 | modules/algorithms/panama.c:420 53 | modules/algorithms/panama.c:421 54 | modules/algorithms/panama.c:431 55 | modules/algorithms/panama.c:431 56 | modules/algorithms/panama.c:432 57 | modules/algorithms/panama.c:432 58 | autoscan: warning: missing AC_FUNC_CLOSEDIR_VOID wanted by: 59 | lib/mcrypt_extra.c:159 60 | lib/mcrypt_extra.c:265 61 | libltdl/ltdl.c:3175 62 | autoscan: warning: missing AC_FUNC_MALLOC wanted by: 63 | lib/mcrypt_modules.c:426 64 | lib/mcrypt_modules.c:997 65 | lib/xmemory.c:54 66 | modules/algorithms/cast-128.c:355 67 | modules/algorithms/safer64.c:347 68 | modules/algorithms/safer128.c:350 69 | modules/algorithms/loki97.c:436 70 | modules/algorithms/rc2.c:275 71 | modules/algorithms/wake.c:327 72 | modules/algorithms/wake.c:328 73 | modules/algorithms/blowfish-compat.c:621 74 | modules/algorithms/saferplus.c:641 75 | modules/algorithms/twofish.c:633 76 | modules/algorithms/tripledes.c:808 77 | modules/algorithms/rijndael-192.c:457 78 | modules/algorithms/serpent.c:921 79 | modules/algorithms/panama.c:647 80 | modules/algorithms/des.c:625 81 | modules/algorithms/3-way.c:305 82 | modules/algorithms/cast-256.c:534 83 | modules/algorithms/rijndael-256.c:459 84 | modules/algorithms/gost.c:375 85 | modules/algorithms/enigma.c:241 86 | modules/algorithms/rijndael-128.c:459 87 | modules/algorithms/arcfour.c:169 88 | modules/algorithms/blowfish.c:529 89 | modules/algorithms/xtea.c:195 90 | modules/modes/ofb.c:53 91 | modules/modes/ofb.c:56 92 | modules/modes/ncfb.c:53 93 | modules/modes/ncfb.c:56 94 | modules/modes/cfb.c:51 95 | modules/modes/cfb.c:54 96 | modules/modes/nofb.c:52 97 | modules/modes/nofb.c:55 98 | modules/modes/cbc.c:53 99 | modules/modes/cbc.c:54 100 | src/aes_test.c:88 101 | src/aes_test.c:121 102 | src/aes_test.c:168 103 | src/aes_test.c:210 104 | doc/example.c:30 105 | doc/example.c:88 106 | doc/example.c:93 107 | autoscan: warning: missing AC_FUNC_MEMCMP wanted by: 108 | modules/algorithms/wake.c:357 109 | modules/algorithms/twofish.c:655 110 | src/aes_test.c:93 111 | src/aes_test.c:132 112 | src/aes_test.c:141 113 | src/aes_test.c:173 114 | src/aes_test.c:183 115 | src/aes_test.c:216 116 | src/aes_test.c:225 117 | src/cipher_test.c:104 118 | autoscan: warning: missing AC_FUNC_REALLOC wanted by: 119 | lib/mcrypt_extra.c:82 120 | lib/mcrypt_extra.c:138 121 | lib/mcrypt_extra.c:188 122 | lib/mcrypt_extra.c:242 123 | lib/xmemory.c:79 124 | libltdl/ltdl.c:386 125 | libltdl/ltdl.c:887 126 | autoscan: warning: missing AC_HEADER_DIRENT wanted by: 127 | lib/libdefs.h:70 128 | libltdl/ltdl.c:69 129 | libltdl/ltdl.c:81 130 | libltdl/ltdl.c:78 131 | libltdl/ltdl.c:75 132 | autoscan: warning: missing AC_PROG_RANLIB wanted by: 133 | ltmain.sh:6857 134 | autoscan: warning: missing AC_STRUCT_TM wanted by: 135 | modules/algorithms/cast-256.c:348 136 | modules/algorithms/cast-256.c:349 137 | modules/algorithms/cast-256.c:350 138 | modules/algorithms/cast-256.c:351 139 | modules/algorithms/cast-256.c:352 140 | modules/algorithms/cast-256.c:353 141 | modules/algorithms/cast-256.c:354 142 | modules/algorithms/cast-256.c:355 143 | modules/algorithms/cast-256.c:362 144 | modules/algorithms/cast-256.c:381 145 | modules/algorithms/cast-256.c:387 146 | modules/algorithms/cast-256.c:390 147 | modules/algorithms/cast-256.c:396 148 | autoscan: warning: missing AC_TYPE_SIZE_T wanted by: 149 | lib/bzero.c:27 150 | lib/bzero.c:30 151 | lib/bzero.c:33 152 | lib/xmemory.h:1 153 | lib/xmemory.h:2 154 | lib/xmemory.h:2 155 | lib/xmemory.h:3 156 | lib/xmemory.h:4 157 | lib/bzero.h:1 158 | lib/xmemory.c:35 159 | lib/xmemory.c:50 160 | lib/xmemory.c:63 161 | lib/xmemory.c:63 162 | lib/xmemory.c:75 163 | lib/xmemory.c:88 164 | libltdl/ltdl.h:204 165 | libltdl/ltdl.h:205 166 | libltdl/ltdl.c:158 167 | libltdl/ltdl.c:159 168 | libltdl/ltdl.c:161 169 | libltdl/ltdl.c:164 170 | libltdl/ltdl.c:165 171 | libltdl/ltdl.c:166 172 | libltdl/ltdl.c:167 173 | libltdl/ltdl.c:324 174 | libltdl/ltdl.c:330 175 | libltdl/ltdl.c:332 176 | libltdl/ltdl.c:348 177 | libltdl/ltdl.c:354 178 | libltdl/ltdl.c:356 179 | libltdl/ltdl.c:388 180 | libltdl/ltdl.c:426 181 | libltdl/ltdl.c:427 182 | libltdl/ltdl.c:432 183 | libltdl/ltdl.c:434 184 | libltdl/ltdl.c:436 185 | libltdl/ltdl.c:469 186 | libltdl/ltdl.c:476 187 | libltdl/ltdl.c:478 188 | libltdl/ltdl.c:531 189 | libltdl/ltdl.c:537 190 | libltdl/ltdl.c:557 191 | libltdl/ltdl.c:558 192 | libltdl/ltdl.c:559 193 | libltdl/ltdl.c:588 194 | libltdl/ltdl.c:594 195 | libltdl/ltdl.c:633 196 | libltdl/ltdl.c:639 197 | libltdl/ltdl.c:874 198 | libltdl/ltdl.c:885 199 | libltdl/ltdl.c:1670 200 | libltdl/ltdl.c:1695 201 | libltdl/ltdl.c:1699 202 | libltdl/ltdl.c:1702 203 | libltdl/ltdl.c:1710 204 | libltdl/ltdl.c:1967 205 | libltdl/ltdl.c:1968 206 | libltdl/ltdl.c:2070 207 | libltdl/ltdl.c:2071 208 | libltdl/ltdl.c:2122 209 | libltdl/ltdl.c:2162 210 | libltdl/ltdl.c:2163 211 | libltdl/ltdl.c:2186 212 | libltdl/ltdl.c:2413 213 | libltdl/ltdl.c:2499 214 | libltdl/ltdl.c:2593 215 | libltdl/ltdl.c:2623 216 | libltdl/ltdl.c:2640 217 | libltdl/ltdl.c:2952 218 | libltdl/ltdl.c:3035 219 | libltdl/ltdl.c:3061 220 | libltdl/ltdl.c:3085 221 | libltdl/ltdl.c:3090 222 | libltdl/ltdl.c:3092 223 | libltdl/ltdl.c:3093 224 | libltdl/ltdl.c:3152 225 | libltdl/ltdl.c:3197 226 | libltdl/ltdl.c:3342 227 | libltdl/ltdl.c:3451 228 | -------------------------------------------------------------------------------- /buildconf: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | aclocal && \ 4 | libtoolize -c --force && \ 5 | autoheader && \ 6 | automake -a -c 7 | autoconf 8 | 9 | -------------------------------------------------------------------------------- /config.h: -------------------------------------------------------------------------------- 1 | /* config.h. Generated by configure. */ 2 | /* config.h.in. Generated from configure.in by autoheader. */ 3 | 4 | /* Define to 1 if the `closedir' function returns void instead of `int'. */ 5 | /* #undef CLOSEDIR_VOID */ 6 | 7 | /* dlmutex */ 8 | /* #undef DLMUTEX */ 9 | 10 | /* Define to 1 if you have the header file. */ 11 | #define HAVE_ARGZ_H 1 12 | 13 | /* Define to 1 if you have the `bcopy */ 14 | /* #undef HAVE_BCOPY */ 15 | 16 | /* Define to 1 if you have the header file. */ 17 | #define HAVE_BYTESWAP_H 1 18 | 19 | /* Define to 1 if you have the `bzero' function. */ 20 | #define HAVE_BZERO 1 21 | 22 | /* Define to 1 if you have the header file. */ 23 | #define HAVE_DIRENT_H 1 24 | 25 | /* Define to 1 if you have the header file. */ 26 | #define HAVE_DLFCN_H 1 27 | 28 | /* Define to 1 if you have the header file. */ 29 | #define HAVE_ENDIAN_H 1 30 | 31 | /* Define to 1 if you have the header file. */ 32 | #define HAVE_INTTYPES_H 1 33 | 34 | /* Define to 1 if you have the `dmalloc' library (-ldmalloc). */ 35 | /* #undef HAVE_LIBDMALLOC */ 36 | 37 | /* Define to 1 if you have the header file. */ 38 | #define HAVE_LIMITS_H 1 39 | 40 | /* Define to 1 if your system has a GNU libc compatible `malloc' function, and 41 | to 0 otherwise. */ 42 | #define HAVE_MALLOC 1 43 | 44 | /* Define to 1 if you have the header file. */ 45 | #define HAVE_MALLOC_H 1 46 | 47 | /* Define to 1 if you have the `memmove' function. */ 48 | #define HAVE_MEMMOVE 1 49 | 50 | /* Define to 1 if you have the header file. */ 51 | #define HAVE_MEMORY_H 1 52 | 53 | /* Define to 1 if you have the `memset' function. */ 54 | #define HAVE_MEMSET 1 55 | 56 | /* Define to 1 if you have the `mlock' function. */ 57 | #define HAVE_MLOCK 1 58 | 59 | /* Define to 1 if you have the header file, and it defines `DIR'. */ 60 | /* #undef HAVE_NDIR_H */ 61 | 62 | /* Define to 1 if you have the `readdir */ 63 | /* #undef HAVE_READDIR */ 64 | 65 | /* Define to 1 if you have the `readdir_r' function. */ 66 | #define HAVE_READDIR_R 1 67 | 68 | /* Define to 1 if your system has a GNU libc compatible `realloc' function, 69 | and to 0 otherwise. */ 70 | #define HAVE_REALLOC 1 71 | 72 | /* Define to 1 if you have the header file. */ 73 | #define HAVE_STDINT_H 1 74 | 75 | /* Define to 1 if you have the header file. */ 76 | #define HAVE_STDLIB_H 1 77 | 78 | /* Define to 1 if you have the `strchr' function. */ 79 | #define HAVE_STRCHR 1 80 | 81 | /* Define to 1 if you have the `strdup' function. */ 82 | #define HAVE_STRDUP 1 83 | 84 | /* Define to 1 if you have the header file. */ 85 | #define HAVE_STRINGS_H 1 86 | 87 | /* Define to 1 if you have the header file. */ 88 | #define HAVE_STRING_H 1 89 | 90 | /* Define to 1 if you have the `strrchr' function. */ 91 | #define HAVE_STRRCHR 1 92 | 93 | /* Define to 1 if you have the header file, and it defines `DIR'. 94 | */ 95 | /* #undef HAVE_SYS_DIR_H */ 96 | 97 | /* Define to 1 if you have the header file. */ 98 | /* #undef HAVE_SYS_ENDIAN_H */ 99 | 100 | /* Define to 1 if you have the header file. */ 101 | #define HAVE_SYS_MMAN_H 1 102 | 103 | /* Define to 1 if you have the header file, and it defines `DIR'. 104 | */ 105 | /* #undef HAVE_SYS_NDIR_H */ 106 | 107 | /* Define to 1 if you have the header file. */ 108 | #define HAVE_SYS_STAT_H 1 109 | 110 | /* Define to 1 if you have the header file. */ 111 | #define HAVE_SYS_TYPES_H 1 112 | 113 | /* Define to 1 if you have the header file. */ 114 | #define HAVE_UNISTD_H 1 115 | 116 | /* Name of package */ 117 | #define PACKAGE "libmcrypt" 118 | 119 | /* Define to the address where bug reports for this package should be sent. */ 120 | #define PACKAGE_BUGREPORT "" 121 | 122 | /* Define to the full name of this package. */ 123 | #define PACKAGE_NAME "" 124 | 125 | /* Define to the full name and version of this package. */ 126 | #define PACKAGE_STRING "" 127 | 128 | /* Define to the one symbol short name of this package. */ 129 | #define PACKAGE_TARNAME "" 130 | 131 | /* Define to the version of this package. */ 132 | #define PACKAGE_VERSION "" 133 | 134 | /* The size of a `unsigned char', as computed by sizeof. */ 135 | #define SIZEOF_UNSIGNED_CHAR 1 136 | 137 | /* The size of a `unsigned int', as computed by sizeof. */ 138 | #define SIZEOF_UNSIGNED_INT 4 139 | 140 | /* The size of a `unsigned long int', as computed by sizeof. */ 141 | #define SIZEOF_UNSIGNED_LONG_INT 4 142 | 143 | /* The size of a `unsigned short int', as computed by sizeof. */ 144 | #define SIZEOF_UNSIGNED_SHORT_INT 2 145 | 146 | /* Define to 1 if you have the ANSI C header files. */ 147 | #define STDC_HEADERS 1 148 | 149 | /* dmalloc */ 150 | /* #undef USE_DMALLOC */ 151 | 152 | /* use libltdl */ 153 | /* #undef USE_LTDL */ 154 | 155 | /* Version number of package */ 156 | #define VERSION "2.5.8" 157 | 158 | /* whether win32 environment */ 159 | /* #undef WIN32 */ 160 | 161 | /* Define to 1 if your processor stores words with the most significant byte 162 | first (like Motorola and SPARC, unlike Intel and VAX). */ 163 | /* #undef WORDS_BIGENDIAN */ 164 | 165 | /* Define to empty if `const' does not conform to ANSI C. */ 166 | /* #undef const */ 167 | 168 | /* Define to `__inline__' or `__inline' if that's what the C compiler 169 | calls it, or to nothing if 'inline' is not supported under any name. */ 170 | #ifndef __cplusplus 171 | /* #undef inline */ 172 | #endif 173 | 174 | /* Define to rpl_malloc if the replacement function should be used. */ 175 | /* #undef malloc */ 176 | 177 | /* Define to rpl_realloc if the replacement function should be used. */ 178 | /* #undef realloc */ 179 | -------------------------------------------------------------------------------- /config.h.in: -------------------------------------------------------------------------------- 1 | /* config.h.in. Generated from configure.in by autoheader. */ 2 | 3 | /* Define to 1 if the `closedir' function returns void instead of `int'. */ 4 | #undef CLOSEDIR_VOID 5 | 6 | /* dlmutex */ 7 | #undef DLMUTEX 8 | 9 | /* Define to 1 if you have the header file. */ 10 | #undef HAVE_ARGZ_H 11 | 12 | /* Define to 1 if you have the `bcopy */ 13 | #undef HAVE_BCOPY 14 | 15 | /* Define to 1 if you have the header file. */ 16 | #undef HAVE_BYTESWAP_H 17 | 18 | /* Define to 1 if you have the `bzero' function. */ 19 | #undef HAVE_BZERO 20 | 21 | /* Define to 1 if you have the header file. */ 22 | #undef HAVE_DIRENT_H 23 | 24 | /* Define to 1 if you have the header file. */ 25 | #undef HAVE_DLFCN_H 26 | 27 | /* Define to 1 if you have the header file. */ 28 | #undef HAVE_ENDIAN_H 29 | 30 | /* Define to 1 if you have the header file. */ 31 | #undef HAVE_INTTYPES_H 32 | 33 | /* Define to 1 if you have the `dmalloc' library (-ldmalloc). */ 34 | #undef HAVE_LIBDMALLOC 35 | 36 | /* Define to 1 if you have the header file. */ 37 | #undef HAVE_LIMITS_H 38 | 39 | /* Define to 1 if your system has a GNU libc compatible `malloc' function, and 40 | to 0 otherwise. */ 41 | #undef HAVE_MALLOC 42 | 43 | /* Define to 1 if you have the header file. */ 44 | #undef HAVE_MALLOC_H 45 | 46 | /* Define to 1 if you have the `memmove' function. */ 47 | #undef HAVE_MEMMOVE 48 | 49 | /* Define to 1 if you have the header file. */ 50 | #undef HAVE_MEMORY_H 51 | 52 | /* Define to 1 if you have the `memset' function. */ 53 | #undef HAVE_MEMSET 54 | 55 | /* Define to 1 if you have the `mlock' function. */ 56 | #undef HAVE_MLOCK 57 | 58 | /* Define to 1 if you have the header file, and it defines `DIR'. */ 59 | #undef HAVE_NDIR_H 60 | 61 | /* Define to 1 if you have the `readdir */ 62 | #undef HAVE_READDIR 63 | 64 | /* Define to 1 if you have the `readdir_r' function. */ 65 | #undef HAVE_READDIR_R 66 | 67 | /* Define to 1 if your system has a GNU libc compatible `realloc' function, 68 | and to 0 otherwise. */ 69 | #undef HAVE_REALLOC 70 | 71 | /* Define to 1 if you have the header file. */ 72 | #undef HAVE_STDINT_H 73 | 74 | /* Define to 1 if you have the header file. */ 75 | #undef HAVE_STDLIB_H 76 | 77 | /* Define to 1 if you have the `strchr' function. */ 78 | #undef HAVE_STRCHR 79 | 80 | /* Define to 1 if you have the `strdup' function. */ 81 | #undef HAVE_STRDUP 82 | 83 | /* Define to 1 if you have the header file. */ 84 | #undef HAVE_STRINGS_H 85 | 86 | /* Define to 1 if you have the header file. */ 87 | #undef HAVE_STRING_H 88 | 89 | /* Define to 1 if you have the `strrchr' function. */ 90 | #undef HAVE_STRRCHR 91 | 92 | /* Define to 1 if you have the header file, and it defines `DIR'. 93 | */ 94 | #undef HAVE_SYS_DIR_H 95 | 96 | /* Define to 1 if you have the header file. */ 97 | #undef HAVE_SYS_ENDIAN_H 98 | 99 | /* Define to 1 if you have the header file. */ 100 | #undef HAVE_SYS_MMAN_H 101 | 102 | /* Define to 1 if you have the header file, and it defines `DIR'. 103 | */ 104 | #undef HAVE_SYS_NDIR_H 105 | 106 | /* Define to 1 if you have the header file. */ 107 | #undef HAVE_SYS_STAT_H 108 | 109 | /* Define to 1 if you have the header file. */ 110 | #undef HAVE_SYS_TYPES_H 111 | 112 | /* Define to 1 if you have the header file. */ 113 | #undef HAVE_UNISTD_H 114 | 115 | /* Name of package */ 116 | #undef PACKAGE 117 | 118 | /* Define to the address where bug reports for this package should be sent. */ 119 | #undef PACKAGE_BUGREPORT 120 | 121 | /* Define to the full name of this package. */ 122 | #undef PACKAGE_NAME 123 | 124 | /* Define to the full name and version of this package. */ 125 | #undef PACKAGE_STRING 126 | 127 | /* Define to the one symbol short name of this package. */ 128 | #undef PACKAGE_TARNAME 129 | 130 | /* Define to the version of this package. */ 131 | #undef PACKAGE_VERSION 132 | 133 | /* The size of a `unsigned char', as computed by sizeof. */ 134 | #undef SIZEOF_UNSIGNED_CHAR 135 | 136 | /* The size of a `unsigned int', as computed by sizeof. */ 137 | #undef SIZEOF_UNSIGNED_INT 138 | 139 | /* The size of a `unsigned long int', as computed by sizeof. */ 140 | #undef SIZEOF_UNSIGNED_LONG_INT 141 | 142 | /* The size of a `unsigned short int', as computed by sizeof. */ 143 | #undef SIZEOF_UNSIGNED_SHORT_INT 144 | 145 | /* Define to 1 if you have the ANSI C header files. */ 146 | #undef STDC_HEADERS 147 | 148 | /* dmalloc */ 149 | #undef USE_DMALLOC 150 | 151 | /* use libltdl */ 152 | #undef USE_LTDL 153 | 154 | /* Version number of package */ 155 | #undef VERSION 156 | 157 | /* whether win32 environment */ 158 | #undef WIN32 159 | 160 | /* Define to 1 if your processor stores words with the most significant byte 161 | first (like Motorola and SPARC, unlike Intel and VAX). */ 162 | #undef WORDS_BIGENDIAN 163 | 164 | /* Define to empty if `const' does not conform to ANSI C. */ 165 | #undef const 166 | 167 | /* Define to `__inline__' or `__inline' if that's what the C compiler 168 | calls it, or to nothing if 'inline' is not supported under any name. */ 169 | #ifndef __cplusplus 170 | #undef inline 171 | #endif 172 | 173 | /* Define to rpl_malloc if the replacement function should be used. */ 174 | #undef malloc 175 | 176 | /* Define to rpl_realloc if the replacement function should be used. */ 177 | #undef realloc 178 | -------------------------------------------------------------------------------- /configure.in: -------------------------------------------------------------------------------- 1 | dnl Process this file with autoconf to produce a configure script. 2 | AC_PREREQ(2.59) 3 | AC_INIT(lib/mcrypt.c) 4 | 5 | LIBMCRYPT_MAJOR_VERSION=2 6 | LIBMCRYPT_MINOR_VERSION=5 7 | LIBMCRYPT_MICRO_VERSION=8 8 | LIBMCRYPT_VERSION=$LIBMCRYPT_MAJOR_VERSION.$LIBMCRYPT_MINOR_VERSION.$LIBMCRYPT_MICRO_VERSION 9 | 10 | LIBMCRYPT_MOST_RECENT_INTERFACE=8 11 | LIBMCRYPT_CURRENT_INTERFACE_IMPLEMENTATION_NUMBER=$LIBMCRYPT_MICRO_VERSION 12 | LIBMCRYPT_OLDEST_INTERFACE=4 13 | 14 | AC_CANONICAL_SYSTEM 15 | AM_INIT_AUTOMAKE(libmcrypt, $LIBMCRYPT_VERSION) 16 | AM_CONFIG_HEADER(config.h) 17 | 18 | AM_MAINTAINER_MODE 19 | 20 | AC_PROG_MAKE_SET 21 | 22 | AC_PROG_CXX 23 | AC_PROG_CC 24 | AC_PROG_CPP 25 | AC_PROG_INSTALL 26 | AC_PROG_LN_S 27 | AC_PROG_MAKE_SET 28 | 29 | case "$host_os" in 30 | *w32*) 31 | LDFLAGS="$LDFLAGS -no-undefined" 32 | AC_DEFINE( WIN32, 1, [whether win32 environment]) 33 | ;; 34 | *win32*) 35 | LDFLAGS="$LDFLAGS -no-undefined" 36 | AC_DEFINE( WIN32, 1, [whether win32 environment]) 37 | ;; 38 | cygwin*) 39 | LDFLAGS="$LDFLAGS -no-undefined" 40 | AC_DEFINE( WIN32, 1, [whether win32 environment]) 41 | ;; 42 | esac 43 | 44 | dnl Checks for programs. 45 | AC_PROG_INSTALL 46 | AC_PROG_LN_S 47 | 48 | 49 | opt_maintainer_mode=no 50 | AC_MSG_CHECKING([whether in maintanance mode]) 51 | AC_ARG_ENABLE(maintainer-mode, 52 | [ --enable-maintainer-mode enable maintainer mode], 53 | opt_maintainer_mode=$enableval) 54 | AC_MSG_RESULT($opt_maintainer_mode) 55 | 56 | opt_dmalloc_mode=no 57 | AC_MSG_CHECKING([whether in dmalloc mode]) 58 | AC_ARG_ENABLE(dmalloc-mode, 59 | [ --enable-dmalloc-mode enable dmalloc mode], 60 | opt_dmalloc_mode=$enableval) 61 | AC_MSG_RESULT($opt_dmalloc_mode) 62 | 63 | 64 | if test x$ac_cv_prog_gcc = xyes; then 65 | if test x$opt_maintainer_mode = xyes; then 66 | CFLAGS=" -ggdb3 -O2 -Wall -Wpointer-arith" 67 | fi 68 | 69 | if test x$opt_dmalloc_mode = xyes; then 70 | AC_CHECK_LIB( dmalloc, main) 71 | AC_DEFINE(USE_DMALLOC, 1, [dmalloc]) 72 | fi 73 | fi 74 | 75 | opt_enable_ltdl=no 76 | AC_MSG_CHECKING([whether to enable dynamic module loading]) 77 | AC_ARG_ENABLE(dynamic-loading, 78 | [ --enable-dynamic-loading enable dynamic module loading], 79 | opt_enable_ltdl=$enableval) 80 | AC_MSG_RESULT($opt_enable_ltdl) 81 | 82 | MCRYPT_MODE_MODULES="cbc cfb ctr ecb ncfb nofb ofb stream" 83 | MCRYPT_ALGORITHM_MODULES="threeway cast-128 gost rijndael-128 safer-sk64 twofish \ 84 | arcfour cast-256 loki97 rijndael-192 saferplus wake \ 85 | blowfish-compat des rijndael-256 serpent xtea \ 86 | blowfish enigma rc2 safer-sk128 tripledes" 87 | 88 | 89 | if test "x$opt_enable_ltdl" != xno; then 90 | touch lib/mcrypt_internal.h 91 | 92 | AC_CHECK_LIB( ltdl, lt_dlmutex_register, AC_DEFINE(DLMUTEX, 1, [dlmutex])) 93 | 94 | dnl AC_LIBLTDL_CONVENIENCE 95 | AC_LIBLTDL_INSTALLABLE 96 | AC_SUBST(INCLTDL) 97 | AC_SUBST(LIBLTDL) 98 | LIBLTDL_DIR=libltdl 99 | AC_SUBST(LIBLTDL_DIR) 100 | 101 | AC_CONFIG_SUBDIRS(libltdl) 102 | AC_DISABLE_STATIC 103 | 104 | AC_DEFINE(USE_LTDL, 1, [use libltdl]) 105 | 106 | if test x$LIBLTDL = x; then 107 | : 108 | else 109 | LTLIBS="-lltdl" 110 | fi 111 | opt_include_algos=no 112 | 113 | # create the names of the .la libraries to install 114 | for i in $MCRYPT_ALGORITHM_MODULES 115 | do \ 116 | INSTALL_ALGORITHM_MODULES="$INSTALL_ALGORITHM_MODULES $i.la" 117 | done 118 | 119 | for i in $MCRYPT_MODE_MODULES 120 | do \ 121 | INSTALL_MODE_MODULES="$INSTALL_MODE_MODULES $i.la" 122 | done 123 | 124 | AC_SUBST(INSTALL_ALGORITHM_MODULES) 125 | AC_SUBST(INSTALL_MODE_MODULES) 126 | 127 | else 128 | for i in $MCRYPT_ALGORITHM_MODULES 129 | do \ 130 | NOINSTALL_ALGORITHM_MODULES="$NOINSTALL_ALGORITHM_MODULES $i.la" 131 | done 132 | 133 | for i in $MCRYPT_MODE_MODULES 134 | do \ 135 | NOINSTALL_MODE_MODULES="$NOINSTALL_MODE_MODULES $i.la" 136 | done 137 | 138 | AC_SUBST(NOINSTALL_ALGORITHM_MODULES) 139 | AC_SUBST(NOINSTALL_MODE_MODULES) 140 | 141 | opt_include_algos="$MCRYPT_MODE_MODULES $MCRYPT_ALGORITHM_MODULES" 142 | echo "***" 143 | echo "*** Dynamic loading has been disabled" 144 | fi 145 | 146 | AC_MSG_CHECKING([which algorithms to include into library]) 147 | AC_ARG_WITH(included-algos, 148 | [ --with-included-algos=algo1,algo2,... include algorithms/modes into the library], 149 | touch lib/mcrypt_internal.h 150 | opt_include_algos=$withval) 151 | 152 | if test "x$opt_include_algos" = xyes; then 153 | opt_include_algos="" 154 | fi 155 | if test "x$opt_include_algos" = xno; then 156 | opt_include_algos="" 157 | fi 158 | 159 | 160 | EXTRA_OBJECTS="" 161 | ALG=`echo -n $opt_include_algos|sed "s/,/ /g"|sed "s/\n/ /g"` 162 | for i in $ALG 163 | do \ 164 | test -f modules/algorithms/$i.c && EXTRA_OBJECTS="$EXTRA_OBJECTS ../modules/algorithms/$i.lo" 165 | test -f modules/modes/$i.c && EXTRA_OBJECTS="$EXTRA_OBJECTS ../modules/modes/$i.lo" 166 | done 167 | 168 | AC_MSG_RESULT($opt_include_algos) 169 | 170 | 171 | EXTRA_ALGOS=$ALG 172 | AC_SUBST(EXTRA_ALGOS) 173 | AC_SUBST(EXTRA_OBJECTS) 174 | 175 | AC_SUBST(LIBMCRYPT_MAJOR_VERSION) 176 | AC_SUBST(LIBMCRYPT_MINOR_VERSION) 177 | AC_SUBST(LIBMCRYPT_MICRO_VERSION) 178 | AC_SUBST(LIBMCRYPT_VERSION) 179 | 180 | AC_SUBST(LIBMCRYPT_MOST_RECENT_INTERFACE) 181 | AC_SUBST(LIBMCRYPT_CURRENT_INTERFACE_IMPLEMENTATION_NUMBER) 182 | AC_SUBST(LIBMCRYPT_OLDEST_INTERFACE) 183 | 184 | LT_CURRENT=$LIBMCRYPT_MOST_RECENT_INTERFACE 185 | LT_REVISION=$LIBMCRYPT_CURRENT_INTERFACE_IMPLEMENTATION_NUMBER 186 | LT_AGE=`expr $LIBMCRYPT_MOST_RECENT_INTERFACE - $LIBMCRYPT_OLDEST_INTERFACE` 187 | AC_SUBST(LT_CURRENT) 188 | AC_SUBST(LT_REVISION) 189 | AC_SUBST(LT_AGE) 190 | 191 | AC_HEADER_DIRENT 192 | AC_HEADER_STDC 193 | AC_C_INLINE 194 | AC_C_CONST 195 | 196 | AC_CHECK_HEADERS([argz.h byteswap.h dirent.h dlfcn.h endian.h malloc.h memory.h]) 197 | AC_CHECK_HEADERS([stdlib.h string.h strings.h]) 198 | AC_CHECK_HEADERS([sys/endian.h sys/types.h sys/mman.h]) 199 | AC_CHECK_HEADERS([limits.h unistd.h]) 200 | 201 | AC_FUNC_CLOSEDIR_VOID 202 | AC_FUNC_MALLOC 203 | AC_FUNC_MEMCMP 204 | AC_FUNC_REALLOC 205 | 206 | AC_CHECK_FUNCS([bzero memmove memset mlock readdir_r strchr strdup strrchr]) 207 | AC_CHECK_FUNCS([readdir,,]) 208 | AC_CHECK_FUNCS([bcopy,,]) 209 | 210 | dnl Checks for libraries. 211 | AC_C_BIGENDIAN 212 | AC_CHECK_SIZEOF(unsigned long int, 4) 213 | AC_CHECK_SIZEOF(unsigned int, 4) 214 | AC_CHECK_SIZEOF(unsigned short int, 2) 215 | AC_CHECK_SIZEOF(unsigned char, 1) 216 | 217 | AC_LIBTOOL_DLOPEN 218 | AC_LIBTOOL_WIN32_DLL 219 | 220 | 221 | 222 | AM_PROG_LIBTOOL 223 | AC_SUBST(LIBTOOL_DEPS) 224 | 225 | 226 | LIBMCRYPT_LIBS="$LIBS -L${libdir} -lmcrypt $LTLIBS" 227 | LIBMCRYPT_CFLAGS="-I${includedir}" 228 | AC_SUBST(LIBMCRYPT_LIBS) 229 | AC_SUBST(LIBMCRYPT_CFLAGS) 230 | 231 | AC_OUTPUT_COMMANDS([ 232 | chmod +x lib/libmcrypt-config 233 | ]) 234 | 235 | AC_CONFIG_FILES([Makefile 236 | libmcrypt.spec 237 | lib/Makefile 238 | doc/Makefile 239 | src/Makefile 240 | include/mutils/mcrypt.h 241 | include/Makefile 242 | modules/Makefile 243 | modules/modes/Makefile 244 | modules/algorithms/Makefile 245 | lib/libmcrypt-config]) 246 | AC_OUTPUT 247 | 248 | -------------------------------------------------------------------------------- /doc/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = README.key example.c mcrypt.3 README.xtea README.config 2 | man_MANS = mcrypt.3 3 | -------------------------------------------------------------------------------- /doc/README.config: -------------------------------------------------------------------------------- 1 | If you want to find the libmcrypt library in other projects 2 | using autoconf/aclocal, put in your 3 | 4 | aclocal.m4: 5 | include(libmcrypt.m4) 6 | 7 | configure.in: 8 | AM_PATH_LIBMCRYPT( 2.4.11,, AC_MSG_ERROR([[*** libmcrypt was not found]])) 9 | 10 | 11 | these macros define LIBMCRYPT_LIBS and LIBMCRYPT_CFLAGS. 12 | If Libmcrypt version 2.2.x is found then LIBMCRYPT22 is defined, 13 | otherwise LIBMCRYPT24. 14 | 15 | -------------------------------------------------------------------------------- /doc/README.key: -------------------------------------------------------------------------------- 1 | Mcrypt 2.1 was insecure (vulnerable to brute force attack for weak keys) 2 | because it just used the plainkey as it was given by the user as algorithm's 3 | key. The solution seems to be a function which tranforms the 4 | key given by the user to a real -random looking- key. 5 | 6 | There are many functions that may convert a password or a passphrase to 7 | a key. Most of them use hash algorithms. You can find some implementations 8 | at the libmhash package at: http://mhash.sourceforge.net 9 | -------------------------------------------------------------------------------- /doc/README.xtea: -------------------------------------------------------------------------------- 1 | 2 | 3 | The xTEA algorithm may not be right implemented. There are two different 4 | behaved implementations, because the specification is not clear. I assumed 5 | that the C code in the specification is right, so in mcrypt xtea behaves 6 | exactly as the code shown in the specification. The different approach 7 | is the code in ftp.funet.fi which seems to be more rational than the 8 | code in the specification. But since there is no indication of the author of 9 | that code I decided not to adopt this version, and I assumed that the 10 | C specification is right. 11 | 12 | Nikos 13 | 14 | -------------------------------------------------------------------------------- /doc/example.c: -------------------------------------------------------------------------------- 1 | /* First example: Encrypts stdin to stdout using TWOFISH with 128 bit key and CFB */ 2 | 3 | #include 4 | #include 5 | #include 6 | /* #include */ 7 | 8 | main() { 9 | 10 | MCRYPT td; 11 | int i; 12 | char *key; 13 | char password[20]; 14 | char block_buffer; 15 | char *IV; 16 | int keysize=19; /* 128 bits */ 17 | 18 | key=calloc(1, keysize); 19 | strcpy(password, "A_large_key"); 20 | 21 | /* Generate the key using the password */ 22 | /* mhash_keygen( KEYGEN_MCRYPT, MHASH_MD5, key, keysize, NULL, 0, password, strlen(password)); 23 | */ 24 | memmove( key, password, strlen(password)); 25 | 26 | td = mcrypt_module_open("twofish", NULL, "cfb", NULL); 27 | if (td==MCRYPT_FAILED) { 28 | return 1; 29 | } 30 | IV = malloc(mcrypt_enc_get_iv_size(td)); 31 | 32 | /* Put random data in IV. Note these are not real random data, 33 | * consider using /dev/random or /dev/urandom. 34 | */ 35 | 36 | /* srand(time(0)); */ 37 | for (i=0; i< mcrypt_enc_get_iv_size( td); i++) { 38 | IV[i]=rand(); 39 | } 40 | 41 | i=mcrypt_generic_init( td, key, keysize, IV); 42 | if (i<0) { 43 | mcrypt_perror(i); 44 | return 1; 45 | } 46 | 47 | /* Encryption in CFB is performed in bytes */ 48 | while ( fread (&block_buffer, 1, 1, stdin) == 1 ) { 49 | mcrypt_generic (td, &block_buffer, 1); 50 | 51 | /* Comment above and uncomment this to decrypt */ 52 | /* mdecrypt_generic (td, &block_buffer, 1); */ 53 | 54 | fwrite ( &block_buffer, 1, 1, stdout); 55 | } 56 | mcrypt_generic_deinit(td); 57 | 58 | mcrypt_module_close(td); 59 | 60 | return 0; 61 | 62 | } 63 | 64 | #if 0 65 | /* Second Example: encrypts using CBC and SAFER+ with 192 bits key */ 66 | 67 | #include 68 | #include 69 | #include 70 | 71 | main() { 72 | 73 | MCRYPT td; 74 | int i; 75 | char *key; /* created using mcrypt_gen_key */ 76 | char *block_buffer; 77 | char *IV; 78 | int blocksize; 79 | int keysize = 24; /* 192 bits == 24 bytes */ 80 | 81 | 82 | key = calloc(1, keysize); 83 | strcpy(key, "A_large_and_random_key"); 84 | 85 | td = mcrypt_module_open("saferplus", NULL, "cbc", NULL); 86 | 87 | blocksize = mcrypt_enc_get_block_size(td); 88 | block_buffer = malloc(blocksize); 89 | /* but unfortunately this does not fill all the key so the rest bytes are 90 | * padded with zeros. Try to use large keys or convert them with mcrypt_gen_key(). 91 | */ 92 | 93 | IV=malloc(mcrypt_enc_get_iv_size(td)); 94 | 95 | /* Put random data in IV. Note these are not real random data, 96 | * consider using /dev/random or /dev/urandom. 97 | */ 98 | 99 | /* srand(time(0)); */ 100 | for (i=0; i < mcrypt_enc_get_iv_size(td); i++) { 101 | IV[i]=rand(); 102 | } 103 | 104 | mcrypt_generic_init ( td key, keysize, IV); 105 | 106 | /* Encryption in CBC is performed in blocks */ 107 | while ( fread (block_buffer, 1, blocksize, stdin) == blocksize ) { 108 | mcrypt_generic (td, block_buffer, blocksize); 109 | /* mdecrypt_generic (td, block_buffer, blocksize); */ 110 | fwrite ( block_buffer, 1, blocksize, stdout); 111 | } 112 | mcrypt_generic_end (td); 113 | 114 | return 0; 115 | 116 | } 117 | 118 | #endif 119 | -------------------------------------------------------------------------------- /include/Makefile.am: -------------------------------------------------------------------------------- 1 | nobase_include_HEADERS = mcrypt.h mutils/mcrypt.h 2 | 3 | dist-hook: 4 | find $(distdir) -name CVS -o -name .cvsignore | xargs rm -rf 5 | 6 | -------------------------------------------------------------------------------- /include/mcrypt.h: -------------------------------------------------------------------------------- 1 | #if !defined(__MCRYPT_H) 2 | #define __MCRYPT_H 3 | 4 | #include 5 | 6 | #endif 7 | 8 | -------------------------------------------------------------------------------- /include/mutils/mcrypt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1998,1999,2002 Nikos Mavroyanopoulos 3 | * 4 | * Encryption/decryption library. This library is free software; 5 | * you can redistribute it and/or modify it under the terms of the 6 | * GNU Library General Public License as published by the Free Software 7 | * Foundation; either version 2 of the License, or (at your option) any 8 | * later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Library General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Library General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | * Boston, MA 02111-1307, USA. 19 | */ 20 | 21 | 22 | #define MCRYPT_API_VERSION 20021217 23 | 24 | #define LIBMCRYPT_VERSION "2.5.8" 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | /* Definitions 30 | */ 31 | #define MCRYPT_FAILED 0x0 32 | 33 | struct CRYPT_STREAM; 34 | typedef struct CRYPT_STREAM *MCRYPT; 35 | 36 | /* generic - high level functions. 37 | */ 38 | MCRYPT mcrypt_module_open(char *algorithm, 39 | char *a_directory, char *mode, 40 | char *m_directory); 41 | int mcrypt_module_close(MCRYPT td); 42 | 43 | /* returns 0 if the library has not been compiled with 44 | * dynamic module support. 45 | */ 46 | int mcrypt_module_support_dynamic(void); 47 | 48 | /* returns thread descriptor */ 49 | 50 | int mcrypt_generic_init(const MCRYPT td, void *key, int lenofkey, 51 | void *IV); 52 | int mcrypt_generic_deinit(const MCRYPT td); 53 | int mcrypt_generic_end(const MCRYPT td); 54 | int mdecrypt_generic(MCRYPT td, void *plaintext, int len); 55 | int mcrypt_generic(MCRYPT td, void *plaintext, int len); 56 | 57 | /* extra functions */ 58 | 59 | int mcrypt_enc_set_state(MCRYPT td, void *st, int size); 60 | int mcrypt_enc_get_state(MCRYPT td, void *st, int *size); /* only 61 | * for block algorithms and certain modes like cbc 62 | * ncfb etc. 63 | */ 64 | int (mcrypt_enc_self_test) (MCRYPT); 65 | int (mcrypt_enc_get_block_size) (MCRYPT); 66 | int (mcrypt_enc_get_iv_size) (MCRYPT); 67 | int (mcrypt_enc_get_key_size) (MCRYPT); 68 | 69 | /* If this is a block algorithm returns 1 70 | */ 71 | int (mcrypt_enc_is_block_algorithm) (MCRYPT); 72 | 73 | /* If the mode operates in blocks returns 1 74 | */ 75 | int (mcrypt_enc_is_block_mode) (MCRYPT); 76 | 77 | /* If the mode is for block algorithms it returns 1 78 | */ 79 | int (mcrypt_enc_is_block_algorithm_mode) (MCRYPT td); 80 | int mcrypt_enc_mode_has_iv(MCRYPT td); 81 | 82 | /* Return a const string containing the name of the algorithm/mode 83 | */ 84 | char *(mcrypt_enc_get_algorithms_name) (MCRYPT td); 85 | char *(mcrypt_enc_get_modes_name) (MCRYPT td); 86 | 87 | int *mcrypt_enc_get_supported_key_sizes(MCRYPT td, int *len); 88 | 89 | 90 | char **mcrypt_list_algorithms(char *libdir, int *size); 91 | char **mcrypt_list_modes(char *libdir, int *size); 92 | 93 | /* Frees the memory allocated by the mcrypt_list_xxx() functions. 94 | */ 95 | void mcrypt_free_p(char **p, int size); 96 | void mcrypt_free(void *ptr); 97 | 98 | /* If mcrypt_xxx functions return an error code, and you supply this 99 | * to this function, it will print a human readable message 100 | */ 101 | void mcrypt_perror(int err); 102 | const char* mcrypt_strerror(int err); 103 | 104 | /* Self test for the specified algorithm 105 | */ 106 | int mcrypt_module_self_test(char *algorithm, char *a_directory); 107 | 108 | int mcrypt_module_is_block_algorithm(char *algorithm, 109 | char *a_directory); 110 | int mcrypt_module_is_block_algorithm_mode(char *mode, 111 | char *m_directory); 112 | int mcrypt_module_is_block_mode(char *mode, char *m_directory); 113 | 114 | int mcrypt_module_get_algo_key_size(char *algorithm, 115 | char *a_directory); 116 | int mcrypt_module_get_algo_block_size(char *algorithm, 117 | char *a_directory); 118 | 119 | int *mcrypt_module_get_algo_supported_key_sizes(char *algorithm, 120 | char *a_directory, 121 | int *len); 122 | 123 | /* Checks the version of the specified module 124 | */ 125 | int mcrypt_module_algorithm_version(char *algorithm, 126 | char *a_directory); 127 | int mcrypt_module_mode_version(char *mode, char *a_directory); 128 | 129 | 130 | /* for multithreaded applications: 131 | */ 132 | int mcrypt_mutex_register ( void (*mutex_lock)(void) , 133 | void (*mutex_unlock)(void), 134 | void (*set_error)(const char*), 135 | const char* (*get_error)(void)); 136 | 137 | const char * 138 | mcrypt_check_version( const char *); 139 | 140 | /* These definitions exist in order to ease the access to 141 | * mcrypt_module_init(). 142 | */ 143 | 144 | /* Algorithms */ 145 | #define MCRYPT_BLOWFISH "blowfish" 146 | #define MCRYPT_DES "des" 147 | #define MCRYPT_3DES "tripledes" 148 | #define MCRYPT_3WAY "threeway" 149 | #define MCRYPT_GOST "gost" 150 | #define MCRYPT_SAFER_SK64 "safer-sk64" 151 | #define MCRYPT_SAFER_SK128 "safer-sk128" 152 | #define MCRYPT_CAST_128 "cast-128" 153 | #define MCRYPT_XTEA "xtea" 154 | #define MCRYPT_RC2 "rc2" 155 | #define MCRYPT_TWOFISH "twofish" 156 | #define MCRYPT_CAST_256 "cast-256" 157 | #define MCRYPT_SAFERPLUS "saferplus" 158 | #define MCRYPT_LOKI97 "loki97" 159 | #define MCRYPT_SERPENT "serpent" 160 | #define MCRYPT_RIJNDAEL_128 "rijndael-128" 161 | #define MCRYPT_RIJNDAEL_192 "rijndael-192" 162 | #define MCRYPT_RIJNDAEL_256 "rijndael-256" 163 | #define MCRYPT_ENIGMA "enigma" 164 | #define MCRYPT_ARCFOUR "arcfour" 165 | #define MCRYPT_WAKE "wake" 166 | 167 | /* Modes */ 168 | #define MCRYPT_CBC "cbc" 169 | #define MCRYPT_ECB "ecb" 170 | #define MCRYPT_CFB "cfb" 171 | #define MCRYPT_OFB "ofb" 172 | #define MCRYPT_nOFB "nofb" 173 | #define MCRYPT_STREAM "stream" 174 | 175 | #ifdef __cplusplus 176 | } 177 | #endif 178 | -------------------------------------------------------------------------------- /include/mutils/mcrypt.h.in: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1998,1999,2002 Nikos Mavroyanopoulos 3 | * 4 | * Encryption/decryption library. This library is free software; 5 | * you can redistribute it and/or modify it under the terms of the 6 | * GNU Library General Public License as published by the Free Software 7 | * Foundation; either version 2 of the License, or (at your option) any 8 | * later version. 9 | * 10 | * This library is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * Library General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU Library General Public 16 | * License along with this library; if not, write to the 17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 | * Boston, MA 02111-1307, USA. 19 | */ 20 | 21 | 22 | #define MCRYPT_API_VERSION 20021217 23 | 24 | #define LIBMCRYPT_VERSION "@VERSION@" 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | /* Definitions 30 | */ 31 | #define MCRYPT_FAILED 0x0 32 | 33 | struct CRYPT_STREAM; 34 | typedef struct CRYPT_STREAM *MCRYPT; 35 | 36 | /* generic - high level functions. 37 | */ 38 | MCRYPT mcrypt_module_open(char *algorithm, 39 | char *a_directory, char *mode, 40 | char *m_directory); 41 | int mcrypt_module_close(MCRYPT td); 42 | 43 | /* returns 0 if the library has not been compiled with 44 | * dynamic module support. 45 | */ 46 | int mcrypt_module_support_dynamic(void); 47 | 48 | /* returns thread descriptor */ 49 | 50 | int mcrypt_generic_init(const MCRYPT td, void *key, int lenofkey, 51 | void *IV); 52 | int mcrypt_generic_deinit(const MCRYPT td); 53 | int mcrypt_generic_end(const MCRYPT td); 54 | int mdecrypt_generic(MCRYPT td, void *plaintext, int len); 55 | int mcrypt_generic(MCRYPT td, void *plaintext, int len); 56 | 57 | /* extra functions */ 58 | 59 | int mcrypt_enc_set_state(MCRYPT td, void *st, int size); 60 | int mcrypt_enc_get_state(MCRYPT td, void *st, int *size); /* only 61 | * for block algorithms and certain modes like cbc 62 | * ncfb etc. 63 | */ 64 | int (mcrypt_enc_self_test) (MCRYPT); 65 | int (mcrypt_enc_get_block_size) (MCRYPT); 66 | int (mcrypt_enc_get_iv_size) (MCRYPT); 67 | int (mcrypt_enc_get_key_size) (MCRYPT); 68 | 69 | /* If this is a block algorithm returns 1 70 | */ 71 | int (mcrypt_enc_is_block_algorithm) (MCRYPT); 72 | 73 | /* If the mode operates in blocks returns 1 74 | */ 75 | int (mcrypt_enc_is_block_mode) (MCRYPT); 76 | 77 | /* If the mode is for block algorithms it returns 1 78 | */ 79 | int (mcrypt_enc_is_block_algorithm_mode) (MCRYPT td); 80 | int mcrypt_enc_mode_has_iv(MCRYPT td); 81 | 82 | /* Return a const string containing the name of the algorithm/mode 83 | */ 84 | char *(mcrypt_enc_get_algorithms_name) (MCRYPT td); 85 | char *(mcrypt_enc_get_modes_name) (MCRYPT td); 86 | 87 | int *mcrypt_enc_get_supported_key_sizes(MCRYPT td, int *len); 88 | 89 | 90 | char **mcrypt_list_algorithms(char *libdir, int *size); 91 | char **mcrypt_list_modes(char *libdir, int *size); 92 | 93 | /* Frees the memory allocated by the mcrypt_list_xxx() functions. 94 | */ 95 | void mcrypt_free_p(char **p, int size); 96 | void mcrypt_free(void *ptr); 97 | 98 | /* If mcrypt_xxx functions return an error code, and you supply this 99 | * to this function, it will print a human readable message 100 | */ 101 | void mcrypt_perror(int err); 102 | const char* mcrypt_strerror(int err); 103 | 104 | /* Self test for the specified algorithm 105 | */ 106 | int mcrypt_module_self_test(char *algorithm, char *a_directory); 107 | 108 | int mcrypt_module_is_block_algorithm(char *algorithm, 109 | char *a_directory); 110 | int mcrypt_module_is_block_algorithm_mode(char *mode, 111 | char *m_directory); 112 | int mcrypt_module_is_block_mode(char *mode, char *m_directory); 113 | 114 | int mcrypt_module_get_algo_key_size(char *algorithm, 115 | char *a_directory); 116 | int mcrypt_module_get_algo_block_size(char *algorithm, 117 | char *a_directory); 118 | 119 | int *mcrypt_module_get_algo_supported_key_sizes(char *algorithm, 120 | char *a_directory, 121 | int *len); 122 | 123 | /* Checks the version of the specified module 124 | */ 125 | int mcrypt_module_algorithm_version(char *algorithm, 126 | char *a_directory); 127 | int mcrypt_module_mode_version(char *mode, char *a_directory); 128 | 129 | 130 | /* for multithreaded applications: 131 | */ 132 | int mcrypt_mutex_register ( void (*mutex_lock)(void) , 133 | void (*mutex_unlock)(void), 134 | void (*set_error)(const char*), 135 | const char* (*get_error)(void)); 136 | 137 | const char * 138 | mcrypt_check_version( const char *); 139 | 140 | /* These definitions exist in order to ease the access to 141 | * mcrypt_module_init(). 142 | */ 143 | 144 | /* Algorithms */ 145 | #define MCRYPT_BLOWFISH "blowfish" 146 | #define MCRYPT_DES "des" 147 | #define MCRYPT_3DES "tripledes" 148 | #define MCRYPT_3WAY "threeway" 149 | #define MCRYPT_GOST "gost" 150 | #define MCRYPT_SAFER_SK64 "safer-sk64" 151 | #define MCRYPT_SAFER_SK128 "safer-sk128" 152 | #define MCRYPT_CAST_128 "cast-128" 153 | #define MCRYPT_XTEA "xtea" 154 | #define MCRYPT_RC2 "rc2" 155 | #define MCRYPT_TWOFISH "twofish" 156 | #define MCRYPT_CAST_256 "cast-256" 157 | #define MCRYPT_SAFERPLUS "saferplus" 158 | #define MCRYPT_LOKI97 "loki97" 159 | #define MCRYPT_SERPENT "serpent" 160 | #define MCRYPT_RIJNDAEL_128 "rijndael-128" 161 | #define MCRYPT_RIJNDAEL_192 "rijndael-192" 162 | #define MCRYPT_RIJNDAEL_256 "rijndael-256" 163 | #define MCRYPT_ENIGMA "enigma" 164 | #define MCRYPT_ARCFOUR "arcfour" 165 | #define MCRYPT_WAKE "wake" 166 | 167 | /* Modes */ 168 | #define MCRYPT_CBC "cbc" 169 | #define MCRYPT_ECB "ecb" 170 | #define MCRYPT_CFB "cfb" 171 | #define MCRYPT_OFB "ofb" 172 | #define MCRYPT_nOFB "nofb" 173 | #define MCRYPT_STREAM "stream" 174 | 175 | #ifdef __cplusplus 176 | } 177 | #endif 178 | -------------------------------------------------------------------------------- /install-sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # install - install a program, script, or datafile 4 | # This comes from X11R5 (mit/util/scripts/install.sh). 5 | # 6 | # Copyright 1991 by the Massachusetts Institute of Technology 7 | # 8 | # Permission to use, copy, modify, distribute, and sell this software and its 9 | # documentation for any purpose is hereby granted without fee, provided that 10 | # the above copyright notice appear in all copies and that both that 11 | # copyright notice and this permission notice appear in supporting 12 | # documentation, and that the name of M.I.T. not be used in advertising or 13 | # publicity pertaining to distribution of the software without specific, 14 | # written prior permission. M.I.T. makes no representations about the 15 | # suitability of this software for any purpose. It is provided "as is" 16 | # without express or implied warranty. 17 | # 18 | # Calling this script install-sh is preferred over install.sh, to prevent 19 | # `make' implicit rules from creating a file called install from it 20 | # when there is no Makefile. 21 | # 22 | # This script is compatible with the BSD install script, but was written 23 | # from scratch. It can only install one file at a time, a restriction 24 | # shared with many OS's install programs. 25 | 26 | 27 | # set DOITPROG to echo to test this script 28 | 29 | # Don't use :- since 4.3BSD and earlier shells don't like it. 30 | doit="${DOITPROG-}" 31 | 32 | 33 | # put in absolute paths if you don't have them in your path; or use env. vars. 34 | 35 | mvprog="${MVPROG-mv}" 36 | cpprog="${CPPROG-cp}" 37 | chmodprog="${CHMODPROG-chmod}" 38 | chownprog="${CHOWNPROG-chown}" 39 | chgrpprog="${CHGRPPROG-chgrp}" 40 | stripprog="${STRIPPROG-strip}" 41 | rmprog="${RMPROG-rm}" 42 | mkdirprog="${MKDIRPROG-mkdir}" 43 | 44 | transformbasename="" 45 | transform_arg="" 46 | instcmd="$mvprog" 47 | chmodcmd="$chmodprog 0755" 48 | chowncmd="" 49 | chgrpcmd="" 50 | stripcmd="" 51 | rmcmd="$rmprog -f" 52 | mvcmd="$mvprog" 53 | src="" 54 | dst="" 55 | dir_arg="" 56 | 57 | while [ x"$1" != x ]; do 58 | case $1 in 59 | -c) instcmd="$cpprog" 60 | shift 61 | continue;; 62 | 63 | -d) dir_arg=true 64 | shift 65 | continue;; 66 | 67 | -m) chmodcmd="$chmodprog $2" 68 | shift 69 | shift 70 | continue;; 71 | 72 | -o) chowncmd="$chownprog $2" 73 | shift 74 | shift 75 | continue;; 76 | 77 | -g) chgrpcmd="$chgrpprog $2" 78 | shift 79 | shift 80 | continue;; 81 | 82 | -s) stripcmd="$stripprog" 83 | shift 84 | continue;; 85 | 86 | -t=*) transformarg=`echo $1 | sed 's/-t=//'` 87 | shift 88 | continue;; 89 | 90 | -b=*) transformbasename=`echo $1 | sed 's/-b=//'` 91 | shift 92 | continue;; 93 | 94 | *) if [ x"$src" = x ] 95 | then 96 | src=$1 97 | else 98 | # this colon is to work around a 386BSD /bin/sh bug 99 | : 100 | dst=$1 101 | fi 102 | shift 103 | continue;; 104 | esac 105 | done 106 | 107 | if [ x"$src" = x ] 108 | then 109 | echo "install: no input file specified" 110 | exit 1 111 | else 112 | true 113 | fi 114 | 115 | if [ x"$dir_arg" != x ]; then 116 | dst=$src 117 | src="" 118 | 119 | if [ -d $dst ]; then 120 | instcmd=: 121 | chmodcmd="" 122 | else 123 | instcmd=mkdir 124 | fi 125 | else 126 | 127 | # Waiting for this to be detected by the "$instcmd $src $dsttmp" command 128 | # might cause directories to be created, which would be especially bad 129 | # if $src (and thus $dsttmp) contains '*'. 130 | 131 | if [ -f $src -o -d $src ] 132 | then 133 | true 134 | else 135 | echo "install: $src does not exist" 136 | exit 1 137 | fi 138 | 139 | if [ x"$dst" = x ] 140 | then 141 | echo "install: no destination specified" 142 | exit 1 143 | else 144 | true 145 | fi 146 | 147 | # If destination is a directory, append the input filename; if your system 148 | # does not like double slashes in filenames, you may need to add some logic 149 | 150 | if [ -d $dst ] 151 | then 152 | dst="$dst"/`basename $src` 153 | else 154 | true 155 | fi 156 | fi 157 | 158 | ## this sed command emulates the dirname command 159 | dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` 160 | 161 | # Make sure that the destination directory exists. 162 | # this part is taken from Noah Friedman's mkinstalldirs script 163 | 164 | # Skip lots of stat calls in the usual case. 165 | if [ ! -d "$dstdir" ]; then 166 | defaultIFS=' 167 | ' 168 | IFS="${IFS-${defaultIFS}}" 169 | 170 | oIFS="${IFS}" 171 | # Some sh's can't handle IFS=/ for some reason. 172 | IFS='%' 173 | set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` 174 | IFS="${oIFS}" 175 | 176 | pathcomp='' 177 | 178 | while [ $# -ne 0 ] ; do 179 | pathcomp="${pathcomp}${1}" 180 | shift 181 | 182 | if [ ! -d "${pathcomp}" ] ; 183 | then 184 | $mkdirprog "${pathcomp}" 185 | else 186 | true 187 | fi 188 | 189 | pathcomp="${pathcomp}/" 190 | done 191 | fi 192 | 193 | if [ x"$dir_arg" != x ] 194 | then 195 | $doit $instcmd $dst && 196 | 197 | if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi && 198 | if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi && 199 | if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi && 200 | if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi 201 | else 202 | 203 | # If we're going to rename the final executable, determine the name now. 204 | 205 | if [ x"$transformarg" = x ] 206 | then 207 | dstfile=`basename $dst` 208 | else 209 | dstfile=`basename $dst $transformbasename | 210 | sed $transformarg`$transformbasename 211 | fi 212 | 213 | # don't allow the sed command to completely eliminate the filename 214 | 215 | if [ x"$dstfile" = x ] 216 | then 217 | dstfile=`basename $dst` 218 | else 219 | true 220 | fi 221 | 222 | # Make a temp file name in the proper directory. 223 | 224 | dsttmp=$dstdir/#inst.$$# 225 | 226 | # Move or copy the file name to the temp name 227 | 228 | $doit $instcmd $src $dsttmp && 229 | 230 | trap "rm -f ${dsttmp}" 0 && 231 | 232 | # and set any options; do chmod last to preserve setuid bits 233 | 234 | # If any of these fail, we abort the whole thing. If we want to 235 | # ignore errors from any of these, just make sure not to ignore 236 | # errors from the above "$doit $instcmd $src $dsttmp" command. 237 | 238 | if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi && 239 | if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi && 240 | if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi && 241 | if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi && 242 | 243 | # Now rename the file to the real destination. 244 | 245 | $doit $rmcmd -f $dstdir/$dstfile && 246 | $doit $mvcmd $dsttmp $dstdir/$dstfile 247 | 248 | fi && 249 | 250 | 251 | exit 0 252 | -------------------------------------------------------------------------------- /lib/Makefile.am: -------------------------------------------------------------------------------- 1 | DEFS = @DEFS@ -DLIBDIR=\"$(libdir)/@PACKAGE@/\" 2 | INCLUDES = -I. -I.. $(INCLTDL) -I../modules/algorithms -I../modules/modes 3 | EXTRA_DIST = libdefs.h bzero.h xmemory.h mcrypt_modules.h mcrypt_internal.h \ 4 | libmcrypt.sym win32_comp.h mcrypt.h.in libmcrypt-config.in libmcrypt.m4 5 | lib_LTLIBRARIES = libmcrypt.la 6 | 7 | libmcrypt_la_SOURCES = mcrypt_extra.c mcrypt.c bzero.c xmemory.c mcrypt_modules.c win32_comp.c mcrypt_threads.c \ 8 | mcrypt_symb.c 9 | 10 | libmcrypt_la_LDFLAGS = \ 11 | -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \ 12 | -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \ 13 | -export-symbols libmcrypt.sym @LIBLTDL@ 14 | libmcrypt_la_LIBADD = @EXTRA_OBJECTS@ 15 | 16 | m4datadir = $(datadir)/aclocal 17 | m4data_DATA = libmcrypt.m4 18 | bin_SCRIPTS = libmcrypt-config 19 | 20 | mcrypt_symb.c: mcrypt_internal.h 21 | @echo "#include \"mcrypt_internal.h\"" > mcrypt_symb.c 22 | @echo "" >> mcrypt_symb.c 23 | @echo "/* This is automatically created. Don't touch... */" >> mcrypt_symb.c 24 | @echo "" >> mcrypt_symb.c 25 | -@for i in $(EXTRA_ALGOS); do \ 26 | if test -f ../modules/algorithms/$$i.c; then cat ../modules/algorithms/$$i.c 2>/dev/null|grep define|grep LTX|awk '{print "extern "$$3"();";}' >> mcrypt_symb.c 2>/dev/null; fi; \ 27 | if test -f ../modules/modes/$$i.c; then cat ../modules/modes/$$i.c 2>/dev/null|grep define|grep LTX|awk '{print "extern "$$3"();";}' >> mcrypt_symb.c 2>/dev/null; fi; \ 28 | done 29 | @echo "" >> mcrypt_symb.c 30 | @echo "const mcrypt_preloaded mps[] = {" >> mcrypt_symb.c 31 | -@for i in $(EXTRA_ALGOS); do \ 32 | if test -f ../modules/modes/$$i.c; then echo " {\"$$i\", NULL}, " >> mcrypt_symb.c 2>/dev/null; fi; \ 33 | if test -f ../modules/algorithms/$$i.c; then echo " {\"$$i\", NULL}, " >> mcrypt_symb.c 2>/dev/null; fi; \ 34 | if test -f ../modules/algorithms/$$i.c; then cat ../modules/algorithms/$$i.c 2>/dev/null|grep define|grep LTX|awk '{print "\t{\""$$3"\", "$$3"},";}' >> mcrypt_symb.c 2>/dev/null; fi; \ 35 | if test -f ../modules/modes/$$i.c; then cat ../modules/modes/$$i.c 2>/dev/null|grep define|grep LTX|awk '{print "\t{\""$$3"\", "$$3"},";}' >> mcrypt_symb.c 2>/dev/null; fi; \ 36 | done 37 | @echo " {NULL, NULL}" >> mcrypt_symb.c 38 | @echo "};" >> mcrypt_symb.c 39 | 40 | clean-local: 41 | -rm mcrypt_symb.c 42 | -------------------------------------------------------------------------------- /lib/autoscan.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/winlibs/libmcrypt/1e93cbe97a463a2c0c62338d607b17fe011eb77e/lib/autoscan.log -------------------------------------------------------------------------------- /lib/bzero.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1998,1999 Nikos Mavroyanopoulos 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | /* $Id: bzero.c,v 1.1.1.1 2000/05/22 13:07:51 nmav Exp $ */ 21 | 22 | #ifndef LIBDEFS_H 23 | # define LIBDEFS_H 24 | # include 25 | #endif 26 | 27 | void Bzero(void *s, size_t n) 28 | { 29 | #ifdef HAVE_MEMSET 30 | memset( (void*) s, '\0', (size_t) n); 31 | #else 32 | # ifdef HAVE_BZERO 33 | bzero( (void*) s, (size_t) n); 34 | # else 35 | char *stmp = s; 36 | int i; 37 | 38 | for (i = 0; i < n; i++) 39 | stmp[i] = '\0'; 40 | 41 | # endif 42 | #endif 43 | } 44 | -------------------------------------------------------------------------------- /lib/bzero.h: -------------------------------------------------------------------------------- 1 | void Bzero(void* s, size_t n); 2 | -------------------------------------------------------------------------------- /lib/configure.scan: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | AC_PREREQ(2.59) 5 | AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS) 6 | AC_CONFIG_SRCDIR([mcrypt_extra.c]) 7 | AC_CONFIG_HEADER([config.h]) 8 | 9 | # Checks for programs. 10 | AC_PROG_CC 11 | 12 | # Checks for libraries. 13 | 14 | # Checks for header files. 15 | AC_HEADER_DIRENT 16 | AC_HEADER_STDC 17 | AC_CHECK_HEADERS([stdlib.h string.h strings.h unistd.h]) 18 | 19 | # Checks for typedefs, structures, and compiler characteristics. 20 | AC_C_CONST 21 | AC_C_INLINE 22 | AC_TYPE_SIZE_T 23 | 24 | # Checks for library functions. 25 | AC_FUNC_CLOSEDIR_VOID 26 | AC_FUNC_MALLOC 27 | AC_FUNC_REALLOC 28 | AC_CHECK_FUNCS([bzero memmove memset strdup strrchr]) 29 | 30 | AC_CONFIG_FILES([Makefile]) 31 | AC_OUTPUT 32 | -------------------------------------------------------------------------------- /lib/libdefs.h: -------------------------------------------------------------------------------- 1 | #ifndef ILIBDEFS_H 2 | # define ILIBDEFS_H 3 | 4 | /* MAX_THREADS removed by Steve Underwood 1999/12/10 */ 5 | 6 | #ifdef HAVE_CONFIG_H 7 | # include 8 | #endif 9 | 10 | 11 | #ifdef HAVE_SYS_TYPES_H 12 | # include 13 | #endif 14 | 15 | #include "win32_comp.h" 16 | 17 | #ifdef USE_LTDL 18 | # include 19 | #else 20 | # define lt_dlexit() 0 21 | # define lt_dlinit() 0 22 | # define lt_dlclose(x) 0 23 | # define lt_dlsym(x,y) 0 24 | # define lt_dlhandle void* 25 | # define lt_ptr_t void* 26 | # define lt_dlerror() 0 27 | # define lt_dlopenext(x) 0 28 | # define lt_dlsetsearchpath(x) 0 29 | #endif 30 | 31 | #ifdef STDC_HEADERS 32 | # include 33 | # include 34 | # include 35 | # include 36 | #endif 37 | 38 | #ifdef HAVE_STRINGS_H 39 | # include 40 | #endif 41 | 42 | #ifdef HAVE_UNISTD_H 43 | # include 44 | #endif 45 | 46 | #ifdef HAVE_SYS_ENDIAN_H 47 | # include 48 | #endif 49 | 50 | #ifdef HAVE_MACHINE_ENDIAN_H 51 | # include 52 | #endif 53 | 54 | #ifdef HAVE_ENDIAN_H 55 | # include 56 | #endif 57 | 58 | #ifdef HAVE_BYTESWAP_H 59 | # include 60 | #endif 61 | 62 | 63 | #ifdef HAVE_READDIR_R 64 | #ifndef _POSIX_C_SOURCE 65 | # define _POSIX_C_SOURCE 199506L 66 | #endif 67 | #endif 68 | 69 | #ifdef HAVE_DIRENT_H 70 | # include 71 | #endif 72 | 73 | #if SIZEOF_UNSIGNED_LONG_INT == 4 74 | typedef unsigned long word32; 75 | typedef signed long sword32; 76 | #elif SIZEOF_UNSIGNED_INT == 4 77 | typedef unsigned int word32; 78 | typedef signed int sword32; 79 | #else 80 | # error "Cannot find a 32 bit integer in your system, sorry." 81 | #endif 82 | 83 | #if SIZEOF_UNSIGNED_INT == 2 84 | typedef unsigned int word16; 85 | #elif SIZEOF_UNSIGNED_SHORT_INT == 2 86 | typedef unsigned short word16; 87 | #else 88 | # error "Cannot find a 16 bit integer in your system, sorry." 89 | #endif 90 | 91 | #if SIZEOF_UNSIGNED_CHAR == 1 92 | typedef unsigned char byte; 93 | #else 94 | # error "Cannot find an 8 bit char in your system, sorry." 95 | #endif 96 | 97 | #ifndef HAVE_MEMMOVE 98 | # ifdef HAVE_BCOPY 99 | # define memmove(d, s, n) bcopy ((s), (d), (n)) 100 | # else 101 | # error "Neither memmove nor bcopy exists on your system." 102 | # endif 103 | #endif 104 | 105 | #ifdef USE_DMALLOC 106 | # include 107 | #endif 108 | 109 | #endif /* LIBDEFS_H */ 110 | 111 | -------------------------------------------------------------------------------- /lib/libmcrypt-config.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | prefix=@prefix@ 4 | exec_prefix=@exec_prefix@ 5 | exec_prefix_set=no 6 | 7 | mcrypt_libs="@LIBMCRYPT_LIBS@" 8 | mcrypt_cflags="@LIBMCRYPT_CFLAGS@" 9 | 10 | 11 | usage() 12 | { 13 | cat <&2 27 | fi 28 | 29 | while test $# -gt 0; do 30 | case "$1" in 31 | -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;; 32 | *) optarg= ;; 33 | esac 34 | 35 | case $1 in 36 | --prefix=*) 37 | prefix=$optarg 38 | if test $exec_prefix_set = no ; then 39 | exec_prefix=$optarg 40 | fi 41 | ;; 42 | --prefix) 43 | echo_prefix=yes 44 | ;; 45 | --exec-prefix=*) 46 | exec_prefix=$optarg 47 | exec_prefix_set=yes 48 | ;; 49 | --exec-prefix) 50 | echo_exec_prefix=yes 51 | ;; 52 | --version) 53 | echo "@VERSION@" 54 | exit 0 55 | ;; 56 | --cflags) 57 | echo_cflags=yes 58 | ;; 59 | --libs) 60 | echo_libs=yes 61 | ;; 62 | *) 63 | usage 1 1>&2 64 | ;; 65 | esac 66 | shift 67 | done 68 | 69 | if test "$echo_prefix" = "yes"; then 70 | echo $prefix 71 | fi 72 | 73 | if test "$echo_exec_prefix" = "yes"; then 74 | echo $exec_prefix 75 | fi 76 | 77 | if test "$echo_cflags" = "yes"; then 78 | if test "@includedir@" != "/usr/include" ; then 79 | includes="-I@includedir@" 80 | for i in $mcrypt_cflags ; do 81 | if test "$i" = "-I@includedir@" ; then 82 | includes="" 83 | fi 84 | done 85 | fi 86 | echo $includes $mcrypt_cflags 87 | fi 88 | 89 | if test "$echo_libs" = "yes"; then 90 | echo ${mcrypt_libs} 91 | fi 92 | 93 | 94 | -------------------------------------------------------------------------------- /lib/libmcrypt.m4: -------------------------------------------------------------------------------- 1 | dnl Autoconf macros for libmcrypt 2 | dnl $id$ 3 | 4 | # This script detects libmcrypt version and defines 5 | # LIBMCRYPT_CFLAGS, LIBMCRYPT_LIBS 6 | # and LIBMCRYPT24 or LIBMCRYPT22 depending on libmcrypt version 7 | # found. 8 | 9 | # Modified for LIBMCRYPT -- nmav 10 | # Configure paths for LIBGCRYPT 11 | # Shamelessly stolen from the one of XDELTA by Owen Taylor 12 | # Werner Koch 99-12-09 13 | 14 | dnl AM_PATH_LIBMCRYPT([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND ]]]) 15 | dnl Test for libmcrypt, and define LIBMCRYPT_CFLAGS and LIBMCRYPT_LIBS 16 | dnl 17 | AC_DEFUN([AM_PATH_LIBMCRYPT], 18 | [dnl 19 | dnl Get the cflags and libraries from the libmcrypt-config script 20 | dnl 21 | AC_ARG_WITH(libmcrypt-prefix, 22 | [ --with-libmcrypt-prefix=PFX Prefix where libmcrypt is installed (optional)], 23 | libmcrypt_config_prefix="$withval", libmcrypt_config_prefix="") 24 | 25 | if test x$libmcrypt_config_prefix != x ; then 26 | libmcrypt_config_args="$libmcrypt_config_args --prefix=$libmcrypt_config_prefix" 27 | if test x${LIBMCRYPT_CONFIG+set} != xset ; then 28 | LIBMCRYPT_CONFIG=$libmcrypt_config_prefix/bin/libmcrypt-config 29 | fi 30 | fi 31 | 32 | AC_PATH_PROG(LIBMCRYPT_CONFIG, libmcrypt-config, no) 33 | min_libmcrypt_version=ifelse([$1], ,2.4.0,$1) 34 | AC_MSG_CHECKING(for libmcrypt - version >= $min_libmcrypt_version) 35 | no_libmcrypt="" 36 | if test "$LIBMCRYPT_CONFIG" = "no" ; then 37 | dnl libmcrypt-config was not found (pre 2.4.11 versions) 38 | dnl Try to detect libmcrypt version 39 | AC_TRY_RUN([ 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | int 46 | main () 47 | { 48 | #if MCRYPT_API_VERSION <= 19991015 49 | /* version 2.2 */ 50 | return 0; 51 | #else 52 | /* version 2.4 */ 53 | return 1; 54 | #endif /* 19991015 */ 55 | } 56 | ], libmcrypt_config_version="2.2.0" 57 | if test x$libmcrypt_config_prefix != x ; then 58 | TTLIBS="-L${libmcrypt_config_prefix}/libs" 59 | TTINCLUDE="-I${libmcrypt_config_prefix}/include" 60 | fi 61 | LIBMCRYPT_CFLAGS="${TTINCLUDE}" 62 | LIBMCRYPT_LIBS="${TTLIBS} -lmcrypt" 63 | AC_DEFINE(LIBMCRYPT22, 1, [have libmcrypt 2.2]) 64 | 65 | , libmcrypt_config_version="2.4.0" 66 | if test x$libmcrypt_config_prefix != x ; then 67 | TTLIBS="-L${libmcrypt_config_prefix}/libs" 68 | TTINCLUDE="-I${libmcrypt_config_prefix}/include" 69 | fi 70 | LIBMCRYPT_CFLAGS="${TTINCLUDE}" 71 | LIBMCRYPT_LIBS="${TTLIBS} -lmcrypt -lltdl ${LIBADD_DL}" 72 | AC_DEFINE(LIBMCRYPT24, 1, [have libmcrypt 2.4])) 73 | else 74 | dnl libmcrypt-config was found 75 | LIBMCRYPT_CFLAGS=`$LIBMCRYPT_CONFIG $libmcrypt_config_args --cflags` 76 | LIBMCRYPT_LIBS=`$LIBMCRYPT_CONFIG $libmcrypt_config_args --libs` 77 | libmcrypt_config_version=`$LIBMCRYPT_CONFIG $libmcrypt_config_args --version` 78 | AC_DEFINE(LIBMCRYPT24, 1, [have libmcrypt 2.4]) 79 | fi 80 | 81 | ac_save_CFLAGS="$CFLAGS" 82 | ac_save_LIBS="$LIBS" 83 | CFLAGS="$CFLAGS $LIBMCRYPT_CFLAGS" 84 | LIBS="$LIBS $LIBMCRYPT_LIBS" 85 | 86 | dnl 87 | dnl Now check if the installed libmcrypt is sufficiently new. Also sanity 88 | dnl checks the results of libmcrypt-config to some extent 89 | dnl 90 | rm -f conf.libmcrypttest 91 | AC_TRY_RUN([ 92 | #include 93 | #include 94 | #include 95 | #include 96 | 97 | #define TWO "2.2" 98 | 99 | int 100 | main () 101 | { 102 | #if MCRYPT_API_VERSION <= 20010201 103 | 104 | #if MCRYPT_API_VERSION <= 19991015 105 | /* version 2.2 */ 106 | int x = mcrypt_get_key_size(MCRYPT_TWOFISH_128); 107 | system ("touch conf.libmcrypttest"); 108 | 109 | if( strncmp( TWO, "$min_libmcrypt_version", strlen(TWO))) { 110 | printf("\n*** Requested libmcrypt %s, but LIBMCRYPT (%s)\n", 111 | "$min_libmcrypt_version", TWO ); 112 | printf("*** was found!\n"); 113 | return 1; 114 | } 115 | return 0; 116 | #else 117 | /* version 2.4 before 11 */ 118 | MCRYPT td = mcrypt_module_open("twofish", NULL, "cbc", NULL); 119 | system ("touch conf.libmcrypttest"); 120 | mcrypt_module_close(td); 121 | 122 | return 0; 123 | #endif /* 19991015 */ 124 | 125 | #else 126 | 127 | system ("touch conf.libmcrypttest"); 128 | 129 | if( strcmp( mcrypt_check_version(NULL), "$libmcrypt_config_version" ) ) 130 | { 131 | printf("\n*** 'libmcrypt-config --version' returned %s, but LIBMCRYPT (%s)\n", 132 | "$libmcrypt_config_version", mcrypt_check_version(NULL) ); 133 | printf("*** was found! If libmcrypt-config was correct, then it is best\n"); 134 | printf("*** to remove the old version of LIBMCRYPT. You may also be able to fix the error\n"); 135 | printf("*** by modifying your LD_LIBRARY_PATH enviroment variable, or by editing\n"); 136 | printf("*** /etc/ld.so.conf. Make sure you have run ldconfig if that is\n"); 137 | printf("*** required on your system.\n"); 138 | printf("*** If libmcrypt-config was wrong, set the environment variable LIBMCRYPT_CONFIG\n"); 139 | printf("*** to point to the correct copy of libmcrypt-config, and remove the file config.cache\n"); 140 | printf("*** before re-running configure\n"); 141 | } 142 | else if ( strcmp(mcrypt_check_version(NULL), LIBMCRYPT_VERSION ) ) 143 | { 144 | printf("\n*** LIBMCRYPT header file (version %s) does not match\n", LIBMCRYPT_VERSION); 145 | printf("*** library (version %s)\n", mcrypt_check_version(NULL) ); 146 | } 147 | else 148 | { 149 | if ( mcrypt_check_version( "$min_libmcrypt_version" ) ) 150 | { 151 | return 0; 152 | } 153 | else 154 | { 155 | printf("no\n*** An old version of LIBMCRYPT (%s) was found.\n", 156 | mcrypt_check_version(NULL) ); 157 | printf("*** You need a version of LIBMCRYPT newer than %s. The latest version of\n", 158 | "$min_libmcrypt_version" ); 159 | printf("*** LIBMCRYPT is always available from ftp://mcrypt.hellug.gr/pub/mcrypt.\n"); 160 | printf("*** \n"); 161 | printf("*** If you have already installed a sufficiently new version, this error\n"); 162 | printf("*** probably means that the wrong copy of the libmcrypt-config shell script is\n"); 163 | printf("*** being found. The easiest way to fix this is to remove the old version\n"); 164 | printf("*** of LIBMCRYPT, but you can also set the LIBMCRYPT_CONFIG environment to point to the\n"); 165 | printf("*** correct copy of libmcrypt-config. (In this case, you will have to\n"); 166 | printf("*** modify your LD_LIBRARY_PATH enviroment variable, or edit /etc/ld.so.conf\n"); 167 | printf("*** so that the correct libraries are found at run-time)\n"); 168 | } 169 | } 170 | return 1; 171 | 172 | #endif /* 20010201 */ 173 | 174 | } 175 | ],, no_libmcrypt=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"]) 176 | CFLAGS="$ac_save_CFLAGS" 177 | LIBS="$ac_save_LIBS" 178 | 179 | 180 | if test "x$no_libmcrypt" = x ; then 181 | AC_MSG_RESULT(yes) 182 | ifelse([$2], , :, [$2]) 183 | else 184 | if test -f conf.libmcrypttest ; then 185 | : 186 | else 187 | AC_MSG_RESULT(no) 188 | fi 189 | 190 | if test -f conf.libmcrypttest ; then 191 | : 192 | else 193 | echo "*** Could not run libmcrypt test program, checking why..." 194 | CFLAGS="$CFLAGS $LIBMCRYPT_CFLAGS" 195 | LIBS="$LIBS $LIBMCRYPT_LIBS" 196 | AC_TRY_LINK([ 197 | #include 198 | #include 199 | #include 200 | #include 201 | ], [ 202 | #if MCRYPT_API_VERSION <= 20010201 203 | 204 | #if MCRYPT_API_VERSION <= 19991015 205 | /* version 2.2 */ 206 | int x = mcrypt_get_key_size(MCRYPT_TWOFISH_128); 207 | return 0; 208 | #else 209 | /* version 2.4 before 11 */ 210 | MCRYPT td = mcrypt_module_open("twofish", NULL, "cbc", NULL); 211 | mcrypt_module_close(td); 212 | return 0; 213 | #endif /* 19991015 */ 214 | #else 215 | 216 | return !!mcrypt_check_version(NULL); 217 | 218 | #endif /* 20010201 */ 219 | 220 | ], 221 | [ echo "*** The test program compiled, but did not run. This usually means" 222 | echo "*** that the run-time linker is not finding LIBMCRYPT or finding the wrong" 223 | echo "*** version of LIBMCRYPT. If it is not finding LIBMCRYPT, you'll need to set your" 224 | echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point" 225 | echo "*** to the installed location Also, make sure you have run ldconfig if that" 226 | echo "*** is required on your system" 227 | echo "***" 228 | echo "*** If you have an old version installed, it is best to remove it, although" 229 | echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH" 230 | echo "***" ], 231 | [ echo "*** The test program failed to compile or link. See the file config.log for the" 232 | echo "*** exact error that occured. This usually means LIBMCRYPT was incorrectly installed" 233 | echo "*** or that you have moved LIBMCRYPT since it was installed. In the latter case, you" 234 | echo "*** may want to edit the libmcrypt-config script: $LIBMCRYPT_CONFIG" ]) 235 | CFLAGS="$ac_save_CFLAGS" 236 | LIBS="$ac_save_LIBS" 237 | fi 238 | 239 | LIBMCRYPT_CFLAGS="" 240 | LIBMCRYPT_LIBS="" 241 | ifelse([$3], , :, [$3]) 242 | fi 243 | rm -f conf.libmcrypttest 244 | AC_SUBST(LIBMCRYPT_CFLAGS) 245 | AC_SUBST(LIBMCRYPT_LIBS) 246 | ]) 247 | 248 | dnl *-*wedit:notab*-* Please keep this as the last line. 249 | -------------------------------------------------------------------------------- /lib/libmcrypt.sym: -------------------------------------------------------------------------------- 1 | mcrypt_generic_deinit 2 | mcrypt_module_open 3 | mcrypt_module_close 4 | mcrypt_generic_init 5 | mcrypt_generic_end 6 | mdecrypt_generic 7 | mcrypt_generic 8 | mcrypt_enc_self_test 9 | mcrypt_enc_get_block_size 10 | mcrypt_enc_get_iv_size 11 | mcrypt_enc_get_key_size 12 | mcrypt_enc_is_block_algorithm 13 | mcrypt_enc_is_block_mode 14 | mcrypt_enc_is_block_algorithm_mode 15 | mcrypt_enc_mode_has_iv 16 | mcrypt_enc_get_algorithms_name 17 | mcrypt_enc_get_modes_name 18 | mcrypt_enc_get_supported_key_sizes 19 | mcrypt_list_algorithms 20 | mcrypt_list_modes 21 | mcrypt_free_p 22 | mcrypt_free 23 | mcrypt_perror 24 | mcrypt_strerror 25 | mcrypt_module_self_test 26 | mcrypt_module_is_block_algorithm 27 | mcrypt_module_is_block_algorithm_mode 28 | mcrypt_module_is_block_mode 29 | mcrypt_module_get_algo_key_size 30 | mcrypt_module_get_algo_block_size 31 | mcrypt_module_get_algo_supported_key_sizes 32 | mcrypt_module_algorithm_version 33 | mcrypt_module_mode_version 34 | mcrypt_enc_set_state 35 | mcrypt_enc_get_state 36 | mcrypt_check_version 37 | mcrypt_mutex_register 38 | mcrypt_module_support_dynamic 39 | -------------------------------------------------------------------------------- /lib/mcrypt.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1998,1999,2000 Nikos Mavroyanopoulos 3 | * 4 | * This library is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU Library General Public License as published 6 | * by the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | /* $Id: mcrypt.c,v 1.19 2002/07/06 10:18:18 nmav Exp $ */ 21 | 22 | /* Changed by Steve Underwood 1999/12/10 to allow an arbitrary number of 23 | * streams of encryption. Currently the resulting code is probably not 24 | * thread safe, but as far as I could tell the previous code wasn't 25 | * either. This version has brute force locking in a lot of places, but 26 | * it has not been tested in a multi-threaded manner. 27 | * The key locking issue is that the table of encryption streams could 28 | * be moved when it is extended. Any address pre-calculated, or in 29 | * calculation at the time of the reallocation would be screwed. 30 | * This won't happen often, but requires lots of locks - PITA! 31 | */ 32 | 33 | /* Changed again at 1999/12/15 to correct the thread safeness. Now it 34 | * seems to be thread safe. Brute force locking was removed and 35 | * locks per thread were introduced. 36 | * --nikos 37 | */ 38 | 39 | /* The above comments are too old! */ 40 | 41 | #ifndef LIBDEFS_H 42 | #define LIBDEFS_H 43 | #include 44 | #endif 45 | #include 46 | #include 47 | #include 48 | 49 | #if 0 50 | static int preloaded_symbols = 0; 51 | #endif 52 | 53 | static int internal_end_mcrypt(MCRYPT td); 54 | 55 | static int internal_init_mcrypt(MCRYPT td, const void *key, int lenofkey, const void *IV) 56 | { 57 | int *sizes = NULL; 58 | int num_of_sizes, i, ok = 0; 59 | int key_size = mcrypt_enc_get_key_size(td); 60 | 61 | if (lenofkey > key_size || lenofkey==0) { 62 | return MCRYPT_KEY_LEN_ERROR; /* error */ 63 | } 64 | 65 | sizes = mcrypt_enc_get_supported_key_sizes(td, &num_of_sizes); 66 | if (sizes != NULL) { 67 | for (i = 0; i < num_of_sizes; i++) { 68 | if (lenofkey == sizes[i]) { 69 | ok = 1; 70 | break; 71 | } 72 | } 73 | } else { /* sizes==NULL */ 74 | if (num_of_sizes == 0 75 | && lenofkey <= mcrypt_enc_get_key_size(td)) 76 | ok = 1; 77 | } 78 | 79 | 80 | if (ok == 0) { /* not supported key size */ 81 | key_size = mcrypt_enc_get_key_size(td); 82 | if (sizes != NULL) { 83 | for (i = 0; i < num_of_sizes; i++) { 84 | if (lenofkey <= sizes[i]) { 85 | key_size = sizes[i]; 86 | break; 87 | } 88 | } 89 | } else { /* well every key size is supported! */ 90 | key_size = lenofkey; 91 | } 92 | } else { 93 | key_size = lenofkey; 94 | } 95 | free(sizes); 96 | 97 | td->keyword_given = mxcalloc(1, mcrypt_enc_get_key_size(td)); 98 | if (td->keyword_given==NULL) return MCRYPT_MEMORY_ALLOCATION_ERROR; 99 | 100 | memmove(td->keyword_given, key, lenofkey); 101 | i = mcrypt_get_size(td); 102 | td->akey = mxcalloc(1, i); 103 | if (td->akey==NULL) { 104 | free(td->keyword_given); 105 | return MCRYPT_MEMORY_ALLOCATION_ERROR; 106 | } 107 | i = mcrypt_mode_get_size(td); 108 | if (i > 0) { 109 | td->abuf = mxcalloc(1, i); 110 | if (td->abuf==NULL) { 111 | free(td->keyword_given); 112 | free(td->akey); 113 | return MCRYPT_MEMORY_ALLOCATION_ERROR; 114 | } 115 | } 116 | ok = init_mcrypt(td, td->abuf, key, key_size, IV); 117 | if (ok!=0) { 118 | free(td->keyword_given); 119 | free(td->akey); 120 | free(td->abuf); 121 | return MCRYPT_UNKNOWN_ERROR; /* algorithm error */ 122 | } 123 | 124 | ok = mcrypt_set_key(td, 125 | (void *) td->akey, 126 | (void *) td->keyword_given, 127 | key_size, IV, IV!=NULL ? mcrypt_enc_get_iv_size(td) : 0); 128 | 129 | if (ok!=0) { 130 | internal_end_mcrypt(td); 131 | return MCRYPT_UNKNOWN_ERROR; /* algorithm error */ 132 | } 133 | 134 | return 0; 135 | } 136 | 137 | static int internal_end_mcrypt(MCRYPT td) 138 | { 139 | mxfree(td->keyword_given, mcrypt_enc_get_key_size(td)); 140 | td->keyword_given = NULL; 141 | 142 | mxfree(td->akey, mcrypt_get_size(td)); 143 | td->akey = NULL; 144 | 145 | end_mcrypt(td, td->abuf); 146 | if (td->abuf!=NULL) mxfree(td->abuf, mcrypt_mode_get_size(td)); 147 | td->abuf = NULL; 148 | 149 | return 0; 150 | } 151 | 152 | /* Generic - High level functions */ 153 | 154 | WIN32DLL_DEFINE 155 | int mcrypt_generic_init(const MCRYPT td, const void *key, int lenofkey, const void *IV) 156 | { 157 | return internal_init_mcrypt(td, key, lenofkey, IV); 158 | } 159 | 160 | WIN32DLL_DEFINE 161 | int mcrypt_generic(MCRYPT td, void *plaintext, int len) 162 | { 163 | int x; 164 | 165 | x = mcrypt(td, td->abuf, plaintext, len); 166 | return x; 167 | } 168 | 169 | WIN32DLL_DEFINE 170 | int mdecrypt_generic(MCRYPT td, void *ciphertext, int len) 171 | { 172 | int x; 173 | x = mdecrypt(td, td->abuf, ciphertext, len); 174 | return x; 175 | } 176 | 177 | WIN32DLL_DEFINE 178 | int mcrypt_generic_end( MCRYPT td) 179 | { 180 | if (td==NULL) return MCRYPT_UNKNOWN_ERROR; 181 | 182 | if (td->keyword_given!=NULL) 183 | internal_end_mcrypt(td); 184 | mcrypt_module_close(td); 185 | return 0; 186 | } 187 | 188 | WIN32DLL_DEFINE 189 | int mcrypt_generic_deinit( MCRYPT td) 190 | { 191 | if (td==NULL || td->keyword_given==NULL) return MCRYPT_UNKNOWN_ERROR; 192 | 193 | internal_end_mcrypt(td); 194 | return 0; 195 | } 196 | 197 | WIN32DLL_DEFINE 198 | void mcrypt_perror(int err) 199 | { 200 | 201 | switch (err) { 202 | case MCRYPT_UNKNOWN_ERROR: 203 | fprintf(stderr, "Unknown error.\n"); 204 | break; 205 | case MCRYPT_ALGORITHM_MODE_INCOMPATIBILITY: 206 | fprintf(stderr, 207 | "Algorithm incompatible with this mode.\n"); 208 | break; 209 | case MCRYPT_KEY_LEN_ERROR: 210 | fprintf(stderr, "Key length is not legal.\n"); 211 | break; 212 | case MCRYPT_MEMORY_ALLOCATION_ERROR: 213 | fprintf(stderr, "Memory allocation failed.\n"); 214 | break; 215 | case MCRYPT_UNKNOWN_MODE: 216 | fprintf(stderr, "Unknown mode.\n"); 217 | break; 218 | case MCRYPT_UNKNOWN_ALGORITHM: 219 | fprintf(stderr, "Unknown algorithm.\n"); 220 | break; 221 | 222 | } 223 | return; 224 | } 225 | 226 | WIN32DLL_DEFINE 227 | const char* mcrypt_strerror(int err) 228 | { 229 | 230 | switch (err) { 231 | case MCRYPT_UNKNOWN_ERROR: 232 | return "Unknown error.\n"; 233 | break; 234 | case MCRYPT_ALGORITHM_MODE_INCOMPATIBILITY: 235 | return "Algorithm incompatible with this mode.\n"; 236 | break; 237 | case MCRYPT_KEY_LEN_ERROR: 238 | return "Key length is not legal.\n"; 239 | break; 240 | case MCRYPT_MEMORY_ALLOCATION_ERROR: 241 | return "Memory allocation failed.\n"; 242 | break; 243 | case MCRYPT_UNKNOWN_MODE: 244 | return "Unknown mode.\n"; 245 | break; 246 | case MCRYPT_UNKNOWN_ALGORITHM: 247 | return "Unknown algorithm.\n"; 248 | break; 249 | 250 | } 251 | return NULL; 252 | } 253 | 254 | WIN32DLL_DEFINE 255 | void mcrypt_free(void *ptr) 256 | { 257 | free(ptr); 258 | } 259 | -------------------------------------------------------------------------------- /lib/mcrypt_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef LIBDEFS_H 2 | #define LIBDEFS_H 3 | #include 4 | #endif 5 | 6 | /* Local Defines */ 7 | 8 | #ifndef lt_ptr 9 | /* older version of libltdl */ 10 | # define lt_ptr lt_ptr_t 11 | #endif 12 | 13 | typedef struct { 14 | char* name; 15 | lt_ptr address; 16 | } mcrypt_preloaded; 17 | 18 | typedef struct { 19 | lt_dlhandle handle; 20 | char name[64]; 21 | } mcrypt_dlhandle; 22 | 23 | #define MCRYPT_INTERNAL_HANDLER (void*)-1 24 | 25 | typedef struct { 26 | mcrypt_dlhandle algorithm_handle; 27 | mcrypt_dlhandle mode_handle; 28 | 29 | /* Holds the algorithm's internal key */ 30 | byte *akey; 31 | 32 | byte *abuf; /* holds the mode's internal buffers */ 33 | 34 | /* holds the key */ 35 | byte *keyword_given; 36 | 37 | /* These were included to speed up encryption/decryption proccess, so 38 | * there is not need for resolving symbols every time. 39 | */ 40 | lt_ptr m_encrypt; 41 | lt_ptr m_decrypt; 42 | lt_ptr a_encrypt; 43 | lt_ptr a_decrypt; 44 | lt_ptr a_block_size; 45 | } CRYPT_STREAM; 46 | 47 | typedef CRYPT_STREAM* MCRYPT; 48 | 49 | #define MCRYPT_FAILED 0x0 50 | 51 | WIN32DLL_DEFINE int mcrypt_module_close(MCRYPT td); 52 | 53 | /* frontends */ 54 | 55 | WIN32DLL_DEFINE int end_mcrypt( MCRYPT td, void *buf); 56 | WIN32DLL_DEFINE int mcrypt_enc_get_size(MCRYPT td); 57 | WIN32DLL_DEFINE int mcrypt_mode_get_size(MCRYPT td); 58 | WIN32DLL_DEFINE int mcrypt_set_key(MCRYPT td, void *a, const void *, int c, const void *, int e); 59 | WIN32DLL_DEFINE int mcrypt_enc_get_block_size(MCRYPT td); 60 | int __mcrypt_get_block_size(MCRYPT td); 61 | int mcrypt_enc_get_algo_iv_size(MCRYPT td); 62 | WIN32DLL_DEFINE int mcrypt_enc_get_iv_size(MCRYPT td); 63 | WIN32DLL_DEFINE int mcrypt_enc_get_key_size(MCRYPT td); 64 | WIN32DLL_DEFINE int* mcrypt_enc_get_supported_key_sizes(MCRYPT td, int* out_size); 65 | WIN32DLL_DEFINE int mcrypt_enc_is_block_algorithm(MCRYPT td); 66 | WIN32DLL_DEFINE char *mcrypt_enc_get_algorithms_name(MCRYPT td); 67 | WIN32DLL_DEFINE int init_mcrypt(MCRYPT td, void*buf, const void *, int, const void *); 68 | WIN32DLL_DEFINE int mcrypt(MCRYPT td, void* buf, void *a, int b); 69 | WIN32DLL_DEFINE int mdecrypt(MCRYPT td, void* buf, void *a, int b); 70 | WIN32DLL_DEFINE char *mcrypt_enc_get_modes_name(MCRYPT td); 71 | WIN32DLL_DEFINE int mcrypt_enc_is_block_mode(MCRYPT td); 72 | WIN32DLL_DEFINE int mcrypt_enc_mode_has_iv(MCRYPT td); 73 | WIN32DLL_DEFINE int mcrypt_enc_is_block_algorithm_mode(MCRYPT td); 74 | WIN32DLL_DEFINE int mcrypt_module_algorithm_version(const char *algorithm, const char *a_directory); 75 | WIN32DLL_DEFINE int mcrypt_module_mode_version(const char *mode, const char *m_directory); 76 | WIN32DLL_DEFINE int mcrypt_get_size(MCRYPT td); 77 | 78 | 79 | #define MCRYPT_UNKNOWN_ERROR -1 80 | #define MCRYPT_ALGORITHM_MODE_INCOMPATIBILITY -2 81 | #define MCRYPT_KEY_LEN_ERROR -3 82 | #define MCRYPT_MEMORY_ALLOCATION_ERROR -4 83 | #define MCRYPT_UNKNOWN_MODE -5 84 | #define MCRYPT_UNKNOWN_ALGORITHM -6 85 | 86 | lt_ptr mcrypt_dlsym( mcrypt_dlhandle, char* str); 87 | void mcrypt_dlclose( mcrypt_dlhandle mod); 88 | lt_ptr _mcrypt_search_symlist_lib(const char* name); 89 | lt_ptr _mcrypt_search_symlist_sym(mcrypt_dlhandle handle, const char* _name); 90 | -------------------------------------------------------------------------------- /lib/mcrypt_modules.h: -------------------------------------------------------------------------------- 1 | #define rotl32(x,n) (((x) << ((word32)(n & 31))) | ((x) >> (32 - (word32)(n & 31)))) 2 | #define rotr32(x,n) (((x) >> ((word32)(n & 31))) | ((x) << (32 - (word32)(n & 31)))) 3 | #define rotl16(x,n) (((x) << ((word16)(n & 15))) | ((x) >> (16 - (word16)(n & 15)))) 4 | #define rotr16(x,n) (((x) >> ((word16)(n & 15))) | ((x) << (16 - (word16)(n & 15)))) 5 | 6 | /* Use hardware rotations.. when available */ 7 | #ifdef swap32 8 | # define byteswap32(x) swap32(x) 9 | #else 10 | # ifdef swap_32 11 | # define byteswap32(x) swap_32(x) 12 | # else 13 | # ifdef bswap_32 14 | # define byteswap32(x) bswap_32(x) 15 | # else 16 | # define byteswap32(x) ((rotl32(x, 8) & 0x00ff00ff) | (rotr32(x, 8) & 0xff00ff00)) 17 | # endif 18 | # endif 19 | #endif 20 | 21 | #ifdef swap16 22 | # define byteswap16(x) swap16(x) 23 | #else 24 | # ifdef swap_16 25 | # define byteswap16(x) swap_16(x) 26 | # else 27 | # ifdef bswap_16 28 | # define byteswap16(x) bswap_16(x) 29 | # else 30 | # define byteswap16(x) ((rotl16(x, 8) & 0x00ff) | (rotr16(x, 8) & 0xff00)) 31 | # endif 32 | # endif 33 | #endif 34 | 35 | #ifdef _MSC_VER 36 | __inline static 37 | #else 38 | inline static 39 | #endif 40 | void memxor(unsigned char *o1, unsigned char *o2, int length) 41 | { 42 | int i; 43 | 44 | for (i = 0; i < length; i++) { 45 | o1[i] ^= o2[i]; 46 | } 47 | return; 48 | } 49 | 50 | 51 | #define Bzero(x, y) memset(x, 0, y) 52 | -------------------------------------------------------------------------------- /lib/mcrypt_threads.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2001 Nikos Mavroyanopoulos 3 | * 4 | * This library is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU Library General Public License as published 6 | * by the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #ifndef LIBDEFS_H 21 | #define LIBDEFS_H 22 | #include 23 | #endif 24 | 25 | #ifdef DLMUTEX 26 | 27 | static void _mcrypt_mutex_seterror (const char *ERROR) { 28 | return; /* do nothing */ 29 | } 30 | static const char * _mcrypt_mutex_geterror (void) { 31 | /* return no error */ 32 | return NULL; 33 | } 34 | 35 | WIN32DLL_DEFINE 36 | int mcrypt_mutex_register ( void (*mutex_lock)(void) , 37 | void (*mutex_unlock)(void)) 38 | { 39 | 40 | return lt_dlmutex_register ( mutex_lock, mutex_unlock, 41 | _mcrypt_mutex_seterror, _mcrypt_mutex_geterror); 42 | 43 | } 44 | #else 45 | WIN32DLL_DEFINE 46 | int mcrypt_mutex_register ( void (*mutex_lock)(void) , 47 | void (*mutex_unlock)(void)) 48 | { 49 | return 0; 50 | } 51 | #endif /* NO_DLMUTEX */ 52 | -------------------------------------------------------------------------------- /lib/win32_comp.c: -------------------------------------------------------------------------------- 1 | /* (c) D.Souflis dsouflis@acm.org */ 2 | 3 | #include "libdefs.h" 4 | #include "win32_comp.h" 5 | 6 | #ifdef WIN32 7 | WIN32DLL_DEFINE int main (void) 8 | { 9 | /* empty main function to avoid linker error (see cygwin FAQ) */ 10 | } 11 | #endif 12 | 13 | #ifdef WIN32_DLOPEN 14 | 15 | void *dlopen(const char *module, int unused) 16 | { 17 | return (void *) LoadLibrary(module); 18 | } 19 | 20 | void *dlsym(void *mo, const char *proc) 21 | { 22 | return (void *) GetProcAddress((HMODULE) mo, proc); 23 | } 24 | 25 | void dlclose(void *mo) 26 | { 27 | (void) FreeLibrary((HMODULE) mo); 28 | } 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /lib/win32_comp.h: -------------------------------------------------------------------------------- 1 | /* (c) D.Souflis dsouflis@acm.org */ 2 | 3 | #ifndef _WINSTUBDL_H 4 | #define _WINSTUBDL_H 5 | 6 | #ifdef WIN32 7 | # define WIN32DLL_DEFINE __declspec( dllexport) 8 | #else 9 | # define WIN32DLL_DEFINE 10 | #endif 11 | 12 | #ifdef WIN32_DLOPEN 13 | #include 14 | #ifndef RTLD_LAZY 15 | # define RTLD_LAZY 1 16 | #endif 17 | void *dlopen(const char *module, int unused); 18 | void* dlsym(void* mo, const char *proc); 19 | void dlclose(void* mo); 20 | #endif 21 | 22 | /* defined by ROB */ 23 | #define STDC_HEADERS 1 24 | #define SIZEOF_UNSIGNED_INT 4 25 | #define SIZEOF_UNSIGNED_LONG_INT 4 26 | #define SIZEOF_UNSIGNED_SHORT_INT 2 27 | #define SIZEOF_UNSIGNED_CHAR 1 28 | #define HAVE_MEMMOVE 1 29 | #define VERSION "2.5.8" 30 | #define LIBDIR "C:\\windows\\system" 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /lib/xmemory.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1998,1999 Nikos Mavroyanopoulos 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Library General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | /* $Id: xmemory.c,v 1.3 2001/05/17 18:58:20 nmav Exp $ */ 21 | 22 | #ifndef LIBDEFS_H 23 | # define LIBDEFS_H 24 | # include 25 | #endif 26 | #include 27 | 28 | #ifdef HAVE_MLOCK 29 | # ifdef HAVE_SYS_MMAN_H 30 | # include 31 | # endif 32 | #endif 33 | 34 | #ifdef HAVE_MLOCK 35 | void LOCKMEM(void *x, size_t size) 36 | { 37 | mlock(x, size); 38 | } 39 | 40 | # define UNLOCKMEM(x,y) munlock(x,y) 41 | #else 42 | # define LOCKMEM(x,y) 43 | # define UNLOCKMEM(x,y) 44 | #endif 45 | 46 | #include 47 | 48 | /* memory allocation */ 49 | 50 | void *mxmalloc(size_t size) 51 | { 52 | char *x; 53 | 54 | x = malloc(size); 55 | 56 | if (x != NULL) { 57 | LOCKMEM(x, size); 58 | return x; 59 | } 60 | return NULL; 61 | } 62 | 63 | void *mxcalloc(size_t nmemb, size_t size) 64 | { 65 | char *x; 66 | 67 | x = calloc(nmemb, size); 68 | if (x != NULL) { 69 | LOCKMEM(x, size); 70 | return x; 71 | } 72 | return NULL; 73 | } 74 | 75 | void *mxrealloc(void *ptr, size_t size) 76 | { 77 | char *x; 78 | 79 | x = realloc(ptr, size); 80 | if (x != NULL) { 81 | LOCKMEM(x, size); 82 | return x; 83 | } 84 | return NULL; 85 | } 86 | 87 | 88 | void mxfree(void *ptr, size_t size) 89 | { 90 | 91 | Bzero(ptr, size); 92 | UNLOCKMEM(ptr, size); 93 | free(ptr); 94 | 95 | } 96 | -------------------------------------------------------------------------------- /lib/xmemory.h: -------------------------------------------------------------------------------- 1 | void *mxmalloc(size_t size); 2 | void *mxcalloc(size_t nmemb, size_t size); 3 | void *mxrealloc(void *ptr, size_t size); 4 | void mxfree( void *ptr, size_t size); 5 | -------------------------------------------------------------------------------- /libltdl/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | 3 | AUTOMAKE_OPTIONS = no-dependencies foreign 4 | 5 | if INSTALL_LTDL 6 | include_HEADERS = ltdl.h 7 | lib_LTLIBRARIES = libltdl.la 8 | else 9 | noinst_HEADERS = ltdl.h 10 | endif 11 | 12 | if CONVENIENCE_LTDL 13 | noinst_LTLIBRARIES = libltdlc.la 14 | endif 15 | 16 | ## Make sure these will be cleaned even when they're not built by 17 | ## default. 18 | CLEANFILES = libltdl.la libltdlc.la 19 | 20 | libltdl_la_SOURCES = ltdl.c 21 | libltdl_la_LDFLAGS = -no-undefined -version-info 4:0:1 22 | libltdl_la_LIBADD = $(LIBADD_DL) 23 | 24 | libltdlc_la_SOURCES = ltdl.c 25 | libltdlc_la_LIBADD = $(LIBADD_DL) 26 | 27 | ## Because we do not have automatic dependency tracking: 28 | ltdl.lo: ltdl.h config.h 29 | 30 | $(OBJECTS) $(libltdl_la_OBJECTS) $(libltdlc_la_OBJECTS): libtool 31 | libtool: $(LIBTOOL_DEPS) 32 | $(SHELL) ./config.status --recheck 33 | 34 | ## This allows us to install libltdl without using ln and without creating 35 | ## a world writeable directory. 36 | ## FIXME: Remove this rule once automake can do this properly by itself. 37 | local-install-files: $(DISTFILES) 38 | -rm -rf $(DESTDIR)$(datadir)/libtool/libltdl 39 | $(mkinstalldirs) $(DESTDIR)$(datadir)/libtool/libltdl 40 | @for file in $(DISTFILES); do \ 41 | d=$(srcdir); \ 42 | if test -d $$d/$$file; then \ 43 | cp -r $$d/$$file $(DESTDIR)$(datadir)/libtool/libltdl/$$file; \ 44 | else \ 45 | test -f $(DESTDIR)$(datadir)/libtool/libltdl/$$file \ 46 | || cp $$d/$$file $(DESTDIR)$(datadir)/libtool/libltdl/$$file || :; \ 47 | fi; \ 48 | done 49 | -------------------------------------------------------------------------------- /libltdl/README: -------------------------------------------------------------------------------- 1 | This is GNU libltdl, a system independent dlopen wrapper for GNU libtool. 2 | 3 | It supports the following dlopen interfaces: 4 | * dlopen (Solaris, Linux and various BSD flavors) 5 | * shl_load (HP-UX) 6 | * LoadLibrary (Win16 and Win32) 7 | * load_add_on (BeOS) 8 | * GNU DLD (emulates dynamic linking for static libraries) 9 | * libtool's dlpreopen 10 | -------------------------------------------------------------------------------- /libltdl/config-h.in: -------------------------------------------------------------------------------- 1 | /* config-h.in. Generated automatically from configure.in by autoheader 2.13. */ 2 | 3 | /* Define to empty if the keyword does not work. */ 4 | #undef const 5 | 6 | /* Define as __inline if that's what the C compiler calls it. */ 7 | #undef inline 8 | 9 | /* Define if you have the ANSI C header files. */ 10 | #undef STDC_HEADERS 11 | 12 | /* Define if you have the argz_append function. */ 13 | #undef HAVE_ARGZ_APPEND 14 | 15 | /* Define if you have the argz_create_sep function. */ 16 | #undef HAVE_ARGZ_CREATE_SEP 17 | 18 | /* Define if you have the argz_insert function. */ 19 | #undef HAVE_ARGZ_INSERT 20 | 21 | /* Define if you have the argz_next function. */ 22 | #undef HAVE_ARGZ_NEXT 23 | 24 | /* Define if you have the argz_stringify function. */ 25 | #undef HAVE_ARGZ_STRINGIFY 26 | 27 | /* Define if you have the bcopy function. */ 28 | #undef HAVE_BCOPY 29 | 30 | /* Define if you have the dlerror function. */ 31 | #undef HAVE_DLERROR 32 | 33 | /* Define if you have the index function. */ 34 | #undef HAVE_INDEX 35 | 36 | /* Define if you have the memcpy function. */ 37 | #undef HAVE_MEMCPY 38 | 39 | /* Define if you have the memmove function. */ 40 | #undef HAVE_MEMMOVE 41 | 42 | /* Define if you have the rindex function. */ 43 | #undef HAVE_RINDEX 44 | 45 | /* Define if you have the strchr function. */ 46 | #undef HAVE_STRCHR 47 | 48 | /* Define if you have the strcmp function. */ 49 | #undef HAVE_STRCMP 50 | 51 | /* Define if you have the strrchr function. */ 52 | #undef HAVE_STRRCHR 53 | 54 | /* Define if you have the header file. */ 55 | #undef HAVE_ARGZ_H 56 | 57 | /* Define if you have the header file. */ 58 | #undef HAVE_ASSERT_H 59 | 60 | /* Define if you have the header file. */ 61 | #undef HAVE_CTYPE_H 62 | 63 | /* Define if you have the header file. */ 64 | #undef HAVE_DIRENT_H 65 | 66 | /* Define if you have the header file. */ 67 | #undef HAVE_DL_H 68 | 69 | /* Define if you have the header file. */ 70 | #undef HAVE_DLD_H 71 | 72 | /* Define if you have the header file. */ 73 | #undef HAVE_DLFCN_H 74 | 75 | /* Define if you have the header file. */ 76 | #undef HAVE_ERRNO_H 77 | 78 | /* Define if you have the header file. */ 79 | #undef HAVE_MALLOC_H 80 | 81 | /* Define if you have the header file. */ 82 | #undef HAVE_MEMORY_H 83 | 84 | /* Define if you have the header file. */ 85 | #undef HAVE_NDIR_H 86 | 87 | /* Define if you have the header file. */ 88 | #undef HAVE_STDIO_H 89 | 90 | /* Define if you have the header file. */ 91 | #undef HAVE_STDLIB_H 92 | 93 | /* Define if you have the header file. */ 94 | #undef HAVE_STRING_H 95 | 96 | /* Define if you have the header file. */ 97 | #undef HAVE_STRINGS_H 98 | 99 | /* Define if you have the header file. */ 100 | #undef HAVE_SYS_DIR_H 101 | 102 | /* Define if you have the header file. */ 103 | #undef HAVE_SYS_DL_H 104 | 105 | /* Define if you have the header file. */ 106 | #undef HAVE_SYS_NDIR_H 107 | 108 | /* Define if you have the header file. */ 109 | #undef HAVE_UNISTD_H 110 | 111 | /* Define to the extension used for shared libraries, say, .so. */ 112 | #undef LTDL_SHLIB_EXT 113 | 114 | /* Define to the name of the environment variable that determines the dynamic library search path. */ 115 | #undef LTDL_SHLIBPATH_VAR 116 | 117 | /* Define to the system default library search path. */ 118 | #undef LTDL_SYSSEARCHPATH 119 | 120 | /* Define to the sub-directory in which libtool stores uninstalled libraries. */ 121 | #undef LTDL_OBJDIR 122 | 123 | /* Define if libtool can extract symbol lists from object files. */ 124 | #undef HAVE_PRELOADED_SYMBOLS 125 | 126 | /* Define if you have the shl_load function. */ 127 | #undef HAVE_SHL_LOAD 128 | 129 | /* Define if you have the shl_load function. */ 130 | #undef HAVE_SHL_LOAD 131 | 132 | /* Define if you have the libdl library or equivalent. */ 133 | #undef HAVE_LIBDL 134 | 135 | /* Define if you have the libdl library or equivalent. */ 136 | #undef HAVE_LIBDL 137 | 138 | /* Define if you have the libdl library or equivalent. */ 139 | #undef HAVE_LIBDL 140 | 141 | /* Define if you have the GNU dld library. */ 142 | #undef HAVE_DLD 143 | 144 | /* Define if dlsym() requires a leading underscore in symbol names. */ 145 | #undef NEED_USCORE 146 | 147 | /* Define if the OS needs help to load dependent libraries for dlopen(). */ 148 | #undef LTDL_DLOPEN_DEPLIBS 149 | 150 | /* Define to a type to use for `error_t' if it is not otherwise available. */ 151 | #undef error_t 152 | 153 | -------------------------------------------------------------------------------- /libltdl/configure.in: -------------------------------------------------------------------------------- 1 | dnl Process this file with autoconf to create configure. 2 | 3 | AC_INIT(ltdl.c) 4 | 5 | dnl We shouldn't be using these internal macros of autoconf, 6 | dnl but CONFIG_AUX_DIR($with_auxdir) breaks automake. 7 | AC_ARG_WITH(auxdir, 8 | [ --with-auxdir=DIR path to autoconf auxiliary files], 9 | [AC_CONFIG_AUX_DIRS($with_auxdir)], 10 | [AC_CONFIG_AUX_DIR_DEFAULT]) 11 | 12 | if test -z "$enable_ltdl_install$enable_ltdl_convenience"; then 13 | if test -f ${srcdir}/ltmain.sh; then 14 | # if libltdl is libtoolized, it is assumed to be stand-alone and 15 | # installed unless the command line overrides it (tested above) 16 | enable_ltdl_install=yes 17 | else 18 | AC_MSG_WARN([*** The top-level configure must select either]) 19 | AC_MSG_WARN([*** [A""C_LIBLTDL_INSTALLABLE] or [A""C_LIBLTDL_CONVENIENCE].]) 20 | AC_MSG_ERROR([*** Maybe you want to --enable-ltdl-install?]) 21 | fi 22 | fi 23 | 24 | AM_INIT_AUTOMAKE(libltdl,1.2,-) 25 | AM_CONFIG_HEADER(config.h:config-h.in) 26 | AM_MAINTAINER_MODE 27 | 28 | AC_PROG_CC 29 | AC_C_CONST 30 | AC_C_INLINE 31 | 32 | AC_LIBTOOL_WIN32_DLL 33 | AM_PROG_LIBTOOL 34 | AC_SUBST(LIBTOOL_DEPS) 35 | 36 | AC_LIB_LTDL 37 | 38 | dnl Output the makefile 39 | AC_OUTPUT(Makefile) 40 | 41 | # Local Variables: 42 | # mode:shell-script 43 | # sh-indentation:2 44 | # End: 45 | -------------------------------------------------------------------------------- /libmcrypt.spec: -------------------------------------------------------------------------------- 1 | Summary: libmcrypt is a data encryption library. 2 | Name: libmcrypt 3 | Version: 2.5.8 4 | Release: 1 5 | Copyright: LGPL 6 | Source: ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/%{name}-%{version}.tar.gz 7 | Vendor: Nikos Mavroyanopoulos 8 | Group: System Environment/Libraries 9 | Packager: Germano Rizzo 10 | Buildroot: %{_tmppath}/%{name}-%{version}-root 11 | Prefix: /usr 12 | 13 | %description 14 | libmcrypt is a data encryption library. The library is thread safe 15 | and provides encryption and decryption functions. This version of the 16 | library supports many encryption algorithms and encryption modes. Some 17 | algorithms which are supported: 18 | SERPENT, RIJNDAEL, 3DES, GOST, SAFER+, CAST-256, RC2, XTEA, 3WAY, 19 | TWOFISH, BLOWFISH, ARCFOUR, WAKE and more. 20 | 21 | %package devel 22 | Summary: Development files of the libmcrypt data encryption library. 23 | Group: Development/Libraries 24 | Requires: libmcrypt = %{version} 25 | 26 | %description devel 27 | Header file and static libraries of libmcrypt data encryption library. 28 | 29 | %prep 30 | %setup 31 | 32 | %build 33 | ./configure --prefix=%{prefix} 34 | 35 | make 36 | 37 | %install 38 | rm -rf $RPM_BUILD_ROOT 39 | 40 | make DESTDIR=$RPM_BUILD_ROOT install 41 | 42 | %clean 43 | rm -rf ${RPM_BUILD_ROOT} 44 | 45 | %post 46 | ldconfig 47 | 48 | %postun 49 | ldconfig 50 | 51 | %files 52 | #%defattr(-, root, root, 0755) 53 | %{_libdir}/libmcrypt.so 54 | %{_libdir}/libmcrypt.so* 55 | 56 | %files devel 57 | #%defattr(-, root, root, 0755) 58 | %doc doc/README* doc/example.c AUTHORS ChangeLog KNOWN-BUGS NEWS 59 | %doc THANKS README TODO 60 | %{_libdir}/libmcrypt.la 61 | %{_includedir}/mcrypt.h 62 | %{prefix}/man/man3/mcrypt.* 63 | %{_bindir}/libmcrypt-config 64 | %{_datadir}/aclocal/libmcrypt.m4 65 | 66 | %changelog 67 | * Tue Dec 17 2002 Germano Rizzo 68 | - modified for new installation structure 69 | 70 | * Fri Feb 01 2002 Germano Rizzo 71 | - built basing on Peter Soos' SPEC file 72 | 73 | * Mon Oct 01 2001 Peter Soos 74 | - rebuilt under RedHat Linux 7.2 beta 75 | - version 2.4.17 76 | 77 | * Fri May 04 2001 Peter Soos 78 | - rebuilt under RedHat Linux 7.1 79 | 80 | * Wed Apr 18 2001 Peter Soos 81 | - RedHat Linux 7.0 82 | 83 | * Thu Feb 15 2001 Peter Soos 84 | - version 2.4.9 85 | 86 | * Thu Nov 02 2000 Peter Soos 87 | - version 2.4.5 88 | 89 | * Fri Jun 23 2000 Peter Soos 90 | - version 2.4.4 91 | 92 | * Sun Nov 07 1999 Peter Soos 93 | - Separate this package from the mcrypt package 94 | -------------------------------------------------------------------------------- /libmcrypt.spec.in: -------------------------------------------------------------------------------- 1 | Summary: libmcrypt is a data encryption library. 2 | Name: @PACKAGE@ 3 | Version: @VERSION@ 4 | Release: 1 5 | Copyright: LGPL 6 | Source: ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/%{name}-%{version}.tar.gz 7 | Vendor: Nikos Mavroyanopoulos 8 | Group: System Environment/Libraries 9 | Packager: Germano Rizzo 10 | Buildroot: %{_tmppath}/%{name}-%{version}-root 11 | Prefix: /usr 12 | 13 | %description 14 | libmcrypt is a data encryption library. The library is thread safe 15 | and provides encryption and decryption functions. This version of the 16 | library supports many encryption algorithms and encryption modes. Some 17 | algorithms which are supported: 18 | SERPENT, RIJNDAEL, 3DES, GOST, SAFER+, CAST-256, RC2, XTEA, 3WAY, 19 | TWOFISH, BLOWFISH, ARCFOUR, WAKE and more. 20 | 21 | %package devel 22 | Summary: Development files of the libmcrypt data encryption library. 23 | Group: Development/Libraries 24 | Requires: libmcrypt = %{version} 25 | 26 | %description devel 27 | Header file and static libraries of libmcrypt data encryption library. 28 | 29 | %prep 30 | %setup 31 | 32 | %build 33 | ./configure --prefix=%{prefix} 34 | 35 | make 36 | 37 | %install 38 | rm -rf $RPM_BUILD_ROOT 39 | 40 | make DESTDIR=$RPM_BUILD_ROOT install 41 | 42 | %clean 43 | rm -rf ${RPM_BUILD_ROOT} 44 | 45 | %post 46 | ldconfig 47 | 48 | %postun 49 | ldconfig 50 | 51 | %files 52 | #%defattr(-, root, root, 0755) 53 | %{_libdir}/libmcrypt.so 54 | %{_libdir}/libmcrypt.so* 55 | 56 | %files devel 57 | #%defattr(-, root, root, 0755) 58 | %doc doc/README* doc/example.c AUTHORS ChangeLog KNOWN-BUGS NEWS 59 | %doc THANKS README TODO 60 | %{_libdir}/libmcrypt.la 61 | %{_includedir}/mcrypt.h 62 | %{prefix}/man/man3/mcrypt.* 63 | %{_bindir}/libmcrypt-config 64 | %{_datadir}/aclocal/libmcrypt.m4 65 | 66 | %changelog 67 | * Tue Dec 17 2002 Germano Rizzo 68 | - modified for new installation structure 69 | 70 | * Fri Feb 01 2002 Germano Rizzo 71 | - built basing on Peter Soos' SPEC file 72 | 73 | * Mon Oct 01 2001 Peter Soos 74 | - rebuilt under RedHat Linux 7.2 beta 75 | - version 2.4.17 76 | 77 | * Fri May 04 2001 Peter Soos 78 | - rebuilt under RedHat Linux 7.1 79 | 80 | * Wed Apr 18 2001 Peter Soos 81 | - RedHat Linux 7.0 82 | 83 | * Thu Feb 15 2001 Peter Soos 84 | - version 2.4.9 85 | 86 | * Thu Nov 02 2000 Peter Soos 87 | - version 2.4.5 88 | 89 | * Fri Jun 23 2000 Peter Soos 90 | - version 2.4.4 91 | 92 | * Sun Nov 07 1999 Peter Soos 93 | - Separate this package from the mcrypt package 94 | -------------------------------------------------------------------------------- /mkinstalldirs: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # mkinstalldirs --- make directory hierarchy 3 | # Author: Noah Friedman 4 | # Created: 1993-05-16 5 | # Public domain 6 | 7 | # $Id: mkinstalldirs,v 1.13 1999/01/05 03:18:55 bje Exp $ 8 | 9 | errstatus=0 10 | 11 | for file 12 | do 13 | set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'` 14 | shift 15 | 16 | pathcomp= 17 | for d 18 | do 19 | pathcomp="$pathcomp$d" 20 | case "$pathcomp" in 21 | -* ) pathcomp=./$pathcomp ;; 22 | esac 23 | 24 | if test ! -d "$pathcomp"; then 25 | echo "mkdir $pathcomp" 26 | 27 | mkdir "$pathcomp" || lasterr=$? 28 | 29 | if test ! -d "$pathcomp"; then 30 | errstatus=$lasterr 31 | fi 32 | fi 33 | 34 | pathcomp="$pathcomp/" 35 | done 36 | done 37 | 38 | exit $errstatus 39 | 40 | # mkinstalldirs ends here 41 | -------------------------------------------------------------------------------- /modules/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | 3 | SUBDIRS = algorithms modes 4 | 5 | 6 | -------------------------------------------------------------------------------- /modules/algorithms/3-way.c: -------------------------------------------------------------------------------- 1 | /********************************************************************\ 2 | * * 3 | * C specification of the threeway block cipher * 4 | * * 5 | * found in ftp://ftp.funet.fi/pub/crypt/ * 6 | \********************************************************************/ 7 | 8 | /* modified in order to use the libmcrypt API by Nikos Mavroyanopoulos 9 | * All modifications are placed under the license of libmcrypt. 10 | */ 11 | 12 | /* $Id: 3-way.c,v 1.12 2003/01/19 17:48:27 nmav Exp $ */ 13 | 14 | #include 15 | 16 | #include 17 | #include "3-way.h" 18 | 19 | #define STRT_E 0x0b0b /* round constant of first encryption round */ 20 | #define STRT_D 0xb1b1 /* round constant of first decryption round */ 21 | #define NMBR 11 /* number of rounds is 11 */ 22 | 23 | #define _mcrypt_set_key threeway_LTX__mcrypt_set_key 24 | #define _mcrypt_encrypt threeway_LTX__mcrypt_encrypt 25 | #define _mcrypt_decrypt threeway_LTX__mcrypt_decrypt 26 | #define _mcrypt_get_size threeway_LTX__mcrypt_get_size 27 | #define _mcrypt_get_block_size threeway_LTX__mcrypt_get_block_size 28 | #define _is_block_algorithm threeway_LTX__is_block_algorithm 29 | #define _mcrypt_get_key_size threeway_LTX__mcrypt_get_key_size 30 | #define _mcrypt_get_supported_key_sizes threeway_LTX__mcrypt_get_supported_key_sizes 31 | #define _mcrypt_get_algorithms_name threeway_LTX__mcrypt_get_algorithms_name 32 | #define _mcrypt_self_test threeway_LTX__mcrypt_self_test 33 | #define _mcrypt_algorithm_version threeway_LTX__mcrypt_algorithm_version 34 | 35 | WIN32DLL_DEFINE 36 | int _mcrypt_set_key(word32 * k, word32 * input_key, int len) 37 | { 38 | k[0] = 0; 39 | k[2] = 0; 40 | k[1] = 0; 41 | memmove(k, input_key, len); 42 | return 0; 43 | } 44 | 45 | 46 | void mu(word32 * a) 47 | { /* inverts the order of the bits of a */ 48 | int i; 49 | word32 b[3]; 50 | 51 | b[0] = b[1] = b[2] = 0; 52 | for (i = 0; i < 32; i++) { 53 | b[0] <<= 1; 54 | b[1] <<= 1; 55 | b[2] <<= 1; 56 | if (a[0] & 1) 57 | b[2] |= 1; 58 | if (a[1] & 1) 59 | b[1] |= 1; 60 | if (a[2] & 1) 61 | b[0] |= 1; 62 | a[0] >>= 1; 63 | a[1] >>= 1; 64 | a[2] >>= 1; 65 | } 66 | 67 | a[0] = b[0]; 68 | a[1] = b[1]; 69 | a[2] = b[2]; 70 | } 71 | 72 | void gamma(word32 * a) 73 | { /* the nonlinear step */ 74 | word32 b[3]; 75 | 76 | b[0] = a[0] ^ (a[1] | (~a[2])); 77 | b[1] = a[1] ^ (a[2] | (~a[0])); 78 | b[2] = a[2] ^ (a[0] | (~a[1])); 79 | 80 | a[0] = b[0]; 81 | a[1] = b[1]; 82 | a[2] = b[2]; 83 | } 84 | 85 | 86 | void theta(word32 * a) 87 | { /* the linear step */ 88 | word32 b[3]; 89 | 90 | b[0] = 91 | a[0] ^ (a[0] >> 16) ^ (a[1] << 16) ^ (a[1] >> 16) ^ (a[2] << 92 | 16) ^ 93 | (a[1] >> 24) ^ (a[2] << 8) ^ (a[2] >> 8) ^ (a[0] << 24) ^ (a[2] 94 | >> 95 | 16) 96 | ^ (a[0] << 16) ^ (a[2] >> 24) ^ (a[0] << 8); 97 | b[1] = 98 | a[1] ^ (a[1] >> 16) ^ (a[2] << 16) ^ (a[2] >> 16) ^ (a[0] << 99 | 16) ^ 100 | (a[2] >> 24) ^ (a[0] << 8) ^ (a[0] >> 8) ^ (a[1] << 24) ^ (a[0] 101 | >> 102 | 16) 103 | ^ (a[1] << 16) ^ (a[0] >> 24) ^ (a[1] << 8); 104 | b[2] = 105 | a[2] ^ (a[2] >> 16) ^ (a[0] << 16) ^ (a[0] >> 16) ^ (a[1] << 106 | 16) ^ 107 | (a[0] >> 24) ^ (a[1] << 8) ^ (a[1] >> 8) ^ (a[2] << 24) ^ (a[1] 108 | >> 109 | 16) 110 | ^ (a[2] << 16) ^ (a[1] >> 24) ^ (a[2] << 8); 111 | 112 | a[0] = b[0]; 113 | a[1] = b[1]; 114 | a[2] = b[2]; 115 | } 116 | 117 | void pi_1(word32 * a) 118 | { 119 | a[0] = (a[0] >> 10) ^ (a[0] << 22); 120 | a[2] = (a[2] << 1) ^ (a[2] >> 31); 121 | } 122 | 123 | void pi_2(word32 * a) 124 | { 125 | a[0] = (a[0] << 1) ^ (a[0] >> 31); 126 | a[2] = (a[2] >> 10) ^ (a[2] << 22); 127 | } 128 | 129 | void rho(word32 * a) 130 | { /* the round function */ 131 | theta(a); 132 | pi_1(a); 133 | gamma(a); 134 | pi_2(a); 135 | } 136 | 137 | void rndcon_gen(word32 strt, word32 * rtab) 138 | { /* generates the round constants */ 139 | int i; 140 | 141 | for (i = 0; i <= NMBR; i++) { 142 | rtab[i] = strt; 143 | strt <<= 1; 144 | if (strt & 0x10000) 145 | strt ^= 0x11011; 146 | } 147 | } 148 | 149 | WIN32DLL_DEFINE void _mcrypt_encrypt(word32 * tk, word32 * ta) 150 | { 151 | int i; 152 | word32 rcon[NMBR + 1]; 153 | word32 a[3], k[3]; 154 | 155 | /* Added to make it compatible with bigendian machines 156 | * --nikos 157 | */ 158 | 159 | #ifndef WORDS_BIGENDIAN 160 | a[0] = byteswap32(ta[0]); 161 | a[1] = byteswap32(ta[1]); 162 | a[2] = byteswap32(ta[2]); 163 | k[0] = byteswap32(tk[0]); 164 | k[1] = byteswap32(tk[1]); 165 | k[2] = byteswap32(tk[2]); 166 | #else 167 | a[0] = ta[0]; 168 | a[1] = ta[1]; 169 | a[2] = ta[2]; 170 | k[0] = (tk[0]); 171 | k[1] = (tk[1]); 172 | k[2] = (tk[2]); 173 | #endif 174 | 175 | rndcon_gen(STRT_E, rcon); 176 | for (i = 0; i < NMBR; i++) { 177 | a[0] ^= k[0] ^ (rcon[i] << 16); 178 | a[1] ^= k[1]; 179 | a[2] ^= k[2] ^ rcon[i]; 180 | rho(a); 181 | } 182 | a[0] ^= k[0] ^ (rcon[NMBR] << 16); 183 | a[1] ^= k[1]; 184 | a[2] ^= k[2] ^ rcon[NMBR]; 185 | theta(a); 186 | 187 | #ifndef WORDS_BIGENDIAN 188 | ta[0] = byteswap32(a[0]); 189 | ta[1] = byteswap32(a[1]); 190 | ta[2] = byteswap32(a[2]); 191 | #else 192 | ta[0] = a[0]; 193 | ta[1] = a[1]; 194 | ta[2] = a[2]; 195 | #endif 196 | 197 | } 198 | 199 | 200 | WIN32DLL_DEFINE void _mcrypt_decrypt(word32 * k, word32 * ta) 201 | { 202 | int i; 203 | word32 ki[3]; /* the `inverse' key */ 204 | word32 rcon[NMBR + 1]; /* the `inverse' round constants */ 205 | word32 a[3]; 206 | 207 | #ifndef WORDS_BIGENDIAN 208 | a[0] = byteswap32(ta[0]); 209 | a[1] = byteswap32(ta[1]); 210 | a[2] = byteswap32(ta[2]); 211 | ki[0] = byteswap32(k[0]); 212 | ki[1] = byteswap32(k[1]); 213 | ki[2] = byteswap32(k[2]); 214 | #else 215 | a[0] = ta[0]; 216 | a[1] = ta[1]; 217 | a[2] = ta[2]; 218 | ki[0] = k[0]; 219 | ki[1] = k[1]; 220 | ki[2] = k[2]; 221 | #endif 222 | 223 | theta(ki); 224 | mu(ki); 225 | 226 | rndcon_gen(STRT_D, rcon); 227 | 228 | mu(a); 229 | for (i = 0; i < NMBR; i++) { 230 | a[0] ^= ki[0] ^ (rcon[i] << 16); 231 | a[1] ^= ki[1]; 232 | a[2] ^= ki[2] ^ rcon[i]; 233 | rho(a); 234 | } 235 | a[0] ^= ki[0] ^ (rcon[NMBR] << 16); 236 | a[1] ^= ki[1]; 237 | a[2] ^= ki[2] ^ rcon[NMBR]; 238 | theta(a); 239 | mu(a); 240 | 241 | #ifndef WORDS_BIGENDIAN 242 | ta[0] = byteswap32(a[0]); 243 | ta[1] = byteswap32(a[1]); 244 | ta[2] = byteswap32(a[2]); 245 | 246 | #else 247 | ta[0] = a[0]; 248 | ta[1] = a[1]; 249 | ta[2] = a[2]; 250 | #endif 251 | 252 | } 253 | 254 | WIN32DLL_DEFINE int _mcrypt_get_size() 255 | { 256 | return 3 * sizeof(word32); 257 | } 258 | WIN32DLL_DEFINE int _mcrypt_get_block_size() 259 | { 260 | return 12; 261 | } 262 | WIN32DLL_DEFINE int _is_block_algorithm() 263 | { 264 | return 1; 265 | } 266 | WIN32DLL_DEFINE int _mcrypt_get_key_size() 267 | { 268 | return 12; 269 | } 270 | 271 | static const int key_sizes[] = { 12 }; 272 | WIN32DLL_DEFINE const int *_mcrypt_get_supported_key_sizes(int *len) 273 | { 274 | *len = sizeof(key_sizes)/sizeof(int); 275 | return key_sizes; 276 | 277 | } 278 | WIN32DLL_DEFINE const char *_mcrypt_get_algorithms_name() 279 | { 280 | return "3-WAY"; 281 | } 282 | 283 | #define CIPHER "46823287358d68f6e034ca62" 284 | 285 | WIN32DLL_DEFINE int _mcrypt_self_test() 286 | { 287 | char *keyword; 288 | unsigned char plaintext[16]; 289 | unsigned char ciphertext[16]; 290 | int blocksize = _mcrypt_get_block_size(), j; 291 | void *key; 292 | unsigned char cipher_tmp[200]; 293 | 294 | keyword = calloc(1, _mcrypt_get_key_size()); 295 | if (keyword == NULL) 296 | return -1; 297 | 298 | for (j = 0; j < _mcrypt_get_key_size(); j++) { 299 | keyword[j] = ((j * 2 + 10) % 256); 300 | } 301 | 302 | for (j = 0; j < blocksize; j++) { 303 | plaintext[j] = j % 256; 304 | } 305 | key = malloc(_mcrypt_get_size()); 306 | if (key == NULL) 307 | return -1; 308 | 309 | memcpy(ciphertext, plaintext, blocksize); 310 | 311 | _mcrypt_set_key(key, (void *) keyword, _mcrypt_get_key_size()); 312 | free(keyword); 313 | 314 | _mcrypt_encrypt(key, (void *) ciphertext); 315 | 316 | for (j = 0; j < blocksize; j++) { 317 | sprintf(&((char *) cipher_tmp)[2 * j], "%.2x", 318 | ciphertext[j]); 319 | } 320 | 321 | if (strcmp((char *) cipher_tmp, CIPHER) != 0) { 322 | printf("failed compatibility\n"); 323 | printf("Expected: %s\nGot: %s\n", CIPHER, 324 | (char *) cipher_tmp); 325 | free(key); 326 | return -1; 327 | } 328 | _mcrypt_decrypt(key, (void *) ciphertext); 329 | free(key); 330 | 331 | if (strcmp(ciphertext, plaintext) != 0) { 332 | printf("failed internally\n"); 333 | return -1; 334 | } 335 | 336 | return 0; 337 | } 338 | 339 | WIN32DLL_DEFINE word32 _mcrypt_algorithm_version() 340 | { 341 | return 20010801; 342 | } 343 | 344 | #ifdef WIN32 345 | # ifdef USE_LTDL 346 | WIN32DLL_DEFINE int main (void) 347 | { 348 | /* empty main function to avoid linker error (see cygwin FAQ) */ 349 | } 350 | # endif 351 | #endif 352 | -------------------------------------------------------------------------------- /modules/algorithms/3-way.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/winlibs/libmcrypt/1e93cbe97a463a2c0c62338d607b17fe011eb77e/modules/algorithms/3-way.h -------------------------------------------------------------------------------- /modules/algorithms/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | DEFS = @DEFS@ 3 | INCLUDES = -I. -I../.. $(INCLTDL) -I../../lib 4 | 5 | EXTRA_DIST = twofish.h saferplus.h rijndael.h \ 6 | rc2.h serpent.h cast-256.h blowfish.h \ 7 | cast-128.h cast-128_sboxes.h des.h tripledes.h \ 8 | 3-way.h enigma.h arcfour.h wake.h \ 9 | safer.h xtea.h panama.h 10 | 11 | pkglib_LTLIBRARIES = @INSTALL_ALGORITHM_MODULES@ 12 | 13 | EXTRA_LTLIBRARIES = twofish.la rijndael-128.la \ 14 | rijndael-192.la rijndael-256.la saferplus.la rc2.la xtea.la \ 15 | serpent.la safer-sk64.la safer-sk128.la cast-256.la loki97.la \ 16 | gost.la threeway.la cast-128.la blowfish.la des.la blowfish-compat.la \ 17 | tripledes.la enigma.la arcfour.la panama.la wake.la 18 | 19 | noinst_LTLIBRARIES = @NOINSTALL_ALGORITHM_MODULES@ 20 | 21 | twofish_la_SOURCES = twofish.c 22 | twofish_la_LDFLAGS = -module -avoid-version -rpath $(pkglibdir) 23 | wake_la_SOURCES = wake.c 24 | wake_la_LDFLAGS = -module -avoid-version -rpath $(pkglibdir) 25 | panama_la_SOURCES = panama.c 26 | panama_la_LDFLAGS = -module -avoid-version -rpath $(pkglibdir) 27 | rijndael_128_la_SOURCES = rijndael-128.c 28 | rijndael_128_la_LDFLAGS = -module -avoid-version -rpath $(pkglibdir) 29 | rijndael_192_la_SOURCES = rijndael-192.c 30 | rijndael_192_la_LDFLAGS = -module -avoid-version -rpath $(pkglibdir) 31 | rijndael_256_la_SOURCES = rijndael-256.c 32 | rijndael_256_la_LDFLAGS = -module -avoid-version -rpath $(pkglibdir) 33 | saferplus_la_SOURCES = saferplus.c 34 | saferplus_la_LDFLAGS = -module -avoid-version -rpath $(pkglibdir) 35 | serpent_la_SOURCES = serpent.c 36 | serpent_la_LDFLAGS = -module -avoid-version -rpath $(pkglibdir) 37 | xtea_la_SOURCES = xtea.c 38 | xtea_la_LDFLAGS = -module -avoid-version -rpath $(pkglibdir) 39 | rc2_la_SOURCES = rc2.c 40 | rc2_la_LDFLAGS = -module -avoid-version -rpath $(pkglibdir) 41 | safer_sk64_la_SOURCES = safer64.c 42 | safer_sk64_la_LDFLAGS = -module -avoid-version -rpath $(pkglibdir) 43 | safer_sk128_la_SOURCES = safer128.c 44 | safer_sk128_la_LDFLAGS = -module -avoid-version -rpath $(pkglibdir) 45 | cast_256_la_SOURCES = cast-256.c 46 | cast_256_la_LDFLAGS = -module -avoid-version -rpath $(pkglibdir) 47 | loki97_la_SOURCES = loki97.c 48 | loki97_la_LDFLAGS = -module -avoid-version -rpath $(pkglibdir) 49 | gost_la_SOURCES = gost.c 50 | gost_la_LDFLAGS = -module -avoid-version -rpath $(pkglibdir) 51 | threeway_la_SOURCES = 3-way.c 52 | threeway_la_LDFLAGS = -module -avoid-version -rpath $(pkglibdir) 53 | blowfish_la_SOURCES = blowfish.c 54 | blowfish_la_LDFLAGS = -module -avoid-version -rpath $(pkglibdir) 55 | blowfish_compat_la_SOURCES = blowfish-compat.c 56 | blowfish_compat_la_LDFLAGS = -module -avoid-version -rpath $(pkglibdir) 57 | cast_128_la_SOURCES = cast-128.c 58 | cast_128_la_LDFLAGS = -module -avoid-version -rpath $(pkglibdir) 59 | des_la_SOURCES = des.c 60 | des_la_LDFLAGS = -module -avoid-version -rpath $(pkglibdir) 61 | tripledes_la_SOURCES = tripledes.c 62 | tripledes_la_LDFLAGS = -module -avoid-version -rpath $(pkglibdir) 63 | enigma_la_SOURCES = enigma.c 64 | enigma_la_LDFLAGS = -module -avoid-version -rpath $(pkglibdir) 65 | arcfour_la_SOURCES = arcfour.c 66 | arcfour_la_LDFLAGS = -module -avoid-version -rpath $(pkglibdir) 67 | -------------------------------------------------------------------------------- /modules/algorithms/arcfour.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1998,1999,2000,2001 Nikos Mavroyanopoulos 3 | * 4 | * This library is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU Library General Public License as published 6 | * by the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include "arcfour.h" 24 | 25 | #define _mcrypt_set_key arcfour_LTX__mcrypt_set_key 26 | #define _mcrypt_encrypt arcfour_LTX__mcrypt_encrypt 27 | #define _mcrypt_decrypt arcfour_LTX__mcrypt_decrypt 28 | #define _mcrypt_get_size arcfour_LTX__mcrypt_get_size 29 | #define _mcrypt_get_block_size arcfour_LTX__mcrypt_get_block_size 30 | #define _is_block_algorithm arcfour_LTX__is_block_algorithm 31 | #define _mcrypt_get_key_size arcfour_LTX__mcrypt_get_key_size 32 | #define _mcrypt_get_algo_iv_size arcfour_LTX__mcrypt_get_algo_iv_size 33 | #define _mcrypt_get_supported_key_sizes arcfour_LTX__mcrypt_get_supported_key_sizes 34 | #define _mcrypt_get_algorithms_name arcfour_LTX__mcrypt_get_algorithms_name 35 | #define _mcrypt_self_test arcfour_LTX__mcrypt_self_test 36 | #define _mcrypt_algorithm_version arcfour_LTX__mcrypt_algorithm_version 37 | 38 | #define swap_byte(x,y) tmp = (x); (x) = (y); (y) = tmp 39 | 40 | /* #define USE_IV */ 41 | /* IV was an mcrypt extension */ 42 | 43 | WIN32DLL_DEFINE void _mcrypt_encrypt(arcfour_key * key, byte * buffer_ptr, int buffer_len); 44 | 45 | /* key is the state that should be allocated by the caller */ 46 | #define STATE key->state 47 | #define I key->i 48 | #define J key->j 49 | WIN32DLL_DEFINE 50 | int _mcrypt_set_key(arcfour_key * key, byte * key_data, int key_len, 51 | char *IV, int iv_len) 52 | { 53 | register int tmp, j, i; 54 | byte *state = STATE; 55 | int ivindex; 56 | 57 | for (i = 0; i < 256; i++) 58 | state[i] = i; 59 | 60 | I = 0; 61 | J = 0; 62 | ivindex = 0; 63 | 64 | for (j = i = 0; i < 256; i++) { 65 | j += state[i] + key_data[i % key_len]; 66 | #ifdef USE_IV 67 | if (iv_len > 0 && IV != NULL) 68 | j += IV[ivindex]; 69 | #endif 70 | j &= 0xff; 71 | swap_byte(state[i], state[j]); 72 | #ifdef USE_IV 73 | if (iv_len > 0) 74 | ivindex = (ivindex + 1) % iv_len; 75 | #endif 76 | } 77 | 78 | return 0; 79 | } 80 | 81 | WIN32DLL_DEFINE 82 | void _mcrypt_encrypt(arcfour_key * key, byte * buffer_ptr, 83 | int buffer_len) 84 | { 85 | register int tmp; 86 | register int counter; 87 | register int i = I, j = J; 88 | byte *state = STATE; 89 | 90 | 91 | for (counter = 0; counter < buffer_len; counter++) { 92 | i++; 93 | i &= 0xff; 94 | j += state[i]; 95 | j &= 0xff; 96 | 97 | /* swap state[i] and state[j] */ 98 | swap_byte(state[i], state[j]); 99 | buffer_ptr[counter] ^= state[(state[i] + tmp) & 0xff]; 100 | } 101 | J = j; 102 | I = i; 103 | } 104 | 105 | /* this is the same with mcrypt_encrypt */ 106 | WIN32DLL_DEFINE 107 | void _mcrypt_decrypt(arcfour_key * key, byte * buffer_ptr, 108 | int buffer_len) 109 | { 110 | _mcrypt_encrypt(key, buffer_ptr, buffer_len); 111 | } 112 | 113 | WIN32DLL_DEFINE int _mcrypt_get_size() 114 | { 115 | return sizeof(arcfour_key); 116 | } 117 | WIN32DLL_DEFINE int _mcrypt_get_block_size() 118 | { 119 | return 1; 120 | } 121 | WIN32DLL_DEFINE int _mcrypt_get_algo_iv_size() 122 | { 123 | #ifdef USE_IV 124 | return 32; 125 | #else 126 | return 0; 127 | #endif 128 | } 129 | WIN32DLL_DEFINE int _is_block_algorithm() 130 | { 131 | return 0; 132 | } 133 | WIN32DLL_DEFINE int _mcrypt_get_key_size() 134 | { 135 | return 256; 136 | } 137 | WIN32DLL_DEFINE const int *_mcrypt_get_supported_key_sizes(int *len) 138 | { 139 | *len = 0; 140 | return NULL; 141 | } 142 | WIN32DLL_DEFINE const char *_mcrypt_get_algorithms_name() 143 | { 144 | return "RC4"; 145 | } 146 | 147 | #define CIPHER "3abaa03a286e24c4196d292ab72934d6854c3eee" 148 | 149 | WIN32DLL_DEFINE int _mcrypt_self_test() 150 | { 151 | char *keyword; 152 | unsigned char plaintext[20]; 153 | unsigned char ciphertext[20]; 154 | int blocksize = 20, j; 155 | void *key; 156 | unsigned char cipher_tmp[200]; 157 | 158 | keyword = calloc(1, _mcrypt_get_key_size()); 159 | if (keyword == NULL) 160 | return -1; 161 | 162 | for (j = 0; j < _mcrypt_get_key_size(); j++) { 163 | keyword[j] = ((j * 2 + 10) % 256); 164 | } 165 | 166 | for (j = 0; j < blocksize; j++) { 167 | plaintext[j] = j % 256; 168 | } 169 | key = malloc(_mcrypt_get_size()); 170 | if (key == NULL) 171 | return -1; 172 | 173 | memcpy(ciphertext, plaintext, blocksize); 174 | 175 | _mcrypt_set_key(key, (void *) keyword, _mcrypt_get_key_size(), 176 | NULL, 0); 177 | _mcrypt_encrypt(key, (void *) ciphertext, blocksize); 178 | 179 | for (j = 0; j < blocksize; j++) { 180 | sprintf(&((char *) cipher_tmp)[2 * j], "%.2x", 181 | ciphertext[j]); 182 | } 183 | 184 | if (strcmp((char *) cipher_tmp, CIPHER) != 0) { 185 | printf("failed compatibility\n"); 186 | printf("Expected: %s\nGot: %s\n", CIPHER, 187 | (char *) cipher_tmp); 188 | free(keyword); 189 | free(key); 190 | return -1; 191 | } 192 | 193 | _mcrypt_set_key(key, (void *) keyword, _mcrypt_get_key_size(), 194 | NULL, 0); 195 | _mcrypt_decrypt(key, (void *) ciphertext, blocksize); 196 | 197 | free(keyword); 198 | free(key); 199 | if (strcmp(ciphertext, plaintext) != 0) { 200 | printf("failed internally\n"); 201 | return -1; 202 | } 203 | 204 | return 0; 205 | } 206 | 207 | WIN32DLL_DEFINE word32 _mcrypt_algorithm_version() 208 | { 209 | return 20020610; 210 | } 211 | 212 | #ifdef WIN32 213 | # ifdef USE_LTDL 214 | WIN32DLL_DEFINE int main (void) 215 | { 216 | /* empty main function to avoid linker error (see cygwin FAQ) */ 217 | } 218 | # endif 219 | #endif 220 | -------------------------------------------------------------------------------- /modules/algorithms/arcfour.h: -------------------------------------------------------------------------------- 1 | typedef struct arcfour_key 2 | { 3 | byte state[256]; 4 | byte i; 5 | byte j; 6 | } arcfour_key; 7 | 8 | -------------------------------------------------------------------------------- /modules/algorithms/blowfish.h: -------------------------------------------------------------------------------- 1 | /* for blowfish */ 2 | typedef struct { 3 | word32 S[4][256],P[18]; 4 | } blf_ctx; 5 | 6 | -------------------------------------------------------------------------------- /modules/algorithms/cast-128.h: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: cast-128.h,v 1.1.1.1 2000/05/22 13:08:18 nmav Exp $ 3 | * 4 | * CAST-128 in C 5 | * Written by Steve Reid 6 | * 100% Public Domain - no warranty 7 | * Released 1997.10.11 8 | */ 9 | 10 | #ifndef _CAST_H_INCLUDED 11 | #define _CAST_H_INCLUDED 12 | 13 | #define CAST_MIN_KEYSIZE 5 14 | #define CAST_MAX_KEYSIZE 16 15 | #define CAST_BLOCKSIZE 8 16 | 17 | #define CAST_SMALL_KEY 10 18 | #define CAST_SMALL_ROUNDS 12 19 | #define CAST_FULL_ROUNDS 16 20 | 21 | typedef struct cast_key { 22 | word32 xkey[32]; /* Key, after expansion */ 23 | unsigned rounds; /* Number of rounds to use, 12 or 16 */ 24 | } CAST_KEY; 25 | 26 | #endif /* ifndef _CAST_H_INCLUDED */ 27 | 28 | -------------------------------------------------------------------------------- /modules/algorithms/cast-256.h: -------------------------------------------------------------------------------- 1 | typedef struct cast256_instance { 2 | word32 l_key[96]; 3 | } cast256_key; 4 | 5 | -------------------------------------------------------------------------------- /modules/algorithms/des.h: -------------------------------------------------------------------------------- 1 | typedef struct des_key { 2 | char kn[16][8]; 3 | word32 sp[8][64]; 4 | char iperm[16][16][8]; 5 | char fperm[16][16][8]; 6 | } DES_KEY; 7 | 8 | -------------------------------------------------------------------------------- /modules/algorithms/enigma.c: -------------------------------------------------------------------------------- 1 | /* 2 | * "enigma.c" is in file cbw.tar from 3 | * anonymous FTP host watmsg.waterloo.edu: pub/crypt/cbw.tar.Z 4 | * 5 | * A one-rotor machine designed along the lines of Enigma 6 | * but considerably trivialized. 7 | * 8 | * A public-domain replacement for the UNIX "crypt" command. 9 | * Changed to fit in mcrypt by nmav@hellug.gr 10 | */ 11 | 12 | /* modified in order to use the libmcrypt API by Nikos Mavroyanopoulos 13 | * All modifications are placed under the license of libmcrypt. 14 | */ 15 | 16 | /* $Id: enigma.c,v 1.13 2003/01/19 17:48:27 nmav Exp $ */ 17 | 18 | #include 19 | 20 | #include 21 | #include "enigma.h" 22 | 23 | #define _mcrypt_set_key enigma_LTX__mcrypt_set_key 24 | #define _mcrypt_encrypt enigma_LTX__mcrypt_encrypt 25 | #define _mcrypt_decrypt enigma_LTX__mcrypt_decrypt 26 | #define _mcrypt_get_size enigma_LTX__mcrypt_get_size 27 | #define _mcrypt_get_block_size enigma_LTX__mcrypt_get_block_size 28 | #define _is_block_algorithm enigma_LTX__is_block_algorithm 29 | #define _mcrypt_get_key_size enigma_LTX__mcrypt_get_key_size 30 | #define _mcrypt_get_algo_iv_size enigma_LTX__mcrypt_get_algo_iv_size 31 | #define _mcrypt_get_supported_key_sizes enigma_LTX__mcrypt_get_supported_key_sizes 32 | #define _mcrypt_get_algorithms_name enigma_LTX__mcrypt_get_algorithms_name 33 | #define _mcrypt_self_test enigma_LTX__mcrypt_self_test 34 | #define _mcrypt_algorithm_version enigma_LTX__mcrypt_algorithm_version 35 | 36 | /* it needs to be linked against libufc or libcrypt */ 37 | /* it no longer needs that. It just needs the password to be 38 | * transformed by unix crypt() or the mhash SCRYPT 39 | */ 40 | 41 | WIN32DLL_DEFINE 42 | int _mcrypt_set_key(CRYPT_KEY * ckey, char *password, int plen, 43 | void *u1, int u2) 44 | { 45 | int ic, i, k, temp; 46 | unsigned random; 47 | sword32 seed; 48 | 49 | 50 | Bzero(ckey, sizeof(CRYPT_KEY)); 51 | ckey->n1 = ckey->n2 = ckey->nr1 = ckey->nr2 = 0; 52 | 53 | if (plen > 13) 54 | plen = 13; 55 | 56 | memmove(ckey->cbuf, password, plen); 57 | 58 | seed = 123; 59 | for (i = 0; i < 13; i++) 60 | seed = seed * ckey->cbuf[i] + i; 61 | for (i = 0; i < ROTORSZ; i++) { 62 | ckey->t1[i] = i; 63 | ckey->deck[i] = i; 64 | } 65 | for (i = 0; i < ROTORSZ; i++) { 66 | seed = 5 * seed + ckey->cbuf[i % 13]; 67 | random = seed % 65521; 68 | k = ROTORSZ - 1 - i; 69 | ic = (random & MASK) % (k + 1); 70 | random >>= 8; 71 | 72 | temp = ckey->t1[k]; 73 | ckey->t1[k] = ckey->t1[ic]; 74 | ckey->t1[ic] = temp; 75 | if (ckey->t3[k] != 0) 76 | continue; 77 | 78 | ic = (random & MASK) % k; 79 | while (ckey->t3[ic] != 0) 80 | ic = (ic + 1) % k; 81 | ckey->t3[k] = ic; 82 | ckey->t3[ic] = k; 83 | } 84 | 85 | for (i = 0; i < ROTORSZ; i++) 86 | ckey->t2[ckey->t1[i] & MASK] = i; 87 | 88 | return 0; 89 | } 90 | 91 | 92 | int shuffle(CRYPT_KEY * ckey) 93 | { 94 | int i, ic, k, temp; 95 | unsigned random; 96 | static sword32 seed = 123; 97 | 98 | for (i = 0; i < ROTORSZ; i++) { 99 | seed = 5 * seed + ckey->cbuf[i % 13]; 100 | random = seed % 65521; 101 | k = ROTORSZ - 1 - i; 102 | ic = (random & MASK) % (k + 1); 103 | temp = ckey->deck[k]; 104 | ckey->deck[k] = ckey->deck[ic]; 105 | ckey->deck[ic] = temp; 106 | } 107 | return 0; 108 | } 109 | 110 | WIN32DLL_DEFINE 111 | void _mcrypt_encrypt(CRYPT_KEY * ckey, void *gtext, int textlen) 112 | { /* 0 or 1 */ 113 | int i, j; 114 | int secureflg = 0; 115 | char *text = gtext; 116 | 117 | for (j = 0; j < textlen; j++) { 118 | 119 | i = text[j]; 120 | if (secureflg) { 121 | ckey->nr1 = ckey->deck[ckey->n1] & MASK; 122 | ckey->nr2 = ckey->deck[ckey->nr1] & MASK; 123 | } else { 124 | ckey->nr1 = ckey->n1; 125 | } 126 | i = ckey-> 127 | t2[(ckey-> 128 | t3[(ckey->t1[(i + ckey->nr1) & MASK] + 129 | ckey->nr2) & MASK] - ckey->nr2) & MASK] - 130 | ckey->nr1; 131 | text[j] = i; 132 | ckey->n1++; 133 | if (ckey->n1 == ROTORSZ) { 134 | ckey->n1 = 0; 135 | ckey->n2++; 136 | if (ckey->n2 == ROTORSZ) 137 | ckey->n2 = 0; 138 | if (secureflg) { 139 | shuffle(ckey); 140 | } else { 141 | ckey->nr2 = ckey->n2; 142 | } 143 | } 144 | } 145 | 146 | return; 147 | } 148 | 149 | WIN32DLL_DEFINE 150 | void _mcrypt_decrypt(CRYPT_KEY * ckey, void *gtext, int textlen) 151 | { /* 0 or 1 */ 152 | int i, j; 153 | int secureflg = 0; 154 | char *text = gtext; 155 | 156 | 157 | for (j = 0; j < textlen; j++) { 158 | 159 | i = text[j]; 160 | if (secureflg) { 161 | ckey->nr1 = ckey->deck[ckey->n1] & MASK; 162 | ckey->nr2 = ckey->deck[ckey->nr1] & MASK; 163 | } else { 164 | ckey->nr1 = ckey->n1; 165 | } 166 | i = ckey-> 167 | t2[(ckey-> 168 | t3[(ckey->t1[(i + ckey->nr1) & MASK] + 169 | ckey->nr2) & MASK] - ckey->nr2) & MASK] - 170 | ckey->nr1; 171 | text[j] = i; 172 | ckey->n1++; 173 | if (ckey->n1 == ROTORSZ) { 174 | ckey->n1 = 0; 175 | ckey->n2++; 176 | if (ckey->n2 == ROTORSZ) 177 | ckey->n2 = 0; 178 | if (secureflg) { 179 | shuffle(ckey); 180 | } else { 181 | ckey->nr2 = ckey->n2; 182 | } 183 | } 184 | } 185 | 186 | return; 187 | } 188 | 189 | 190 | WIN32DLL_DEFINE int _mcrypt_get_size() 191 | { 192 | return sizeof(CRYPT_KEY); 193 | } 194 | WIN32DLL_DEFINE int _mcrypt_get_block_size() 195 | { 196 | return 1; 197 | } 198 | WIN32DLL_DEFINE int _mcrypt_get_algo_iv_size() 199 | { 200 | return 0; 201 | } 202 | WIN32DLL_DEFINE int _is_block_algorithm() 203 | { 204 | return 0; 205 | } 206 | WIN32DLL_DEFINE int _mcrypt_get_key_size() 207 | { 208 | return 13; 209 | } 210 | WIN32DLL_DEFINE const int *_mcrypt_get_supported_key_sizes(int *len) 211 | { 212 | *len = 0; 213 | return NULL; 214 | } 215 | 216 | WIN32DLL_DEFINE char *_mcrypt_get_algorithms_name() 217 | { 218 | return "enigma"; 219 | } 220 | 221 | #define CIPHER "f3edda7da20f8975884600f014d32c7a08e59d7b" 222 | 223 | WIN32DLL_DEFINE int _mcrypt_self_test() 224 | { 225 | char *keyword; 226 | unsigned char plaintext[20]; 227 | unsigned char ciphertext[20]; 228 | int blocksize = 20, j; 229 | void *key; 230 | unsigned char cipher_tmp[200]; 231 | 232 | keyword = calloc(1, _mcrypt_get_key_size()); 233 | if (keyword == NULL) 234 | return -1; 235 | 236 | strcpy(keyword, "enadyotr"); 237 | 238 | for (j = 0; j < blocksize; j++) { 239 | plaintext[j] = j % 256; 240 | } 241 | key = malloc(_mcrypt_get_size()); 242 | if (key == NULL) { 243 | free(keyword); 244 | return -1; 245 | } 246 | memmove(ciphertext, plaintext, blocksize); 247 | 248 | _mcrypt_set_key(key, (void *) keyword, _mcrypt_get_key_size(), 249 | NULL, 0); 250 | _mcrypt_encrypt(key, (void *) ciphertext, blocksize); 251 | 252 | for (j = 0; j < blocksize; j++) { 253 | sprintf(&((char *) cipher_tmp)[2 * j], "%.2x", 254 | ciphertext[j]); 255 | } 256 | 257 | if (strcmp((char *) cipher_tmp, CIPHER) != 0) { 258 | printf("failed compatibility\n"); 259 | printf("Expected: %s\nGot: %s\n", CIPHER, 260 | (char *) cipher_tmp); 261 | free(keyword); 262 | free(key); 263 | return -1; 264 | } 265 | 266 | _mcrypt_set_key(key, (void *) keyword, _mcrypt_get_key_size(), 267 | NULL, 0); 268 | free(keyword); 269 | 270 | _mcrypt_decrypt(key, (void *) ciphertext, blocksize); 271 | free(key); 272 | 273 | if (strcmp(ciphertext, plaintext) != 0) { 274 | printf("failed internally\n"); 275 | return -1; 276 | } 277 | 278 | return 0; 279 | } 280 | 281 | WIN32DLL_DEFINE word32 _mcrypt_algorithm_version() 282 | { 283 | return 20010801; 284 | } 285 | 286 | #ifdef WIN32 287 | # ifdef USE_LTDL 288 | WIN32DLL_DEFINE int main (void) 289 | { 290 | /* empty main function to avoid linker error (see cygwin FAQ) */ 291 | } 292 | # endif 293 | #endif 294 | -------------------------------------------------------------------------------- /modules/algorithms/enigma.h: -------------------------------------------------------------------------------- 1 | #define E_ECHO 010 2 | #define ROTORSZ 256 3 | #define MASK 0377 4 | 5 | typedef struct crypt_key { 6 | signed char t1[ROTORSZ]; 7 | signed char t2[ROTORSZ]; 8 | signed char t3[ROTORSZ]; 9 | signed char deck[ROTORSZ]; 10 | signed char cbuf[13]; 11 | int n1, n2, nr1, nr2; 12 | } CRYPT_KEY; 13 | 14 | -------------------------------------------------------------------------------- /modules/algorithms/panama.h: -------------------------------------------------------------------------------- 1 | /* panama.h */ 2 | 3 | /**************************************************************************+ 4 | * 5 | * PANAMA high-performance reference C-code, based on the description in 6 | * the paper 'Fast Hashing and Stream Encryption with PANAMA', presented 7 | * at the Fast Software Encryption Workshop, Paris, 1998, see "Fast 8 | * Software Encryption - 5th International Workshop, FSE'98", edited by 9 | * Serge Vaudenay, LNCS-1372, Springer-Verlag, 1998, pp 60-74, also 10 | * available on-line at http://standard.pictel.com/ftp/research/security 11 | * 12 | * Algorithm design by Joan Daemen and Craig Clapp 13 | * 14 | * panama.h - Header file for Panama C-code implementation. 15 | * 16 | * 17 | * History: 18 | * 19 | * 29-Oct-98 Craig Clapp Implemention for Dr. Dobbs, Dec. 1998 issue, 20 | * based on earlier performance-benchmark code. 21 | * 22 | * 23 | * Notes: This code is supplied for the purposes of evaluating the 24 | * performance of the Panama stream/hash module and as a 25 | * reference implementation for generating test vectors for 26 | * compatibility / interoperability verification. 27 | * 28 | * 29 | +**************************************************************************/ 30 | 31 | #ifndef NULL 32 | #define NULL 0 33 | #endif 34 | 35 | #define WORDLENGTH 32 36 | #define ONES 0xffffffffL 37 | 38 | 39 | /* standard C idioms for Microsoft and TriMedia compiler features */ 40 | #define restrict /* 'restrict' keyword is not part of ANSI C, null it out */ 41 | #define ROTL32(a,shift) (((a) << (shift)) | ((a) >> (WORDLENGTH - (shift)))) 42 | 43 | 44 | 45 | /****** structure definitions ******/ 46 | 47 | #define PAN_STAGE_SIZE 8 48 | #define PAN_STAGES 32 49 | #define PAN_STATE_SIZE 17 50 | 51 | 52 | typedef struct { 53 | word32 word[PAN_STAGE_SIZE]; 54 | } PAN_STAGE; 55 | 56 | typedef struct { 57 | PAN_STAGE stage[PAN_STAGES]; 58 | int tap_0; 59 | } PAN_BUFFER; 60 | 61 | typedef struct { 62 | word32 word[PAN_STATE_SIZE]; 63 | } PAN_STATE; 64 | 65 | typedef struct { 66 | PAN_BUFFER buffer; 67 | PAN_STATE state; 68 | word32 wkeymat[8]; 69 | byte *keymat; 70 | int keymat_pointer; 71 | } PANAMA_KEY; 72 | 73 | 74 | /****** function prototypes ******/ 75 | 76 | static void pan_pull(word32 * restrict In, /* input array */ 77 | word32 * restrict Out, /* output array */ 78 | word32 pan_blocks, /* number of blocks to be Pulled */ 79 | PAN_BUFFER * restrict buffer, /* LFSR buffer */ 80 | PAN_STATE * restrict state); /* 17-word finite-state machine */ 81 | 82 | static void pan_push(word32 * restrict In, /* input array */ 83 | word32 pan_blocks, /* number of blocks to be Pushed */ 84 | PAN_BUFFER * restrict buffer, /* LFSR buffer */ 85 | PAN_STATE * restrict state); /* 17-word finite-state machine */ 86 | 87 | static void pan_reset(PAN_BUFFER * buffer, PAN_STATE * state); 88 | 89 | #ifndef USE_MODULES 90 | void _mcrypt_panama_set_key(PANAMA_KEY * pan_key, char *in_key, int keysize, 91 | char *init_vec, int vecsize); 92 | void _mcrypt_panama_encrypt(PANAMA_KEY * pan_key, byte * buf, int length); 93 | void _mcrypt_panama_decrypt(PANAMA_KEY * pan_key, byte * buf, int length); 94 | int _mcrypt_panama_get_size (); 95 | int _mcrypt_panama_get_block_size(); 96 | int _panama_is_block_algorithm(); 97 | int _mcrypt_panama_get_key_size(); 98 | int _mcrypt_panama_get_supported_key_sizes(int *size); 99 | char * _mcrypt_panama_get_algorithms_name(); 100 | int _mcrypt_panama_self_test(); 101 | word32 _mcrypt_panama_algorithm_version(); 102 | #endif 103 | -------------------------------------------------------------------------------- /modules/algorithms/rc2.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/winlibs/libmcrypt/1e93cbe97a463a2c0c62338d607b17fe011eb77e/modules/algorithms/rc2.h -------------------------------------------------------------------------------- /modules/algorithms/rijndael.h: -------------------------------------------------------------------------------- 1 | 2 | typedef struct rijndael_instance { 3 | int Nk,Nb,Nr; 4 | byte fi[24],ri[24]; 5 | word32 fkey[120]; 6 | word32 rkey[120]; 7 | } RI; 8 | 9 | /* void _mcrypt_rijndael_128_set_key(RI* rinst, int nb,int nk,byte *key); */ 10 | /* blocksize=32*nb bits. Key=32*nk bits */ 11 | /* currently nb,bk = 4, 6 or 8 */ 12 | /* key comes as 4*Nk bytes */ 13 | /* Key Scheduler. Create expanded encryption key */ 14 | -------------------------------------------------------------------------------- /modules/algorithms/safer.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * 3 | * FILE: safer.h 4 | * 5 | * DESCRIPTION: block-cipher algorithm SAFER (Secure And Fast Encryption 6 | * Routine) in its four versions: SAFER K-64, SAFER K-128, 7 | * SAFER SK-64 and SAFER SK-128. 8 | * 9 | * AUTHOR: Richard De Moliner (demoliner@isi.ee.ethz.ch) 10 | * Signal and Information Processing Laboratory 11 | * Swiss Federal Institute of Technology 12 | * CH-8092 Zuerich, Switzerland 13 | * 14 | * DATE: September 9, 1995 15 | * 16 | * CHANGE HISTORY: 17 | * 18 | *******************************************************************************/ 19 | #ifndef SAFER_H 20 | #define SAFER_H 21 | 22 | /******************* External Headers *****************************************/ 23 | 24 | /******************* Local Headers ********************************************/ 25 | 26 | /******************* Constants ************************************************/ 27 | #define SAFER_K64_DEFAULT_NOF_ROUNDS 6 28 | #define SAFER_K128_DEFAULT_NOF_ROUNDS 10 29 | #define SAFER_SK64_DEFAULT_NOF_ROUNDS 8 30 | #define SAFER_SK128_DEFAULT_NOF_ROUNDS 10 31 | #define SAFER_MAX_NOF_ROUNDS 13 32 | #define SAFER_BLOCK_LEN 8 33 | #define SAFER_KEY_LEN (1 + SAFER_BLOCK_LEN * (1 + 2 * SAFER_MAX_NOF_ROUNDS)) 34 | 35 | /******************* Assertions ***********************************************/ 36 | 37 | /******************* Macros ***************************************************/ 38 | 39 | /******************* Types ****************************************************/ 40 | #define safer_block_t unsigned char 41 | /* [SAFER_BLOCK_LEN]; */ 42 | #define safer_key_t unsigned char 43 | /* [SAFER_KEY_LEN]; */ 44 | 45 | /******************* Module Data **********************************************/ 46 | 47 | /******************* Prototypes ***********************************************/ 48 | 49 | /******************************************************************************* 50 | * void Safer_Init_Module(void) 51 | * 52 | * initializes this module. 53 | * 54 | ******************************************************************************** 55 | * void Safer_Expand_Userkey(safer_block_t userkey_1, 56 | * safer_block_t userkey_2, 57 | * unsigned int nof_rounds, 58 | * int strengthened, 59 | * safer_key_t key) 60 | * 61 | * expands a user-selected key of length 64 bits or 128 bits to a encryption / 62 | * decryption key. If your user-selected key is of length 64 bits, then give 63 | * this key to both arguments 'userkey_1' and 'userkey_2', e.g. 64 | * 'Safer_Expand_Userkey(z, z, key)'. Note: SAFER K-64 and SAFER SK-64 with a 65 | * user-selected key 'z' of length 64 bits are identical to SAFER K-128 and 66 | * SAFER SK-128 with a user-selected key 'z z' of length 128 bits, 67 | * respectively. 68 | * pre: 'userkey_1' contains the first 64 bits of user key. 69 | * 'userkey_2' contains the second 64 bits of user key. 70 | * 'nof_rounds' contains the number of encryption rounds 71 | * 'nof_rounds' <= 'SAFER_MAX_NOF_ROUNDS' 72 | * 'strengthened' is non-zero if the strengthened key schedule should be 73 | * used and zero if the original key schedule should be 74 | * used. 75 | * post: 'key' contains the expanded key. 76 | * 77 | ******************************************************************************** 78 | * void Safer_Encrypt_Block(safer_block_t block_in, safer_key_t key, 79 | * safer_block_t block_out) 80 | * 81 | * encryption algorithm. 82 | * pre: 'block_in' contains the plain-text block. 83 | * 'key' contains the expanded key. 84 | * post: 'block_out' contains the cipher-text block. 85 | * 86 | ******************************************************************************** 87 | * void Safer_Decrypt_Block(safer_block_t block_in, safer_key_t key, 88 | * safer_block_t block_out) 89 | * 90 | * decryption algorithm. 91 | * pre: 'block_in' contains the cipher-text block. 92 | * 'key' contains the expanded key. 93 | * post: 'block_out' contains the plain-text block. 94 | * 95 | *******************************************************************************/ 96 | 97 | static void _mcrypt_Safer_Init_Module(); 98 | 99 | /******************************************************************************/ 100 | #endif /* SAFER_H */ 101 | -------------------------------------------------------------------------------- /modules/algorithms/saferplus.h: -------------------------------------------------------------------------------- 1 | typedef struct saferplus_instance { 2 | byte l_key[33*16]; 3 | word32 k_bytes; 4 | } SPI; 5 | 6 | -------------------------------------------------------------------------------- /modules/algorithms/serpent.h: -------------------------------------------------------------------------------- 1 | typedef struct { 2 | word32 l_key[140]; 3 | } SERPENT_KEY; 4 | 5 | -------------------------------------------------------------------------------- /modules/algorithms/tripledes.h: -------------------------------------------------------------------------------- 1 | typedef struct triple_des_key { 2 | char kn[3][16][8]; 3 | word32 sp[3][8][64]; 4 | 5 | char iperm[16][16][8]; 6 | char fperm[16][16][8]; 7 | 8 | } TRIPLEDES_KEY; 9 | 10 | -------------------------------------------------------------------------------- /modules/algorithms/twofish.h: -------------------------------------------------------------------------------- 1 | #define Q_TABLES 2 | #define M_TABLE 3 | #define MK_TABLE 4 | #define ONE_STEP 5 | 6 | typedef struct twofish_instance { 7 | word32 k_len; 8 | word32 l_key[40]; 9 | word32 s_key[4]; 10 | #ifdef Q_TABLES 11 | word32 qt_gen; 12 | byte q_tab[2][256]; 13 | #endif 14 | #ifdef M_TABLE 15 | word32 mt_gen; 16 | word32 m_tab[4][256]; 17 | #endif 18 | #ifdef ONE_STEP 19 | word32 mk_tab[4][256]; 20 | #else 21 | byte sb[4][256]; 22 | #endif 23 | } TWI; 24 | 25 | -------------------------------------------------------------------------------- /modules/algorithms/wake.h: -------------------------------------------------------------------------------- 1 | typedef struct wake_key { 2 | word32 t[257]; 3 | word32 r[4]; 4 | int counter; 5 | word32 tmp; /* used as r1 or r2 */ 6 | int started; 7 | word32 iv[8]; 8 | int ivsize; 9 | } WAKE_KEY; 10 | 11 | -------------------------------------------------------------------------------- /modules/algorithms/xtea.c: -------------------------------------------------------------------------------- 1 | /********************************************************** 2 | TEA - Tiny Encryption Algorithm 3 | Feistel cipher by David Wheeler & Roger M. Needham 4 | (extended version) 5 | **********************************************************/ 6 | 7 | /* $Id: xtea.c,v 1.13 2003/01/19 17:48:27 nmav Exp $ */ 8 | 9 | /* modified in order to use the libmcrypt API by Nikos Mavroyanopoulos 10 | * All modifications are placed under the license of libmcrypt. 11 | */ 12 | 13 | #include 14 | 15 | #include 16 | 17 | #define _mcrypt_set_key xtea_LTX__mcrypt_set_key 18 | #define _mcrypt_encrypt xtea_LTX__mcrypt_encrypt 19 | #define _mcrypt_decrypt xtea_LTX__mcrypt_decrypt 20 | #define _mcrypt_get_size xtea_LTX__mcrypt_get_size 21 | #define _mcrypt_get_block_size xtea_LTX__mcrypt_get_block_size 22 | #define _is_block_algorithm xtea_LTX__is_block_algorithm 23 | #define _mcrypt_get_key_size xtea_LTX__mcrypt_get_key_size 24 | #define _mcrypt_get_supported_key_sizes xtea_LTX__mcrypt_get_supported_key_sizes 25 | #define _mcrypt_get_algorithms_name xtea_LTX__mcrypt_get_algorithms_name 26 | #define _mcrypt_self_test xtea_LTX__mcrypt_self_test 27 | #define _mcrypt_algorithm_version xtea_LTX__mcrypt_algorithm_version 28 | 29 | #define ROUNDS 32 30 | #define DELTA 0x9e3779b9 /* sqr(5)-1 * 2^31 */ 31 | 32 | /********************************************************** 33 | Input values: k[4] 128-bit key 34 | v[2] 64-bit plaintext block 35 | Output values: v[2] 64-bit ciphertext block 36 | **********************************************************/ 37 | 38 | WIN32DLL_DEFINE 39 | int _mcrypt_set_key(word32 * k, word32 * input_key, int len) 40 | { 41 | k[0] = 0; 42 | k[2] = 0; 43 | k[1] = 0; 44 | k[3] = 0; 45 | memmove(k, input_key, len); 46 | return 0; 47 | } 48 | 49 | WIN32DLL_DEFINE void _mcrypt_encrypt(word32 * k, word32 * v) 50 | { 51 | #ifdef WORDS_BIGENDIAN 52 | word32 y = v[0], z = v[1]; 53 | #else 54 | word32 y = byteswap32(v[0]), z = byteswap32(v[1]); 55 | #endif 56 | word32 limit, sum = 0; 57 | int N = ROUNDS; 58 | 59 | limit = DELTA * N; 60 | #ifdef WORDS_BIGENDIAN 61 | while (sum != limit) { 62 | y += (((z << 4) ^ (z >> 5)) + z) ^ (sum + k[sum & 3]); 63 | sum += DELTA; 64 | z += (((y << 4) ^ (y >> 5)) + y) ^ (sum + 65 | k[(sum >> 11) & 3]); 66 | } 67 | #else 68 | while (sum != limit) { 69 | y += (((z << 4) ^ (z >> 5)) + z) ^ (sum + 70 | byteswap32(k 71 | [sum & 3])); 72 | sum += DELTA; 73 | z += (((y << 4) ^ (y >> 5)) + y) ^ (sum + 74 | byteswap32(k 75 | [(sum >> 76 | 11) & 77 | 3])); 78 | } 79 | #endif 80 | 81 | #ifdef WORDS_BIGENDIAN 82 | v[0] = y; 83 | v[1] = z; 84 | #else 85 | v[0] = byteswap32(y); 86 | v[1] = byteswap32(z); 87 | #endif 88 | } 89 | 90 | WIN32DLL_DEFINE void _mcrypt_decrypt(word32 * k, word32 * v) 91 | { 92 | #ifdef WORDS_BIGENDIAN 93 | word32 y = v[0], z = v[1]; 94 | #else 95 | word32 y = byteswap32(v[0]), z = byteswap32(v[1]); 96 | #endif 97 | word32 limit, sum = 0; 98 | int N = (-ROUNDS); 99 | 100 | limit = DELTA * N; 101 | #ifdef WORDS_BIGENDIAN 102 | 103 | sum = DELTA * (-N); 104 | while (sum) { 105 | z -= (((y << 4) ^ (y >> 5)) + y) ^ (sum + 106 | k[(sum >> 11) & 3]); 107 | sum -= DELTA; 108 | y -= (((z << 4) ^ (z >> 5)) + z) ^ (sum + k[sum & 3]); 109 | #else 110 | sum = DELTA * (-N); 111 | while (sum) { 112 | z -= (((y << 4) ^ (y >> 5)) + y) ^ (sum + 113 | byteswap32(k 114 | [(sum >> 115 | 11) & 116 | 3])); 117 | sum -= DELTA; 118 | y -= (((z << 4) ^ (z >> 5)) + z) ^ (sum + 119 | byteswap32(k 120 | [sum & 3])); 121 | #endif 122 | } 123 | #ifdef WORDS_BIGENDIAN 124 | v[0] = y; 125 | v[1] = z; 126 | #else 127 | v[0] = byteswap32(y); 128 | v[1] = byteswap32(z); 129 | #endif 130 | } 131 | 132 | /* 133 | void _mcrypt_encrypt(word32 * k, word32 * v) 134 | { 135 | _mcrypt_tean(k, v, ROUNDS); 136 | } 137 | 138 | void _mcrypt_decrypt(word32 * k, word32 * v) 139 | { 140 | _mcrypt_tean(k, v, -ROUNDS); 141 | } 142 | */ 143 | 144 | WIN32DLL_DEFINE int _mcrypt_get_size() 145 | { 146 | return 4 * sizeof(word32); 147 | } 148 | WIN32DLL_DEFINE int _mcrypt_get_block_size() 149 | { 150 | return 8; 151 | } 152 | WIN32DLL_DEFINE int _is_block_algorithm() 153 | { 154 | return 1; 155 | } 156 | WIN32DLL_DEFINE int _mcrypt_get_key_size() 157 | { 158 | return 16; 159 | } 160 | 161 | static const int key_sizes[] = { 16 }; 162 | WIN32DLL_DEFINE const int *_mcrypt_get_supported_key_sizes(int *len) 163 | { 164 | *len = sizeof(key_sizes)/sizeof(int); 165 | return key_sizes; 166 | } 167 | 168 | WIN32DLL_DEFINE const char *_mcrypt_get_algorithms_name() 169 | { 170 | return "xTEA"; 171 | } 172 | 173 | #define CIPHER "f61e7ff6da7cdb27" 174 | 175 | WIN32DLL_DEFINE int _mcrypt_self_test() 176 | { 177 | char *keyword; 178 | unsigned char plaintext[16]; 179 | unsigned char ciphertext[16]; 180 | int blocksize = _mcrypt_get_block_size(), j; 181 | void *key; 182 | unsigned char cipher_tmp[200]; 183 | 184 | keyword = calloc(1, _mcrypt_get_key_size()); 185 | if (keyword == NULL) 186 | return -1; 187 | 188 | for (j = 0; j < _mcrypt_get_key_size(); j++) { 189 | keyword[j] = ((j * 2 + 10) % 256); 190 | } 191 | 192 | for (j = 0; j < blocksize; j++) { 193 | plaintext[j] = j % 256; 194 | } 195 | key = malloc(_mcrypt_get_size()); 196 | if (key == NULL) 197 | return -1; 198 | 199 | memcpy(ciphertext, plaintext, blocksize); 200 | 201 | _mcrypt_set_key(key, (void *) keyword, _mcrypt_get_key_size()); 202 | free(keyword); 203 | _mcrypt_encrypt(key, (void *) ciphertext); 204 | 205 | for (j = 0; j < blocksize; j++) { 206 | sprintf(&((char *) cipher_tmp)[2 * j], "%.2x", 207 | ciphertext[j]); 208 | } 209 | 210 | if (strcmp((char *) cipher_tmp, CIPHER) != 0) { 211 | printf("failed compatibility\n"); 212 | printf("Expected: %s\nGot: %s\n", CIPHER, 213 | (char *) cipher_tmp); 214 | free(key); 215 | return -1; 216 | } 217 | _mcrypt_decrypt(key, (void *) ciphertext); 218 | free(key); 219 | 220 | if (strcmp(ciphertext, plaintext) != 0) { 221 | printf("failed internally\n"); 222 | return -1; 223 | } 224 | 225 | return 0; 226 | } 227 | 228 | WIN32DLL_DEFINE word32 _mcrypt_algorithm_version() 229 | { 230 | return 20010801; 231 | } 232 | 233 | #ifdef WIN32 234 | # ifdef USE_LTDL 235 | WIN32DLL_DEFINE int main (void) 236 | { 237 | /* empty main function to avoid linker error (see cygwin FAQ) */ 238 | } 239 | # endif 240 | #endif 241 | -------------------------------------------------------------------------------- /modules/algorithms/xtea.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/winlibs/libmcrypt/1e93cbe97a463a2c0c62338d607b17fe011eb77e/modules/algorithms/xtea.h -------------------------------------------------------------------------------- /modules/modes/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | DEFS = @DEFS@ 3 | INCLUDES = -I. -I../.. $(INCLTDL) -I../../lib 4 | 5 | EXTRA_DIST = ofb.h cfb.h nofb.h cbc.h ecb.h stream.h ncfb.h ctr.h 6 | pkglib_LTLIBRARIES = @INSTALL_MODE_MODULES@ 7 | 8 | EXTRA_LTLIBRARIES = ofb.la cfb.la nofb.la cbc.la ecb.la stream.la ncfb.la \ 9 | ctr.la 10 | noinst_LTLIBRARIES = @NOINSTALL_MODE_MODULES@ 11 | 12 | ofb_la_SOURCES = ofb.c 13 | ofb_la_LDFLAGS = -module -avoid-version -rpath $(pkglibdir) 14 | ctr_la_SOURCES = ctr.c 15 | ctr_la_LDFLAGS = -module -avoid-version -rpath $(pkglibdir) 16 | cfb_la_SOURCES = cfb.c 17 | cfb_la_LDFLAGS = -module -avoid-version -rpath $(pkglibdir) 18 | ncfb_la_SOURCES = ncfb.c 19 | ncfb_la_LDFLAGS = -module -avoid-version -rpath $(pkglibdir) 20 | nofb_la_SOURCES = nofb.c 21 | nofb_la_LDFLAGS = -module -avoid-version -rpath $(pkglibdir) 22 | ecb_la_SOURCES = ecb.c 23 | ecb_la_LDFLAGS = -module -avoid-version -rpath $(pkglibdir) 24 | cbc_la_SOURCES = cbc.c 25 | cbc_la_LDFLAGS = -module -avoid-version -rpath $(pkglibdir) 26 | stream_la_SOURCES = stream.c 27 | stream_la_LDFLAGS = -module -avoid-version -rpath $(pkglibdir) 28 | -------------------------------------------------------------------------------- /modules/modes/cbc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1998,1999,2000,2001 Nikos Mavroyanopoulos 3 | * 4 | * This library is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU Library General Public License as published 6 | * by the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | #define _init_mcrypt cbc_LTX__init_mcrypt 24 | #define _mcrypt_set_state cbc_LTX__mcrypt_set_state 25 | #define _mcrypt_get_state cbc_LTX__mcrypt_get_state 26 | #define _end_mcrypt cbc_LTX__end_mcrypt 27 | #define _mcrypt cbc_LTX__mcrypt 28 | #define _mdecrypt cbc_LTX__mdecrypt 29 | #define _has_iv cbc_LTX__has_iv 30 | #define _is_block_mode cbc_LTX__is_block_mode 31 | #define _is_block_algorithm_mode cbc_LTX__is_block_algorithm_mode 32 | #define _mcrypt_get_modes_name cbc_LTX__mcrypt_get_modes_name 33 | #define _mcrypt_mode_get_size cbc_LTX__mcrypt_mode_get_size 34 | #define _mcrypt_mode_version cbc_LTX__mcrypt_mode_version 35 | 36 | typedef struct cbc_buf { 37 | word32 *previous_ciphertext; 38 | word32 *previous_cipher; 39 | int blocksize; 40 | } CBC_BUFFER; 41 | 42 | /* CBC MODE */ 43 | 44 | 45 | int _init_mcrypt( CBC_BUFFER* buf,void *key, int lenofkey, void *IV, int size) 46 | { 47 | /* For cbc */ 48 | buf->previous_ciphertext = 49 | buf->previous_cipher = NULL; 50 | 51 | buf->blocksize = size; 52 | 53 | buf->previous_ciphertext = malloc( size); 54 | buf->previous_cipher = malloc( size); 55 | 56 | if (buf->previous_ciphertext==NULL || 57 | buf->previous_cipher==NULL) goto freeall; 58 | 59 | if (IV!=NULL) { 60 | memcpy(buf->previous_ciphertext, IV, size); 61 | } else { 62 | memset(buf->previous_ciphertext, 0, size); 63 | } 64 | 65 | return 0; 66 | 67 | freeall: 68 | free(buf->previous_ciphertext); 69 | free(buf->previous_cipher); 70 | return -1; 71 | } 72 | 73 | int _mcrypt_set_state( CBC_BUFFER* buf, void *IV, int size) 74 | { 75 | /* For cbc */ 76 | 77 | memcpy(buf->previous_ciphertext, IV, size); 78 | memcpy(buf->previous_cipher, IV, size); 79 | 80 | return 0; 81 | } 82 | 83 | int _mcrypt_get_state( CBC_BUFFER* buf, void *IV, int *size) 84 | { 85 | if (*size < buf->blocksize) { 86 | *size = buf->blocksize; 87 | return -1; 88 | } 89 | *size = buf->blocksize; 90 | 91 | memcpy( IV, buf->previous_ciphertext, buf->blocksize); 92 | 93 | return 0; 94 | } 95 | 96 | 97 | void _end_mcrypt( CBC_BUFFER* buf) { 98 | free(buf->previous_ciphertext); 99 | free(buf->previous_cipher); 100 | } 101 | 102 | int _mcrypt( CBC_BUFFER* buf, void *plaintext, int len, int blocksize, void* akey, void (*func)(void*,void*), void (*func2)(void*,void*)) 103 | { 104 | word32 *fplain = plaintext; 105 | word32 *plain; 106 | int i, j; 107 | void (*_mcrypt_block_encrypt) (void *, void *); 108 | 109 | _mcrypt_block_encrypt = func; 110 | 111 | for (j = 0; j < len / blocksize; j++) { 112 | 113 | plain = &fplain[j * blocksize / sizeof(word32)]; 114 | 115 | for (i = 0; i < blocksize / sizeof(word32); i++) { 116 | plain[i] ^= buf->previous_ciphertext[i]; 117 | } 118 | 119 | _mcrypt_block_encrypt(akey, plain); 120 | 121 | /* Copy the ciphertext to prev_ciphertext */ 122 | memcpy(buf->previous_ciphertext, plain, blocksize); 123 | } 124 | if (j==0 && len!=0) return -1; 125 | return 0; 126 | } 127 | 128 | 129 | 130 | int _mdecrypt( CBC_BUFFER* buf, void *ciphertext, int len, int blocksize,void* akey, void (*func)(void*,void*), void (*func2)(void*,void*)) 131 | { 132 | word32 *cipher; 133 | word32 *fcipher = ciphertext; 134 | int i, j; 135 | void (*_mcrypt_block_decrypt) (void *, void *); 136 | 137 | _mcrypt_block_decrypt = func2; 138 | 139 | 140 | for (j = 0; j < len / blocksize; j++) { 141 | 142 | cipher = &fcipher[j * blocksize / sizeof(word32)]; 143 | memcpy(buf->previous_cipher, cipher, blocksize); 144 | 145 | _mcrypt_block_decrypt(akey, cipher); 146 | for (i = 0; i < blocksize / sizeof(word32); i++) { 147 | cipher[i] ^= buf->previous_ciphertext[i]; 148 | } 149 | 150 | /* Copy the ciphertext to prev_cipher */ 151 | memcpy(buf->previous_ciphertext, buf->previous_cipher, blocksize); 152 | 153 | } 154 | if (j==0 && len!=0) return -1; 155 | return 0; 156 | } 157 | 158 | int _has_iv() { return 1; } 159 | int _is_block_mode() { return 1; } 160 | int _is_block_algorithm_mode() { return 1; } 161 | const char *_mcrypt_get_modes_name() { return "CBC";} 162 | int _mcrypt_mode_get_size () {return sizeof(CBC_BUFFER);} 163 | 164 | word32 _mcrypt_mode_version() { 165 | return 20010801; 166 | } 167 | 168 | 169 | #ifdef WIN32 170 | # ifdef USE_LTDL 171 | WIN32DLL_DEFINE int main (void) 172 | { 173 | /* empty main function to avoid linker error (see cygwin FAQ) */ 174 | } 175 | # endif 176 | #endif 177 | -------------------------------------------------------------------------------- /modules/modes/cbc.h: -------------------------------------------------------------------------------- 1 | #ifndef USE_MODULES 2 | int _cbc_init_mcrypt( int td, void* buf, void *key, int lenofkey, void *IV); 3 | int _mcrypt_cbc(int td, void* buf,void *plaintext, int len); 4 | int _mdecrypt_cbc(int td, void* buf, void *plaintext, int len); 5 | int _cbc_is_block_mode(); 6 | int _cbc_has_iv(); 7 | int _cbc_is_block_algorithm_mode(); 8 | char *_mcrypt_cbc_get_modes_name(); 9 | int _mcrypt_cbc_mode_get_size (); 10 | int _mcrypt_cbc_get_iv_size(int td); 11 | word32 _mcrypt_cbc_mode_version(); 12 | #endif 13 | -------------------------------------------------------------------------------- /modules/modes/cfb.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1998,1999,2000,2001,2002 Nikos Mavroyanopoulos 3 | * 4 | * This library is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU Library General Public License as published 6 | * by the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | #define _init_mcrypt cfb_LTX__init_mcrypt 24 | #define _mcrypt_set_state cfb_LTX__mcrypt_set_state 25 | #define _mcrypt_get_state cfb_LTX__mcrypt_get_state 26 | #define _end_mcrypt cfb_LTX__end_mcrypt 27 | #define _mcrypt cfb_LTX__mcrypt 28 | #define _mdecrypt cfb_LTX__mdecrypt 29 | #define _has_iv cfb_LTX__has_iv 30 | #define _is_block_mode cfb_LTX__is_block_mode 31 | #define _is_block_algorithm_mode cfb_LTX__is_block_algorithm_mode 32 | #define _mcrypt_get_modes_name cfb_LTX__mcrypt_get_modes_name 33 | #define _mcrypt_mode_get_size cfb_LTX__mcrypt_mode_get_size 34 | #define _mcrypt_mode_version cfb_LTX__mcrypt_mode_version 35 | 36 | typedef struct cfb_buf { 37 | byte* s_register; 38 | byte* enc_s_register; 39 | int blocksize; 40 | } CFB_BUFFER; 41 | 42 | /* CFB MODE */ 43 | 44 | int _init_mcrypt( CFB_BUFFER* buf, void *key, int lenofkey, void *IV, int size) 45 | { 46 | 47 | buf->s_register = buf->enc_s_register = NULL; 48 | 49 | buf->blocksize = size; 50 | /* For cfb */ 51 | buf->s_register=malloc( size); 52 | if (buf->s_register==NULL) goto freeall; 53 | 54 | buf->enc_s_register=malloc( size); 55 | if (buf->enc_s_register==NULL) goto freeall; 56 | 57 | if (IV!=NULL) { 58 | memcpy(buf->s_register, IV, size); 59 | } else { 60 | memset(buf->s_register, 0, size); 61 | } 62 | /* End cfb */ 63 | return 0; 64 | 65 | freeall: 66 | free(buf->s_register); 67 | free(buf->enc_s_register); 68 | return -1; 69 | } 70 | 71 | 72 | int _mcrypt_set_state( CFB_BUFFER* buf, void *IV, int size) 73 | { 74 | memcpy(buf->enc_s_register, IV, size); 75 | memcpy(buf->s_register, IV, size); 76 | 77 | return 0; 78 | } 79 | 80 | int _mcrypt_get_state( CFB_BUFFER* buf, byte *IV, int *size) 81 | { 82 | if (*size < buf->blocksize) { 83 | *size = buf->blocksize; 84 | return -1; 85 | } 86 | *size = buf->blocksize; 87 | 88 | memcpy( IV, buf->s_register, buf->blocksize); 89 | 90 | return 0; 91 | } 92 | 93 | 94 | void _end_mcrypt( CFB_BUFFER* buf) { 95 | free(buf->s_register); 96 | free(buf->enc_s_register); 97 | } 98 | 99 | int _mcrypt( CFB_BUFFER* buf, void *plaintext, int len, int blocksize, void* akey, void (*func)(void*,void*), void (*func2)(void*,void*)) 100 | { /* plaintext is 1 byte (8bit cfb) */ 101 | char *plain = plaintext; 102 | int i, j; 103 | void (*_mcrypt_block_encrypt) (void *, void *); 104 | 105 | _mcrypt_block_encrypt = func; 106 | 107 | for (j = 0; j < len; j++) { 108 | 109 | memcpy(buf->enc_s_register, buf->s_register, blocksize); 110 | 111 | _mcrypt_block_encrypt(akey, buf->enc_s_register); 112 | 113 | plain[j] ^= buf->enc_s_register[0]; 114 | 115 | /* Shift the register */ 116 | for (i = 0; i < (blocksize - 1); i++) 117 | buf->s_register[i] = buf->s_register[i + 1]; 118 | 119 | buf->s_register[blocksize - 1] = plain[j]; 120 | } 121 | 122 | return 0; 123 | 124 | } 125 | 126 | 127 | int _mdecrypt( CFB_BUFFER* buf, void *plaintext, int len, int blocksize, void* akey, void (*func)(void*,void*), void (*func2)(void*,void*)) 128 | { /* plaintext is 1 byte (8bit ofb) */ 129 | char *plain = plaintext; 130 | int i, j; 131 | void (*_mcrypt_block_encrypt) (void *, void *); 132 | 133 | _mcrypt_block_encrypt = func; 134 | 135 | for (j = 0; j < len; j++) { 136 | 137 | memcpy(buf->enc_s_register, buf->s_register, blocksize); 138 | 139 | _mcrypt_block_encrypt(akey, buf->enc_s_register); 140 | 141 | /* Shift the register */ 142 | for (i = 0; i < (blocksize - 1); i++) 143 | buf->s_register[i] = buf->s_register[i + 1]; 144 | 145 | buf->s_register[blocksize - 1] = plain[j]; 146 | 147 | plain[j] ^= buf->enc_s_register[0]; 148 | 149 | } 150 | 151 | return 0; 152 | } 153 | 154 | int _has_iv() { return 1; } 155 | int _is_block_mode() { return 0; } 156 | int _is_block_algorithm_mode() { return 1; } 157 | const char *_mcrypt_get_modes_name() { return "CFB"; } 158 | int _mcrypt_mode_get_size () {return sizeof(CFB_BUFFER);} 159 | 160 | word32 _mcrypt_mode_version() { 161 | return 20020310; 162 | } 163 | 164 | #ifdef WIN32 165 | # ifdef USE_LTDL 166 | WIN32DLL_DEFINE int main (void) 167 | { 168 | /* empty main function to avoid linker error (see cygwin FAQ) */ 169 | } 170 | # endif 171 | #endif 172 | -------------------------------------------------------------------------------- /modules/modes/cfb.h: -------------------------------------------------------------------------------- 1 | #ifndef USE_MODULES 2 | int _cfb_init_mcrypt( int td, void* buf, void *key, int lenofkey, void *IV); 3 | int _mcrypt_cfb(int td, void* buf,void *plaintext, int len); 4 | int _mdecrypt_cfb(int td, void* buf, void *plaintext, int len); 5 | int _cfb_is_block_mode(); 6 | int _cfb_has_iv(); 7 | int _cfb_is_block_algorithm_mode(); 8 | char *_mcrypt_cfb_get_modes_name(); 9 | int _mcrypt_cfb_mode_get_size (); 10 | int _mcrypt_cfb_get_iv_size(int td); 11 | word32 _mcrypt_cfb_mode_version(); 12 | #endif 13 | -------------------------------------------------------------------------------- /modules/modes/ctr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2002 Nikos Mavroyanopoulos 3 | * 4 | * This library is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU Library General Public License as published 6 | * by the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | #define _init_mcrypt ctr_LTX__init_mcrypt 24 | #define _mcrypt_set_state ctr_LTX__mcrypt_set_state 25 | #define _mcrypt_get_state ctr_LTX__mcrypt_get_state 26 | #define _end_mcrypt ctr_LTX__end_mcrypt 27 | #define _mcrypt ctr_LTX__mcrypt 28 | #define _mdecrypt ctr_LTX__mdecrypt 29 | #define _has_iv ctr_LTX__has_iv 30 | #define _is_block_mode ctr_LTX__is_block_mode 31 | #define _is_block_algorithm_mode ctr_LTX__is_block_algorithm_mode 32 | #define _mcrypt_get_modes_name ctr_LTX__mcrypt_get_modes_name 33 | #define _mcrypt_mode_get_size ctr_LTX__mcrypt_mode_get_size 34 | #define _mcrypt_mode_version ctr_LTX__mcrypt_mode_version 35 | 36 | typedef struct ctr_buf { 37 | byte* enc_counter; 38 | byte* c_counter; 39 | int c_counter_pos; 40 | int blocksize; 41 | } CTR_BUFFER; 42 | 43 | /* CTR MODE */ 44 | 45 | /* This function will add one to the given number (as a byte string). 46 | * has been reached. 47 | */ 48 | static void increase_counter( byte *x, int x_size) { 49 | register int i, y=0; 50 | 51 | for (i=x_size-1;i>=0;i--) { 52 | y = 0; 53 | if ( x[i] == 0xff) { 54 | x[i] = 0; 55 | y = 1; 56 | } else x[i]++; 57 | 58 | if (y==0) break; 59 | } 60 | 61 | return; 62 | } 63 | 64 | 65 | /* size holds the size of the IV (counter in this mode). 66 | * This is the block size. 67 | */ 68 | int _init_mcrypt( CTR_BUFFER* buf, void *key, int lenofkey, void *IV, int size) 69 | { 70 | buf->c_counter = buf->enc_counter = NULL; 71 | 72 | /* For ctr */ 73 | buf->c_counter_pos = 0; 74 | buf->blocksize = size; 75 | 76 | buf->c_counter=calloc( 1, size); 77 | if (buf->c_counter==NULL) goto freeall; 78 | 79 | buf->enc_counter=calloc( 1, size); 80 | if (buf->enc_counter==NULL) goto freeall; 81 | 82 | if (IV!=NULL) { 83 | memcpy(buf->enc_counter, IV, size); 84 | memcpy(buf->c_counter, IV, size); 85 | } 86 | 87 | /* End ctr */ 88 | 89 | return 0; 90 | freeall: 91 | free(buf->c_counter); 92 | free(buf->enc_counter); 93 | return -1; 94 | } 95 | 96 | int _mcrypt_set_state( CTR_BUFFER* buf, byte *IV, int size) 97 | { 98 | buf->c_counter_pos = IV[0]; 99 | memcpy(buf->c_counter, &IV[1], size-1); 100 | memcpy(buf->enc_counter, &IV[1], size-1); 101 | 102 | return 0; 103 | } 104 | 105 | int _mcrypt_get_state( CTR_BUFFER* buf, byte *IV, int *size) 106 | { 107 | if (*size < buf->blocksize + 1) { 108 | *size = buf->blocksize + 1; 109 | return -1; 110 | } 111 | *size = buf->blocksize + 1; 112 | 113 | IV[0] = buf->c_counter_pos; 114 | memcpy( &IV[1], buf->c_counter, buf->blocksize); 115 | 116 | return 0; 117 | } 118 | 119 | 120 | void _end_mcrypt( CTR_BUFFER* buf) { 121 | free(buf->c_counter); 122 | free(buf->enc_counter); 123 | } 124 | 125 | #ifdef _MSC_VER 126 | __inline static 127 | #else 128 | inline static 129 | #endif 130 | void xor_stuff( CTR_BUFFER *buf, void* akey, void (*func)(void*,void*), byte* plain, int blocksize, int xor_size) 131 | { 132 | void (*_mcrypt_block_encrypt) (void *, void *); 133 | 134 | _mcrypt_block_encrypt = func; 135 | 136 | if (xor_size == blocksize) { 137 | if (buf->c_counter_pos == 0) { 138 | 139 | memcpy( buf->enc_counter, buf->c_counter, blocksize); 140 | _mcrypt_block_encrypt(akey, buf->enc_counter); 141 | 142 | memxor( plain, buf->enc_counter, blocksize); 143 | 144 | increase_counter( buf->c_counter, blocksize); 145 | 146 | 147 | } else { 148 | int size = blocksize - buf->c_counter_pos; 149 | 150 | memxor( plain, &buf->enc_counter[buf->c_counter_pos], 151 | size); 152 | 153 | increase_counter( buf->c_counter, blocksize); 154 | 155 | memcpy( buf->enc_counter, buf->c_counter, blocksize); 156 | _mcrypt_block_encrypt(akey, buf->enc_counter); 157 | 158 | memxor( &plain[size], buf->enc_counter, 159 | buf->c_counter_pos); 160 | 161 | /* buf->c_counter_pos remains the same */ 162 | 163 | } 164 | } else { /* xor_size != blocksize */ 165 | if (buf->c_counter_pos == 0) { 166 | memcpy( buf->enc_counter, buf->c_counter, blocksize); 167 | _mcrypt_block_encrypt(akey, buf->enc_counter); 168 | 169 | memxor( plain, buf->enc_counter, xor_size); 170 | buf->c_counter_pos = xor_size; 171 | } else { 172 | int size = blocksize - buf->c_counter_pos; 173 | int min_size = size < xor_size ? size: xor_size; 174 | 175 | memxor( plain, &buf->enc_counter[buf->c_counter_pos], 176 | min_size); 177 | 178 | buf->c_counter_pos += min_size; 179 | 180 | if (min_size >= xor_size) 181 | return; 182 | 183 | increase_counter( buf->c_counter, blocksize); 184 | 185 | memcpy( buf->enc_counter, buf->c_counter, blocksize); 186 | _mcrypt_block_encrypt(akey, buf->enc_counter); 187 | 188 | memxor( &plain[min_size], buf->enc_counter, 189 | xor_size - min_size); 190 | 191 | buf->c_counter_pos = xor_size - min_size; 192 | 193 | } 194 | 195 | } 196 | return; 197 | } 198 | 199 | int _mcrypt( CTR_BUFFER* buf,void *plaintext, int len, int blocksize, void* akey, void (*func)(void*,void*), void (*func2)(void*,void*)) 200 | { /* plaintext can be any size */ 201 | byte *plain; 202 | word32 *fplain = plaintext; 203 | int i, j=0; 204 | int modlen; 205 | 206 | plain = plaintext; 207 | for (j = 0; j < len / blocksize; j++) { 208 | 209 | xor_stuff( buf, akey, func, plain, blocksize, blocksize); 210 | 211 | plain += blocksize; 212 | 213 | /* Put the new register */ 214 | 215 | } 216 | modlen = len % blocksize; 217 | if (modlen > 0) { 218 | /* This is only usefull if encrypting the 219 | * final block. Otherwise you'll not be 220 | * able to decrypt it. 221 | */ 222 | 223 | xor_stuff( buf, akey, func, plain, blocksize, modlen); 224 | 225 | } 226 | 227 | return 0; 228 | } 229 | 230 | 231 | int _mdecrypt( CTR_BUFFER* buf,void *plaintext, int len, int blocksize, void* akey, void (*func)(void*,void*), void (*func2)(void*,void*)) 232 | { /* plaintext can be any size */ 233 | return _mcrypt( buf, plaintext, len, blocksize, akey, func, func2); 234 | } 235 | 236 | int _has_iv() { return 1; } 237 | int _is_block_mode() { return 0; } 238 | int _is_block_algorithm_mode() { return 1; } 239 | const char *_mcrypt_get_modes_name() { return "CTR";} 240 | int _mcrypt_mode_get_size () {return sizeof(CTR_BUFFER);} 241 | 242 | 243 | word32 _mcrypt_mode_version() { 244 | return 20020307; 245 | } 246 | 247 | #ifdef WIN32 248 | # ifdef USE_LTDL 249 | WIN32DLL_DEFINE int main (void) 250 | { 251 | /* empty main function to avoid linker error (see cygwin FAQ) */ 252 | } 253 | # endif 254 | #endif 255 | -------------------------------------------------------------------------------- /modules/modes/ctr.h: -------------------------------------------------------------------------------- 1 | #ifndef USE_MODULES 2 | int _ctr_init_mcrypt( int td, void* buf, void *key, int lenofkey, void *IV); 3 | int _mcrypt_ctr(int td, void* buf,void *plaintext, int len); 4 | int _mdecrypt_ctr(int td, void* buf, void *plaintext, int len); 5 | int _ctr_is_block_mode(); 6 | int _ctr_has_iv(); 7 | int _ctr_is_block_algorithm_mode(); 8 | char *_mcrypt_ctr_get_modes_name(); 9 | int _mcrypt_ctr_mode_get_size (); 10 | int _mcrypt_ctr_get_iv_size(int td); 11 | word32 _mcrypt_ctr_mode_version(); 12 | #endif 13 | -------------------------------------------------------------------------------- /modules/modes/ecb.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1998,1999,2000,2001 Nikos Mavroyanopoulos 3 | * 4 | * This library is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU Library General Public License as published 6 | * by the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | /* EBC MODE */ 24 | 25 | #define _mcrypt_set_state ecb_LTX__mcrypt_set_state 26 | #define _mcrypt_get_state ecb_LTX__mcrypt_get_state 27 | #define _init_mcrypt ecb_LTX__init_mcrypt 28 | #define _end_mcrypt ecb_LTX__end_mcrypt 29 | #define _mcrypt ecb_LTX__mcrypt 30 | #define _mdecrypt ecb_LTX__mdecrypt 31 | #define _has_iv ecb_LTX__has_iv 32 | #define _is_block_mode ecb_LTX__is_block_mode 33 | #define _is_block_algorithm_mode ecb_LTX__is_block_algorithm_mode 34 | #define _mcrypt_get_modes_name ecb_LTX__mcrypt_get_modes_name 35 | #define _mcrypt_mode_get_size ecb_LTX__mcrypt_mode_get_size 36 | #define _mcrypt_mode_version ecb_LTX__mcrypt_mode_version 37 | 38 | int _init_mcrypt( void* ign, void *key, int lenofkey, void *IV, int size) 39 | { 40 | return 0; 41 | 42 | } 43 | 44 | int _mcrypt_set_state( void* buf, void *IV, int size) { return -1; } 45 | int _mcrypt_get_state( void* buf, void *IV, int *size) { return -1; } 46 | 47 | int _end_mcrypt (void* buf) {return 0;} 48 | 49 | int _mcrypt( void* ign, void *plaintext, int len, int blocksize, void* akey, void (*func)(void*,void*), void (*func2)(void*,void*)) 50 | { 51 | int j; 52 | char *plain = plaintext; 53 | void (*_mcrypt_block_encrypt) (void *, void *); 54 | 55 | _mcrypt_block_encrypt = func; 56 | 57 | for (j = 0; j < len / blocksize; j++) { 58 | _mcrypt_block_encrypt(akey, &plain[j * blocksize]); 59 | } 60 | if (j==0 && len!=0) return -1; /* no blocks were encrypted */ 61 | return 0; 62 | } 63 | 64 | 65 | 66 | int _mdecrypt( void* ign, void *ciphertext, int len, int blocksize, void* akey, void (*func)(void*,void*), void (*func2)(void*,void*)) 67 | { 68 | int j; 69 | char *cipher = ciphertext; 70 | void (*_mcrypt_block_decrypt) (void *, void *); 71 | 72 | _mcrypt_block_decrypt = func2; 73 | 74 | for (j = 0; j < len / blocksize; j++) { 75 | _mcrypt_block_decrypt(akey, &cipher[j * blocksize]); 76 | } 77 | if (j==0 && len!=0) return -1; /* no blocks were encrypted */ 78 | return 0; 79 | } 80 | 81 | int _has_iv() { return 0; } 82 | int _is_block_mode() { return 1; } 83 | int _is_block_algorithm_mode() { return 1; } 84 | const char *_mcrypt_get_modes_name() { return "ECB";} 85 | int _mcrypt_mode_get_size () {return 0;} 86 | 87 | word32 _mcrypt_mode_version() { 88 | return 20010801; 89 | } 90 | 91 | #ifdef WIN32 92 | # ifdef USE_LTDL 93 | WIN32DLL_DEFINE int main (void) 94 | { 95 | /* empty main function to avoid linker error (see cygwin FAQ) */ 96 | } 97 | # endif 98 | #endif 99 | -------------------------------------------------------------------------------- /modules/modes/ecb.h: -------------------------------------------------------------------------------- 1 | #ifndef USE_MODULES 2 | int _ecb_init_mcrypt( int td, void* buf, void *key, int lenofkey, void *IV); 3 | int _mcrypt_ecb(int td, void* buf,void *plaintext, int len); 4 | int _mdecrypt_ecb(int td, void* buf, void *plaintext, int len); 5 | int _ecb_is_block_mode(); 6 | int _ecb_has_iv(); 7 | int _ecb_is_block_algorithm_mode(); 8 | char *_mcrypt_ecb_get_modes_name(); 9 | int _mcrypt_ecb_mode_get_size (); 10 | int _mcrypt_ecb_get_iv_size(int td); 11 | word32 _mcrypt_ecb_mode_version(); 12 | #endif 13 | -------------------------------------------------------------------------------- /modules/modes/ncfb.h: -------------------------------------------------------------------------------- 1 | #ifndef USE_MODULES 2 | int _ncfb_init_mcrypt( int td, void* buf, void *key, int lenofkey, void *IV); 3 | int _mcrypt_ncfb(int td, void* buf,void *plaintext, int len); 4 | int _mdecrypt_ncfb(int td, void* buf, void *plaintext, int len); 5 | int _ncfb_is_block_mode(); 6 | int _ncfb_has_iv(); 7 | int _ncfb_is_block_algorithm_mode(); 8 | char *_mcrypt_ncfb_get_modes_name(); 9 | int _mcrypt_ncfb_mode_get_size (); 10 | int _mcrypt_ncfb_get_iv_size(int td); 11 | word32 _mcrypt_ncfb_mode_version(); 12 | #endif 13 | -------------------------------------------------------------------------------- /modules/modes/nofb.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1998,1999,2000,2001 Nikos Mavroyanopoulos 3 | * 4 | * This library is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU Library General Public License as published 6 | * by the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | #define _init_mcrypt nofb_LTX__init_mcrypt 24 | #define _mcrypt_set_state nofb_LTX__mcrypt_set_state 25 | #define _mcrypt_get_state nofb_LTX__mcrypt_get_state 26 | #define _end_mcrypt nofb_LTX__end_mcrypt 27 | #define _mcrypt nofb_LTX__mcrypt 28 | #define _mdecrypt nofb_LTX__mdecrypt 29 | #define _has_iv nofb_LTX__has_iv 30 | #define _is_block_mode nofb_LTX__is_block_mode 31 | #define _is_block_algorithm_mode nofb_LTX__is_block_algorithm_mode 32 | #define _mcrypt_get_modes_name nofb_LTX__mcrypt_get_modes_name 33 | #define _mcrypt_mode_get_size nofb_LTX__mcrypt_mode_get_size 34 | #define _mcrypt_mode_version nofb_LTX__mcrypt_mode_version 35 | 36 | typedef struct ncfb_buf { 37 | byte* enc_s_register; 38 | byte* s_register; 39 | int s_register_pos; 40 | int blocksize; 41 | } nOFB_BUFFER; 42 | 43 | /* nOFB MODE */ 44 | 45 | int _init_mcrypt( nOFB_BUFFER* buf, void *key, int lenofkey, void *IV, int size) 46 | { 47 | buf->enc_s_register = buf->s_register = NULL; 48 | buf->s_register_pos = 0; 49 | 50 | buf->blocksize = size; 51 | /* For ofb */ 52 | buf->enc_s_register=malloc( size); 53 | if (buf->enc_s_register==NULL) goto freeall; 54 | 55 | buf->s_register=malloc( size); 56 | if (buf->s_register==NULL) goto freeall; 57 | 58 | if (IV!=NULL) { 59 | memcpy(buf->enc_s_register, IV, size); 60 | memcpy(buf->s_register, IV, size); 61 | } else { 62 | memset(buf->enc_s_register, 0, size); 63 | memset(buf->s_register, 0, size); 64 | } 65 | 66 | /* End nofb */ 67 | 68 | return 0; 69 | freeall: 70 | free(buf->enc_s_register); 71 | free(buf->s_register); 72 | return -1; 73 | } 74 | 75 | int _mcrypt_set_state( nOFB_BUFFER* buf, byte *IV, int size) 76 | { 77 | buf->s_register_pos = IV[0]; 78 | memcpy(buf->enc_s_register, &IV[1], size-1); 79 | memcpy(buf->s_register, &IV[1], size-1); 80 | 81 | return 0; 82 | } 83 | 84 | int _mcrypt_get_state( nOFB_BUFFER* buf, byte *IV, int *size) 85 | { 86 | if (*size < buf->blocksize + 1) { 87 | *size = buf->blocksize + 1; 88 | return -1; 89 | } 90 | *size = buf->blocksize + 1; 91 | 92 | IV[0] = buf->s_register_pos; 93 | memcpy( &IV[1], buf->s_register, buf->blocksize); 94 | 95 | return 0; 96 | } 97 | 98 | 99 | void _end_mcrypt( nOFB_BUFFER* buf) { 100 | free(buf->s_register); 101 | free(buf->enc_s_register); 102 | } 103 | 104 | #ifdef _MSC_VER 105 | __inline static 106 | #else 107 | inline static 108 | #endif 109 | void xor_stuff( nOFB_BUFFER *buf, void* akey, void (*func)(void*,void*), byte* plain, int blocksize, int xor_size) 110 | { 111 | void (*_mcrypt_block_encrypt) (void *, void *); 112 | 113 | _mcrypt_block_encrypt = func; 114 | 115 | if (xor_size == blocksize) { 116 | if (buf->s_register_pos == 0) { 117 | 118 | memcpy(buf->enc_s_register, buf->s_register, blocksize); 119 | 120 | _mcrypt_block_encrypt(akey, buf->enc_s_register); 121 | 122 | memcpy(buf->s_register, buf->enc_s_register, blocksize); 123 | 124 | memxor( plain, buf->enc_s_register, blocksize); 125 | 126 | } else { 127 | int size = blocksize - buf->s_register_pos; 128 | 129 | memxor( plain, &buf->enc_s_register[buf->s_register_pos], 130 | size); 131 | 132 | memcpy(buf->enc_s_register, buf->s_register, blocksize); 133 | 134 | _mcrypt_block_encrypt(akey, buf->enc_s_register); 135 | 136 | memcpy( buf->s_register, 137 | buf->enc_s_register, blocksize); 138 | 139 | memxor( &plain[size], buf->enc_s_register, 140 | buf->s_register_pos); 141 | 142 | /* buf->s_register_pos remains the same */ 143 | } 144 | } else { /* xor_size != blocksize */ 145 | if (buf->s_register_pos == 0) { 146 | memcpy(buf->enc_s_register, buf->s_register, blocksize); 147 | 148 | _mcrypt_block_encrypt(akey, buf->enc_s_register); 149 | 150 | memcpy(buf->s_register, buf->enc_s_register, blocksize); 151 | 152 | memxor( plain, buf->enc_s_register, xor_size); 153 | 154 | buf->s_register_pos = xor_size; 155 | } else { 156 | int size = blocksize - buf->s_register_pos; 157 | int min_size = size < xor_size ? size: xor_size; 158 | 159 | memxor( plain, &buf->enc_s_register[buf->s_register_pos], 160 | min_size); 161 | 162 | buf->s_register_pos += min_size; 163 | 164 | if (min_size >= xor_size) 165 | return; 166 | 167 | memcpy(buf->enc_s_register, buf->s_register, blocksize); 168 | 169 | _mcrypt_block_encrypt(akey, buf->enc_s_register); 170 | 171 | memcpy(buf->s_register, buf->enc_s_register, blocksize); 172 | 173 | memxor( &plain[min_size], buf->s_register, 174 | xor_size - min_size); 175 | 176 | buf->s_register_pos = xor_size - min_size; 177 | 178 | } 179 | 180 | } 181 | return; 182 | } 183 | 184 | 185 | int _mcrypt( nOFB_BUFFER* buf,void *plaintext, int len, int blocksize, void* akey, void (*func)(void*,void*), void (*func2)(void*,void*)) 186 | { /* plaintext is n*blocksize bytes (nbit cfb) */ 187 | byte* plain; 188 | int i, j=0; 189 | void (*_mcrypt_block_encrypt) (void *, void *); 190 | int modlen; 191 | 192 | _mcrypt_block_encrypt = func; 193 | 194 | plain = plaintext; 195 | for (j = 0; j < len / blocksize; j++) { 196 | xor_stuff( buf, akey, func, plain, blocksize, blocksize); 197 | 198 | plain += blocksize; 199 | 200 | } 201 | modlen = len % blocksize; 202 | if (modlen > 0) { 203 | xor_stuff( buf, akey, func, plain, blocksize, modlen); 204 | } 205 | 206 | return 0; 207 | } 208 | 209 | 210 | int _mdecrypt( nOFB_BUFFER* buf,void *plaintext, int len, int blocksize, void* akey, void (*func)(void*,void*), void (*func2)(void*,void*)) 211 | { /* plaintext is n*blocksize bytes (nbit cfb) */ 212 | return _mcrypt( buf, plaintext, len, blocksize, akey, func, func2); 213 | } 214 | 215 | int _has_iv() { return 1; } 216 | int _is_block_mode() { return 0; } 217 | int _is_block_algorithm_mode() { return 1; } 218 | char *_mcrypt_get_modes_name() { return "nOFB";} 219 | int _mcrypt_mode_get_size () {return sizeof(nOFB_BUFFER);} 220 | 221 | 222 | word32 _mcrypt_mode_version() { 223 | return 20020307; 224 | } 225 | 226 | #ifdef WIN32 227 | # ifdef USE_LTDL 228 | WIN32DLL_DEFINE int main (void) 229 | { 230 | /* empty main function to avoid linker error (see cygwin FAQ) */ 231 | } 232 | # endif 233 | #endif 234 | -------------------------------------------------------------------------------- /modules/modes/nofb.h: -------------------------------------------------------------------------------- 1 | #ifndef USE_MODULES 2 | int _nofb_init_mcrypt( int td, void* buf, void *key, int lenofkey, void *IV); 3 | int _mcrypt_nofb(int td, void* buf,void *plaintext, int len); 4 | int _mdecrypt_nofb(int td, void* buf, void *plaintext, int len); 5 | int _nofb_is_block_mode(); 6 | int _nofb_has_iv(); 7 | int _nofb_is_block_algorithm_mode(); 8 | char *_mcrypt_nofb_get_modes_name(); 9 | int _mcrypt_nofb_mode_get_size (); 10 | int _mcrypt_nofb_get_iv_size(int td); 11 | word32 _mcrypt_nofb_mode_version(); 12 | #endif 13 | -------------------------------------------------------------------------------- /modules/modes/ofb.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1998,1999,2000,2001,2002 Nikos Mavroyanopoulos 3 | * 4 | * This library is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU Library General Public License as published 6 | * by the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | #define _init_mcrypt ofb_LTX__init_mcrypt 24 | #define _mcrypt_set_state ofb_LTX__mcrypt_set_state 25 | #define _mcrypt_get_state ofb_LTX__mcrypt_get_state 26 | #define _end_mcrypt ofb_LTX__end_mcrypt 27 | #define _mcrypt ofb_LTX__mcrypt 28 | #define _mdecrypt ofb_LTX__mdecrypt 29 | #define _has_iv ofb_LTX__has_iv 30 | #define _is_block_mode ofb_LTX__is_block_mode 31 | #define _is_block_algorithm_mode ofb_LTX__is_block_algorithm_mode 32 | #define _mcrypt_get_modes_name ofb_LTX__mcrypt_get_modes_name 33 | #define _mcrypt_mode_get_size ofb_LTX__mcrypt_mode_get_size 34 | #define _mcrypt_mode_version ofb_LTX__mcrypt_mode_version 35 | 36 | typedef struct ofb_buf { 37 | byte* s_register; 38 | byte* enc_s_register; 39 | int blocksize; 40 | } OFB_BUFFER; 41 | 42 | 43 | /* OFB MODE */ 44 | 45 | int _init_mcrypt( OFB_BUFFER* buf, void *key, int lenofkey, void *IV, int size) 46 | { 47 | 48 | buf->s_register = buf->enc_s_register = NULL; 49 | 50 | buf->blocksize = size; 51 | 52 | /* For ofb */ 53 | buf->s_register=malloc( size); 54 | if (buf->s_register==NULL) goto freeall; 55 | 56 | buf->enc_s_register=malloc( size); 57 | if (buf->enc_s_register==NULL) goto freeall; 58 | 59 | if (IV!=NULL) { 60 | memcpy(buf->s_register, IV, size); 61 | } else { 62 | memset(buf->s_register, 0, size); 63 | } 64 | /* End ofb */ 65 | 66 | return 0; 67 | 68 | freeall: 69 | free(buf->s_register); 70 | free(buf->enc_s_register); 71 | return -1; 72 | } 73 | 74 | int _mcrypt_get_state( OFB_BUFFER* buf, byte *IV, int *size) 75 | { 76 | if (*size < buf->blocksize) { 77 | *size = buf->blocksize; 78 | return -1; 79 | } 80 | *size = buf->blocksize; 81 | 82 | memcpy( IV, buf->s_register, buf->blocksize); 83 | 84 | return 0; 85 | } 86 | 87 | int _mcrypt_set_state( OFB_BUFFER* buf, void *IV, int size) 88 | { 89 | memcpy(buf->enc_s_register, IV, size); 90 | memcpy(buf->s_register, IV, size); 91 | 92 | return 0; 93 | } 94 | 95 | 96 | void _end_mcrypt( OFB_BUFFER* buf) { 97 | free(buf->s_register); 98 | free(buf->enc_s_register); 99 | } 100 | 101 | 102 | int _mcrypt( OFB_BUFFER* buf,void *plaintext, int len, int blocksize, void* akey, void (*func)(void*,void*), void (*func2)(void*,void*) ) 103 | { /* plaintext is 1 byte (8bit ofb) */ 104 | char *plain = plaintext; 105 | int i, j; 106 | void (*_mcrypt_block_encrypt) (void *, void *); 107 | 108 | _mcrypt_block_encrypt = func; 109 | 110 | for (j = 0; j < len; j++) { 111 | 112 | memcpy(buf->enc_s_register, buf->s_register, blocksize); 113 | 114 | _mcrypt_block_encrypt(akey, buf->enc_s_register); 115 | 116 | plain[j] ^= buf->enc_s_register[0]; 117 | 118 | /* Shift the register */ 119 | for (i = 0; i < (blocksize - 1); i++) 120 | buf->s_register[i] = buf->s_register[i + 1]; 121 | 122 | buf->s_register[blocksize - 1] = buf->enc_s_register[0]; 123 | } 124 | 125 | return 0; 126 | 127 | } 128 | 129 | 130 | int _mdecrypt( OFB_BUFFER* buf, void *plaintext, int len, int blocksize, void* akey, void (*func)(void*,void*), void (*func2)(void*,void*)) 131 | { /* plaintext is 1 byte (8bit ofb) */ 132 | char *plain = plaintext; 133 | int i, j; 134 | void (*_mcrypt_block_encrypt) (void *, void *); 135 | 136 | _mcrypt_block_encrypt = func; 137 | 138 | for (j = 0; j < len; j++) { 139 | 140 | memcpy(buf->enc_s_register, buf->s_register, blocksize); 141 | 142 | _mcrypt_block_encrypt(akey, buf->enc_s_register); 143 | 144 | /* Shift the register */ 145 | for (i = 0; i < (blocksize - 1); i++) 146 | buf->s_register[i] = buf->s_register[i + 1]; 147 | 148 | buf->s_register[blocksize - 1] = buf->enc_s_register[0]; 149 | 150 | plain[j] ^= buf->enc_s_register[0]; 151 | 152 | } 153 | 154 | return 0; 155 | } 156 | 157 | int _is_block_mode() { return 0; } 158 | int _has_iv() { return 1; } 159 | int _is_block_algorithm_mode() { return 1; } 160 | char *_mcrypt_get_modes_name() { return "OFB"; } 161 | int _mcrypt_mode_get_size () {return sizeof(OFB_BUFFER);} 162 | 163 | word32 _mcrypt_mode_version() { 164 | return 20010310; 165 | } 166 | 167 | #ifdef WIN32 168 | # ifdef USE_LTDL 169 | WIN32DLL_DEFINE int main (void) 170 | { 171 | /* empty main function to avoid linker error (see cygwin FAQ) */ 172 | } 173 | # endif 174 | #endif 175 | -------------------------------------------------------------------------------- /modules/modes/ofb.h: -------------------------------------------------------------------------------- 1 | #ifndef USE_MODULES 2 | int _ofb_init_mcrypt( int td, void* buf, void *key, int lenofkey, void *IV); 3 | int _mcrypt_ofb(int td, void* buf,void *plaintext, int len); 4 | int _mdecrypt_ofb(int td, void* buf, void *plaintext, int len); 5 | int _ofb_is_block_mode(); 6 | int _ofb_has_iv(); 7 | int _ofb_is_block_algorithm_mode(); 8 | char *_mcrypt_ofb_get_modes_name(); 9 | int _mcrypt_ofb_mode_get_size (); 10 | int _mcrypt_ofb_get_iv_size(int td); 11 | word32 _mcrypt_ofb_mode_version(); 12 | #endif 13 | -------------------------------------------------------------------------------- /modules/modes/stream.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1998,1999,2000,2001 Nikos Mavroyanopoulos 3 | * 4 | * This library is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU Library General Public License as published 6 | * by the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Library General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Library General Public 15 | * License along with this library; if not, write to the 16 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 | * Boston, MA 02111-1307, USA. 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | #define _init_mcrypt stream_LTX__init_mcrypt 24 | #define _mcrypt_set_state stream_LTX__mcrypt_set_state 25 | #define _mcrypt_get_state stream_LTX__mcrypt_get_state 26 | #define _end_mcrypt stream_LTX__end_mcrypt 27 | #define _mcrypt stream_LTX__mcrypt 28 | #define _mdecrypt stream_LTX__mdecrypt 29 | #define _has_iv stream_LTX__has_iv 30 | #define _is_block_mode stream_LTX__is_block_mode 31 | #define _is_block_algorithm_mode stream_LTX__is_block_algorithm_mode 32 | #define _mcrypt_get_modes_name stream_LTX__mcrypt_get_modes_name 33 | #define _mcrypt_mode_get_size stream_LTX__mcrypt_mode_get_size 34 | #define _mcrypt_mode_version stream_LTX__mcrypt_mode_version 35 | 36 | /* STREAM MODE */ 37 | 38 | int _init_mcrypt( void* ign, void *key, int lenofkey, void *IV, int size) { return 0; } 39 | 40 | int _mcrypt_set_state( void* buf, void *IV, int size) { return -1; } 41 | int _mcrypt_get_state( void* buf, void *IV, int *size) { return -1; } 42 | 43 | int _end_mcrypt(void* ign) {return 0;} 44 | 45 | int _mcrypt( void* ign, void *plaintext, int len, int blocksize, void* akey, void (*func)(void*,void*, int), void (*func2)(void*,void*, int)) 46 | { 47 | void (*_mcrypt_stream_encrypt) (void *, void *, int); 48 | 49 | _mcrypt_stream_encrypt = func; 50 | 51 | _mcrypt_stream_encrypt(akey, plaintext, len); 52 | return 0; 53 | } 54 | 55 | 56 | 57 | int _mdecrypt( void* ign, void *ciphertext, int len, int blocksize, void* akey, void (*func)(void*,void*, int), void (*func2)(void*,void*, int)) 58 | { 59 | void (*_mcrypt_stream_decrypt) (void *, void *, int); 60 | 61 | _mcrypt_stream_decrypt = func2; 62 | 63 | _mcrypt_stream_decrypt(akey, ciphertext, len); 64 | return 0; 65 | } 66 | 67 | int _has_iv() { return 1; } 68 | int _is_block_mode() { return 0; } 69 | int _is_block_algorithm_mode() { return 0; } 70 | const char *_mcrypt_get_modes_name() { return "STREAM";} 71 | int _mcrypt_mode_get_size () {return 0;} 72 | 73 | word32 _mcrypt_mode_version() { 74 | return 20010801; 75 | } 76 | 77 | #ifdef WIN32 78 | # ifdef USE_LTDL 79 | WIN32DLL_DEFINE int main (void) 80 | { 81 | /* empty main function to avoid linker error (see cygwin FAQ) */ 82 | } 83 | # endif 84 | #endif 85 | -------------------------------------------------------------------------------- /modules/modes/stream.h: -------------------------------------------------------------------------------- 1 | #ifndef USE_MODULES 2 | int _stream_init_mcrypt( int td, void* buf, void *key, int lenofkey, void *IV); 3 | int _mcrypt_stream(int td, void* buf,void *plaintext, int len); 4 | int _mdecrypt_stream(int td, void* buf, void *plaintext, int len); 5 | int _stream_is_block_mode(); 6 | int _stream_has_iv(); 7 | int _stream_is_block_algorithm_mode(); 8 | char *_mcrypt_stream_get_modes_name(); 9 | int _mcrypt_stream_mode_get_size (); 10 | int _mcrypt_stream_get_iv_size(int td); 11 | word32 _mcrypt_stream_mode_version(); 12 | #endif 13 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | 3 | noinst_PROGRAMS = ciphertest aestest 4 | ciphertest_SOURCES = cipher_test.c 5 | ciphertest_LDADD = ../lib/libmcrypt.la $(LIBLTDL) 6 | aestest_SOURCES = aes_test.c 7 | aestest_LDADD = ../lib/libmcrypt.la $(LIBLTDL) 8 | TESTS = ciphertest aestest 9 | -------------------------------------------------------------------------------- /src/aes_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2002 Nikos Mavroyanopoulos 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 | */ 18 | 19 | #include "../include/mutils/mcrypt.h" 20 | #include 21 | #include 22 | #include 23 | 24 | /* Prints plaintext and ciphertext in hex for all the algorithms */ 25 | 26 | #define ALGORITHMS_DIR "../modules/algorithms/.libs" 27 | #define MODES_DIR "../modules/modes/.libs" 28 | /* #define ALGORITHMS_DIR NULL 29 | * #define MODES_DIR NULL 30 | */ 31 | 32 | #define CFB8_AES_128_KEY "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c" 33 | #define CFB8_AES_128_IV "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" 34 | #define CFB8_AES_128_PT "\x6b\xc1\xbe\xe2\x2e" 35 | #define CFB8_AES_128_CT "\x3b\x79\x42\x4c\x9c" 36 | #define CFB8_AES_128_PT_SIZE 5 37 | 38 | #define CFB128_AES_128_KEY "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c" 39 | #define CFB128_AES_128_IV "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" 40 | #define CFB128_AES_128_PT "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a" 41 | #define CFB128_AES_128_CT "\x3b\x3f\xd9\x2e\xb7\x2d\xad\x20\x33\x34\x49\xf8\xe8\x3c\xfb\x4a" 42 | #define CFB128_AES_128_PT2 "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51" 43 | #define CFB128_AES_128_CT2 "\xc8\xa6\x45\x37\xa0\xb3\xa9\x3f\xcd\xe3\xcd\xad\x9f\x1c\xe5\x8b" 44 | #define CFB128_AES_128_PT_SIZE 16 45 | 46 | #define OFB128_AES_128_KEY "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c" 47 | #define OFB128_AES_128_IV "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" 48 | #define OFB128_AES_128_PT "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a" 49 | #define OFB128_AES_128_CT "\x3b\x3f\xd9\x2e\xb7\x2d\xad\x20\x33\x34\x49\xf8\xe8\x3c\xfb\x4a" 50 | #define OFB128_AES_128_PT2 "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51" 51 | #define OFB128_AES_128_CT2 "\x77\x89\x50\x8d\x16\x91\x8f\x03\xf5\x3c\x52\xda\xc5\x4e\xd8\x25" 52 | #define OFB128_AES_128_PT_SIZE 16 53 | 54 | #define CTR_AES_128_KEY "\x2b\x7e\x15\x16\x28\xae\xd2\xa6\xab\xf7\x15\x88\x09\xcf\x4f\x3c" 55 | #define CTR_AES_128_IV "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff" 56 | #define CTR_AES_128_PT "\x6b\xc1\xbe\xe2\x2e\x40\x9f\x96\xe9\x3d\x7e\x11\x73\x93\x17\x2a" 57 | #define CTR_AES_128_CT "\x87\x4d\x61\x91\xb6\x20\xe3\x26\x1b\xef\x68\x64\x99\x0d\xb6\xce" 58 | #define CTR_AES_128_PT2 "\xae\x2d\x8a\x57\x1e\x03\xac\x9c\x9e\xb7\x6f\xac\x45\xaf\x8e\x51" 59 | #define CTR_AES_128_CT2 "\x98\x06\xf6\x6b\x79\x70\xfd\xff\x86\x17\x18\x7b\xb9\xff\xfd\xff" 60 | #define CTR_AES_128_PT_SIZE 16 61 | 62 | 63 | int main() 64 | { 65 | MCRYPT td, td2; 66 | int i, t, imax; 67 | int j, jmax, ivsize; 68 | int x = 0, siz; 69 | char *text; 70 | unsigned char *IV; 71 | unsigned char *key; 72 | int keysize; 73 | 74 | /* CFB 8 test */ 75 | td = mcrypt_module_open("rijndael-128", ALGORITHMS_DIR, "cfb", MODES_DIR); 76 | 77 | if (td != MCRYPT_FAILED) { 78 | key = CFB8_AES_128_KEY; 79 | IV = CFB8_AES_128_IV; 80 | 81 | if (mcrypt_generic_init( td, key, 16, IV) < 0) { 82 | fprintf(stderr, "Failed to Initialize algorithm!\n"); 83 | return -1; 84 | } 85 | 86 | siz = CFB8_AES_128_PT_SIZE; 87 | 88 | text = malloc( siz); 89 | memcpy( text, CFB8_AES_128_PT, siz); 90 | 91 | mcrypt_generic( td, text, siz); 92 | 93 | if (memcmp( text, CFB8_AES_128_CT, siz)!=0) { 94 | fprintf(stderr, "Failed CFB8 compliance\n"); 95 | return(1); 96 | } 97 | 98 | mcrypt_generic_deinit(td); 99 | mcrypt_module_close(td); 100 | 101 | } else { 102 | fprintf(stderr, "Failed to initialize cipher - rijndael-128/cfb\n"); 103 | return 1; 104 | } 105 | 106 | 107 | /* CFB 128 test */ 108 | td = mcrypt_module_open("rijndael-128", ALGORITHMS_DIR, "ncfb", MODES_DIR); 109 | 110 | if (td != MCRYPT_FAILED) { 111 | key = CFB128_AES_128_KEY; 112 | IV = CFB128_AES_128_IV; 113 | 114 | if (mcrypt_generic_init( td, key, 16, IV) < 0) { 115 | fprintf(stderr, "Failed to Initialize algorithm!\n"); 116 | return -1; 117 | } 118 | 119 | siz = CFB128_AES_128_PT_SIZE; 120 | 121 | text = malloc( siz); 122 | memcpy( text, CFB128_AES_128_PT, siz); 123 | 124 | /* mcrypt_generic( td, text, siz); */ 125 | 126 | /* here we test if the stream mode is correctly 127 | * implemented. 128 | */ 129 | mcrypt_generic( td, text, 5); 130 | mcrypt_generic( td, &text[5], siz-5); 131 | 132 | if (memcmp( text, CFB128_AES_128_CT, siz)!=0) { 133 | fprintf(stderr, "Failed CFB128-1 compliance\n"); 134 | return(1); 135 | } 136 | 137 | memcpy( text, CFB128_AES_128_PT2, siz); 138 | 139 | mcrypt_generic( td, text, siz); 140 | 141 | if (memcmp( text, CFB128_AES_128_CT2, siz)!=0) { 142 | fprintf(stderr, "Failed CFB128-2 compliance\n"); 143 | return(1); 144 | } 145 | 146 | mcrypt_generic_deinit(td); 147 | mcrypt_module_close(td); 148 | 149 | } else { 150 | fprintf(stderr, "Failed to initialize cipher - rijndael-128/ncfb\n"); 151 | return 1; 152 | } 153 | 154 | /* OFB 128 test */ 155 | td = mcrypt_module_open("rijndael-128", ALGORITHMS_DIR, "nofb", MODES_DIR); 156 | 157 | if (td != MCRYPT_FAILED) { 158 | key = OFB128_AES_128_KEY; 159 | IV = OFB128_AES_128_IV; 160 | 161 | if (mcrypt_generic_init( td, key, 16, IV) < 0) { 162 | fprintf(stderr, "Failed to Initialize algorithm!\n"); 163 | return -1; 164 | } 165 | 166 | siz = OFB128_AES_128_PT_SIZE; 167 | 168 | text = malloc( siz); 169 | memcpy( text, OFB128_AES_128_PT, siz); 170 | 171 | mcrypt_generic( td, text, siz); 172 | 173 | if (memcmp( text, OFB128_AES_128_CT, siz)!=0) { 174 | fprintf(stderr, "Failed OFB128-1 compliance\n"); 175 | return(1); 176 | } 177 | 178 | memcpy( text, OFB128_AES_128_PT2, siz); 179 | 180 | mcrypt_generic( td, text, 5); 181 | mcrypt_generic( td, &text[5], siz-5); 182 | 183 | if (memcmp( text, OFB128_AES_128_CT2, siz)!=0) { 184 | fprintf(stderr, "Failed OFB128-2 compliance\n"); 185 | return(1); 186 | } 187 | 188 | mcrypt_generic_deinit(td); 189 | mcrypt_module_close(td); 190 | 191 | } else { 192 | fprintf(stderr, "Failed to initialize cipher - rijndael-128/nofb\n"); 193 | return 1; 194 | } 195 | 196 | /* CTR test */ 197 | td = mcrypt_module_open("rijndael-128", ALGORITHMS_DIR, "ctr", MODES_DIR); 198 | 199 | if (td != MCRYPT_FAILED) { 200 | key = CTR_AES_128_KEY; 201 | IV = CTR_AES_128_IV; 202 | 203 | if (mcrypt_generic_init( td, key, 16, IV) < 0) { 204 | fprintf(stderr, "Failed to Initialize algorithm!\n"); 205 | return -1; 206 | } 207 | 208 | siz = CTR_AES_128_PT_SIZE; 209 | 210 | text = malloc( siz); 211 | memcpy( text, CTR_AES_128_PT, siz); 212 | 213 | mcrypt_generic( td, text, 5); 214 | mcrypt_generic( td, &text[5], siz-5); 215 | 216 | if (memcmp( text, CTR_AES_128_CT, siz)!=0) { 217 | fprintf(stderr, "Failed CTR-1 compliance\n"); 218 | return(1); 219 | } 220 | 221 | memcpy( text, CTR_AES_128_PT2, siz); 222 | 223 | mcrypt_generic( td, text, siz); 224 | 225 | if (memcmp( text, CTR_AES_128_CT2, siz)!=0) { 226 | fprintf(stderr, "Failed CTR-2 compliance\n"); 227 | return(1); 228 | } 229 | 230 | mcrypt_generic_deinit(td); 231 | mcrypt_module_close(td); 232 | 233 | } else { 234 | fprintf(stderr, "Failed to initialize cipher - rijndael-128/nofb\n"); 235 | return 1; 236 | } 237 | 238 | fprintf(stdout, "AES tests (CFB, nCFB, nOFB, CTR) were successful.\n"); 239 | return 0; 240 | } 241 | -------------------------------------------------------------------------------- /src/cipher_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1998,1999,2000,2002 Nikos Mavroyanopoulos 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 | */ 18 | 19 | #include "../include/mutils/mcrypt.h" 20 | #include 21 | #include 22 | #include 23 | 24 | /* Prints plaintext and ciphertext in hex for all the algorithms */ 25 | 26 | #define ALGORITHMS_DIR "../modules/algorithms/.libs" 27 | #define MODES_DIR "../modules/modes/.libs" 28 | /* #define ALGORITHMS_DIR NULL 29 | * #define MODES_DIR NULL 30 | */ 31 | #define TEXT "a small text, just to test the implementation" 32 | 33 | int main() 34 | { 35 | MCRYPT td, td2; 36 | int i, t, imax; 37 | int j, jmax, ivsize; 38 | int x = 0, siz; 39 | char **names; 40 | char **modes; 41 | char *text; 42 | unsigned char *IV; 43 | unsigned char *key; 44 | int keysize; 45 | 46 | names = mcrypt_list_algorithms (ALGORITHMS_DIR, &jmax); 47 | modes = mcrypt_list_modes (MODES_DIR, &imax); 48 | 49 | if (names==NULL || modes==NULL) { 50 | fprintf(stderr, "Error getting algorithms/modes\n"); 51 | exit(1); 52 | } 53 | 54 | for (j=0;j0) { 77 | IV = calloc( 1, ivsize); 78 | if (IV==NULL) exit(1); 79 | for (t=0;t0) free(IV); 116 | } 117 | } 118 | printf("\n"); 119 | 120 | } 121 | mcrypt_free_p(names, jmax); 122 | mcrypt_free_p(modes, imax); 123 | 124 | 125 | if (x>0) fprintf(stderr, "\nProbably some of the algorithms listed above failed. " 126 | "Try not to use these algorithms, and file a bug report to mcrypt-dev@lists.hellug.gr\n\n"); 127 | return x; 128 | } 129 | -------------------------------------------------------------------------------- /stamp-h1: -------------------------------------------------------------------------------- 1 | timestamp for config.h 2 | -------------------------------------------------------------------------------- /win32/vc11/libmcrypt.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libmcrypt", "libmcrypt.vcxproj", "{0AC42F59-CFB2-415C-A110-6E839F12CBCA}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Debug|x64 = Debug|x64 10 | Release dll|Win32 = Release dll|Win32 11 | Release dll|x64 = Release dll|x64 12 | Release lib|Win32 = Release lib|Win32 13 | Release lib|x64 = Release lib|x64 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Debug|Win32.ActiveCfg = Debug|Win32 17 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Debug|Win32.Build.0 = Debug|Win32 18 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Debug|x64.ActiveCfg = Debug|x64 19 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Debug|x64.Build.0 = Debug|x64 20 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Release dll|Win32.ActiveCfg = Release dll|Win32 21 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Release dll|Win32.Build.0 = Release dll|Win32 22 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Release dll|x64.ActiveCfg = Release dll|x64 23 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Release dll|x64.Build.0 = Release dll|x64 24 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Release lib|Win32.ActiveCfg = Release lib|Win32 25 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Release lib|Win32.Build.0 = Release lib|Win32 26 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Release lib|x64.ActiveCfg = Release lib|x64 27 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Release lib|x64.Build.0 = Release lib|x64 28 | EndGlobalSection 29 | GlobalSection(SolutionProperties) = preSolution 30 | HideSolutionNode = FALSE 31 | EndGlobalSection 32 | EndGlobal 33 | -------------------------------------------------------------------------------- /win32/vc14/libmcrypt.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.22823.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libmcrypt", "libmcrypt.vcxproj", "{0AC42F59-CFB2-415C-A110-6E839F12CBCA}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Debug|x64 = Debug|x64 12 | Release dll|Win32 = Release dll|Win32 13 | Release dll|x64 = Release dll|x64 14 | Release lib|Win32 = Release lib|Win32 15 | Release lib|x64 = Release lib|x64 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Debug|Win32.ActiveCfg = Debug|Win32 19 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Debug|Win32.Build.0 = Debug|Win32 20 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Debug|x64.ActiveCfg = Debug|x64 21 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Debug|x64.Build.0 = Debug|x64 22 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Release dll|Win32.ActiveCfg = Release dll|Win32 23 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Release dll|Win32.Build.0 = Release dll|Win32 24 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Release dll|x64.ActiveCfg = Release dll|x64 25 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Release dll|x64.Build.0 = Release dll|x64 26 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Release lib|Win32.ActiveCfg = Release lib|Win32 27 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Release lib|Win32.Build.0 = Release lib|Win32 28 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Release lib|x64.ActiveCfg = Release lib|x64 29 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Release lib|x64.Build.0 = Release lib|x64 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | EndGlobal 35 | -------------------------------------------------------------------------------- /win32/vc15/libmcrypt.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.22823.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libmcrypt", "libmcrypt.vcxproj", "{0AC42F59-CFB2-415C-A110-6E839F12CBCA}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Debug|x64 = Debug|x64 12 | Release dll|Win32 = Release dll|Win32 13 | Release dll|x64 = Release dll|x64 14 | Release lib|Win32 = Release lib|Win32 15 | Release lib|x64 = Release lib|x64 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Debug|Win32.ActiveCfg = Debug|Win32 19 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Debug|Win32.Build.0 = Debug|Win32 20 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Debug|x64.ActiveCfg = Debug|x64 21 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Debug|x64.Build.0 = Debug|x64 22 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Release dll|Win32.ActiveCfg = Release dll|Win32 23 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Release dll|Win32.Build.0 = Release dll|Win32 24 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Release dll|x64.ActiveCfg = Release dll|x64 25 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Release dll|x64.Build.0 = Release dll|x64 26 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Release lib|Win32.ActiveCfg = Release lib|Win32 27 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Release lib|Win32.Build.0 = Release lib|Win32 28 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Release lib|x64.ActiveCfg = Release lib|x64 29 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Release lib|x64.Build.0 = Release lib|x64 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | EndGlobal 35 | -------------------------------------------------------------------------------- /win32/vc6/libmcrypt.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "libmcrypt"=".\libmcrypt.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /win32/vc8/libmcrypt.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 9.00 3 | # Visual Studio 2005 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libmcrypt", "libmcrypt.vcproj", "{0AC42F59-CFB2-415C-A110-6E839F12CBCA}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Debug|x64 = Debug|x64 10 | Release|Win32 = Release|Win32 11 | Release|x64 = Release|x64 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Debug|Win32.Build.0 = Debug|Win32 16 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Debug|x64.ActiveCfg = Debug|Win32 17 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Release|Win32.ActiveCfg = Release|Win32 18 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Release|Win32.Build.0 = Release|Win32 19 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Release|x64.ActiveCfg = Release|Win32 20 | EndGlobalSection 21 | GlobalSection(SolutionProperties) = preSolution 22 | HideSolutionNode = FALSE 23 | EndGlobalSection 24 | EndGlobal 25 | -------------------------------------------------------------------------------- /win32/vc9/libmcrypt.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 10.00 3 | # Visual Studio 2008 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libmcrypt", "libmcrypt.vcproj", "{0AC42F59-CFB2-415C-A110-6E839F12CBCA}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Debug|x64 = Debug|x64 10 | Release|Win32 = Release|Win32 11 | Release|x64 = Release|x64 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Debug|Win32.Build.0 = Debug|Win32 16 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Debug|x64.ActiveCfg = Debug|x64 17 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Debug|x64.Build.0 = Debug|x64 18 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Release|Win32.ActiveCfg = Release|Win32 19 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Release|Win32.Build.0 = Release|Win32 20 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Release|x64.ActiveCfg = Release|x64 21 | {0AC42F59-CFB2-415C-A110-6E839F12CBCA}.Release|x64.Build.0 = Release|x64 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | EndGlobal 27 | -------------------------------------------------------------------------------- /win32/vc9/libmcrypt.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/winlibs/libmcrypt/1e93cbe97a463a2c0c62338d607b17fe011eb77e/win32/vc9/libmcrypt.suo --------------------------------------------------------------------------------