-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
2,583 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
-------------------------------------------------------------------- | ||
The PHP License, version 3.01 | ||
Copyright (c) 1999 - 2014 The PHP Group. All rights reserved. | ||
-------------------------------------------------------------------- | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, is permitted provided that the following conditions | ||
are met: | ||
|
||
1. Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in | ||
the documentation and/or other materials provided with the | ||
distribution. | ||
|
||
3. The name "PHP" must not be used to endorse or promote products | ||
derived from this software without prior written permission. For | ||
written permission, please contact [email protected]. | ||
|
||
4. Products derived from this software may not be called "PHP", nor | ||
may "PHP" appear in their name, without prior written permission | ||
from [email protected]. You may indicate that your software works in | ||
conjunction with PHP by saying "Foo for PHP" instead of calling | ||
it "PHP Foo" or "phpfoo" | ||
|
||
5. The PHP Group may publish revised and/or new versions of the | ||
license from time to time. Each version will be given a | ||
distinguishing version number. | ||
Once covered code has been published under a particular version | ||
of the license, you may always continue to use it under the terms | ||
of that version. You may also choose to use such covered code | ||
under the terms of any subsequent version of the license | ||
published by the PHP Group. No one other than the PHP Group has | ||
the right to modify the terms applicable to covered code created | ||
under this License. | ||
|
||
6. Redistributions of any form whatsoever must retain the following | ||
acknowledgment: | ||
"This product includes PHP software, freely available from | ||
<http://www.php.net/software/>". | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE PHP DEVELOPMENT TEAM ``AS IS'' AND | ||
ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | ||
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PHP | ||
DEVELOPMENT TEAM OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | ||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
-------------------------------------------------------------------- | ||
|
||
This software consists of voluntary contributions made by many | ||
individuals on behalf of the PHP Group. | ||
|
||
The PHP Group can be contacted via Email at [email protected]. | ||
|
||
For more information on the PHP Group and the PHP project, | ||
please see <http://www.php.net>. | ||
|
||
PHP includes the Zend Engine, freely available at | ||
<http://www.zend.com>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
php_tomcrypt | ||
============ | ||
|
||
PHP bindings for `libtomcrypt <http://www.libtom.net/>`. | ||
|
||
Why? | ||
---- | ||
I made this extension for two reasons: | ||
|
||
* First, I wanted to learn how to write a PHP extension. | ||
|
||
* Secondly, there has been discussion recently on the ``php.internals`` | ||
mailing list to remove the bundled ``mcrypt`` extension from PHP 7.0+. | ||
|
||
While I agree with the rationale behind that discussion (libmcrypt | ||
seems to have been abandoned since a few years), I also needed a | ||
replacement for some of my own projects. Therefore, I decided to | ||
look for a crypto library with: | ||
|
||
* a permissive license (see below) | ||
|
||
* a simple API so that I could easily write bindings for it | ||
(I didn't want to have to learn OpenSSL's API for example) | ||
|
||
* relatively good support (eg. widely packaged, receiving | ||
updates, etc.) | ||
|
||
Installation | ||
------------ | ||
You can install this extension using ``pear``: | ||
|
||
.. sourcecode:: console | ||
|
||
pear install https://github.com/fpoirotte/php_tomcrypt/archive/master.tar.gz | ||
|
||
It will also try to add the extension to your ``php.ini`` automatically. | ||
If it fails to do so, you can enable the extension manually by adding | ||
the following line to your ``php.ini``: | ||
|
||
.. sourcecode:: ini | ||
|
||
extension=tomcrypt.so | ||
|
||
Windows support | ||
--------------- | ||
The extension should compile and run just fine under Windows. | ||
Unfortunately, I do not have access to Windows development tools | ||
and cannot compile a binary release for Windows users. | ||
|
||
If you manage to compile the extension on Windows, please let me know through | ||
`GitHub's issue tracker <https://github.com/fpoirotte/php_tomcrypt/issues>`. | ||
|
||
License | ||
------- | ||
libtomcrypt is released under the `WTFPL <http://sam.zoy.org/wtfpl/>` license. | ||
|
||
php_tomcrypt is released under version 3.01 of the | ||
`PHP <http://www.php.net/license/3_01.txt>` license. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
dnl | ||
dnl $Id$ | ||
dnl | ||
|
||
PHP_ARG_WITH(tomcrypt, for libtomcrypt support, | ||
[ --with-tomcrypt[=DIR] Include tomcrypt support]) | ||
|
||
if test "$PHP_TOMCRYPT" != "no"; then | ||
for i in $PHP_TOMCRYPT /usr/local /usr; do | ||
test -f $i/include/tomcrypt.h && TOMCRYPT_DIR=$i && break | ||
done | ||
|
||
if test -z "$TOMCRYPT_DIR"; then | ||
AC_MSG_ERROR(tomcrypt.h not found) | ||
fi | ||
|
||
TOMCRYPT_LIBDIR=$TOMCRYPT_DIR/$PHP_LIBDIR | ||
TOMCRYPT_INCDIR=$TOMCRYPT_DIR/include | ||
|
||
O_LDFLAGS=$LDFLAGS | ||
LDFLAGS="$LDFLAGS -L$TOMCRYPT_LIBDIR" | ||
AC_CHECK_LIB(tomcrypt, find_cipher, [ | ||
TOMCRYPT_LIBS=tomcrypt | ||
TOMCRYPT_CHECK_IN_LIB=tomcrypt | ||
],[ | ||
AC_MSG_ERROR(Unable to find required tomcrypt library) | ||
] | ||
) | ||
LDFLAGS=$O_LDFLAGS | ||
|
||
AC_DEFINE(HAVE_LIBTOMCRYPT,1,[ ]) | ||
PHP_NEW_EXTENSION(tomcrypt, tomcrypt.c, $ext_shared) | ||
PHP_SUBST(TOMCRYPT_SHARED_LIBADD) | ||
|
||
if test -n "$TOMCRYPT_LIBS"; then | ||
PHP_ADD_LIBRARY_WITH_PATH($TOMCRYPT_LIBS, $TOMCRYPT_LIBDIR/lib, TOMCRYPT_SHARED_LIBADD) | ||
fi | ||
|
||
PHP_ADD_INCLUDE($tomcrypt_DIR/include) | ||
|
||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// $Id: config.w32 192637 2005-08-06 23:46:34Z edink $ | ||
// vim:ft=javascript | ||
|
||
ARG_WITH("tomcrypt", "libtomcrypt support", "no"); | ||
|
||
if (PHP_TOMCRYPT != "no") { | ||
|
||
if (CHECK_HEADER_ADD_INCLUDE('tomcrypt.h', 'CFLAGS_TOMCRYPT') && | ||
CHECK_LIB('libtomcrypt.lib', 'tomcrypt')) { | ||
EXTENSION('tomcrypt', 'tomcrypt.c'); | ||
AC_DEFINE('HAVE_LIBTOMCRYPT', 1); | ||
} else { | ||
WARNING("tomcrypt not enabled; libraries and headers not found"); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?xml version="1.0"?> | ||
<package | ||
packagerversion="1.4.0a2" | ||
version="2.0" | ||
xmlns="http://pear.php.net/dtd/package-2.0" | ||
xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<name>tomcrypt</name> | ||
<channel>pecl.php.net</channel> | ||
<summary>PHP bindings for libtomcrypt</summary> | ||
<description> | ||
Provides a replacement API for the old mcrypt extension. | ||
</description> | ||
<lead> | ||
<name>François Poirotte</name> | ||
<user>Clicky</user> | ||
<email>[email protected]</email> | ||
<active>yes</active> | ||
</lead> | ||
<date>2015-05-17</date> | ||
<time>20:36:00</time> | ||
<version> | ||
<release>0.1.0</release> | ||
<api>0.1</api> | ||
</version> | ||
<stability> | ||
<release>beta</release> | ||
<api>stable</api> | ||
</stability> | ||
<license uri="http://www.php.net/license/3_01.txt">PHP</license> | ||
<notes>Initial Release. | ||
</notes> | ||
<contents> | ||
<dir name="/"> | ||
<file name="config.m4" role="src" /> | ||
<file name="tomcrypt.c" role="src" /> | ||
<file name="php_tomcrypt.h" role="src" /> | ||
</dir> | ||
</contents> | ||
<dependencies> | ||
<required> | ||
<php> | ||
<min>5.0.0</min> | ||
<max>6.0.0</max> | ||
</php> | ||
<pearinstaller> | ||
<min>1.4.0a2</min> | ||
</pearinstaller> | ||
</required> | ||
</dependencies> | ||
<providesextension>tomcrypt</providesextension> | ||
<extsrcrelease /> | ||
</package> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
/* | ||
+----------------------------------------------------------------------+ | ||
| PHP Version 5 | | ||
+----------------------------------------------------------------------+ | ||
| Copyright (c) 2015 The PHP Group | | ||
+----------------------------------------------------------------------+ | ||
| This source file is subject to version 3.01 of the PHP license, | | ||
| that is bundled with this package in the file LICENSE, and is | | ||
| available through the world-wide-web at the following url: | | ||
| http://www.php.net/license/3_01.txt | | ||
| If you did not receive a copy of the PHP license and are unable to | | ||
| obtain it through the world-wide-web, please send a note to | | ||
| [email protected] so we can mail you a copy immediately. | | ||
+----------------------------------------------------------------------+ | ||
| Author: François Poirotte <[email protected]> | | ||
+----------------------------------------------------------------------+ | ||
*/ | ||
|
||
#ifndef PHP_TOMCRYPT_H | ||
#define PHP_TOMCRYPT_H | ||
|
||
#if HAVE_LIBMCRYPT | ||
|
||
#ifdef ZTS | ||
#include "TSRM.h" | ||
#endif | ||
|
||
#define PHP_TOMCRYPT_EXTNAME "tomcrypt" | ||
#define PHP_TOMCRYPT_VERSION "0.1.0" | ||
|
||
/* MAC protocols */ | ||
#define PHP_TOMCRYPT_MAC_HMAC "hmac" | ||
#define PHP_TOMCRYPT_MAC_CMAC "cmac" | ||
#define PHP_TOMCRYPT_MAC_PMAC "pmac" | ||
#define PHP_TOMCRYPT_MAC_PELICAN "pelican" | ||
#define PHP_TOMCRYPT_MAC_XCBC "xcbc" | ||
#define PHP_TOMCRYPT_MAC_F9 "f9" | ||
|
||
/* Regular modes */ | ||
#define PHP_TOMCRYPT_MODE_ECB "ecb" | ||
#define PHP_TOMCRYPT_MODE_CFB "cfb" | ||
#define PHP_TOMCRYPT_MODE_OFB "ofb" | ||
#define PHP_TOMCRYPT_MODE_CBC "cbc" | ||
#define PHP_TOMCRYPT_MODE_CTR "ctr" | ||
#define PHP_TOMCRYPT_MODE_LRW "lrw" | ||
#define PHP_TOMCRYPT_MODE_F8 "f8" | ||
#define PHP_TOMCRYPT_MODE_XTS "xts" | ||
|
||
/* AEAD modes */ | ||
#define PHP_TOMCRYPT_MODE_CCM "ccm" | ||
#define PHP_TOMCRYPT_MODE_GCM "gcm" | ||
#define PHP_TOMCRYPT_MODE_EAX "eax" | ||
#define PHP_TOMCRYPT_MODE_OCB "ocb" | ||
|
||
/* RNGs */ | ||
#define PHP_TOMCRYPT_RNG_FORTUNA "fortuna" | ||
#define PHP_TOMCRYPT_RNG_RC4 "rc4" | ||
#define PHP_TOMCRYPT_RNG_SOBER128 "sober128" | ||
#define PHP_TOMCRYPT_RNG_SECURE "sprng" | ||
#define PHP_TOMCRYPT_RNG_YARROW "yarrow" | ||
|
||
extern zend_module_entry tomcrypt_module_entry; | ||
#define tomcrypt_module_ptr &tomcrypt_module_entry | ||
|
||
/* Miscelleanous functions */ | ||
PHP_FUNCTION(tomcrypt_strerror); | ||
#ifdef LTC_BASE64 | ||
PHP_FUNCTION(tomcrypt_base64_encode); | ||
PHP_FUNCTION(tomcrypt_base64_decode); | ||
#endif | ||
|
||
/* Various lists */ | ||
PHP_FUNCTION(tomcrypt_list_modes); | ||
PHP_FUNCTION(tomcrypt_list_ciphers); | ||
PHP_FUNCTION(tomcrypt_list_hashes); | ||
PHP_FUNCTION(tomcrypt_list_macs); | ||
PHP_FUNCTION(tomcrypt_list_rngs); | ||
|
||
/* Cipher-related functions */ | ||
PHP_FUNCTION(tomcrypt_cipher_name); | ||
PHP_FUNCTION(tomcrypt_cipher_block_size); | ||
PHP_FUNCTION(tomcrypt_cipher_adapt_key_size); | ||
PHP_FUNCTION(tomcrypt_cipher_min_key_size); | ||
PHP_FUNCTION(tomcrypt_cipher_max_key_size); | ||
PHP_FUNCTION(tomcrypt_cipher_default_rounds); | ||
PHP_FUNCTION(tomcrypt_cipher_encrypt); | ||
PHP_FUNCTION(tomcrypt_cipher_decrypt); | ||
|
||
/* Hash-related functions */ | ||
PHP_FUNCTION(tomcrypt_hash_name); | ||
PHP_FUNCTION(tomcrypt_hash_block_size); | ||
PHP_FUNCTION(tomcrypt_hash_digest_size); | ||
PHP_FUNCTION(tomcrypt_hash_string); | ||
PHP_FUNCTION(tomcrypt_hash_file); | ||
|
||
/* xMAC-related functions */ | ||
#ifdef LTC_HMAC | ||
PHP_FUNCTION(tomcrypt_hmac_string); | ||
PHP_FUNCTION(tomcrypt_hmac_file); | ||
#endif | ||
#ifdef LTC_OMAC | ||
PHP_FUNCTION(tomcrypt_cmac_string); | ||
PHP_FUNCTION(tomcrypt_cmac_file); | ||
#endif | ||
#ifdef LTC_PMAC | ||
PHP_FUNCTION(tomcrypt_pmac_string); | ||
PHP_FUNCTION(tomcrypt_pmac_file); | ||
#endif | ||
#ifdef LTC_PELICAN | ||
PHP_FUNCTION(tomcrypt_pelican_string); | ||
PHP_FUNCTION(tomcrypt_pelican_file); | ||
#endif | ||
#ifdef LTC_XCBC | ||
PHP_FUNCTION(tomcrypt_xcbc_string); | ||
PHP_FUNCTION(tomcrypt_xcbc_file); | ||
#endif | ||
#ifdef LTC_F9_MODE | ||
PHP_FUNCTION(tomcrypt_f9_string); | ||
PHP_FUNCTION(tomcrypt_f9_file); | ||
#endif | ||
|
||
/* RNG-related functions */ | ||
PHP_FUNCTION(tomcrypt_rng_name); | ||
PHP_FUNCTION(tomcrypt_rng_get_bytes); | ||
|
||
|
||
static inline void php_tomcrypt_bin2hex(char *out, const unsigned char *in, int in_len) | ||
{ | ||
static const char hexits[17] = "0123456789abcdef"; | ||
int i; | ||
|
||
for(i = 0; i < in_len; i++) { | ||
out[i * 2] = hexits[in[i] >> 4]; | ||
out[(i * 2) + 1] = hexits[in[i] & 0x0F]; | ||
} | ||
} | ||
|
||
#else | ||
#define tomcrypt_module_ptr NULL | ||
#endif | ||
|
||
#define phpext_tomcrypt_ptr tomcrypt_module_ptr | ||
|
||
#endif /* PHP_TOMCRYPT_H */ |
Oops, something went wrong.