aboutsummaryrefslogtreecommitdiffstats
path: root/include/crypto.php
diff options
context:
space:
mode:
authorfriendica <info@friendica.com>2012-07-21 03:48:59 -0700
committerfriendica <info@friendica.com>2012-07-21 03:48:59 -0700
commit6e08f398200de8a1560e14cdb4fb6c278a8e2b94 (patch)
tree9ca6e1e6350ba49b8f3abc130c9551afe7fa436d /include/crypto.php
parentbf386749047731d3a7f47fd99f7dcc4e93ed7be7 (diff)
downloadvolse-hubzilla-6e08f398200de8a1560e14cdb4fb6c278a8e2b94.tar.gz
volse-hubzilla-6e08f398200de8a1560e14cdb4fb6c278a8e2b94.tar.bz2
volse-hubzilla-6e08f398200de8a1560e14cdb4fb6c278a8e2b94.zip
simplify
Diffstat (limited to 'include/crypto.php')
-rw-r--r--include/crypto.php38
1 files changed, 2 insertions, 36 deletions
diff --git a/include/crypto.php b/include/crypto.php
index ed0a35704..4c6f9a2ae 100644
--- a/include/crypto.php
+++ b/include/crypto.php
@@ -8,47 +8,13 @@ require_once('library/asn1.php');
function rsa_sign($data,$key,$alg = 'sha256') {
$sig = '';
- if (version_compare(PHP_VERSION, '5.3.0', '>=') || $alg === 'sha1') {
- openssl_sign($data,$sig,$key,(($alg == 'sha1') ? OPENSSL_ALGO_SHA1 : $alg));
- }
- else {
- if(strlen($key) < 1024 || extension_loaded('gmp')) {
- require_once('library/phpsec/Crypt/RSA.php');
- $rsa = new CRYPT_RSA();
- $rsa->signatureMode = CRYPT_RSA_SIGNATURE_PKCS1;
- $rsa->setHash($alg);
- $rsa->loadKey($key);
- $sig = $rsa->sign($data);
- }
- else {
- logger('rsa_sign: insecure algorithm used. Please upgrade PHP to 5.3');
- openssl_private_encrypt(hex2bin('3031300d060960864801650304020105000420') . hash('sha256',$data,true), $sig, $key);
- }
- }
+ openssl_sign($data,$sig,$key,$alg);
return $sig;
}
function rsa_verify($data,$sig,$key,$alg = 'sha256') {
- if (version_compare(PHP_VERSION, '5.3.0', '>=') || $alg === 'sha1') {
- $verify = openssl_verify($data,$sig,$key,(($alg == 'sha1') ? OPENSSL_ALGO_SHA1 : $alg));
- }
- else {
- if(strlen($key) <= 300 || extension_loaded('gmp')) {
- require_once('library/phpsec/Crypt/RSA.php');
- $rsa = new CRYPT_RSA();
- $rsa->signatureMode = CRYPT_RSA_SIGNATURE_PKCS1;
- $rsa->setHash($alg);
- $rsa->loadKey($key);
- $verify = $rsa->verify($data,$sig);
- }
- else {
- // fallback sha256 verify for PHP < 5.3 and large key lengths
- $rawsig = '';
- openssl_public_decrypt($sig,$rawsig,$key);
- $verify = (($rawsig && substr($rawsig,-32) === hash('sha256',$data,true)) ? true : false);
- }
- }
+ $verify = openssl_verify($data,$sig,$key,$alg);
return $verify;
}