diff options
Diffstat (limited to 'include/crypto.php')
-rw-r--r-- | include/crypto.php | 38 |
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; } |