aboutsummaryrefslogtreecommitdiffstats
path: root/security/pear-Crypt_CBC
diff options
context:
space:
mode:
authordirk <dirk@FreeBSD.org>2003-01-30 17:50:18 +0800
committerdirk <dirk@FreeBSD.org>2003-01-30 17:50:18 +0800
commit33a6aa9a28a1ee9160f6833ea6a5504dd3a5e51b (patch)
tree5ad4b126ed6bb792ce7ec37744e41df6bfaeb17c /security/pear-Crypt_CBC
parentc440e0bd5700b1de31afbe376b62c92211b7e2d6 (diff)
downloadfreebsd-ports-gnome-33a6aa9a28a1ee9160f6833ea6a5504dd3a5e51b.tar.gz
freebsd-ports-gnome-33a6aa9a28a1ee9160f6833ea6a5504dd3a5e51b.tar.zst
freebsd-ports-gnome-33a6aa9a28a1ee9160f6833ea6a5504dd3a5e51b.zip
Add security/pear-Crypt_CBC:
PEAR class to emulate Perl's Crypt::CBC module PR: ports/47418 Submitted by: Thierry Thomas <thierry@pompo.net>
Diffstat (limited to 'security/pear-Crypt_CBC')
-rw-r--r--security/pear-Crypt_CBC/Makefile35
-rw-r--r--security/pear-Crypt_CBC/distinfo1
-rw-r--r--security/pear-Crypt_CBC/files/Crypt_HCEMD5.php288
-rw-r--r--security/pear-Crypt_CBC/pkg-comment1
-rw-r--r--security/pear-Crypt_CBC/pkg-descr3
-rw-r--r--security/pear-Crypt_CBC/pkg-plist3
6 files changed, 331 insertions, 0 deletions
diff --git a/security/pear-Crypt_CBC/Makefile b/security/pear-Crypt_CBC/Makefile
new file mode 100644
index 000000000000..f8d16af22b09
--- /dev/null
+++ b/security/pear-Crypt_CBC/Makefile
@@ -0,0 +1,35 @@
+# Ports collection makefile for: pear-Crypt_CBC
+# Date created: 28 November 2002
+# Whom: Thierry Thomas (<thierry@pompo.net>)
+#
+# $FreeBSD$
+#
+
+PORTNAME= Crypt_CBC
+PORTVERSION= 0.3
+CATEGORIES= security www
+MASTER_SITES= http://pear.php.net/get/
+PKGNAMEPREFIX= pear-
+EXTRACT_SUFX= .tgz
+DIST_SUBDIR= PEAR
+
+MAINTAINER= ports@FreeBSD.org
+
+BUILD_DEPENDS= ${PEARDIR}.DIST_PHP:${PORTSDIR}/devel/pear-install
+RUN_DEPENDS= ${BUILD_DEPENDS}
+
+NO_BUILD= yes
+
+LPHP_LIB= lib/php
+PEARDIR= ${LOCALBASE}/${LPHP_LIB}
+PLIST_SUB= PEARDIR=${LPHP_LIB}
+
+do-install:
+ @${MKDIR} ${PEARDIR}/Crypt
+ @${CP} -Rp ${WRKSRC}/CBC.php ${PEARDIR}/Crypt
+#Note: HCEMD5.php is still needed for IMP 3.1,
+# but should be removed with the next releases.
+ @${CP} -p ${FILESDIR}/Crypt_HCEMD5.php ${PEARDIR}/Crypt/HCEMD5.php
+ @${CHOWN} -R ${SHAREOWN}:${SHAREGRP} ${PEARDIR}/Crypt
+
+.include <bsd.port.mk>
diff --git a/security/pear-Crypt_CBC/distinfo b/security/pear-Crypt_CBC/distinfo
new file mode 100644
index 000000000000..c14047b482fc
--- /dev/null
+++ b/security/pear-Crypt_CBC/distinfo
@@ -0,0 +1 @@
+MD5 (PEAR/Crypt_CBC-0.3.tgz) = 78a66ff02ab1e908c3ab1063e409e667
diff --git a/security/pear-Crypt_CBC/files/Crypt_HCEMD5.php b/security/pear-Crypt_CBC/files/Crypt_HCEMD5.php
new file mode 100644
index 000000000000..674c902a7117
--- /dev/null
+++ b/security/pear-Crypt_CBC/files/Crypt_HCEMD5.php
@@ -0,0 +1,288 @@
+<?php
+//
+// +----------------------------------------------------------------------+
+// | PHP Version 4 |
+// +----------------------------------------------------------------------+
+// | Copyright (c) 1997-2002 The PHP Group |
+// +----------------------------------------------------------------------+
+// | This source file is subject to version 2.02 of the PHP license, |
+// | that is bundled with this package in the file LICENSE, and is |
+// | available at through the world-wide-web at |
+// | http://www.php.net/license/2_02.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 |
+// | license@php.net so we can mail you a copy immediately. |
+// +----------------------------------------------------------------------+
+// | Authors: Manon Goo <manon@passionet.de> |
+// | Chuck Hagenbuch <chuck@horde.org> |
+// +----------------------------------------------------------------------+
+
+/**
+* Class to emulate Perl's Crypt::HCE_MD5 module
+*
+* The MIME Functions are tested and work symmetrically with the
+* Crypt::HCE_MD5 package (0.45) (without the KEYBUG Flag ..).
+*
+* Shamelessly stolen from Eric Estabrooks, eric@urbanrage.com
+* Crypt::HCE_MD5 package:
+*
+* This package implements a chaining block cipher using a one way
+* hash. This method of encryption is the same that is used by radius
+* (RFC2138) and is also described in Applied Cryptography by Bruce
+* Schneider (p. 353 / "Karn").
+*
+* Two interfaces are provided in the package. The first is straight
+* block encryption/decryption the second does base64 mime
+* encoding/decoding of the encrypted/decrypted blocks.
+*
+* The idea is the the two sides have a shared secret that supplies one
+* of the keys and a randomly generated block of bytes provides the
+* second key. The random key is passed in cleartext between the two
+* sides.
+*
+* Usage:
+* require_once 'Crypt/HCEMD5.php';
+* $key = 'my secret key';
+* srand((double)microtime()*32767);
+* $rand = rand(1, 32767);
+* $rand = pack('i*', $rand);
+* $message = 'text to encrypt';
+* $hcemd5 = new Crypt_HCEMD5($key, $rand);
+*
+* // These Functions work with mime decoded Data
+* $ciphertext = $hcemd5->encodeMime($message);
+* $cleartext = $hcemd5->decodeMime($ciphertext);
+*
+* // These Functions work with binary Data
+* $ciphertext = $hcemd5->encrypt($message);
+* $cleartext = $hcemd5->decrypt($ciphertext);
+*
+* // These Functions work with mime decoded Data the selfrand
+* // functions put the random value infront of the encrypted data to
+* // be restored later
+* $ciphertext = $hcemd5->encodeMimeSelfRand($message);
+* $new_hcemd5 = new Crypt_HCEMD5($key, '');
+* $cleartext = $new_hcemd5->DecodeMimeSelfRand($ciphertext);
+*
+* @version $Id: HCEMD5.php,v 1.8 2002/01/19 17:56:33 mj Exp $
+* @access public
+* @package Crypt
+*/
+class Crypt_HCEMD5 {
+
+ /**
+ * The first key to use. This should be a shared secret.
+ * @var string
+ */
+ var $key;
+
+ /**
+ * The second key to use. This should be a randomly generated
+ * block of bytes.
+ * @var long
+ */
+ var $rand;
+
+
+ /**
+ * Creates a Crypt_HCEMD5 object.
+ *
+ * @param string The shared secret key
+ * @param long (optional) The randomly generated key
+ *
+ * @access public
+ */
+ function Crypt_HCEMD5($key, $rand = null) {
+ $this->key = $key;
+
+ if (!isset($rand)) {
+ srand((double)microtime() * 32767);
+ $rand = rand(1, 32767);
+ $rand = pack('i*', $rand);
+ }
+ $this->rand = $rand;
+ }
+
+
+ /**
+ * Encrypt a block of data.
+ *
+ * @param string The data to encrypt.
+ * @return string The encrypted binary data.
+ * @access public
+ */
+ function encrypt($data)
+ {
+ $data = unpack('C*', $data);
+ $ans = array();
+ $ans1 = array();
+ $eblock = 1;
+ $e_block = $this->newKey($this->rand);
+ $data_size = count($data);
+ for ($i = 0; $i < $data_size; $i++) {
+ $mod = $i % 16;
+ if (($mod == 0) && ($i > 15)) {
+ $tmparr = array($ans[$i - 15], $ans[$i - 14], $ans[$i - 13], $ans[$i - 12], $ans[$i - 11], $ans[$i - 10], $ans[$i - 9], $ans[$i - 8], $ans[$i - 7], $ans[$i - 6], $ans[$i - 5], $ans[$i - 4], $ans[$i - 3], $ans[$i - 2], $ans[$i - 1], $ans[$i] );
+ $tmparr = $this->array2pack($tmparr);
+ $tmparr = implode('', $tmparr);
+ $e_block = $this->newKey($tmparr);
+ }
+
+ $mod++;
+ $i++;
+ $ans[$i] = $e_block[$mod] ^ $data[$i];
+ $ans1[$i] = pack('C*', $ans[$i]);
+ $i--;
+ $mod--;
+ }
+ return implode('', $ans1);
+ }
+
+ /**
+ * Decrypt a block of data.
+ *
+ * @param string The data to decrypt.
+ * @return string The decrypted binary data.
+ * @access public
+ */
+ function decrypt($data)
+ {
+ $data = unpack('C*', $data);
+ $ans = array();
+ $ans1 = array();
+ $eblock = 1;
+ $e_block = $this->newKey($this->rand);
+ $data_size = count($data);
+ for ($i = 0; $i < $data_size; $i++) {
+ $mod = $i % 16;
+ if (($mod == 0) && ($i > 15)) {
+ $tmparr = array($data[$i - 15], $data[$i - 14], $data[$i - 13], $data[$i - 12], $data[$i - 11], $data[$i - 10], $data[$i - 9], $data[$i - 8], $data[$i - 7], $data[$i - 6], $data[$i - 5], $data[$i - 4], $data[$i - 3], $data[$i - 2], $data[$i - 1], $data[$i]);
+ $tmparr = $this->array2pack($tmparr);
+ $tmparr = implode('', $tmparr);
+ $e_block = $this->newKey($tmparr);
+ }
+
+ $mod++;
+ $i++;
+ $ans[$i] = $e_block[$mod] ^ $data[$i];
+ $ans1[$i] = pack('C*', $ans[$i]);
+ $i--;
+ }
+ return implode('', $ans1);
+ }
+
+ /**
+ * Encrypt a block of data after MIME-encoding it.
+ *
+ * @param string The data to encrypt.
+ * @return string The encrypted mime-encoded data.
+ * @access public
+ */
+ function encodeMime($data)
+ {
+ return base64_encode($this->encrypt($data));
+ }
+
+ /**
+ * Decrypt a block of data and then MIME-decode it.
+ *
+ * @param string The data to decrypt.
+ * @return string The decrypted mime-decoded data.
+ * @access public
+ */
+ function decodeMime($data)
+ {
+ return $this->decrypt(base64_decode($data));
+ }
+
+ /**
+ * Encrypt a block of data after MIME-encoding it, and include the
+ * random hash in the final output in plaintext so it can be
+ * retrieved and decrypted with only the secret key by
+ * decodeMimeSelfRand().
+ *
+ * @param string The data to encrypt.
+ * @param string The encrypted mime-encoded data, in the format: randkey#encrypted_data.
+ * @access public
+ */
+ function encodeMimeSelfRand($data) {
+ return base64_encode($this->rand) . '#' . $this->encodeMime($data);
+ }
+
+ /**
+ * Decrypt a block of data and then MIME-decode it, using the
+ * random key stored in beginning of the ciphertext generated by
+ * encodeMimeSelfRand().
+ *
+ * @param string The data to decrypt, in the format: randkey#encrypted_data.
+ * @return string The decrypted, mime-decoded data.
+ * @access public
+ */
+ function decodeMimeSelfRand($data)
+ {
+ if (strpos($data, '#') === false) {
+ return false;
+ }
+
+ list($rand, $data_crypt) = explode('#', $data);
+ if (isset($data_crypt)) {
+ $rand = base64_decode($rand);
+ $this->rand = $rand;
+ return $this->decodeMime($data_crypt);
+ } else {
+ return false;
+ }
+ }
+
+
+ /**
+ ** Support Functions
+ **/
+
+ /**
+ * Implment md5 hashing in php, though use the mhash() function if it is available.
+ *
+ * @param string The string to hash.
+ * @return string The md5 mhash of the string.
+ * @access private
+ */
+ function binmd5($string)
+ {
+ if (extension_loaded('mhash')) {
+ return mhash(MHASH_MD5, $string);
+ }
+
+ return pack('H*', md5($string));
+ }
+
+ /**
+ * Turn an array into a binary packed string.
+ *
+ * @param array The array to pack.
+ * @return string The binary packed representation of the array.
+ * @access private
+ */
+ function array2pack($array)
+ {
+ $pack = array();
+ foreach ($array as $val) {
+ $pack[] = pack('C*', $val);
+ }
+ return $pack;
+ }
+
+ /**
+ * Generate a new key for a new encryption block.
+ *
+ * @param string The basis for the key.
+ * @param string The new key.
+ * @access private
+ */
+ function newKey($round)
+ {
+ $digest = $this->binmd5($this->key . $round);
+ return unpack('C*', $digest);
+ }
+
+}
+?>
diff --git a/security/pear-Crypt_CBC/pkg-comment b/security/pear-Crypt_CBC/pkg-comment
new file mode 100644
index 000000000000..a7fcd4be792e
--- /dev/null
+++ b/security/pear-Crypt_CBC/pkg-comment
@@ -0,0 +1 @@
+PEAR class to emulate Perl's Crypt::CBC module
diff --git a/security/pear-Crypt_CBC/pkg-descr b/security/pear-Crypt_CBC/pkg-descr
new file mode 100644
index 000000000000..af138b21b04f
--- /dev/null
+++ b/security/pear-Crypt_CBC/pkg-descr
@@ -0,0 +1,3 @@
+A PEAR class to emulate Perl's Crypt::CBC module.
+
+WWW: http://pear.php.net/package-info.php?pacid=48
diff --git a/security/pear-Crypt_CBC/pkg-plist b/security/pear-Crypt_CBC/pkg-plist
new file mode 100644
index 000000000000..5adb75cf2b9b
--- /dev/null
+++ b/security/pear-Crypt_CBC/pkg-plist
@@ -0,0 +1,3 @@
+%%PEARDIR%%/Crypt/CBC.php
+%%PEARDIR%%/Crypt/HCEMD5.php
+@dirrm %%PEARDIR%%/Crypt