aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorFriendika <info@friendika.com>2011-08-20 04:53:11 -0700
committerFriendika <info@friendika.com>2011-08-20 04:53:11 -0700
commit0d9d576aa642e02eb8673aa20bdf4b6a18ae6bc3 (patch)
treecf41c9c4bc72a345f8a05896b82d54c06074dbf0 /include
parent6aa633efc829d4d3e9ccba4f6fb4d555f3c968ca (diff)
downloadvolse-hubzilla-0d9d576aa642e02eb8673aa20bdf4b6a18ae6bc3.tar.gz
volse-hubzilla-0d9d576aa642e02eb8673aa20bdf4b6a18ae6bc3.tar.bz2
volse-hubzilla-0d9d576aa642e02eb8673aa20bdf4b6a18ae6bc3.zip
move encryption functions to crypto file
Diffstat (limited to 'include')
-rw-r--r--include/crypto.php42
-rw-r--r--include/diaspora.php1
-rw-r--r--include/items.php5
-rw-r--r--include/text.php40
-rw-r--r--include/zotfns.php2
5 files changed, 47 insertions, 43 deletions
diff --git a/include/crypto.php b/include/crypto.php
index 6b27e832b..999b48be4 100644
--- a/include/crypto.php
+++ b/include/crypto.php
@@ -74,7 +74,7 @@ function DerToRsa($Der)
//Encode:
$Der = base64_encode($Der);
//Split lines:
- $lines = str_split($Der, 65);
+ $lines = str_split($Der, 64);
$body = implode("\n", $lines);
//Get title:
$title = 'RSA PUBLIC KEY';
@@ -184,3 +184,43 @@ function salmon_key($pubkey) {
}
+
+if(! function_exists('aes_decrypt')) {
+function aes_decrypt($val,$ky)
+{
+ $key="\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
+ for($a=0;$a<strlen($ky);$a++)
+ $key[$a%16]=chr(ord($key[$a%16]) ^ ord($ky[$a]));
+ $mode = MCRYPT_MODE_ECB;
+ $enc = MCRYPT_RIJNDAEL_128;
+ $dec = @mcrypt_decrypt($enc, $key, $val, $mode, @mcrypt_create_iv( @mcrypt_get_iv_size($enc, $mode), MCRYPT_DEV_URANDOM ) );
+ return rtrim($dec,(( ord(substr($dec,strlen($dec)-1,1))>=0 and ord(substr($dec, strlen($dec)-1,1))<=16)? chr(ord( substr($dec,strlen($dec)-1,1))):null));
+}}
+
+
+if(! function_exists('aes_encrypt')) {
+function aes_encrypt($val,$ky)
+{
+ $key="\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
+ for($a=0;$a<strlen($ky);$a++)
+ $key[$a%16]=chr(ord($key[$a%16]) ^ ord($ky[$a]));
+ $mode=MCRYPT_MODE_ECB;
+ $enc=MCRYPT_RIJNDAEL_128;
+ $val=str_pad($val, (16*(floor(strlen($val) / 16)+(strlen($val) % 16==0?2:1))), chr(16-(strlen($val) % 16)));
+ return mcrypt_encrypt($enc, $key, $val, $mode, mcrypt_create_iv( mcrypt_get_iv_size($enc, $mode), MCRYPT_DEV_URANDOM));
+}}
+
+
+function pkcs5_pad ($text, $blocksize)
+{
+ $pad = $blocksize - (strlen($text) % $blocksize);
+ return $text . str_repeat(chr($pad), $pad);
+}
+
+function pkcs5_unpad($text)
+{
+ $pad = ord($text{strlen($text)-1});
+ if ($pad > strlen($text)) return false;
+ if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) return false;
+ return substr($text, 0, -1 * $pad);
+}
diff --git a/include/diaspora.php b/include/diaspora.php
index 2e8ff6892..a52c82913 100644
--- a/include/diaspora.php
+++ b/include/diaspora.php
@@ -141,6 +141,7 @@ function diaspora_decode($importer,$xml) {
$decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $outer_key, $ciphertext, MCRYPT_MODE_CBC, $outer_iv);
+
$decrypted = pkcs5_unpad($decrypted);
/**
diff --git a/include/items.php b/include/items.php
index 39a61c4ad..b84b71ba8 100644
--- a/include/items.php
+++ b/include/items.php
@@ -1,8 +1,9 @@
<?php
-require_once('bbcode.php');
-require_once('oembed.php');
+require_once('include/bbcode.php');
+require_once('include/oembed.php');
require_once('include/salmon.php');
+require_once('include/crypto.php');
function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0) {
diff --git a/include/text.php b/include/text.php
index b13cf980f..66447069e 100644
--- a/include/text.php
+++ b/include/text.php
@@ -620,32 +620,6 @@ function valid_email($x){
}}
-if(! function_exists('aes_decrypt')) {
-function aes_decrypt($val,$ky)
-{
- $key="\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
- for($a=0;$a<strlen($ky);$a++)
- $key[$a%16]=chr(ord($key[$a%16]) ^ ord($ky[$a]));
- $mode = MCRYPT_MODE_ECB;
- $enc = MCRYPT_RIJNDAEL_128;
- $dec = @mcrypt_decrypt($enc, $key, $val, $mode, @mcrypt_create_iv( @mcrypt_get_iv_size($enc, $mode), MCRYPT_DEV_URANDOM ) );
- return rtrim($dec,(( ord(substr($dec,strlen($dec)-1,1))>=0 and ord(substr($dec, strlen($dec)-1,1))<=16)? chr(ord( substr($dec,strlen($dec)-1,1))):null));
-}}
-
-
-if(! function_exists('aes_encrypt')) {
-function aes_encrypt($val,$ky)
-{
- $key="\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
- for($a=0;$a<strlen($ky);$a++)
- $key[$a%16]=chr(ord($key[$a%16]) ^ ord($ky[$a]));
- $mode=MCRYPT_MODE_ECB;
- $enc=MCRYPT_RIJNDAEL_128;
- $val=str_pad($val, (16*(floor(strlen($val) / 16)+(strlen($val) % 16==0?2:1))), chr(16-(strlen($val) % 16)));
- return mcrypt_encrypt($enc, $key, $val, $mode, mcrypt_create_iv( mcrypt_get_iv_size($enc, $mode), MCRYPT_DEV_URANDOM));
-}}
-
-
/**
*
* Function: linkify
@@ -903,20 +877,6 @@ function generate_user_guid() {
}
-function pkcs5_pad ($text, $blocksize)
-{
- $pad = $blocksize - (strlen($text) % $blocksize);
- return $text . str_repeat(chr($pad), $pad);
-}
-
-function pkcs5_unpad($text)
-{
- $pad = ord($text{strlen($text)-1});
- if ($pad > strlen($text)) return false;
- if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) return false;
- return substr($text, 0, -1 * $pad);
-}
-
function base64url_encode($s, $strip_padding = false) {
diff --git a/include/zotfns.php b/include/zotfns.php
index b695b6fcb..b23fce82a 100644
--- a/include/zotfns.php
+++ b/include/zotfns.php
@@ -2,6 +2,8 @@
require_once('include/salmon.php');
+require_once('include/crypto.php');
+
function zot_get($url,$args) {
$argstr = '';